1 ;;; org.el --- Outline-based notes management and organizer
3 ;; Carstens outline-mode for keeping track of everything.
4 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Maintainer: Bastien Guerry <bzg at gnu dot org>
8 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; Homepage: http://orgmode.org
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
31 ;; project planning with a fast and effective plain-text system.
33 ;; Org-mode develops organizational tasks around NOTES files that contain
34 ;; information about projects as plain text. Org-mode is implemented on
35 ;; top of outline-mode, which makes it possible to keep the content of
36 ;; large files well structured. Visibility cycling and structure editing
37 ;; help to work with the tree. Tables are easily created with a built-in
38 ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
39 ;; and scheduling. It dynamically compiles entries into an agenda that
40 ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
41 ;; Plain text URL-like links connect to websites, emails, Usenet
42 ;; messages, BBDB entries, and any files related to the projects. For
43 ;; printing and sharing of notes, an Org-mode file can be exported as a
44 ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
45 ;; iCalendar file. It can also serve as a publishing tool for a set of
48 ;; Installation and Activation
49 ;; ---------------------------
50 ;; See the corresponding sections in the manual at
52 ;; http://orgmode.org/org.html#Installation
56 ;; The documentation of Org-mode can be found in the TeXInfo file. The
57 ;; distribution also contains a PDF version of it. At the homepage of
58 ;; Org-mode, you can read the same text online as HTML. There is also an
59 ;; excellent reference card made by Philip Rooke. This card can be found
60 ;; in the etc/ directory of Emacs 22.
62 ;; A list of recent changes can be found at
63 ;; http://orgmode.org/Changes.html
67 (defvar org-inhibit-highlight-removal nil
) ; dynamically scoped param
68 (defvar org-table-formula-constants-local nil
69 "Local version of `org-table-formula-constants'.")
70 (make-variable-buffer-local 'org-table-formula-constants-local
)
72 ;;;; Require other packages
80 ;; Emacs 22 calendar compatibility: Make sure the new variables are available
81 (when (fboundp 'defvaralias
)
82 (unless (boundp 'calendar-view-holidays-initially-flag
)
83 (defvaralias 'calendar-view-holidays-initially-flag
84 'view-calendar-holidays-initially
))
85 (unless (boundp 'calendar-view-diary-initially-flag
)
86 (defvaralias 'calendar-view-diary-initially-flag
87 'view-diary-entries-initially
))
88 (unless (boundp 'diary-fancy-buffer
)
89 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
)))
91 (require 'outline
) (require 'noutline
)
92 ;; Other stuff we need.
94 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
99 (require 'org-entities
)
100 (require 'org-compat
)
103 (require 'org-pcomplete
)
105 (require 'org-footnote
)
107 (declare-function org-inlinetask-at-task-p
"org-inlinetask" ())
108 (declare-function org-inlinetask-outline-regexp
"org-inlinetask" ())
109 (declare-function org-inlinetask-toggle-visibility
"org-inlinetask" ())
110 (declare-function org-pop-to-buffer-same-window
"org-compat" (&optional buffer-or-name norecord label
))
111 (declare-function org-at-clock-log-p
"org-clock" ())
112 (declare-function org-clock-timestamps-up
"org-clock" ())
113 (declare-function org-clock-timestamps-down
"org-clock" ())
124 ;; load languages based on value of `org-babel-load-languages'
125 (defvar org-babel-load-languages
)
127 (defun org-babel-do-load-languages (sym value
)
128 "Load the languages defined in `org-babel-load-languages'."
129 (set-default sym value
)
131 (let ((active (cdr pair
)) (lang (symbol-name (car pair
))))
134 (require (intern (concat "ob-" lang
))))
136 (funcall 'fmakunbound
137 (intern (concat "org-babel-execute:" lang
)))
138 (funcall 'fmakunbound
139 (intern (concat "org-babel-expand-body:" lang
)))))))
140 org-babel-load-languages
))
142 (defcustom org-babel-load-languages
'((emacs-lisp . t
))
143 "Languages which can be evaluated in Org-mode buffers.
144 This list can be used to load support for any of the languages
145 below, note that each language will depend on a different set of
146 system executables and/or Emacs modes. When a language is
147 \"loaded\", then code blocks in that language can be evaluated
148 with `org-babel-execute-src-block' bound by default to C-c
149 C-c (note the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can
150 be set to remove code block evaluation from the C-c C-c
151 keybinding. By default only Emacs Lisp (which has no
152 requirements) is loaded."
154 :set
'org-babel-do-load-languages
156 :type
'(alist :tag
"Babel Languages"
159 (const :tag
"Awk" awk
)
162 (const :tag
"Asymptote" asymptote
)
163 (const :tag
"Calc" calc
)
164 (const :tag
"Clojure" clojure
)
165 (const :tag
"CSS" css
)
166 (const :tag
"Ditaa" ditaa
)
167 (const :tag
"Dot" dot
)
168 (const :tag
"Emacs Lisp" emacs-lisp
)
169 (const :tag
"Fortran" fortran
)
170 (const :tag
"Gnuplot" gnuplot
)
171 (const :tag
"Haskell" haskell
)
173 (const :tag
"Java" java
)
174 (const :tag
"Javascript" js
)
175 (const :tag
"LaTeX" latex
)
176 (const :tag
"Ledger" ledger
)
177 (const :tag
"Lilypond" lilypond
)
178 (const :tag
"Maxima" maxima
)
179 (const :tag
"Matlab" matlab
)
180 (const :tag
"Mscgen" mscgen
)
181 (const :tag
"Ocaml" ocaml
)
182 (const :tag
"Octave" octave
)
183 (const :tag
"Org" org
)
184 (const :tag
"Perl" perl
)
185 (const :tag
"Pico Lisp" picolisp
)
186 (const :tag
"PlantUML" plantuml
)
187 (const :tag
"Python" python
)
188 (const :tag
"Ruby" ruby
)
189 (const :tag
"Sass" sass
)
190 (const :tag
"Scala" scala
)
191 (const :tag
"Scheme" scheme
)
192 (const :tag
"Screen" screen
)
193 (const :tag
"Shell Script" sh
)
194 (const :tag
"Shen" shen
)
195 (const :tag
"Sql" sql
)
196 (const :tag
"Sqlite" sqlite
))
197 :value-type
(boolean :tag
"Activate" :value t
)))
199 ;;;; Customization variables
200 (defcustom org-clone-delete-id nil
201 "Remove ID property of clones of a subtree.
202 When non-nil, clones of a subtree don't inherit the ID property.
203 Otherwise they inherit the ID property with a new unique
211 (defconst org-version
"7.8.03"
212 "The version number of the file org.el.")
214 (defun org-version (&optional here
)
215 "Show the org-mode version in the echo area.
216 With prefix arg HERE, insert it at point."
218 (let* ((origin default-directory
)
219 (version org-version
)
221 (dir (concat (file-name-directory (locate-library "org")) "../" )))
222 (when (and (file-exists-p (expand-file-name ".git" dir
))
223 (executable-find "git"))
227 (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
228 (with-current-buffer "*Shell Command Output*"
229 (goto-char (point-min))
230 (setq git-version
(buffer-substring (point) (point-at-eol))))
231 (subst-char-in-string ?- ?. git-version t
)
232 (when (string-match "\\S-"
233 (shell-command-to-string
234 "git diff-index --name-only HEAD --"))
235 (setq git-version
(concat git-version
".dirty")))
236 (setq version
(concat version
" (" git-version
")"))))
238 (setq version
(format "Org-mode version %s" version
))
239 (if here
(insert version
))
242 ;;; Compatibility constants
244 ;;; The custom variables
247 "Outline-based notes management and organizer."
252 (defcustom org-mode-hook nil
253 "Mode hook for Org-mode, run after the mode was turned on."
257 (defcustom org-load-hook nil
258 "Hook that is run after org.el has been loaded."
262 (defcustom org-log-buffer-setup-hook nil
263 "Hook that is run after an Org log buffer is created."
268 (defvar org-modules
) ; defined below
269 (defvar org-modules-loaded nil
270 "Have the modules been loaded already?")
272 (defun org-load-modules-maybe (&optional force
)
273 "Load all extensions listed in `org-modules'."
274 (when (or force
(not org-modules-loaded
))
276 (condition-case nil
(require ext
)
277 (error (message "Problems while trying to load feature `%s'" ext
))))
279 (setq org-modules-loaded t
)))
281 (defun org-set-modules (var value
)
282 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
284 (when (featurep 'org
)
285 (org-load-modules-maybe 'force
)))
287 (when (org-bound-and-true-p org-modules
)
288 (let ((a (member 'org-infojs org-modules
)))
289 (and a
(setcar a
'org-jsinfo
))))
291 (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
)
292 "Modules that should always be loaded together with org.el.
293 If a description starts with <C>, the file is not part of Emacs
294 and loading it will require that you have downloaded and properly installed
295 the org-mode distribution.
297 You can also use this system to load external packages (i.e. neither Org
298 core modules, nor modules from the CONTRIB directory). Just add symbols
299 to the end of the list. If the package is called org-xyz.el, then you need
300 to add the symbol `xyz', and the package must have a call to
304 :set
'org-set-modules
307 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
308 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
309 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
310 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
311 (const :tag
" docview: Links to doc-view buffers" org-docview
)
312 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
313 (const :tag
" id: Global IDs for identifying entries" org-id
)
314 (const :tag
" info: Links to Info nodes" org-info
)
315 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
316 (const :tag
" habit: Track your consistency with habits" org-habit
)
317 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
318 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
319 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
320 (const :tag
" mew Links to Mew folders/messages" org-mew
)
321 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
322 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
323 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
324 (const :tag
" special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
325 (const :tag
" vm: Links to VM folders/messages" org-vm
)
326 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
327 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
328 (const :tag
" mouse: Additional mouse support" org-mouse
)
329 (const :tag
" TaskJuggler: Export tasks to a TaskJuggler project" org-taskjuggler
)
331 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
332 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
333 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
334 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
335 (const :tag
"C collector: Collect properties into tables" org-collector
)
336 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
337 (const :tag
"C drill: Flashcards and spaced repetition for Org-mode" org-drill
)
338 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
339 (const :tag
"C eshell Support for links to working directories in eshell" org-eshell
)
340 (const :tag
"C eval: Include command output as text" org-eval
)
341 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
342 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
343 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
344 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
345 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
347 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
349 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
350 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
351 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
352 (const :tag
"C notmuch: Provide org links to notmuch searches or messages" org-notmuch
)
353 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
354 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
355 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
356 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
357 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
358 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
359 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
360 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
361 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
362 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
363 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
364 (const :tag
"C track: Keep up with Org-mode development" org-track
)
365 (const :tag
"C velocity Something like Notational Velocity for Org" org-velocity
)
366 (const :tag
"C wikinodes: CamelCase wiki-like links" org-wikinodes
)
367 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
369 (defcustom org-support-shift-select nil
370 "Non-nil means make shift-cursor commands select text when possible.
372 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys
373 start selecting a region, or enlarge regions started in this way.
374 In Org-mode, in special contexts, these same keys are used for
375 other purposes, important enough to compete with shift selection.
376 Org tries to balance these needs by supporting `shift-select-mode'
377 outside these special contexts, under control of this variable.
379 The default of this variable is nil, to avoid confusing behavior. Shifted
380 cursor keys will then execute Org commands in the following contexts:
381 - on a headline, changing TODO state (left/right) and priority (up/down)
382 - on a time stamp, changing the time
383 - in a plain list item, changing the bullet type
384 - in a property definition line, switching between allowed values
385 - in the BEGIN line of a clock table (changing the time block).
386 Outside these contexts, the commands will throw an error.
388 When this variable is t and the cursor is not in a special
389 context, Org-mode will support shift-selection for making and
390 enlarging regions. To make this more effective, the bullet
391 cycling will no longer happen anywhere in an item line, but only
392 if the cursor is exactly on the bullet.
394 If you set this variable to the symbol `always', then the keys
395 will not be special in headlines, property lines, and item lines,
396 to make shift selection work there as well. If this is what you
397 want, you can use the following alternative commands: `C-c C-t'
398 and `C-c ,' to change TODO state and priority, `C-u C-u C-c C-t'
399 can be used to switch TODO sets, `C-c -' to cycle item bullet
400 types, and properties can be edited by hand or in column view.
402 However, when the cursor is on a timestamp, shift-cursor commands
403 will still edit the time stamp - this is just too good to give up.
405 XEmacs user should have this variable set to nil, because
406 `shift-select-mode' is in Emacs 23 or later only."
409 (const :tag
"Never" nil
)
410 (const :tag
"When outside special context" t
)
411 (const :tag
"Everywhere except timestamps" always
)))
413 (defcustom org-loop-over-headlines-in-active-region nil
414 "Shall some commands act upon headlines in the active region?
416 When set to `t', some commands will be performed in all headlines
417 within the active region.
419 When set to `start-level', some commands will be performed in all
420 headlines within the active region, provided that these headlines
421 are of the same level than the first one.
423 When set to a string, those commands will be performed on the
424 matching headlines within the active region. Such string must be
425 a tags/property/todo match as it is used in the agenda tags view.
427 The list of commands is: `org-schedule', `org-deadline',
428 `org-todo', `org-archive-subtree', `org-archive-set-tag' and
429 `org-archive-to-archive-sibling'. The archiving commands skip
430 already archived entries."
431 :type
'(choice (const :tag
"Don't loop" nil
)
432 (const :tag
"All headlines in active region" t
)
433 (const :tag
"In active region, headlines at the same level than the first one" 'start-level
)
434 (string :tag
"Tags/Property/Todo matcher"))
439 (defgroup org-startup nil
440 "Options concerning startup of Org-mode."
444 (defcustom org-startup-folded t
445 "Non-nil means entering Org-mode will switch to OVERVIEW.
446 This can also be configured on a per-file basis by adding one of
447 the following lines anywhere in the buffer:
449 #+STARTUP: fold (or `overview', this is equivalent)
450 #+STARTUP: nofold (or `showall', this is equivalent)
452 #+STARTUP: showeverything"
455 (const :tag
"nofold: show all" nil
)
456 (const :tag
"fold: overview" t
)
457 (const :tag
"content: all headlines" content
)
458 (const :tag
"show everything, even drawers" showeverything
)))
460 (defcustom org-startup-truncated t
461 "Non-nil means entering Org-mode will set `truncate-lines'.
462 This is useful since some lines containing links can be very long and
463 uninteresting. Also tables look terrible when wrapped."
467 (defcustom org-startup-indented nil
468 "Non-nil means turn on `org-indent-mode' on startup.
469 This can also be configured on a per-file basis by adding one of
470 the following lines anywhere in the buffer:
474 :group
'org-structure
476 (const :tag
"Not" nil
)
477 (const :tag
"Globally (slow on startup in large files)" t
)))
479 (defcustom org-use-sub-superscripts t
480 "Non-nil means interpret \"_\" and \"^\" for export.
481 When this option is turned on, you can use TeX-like syntax for sub- and
482 superscripts. Several characters after \"_\" or \"^\" will be
483 considered as a single item - so grouping with {} is normally not
484 needed. For example, the following things will be parsed as single
485 sub- or superscripts.
487 10^24 or 10^tau several digits will be considered 1 item.
488 10^-12 or 10^-tau a leading sign with digits or a word
489 x^2-y^3 will be read as x^2 - y^3, because items are
490 terminated by almost any nonword/nondigit char.
491 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
493 Still, ambiguity is possible - so when in doubt use {} to enclose the
494 sub/superscript. If you set this variable to the symbol `{}',
495 the braces are *required* in order to trigger interpretations as
496 sub/superscript. This can be helpful in documents that need \"_\"
497 frequently in plain text.
499 Not all export backends support this, but HTML does.
501 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
503 :group
'org-export-translation
506 (const :tag
"Always interpret" t
)
507 (const :tag
"Only with braces" {})
508 (const :tag
"Never interpret" nil
)))
510 (if (fboundp 'defvaralias
)
511 (defvaralias 'org-export-with-sub-superscripts
'org-use-sub-superscripts
))
514 (defcustom org-startup-with-beamer-mode nil
515 "Non-nil means turn on `org-beamer-mode' on startup.
516 This can also be configured on a per-file basis by adding one of
517 the following lines anywhere in the buffer:
524 (defcustom org-startup-align-all-tables nil
525 "Non-nil means align all tables when visiting a file.
526 This is useful when the column width in tables is forced with <N> cookies
527 in table fields. Such tables will look correct only after the first re-align.
528 This can also be configured on a per-file basis by adding one of
529 the following lines anywhere in the buffer:
535 (defcustom org-startup-with-inline-images nil
536 "Non-nil means show inline images when loading a new Org file.
537 This can also be configured on a per-file basis by adding one of
538 the following lines anywhere in the buffer:
539 #+STARTUP: inlineimages
540 #+STARTUP: noinlineimages"
545 (defcustom org-insert-mode-line-in-empty-file nil
546 "Non-nil means insert the first line setting Org-mode in empty files.
547 When the function `org-mode' is called interactively in an empty file, this
548 normally means that the file name does not automatically trigger Org-mode.
549 To ensure that the file will always be in Org-mode in the future, a
550 line enforcing Org-mode will be inserted into the buffer, if this option
555 (defcustom org-replace-disputed-keys nil
556 "Non-nil means use alternative key bindings for some keys.
557 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
558 These keys are also used by other packages like shift-selection-mode'
559 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
560 If you want to use Org-mode together with one of these other modes,
561 or more generally if you would like to move some Org-mode commands to
562 other keys, set this variable and configure the keys with the variable
565 This option is only relevant at load-time of Org-mode, and must be set
566 *before* org.el is loaded. Changing it requires a restart of Emacs to
571 (defcustom org-use-extra-keys nil
572 "Non-nil means use extra key sequence definitions for certain commands.
573 This happens automatically if you run XEmacs or if `window-system'
574 is nil. This variable lets you do the same manually. You must
575 set it before loading org.
577 Example: on Carbon Emacs 22 running graphically, with an external
578 keyboard on a Powerbook, the default way of setting M-left might
579 not work for either Alt or ESC. Setting this variable will make
584 (if (fboundp 'defvaralias
)
585 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
587 (defcustom org-disputed-keys
588 '(([(shift up
)] .
[(meta p
)])
589 ([(shift down
)] .
[(meta n
)])
590 ([(shift left
)] .
[(meta -
)])
591 ([(shift right
)] .
[(meta +)])
592 ([(control shift right
)] .
[(meta shift
+)])
593 ([(control shift left
)] .
[(meta shift -
)]))
594 "Keys for which Org-mode and other modes compete.
595 This is an alist, cars are the default keys, second element specifies
596 the alternative to use when `org-replace-disputed-keys' is t.
598 Keys can be specified in any syntax supported by `define-key'.
599 The value of this option takes effect only at Org-mode's startup,
600 therefore you'll have to restart Emacs to apply it after changing."
605 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
606 Or return the original if not disputed.
607 Also apply the translations defined in `org-xemacs-key-equivalents'."
608 (when org-replace-disputed-keys
609 (let* ((nkey (key-description key
))
610 (x (org-find-if (lambda (x)
611 (equal (key-description (car x
)) nkey
))
613 (setq key
(if x
(cdr x
) key
))))
614 (when (featurep 'xemacs
)
615 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
618 (defun org-find-if (predicate seq
)
621 (if (funcall predicate
(car seq
))
622 (throw 'exit
(car seq
))
625 (defun org-defkey (keymap key def
)
626 "Define a key, possibly translated, as returned by `org-key'."
627 (define-key keymap
(org-key key
) def
))
629 (defcustom org-ellipsis nil
630 "The ellipsis to use in the Org-mode outline.
631 When nil, just use the standard three dots. When a string, use that instead,
632 When a face, use the standard 3 dots, but with the specified face.
633 The change affects only Org-mode (which will then use its own display table).
634 Changing this requires executing `M-x org-mode' in a buffer to become
637 :type
'(choice (const :tag
"Default" nil
)
638 (face :tag
"Face" :value org-warning
)
639 (string :tag
"String" :value
"...#")))
641 (defvar org-display-table nil
642 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
644 (defgroup org-keywords nil
645 "Keywords in Org-mode."
649 (defcustom org-deadline-string
"DEADLINE:"
650 "String to mark deadline entries.
651 A deadline is this string, followed by a time stamp. Should be a word,
652 terminated by a colon. You can insert a schedule keyword and
653 a timestamp with \\[org-deadline].
654 Changes become only effective after restarting Emacs."
658 (defcustom org-scheduled-string
"SCHEDULED:"
659 "String to mark scheduled TODO entries.
660 A schedule is this string, followed by a time stamp. Should be a word,
661 terminated by a colon. You can insert a schedule keyword and
662 a timestamp with \\[org-schedule].
663 Changes become only effective after restarting Emacs."
667 (defcustom org-closed-string
"CLOSED:"
668 "String used as the prefix for timestamps logging closing a TODO entry."
672 (defcustom org-clock-string
"CLOCK:"
673 "String used as prefix for timestamps clocking work hours on an item."
677 (defcustom org-comment-string
"COMMENT"
678 "Entries starting with this keyword will never be exported.
679 An entry can be toggled between COMMENT and normal with
680 \\[org-toggle-comment].
681 Changes become only effective after restarting Emacs."
685 (defcustom org-quote-string
"QUOTE"
686 "Entries starting with this keyword will be exported in fixed-width font.
687 Quoting applies only to the text in the entry following the headline, and does
688 not extend beyond the next headline, even if that is lower level.
689 An entry can be toggled between QUOTE and normal with
690 \\[org-toggle-fixed-width-section]."
694 (defconst org-repeat-re
695 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)"
696 "Regular expression for specifying repeated events.
697 After a match, group 1 contains the repeat expression.")
699 (defgroup org-structure nil
700 "Options concerning the general structure of Org-mode files."
704 (defgroup org-reveal-location nil
705 "Options about how to make context of a location visible."
706 :tag
"Org Reveal Location"
707 :group
'org-structure
)
709 (defconst org-context-choice
711 (const :tag
"Always" t
)
712 (const :tag
"Never" nil
)
713 (repeat :greedy t
:tag
"Individual contexts"
715 (choice :tag
"Context"
722 (const bookmark-jump
)
726 "Contexts for the reveal options.")
728 (defcustom org-show-hierarchy-above
'((default . t
))
729 "Non-nil means show full hierarchy when revealing a location.
730 Org-mode often shows locations in an org-mode file which might have
731 been invisible before. When this is set, the hierarchy of headings
732 above the exposed location is shown.
733 Turning this off for example for sparse trees makes them very compact.
734 Instead of t, this can also be an alist specifying this option for different
735 contexts. Valid contexts are
736 agenda when exposing an entry from the agenda
737 org-goto when using the command `org-goto' on key C-c C-j
738 occur-tree when using the command `org-occur' on key C-c /
739 tags-tree when constructing a sparse tree based on tags matches
740 link-search when exposing search matches associated with a link
741 mark-goto when exposing the jump goal of a mark
742 bookmark-jump when exposing a bookmark location
743 isearch when exiting from an incremental search
744 default default for all contexts not set explicitly"
745 :group
'org-reveal-location
746 :type org-context-choice
)
748 (defcustom org-show-following-heading
'((default . nil
))
749 "Non-nil means show following heading when revealing a location.
750 Org-mode often shows locations in an org-mode file which might have
751 been invisible before. When this is set, the heading following the
753 Turning this off for example for sparse trees makes them very compact,
754 but makes it harder to edit the location of the match. In such a case,
755 use the command \\[org-reveal] to show more context.
756 Instead of t, this can also be an alist specifying this option for different
757 contexts. See `org-show-hierarchy-above' for valid contexts."
758 :group
'org-reveal-location
759 :type org-context-choice
)
761 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
762 "Non-nil means show all sibling heading when revealing a location.
763 Org-mode often shows locations in an org-mode file which might have
764 been invisible before. When this is set, the sibling of the current entry
765 heading are all made visible. If `org-show-hierarchy-above' is t,
766 the same happens on each level of the hierarchy above the current entry.
768 By default this is on for the isearch context, off for all other contexts.
769 Turning this off for example for sparse trees makes them very compact,
770 but makes it harder to edit the location of the match. In such a case,
771 use the command \\[org-reveal] to show more context.
772 Instead of t, this can also be an alist specifying this option for different
773 contexts. See `org-show-hierarchy-above' for valid contexts."
774 :group
'org-reveal-location
775 :type org-context-choice
)
777 (defcustom org-show-entry-below
'((default . nil
))
778 "Non-nil means show the entry below a headline when revealing a location.
779 Org-mode often shows locations in an org-mode file which might have
780 been invisible before. When this is set, the text below the headline that is
781 exposed is also shown.
783 By default this is off for all contexts.
784 Instead of t, this can also be an alist specifying this option for different
785 contexts. See `org-show-hierarchy-above' for valid contexts."
786 :group
'org-reveal-location
787 :type org-context-choice
)
789 (defcustom org-indirect-buffer-display
'other-window
790 "How should indirect tree buffers be displayed?
791 This applies to indirect buffers created with the commands
792 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
794 current-window Display in the current window
795 other-window Just display in another window.
796 dedicated-frame Create one new frame, and re-use it each time.
797 new-frame Make a new frame each time. Note that in this case
798 previously-made indirect buffers are kept, and you need to
799 kill these buffers yourself."
800 :group
'org-structure
801 :group
'org-agenda-windows
803 (const :tag
"In current window" current-window
)
804 (const :tag
"In current frame, other window" other-window
)
805 (const :tag
"Each time a new frame" new-frame
)
806 (const :tag
"One dedicated frame" dedicated-frame
)))
808 (defcustom org-use-speed-commands nil
809 "Non-nil means activate single letter commands at beginning of a headline.
810 This may also be a function to test for appropriate locations where speed
811 commands should be active."
812 :group
'org-structure
814 (const :tag
"Never" nil
)
815 (const :tag
"At beginning of headline stars" t
)
818 (defcustom org-speed-commands-user nil
819 "Alist of additional speed commands.
820 This list will be checked before `org-speed-commands-default'
821 when the variable `org-use-speed-commands' is non-nil
822 and when the cursor is at the beginning of a headline.
823 The car if each entry is a string with a single letter, which must
824 be assigned to `self-insert-command' in the global map.
825 The cdr is either a command to be called interactively, a function
826 to be called, or a form to be evaluated.
827 An entry that is just a list with a single string will be interpreted
828 as a descriptive headline that will be added when listing the speed
829 commands in the Help buffer using the `?' speed command."
830 :group
'org-structure
831 :type
'(repeat :value
("k" . ignore
)
832 (choice :value
("k" . ignore
)
833 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
834 (cons :tag
"Letter and Command"
835 (string :tag
"Command letter")
840 (defgroup org-cycle nil
841 "Options concerning visibility cycling in Org-mode."
843 :group
'org-structure
)
845 (defcustom org-cycle-skip-children-state-if-no-children t
846 "Non-nil means skip CHILDREN state in entries that don't have any."
850 (defcustom org-cycle-max-level nil
851 "Maximum level which should still be subject to visibility cycling.
852 Levels higher than this will, for cycling, be treated as text, not a headline.
853 When `org-odd-levels-only' is set, a value of N in this variable actually
854 means 2N-1 stars as the limiting headline.
855 When nil, cycle all levels.
856 Note that the limiting level of cycling is also influenced by
857 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
858 `org-inlinetask-min-level' is, cycling will be limited to levels one less
862 (const :tag
"No limit" nil
)
863 (integer :tag
"Maximum level")))
865 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK" "RESULTS")
866 "Names of drawers. Drawers are not opened by cycling on the headline above.
867 Drawers only open with a TAB on the drawer line itself. A drawer looks like
872 The drawer \"PROPERTIES\" is special for capturing properties through
875 Drawers can be defined on the per-file basis with a line like:
877 #+DRAWERS: HIDDEN STATE PROPERTIES"
878 :group
'org-structure
880 :type
'(repeat (string :tag
"Drawer Name")))
882 (defcustom org-hide-block-startup nil
883 "Non-nil means entering Org-mode will fold all blocks.
884 This can also be set in on a per-file basis with
886 #+STARTUP: hideblocks
887 #+STARTUP: showblocks"
892 (defcustom org-cycle-global-at-bob nil
893 "Cycle globally if cursor is at beginning of buffer and not at a headline.
894 This makes it possible to do global cycling without having to use S-TAB or
895 \\[universal-argument] TAB. For this special case to work, the first line \
897 must not be a headline - it may be empty or some other text. When used in
898 this way, `org-cycle-hook' is disables temporarily, to make sure the
899 cursor stays at the beginning of the buffer.
900 When this option is nil, don't do anything special at the beginning
905 (defcustom org-cycle-level-after-item
/entry-creation t
906 "Non-nil means cycle entry level or item indentation in new empty entries.
908 When the cursor is at the end of an empty headline, i.e with only stars
909 and maybe a TODO keyword, TAB will then switch the entry to become a child,
910 and then all possible ancestor states, before returning to the original state.
911 This makes data entry extremely fast: M-RET to create a new headline,
912 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
914 When the cursor is at the end of an empty plain list item, one TAB will
915 make it a subitem, two or more tabs will back up to make this an item
916 higher up in the item hierarchy."
920 (defcustom org-cycle-emulate-tab t
921 "Where should `org-cycle' emulate TAB.
923 white Only in completely white lines
924 whitestart Only at the beginning of lines, before the first non-white char
925 t Everywhere except in headlines
926 exc-hl-bol Everywhere except at the start of a headline
927 If TAB is used in a place where it does not emulate TAB, the current subtree
928 visibility is cycled."
930 :type
'(choice (const :tag
"Never" nil
)
931 (const :tag
"Only in completely white lines" white
)
932 (const :tag
"Before first char in a line" whitestart
)
933 (const :tag
"Everywhere except in headlines" t
)
934 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
937 (defcustom org-cycle-separator-lines
2
938 "Number of empty lines needed to keep an empty line between collapsed trees.
939 If you leave an empty line between the end of a subtree and the following
940 headline, this empty line is hidden when the subtree is folded.
941 Org-mode will leave (exactly) one empty line visible if the number of
942 empty lines is equal or larger to the number given in this variable.
943 So the default 2 means at least 2 empty lines after the end of a subtree
944 are needed to produce free space between a collapsed subtree and the
947 If the number is negative, and the number of empty lines is at least -N,
948 all empty lines are shown.
950 Special case: when 0, never leave empty lines in collapsed view."
953 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
955 (defcustom org-pre-cycle-hook nil
956 "Hook that is run before visibility cycling is happening.
957 The function(s) in this hook must accept a single argument which indicates
958 the new state that will be set right after running this hook. The
959 argument is a symbol. Before a global state change, it can have the values
960 `overview', `content', or `all'. Before a local state change, it can have
961 the values `folded', `children', or `subtree'."
965 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
966 org-cycle-hide-drawers
967 org-cycle-show-empty-lines
968 org-optimize-window-after-visibility-change
)
969 "Hook that is run after `org-cycle' has changed the buffer visibility.
970 The function(s) in this hook must accept a single argument which indicates
971 the new state that was set by the most recent `org-cycle' command. The
972 argument is a symbol. After a global state change, it can have the values
973 `overview', `content', or `all'. After a local state change, it can have
974 the values `folded', `children', or `subtree'."
978 (defgroup org-edit-structure nil
979 "Options concerning structure editing in Org-mode."
980 :tag
"Org Edit Structure"
981 :group
'org-structure
)
983 (defcustom org-odd-levels-only nil
984 "Non-nil means skip even levels and only use odd levels for the outline.
985 This has the effect that two stars are being added/taken away in
986 promotion/demotion commands. It also influences how levels are
987 handled by the exporters.
988 Changing it requires restart of `font-lock-mode' to become effective
989 for fontification also in regions already fontified.
990 You may also set this on a per-file basis by adding one of the following
995 :group
'org-edit-structure
996 :group
'org-appearance
999 (defcustom org-adapt-indentation t
1000 "Non-nil means adapt indentation to outline node level.
1002 When this variable is set, Org assumes that you write outlines by
1003 indenting text in each node to align with the headline (after the stars).
1004 The following issues are influenced by this variable:
1006 - When this is set and the *entire* text in an entry is indented, the
1007 indentation is increased by one space in a demotion command, and
1008 decreased by one in a promotion command. If any line in the entry
1009 body starts with text at column 0, indentation is not changed at all.
1011 - Property drawers and planning information is inserted indented when
1012 this variable s set. When nil, they will not be indented.
1014 - TAB indents a line relative to context. The lines below a headline
1015 will be indented when this variable is set.
1017 Note that this is all about true indentation, by adding and removing
1018 space characters. See also `org-indent.el' which does level-dependent
1019 indentation in a virtual way, i.e. at display time in Emacs."
1020 :group
'org-edit-structure
1023 (defcustom org-special-ctrl-a
/e nil
1024 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
1026 When t, `C-a' will bring back the cursor to the beginning of the
1027 headline text, i.e. after the stars and after a possible TODO
1028 keyword. In an item, this will be the position after bullet and
1029 check-box, if any. When the cursor is already at that position,
1030 another `C-a' will bring it to the beginning of the line.
1032 `C-e' will jump to the end of the headline, ignoring the presence
1033 of tags in the headline. A second `C-e' will then jump to the
1034 true end of the line, after any tags. This also means that, when
1035 this variable is non-nil, `C-e' also will never jump beyond the
1036 end of the heading of a folded section, i.e. not after the
1039 When set to the symbol `reversed', the first `C-a' or `C-e' works
1040 normally, going to the true line boundary first. Only a directly
1041 following, identical keypress will bring the cursor to the
1044 This may also be a cons cell where the behavior for `C-a' and
1045 `C-e' is set separately."
1046 :group
'org-edit-structure
1048 (const :tag
"off" nil
)
1049 (const :tag
"on: after stars/bullet and before tags first" t
)
1050 (const :tag
"reversed: true line boundary first" reversed
)
1051 (cons :tag
"Set C-a and C-e separately"
1052 (choice :tag
"Special C-a"
1053 (const :tag
"off" nil
)
1054 (const :tag
"on: after stars/bullet first" t
)
1055 (const :tag
"reversed: before stars/bullet first" reversed
))
1056 (choice :tag
"Special C-e"
1057 (const :tag
"off" nil
)
1058 (const :tag
"on: before tags first" t
)
1059 (const :tag
"reversed: after tags first" reversed
)))))
1060 (if (fboundp 'defvaralias
)
1061 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
1063 (defcustom org-special-ctrl-k nil
1064 "Non-nil means `C-k' will behave specially in headlines.
1065 When nil, `C-k' will call the default `kill-line' command.
1066 When t, the following will happen while the cursor is in the headline:
1068 - When the cursor is at the beginning of a headline, kill the entire
1069 line and possible the folded subtree below the line.
1070 - When in the middle of the headline text, kill the headline up to the tags.
1071 - When after the headline text, kill the tags."
1072 :group
'org-edit-structure
1075 (defcustom org-ctrl-k-protect-subtree nil
1076 "Non-nil means, do not delete a hidden subtree with C-k.
1077 When set to the symbol `error', simply throw an error when C-k is
1078 used to kill (part-of) a headline that has hidden text behind it.
1079 Any other non-nil value will result in a query to the user, if it is
1080 OK to kill that hidden subtree. When nil, kill without remorse."
1081 :group
'org-edit-structure
1084 (const :tag
"Do not protect hidden subtrees" nil
)
1085 (const :tag
"Protect hidden subtrees with a security query" t
)
1086 (const :tag
"Never kill a hidden subtree with C-k" error
)))
1088 (defcustom org-catch-invisible-edits nil
1089 "Check if in invisible region before inserting or deleting a character.
1092 nil Do not check, so just do invisible edits.
1093 error Throw an error and do nothing.
1094 show Make point visible, and do the requested edit.
1095 show-and-error Make point visible, then throw an error and abort the edit.
1096 smart Make point visible, and do insertion/deletion if it is
1097 adjacent to visible text and the change feels predictable.
1098 Never delete a previously invisible character or add in the
1099 middle or right after an invisible region. Basically, this
1100 allows insertion and backward-delete right before ellipses.
1101 FIXME: maybe in this case we should not even show?"
1102 :group
'org-edit-structure
1105 (const :tag
"Do not check" nil
)
1106 (const :tag
"Throw error when trying to edit" error
)
1107 (const :tag
"Unhide, but do not do the edit" show-and-error
)
1108 (const :tag
"Show invisible part and do the edit" show
)
1109 (const :tag
"Be smart and do the right thing" smart
)))
1111 (defcustom org-yank-folded-subtrees t
1112 "Non-nil means when yanking subtrees, fold them.
1113 If the kill is a single subtree, or a sequence of subtrees, i.e. if
1114 it starts with a heading and all other headings in it are either children
1115 or siblings, then fold all the subtrees. However, do this only if no
1116 text after the yank would be swallowed into a folded tree by this action."
1117 :group
'org-edit-structure
1120 (defcustom org-yank-adjusted-subtrees nil
1121 "Non-nil means when yanking subtrees, adjust the level.
1122 With this setting, `org-paste-subtree' is used to insert the subtree, see
1123 this function for details."
1124 :group
'org-edit-structure
1127 (defcustom org-M-RET-may-split-line
'((default . t
))
1128 "Non-nil means M-RET will split the line at the cursor position.
1129 When nil, it will go to the end of the line before making a
1131 You may also set this option in a different way for different
1132 contexts. Valid contexts are:
1134 headline when creating a new headline
1135 item when creating a new item
1136 table in a table field
1137 default the value to be used for all contexts not explicitly
1139 :group
'org-structure
1142 (const :tag
"Always" t
)
1143 (const :tag
"Never" nil
)
1144 (repeat :greedy t
:tag
"Individual contexts"
1146 (choice :tag
"Context"
1154 (defcustom org-insert-heading-respect-content nil
1155 "Non-nil means insert new headings after the current subtree.
1156 When nil, the new heading is created directly after the current line.
1157 The commands \\[org-insert-heading-respect-content] and
1158 \\[org-insert-todo-heading-respect-content] turn this variable on
1159 for the duration of the command."
1160 :group
'org-structure
1163 (defcustom org-blank-before-new-entry
'((heading . auto
)
1164 (plain-list-item . auto
))
1165 "Should `org-insert-heading' leave a blank line before new heading/item?
1166 The value is an alist, with `heading' and `plain-list-item' as CAR,
1167 and a boolean flag as CDR. The cdr may also be the symbol `auto', in
1168 which case Org will look at the surrounding headings/items and try to
1169 make an intelligent decision whether to insert a blank line or not.
1171 For plain lists, if the variable `org-empty-line-terminates-plain-lists' is
1172 set, the setting here is ignored and no empty line is inserted, to avoid
1173 breaking the list structure."
1174 :group
'org-edit-structure
1176 (cons (const heading
)
1177 (choice (const :tag
"Never" nil
)
1178 (const :tag
"Always" t
)
1179 (const :tag
"Auto" auto
)))
1180 (cons (const plain-list-item
)
1181 (choice (const :tag
"Never" nil
)
1182 (const :tag
"Always" t
)
1183 (const :tag
"Auto" auto
)))))
1185 (defcustom org-insert-heading-hook nil
1186 "Hook being run after inserting a new heading."
1187 :group
'org-edit-structure
1190 (defcustom org-enable-fixed-width-editor t
1191 "Non-nil means lines starting with \":\" are treated as fixed-width.
1192 This currently only means they are never auto-wrapped.
1193 When nil, such lines will be treated like ordinary lines.
1194 See also the QUOTE keyword."
1195 :group
'org-edit-structure
1198 (defcustom org-goto-auto-isearch t
1199 "Non-nil means typing characters in `org-goto' starts incremental search."
1200 :group
'org-edit-structure
1203 (defgroup org-sparse-trees nil
1204 "Options concerning sparse trees in Org-mode."
1205 :tag
"Org Sparse Trees"
1206 :group
'org-structure
)
1208 (defcustom org-highlight-sparse-tree-matches t
1209 "Non-nil means highlight all matches that define a sparse tree.
1210 The highlights will automatically disappear the next time the buffer is
1211 changed by an edit command."
1212 :group
'org-sparse-trees
1215 (defcustom org-remove-highlights-with-change t
1216 "Non-nil means any change to the buffer will remove temporary highlights.
1217 Such highlights are created by `org-occur' and `org-clock-display'.
1218 When nil, `C-c C-c needs to be used to get rid of the highlights.
1219 The highlights created by `org-preview-latex-fragment' always need
1220 `C-c C-c' to be removed."
1221 :group
'org-sparse-trees
1226 (defcustom org-occur-hook
'(org-first-headline-recenter)
1227 "Hook that is run after `org-occur' has constructed a sparse tree.
1228 This can be used to recenter the window to show as much of the structure
1230 :group
'org-sparse-trees
1233 (defgroup org-imenu-and-speedbar nil
1234 "Options concerning imenu and speedbar in Org-mode."
1235 :tag
"Org Imenu and Speedbar"
1236 :group
'org-structure
)
1238 (defcustom org-imenu-depth
2
1239 "The maximum level for Imenu access to Org-mode headlines.
1240 This also applied for speedbar access."
1241 :group
'org-imenu-and-speedbar
1244 (defgroup org-table nil
1245 "Options concerning tables in Org-mode."
1249 (defcustom org-enable-table-editor
'optimized
1250 "Non-nil means lines starting with \"|\" are handled by the table editor.
1251 When nil, such lines will be treated like ordinary lines.
1253 When equal to the symbol `optimized', the table editor will be optimized to
1255 - Automatic overwrite mode in front of whitespace in table fields.
1256 This makes the structure of the table stay in tact as long as the edited
1257 field does not exceed the column width.
1258 - Minimize the number of realigns. Normally, the table is aligned each time
1259 TAB or RET are pressed to move to another field. With optimization this
1260 happens only if changes to a field might have changed the column width.
1261 Optimization requires replacing the functions `self-insert-command',
1262 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1263 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1264 very good at guessing when a re-align will be necessary, but you can always
1265 force one with \\[org-ctrl-c-ctrl-c].
1267 If you would like to use the optimized version in Org-mode, but the
1268 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1270 This variable can be used to turn on and off the table editor during a session,
1271 but in order to toggle optimization, a restart is required.
1273 See also the variable `org-table-auto-blank-field'."
1276 (const :tag
"off" nil
)
1278 (const :tag
"on, optimized" optimized
)))
1280 (defcustom org-self-insert-cluster-for-undo t
1281 "Non-nil means cluster self-insert commands for undo when possible.
1282 If this is set, then, like in the Emacs command loop, 20 consecutive
1283 characters will be undone together.
1284 This is configurable, because there is some impact on typing performance."
1288 (defcustom org-table-tab-recognizes-table.el t
1289 "Non-nil means TAB will automatically notice a table.el table.
1290 When it sees such a table, it moves point into it and - if necessary -
1291 calls `table-recognize-table'."
1292 :group
'org-table-editing
1295 (defgroup org-link nil
1296 "Options concerning links in Org-mode."
1300 (defvar org-link-abbrev-alist-local nil
1301 "Buffer-local version of `org-link-abbrev-alist', which see.
1302 The value of this is taken from the #+LINK lines.")
1303 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1305 (defcustom org-link-abbrev-alist nil
1306 "Alist of link abbreviations.
1307 The car of each element is a string, to be replaced at the start of a link.
1308 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1309 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1311 [[linkkey:tag][description]]
1313 The 'linkkey' must be a word word, starting with a letter, followed
1314 by letters, numbers, '-' or '_'.
1316 If REPLACE is a string, the tag will simply be appended to create the link.
1317 If the string contains \"%s\", the tag will be inserted there. Alternatively,
1318 the placeholder \"%h\" will cause a url-encoded version of the tag to
1319 be inserted at that point (see the function `url-hexify-string').
1321 REPLACE may also be a function that will be called with the tag as the
1322 only argument to create the link, which should be returned as a string.
1324 See the manual for examples."
1328 (string :tag
"Protocol")
1330 (string :tag
"Format")
1333 (defcustom org-descriptive-links t
1334 "Non-nil means Org will display descriptive links.
1335 E.g. [[http://orgmode.org][Org website]] will be displayed as
1336 \"Org Website\", hiding the link itself and just displaying its
1337 description. When set to `nil', Org will display the full links
1340 You can interactively set the value of this variable by calling
1341 `org-toggle-link-display' or from the menu Org>Hyperlinks menu."
1345 (defcustom org-link-file-path-type
'adaptive
1346 "How the path name in file links should be stored.
1349 relative Relative to the current directory, i.e. the directory of the file
1350 into which the link is being inserted.
1351 absolute Absolute path, if possible with ~ for home directory.
1352 noabbrev Absolute path, no abbreviation of home directory.
1353 adaptive Use relative path for files in the current directory and sub-
1354 directories of it. For other files, use an absolute path."
1362 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1363 "Types of links that should be activated in Org-mode files.
1364 This is a list of symbols, each leading to the activation of a certain link
1365 type. In principle, it does not hurt to turn on most link types - there may
1366 be a small gain when turning off unused link types. The types are:
1368 bracket The recommended [[link][description]] or [[link]] links with hiding.
1369 angle Links in angular brackets that may contain whitespace like
1370 <bbdb:Carsten Dominik>.
1371 plain Plain links in normal text, no whitespace, like http://google.com.
1372 radio Text that is matched by a radio target, see manual for details.
1373 tag Tag settings in a headline (link to tag search).
1374 date Time stamps (link to calendar).
1375 footnote Footnote labels.
1377 Changing this variable requires a restart of Emacs to become effective."
1379 :type
'(set :greedy t
1380 (const :tag
"Double bracket links" bracket
)
1381 (const :tag
"Angular bracket links" angle
)
1382 (const :tag
"Plain text links" plain
)
1383 (const :tag
"Radio target matches" radio
)
1384 (const :tag
"Tags" tag
)
1385 (const :tag
"Timestamps" date
)
1386 (const :tag
"Footnotes" footnote
)))
1388 (defcustom org-make-link-description-function nil
1389 "Function to use to generate link descriptions from links.
1390 If nil the link location will be used. This function must take
1391 two parameters; the first is the link and the second the
1392 description `org-insert-link' has generated, and should return the
1393 description to use."
1397 (defgroup org-link-store nil
1398 "Options concerning storing links in Org-mode."
1399 :tag
"Org Store Link"
1402 (defcustom org-email-link-description-format
"Email %c: %.30s"
1403 "Format of the description part of a link to an email or usenet message.
1404 The following %-escapes will be replaced by corresponding information:
1406 %F full \"From\" field
1407 %f name, taken from \"From\" field, address if no name
1408 %T full \"To\" field
1409 %t first name in \"To\" field, address if no name
1410 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1411 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1416 You may use normal field width specification between the % and the letter.
1417 This is for example useful to limit the length of the subject.
1419 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1420 :group
'org-link-store
1423 (defcustom org-from-is-user-regexp
1425 (when (and user-mail-address
(not (string= user-mail-address
"")))
1426 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1427 (when (and user-full-name
(not (string= user-full-name
"")))
1428 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1429 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1430 "Regexp matched against the \"From:\" header of an email or usenet message.
1431 It should match if the message is from the user him/herself."
1432 :group
'org-link-store
1435 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1436 "Non-nil means storing a link to an Org file will use entry IDs.
1438 Note that before this variable is even considered, org-id must be loaded,
1439 so please customize `org-modules' and turn it on.
1441 The variable can have the following values:
1443 t Create an ID if needed to make a link to the current entry.
1445 create-if-interactive
1446 If `org-store-link' is called directly (interactively, as a user
1447 command), do create an ID to support the link. But when doing the
1448 job for remember, only use the ID if it already exists. The
1449 purpose of this setting is to avoid proliferation of unwanted
1450 IDs, just because you happen to be in an Org file when you
1451 call `org-remember' that automatically and preemptively
1452 creates a link. If you do want to get an ID link in a remember
1453 template to an entry not having an ID, create it first by
1454 explicitly creating a link to it, using `C-c C-l' first.
1456 create-if-interactive-and-no-custom-id
1457 Like create-if-interactive, but do not create an ID if there is
1458 a CUSTOM_ID property defined in the entry. This is the default.
1461 Use existing ID, do not create one.
1463 nil Never use an ID to make a link, instead link using a text search for
1465 :group
'org-link-store
1467 (const :tag
"Create ID to make link" t
)
1468 (const :tag
"Create if storing link interactively"
1469 create-if-interactive
)
1470 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1471 create-if-interactive-and-no-custom-id
)
1472 (const :tag
"Only use existing" use-existing
)
1473 (const :tag
"Do not use ID to create link" nil
)))
1475 (defcustom org-context-in-file-links t
1476 "Non-nil means file links from `org-store-link' contain context.
1477 A search string will be added to the file name with :: as separator and
1478 used to find the context when the link is activated by the command
1479 `org-open-at-point'. When this option is t, the entire active region
1480 will be placed in the search string of the file link. If set to a
1481 positive integer, only the first n lines of context will be stored.
1483 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1484 negates this setting for the duration of the command."
1485 :group
'org-link-store
1486 :type
'(choice boolean integer
))
1488 (defcustom org-keep-stored-link-after-insertion nil
1489 "Non-nil means keep link in list for entire session.
1491 The command `org-store-link' adds a link pointing to the current
1492 location to an internal list. These links accumulate during a session.
1493 The command `org-insert-link' can be used to insert links into any
1494 Org-mode file (offering completion for all stored links). When this
1495 option is nil, every link which has been inserted once using \\[org-insert-link]
1496 will be removed from the list, to make completing the unused links
1498 :group
'org-link-store
1501 (defgroup org-link-follow nil
1502 "Options concerning following links in Org-mode."
1503 :tag
"Org Follow Link"
1506 (defcustom org-link-translation-function nil
1507 "Function to translate links with different syntax to Org syntax.
1508 This can be used to translate links created for example by the Planner
1509 or emacs-wiki packages to Org syntax.
1510 The function must accept two parameters, a TYPE containing the link
1511 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1512 which is everything after the link protocol. It should return a cons
1513 with possibly modified values of type and path.
1514 Org contains a function for this, so if you set this variable to
1515 `org-translate-link-from-planner', you should be able follow many
1516 links created by planner."
1517 :group
'org-link-follow
1520 (defcustom org-follow-link-hook nil
1521 "Hook that is run after a link has been followed."
1522 :group
'org-link-follow
1525 (defcustom org-tab-follows-link nil
1526 "Non-nil means on links TAB will follow the link.
1527 Needs to be set before org.el is loaded.
1528 This really should not be used, it does not make sense, and the
1529 implementation is bad."
1530 :group
'org-link-follow
1533 (defcustom org-return-follows-link nil
1534 "Non-nil means on links RET will follow the link."
1535 :group
'org-link-follow
1538 (defcustom org-mouse-1-follows-link
1539 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1540 "Non-nil means mouse-1 on a link will follow the link.
1541 A longer mouse click will still set point. Does not work on XEmacs.
1542 Needs to be set before org.el is loaded."
1543 :group
'org-link-follow
1546 (defcustom org-mark-ring-length
4
1547 "Number of different positions to be recorded in the ring.
1548 Changing this requires a restart of Emacs to work correctly."
1549 :group
'org-link-follow
1552 (defcustom org-link-search-must-match-exact-headline
'query-to-create
1553 "Non-nil means internal links in Org files must exactly match a headline.
1554 When nil, the link search tries to match a phrase with all words
1555 in the search text."
1556 :group
'org-link-follow
1559 (const :tag
"Use fuzzy text search" nil
)
1560 (const :tag
"Match only exact headline" t
)
1561 (const :tag
"Match exact headline or query to create it"
1564 (defcustom org-link-frame-setup
1565 '((vm . vm-visit-folder-other-frame
)
1566 (vm-imap . vm-visit-imap-folder-other-frame
)
1567 (gnus . org-gnus-no-new-news
)
1568 (file . find-file-other-window
)
1569 (wl . wl-other-frame
))
1570 "Setup the frame configuration for following links.
1571 When following a link with Emacs, it may often be useful to display
1572 this link in another window or frame. This variable can be used to
1573 set this up for the different types of links.
1576 `vm-visit-folder-other-window'
1577 `vm-visit-folder-other-frame'
1578 For Gnus, use any of
1581 `org-gnus-no-new-news'
1582 For FILE, use any of
1584 `find-file-other-window'
1585 `find-file-other-frame'
1586 For Wanderlust use any of
1589 For the calendar, use the variable `calendar-setup'.
1590 For BBDB, it is currently only possible to display the matches in
1592 :group
'org-link-follow
1596 (const vm-visit-folder
)
1597 (const vm-visit-folder-other-window
)
1598 (const vm-visit-folder-other-frame
)))
1602 (const gnus-other-frame
)
1603 (const org-gnus-no-new-news
)))
1607 (const find-file-other-window
)
1608 (const find-file-other-frame
)))
1612 (const wl-other-frame
)))))
1614 (defcustom org-display-internal-link-with-indirect-buffer nil
1615 "Non-nil means use indirect buffer to display infile links.
1616 Activating internal links (from one location in a file to another location
1617 in the same file) normally just jumps to the location. When the link is
1618 activated with a \\[universal-argument] prefix (or with mouse-3), the link \
1620 another window. When this option is set, the other window actually displays
1621 an indirect buffer clone of the current buffer, to avoid any visibility
1622 changes to the current buffer."
1623 :group
'org-link-follow
1626 (defcustom org-open-non-existing-files nil
1627 "Non-nil means `org-open-file' will open non-existing files.
1628 When nil, an error will be generated.
1629 This variable applies only to external applications because they
1630 might choke on non-existing files. If the link is to a file that
1631 will be opened in Emacs, the variable is ignored."
1632 :group
'org-link-follow
1635 (defcustom org-open-directory-means-index-dot-org nil
1636 "Non-nil means a link to a directory really means to index.org.
1637 When nil, following a directory link will run dired or open a finder/explorer
1638 window on that directory."
1639 :group
'org-link-follow
1642 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1643 "Function and arguments to call for following mailto links.
1644 This is a list with the first element being a Lisp function, and the
1645 remaining elements being arguments to the function. In string arguments,
1646 %a will be replaced by the address, and %s will be replaced by the subject
1647 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1648 :group
'org-link-follow
1650 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1651 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1652 (const :tag
"message-mail" (message-mail "%a" "%s"))
1653 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1655 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1656 "Non-nil means ask for confirmation before executing shell links.
1657 Shell links can be dangerous: just think about a link
1659 [[shell:rm -rf ~/*][Google Search]]
1661 This link would show up in your Org-mode document as \"Google Search\",
1662 but really it would remove your entire home directory.
1663 Therefore we advise against setting this variable to nil.
1664 Just change it to `y-or-n-p' if you want to confirm with a
1665 single keystroke rather than having to type \"yes\"."
1666 :group
'org-link-follow
1668 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1669 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1670 (const :tag
"no confirmation (dangerous)" nil
)))
1671 (put 'org-confirm-shell-link-function
1672 'safe-local-variable
1673 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1675 (defcustom org-confirm-shell-link-not-regexp
""
1676 "A regexp to skip confirmation for shell links."
1677 :group
'org-link-follow
1681 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1682 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1683 Elisp links can be dangerous: just think about a link
1685 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1687 This link would show up in your Org-mode document as \"Google Search\",
1688 but really it would remove your entire home directory.
1689 Therefore we advise against setting this variable to nil.
1690 Just change it to `y-or-n-p' if you want to confirm with a
1691 single keystroke rather than having to type \"yes\"."
1692 :group
'org-link-follow
1694 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1695 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1696 (const :tag
"no confirmation (dangerous)" nil
)))
1697 (put 'org-confirm-shell-link-function
1698 'safe-local-variable
1699 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1701 (defcustom org-confirm-elisp-link-not-regexp
""
1702 "A regexp to skip confirmation for Elisp links."
1703 :group
'org-link-follow
1707 (defconst org-file-apps-defaults-gnu
1711 "Default file applications on a UNIX or GNU/Linux system.
1712 See `org-file-apps'.")
1714 (defconst org-file-apps-defaults-macosx
1717 (system .
"open %s")
1719 ("eps.gz" .
"gv %s")
1721 ("fig" .
"xfig %s"))
1722 "Default file applications on a MacOS X system.
1723 The system \"open\" is known as a default, but we use X11 applications
1724 for some files for which the OS does not have a good default.
1725 See `org-file-apps'.")
1727 (defconst org-file-apps-defaults-windowsnt
1731 (list (if (featurep 'xemacs
)
1732 'mswindows-shell-execute
1736 (list (if (featurep 'xemacs
)
1737 'mswindows-shell-execute
1740 "Default file applications on a Windows NT system.
1741 The system \"open\" is used for most files.
1742 See `org-file-apps'.")
1744 (defcustom org-file-apps
1747 ("\\.mm\\'" . default
)
1748 ("\\.x?html?\\'" . default
)
1749 ("\\.pdf\\'" . default
)
1751 "External applications for opening `file:path' items in a document.
1752 Org-mode uses system defaults for different file types, but
1753 you can use this variable to set the application for a given file
1754 extension. The entries in this list are cons cells where the car identifies
1755 files and the cdr the corresponding command. Possible values for the
1757 \"string\" A string as a file identifier can be interpreted in different
1758 ways, depending on its contents:
1760 - Alphanumeric characters only:
1761 Match links with this file extension.
1762 Example: (\"pdf\" . \"evince %s\")
1763 to open PDFs with evince.
1765 - Regular expression: Match links where the
1766 filename matches the regexp. If you want to
1767 use groups here, use shy groups.
1769 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1770 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1771 to open *.html and *.xhtml with firefox.
1773 - Regular expression which contains (non-shy) groups:
1774 Match links where the whole link, including \"::\", and
1775 anything after that, matches the regexp.
1776 In a custom command string, %1, %2, etc. are replaced with
1777 the parts of the link that were matched by the groups.
1778 For backwards compatibility, if a command string is given
1779 that does not use any of the group matches, this case is
1780 handled identically to the second one (i.e. match against
1782 In a custom lisp form, you can access the group matches with
1783 (match-string n link).
1785 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1786 to open [[file:document.pdf::5]] with evince at page 5.
1788 `directory' Matches a directory
1789 `remote' Matches a remote file, accessible through tramp or efs.
1790 Remote files most likely should be visited through Emacs
1791 because external applications cannot handle such paths.
1792 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1793 so all files Emacs knows how to handle. Using this with
1794 command `emacs' will open most files in Emacs. Beware that this
1795 will also open html files inside Emacs, unless you add
1796 (\"html\" . default) to the list as well.
1797 t Default for files not matched by any of the other options.
1798 `system' The system command to open files, like `open' on Windows
1799 and Mac OS X, and mailcap under GNU/Linux. This is the command
1800 that will be selected if you call `C-c C-o' with a double
1801 \\[universal-argument] \\[universal-argument] prefix.
1803 Possible values for the command are:
1804 `emacs' The file will be visited by the current Emacs process.
1805 `default' Use the default application for this file type, which is the
1806 association for t in the list, most likely in the system-specific
1808 This can be used to overrule an unwanted setting in the
1809 system-specific variable.
1810 `system' Use the system command for opening files, like \"open\".
1811 This command is specified by the entry whose car is `system'.
1812 Most likely, the system-specific version of this variable
1813 does define this command, but you can overrule/replace it
1815 string A command to be executed by a shell; %s will be replaced
1816 by the path to the file.
1817 sexp A Lisp form which will be evaluated. The file path will
1818 be available in the Lisp variable `file'.
1819 For more examples, see the system specific constants
1820 `org-file-apps-defaults-macosx'
1821 `org-file-apps-defaults-windowsnt'
1822 `org-file-apps-defaults-gnu'."
1823 :group
'org-link-follow
1825 (cons (choice :value
""
1826 (string :tag
"Extension")
1827 (const :tag
"System command to open files" system
)
1828 (const :tag
"Default for unrecognized files" t
)
1829 (const :tag
"Remote file" remote
)
1830 (const :tag
"Links to a directory" directory
)
1831 (const :tag
"Any files that have Emacs modes"
1834 (const :tag
"Visit with Emacs" emacs
)
1835 (const :tag
"Use default" default
)
1836 (const :tag
"Use the system command" system
)
1837 (string :tag
"Command")
1838 (sexp :tag
"Lisp form")))))
1842 (defgroup org-refile nil
1843 "Options concerning refiling entries in Org-mode."
1847 (defcustom org-directory
"~/org"
1848 "Directory with org files.
1849 This is just a default location to look for Org files. There is no need
1850 at all to put your files into this directory. It is only used in the
1851 following situations:
1853 1. When a remember template specifies a target file that is not an
1854 absolute path. The path will then be interpreted relative to
1856 2. When a remember note is filed away in an interactive way (when exiting the
1857 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1858 with `org-directory' as the default path."
1860 :group
'org-remember
1863 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1864 "Default target for storing notes.
1865 Used as a fall back file for org-remember.el and org-capture.el, for
1866 templates that do not specify a target file."
1868 :group
'org-remember
1870 (const :tag
"Default from remember-data-file" nil
)
1873 (defcustom org-goto-interface
'outline
1874 "The default interface to be used for `org-goto'.
1876 outline The interface shows an outline of the relevant file
1877 and the correct heading is found by moving through
1878 the outline or by searching with incremental search.
1879 outline-path-completion Headlines in the current buffer are offered via
1880 completion. This is the interface also used by
1881 the refile command."
1884 (const :tag
"Outline" outline
)
1885 (const :tag
"Outline-path-completion" outline-path-completion
)))
1887 (defcustom org-goto-max-level
5
1888 "Maximum target level when running `org-goto' with refile interface."
1892 (defcustom org-reverse-note-order nil
1893 "Non-nil means store new notes at the beginning of a file or entry.
1894 When nil, new notes will be filed to the end of a file or entry.
1895 This can also be a list with cons cells of regular expressions that
1896 are matched against file names, and values."
1897 :group
'org-remember
1900 (const :tag
"Reverse always" t
)
1901 (const :tag
"Reverse never" nil
)
1902 (repeat :tag
"By file name regexp"
1903 (cons regexp boolean
))))
1905 (defcustom org-log-refile nil
1906 "Information to record when a task is refiled.
1908 Possible values are:
1910 nil Don't add anything
1911 time Add a time stamp to the task
1912 note Prompt for a note and add it with template `org-log-note-headings'
1914 This option can also be set with on a per-file-basis with
1916 #+STARTUP: nologrefile
1917 #+STARTUP: logrefile
1918 #+STARTUP: lognoterefile
1920 You can have local logging settings for a subtree by setting the LOGGING
1921 property to one or more of these keywords.
1923 When bulk-refiling from the agenda, the value `note' is forbidden and
1924 will temporarily be changed to `time'."
1926 :group
'org-progress
1929 (const :tag
"No logging" nil
)
1930 (const :tag
"Record timestamp" time
)
1931 (const :tag
"Record timestamp with note." note
)))
1933 (defcustom org-refile-targets nil
1934 "Targets for refiling entries with \\[org-refile].
1935 This is a list of cons cells. Each cell contains:
1936 - a specification of the files to be considered, either a list of files,
1937 or a symbol whose function or variable value will be used to retrieve
1938 a file name or a list of file names. If you use `org-agenda-files' for
1939 that, all agenda files will be scanned for targets. Nil means consider
1940 headings in the current buffer.
1941 - A specification of how to find candidate refile targets. This may be
1943 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1944 This tag has to be present in all target headlines, inheritance will
1946 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1948 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1949 headlines that are refiling targets.
1950 - a cons cell (:level . N). Any headline of level N is considered a target.
1951 Note that, when `org-odd-levels-only' is set, level corresponds to
1952 order in hierarchy, not to the number of stars.
1953 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1954 Note that, when `org-odd-levels-only' is set, level corresponds to
1955 order in hierarchy, not to the number of stars.
1957 Each element of this list generates a set of possible targets.
1958 The union of these sets is presented (with completion) to
1959 the user by `org-refile'.
1961 You can set the variable `org-refile-target-verify-function' to a function
1962 to verify each headline found by the simple criteria above.
1964 When this variable is nil, all top-level headlines in the current buffer
1965 are used, equivalent to the value `((nil . (:level . 1))'."
1969 (choice :value org-agenda-files
1970 (const :tag
"All agenda files" org-agenda-files
)
1971 (const :tag
"Current buffer" nil
)
1972 (function) (variable) (file))
1973 (choice :tag
"Identify target headline by"
1974 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1975 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1976 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1977 (cons :tag
"Level number" (const :value
:level
) (integer))
1978 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
1980 (defcustom org-refile-target-verify-function nil
1981 "Function to verify if the headline at point should be a refile target.
1982 The function will be called without arguments, with point at the
1983 beginning of the headline. It should return t and leave point
1984 where it is if the headline is a valid target for refiling.
1986 If the target should not be selected, the function must return nil.
1987 In addition to this, it may move point to a place from where the search
1988 should be continued. For example, the function may decide that the entire
1989 subtree of the current entry should be excluded and move point to the end
1994 (defcustom org-refile-use-cache nil
1995 "Non-nil means cache refile targets to speed up the process.
1996 The cache for a particular file will be updated automatically when
1997 the buffer has been killed, or when any of the marker used for flagging
1998 refile targets no longer points at a live buffer.
1999 If you have added new entries to a buffer that might themselves be targets,
2000 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
2001 find that easier, `C-u C-u C-u C-c C-w'."
2006 (defcustom org-refile-use-outline-path nil
2007 "Non-nil means provide refile targets as paths.
2008 So a level 3 headline will be available as level1/level2/level3.
2010 When the value is `file', also include the file name (without directory)
2011 into the path. In this case, you can also stop the completion after
2012 the file name, to get entries inserted as top level in the file.
2014 When `full-file-path', include the full file path."
2017 (const :tag
"Not" nil
)
2018 (const :tag
"Yes" t
)
2019 (const :tag
"Start with file name" file
)
2020 (const :tag
"Start with full file path" full-file-path
)))
2022 (defcustom org-outline-path-complete-in-steps t
2023 "Non-nil means complete the outline path in hierarchical steps.
2024 When Org-mode uses the refile interface to select an outline path
2025 \(see variable `org-refile-use-outline-path'), the completion of
2026 the path can be done is a single go, or if can be done in steps down
2027 the headline hierarchy. Going in steps is probably the best if you
2028 do not use a special completion package like `ido' or `icicles'.
2029 However, when using these packages, going in one step can be very
2030 fast, while still showing the whole path to the entry."
2034 (defcustom org-refile-allow-creating-parent-nodes nil
2035 "Non-nil means allow to create new nodes as refile targets.
2036 New nodes are then created by adding \"/new node name\" to the completion
2037 of an existing node. When the value of this variable is `confirm',
2038 new node creation must be confirmed by the user (recommended)
2039 When nil, the completion must match an existing entry.
2041 Note that, if the new heading is not seen by the criteria
2042 listed in `org-refile-targets', multiple instances of the same
2043 heading would be created by trying again to file under the new
2047 (const :tag
"Never" nil
)
2048 (const :tag
"Always" t
)
2049 (const :tag
"Prompt for confirmation" confirm
)))
2051 (defcustom org-refile-active-region-within-subtree nil
2052 "Non-nil means also refile active region within a subtree.
2054 By default `org-refile' doesn't allow refiling regions if they
2055 don't contain a set of subtrees, but it might be convenient to
2056 do so sometimes: in that case, the first line of the region is
2057 converted to a headline before refiling."
2062 (defgroup org-todo nil
2063 "Options concerning TODO items in Org-mode."
2067 (defgroup org-progress nil
2068 "Options concerning Progress logging in Org-mode."
2072 (defvar org-todo-interpretation-widgets
2073 '((:tag
"Sequence (cycling hits every state)" sequence
)
2074 (:tag
"Type (cycling directly to DONE)" type
))
2075 "The available interpretation symbols for customizing `org-todo-keywords'.
2076 Interested libraries should add to this list.")
2078 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
2079 "List of TODO entry keyword sequences and their interpretation.
2080 \\<org-mode-map>This is a list of sequences.
2082 Each sequence starts with a symbol, either `sequence' or `type',
2083 indicating if the keywords should be interpreted as a sequence of
2084 action steps, or as different types of TODO items. The first
2085 keywords are states requiring action - these states will select a headline
2086 for inclusion into the global TODO list Org-mode produces. If one of
2087 the \"keywords\" is the vertical bar, \"|\", the remaining keywords
2088 signify that no further action is necessary. If \"|\" is not found,
2089 the last keyword is treated as the only DONE state of the sequence.
2091 The command \\[org-todo] cycles an entry through these states, and one
2092 additional state where no keyword is present. For details about this
2093 cycling, see the manual.
2095 TODO keywords and interpretation can also be set on a per-file basis with
2096 the special #+SEQ_TODO and #+TYP_TODO lines.
2098 Each keyword can optionally specify a character for fast state selection
2099 \(in combination with the variable `org-use-fast-todo-selection')
2100 and specifiers for state change logging, using the same syntax
2101 that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says
2102 that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
2103 indicates to record a time stamp each time this state is selected.
2105 Each keyword may also specify if a timestamp or a note should be
2106 recorded when entering or leaving the state, by adding additional
2107 characters in the parenthesis after the keyword. This looks like this:
2108 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
2109 record only the time of the state change. With X and Y being either
2110 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
2111 Y when leaving the state if and only if the *target* state does not
2112 define X. You may omit any of the fast-selection key or X or /Y,
2113 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
2115 For backward compatibility, this variable may also be just a list
2116 of keywords - in this case the interpretation (sequence or type) will be
2117 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
2119 :group
'org-keywords
2121 (repeat :tag
"Old syntax, just keywords"
2122 (string :tag
"Keyword"))
2123 (repeat :tag
"New syntax"
2126 :tag
"Interpretation"
2127 ;;Quick and dirty way to see
2128 ;;`org-todo-interpretations'. This takes the
2129 ;;place of item arguments
2137 org-todo-interpretation-widgets
))
2140 (string :tag
"Keyword"))))))
2142 (defvar org-todo-keywords-1 nil
2143 "All TODO and DONE keywords active in a buffer.")
2144 (make-variable-buffer-local 'org-todo-keywords-1
)
2145 (defvar org-todo-keywords-for-agenda nil
)
2146 (defvar org-done-keywords-for-agenda nil
)
2147 (defvar org-drawers-for-agenda nil
)
2148 (defvar org-todo-keyword-alist-for-agenda nil
)
2149 (defvar org-tag-alist-for-agenda nil
)
2150 (defvar org-agenda-contributing-files nil
)
2151 (defvar org-not-done-keywords nil
)
2152 (make-variable-buffer-local 'org-not-done-keywords
)
2153 (defvar org-done-keywords nil
)
2154 (make-variable-buffer-local 'org-done-keywords
)
2155 (defvar org-todo-heads nil
)
2156 (make-variable-buffer-local 'org-todo-heads
)
2157 (defvar org-todo-sets nil
)
2158 (make-variable-buffer-local 'org-todo-sets
)
2159 (defvar org-todo-log-states nil
)
2160 (make-variable-buffer-local 'org-todo-log-states
)
2161 (defvar org-todo-kwd-alist nil
)
2162 (make-variable-buffer-local 'org-todo-kwd-alist
)
2163 (defvar org-todo-key-alist nil
)
2164 (make-variable-buffer-local 'org-todo-key-alist
)
2165 (defvar org-todo-key-trigger nil
)
2166 (make-variable-buffer-local 'org-todo-key-trigger
)
2168 (defcustom org-todo-interpretation
'sequence
2169 "Controls how TODO keywords are interpreted.
2170 This variable is in principle obsolete and is only used for
2171 backward compatibility, if the interpretation of todo keywords is
2172 not given already in `org-todo-keywords'. See that variable for
2175 :group
'org-keywords
2176 :type
'(choice (const sequence
)
2179 (defcustom org-use-fast-todo-selection t
2180 "Non-nil means use the fast todo selection scheme with C-c C-t.
2181 This variable describes if and under what circumstances the cycling
2182 mechanism for TODO keywords will be replaced by a single-key, direct
2185 When nil, fast selection is never used.
2187 When the symbol `prefix', it will be used when `org-todo' is called with
2188 a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t'
2189 in an agenda buffer.
2191 When t, fast selection is used by default. In this case, the prefix
2192 argument forces cycling instead.
2194 In all cases, the special interface is only used if access keys have actually
2195 been assigned by the user, i.e. if keywords in the configuration are followed
2196 by a letter in parenthesis, like TODO(t)."
2199 (const :tag
"Never" nil
)
2200 (const :tag
"By default" t
)
2201 (const :tag
"Only with C-u C-c C-t" prefix
)))
2203 (defcustom org-provide-todo-statistics t
2204 "Non-nil means update todo statistics after insert and toggle.
2205 ALL-HEADLINES means update todo statistics by including headlines
2206 with no TODO keyword as well, counting them as not done.
2207 A list of TODO keywords means the same, but skip keywords that are
2210 When this is set, todo statistics is updated in the parent of the
2211 current entry each time a todo state is changed."
2214 (const :tag
"Yes, only for TODO entries" t
)
2215 (const :tag
"Yes, including all entries" 'all-headlines
)
2216 (repeat :tag
"Yes, for TODOs in this list"
2217 (string :tag
"TODO keyword"))
2218 (other :tag
"No TODO statistics" nil
)))
2220 (defcustom org-hierarchical-todo-statistics t
2221 "Non-nil means TODO statistics covers just direct children.
2222 When nil, all entries in the subtree are considered.
2223 This has only an effect if `org-provide-todo-statistics' is set.
2224 To set this to nil for only a single subtree, use a COOKIE_DATA
2225 property and include the word \"recursive\" into the value."
2229 (defcustom org-after-todo-state-change-hook nil
2230 "Hook which is run after the state of a TODO item was changed.
2231 The new state (a string with a TODO keyword, or nil) is available in the
2232 Lisp variable `state'."
2236 (defvar org-blocker-hook nil
2237 "Hook for functions that are allowed to block a state change.
2239 Each function gets as its single argument a property list, see
2240 `org-trigger-hook' for more information about this list.
2242 If any of the functions in this hook returns nil, the state change
2245 (defvar org-trigger-hook nil
2246 "Hook for functions that are triggered by a state change.
2248 Each function gets as its single argument a property list with at least
2249 the following elements:
2251 (:type type-of-change :position pos-at-entry-start
2252 :from old-state :to new-state)
2254 Depending on the type, more properties may be present.
2256 This mechanism is currently implemented for:
2260 :type todo-state-change
2261 :from previous state (keyword as a string), or nil, or a symbol
2262 'todo' or 'done', to indicate the general type of state.
2263 :to new state, like in :from")
2265 (defcustom org-enforce-todo-dependencies nil
2266 "Non-nil means undone TODO entries will block switching the parent to DONE.
2267 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2268 be blocked if any prior sibling is not yet done.
2269 Finally, if the parent is blocked because of ordered siblings of its own,
2270 the child will also be blocked.
2271 This variable needs to be set before org.el is loaded, and you need to
2272 restart Emacs after a change to make the change effective. The only way
2273 to change is while Emacs is running is through the customize interface."
2274 :set
(lambda (var val
)
2277 (add-hook 'org-blocker-hook
2278 'org-block-todo-from-children-or-siblings-or-parent
)
2279 (remove-hook 'org-blocker-hook
2280 'org-block-todo-from-children-or-siblings-or-parent
)))
2284 (defcustom org-enforce-todo-checkbox-dependencies nil
2285 "Non-nil means unchecked boxes will block switching the parent to DONE.
2286 When this is nil, checkboxes have no influence on switching TODO states.
2287 When non-nil, you first need to check off all check boxes before the TODO
2288 entry can be switched to DONE.
2289 This variable needs to be set before org.el is loaded, and you need to
2290 restart Emacs after a change to make the change effective. The only way
2291 to change is while Emacs is running is through the customize interface."
2292 :set
(lambda (var val
)
2295 (add-hook 'org-blocker-hook
2296 'org-block-todo-from-checkboxes
)
2297 (remove-hook 'org-blocker-hook
2298 'org-block-todo-from-checkboxes
)))
2302 (defcustom org-treat-insert-todo-heading-as-state-change nil
2303 "Non-nil means inserting a TODO heading is treated as state change.
2304 So when the command \\[org-insert-todo-heading] is used, state change
2305 logging will apply if appropriate. When nil, the new TODO item will
2306 be inserted directly, and no logging will take place."
2310 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2311 "Non-nil means switching TODO states with S-cursor counts as state change.
2312 This is the default behavior. However, setting this to nil allows a
2313 convenient way to select a TODO state and bypass any logging associated
2318 (defcustom org-todo-state-tags-triggers nil
2319 "Tag changes that should be triggered by TODO state changes.
2320 This is a list. Each entry is
2322 (state-change (tag . flag) .......)
2324 State-change can be a string with a state, and empty string to indicate the
2325 state that has no TODO keyword, or it can be one of the symbols `todo'
2326 or `done', meaning any not-done or done state, respectively."
2330 (cons (choice :tag
"When changing to"
2331 (const :tag
"Not-done state" todo
)
2332 (const :tag
"Done state" done
)
2333 (string :tag
"State"))
2335 (cons :tag
"Tag action"
2337 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2339 (defcustom org-log-done nil
2340 "Information to record when a task moves to the DONE state.
2342 Possible values are:
2344 nil Don't add anything, just change the keyword
2345 time Add a time stamp to the task
2346 note Prompt for a note and add it with template `org-log-note-headings'
2348 This option can also be set with on a per-file-basis with
2350 #+STARTUP: nologdone
2352 #+STARTUP: lognotedone
2354 You can have local logging settings for a subtree by setting the LOGGING
2355 property to one or more of these keywords."
2357 :group
'org-progress
2359 (const :tag
"No logging" nil
)
2360 (const :tag
"Record CLOSED timestamp" time
)
2361 (const :tag
"Record CLOSED timestamp with note." note
)))
2363 ;; Normalize old uses of org-log-done.
2365 ((eq org-log-done t
) (setq org-log-done
'time
))
2366 ((and (listp org-log-done
) (memq 'done org-log-done
))
2367 (setq org-log-done
'note
)))
2369 (defcustom org-log-reschedule nil
2370 "Information to record when the scheduling date of a tasks is modified.
2372 Possible values are:
2374 nil Don't add anything, just change the date
2375 time Add a time stamp to the task
2376 note Prompt for a note and add it with template `org-log-note-headings'
2378 This option can also be set with on a per-file-basis with
2380 #+STARTUP: nologreschedule
2381 #+STARTUP: logreschedule
2382 #+STARTUP: lognotereschedule"
2384 :group
'org-progress
2386 (const :tag
"No logging" nil
)
2387 (const :tag
"Record timestamp" time
)
2388 (const :tag
"Record timestamp with note." note
)))
2390 (defcustom org-log-redeadline nil
2391 "Information to record when the deadline date of a tasks is modified.
2393 Possible values are:
2395 nil Don't add anything, just change the date
2396 time Add a time stamp to the task
2397 note Prompt for a note and add it with template `org-log-note-headings'
2399 This option can also be set with on a per-file-basis with
2401 #+STARTUP: nologredeadline
2402 #+STARTUP: logredeadline
2403 #+STARTUP: lognoteredeadline
2405 You can have local logging settings for a subtree by setting the LOGGING
2406 property to one or more of these keywords."
2408 :group
'org-progress
2410 (const :tag
"No logging" nil
)
2411 (const :tag
"Record timestamp" time
)
2412 (const :tag
"Record timestamp with note." note
)))
2414 (defcustom org-log-note-clock-out nil
2415 "Non-nil means record a note when clocking out of an item.
2416 This can also be configured on a per-file basis by adding one of
2417 the following lines anywhere in the buffer:
2419 #+STARTUP: lognoteclock-out
2420 #+STARTUP: nolognoteclock-out"
2422 :group
'org-progress
2425 (defcustom org-log-done-with-time t
2426 "Non-nil means the CLOSED time stamp will contain date and time.
2427 When nil, only the date will be recorded."
2428 :group
'org-progress
2431 (defcustom org-log-note-headings
2432 '((done .
"CLOSING NOTE %t")
2433 (state .
"State %-12s from %-12S %t")
2434 (note .
"Note taken on %t")
2435 (reschedule .
"Rescheduled from %S on %t")
2436 (delschedule .
"Not scheduled, was %S on %t")
2437 (redeadline .
"New deadline from %S on %t")
2438 (deldeadline .
"Removed deadline, was %S on %t")
2439 (refile .
"Refiled on %t")
2441 "Headings for notes added to entries.
2442 The value is an alist, with the car being a symbol indicating the note
2443 context, and the cdr is the heading to be used. The heading may also be the
2445 %t in the heading will be replaced by a time stamp.
2446 %T will be an active time stamp instead the default inactive one
2447 %d will be replaced by a short-format time stamp.
2448 %D will be replaced by an active short-format time stamp.
2449 %s will be replaced by the new TODO state, in double quotes.
2450 %S will be replaced by the old TODO state, in double quotes.
2451 %u will be replaced by the user name.
2452 %U will be replaced by the full user name.
2454 In fact, it is not a good idea to change the `state' entry, because
2455 agenda log mode depends on the format of these entries."
2457 :group
'org-progress
2458 :type
'(list :greedy t
2459 (cons (const :tag
"Heading when closing an item" done
) string
)
2461 "Heading when changing todo state (todo sequence only)"
2463 (cons (const :tag
"Heading when just taking a note" note
) string
)
2464 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2465 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2466 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2467 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2468 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2469 (cons (const :tag
"Heading when refiling" refile
) string
)))
2471 (unless (assq 'note org-log-note-headings
)
2472 (push '(note .
"%t") org-log-note-headings
))
2474 (defcustom org-log-into-drawer nil
2475 "Non-nil means insert state change notes and time stamps into a drawer.
2476 When nil, state changes notes will be inserted after the headline and
2477 any scheduling and clock lines, but not inside a drawer.
2479 The value of this variable should be the name of the drawer to use.
2480 LOGBOOK is proposed as the default drawer for this purpose, you can
2481 also set this to a string to define the drawer of your choice.
2483 A value of t is also allowed, representing \"LOGBOOK\".
2485 If this variable is set, `org-log-state-notes-insert-after-drawers'
2488 You can set the property LOG_INTO_DRAWER to overrule this setting for
2491 :group
'org-progress
2493 (const :tag
"Not into a drawer" nil
)
2494 (const :tag
"LOGBOOK" t
)
2495 (string :tag
"Other")))
2497 (if (fboundp 'defvaralias
)
2498 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2500 (defun org-log-into-drawer ()
2501 "Return the value of `org-log-into-drawer', but let properties overrule.
2502 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2503 used instead of the default value."
2504 (let ((p (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
)))
2506 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2507 ((equal p
"t") "LOGBOOK")
2510 (defcustom org-log-state-notes-insert-after-drawers nil
2511 "Non-nil means insert state change notes after any drawers in entry.
2512 Only the drawers that *immediately* follow the headline and the
2513 deadline/scheduled line are skipped.
2514 When nil, insert notes right after the heading and perhaps the line
2515 with deadline/scheduling if present.
2517 This variable will have no effect if `org-log-into-drawer' is
2520 :group
'org-progress
2523 (defcustom org-log-states-order-reversed t
2524 "Non-nil means the latest state note will be directly after heading.
2525 When nil, the state change notes will be ordered according to time."
2527 :group
'org-progress
2530 (defcustom org-todo-repeat-to-state nil
2531 "The TODO state to which a repeater should return the repeating task.
2532 By default this is the first task in a TODO sequence, or the previous state
2533 in a TODO_TYP set. But you can specify another task here.
2534 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2537 :type
'(choice (const :tag
"Head of sequence" nil
)
2538 (string :tag
"Specific state")))
2540 (defcustom org-log-repeat
'time
2541 "Non-nil means record moving through the DONE state when triggering repeat.
2542 An auto-repeating task is immediately switched back to TODO when
2543 marked DONE. If you are not logging state changes (by adding \"@\"
2544 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2545 record a closing note, there will be no record of the task moving
2546 through DONE. This variable forces taking a note anyway.
2548 nil Don't force a record
2549 time Record a time stamp
2552 This option can also be set with on a per-file-basis with
2554 #+STARTUP: logrepeat
2555 #+STARTUP: lognoterepeat
2556 #+STARTUP: nologrepeat
2558 You can have local logging settings for a subtree by setting the LOGGING
2559 property to one or more of these keywords."
2561 :group
'org-progress
2563 (const :tag
"Don't force a record" nil
)
2564 (const :tag
"Force recording the DONE state" time
)
2565 (const :tag
"Force recording a note with the DONE state" note
)))
2568 (defgroup org-priorities nil
2569 "Priorities in Org-mode."
2570 :tag
"Org Priorities"
2573 (defcustom org-enable-priority-commands t
2574 "Non-nil means priority commands are active.
2575 When nil, these commands will be disabled, so that you never accidentally
2577 :group
'org-priorities
2580 (defcustom org-highest-priority ?A
2581 "The highest priority of TODO items. A character like ?A, ?B etc.
2582 Must have a smaller ASCII number than `org-lowest-priority'."
2583 :group
'org-priorities
2586 (defcustom org-lowest-priority ?C
2587 "The lowest priority of TODO items. A character like ?A, ?B etc.
2588 Must have a larger ASCII number than `org-highest-priority'."
2589 :group
'org-priorities
2592 (defcustom org-default-priority ?B
2593 "The default priority of TODO items.
2594 This is the priority an item gets if no explicit priority is given.
2595 When starting to cycle on an empty priority the first step in the cycle
2596 depends on `org-priority-start-cycle-with-default'. The resulting first
2597 step priority must not exceed the range from `org-highest-priority' to
2598 `org-lowest-priority' which means that `org-default-priority' has to be
2599 in this range exclusive or inclusive the range boundaries. Else the
2600 first step refuses to set the default and the second will fall back
2601 to (depending on the command used) the highest or lowest priority."
2602 :group
'org-priorities
2605 (defcustom org-priority-start-cycle-with-default t
2606 "Non-nil means start with default priority when starting to cycle.
2607 When this is nil, the first step in the cycle will be (depending on the
2608 command used) one higher or lower than the default priority.
2609 See also `org-default-priority'."
2610 :group
'org-priorities
2613 (defcustom org-get-priority-function nil
2614 "Function to extract the priority from a string.
2615 The string is normally the headline. If this is nil Org computes the
2616 priority from the priority cookie like [#A] in the headline. It returns
2617 an integer, increasing by 1000 for each priority level.
2618 The user can set a different function here, which should take a string
2619 as an argument and return the numeric priority."
2620 :group
'org-priorities
2624 (defgroup org-time nil
2625 "Options concerning time stamps and deadlines in Org-mode."
2629 (defcustom org-insert-labeled-timestamps-at-point nil
2630 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2631 When nil, these labeled time stamps are forces into the second line of an
2632 entry, just after the headline. When scheduling from the global TODO list,
2633 the time stamp will always be forced into the second line."
2637 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2638 "Formats for `format-time-string' which are used for time stamps.
2639 It is not recommended to change this constant.")
2641 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2642 "Number of minutes to round time stamps to.
2643 These are two values, the first applies when first creating a time stamp.
2644 The second applies when changing it with the commands `S-up' and `S-down'.
2645 When changing the time stamp, this means that it will change in steps
2646 of N minutes, as given by the second value.
2648 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2649 numbers should be factors of 60, so for example 5, 10, 15.
2651 When this is larger than 1, you can still force an exact time stamp by using
2652 a double prefix argument to a time stamp command like `C-c .' or `C-c !',
2653 and by using a prefix arg to `S-up/down' to specify the exact number
2654 of minutes to shift."
2656 :get
#'(lambda (var) ; Make sure both elements are there
2657 (if (integerp (default-value var
))
2658 (list (default-value var
) 5)
2659 (default-value var
)))
2661 (integer :tag
"when inserting times")
2662 (integer :tag
"when modifying times")))
2664 ;; Normalize old customizations of this variable.
2665 (when (integerp org-time-stamp-rounding-minutes
)
2666 (setq org-time-stamp-rounding-minutes
2667 (list org-time-stamp-rounding-minutes
2668 org-time-stamp-rounding-minutes
)))
2670 (defcustom org-display-custom-times nil
2671 "Non-nil means overlay custom formats over all time stamps.
2672 The formats are defined through the variable `org-time-stamp-custom-formats'.
2673 To turn this on on a per-file basis, insert anywhere in the file:
2674 #+STARTUP: customtime"
2678 (make-variable-buffer-local 'org-display-custom-times
)
2680 (defcustom org-time-stamp-custom-formats
2681 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2682 "Custom formats for time stamps. See `format-time-string' for the syntax.
2683 These are overlaid over the default ISO format if the variable
2684 `org-display-custom-times' is set. Time like %H:%M should be at the
2685 end of the second format. The custom formats are also honored by export
2686 commands, if custom time display is turned on at the time of export."
2690 (defun org-time-stamp-format (&optional long inactive
)
2691 "Get the right format for a time string."
2692 (let ((f (if long
(cdr org-time-stamp-formats
)
2693 (car org-time-stamp-formats
))))
2695 (concat "[" (substring f
1 -
1) "]")
2698 (defcustom org-time-clocksum-format
"%d:%02d"
2699 "The format string used when creating CLOCKSUM lines.
2700 This is also used when org-mode generates a time duration."
2704 (defcustom org-time-clocksum-use-fractional nil
2705 "If non-nil, \\[org-clock-display] uses fractional times.
2706 org-mode generates a time duration."
2710 (defcustom org-time-clocksum-fractional-format
"%.2f"
2711 "The format string used when creating CLOCKSUM lines, or when
2712 org-mode generates a time duration."
2716 (defcustom org-deadline-warning-days
14
2717 "No. of days before expiration during which a deadline becomes active.
2718 This variable governs the display in sparse trees and in the agenda.
2719 When 0 or negative, it means use this number (the absolute value of it)
2720 even if a deadline has a different individual lead time specified.
2722 Custom commands can set this variable in the options section."
2724 :group
'org-agenda-daily
/weekly
2727 (defcustom org-read-date-prefer-future t
2728 "Non-nil means assume future for incomplete date input from user.
2729 This affects the following situations:
2730 1. The user gives a month but not a year.
2731 For example, if it is April and you enter \"feb 2\", this will be read
2732 as Feb 2, *next* year. \"May 5\", however, will be this year.
2733 2. The user gives a day, but no month.
2734 For example, if today is the 15th, and you enter \"3\", Org-mode will
2735 read this as the third of *next* month. However, if you enter \"17\",
2736 it will be considered as *this* month.
2738 If you set this variable to the symbol `time', then also the following
2741 3. If the user gives a time, but no day. If the time is before now,
2742 to will be interpreted as tomorrow.
2744 Currently none of this works for ISO week specifications.
2746 When this option is nil, the current day, month and year will always be
2749 See also `org-agenda-jump-prefer-future'."
2752 (const :tag
"Never" nil
)
2753 (const :tag
"Check month and day" t
)
2754 (const :tag
"Check month, day, and time" time
)))
2756 (defcustom org-agenda-jump-prefer-future
'org-read-date-prefer-future
2757 "Should the agenda jump command prefer the future for incomplete dates?
2758 The default is to do the same as configured in `org-read-date-prefer-future'.
2759 But you can also set a deviating value here.
2760 This may t or nil, or the symbol `org-read-date-prefer-future'."
2765 (const :tag
"Use org-read-date-prefer-future"
2766 org-read-date-prefer-future
)
2767 (const :tag
"Never" nil
)
2768 (const :tag
"Always" t
)))
2770 (defcustom org-read-date-force-compatible-dates t
2771 "Should date/time prompt force dates that are guaranteed to work in Emacs?
2773 Depending on the system Emacs is running on, certain dates cannot
2774 be represented with the type used internally to represent time.
2775 Dates between 1970-1-1 and 2038-1-1 can always be represented
2776 correctly. Some systems allow for earlier dates, some for later,
2777 some for both. One way to find out it to insert any date into an
2778 Org buffer, putting the cursor on the year and hitting S-up and
2779 S-down to test the range.
2781 When this variable is set to t, the date/time prompt will not let
2782 you specify dates outside the 1970-2037 range, so it is certain that
2783 these dates will work in whatever version of Emacs you are
2784 running, and also that you can move a file from one Emacs implementation
2785 to another. WHenever Org is forcing the year for you, it will display
2788 When this variable is nil, Org will check if the date is
2789 representable in the specific Emacs implementation you are using.
2790 If not, it will force a year, usually the current year, and beep
2791 to remind you. Currently this setting is not recommended because
2792 the likelihood that you will open your Org files in an Emacs that
2793 has limited date range is not negligible.
2795 A workaround for this problem is to use diary sexp dates for time
2796 stamps outside of this range."
2801 (defcustom org-read-date-display-live t
2802 "Non-nil means display current interpretation of date prompt live.
2803 This display will be in an overlay, in the minibuffer."
2807 (defcustom org-read-date-popup-calendar t
2808 "Non-nil means pop up a calendar when prompting for a date.
2809 In the calendar, the date can be selected with mouse-1. However, the
2810 minibuffer will also be active, and you can simply enter the date as well.
2811 When nil, only the minibuffer will be available."
2814 (if (fboundp 'defvaralias
)
2815 (defvaralias 'org-popup-calendar-for-date-prompt
2816 'org-read-date-popup-calendar
))
2818 (defcustom org-read-date-minibuffer-setup-hook nil
2819 "Hook to be used to set up keys for the date/time interface.
2820 Add key definitions to `minibuffer-local-map', which will be a temporary
2825 (defcustom org-extend-today-until
0
2826 "The hour when your day really ends. Must be an integer.
2827 This has influence for the following applications:
2828 - When switching the agenda to \"today\". It it is still earlier than
2829 the time given here, the day recognized as TODAY is actually yesterday.
2830 - When a date is read from the user and it is still before the time given
2831 here, the current date and time will be assumed to be yesterday, 23:59.
2832 Also, timestamps inserted in remember templates follow this rule.
2834 IMPORTANT: This is a feature whose implementation is and likely will
2835 remain incomplete. Really, it is only here because past midnight seems to
2836 be the favorite working time of John Wiegley :-)"
2840 (defcustom org-use-effective-time nil
2841 "If non-nil, consider `org-extend-today-until' when creating timestamps.
2842 For example, if `org-extend-today-until' is 8, and it's 4am, then the
2843 \"effective time\" of any timestamps between midnight and 8am will be
2844 23:59 of the previous day."
2849 (defcustom org-edit-timestamp-down-means-later nil
2850 "Non-nil means S-down will increase the time in a time stamp.
2851 When nil, S-up will increase."
2855 (defcustom org-calendar-follow-timestamp-change t
2856 "Non-nil means make the calendar window follow timestamp changes.
2857 When a timestamp is modified and the calendar window is visible, it will be
2858 moved to the new date."
2862 (defgroup org-tags nil
2863 "Options concerning tags in Org-mode."
2867 (defcustom org-tag-alist nil
2868 "List of tags allowed in Org-mode files.
2869 When this list is nil, Org-mode will base TAG input on what is already in the
2871 The value of this variable is an alist, the car of each entry must be a
2872 keyword as a string, the cdr may be a character that is used to select
2873 that tag through the fast-tag-selection interface.
2874 See the manual for details."
2878 (cons (string :tag
"Tag name")
2879 (character :tag
"Access char"))
2880 (list :tag
"Start radio group"
2882 (option (string :tag
"Group description")))
2883 (list :tag
"End radio group"
2885 (option (string :tag
"Group description")))
2886 (const :tag
"New line" (:newline
)))))
2888 (defcustom org-tag-persistent-alist nil
2889 "List of tags that will always appear in all Org-mode files.
2890 This is in addition to any in buffer settings or customizations
2892 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2893 The value of this variable is an alist, the car of each entry must be a
2894 keyword as a string, the cdr may be a character that is used to select
2895 that tag through the fast-tag-selection interface.
2896 See the manual for details.
2897 To disable these tags on a per-file basis, insert anywhere in the file:
2902 (cons (string :tag
"Tag name")
2903 (character :tag
"Access char"))
2904 (const :tag
"Start radio group" (:startgroup
))
2905 (const :tag
"End radio group" (:endgroup
))
2906 (const :tag
"New line" (:newline
)))))
2908 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2909 "If non-nil, always offer completion for all tags of all agenda files.
2910 Instead of customizing this variable directly, you might want to
2911 set it locally for capture buffers, because there no list of
2912 tags in that file can be created dynamically (there are none).
2914 (add-hook 'org-capture-mode-hook
2916 (set (make-local-variable
2917 'org-complete-tags-always-offer-all-agenda-tags)
2923 (defvar org-file-tags nil
2924 "List of tags that can be inherited by all entries in the file.
2925 The tags will be inherited if the variable `org-use-tag-inheritance'
2926 says they should be.
2927 This variable is populated from #+FILETAGS lines.")
2929 (defcustom org-use-fast-tag-selection
'auto
2930 "Non-nil means use fast tag selection scheme.
2931 This is a special interface to select and deselect tags with single keys.
2932 When nil, fast selection is never used.
2933 When the symbol `auto', fast selection is used if and only if selection
2934 characters for tags have been configured, either through the variable
2935 `org-tag-alist' or through a #+TAGS line in the buffer.
2936 When t, fast selection is always used and selection keys are assigned
2937 automatically if necessary."
2940 (const :tag
"Always" t
)
2941 (const :tag
"Never" nil
)
2942 (const :tag
"When selection characters are configured" 'auto
)))
2944 (defcustom org-fast-tag-selection-single-key nil
2945 "Non-nil means fast tag selection exits after first change.
2946 When nil, you have to press RET to exit it.
2947 During fast tag selection, you can toggle this flag with `C-c'.
2948 This variable can also have the value `expert'. In this case, the window
2949 displaying the tags menu is not even shown, until you press C-c again."
2952 (const :tag
"No" nil
)
2953 (const :tag
"Yes" t
)
2954 (const :tag
"Expert" expert
)))
2956 (defvar org-fast-tag-selection-include-todo nil
2957 "Non-nil means fast tags selection interface will also offer TODO states.
2958 This is an undocumented feature, you should not rely on it.")
2960 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2961 "The column to which tags should be indented in a headline.
2962 If this number is positive, it specifies the column. If it is negative,
2963 it means that the tags should be flushright to that column. For example,
2964 -80 works well for a normal 80 character screen.
2965 When 0, place tags directly after headline text, with only one space in
2970 (defcustom org-auto-align-tags t
2971 "Non-nil keeps tags aligned when modifying headlines.
2972 Some operations (i.e. demoting) change the length of a headline and
2973 therefore shift the tags around. With this option turned on, after
2974 each such operation the tags are again aligned to `org-tags-column'."
2978 (defcustom org-use-tag-inheritance t
2979 "Non-nil means tags in levels apply also for sublevels.
2980 When nil, only the tags directly given in a specific line apply there.
2981 This may also be a list of tags that should be inherited, or a regexp that
2982 matches tags that should be inherited. Additional control is possible
2983 with the variable `org-tags-exclude-from-inheritance' which gives an
2984 explicit list of tags to be excluded from inheritance., even if the value of
2985 `org-use-tag-inheritance' would select it for inheritance.
2987 If this option is t, a match early-on in a tree can lead to a large
2988 number of matches in the subtree when constructing the agenda or creating
2989 a sparse tree. If you only want to see the first match in a tree during
2990 a search, check out the variable `org-tags-match-list-sublevels'."
2993 (const :tag
"Not" nil
)
2994 (const :tag
"Always" t
)
2995 (repeat :tag
"Specific tags" (string :tag
"Tag"))
2996 (regexp :tag
"Tags matched by regexp")))
2998 (defcustom org-tags-exclude-from-inheritance nil
2999 "List of tags that should never be inherited.
3000 This is a way to exclude a few tags from inheritance. For way to do
3001 the opposite, to actively allow inheritance for selected tags,
3002 see the variable `org-use-tag-inheritance'."
3004 :type
'(repeat (string :tag
"Tag")))
3006 (defun org-tag-inherit-p (tag)
3007 "Check if TAG is one that should be inherited."
3009 ((member tag org-tags-exclude-from-inheritance
) nil
)
3010 ((eq org-use-tag-inheritance t
) t
)
3011 ((not org-use-tag-inheritance
) nil
)
3012 ((stringp org-use-tag-inheritance
)
3013 (string-match org-use-tag-inheritance tag
))
3014 ((listp org-use-tag-inheritance
)
3015 (member tag org-use-tag-inheritance
))
3016 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
3018 (defcustom org-tags-match-list-sublevels t
3019 "Non-nil means list also sublevels of headlines matching a search.
3020 This variable applies to tags/property searches, and also to stuck
3021 projects because this search is based on a tags match as well.
3023 When set to the symbol `indented', sublevels are indented with
3026 Because of tag inheritance (see variable `org-use-tag-inheritance'),
3027 the sublevels of a headline matching a tag search often also match
3028 the same search. Listing all of them can create very long lists.
3029 Setting this variable to nil causes subtrees of a match to be skipped.
3031 This variable is semi-obsolete and probably should always be true. It
3032 is better to limit inheritance to certain tags using the variables
3033 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
3036 (const :tag
"No, don't list them" nil
)
3037 (const :tag
"Yes, do list them" t
)
3038 (const :tag
"List them, indented with leading dots" indented
)))
3040 (defcustom org-tags-sort-function nil
3041 "When set, tags are sorted using this function as a comparator."
3044 (const :tag
"No sorting" nil
)
3045 (const :tag
"Alphabetical" string
<)
3046 (const :tag
"Reverse alphabetical" string
>)
3047 (function :tag
"Custom function" nil
)))
3049 (defvar org-tags-history nil
3050 "History of minibuffer reads for tags.")
3051 (defvar org-last-tags-completion-table nil
3052 "The last used completion table for tags.")
3053 (defvar org-after-tags-change-hook nil
3054 "Hook that is run after the tags in a line have changed.")
3056 (defgroup org-properties nil
3057 "Options concerning properties in Org-mode."
3058 :tag
"Org Properties"
3061 (defcustom org-property-format
"%-10s %s"
3062 "How property key/value pairs should be formatted by `indent-line'.
3063 When `indent-line' hits a property definition, it will format the line
3064 according to this format, mainly to make sure that the values are
3065 lined-up with respect to each other."
3066 :group
'org-properties
3069 (defcustom org-properties-postprocess-alist nil
3070 "Alist of properties and functions to adjust inserted values.
3071 Elements of this alist must be of the form
3073 ([string] [function])
3075 where [string] must be a property name and [function] must be a
3076 lambda expression: this lambda expression must take one argument,
3077 the value to adjust, and return the new value as a string.
3079 For example, this element will allow the property \"Remaining\"
3080 to be updated wrt the relation between the \"Effort\" property
3081 and the clock summary:
3083 ((\"Remaining\" (lambda(value)
3084 (let ((clocksum (org-clock-sum-current-item))
3085 (effort (org-duration-string-to-minutes
3086 (org-entry-get (point) \"Effort\"))))
3087 (org-minutes-to-hh:mm-string (- effort clocksum))))))"
3088 :group
'org-properties
3092 (defcustom org-use-property-inheritance nil
3093 "Non-nil means properties apply also for sublevels.
3095 This setting is chiefly used during property searches. Turning it on can
3096 cause significant overhead when doing a search, which is why it is not
3099 When nil, only the properties directly given in the current entry count.
3100 When t, every property is inherited. The value may also be a list of
3101 properties that should have inheritance, or a regular expression matching
3102 properties that should be inherited.
3104 However, note that some special properties use inheritance under special
3105 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
3106 and the properties ending in \"_ALL\" when they are used as descriptor
3107 for valid values of a property.
3109 Note for programmers:
3110 When querying an entry with `org-entry-get', you can control if inheritance
3111 should be used. By default, `org-entry-get' looks only at the local
3112 properties. You can request inheritance by setting the inherit argument
3113 to t (to force inheritance) or to `selective' (to respect the setting
3115 :group
'org-properties
3117 (const :tag
"Not" nil
)
3118 (const :tag
"Always" t
)
3119 (repeat :tag
"Specific properties" (string :tag
"Property"))
3120 (regexp :tag
"Properties matched by regexp")))
3122 (defun org-property-inherit-p (property)
3123 "Check if PROPERTY is one that should be inherited."
3125 ((eq org-use-property-inheritance t
) t
)
3126 ((not org-use-property-inheritance
) nil
)
3127 ((stringp org-use-property-inheritance
)
3128 (string-match org-use-property-inheritance property
))
3129 ((listp org-use-property-inheritance
)
3130 (member property org-use-property-inheritance
))
3131 (t (error "Invalid setting of `org-use-property-inheritance'"))))
3133 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
3134 "The default column format, if no other format has been defined.
3135 This variable can be set on the per-file basis by inserting a line
3137 #+COLUMNS: %25ITEM ....."
3138 :group
'org-properties
3141 (defcustom org-columns-ellipses
".."
3142 "The ellipses to be used when a field in column view is truncated.
3143 When this is the empty string, as many characters as possible are shown,
3144 but then there will be no visual indication that the field has been truncated.
3145 When this is a string of length N, the last N characters of a truncated
3146 field are replaced by this string. If the column is narrower than the
3147 ellipses string, only part of the ellipses string will be shown."
3148 :group
'org-properties
3151 (defcustom org-columns-modify-value-for-display-function nil
3152 "Function that modifies values for display in column view.
3153 For example, it can be used to cut out a certain part from a time stamp.
3154 The function must take 2 arguments:
3156 column-title The title of the column (*not* the property name)
3157 value The value that should be modified.
3159 The function should return the value that should be displayed,
3160 or nil if the normal value should be used."
3161 :group
'org-properties
3164 (defcustom org-effort-property
"Effort"
3165 "The property that is being used to keep track of effort estimates.
3166 Effort estimates given in this property need to have the format H:MM."
3167 :group
'org-properties
3168 :group
'org-progress
3169 :type
'(string :tag
"Property"))
3171 (defconst org-global-properties-fixed
3172 '(("VISIBILITY_ALL" .
"folded children content all")
3173 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
3174 "List of property/value pairs that can be inherited by any entry.
3176 These are fixed values, for the preset properties. The user variable
3177 that can be used to add to this list is `org-global-properties'.
3179 The entries in this list are cons cells where the car is a property
3180 name and cdr is a string with the value. If the value represents
3181 multiple items like an \"_ALL\" property, separate the items by
3184 (defcustom org-global-properties nil
3185 "List of property/value pairs that can be inherited by any entry.
3187 This list will be combined with the constant `org-global-properties-fixed'.
3189 The entries in this list are cons cells where the car is a property
3190 name and cdr is a string with the value.
3192 You can set buffer-local values for the same purpose in the variable
3193 `org-file-properties' this by adding lines like
3195 #+PROPERTY: NAME VALUE"
3196 :group
'org-properties
3198 (cons (string :tag
"Property")
3199 (string :tag
"Value"))))
3201 (defvar org-file-properties nil
3202 "List of property/value pairs that can be inherited by any entry.
3203 Valid for the current buffer.
3204 This variable is populated from #+PROPERTY lines.")
3205 (make-variable-buffer-local 'org-file-properties
)
3207 (defgroup org-agenda nil
3208 "Options concerning agenda views in Org-mode."
3212 (defvar org-category nil
3213 "Variable used by org files to set a category for agenda display.
3214 Such files should use a file variable to set it, for example
3216 # -*- mode: org; org-category: \"ELisp\"
3218 or contain a special line
3222 If the file does not specify a category, then file's base name
3224 (make-variable-buffer-local 'org-category
)
3225 (put 'org-category
'safe-local-variable
#'(lambda (x) (or (symbolp x
) (stringp x
))))
3227 (defcustom org-agenda-files nil
3228 "The files to be used for agenda display.
3229 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
3230 \\[org-remove-file]. You can also use customize to edit the list.
3232 If an entry is a directory, all files in that directory that are matched by
3233 `org-agenda-file-regexp' will be part of the file list.
3235 If the value of the variable is not a list but a single file name, then
3236 the list of agenda files is actually stored and maintained in that file, one
3237 agenda file per line. In this file paths can be given relative to
3238 `org-directory'. Tilde expansion and environment variable substitution
3242 (repeat :tag
"List of files and directories" file
)
3243 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
3245 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
3246 "Regular expression to match files for `org-agenda-files'.
3247 If any element in the list in that variable contains a directory instead
3248 of a normal file, all files in that directory that are matched by this
3249 regular expression will be included."
3253 (defcustom org-agenda-text-search-extra-files nil
3254 "List of extra files to be searched by text search commands.
3255 These files will be search in addition to the agenda files by the
3256 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
3257 Note that these files will only be searched for text search commands,
3258 not for the other agenda views like todo lists, tag searches or the weekly
3259 agenda. This variable is intended to list notes and possibly archive files
3260 that should also be searched by these two commands.
3261 In fact, if the first element in the list is the symbol `agenda-archives',
3262 than all archive files of all agenda files will be added to the search
3265 :type
'(set :greedy t
3266 (const :tag
"Agenda Archives" agenda-archives
)
3267 (repeat :inline t
(file))))
3269 (if (fboundp 'defvaralias
)
3270 (defvaralias 'org-agenda-multi-occur-extra-files
3271 'org-agenda-text-search-extra-files
))
3273 (defcustom org-agenda-skip-unavailable-files nil
3274 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
3275 A nil value means to remove them, after a query, from the list."
3279 (defcustom org-calendar-to-agenda-key
[?c
]
3280 "The key to be installed in `calendar-mode-map' for switching to the agenda.
3281 The command `org-calendar-goto-agenda' will be bound to this key. The
3282 default is the character `c' because then `c' can be used to switch back and
3283 forth between agenda and calendar."
3287 (defcustom org-calendar-agenda-action-key
[?k
]
3288 "The key to be installed in `calendar-mode-map' for agenda-action.
3289 The command `org-agenda-action' will be bound to this key. The
3290 default is the character `k' because we use the same key in the agenda."
3294 (defcustom org-calendar-insert-diary-entry-key
[?i
]
3295 "The key to be installed in `calendar-mode-map' for adding diary entries.
3296 This option is irrelevant until `org-agenda-diary-file' has been configured
3297 to point to an Org-mode file. When that is the case, the command
3298 `org-agenda-diary-entry' will be bound to the key given here, by default
3299 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
3300 if you want to continue doing this, you need to change this to a different
3305 (defcustom org-agenda-diary-file
'diary-file
3306 "File to which to add new entries with the `i' key in agenda and calendar.
3307 When this is the symbol `diary-file', the functionality in the Emacs
3308 calendar will be used to add entries to the `diary-file'. But when this
3309 points to a file, `org-agenda-diary-entry' will be used instead."
3312 (const :tag
"The standard Emacs diary file" diary-file
)
3313 (file :tag
"Special Org file diary entries")))
3315 (eval-after-load "calendar"
3317 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3318 'org-calendar-goto-agenda
)
3319 (org-defkey calendar-mode-map org-calendar-agenda-action-key
3321 (add-hook 'calendar-mode-hook
3323 (unless (eq org-agenda-diary-file
'diary-file
)
3324 (define-key calendar-mode-map
3325 org-calendar-insert-diary-entry-key
3326 'org-agenda-diary-entry
))))))
3328 (defgroup org-latex nil
3329 "Options for embedding LaTeX code into Org-mode."
3333 (defcustom org-format-latex-options
3334 '(:foreground default
:background default
:scale
1.0
3335 :html-foreground
"Black" :html-background
"Transparent"
3336 :html-scale
1.0 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3337 "Options for creating images from LaTeX fragments.
3338 This is a property list with the following properties:
3339 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3340 `default' means use the foreground of the default face.
3341 :background the background color, or \"Transparent\".
3342 `default' means use the background of the default face.
3343 :scale a scaling factor for the size of the images, to get more pixels
3344 :html-foreground, :html-background, :html-scale
3345 the same numbers for HTML export.
3346 :matchers a list indicating which matchers should be used to
3347 find LaTeX fragments. Valid members of this list are:
3348 \"begin\" find environments
3349 \"$1\" find single characters surrounded by $.$
3350 \"$\" find math expressions surrounded by $...$
3351 \"$$\" find math expressions surrounded by $$....$$
3352 \"\\(\" find math expressions surrounded by \\(...\\)
3353 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3357 (defcustom org-format-latex-signal-error t
3358 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3359 When nil, just push out a message."
3364 (defcustom org-latex-to-mathml-jar-file nil
3365 "Value of\"%j\" in `org-latex-to-mathml-convert-command'.
3366 Use this to specify additional executable file say a jar file.
3368 When using MathToWeb as the converter, specify the full-path to
3369 your mathtoweb.jar file."
3373 (const :tag
"None" nil
)
3374 (file :tag
"JAR file" :must-match t
)))
3376 (defcustom org-latex-to-mathml-convert-command nil
3377 "Command to convert LaTeX fragments to MathML.
3378 Replace format-specifiers in the command as noted below and use
3379 `shell-command' to convert LaTeX to MathML.
3380 %j: Executable file in fully expanded form as specified by
3381 `org-latex-to-mathml-jar-file'.
3382 %I: Input LaTeX file in fully expanded form
3383 %o: Output MathML file
3384 This command is used by `org-create-math-formula'.
3386 When using MathToWeb as the converter, set this to
3387 \"java -jar %j -unicode -force -df %o %I\"."
3391 (const :tag
"None" nil
)
3392 (string :tag
"\nShell command")))
3394 (defun org-format-latex-mathml-available-p ()
3395 "Return t if `org-latex-to-mathml-convert-command' is usable."
3397 (when (and (boundp 'org-latex-to-mathml-convert-command
)
3398 org-latex-to-mathml-convert-command
)
3399 (let ((executable (car (split-string
3400 org-latex-to-mathml-convert-command
))))
3401 (when (executable-find executable
)
3403 "%j" org-latex-to-mathml-convert-command
)
3404 (file-readable-p org-latex-to-mathml-jar-file
)
3407 (defcustom org-format-latex-header
"\\documentclass{article}
3408 \\usepackage[usenames]{color}
3409 \\usepackage{amsmath}
3410 \\usepackage[mathscr]{eucal}
3411 \\pagestyle{empty} % do not remove
3414 % The settings below are copied from fullpage.sty
3415 \\setlength{\\textwidth}{\\paperwidth}
3416 \\addtolength{\\textwidth}{-3cm}
3417 \\setlength{\\oddsidemargin}{1.5cm}
3418 \\addtolength{\\oddsidemargin}{-2.54cm}
3419 \\setlength{\\evensidemargin}{\\oddsidemargin}
3420 \\setlength{\\textheight}{\\paperheight}
3421 \\addtolength{\\textheight}{-\\headheight}
3422 \\addtolength{\\textheight}{-\\headsep}
3423 \\addtolength{\\textheight}{-\\footskip}
3424 \\addtolength{\\textheight}{-3cm}
3425 \\setlength{\\topmargin}{1.5cm}
3426 \\addtolength{\\topmargin}{-2.54cm}"
3427 "The document header used for processing LaTeX fragments.
3428 It is imperative that this header make sure that no page number
3429 appears on the page. The package defined in the variables
3430 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
3431 will either replace the placeholder \"[PACKAGES]\" in this header, or they
3436 (defvar org-format-latex-header-extra nil
)
3438 (defun org-set-packages-alist (var val
)
3439 "Set the packages alist and make sure it has 3 elements per entry."
3440 (set var
(mapcar (lambda (x)
3441 (if (and (consp x
) (= (length x
) 2))
3442 (list (car x
) (nth 1 x
) t
)
3446 (defun org-get-packages-alist (var)
3448 "Get the packages alist and make sure it has 3 elements per entry."
3450 (if (and (consp x
) (= (length x
) 2))
3451 (list (car x
) (nth 1 x
) t
)
3453 (default-value var
)))
3455 ;; The following variables are defined here because is it also used
3456 ;; when formatting latex fragments. Originally it was part of the
3457 ;; LaTeX exporter, which is why the name includes "export".
3458 (defcustom org-export-latex-default-packages-alist
3459 '(("AUTO" "inputenc" t
)
3463 ("" "longtable" nil
)
3475 "Alist of default packages to be inserted in the header.
3476 Change this only if one of the packages here causes an incompatibility
3477 with another package you are using.
3478 The packages in this list are needed by one part or another of Org-mode
3479 to function properly.
3481 - inputenc, fontenc: for basic font and character selection
3482 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3483 for interpreting the entities in `org-entities'. You can skip some of these
3484 packages if you don't use any of the symbols in it.
3485 - graphicx: for including images
3486 - float, wrapfig: for figure placement
3487 - longtable: for long tables
3488 - hyperref: for cross references
3490 Therefore you should not modify this variable unless you know what you
3491 are doing. The one reason to change it anyway is that you might be loading
3492 some other package that conflicts with one of the default packages.
3493 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3494 If SNIPPET-FLAG is t, the package also needs to be included when
3495 compiling LaTeX snippets into images for inclusion into HTML."
3496 :group
'org-export-latex
3497 :set
'org-set-packages-alist
3498 :get
'org-get-packages-alist
3502 (list :tag
"options/package pair"
3503 (string :tag
"options")
3504 (string :tag
"package")
3505 (boolean :tag
"Snippet"))
3506 (string :tag
"A line of LaTeX"))))
3508 (defcustom org-export-latex-packages-alist nil
3509 "Alist of packages to be inserted in every LaTeX header.
3510 These will be inserted after `org-export-latex-default-packages-alist'.
3511 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3512 SNIPPET-FLAG, when t, indicates that this package is also needed when
3513 turning LaTeX snippets into images for inclusion into HTML.
3514 Make sure that you only list packages here which:
3515 - you want in every file
3516 - do not conflict with the default packages in
3517 `org-export-latex-default-packages-alist'
3518 - do not conflict with the setup in `org-format-latex-header'."
3519 :group
'org-export-latex
3520 :set
'org-set-packages-alist
3521 :get
'org-get-packages-alist
3524 (list :tag
"options/package pair"
3525 (string :tag
"options")
3526 (string :tag
"package")
3527 (boolean :tag
"Snippet"))
3528 (string :tag
"A line of LaTeX"))))
3531 (defgroup org-appearance nil
3532 "Settings for Org-mode appearance."
3533 :tag
"Org Appearance"
3536 (defcustom org-level-color-stars-only nil
3537 "Non-nil means fontify only the stars in each headline.
3538 When nil, the entire headline is fontified.
3539 Changing it requires restart of `font-lock-mode' to become effective
3540 also in regions already fontified."
3541 :group
'org-appearance
3544 (defcustom org-hide-leading-stars nil
3545 "Non-nil means hide the first N-1 stars in a headline.
3546 This works by using the face `org-hide' for these stars. This
3547 face is white for a light background, and black for a dark
3548 background. You may have to customize the face `org-hide' to
3550 Changing it requires restart of `font-lock-mode' to become effective
3551 also in regions already fontified.
3552 You may also set this on a per-file basis by adding one of the following
3553 lines to the buffer:
3555 #+STARTUP: hidestars
3556 #+STARTUP: showstars"
3557 :group
'org-appearance
3560 (defcustom org-hidden-keywords nil
3561 "List of symbols corresponding to keywords to be hidden the org buffer.
3562 For example, a value '(title) for this list will make the document's title
3563 appear in the buffer without the initial #+TITLE: keyword."
3564 :group
'org-appearance
3566 :type
'(set (const :tag
"#+AUTHOR" author
)
3567 (const :tag
"#+DATE" date
)
3568 (const :tag
"#+EMAIL" email
)
3569 (const :tag
"#+TITLE" title
)))
3571 (defcustom org-fontify-done-headline nil
3572 "Non-nil means change the face of a headline if it is marked DONE.
3573 Normally, only the TODO/DONE keyword indicates the state of a headline.
3574 When this is non-nil, the headline after the keyword is set to the
3575 `org-headline-done' as an additional indication."
3576 :group
'org-appearance
3579 (defcustom org-fontify-emphasized-text t
3580 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3581 Changing this variable requires a restart of Emacs to take effect."
3582 :group
'org-appearance
3585 (defcustom org-fontify-whole-heading-line nil
3586 "Non-nil means fontify the whole line for headings.
3587 This is useful when setting a background color for the
3589 :group
'org-appearance
3592 (defcustom org-highlight-latex-fragments-and-specials nil
3593 "Non-nil means fontify what is treated specially by the exporters."
3594 :group
'org-appearance
3597 (defcustom org-hide-emphasis-markers nil
3598 "Non-nil mean font-lock should hide the emphasis marker characters."
3599 :group
'org-appearance
3602 (defcustom org-pretty-entities nil
3603 "Non-nil means show entities as UTF8 characters.
3604 When nil, the \\name form remains in the buffer."
3605 :group
'org-appearance
3609 (defcustom org-pretty-entities-include-sub-superscripts t
3610 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3611 :group
'org-appearance
3615 (defvar org-emph-re nil
3616 "Regular expression for matching emphasis.
3617 After a match, the match groups contain these elements:
3618 0 The match of the full regular expression, including the characters
3619 before and after the proper match
3620 1 The character before the proper match, or empty at beginning of line
3621 2 The proper match, including the leading and trailing markers
3622 3 The leading marker like * or /, indicating the type of highlighting
3623 4 The text between the emphasis markers, not including the markers
3624 5 The character after the match, empty at the end of a line")
3625 (defvar org-verbatim-re nil
3626 "Regular expression for matching verbatim text.")
3627 (defvar org-emphasis-regexp-components
) ; defined just below
3628 (defvar org-emphasis-alist
) ; defined just below
3629 (defun org-set-emph-re (var val
)
3630 "Set variable and compute the emphasis regular expression."
3632 (when (and (boundp 'org-emphasis-alist
)
3633 (boundp 'org-emphasis-regexp-components
)
3634 org-emphasis-alist org-emphasis-regexp-components
)
3635 (let* ((e org-emphasis-regexp-components
)
3641 (body1 (concat body
"*?"))
3642 (markers (mapconcat 'car org-emphasis-alist
""))
3643 (vmarkers (mapconcat
3644 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3645 org-emphasis-alist
"")))
3646 ;; make sure special characters appear at the right position in the class
3647 (if (string-match "\\^" markers
)
3648 (setq markers
(concat (replace-match "" t t markers
) "^")))
3649 (if (string-match "-" markers
)
3650 (setq markers
(concat (replace-match "" t t markers
) "-")))
3651 (if (string-match "\\^" vmarkers
)
3652 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3653 (if (string-match "-" vmarkers
)
3654 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3656 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3657 (int-to-string nl
) "\\}")))
3660 (concat "\\([" pre
"]\\|^\\)"
3662 "\\([" markers
"]\\)"
3670 "\\([" post
"]\\|$\\)"))
3671 (setq org-verbatim-re
3672 (concat "\\([" pre
"]\\|^\\)"
3674 "\\([" vmarkers
"]\\)"
3682 "\\([" post
"]\\|$\\)")))))
3684 (defcustom org-emphasis-regexp-components
3685 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3686 "Components used to build the regular expression for emphasis.
3687 This is a list with five entries. Terminology: In an emphasis string
3688 like \" *strong word* \", we call the initial space PREMATCH, the final
3689 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3690 and \"trong wor\" is the body. The different components in this variable
3691 specify what is allowed/forbidden in each part:
3693 pre Chars allowed as prematch. Beginning of line will be allowed too.
3694 post Chars allowed as postmatch. End of line will be allowed too.
3695 border The chars *forbidden* as border characters.
3696 body-regexp A regexp like \".\" to match a body character. Don't use
3697 non-shy groups here, and don't allow newline here.
3698 newline The maximum number of newlines allowed in an emphasis exp.
3700 Use customize to modify this, or restart Emacs after changing it."
3701 :group
'org-appearance
3702 :set
'org-set-emph-re
3704 (sexp :tag
"Allowed chars in pre ")
3705 (sexp :tag
"Allowed chars in post ")
3706 (sexp :tag
"Forbidden chars in border ")
3707 (sexp :tag
"Regexp for body ")
3708 (integer :tag
"number of newlines allowed")
3709 (option (boolean :tag
"Please ignore this button"))))
3711 (defcustom org-emphasis-alist
3712 `(("*" bold
"<b>" "</b>")
3713 ("/" italic
"<i>" "</i>")
3714 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3715 ("=" org-code
"<code>" "</code>" verbatim
)
3716 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3717 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3720 "Special syntax for emphasized text.
3721 Text starting and ending with a special character will be emphasized, for
3722 example *bold*, _underlined_ and /italic/. This variable sets the marker
3723 characters, the face to be used by font-lock for highlighting in Org-mode
3724 Emacs buffers, and the HTML tags to be used for this.
3725 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3726 For DocBook export, see the variable `org-export-docbook-emphasis-alist'.
3727 Use customize to modify this, or restart Emacs after changing it."
3728 :group
'org-appearance
3729 :set
'org-set-emph-re
3732 (string :tag
"Marker character")
3734 (face :tag
"Font-lock-face")
3735 (plist :tag
"Face property list"))
3736 (string :tag
"HTML start tag")
3737 (string :tag
"HTML end tag")
3738 (option (const verbatim
)))))
3740 (defvar org-protecting-blocks
3741 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3742 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3743 This is needed for font-lock setup.")
3745 ;;; Miscellaneous options
3747 (defgroup org-completion nil
3748 "Completion in Org-mode."
3749 :tag
"Org Completion"
3752 (defcustom org-completion-use-ido nil
3753 "Non-nil means use ido completion wherever possible.
3754 Note that `ido-mode' must be active for this variable to be relevant.
3755 If you decide to turn this variable on, you might well want to turn off
3756 `org-outline-path-complete-in-steps'.
3757 See also `org-completion-use-iswitchb'."
3758 :group
'org-completion
3761 (defcustom org-completion-use-iswitchb nil
3762 "Non-nil means use iswitchb completion wherever possible.
3763 Note that `iswitchb-mode' must be active for this variable to be relevant.
3764 If you decide to turn this variable on, you might well want to turn off
3765 `org-outline-path-complete-in-steps'.
3766 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3767 :group
'org-completion
3770 (defcustom org-completion-fallback-command
'hippie-expand
3771 "The expansion command called by \\[pcomplete] in normal context.
3772 Normal means, no org-mode-specific context."
3773 :group
'org-completion
3776 ;;; Functions and variables from their packages
3777 ;; Declared here to avoid compiler warnings
3780 (defvar outline-mode-menu-heading
)
3781 (defvar outline-mode-menu-show
)
3782 (defvar outline-mode-menu-hide
)
3783 (defvar zmacs-regions
) ; XEmacs regions
3786 (defvar mark-active
)
3789 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3790 (declare-function calendar-forward-day
"cal-move" (arg))
3791 (declare-function calendar-goto-date
"cal-move" (date))
3792 (declare-function calendar-goto-today
"cal-move" ())
3793 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3794 (defvar calc-embedded-close-formula
)
3795 (defvar calc-embedded-open-formula
)
3796 (declare-function cdlatex-tab
"ext:cdlatex" ())
3797 (declare-function cdlatex-compute-tables
"ext:cdlatex" ())
3798 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3799 (defvar font-lock-unfontify-region-function
)
3800 (declare-function iswitchb-read-buffer
"iswitchb"
3801 (prompt &optional default require-match start matches-set
))
3802 (defvar iswitchb-temp-buflist
)
3803 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3804 (defvar org-agenda-tags-todo-honor-ignore-options
)
3805 (declare-function org-agenda-skip
"org-agenda" ())
3807 org-agenda-format-item
"org-agenda"
3808 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3809 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3810 (declare-function org-agenda-change-all-lines
"org-agenda"
3811 (newhead hdmarker
&optional fixface just-this
))
3812 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3813 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3814 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3816 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3817 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3818 "org-agenda" (&optional end
))
3819 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3820 (declare-function org-inlinetask-in-task-p
"org-inlinetask" ())
3821 (declare-function org-inlinetask-goto-beginning
"org-inlinetask" ())
3822 (declare-function org-inlinetask-goto-end
"org-inlinetask" ())
3823 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3824 (declare-function parse-time-string
"parse-time" (string))
3825 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3826 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3827 (declare-function orgtbl-send-table
"org-table" (&optional maybe
))
3828 (defvar remember-data-file
)
3829 (defvar texmathp-why
)
3830 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3831 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3833 (defvar w3m-current-url
)
3834 (defvar w3m-current-title
)
3836 (defvar org-latex-regexps
)
3838 ;;; Autoload and prepare some org modules
3840 ;; Some table stuff that needs to be defined here, because it is used
3841 ;; by the functions setting up org-mode or checking for table context.
3843 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3844 "Detect an org-type or table-type table.")
3845 (defconst org-table-line-regexp
"^[ \t]*|"
3846 "Detect an org-type table line.")
3847 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3848 "Detect an org-type table line.")
3849 (defconst org-table-hline-regexp
"^[ \t]*|-"
3850 "Detect an org-type table hline.")
3851 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3852 "Detect a table-type table hline.")
3853 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3854 "Detect the first line outside a table when searching from within it.
3855 This works for both table types.")
3857 ;; Autoload the functions in org-table.el that are needed by functions here.
3860 (org-autoload "org-table"
3861 '(org-table-align org-table-begin org-table-blank-field
3862 org-table-convert org-table-convert-region org-table-copy-down
3863 org-table-copy-region org-table-create
3864 org-table-create-or-convert-from-region
3865 org-table-create-with-table.el org-table-current-dline
3866 org-table-cut-region org-table-delete-column org-table-edit-field
3867 org-table-edit-formulas org-table-end org-table-eval-formula
3868 org-table-export org-table-field-info
3869 org-table-get-stored-formulas org-table-goto-column
3870 org-table-hline-and-move org-table-import org-table-insert-column
3871 org-table-insert-hline org-table-insert-row org-table-iterate
3872 org-table-justify-field-maybe org-table-kill-row
3873 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3874 org-table-move-column org-table-move-column-left
3875 org-table-move-column-right org-table-move-row
3876 org-table-move-row-down org-table-move-row-up
3877 org-table-next-field org-table-next-row org-table-paste-rectangle
3878 org-table-previous-field org-table-recalculate
3879 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3880 org-table-toggle-coordinate-overlays
3881 org-table-toggle-formula-debugger org-table-wrap-region
3882 orgtbl-mode turn-on-orgtbl org-table-to-lisp
3883 orgtbl-to-generic orgtbl-to-tsv orgtbl-to-csv orgtbl-to-latex
3884 orgtbl-to-orgtbl orgtbl-to-html orgtbl-to-texinfo
)))
3886 (defun org-at-table-p (&optional table-type
)
3887 "Return t if the cursor is inside an org-type table.
3888 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3889 (if org-enable-table-editor
3891 (beginning-of-line 1)
3892 (looking-at (if table-type org-table-any-line-regexp
3893 org-table-line-regexp
)))
3895 (defsubst org-table-p
() (org-at-table-p))
3897 (defun org-at-table.el-p
()
3898 "Return t if and only if we are at a table.el table."
3899 (and (org-at-table-p 'any
)
3901 (goto-char (org-table-begin 'any
))
3902 (looking-at org-table1-hline-regexp
))))
3903 (defun org-table-recognize-table.el
()
3904 "If there is a table.el table nearby, recognize it and move into it."
3905 (if org-table-tab-recognizes-table.el
3906 (if (org-at-table.el-p
)
3908 (beginning-of-line 1)
3909 (if (looking-at org-table-dataline-regexp
)
3911 (if (looking-at org-table1-hline-regexp
)
3913 (beginning-of-line 2)
3914 (if (looking-at org-table-any-border-regexp
)
3915 (beginning-of-line -
1)))))
3916 (if (re-search-forward "|" (org-table-end t
) t
)
3919 (if (table--at-cell-p (point))
3921 (message "recognizing table.el table...")
3922 (table-recognize-table)
3923 (message "recognizing table.el table...done")))
3924 (error "This should not happen"))
3929 (defun org-at-table-hline-p ()
3930 "Return t if the cursor is inside a hline in a table."
3931 (if org-enable-table-editor
3933 (beginning-of-line 1)
3934 (looking-at org-table-hline-regexp
))
3937 (defvar org-table-clean-did-remove-column nil
)
3939 (defun org-table-map-tables (function &optional quietly
)
3940 "Apply FUNCTION to the start of all tables in the buffer."
3944 (goto-char (point-min))
3945 (while (re-search-forward org-table-any-line-regexp nil t
)
3947 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3948 (beginning-of-line 1)
3949 (when (looking-at org-table-line-regexp
)
3950 (save-excursion (funcall function
))
3951 (or (looking-at org-table-line-regexp
)
3953 (re-search-forward org-table-any-border-regexp nil
1))))
3954 (unless quietly
(message "Mapping tables: done")))
3956 ;; Declare and autoload functions from org-exp.el & Co
3958 (declare-function org-default-export-plist
"org-exp")
3959 (declare-function org-infile-export-plist
"org-exp")
3960 (declare-function org-get-current-options
"org-exp")
3962 (org-autoload "org-exp"
3963 '(org-export org-export-visible
3964 org-insert-export-options-template
3965 org-table-clean-before-export
))
3966 (org-autoload "org-ascii"
3967 '(org-export-as-ascii org-export-ascii-preprocess
3968 org-export-as-ascii-to-buffer org-replace-region-by-ascii
3969 org-export-region-as-ascii
))
3970 (org-autoload "org-latex"
3971 '(org-export-as-latex-batch org-export-as-latex-to-buffer
3972 org-replace-region-by-latex org-export-region-as-latex
3973 org-export-as-latex org-export-as-pdf
3974 org-export-as-pdf-and-open
))
3975 (org-autoload "org-html"
3976 '(org-export-as-html-and-open
3977 org-export-as-html-batch org-export-as-html-to-buffer
3978 org-replace-region-by-html org-export-region-as-html
3979 org-export-as-html
))
3980 (org-autoload "org-docbook"
3981 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
3982 org-replace-region-by-docbook org-export-region-as-docbook
3983 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
3984 org-export-as-docbook
))
3985 (org-autoload "org-icalendar"
3986 '(org-export-icalendar-this-file
3987 org-export-icalendar-all-agenda-files
3988 org-export-icalendar-combine-agenda-files
))
3989 (org-autoload "org-xoxo" '(org-export-as-xoxo))
3990 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
3992 ;; Declare and autoload functions from org-agenda.el
3995 (org-autoload "org-agenda"
3996 '(org-agenda org-agenda-list org-search-view
3997 org-todo-list org-tags-view org-agenda-list-stuck-projects
3998 org-diary org-agenda-to-appt
3999 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
4001 ;; Autoload org-remember
4004 (org-autoload "org-remember"
4005 '(org-remember-insinuate org-remember-annotation
4006 org-remember-apply-template org-remember org-remember-handler
)))
4009 (org-autoload "org-capture"
4010 '(org-capture org-capture-insert-template-here
4011 org-capture-import-remember-templates
)))
4013 ;; Autoload org-clock.el
4015 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
4017 (declare-function org-clock-update-mode-line
"org-clock" ())
4018 (declare-function org-resolve-clocks
"org-clock"
4019 (&optional also-non-dangling-p prompt last-valid
))
4020 (defvar org-clock-start-time
)
4021 (defvar org-clock-marker
(make-marker)
4022 "Marker recording the last clock-in.")
4023 (defvar org-clock-hd-marker
(make-marker)
4024 "Marker recording the last clock-in, but the headline position.")
4025 (defvar org-clock-heading
""
4026 "The heading of the current clock entry.")
4027 (defun org-clock-is-active ()
4028 "Return non-nil if clock is currently running.
4029 The return value is actually the clock marker."
4030 (marker-buffer org-clock-marker
))
4035 '(org-clock-in org-clock-out org-clock-cancel
4036 org-clock-goto org-clock-sum org-clock-display
4037 org-clock-remove-overlays org-clock-report
4038 org-clocktable-shift org-dblock-write
:clocktable
4039 org-get-clocktable org-resolve-clocks
)))
4041 (defun org-clock-update-time-maybe ()
4042 "If this is a CLOCK line, update it and return t.
4043 Otherwise, return nil."
4046 (beginning-of-line 1)
4047 (skip-chars-forward " \t")
4048 (when (looking-at org-clock-string
)
4049 (let ((re (concat "[ \t]*" org-clock-string
4050 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
4051 "\\([ \t]*=>.*\\)?\\)?"))
4054 ((not (looking-at re
))
4056 ((not (match-end 2))
4057 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
4058 (> org-clock-marker
(point))
4059 (<= org-clock-marker
(point-at-eol)))
4060 ;; The clock is running here
4061 (setq org-clock-start-time
4063 (org-parse-time-string (match-string 1))))
4064 (org-clock-update-mode-line)))
4066 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
4068 (setq ts
(match-string 1)
4069 te
(match-string 3))
4070 (setq s
(- (org-float-time
4071 (apply 'encode-time
(org-parse-time-string te
)))
4073 (apply 'encode-time
(org-parse-time-string ts
))))
4076 h
(floor (/ s
3600))
4080 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
4083 (defun org-check-running-clock ()
4084 "Check if the current buffer contains the running clock.
4085 If yes, offer to stop it and to save the buffer with the changes."
4086 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
4087 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
4090 (when (y-or-n-p "Save changed buffer?")
4093 (defun org-clocktable-try-shift (dir n
)
4094 "Check if this line starts a clock table, if yes, shift the time block."
4095 (when (org-match-line "^[ \t]*#\\+BEGIN:[ \t]+clocktable\\>")
4096 (org-clocktable-shift dir n
)))
4098 ;; Autoload org-timer.el
4103 '(org-timer-start org-timer org-timer-item
4104 org-timer-change-times-in-region
4106 org-timer-reset-timers
4107 org-timer-show-remaining-time
)))
4109 ;; Autoload org-feed.el
4114 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
4117 ;; Autoload org-indent.el
4119 ;; Define the variable already here, to make sure we have it.
4120 (defvar org-indent-mode nil
4121 "Non-nil if Org-Indent mode is enabled.
4122 Use the command `org-indent-mode' to change this variable.")
4127 '(org-indent-mode)))
4129 ;; Autoload org-mobile.el
4134 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
4136 ;; Autoload archiving code
4137 ;; The stuff that is needed for cycling and tags has to be defined here.
4139 (defgroup org-archive nil
4140 "Options concerning archiving in Org-mode."
4142 :group
'org-structure
)
4144 (defcustom org-archive-location
"%s_archive::"
4145 "The location where subtrees should be archived.
4147 The value of this variable is a string, consisting of two parts,
4148 separated by a double-colon. The first part is a filename and
4149 the second part is a headline.
4151 When the filename is omitted, archiving happens in the same file.
4152 %s in the filename will be replaced by the current file
4153 name (without the directory part). Archiving to a different file
4154 is useful to keep archived entries from contributing to the
4157 The archived entries will be filed as subtrees of the specified
4158 headline. When the headline is omitted, the subtrees are simply
4159 filed away at the end of the file, as top-level entries. Also in
4160 the heading you can use %s to represent the file name, this can be
4161 useful when using the same archive for a number of different files.
4163 Here are a few examples:
4165 If the current file is Projects.org, archive in file
4166 Projects.org_archive, as top-level trees. This is the default.
4168 \"::* Archived Tasks\"
4169 Archive in the current file, under the top-level headline
4170 \"* Archived Tasks\".
4172 \"~/org/archive.org::\"
4173 Archive in file ~/org/archive.org (absolute path), as top-level trees.
4175 \"~/org/archive.org::* From %s\"
4176 Archive in file ~/org/archive.org (absolute path), under headlines
4177 \"From FILENAME\" where file name is the current file name.
4179 \"basement::** Finished Tasks\"
4180 Archive in file ./basement (relative path), as level 3 trees
4181 below the level 2 heading \"** Finished Tasks\".
4183 You may set this option on a per-file basis by adding to the buffer a
4186 #+ARCHIVE: basement::** Finished Tasks
4188 You may also define it locally for a subtree by setting an ARCHIVE property
4189 in the entry. If such a property is found in an entry, or anywhere up
4190 the hierarchy, it will be used."
4194 (defcustom org-archive-tag
"ARCHIVE"
4195 "The tag that marks a subtree as archived.
4196 An archived subtree does not open during visibility cycling, and does
4197 not contribute to the agenda listings.
4198 After changing this, font-lock must be restarted in the relevant buffers to
4199 get the proper fontification."
4201 :group
'org-keywords
4204 (defcustom org-agenda-skip-archived-trees t
4205 "Non-nil means the agenda will skip any items located in archived trees.
4206 An archived tree is a tree marked with the tag ARCHIVE. The use of this
4207 variable is no longer recommended, you should leave it at the value t.
4208 Instead, use the key `v' to cycle the archives-mode in the agenda."
4210 :group
'org-agenda-skip
4213 (defcustom org-columns-skip-archived-trees t
4214 "Non-nil means ignore archived trees when creating column view."
4216 :group
'org-properties
4219 (defcustom org-cycle-open-archived-trees nil
4220 "Non-nil means `org-cycle' will open archived trees.
4221 An archived tree is a tree marked with the tag ARCHIVE.
4222 When nil, archived trees will stay folded. You can still open them with
4223 normal outline commands like `show-all', but not with the cycling commands."
4228 (defcustom org-sparse-tree-open-archived-trees nil
4229 "Non-nil means sparse tree construction shows matches in archived trees.
4230 When nil, matches in these trees are highlighted, but the trees are kept in
4233 :group
'org-sparse-trees
4236 (defun org-cycle-hide-archived-subtrees (state)
4237 "Re-hide all archived subtrees after a visibility state change."
4238 (when (and (not org-cycle-open-archived-trees
)
4239 (not (memq state
'(overview folded
))))
4241 (let* ((globalp (memq state
'(contents all
)))
4242 (beg (if globalp
(point-min) (point)))
4243 (end (if globalp
(point-max) (org-end-of-subtree t
))))
4244 (org-hide-archived-subtrees beg end
)
4246 (if (looking-at (concat ".*:" org-archive-tag
":"))
4247 (message "%s" (substitute-command-keys
4248 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
4250 (defun org-force-cycle-archived ()
4251 "Cycle subtree even if it is archived."
4253 (setq this-command
'org-cycle
)
4254 (let ((org-cycle-open-archived-trees t
))
4255 (call-interactively 'org-cycle
)))
4257 (defun org-hide-archived-subtrees (beg end
)
4258 "Re-hide all archived subtrees after a visibility state change."
4260 (let* ((re (concat ":" org-archive-tag
":")))
4262 (while (re-search-forward re end t
)
4263 (when (org-at-heading-p)
4264 (org-flag-subtree t
)
4265 (org-end-of-subtree t
))))))
4267 (defun org-flag-subtree (flag)
4269 (org-back-to-heading t
)
4270 (outline-end-of-heading)
4271 (outline-flag-region (point)
4272 (progn (org-end-of-subtree t
) (point))
4275 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
4278 (org-autoload "org-archive"
4279 '(org-add-archive-files org-archive-subtree
4280 org-archive-to-archive-sibling org-toggle-archive-tag
4281 org-archive-subtree-default
4282 org-archive-subtree-default-with-confirmation
)))
4284 ;; Autoload Column View Code
4286 (declare-function org-columns-number-to-string
"org-colview")
4287 (declare-function org-columns-get-format-and-top-level
"org-colview")
4288 (declare-function org-columns-compute
"org-colview")
4290 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
4291 '(org-columns-number-to-string org-columns-get-format-and-top-level
4292 org-columns-compute org-agenda-columns org-columns-remove-overlays
4293 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
4297 (declare-function org-id-store-link
"org-id")
4298 (declare-function org-id-locations-load
"org-id")
4299 (declare-function org-id-locations-save
"org-id")
4300 (defvar org-id-track-globally
)
4301 (org-autoload "org-id"
4302 '(org-id-get-create org-id-new org-id-copy org-id-get
4303 org-id-get-with-outline-path-completion
4304 org-id-get-with-outline-drilling org-id-store-link
4305 org-id-goto org-id-find org-id-store-link
))
4307 ;; Autoload Plotting Code
4309 (org-autoload "org-plot"
4310 '(org-plot/gnuplot
))
4312 ;;; Variables for pre-computed regular expressions, all buffer local
4314 (defvar org-drawer-regexp nil
4315 "Matches first line of a hidden block.")
4316 (make-variable-buffer-local 'org-drawer-regexp
)
4317 (defvar org-todo-regexp nil
4318 "Matches any of the TODO state keywords.")
4319 (make-variable-buffer-local 'org-todo-regexp
)
4320 (defvar org-not-done-regexp nil
4321 "Matches any of the TODO state keywords except the last one.")
4322 (make-variable-buffer-local 'org-not-done-regexp
)
4323 (defvar org-not-done-heading-regexp nil
4324 "Matches a TODO headline that is not done.")
4325 (make-variable-buffer-local 'org-not-done-regexp
)
4326 (defvar org-todo-line-regexp nil
4327 "Matches a headline and puts TODO state into group 2 if present.")
4328 (make-variable-buffer-local 'org-todo-line-regexp
)
4329 (defvar org-complex-heading-regexp nil
4330 "Matches a headline and puts everything into groups:
4332 group 2: The todo keyword, maybe
4333 group 3: Priority cookie
4334 group 4: True headline
4336 (make-variable-buffer-local 'org-complex-heading-regexp
)
4337 (defvar org-complex-heading-regexp-format nil
4338 "Printf format to make regexp to match an exact headline.
4339 This regexp will match the headline of any node which has the
4340 exact headline text that is put into the format, but may have any
4341 TODO state, priority and tags.")
4342 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
4343 (defvar org-todo-line-tags-regexp nil
4344 "Matches a headline and puts TODO state into group 2 if present.
4345 Also put tags into group 4 if tags are present.")
4346 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
4347 (defvar org-ds-keyword-length
12
4348 "Maximum length of the Deadline and SCHEDULED keywords.")
4349 (make-variable-buffer-local 'org-ds-keyword-length
)
4350 (defvar org-deadline-regexp nil
4351 "Matches the DEADLINE keyword.")
4352 (make-variable-buffer-local 'org-deadline-regexp
)
4353 (defvar org-deadline-time-regexp nil
4354 "Matches the DEADLINE keyword together with a time stamp.")
4355 (make-variable-buffer-local 'org-deadline-time-regexp
)
4356 (defvar org-deadline-line-regexp nil
4357 "Matches the DEADLINE keyword and the rest of the line.")
4358 (make-variable-buffer-local 'org-deadline-line-regexp
)
4359 (defvar org-scheduled-regexp nil
4360 "Matches the SCHEDULED keyword.")
4361 (make-variable-buffer-local 'org-scheduled-regexp
)
4362 (defvar org-scheduled-time-regexp nil
4363 "Matches the SCHEDULED keyword together with a time stamp.")
4364 (make-variable-buffer-local 'org-scheduled-time-regexp
)
4365 (defvar org-closed-time-regexp nil
4366 "Matches the CLOSED keyword together with a time stamp.")
4367 (make-variable-buffer-local 'org-closed-time-regexp
)
4369 (defvar org-keyword-time-regexp nil
4370 "Matches any of the 4 keywords, together with the time stamp.")
4371 (make-variable-buffer-local 'org-keyword-time-regexp
)
4372 (defvar org-keyword-time-not-clock-regexp nil
4373 "Matches any of the 3 keywords, together with the time stamp.")
4374 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4375 (defvar org-maybe-keyword-time-regexp nil
4376 "Matches a timestamp, possibly preceded by a keyword.")
4377 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4378 (defvar org-planning-or-clock-line-re nil
4379 "Matches a line with planning or clock info.")
4380 (make-variable-buffer-local 'org-planning-or-clock-line-re
)
4381 (defvar org-all-time-keywords nil
4382 "List of time keywords.")
4383 (make-variable-buffer-local 'org-all-time-keywords
)
4385 (defconst org-plain-time-of-day-regexp
4388 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4391 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4393 "Regular expression to match a plain time or time range.
4394 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4395 groups carry important information:
4397 1 the first time, range or not
4398 8 the second time, if it is a range.")
4400 (defconst org-plain-time-extension-regexp
4403 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4404 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4405 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4406 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4407 groups carry important information:
4410 9 minutes of duration")
4412 (defconst org-stamp-time-of-day-regexp
4414 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4415 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4417 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4418 "Regular expression to match a timestamp time or time range.
4419 After a match, the following groups carry important information:
4421 1 date plus weekday, for back referencing to make sure both times are on the same day
4422 2 the first time, range or not
4423 4 the second time, if it is a range.")
4425 (defconst org-startup-options
4426 '(("fold" org-startup-folded t
)
4427 ("overview" org-startup-folded t
)
4428 ("nofold" org-startup-folded nil
)
4429 ("showall" org-startup-folded nil
)
4430 ("showeverything" org-startup-folded showeverything
)
4431 ("content" org-startup-folded content
)
4432 ("indent" org-startup-indented t
)
4433 ("noindent" org-startup-indented nil
)
4434 ("hidestars" org-hide-leading-stars t
)
4435 ("showstars" org-hide-leading-stars nil
)
4436 ("odd" org-odd-levels-only t
)
4437 ("oddeven" org-odd-levels-only nil
)
4438 ("align" org-startup-align-all-tables t
)
4439 ("noalign" org-startup-align-all-tables nil
)
4440 ("inlineimages" org-startup-with-inline-images t
)
4441 ("noinlineimages" org-startup-with-inline-images nil
)
4442 ("customtime" org-display-custom-times t
)
4443 ("logdone" org-log-done time
)
4444 ("lognotedone" org-log-done note
)
4445 ("nologdone" org-log-done nil
)
4446 ("lognoteclock-out" org-log-note-clock-out t
)
4447 ("nolognoteclock-out" org-log-note-clock-out nil
)
4448 ("logrepeat" org-log-repeat state
)
4449 ("lognoterepeat" org-log-repeat note
)
4450 ("nologrepeat" org-log-repeat nil
)
4451 ("logreschedule" org-log-reschedule time
)
4452 ("lognotereschedule" org-log-reschedule note
)
4453 ("nologreschedule" org-log-reschedule nil
)
4454 ("logredeadline" org-log-redeadline time
)
4455 ("lognoteredeadline" org-log-redeadline note
)
4456 ("nologredeadline" org-log-redeadline nil
)
4457 ("logrefile" org-log-refile time
)
4458 ("lognoterefile" org-log-refile note
)
4459 ("nologrefile" org-log-refile nil
)
4460 ("fninline" org-footnote-define-inline t
)
4461 ("nofninline" org-footnote-define-inline nil
)
4462 ("fnlocal" org-footnote-section nil
)
4463 ("fnauto" org-footnote-auto-label t
)
4464 ("fnprompt" org-footnote-auto-label nil
)
4465 ("fnconfirm" org-footnote-auto-label confirm
)
4466 ("fnplain" org-footnote-auto-label plain
)
4467 ("fnadjust" org-footnote-auto-adjust t
)
4468 ("nofnadjust" org-footnote-auto-adjust nil
)
4469 ("constcgs" constants-unit-system cgs
)
4470 ("constSI" constants-unit-system SI
)
4471 ("noptag" org-tag-persistent-alist nil
)
4472 ("hideblocks" org-hide-block-startup t
)
4473 ("nohideblocks" org-hide-block-startup nil
)
4474 ("beamer" org-startup-with-beamer-mode t
)
4475 ("entitiespretty" org-pretty-entities t
)
4476 ("entitiesplain" org-pretty-entities nil
))
4477 "Variable associated with STARTUP options for org-mode.
4478 Each element is a list of three items: The startup options as written
4479 in the #+STARTUP line, the corresponding variable, and the value to
4480 set this variable to if the option is found. An optional forth element PUSH
4481 means to push this value onto the list in the variable.")
4483 (defun org-update-property-plist (key val props
)
4484 "Update PROPS with KEY and VAL."
4485 (let* ((appending (string= "+" (substring key
(- (length key
) 1))))
4486 (key (if appending
(substring key
0 (- (length key
) 1)) key
))
4487 (remainder (org-remove-if (lambda (p) (string= (car p
) key
)) props
))
4488 (previous (cdr (assoc key props
))))
4490 (cons (cons key
(if previous
(concat previous
" " val
) val
)) remainder
)
4491 (cons (cons key val
) remainder
))))
4493 (defconst org-block-regexp
4494 "^[ \t]*#\\+begin_?\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_?\\1[ \t]*$"
4495 "Regular expression for hiding blocks.")
4496 (defconst org-heading-keyword-regexp-format
4497 "^\\(\\*+\\)\\(?: +%s\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
4498 "Printf format for a regexp matching an headline with some keyword.
4499 This regexp will match the headline of any node which has the
4500 exact keyword that is put into the format. The keyword isn't in
4501 any group by default, but the stars and the body are.")
4502 (defconst org-heading-keyword-maybe-regexp-format
4503 "^\\(\\*+\\)\\(?: +%s\\)?\\(?: +\\(.*?\\)\\)?[ \t]*$"
4504 "Printf format for a regexp matching an headline, possibly with some keyword.
4505 This regexp can match any headline with the specified keyword, or
4506 without a keyword. The keyword isn't in any group by default,
4507 but the stars and the body are.")
4509 (defun org-set-regexps-and-options ()
4510 "Precompute regular expressions for current buffer."
4511 (when (eq major-mode
'org-mode
)
4512 (org-set-local 'org-todo-kwd-alist nil
)
4513 (org-set-local 'org-todo-key-alist nil
)
4514 (org-set-local 'org-todo-key-trigger nil
)
4515 (org-set-local 'org-todo-keywords-1 nil
)
4516 (org-set-local 'org-done-keywords nil
)
4517 (org-set-local 'org-todo-heads nil
)
4518 (org-set-local 'org-todo-sets nil
)
4519 (org-set-local 'org-todo-log-states nil
)
4520 (org-set-local 'org-file-properties nil
)
4521 (org-set-local 'org-file-tags nil
)
4522 (let ((re (org-make-options-regexp
4523 '("CATEGORY" "TODO" "COLUMNS"
4524 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
4525 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS"
4527 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4529 (scripts org-use-sub-superscripts
)
4530 kwds kws0 kwsa key log value cat arch tags const links hw dws
4531 tail sep kws1 prio props ftags drawers beamer-p
4532 ext-setup-or-nil setup-contents
(start 0))
4536 (goto-char (point-min))
4537 (while (or (and ext-setup-or-nil
4538 (string-match re ext-setup-or-nil start
)
4539 (setq start
(match-end 0)))
4540 (and (setq ext-setup-or-nil nil start
0)
4541 (re-search-forward re nil t
)))
4542 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4543 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4544 (if (stringp value
) (setq value
(org-trim value
)))
4546 ((equal key
"CATEGORY")
4548 ((member key
'("SEQ_TODO" "TODO"))
4549 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4550 ((equal key
"TYP_TODO")
4551 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4552 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4553 ;; general TODO-like setup
4554 (push (cons (intern (downcase (match-string 1 key
)))
4555 (org-split-string value splitre
)) kwds
))
4557 (setq tags
(append tags
(if tags
'("\\n") nil
)
4558 (org-split-string value splitre
))))
4559 ((equal key
"COLUMNS")
4560 (org-set-local 'org-columns-default-format value
))
4562 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4563 (push (cons (match-string 1 value
)
4564 (org-trim (match-string 2 value
)))
4566 ((equal key
"PRIORITIES")
4567 (setq prio
(org-split-string value
" +")))
4568 ((equal key
"PROPERTY")
4569 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4570 (setq props
(org-update-property-plist (match-string 1 value
)
4571 (match-string 2 value
)
4573 ((equal key
"FILETAGS")
4574 (when (string-match "\\S-" value
)
4579 (mapcar (lambda (x) (org-split-string x
":"))
4580 (org-split-string value
)))))))
4581 ((equal key
"DRAWERS")
4582 (setq drawers
(delete-dups (append org-drawers
(org-split-string value splitre
)))))
4583 ((equal key
"CONSTANTS")
4584 (setq const
(append const
(org-split-string value splitre
))))
4585 ((equal key
"STARTUP")
4586 (let ((opts (org-split-string value splitre
))
4588 (while (setq l
(pop opts
))
4589 (when (setq l
(assoc l org-startup-options
))
4590 (setq var
(nth 1 l
) val
(nth 2 l
))
4592 (set (make-local-variable var
) val
)
4593 (if (not (listp (symbol-value var
)))
4594 (set (make-local-variable var
) nil
))
4595 (set (make-local-variable var
) (symbol-value var
))
4596 (add-to-list var val
))))))
4597 ((equal key
"ARCHIVE")
4599 (remove-text-properties 0 (length arch
)
4600 '(face t fontified t
) arch
))
4601 ((equal key
"LATEX_CLASS")
4602 (setq beamer-p
(equal value
"beamer")))
4603 ((equal key
"OPTIONS")
4604 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4605 (setq scripts
(read (match-string 2 value
)))))
4606 ((equal key
"SETUPFILE")
4607 (setq setup-contents
(org-file-contents
4609 (org-remove-double-quotes value
))
4611 (if (not ext-setup-or-nil
)
4612 (setq ext-setup-or-nil setup-contents start
0)
4613 (setq ext-setup-or-nil
4614 (concat (substring ext-setup-or-nil
0 start
)
4615 "\n" setup-contents
"\n"
4616 (substring ext-setup-or-nil start
)))))))
4617 ;; search for property blocks
4618 (goto-char (point-min))
4619 (while (re-search-forward org-block-regexp nil t
)
4620 (when (equal "PROPERTY" (upcase (match-string 1)))
4621 (setq value
(replace-regexp-in-string
4622 "[\n\r]" " " (match-string 4)))
4623 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4624 (setq props
(org-update-property-plist (match-string 1 value
)
4625 (match-string 2 value
)
4627 (org-set-local 'org-use-sub-superscripts scripts
)
4629 (org-set-local 'org-category
(intern cat
))
4630 (push (cons "CATEGORY" cat
) props
))
4632 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4633 (setq prio
(mapcar 'string-to-char prio
))
4634 (org-set-local 'org-highest-priority
(nth 0 prio
))
4635 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4636 (org-set-local 'org-default-priority
(nth 2 prio
)))
4637 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4638 (and ftags
(org-set-local 'org-file-tags
4639 (mapcar 'org-add-prop-inherited ftags
)))
4640 (and drawers
(org-set-local 'org-drawers drawers
))
4641 (and arch
(org-set-local 'org-archive-location arch
))
4642 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4643 ;; Process the TODO keywords
4645 ;; Use the global values as if they had been given locally.
4646 (setq kwds
(default-value 'org-todo-keywords
))
4647 (if (stringp (car kwds
))
4648 (setq kwds
(list (cons org-todo-interpretation
4649 (default-value 'org-todo-keywords
)))))
4650 (setq kwds
(reverse kwds
)))
4651 (setq kwds
(nreverse kwds
))
4653 (while (setq kws
(pop kwds
))
4655 (run-hook-with-args-until-success
4656 'org-todo-setup-filter-hook kws
)
4658 (setq inter
(pop kws
) sep
(member "|" kws
)
4659 kws0
(delete "|" (copy-sequence kws
))
4664 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4666 (setq kw
(match-string 1 x
)
4667 key
(and (match-end 2) (match-string 2 x
))
4668 log
(org-extract-log-state-settings x
))
4669 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4670 (and log
(push log org-todo-log-states
))
4672 (error "Invalid TODO keyword %s" x
)))
4674 kwsa
(if kwsa
(append '((:startgroup
))
4678 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4679 tail
(list inter hw
(car dws
) (org-last dws
))))
4680 (add-to-list 'org-todo-heads hw
'append
)
4681 (push kws1 org-todo-sets
)
4682 (setq org-done-keywords
(append org-done-keywords dws nil
))
4683 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4684 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4685 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4686 (setq org-todo-sets
(nreverse org-todo-sets
)
4687 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4688 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4689 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4690 ;; Process the constants
4693 (while (setq e
(pop const
))
4694 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4695 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4696 (setq org-table-formula-constants-local cst
)))
4698 ;; Process the tags.
4701 (while (setq e
(pop tags
))
4703 ((equal e
"{") (push '(:startgroup
) tgs
))
4704 ((equal e
"}") (push '(:endgroup
) tgs
))
4705 ((equal e
"\\n") (push '(:newline
) tgs
))
4706 ((string-match (org-re "^\\([[:alnum:]_@#%]+\\)(\\(.\\))$") e
)
4707 (push (cons (match-string 1 e
)
4708 (string-to-char (match-string 2 e
)))
4710 (t (push (list e
) tgs
))))
4711 (org-set-local 'org-tag-alist nil
)
4712 (while (setq e
(pop tgs
))
4713 (or (and (stringp (car e
))
4714 (assoc (car e
) org-tag-alist
))
4715 (push e org-tag-alist
)))))
4717 ;; Compute the regular expressions and other local variables.
4718 ;; Using `org-outline-regexp-bol' would complicate them much,
4719 ;; because of the fixed white space at the end of that string.
4720 (if (not org-done-keywords
)
4721 (setq org-done-keywords
(and org-todo-keywords-1
4722 (list (org-last org-todo-keywords-1
)))))
4723 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4724 (length org-scheduled-string
)
4725 (length org-clock-string
)
4726 (length org-closed-string
)))
4728 (concat "^[ \t]*:\\("
4729 (mapconcat 'regexp-quote org-drawers
"\\|")
4731 org-not-done-keywords
4732 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4735 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4739 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4741 org-not-done-heading-regexp
4742 (format org-heading-keyword-regexp-format org-not-done-regexp
)
4743 org-todo-line-regexp
4744 (format org-heading-keyword-maybe-regexp-format org-todo-regexp
)
4745 org-complex-heading-regexp
4746 (concat "^\\(\\*+\\)"
4747 "\\(?: +" org-todo-regexp
"\\)?"
4748 "\\(?: +\\(\\[#.\\]\\)\\)?"
4749 "\\(?: +\\(.*?\\)\\)?"
4750 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?")
4752 org-complex-heading-regexp-format
4753 (concat "^\\(\\*+\\)"
4754 "\\(?: +" org-todo-regexp
"\\)?"
4755 "\\(?: +\\(\\[#.\\]\\)\\)?"
4757 ;; Stats cookies can be stuck to body.
4758 "\\(?:\\[[0-9%%/]+\\] *\\)?"
4760 "\\(?: *\\[[0-9%%/]+\\]\\)?"
4762 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?")
4764 org-todo-line-tags-regexp
4765 (concat "^\\(\\*+\\)"
4766 "\\(?: +" org-todo-regexp
"\\)?"
4767 "\\(?: +\\(.*?\\)\\)?"
4768 (org-re "\\(?:[ \t]+\\(:[[:alnum:]:_@#%]+:\\)\\)?")
4770 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4771 org-deadline-time-regexp
4772 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4773 org-deadline-line-regexp
4774 (concat "\\<\\(" org-deadline-string
"\\).*")
4775 org-scheduled-regexp
4776 (concat "\\<" org-scheduled-string
)
4777 org-scheduled-time-regexp
4778 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4779 org-closed-time-regexp
4780 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4781 org-keyword-time-regexp
4782 (concat "\\<\\(" org-scheduled-string
4783 "\\|" org-deadline-string
4784 "\\|" org-closed-string
4785 "\\|" org-clock-string
"\\)"
4786 " *[[<]\\([^]>]+\\)[]>]")
4787 org-keyword-time-not-clock-regexp
4788 (concat "\\<\\(" org-scheduled-string
4789 "\\|" org-deadline-string
4790 "\\|" org-closed-string
4792 " *[[<]\\([^]>]+\\)[]>]")
4793 org-maybe-keyword-time-regexp
4794 (concat "\\(\\<\\(" org-scheduled-string
4795 "\\|" org-deadline-string
4796 "\\|" org-closed-string
4797 "\\|" org-clock-string
"\\)\\)?"
4798 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4799 org-planning-or-clock-line-re
4800 (concat "\\(?:^[ \t]*\\(" org-scheduled-string
4801 "\\|" org-deadline-string
4802 "\\|" org-closed-string
"\\|" org-clock-string
4804 org-all-time-keywords
4805 (mapcar (lambda (w) (substring w
0 -
1))
4806 (list org-scheduled-string org-deadline-string
4807 org-clock-string org-closed-string
))
4809 (org-compute-latex-and-specials-regexp)
4810 (org-set-font-lock-defaults))))
4812 (defun org-file-contents (file &optional noerror
)
4813 "Return the contents of FILE, as a string."
4815 (not (file-readable-p file
)))
4818 (message "Cannot read file \"%s\"" file
)
4821 (error "Cannot read file \"%s\"" file
))
4823 (insert-file-contents file
)
4826 (defun org-extract-log-state-settings (x)
4827 "Extract the log state setting from a TODO keyword string.
4828 This will extract info from a string like \"WAIT(w@/!)\"."
4829 (let (kw key log1 log2
)
4830 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4831 (setq kw
(match-string 1 x
)
4832 key
(and (match-end 2) (match-string 2 x
))
4833 log1
(and (match-end 3) (match-string 3 x
))
4834 log2
(and (match-end 4) (match-string 4 x
)))
4837 (and log1
(if (equal log1
"!") 'time
'note
))
4838 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4840 (defun org-remove-keyword-keys (list)
4841 "Remove a pair of parenthesis at the end of each string in LIST."
4843 (if (string-match "(.*)$" x
)
4844 (substring x
0 (match-beginning 0))
4848 (defun org-assign-fast-keys (alist)
4849 "Assign fast keys to a keyword-key alist.
4850 Respect keys that are already there."
4851 (let (new e
(alt ?
0))
4852 (while (setq e
(pop alist
))
4853 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4854 (cdr e
)) ;; Key already assigned.
4856 (let ((clist (string-to-list (downcase (car e
))))
4857 (used (append new alist
)))
4858 (when (= (car clist
) ?
@)
4860 (while (and clist
(rassoc (car clist
) used
))
4863 (while (rassoc alt used
)
4865 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4868 ;;; Some variables used in various places
4870 (defvar org-window-configuration nil
4871 "Used in various places to store a window configuration.")
4872 (defvar org-selected-window nil
4873 "Used in various places to store a window configuration.")
4874 (defvar org-finish-function nil
4875 "Function to be called when `C-c C-c' is used.
4876 This is for getting out of special buffers like remember.")
4879 ;; FIXME: Occasionally check by commenting these, to make sure
4880 ;; no other functions uses these, forgetting to let-bind them.
4885 ;; Defined somewhere in this file, but used before definition.
4886 (defvar org-entities
) ;; defined in org-entities.el
4887 (defvar org-struct-menu
)
4888 (defvar org-org-menu
)
4889 (defvar org-tbl-menu
)
4891 ;;;; Define the Org-mode
4893 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4894 (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"))
4897 ;; We use a before-change function to check if a table might need
4899 (defvar org-table-may-need-update t
4900 "Indicates that a table might need an update.
4901 This variable is set by `org-before-change-function'.
4902 `org-table-align' sets it back to nil.")
4903 (defun org-before-change-function (beg end
)
4904 "Every change indicates that a table might need an update."
4905 (setq org-table-may-need-update t
))
4906 (defvar org-mode-map
)
4907 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4908 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4909 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4910 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4911 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4912 (defvar org-table-buffer-is-an nil
)
4914 ;; `org-outline-regexp' ought to be a defconst but is let-binding in
4915 ;; some places -- e.g. see the macro org-with-limited-levels.
4917 ;; In Org buffers, the value of `outline-regexp' is that of
4918 ;; `org-outline-regexp'. The only function still directly relying on
4919 ;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
4920 ;; job when `orgstruct-mode' is active.
4921 (defvar org-outline-regexp
"\\*+ "
4922 "Regexp to match Org headlines.")
4923 (defconst org-outline-regexp-bol
"^\\*+ "
4924 "Regexp to match Org headlines.
4925 This is similar to `org-outline-regexp' but additionally makes
4926 sure that we are at the beginning of the line.")
4928 (defconst org-heading-regexp
"^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
4929 "Matches an headline, putting stars and text into groups.
4930 Stars are put in group 1 and the trimmed body in group 2.")
4933 (define-derived-mode org-mode outline-mode
"Org"
4934 "Outline-based notes management and organizer, alias
4935 \"Carsten's outline-mode for keeping track of everything.\"
4937 Org-mode develops organizational tasks around a NOTES file which
4938 contains information about projects as plain text. Org-mode is
4939 implemented on top of outline-mode, which is ideal to keep the content
4940 of large files well structured. It supports ToDo items, deadlines and
4941 time stamps, which magically appear in the diary listing of the Emacs
4942 calendar. Tables are easily created with a built-in table editor.
4943 Plain text URL-like links connect to websites, emails (VM), Usenet
4944 messages (Gnus), BBDB entries, and any files related to the project.
4945 For printing and sharing of notes, an Org-mode file (or a part of it)
4946 can be exported as a structured ASCII or HTML file.
4948 The following commands are available:
4952 ;; Get rid of Outline menus, they are not needed
4953 ;; Need to do this here because define-derived-mode sets up
4954 ;; the keymap so late. Still, it is a waste to call this each time
4955 ;; we switch another buffer into org-mode.
4956 (if (featurep 'xemacs
)
4957 (when (boundp 'outline-mode-menu-heading
)
4958 ;; Assume this is Greg's port, it uses easymenu
4959 (easy-menu-remove outline-mode-menu-heading
)
4960 (easy-menu-remove outline-mode-menu-show
)
4961 (easy-menu-remove outline-mode-menu-hide
))
4962 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
4963 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
4964 (define-key org-mode-map
[menu-bar show
] 'undefined
))
4966 (org-load-modules-maybe)
4967 (easy-menu-add org-org-menu
)
4968 (easy-menu-add org-tbl-menu
)
4969 (org-install-agenda-files-menu)
4970 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
4971 (add-to-invisibility-spec '(org-cwidth))
4972 (add-to-invisibility-spec '(org-hide-block . t
))
4973 (when (featurep 'xemacs
)
4974 (org-set-local 'line-move-ignore-invisible t
))
4975 (org-set-local 'outline-regexp org-outline-regexp
)
4976 (org-set-local 'outline-level
'org-outline-level
)
4977 (setq bidi-paragraph-direction
'left-to-right
)
4978 (when (and org-ellipsis
4979 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
4980 (fboundp 'make-glyph-code
))
4981 (unless org-display-table
4982 (setq org-display-table
(make-display-table)))
4983 (set-display-table-slot
4986 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
4988 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
4989 (setq buffer-display-table org-display-table
))
4990 (org-set-regexps-and-options)
4991 (when (and org-tag-faces
(not org-tags-special-faces-re
))
4992 ;; tag faces set outside customize.... force initialization.
4993 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
4995 (org-set-local 'calc-embedded-open-mode
"# ")
4996 (modify-syntax-entry ?
@ "w")
4997 (if org-startup-truncated
(setq truncate-lines t
))
4998 (org-set-local 'font-lock-unfontify-region-function
4999 'org-unfontify-region
)
5000 ;; Activate before-change-function
5001 (org-set-local 'org-table-may-need-update t
)
5002 (org-add-hook 'before-change-functions
'org-before-change-function nil
5004 ;; Check for running clock before killing a buffer
5005 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
5006 ;; Paragraphs and auto-filling
5007 (org-set-autofill-regexps)
5008 (setq indent-line-function
'org-indent-line-function
)
5009 (org-update-radio-target-regexp)
5010 ;; Beginning/end of defun
5011 (org-set-local 'beginning-of-defun-function
'org-beginning-of-defun
)
5012 (org-set-local 'end-of-defun-function
'org-end-of-defun
)
5013 ;; Next error for sparse trees
5014 (org-set-local 'next-error-function
'org-occur-next-match
)
5015 ;; Make sure dependence stuff works reliably, even for users who set it
5017 (if org-enforce-todo-dependencies
5018 (add-hook 'org-blocker-hook
5019 'org-block-todo-from-children-or-siblings-or-parent
)
5020 (remove-hook 'org-blocker-hook
5021 'org-block-todo-from-children-or-siblings-or-parent
))
5022 (if org-enforce-todo-checkbox-dependencies
5023 (add-hook 'org-blocker-hook
5024 'org-block-todo-from-checkboxes
)
5025 (remove-hook 'org-blocker-hook
5026 'org-block-todo-from-checkboxes
))
5028 ;; Comment characters
5029 (org-set-local 'comment-start
"#")
5030 (org-set-local 'comment-padding
" ")
5032 ;; Align options lines
5034 'align-mode-rules-list
5035 '((org-in-buffer-settings
5036 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
5037 (modes .
'(org-mode)))))
5040 (org-set-local 'imenu-create-index-function
5041 'org-imenu-get-tree
)
5043 ;; Make isearch reveal context
5044 (if (or (featurep 'xemacs
)
5045 (not (boundp 'outline-isearch-open-invisible-function
)))
5046 ;; Emacs 21 and XEmacs make use of the hook
5047 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
5048 ;; Emacs 22 deals with this through a special variable
5049 (org-set-local 'outline-isearch-open-invisible-function
5050 (lambda (&rest ignore
) (org-show-context 'isearch
))))
5052 ;; Turn on org-beamer-mode?
5053 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
5055 ;; Setup the pcomplete hooks
5056 (set (make-local-variable 'pcomplete-command-completion-function
)
5057 'org-pcomplete-initial
)
5058 (set (make-local-variable 'pcomplete-command-name-function
)
5059 'org-command-at-point
)
5060 (set (make-local-variable 'pcomplete-default-completion-function
)
5062 (set (make-local-variable 'pcomplete-parse-arguments-function
)
5063 'org-parse-arguments
)
5064 (set (make-local-variable 'pcomplete-termination-string
) "")
5065 (set (make-local-variable 'face-remapping-alist
)
5066 '((default org-default
)))
5068 ;; If empty file that did not turn on org-mode automatically, make it to.
5069 (if (and org-insert-mode-line-in-empty-file
5070 (org-called-interactively-p 'any
)
5071 (= (point-min) (point-max)))
5072 (insert "# -*- mode: org -*-\n\n"))
5073 (unless org-inhibit-startup
5074 (when org-startup-align-all-tables
5075 (let ((bmp (buffer-modified-p)))
5076 (org-table-map-tables 'org-table-align
'quietly
)
5077 (set-buffer-modified-p bmp
)))
5078 (when org-startup-with-inline-images
5079 (org-display-inline-images))
5080 (when org-startup-indented
5081 (require 'org-indent
)
5082 (org-indent-mode 1))
5083 (unless org-inhibit-startup-visibility-stuff
5084 (org-set-startup-visibility))))
5086 (when (fboundp 'abbrev-table-put
)
5087 (abbrev-table-put org-mode-abbrev-table
5088 :parents
(list text-mode-abbrev-table
)))
5090 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
5092 (defun org-current-time ()
5093 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
5094 (if (> (car org-time-stamp-rounding-minutes
) 1)
5095 (let ((r (car org-time-stamp-rounding-minutes
))
5096 (time (decode-time)))
5098 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
5103 "Return today date, considering `org-extend-today-until'."
5105 (time-subtract (current-time)
5106 (list 0 (* 3600 org-extend-today-until
) 0))))
5108 ;;;; Font-Lock stuff, including the activators
5110 (defvar org-mouse-map
(make-sparse-keymap))
5111 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
5112 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
5113 (when org-mouse-1-follows-link
5114 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
5115 (when org-tab-follows-link
5116 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
5117 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
5119 (require 'font-lock
)
5121 (defconst org-non-link-chars
"]\t\n\r<>")
5122 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
5123 "shell" "elisp" "doi" "message"))
5124 (defvar org-link-types-re nil
5125 "Matches a link that has a url-like prefix like \"http:\"")
5126 (defvar org-link-re-with-space nil
5127 "Matches a link with spaces, optional angular brackets around it.")
5128 (defvar org-link-re-with-space2 nil
5129 "Matches a link with spaces, optional angular brackets around it.")
5130 (defvar org-link-re-with-space3 nil
5131 "Matches a link with spaces, only for internal part in bracket links.")
5132 (defvar org-angle-link-re nil
5133 "Matches link with angular brackets, spaces are allowed.")
5134 (defvar org-plain-link-re nil
5135 "Matches plain link, without spaces.")
5136 (defvar org-bracket-link-regexp nil
5137 "Matches a link in double brackets.")
5138 (defvar org-bracket-link-analytic-regexp nil
5139 "Regular expression used to analyze links.
5140 Here is what the match groups contain after a match:
5146 (defvar org-bracket-link-analytic-regexp
++ nil
5147 "Like `org-bracket-link-analytic-regexp', but include coderef internal type.")
5148 (defvar org-any-link-re nil
5149 "Regular expression matching any link.")
5151 (defcustom org-match-sexp-depth
3
5152 "Number of stacked braces for sub/superscript matching.
5153 This has to be set before loading org.el to be effective."
5154 :group
'org-export-translation
; ??????????????????????????/
5157 (defun org-create-multibrace-regexp (left right n
)
5158 "Create a regular expression which will match a balanced sexp.
5159 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
5160 as single character strings.
5161 The regexp returned will match the entire expression including the
5162 delimiters. It will also define a single group which contains the
5163 match except for the outermost delimiters. The maximum depth of
5164 stacked delimiters is N. Escaping delimiters is not possible."
5165 (let* ((nothing (concat "[^" left right
"]*?"))
5168 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
5171 re
(concat re or next
)
5172 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
5173 (concat left
"\\(" re
"\\)" right
)))
5175 (defvar org-match-substring-regexp
5177 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5178 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5180 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
5182 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
5183 "The regular expression matching a sub- or superscript.")
5185 (defvar org-match-substring-with-braces-regexp
5187 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5188 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5190 "The regular expression matching a sub- or superscript, forcing braces.")
5192 (defun org-make-link-regexps ()
5193 "Update the link regular expressions.
5194 This should be called after the variable `org-link-types' has changed."
5195 (setq org-link-types-re
5197 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
5198 org-link-re-with-space
5200 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5201 "\\([^" org-non-link-chars
" ]"
5202 "[^" org-non-link-chars
"]*"
5203 "[^" org-non-link-chars
" ]\\)>?")
5204 org-link-re-with-space2
5206 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5207 "\\([^" org-non-link-chars
" ]"
5209 "[^" org-non-link-chars
" ]\\)>?")
5210 org-link-re-with-space3
5212 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5213 "\\([^" org-non-link-chars
" ]"
5217 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5218 "\\([^" org-non-link-chars
" ]"
5219 "[^" org-non-link-chars
"]*"
5223 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5224 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
5225 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
5226 org-bracket-link-regexp
5227 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
5228 org-bracket-link-analytic-regexp
5231 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
5234 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5236 org-bracket-link-analytic-regexp
++
5239 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
5242 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5245 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
5246 org-angle-link-re
"\\)\\|\\("
5247 org-plain-link-re
"\\)")))
5249 (org-make-link-regexps)
5251 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)>"
5252 "Regular expression for fast time stamp matching.")
5253 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?\\)[]>]"
5254 "Regular expression for fast time stamp matching.")
5255 (defconst org-ts-regexp0
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5256 "Regular expression matching time strings for analysis.
5257 This one does not require the space after the date, so it can be used
5258 on a string that terminates immediately after the date.")
5259 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5260 "Regular expression matching time strings for analysis.")
5261 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
5262 "Regular expression matching time stamps, with groups.")
5263 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
5264 "Regular expression matching time stamps (also [..]), with groups.")
5265 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
5266 "Regular expression matching a time stamp range.")
5267 (defconst org-tr-regexp-both
5268 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
5269 "Regular expression matching a time stamp range.")
5270 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
5271 org-ts-regexp
"\\)?")
5272 "Regular expression matching a time stamp or time stamp range.")
5273 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
5274 org-ts-regexp-both
"\\)?")
5275 "Regular expression matching a time stamp or time stamp range.
5276 The time stamps may be either active or inactive.")
5278 (defvar org-emph-face nil
)
5280 (defun org-do-emphasis-faces (limit)
5281 "Run through the buffer and add overlays to emphasized strings."
5283 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
5284 (if (not (= (char-after (match-beginning 3))
5285 (char-after (match-beginning 4))))
5288 (setq a
(assoc (match-string 3) org-emphasis-alist
))
5289 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
5293 (org-remove-flyspell-overlays-in
5294 (match-beginning 0) (match-end 0)))
5295 (add-text-properties (match-beginning 2) (match-end 2)
5296 '(font-lock-multiline t org-emphasis t
))
5297 (when org-hide-emphasis-markers
5298 (add-text-properties (match-end 4) (match-beginning 5)
5299 '(invisible org-link
))
5300 (add-text-properties (match-beginning 3) (match-end 3)
5301 '(invisible org-link
)))))
5305 (defun org-emphasize (&optional char
)
5306 "Insert or change an emphasis, i.e. a font like bold or italic.
5307 If there is an active region, change that region to a new emphasis.
5308 If there is no region, just insert the marker characters and position
5309 the cursor between them.
5310 CHAR should be either the marker character, or the first character of the
5311 HTML tag associated with that emphasis. If CHAR is a space, the means
5312 to remove the emphasis of the selected region.
5313 If char is not given (for example in an interactive call) it
5314 will be prompted for."
5316 (let ((eal org-emphasis-alist
) e det
5317 (erc org-emphasis-regexp-components
)
5319 (string "") beg end move tag c s
)
5320 (if (org-region-active-p)
5321 (setq beg
(region-beginning) end
(region-end)
5322 string
(buffer-substring beg end
))
5325 (while (setq e
(pop eal
))
5326 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
5328 (push (cons c
(string-to-char (car e
))) det
)
5329 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
5330 (substring tag
1)))))
5331 (setq det
(nreverse det
))
5333 (message "%s" (concat "Emphasis marker or tag:" prompt
))
5334 (setq char
(read-char-exclusive)))
5335 (setq char
(or (cdr (assoc char det
)) char
))
5336 (if (equal char ?\
)
5337 (setq s
"" move nil
)
5338 (unless (assoc (char-to-string char
) org-emphasis-alist
)
5339 (error "No such emphasis marker: \"%c\"" char
))
5340 (setq s
(char-to-string char
)))
5341 (while (and (> (length string
) 1)
5342 (equal (substring string
0 1) (substring string -
1))
5343 (assoc (substring string
0 1) org-emphasis-alist
))
5344 (setq string
(substring string
1 -
1)))
5345 (setq string
(concat s string s
))
5346 (if beg
(delete-region beg end
))
5348 (string-match (concat "[" (nth 0 erc
) "\n]")
5349 (char-to-string (char-before (point)))))
5352 (string-match (concat "[" (nth 1 erc
) "\n]")
5353 (char-to-string (char-after (point)))))
5354 (insert " ") (backward-char 1))
5356 (and move
(backward-char 1))))
5358 (defconst org-nonsticky-props
5359 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
5361 (defsubst org-rear-nonsticky-at
(pos)
5362 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
5364 (defun org-activate-plain-links (limit)
5365 "Run through the buffer and add overlays to links."
5368 (if (re-search-forward org-plain-link-re limit t
)
5370 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5371 (setq f
(get-text-property (match-beginning 0) 'face
))
5372 (if (or (eq f
'org-tag
)
5373 (and (listp f
) (memq 'org-tag f
)))
5375 (add-text-properties (match-beginning 0) (match-end 0)
5376 (list 'mouse-face
'highlight
5378 'keymap org-mouse-map
))
5379 (org-rear-nonsticky-at (match-end 0)))
5382 (defun org-activate-code (limit)
5383 (if (re-search-forward "^[ \t]*\\(:\\(?: .*\\|$\\)\n?\\)" limit t
)
5385 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5386 (remove-text-properties (match-beginning 0) (match-end 0)
5387 '(display t invisible t intangible t
))
5390 (defcustom org-src-fontify-natively nil
5391 "When non-nil, fontify code in code blocks."
5394 :group
'org-appearance
5397 (defun org-fontify-meta-lines-and-blocks (limit)
5399 (org-fontify-meta-lines-and-blocks-1 limit
)
5400 (error (message "org-mode fontification error"))))
5402 (defun org-fontify-meta-lines-and-blocks-1 (limit)
5403 "Fontify #+ lines and blocks, in the correct ways."
5404 (let ((case-fold-search t
))
5405 (if (re-search-forward
5406 "^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
5408 (let ((beg (match-beginning 0))
5409 (block-start (match-end 0))
5411 (lang (match-string 7))
5412 (beg1 (line-beginning-position 2))
5413 (dc1 (downcase (match-string 2)))
5414 (dc3 (downcase (match-string 3)))
5415 end end1 quoting block-type ovl
)
5417 ((member dc1
'("html:" "ascii:" "latex:" "docbook:"))
5418 ;; a single line of backend-specific content
5419 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5420 (remove-text-properties (match-beginning 0) (match-end 0)
5421 '(display t invisible t intangible t
))
5422 (add-text-properties (match-beginning 1) (match-end 3)
5423 '(font-lock-fontified t face org-meta-line
))
5424 (add-text-properties (match-beginning 6) (+ (match-end 6) 1)
5425 '(font-lock-fontified t face org-block
))
5426 ; for backend-specific code
5428 ((and (match-end 4) (equal dc3
"begin"))
5430 (setq block-type
(downcase (match-string 5))
5431 quoting
(member block-type org-protecting-blocks
))
5432 (when (re-search-forward
5433 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
5434 nil t
) ;; on purpose, we look further than LIMIT
5435 (setq end
(match-end 0) end1
(1- (match-beginning 0)))
5436 (setq block-end
(match-beginning 0))
5438 (remove-text-properties beg end
5439 '(display t invisible t intangible t
)))
5440 (add-text-properties
5442 '(font-lock-fontified t font-lock-multiline t
))
5443 (add-text-properties beg beg1
'(face org-meta-line
))
5444 (add-text-properties end1
(min (point-max) (1+ end
))
5445 '(face org-meta-line
)) ; for end_src
5447 ((and lang
(not (string= lang
"")) org-src-fontify-natively
)
5448 (org-src-font-lock-fontify-block lang block-start block-end
)
5449 ;; remove old background overlays
5451 (if (eq (overlay-get ov
'face
) 'org-block-background
)
5452 (delete-overlay ov
)))
5453 (overlays-at (/ (+ beg1 block-end
) 2)))
5454 ;; add a background overlay
5455 (setq ovl
(make-overlay beg1 block-end
))
5456 (overlay-put ovl
'face
'org-block-background
)
5457 (overlay-put ovl
'evaporate t
)) ;; make it go away when empty
5459 (add-text-properties beg1
(min (point-max) (1+ end1
))
5460 '(face org-block
))) ; end of source block
5461 ((not org-fontify-quote-and-verse-blocks
))
5462 ((string= block-type
"quote")
5463 (add-text-properties beg1
(1+ end1
) '(face org-quote
)))
5464 ((string= block-type
"verse")
5465 (add-text-properties beg1
(1+ end1
) '(face org-verse
))))
5466 (add-text-properties beg beg1
'(face org-block-begin-line
))
5467 (add-text-properties (1+ end
) (1+ end1
) '(face org-block-end-line
))
5469 ((member dc1
'("title:" "author:" "email:" "date:"))
5470 (add-text-properties
5472 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
5473 '(font-lock-fontified t invisible t
)
5474 '(font-lock-fontified t face org-document-info-keyword
)))
5475 (add-text-properties
5476 (match-beginning 6) (match-end 6)
5477 (if (string-equal dc1
"title:")
5478 '(font-lock-fontified t face org-document-title
)
5479 '(font-lock-fontified t face org-document-info
))))
5480 ((not (member (char-after beg
) '(?\ ?
\t)))
5481 ;; just any other in-buffer setting, but not indented
5482 (add-text-properties
5483 beg
(1+ (match-end 0))
5484 '(font-lock-fontified t face org-meta-line
))
5486 ((or (member dc1
'("begin:" "end:" "caption:" "label:"
5487 "orgtbl:" "tblfm:" "tblname:" "results:"
5488 "call:" "header:" "headers:" "name:"))
5489 (and (match-end 4) (equal dc3
"attr")))
5490 (add-text-properties
5492 '(font-lock-fontified t face org-meta-line
))
5494 ((member dc3
'(" " ""))
5495 (add-text-properties
5497 '(font-lock-fontified t face font-lock-comment-face
)))
5500 (defun org-strip-protective-commas (beg end
)
5501 "Strip protective commas between BEG and END in the current buffer."
5506 (let ((front-line (save-excursion
5508 "[^[:space:]]" end t
)
5509 (goto-char (match-beginning 0))
5511 (while (re-search-forward "^[ \t]*\\(,\\)\\([*]\\|#\\+\\)" end t
)
5512 (goto-char (match-beginning 1))
5513 (when (= (current-column) front-line
)
5514 (replace-match "" nil nil nil
1)))))))
5516 (defun org-activate-angle-links (limit)
5517 "Run through the buffer and add overlays to links."
5518 (if (re-search-forward org-angle-link-re limit t
)
5520 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5521 (add-text-properties (match-beginning 0) (match-end 0)
5522 (list 'mouse-face
'highlight
5523 'keymap org-mouse-map
))
5524 (org-rear-nonsticky-at (match-end 0))
5527 (defun org-activate-footnote-links (limit)
5528 "Run through the buffer and add overlays to footnotes."
5529 (let ((fn (org-footnote-next-reference-or-definition limit
)))
5531 (let ((beg (nth 1 fn
)) (end (nth 2 fn
)))
5532 (org-remove-flyspell-overlays-in beg end
)
5533 (add-text-properties beg end
5534 (list 'mouse-face
'highlight
5535 'keymap org-mouse-map
5537 (if (= (point-at-bol) beg
)
5538 "Footnote definition"
5539 "Footnote reference")
5540 'font-lock-fontified t
5541 'font-lock-multiline t
5542 'face
'org-footnote
))))))
5544 (defun org-activate-bracket-links (limit)
5545 "Run through the buffer and add overlays to bracketed links."
5546 (if (re-search-forward org-bracket-link-regexp limit t
)
5547 (let* ((help (concat "LINK: "
5548 (org-match-string-no-properties 1)))
5549 ;; FIXME: above we should remove the escapes.
5550 ;; but that requires another match, protecting match data,
5551 ;; a lot of overhead for font-lock.
5552 (ip (org-maybe-intangible
5553 (list 'invisible
'org-link
5554 'keymap org-mouse-map
'mouse-face
'highlight
5555 'font-lock-multiline t
'help-echo help
)))
5556 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5557 'font-lock-multiline t
'help-echo help
)))
5558 ;; We need to remove the invisible property here. Table narrowing
5559 ;; may have made some of this invisible.
5560 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5561 (remove-text-properties (match-beginning 0) (match-end 0)
5565 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5566 (org-rear-nonsticky-at (match-beginning 3))
5567 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5568 (org-rear-nonsticky-at (match-end 3))
5569 (add-text-properties (match-end 3) (match-end 0) ip
)
5570 (org-rear-nonsticky-at (match-end 0)))
5571 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5572 (org-rear-nonsticky-at (match-beginning 1))
5573 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5574 (org-rear-nonsticky-at (match-end 1))
5575 (add-text-properties (match-end 1) (match-end 0) ip
)
5576 (org-rear-nonsticky-at (match-end 0)))
5579 (defun org-activate-dates (limit)
5580 "Run through the buffer and add overlays to dates."
5581 (if (re-search-forward org-tsr-regexp-both limit t
)
5583 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5584 (add-text-properties (match-beginning 0) (match-end 0)
5585 (list 'mouse-face
'highlight
5586 'keymap org-mouse-map
))
5587 (org-rear-nonsticky-at (match-end 0))
5588 (when org-display-custom-times
5590 (org-display-custom-time (match-beginning 3) (match-end 3)))
5591 (org-display-custom-time (match-beginning 1) (match-end 1)))
5594 (defvar org-target-link-regexp nil
5595 "Regular expression matching radio targets in plain text.")
5596 (make-variable-buffer-local 'org-target-link-regexp
)
5597 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5598 "Regular expression matching a link target.")
5599 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5600 "Regular expression matching a radio target.")
5601 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5602 "Regular expression matching any target.")
5604 (defun org-activate-target-links (limit)
5605 "Run through the buffer and add overlays to target matches."
5606 (when org-target-link-regexp
5607 (let ((case-fold-search t
))
5608 (if (re-search-forward org-target-link-regexp limit t
)
5610 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5611 (add-text-properties (match-beginning 0) (match-end 0)
5612 (list 'mouse-face
'highlight
5613 'keymap org-mouse-map
5614 'help-echo
"Radio target link"
5615 'org-linked-text t
))
5616 (org-rear-nonsticky-at (match-end 0))
5619 (defun org-update-radio-target-regexp ()
5620 "Find all radio targets in this file and update the regular expression."
5622 (when (memq 'radio org-activate-links
)
5623 (setq org-target-link-regexp
5624 (org-make-target-link-regexp (org-all-targets 'radio
)))
5625 (org-restart-font-lock)))
5627 (defun org-hide-wide-columns (limit)
5629 (setq s
(text-property-any (point) (or limit
(point-max))
5632 (setq e
(next-single-property-change s
'org-cwidth
))
5633 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5637 (defvar org-latex-and-specials-regexp nil
5638 "Regular expression for highlighting export special stuff.")
5639 (defvar org-match-substring-regexp
)
5640 (defvar org-match-substring-with-braces-regexp
)
5642 ;; This should be with the exporter code, but we also use if for font-locking
5643 (defconst org-export-html-special-string-regexps
5644 '(("\\\\-" .
"­")
5645 ("---\\([^-]\\)" .
"—\\1")
5646 ("--\\([^-]\\)" .
"–\\1")
5647 ("\\.\\.\\." .
"…"))
5648 "Regular expressions for special string conversion.")
5651 (defun org-compute-latex-and-specials-regexp ()
5652 "Compute regular expression for stuff treated specially by exporters."
5653 (if (not org-highlight-latex-fragments-and-specials
)
5654 (org-set-local 'org-latex-and-specials-regexp nil
)
5657 ((matchers (plist-get org-format-latex-options
:matchers
))
5658 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
5659 org-latex-regexps
)))
5660 (org-export-allow-BIND nil
)
5661 (options (org-combine-plists (org-default-export-plist)
5662 (org-infile-export-plist)))
5663 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
5664 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
5665 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
5666 (org-export-html-expand (plist-get options
:expand-quoted-html
))
5667 (org-export-with-special-strings (plist-get options
:special-strings
))
5670 ((equal org-export-with-sub-superscripts
'{})
5671 (list org-match-substring-with-braces-regexp
))
5672 (org-export-with-sub-superscripts
5673 (list org-match-substring-regexp
))
5676 (if org-export-with-LaTeX-fragments
5677 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
5679 (if org-export-with-TeX-macros
5680 (list (concat "\\\\"
5686 (append org-entities-user
5688 (if (boundp 'org-latex-entities
)
5690 (or (car-safe x
) x
))
5695 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5696 (re-special (if org-export-with-special-strings
5697 (mapcar (lambda (x) (car x
))
5698 org-export-html-special-string-regexps
)))
5702 (if org-export-html-expand
"@<[^>\n]+>")
5705 'org-latex-and-specials-regexp
5706 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5709 (defun org-do-latex-and-special-faces (limit)
5710 "Run through the buffer and add overlays to links."
5711 (when org-latex-and-specials-regexp
5713 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5715 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5717 '(org-code org-verbatim underline
)))
5720 d
(cond ((member (char-after (1+ (match-beginning 0)))
5723 (font-lock-prepend-text-property
5724 (+ d
(match-beginning 0)) (match-end 0)
5725 'face
'org-latex-and-export-specials
)
5726 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5727 '(font-lock-multiline t
)))))
5730 (defun org-restart-font-lock ()
5731 "Restart `font-lock-mode', to force refontification."
5732 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5734 (font-lock-mode 1)))
5736 (defun org-all-targets (&optional radio
)
5737 "Return a list of all targets in this file.
5738 With optional argument RADIO, only find radio targets."
5739 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5742 (goto-char (point-min))
5743 (while (re-search-forward re nil t
)
5744 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5747 (defun org-make-target-link-regexp (targets)
5748 "Make regular expression matching all strings in TARGETS.
5749 The regular expression finds the targets also if there is a line break
5756 (setq x
(regexp-quote x
))
5757 (while (string-match " +" x
)
5758 (setq x
(replace-match "\\s-+" t t x
)))
5764 (defun org-activate-tags (limit)
5765 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t
)
5767 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5768 (add-text-properties (match-beginning 1) (match-end 1)
5769 (list 'mouse-face
'highlight
5770 'keymap org-mouse-map
))
5771 (org-rear-nonsticky-at (match-end 1))
5774 (defun org-outline-level ()
5775 "Compute the outline level of the heading at point.
5776 This function assumes that the cursor is at the beginning of a line matched
5777 by `outline-regexp'. Otherwise it returns garbage.
5778 If this is called at a normal headline, the level is the number of stars.
5779 Use `org-reduced-level' to remove the effect of `org-odd-levels'."
5781 (looking-at org-outline-regexp
)
5782 (1- (- (match-end 0) (match-beginning 0)))))
5784 (defvar org-font-lock-keywords nil
)
5786 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\+?\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5787 "Regular expression matching a property line.")
5789 (defvar org-font-lock-hook nil
5790 "Functions to be called for special font lock stuff.")
5792 (defvar org-font-lock-set-keywords-hook nil
5793 "Functions that can manipulate `org-font-lock-extra-keywords'.
5794 This is called after `org-font-lock-extra-keywords' is defined, but before
5795 it is installed to be used by font lock. This can be useful if something
5796 needs to be inserted at a specific position in the font-lock sequence.")
5798 (defun org-font-lock-hook (limit)
5799 (run-hook-with-args 'org-font-lock-hook limit
))
5801 (defun org-set-font-lock-defaults ()
5802 (let* ((em org-fontify-emphasized-text
)
5803 (lk org-activate-links
)
5804 (org-font-lock-extra-keywords
5807 '(org-font-lock-hook)
5809 `(,(if org-fontify-whole-heading-line
5810 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5811 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5812 (1 (org-get-level-face 1))
5813 (2 (org-get-level-face 2))
5814 (3 (org-get-level-face 3)))
5816 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5819 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5820 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5821 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5822 '("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t
))
5824 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5825 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5827 (list org-property-re
5828 '(1 'org-special-keyword t
)
5829 '(3 'org-property-value t
))
5831 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5832 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5833 (if (memq 'plain lk
) '(org-activate-plain-links))
5834 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5835 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5836 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5837 (if (memq 'footnote lk
) '(org-activate-footnote-links))
5838 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5839 '(org-hide-wide-columns (0 nil append
))
5841 (list (format org-heading-keyword-regexp-format
5843 '(2 (org-get-todo-face 2) t
))
5845 (if org-fontify-done-headline
5846 (list (format org-heading-keyword-regexp-format
5849 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5851 '(2 'org-headline-done t
))
5854 '(org-font-lock-add-priority-faces)
5856 '(org-font-lock-add-tag-faces)
5858 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5859 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5860 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5861 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5864 (if (featurep 'xemacs
)
5865 '(org-do-emphasis-faces (0 nil append
))
5866 '(org-do-emphasis-faces)))
5868 '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
5869 1 'org-checkbox prepend
)
5870 (if (cdr (assq 'checkbox org-list-automatic-rules
))
5871 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5872 (0 (org-get-checkbox-statistics-face) t
)))
5873 ;; Description list items
5874 '("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+::\\)\\([ \t]+\\|$\\)"
5876 ;; ARCHIVEd headings
5878 org-outline-regexp-bol
5879 "\\(.*:" org-archive-tag
":.*\\)")
5880 '(1 'org-archived prepend
))
5882 '(org-do-latex-and-special-faces)
5883 '(org-fontify-entities)
5884 '(org-raise-scripts)
5886 '(org-activate-code (1 'org-code t
))
5888 (list (format org-heading-keyword-regexp-format
5890 org-comment-string
"\\|" org-quote-string
5892 '(2 'org-special-keyword t
))
5893 '("^#.*" (0 'font-lock-comment-face t
))
5894 ;; Blocks and meta lines
5895 '(org-fontify-meta-lines-and-blocks)
5897 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5898 (run-hooks 'org-font-lock-set-keywords-hook
)
5899 ;; Now set the full font-lock-keywords
5900 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5901 (org-set-local 'font-lock-defaults
5902 '(org-font-lock-keywords t nil nil backward-paragraph
))
5903 (kill-local-variable 'font-lock-keywords
) nil
))
5905 (defun org-toggle-pretty-entities ()
5906 "Toggle the composition display of entities as UTF8 characters."
5908 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
5909 (org-restart-font-lock)
5910 (if org-pretty-entities
5911 (message "Entities are displayed as UTF8 characters")
5914 (org-decompose-region (point-min) (point-max))
5915 (message "Entities are displayed plain"))))
5917 (defun org-fontify-entities (limit)
5918 "Find an entity to fontify."
5920 (when org-pretty-entities
5922 (while (re-search-forward
5923 "\\\\\\(frac[13][24]\\|[a-zA-Z]+\\)\\($\\|[^[:alpha:]\n]\\)"
5925 (if (and (not (org-in-indented-comment-line))
5926 (setq ee
(org-entity-get (match-string 1)))
5927 (= (length (nth 6 ee
)) 1))
5929 (add-text-properties
5930 (match-beginning 0) (match-end 1)
5931 (list 'font-lock-fontified t
))
5932 (compose-region (match-beginning 0) (match-end 1)
5938 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
5939 "Fontify string S like in Org-mode."
5942 (let ((org-odd-levels-only odd-levels
))
5944 (font-lock-fontify-buffer)
5950 (defun org-get-level-face (n)
5951 "Get the right face for match N in font-lock matching of headlines."
5952 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
5953 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
5954 (if org-cycle-level-faces
5955 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
5956 (setq org-f
(nth (1- (min org-l org-n-level-faces
)) org-level-faces
)))
5958 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
5960 (t (if org-level-color-stars-only nil org-f
))))
5963 (defun org-get-todo-face (kwd)
5964 "Get the right face for a TODO keyword KWD.
5965 If KWD is a number, get the corresponding match group."
5966 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
5967 (or (org-face-from-face-or-color
5968 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
5969 (and (member kwd org-done-keywords
) 'org-done
)
5972 (defun org-face-from-face-or-color (context inherit face-or-color
)
5973 "Create a face list that inherits INHERIT, but sets the foreground color.
5974 When FACE-OR-COLOR is not a string, just return it."
5975 (if (stringp face-or-color
)
5976 (list :inherit inherit
5977 (cdr (assoc context org-faces-easy-properties
))
5981 (defun org-font-lock-add-tag-faces (limit)
5982 "Add the special tag faces."
5983 (when (and org-tag-faces org-tags-special-faces-re
)
5984 (while (re-search-forward org-tags-special-faces-re limit t
)
5985 (add-text-properties (match-beginning 1) (match-end 1)
5986 (list 'face
(org-get-tag-face 1)
5987 'font-lock-fontified t
))
5988 (backward-char 1))))
5990 (defun org-font-lock-add-priority-faces (limit)
5991 "Add the special priority faces."
5992 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
5993 (add-text-properties
5994 (match-beginning 0) (match-end 0)
5995 (list 'face
(or (org-face-from-face-or-color
5996 'priority
'org-special-keyword
5997 (cdr (assoc (char-after (match-beginning 1))
5998 org-priority-faces
)))
5999 'org-special-keyword
)
6000 'font-lock-fontified t
))))
6002 (defun org-get-tag-face (kwd)
6003 "Get the right face for a TODO keyword KWD.
6004 If KWD is a number, get the corresponding match group."
6005 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
6006 (or (org-face-from-face-or-color
6007 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
6010 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
6011 "Remove fontification and activation overlays from links."
6012 (font-lock-default-unfontify-region beg end
)
6013 (let* ((buffer-undo-list t
)
6014 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
6015 (inhibit-modification-hooks t
)
6016 deactivate-mark buffer-file-name buffer-file-truename
)
6017 (org-decompose-region beg end
)
6018 (remove-text-properties beg end
6019 '(mouse-face t keymap t org-linked-text t
6020 invisible t intangible t
6021 org-no-flyspell t org-emphasis t
))
6022 (org-remove-font-lock-display-properties beg end
)))
6024 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
6025 ((raise 0.3) (height 0.7))
6028 "Display properties for showing superscripts and subscripts.")
6030 (defun org-remove-font-lock-display-properties (beg end
)
6031 "Remove specific display properties that have been added by font lock.
6032 The will remove the raise properties that are used to show superscripts
6036 (setq next
(next-single-property-change beg
'display nil end
)
6037 prop
(get-text-property beg
'display
))
6038 (if (member prop org-script-display
)
6039 (put-text-property beg next
'display nil
))
6042 (defun org-raise-scripts (limit)
6043 "Add raise properties to sub/superscripts."
6044 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
6045 (if (re-search-forward
6046 (if (eq org-use-sub-superscripts t
)
6047 org-match-substring-regexp
6048 org-match-substring-with-braces-regexp
)
6050 (let* ((pos (point)) table-p comment-p
6051 (mpos (match-beginning 3))
6052 (emph-p (get-text-property mpos
'org-emphasis
))
6053 (link-p (get-text-property mpos
'mouse-face
))
6054 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
6055 (goto-char (point-at-bol))
6056 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
6057 comment-p
(org-looking-at-p "[ \t]*#"))
6059 ;; FIXME: Should we go back one character here, for a_b^c
6060 ;; (goto-char (1- pos)) ;????????????????????
6061 (if (or comment-p emph-p link-p keyw-p
)
6063 (put-text-property (match-beginning 3) (match-end 0)
6065 (if (equal (char-after (match-beginning 2)) ?^
)
6066 (nth (if table-p
3 1) org-script-display
)
6067 (nth (if table-p
2 0) org-script-display
)))
6068 (add-text-properties (match-beginning 2) (match-end 2)
6070 'org-dwidth t
'org-dwidth-n
1))
6071 (if (and (eq (char-after (match-beginning 3)) ?
{)
6072 (eq (char-before (match-end 3)) ?
}))
6074 (add-text-properties
6075 (match-beginning 3) (1+ (match-beginning 3))
6076 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
6077 (add-text-properties
6078 (1- (match-end 3)) (match-end 3)
6079 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
6082 ;;;; Visibility cycling, including org-goto and indirect buffer
6086 (defvar org-cycle-global-status nil
)
6087 (make-variable-buffer-local 'org-cycle-global-status
)
6088 (defvar org-cycle-subtree-status nil
)
6089 (make-variable-buffer-local 'org-cycle-subtree-status
)
6093 (defvar org-inlinetask-min-level
)
6095 (defun org-cycle (&optional arg
)
6096 "TAB-action and visibility cycling for Org-mode.
6098 This is the command invoked in Org-mode by the TAB key. Its main purpose
6099 is outline visibility cycling, but it also invokes other actions
6100 in special contexts.
6102 - When this function is called with a prefix argument, rotate the entire
6103 buffer through 3 states (global cycling)
6104 1. OVERVIEW: Show only top-level headlines.
6105 2. CONTENTS: Show all headlines of all levels, but no body text.
6106 3. SHOW ALL: Show everything.
6107 When called with two `C-u C-u' prefixes, switch to the startup visibility,
6108 determined by the variable `org-startup-folded', and by any VISIBILITY
6109 properties in the buffer.
6110 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
6111 including any drawers.
6113 - When inside a table, re-align the table and move to the next field.
6115 - When point is at the beginning of a headline, rotate the subtree started
6116 by this line through 3 different states (local cycling)
6117 1. FOLDED: Only the main headline is shown.
6118 2. CHILDREN: The main headline and the direct children are shown.
6119 From this state, you can move to one of the children
6120 and zoom in further.
6121 3. SUBTREE: Show the entire subtree, including body text.
6122 If there is no subtree, switch directly from CHILDREN to FOLDED.
6124 - When point is at the beginning of an empty headline and the variable
6125 `org-cycle-level-after-item/entry-creation' is set, cycle the level
6126 of the headline by demoting and promoting it to likely levels. This
6127 speeds up creation document structure by pressing TAB once or several
6128 times right after creating a new headline.
6130 - When there is a numeric prefix, go up to a heading with level ARG, do
6131 a `show-subtree' and return to the previous cursor position. If ARG
6132 is negative, go up that many levels.
6134 - When point is not at the beginning of a headline, execute the global
6135 binding for TAB, which is re-indenting the line. See the option
6136 `org-cycle-emulate-tab' for details.
6138 - Special case: if point is at the beginning of the buffer and there is
6139 no headline in line 1, this function will act as if called with prefix arg
6140 (C-u TAB, same as S-TAB) also when called without prefix arg.
6141 But only if also the variable `org-cycle-global-at-bob' is t."
6143 (org-load-modules-maybe)
6144 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
6145 (and org-cycle-level-after-item
/entry-creation
6146 (or (org-cycle-level)
6147 (org-cycle-item-indentation))))
6149 (or org-cycle-max-level
6150 (and (boundp 'org-inlinetask-min-level
)
6151 org-inlinetask-min-level
6152 (1- org-inlinetask-min-level
))))
6153 (nstars (and limit-level
6154 (if org-odd-levels-only
6155 (and limit-level
(1- (* limit-level
2)))
6158 (if (not (eq major-mode
'org-mode
))
6160 (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ "))))
6161 (bob-special (and org-cycle-global-at-bob
(not arg
) (bobp)
6162 (not (looking-at org-outline-regexp
))))
6165 (delq 'org-optimize-window-after-visibility-change
6166 (copy-sequence org-cycle-hook
))
6170 (if (or bob-special
(equal arg
'(4)))
6171 ;; special case: use global cycling
6177 (setq last-command
'dummy
)
6178 (org-set-startup-visibility)
6179 (message "Startup visibility, plus VISIBILITY properties"))
6183 (message "Entire buffer visible, including drawers"))
6185 ;; Table: enter it or move to the next field.
6186 ((org-at-table-p 'any
)
6187 (if (org-at-table.el-p
)
6188 (message "Use C-c ' to edit table.el tables")
6189 (if arg
(org-table-edit-field t
)
6190 (org-table-justify-field-maybe)
6191 (call-interactively 'org-table-next-field
))))
6193 ((run-hook-with-args-until-success
6194 'org-tab-after-check-for-table-hook
))
6196 ;; Global cycling: delegate to `org-cycle-internal-global'.
6197 ((eq arg t
) (org-cycle-internal-global))
6199 ;; Drawers: delegate to `org-flag-drawer'.
6200 ((and org-drawers org-drawer-regexp
6202 (beginning-of-line 1)
6203 (looking-at org-drawer-regexp
)))
6204 (org-flag-drawer ; toggle block visibility
6205 (not (get-char-property (match-end 0) 'invisible
))))
6207 ;; Show-subtree, ARG levels up from here.
6210 (org-back-to-heading)
6211 (outline-up-heading (if (< arg
0) (- arg
)
6212 (- (funcall outline-level
) arg
)))
6213 (org-show-subtree)))
6215 ;; Inline task: delegate to `org-inlinetask-toggle-visibility'.
6216 ((and (featurep 'org-inlinetask
)
6217 (org-inlinetask-at-task-p)
6218 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6219 (org-inlinetask-toggle-visibility))
6221 ((org-try-cdlatex-tab))
6223 ;; At an item/headline: delegate to `org-cycle-internal-local'.
6224 ((and (or (and org-cycle-include-plain-lists
(org-at-item-p))
6225 (save-excursion (beginning-of-line 1)
6226 (looking-at org-outline-regexp
)))
6227 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6228 (org-cycle-internal-local))
6230 ;; From there: TAB emulation and template completion.
6231 (buffer-read-only (org-back-to-heading))
6233 ((run-hook-with-args-until-success
6234 'org-tab-after-check-for-cycling-hook
))
6236 ((org-try-structure-completion))
6238 ((run-hook-with-args-until-success
6239 'org-tab-before-tab-emulation-hook
))
6241 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
6243 (not (looking-at org-outline-regexp
))))
6244 (call-interactively (global-key-binding "\t")))
6246 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
6247 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
6248 (or (and (eq org-cycle-emulate-tab
'white
)
6249 (= (match-end 0) (point-at-eol)))
6250 (and (eq org-cycle-emulate-tab
'whitestart
)
6251 (>= (match-end 0) pos
))))
6253 (eq org-cycle-emulate-tab t
))
6254 (call-interactively (global-key-binding "\t")))
6257 (org-back-to-heading)
6260 (defun org-cycle-internal-global ()
6261 "Do the global cycling action."
6262 ;; Hack to avoid display of messages for .org attachments in Gnus
6263 (let ((ga (string-match "\\*fontification" (buffer-name))))
6265 ((and (eq last-command this-command
)
6266 (eq org-cycle-global-status
'overview
))
6267 ;; We just created the overview - now do table of contents
6268 ;; This can be slow in very large buffers, so indicate action
6269 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
6270 (unless ga
(message "CONTENTS..."))
6272 (unless ga
(message "CONTENTS...done"))
6273 (setq org-cycle-global-status
'contents
)
6274 (run-hook-with-args 'org-cycle-hook
'contents
))
6276 ((and (eq last-command this-command
)
6277 (eq org-cycle-global-status
'contents
))
6278 ;; We just showed the table of contents - now show everything
6279 (run-hook-with-args 'org-pre-cycle-hook
'all
)
6281 (unless ga
(message "SHOW ALL"))
6282 (setq org-cycle-global-status
'all
)
6283 (run-hook-with-args 'org-cycle-hook
'all
))
6286 ;; Default action: go to overview
6287 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
6289 (unless ga
(message "OVERVIEW"))
6290 (setq org-cycle-global-status
'overview
)
6291 (run-hook-with-args 'org-cycle-hook
'overview
)))))
6293 (defun org-cycle-internal-local ()
6294 "Do the local cycling action."
6295 (let ((goal-column 0) eoh eol eos has-children children-skipped struct
)
6296 ;; First, determine end of headline (EOH), end of subtree or item
6297 ;; (EOS), and if item or heading has children (HAS-CHILDREN).
6302 (setq struct
(org-list-struct))
6303 (setq eoh
(point-at-eol))
6304 (setq eos
(org-list-get-item-end-before-blank (point) struct
))
6305 (setq has-children
(org-list-has-child-p (point) struct
)))
6306 (org-back-to-heading)
6307 (setq eoh
(save-excursion (outline-end-of-heading) (point)))
6308 (setq eos
(save-excursion
6309 (org-end-of-subtree t
)
6311 (skip-chars-forward " \t\n"))
6312 (if (eobp) (point) (1- (point)))))
6315 (let ((level (funcall outline-level
)))
6316 (outline-next-heading)
6317 (and (org-at-heading-p t
)
6318 (> (funcall outline-level
) level
))))
6320 (org-list-search-forward (org-item-beginning-re) eos t
)))))
6321 ;; Determine end invisible part of buffer (EOL)
6322 (beginning-of-line 2)
6323 ;; XEmacs doesn't have `next-single-char-property-change'
6324 (if (featurep 'xemacs
)
6325 (while (and (not (eobp)) ;; this is like `next-line'
6326 (get-char-property (1- (point)) 'invisible
))
6327 (beginning-of-line 2))
6328 (while (and (not (eobp)) ;; this is like `next-line'
6329 (get-char-property (1- (point)) 'invisible
))
6330 (goto-char (next-single-char-property-change (point) 'invisible
))
6331 (and (eolp) (beginning-of-line 2))))
6333 ;; Find out what to do next and set `this-command'
6336 ;; Nothing is hidden behind this heading
6337 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
6338 (message "EMPTY ENTRY")
6339 (setq org-cycle-subtree-status nil
)
6342 (outline-next-heading)
6343 (if (outline-invisible-p) (org-flag-heading nil
))))
6344 ((and (or (>= eol eos
)
6345 (not (string-match "\\S-" (buffer-substring eol eos
))))
6347 (not (setq children-skipped
6348 org-cycle-skip-children-state-if-no-children
))))
6349 ;; Entire subtree is hidden in one line: children view
6350 (run-hook-with-args 'org-pre-cycle-hook
'children
)
6352 (org-list-set-item-visibility (point-at-bol) struct
'children
)
6354 (org-with-limited-levels (show-children))
6355 (when (memq 'org-cycle-hide-drawers org-cycle-hook
)
6356 (org-cycle-hide-drawers 'subtree
))
6357 ;; Fold every list in subtree to top-level items.
6358 (when (eq org-cycle-include-plain-lists
'integrate
)
6360 (org-back-to-heading)
6361 (while (org-list-search-forward (org-item-beginning-re) eos t
)
6362 (beginning-of-line 1)
6363 (let* ((struct (org-list-struct))
6364 (prevs (org-list-prevs-alist struct
))
6365 (end (org-list-get-bottom-point struct
)))
6366 (mapc (lambda (e) (org-list-set-item-visibility e struct
'folded
))
6367 (org-list-get-all-items (point) struct prevs
))
6368 (goto-char end
))))))
6369 (message "CHILDREN")
6372 (outline-next-heading)
6373 (if (outline-invisible-p) (org-flag-heading nil
)))
6374 (setq org-cycle-subtree-status
'children
)
6375 (run-hook-with-args 'org-cycle-hook
'children
))
6376 ((or children-skipped
6377 (and (eq last-command this-command
)
6378 (eq org-cycle-subtree-status
'children
)))
6379 ;; We just showed the children, or no children are there,
6380 ;; now show everything.
6381 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
6382 (outline-flag-region eoh eos nil
)
6383 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
6384 (setq org-cycle-subtree-status
'subtree
)
6385 (run-hook-with-args 'org-cycle-hook
'subtree
))
6387 ;; Default action: hide the subtree.
6388 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
6389 (outline-flag-region eoh eos t
)
6391 (setq org-cycle-subtree-status
'folded
)
6392 (run-hook-with-args 'org-cycle-hook
'folded
)))))
6395 (defun org-global-cycle (&optional arg
)
6396 "Cycle the global visibility. For details see `org-cycle'.
6397 With \\[universal-argument] prefix arg, switch to startup visibility.
6398 With a numeric prefix, show all headlines up to that level."
6400 (let ((org-cycle-include-plain-lists
6401 (if (eq major-mode
'org-mode
) org-cycle-include-plain-lists nil
)))
6405 (hide-sublevels arg
)
6406 (setq org-cycle-global-status
'contents
))
6408 (org-set-startup-visibility)
6409 (message "Startup visibility, plus VISIBILITY properties."))
6411 (org-cycle '(4))))))
6413 (defun org-set-startup-visibility ()
6414 "Set the visibility required by startup options and properties."
6416 ((eq org-startup-folded t
)
6418 ((eq org-startup-folded
'content
)
6419 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
6420 (org-cycle '(4)) (org-cycle '(4)))))
6421 (unless (eq org-startup-folded
'showeverything
)
6422 (if org-hide-block-startup
(org-hide-block-all))
6423 (org-set-visibility-according-to-property 'no-cleanup
)
6424 (org-cycle-hide-archived-subtrees 'all
)
6425 (org-cycle-hide-drawers 'all
)
6426 (org-cycle-show-empty-lines t
)))
6428 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
6429 "Switch subtree visibilities according to :VISIBILITY: property."
6431 (let (org-show-entry-below state
)
6433 (goto-char (point-min))
6434 (while (re-search-forward
6435 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
6437 (setq state
(match-string 1))
6439 (org-back-to-heading t
)
6443 ((equal state
'("fold" "folded"))
6445 ((equal state
"children")
6446 (org-show-hidden-entry)
6448 ((equal state
"content")
6451 (org-narrow-to-subtree)
6453 ((member state
'("all" "showall"))
6456 (org-cycle-hide-archived-subtrees 'all
)
6457 (org-cycle-hide-drawers 'all
)
6458 (org-cycle-show-empty-lines 'all
)))))
6460 ;; This function uses outline-regexp instead of the more fundamental
6461 ;; org-outline-regexp so that org-cycle-global works outside of Org
6462 ;; buffers, where outline-regexp is needed.
6463 (defun org-overview ()
6464 "Switch to overview mode, showing only top-level headlines.
6465 Really, this shows all headlines with level equal or greater than the level
6466 of the first headline in the buffer. This is important, because if the
6467 first headline is not level one, then (hide-sublevels 1) gives confusing
6470 (let ((level (save-excursion
6471 (goto-char (point-min))
6472 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
6474 (goto-char (match-beginning 0))
6475 (funcall outline-level
))))))
6476 (and level
(hide-sublevels level
))))
6478 (defun org-content (&optional arg
)
6479 "Show all headlines in the buffer, like a table of contents.
6480 With numerical argument N, show content up to level N."
6483 ;; Visit all headings and show their offspring
6484 (and (integerp arg
) (org-overview))
6485 (goto-char (point-max))
6487 (while (and (progn (condition-case nil
6488 (outline-previous-visible-heading 1)
6489 (error (goto-char (point-min))))
6491 (looking-at org-outline-regexp
))
6493 (show-children (1- arg
))
6495 (if (bobp) (throw 'exit nil
))))))
6498 (defun org-optimize-window-after-visibility-change (state)
6499 "Adjust the window after a change in outline visibility.
6500 This function is the default value of the hook `org-cycle-hook'."
6501 (when (get-buffer-window (current-buffer))
6503 ((eq state
'content
) nil
)
6504 ((eq state
'all
) nil
)
6505 ((eq state
'folded
) nil
)
6506 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
6507 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
6509 (defun org-remove-empty-overlays-at (pos)
6510 "Remove outline overlays that do not contain non-white stuff."
6513 (and (eq 'outline
(overlay-get o
'invisible
))
6514 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
6516 (delete-overlay o
)))
6519 (defun org-clean-visibility-after-subtree-move ()
6520 "Fix visibility issues after moving a subtree."
6521 ;; First, find a reasonable region to look at:
6522 ;; Start two siblings above, end three below
6523 (let* ((beg (save-excursion
6524 (and (org-get-last-sibling)
6525 (org-get-last-sibling))
6527 (end (save-excursion
6528 (and (org-get-next-sibling)
6529 (org-get-next-sibling)
6530 (org-get-next-sibling))
6531 (if (org-at-heading-p)
6534 (level (looking-at "\\*+"))
6535 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6538 (narrow-to-region beg end
)
6540 ;; Properly fold already folded siblings
6541 (goto-char (point-min))
6542 (while (re-search-forward re nil t
)
6543 (if (and (not (outline-invisible-p))
6545 (goto-char (point-at-eol)) (outline-invisible-p)))
6547 (org-cycle-show-empty-lines 'overview
)
6548 (org-cycle-hide-drawers 'overview
)))))
6550 (defun org-cycle-show-empty-lines (state)
6551 "Show empty lines above all visible headlines.
6552 The region to be covered depends on STATE when called through
6553 `org-cycle-hook'. Lisp program can use t for STATE to get the
6554 entire buffer covered. Note that an empty line is only shown if there
6555 are at least `org-cycle-separator-lines' empty lines before the headline."
6556 (when (not (= org-cycle-separator-lines
0))
6558 (let* ((n (abs org-cycle-separator-lines
))
6560 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6561 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6562 (t (let ((ns (number-to-string (- n
2))))
6563 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6564 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6567 ((memq state
'(overview contents t
))
6568 (setq beg
(point-min) end
(point-max)))
6569 ((memq state
'(children folded
))
6570 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6571 (beginning-of-line 2)
6575 (while (re-search-forward re end t
)
6576 (unless (get-char-property (match-end 1) 'invisible
)
6577 (setq e
(match-end 1))
6578 (if (< org-cycle-separator-lines
0)
6579 (setq b
(save-excursion
6580 (goto-char (match-beginning 0))
6581 (org-back-over-empty-lines)
6583 (goto-char (max (point-min) (1- (point))))
6587 (setq b
(match-beginning 1)))
6588 (outline-flag-region b e nil
)))))))
6589 ;; Never hide empty lines at the end of the file.
6591 (goto-char (point-max))
6592 (outline-previous-heading)
6593 (outline-end-of-heading)
6594 (if (and (looking-at "[ \t\n]+")
6595 (= (match-end 0) (point-max)))
6596 (outline-flag-region (point) (match-end 0) nil
))))
6598 (defun org-show-empty-lines-in-parent ()
6599 "Move to the parent and re-show empty lines before visible headlines."
6601 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6602 (org-cycle-show-empty-lines context
))))
6604 (defun org-files-list ()
6605 "Return `org-agenda-files' list, plus all open org-mode files.
6606 This is useful for operations that need to scan all of a user's
6607 open and agenda-wise Org files."
6608 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6609 (dolist (buf (buffer-list))
6610 (with-current-buffer buf
6611 (if (and (eq major-mode
'org-mode
) (buffer-file-name))
6612 (let ((file (expand-file-name (buffer-file-name))))
6613 (unless (member file files
)
6614 (push file files
))))))
6617 (defsubst org-entry-beginning-position
()
6618 "Return the beginning position of the current entry."
6619 (save-excursion (outline-back-to-heading t
) (point)))
6621 (defsubst org-entry-end-position
()
6622 "Return the end position of the current entry."
6623 (save-excursion (outline-next-heading) (point)))
6625 (defun org-cycle-hide-drawers (state)
6626 "Re-hide all drawers after a visibility state change."
6627 (when (and (eq major-mode
'org-mode
)
6628 (not (memq state
'(overview folded contents
))))
6630 (let* ((globalp (memq state
'(contents all
)))
6631 (beg (if globalp
(point-min) (point)))
6632 (end (if globalp
(point-max)
6633 (if (eq state
'children
)
6634 (save-excursion (outline-next-heading) (point))
6635 (org-end-of-subtree t
)))))
6637 (while (re-search-forward org-drawer-regexp end t
)
6638 (org-flag-drawer t
))))))
6640 (defun org-flag-drawer (flag)
6642 (beginning-of-line 1)
6643 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6644 (let ((b (match-end 0)))
6645 (if (re-search-forward
6647 (save-excursion (outline-next-heading) (point)) t
)
6648 (outline-flag-region b
(point-at-eol) flag
)
6649 (error ":END: line missing at position %s" b
))))))
6651 (defun org-subtree-end-visible-p ()
6652 "Is the end of the current subtree visible?"
6653 (pos-visible-in-window-p
6654 (save-excursion (org-end-of-subtree t
) (point))))
6656 (defun org-first-headline-recenter (&optional N
)
6657 "Move cursor to the first headline and recenter the headline.
6658 Optional argument N means put the headline into the Nth line of the window."
6659 (goto-char (point-min))
6660 (when (re-search-forward (concat "^\\(" org-outline-regexp
"\\)") nil t
)
6662 (recenter (prefix-numeric-value N
))))
6664 ;;; Saving and restoring visibility
6666 (defun org-outline-overlay-data (&optional use-markers
)
6667 "Return a list of the locations of all outline overlays.
6668 These are overlays with the `invisible' property value `outline'.
6669 The return value is a list of cons cells, with start and stop
6670 positions for each overlay.
6671 If USE-MARKERS is set, return the positions as markers."
6678 (when (eq (overlay-get o
'invisible
) 'outline
)
6679 (setq beg
(overlay-start o
)
6680 end
(overlay-end o
))
6681 (and beg end
(> end beg
)
6683 (cons (move-marker (make-marker) beg
)
6684 (move-marker (make-marker) end
))
6686 (overlays-in (point-min) (point-max))))))))
6688 (defun org-set-outline-overlay-data (data)
6689 "Create visibility overlays for all positions in DATA.
6690 DATA should have been made by `org-outline-overlay-data'."
6697 (outline-flag-region (car c
) (cdr c
) t
))
6700 ;;; Folding of blocks
6702 (defvar org-hide-block-overlays nil
6703 "Overlays hiding blocks.")
6704 (make-variable-buffer-local 'org-hide-block-overlays
)
6706 (defun org-block-map (function &optional start end
)
6707 "Call FUNCTION at the head of all source blocks in the current buffer.
6708 Optional arguments START and END can be used to limit the range."
6709 (let ((start (or start
(point-min)))
6710 (end (or end
(point-max))))
6713 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6716 (goto-char (match-beginning 0))
6717 (funcall function
)))))))
6719 (defun org-hide-block-toggle-all ()
6720 "Toggle the visibility of all blocks in the current buffer."
6721 (org-block-map #'org-hide-block-toggle
))
6723 (defun org-hide-block-all ()
6724 "Fold all blocks in the current buffer."
6726 (org-show-block-all)
6727 (org-block-map #'org-hide-block-toggle-maybe
))
6729 (defun org-show-block-all ()
6730 "Unfold all blocks in the current buffer."
6732 (mapc 'delete-overlay org-hide-block-overlays
)
6733 (setq org-hide-block-overlays nil
))
6735 (defun org-hide-block-toggle-maybe ()
6736 "Toggle visibility of block at point."
6738 (let ((case-fold-search t
))
6740 (beginning-of-line 1)
6741 (looking-at org-block-regexp
))
6742 (progn (org-hide-block-toggle)
6743 t
) ;; to signal that we took action
6744 nil
))) ;; to signal that we did not
6746 (defun org-hide-block-toggle (&optional force
)
6747 "Toggle the visibility of the current block."
6751 (if (re-search-forward org-block-regexp nil t
)
6752 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6753 (end (match-end 0)) ;; end of entire body
6755 (if (memq t
(mapcar (lambda (overlay)
6756 (eq (overlay-get overlay
'invisible
)
6758 (overlays-at start
)))
6759 (if (or (not force
) (eq force
'off
))
6761 (when (member ov org-hide-block-overlays
)
6762 (setq org-hide-block-overlays
6763 (delq ov org-hide-block-overlays
)))
6764 (when (eq (overlay-get ov
'invisible
)
6766 (delete-overlay ov
)))
6767 (overlays-at start
)))
6768 (setq ov
(make-overlay start end
))
6769 (overlay-put ov
'invisible
'org-hide-block
)
6770 ;; make the block accessible to isearch
6772 ov
'isearch-open-invisible
6774 (when (member ov org-hide-block-overlays
)
6775 (setq org-hide-block-overlays
6776 (delq ov org-hide-block-overlays
)))
6777 (when (eq (overlay-get ov
'invisible
)
6779 (delete-overlay ov
))))
6780 (push ov org-hide-block-overlays
)))
6781 (error "Not looking at a source block"))))
6783 ;; org-tab-after-check-for-cycling-hook
6784 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6785 ;; Remove overlays when changing major mode
6786 (add-hook 'org-mode-hook
6787 (lambda () (org-add-hook 'change-major-mode-hook
6788 'org-show-block-all
'append
'local
)))
6792 (defvar org-goto-window-configuration nil
)
6793 (defvar org-goto-marker nil
)
6794 (defvar org-goto-map
6795 (let ((map (make-sparse-keymap)))
6796 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6797 (while (setq cmd
(pop cmds
))
6798 (substitute-key-definition cmd cmd map global-map
)))
6799 (suppress-keymap map
)
6800 (org-defkey map
"\C-m" 'org-goto-ret
)
6801 (org-defkey map
[(return)] 'org-goto-ret
)
6802 (org-defkey map
[(left)] 'org-goto-left
)
6803 (org-defkey map
[(right)] 'org-goto-right
)
6804 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6805 (org-defkey map
"\C-i" 'org-cycle
)
6806 (org-defkey map
[(tab)] 'org-cycle
)
6807 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6808 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6809 (if org-goto-auto-isearch
6810 (if (fboundp 'define-key-after
)
6811 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6813 (org-defkey map "q" 'org-goto-quit)
6814 (org-defkey map "n" 'outline-next-visible-heading)
6815 (org-defkey map "p" 'outline-previous-visible-heading)
6816 (org-defkey map "f" 'outline-forward-same-level)
6817 (org-defkey map "b" 'outline-backward-same-level)
6818 (org-defkey map "u" 'outline-up-heading))
6819 (org-defkey map "/" 'org-occur)
6820 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6821 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6822 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6823 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6824 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6827 (defconst org-goto-help
6828 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6829 RET=jump to location [Q]uit and return to previous location
6830 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6832 (defvar org-goto-start-pos) ; dynamically scoped parameter
6834 ;; FIXME: Docstring does not mention both interfaces
6835 (defun org-goto (&optional alternative-interface)
6836 "Look up a different location in the current file, keeping current visibility.
6838 When you want look-up or go to a different location in a document, the
6839 fastest way is often to fold the entire buffer and then dive into the tree.
6840 This method has the disadvantage, that the previous location will be folded,
6841 which may not be what you want.
6843 This command works around this by showing a copy of the current buffer
6844 in an indirect buffer, in overview mode. You can dive into the tree in
6845 that copy, use org-occur and incremental search to find a location.
6846 When pressing RET or `Q', the command returns to the original buffer in
6847 which the visibility is still unchanged. After RET is will also jump to
6848 the location selected in the indirect buffer and expose the headline
6851 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6852 (org-refile-use-outline-path t)
6853 (org-refile-target-verify-function nil)
6855 (if (not alternative-interface)
6857 (if (eq org-goto-interface 'outline)
6858 'outline-path-completion
6860 (org-goto-start-pos (point))
6862 (if (eq interface 'outline)
6863 (car (org-get-location (current-buffer) org-goto-help))
6864 (let ((pa (org-refile-get-location "Goto" nil nil t)))
6865 (org-refile-check-position pa)
6869 (org-mark-ring-push org-goto-start-pos)
6870 (goto-char selected-point)
6871 (if (or (outline-invisible-p) (org-invisible-p2))
6872 (org-show-context 'org-goto)))
6875 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
6876 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
6877 (defvar org-goto-local-auto-isearch-map) ; defined below
6879 (defun org-get-location (buf help)
6880 "Let the user select a location in the Org-mode buffer BUF.
6881 This function uses a recursive edit. It returns the selected position
6883 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
6884 (isearch-hide-immediately nil)
6885 (isearch-search-fun-function
6886 (lambda () 'org-goto-local-search-headings))
6887 (org-goto-selected-point org-goto-exit-command)
6889 (special-display-buffer-names nil)
6890 (special-display-regexps nil)
6891 (special-display-function nil))
6893 (save-window-excursion
6894 (delete-other-windows)
6895 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
6896 (org-pop-to-buffer-same-window
6898 (make-indirect-buffer (current-buffer) "*org-goto*")
6899 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
6900 (with-output-to-temp-buffer "*Help*"
6902 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
6903 (setq buffer-read-only nil)
6904 (let ((org-startup-truncated t)
6905 (org-startup-folded nil)
6906 (org-startup-align-all-tables nil))
6909 (setq buffer-read-only t)
6910 (if (and (boundp 'org-goto-start-pos)
6911 (integer-or-marker-p org-goto-start-pos))
6912 (let ((org-show-hierarchy-above t)
6913 (org-show-siblings t)
6914 (org-show-following-heading t))
6915 (goto-char org-goto-start-pos)
6916 (and (outline-invisible-p) (org-show-context)))
6917 (goto-char (point-min)))
6918 (let (org-special-ctrl-a/e) (org-beginning-of-line))
6919 (message "Select location and press RET")
6920 (use-local-map org-goto-map)
6923 (kill-buffer "*org-goto*")
6924 (cons org-goto-selected-point org-goto-exit-command)))
6926 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
6927 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
6928 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
6929 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
6931 (defun org-goto-local-search-headings (string bound noerror)
6932 "Search and make sure that any matches are in headlines."
6934 (while (if isearch-forward
6935 (search-forward string bound noerror)
6936 (search-backward string bound noerror))
6937 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
6938 (and (member :headline context)
6939 (not (member :tags context))))
6940 (throw 'return (point))))))
6942 (defun org-goto-local-auto-isearch ()
6945 (goto-char (point-min))
6946 (let ((keys (this-command-keys)))
6947 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
6949 (isearch-process-search-char (string-to-char keys)))))
6951 (defun org-goto-ret (&optional arg)
6952 "Finish `org-goto' by going to the new location."
6954 (setq org-goto-selected-point (point)
6955 org-goto-exit-command 'return)
6958 (defun org-goto-left ()
6959 "Finish `org-goto' by going to the new location."
6961 (if (org-at-heading-p)
6963 (beginning-of-line 1)
6964 (setq org-goto-selected-point (point)
6965 org-goto-exit-command 'left)
6967 (error "Not on a heading")))
6969 (defun org-goto-right ()
6970 "Finish `org-goto' by going to the new location."
6972 (if (org-at-heading-p)
6974 (setq org-goto-selected-point (point)
6975 org-goto-exit-command 'right)
6977 (error "Not on a heading")))
6979 (defun org-goto-quit ()
6980 "Finish `org-goto' without cursor motion."
6982 (setq org-goto-selected-point nil)
6983 (setq org-goto-exit-command 'quit)
6986 ;;; Indirect buffer display of subtrees
6988 (defvar org-indirect-dedicated-frame nil
6989 "This is the frame being used for indirect tree display.")
6990 (defvar org-last-indirect-buffer nil)
6992 (defun org-tree-to-indirect-buffer (&optional arg)
6993 "Create indirect buffer and narrow it to current subtree.
6994 With numerical prefix ARG, go up to this level and then take that tree.
6995 If ARG is negative, go up that many levels.
6996 If `org-indirect-buffer-display' is not `new-frame', the command removes the
6997 indirect buffer previously made with this command, to avoid proliferation of
6998 indirect buffers. However, when you call the command with a \
6999 \\[universal-argument] prefix, or
7000 when `org-indirect-buffer-display' is `new-frame', the last buffer
7001 is kept so that you can work with several indirect buffers at the same time.
7002 If `org-indirect-buffer-display' is `dedicated-frame', the \
7003 \\[universal-argument] prefix also
7004 requests that a new frame be made for the new buffer, so that the dedicated
7005 frame is not changed."
7007 (let ((cbuf (current-buffer))
7008 (cwin (selected-window))
7010 beg end level heading ibuf)
7012 (org-back-to-heading t)
7014 (setq level (org-outline-level))
7015 (if (< arg 0) (setq arg (+ level arg)))
7016 (while (> (setq level (org-outline-level)) arg)
7017 (outline-up-heading 1 t)))
7019 heading (org-get-heading))
7020 (org-end-of-subtree t t)
7021 (if (org-at-heading-p) (backward-char 1))
7023 (if (and (buffer-live-p org-last-indirect-buffer)
7024 (not (eq org-indirect-buffer-display 'new-frame))
7026 (kill-buffer org-last-indirect-buffer))
7027 (setq ibuf (org-get-indirect-buffer cbuf)
7028 org-last-indirect-buffer ibuf)
7030 ((or (eq org-indirect-buffer-display 'new-frame)
7031 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
7032 (select-frame (make-frame))
7033 (delete-other-windows)
7034 (org-pop-to-buffer-same-window ibuf)
7035 (org-set-frame-title heading))
7036 ((eq org-indirect-buffer-display 'dedicated-frame)
7038 (select-frame (or (and org-indirect-dedicated-frame
7039 (frame-live-p org-indirect-dedicated-frame)
7040 org-indirect-dedicated-frame)
7041 (setq org-indirect-dedicated-frame (make-frame)))))
7042 (delete-other-windows)
7043 (org-pop-to-buffer-same-window ibuf)
7044 (org-set-frame-title (concat "Indirect: " heading)))
7045 ((eq org-indirect-buffer-display 'current-window)
7046 (org-pop-to-buffer-same-window ibuf))
7047 ((eq org-indirect-buffer-display 'other-window)
7048 (pop-to-buffer ibuf))
7049 (t (error "Invalid value")))
7050 (if (featurep 'xemacs)
7051 (save-excursion (org-mode) (turn-on-font-lock)))
7052 (narrow-to-region beg end)
7055 (run-hook-with-args 'org-cycle-hook 'all)
7056 (and (window-live-p cwin) (select-window cwin))))
7058 (defun org-get-indirect-buffer (&optional buffer)
7059 (setq buffer (or buffer (current-buffer)))
7060 (let ((n 1) (base (buffer-name buffer)) bname)
7061 (while (buffer-live-p
7062 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
7065 (make-indirect-buffer buffer bname 'clone)
7066 (error (make-indirect-buffer buffer bname)))))
7068 (defun org-set-frame-title (title)
7069 "Set the title of the current frame to the string TITLE."
7070 ;; FIXME: how to name a single frame in XEmacs???
7071 (unless (featurep 'xemacs)
7072 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
7074 ;;;; Structure editing
7076 ;;; Inserting headlines
7078 (defun org-previous-line-empty-p ()
7081 (or (beginning-of-line 0) t)
7083 (looking-at "[ \t]*$")))))
7085 (defun org-insert-heading (&optional force-heading invisible-ok)
7086 "Insert a new heading or item with same depth at point.
7087 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
7088 If point is at the beginning of a headline, insert a sibling before the
7089 current headline. If point is not at the beginning, split the line,
7090 create the new headline with the text in the current line after point
7091 \(but see also the variable `org-M-RET-may-split-line').
7093 When INVISIBLE-OK is set, stop at invisible headlines when going back.
7094 This is important for non-interactive uses of the command."
7096 (if (or (= (buffer-size) 0)
7097 (and (not (save-excursion
7098 (and (ignore-errors (org-back-to-heading invisible-ok))
7099 (org-at-heading-p))))
7100 (or force-heading (not (org-in-item-p)))))
7103 (run-hooks 'org-insert-heading-hook))
7104 (when (or force-heading (not (org-insert-item)))
7105 (let* ((empty-line-p nil)
7107 (on-heading (org-at-heading-p))
7108 (head (save-excursion
7111 (org-back-to-heading invisible-ok)
7112 (when (and (not on-heading)
7113 (featurep 'org-inlinetask)
7114 (integerp org-inlinetask-min-level)
7115 (>= (length (match-string 0))
7116 org-inlinetask-min-level))
7117 ;; Find a heading level before the inline task
7118 (while (and (setq level (org-up-heading-safe))
7119 (>= level org-inlinetask-min-level)))
7120 (if (org-at-heading-p)
7121 (org-back-to-heading invisible-ok)
7122 (error "This should not happen")))
7123 (setq empty-line-p (org-previous-line-empty-p))
7126 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
7127 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
7128 pos hide-previous previous-pos)
7130 ((and (org-at-heading-p) (bolp)
7132 (save-excursion (backward-char 1) (not (outline-invisible-p)))))
7133 ;; insert before the current line
7134 (open-line (if blank 2 1)))
7136 (not org-insert-heading-respect-content)
7139 (backward-char 1) (not (outline-invisible-p)))))
7140 ;; insert right here
7143 ;; somewhere in the line
7145 (setq previous-pos (point-at-bol))
7147 (setq hide-previous (outline-invisible-p)))
7148 (and org-insert-heading-respect-content (org-show-subtree))
7150 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
7153 (goto-char (point-at-bol))
7154 (and (looking-at org-complex-heading-regexp)
7156 (> p (match-beginning 4)))))))
7159 (org-insert-heading-respect-content
7160 (org-end-of-subtree nil t)
7161 (when (featurep 'org-inlinetask)
7162 (while (and (not (eobp))
7163 (looking-at "\\(\\*+\\)[ \t]+")
7164 (>= (length (match-string 1))
7165 org-inlinetask-min-level))
7166 (org-end-of-subtree nil t)))
7167 (or (bolp) (newline))
7168 (or (org-previous-line-empty-p)
7169 (and blank (newline)))
7175 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ \t]*$")
7176 (setq tags (and (match-end 2) (match-string 2)))
7178 (delete-region (match-beginning 1) (match-end 1)))
7179 (setq pos (point-at-bol))
7180 (or split (end-of-line 1))
7181 (delete-horizontal-space)
7182 (if (string-match "\\`\\*+\\'"
7183 (buffer-substring (point-at-bol) (point)))
7185 (newline (if blank 2 1))
7191 (org-set-tags nil 'align))))
7193 (or split (end-of-line 1))
7194 (newline (if blank 2 1)))))))
7195 (insert head) (just-one-space)
7198 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
7199 (when (and org-insert-heading-respect-content hide-previous)
7201 (goto-char previous-pos)
7203 (run-hooks 'org-insert-heading-hook)))))
7205 (defun org-get-heading (&optional no-tags no-todo)
7206 "Return the heading of the current entry, without the stars.
7207 When NO-TAGS is non-nil, don't include tags.
7208 When NO-TODO is non-nil, don't include TODO keywords."
7210 (org-back-to-heading t)
7212 ((and no-tags no-todo)
7213 (looking-at org-complex-heading-regexp)
7216 (looking-at (concat org-outline-regexp
7218 "\\(?:[ \t]+:[[:alnum:]:_@#%]+:\\)?[ \t]*$"))
7221 (looking-at org-todo-line-regexp)
7223 (t (looking-at org-heading-regexp)
7224 (match-string 2)))))
7226 (defun org-heading-components ()
7227 "Return the components of the current heading.
7228 This is a list with the following elements:
7229 - the level as an integer
7230 - the reduced level, different if `org-odd-levels-only' is set.
7231 - the TODO keyword, or nil
7232 - the priority character, like ?A, or nil if no priority is given
7233 - the headline text itself, or the tags string if no headline text
7234 - the tags string, or nil."
7236 (org-back-to-heading t)
7237 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
7238 (list (length (match-string 1))
7239 (org-reduced-level (length (match-string 1)))
7240 (org-match-string-no-properties 2)
7241 (and (match-end 3) (aref (match-string 3) 2))
7242 (org-match-string-no-properties 4)
7243 (org-match-string-no-properties 5)))))
7245 (defun org-get-entry ()
7246 "Get the entry text, after heading, entire subtree."
7248 (org-back-to-heading t)
7249 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
7251 (defun org-insert-heading-after-current ()
7252 "Insert a new heading with same level as current, after current subtree."
7254 (org-back-to-heading)
7255 (org-insert-heading)
7256 (org-move-subtree-down)
7259 (defun org-insert-heading-respect-content ()
7261 (let ((org-insert-heading-respect-content t))
7262 (org-insert-heading t)))
7264 (defun org-insert-todo-heading-respect-content (&optional force-state)
7266 (let ((org-insert-heading-respect-content t))
7267 (org-insert-todo-heading force-state t)))
7269 (defun org-insert-todo-heading (arg &optional force-heading)
7270 "Insert a new heading with the same level and TODO state as current heading.
7271 If the heading has no TODO state, or if the state is DONE, use the first
7272 state (TODO by default). Also with prefix arg, force first state."
7274 (when (or force-heading (not (org-insert-item 'checkbox)))
7275 (org-insert-heading force-heading)
7277 (org-back-to-heading)
7278 (outline-previous-heading)
7279 (looking-at org-todo-line-regexp))
7283 (not (match-beginning 2))
7284 (member (match-string 2) org-done-keywords))
7285 (car org-todo-keywords-1)
7289 (run-hook-with-args-until-success
7290 'org-todo-get-default-hook new-mark-x nil)
7292 (beginning-of-line 1)
7293 (and (looking-at org-outline-regexp) (goto-char (match-end 0))
7294 (if org-treat-insert-todo-heading-as-state-change
7296 (insert new-mark " "))))
7297 (when org-provide-todo-statistics
7298 (org-update-parent-todo-statistics))))
7300 (defun org-insert-subheading (arg)
7301 "Insert a new subheading and demote it.
7302 Works for outline headings and for plain lists alike."
7304 (org-insert-heading arg)
7306 ((org-at-heading-p) (org-do-demote))
7307 ((org-at-item-p) (org-indent-item))))
7309 (defun org-insert-todo-subheading (arg)
7310 "Insert a new subheading with TODO keyword or checkbox and demote it.
7311 Works for outline headings and for plain lists alike."
7313 (org-insert-todo-heading arg)
7315 ((org-at-heading-p) (org-do-demote))
7316 ((org-at-item-p) (org-indent-item))))
7318 ;;; Promotion and Demotion
7320 (defvar org-after-demote-entry-hook nil
7321 "Hook run after an entry has been demoted.
7322 The cursor will be at the beginning of the entry.
7323 When a subtree is being demoted, the hook will be called for each node.")
7325 (defvar org-after-promote-entry-hook nil
7326 "Hook run after an entry has been promoted.
7327 The cursor will be at the beginning of the entry.
7328 When a subtree is being promoted, the hook will be called for each node.")
7330 (defun org-promote-subtree ()
7331 "Promote the entire subtree.
7332 See also `org-promote'."
7335 (org-with-limited-levels (org-map-tree 'org-promote)))
7336 (org-fix-position-after-promote))
7338 (defun org-demote-subtree ()
7339 "Demote the entire subtree. See `org-demote'.
7340 See also `org-promote'."
7343 (org-with-limited-levels (org-map-tree 'org-demote)))
7344 (org-fix-position-after-promote))
7347 (defun org-do-promote ()
7348 "Promote the current heading higher up the tree.
7349 If the region is active in `transient-mark-mode', promote all headings
7353 (if (org-region-active-p)
7354 (org-map-region 'org-promote (region-beginning) (region-end))
7356 (org-fix-position-after-promote))
7358 (defun org-do-demote ()
7359 "Demote the current heading lower down the tree.
7360 If the region is active in `transient-mark-mode', demote all headings
7364 (if (org-region-active-p)
7365 (org-map-region 'org-demote (region-beginning) (region-end))
7367 (org-fix-position-after-promote))
7369 (defun org-fix-position-after-promote ()
7370 "Make sure that after pro/demotion cursor position is right."
7371 (let ((pos (point)))
7372 (when (save-excursion
7373 (beginning-of-line 1)
7374 (looking-at org-todo-line-regexp)
7375 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
7376 (cond ((eobp) (insert " "))
7377 ((eolp) (insert " "))
7378 ((equal (char-after) ?\ ) (forward-char 1))))))
7380 (defun org-current-level ()
7381 "Return the level of the current entry, or nil if before the first headline.
7382 The level is the number of stars at the beginning of the headline."
7384 (org-with-limited-levels
7385 (if (ignore-errors (org-back-to-heading t))
7386 (funcall outline-level)))))
7388 (defun org-get-previous-line-level ()
7389 "Return the outline depth of the last headline before the current line.
7390 Returns 0 for the first headline in the buffer, and nil if before the
7392 (let ((current-level (org-current-level))
7393 (prev-level (when (> (line-number-at-pos) 1)
7395 (beginning-of-line 0)
7396 (org-current-level)))))
7397 (cond ((null current-level) nil) ; Before first headline
7398 ((null prev-level) 0) ; At first headline
7401 (defun org-reduced-level (l)
7402 "Compute the effective level of a heading.
7403 This takes into account the setting of `org-odd-levels-only'."
7406 (org-odd-levels-only (1+ (floor (/ l 2))))
7409 (defun org-level-increment ()
7410 "Return the number of stars that will be added or removed at a
7411 time to headlines when structure editing, based on the value of
7412 `org-odd-levels-only'."
7413 (if org-odd-levels-only 2 1))
7415 (defun org-get-valid-level (level &optional change)
7416 "Rectify a level change under the influence of `org-odd-levels-only'
7417 LEVEL is a current level, CHANGE is by how much the level should be
7418 modified. Even if CHANGE is nil, LEVEL may be returned modified because
7419 even level numbers will become the next higher odd number."
7420 (if org-odd-levels-only
7421 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
7422 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
7423 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
7424 (max 1 (+ level (or change 0)))))
7426 (if (boundp 'define-obsolete-function-alias)
7427 (if (or (featurep 'xemacs) (< emacs-major-version 23))
7428 (define-obsolete-function-alias 'org-get-legal-level
7429 'org-get-valid-level)
7430 (define-obsolete-function-alias 'org-get-legal-level
7431 'org-get-valid-level "23.1")))
7433 (defun org-promote ()
7434 "Promote the current heading higher up the tree.
7435 If the region is active in `transient-mark-mode', promote all headings
7437 (org-back-to-heading t)
7438 (let* ((level (save-match-data (funcall outline-level)))
7439 (after-change-functions (remove 'flyspell-after-change-function
7440 after-change-functions))
7441 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
7442 (diff (abs (- level (length up-head) -1))))
7443 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary"))
7444 (replace-match up-head nil t)
7445 ;; Fixup tag positioning
7446 (and org-auto-align-tags (org-set-tags nil t))
7447 (if org-adapt-indentation (org-fixup-indentation (- diff)))
7448 (run-hooks 'org-after-promote-entry-hook)))
7450 (defun org-demote ()
7451 "Demote the current heading lower down the tree.
7452 If the region is active in `transient-mark-mode', demote all headings
7454 (org-back-to-heading t)
7455 (let* ((level (save-match-data (funcall outline-level)))
7456 (after-change-functions (remove 'flyspell-after-change-function
7457 after-change-functions))
7458 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
7459 (diff (abs (- level (length down-head) -1))))
7460 (replace-match down-head nil t)
7461 ;; Fixup tag positioning
7462 (and org-auto-align-tags (org-set-tags nil t))
7463 (if org-adapt-indentation (org-fixup-indentation diff))
7464 (run-hooks 'org-after-demote-entry-hook)))
7466 (defun org-cycle-level ()
7467 "Cycle the level of an empty headline through possible states.
7468 This goes first to child, then to parent, level, then up the hierarchy.
7469 After top level, it switches back to sibling level."
7471 (let ((org-adapt-indentation nil))
7472 (when (org-point-at-end-of-empty-headline)
7473 (setq this-command 'org-cycle-level) ; Only needed for caching
7474 (let ((cur-level (org-current-level))
7475 (prev-level (org-get-previous-line-level)))
7477 ;; If first headline in file, promote to top-level.
7479 (loop repeat (/ (- cur-level 1) (org-level-increment))
7480 do (org-do-promote)))
7481 ;; If same level as prev, demote one.
7482 ((= prev-level cur-level)
7484 ;; If parent is top-level, promote to top level if not already.
7486 (loop repeat (/ (- cur-level 1) (org-level-increment))
7487 do (org-do-promote)))
7488 ;; If top-level, return to prev-level.
7490 (loop repeat (/ (- prev-level 1) (org-level-increment))
7491 do (org-do-demote)))
7492 ;; If less than prev-level, promote one.
7493 ((< cur-level prev-level)
7495 ;; If deeper than prev-level, promote until higher than
7497 ((> cur-level prev-level)
7498 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
7499 do (org-do-promote))))
7502 (defun org-map-tree (fun)
7503 "Call FUN for every heading underneath the current one."
7504 (org-back-to-heading)
7505 (let ((level (funcall outline-level)))
7509 (outline-next-heading)
7510 (> (funcall outline-level) level))
7514 (defun org-map-region (fun beg end)
7515 "Call FUN for every heading between BEG and END."
7516 (let ((org-ignore-region t))
7518 (setq end (copy-marker end))
7520 (if (and (re-search-forward org-outline-regexp-bol nil t)
7524 (outline-next-heading)
7529 (defvar org-property-end-re) ; silence byte-compiler
7530 (defun org-fixup-indentation (diff)
7531 "Change the indentation in the current entry by DIFF.
7532 However, if any line in the current entry has no indentation, or if it
7533 would end up with no indentation after the change, nothing at all is done."
7535 (let ((end (save-excursion (outline-next-heading)
7537 (prohibit (if (> diff 0)
7539 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
7541 (unless (save-excursion (end-of-line 1)
7542 (re-search-forward prohibit end t))
7543 (while (and (< (point) end)
7544 (re-search-forward "^[ \t]+" end t))
7545 (goto-char (match-end 0))
7546 (setq col (current-column))
7547 (if (< diff 0) (replace-match ""))
7548 (org-indent-to-column (+ diff col))))
7549 (move-marker end nil))))
7551 (defun org-convert-to-odd-levels ()
7552 "Convert an org-mode file with all levels allowed to one with odd levels.
7553 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7556 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7557 (let ((outline-level 'org-outline-level)
7558 (org-odd-levels-only nil) n)
7560 (goto-char (point-min))
7561 (while (re-search-forward "^\\*\\*+ " nil t)
7562 (setq n (- (length (match-string 0)) 2))
7563 (while (>= (setq n (1- n)) 0)
7565 (end-of-line 1))))))
7567 (defun org-convert-to-oddeven-levels ()
7568 "Convert an org-mode file with only odd levels to one with odd/even levels.
7569 This promotes level 3 to level 2, level 5 to level 3 etc. If the
7570 file contains a section with an even level, conversion would
7571 destroy the structure of the file. An error is signaled in this
7574 (goto-char (point-min))
7575 ;; First check if there are no even levels
7576 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7577 (org-show-context t)
7578 (error "Not all levels are odd in this file. Conversion not possible"))
7579 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7580 (let ((outline-regexp org-outline-regexp)
7581 (outline-level 'org-outline-level)
7582 (org-odd-levels-only nil) n)
7584 (goto-char (point-min))
7585 (while (re-search-forward "^\\*\\*+ " nil t)
7586 (setq n (/ (1- (length (match-string 0))) 2))
7587 (while (>= (setq n (1- n)) 0)
7589 (end-of-line 1))))))
7591 (defun org-tr-level (n)
7592 "Make N odd if required."
7593 (if org-odd-levels-only (1+ (/ n 2)) n))
7595 ;;; Vertical tree motion, cutting and pasting of subtrees
7597 (defun org-move-subtree-up (&optional arg)
7598 "Move the current subtree up past ARG headlines of the same level."
7600 (org-move-subtree-down (- (prefix-numeric-value arg))))
7602 (defun org-move-subtree-down (&optional arg)
7603 "Move the current subtree down past ARG headlines of the same level."
7605 (setq arg (prefix-numeric-value arg))
7606 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7607 'org-get-last-sibling))
7608 (ins-point (make-marker))
7610 (col (current-column))
7611 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7613 (org-back-to-heading)
7616 (setq ne-beg (org-back-over-empty-lines))
7619 (save-excursion (outline-end-of-heading)
7620 (setq folded (outline-invisible-p)))
7621 (outline-end-of-subtree))
7622 (outline-next-heading)
7623 (setq ne-end (org-back-over-empty-lines))
7626 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7627 ;; include less whitespace
7630 (forward-line (- ne-beg ne-end))
7631 (setq beg (point))))
7632 ;; Find insertion point, with error handling
7634 (or (and (funcall movfunc) (looking-at org-outline-regexp))
7635 (progn (goto-char beg0)
7636 (error "Cannot move past superior level or buffer limit")))
7637 (setq cnt (1- cnt)))
7639 ;; Moving forward - still need to move over subtree
7640 (progn (org-end-of-subtree t t)
7642 (org-back-over-empty-lines)
7643 (or (bolp) (newline)))))
7644 (setq ne-ins (org-back-over-empty-lines))
7645 (move-marker ins-point (point))
7646 (setq txt (buffer-substring beg end))
7647 (org-save-markers-in-region beg end)
7648 (delete-region beg end)
7649 (org-remove-empty-overlays-at beg)
7650 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7651 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7652 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7653 (let ((bbb (point)))
7654 (insert-before-markers txt)
7655 (org-reinstall-markers-in-region bbb)
7656 (move-marker ins-point bbb))
7657 (or (bolp) (insert "\n"))
7658 (setq ins-end (point))
7659 (goto-char ins-point)
7660 (org-skip-whitespace)
7661 (when (and (< arg 0)
7662 (org-first-sibling-p)
7664 ;; Move whitespace back to beginning
7667 (let ((kill-whole-line t))
7668 (kill-line (- ne-ins ne-beg)) (point)))
7669 (insert (make-string (- ne-ins ne-beg) ?\n)))
7670 (move-marker ins-point nil)
7675 (org-cycle-hide-drawers 'children))
7676 (org-clean-visibility-after-subtree-move)
7677 ;; move back to the initial column we were at
7678 (move-to-column col)))
7680 (defvar org-subtree-clip ""
7681 "Clipboard for cut and paste of subtrees.
7682 This is actually only a copy of the kill, because we use the normal kill
7683 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7685 (defvar org-subtree-clip-folded nil
7686 "Was the last copied subtree folded?
7687 This is used to fold the tree back after pasting.")
7689 (defun org-cut-subtree (&optional n)
7690 "Cut the current subtree into the clipboard.
7691 With prefix arg N, cut this many sequential subtrees.
7692 This is a short-hand for marking the subtree and then cutting it."
7694 (org-copy-subtree n 'cut))
7696 (defun org-copy-subtree (&optional n cut force-store-markers)
7697 "Cut the current subtree into the clipboard.
7698 With prefix arg N, cut this many sequential subtrees.
7699 This is a short-hand for marking the subtree and then copying it.
7700 If CUT is non-nil, actually cut the subtree.
7701 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7702 of some markers in the region, even if CUT is non-nil. This is
7703 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7705 (let (beg end folded (beg0 (point)))
7706 (if (org-called-interactively-p 'any)
7707 (org-back-to-heading nil) ; take what looks like a subtree
7708 (org-back-to-heading t)) ; take what is really there
7709 (org-back-over-empty-lines)
7711 (skip-chars-forward " \t\r\n")
7713 (save-excursion (outline-end-of-heading)
7714 (setq folded (outline-invisible-p)))
7716 (org-forward-same-level (1- n) t)
7718 (org-end-of-subtree t t))
7719 (org-back-over-empty-lines)
7723 (setq org-subtree-clip-folded folded)
7724 (when (or cut force-store-markers)
7725 (org-save-markers-in-region beg end))
7726 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7727 (setq org-subtree-clip (current-kill 0))
7728 (message "%s: Subtree(s) with %d characters"
7729 (if cut "Cut" "Copied")
7730 (length org-subtree-clip)))))
7732 (defun org-paste-subtree (&optional level tree for-yank)
7733 "Paste the clipboard as a subtree, with modification of headline level.
7734 The entire subtree is promoted or demoted in order to match a new headline
7737 If the cursor is at the beginning of a headline, the same level as
7738 that headline is used to paste the tree
7740 If not, the new level is derived from the *visible* headings
7741 before and after the insertion point, and taken to be the inferior headline
7742 level of the two. So if the previous visible heading is level 3 and the
7743 next is level 4 (or vice versa), level 4 will be used for insertion.
7744 This makes sure that the subtree remains an independent subtree and does
7745 not swallow low level entries.
7747 You can also force a different level, either by using a numeric prefix
7748 argument, or by inserting the heading marker by hand. For example, if the
7749 cursor is after \"*****\", then the tree will be shifted to level 5.
7751 If optional TREE is given, use this text instead of the kill ring.
7753 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7754 move back over whitespace before inserting, and move point to the end of
7755 the inserted text when done."
7757 (setq tree (or tree (and kill-ring (current-kill 0))))
7758 (unless (org-kill-is-subtree-p tree)
7760 (substitute-command-keys
7761 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7762 (org-with-limited-levels
7763 (let* ((visp (not (outline-invisible-p)))
7765 (^re_ "\\(\\*+\\)[ \t]*")
7766 (old-level (if (string-match org-outline-regexp-bol txt)
7767 (- (match-end 0) (match-beginning 0) 1)
7769 (force-level (cond (level (prefix-numeric-value level))
7770 ((and (looking-at "[ \t]*$")
7772 "^\\*+$" (buffer-substring
7773 (point-at-bol) (point))))
7774 (- (match-end 1) (match-beginning 1)))
7776 (looking-at org-outline-regexp))
7777 (- (match-end 0) (point) 1))
7779 (previous-level (save-excursion
7782 (outline-previous-visible-heading 1)
7783 (if (looking-at ^re_)
7784 (- (match-end 0) (match-beginning 0) 1)
7787 (next-level (save-excursion
7790 (or (looking-at org-outline-regexp)
7791 (outline-next-visible-heading 1))
7792 (if (looking-at ^re_)
7793 (- (match-end 0) (match-beginning 0) 1)
7796 (new-level (or force-level (max previous-level next-level)))
7797 (shift (if (or (= old-level -1)
7799 (= old-level new-level))
7801 (- new-level old-level)))
7802 (delta (if (> shift 0) -1 1))
7803 (func (if (> shift 0) 'org-demote 'org-promote))
7804 (org-odd-levels-only nil)
7806 ;; Remove the forced level indicator
7808 (delete-region (point-at-bol) (point)))
7810 (beginning-of-line (if (bolp) 1 2))
7811 (unless for-yank (org-back-over-empty-lines))
7813 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7814 (insert-before-markers txt)
7815 (unless (string-match "\n\\'" txt) (insert "\n"))
7816 (setq newend (point))
7817 (org-reinstall-markers-in-region beg)
7820 (skip-chars-forward " \t\n\r")
7822 (if (and (outline-invisible-p) visp)
7823 (save-excursion (outline-show-heading)))
7824 ;; Shift if necessary
7827 (narrow-to-region beg end)
7828 (while (not (= shift 0))
7829 (org-map-region func (point-min) (point-max))
7830 (setq shift (+ delta shift)))
7831 (goto-char (point-min))
7832 (setq newend (point-max))))
7833 (when (or (org-called-interactively-p 'interactive) for-yank)
7834 (message "Clipboard pasted as level %d subtree" new-level))
7835 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7837 (eq org-subtree-clip (current-kill 0))
7838 org-subtree-clip-folded)
7839 ;; The tree was folded before it was killed/copied
7841 (and for-yank (goto-char newend)))))
7843 (defun org-kill-is-subtree-p (&optional txt)
7844 "Check if the current kill is an outline subtree, or a set of trees.
7845 Returns nil if kill does not start with a headline, or if the first
7846 headline level is not the largest headline level in the tree.
7847 So this will actually accept several entries of equal levels as well,
7848 which is OK for `org-paste-subtree'.
7849 If optional TXT is given, check this string instead of the current kill."
7850 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7851 (re (org-get-limited-outline-regexp))
7852 (^re (concat "^" re))
7853 (start-level (and kill
7855 (concat "\\`\\([ \t\n\r]*?\n\\)?\\(" re "\\)")
7857 (- (match-end 2) (match-beginning 2) 1)))
7858 (start (1+ (or (match-beginning 2) -1))))
7859 (if (not start-level)
7861 nil) ;; does not even start with a heading
7863 (while (setq start (string-match ^re kill (1+ start)))
7864 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
7868 (defvar org-markers-to-move nil
7869 "Markers that should be moved with a cut-and-paste operation.
7870 Those markers are stored together with their positions relative to
7871 the start of the region.")
7873 (defun org-save-markers-in-region (beg end)
7874 "Check markers in region.
7875 If these markers are between BEG and END, record their position relative
7876 to BEG, so that after moving the block of text, we can put the markers back
7878 This function gets called just before an entry or tree gets cut from the
7879 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
7880 called immediately, to move the markers with the entries."
7881 (setq org-markers-to-move nil)
7882 (when (featurep 'org-clock)
7883 (org-clock-save-markers-for-cut-and-paste beg end))
7884 (when (featurep 'org-agenda)
7885 (org-agenda-save-markers-for-cut-and-paste beg end)))
7887 (defun org-check-and-save-marker (marker beg end)
7888 "Check if MARKER is between BEG and END.
7889 If yes, remember the marker and the distance to BEG."
7890 (when (and (marker-buffer marker)
7891 (equal (marker-buffer marker) (current-buffer)))
7892 (if (and (>= marker beg) (< marker end))
7893 (push (cons marker (- marker beg)) org-markers-to-move))))
7895 (defun org-reinstall-markers-in-region (beg)
7896 "Move all remembered markers to their position relative to BEG."
7898 (move-marker (car x) (+ beg (cdr x))))
7899 org-markers-to-move)
7900 (setq org-markers-to-move nil))
7902 (defun org-narrow-to-subtree ()
7903 "Narrow buffer to the current subtree."
7907 (org-with-limited-levels
7909 (progn (org-back-to-heading t) (point))
7910 (progn (org-end-of-subtree t t)
7911 (if (and (org-at-heading-p) (not (eobp))) (backward-char 1))
7914 (defun org-narrow-to-block ()
7915 "Narrow buffer to the current block."
7917 (let* ((case-fold-search t)
7918 (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
7919 "^[ \t]*#\\+end_.*")))
7921 (narrow-to-region (car blockp) (cdr blockp))
7922 (error "Not in a block"))))
7925 (defvar org-property-drawer-re))
7927 (defvar org-property-start-re) ;; defined below
7928 (defun org-clone-subtree-with-time-shift (n &optional shift)
7929 "Clone the task (subtree) at point N times.
7930 The clones will be inserted as siblings.
7932 In interactive use, the user will be prompted for the number of
7933 clones to be produced, and for a time SHIFT, which may be a
7934 repeater as used in time stamps, for example `+3d'.
7936 When a valid repeater is given and the entry contains any time
7937 stamps, the clones will become a sequence in time, with time
7938 stamps in the subtree shifted for each clone produced. If SHIFT
7939 is nil or the empty string, time stamps will be left alone. The
7940 ID property of the original subtree is removed.
7942 If the original subtree did contain time stamps with a repeater,
7943 the following will happen:
7944 - the repeater will be removed in each clone
7945 - an additional clone will be produced, with the current, unshifted
7946 date(s) in the entry.
7947 - the original entry will be placed *after* all the clones, with
7949 - the start days in the repeater in the original entry will be shifted
7950 to past the last clone.
7951 I this way you can spell out a number of instances of a repeating task,
7952 and still retain the repeater to cover future instances of the task."
7953 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
7954 (let (beg end template task idprop
7955 shift-n shift-what doshift nmin nmax (n-no-remove -1)
7956 (drawer-re org-drawer-regexp))
7957 (if (not (and (integerp n) (> n 0)))
7958 (error "Invalid number of replications %s" n))
7959 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
7960 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([dwmy]\\)[ \t]*\\'"
7962 (error "Invalid shift specification %s" shift))
7964 (setq shift-n (string-to-number (match-string 1 shift))
7965 shift-what (cdr (assoc (match-string 2 shift)
7966 '(("d" . day) ("w" . week)
7967 ("m" . month) ("y" . year))))))
7968 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
7969 (setq nmin 1 nmax n)
7970 (org-back-to-heading t)
7972 (setq idprop (org-entry-get nil "ID"))
7973 (org-end-of-subtree t t)
7974 (or (bolp) (insert "\n"))
7976 (setq template (buffer-substring beg end))
7978 (string-match "<[^<>\n]+ \\+[0-9]+[dwmy][^<>\n]*>" template))
7979 (delete-region beg end)
7981 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
7983 (loop for n from nmin to nmax do
7988 (goto-char (point-min))
7990 (and idprop (if org-clone-delete-id
7991 (org-entry-delete nil "ID")
7992 (org-id-get-create t)))
7994 (while (re-search-forward "^[ \t]*CLOCK:.*$" nil t)
7996 (goto-char (point-min))
7997 (while (re-search-forward drawer-re nil t)
7999 (org-remove-empty-drawer-at d (point))) org-drawers)))
8000 (goto-char (point-min))
8002 (while (re-search-forward org-ts-regexp-both nil t)
8003 (org-timestamp-change (* n shift-n) shift-what))
8004 (unless (= n n-no-remove)
8005 (goto-char (point-min))
8006 (while (re-search-forward org-ts-regexp nil t)
8008 (goto-char (match-beginning 0))
8009 (if (looking-at "<[^<>\n]+\\( +\\+[0-9]+[dwmy]\\)")
8010 (delete-region (match-beginning 1) (match-end 1)))))))
8011 (setq task (buffer-string)))
8017 (defun org-sort (with-case)
8018 "Call `org-sort-entries', `org-table-sort-lines' or `org-sort-list'.
8019 Optional argument WITH-CASE means sort case-sensitively."
8022 ((org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case))
8023 ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case))
8025 (org-call-with-arg 'org-sort-entries with-case))))
8027 (defun org-sort-remove-invisible (s)
8028 (remove-text-properties 0 (length s) org-rm-props s)
8029 (while (string-match org-bracket-link-regexp s)
8030 (setq s (replace-match (if (match-end 2)
8032 (match-string 1 s)) t t s)))
8035 (defvar org-priority-regexp) ; defined later in the file
8037 (defvar org-after-sorting-entries-or-items-hook nil
8038 "Hook that is run after a bunch of entries or items have been sorted.
8039 When children are sorted, the cursor is in the parent line when this
8040 hook gets called. When a region or a plain list is sorted, the cursor
8041 will be in the first entry of the sorted region/list.")
8043 (defun org-sort-entries
8044 (&optional with-case sorting-type getkey-func compare-func property)
8045 "Sort entries on a certain level of an outline tree.
8046 If there is an active region, the entries in the region are sorted.
8047 Else, if the cursor is before the first entry, sort the top-level items.
8048 Else, the children of the entry at point are sorted.
8050 Sorting can be alphabetically, numerically, by date/time as given by
8051 a time stamp, by a property or by priority.
8053 The command prompts for the sorting type unless it has been given to the
8054 function through the SORTING-TYPE argument, which needs to be a character,
8055 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
8056 precise meaning of each character:
8058 n Numerically, by converting the beginning of the entry/item to a number.
8059 a Alphabetically, ignoring the TODO keyword and the priority, if any.
8060 t By date/time, either the first active time stamp in the entry, or, if
8061 none exist, by the first inactive one.
8062 s By the scheduled date/time.
8063 d By deadline date/time.
8064 c By creation time, which is assumed to be the first inactive time stamp
8065 at the beginning of a line.
8066 p By priority according to the cookie.
8067 r By the value of a property.
8069 Capital letters will reverse the sort order.
8071 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
8072 called with point at the beginning of the record. It must return either
8073 a string or a number that should serve as the sorting key for that record.
8075 Comparing entries ignores case by default. However, with an optional argument
8076 WITH-CASE, the sorting considers case as well."
8078 (let ((case-func (if with-case 'identity 'downcase))
8079 start beg end stars re re2
8081 ;; Find beginning and end of region to sort
8083 ((org-region-active-p)
8084 ;; we will sort the region
8085 (setq end (region-end)
8087 (goto-char (region-beginning))
8088 (if (not (org-at-heading-p)) (outline-next-heading))
8089 (setq start (point)))
8090 ((or (org-at-heading-p)
8091 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
8092 ;; we will sort the children of the current headline
8093 (org-back-to-heading)
8095 end (progn (org-end-of-subtree t t)
8096 (or (bolp) (insert "\n"))
8097 (org-back-over-empty-lines)
8102 (outline-next-heading))
8104 ;; we will sort the top-level entries in this file
8105 (goto-char (point-min))
8106 (or (org-at-heading-p) (outline-next-heading))
8107 (setq start (point))
8108 (goto-char (point-max))
8109 (beginning-of-line 1)
8110 (when (looking-at ".*?\\S-")
8111 ;; File ends in a non-white line
8114 (setq end (point-max))
8115 (setq what "top-level")
8120 (if (>= beg end) (error "Nothing to sort"))
8122 (looking-at "\\(\\*+\\)")
8123 (setq stars (match-string 1)
8124 re (concat "^" (regexp-quote stars) " +")
8125 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[ \t\n]")
8126 txt (buffer-substring beg end))
8127 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
8128 (if (and (not (equal stars "*")) (string-match re2 txt))
8129 (error "Region to sort contains a level above the first entry"))
8131 (unless sorting-type
8133 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
8134 [t]ime
[s]cheduled [d]eadline [c]reated
8135 A/N/T/S/D/C/P/O/F means reversed:"
8137 (setq sorting-type (read-char-exclusive))
8139 (and (= (downcase sorting-type) ?f)
8141 (org-icompleting-read "Sort using function: "
8142 obarray 'fboundp t nil nil))
8143 (setq getkey-func (intern getkey-func)))
8145 (and (= (downcase sorting-type) ?r)
8147 (org-icompleting-read "Property: "
8148 (mapcar 'list (org-buffer-property-keys t))
8151 (message "Sorting entries...")
8154 (narrow-to-region start end)
8155 (let ((dcst (downcase sorting-type))
8156 (case-fold-search nil)
8157 (now (current-time)))
8159 (/= dcst sorting-type)
8160 ;; This function moves to the beginning character of the "record" to
8163 (if (re-search-forward re nil t)
8164 (goto-char (match-beginning 0))
8165 (goto-char (point-max))))
8166 ;; This function moves to the last character of the "record" being
8171 (outline-forward-same-level 1)
8173 (goto-char (point-max))))))
8174 ;; This function returns the value that gets sorted against.
8178 (if (looking-at org-complex-heading-regexp)
8179 (string-to-number (match-string 4))
8182 (if (looking-at org-complex-heading-regexp)
8183 (funcall case-func (match-string 4))
8186 (let ((end (save-excursion (outline-next-heading) (point))))
8187 (if (or (re-search-forward org-ts-regexp end t)
8188 (re-search-forward org-ts-regexp-both end t))
8189 (org-time-string-to-seconds (match-string 0))
8190 (org-float-time now))))
8192 (let ((end (save-excursion (outline-next-heading) (point))))
8193 (if (re-search-forward
8194 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
8196 (org-time-string-to-seconds (match-string 0))
8197 (org-float-time now))))
8199 (let ((end (save-excursion (outline-next-heading) (point))))
8200 (if (re-search-forward org-scheduled-time-regexp end t)
8201 (org-time-string-to-seconds (match-string 1))
8202 (org-float-time now))))
8204 (let ((end (save-excursion (outline-next-heading) (point))))
8205 (if (re-search-forward org-deadline-time-regexp end t)
8206 (org-time-string-to-seconds (match-string 1))
8207 (org-float-time now))))
8209 (if (re-search-forward org-priority-regexp (point-at-eol) t)
8210 (string-to-char (match-string 2))
8211 org-default-priority))
8213 (or (org-entry-get nil property) ""))
8215 (if (looking-at org-complex-heading-regexp)
8216 (- 9999 (length (member (match-string 2)
8217 org-todo-keywords-1)))))
8221 (setq tmp (funcall getkey-func))
8222 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
8224 (error "Invalid key function `%s'" getkey-func)))
8225 (t (error "Invalid sorting type `%c'" sorting-type))))
8228 ((= dcst ?a) 'string<)
8229 ((= dcst ?f) compare-func)
8230 ((member dcst '(?p ?t ?s ?d ?c)) '<)
8232 (run-hooks 'org-after-sorting-entries-or-items-hook)
8233 (message "Sorting entries...done")))
8235 (defun org-do-sort (table what &optional with-case sorting-type)
8236 "Sort TABLE of WHAT according to SORTING-TYPE.
8237 The user will be prompted for the SORTING-TYPE if the call to this
8238 function does not specify it. WHAT is only for the prompt, to indicate
8239 what is being sorted. The sorting key will be extracted from
8240 the car of the elements of the table.
8241 If WITH-CASE is non-nil, the sorting will be case-sensitive."
8242 (unless sorting-type
8244 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
8246 (setq sorting-type (read-char-exclusive)))
8247 (let ((dcst (downcase sorting-type))
8248 extractfun comparefun)
8249 ;; Define the appropriate functions
8252 (setq extractfun 'string-to-number
8253 comparefun (if (= dcst sorting-type) '< '>)))
8255 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
8256 (lambda(x) (downcase (org-sort-remove-invisible x))))
8257 comparefun (if (= dcst sorting-type)
8259 (lambda (a b) (and (not (string< a b))
8260 (not (string= a b)))))))
8264 (if (or (string-match org-ts-regexp x)
8265 (string-match org-ts-regexp-both x))
8267 (org-time-string-to-time (match-string 0 x)))
8269 comparefun (if (= dcst sorting-type) '< '>)))
8270 (t (error "Invalid sorting type `%c'" sorting-type)))
8272 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
8274 (lambda (a b) (funcall comparefun (car a) (car b))))))
8277 ;;; The orgstruct minor mode
8279 ;; Define a minor mode which can be used in other modes in order to
8280 ;; integrate the org-mode structure editing commands.
8282 ;; This is really a hack, because the org-mode structure commands use
8283 ;; keys which normally belong to the major mode. Here is how it
8284 ;; works: The minor mode defines all the keys necessary to operate the
8285 ;; structure commands, but wraps the commands into a function which
8286 ;; tests if the cursor is currently at a headline or a plain list
8287 ;; item. If that is the case, the structure command is used,
8288 ;; temporarily setting many Org-mode variables like regular
8289 ;; expressions for filling etc. However, when any of those keys is
8290 ;; used at a different location, function uses `key-binding' to look
8291 ;; up if the key has an associated command in another currently active
8292 ;; keymap (minor modes, major mode, global), and executes that
8293 ;; command. There might be problems if any of the keys is otherwise
8294 ;; used as a prefix key.
8296 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
8297 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
8298 ;; addresses this by checking explicitly for both bindings.
8300 (defvar orgstruct-mode-map (make-sparse-keymap)
8301 "Keymap for the minor `orgstruct-mode'.")
8303 (defvar org-local-vars nil
8304 "List of local variables, for use by `orgstruct-mode'.")
8307 (define-minor-mode orgstruct-mode
8308 "Toggle the minor mode `orgstruct-mode'.
8309 This mode is for using Org-mode structure commands in other
8310 modes. The following keys behave as if Org-mode were active, if
8311 the cursor is on a headline, or on a plain list item (both as
8312 defined by Org-mode).
8314 M-up Move entry/item up
8315 M-down Move entry/item down
8318 M-S-up Move entry/item up
8319 M-S-down Move entry/item down
8320 M-S-left Promote subtree
8321 M-S-right Demote subtree
8322 M-q Fill paragraph and items like in Org-mode
8324 C-c - Cycle list bullet
8325 TAB Cycle item visibility
8326 M-RET Insert new heading/item
8327 S-M-RET Insert new TODO heading / Checkbox item
8328 C-c C-c Set tags / toggle checkbox"
8329 nil " OrgStruct" nil
8330 (org-load-modules-maybe)
8331 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
8334 (defun turn-on-orgstruct ()
8335 "Unconditionally turn on `orgstruct-mode'."
8338 (defun orgstruct++-mode (&optional arg)
8339 "Toggle `orgstruct-mode', the enhanced version of it.
8340 In addition to setting orgstruct-mode, this also exports all indentation
8341 and autofilling variables from org-mode into the buffer. It will also
8342 recognize item context in multiline items.
8343 Note that turning off orgstruct-mode will *not* remove the
8344 indentation/paragraph settings. This can only be done by refreshing the
8345 major mode, for example with \\[normal-mode]."
8347 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
8355 "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
8356 (symbol-name (car x)))
8357 (setq var (car x) val (nth 1 x))
8358 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
8360 (org-set-local 'orgstruct-is-++ t))))
8362 (defvar orgstruct-is-++ nil
8363 "Is `orgstruct-mode' in ++ version in the current-buffer?")
8364 (make-variable-buffer-local 'orgstruct-is-++)
8367 (defun turn-on-orgstruct++ ()
8368 "Unconditionally turn on `orgstruct++-mode'."
8369 (orgstruct++-mode 1))
8371 (defun orgstruct-error ()
8372 "Error when there is no default binding for a structure key."
8374 (error "This key has no function outside structure elements"))
8376 (defun orgstruct-setup ()
8377 "Setup orgstruct keymaps."
8381 '([(meta up)] org-metaup)
8382 '([(meta down)] org-metadown)
8383 '([(meta left)] org-metaleft)
8384 '([(meta right)] org-metaright)
8385 '([(meta shift up)] org-shiftmetaup)
8386 '([(meta shift down)] org-shiftmetadown)
8387 '([(meta shift left)] org-shiftmetaleft)
8388 '([(meta shift right)] org-shiftmetaright)
8389 '([?\e (up)] org-metaup)
8390 '([?\e (down)] org-metadown)
8391 '([?\e (left)] org-metaleft)
8392 '([?\e (right)] org-metaright)
8393 '([?\e (shift up)] org-shiftmetaup)
8394 '([?\e (shift down)] org-shiftmetadown)
8395 '([?\e (shift left)] org-shiftmetaleft)
8396 '([?\e (shift right)] org-shiftmetaright)
8397 '([(shift up)] org-shiftup)
8398 '([(shift down)] org-shiftdown)
8399 '([(shift left)] org-shiftleft)
8400 '([(shift right)] org-shiftright)
8401 '("\C-c\C-c" org-ctrl-c-ctrl-c)
8402 '("\M-q" fill-paragraph)
8404 '("\C-c-" org-cycle-list-bullet)))
8406 (while (setq elt (pop bindings))
8407 (setq nfunc (1+ nfunc))
8408 (setq key (org-key (car elt))
8410 cmd (orgstruct-make-binding fun nfunc key))
8411 (org-defkey orgstruct-mode-map key cmd))
8413 ;; Special treatment needed for TAB and RET
8414 (org-defkey orgstruct-mode-map [(tab)]
8415 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
8416 (org-defkey orgstruct-mode-map "\C-i"
8417 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
8419 (org-defkey orgstruct-mode-map "\M-\C-m"
8420 (orgstruct-make-binding 'org-insert-heading 105
8421 "\M-\C-m" [(meta return)]))
8422 (org-defkey orgstruct-mode-map [(meta return)]
8423 (orgstruct-make-binding 'org-insert-heading 106
8424 [(meta return)] "\M-\C-m"))
8426 (org-defkey orgstruct-mode-map [(shift meta return)]
8427 (orgstruct-make-binding 'org-insert-todo-heading 107
8428 [(meta return)] "\M-\C-m"))
8430 (org-defkey orgstruct-mode-map "\e\C-m"
8431 (orgstruct-make-binding 'org-insert-heading 108
8432 "\e\C-m" [?\e (return)]))
8433 (org-defkey orgstruct-mode-map [?\e (return)]
8434 (orgstruct-make-binding 'org-insert-heading 109
8435 [?\e (return)] "\e\C-m"))
8436 (org-defkey orgstruct-mode-map [?\e (shift return)]
8437 (orgstruct-make-binding 'org-insert-todo-heading 110
8438 [?\e (return)] "\e\C-m"))
8440 (unless org-local-vars
8441 (setq org-local-vars (org-get-local-variables)))
8445 (defun orgstruct-make-binding (fun n &rest keys)
8446 "Create a function for binding in the structure minor mode.
8447 FUN is the command to call inside a table. N is used to create a unique
8448 command name. KEYS are keys that should be checked in for a command
8449 to execute outside of tables."
8452 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
8454 (concat "In Structure, run `" (symbol-name fun) "'.\n"
8455 "Outside of structure, run the binding of `"
8456 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
8460 `(org-context-p 'headline 'item
8461 (and orgstruct-is-++
8462 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
8464 (list 'org-run-like-in-org-mode (list 'quote fun))
8465 (list 'let '(orgstruct-mode)
8466 (list 'call-interactively
8469 (list 'key-binding k))
8471 '('orgstruct-error))))))))
8473 (defun org-context-p (&rest contexts)
8474 "Check if local context is any of CONTEXTS.
8475 Possible values in the list of contexts are `table', `headline', and `item'."
8476 (let ((pos (point)))
8477 (goto-char (point-at-bol))
8478 (prog1 (or (and (memq 'table contexts)
8479 (looking-at "[ \t]*|"))
8480 (and (memq 'headline contexts)
8481 (looking-at org-outline-regexp))
8482 (and (memq 'item contexts)
8483 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
8484 (and (memq 'item-body contexts)
8488 (defun org-get-local-variables ()
8489 "Return a list of all local variables in an org-mode buffer."
8491 (with-current-buffer (get-buffer-create "*Org tmp*")
8494 (setq varlist (buffer-local-variables)))
8495 (kill-buffer "*Org tmp*")
8502 (list (car x) (list 'quote (cdr x)))))
8504 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)"
8505 (symbol-name (car x)))
8509 (defun org-clone-local-variables (from-buffer &optional regexp)
8510 "Clone local variables from FROM-BUFFER.
8511 Optional argument REGEXP selects variables to clone."
8514 (and (symbolp (car pair))
8516 (string-match regexp (symbol-name (car pair))))
8517 (set (make-local-variable (car pair))
8519 (buffer-local-variables from-buffer)))
8522 (defun org-run-like-in-org-mode (cmd)
8523 "Run a command, pretending that the current buffer is in Org-mode.
8524 This will temporarily bind local variables that are typically bound in
8525 Org-mode to the values they have in Org-mode, and then interactively
8527 (org-load-modules-maybe)
8528 (unless org-local-vars
8529 (setq org-local-vars (org-get-local-variables)))
8530 (eval (list 'let org-local-vars
8531 (list 'call-interactively (list 'quote cmd)))))
8535 (defun org-get-category (&optional pos force-refresh)
8536 "Get the category applying to position POS."
8537 (if force-refresh (org-refresh-category-properties))
8538 (let ((pos (or pos (point))))
8539 (or (get-text-property pos 'org-category)
8540 (progn (org-refresh-category-properties)
8541 (get-text-property pos 'org-category)))))
8543 (defun org-refresh-category-properties ()
8544 "Refresh category text properties in the buffer."
8545 (let ((def-cat (cond
8546 ((null org-category)
8547 (if buffer-file-name
8548 (file-name-sans-extension
8549 (file-name-nondirectory buffer-file-name))
8551 ((symbolp org-category) (symbol-name org-category))
8553 beg end cat pos optionp)
8558 (goto-char (point-min))
8559 (put-text-property (point) (point-max) 'org-category def-cat)
8560 (while (re-search-forward
8561 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
8562 (setq pos (match-end 0)
8563 optionp (equal (char-after (match-beginning 0)) ?#)
8564 cat (org-trim (match-string 2)))
8566 (setq beg (point-at-bol) end (point-max))
8567 (org-back-to-heading t)
8568 (setq beg (point) end (org-end-of-subtree t t)))
8569 (put-text-property beg end 'org-category cat)
8570 (put-text-property beg end 'org-category-position beg)
8571 (goto-char pos)))))))
8576 ;;; Link abbreviations
8578 (defun org-link-expand-abbrev (link)
8579 "Apply replacements as defined in `org-link-abbrev-alist."
8580 (if (string-match "^\\([^:]*\\)\\(::?\\(.*\\)\\)?$" link)
8581 (let* ((key (match-string 1 link))
8582 (as (or (assoc key org-link-abbrev-alist-local)
8583 (assoc key org-link-abbrev-alist)))
8584 (tag (and (match-end 2) (match-string 3 link)))
8590 ((symbolp rpl) (funcall rpl tag))
8591 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
8592 ((string-match "%h" rpl)
8593 (replace-match (url-hexify-string (or tag "")) t t rpl))
8594 (t (concat rpl tag)))))
8597 ;;; Storing and inserting links
8599 (defvar org-insert-link-history nil
8600 "Minibuffer history for links inserted with `org-insert-link'.")
8602 (defvar org-stored-links nil
8603 "Contains the links stored with `org-store-link'.")
8605 (defvar org-store-link-plist nil
8606 "Plist with info about the most recently link created with `org-store-link'.")
8608 (defvar org-link-protocols nil
8609 "Link protocols added to Org-mode using `org-add-link-type'.")
8611 (defvar org-store-link-functions nil
8612 "List of functions that are called to create and store a link.
8613 Each function will be called in turn until one returns a non-nil
8614 value. Each function should check if it is responsible for creating
8615 this link (for example by looking at the major mode).
8616 If not, it must exit and return nil.
8617 If yes, it should return a non-nil value after a calling
8618 `org-store-link-props' with a list of properties and values.
8619 Special properties are:
8621 :type The link prefix, like \"http\". This must be given.
8622 :link The link, like \"http://www.astro.uva.nl/~dominik\".
8623 This is obligatory as well.
8624 :description Optional default description for the second pair
8625 of brackets in an Org-mode link. The user can still change
8626 this when inserting this link into an Org-mode buffer.
8628 In addition to these, any additional properties can be specified
8629 and then used in remember templates.")
8631 (defun org-add-link-type (type &optional follow export)
8632 "Add TYPE to the list of `org-link-types'.
8633 Re-compute all regular expressions depending on `org-link-types'
8635 FOLLOW and EXPORT are two functions.
8637 FOLLOW should take the link path as the single argument and do whatever
8638 is necessary to follow the link, for example find a file or display
8641 EXPORT should format the link path for export to one of the export formats.
8642 It should be a function accepting three arguments:
8644 path the path of the link, the text after the prefix (like \"http:\")
8645 desc the description of the link, if any, or a description added by
8646 org-export-normalize-links if there is none
8647 format the export format, a symbol like `html' or `latex' or `ascii'..
8649 The function may use the FORMAT information to return different values
8650 depending on the format. The return value will be put literally into
8651 the exported file. If the return value is nil, this means Org should
8652 do what it normally does with links which do not have EXPORT defined.
8654 Org-mode has a built-in default for exporting links. If you are happy with
8655 this default, there is no need to define an export function for the link
8656 type. For a simple example of an export function, see `org-bbdb.el'."
8657 (add-to-list 'org-link-types type t)
8658 (org-make-link-regexps)
8659 (if (assoc type org-link-protocols)
8660 (setcdr (assoc type org-link-protocols) (list follow export))
8661 (push (list type follow export) org-link-protocols)))
8663 (defvar org-agenda-buffer-name)
8666 (defun org-store-link (arg)
8667 "\\<org-mode-map>Store an org-link to the current location.
8668 This link is added to `org-stored-links' and can later be inserted
8669 into an org-buffer with \\[org-insert-link].
8671 For some link types, a prefix arg is interpreted:
8672 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
8673 For file links, arg negates `org-context-in-file-links'."
8675 (org-load-modules-maybe)
8676 (setq org-store-link-plist nil) ; reset
8677 (org-with-limited-levels
8678 (let (link cpltxt desc description search txt custom-id agenda-link)
8681 ((run-hook-with-args-until-success 'org-store-link-functions)
8682 (setq link (plist-get org-store-link-plist :link)
8683 desc (or (plist-get org-store-link-plist :description) link)))
8685 ((equal (buffer-name) "*Org Edit Src Example*")
8687 (while (or (not label)
8691 (goto-char (point-min))
8693 (regexp-quote (format org-coderef-label-format label))
8695 (when label (message "Label exists already") (sit-for 2))
8696 (setq label (read-string "Code line label: " label)))
8698 (setq link (format org-coderef-label-format label))
8699 (setq gc (- 79 (length link)))
8700 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8702 (setq link (concat "(" label ")") desc nil)))
8704 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8705 ;; We are in the agenda, link to referenced location
8706 (let ((m (or (get-text-property (point) 'org-hd-marker)
8707 (get-text-property (point) 'org-marker))))
8709 (org-with-point-at m
8711 (if (org-called-interactively-p 'any)
8712 (call-interactively 'org-store-link)
8713 (org-store-link nil)))))))
8715 ((eq major-mode 'calendar-mode)
8716 (let ((cd (calendar-cursor-to-date)))
8719 (car org-time-stamp-formats)
8721 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8723 (org-store-link-props :type "calendar" :date cd)))
8725 ((eq major-mode 'w3-mode)
8726 (setq cpltxt (if (and (buffer-name)
8727 (not (string-match "Untitled" (buffer-name))))
8730 link (org-make-link (url-view-url t)))
8731 (org-store-link-props :type "w3" :url (url-view-url t)))
8733 ((eq major-mode 'w3m-mode)
8734 (setq cpltxt (or w3m-current-title w3m-current-url)
8735 link (org-make-link w3m-current-url))
8736 (org-store-link-props :type "w3m" :url (url-view-url t)))
8738 ((setq search (run-hook-with-args-until-success
8739 'org-create-file-search-functions))
8740 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
8742 (setq cpltxt (or description link)))
8744 ((eq major-mode 'image-mode)
8745 (setq cpltxt (concat "file:"
8746 (abbreviate-file-name buffer-file-name))
8747 link (org-make-link cpltxt))
8748 (org-store-link-props :type "image" :file buffer-file-name))
8750 ((eq major-mode 'dired-mode)
8751 ;; link to the file in the current line
8752 (let ((file (dired-get-filename nil t)))
8754 (abbreviate-file-name
8755 (expand-file-name (dired-get-filename nil t)))
8756 ;; otherwise, no file so use current directory.
8758 (setq cpltxt (concat "file:" file)
8759 link (org-make-link cpltxt))))
8761 ((and (buffer-file-name (buffer-base-buffer)) (eq major-mode 'org-mode))
8762 (setq custom-id (org-entry-get nil "CUSTOM_ID"))
8764 ((org-in-regexp "<<\\(.*?\\)>>")
8767 (abbreviate-file-name
8768 (buffer-file-name (buffer-base-buffer)))
8769 "::" (match-string 1))
8770 link (org-make-link cpltxt)))
8771 ((and (featurep 'org-id)
8772 (or (eq org-link-to-org-use-id t)
8773 (and (eq org-link-to-org-use-id 'create-if-interactive)
8774 (org-called-interactively-p 'any))
8775 (and (eq org-link-to-org-use-id
8776 'create-if-interactive-and-no-custom-id)
8777 (org-called-interactively-p 'any)
8779 (and org-link-to-org-use-id
8780 (org-entry-get nil "ID"))))
8781 ;; We can make a link using the ID.
8782 (setq link (condition-case nil
8783 (prog1 (org-id-store-link)
8784 (setq desc (plist-get org-store-link-plist
8787 ;; probably before first headline, link to file only
8789 (abbreviate-file-name
8790 (buffer-file-name (buffer-base-buffer))))))))
8792 ;; Just link to current headline
8793 (setq cpltxt (concat "file:"
8794 (abbreviate-file-name
8795 (buffer-file-name (buffer-base-buffer)))))
8796 ;; Add a context search string
8797 (when (org-xor org-context-in-file-links arg)
8799 ((org-at-heading-p) nil)
8800 ((org-region-active-p)
8801 (buffer-substring (region-beginning) (region-end)))
8803 (when (or (null txt) (string-match "\\S-" txt))
8807 (org-make-org-heading-search-string txt)
8809 desc (or (nth 4 (ignore-errors
8810 (org-heading-components))) "NONE"))))
8811 (if (string-match "::\\'" cpltxt)
8812 (setq cpltxt (substring cpltxt 0 -2)))
8813 (setq link (org-make-link cpltxt)))))
8815 ((buffer-file-name (buffer-base-buffer))
8816 ;; Just link to this file here.
8817 (setq cpltxt (concat "file:"
8818 (abbreviate-file-name
8819 (buffer-file-name (buffer-base-buffer)))))
8820 ;; Add a context string
8821 (when (org-xor org-context-in-file-links arg)
8822 (setq txt (if (org-region-active-p)
8823 (buffer-substring (region-beginning) (region-end))
8824 (buffer-substring (point-at-bol) (point-at-eol))))
8825 ;; Only use search option if there is some text.
8826 (when (string-match "\\S-" txt)
8828 (concat cpltxt "::" (org-make-org-heading-search-string txt))
8830 (setq link (org-make-link cpltxt)))
8832 ((org-called-interactively-p 'interactive)
8833 (error "Cannot link to a buffer which is not visiting a file"))
8835 (t (setq link nil)))
8837 (if (consp link) (setq cpltxt (car link) link (cdr link)))
8838 (setq link (or link cpltxt)
8839 desc (or desc cpltxt))
8840 (if (equal desc "NONE") (setq desc nil))
8842 (if (and (or (org-called-interactively-p 'any) executing-kbd-macro) link)
8844 (setq org-stored-links
8845 (cons (list link desc) org-stored-links))
8846 (message "Stored: %s" (or desc link))
8848 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
8850 (setq org-stored-links
8851 (cons (list link desc) org-stored-links))))
8852 (or agenda-link (and link (org-make-link-string link desc)))))))
8854 (defun org-store-link-props (&rest plist)
8855 "Store link properties, extract names and addresses."
8857 (when (setq x (plist-get plist :from))
8858 (setq adr (mail-extract-address-components x))
8859 (setq plist (plist-put plist :fromname (car adr)))
8860 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
8861 (when (setq x (plist-get plist :to))
8862 (setq adr (mail-extract-address-components x))
8863 (setq plist (plist-put plist :toname (car adr)))
8864 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
8865 (let ((from (plist-get plist :from))
8866 (to (plist-get plist :to)))
8867 (when (and from to org-from-is-user-regexp)
8869 (plist-put plist :fromto
8870 (if (string-match org-from-is-user-regexp from)
8872 (concat "from %f"))))))
8873 (setq org-store-link-plist plist))
8875 (defun org-add-link-props (&rest plist)
8876 "Add these properties to the link property list."
8879 (setq key (pop plist) value (pop plist))
8880 (setq org-store-link-plist
8881 (plist-put org-store-link-plist key value)))))
8883 (defun org-email-link-description (&optional fmt)
8884 "Return the description part of an email link.
8885 This takes information from `org-store-link-plist' and formats it
8886 according to FMT (default from `org-email-link-description-format')."
8887 (setq fmt (or fmt org-email-link-description-format))
8888 (let* ((p org-store-link-plist)
8889 (to (plist-get p :toaddress))
8890 (from (plist-get p :fromaddress))
8893 (cons "%c" (plist-get p :fromto))
8894 (cons "%F" (plist-get p :from))
8895 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
8896 (cons "%T" (plist-get p :to))
8897 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
8898 (cons "%s" (plist-get p :subject))
8899 (cons "%d" (plist-get p :date))
8900 (cons "%m" (plist-get p :message-id)))))
8901 (when (string-match "%c" fmt)
8902 ;; Check if the user wrote this message
8903 (if (and org-from-is-user-regexp from to
8904 (save-match-data (string-match org-from-is-user-regexp from)))
8905 (setq fmt (replace-match "to %t" t t fmt))
8906 (setq fmt (replace-match "from %f" t t fmt))))
8907 (org-replace-escapes fmt table)))
8909 (defun org-make-org-heading-search-string (&optional string heading)
8910 "Make search string for STRING or current headline."
8912 (let ((s (or string (org-get-heading)))
8913 (lines org-context-in-file-links))
8914 (unless (and string (not heading))
8915 ;; We are using a headline, clean up garbage in there.
8916 (if (string-match org-todo-regexp s)
8917 (setq s (replace-match "" t t s)))
8918 (if (string-match (org-re ":[[:alnum:]_@#%:]+:[ \t]*$") s)
8919 (setq s (replace-match "" t t s)))
8920 (setq s (org-trim s))
8921 (if (string-match (concat "^\\(" org-quote-string "\\|"
8922 org-comment-string "\\)") s)
8923 (setq s (replace-match "" t t s)))
8924 (while (string-match org-ts-regexp s)
8925 (setq s (replace-match "" t t s))))
8926 (or string (setq s (concat "*" s))) ; Add * for headlines
8927 (when (and string (integerp lines) (> lines 0))
8928 (let ((slines (org-split-string s "\n")))
8929 (when (< lines (length slines))
8932 (reverse (nthcdr (- (length slines) lines)
8933 (reverse slines))) "\n")))))
8934 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
8936 (defun org-make-link (&rest strings)
8937 "Concatenate STRINGS."
8938 (apply 'concat strings))
8940 (defun org-make-link-string (link &optional description)
8941 "Make a link with brackets, consisting of LINK and DESCRIPTION."
8942 (unless (string-match "\\S-" link)
8943 (error "Empty link"))
8944 (when (and description
8945 (stringp description)
8946 (not (string-match "\\S-" description)))
8947 (setq description nil))
8948 (when (stringp description)
8949 ;; Remove brackets from the description, they are fatal.
8950 (while (string-match "\\[" description)
8951 (setq description (replace-match "{" t t description)))
8952 (while (string-match "\\]" description)
8953 (setq description (replace-match "}" t t description))))
8954 (when (equal link description)
8955 ;; No description needed, it is identical
8956 (setq description nil))
8957 (when (and (not description)
8958 (not (string-match (org-image-file-name-regexp) link))
8959 (not (equal link (org-link-escape link))))
8960 (setq description (org-extract-attributes link)))
8962 (cond ((string-match (org-image-file-name-regexp) link) link)
8963 ((string-match org-link-types-re link)
8964 (concat (match-string 1 link)
8965 (org-link-escape (substring link (match-end 1)))))
8966 (t (org-link-escape link))))
8967 (concat "[[" link "]"
8968 (if description (concat "[" description "]") "")
8971 (defconst org-link-escape-chars
8972 '(?\ ?\[ ?\] ?\; ?\= ?\+)
8973 "List of characters that should be escaped in link.
8974 This is the list that is used for internal purposes.")
8976 (defvar org-url-encoding-use-url-hexify nil)
8978 (defconst org-link-escape-chars-browser
8980 "List of escapes for characters that are problematic in links.
8981 This is the list that is used before handing over to the browser.")
8983 (defun org-link-escape (text &optional table merge)
8984 "Return percent escaped representation of TEXT.
8985 TEXT is a string with the text to escape.
8986 Optional argument TABLE is a list with characters that should be
8987 escaped. When nil, `org-link-escape-chars' is used.
8988 If optional argument MERGE is set, merge TABLE into
8989 `org-link-escape-chars'."
8990 (if (and org-url-encoding-use-url-hexify (not table))
8991 (url-hexify-string text)
8994 (mapc (lambda (defchr)
8995 (unless (member defchr table)
8996 (setq table (cons defchr table)))) org-link-escape-chars))
8998 (setq table org-link-escape-chars)))
9001 (if (or (member char table)
9002 (< char 32) (= char 37) (> char 126))
9003 (mapconcat (lambda (sequence-element)
9004 (format "%%%.2X" sequence-element))
9005 (or (encode-coding-char char 'utf-8)
9006 (error "Unable to percent escape character: %s"
9007 (char-to-string char))) "")
9008 (char-to-string char))) text "")))
9010 (defun org-link-unescape (str)
9011 "Unhex hexified Unicode strings as returned from the JavaScript function
9012 encodeURIComponent. E.g. `%C3%B6' is the german Umlaut `ö'."
9013 (unless (and (null str) (string= "" str))
9014 (let ((pos 0) (case-fold-search t) unhexed)
9015 (while (setq pos (string-match "\\(%[0-9a-f][0-9a-f]\\)+" str pos))
9016 (setq unhexed (org-link-unescape-compound (match-string 0 str)))
9017 (setq str (replace-match unhexed t t str))
9018 (setq pos (+ pos (length unhexed))))))
9021 (defun org-link-unescape-compound (hex)
9022 "Unhexify Unicode hex-chars. E.g. `%C3%B6' is the German Umlaut `ö'.
9023 Note: this function also decodes single byte encodings like
9024 `%E1' (\"á\") if not followed by another `%[A-F0-9]{2}' group."
9026 (let* ((bytes (cdr (split-string hex "%")))
9031 (let* ((val (string-to-number (pop bytes) 16))
9035 ((>= val 252) (cons 6 252))
9036 ((>= val 248) (cons 5 248))
9037 ((>= val 240) (cons 4 240))
9038 ((>= val 224) (cons 3 224))
9039 ((>= val 192) (cons 2 192))
9042 (if (>= val 192) (setq eat (car shift-xor)))
9043 (setq val (logxor val (cdr shift-xor)))
9044 (setq sum (+ (lsh sum (car shift-xor)) val))
9045 (if (> eat 0) (setq eat (- eat 1)))
9047 ((= 0 eat) ;multi byte
9048 (setq ret (concat ret (org-char-to-string sum)))
9050 ((not bytes) ; single byte(s)
9051 (setq ret (org-link-unescape-single-byte-sequence hex))))
9052 )) ;; end (while bytes
9055 (defun org-link-unescape-single-byte-sequence (hex)
9056 "Unhexify hex-encoded single byte character sequences."
9057 (mapconcat (lambda (byte)
9058 (char-to-string (string-to-number byte 16)))
9059 (cdr (split-string hex "%")) ""))
9061 (defun org-xor (a b)
9065 (defun org-fixup-message-id-for-http (s)
9066 "Replace special characters in a message id, so it can be used in an http query."
9067 (when (string-match "%" s)
9068 (setq s (mapconcat (lambda (c)
9071 (char-to-string c)))
9073 (while (string-match "<" s)
9074 (setq s (replace-match "%3C" t t s)))
9075 (while (string-match ">" s)
9076 (setq s (replace-match "%3E" t t s)))
9077 (while (string-match "@" s)
9078 (setq s (replace-match "%40" t t s)))
9082 (defun org-insert-link-global ()
9083 "Insert a link like Org-mode does.
9084 This command can be called in any mode to insert a link in Org-mode syntax."
9086 (org-load-modules-maybe)
9087 (org-run-like-in-org-mode 'org-insert-link))
9089 (defun org-insert-link (&optional complete-file link-location default-description)
9090 "Insert a link. At the prompt, enter the link.
9092 Completion can be used to insert any of the link protocol prefixes like
9095 The history can be used to select a link previously stored with
9096 `org-store-link'. When the empty string is entered (i.e. if you just
9097 press RET at the prompt), the link defaults to the most recently
9098 stored link. As SPC triggers completion in the minibuffer, you need to
9099 use M-SPC or C-q SPC to force the insertion of a space character.
9101 You will also be prompted for a description, and if one is given, it will
9102 be displayed in the buffer instead of the link.
9104 If there is already a link at point, this command will allow you to edit link
9105 and description parts.
9107 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
9108 be selected using completion. The path to the file will be relative to the
9109 current directory if the file is in the current directory or a subdirectory.
9110 Otherwise, the link will be the absolute path as completed in the minibuffer
9111 \(i.e. normally ~/path/to/file). You can configure this behavior using the
9112 option `org-link-file-path-type'.
9114 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
9115 the current directory or below.
9117 With three \\[universal-argument] prefixes, negate the meaning of
9118 `org-keep-stored-link-after-insertion'.
9120 If `org-make-link-description-function' is non-nil, this function will be
9121 called with the link target, and the result will be the default
9124 If the LINK-LOCATION parameter is non-nil, this value will be
9125 used as the link location instead of reading one interactively.
9127 If the DEFAULT-DESCRIPTION parameter is non-nil, this value will
9128 be used as the default description."
9130 (let* ((wcf (current-window-configuration))
9131 (region (if (org-region-active-p)
9132 (buffer-substring (region-beginning) (region-end))))
9133 (remove (and region (list (region-beginning) (region-end))))
9135 tmphist ; byte-compile incorrectly complains about this
9136 (link link-location)
9137 entry file all-prefixes)
9139 (link-location) ; specified by arg, just use it.
9140 ((org-in-regexp org-bracket-link-regexp 1)
9141 ;; We do have a link at point, and we are going to edit it.
9142 (setq remove (list (match-beginning 0) (match-end 0)))
9143 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
9144 (setq link (read-string "Link: "
9146 (org-match-string-no-properties 1)))))
9147 ((or (org-in-regexp org-angle-link-re)
9148 (org-in-regexp org-plain-link-re))
9149 ;; Convert to bracket link
9150 (setq remove (list (match-beginning 0) (match-end 0))
9151 link (read-string "Link: "
9152 (org-remove-angle-brackets (match-string 0)))))
9153 ((member complete-file '((4) (16)))
9154 ;; Completing read for file names.
9155 (setq link (org-file-complete-link complete-file)))
9157 ;; Read link, with completion for stored links.
9158 (with-output-to-temp-buffer "*Org Links*"
9159 (princ "Insert a link.
9160 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
9161 (when org-stored-links
9162 (princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
9165 (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
9166 (reverse org-stored-links) "\n"))))
9167 (let ((cw (selected-window)))
9168 (select-window (get-buffer-window "*Org Links*" 'visible))
9169 (with-current-buffer "*Org Links*" (setq truncate-lines t))
9170 (unless (pos-visible-in-window-p (point-max))
9171 (org-fit-window-to-buffer))
9172 (and (window-live-p cw) (select-window cw)))
9173 ;; Fake a link history, containing the stored links.
9174 (setq tmphist (append (mapcar 'car org-stored-links)
9175 org-insert-link-history))
9176 (setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
9177 (mapcar 'car org-link-abbrev-alist)
9182 (let ((org-completion-use-ido nil)
9183 (org-completion-use-iswitchb nil))
9184 (org-completing-read
9187 (mapcar (lambda (x) (list (concat x ":")))
9189 (mapcar 'car org-stored-links))
9192 (car (car org-stored-links)))))
9193 (if (not (string-match "\\S-" link))
9194 (error "No link selected"))
9195 (if (or (member link all-prefixes)
9196 (and (equal ":" (substring link -1))
9197 (member (substring link 0 -1) all-prefixes)
9198 (setq link (substring link 0 -1))))
9199 (setq link (org-link-try-special-completion link))))
9200 (set-window-configuration wcf)
9201 (kill-buffer "*Org Links*"))
9202 (setq entry (assoc link org-stored-links))
9203 (or entry (push link org-insert-link-history))
9204 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
9205 (not org-keep-stored-link-after-insertion))
9206 (setq org-stored-links (delq (assoc link org-stored-links)
9208 (setq desc (or desc (nth 1 entry)))))
9210 (if (string-match org-plain-link-re link)
9211 ;; URL-like link, normalize the use of angular brackets.
9212 (setq link (org-make-link (org-remove-angle-brackets link))))
9214 ;; Check if we are linking to the current file with a search option
9215 ;; If yes, simplify the link by using only the search option.
9216 (when (and buffer-file-name
9217 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
9218 (let* ((path (match-string 1 link))
9219 (case-fold-search nil)
9220 (search (match-string 2 link)))
9222 (if (equal (file-truename buffer-file-name) (file-truename path))
9223 ;; We are linking to this same file, with a search option
9224 (setq link search)))))
9226 ;; Check if we can/should use a relative path. If yes, simplify the link
9227 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
9228 (let* ((type (match-string 1 link))
9229 (path (match-string 2 link))
9231 (case-fold-search nil))
9233 ((or (eq org-link-file-path-type 'absolute)
9234 (equal complete-file '(16)))
9235 (setq path (abbreviate-file-name (expand-file-name path))))
9236 ((eq org-link-file-path-type 'noabbrev)
9237 (setq path (expand-file-name path)))
9238 ((eq org-link-file-path-type 'relative)
9239 (setq path (file-relative-name path)))
9242 (if (string-match (concat "^" (regexp-quote
9244 (file-name-as-directory
9245 default-directory))))
9246 (expand-file-name path))
9247 ;; We are linking a file with relative path name.
9248 (setq path (substring (expand-file-name path)
9250 (setq path (abbreviate-file-name (expand-file-name path)))))))
9251 (setq link (concat type path))
9252 (if (equal desc origpath)
9255 (if org-make-link-description-function
9256 (setq desc (funcall org-make-link-description-function link desc))
9257 (if default-description (setq desc default-description)))
9259 (setq desc (read-string "Description: " desc))
9260 (unless (string-match "\\S-" desc) (setq desc nil))
9261 (if remove (apply 'delete-region remove))
9262 (insert (org-make-link-string link desc))))
9264 (defun org-link-try-special-completion (type)
9265 "If there is completion support for link type TYPE, offer it."
9266 (let ((fun (intern (concat "org-" type "-complete-link"))))
9269 (read-string "Link (no completion support): " (concat type ":")))))
9271 (defun org-file-complete-link (&optional arg)
9272 "Create a file link using completion."
9274 (setq file (read-file-name "File: "))
9275 (let ((pwd (file-name-as-directory (expand-file-name ".")))
9276 (pwd1 (file-name-as-directory (abbreviate-file-name
9277 (expand-file-name ".")))))
9280 (setq link (org-make-link
9282 (abbreviate-file-name (expand-file-name file)))))
9283 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
9284 (setq link (org-make-link "file:" (match-string 1 file))))
9285 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
9286 (expand-file-name file))
9287 (setq link (org-make-link
9288 "file:" (match-string 1 (expand-file-name file)))))
9289 (t (setq link (org-make-link "file:" file)))))
9292 (defun org-completing-read (&rest args)
9293 "Completing-read with SPACE being a normal character."
9294 (let ((enable-recursive-minibuffers t)
9295 (minibuffer-local-completion-map
9296 (copy-keymap minibuffer-local-completion-map)))
9297 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
9298 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
9299 (org-defkey minibuffer-local-completion-map (kbd "C-c !") 'org-time-stamp-inactive)
9300 (apply 'org-icompleting-read args)))
9302 (defun org-completing-read-no-i (&rest args)
9303 (let (org-completion-use-ido org-completion-use-iswitchb)
9304 (apply 'org-completing-read args)))
9306 (defun org-iswitchb-completing-read (prompt choices &rest args)
9307 "Use iswitch as a completing-read replacement to choose from choices.
9308 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
9310 (let* ((iswitchb-use-virtual-buffers nil)
9311 (iswitchb-make-buflist-hook
9313 (setq iswitchb-temp-buflist choices))))
9314 (iswitchb-read-buffer prompt)))
9316 (defun org-icompleting-read (&rest args)
9317 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
9318 (org-without-partial-completion
9319 (if (and org-completion-use-ido
9320 (fboundp 'ido-completing-read)
9321 (boundp 'ido-mode) ido-mode
9322 (listp (second args)))
9323 (let ((ido-enter-matching-directory nil))
9324 (apply 'ido-completing-read (concat (car args))
9325 (if (consp (car (nth 1 args)))
9326 (mapcar 'car (nth 1 args))
9329 (if (and org-completion-use-iswitchb
9330 (boundp 'iswitchb-mode) iswitchb-mode
9331 (listp (second args)))
9332 (apply 'org-iswitchb-completing-read (concat (car args))
9333 (if (consp (car (nth 1 args)))
9334 (mapcar 'car (nth 1 args))
9337 (apply 'completing-read args)))))
9339 (defun org-extract-attributes (s)
9340 "Extract the attributes cookie from a string and set as text property."
9341 (let (a attr (start 0) key value)
9343 (when (string-match "{{\\([^}]+\\)}}$" s)
9344 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
9345 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
9346 (setq key (match-string 1 a) value (match-string 2 a)
9348 attr (plist-put attr (intern key) value))))
9349 (org-add-props s nil 'org-attr attr))
9352 (defun org-extract-attributes-from-string (tag)
9353 (let (key value attr)
9354 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
9355 (setq key (match-string 1 tag) value (match-string 2 tag)
9356 tag (replace-match "" t t tag)
9357 attr (plist-put attr (intern key) value)))
9360 (defun org-attributes-to-string (plist)
9361 "Format a property list into an HTML attribute list."
9362 (let ((s "") key value)
9364 (setq key (pop plist) value (pop plist))
9366 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
9369 ;;; Opening/following a link
9371 (defvar org-link-search-failed nil)
9373 (defvar org-open-link-functions nil
9374 "Hook for functions finding a plain text link.
9375 These functions must take a single argument, the link content.
9376 They will be called for links that look like [[link text][description]]
9377 when LINK TEXT does not have a protocol like \"http:\" and does not look
9378 like a filename (e.g. \"./blue.png\").
9380 These functions will be called *before* Org attempts to resolve the
9381 link by doing text searches in the current buffer - so if you want a
9382 link \"[[target]]\" to still find \"<<target>>\", your function should
9383 handle this as a special case.
9385 When the function does handle the link, it must return a non-nil value.
9386 If it decides that it is not responsible for this link, it must return
9387 nil to indicate that that Org-mode can continue with other options
9388 like exact and fuzzy text search.")
9390 (defun org-next-link ()
9391 "Move forward to the next link.
9392 If the link is in hidden text, expose it."
9394 (when (and org-link-search-failed (eq this-command last-command))
9395 (goto-char (point-min))
9396 (message "Link search wrapped back to beginning of buffer"))
9397 (setq org-link-search-failed nil)
9398 (let* ((pos (point))
9400 (a (assoc :link ct)))
9401 (if a (goto-char (nth 2 a)))
9402 (if (re-search-forward org-any-link-re nil t)
9404 (goto-char (match-beginning 0))
9405 (if (outline-invisible-p) (org-show-context)))
9407 (setq org-link-search-failed t)
9408 (error "No further link found"))))
9410 (defun org-previous-link ()
9411 "Move backward to the previous link.
9412 If the link is in hidden text, expose it."
9414 (when (and org-link-search-failed (eq this-command last-command))
9415 (goto-char (point-max))
9416 (message "Link search wrapped back to end of buffer"))
9417 (setq org-link-search-failed nil)
9418 (let* ((pos (point))
9420 (a (assoc :link ct)))
9421 (if a (goto-char (nth 1 a)))
9422 (if (re-search-backward org-any-link-re nil t)
9424 (goto-char (match-beginning 0))
9425 (if (outline-invisible-p) (org-show-context)))
9427 (setq org-link-search-failed t)
9428 (error "No further link found"))))
9430 (defun org-translate-link (s)
9431 "Translate a link string if a translation function has been defined."
9432 (if (and org-link-translation-function
9433 (fboundp org-link-translation-function)
9434 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
9436 (setq s (funcall org-link-translation-function
9437 (match-string 1) (match-string 2)))
9438 (concat (car s) ":" (cdr s)))
9441 (defun org-translate-link-from-planner (type path)
9442 "Translate a link from Emacs Planner syntax so that Org can follow it.
9443 This is still an experimental function, your mileage may vary."
9445 ((member type '("http" "https" "news" "ftp"))
9446 ;; standard Internet links are the same.
9448 ((and (equal type "irc") (string-match "^//" path))
9449 ;; Planner has two / at the beginning of an irc link, we have 1.
9450 ;; We should have zero, actually....
9451 (setq path (substring path 1)))
9452 ((and (equal type "lisp") (string-match "^/" path))
9453 ;; Planner has a slash, we do not.
9454 (setq type "elisp" path (substring path 1)))
9455 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
9456 ;; A typical message link. Planner has the id after the final slash,
9457 ;; we separate it with a hash mark
9458 (setq path (concat (match-string 1 path) "#"
9459 (org-remove-angle-brackets (match-string 2 path)))))
9463 (defun org-find-file-at-mouse (ev)
9464 "Open file link or URL at mouse."
9466 (mouse-set-point ev)
9467 (org-open-at-point 'in-emacs))
9469 (defun org-open-at-mouse (ev)
9470 "Open file link or URL at mouse.
9471 See the docstring of `org-open-file' for details."
9473 (mouse-set-point ev)
9474 (if (eq major-mode 'org-agenda-mode)
9475 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
9476 (org-open-at-point))
9478 (defvar org-window-config-before-follow-link nil
9479 "The window configuration before following a link.
9480 This is saved in case the need arises to restore it.")
9482 (defvar org-open-link-marker (make-marker)
9483 "Marker pointing to the location where `org-open-at-point; was called.")
9486 (defun org-open-at-point-global ()
9487 "Follow a link like Org-mode does.
9488 This command can be called in any mode to follow a link that has
9491 (org-run-like-in-org-mode 'org-open-at-point))
9494 (defun org-open-link-from-string (s &optional arg reference-buffer)
9495 "Open a link in the string S, as if it was in Org-mode."
9496 (interactive "sLink: \nP")
9497 (let ((reference-buffer (or reference-buffer (current-buffer))))
9499 (let ((org-inhibit-startup (not reference-buffer)))
9502 (goto-char (point-min))
9503 (when reference-buffer
9504 (setq org-link-abbrev-alist-local
9505 (with-current-buffer reference-buffer
9506 org-link-abbrev-alist-local)))
9507 (org-open-at-point arg reference-buffer)))))
9509 (defvar org-open-at-point-functions nil
9510 "Hook that is run when following a link at point.
9512 Functions in this hook must return t if they identify and follow
9513 a link at point. If they don't find anything interesting at point,
9514 they must return nil.")
9516 (defun org-open-at-point (&optional arg reference-buffer)
9517 "Open link at or after point.
9518 If there is no link at point, this function will search forward up to
9519 the end of the current line.
9520 Normally, files will be opened by an appropriate application. If the
9521 optional prefix argument ARG is non-nil, Emacs will visit the file.
9522 With a double prefix argument, try to open outside of Emacs, in the
9523 application the system uses for this file type."
9525 ;; if in a code block, then open the block's results
9526 (unless (call-interactively #'org-babel-open-src-block-result)
9527 (org-load-modules-maybe)
9528 (move-marker org-open-link-marker (point))
9529 (setq org-window-config-before-follow-link (current-window-configuration))
9530 (org-remove-occur-highlights nil nil t)
9532 ((and (org-at-heading-p)
9534 (concat org-plain-link-re "\\|"
9535 org-bracket-link-regexp "\\|"
9536 org-angle-link-re "\\|"
9537 "[ \t]:[^ \t\n]+:[ \t]*$")))
9538 (not (get-text-property (point) 'org-linked-text)))
9539 (or (org-offer-links-in-entry arg)
9540 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
9541 ((run-hook-with-args-until-success 'org-open-at-point-functions))
9542 ((org-at-timestamp-p t) (org-follow-timestamp-link))
9543 ((and (or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
9544 (not (org-in-regexp org-bracket-link-regexp)))
9545 (org-footnote-action))
9547 (let (type path link line search (pos (point)))
9550 (skip-chars-forward "^]\n\r")
9551 (when (org-in-regexp org-bracket-link-regexp 1)
9552 (setq link (org-extract-attributes
9553 (org-link-unescape (org-match-string-no-properties 1))))
9554 (while (string-match " *\n *" link)
9555 (setq link (replace-match " " t t link)))
9556 (setq link (org-link-expand-abbrev link))
9558 ((or (file-name-absolute-p link)
9559 (string-match "^\\.\\.?/" link))
9560 (setq type "file" path link))
9561 ((string-match org-link-re-with-space3 link)
9562 (setq type (match-string 1 link) path (match-string 2 link)))
9563 (t (setq type "thisfile" path link)))
9566 (when (get-text-property (point) 'org-linked-text)
9567 (setq type "thisfile"
9568 pos (if (get-text-property (1+ (point)) 'org-linked-text)
9569 (1+ (point)) (point))
9570 path (buffer-substring
9571 (or (previous-single-property-change pos 'org-linked-text)
9573 (or (next-single-property-change pos 'org-linked-text)
9578 (when (or (org-in-regexp org-angle-link-re)
9579 (org-in-regexp org-plain-link-re))
9580 (setq type (match-string 1)
9581 path (org-link-unescape (match-string 2)))
9584 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@#%:]+\\):[ \t]*$"))
9586 path (match-string 1))
9587 (while (string-match ":" path)
9588 (setq path (replace-match "+" t t path)))
9590 (when (org-in-regexp "<\\([^><\n]+\\)>")
9591 (setq type "tree-match"
9592 path (match-string 1))
9595 (error "No link found"))
9597 ;; switch back to reference buffer
9598 ;; needed when if called in a temporary buffer through
9599 ;; org-open-link-from-string
9600 (with-current-buffer (or reference-buffer (current-buffer))
9602 ;; Remove any trailing spaces in path
9603 (if (string-match " +\\'" path)
9604 (setq path (replace-match "" t t path)))
9605 (if (and org-link-translation-function
9606 (fboundp org-link-translation-function))
9607 ;; Check if we need to translate the link
9608 (let ((tmp (funcall org-link-translation-function type path)))
9609 (setq type (car tmp) path (cdr tmp))))
9613 ((assoc type org-link-protocols)
9614 (funcall (nth 1 (assoc type org-link-protocols)) path))
9616 ((equal type "mailto")
9617 (let ((cmd (car org-link-mailto-program))
9618 (args (cdr org-link-mailto-program)) args1
9619 (address path) (subject "") a)
9620 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9621 (setq address (match-string 1 path)
9622 subject (org-link-escape (match-string 2 path))))
9625 ((not (stringp (car args))) (push (pop args) args1))
9626 (t (setq a (pop args))
9627 (if (string-match "%a" a)
9628 (setq a (replace-match address t t a)))
9629 (if (string-match "%s" a)
9630 (setq a (replace-match subject t t a)))
9632 (apply cmd (nreverse args1))))
9634 ((member type '("http" "https" "ftp" "news"))
9635 (browse-url (concat type ":" (if (org-string-match-p "[[:nonascii:] ]" path)
9637 path org-link-escape-chars-browser)
9640 ((string= type "doi")
9641 (browse-url (concat "http://dx.doi.org/" (if (org-string-match-p "[[:nonascii:] ]" path)
9643 path org-link-escape-chars-browser)
9646 ((member type '("message"))
9647 (browse-url (concat type ":" path)))
9649 ((string= type "tags")
9650 (org-tags-view arg path))
9652 ((string= type "tree-match")
9653 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9655 ((string= type "file")
9656 (if (string-match "::\\([0-9]+\\)\\'" path)
9657 (setq line (string-to-number (match-string 1 path))
9658 path (substring path 0 (match-beginning 0)))
9659 (if (string-match "::\\(.+\\)\\'" path)
9660 (setq search (match-string 1 path)
9661 path (substring path 0 (match-beginning 0)))))
9662 (if (string-match "[*?{]" (file-name-nondirectory path))
9664 (org-open-file path arg line search)))
9666 ((string= type "shell")
9668 (if (or (and (not (string= org-confirm-shell-link-not-regexp ""))
9669 (string-match org-confirm-shell-link-not-regexp cmd))
9670 (not org-confirm-shell-link-function)
9671 (funcall org-confirm-shell-link-function
9672 (format "Execute \"%s\" in shell? "
9673 (org-add-props cmd nil
9674 'face 'org-warning))))
9676 (message "Executing %s" cmd)
9677 (shell-command cmd))
9680 ((string= type "elisp")
9682 (if (or (and (not (string= org-confirm-elisp-link-not-regexp ""))
9683 (string-match org-confirm-elisp-link-not-regexp cmd))
9684 (not org-confirm-elisp-link-function)
9685 (funcall org-confirm-elisp-link-function
9686 (format "Execute \"%s\" as elisp? "
9687 (org-add-props cmd nil
9688 'face 'org-warning))))
9689 (message "%s => %s" cmd
9690 (if (equal (string-to-char cmd) ?\()
9692 (call-interactively (read cmd))))
9695 ((and (string= type "thisfile")
9696 (run-hook-with-args-until-success
9697 'org-open-link-functions path)))
9699 ((string= type "thisfile")
9701 (switch-to-buffer-other-window
9702 (org-get-buffer-for-internal-link (current-buffer)))
9703 (org-mark-ring-push))
9704 (let ((cmd `(org-link-search
9706 ,(cond ((equal arg '(4)) ''occur)
9707 ((equal arg '(16)) ''org-occur)
9710 (condition-case nil (let ((org-link-search-inhibit-query t))
9712 (error (progn (widen) (eval cmd))))))
9715 (browse-url-at-point)))))))
9716 (move-marker org-open-link-marker nil)
9717 (run-hook-with-args 'org-follow-link-hook)))
9719 (defun org-offer-links-in-entry (&optional nth zero)
9720 "Offer links in the current entry and follow the selected link.
9721 If there is only one link, follow it immediately as well.
9722 If NTH is an integer, immediately pick the NTH link found.
9723 If ZERO is a string, check also this string for a link, and if
9724 there is one, offer it as link number zero."
9725 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
9726 "\\(" org-angle-link-re "\\)\\|"
9727 "\\(" org-plain-link-re "\\)"))
9729 (in-emacs (if (integerp nth) nil nth))
9730 have-zero end links link c)
9731 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
9732 (push (match-string 0 zero) links)
9733 (setq cnt (1- cnt) have-zero t))
9735 (org-back-to-heading t)
9736 (setq end (save-excursion (outline-next-heading) (point)))
9737 (while (re-search-forward re end t)
9738 (push (match-string 0) links))
9739 (setq links (org-uniquify (reverse links))))
9743 (message "No links"))
9744 ((equal (length links) 1)
9745 (setq link (list (car links))))
9746 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
9747 (setq link (list (nth (if have-zero nth (1- nth)) links))))
9748 (t ; we have to select a link
9750 (save-window-excursion
9751 (delete-other-windows)
9752 (with-output-to-temp-buffer "*Select Link*"
9754 (if (not (string-match org-bracket-link-regexp l))
9755 (princ (format "[%c] %s\n" (incf cnt)
9756 (org-remove-angle-brackets l)))
9758 (princ (format "[%c] %s (%s)\n" (incf cnt)
9759 (match-string 3 l) (match-string 1 l)))
9760 (princ (format "[%c] %s\n" (incf cnt)
9761 (match-string 1 l))))))
9763 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
9764 (message "Select link to open, RET to open all:")
9765 (setq c (read-char-exclusive))
9766 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
9767 (when (equal c ?q) (error "Abort"))
9771 (if have-zero (setq nth (1+ nth)))
9772 (unless (and (integerp nth) (>= (length links) nth))
9773 (error "Invalid link selection"))
9774 (setq link (list (nth (1- nth) links))))))
9776 (let ((buf (current-buffer)))
9778 (org-open-link-from-string l in-emacs buf))
9782 ;; Add special file links that specify the way of opening
9784 (org-add-link-type "file+sys" 'org-open-file-with-system)
9785 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
9786 (defun org-open-file-with-system (path)
9787 "Open file at PATH using the system way of opening it."
9788 (org-open-file path 'system))
9789 (defun org-open-file-with-emacs (path)
9790 "Open file at PATH in Emacs."
9791 (org-open-file path 'emacs))
9792 (defun org-remove-file-link-modifiers ()
9793 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
9794 (goto-char (point-min))
9795 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
9797 (replace-match "file:" t t))))
9798 (eval-after-load "org-exp"
9799 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
9800 'org-remove-file-link-modifiers))
9804 (defun org-get-effort (&optional pom)
9805 "Get the effort estimate for the current entry."
9806 (org-entry-get pom org-effort-property))
9810 (defvar org-create-file-search-functions nil
9811 "List of functions to construct the right search string for a file link.
9812 These functions are called in turn with point at the location to
9813 which the link should point.
9815 A function in the hook should first test if it would like to
9816 handle this file type, for example by checking the `major-mode'
9817 or the file extension. If it decides not to handle this file, it
9818 should just return nil to give other functions a chance. If it
9819 does handle the file, it must return the search string to be used
9820 when following the link. The search string will be part of the
9821 file link, given after a double colon, and `org-open-at-point'
9822 will automatically search for it. If special measures must be
9823 taken to make the search successful, another function should be
9824 added to the companion hook `org-execute-file-search-functions',
9827 A function in this hook may also use `setq' to set the variable
9828 `description' to provide a suggestion for the descriptive text to
9829 be used for this link when it gets inserted into an Org-mode
9830 buffer with \\[org-insert-link].")
9832 (defvar org-execute-file-search-functions nil
9833 "List of functions to execute a file search triggered by a link.
9835 Functions added to this hook must accept a single argument, the
9836 search string that was part of the file link, the part after the
9837 double colon. The function must first check if it would like to
9838 handle this search, for example by checking the `major-mode' or
9839 the file extension. If it decides not to handle this search, it
9840 should just return nil to give other functions a chance. If it
9841 does handle the search, it must return a non-nil value to keep
9842 other functions from trying.
9844 Each function can access the current prefix argument through the
9845 variable `current-prefix-argument'. Note that a single prefix is
9846 used to force opening a link in Emacs, so it may be good to only
9847 use a numeric or double prefix to guide the search function.
9849 In case this is needed, a function in this hook can also restore
9850 the window configuration before `org-open-at-point' was called using:
9852 (set-window-configuration org-window-config-before-follow-link)")
9854 (defvar org-link-search-inhibit-query nil) ;; dynamically scoped
9855 (defun org-link-search (s &optional type avoid-pos stealth)
9856 "Search for a link search option.
9857 If S is surrounded by forward slashes, it is interpreted as a
9858 regular expression. In org-mode files, this will create an `org-occur'
9859 sparse tree. In ordinary files, `occur' will be used to list matches.
9860 If the current buffer is in `dired-mode', grep will be used to search
9861 in all files. If AVOID-POS is given, ignore matches near that position.
9863 When optional argument STEALTH is non-nil, do not modify
9864 visibility around point, thus ignoring
9865 `org-show-hierarchy-above', `org-show-following-heading' and
9866 `org-show-siblings' variables."
9867 (let ((case-fold-search t)
9868 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
9869 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
9870 (append '(("") (" ") ("\t") ("\n"))
9874 (pre nil) (post nil)
9875 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
9877 ;; First check if there are any special search functions
9878 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
9879 ;; Now try the builtin stuff
9880 ((and (equal (string-to-char s0) ?#)
9883 (goto-char (point-min))
9886 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
9887 (setq type 'dedicated
9888 pos (match-beginning 0))))
9889 ;; There is an exact target for this
9891 (org-back-to-heading t)))
9893 (goto-char (point-min))
9896 (concat "<<" (regexp-quote s0) ">>") nil t)
9897 (setq type 'dedicated
9898 pos (match-beginning 0))))
9899 ;; There is an exact target for this
9901 ((and (string-match "^(\\(.*\\))$" s0)
9903 (goto-char (point-min))
9906 (concat "[^[]" (regexp-quote
9907 (format org-coderef-label-format
9908 (match-string 1 s0))))
9910 (setq type 'dedicated
9911 pos (1+ (match-beginning 0))))))
9912 ;; There is a coderef target for this
9914 ((string-match "^/\\(.*\\)/$" s)
9915 ;; A regular expression
9917 ((eq major-mode 'org-mode)
9918 (org-occur (match-string 1 s)))
9919 ;;((eq major-mode 'dired-mode)
9920 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9921 (t (org-do-occur (match-string 1 s)))))
9922 ((and (eq major-mode 'org-mode) org-link-search-must-match-exact-headline)
9923 (and (equal (string-to-char s) ?*) (setq s (substring s 1)))
9924 (goto-char (point-min))
9926 ((let (case-fold-search)
9927 (re-search-forward (format org-complex-heading-regexp-format
9930 ;; OK, found a match
9931 (setq type 'dedicated)
9932 (goto-char (match-beginning 0)))
9933 ((and (not org-link-search-inhibit-query)
9934 (eq org-link-search-must-match-exact-headline 'query-to-create)
9935 (y-or-n-p "No match - create this as a new heading? "))
9936 (goto-char (point-max))
9937 (or (bolp) (newline))
9938 (insert "* " s "\n")
9939 (beginning-of-line 0))
9942 (error "No match"))))
9944 ;; A normal search string
9945 (when (equal (string-to-char s) ?*)
9946 ;; Anchor on headlines, post may include tags.
9947 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
9948 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@#%:+]:[ \t]*\\)?$")
9950 (remove-text-properties
9952 '(face nil mouse-face nil keymap nil fontified nil) s)
9953 ;; Make a series of regular expressions to find a match
9954 (setq words (org-split-string s "[ \n\r\t]+")
9956 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
9957 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
9959 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
9960 re2a (concat "[ \t\r\n]" re2a_)
9961 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9962 re4 (concat "[^a-zA-Z_]" re4_)
9964 re1 (concat pre re2 post)
9965 re3 (concat pre (if pre re4_ re4) post)
9966 re5 (concat pre ".*" re4)
9967 re2 (concat pre re2)
9968 re2a (concat pre (if pre re2a_ re2a))
9969 re4 (concat pre (if pre re4_ re4))
9970 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
9971 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
9975 ((eq type 'org-occur) (org-occur reall))
9976 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
9977 (t (goto-char (point-min))
9979 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
9980 (org-search-not-self 1 re1 nil t)
9981 (org-search-not-self 1 re2 nil t)
9982 (org-search-not-self 1 re2a nil t)
9983 (org-search-not-self 1 re3 nil t)
9984 (org-search-not-self 1 re4 nil t)
9985 (org-search-not-self 1 re5 nil t)
9987 (goto-char (match-beginning 1))
9989 (error "No match"))))))
9990 (and (eq major-mode 'org-mode)
9992 (org-show-context 'link-search))
9995 (defun org-search-not-self (group &rest args)
9996 "Execute `re-search-forward', but only accept matches that do not
9997 enclose the position of `org-open-link-marker'."
9998 (let ((m org-open-link-marker))
10000 (while (apply 're-search-forward args)
10001 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
10002 (goto-char (match-end group))
10003 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
10004 (> (match-beginning 0) (marker-position m))
10005 (< (match-end 0) (marker-position m)))
10007 (or (not (org-in-regexp
10008 org-bracket-link-analytic-regexp 1))
10009 (not (match-end 4)) ; no description
10010 (and (<= (match-beginning 4) (point))
10011 (>= (match-end 4) (point))))))
10012 (throw 'exit (point))))))))
10014 (defun org-get-buffer-for-internal-link (buffer)
10015 "Return a buffer to be used for displaying the link target of internal links."
10017 ((not org-display-internal-link-with-indirect-buffer)
10019 ((string-match "(Clone)$" (buffer-name buffer))
10020 (message "Buffer is already a clone, not making another one")
10021 ;; we also do not modify visibility in this case
10023 (t ; make a new indirect buffer for displaying the link
10024 (let* ((bn (buffer-name buffer))
10025 (ibn (concat bn "(Clone)"))
10026 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
10027 (with-current-buffer ib (org-overview))
10030 (defun org-do-occur (regexp &optional cleanup)
10031 "Call the Emacs command `occur'.
10032 If CLEANUP is non-nil, remove the printout of the regular expression
10033 in the *Occur* buffer. This is useful if the regex is long and not useful
10037 (let ((cwin (selected-window)) win beg end)
10038 (when (setq win (get-buffer-window "*Occur*"))
10039 (select-window win))
10040 (goto-char (point-min))
10041 (when (re-search-forward "match[a-z]+" nil t)
10042 (setq beg (match-end 0))
10043 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
10044 (setq end (1- (match-beginning 0)))))
10045 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
10046 (goto-char (point-min))
10047 (select-window cwin))))
10049 ;;; The mark ring for links jumps
10051 (defvar org-mark-ring nil
10052 "Mark ring for positions before jumps in Org-mode.")
10053 (defvar org-mark-ring-last-goto nil
10054 "Last position in the mark ring used to go back.")
10055 ;; Fill and close the ring
10056 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
10057 (loop for i from 1 to org-mark-ring-length do
10058 (push (make-marker) org-mark-ring))
10059 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
10062 (defun org-mark-ring-push (&optional pos buffer)
10063 "Put the current position or POS into the mark ring and rotate it."
10065 (setq pos (or pos (point)))
10066 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
10067 (move-marker (car org-mark-ring)
10069 (or buffer (current-buffer)))
10071 (substitute-command-keys
10072 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
10074 (defun org-mark-ring-goto (&optional n)
10075 "Jump to the previous position in the mark ring.
10076 With prefix arg N, jump back that many stored positions. When
10077 called several times in succession, walk through the entire ring.
10078 Org-mode commands jumping to a different position in the current file,
10079 or to another Org-mode file, automatically push the old position
10083 (if (eq last-command this-command)
10084 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
10085 (setq p org-mark-ring))
10086 (setq org-mark-ring-last-goto p)
10088 (org-pop-to-buffer-same-window (marker-buffer m))
10090 (if (or (outline-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
10092 (defun org-remove-angle-brackets (s)
10093 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
10094 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
10096 (defun org-add-angle-brackets (s)
10097 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
10098 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
10100 (defun org-remove-double-quotes (s)
10101 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
10102 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
10105 ;;; Following specific links
10107 (defun org-follow-timestamp-link ()
10109 ((org-at-date-range-p t)
10110 (let ((org-agenda-start-on-weekday)
10111 (t1 (match-string 1))
10112 (t2 (match-string 2)))
10113 (setq t1 (time-to-days (org-time-string-to-time t1))
10114 t2 (time-to-days (org-time-string-to-time t2)))
10115 (org-agenda-list nil t1 (1+ (- t2 t1)))))
10116 ((org-at-timestamp-p t)
10117 (org-agenda-list nil (time-to-days (org-time-string-to-time
10118 (substring (match-string 1) 0 10)))
10120 (t (error "This should not happen"))))
10123 ;;; Following file links
10124 (declare-function mailcap-parse-mailcaps "mailcap" (&optional path force))
10125 (declare-function mailcap-extension-to-mime "mailcap" (extn))
10126 (declare-function mailcap-mime-info
10127 "mailcap" (string &optional request no-decode))
10128 (defvar org-wait nil)
10129 (defun org-open-file (path &optional in-emacs line search)
10130 "Open the file at PATH.
10131 First, this expands any special file name abbreviations. Then the
10132 configuration variable `org-file-apps' is checked if it contains an
10133 entry for this file type, and if yes, the corresponding command is launched.
10135 If no application is found, Emacs simply visits the file.
10137 With optional prefix argument IN-EMACS, Emacs will visit the file.
10138 With a double \\[universal-argument] \\[universal-argument] \
10139 prefix arg, Org tries to avoid opening in Emacs
10140 and to use an external application to visit the file.
10142 Optional LINE specifies a line to go to, optional SEARCH a string
10143 to search for. If LINE or SEARCH is given, the file will be
10144 opened in Emacs, unless an entry from org-file-apps that makes
10145 use of groups in a regexp matches.
10147 If you want to change the way frames are used when following a
10148 link, please customize `org-link-frame-setup'.
10150 If the file does not exist, an error is thrown."
10151 (let* ((file (if (equal path "")
10153 (substitute-in-file-name (expand-file-name path))))
10154 (file-apps (append org-file-apps (org-default-apps)))
10155 (apps (org-remove-if
10156 'org-file-apps-entry-match-against-dlink-p file-apps))
10157 (apps-dlink (org-remove-if-not
10158 'org-file-apps-entry-match-against-dlink-p file-apps))
10159 (remp (and (assq 'remote apps) (org-file-remote-p file)))
10160 (dirp (if remp nil (file-directory-p file)))
10161 (file (if (and dirp org-open-directory-means-index-dot-org)
10162 (concat (file-name-as-directory file) "index.org")
10164 (a-m-a-p (assq 'auto-mode apps))
10165 (dfile (downcase file))
10166 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
10167 (link (cond ((and (eq line nil)
10171 (concat file "::" (number-to-string line)))
10173 (concat file "::" search))))
10174 (dlink (downcase link))
10175 (old-buffer (current-buffer))
10177 (old-mode major-mode)
10178 ext cmd link-match-data)
10179 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
10180 (setq ext (match-string 1 dfile))
10181 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
10182 (setq ext (match-string 1 dfile))))
10184 ((member in-emacs '((16) system))
10185 (setq cmd (cdr (assoc 'system apps))))
10186 (in-emacs (setq cmd 'emacs))
10188 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
10189 (and dirp (cdr (assoc 'directory apps)))
10190 ; first, try matching against apps-dlink
10191 ; if we get a match here, store the match data for later
10192 (let ((match (assoc-default dlink apps-dlink
10195 (progn (setq link-match-data (match-data))
10197 (progn (setq in-emacs (or in-emacs line search))
10198 nil))) ; if we have no match in apps-dlink,
10199 ; always open the file in emacs if line or search
10200 ; is given (for backwards compatibility)
10201 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
10203 (cdr (assoc ext apps))
10204 (cdr (assoc t apps))))))
10205 (when (eq cmd 'system)
10206 (setq cmd (cdr (assoc 'system apps))))
10207 (when (eq cmd 'default)
10208 (setq cmd (cdr (assoc t apps))))
10209 (when (eq cmd 'mailcap)
10211 (mailcap-parse-mailcaps)
10212 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
10213 (command (mailcap-mime-info mime-type)))
10214 (if (stringp command)
10216 (setq cmd 'emacs))))
10217 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
10218 (not (file-exists-p file))
10219 (not org-open-non-existing-files))
10220 (error "No such file: %s" file))
10222 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
10223 ;; Remove quotes around the file name - we'll use shell-quote-argument.
10224 (while (string-match "['\"]%s['\"]" cmd)
10225 (setq cmd (replace-match "%s" t t cmd)))
10226 (while (string-match "%s" cmd)
10227 (setq cmd (replace-match
10229 (shell-quote-argument
10230 (convert-standard-filename file)))
10233 ;; Replace "%1", "%2" etc. in command with group matches from regex
10235 (let ((match-index 1)
10236 (number-of-groups (- (/ (length link-match-data) 2) 1)))
10237 (set-match-data link-match-data)
10238 (while (<= match-index number-of-groups)
10239 (let ((regex (concat "%" (number-to-string match-index)))
10240 (replace-with (match-string match-index dlink)))
10241 (while (string-match regex cmd)
10242 (setq cmd (replace-match replace-with t t cmd))))
10243 (setq match-index (+ match-index 1)))))
10245 (save-window-excursion
10246 (start-process-shell-command cmd nil cmd)
10247 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
10251 (funcall (cdr (assq 'file org-link-frame-setup)) file)
10253 (if line (org-goto-line line)
10254 (if search (org-link-search search))))
10256 (let ((file (convert-standard-filename file)))
10258 (set-match-data link-match-data)
10260 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
10261 (and (eq major-mode 'org-mode) (eq old-mode 'org-mode)
10262 (or (not (equal old-buffer (current-buffer)))
10263 (not (equal old-pos (point))))
10264 (org-mark-ring-push old-pos old-buffer))))
10266 (defun org-file-apps-entry-match-against-dlink-p (entry)
10267 "This function returns non-nil if `entry' uses a regular
10268 expression which should be matched against the whole link by
10271 It assumes that is the case when the entry uses a regular
10272 expression which has at least one grouping construct and the
10273 action is either a lisp form or a command string containing
10274 '%1', i.e. using at least one subexpression match as a
10276 (let ((selector (car entry))
10277 (action (cdr entry)))
10278 (if (stringp selector)
10279 (and (> (regexp-opt-depth selector) 0)
10280 (or (and (stringp action)
10281 (string-match "%[0-9]" action))
10285 (defun org-default-apps ()
10286 "Return the default applications for this operating system."
10288 ((eq system-type 'darwin)
10289 org-file-apps-defaults-macosx)
10290 ((eq system-type 'windows-nt)
10291 org-file-apps-defaults-windowsnt)
10292 (t org-file-apps-defaults-gnu)))
10294 (defun org-apps-regexp-alist (list &optional add-auto-mode)
10295 "Convert extensions to regular expressions in the cars of LIST.
10296 Also, weed out any non-string entries, because the return value is used
10297 only for regexp matching.
10298 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
10299 point to the symbol `emacs', indicating that the file should
10300 be opened in Emacs."
10303 (mapcar (lambda (x)
10304 (if (not (stringp (car x)))
10306 (if (string-match "\\W" (car x))
10308 (cons (concat "\\." (car x) "\\'") (cdr x)))))
10311 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
10313 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
10314 (defun org-file-remote-p (file)
10315 "Test whether FILE specifies a location on a remote system.
10316 Return non-nil if the location is indeed remote.
10318 For example, the filename \"/user@host:/foo\" specifies a location
10319 on the system \"/user@host:\"."
10320 (cond ((fboundp 'file-remote-p)
10321 (file-remote-p file))
10322 ((fboundp 'tramp-handle-file-remote-p)
10323 (tramp-handle-file-remote-p file))
10324 ((and (boundp 'ange-ftp-name-format)
10325 (string-match (car ange-ftp-name-format) file))
10332 (defun org-get-org-file ()
10333 "Read a filename, with default directory `org-directory'."
10334 (let ((default (or org-default-notes-file remember-data-file)))
10335 (read-file-name (format "File name [%s]: " default)
10336 (file-name-as-directory org-directory)
10339 (defun org-notes-order-reversed-p ()
10340 "Check if the current file should receive notes in reversed order."
10342 ((not org-reverse-note-order) nil)
10343 ((eq t org-reverse-note-order) t)
10344 ((not (listp org-reverse-note-order)) nil)
10346 (let ((all org-reverse-note-order)
10348 (while (setq entry (pop all))
10349 (if (string-match (car entry) buffer-file-name)
10350 (throw 'exit (cdr entry))))
10353 (defvar org-refile-target-table nil
10354 "The list of refile targets, created by `org-refile'.")
10356 (defvar org-agenda-new-buffers nil
10357 "Buffers created to visit agenda files.")
10359 (defvar org-refile-cache nil
10360 "Cache for refile targets.")
10362 (defvar org-refile-markers nil
10363 "All the markers used for caching refile locations.")
10365 (defun org-refile-marker (pos)
10366 "Get a new refile marker, but only if caching is in use."
10367 (if (not org-refile-use-cache)
10369 (let ((m (make-marker)))
10370 (move-marker m pos)
10371 (push m org-refile-markers)
10374 (defun org-refile-cache-clear ()
10375 "Clear the refile cache and disable all the markers."
10376 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
10377 (setq org-refile-markers nil)
10378 (setq org-refile-cache nil)
10379 (message "Refile cache has been cleared"))
10381 (defun org-refile-cache-check-set (set)
10382 "Check if all the markers in the cache still have live buffers."
10385 (while (and set (setq marker (nth 3 (pop set))))
10386 ;; if org-refile-use-outline-path is 'file, marker may be nil
10387 (when (and marker (null (marker-buffer marker)))
10388 (message "not found") (sit-for 3)
10389 (throw 'exit nil)))
10392 (defun org-refile-cache-put (set &rest identifiers)
10393 "Push the refile targets SET into the cache, under IDENTIFIERS."
10394 (let* ((key (sha1 (prin1-to-string identifiers)))
10395 (entry (assoc key org-refile-cache)))
10398 (push (cons key set) org-refile-cache))))
10400 (defun org-refile-cache-get (&rest identifiers)
10401 "Retrieve the cached value for refile targets given by IDENTIFIERS."
10403 ((not org-refile-cache) nil)
10404 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
10406 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
10407 org-refile-cache))))
10408 (and set (org-refile-cache-check-set set) set)))))
10410 (defun org-refile-get-targets (&optional default-buffer excluded-entries)
10411 "Produce a table with refile targets."
10412 (let ((case-fold-search nil)
10413 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
10414 (entries (or org-refile-targets '((nil . (:level . 1)))))
10415 targets tgs txt re files f desc descre fast-path-p level pos0)
10416 (message "Getting targets...")
10417 (with-current-buffer (or default-buffer (current-buffer))
10418 (while (setq entry (pop entries))
10419 (setq files (car entry) desc (cdr entry))
10420 (setq fast-path-p nil)
10422 ((null files) (setq files (list (current-buffer))))
10423 ((eq files 'org-agenda-files)
10424 (setq files (org-agenda-files 'unrestricted)))
10425 ((and (symbolp files) (fboundp files))
10426 (setq files (funcall files)))
10427 ((and (symbolp files) (boundp files))
10428 (setq files (symbol-value files))))
10429 (if (stringp files) (setq files (list files)))
10431 ((eq (car desc) :tag)
10432 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
10433 ((eq (car desc) :todo)
10434 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
10435 ((eq (car desc) :regexp)
10436 (setq descre (cdr desc)))
10437 ((eq (car desc) :level)
10438 (setq descre (concat "^\\*\\{" (number-to-string
10439 (if org-odd-levels-only
10440 (1- (* 2 (cdr desc)))
10443 ((eq (car desc) :maxlevel)
10444 (setq fast-path-p t)
10445 (setq descre (concat "^\\*\\{1," (number-to-string
10446 (if org-odd-levels-only
10447 (1- (* 2 (cdr desc)))
10450 (t (error "Bad refiling target description %s" desc)))
10451 (while (setq f (pop files))
10452 (with-current-buffer
10453 (if (bufferp f) f (org-get-agenda-file-buffer f))
10455 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
10457 (if (bufferp f) (setq f (buffer-file-name
10458 (buffer-base-buffer f))))
10459 (setq f (and f (expand-file-name f)))
10460 (if (eq org-refile-use-outline-path 'file)
10461 (push (list (file-name-nondirectory f) f nil nil) tgs))
10465 (goto-char (point-min))
10466 (while (re-search-forward descre nil t)
10467 (goto-char (setq pos0 (point-at-bol)))
10469 (when org-refile-target-verify-function
10471 (or (funcall org-refile-target-verify-function)
10473 (when (and (looking-at org-complex-heading-regexp)
10474 (not (member (match-string 4) excluded-entries))
10476 (setq level (org-reduced-level
10477 (- (match-end 1) (match-beginning 1)))
10478 txt (org-link-display-format (match-string 4))
10479 txt (replace-regexp-in-string "\\( *\[[0-9]+/?[0-9]*%?\]\\)+$" "" txt)
10480 re (format org-complex-heading-regexp-format
10481 (regexp-quote (match-string 4))))
10482 (when org-refile-use-outline-path
10483 (setq txt (mapconcat
10486 (if (eq org-refile-use-outline-path
10488 (list (file-name-nondirectory
10490 (buffer-base-buffer))))
10491 (if (eq org-refile-use-outline-path
10493 (list (buffer-file-name
10494 (buffer-base-buffer)))))
10495 (org-get-outline-path fast-path-p
10499 (push (list txt f re (org-refile-marker (point)))
10501 (when (= (point) pos0)
10502 ;; verification function has not moved point
10503 (goto-char (point-at-eol))))))))
10504 (when org-refile-use-cache
10505 (org-refile-cache-put tgs (buffer-file-name) descre))
10506 (setq targets (append tgs targets))
10508 (message "Getting targets...done")
10509 (nreverse targets)))
10511 (defun org-protect-slash (s)
10512 (while (string-match "/" s)
10513 (setq s (replace-match "\\" t t s)))
10516 (defvar org-olpa (make-vector 20 nil))
10518 (defun org-get-outline-path (&optional fastp level heading)
10519 "Return the outline path to the current entry, as a list.
10521 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
10522 routine which makes outline path derivations for an entire file,
10523 avoiding backtracing. Refile target collection makes use of that."
10527 (error "Outline path failure, more than 19 levels"))
10528 (loop for i from level upto 19 do
10529 (aset org-olpa i nil))
10531 (delq nil (append org-olpa nil))
10532 (aset org-olpa level heading)))
10533 (let (rtn case-fold-search)
10537 (while (org-up-heading-safe)
10538 (when (looking-at org-complex-heading-regexp)
10539 (push (org-match-string-no-properties 4) rtn)))
10542 (defun org-format-outline-path (path &optional width prefix)
10543 "Format the outline path PATH for display.
10544 Width is the maximum number of characters that is available.
10545 Prefix is a prefix to be included in the returned string,
10546 such as the file name."
10547 (setq width (or width 79))
10548 (if prefix (setq width (- width (length prefix))))
10551 (let* ((nsteps (length path))
10552 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
10553 (maxwidth (if (<= total-width width)
10554 10000 ;; everything fits
10555 ;; we need to shorten the level headings
10556 (/ (- width nsteps) nsteps)))
10557 (org-odd-levels-only nil)
10559 (total (1+ (length prefix))))
10560 (setq maxwidth (max maxwidth 10))
10565 (if (and (= n nsteps) (< maxwidth 10000))
10566 (setq maxwidth (- total-width total)))
10567 (if (< (length h) maxwidth)
10568 (progn (setq total (+ total (length h) 1)) h)
10569 (setq h (substring h 0 (- maxwidth 2))
10570 total (+ total maxwidth 1))
10571 (if (string-match "[ \t]+\\'" h)
10572 (setq h (substring h 0 (match-beginning 0))))
10573 (setq h (concat h "..")))
10574 (org-add-props h nil 'face
10575 (nth (% (1- n) org-n-level-faces)
10580 (defun org-display-outline-path (&optional file current)
10581 "Display the current outline path in the echo area."
10583 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
10584 (case-fold-search nil)
10585 (path (and (eq major-mode 'org-mode) (org-get-outline-path))))
10586 (if current (setq path (append path
10588 (org-back-to-heading t)
10589 (if (looking-at org-complex-heading-regexp)
10590 (list (match-string 4)))))))
10592 (org-format-outline-path
10595 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
10597 (defvar org-refile-history nil
10598 "History for refiling operations.")
10600 (defvar org-after-refile-insert-hook nil
10601 "Hook run after `org-refile' has inserted its stuff at the new location.
10602 Note that this is still *before* the stuff will be removed from
10603 the *old* location.")
10605 (defvar org-capture-last-stored-marker)
10606 (defun org-refile (&optional goto default-buffer rfloc)
10607 "Move the entry or entries at point to another heading.
10608 The list of target headings is compiled using the information in
10609 `org-refile-targets', which see.
10611 At the target location, the entry is filed as a subitem of the target
10612 heading. Depending on `org-reverse-note-order', the new subitem will
10613 either be the first or the last subitem.
10615 If there is an active region, all entries in that region will be moved.
10616 However, the region must fulfill the requirement that the first heading
10617 is the first one sets the top-level of the moved text - at most siblings
10618 below it are allowed.
10620 With prefix arg GOTO, the command will only visit the target location
10621 and not actually move anything.
10623 With a double prefix arg \\[universal-argument] \\[universal-argument], \
10624 go to the location where the last refiling operation has put the subtree.
10625 With a prefix argument of `2', refile to the running clock.
10627 RFLOC can be a refile location obtained in a different way.
10629 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
10631 If you are using target caching (see `org-refile-use-cache'),
10632 You have to clear the target cache in order to find new targets.
10633 This can be done with a 0 prefix (`C-0 C-c C-w') or a triple
10634 prefix argument (`C-u C-u C-u C-c C-w')."
10637 (if (member goto '(0 (64)))
10638 (org-refile-cache-clear)
10639 (let* ((cbuf (current-buffer))
10640 (regionp (org-region-active-p))
10641 (region-start (and regionp (region-beginning)))
10642 (region-end (and regionp (region-end)))
10643 (region-length (and regionp (- region-end region-start)))
10644 (filename (buffer-file-name (buffer-base-buffer cbuf)))
10645 pos it nbuf file re level reversed)
10646 (setq last-command nil)
10648 (goto-char region-start)
10649 (or (bolp) (goto-char (point-at-bol)))
10650 (setq region-start (point))
10651 (unless (or (org-kill-is-subtree-p
10652 (buffer-substring region-start region-end))
10653 (prog1 org-refile-active-region-within-subtree
10654 (org-toggle-heading)))
10655 (error "The region is not a (sequence of) subtree(s)")))
10656 (if (equal goto '(16))
10657 (org-refile-goto-last-stored)
10659 (and (equal goto 2)
10660 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10662 (setq it (list (or org-clock-heading "running clock")
10664 (marker-buffer org-clock-hd-marker))
10666 (marker-position org-clock-hd-marker)))
10669 (let (heading-text)
10672 (org-back-to-heading t)
10674 (nth 4 (org-heading-components))))
10675 (org-refile-get-location
10676 (cond (goto "Goto")
10677 (regionp "Refile region to")
10678 (t (concat "Refile subtree \""
10679 heading-text "\" to")))
10681 org-refile-allow-creating-parent-nodes
10683 (setq file (nth 1 it)
10686 (if (and (not goto)
10688 (equal (buffer-file-name) file)
10690 (and (>= pos region-start)
10691 (<= pos region-end))
10692 (and (>= pos (point))
10693 (< pos (save-excursion
10694 (org-end-of-subtree t t))))))
10695 (error "Cannot refile to position inside the tree or region"))
10697 (setq nbuf (or (find-buffer-visiting file)
10698 (find-file-noselect file)))
10701 (org-pop-to-buffer-same-window nbuf)
10703 (org-show-context 'org-goto))
10706 (org-kill-new (buffer-substring region-start region-end))
10707 (org-save-markers-in-region region-start region-end))
10708 (org-copy-subtree 1 nil t))
10709 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
10710 (find-file-noselect file)))
10711 (setq reversed (org-notes-order-reversed-p))
10718 (looking-at org-outline-regexp)
10719 (setq level (org-get-valid-level (funcall outline-level) 1))
10722 (or (outline-next-heading) (point-max))
10723 (or (save-excursion (org-get-next-sibling))
10724 (org-end-of-subtree t t)
10728 (goto-char (point-max))
10729 (goto-char (point-min))
10730 (or (outline-next-heading) (goto-char (point-max)))))
10731 (if (not (bolp)) (newline))
10732 (org-paste-subtree level)
10733 (when org-log-refile
10734 (org-add-log-setup 'refile nil nil 'findpos
10736 (unless (eq org-log-refile 'note)
10737 (save-excursion (org-add-log-note))))
10738 (and org-auto-align-tags (org-set-tags nil t))
10739 (bookmark-set "org-refile-last-stored")
10740 ;; If we are refiling for capture, make sure that the
10741 ;; last-capture pointers point here
10742 (when (org-bound-and-true-p org-refile-for-capture)
10743 (bookmark-set "org-capture-last-stored-marker")
10744 (move-marker org-capture-last-stored-marker (point)))
10745 (if (fboundp 'deactivate-mark) (deactivate-mark))
10746 (run-hooks 'org-after-refile-insert-hook))))
10748 (delete-region (point) (+ (point) region-length))
10750 (when (featurep 'org-inlinetask)
10751 (org-inlinetask-remove-END-maybe))
10752 (setq org-markers-to-move nil)
10753 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
10755 (defun org-refile-goto-last-stored ()
10756 "Go to the location where the last refile was stored."
10758 (bookmark-jump "org-refile-last-stored")
10759 (message "This is the location of the last refile"))
10761 (defun org-refile-get-location (&optional prompt default-buffer new-nodes
10763 "Prompt the user for a refile location, using PROMPT.
10764 PROMPT should not be suffixed with a colon and a space, because
10765 this function appends the default value from
10766 `org-refile-history' automatically, if that is not empty.
10767 When NO-EXCLUDE is set, do not exclude headlines in the current subtree,
10768 this is used for the GOTO interface."
10769 (let ((org-refile-targets org-refile-targets)
10770 (org-refile-use-outline-path org-refile-use-outline-path)
10772 (when (and (eq major-mode 'org-mode)
10773 (not org-refile-use-cache)
10777 (setq excluded-entries
10778 (append excluded-entries (list (org-get-heading t t)))))))
10779 (setq org-refile-target-table
10780 (org-refile-get-targets default-buffer excluded-entries)))
10781 (unless org-refile-target-table
10782 (error "No refile targets"))
10783 (let* ((prompt (concat prompt
10784 (and (car org-refile-history)
10785 (concat " (default " (car org-refile-history) ")"))
10787 (cbuf (current-buffer))
10788 (partial-completion-mode nil)
10789 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
10790 (cfunc (if (and org-refile-use-outline-path
10791 org-outline-path-complete-in-steps)
10792 'org-olpath-completing-read
10793 'org-icompleting-read))
10794 (extra (if org-refile-use-outline-path "/" ""))
10795 (filename (and cfn (expand-file-name cfn)))
10798 (if (and (not (member org-refile-use-outline-path
10799 '(file full-file-path)))
10800 (not (equal filename (nth 1 x))))
10801 (cons (concat (car x) extra " ("
10802 (file-name-nondirectory (nth 1 x)) ")")
10804 (cons (concat (car x) extra) (cdr x))))
10805 org-refile-target-table))
10806 (completion-ignore-case t)
10807 pa answ parent-target child parent old-hist)
10808 (setq old-hist org-refile-history)
10809 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
10810 nil 'org-refile-history (car org-refile-history)))
10811 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
10812 (org-refile-check-position pa)
10815 (when (or (not org-refile-history)
10816 (not (eq old-hist org-refile-history))
10817 (not (equal (car pa) (car org-refile-history))))
10818 (setq org-refile-history
10819 (cons (car pa) (if (assoc (car org-refile-history) tbl)
10821 (cdr org-refile-history))))
10822 (if (equal (car org-refile-history) (nth 1 org-refile-history))
10823 (pop org-refile-history)))
10825 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
10827 (setq parent (match-string 1 answ)
10828 child (match-string 2 answ))
10829 (setq parent-target (or (assoc parent tbl)
10830 (assoc (concat parent "/") tbl)))
10831 (when (and parent-target
10832 (or (eq new-nodes t)
10833 (and (eq new-nodes 'confirm)
10834 (y-or-n-p (format "Create new node \"%s\"? "
10836 (org-refile-new-child parent-target child)))
10837 (error "Invalid target location")))))
10839 (defun org-refile-check-position (refile-pointer)
10840 "Check if the refile pointer matches the readline to which it points."
10841 (let* ((file (nth 1 refile-pointer))
10842 (re (nth 2 refile-pointer))
10843 (pos (nth 3 refile-pointer))
10845 (when (org-string-nw-p re)
10846 (setq buffer (if (markerp pos)
10847 (marker-buffer pos)
10848 (or (find-buffer-visiting file)
10849 (find-file-noselect file))))
10850 (with-current-buffer buffer
10855 (beginning-of-line 1)
10856 (unless (org-looking-at-p re)
10857 (error "Invalid refile position, please clear the cache with `C-0 C-c C-w' before refiling"))))))))
10859 (defun org-refile-new-child (parent-target child)
10860 "Use refile target PARENT-TARGET to add new CHILD below it."
10861 (unless parent-target
10862 (error "Cannot find parent for new node"))
10863 (let ((file (nth 1 parent-target))
10864 (pos (nth 3 parent-target))
10866 (with-current-buffer (or (find-buffer-visiting file)
10867 (find-file-noselect file))
10873 (goto-char (point-max))
10874 (if (not (bolp)) (newline)))
10875 (when (looking-at org-outline-regexp)
10876 (setq level (funcall outline-level))
10877 (org-end-of-subtree t t))
10878 (org-back-over-empty-lines)
10879 (insert "\n" (make-string
10880 (if pos (org-get-valid-level level 1) 1) ?*)
10882 (beginning-of-line 0)
10883 (list (concat (car parent-target) "/" child) file "" (point)))))))
10885 (defun org-olpath-completing-read (prompt collection &rest args)
10886 "Read an outline path like a file name."
10887 (let ((thetable collection)
10888 (org-completion-use-ido nil) ; does not work with ido.
10889 (org-completion-use-iswitchb nil)) ; or iswitchb
10891 'org-icompleting-read prompt
10892 (lambda (string predicate &optional flag)
10893 (let (rtn r f (l (length string)))
10897 (try-completion string thetable))
10900 (setq rtn (all-completions string thetable predicate))
10903 (setq r (substring x l))
10904 (if (string-match " ([^)]*)$" x)
10905 (setq f (match-string 0 x))
10907 (if (string-match "/" r)
10908 (concat string (substring r 0 (match-end 0)) f)
10913 (assoc string thetable)))
10917 ;;;; Dynamic blocks
10919 (defun org-find-dblock (name)
10920 "Find the first dynamic block with name NAME in the buffer.
10921 If not found, stay at current position and return nil."
10924 (goto-char (point-min))
10925 (setq pos (and (re-search-forward (concat "^[ \t]*#\\+BEGIN:[ \t]+" name "\\>")
10927 (match-beginning 0))))
10928 (if pos (goto-char pos))
10931 (defconst org-dblock-start-re
10932 "^[ \t]*#\\+BEGIN:[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
10933 "Matches the start line of a dynamic block, with parameters.")
10935 (defconst org-dblock-end-re "^[ \t]*#\\+END\\([: \t\r\n]\\|$\\)"
10936 "Matches the end of a dynamic block.")
10938 (defun org-create-dblock (plist)
10939 "Create a dynamic block section, with parameters taken from PLIST.
10940 PLIST must contain a :name entry which is used as name of the block."
10941 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
10944 (let ((col (current-column))
10945 (name (plist-get plist :name)))
10946 (insert "#+BEGIN: " name)
10948 (if (eq (car plist) :name)
10949 (setq plist (cddr plist))
10950 (insert " " (prin1-to-string (pop plist)))))
10951 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
10952 (beginning-of-line -2)))
10954 (defun org-prepare-dblock ()
10955 "Prepare dynamic block for refresh.
10956 This empties the block, puts the cursor at the insert position and returns
10957 the property list including an extra property :name with the block name."
10958 (unless (looking-at org-dblock-start-re)
10959 (error "Not at a dynamic block"))
10960 (let* ((begdel (1+ (match-end 0)))
10961 (name (org-no-properties (match-string 1)))
10962 (params (append (list :name name)
10963 (read (concat "(" (match-string 3) ")")))))
10965 (beginning-of-line 1)
10966 (skip-chars-forward " \t")
10967 (setq params (plist-put params :indentation-column (current-column))))
10968 (unless (re-search-forward org-dblock-end-re nil t)
10969 (error "Dynamic block not terminated"))
10972 (list :content (buffer-substring
10973 begdel (match-beginning 0)))))
10974 (delete-region begdel (match-beginning 0))
10979 (defun org-map-dblocks (&optional command)
10980 "Apply COMMAND to all dynamic blocks in the current buffer.
10981 If COMMAND is not given, use `org-update-dblock'."
10982 (let ((cmd (or command 'org-update-dblock)))
10984 (goto-char (point-min))
10985 (while (re-search-forward org-dblock-start-re nil t)
10986 (goto-char (match-beginning 0))
10988 (condition-case nil
10990 (error (message "Error during update of dynamic block"))))
10991 (unless (re-search-forward org-dblock-end-re nil t)
10992 (error "Dynamic block not terminated"))))))
10994 (defun org-dblock-update (&optional arg)
10995 "User command for updating dynamic blocks.
10996 Update the dynamic block at point. With prefix ARG, update all dynamic
10997 blocks in the buffer."
11000 (org-update-all-dblocks)
11001 (or (looking-at org-dblock-start-re)
11002 (org-beginning-of-dblock))
11003 (org-update-dblock)))
11005 (defun org-update-dblock ()
11006 "Update the dynamic block at point.
11007 This means to empty the block, parse for parameters and then call
11008 the correct writing function."
11010 (save-window-excursion
11011 (let* ((pos (point))
11012 (line (org-current-line))
11013 (params (org-prepare-dblock))
11014 (name (plist-get params :name))
11015 (indent (plist-get params :indentation-column))
11016 (cmd (intern (concat "org-dblock-write:" name))))
11017 (message "Updating dynamic block `%s' at line %d..." name line)
11018 (funcall cmd params)
11019 (message "Updating dynamic block `%s' at line %d...done" name line)
11021 (when (and indent (> indent 0))
11022 (setq indent (make-string indent ?\ ))
11024 (org-beginning-of-dblock)
11026 (while (not (looking-at org-dblock-end-re))
11028 (beginning-of-line 2))
11029 (when (looking-at org-dblock-end-re)
11030 (and (looking-at "[ \t]+")
11031 (replace-match ""))
11032 (insert indent)))))))
11034 (defun org-beginning-of-dblock ()
11035 "Find the beginning of the dynamic block at point.
11036 Error if there is no such block at point."
11037 (let ((pos (point))
11040 (if (and (re-search-backward org-dblock-start-re nil t)
11041 (setq beg (match-beginning 0))
11042 (re-search-forward org-dblock-end-re nil t)
11043 (> (match-end 0) pos))
11046 (error "Not in a dynamic block"))))
11048 (defun org-update-all-dblocks ()
11049 "Update all dynamic blocks in the buffer.
11050 This function can be used in a hook."
11052 (when (eq major-mode 'org-mode)
11053 (org-map-dblocks 'org-update-dblock)))
11058 (defconst org-additional-option-like-keywords
11059 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML:"
11060 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook:"
11061 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
11062 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX:"
11064 "ORGTBL" "TBLFM:" "TBLNAME:"
11065 "BEGIN_EXAMPLE" "END_EXAMPLE"
11066 "BEGIN_QUOTE" "END_QUOTE"
11067 "BEGIN_VERSE" "END_VERSE"
11068 "BEGIN_CENTER" "END_CENTER"
11069 "BEGIN_SRC" "END_SRC"
11070 "BEGIN_RESULT" "END_RESULT"
11072 "HEADER:" "HEADERS:"
11073 "CATEGORY:" "COLUMNS:" "PROPERTY:"
11074 "CAPTION:" "LABEL:"
11080 (defcustom org-structure-template-alist
11082 ("s" "#+BEGIN_SRC ?\n\n#+END_SRC"
11083 "<src lang=\"?\">\n\n</src>")
11084 ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE"
11085 "<example>\n?\n</example>")
11086 ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE"
11087 "<quote>\n?\n</quote>")
11088 ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE"
11089 "<verse>\n?\n</verse>")
11090 ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER"
11091 "<center>\n?\n</center>")
11092 ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX"
11093 "<literal style=\"latex\">\n?\n</literal>")
11095 "<literal style=\"latex\">?</literal>")
11096 ("h" "#+BEGIN_HTML\n?\n#+END_HTML"
11097 "<literal style=\"html\">\n?\n</literal>")
11099 "<literal style=\"html\">?</literal>")
11100 ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII")
11104 ("I" "#+INCLUDE %file ?"
11105 "<include file=%file markup=\"?\">")
11107 "Structure completion elements.
11108 This is a list of abbreviation keys and values. The value gets inserted
11109 if you type `<' followed by the key and then press the completion key,
11110 usually `M-TAB'. %file will be replaced by a file name after prompting
11111 for the file using completion. The cursor will be placed at the position
11112 of the `?` in the template.
11113 There are two templates for each key, the first uses the original Org syntax,
11114 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
11115 the default when the /org-mtags.el/ module has been loaded. See also the
11116 variable `org-mtags-prefer-muse-templates'."
11117 :group 'org-completion
11119 (string :tag "Key")
11120 (string :tag "Template")
11121 (string :tag "Muse Template")))
11123 (defun org-try-structure-completion ()
11124 "Try to complete a structure template before point.
11125 This looks for strings like \"<e\" on an otherwise empty line and
11127 (let ((l (buffer-substring (point-at-bol) (point)))
11129 (when (and (looking-at "[ \t]*$")
11130 (string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l)
11131 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
11132 (org-complete-expand-structure-template (+ -1 (point-at-bol)
11133 (match-beginning 1)) a)
11136 (defun org-complete-expand-structure-template (start cell)
11137 "Expand a structure template."
11138 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
11139 (rpl (nth (if musep 2 1) cell))
11141 (delete-region start (point))
11142 (when (string-match "\\`#\\+" rpl)
11145 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
11146 (setq ind (buffer-substring (point-at-bol) (point))))
11148 (setq start (point))
11149 (if (string-match "%file" rpl)
11150 (setq rpl (replace-match
11154 (abbreviate-file-name (read-file-name "Include file: ")))
11157 (setq rpl (mapconcat 'identity (split-string rpl "\n")
11158 (concat "\n" ind)))
11160 (if (re-search-backward "\\?" start t) (delete-char 1))))
11162 ;;;; TODO, DEADLINE, Comments
11164 (defun org-toggle-comment ()
11165 "Change the COMMENT state of an entry."
11168 (org-back-to-heading)
11169 (let (case-fold-search)
11171 ((looking-at (format org-heading-keyword-regexp-format
11172 org-comment-string))
11173 (goto-char (match-end 1))
11174 (looking-at (concat " +" org-comment-string))
11175 (replace-match "" t t)
11176 (when (eolp) (insert " ")))
11177 ((looking-at org-outline-regexp)
11178 (goto-char (match-end 0))
11179 (insert org-comment-string " "))))))
11181 (defvar org-last-todo-state-is-todo nil
11182 "This is non-nil when the last TODO state change led to a TODO state.
11183 If the last change removed the TODO tag or switched to DONE, then
11186 (defvar org-setting-tags nil) ; dynamically skipped
11188 (defvar org-todo-setup-filter-hook nil
11189 "Hook for functions that pre-filter todo specs.
11190 Each function takes a todo spec and returns either nil or the spec
11191 transformed into canonical form." )
11193 (defvar org-todo-get-default-hook nil
11194 "Hook for functions that get a default item for todo.
11195 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
11196 nil or a string to be used for the todo mark." )
11198 (defvar org-agenda-headline-snapshot-before-repeat)
11200 (defun org-current-effective-time ()
11201 "Return current time adjusted for `org-extend-today-until' variable"
11202 (let* ((ct (org-current-time))
11203 (dct (decode-time ct))
11205 (if (and org-use-effective-time
11206 (< (nth 2 dct) org-extend-today-until))
11207 (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
11211 (defun org-todo-yesterday (&optional arg)
11212 "Like `org-todo' but the time of change will be 23:59 of yesterday."
11214 (if (eq major-mode 'org-agenda-mode)
11215 (apply 'org-agenda-todo-yesterday arg)
11216 (let* ((hour (third (decode-time
11217 (org-current-time))))
11218 (org-extend-today-until (1+ hour)))
11221 (defun org-todo (&optional arg)
11222 "Change the TODO state of an item.
11223 The state of an item is given by a keyword at the start of the heading,
11225 *** TODO Write paper
11228 The different keywords are specified in the variable `org-todo-keywords'.
11229 By default the available states are \"TODO\" and \"DONE\".
11230 So for this example: when the item starts with TODO, it is changed to DONE.
11231 When it starts with DONE, the DONE is removed. And when neither TODO nor
11232 DONE are present, add TODO at the beginning of the heading.
11234 With \\[universal-argument] prefix arg, use completion to determine the new \
11236 With numeric prefix arg, switch to that state.
11237 With a double \\[universal-argument] prefix, switch to the next set of TODO \
11238 keywords (nextset).
11239 With a triple \\[universal-argument] prefix, circumvent any state blocking.
11240 With a numeric prefix arg of 0, inhibit note taking for the change.
11242 For calling through lisp, arg is also interpreted in the following way:
11243 'none -> empty state
11244 \"\"(empty string) -> switch to empty state
11245 'done -> switch to DONE
11246 'nextset -> switch to the next set of keywords
11247 'previousset -> switch to the previous set of keywords
11248 \"WAITING\" -> switch to the specified keyword, but only if it
11249 really is a member of `org-todo-keywords'."
11251 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
11252 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
11253 'region-start-level 'region))
11254 org-loop-over-headlines-in-active-region)
11257 org-loop-over-headlines-in-active-region
11258 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
11259 (if (equal arg '(16)) (setq arg 'nextset))
11260 (let ((org-blocker-hook org-blocker-hook)
11261 (case-fold-search nil))
11262 (when (equal arg '(64))
11263 (setq arg nil org-blocker-hook nil))
11264 (when (and org-blocker-hook
11265 (or org-inhibit-blocking
11266 (org-entry-get nil "NOBLOCKING")))
11267 (setq org-blocker-hook nil))
11270 (org-back-to-heading t)
11271 (if (looking-at org-outline-regexp) (goto-char (1- (match-end 0))))
11272 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|[ \t]*$\\)"))
11273 (looking-at "\\(?: *\\|[ \t]*$\\)"))
11274 (let* ((match-data (match-data))
11275 (startpos (point-at-bol))
11276 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
11277 (org-log-done org-log-done)
11278 (org-log-repeat org-log-repeat)
11279 (org-todo-log-states org-todo-log-states)
11280 (org-inhibit-logging
11282 (progn (setq arg nil) 'note) org-inhibit-logging))
11283 (this (match-string 1))
11284 (hl-pos (match-beginning 0))
11285 (head (org-get-todo-sequence-head this))
11286 (ass (assoc head org-todo-kwd-alist))
11287 (interpret (nth 1 ass))
11288 (done-word (nth 3 ass))
11289 (final-done-word (nth 4 ass))
11290 (last-state (or this ""))
11291 (completion-ignore-case t)
11292 (member (member this org-todo-keywords-1))
11293 (tail (cdr member))
11295 ((and org-todo-key-trigger
11296 (or (and (equal arg '(4))
11297 (eq org-use-fast-todo-selection 'prefix))
11298 (and (not arg) org-use-fast-todo-selection
11299 (not (eq org-use-fast-todo-selection
11301 ;; Use fast selection
11302 (org-fast-todo-selection))
11303 ((and (equal arg '(4))
11304 (or (not org-use-fast-todo-selection)
11305 (not org-todo-key-trigger)))
11306 ;; Read a state with completion
11307 (org-icompleting-read
11308 "State: " (mapcar (lambda(x) (list x))
11309 org-todo-keywords-1)
11313 (if tail (car tail) nil)
11314 (car org-todo-keywords-1)))
11316 (if (equal member org-todo-keywords-1)
11319 (nth (- (length org-todo-keywords-1)
11321 org-todo-keywords-1)
11322 (org-last org-todo-keywords-1))))
11323 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
11324 (setq arg nil))) ; hack to fall back to cycling
11326 ;; user or caller requests a specific state
11328 ((equal arg "") nil)
11329 ((eq arg 'none) nil)
11330 ((eq arg 'done) (or done-word (car org-done-keywords)))
11332 (or (car (cdr (member head org-todo-heads)))
11333 (car org-todo-heads)))
11334 ((eq arg 'previousset)
11335 (let ((org-todo-heads (reverse org-todo-heads)))
11336 (or (car (cdr (member head org-todo-heads)))
11337 (car org-todo-heads))))
11338 ((car (member arg org-todo-keywords-1)))
11340 (error "State `%s' not valid in this file" arg))
11341 ((nth (1- (prefix-numeric-value arg))
11342 org-todo-keywords-1))))
11343 ((null member) (or head (car org-todo-keywords-1)))
11344 ((equal this final-done-word) nil) ;; -> make empty
11345 ((null tail) nil) ;; -> first entry
11346 ((memq interpret '(type priority))
11347 (if (eq this-command last-command)
11349 (if (> (length tail) 0)
11350 (or done-word (car org-done-keywords))
11355 (run-hook-with-args-until-success
11356 'org-todo-get-default-hook state last-state)
11358 (next (if state (concat " " state " ") " "))
11359 (change-plist (list :type 'todo-state-change :from this :to state
11360 :position startpos))
11362 (when org-blocker-hook
11363 (setq org-last-todo-state-is-todo
11364 (not (member this org-done-keywords)))
11365 (unless (save-excursion
11367 (org-with-wide-buffer
11368 (run-hook-with-args-until-failure
11369 'org-blocker-hook change-plist))))
11370 (if (org-called-interactively-p 'interactive)
11371 (error "TODO state change from %s to %s blocked" this state)
11373 (message "TODO state change from %s to %s blocked" this state)
11374 (throw 'exit nil))))
11375 (store-match-data match-data)
11376 (replace-match next t t)
11377 (unless (pos-visible-in-window-p hl-pos)
11378 (message "TODO state changed to %s" (org-trim next)))
11380 (setq head (org-get-todo-sequence-head state)
11381 ass (assoc head org-todo-kwd-alist)
11382 interpret (nth 1 ass)
11383 done-word (nth 3 ass)
11384 final-done-word (nth 4 ass)))
11385 (when (memq arg '(nextset previousset))
11386 (message "Keyword-Set %d/%d: %s"
11387 (- (length org-todo-sets) -1
11388 (length (memq (assoc state org-todo-sets) org-todo-sets)))
11389 (length org-todo-sets)
11390 (mapconcat 'identity (assoc state org-todo-sets) " ")))
11391 (setq org-last-todo-state-is-todo
11392 (not (member state org-done-keywords)))
11393 (setq now-done-p (and (member state org-done-keywords)
11394 (not (member this org-done-keywords))))
11395 (and logging (org-local-logging logging))
11396 (when (and (or org-todo-log-states org-log-done)
11397 (not (eq org-inhibit-logging t))
11398 (not (memq arg '(nextset previousset))))
11399 ;; we need to look at recording a time and note
11400 (setq dolog (or (nth 1 (assoc state org-todo-log-states))
11401 (nth 2 (assoc this org-todo-log-states))))
11402 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
11403 (setq dolog 'time))
11405 (member state org-not-done-keywords)
11406 (not (member this org-not-done-keywords)))
11407 ;; This is now a todo state and was not one before
11408 ;; If there was a CLOSED time stamp, get rid of it.
11409 (org-add-planning-info nil nil 'closed))
11410 (when (and now-done-p org-log-done)
11411 ;; It is now done, and it was not done before
11412 (org-add-planning-info 'closed (org-current-effective-time))
11413 (if (and (not dolog) (eq 'note org-log-done))
11414 (org-add-log-setup 'done state this 'findpos 'note)))
11415 (when (and state dolog)
11416 ;; This is a non-nil state, and we need to log it
11417 (org-add-log-setup 'state state this 'findpos dolog)))
11418 ;; Fixup tag positioning
11419 (org-todo-trigger-tag-changes state)
11420 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
11421 (when org-provide-todo-statistics
11422 (org-update-parent-todo-statistics))
11423 (run-hooks 'org-after-todo-state-change-hook)
11424 (if (and arg (not (member state org-done-keywords)))
11425 (setq head (org-get-todo-sequence-head state)))
11426 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
11427 ;; Do we need to trigger a repeat?
11429 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
11430 ;; This is for the agenda, take a snapshot of the headline.
11432 (setq org-agenda-headline-snapshot-before-repeat
11433 (org-get-heading))))
11434 (org-auto-repeat-maybe state))
11435 ;; Fixup cursor location if close to the keyword
11436 (if (and (outline-on-heading-p)
11438 (save-excursion (beginning-of-line 1)
11439 (looking-at org-todo-line-regexp))
11440 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
11442 (goto-char (or (match-end 2) (match-end 1)))
11443 (and (looking-at " ") (just-one-space))))
11444 (when org-trigger-hook
11446 (run-hook-with-args 'org-trigger-hook change-plist)))))))))
11448 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
11449 "Block turning an entry into a TODO, using the hierarchy.
11450 This checks whether the current task should be blocked from state
11451 changes. Such blocking occurs when:
11453 1. The task has children which are not all in a completed state.
11455 2. A task has a parent with the property :ORDERED:, and there
11456 are siblings prior to the current task with incomplete
11459 3. The parent of the task is blocked because it has siblings that should
11460 be done first, or is child of a block grandparent TODO entry."
11462 (if (not org-enforce-todo-dependencies)
11463 t ; if locally turned off don't block
11465 ;; If this is not a todo state change, or if this entry is already DONE,
11467 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
11468 (member (plist-get change-plist :from)
11469 (cons 'done org-done-keywords))
11470 (member (plist-get change-plist :to)
11471 (cons 'todo org-not-done-keywords))
11472 (not (plist-get change-plist :to)))
11473 (throw 'dont-block t))
11474 ;; If this task has children, and any are undone, it's blocked
11476 (org-back-to-heading t)
11477 (let ((this-level (funcall outline-level)))
11478 (outline-next-heading)
11479 (let ((child-level (funcall outline-level)))
11480 (while (and (not (eobp))
11481 (> child-level this-level))
11482 ;; this todo has children, check whether they are all
11484 (if (and (not (org-entry-is-done-p))
11485 (org-entry-is-todo-p))
11486 (throw 'dont-block nil))
11487 (outline-next-heading)
11488 (setq child-level (funcall outline-level))))))
11489 ;; Otherwise, if the task's parent has the :ORDERED: property, and
11490 ;; any previous siblings are undone, it's blocked
11492 (org-back-to-heading t)
11493 (let* ((pos (point))
11494 (parent-pos (and (org-up-heading-safe) (point))))
11495 (if (not parent-pos) (throw 'dont-block t)) ; no parent
11496 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
11498 (re-search-forward org-not-done-heading-regexp pos t))
11499 (throw 'dont-block nil)) ; block, there is an older sibling not done.
11500 ;; Search further up the hierarchy, to see if an ancestor is blocked
11502 (goto-char parent-pos)
11503 (if (not (looking-at org-not-done-heading-regexp))
11504 (throw 'dont-block t)) ; do not block, parent is not a TODO
11506 (setq parent-pos (and (org-up-heading-safe) (point)))
11507 (if (not parent-pos) (throw 'dont-block t)) ; no parent
11508 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
11510 (re-search-forward org-not-done-heading-regexp pos t))
11511 (throw 'dont-block nil)))))))) ; block, older sibling not done.
11513 (defcustom org-track-ordered-property-with-tag nil
11514 "Should the ORDERED property also be shown as a tag?
11515 The ORDERED property decides if an entry should require subtasks to be
11516 completed in sequence. Since a property is not very visible, setting
11517 this option means that toggling the ORDERED property with the command
11518 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
11519 not relevant for the behavior, but it makes things more visible.
11521 Note that toggling the tag with tags commands will not change the property
11522 and therefore not influence behavior!
11524 This can be t, meaning the tag ORDERED should be used, It can also be a
11525 string to select a different tag for this task."
11528 (const :tag "No tracking" nil)
11529 (const :tag "Track with ORDERED tag" t)
11530 (string :tag "Use other tag")))
11532 (defun org-toggle-ordered-property ()
11533 "Toggle the ORDERED property of the current entry.
11534 For better visibility, you can track the value of this property with a tag.
11535 See variable `org-track-ordered-property-with-tag'."
11537 (let* ((t1 org-track-ordered-property-with-tag)
11538 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
11540 (org-back-to-heading)
11541 (if (org-entry-get nil "ORDERED")
11543 (org-delete-property "ORDERED")
11544 (and tag (org-toggle-tag tag 'off))
11545 (message "Subtasks can be completed in arbitrary order"))
11546 (org-entry-put nil "ORDERED" "t")
11547 (and tag (org-toggle-tag tag 'on))
11548 (message "Subtasks must be completed in sequence")))))
11550 (defvar org-blocked-by-checkboxes) ; dynamically scoped
11551 (defun org-block-todo-from-checkboxes (change-plist)
11552 "Block turning an entry into a TODO, using checkboxes.
11553 This checks whether the current task should be blocked from state
11554 changes because there are unchecked boxes in this entry."
11555 (if (not org-enforce-todo-checkbox-dependencies)
11556 t ; if locally turned off don't block
11558 ;; If this is not a todo state change, or if this entry is already DONE,
11560 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
11561 (member (plist-get change-plist :from)
11562 (cons 'done org-done-keywords))
11563 (member (plist-get change-plist :to)
11564 (cons 'todo org-not-done-keywords))
11565 (not (plist-get change-plist :to)))
11566 (throw 'dont-block t))
11567 ;; If this task has checkboxes that are not checked, it's blocked
11569 (org-back-to-heading t)
11570 (let ((beg (point)) end)
11571 (outline-next-heading)
11574 (if (org-list-search-forward
11575 (concat (org-item-beginning-re)
11576 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
11580 (if (boundp 'org-blocked-by-checkboxes)
11581 (setq org-blocked-by-checkboxes t))
11582 (throw 'dont-block nil)))))
11583 t))) ; do not block
11585 (defun org-entry-blocked-p ()
11586 "Is the current entry blocked?"
11587 (if (org-entry-get nil "NOBLOCKING")
11588 nil ;; Never block this entry
11590 (run-hook-with-args-until-failure
11592 (list :type 'todo-state-change
11597 (defun org-update-statistics-cookies (all)
11598 "Update the statistics cookie, either from TODO or from checkboxes.
11599 This should be called with the cursor in a line with a statistics cookie."
11603 (org-update-checkbox-count 'all)
11604 (org-map-entries 'org-update-parent-todo-statistics))
11605 (if (not (org-at-heading-p))
11606 (org-update-checkbox-count)
11607 (let ((pos (move-marker (make-marker) (point)))
11609 (ignore-errors (org-back-to-heading t))
11610 (if (not (org-at-heading-p))
11611 (org-update-checkbox-count)
11612 (setq l1 (org-outline-level))
11613 (setq end (save-excursion
11614 (outline-next-heading)
11615 (if (org-at-heading-p) (setq l2 (org-outline-level)))
11617 (if (and (save-excursion
11619 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11620 (not (save-excursion (re-search-forward
11621 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11622 (org-update-checkbox-count)
11623 (if (and l2 (> l2 l1))
11626 (org-update-parent-todo-statistics))
11628 (beginning-of-line 1)
11629 (while (re-search-forward
11630 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11632 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11634 (move-marker pos nil)))))
11636 (defvar org-entry-property-inherited-from) ;; defined below
11637 (defun org-update-parent-todo-statistics ()
11638 "Update any statistics cookie in the parent of the current headline.
11639 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11640 the entire subtree and this will travel up the hierarchy and update
11641 statistics everywhere."
11642 (let* ((prop (save-excursion (org-up-heading-safe)
11643 (org-entry-get nil "COOKIE_DATA" 'inherit)))
11644 (recursive (or (not org-hierarchical-todo-statistics)
11645 (and prop (string-match "\\<recursive\\>" prop))))
11646 (lim (or (and prop (marker-position org-entry-property-inherited-from))
11649 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11650 level ltoggle l1 new ndel
11651 (cnt-all 0) (cnt-done 0) is-percent kwd
11652 checkbox-beg ov ovs ove cookie-present)
11655 (beginning-of-line 1)
11656 (setq ltoggle (funcall outline-level))
11657 ;; Three situations are to consider:
11659 ;; 1. if `org-hierarchical-todo-statistics' is nil, repeat up
11660 ;; to the top-level ancestor on the headline;
11662 ;; 2. If parent has "recursive" property, repeat up to the
11663 ;; headline setting that property, taking inheritance into
11666 ;; 3. Else, move up to direct parent and proceed only once.
11667 (while (and (setq level (org-up-heading-safe))
11668 (or recursive first)
11670 (setq first nil cookie-present nil)
11674 (downcase (or (org-entry-get nil "COOKIE_DATA")
11677 (while (re-search-forward box-re (point-at-eol) t)
11678 (setq cnt-all 0 cnt-done 0 cookie-present t)
11679 (setq is-percent (match-end 2) checkbox-beg (match-beginning 0))
11681 (unless (outline-next-heading) (throw 'exit nil))
11682 (while (and (looking-at org-complex-heading-regexp)
11683 (> (setq l1 (length (match-string 1))) level))
11684 (setq kwd (and (or recursive (= l1 ltoggle))
11686 (if (or (eq org-provide-todo-statistics 'all-headlines)
11687 (and (listp org-provide-todo-statistics)
11688 (or (member kwd org-provide-todo-statistics)
11689 (member kwd org-done-keywords))))
11690 (setq cnt-all (1+ cnt-all))
11691 (if (eq org-provide-todo-statistics t)
11692 (and kwd (setq cnt-all (1+ cnt-all)))))
11693 (and (member kwd org-done-keywords)
11694 (setq cnt-done (1+ cnt-done)))
11695 (outline-next-heading)))
11698 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
11699 (format "[%d/%d]" cnt-done cnt-all))
11700 ndel (- (match-end 0) checkbox-beg))
11701 ;; handle overlays when updating cookie from column view
11702 (when (setq ov (car (overlays-at checkbox-beg)))
11703 (setq ovs (overlay-start ov) ove (overlay-end ov))
11704 (delete-overlay ov))
11705 (goto-char checkbox-beg)
11707 (delete-region (point) (+ (point) ndel))
11708 (when org-auto-align-tags (org-fix-tags-on-the-fly))
11709 (when ov (move-overlay ov ovs ove)))
11710 (when cookie-present
11711 (run-hook-with-args 'org-after-todo-statistics-hook
11712 cnt-done (- cnt-all cnt-done))))))
11713 (run-hooks 'org-todo-statistics-hook)))
11715 (defvar org-after-todo-statistics-hook nil
11716 "Hook that is called after a TODO statistics cookie has been updated.
11717 Each function is called with two arguments: the number of not-done entries
11718 and the number of done entries.
11720 For example, the following function, when added to this hook, will switch
11721 an entry to DONE when all children are done, and back to TODO when new
11722 entries are set to a TODO status. Note that this hook is only called
11723 when there is a statistics cookie in the headline!
11725 (defun org-summary-todo (n-done n-not-done)
11726 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
11727 (let (org-log-done org-log-states) ; turn off logging
11728 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
11731 (defvar org-todo-statistics-hook nil
11732 "Hook that is run whenever Org thinks TODO statistics should be updated.
11733 This hook runs even if there is no statistics cookie present, in which case
11734 `org-after-todo-statistics-hook' would not run.")
11736 (defun org-todo-trigger-tag-changes (state)
11737 "Apply the changes defined in `org-todo-state-tags-triggers'."
11738 (let ((l org-todo-state-tags-triggers)
11740 (when (or (not state) (equal state ""))
11741 (setq changes (append changes (cdr (assoc "" l)))))
11742 (when (and (stringp state) (> (length state) 0))
11743 (setq changes (append changes (cdr (assoc state l)))))
11744 (when (member state org-not-done-keywords)
11745 (setq changes (append changes (cdr (assoc 'todo l)))))
11746 (when (member state org-done-keywords)
11747 (setq changes (append changes (cdr (assoc 'done l)))))
11748 (dolist (c changes)
11749 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
11751 (defun org-local-logging (value)
11752 "Get logging settings from a property VALUE."
11754 ;; directly set the variables, they are already local.
11755 (setq org-log-done nil
11757 org-todo-log-states nil)
11758 (setq words (org-split-string value))
11759 (while (setq w (pop words))
11761 ((setq a (assoc w org-startup-options))
11762 (and (member (nth 1 a) '(org-log-done org-log-repeat))
11763 (set (nth 1 a) (nth 2 a))))
11764 ((setq a (org-extract-log-state-settings w))
11765 (and (member (car a) org-todo-keywords-1)
11766 (push a org-todo-log-states)))))))
11768 (defun org-get-todo-sequence-head (kwd)
11769 "Return the head of the TODO sequence to which KWD belongs.
11770 If KWD is not set, check if there is a text property remembering the
11775 (or (get-text-property (point-at-bol) 'org-todo-head)
11777 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
11778 nil (point-at-eol)))
11779 (get-text-property p 'org-todo-head))))
11780 ((not (member kwd org-todo-keywords-1))
11781 (car org-todo-keywords-1))
11782 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
11784 (defun org-fast-todo-selection ()
11785 "Fast TODO keyword selection with single keys.
11786 Returns the new TODO keyword, or nil if no state change should occur."
11787 (let* ((fulltable org-todo-key-alist)
11788 (done-keywords org-done-keywords) ;; needed for the faces.
11789 (maxlen (apply 'max (mapcar
11791 (if (stringp (car x)) (string-width (car x)) 0))
11794 (fwidth (+ maxlen 3 1 3))
11795 (ncol (/ (- (window-width) 4) fwidth))
11799 (save-window-excursion
11801 (set-buffer (get-buffer-create " *Org todo*"))
11802 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
11804 (org-set-local 'org-done-keywords done-keywords)
11805 (setq tbl fulltable cnt 0)
11806 (while (setq e (pop tbl))
11808 ((equal e '(:startgroup))
11809 (push '() groups) (setq ingroup t)
11810 (when (not (= cnt 0))
11814 ((equal e '(:endgroup))
11815 (setq ingroup nil cnt 0)
11817 ((equal e '(:newline))
11818 (when (not (= cnt 0))
11822 (while (equal (car tbl) '(:newline))
11824 (setq tbl (cdr tbl)))))
11826 (setq tg (car e) c (cdr e))
11827 (if ingroup (push tg (car groups)))
11828 (setq tg (org-add-props tg nil 'face
11829 (org-get-todo-face tg)))
11830 (if (and (= cnt 0) (not ingroup)) (insert " "))
11831 (insert "[" c "] " tg (make-string
11832 (- fwidth 4 (length tg)) ?\ ))
11833 (when (= (setq cnt (1+ cnt)) ncol)
11835 (if ingroup (insert " "))
11838 (goto-char (point-min))
11839 (if (not expert) (org-fit-window-to-buffer))
11840 (message "[a-z..]:Set [SPC]:clear")
11841 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
11844 (and (= c ?q) (not (rassoc c fulltable))))
11845 (setq quit-flag t))
11847 ((setq e (rassoc c fulltable) tg (car e))
11849 (t (setq quit-flag t)))))))
11851 (defun org-entry-is-todo-p ()
11852 (member (org-get-todo-state) org-not-done-keywords))
11854 (defun org-entry-is-done-p ()
11855 (member (org-get-todo-state) org-done-keywords))
11857 (defun org-get-todo-state ()
11859 (org-back-to-heading t)
11860 (and (looking-at org-todo-line-regexp)
11862 (match-string 2))))
11864 (defun org-at-date-range-p (&optional inactive-ok)
11865 "Is the cursor inside a date range?"
11869 (let ((pos (point)))
11870 (skip-chars-backward "^[<\r\n")
11871 (skip-chars-backward "<[")
11872 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11873 (>= (match-end 0) pos)
11875 (skip-chars-backward "^<[\r\n")
11876 (skip-chars-backward "<[")
11877 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
11878 (>= (match-end 0) pos)
11882 (defun org-get-repeat (&optional tagline)
11883 "Check if there is a deadline/schedule with repeater in this entry."
11886 (org-back-to-heading t)
11887 (and (re-search-forward (if tagline
11888 (concat tagline "\\s-*" org-repeat-re)
11890 (org-entry-end-position) t)
11891 (match-string-no-properties 1)))))
11893 (defvar org-last-changed-timestamp)
11894 (defvar org-last-inserted-timestamp)
11895 (defvar org-log-post-message)
11896 (defvar org-log-note-purpose)
11897 (defvar org-log-note-how)
11898 (defvar org-log-note-extra)
11899 (defun org-auto-repeat-maybe (done-word)
11900 "Check if the current headline contains a repeated deadline/schedule.
11901 If yes, set TODO state back to what it was and change the base date
11902 of repeating deadline/scheduled time stamps to new date.
11903 This function is run automatically after each state change to a DONE state."
11904 ;; last-state is dynamically scoped into this function
11905 (let* ((repeat (org-get-repeat))
11906 (aa (assoc last-state org-todo-kwd-alist))
11907 (interpret (nth 1 aa))
11909 (whata '(("d" . day) ("m" . month) ("y" . year)))
11910 (msg "Entry repeats: ")
11912 (org-todo-log-states nil)
11913 re type n what ts time to-state)
11915 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
11916 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
11917 org-todo-repeat-to-state))
11918 (unless (and to-state (member to-state org-todo-keywords-1))
11919 (setq to-state (if (eq interpret 'type) last-state head)))
11920 (org-todo to-state)
11921 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
11922 (org-entry-put nil "LAST_REPEAT" (format-time-string
11923 (org-time-stamp-format t t))))
11924 (when org-log-repeat
11925 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
11926 (memq 'org-add-log-note post-command-hook))
11927 ;; OK, we are already setup for some record
11928 (if (eq org-log-repeat 'note)
11929 ;; make sure we take a note, not only a time stamp
11930 (setq org-log-note-how 'note))
11931 ;; Set up for taking a record
11932 (org-add-log-setup 'state (or done-word (car org-done-keywords))
11934 'findpos org-log-repeat)))
11935 (org-back-to-heading t)
11936 (org-add-planning-info nil nil 'closed)
11937 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
11938 org-deadline-time-regexp "\\)\\|\\("
11939 org-ts-regexp "\\)"))
11940 (while (re-search-forward
11941 re (save-excursion (outline-next-heading) (point)) t)
11942 (setq type (if (match-end 1) org-scheduled-string
11943 (if (match-end 3) org-deadline-string "Plain:"))
11944 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
11945 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts)
11946 (setq n (string-to-number (match-string 2 ts))
11947 what (match-string 3 ts))
11948 (if (equal what "w") (setq n (* n 7) what "d"))
11949 ;; Preparation, see if we need to modify the start date for the change
11950 (when (match-end 1)
11951 (setq time (save-match-data (org-time-string-to-time ts)))
11953 ((equal (match-string 1 ts) ".")
11954 ;; Shift starting date to today
11955 (org-timestamp-change
11956 (- (org-today) (time-to-days time))
11958 ((equal (match-string 1 ts) "+")
11959 (let ((nshiftmax 10) (nshift 0))
11960 (while (or (= nshift 0)
11961 (<= (time-to-days time)
11962 (time-to-days (current-time))))
11963 (when (= (incf nshift) nshiftmax)
11964 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
11966 (org-timestamp-change n (cdr (assoc what whata)))
11967 (org-at-timestamp-p t)
11968 (setq ts (match-string 1))
11969 (setq time (save-match-data (org-time-string-to-time ts)))))
11970 (org-timestamp-change (- n) (cdr (assoc what whata)))
11971 ;; rematch, so that we have everything in place for the real shift
11972 (org-at-timestamp-p t)
11973 (setq ts (match-string 1))
11974 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([dwmy]\\)" ts))))
11975 (org-timestamp-change n (cdr (assoc what whata)))
11976 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
11977 (setq org-log-post-message msg)
11978 (message "%s" msg))))
11980 (defun org-show-todo-tree (arg)
11981 "Make a compact tree which shows all headlines marked with TODO.
11982 The tree will show the lines where the regexp matches, and all higher
11983 headlines above the match.
11984 With a \\[universal-argument] prefix, prompt for a regexp to match.
11985 With a numeric prefix N, construct a sparse tree for the Nth element
11986 of `org-todo-keywords-1'."
11988 (let ((case-fold-search nil)
11990 (cond ((null arg) org-not-done-regexp)
11992 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
11993 (mapcar 'list org-todo-keywords-1))))
11995 (mapconcat 'identity (org-split-string kwd "|") "\\|")
11997 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
11998 (regexp-quote (nth (1- (prefix-numeric-value arg))
11999 org-todo-keywords-1)))
12000 (t (error "Invalid prefix argument: %s" arg)))))
12001 (message "%d TODO entries found"
12002 (org-occur (concat "^" org-outline-regexp " *" kwd-re )))))
12004 (defun org-deadline (&optional remove time)
12005 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
12006 With argument REMOVE, remove any deadline from the item.
12007 With argument TIME, set the deadline at the corresponding date. TIME
12008 can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12010 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12011 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12012 'region-start-level 'region))
12013 org-loop-over-headlines-in-active-region)
12015 `(org-deadline ',remove ,time)
12016 org-loop-over-headlines-in-active-region
12017 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12018 (let* ((old-date (org-entry-get nil "DEADLINE"))
12019 (repeater (and old-date
12021 "\\([.+-]+[0-9]+[dwmy]\\(?:[/ ][-+]?[0-9]+[dwmy]\\)?\\) ?"
12023 (match-string 1 old-date))))
12026 (when (and old-date org-log-redeadline)
12027 (org-add-log-setup 'deldeadline nil old-date 'findpos
12028 org-log-redeadline))
12029 (org-remove-timestamp-with-keyword org-deadline-string)
12030 (message "Item no longer has a deadline."))
12031 (org-add-planning-info 'deadline time 'closed)
12032 (when (and old-date org-log-redeadline
12033 (not (equal old-date
12034 (substring org-last-inserted-timestamp 1 -1))))
12035 (org-add-log-setup 'redeadline nil old-date 'findpos
12036 org-log-redeadline))
12039 (org-back-to-heading t)
12040 (when (re-search-forward (concat org-deadline-string " "
12041 org-last-inserted-timestamp)
12043 (outline-next-heading) (point)) t)
12044 (goto-char (1- (match-end 0)))
12045 (insert " " repeater)
12046 (setq org-last-inserted-timestamp
12047 (concat (substring org-last-inserted-timestamp 0 -1)
12049 (substring org-last-inserted-timestamp -1))))))
12050 (message "Deadline on %s" org-last-inserted-timestamp)))))
12052 (defun org-schedule (&optional remove time)
12053 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
12054 With argument REMOVE, remove any scheduling date from the item.
12055 With argument TIME, scheduled at the corresponding date. TIME can
12056 either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12058 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12059 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12060 'region-start-level 'region))
12061 org-loop-over-headlines-in-active-region)
12063 `(org-schedule ',remove ,time)
12064 org-loop-over-headlines-in-active-region
12065 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12066 (let* ((old-date (org-entry-get nil "SCHEDULED"))
12067 (repeater (and old-date
12069 "\\([.+-]+[0-9]+[dwmy]\\(?:[/ ][-+]?[0-9]+[dwmy]\\)?\\) ?"
12071 (match-string 1 old-date))))
12074 (when (and old-date org-log-reschedule)
12075 (org-add-log-setup 'delschedule nil old-date 'findpos
12076 org-log-reschedule))
12077 (org-remove-timestamp-with-keyword org-scheduled-string)
12078 (message "Item is no longer scheduled."))
12079 (org-add-planning-info 'scheduled time 'closed)
12080 (when (and old-date org-log-reschedule
12081 (not (equal old-date
12082 (substring org-last-inserted-timestamp 1 -1))))
12083 (org-add-log-setup 'reschedule nil old-date 'findpos
12084 org-log-reschedule))
12087 (org-back-to-heading t)
12088 (when (re-search-forward (concat org-scheduled-string " "
12089 org-last-inserted-timestamp)
12091 (outline-next-heading) (point)) t)
12092 (goto-char (1- (match-end 0)))
12093 (insert " " repeater)
12094 (setq org-last-inserted-timestamp
12095 (concat (substring org-last-inserted-timestamp 0 -1)
12097 (substring org-last-inserted-timestamp -1))))))
12098 (message "Scheduled to %s" org-last-inserted-timestamp)))))
12100 (defun org-get-scheduled-time (pom &optional inherit)
12101 "Get the scheduled time as a time tuple, of a format suitable
12102 for calling org-schedule with, or if there is no scheduling,
12104 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
12106 (apply 'encode-time (org-parse-time-string time)))))
12108 (defun org-get-deadline-time (pom &optional inherit)
12109 "Get the deadline as a time tuple, of a format suitable for
12110 calling org-deadline with, or if there is no scheduling, returns
12112 (let ((time (org-entry-get pom "DEADLINE" inherit)))
12114 (apply 'encode-time (org-parse-time-string time)))))
12116 (defun org-remove-timestamp-with-keyword (keyword)
12117 "Remove all time stamps with KEYWORD in the current entry."
12118 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
12121 (org-back-to-heading t)
12123 (outline-next-heading)
12124 (while (re-search-backward re beg t)
12126 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
12127 (equal (char-before) ?\ ))
12128 (backward-delete-char 1)
12129 (if (string-match "^[ \t]*$" (buffer-substring
12130 (point-at-bol) (point-at-eol)))
12131 (delete-region (point-at-bol)
12132 (min (point-max) (1+ (point-at-eol))))))))))
12134 (defun org-add-planning-info (what &optional time &rest remove)
12135 "Insert new timestamp with keyword in the line directly after the headline.
12136 WHAT indicates what kind of time stamp to add. TIME indicates the time to use.
12137 If non is given, the user is prompted for a date.
12138 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
12141 (let (org-time-was-given org-end-time-was-given ts
12142 end default-time default-input)
12145 (when (and (memq what '(scheduled deadline))
12147 (and (stringp time)
12148 (string-match "^[-+]+[0-9]" time))))
12149 ;; Try to get a default date/time from existing timestamp
12151 (org-back-to-heading t)
12152 (setq end (save-excursion (outline-next-heading) (point)))
12153 (when (re-search-forward (if (eq what 'scheduled)
12154 org-scheduled-time-regexp
12155 org-deadline-time-regexp)
12157 (setq ts (match-string 1)
12159 (apply 'encode-time (org-parse-time-string ts))
12160 default-input (and ts (org-get-compact-tod ts))))))
12164 ;; This is a string (relative or absolute), set proper date
12165 (apply 'encode-time
12166 (org-read-date-analyze
12167 time default-time (decode-time default-time)))
12168 ;; If necessary, get the time from the user
12169 (or time (org-read-date nil 'to-time nil nil
12170 default-time default-input)))))
12172 (when (and org-insert-labeled-timestamps-at-point
12173 (member what '(scheduled deadline)))
12175 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
12176 (org-insert-time-stamp time org-time-was-given
12177 nil nil nil (list org-end-time-was-given))
12181 (let (col list elt ts buffer-invisibility-spec)
12182 (org-back-to-heading t)
12183 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"))
12184 (goto-char (match-end 1))
12185 (setq col (current-column))
12186 (goto-char (match-end 0))
12187 (if (eobp) (insert "\n") (forward-char 1))
12188 (when (and (not what)
12191 org-keyword-time-not-clock-regexp))))
12192 ;; Nothing to add, nothing to remove...... :-)
12194 (if (and (not (looking-at org-outline-regexp))
12195 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
12197 (not (equal (match-string 1) org-clock-string)))
12198 (narrow-to-region (match-beginning 0) (match-end 0))
12199 (insert-before-markers "\n")
12201 (narrow-to-region (point) (point))
12202 (and org-adapt-indentation (org-indent-to-column col)))
12203 ;; Check if we have to remove something.
12204 (setq list (cons what remove))
12206 (setq elt (pop list))
12207 (when (or (and (eq elt 'scheduled)
12208 (re-search-forward org-scheduled-time-regexp nil t))
12209 (and (eq elt 'deadline)
12210 (re-search-forward org-deadline-time-regexp nil t))
12211 (and (eq elt 'closed)
12212 (re-search-forward org-closed-time-regexp nil t)))
12214 (if (looking-at "--+<[^>]+>") (replace-match ""))))
12215 (and (looking-at "[ \t]+") (replace-match ""))
12216 (and org-adapt-indentation (bolp) (org-indent-to-column col))
12219 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
12220 (cond ((eq what 'scheduled) org-scheduled-string)
12221 ((eq what 'deadline) org-deadline-string)
12222 ((eq what 'closed) org-closed-string))
12224 (setq ts (org-insert-time-stamp
12226 (or org-time-was-given
12227 (and (eq what 'closed) org-log-done-with-time))
12229 nil nil (list org-end-time-was-given)))
12231 (if (not (or (bolp) (eq (char-before) ?\ )
12232 (memq (char-after) '(32 10))
12235 (goto-char (point-min))
12237 (if (and (looking-at "[ \t]*\n")
12238 (equal (char-before) ?\n))
12239 (delete-region (1- (point)) (point-at-eol)))
12242 (defvar org-log-note-marker (make-marker))
12243 (defvar org-log-note-purpose nil)
12244 (defvar org-log-note-state nil)
12245 (defvar org-log-note-previous-state nil)
12246 (defvar org-log-note-how nil)
12247 (defvar org-log-note-extra nil)
12248 (defvar org-log-note-window-configuration nil)
12249 (defvar org-log-note-return-to (make-marker))
12250 (defvar org-log-note-effective-time nil
12251 "Remembered current time so that dynamically scoped
12252 `org-extend-today-until' affects tha timestamps in state change
12255 (defvar org-log-post-message nil
12256 "Message to be displayed after a log note has been stored.
12257 The auto-repeater uses this.")
12259 (defun org-add-note ()
12260 "Add a note to the current entry.
12261 This is done in the same way as adding a state change note."
12263 (org-add-log-setup 'note nil nil 'findpos nil))
12265 (defvar org-property-end-re)
12266 (defun org-add-log-setup (&optional purpose state prev-state
12268 "Set up the post command hook to take a note.
12269 If this is about to TODO state change, the new state is expected in STATE.
12270 When FINDPOS is non-nil, find the correct position for the note in
12271 the current entry. If not, assume that it can be inserted at point.
12272 HOW is an indicator what kind of note should be created.
12273 EXTRA is additional text that will be inserted into the notes buffer."
12274 (let* ((org-log-into-drawer (org-log-into-drawer))
12275 (drawer (cond ((stringp org-log-into-drawer)
12276 org-log-into-drawer)
12277 (org-log-into-drawer "LOGBOOK")
12282 (org-back-to-heading t)
12283 (narrow-to-region (point) (save-excursion
12284 (outline-next-heading) (point)))
12285 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"
12286 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
12288 (goto-char (match-end 0))
12291 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
12294 (goto-char (match-end 0))
12295 (or org-log-states-order-reversed
12296 (and (re-search-forward org-property-end-re nil t)
12297 (goto-char (1- (match-beginning 0))))))
12298 (insert "\n:" drawer ":\n:END:")
12299 (beginning-of-line 0)
12300 (org-indent-line-function)
12301 (beginning-of-line 2)
12302 (org-indent-line-function)
12304 ((and org-log-state-notes-insert-after-drawers
12306 (forward-line) (looking-at org-drawer-regexp)))
12308 (while (looking-at org-drawer-regexp)
12309 (goto-char (match-end 0))
12310 (re-search-forward org-property-end-re (point-max) t)
12312 (forward-line -1)))
12313 (unless org-log-states-order-reversed
12314 (and (= (char-after) ?\n) (forward-char 1))
12315 (org-skip-over-state-notes)
12316 (skip-chars-backward " \t\n\r")))
12317 (move-marker org-log-note-marker (point))
12318 (setq org-log-note-purpose purpose
12319 org-log-note-state state
12320 org-log-note-previous-state prev-state
12321 org-log-note-how how
12322 org-log-note-extra extra
12323 org-log-note-effective-time (org-current-effective-time))
12324 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
12326 (defun org-skip-over-state-notes ()
12327 "Skip past the list of State notes in an entry."
12328 (if (looking-at "\n[ \t]*- State") (forward-char 1))
12329 (when (ignore-errors (goto-char (org-in-item-p)))
12330 (let* ((struct (org-list-struct))
12331 (prevs (org-list-prevs-alist struct)))
12332 (while (looking-at "[ \t]*- State")
12333 (goto-char (or (org-list-get-next-item (point) struct prevs)
12334 (org-list-get-item-end (point) struct)))))))
12336 (defun org-add-log-note (&optional purpose)
12337 "Pop up a window for taking a note, and add this note later at point."
12338 (remove-hook 'post-command-hook 'org-add-log-note)
12339 (setq org-log-note-window-configuration (current-window-configuration))
12340 (delete-other-windows)
12341 (move-marker org-log-note-return-to (point))
12342 (org-pop-to-buffer-same-window (marker-buffer org-log-note-marker))
12343 (goto-char org-log-note-marker)
12344 (org-switch-to-buffer-other-window "*Org Note*")
12346 (if (memq org-log-note-how '(time state))
12347 (let (current-prefix-arg) (org-store-log-note))
12348 (let ((org-inhibit-startup t)) (org-mode))
12349 (insert (format "# Insert note for %s.
12350 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
12352 ((eq org-log-note-purpose 'clock-out) "stopped clock")
12353 ((eq org-log-note-purpose 'done) "closed todo item")
12354 ((eq org-log-note-purpose 'state)
12355 (format "state change from \"%s\" to \"%s\""
12356 (or org-log-note-previous-state "")
12357 (or org-log-note-state "")))
12358 ((eq org-log-note-purpose 'reschedule)
12360 ((eq org-log-note-purpose 'delschedule)
12361 "no longer scheduled")
12362 ((eq org-log-note-purpose 'redeadline)
12363 "changing deadline")
12364 ((eq org-log-note-purpose 'deldeadline)
12365 "removing deadline")
12366 ((eq org-log-note-purpose 'refile)
12368 ((eq org-log-note-purpose 'note)
12370 (t (error "This should not happen")))))
12371 (if org-log-note-extra (insert org-log-note-extra))
12372 (org-set-local 'org-finish-function 'org-store-log-note)
12373 (run-hooks 'org-log-buffer-setup-hook)))
12375 (defvar org-note-abort nil) ; dynamically scoped
12376 (defun org-store-log-note ()
12377 "Finish taking a log note, and insert it to where it belongs."
12378 (let ((txt (buffer-string))
12379 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
12381 (kill-buffer (current-buffer))
12382 (while (string-match "\\`#.*\n[ \t\n]*" txt)
12383 (setq txt (replace-match "" t t txt)))
12384 (if (string-match "\\s-+\\'" txt)
12385 (setq txt (replace-match "" t t txt)))
12386 (setq lines (org-split-string txt "\n"))
12387 (when (and note (string-match "\\S-" note))
12389 (org-replace-escapes
12391 (list (cons "%u" (user-login-name))
12392 (cons "%U" user-full-name)
12393 (cons "%t" (format-time-string
12394 (org-time-stamp-format 'long 'inactive)
12395 org-log-note-effective-time))
12396 (cons "%T" (format-time-string
12397 (org-time-stamp-format 'long nil)
12398 org-log-note-effective-time))
12399 (cons "%d" (format-time-string
12400 (org-time-stamp-format nil 'inactive)
12401 org-log-note-effective-time))
12402 (cons "%D" (format-time-string
12403 (org-time-stamp-format nil nil)
12404 org-log-note-effective-time))
12405 (cons "%s" (if org-log-note-state
12406 (concat "\"" org-log-note-state "\"")
12408 (cons "%S" (if org-log-note-previous-state
12409 (concat "\"" org-log-note-previous-state "\"")
12411 (if lines (setq note (concat note " \\\\")))
12413 (when (or current-prefix-arg org-note-abort)
12414 (when org-log-into-drawer
12415 (org-remove-empty-drawer-at
12416 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
12417 org-log-note-marker))
12420 (with-current-buffer (marker-buffer org-log-note-marker)
12422 (goto-char org-log-note-marker)
12423 (move-marker org-log-note-marker nil)
12425 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
12426 (setq ind (save-excursion
12427 (if (ignore-errors (goto-char (org-in-item-p)))
12428 (let ((struct (org-list-struct)))
12430 (org-list-get-top-point struct) struct))
12431 (skip-chars-backward " \r\t\n")
12433 ((and (org-at-heading-p)
12434 org-adapt-indentation)
12435 (1+ (org-current-level)))
12436 ((org-at-heading-p) 0)
12437 (t (org-get-indentation))))))
12438 (setq bul (org-list-bullet-string "-"))
12439 (org-indent-line-to ind)
12440 (insert bul (pop lines))
12441 (let ((ind-body (+ (length bul) ind)))
12444 (org-indent-line-to ind-body)
12445 (insert (pop lines))))
12446 (message "Note stored")
12447 (org-back-to-heading t)
12448 (org-cycle-hide-drawers 'children)))))
12449 (set-window-configuration org-log-note-window-configuration)
12450 (with-current-buffer (marker-buffer org-log-note-return-to)
12451 (goto-char org-log-note-return-to))
12452 (move-marker org-log-note-return-to nil)
12453 (and org-log-post-message (message "%s" org-log-post-message)))
12455 (defun org-remove-empty-drawer-at (drawer pos)
12456 "Remove an empty drawer DRAWER at position POS.
12457 POS may also be a marker."
12458 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
12464 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
12465 (replace-match ""))))))
12467 (defun org-sparse-tree (&optional arg)
12468 "Create a sparse tree, prompt for the details.
12469 This command can create sparse trees. You first need to select the type
12470 of match used to create the tree:
12472 t Show all TODO entries.
12473 T Show entries with a specific TODO keyword.
12474 m Show entries selected by a tags/property match.
12475 p Enter a property name and its value (both with completion on existing
12476 names/values) and show entries with that property.
12477 r Show entries matching a regular expression (`/' can be used as well)
12478 d Show deadlines due within `org-deadline-warning-days'.
12479 b Show deadlines and scheduled items before a date.
12480 a Show deadlines and scheduled items after a date."
12482 (let (ans kwd value)
12483 (message "Sparse tree: [r]egexp [/]regexp [t]odo [T]odo-kwd [m]atch [p]roperty\n [d]eadlines [b]efore-date [a]fter-date [D]ates range")
12484 (setq ans (read-char-exclusive))
12487 (call-interactively 'org-check-deadlines))
12489 (call-interactively 'org-check-before-date))
12491 (call-interactively 'org-check-after-date))
12493 (call-interactively 'org-check-dates-range))
12495 (org-show-todo-tree nil))
12497 (org-show-todo-tree '(4)))
12498 ((member ans '(?T ?m))
12499 (call-interactively 'org-match-sparse-tree))
12500 ((member ans '(?p ?P))
12501 (setq kwd (org-icompleting-read "Property: "
12502 (mapcar 'list (org-buffer-property-keys))))
12503 (setq value (org-icompleting-read "Value: "
12504 (mapcar 'list (org-property-values kwd))))
12505 (unless (string-match "\\`{.*}\\'" value)
12506 (setq value (concat "\"" value "\"")))
12507 (org-match-sparse-tree arg (concat kwd "=" value)))
12508 ((member ans '(?r ?R ?/))
12509 (call-interactively 'org-occur))
12510 (t (error "No such sparse tree command \"%c\"" ans)))))
12512 (defvar org-occur-highlights nil
12513 "List of overlays used for occur matches.")
12514 (make-variable-buffer-local 'org-occur-highlights)
12515 (defvar org-occur-parameters nil
12516 "Parameters of the active org-occur calls.
12517 This is a list, each call to org-occur pushes as cons cell,
12518 containing the regular expression and the callback, onto the list.
12519 The list can contain several entries if `org-occur' has been called
12520 several time with the KEEP-PREVIOUS argument. Otherwise, this list
12521 will only contain one set of parameters. When the highlights are
12522 removed (for example with `C-c C-c', or with the next edit (depending
12523 on `org-remove-highlights-with-change'), this variable is emptied
12525 (make-variable-buffer-local 'org-occur-parameters)
12527 (defun org-occur (regexp &optional keep-previous callback)
12528 "Make a compact tree which shows all matches of REGEXP.
12529 The tree will show the lines where the regexp matches, and all higher
12530 headlines above the match. It will also show the heading after the match,
12531 to make sure editing the matching entry is easy.
12532 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
12533 call to `org-occur' will be kept, to allow stacking of calls to this
12535 If CALLBACK is non-nil, it is a function which is called to confirm
12536 that the match should indeed be shown."
12537 (interactive "sRegexp: \nP")
12538 (when (equal regexp "")
12539 (error "Regexp cannot be empty"))
12540 (unless keep-previous
12541 (org-remove-occur-highlights nil nil t))
12542 (push (cons regexp callback) org-occur-parameters)
12545 (goto-char (point-min))
12546 (if (or (not keep-previous) ; do not want to keep
12547 (not org-occur-highlights)) ; no previous matches
12550 (while (re-search-forward regexp nil t)
12551 (when (or (not callback)
12552 (save-match-data (funcall callback)))
12553 (setq cnt (1+ cnt))
12554 (when org-highlight-sparse-tree-matches
12555 (org-highlight-new-match (match-beginning 0) (match-end 0)))
12556 (org-show-context 'occur-tree))))
12557 (when org-remove-highlights-with-change
12558 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
12560 (unless org-sparse-tree-open-archived-trees
12561 (org-hide-archived-subtrees (point-min) (point-max)))
12562 (run-hooks 'org-occur-hook)
12563 (if (org-called-interactively-p 'interactive)
12564 (message "%d match(es) for regexp %s" cnt regexp))
12567 (defun org-occur-next-match (&optional n reset)
12568 "Function for `next-error-function' to find sparse tree matches.
12569 N is the number of matches to move, when negative move backwards.
12570 RESET is entirely ignored - this function always goes back to the
12571 starting point when no match is found."
12572 (let* ((limit (if (< n 0) (point-min) (point-max)))
12573 (search-func (if (< n 0)
12574 'previous-single-char-property-change
12575 'next-single-char-property-change))
12580 (while (setq p1 (funcall search-func (point) 'org-type))
12581 (when (equal p1 limit)
12583 (error "No more matches"))
12584 (when (equal (get-char-property p1 'org-type) 'org-occur)
12588 (throw 'exit (point))))
12591 (error "No more matches"))))
12593 (defun org-show-context (&optional key)
12594 "Make sure point and context are visible.
12595 How much context is shown depends upon the variables
12596 `org-show-hierarchy-above', `org-show-following-heading',
12597 `org-show-entry-below' and `org-show-siblings'."
12598 (let ((heading-p (org-at-heading-p t))
12599 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
12600 (following-p (org-get-alist-option org-show-following-heading key))
12601 (entry-p (org-get-alist-option org-show-entry-below key))
12602 (siblings-p (org-get-alist-option org-show-siblings key)))
12604 ;; Show heading or entry text
12605 (if (and heading-p (not entry-p))
12606 (org-flag-heading nil) ; only show the heading
12607 (and (or entry-p (outline-invisible-p) (org-invisible-p2))
12608 (org-show-hidden-entry))) ; show entire entry
12610 ;; Show next sibling, or heading below text
12612 (and (if heading-p (org-goto-sibling) (outline-next-heading))
12613 (org-flag-heading nil))))
12614 (when siblings-p (org-show-siblings))
12616 ;; show all higher headings, possibly with siblings
12618 (while (and (condition-case nil
12619 (progn (org-up-heading-all 1) t)
12622 (org-flag-heading nil)
12623 (when siblings-p (org-show-siblings))))))))
12625 (defvar org-reveal-start-hook nil
12626 "Hook run before revealing a location.")
12628 (defun org-reveal (&optional siblings)
12629 "Show current entry, hierarchy above it, and the following headline.
12630 This can be used to show a consistent set of context around locations
12631 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
12632 not t for the search context.
12634 With optional argument SIBLINGS, on each level of the hierarchy all
12635 siblings are shown. This repairs the tree structure to what it would
12636 look like when opened with hierarchical calls to `org-cycle'.
12637 With double optional argument \\[universal-argument] \\[universal-argument], \
12638 go to the parent and show the
12641 (run-hooks 'org-reveal-start-hook)
12642 (let ((org-show-hierarchy-above t)
12643 (org-show-following-heading t)
12644 (org-show-siblings (if siblings t org-show-siblings)))
12645 (org-show-context nil))
12646 (when (equal siblings '(16))
12648 (when (org-up-heading-safe)
12650 (run-hook-with-args 'org-cycle-hook 'subtree)))))
12652 (defun org-highlight-new-match (beg end)
12653 "Highlight from BEG to END and mark the highlight is an occur headline."
12654 (let ((ov (make-overlay beg end)))
12655 (overlay-put ov 'face 'secondary-selection)
12656 (overlay-put ov 'org-type 'org-occur)
12657 (push ov org-occur-highlights)))
12659 (defun org-remove-occur-highlights (&optional beg end noremove)
12660 "Remove the occur highlights from the buffer.
12661 BEG and END are ignored. If NOREMOVE is nil, remove this function
12662 from the `before-change-functions' in the current buffer."
12664 (unless org-inhibit-highlight-removal
12665 (mapc 'delete-overlay org-occur-highlights)
12666 (setq org-occur-highlights nil)
12667 (setq org-occur-parameters nil)
12669 (remove-hook 'before-change-functions
12670 'org-remove-occur-highlights 'local))))
12674 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
12675 "Regular expression matching the priority indicator.")
12677 (defvar org-remove-priority-next-time nil)
12679 (defun org-priority-up ()
12680 "Increase the priority of the current item."
12682 (org-priority 'up))
12684 (defun org-priority-down ()
12685 "Decrease the priority of the current item."
12687 (org-priority 'down))
12689 (defun org-priority (&optional action)
12690 "Change the priority of an item by ARG.
12691 ACTION can be `set', `up', `down', or a character."
12693 (unless org-enable-priority-commands
12694 (error "Priority commands are disabled"))
12695 (setq action (or action 'set))
12696 (let (current new news have remove)
12698 (org-back-to-heading t)
12699 (if (looking-at org-priority-regexp)
12700 (setq current (string-to-char (match-string 2))
12703 ((eq action 'remove)
12704 (setq remove t new ?\ ))
12705 ((or (eq action 'set)
12706 (if (featurep 'xemacs) (characterp action) (integerp action)))
12707 (if (not (eq action 'set))
12709 (message "Priority %c-%c, SPC to remove: "
12710 org-highest-priority org-lowest-priority)
12712 (setq new (read-char-exclusive))))
12713 (if (and (= (upcase org-highest-priority) org-highest-priority)
12714 (= (upcase org-lowest-priority) org-lowest-priority))
12715 (setq new (upcase new)))
12716 (cond ((equal new ?\ ) (setq remove t))
12717 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
12718 (error "Priority must be between `%c' and `%c'"
12719 org-highest-priority org-lowest-priority))))
12722 (1- current) ; normal cycling
12723 ;; last priority was empty
12724 (if (eq last-command this-command)
12725 org-lowest-priority ; wrap around empty to lowest
12727 (if org-priority-start-cycle-with-default
12728 org-default-priority
12729 (1- org-default-priority))))))
12732 (1+ current) ; normal cycling
12733 ;; last priority was empty
12734 (if (eq last-command this-command)
12735 org-highest-priority ; wrap around empty to highest
12737 (if org-priority-start-cycle-with-default
12738 org-default-priority
12739 (1+ org-default-priority))))))
12740 (t (error "Invalid action")))
12741 (if (or (< (upcase new) org-highest-priority)
12742 (> (upcase new) org-lowest-priority))
12743 (if (and (memq action '(up down))
12744 (not have) (not (eq last-command this-command)))
12745 ;; `new' is from default priority
12747 "The default can not be set, see `org-default-priority' why")
12748 ;; normal cycling: `new' is beyond highest/lowest priority
12749 ;; and is wrapped around to the empty priority
12751 (setq news (format "%c" new))
12754 (replace-match "" t t nil 1)
12755 (replace-match news t t nil 2))
12757 (error "No priority cookie found in line")
12758 (let ((case-fold-search nil))
12759 (looking-at org-todo-line-regexp))
12762 (goto-char (match-end 2))
12763 (insert " [#" news "]"))
12764 (goto-char (match-beginning 3))
12765 (insert "[#" news "] "))))
12766 (org-preserve-lc (org-set-tags nil 'align)))
12768 (message "Priority removed")
12769 (message "Priority of current item set to %s" news))))
12771 (defun org-get-priority (s)
12772 "Find priority cookie and return priority."
12773 (if (functionp org-get-priority-function)
12774 (funcall org-get-priority-function)
12776 (if (not (string-match org-priority-regexp s))
12777 (* 1000 (- org-lowest-priority org-default-priority))
12778 (* 1000 (- org-lowest-priority
12779 (string-to-char (match-string 2 s))))))))
12783 (defvar org-agenda-archives-mode)
12784 (defvar org-map-continue-from nil
12785 "Position from where mapping should continue.
12786 Can be set by the action argument to `org-scan-tags' and `org-map-entries'.")
12788 (defvar org-scanner-tags nil
12789 "The current tag list while the tags scanner is running.")
12790 (defvar org-trust-scanner-tags nil
12791 "Should `org-get-tags-at' use the tags for the scanner.
12792 This is for internal dynamical scoping only.
12793 When this is non-nil, the function `org-get-tags-at' will return the value
12794 of `org-scanner-tags' instead of building the list by itself. This
12795 can lead to large speed-ups when the tags scanner is used in a file with
12796 many entries, and when the list of tags is retrieved, for example to
12797 obtain a list of properties. Building the tags list for each entry in such
12798 a file becomes an N^2 operation - but with this variable set, it scales
12801 (defun org-scan-tags (action matcher &optional todo-only start-level)
12802 "Scan headline tags with inheritance and produce output ACTION.
12804 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
12805 or `agenda' to produce an entry list for an agenda view. It can also be
12806 a Lisp form or a function that should be called at each matched headline, in
12807 this case the return value is a list of all return values from these calls.
12809 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
12810 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
12811 only lines with a TODO keyword are included in the output.
12813 START-LEVEL can be a string with asterisks, reducing the scope to
12814 headlines matching this string."
12815 (require 'org-agenda)
12816 (let* ((re (concat "^"
12818 ;; Get the correct level to match
12819 (concat "\\*\\{" (number-to-string start-level) "\\} ")
12820 org-outline-regexp)
12822 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
12824 "\\>\\)\\)? *\\(.*?\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*$")))
12825 (props (list 'face 'default
12826 'done-face 'org-agenda-done
12827 'undone-face 'default
12828 'mouse-face 'highlight
12829 'org-not-done-regexp org-not-done-regexp
12830 'org-todo-regexp org-todo-regexp
12831 'org-complex-heading-regexp org-complex-heading-regexp
12833 (format "mouse-2 or RET jump to org file %s"
12834 (abbreviate-file-name
12835 (or (buffer-file-name (buffer-base-buffer))
12836 (buffer-name (buffer-base-buffer)))))))
12837 (case-fold-search nil)
12838 (org-map-continue-from nil)
12840 (tags-alist (list (cons 0 org-file-tags)))
12841 (llast 0) rtn rtn1 level category i txt
12842 todo marker entry priority)
12843 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
12844 (setq action (list 'lambda nil action)))
12846 (goto-char (point-min))
12847 (when (eq action 'sparse-tree)
12849 (org-remove-occur-highlights))
12850 (while (re-search-forward re nil t)
12851 (setq org-map-continue-from nil)
12853 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
12854 tags (if (match-end 4) (org-match-string-no-properties 4)))
12855 (goto-char (setq lspos (match-beginning 0)))
12856 (setq level (org-reduced-level (funcall outline-level))
12857 category (org-get-category))
12858 (setq i llast llast level)
12859 ;; remove tag lists from same and sublevels
12860 (while (>= i level)
12861 (when (setq entry (assoc i tags-alist))
12862 (setq tags-alist (delete entry tags-alist)))
12864 ;; add the next tags
12866 (setq tags (org-split-string tags ":")
12868 (cons (cons level tags) tags-alist)))
12869 ;; compile tags for current headline
12871 (if org-use-tag-inheritance
12872 (apply 'append (mapcar 'cdr (reverse tags-alist)))
12874 org-scanner-tags tags-list)
12875 (when org-use-tag-inheritance
12876 (setcdr (car tags-alist)
12877 (mapcar (lambda (x)
12878 (setq x (copy-sequence x))
12879 (org-add-prop-inherited x))
12880 (cdar tags-alist))))
12881 (when (and tags org-use-tag-inheritance
12882 (or (not (eq t org-use-tag-inheritance))
12883 org-tags-exclude-from-inheritance))
12884 ;; selective inheritance, remove uninherited ones
12885 (setcdr (car tags-alist)
12886 (org-remove-uninherited-tags (cdar tags-alist))))
12889 ;; eval matcher only when the todo condition is OK
12890 (and (or (not todo-only) (member todo org-not-done-keywords))
12891 (let ((case-fold-search t)) (eval matcher)))
12893 ;; Call the skipper, but return t if it does not skip,
12894 ;; so that the `and' form continues evaluating
12896 (unless (eq action 'sparse-tree) (org-agenda-skip))
12899 ;; Check if timestamps are deselecting this entry
12900 (or (not todo-only)
12901 (and (member todo org-not-done-keywords)
12902 (or (not org-agenda-tags-todo-honor-ignore-options)
12903 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
12905 ;; Extra check for the archive tag
12906 ;; FIXME: Does the skipper already do this????
12908 (not (member org-archive-tag tags-list))
12909 ;; we have an archive tag, should we use this anyway?
12910 (or (not org-agenda-skip-archived-trees)
12911 (and (eq action 'agenda) org-agenda-archives-mode))))
12913 ;; select this headline
12916 ((eq action 'sparse-tree)
12917 (and org-highlight-sparse-tree-matches
12918 (org-get-heading) (match-end 0)
12919 (org-highlight-new-match
12920 (match-beginning 1) (match-end 1)))
12921 (org-show-context 'tags-tree))
12922 ((eq action 'agenda)
12923 (setq txt (org-agenda-format-item
12926 (if (eq org-tags-match-list-sublevels 'indented)
12927 (make-string (1- level) ?.) "")
12931 priority (org-get-priority txt))
12933 (setq marker (org-agenda-new-marker))
12934 (org-add-props txt props
12935 'org-marker marker 'org-hd-marker marker 'org-category category
12937 'priority priority 'type "tagsmatch")
12939 ((functionp action)
12940 (setq org-map-continue-from nil)
12942 (setq rtn1 (funcall action))
12944 (t (error "Invalid action")))
12946 ;; if we are to skip sublevels, jump to end of subtree
12947 (unless org-tags-match-list-sublevels
12948 (org-end-of-subtree t)
12949 (backward-char 1))))
12950 ;; Get the correct position from where to continue
12951 (if org-map-continue-from
12952 (goto-char org-map-continue-from)
12953 (and (= (point) lspos) (end-of-line 1)))))
12954 (when (and (eq action 'sparse-tree)
12955 (not org-sparse-tree-open-archived-trees))
12956 (org-hide-archived-subtrees (point-min) (point-max)))
12959 (defun org-remove-uninherited-tags (tags)
12960 "Remove all tags that are not inherited from the list TAGS."
12962 ((eq org-use-tag-inheritance t)
12963 (if org-tags-exclude-from-inheritance
12964 (org-delete-all org-tags-exclude-from-inheritance tags)
12966 ((not org-use-tag-inheritance) nil)
12967 ((stringp org-use-tag-inheritance)
12970 (if (and (string-match org-use-tag-inheritance x)
12971 (not (member x org-tags-exclude-from-inheritance)))
12974 ((listp org-use-tag-inheritance)
12977 (if (member x org-use-tag-inheritance) x nil))
12980 (defvar todo-only) ;; dynamically scoped
12982 (defun org-match-sparse-tree (&optional todo-only match)
12983 "Create a sparse tree according to tags string MATCH.
12984 MATCH can contain positive and negative selection of tags, like
12985 \"+WORK+URGENT-WITHBOSS\".
12986 If optional argument TODO-ONLY is non-nil, only select lines that are
12989 (org-prepare-agenda-buffers (list (current-buffer)))
12990 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
12992 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
12994 (defvar org-cached-props nil)
12995 (defun org-cached-entry-get (pom property)
12996 (if (or (eq t org-use-property-inheritance)
12997 (and (stringp org-use-property-inheritance)
12998 (string-match org-use-property-inheritance property))
12999 (and (listp org-use-property-inheritance)
13000 (member property org-use-property-inheritance)))
13001 ;; Caching is not possible, check it directly
13002 (org-entry-get pom property 'inherit)
13003 ;; Get all properties, so that we can do complicated checks easily
13004 (cdr (assoc property (or org-cached-props
13005 (setq org-cached-props
13006 (org-entry-properties pom)))))))
13008 (defun org-global-tags-completion-table (&optional files)
13009 "Return the list of all tags in all agenda buffer/files.
13010 Optional FILES argument is a list of files to which can be used
13011 instead of the agenda files."
13018 (set-buffer (find-file-noselect file))
13019 (append (org-get-buffer-tags)
13020 (mapcar (lambda (x) (if (stringp (car-safe x))
13021 (list (car-safe x)) nil))
13023 (if (and files (car files))
13025 (org-agenda-files))))))))
13027 (defun org-make-tags-matcher (match)
13028 "Create the TAGS/TODO matcher form for the selection string MATCH."
13029 ;; todo-only is scoped dynamically into this function, and the function
13030 ;; may change it if the matcher asks for it.
13032 ;; Get a new match request, with completion
13033 (let ((org-last-tags-completion-table
13034 (org-global-tags-completion-table)))
13035 (setq match (org-completing-read-no-i
13036 "Match: " 'org-tags-completion-function nil nil nil
13037 'org-tags-history))))
13039 ;; Parse the string and create a lisp form
13040 (let ((match0 match)
13041 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@#%]+\\)"))
13043 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
13044 orterms term orlist re-p str-p level-p level-op time-p
13045 prop-p pn pv po gv rest)
13046 (if (string-match "/+" match)
13047 ;; match contains also a todo-matching request
13049 (setq tagsmatch (substring match 0 (match-beginning 0))
13050 todomatch (substring match (match-end 0)))
13051 (if (string-match "^!" todomatch)
13052 (setq todo-only t todomatch (substring todomatch 1)))
13053 (if (string-match "^\\s-*$" todomatch)
13054 (setq todomatch nil)))
13055 ;; only matching tags
13056 (setq tagsmatch match todomatch nil))
13058 ;; Make the tags matcher
13059 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
13060 (setq tagsmatcher t)
13061 (setq orterms (org-split-string tagsmatch "|") orlist nil)
13062 (while (setq term (pop orterms))
13063 (while (and (equal (substring term -1) "\\") orterms)
13064 (setq term (concat term "|" (pop orterms)))) ; repair bad split
13065 (while (string-match re term)
13066 (setq rest (substring term (match-end 0))
13067 minus (and (match-end 1)
13068 (equal (match-string 1 term) "-"))
13069 tag (save-match-data (replace-regexp-in-string
13071 (match-string 2 term)))
13072 re-p (equal (string-to-char tag) ?{)
13073 level-p (match-end 4)
13074 prop-p (match-end 5)
13076 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
13078 (setq level-op (org-op-to-function (match-string 3 term)))
13079 `(,level-op level ,(string-to-number
13080 (match-string 4 term))))
13082 (setq pn (match-string 5 term)
13083 po (match-string 6 term)
13084 pv (match-string 7 term)
13085 re-p (equal (string-to-char pv) ?{)
13086 str-p (equal (string-to-char pv) ?\")
13087 time-p (save-match-data
13088 (string-match "^\"[[<].*[]>]\"$" pv))
13089 pv (if (or re-p str-p) (substring pv 1 -1) pv))
13090 (if time-p (setq pv (org-matcher-time pv)))
13091 (setq po (org-op-to-function po (if time-p 'time str-p)))
13093 ((equal pn "CATEGORY")
13094 (setq gv '(get-text-property (point) 'org-category)))
13098 (setq gv `(org-cached-entry-get nil ,pn))))
13101 `(not (string-match ,pv (or ,gv "")))
13102 `(string-match ,pv (or ,gv "")))
13104 `(,po (or ,gv "") ,pv)
13105 `(,po (string-to-number (or ,gv ""))
13106 ,(string-to-number pv) ))))
13107 (t `(member ,tag tags-list)))
13108 mm (if minus (list 'not mm) mm)
13110 (push mm tagsmatcher))
13111 (push (if (> (length tagsmatcher) 1)
13112 (cons 'and tagsmatcher)
13115 (setq tagsmatcher nil))
13116 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
13118 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
13119 ;; Make the todo matcher
13120 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
13121 (setq todomatcher t)
13122 (setq orterms (org-split-string todomatch "|") orlist nil)
13123 (while (setq term (pop orterms))
13124 (while (string-match re term)
13125 (setq minus (and (match-end 1)
13126 (equal (match-string 1 term) "-"))
13127 kwd (match-string 2 term)
13128 re-p (equal (string-to-char kwd) ?{)
13129 term (substring term (match-end 0))
13131 `(string-match ,(substring kwd 1 -1) todo)
13132 (list 'equal 'todo kwd))
13133 mm (if minus (list 'not mm) mm))
13134 (push mm todomatcher))
13135 (push (if (> (length todomatcher) 1)
13136 (cons 'and todomatcher)
13139 (setq todomatcher nil))
13140 (setq todomatcher (if (> (length orlist) 1)
13141 (cons 'or orlist) (car orlist))))
13143 ;; Return the string and lisp forms of the matcher
13144 (setq matcher (if todomatcher
13145 (list 'and tagsmatcher todomatcher)
13147 (cons match0 matcher)))
13149 (defun org-op-to-function (op &optional stringp)
13150 "Turn an operator into the appropriate function."
13153 ((equal op "<" ) '(< string< org-time<))
13154 ((equal op ">" ) '(> org-string> org-time>))
13155 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
13156 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
13157 ((member op '("=" "==")) '(= string= org-time=))
13158 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
13159 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
13161 (defun org<> (a b) (not (= a b)))
13162 (defun org-string<= (a b) (or (string= a b) (string< a b)))
13163 (defun org-string>= (a b) (not (string< a b)))
13164 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
13165 (defun org-string<> (a b) (not (string= a b)))
13166 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
13167 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
13168 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
13169 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
13170 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
13171 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
13173 "Convert S to a floating point time.
13174 If S is already a number, just return it. If it is a string, parse
13175 it as a time string and apply `float-time' to it. If S is nil, just return 0."
13179 (condition-case nil
13180 (float-time (apply 'encode-time (org-parse-time-string s)))
13184 (defun org-time-today ()
13185 "Time in seconds today at 0:00.
13186 Returns the float number of seconds since the beginning of the
13187 epoch to the beginning of today (00:00)."
13188 (float-time (apply 'encode-time
13189 (append '(0 0 0) (nthcdr 3 (decode-time))))))
13191 (defun org-matcher-time (s)
13192 "Interpret a time comparison value."
13195 ((string= s "<now>") (float-time))
13196 ((string= s "<today>") (org-time-today))
13197 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
13198 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
13199 ((string-match "^<\\([-+][0-9]+\\)\\([dwmy]\\)>$" s)
13200 (+ (org-time-today)
13201 (* (string-to-number (match-string 1 s))
13202 (cdr (assoc (match-string 2 s)
13203 '(("d" . 86400.0) ("w" . 604800.0)
13204 ("m" . 2678400.0) ("y" . 31557600.0)))))))
13207 (defun org-match-any-p (re list)
13208 "Does re match any element of list?"
13209 (setq list (mapcar (lambda (x) (string-match re x)) list))
13212 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
13213 (defvar org-tags-overlay (make-overlay 1 1))
13214 (org-detach-overlay org-tags-overlay)
13216 (defun org-get-local-tags-at (&optional pos)
13217 "Get a list of tags defined in the current headline."
13218 (org-get-tags-at pos 'local))
13220 (defun org-get-local-tags ()
13221 "Get a list of tags defined in the current headline."
13222 (org-get-tags-at nil 'local))
13224 (defun org-get-tags-at (&optional pos local)
13225 "Get a list of all headline tags applicable at POS.
13226 POS defaults to point. If tags are inherited, the list contains
13227 the targets in the same sequence as the headlines appear, i.e.
13228 the tags of the current headline come last.
13229 When LOCAL is non-nil, only return tags from the current headline,
13230 ignore inherited ones."
13232 (if (and org-trust-scanner-tags
13233 (or (not pos) (equal pos (point)))
13236 (let (tags ltags lastpos parent)
13240 (goto-char (or pos (point)))
13243 (condition-case nil
13245 (org-back-to-heading t)
13246 (while (not (equal lastpos (point)))
13247 (setq lastpos (point))
13249 (org-re "[^\r\n]+?:\\([[:alnum:]_@#%:]+\\):[ \t]*$"))
13250 (setq ltags (org-split-string
13251 (org-match-string-no-properties 1) ":"))
13253 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
13256 (org-remove-uninherited-tags ltags)
13259 (or org-use-tag-inheritance (throw 'done t))
13260 (if local (throw 'done t))
13261 (or (org-up-heading-safe) (error nil))
13266 (append (org-remove-uninherited-tags org-file-tags) tags))))))
13268 (defun org-add-prop-inherited (s)
13269 (add-text-properties 0 (length s) '(inherited t) s)
13272 (defun org-toggle-tag (tag &optional onoff)
13273 "Toggle the tag TAG for the current line.
13274 If ONOFF is `on' or `off', don't toggle but set to this state."
13277 (org-back-to-heading t)
13278 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$")
13281 (setq current (match-string 1))
13282 (replace-match ""))
13284 (setq current (nreverse (org-split-string current ":")))
13288 (or (member tag current) (push tag current)))
13290 (or (not (member tag current)) (setq current (delete tag current))))
13291 (t (if (member tag current)
13292 (setq current (delete tag current))
13294 (push tag current))))
13298 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
13299 (org-set-tags nil t))
13300 (delete-horizontal-space))
13301 (run-hooks 'org-after-tags-change-hook))
13304 (defun org-align-tags-here (to-col)
13305 ;; Assumes that this is a headline
13306 (let ((pos (point)) (col (current-column)) ncol tags-l p)
13307 (beginning-of-line 1)
13308 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13309 (< pos (match-beginning 2)))
13311 (setq tags-l (- (match-end 2) (match-beginning 2)))
13312 (goto-char (match-beginning 1))
13314 (delete-region (point) (1+ (match-beginning 2)))
13315 (setq ncol (max (current-column)
13319 (- (abs to-col) tags-l))))
13321 (insert (make-string (- ncol (current-column)) ?\ ))
13322 (setq ncol (current-column))
13323 (when indent-tabs-mode (tabify p (point-at-eol)))
13324 (org-move-to-column (min ncol col) t))
13327 (defun org-set-tags-command (&optional arg just-align)
13328 "Call the set-tags command for the current entry."
13330 (if (or (org-at-heading-p) (and arg (org-before-first-heading-p)))
13331 (org-set-tags arg just-align)
13333 (org-back-to-heading t)
13334 (org-set-tags arg just-align))))
13336 (defun org-set-tags-to (data)
13337 "Set the tags of the current entry to DATA, replacing the current tags.
13338 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
13339 If DATA is nil or the empty string, any tags will be removed."
13340 (interactive "sTags: ")
13344 ((equal data "") "")
13346 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
13349 (concat ":" (mapconcat 'identity data ":") ":"))
13353 (org-back-to-heading t)
13354 (when (looking-at org-complex-heading-regexp)
13357 (goto-char (match-beginning 5))
13359 (delete-region (point) (point-at-eol))
13360 (org-set-tags nil 'align))
13361 (goto-char (point-at-eol))
13363 (org-set-tags nil 'align)))
13364 (beginning-of-line 1)
13365 (if (looking-at ".*?\\([ \t]+\\)$")
13366 (delete-region (match-beginning 1) (match-end 1))))))
13368 (defun org-align-all-tags ()
13369 "Align the tags i all headings."
13372 (or (ignore-errors (org-back-to-heading t))
13373 (outline-next-heading))
13374 (if (org-at-heading-p)
13376 (message "No headings"))))
13378 (defvar org-indent-indentation-per-level)
13379 (defun org-set-tags (&optional arg just-align)
13380 "Set the tags for the current headline.
13381 With prefix ARG, realign all tags in headings in the current buffer."
13383 (let* ((re org-outline-regexp-bol)
13384 (current (unless arg (org-get-tags-string)))
13385 (col (current-column))
13386 (org-setting-tags t)
13387 table current-tags inherited-tags ; computed below when needed
13388 tags p0 c0 c1 rpl di tc level)
13391 (goto-char (point-min))
13392 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
13393 (while (re-search-forward re nil t)
13394 (org-set-tags nil t)
13396 (message "All tags realigned to column %d" org-tags-column))
13398 (setq tags current)
13399 ;; Get a new set of tags from the user
13401 (setq table (append org-tag-persistent-alist
13402 (or org-tag-alist (org-get-buffer-tags))
13404 org-complete-tags-always-offer-all-agenda-tags
13405 (org-global-tags-completion-table
13406 (org-agenda-files))))
13407 org-last-tags-completion-table table
13408 current-tags (org-split-string current ":")
13409 inherited-tags (nreverse
13410 (nthcdr (length current-tags)
13411 (nreverse (org-get-tags-at))))
13413 (if (or (eq t org-use-fast-tag-selection)
13414 (and org-use-fast-tag-selection
13415 (delq nil (mapcar 'cdr table))))
13416 (org-fast-tag-selection
13417 current-tags inherited-tags table
13418 (if org-fast-tag-selection-include-todo
13419 org-todo-key-alist))
13420 (let ((org-add-colon-after-tag-completion t))
13422 (org-icompleting-read "Tags: "
13423 'org-tags-completion-function
13424 nil nil current 'org-tags-history))))))
13425 (while (string-match "[-+&]+" tags)
13426 ;; No boolean logic, just a list
13427 (setq tags (replace-match ":" t t tags))))
13429 (setq tags (replace-regexp-in-string "[,]" ":" tags))
13431 (if org-tags-sort-function
13432 (setq tags (mapconcat 'identity
13433 (sort (org-split-string
13434 tags (org-re "[^[:alnum:]_@#%]+"))
13435 org-tags-sort-function) ":")))
13437 (if (string-match "\\`[\t ]*\\'" tags)
13439 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
13440 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
13442 ;; Insert new tags at the correct column
13443 (beginning-of-line 1)
13444 (setq level (or (and (looking-at org-outline-regexp)
13445 (- (match-end 0) (point) 1))
13448 ((and (equal current "") (equal tags "")))
13449 ((re-search-forward
13450 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
13452 (if (equal tags "")
13454 (goto-char (match-beginning 0))
13455 (setq c0 (current-column)
13456 ;; compute offset for the case of org-indent-mode active
13457 di (if org-indent-mode
13458 (* (1- org-indent-indentation-per-level) (1- level))
13460 p0 (if (equal (char-before) ?*) (1+ (point)) (point))
13461 tc (+ org-tags-column (if (> org-tags-column 0) (- di) di))
13462 c1 (max (1+ c0) (if (> tc 0) tc (- (- tc) (length tags))))
13463 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
13464 (replace-match rpl t t)
13465 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
13467 (t (error "Tags alignment failed")))
13468 (org-move-to-column col)
13470 (run-hooks 'org-after-tags-change-hook)))))
13472 (defun org-change-tag-in-region (beg end tag off)
13473 "Add or remove TAG for each entry in the region.
13474 This works in the agenda, and also in an org-mode buffer."
13476 (list (region-beginning) (region-end)
13477 (let ((org-last-tags-completion-table
13478 (if (eq major-mode 'org-mode)
13479 (org-get-buffer-tags)
13480 (org-global-tags-completion-table))))
13481 (org-icompleting-read
13482 "Tag: " 'org-tags-completion-function nil nil nil
13483 'org-tags-history))
13485 (message "[s]et or
[r]emove? ")
13486 (equal (read-char-exclusive) ?r))))
13487 (if (fboundp 'deactivate-mark) (deactivate-mark))
13488 (let ((agendap (equal major-mode 'org-agenda-mode))
13489 l1 l2 m buf pos newhead (cnt 0))
13491 (setq l2 (1- (org-current-line)))
13493 (setq l1 (org-current-line))
13494 (loop for l from l1 to l2 do
13496 (setq m (get-text-property (point) 'org-hd-marker))
13497 (when (or (and (eq major-mode 'org-mode) (org-at-heading-p))
13499 (setq buf (if agendap (marker-buffer m) (current-buffer))
13500 pos (if agendap m (point)))
13501 (with-current-buffer buf
13505 (setq cnt (1+ cnt))
13506 (org-toggle-tag tag (if off 'off 'on))
13507 (setq newhead (org-get-heading)))))
13508 (and agendap (org-agenda-change-all-lines newhead m))))
13509 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
13511 (defun org-tags-completion-function (string predicate &optional flag)
13512 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
13513 (confirm (lambda (x) (stringp (car x)))))
13514 (if (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
13515 (setq s1 (match-string 1 string)
13516 s2 (match-string 2 string))
13517 (setq s1 "" s2 string))
13521 (setq rtn (try-completion s2 ctable confirm))
13524 (concat s1 s2 (substring rtn (length s2))
13525 (if (and org-add-colon-after-tag-completion
13526 (assoc rtn ctable))
13531 (all-completions s2 ctable confirm)
13535 (assoc s2 ctable)))
13538 (defun org-fast-tag-insert (kwd tags face &optional end)
13539 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
13540 (insert (format "%-12s" (concat kwd ":"))
13541 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
13544 (defun org-fast-tag-show-exit (flag)
13547 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
13548 (replace-match ""))
13551 (org-move-to-column (- (window-width) 19) t)
13552 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
13554 (defun org-set-current-tags-overlay (current prefix)
13555 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
13556 (if (featurep 'xemacs)
13557 (org-overlay-display org-tags-overlay (concat prefix s)
13558 'secondary-selection)
13559 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
13560 (org-overlay-display org-tags-overlay (concat prefix s)))))
13562 (defvar org-last-tag-selection-key nil)
13563 (defun org-fast-tag-selection (current inherited table &optional todo-table)
13564 "Fast tag selection with single keys.
13565 CURRENT is the current list of tags in the headline, INHERITED is the
13566 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
13567 possibly with grouping information. TODO-TABLE is a similar table with
13568 TODO keywords, should these have keys assigned to them.
13569 If the keys are nil, a-z are automatically assigned.
13570 Returns the new tags string, or nil to not change the current settings."
13571 (let* ((fulltable (append table todo-table))
13572 (maxlen (apply 'max (mapcar
13574 (if (stringp (car x)) (string-width (car x)) 0))
13576 (buf (current-buffer))
13577 (expert (eq org-fast-tag-selection-single-key 'expert))
13579 (fwidth (+ maxlen 3 1 3))
13580 (ncol (/ (- (window-width) 4) fwidth))
13583 tg cnt e c char c1 c2 ntable tbl rtn
13584 ov-start ov-end ov-prefix
13585 (exit-after-next org-fast-tag-selection-single-key)
13586 (done-keywords org-done-keywords)
13589 (beginning-of-line 1)
13591 (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13592 (setq ov-start (match-beginning 1)
13593 ov-end (match-end 1)
13595 (setq ov-start (1- (point-at-eol))
13596 ov-end (1+ ov-start))
13597 (skip-chars-forward "^\n\r")
13600 (buffer-substring (1- (point)) (point))
13601 (if (> (current-column) org-tags-column)
13603 (make-string (- org-tags-column (current-column)) ?\ ))))))
13604 (move-overlay org-tags-overlay ov-start ov-end)
13605 (save-window-excursion
13607 (set-buffer (get-buffer-create " *Org tags*"))
13608 (delete-other-windows)
13609 (split-window-vertically)
13610 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
13612 (org-set-local 'org-done-keywords done-keywords)
13613 (org-fast-tag-insert "Inherited" inherited i-face "\n")
13614 (org-fast-tag-insert "Current" current c-face "\n\n")
13615 (org-fast-tag-show-exit exit-after-next)
13616 (org-set-current-tags-overlay current ov-prefix)
13617 (setq tbl fulltable char ?a cnt 0)
13618 (while (setq e (pop tbl))
13620 ((equal (car e) :startgroup)
13621 (push '() groups) (setq ingroup t)
13622 (when (not (= cnt 0))
13625 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
13626 ((equal (car e) :endgroup)
13627 (setq ingroup nil cnt 0)
13628 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
13629 ((equal e '(:newline))
13630 (when (not (= cnt 0))
13634 (while (equal (car tbl) '(:newline))
13636 (setq tbl (cdr tbl)))))
13638 (setq tg (copy-sequence (car e)) c2 nil)
13641 ;; automatically assign a character.
13642 (setq c1 (string-to-char
13643 (downcase (substring
13644 tg (if (= (string-to-char tg) ?@) 1 0)))))
13645 (if (or (rassoc c1 ntable) (rassoc c1 table))
13646 (while (or (rassoc char ntable) (rassoc char table))
13647 (setq char (1+ char)))
13649 (setq c (or c2 char)))
13650 (if ingroup (push tg (car groups)))
13651 (setq tg (org-add-props tg nil 'face
13653 ((not (assoc tg table))
13654 (org-get-todo-face tg))
13655 ((member tg current) c-face)
13656 ((member tg inherited) i-face)
13658 (if (and (= cnt 0) (not ingroup)) (insert " "))
13659 (insert "[" c "] " tg (make-string
13660 (- fwidth 4 (length tg)) ?\ ))
13661 (push (cons tg c) ntable)
13662 (when (= (setq cnt (1+ cnt)) ncol)
13664 (if ingroup (insert " "))
13666 (setq ntable (nreverse ntable))
13668 (goto-char (point-min))
13669 (if (not expert) (org-fit-window-to-buffer))
13673 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
13674 (if (not groups) "no " "")
13675 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
13676 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
13677 (setq org-last-tag-selection-key c)
13679 ((= c ?\r) (throw 'exit t))
13681 (setq groups (not groups))
13682 (goto-char (point-min))
13683 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
13686 (org-fast-tag-show-exit
13687 (setq exit-after-next (not exit-after-next)))
13689 (delete-other-windows)
13690 (set-window-buffer (split-window-vertically) " *Org tags*")
13691 (org-switch-to-buffer-other-window " *Org tags*")
13692 (org-fit-window-to-buffer)))
13694 (and (= c ?q) (not (rassoc c ntable))))
13695 (org-detach-overlay org-tags-overlay)
13696 (setq quit-flag t))
13699 (if exit-after-next (setq exit-after-next 'now)))
13701 (condition-case nil
13702 (setq tg (org-icompleting-read
13705 (with-current-buffer buf
13706 (org-get-buffer-tags)))))
13707 (quit (setq tg "")))
13708 (when (string-match "\\S-" tg)
13709 (add-to-list 'buffer-tags (list tg))
13710 (if (member tg current)
13711 (setq current (delete tg current))
13712 (push tg current)))
13713 (if exit-after-next (setq exit-after-next 'now)))
13714 ((setq e (rassoc c todo-table) tg (car e))
13715 (with-current-buffer buf
13716 (save-excursion (org-todo tg)))
13717 (if exit-after-next (setq exit-after-next 'now)))
13718 ((setq e (rassoc c ntable) tg (car e))
13719 (if (member tg current)
13720 (setq current (delete tg current))
13721 (loop for g in groups do
13724 (setq current (delete x current)))
13727 (if exit-after-next (setq exit-after-next 'now))))
13729 ;; Create a sorted list
13733 (assoc b (cdr (memq (assoc a ntable) ntable))))))
13734 (if (eq exit-after-next 'now) (throw 'exit t))
13735 (goto-char (point-min))
13736 (beginning-of-line 2)
13737 (delete-region (point) (point-at-eol))
13738 (org-fast-tag-insert "Current" current c-face)
13739 (org-set-current-tags-overlay current ov-prefix)
13740 (while (re-search-forward
13741 (org-re "\\[.\\] \\([[:alnum:]_@#%]+\\)") nil t)
13742 (setq tg (match-string 1))
13743 (add-text-properties
13744 (match-beginning 1) (match-end 1)
13747 ((member tg current) c-face)
13748 ((member tg inherited) i-face)
13749 (t (get-text-property (match-beginning 1) 'face))))))
13750 (goto-char (point-min)))))
13751 (org-detach-overlay org-tags-overlay)
13753 (mapconcat 'identity current ":")
13756 (defun org-get-tags-string ()
13757 "Get the TAGS string in the current headline."
13758 (unless (org-at-heading-p t)
13759 (error "Not on a heading"))
13761 (beginning-of-line 1)
13762 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13763 (org-match-string-no-properties 1)
13766 (defun org-get-tags ()
13767 "Get the list of tags specified in the current headline."
13768 (org-split-string (org-get-tags-string) ":"))
13770 (defun org-get-buffer-tags ()
13771 "Get a table of all tags used in the buffer, for completion."
13774 (goto-char (point-min))
13775 (while (re-search-forward
13776 (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t\r\n]") nil t)
13777 (when (equal (char-after (point-at-bol 0)) ?*)
13778 (mapc (lambda (x) (add-to-list 'tags x))
13779 (org-split-string (org-match-string-no-properties 1) ":")))))
13780 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
13781 (mapcar 'list tags)))
13783 ;;;; The mapping API
13786 (defun org-map-entries (func &optional match scope &rest skip)
13787 "Call FUNC at each headline selected by MATCH in SCOPE.
13789 FUNC is a function or a lisp form. The function will be called without
13790 arguments, with the cursor positioned at the beginning of the headline.
13791 The return values of all calls to the function will be collected and
13792 returned as a list.
13794 The call to FUNC will be wrapped into a save-excursion form, so FUNC
13795 does not need to preserve point. After evaluation, the cursor will be
13796 moved to the end of the line (presumably of the headline of the
13797 processed entry) and search continues from there. Under some
13798 circumstances, this may not produce the wanted results. For example,
13799 if you have removed (e.g. archived) the current (sub)tree it could
13800 mean that the next entry will be skipped entirely. In such cases, you
13801 can specify the position from where search should continue by making
13802 FUNC set the variable `org-map-continue-from' to the desired buffer
13805 MATCH is a tags/property/todo match as it is used in the agenda tags view.
13806 Only headlines that are matched by this query will be considered during
13807 the iteration. When MATCH is nil or t, all headlines will be
13808 visited by the iteration.
13810 SCOPE determines the scope of this command. It can be any of:
13812 nil The current buffer, respecting the restriction if any
13813 tree The subtree started with the entry at point
13814 region The entries within the active region, if any
13816 The entries within the active region, but only those at
13817 the same level than the first one.
13818 file The current buffer, without restriction
13820 The current buffer, and any archives associated with it
13821 agenda All agenda files
13822 agenda-with-archives
13823 All agenda files with any archive files associated with them
13825 If this is a list, all files in the list will be scanned
13827 The remaining args are treated as settings for the skipping facilities of
13828 the scanner. The following items can be given here:
13830 archive skip trees with the archive tag.
13831 comment skip trees with the COMMENT keyword
13832 function or Emacs Lisp form:
13833 will be used as value for `org-agenda-skip-function', so whenever
13834 the function returns t, FUNC will not be called for that
13835 entry and search will continue from the point where the
13836 function leaves it.
13838 If your function needs to retrieve the tags including inherited tags
13839 at the *current* entry, you can use the value of the variable
13840 `org-scanner-tags' which will be much faster than getting the value
13841 with `org-get-tags-at'. If your function gets properties with
13842 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
13843 to t around the call to `org-entry-properties' to get the same speedup.
13844 Note that if your function moves around to retrieve tags and properties at
13845 a *different* entry, you cannot use these techniques."
13846 (unless (and (or (eq scope 'region) (eq scope 'region-start-level))
13847 (not (org-region-active-p)))
13848 (let* ((org-agenda-archives-mode nil) ; just to make sure
13849 (org-agenda-skip-archived-trees (memq 'archive skip))
13850 (org-agenda-skip-comment-trees (memq 'comment skip))
13851 (org-agenda-skip-function
13852 (car (org-delete-all '(comment archive) skip)))
13853 (org-tags-match-list-sublevels t)
13854 (start-level (eq scope 'region-start-level))
13856 org-todo-keywords-for-agenda
13857 org-done-keywords-for-agenda
13858 org-todo-keyword-alist-for-agenda
13859 org-drawers-for-agenda
13860 org-tag-alist-for-agenda)
13863 ((eq match t) (setq matcher t))
13864 ((eq match nil) (setq matcher t))
13865 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
13869 (cond ((eq scope 'tree)
13870 (org-back-to-heading t)
13871 (org-narrow-to-subtree)
13873 ((and (or (eq scope 'region) (eq scope 'region-start-level))
13874 (org-region-active-p))
13875 ;; If needed, set start-level to a string like "2"
13878 (goto-char (region-beginning))
13879 (unless (org-at-heading-p) (outline-next-heading))
13880 (setq start-level (org-current-level))))
13881 (narrow-to-region (region-beginning)
13883 (goto-char (region-end))
13884 (unless (and (bolp) (org-at-heading-p))
13885 (outline-next-heading))
13891 (org-prepare-agenda-buffers
13892 (list (buffer-file-name (current-buffer))))
13893 (setq res (org-scan-tags func matcher nil start-level)))
13894 ;; Get the right scope
13896 ((and scope (listp scope) (symbolp (car scope)))
13897 (setq scope (eval scope)))
13898 ((eq scope 'agenda)
13899 (setq scope (org-agenda-files t)))
13900 ((eq scope 'agenda-with-archives)
13901 (setq scope (org-agenda-files t))
13902 (setq scope (org-add-archive-files scope)))
13904 (setq scope (list (buffer-file-name))))
13905 ((eq scope 'file-with-archives)
13906 (setq scope (org-add-archive-files (list (buffer-file-name))))))
13907 (org-prepare-agenda-buffers scope)
13908 (while (setq file (pop scope))
13909 (with-current-buffer (org-find-base-buffer-visiting file)
13913 (goto-char (point-min))
13914 (setq res (append res (org-scan-tags func matcher))))))))))
13919 ;;; Setting and retrieving properties
13921 (defconst org-special-properties
13922 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
13923 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED" "FILE" "CLOCKSUM")
13924 "The special properties valid in Org-mode.
13926 These are properties that are not defined in the property drawer,
13927 but in some other way.")
13929 (defconst org-default-properties
13930 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
13931 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
13932 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
13933 "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME"
13934 "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
13935 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
13936 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
13937 "Some properties that are used by Org-mode for various purposes.
13938 Being in this list makes sure that they are offered for completion.")
13940 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
13941 "Regular expression matching the first line of a property drawer.")
13943 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
13944 "Regular expression matching the last line of a property drawer.")
13946 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
13947 "Regular expression matching the first line of a property drawer.")
13949 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
13950 "Regular expression matching the first line of a property drawer.")
13952 (defconst org-property-drawer-re
13953 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
13954 org-property-end-re "\\)\n?")
13955 "Matches an entire property drawer.")
13957 (defconst org-clock-drawer-re
13958 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
13959 org-property-end-re "\\)\n?")
13960 "Matches an entire clock drawer.")
13962 (defsubst org-re-property (property)
13963 "Return a regexp matching PROPERTY.
13964 Match group 1 will be set to the value "
13965 (concat "^[ \t]*:" (regexp-quote property) ":[ \t]*\\(\\S-.*\\)"))
13967 (defun org-property-action ()
13968 "Do an action on properties."
13971 (org-at-property-p)
13972 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
13973 (setq c (read-char-exclusive))
13976 (call-interactively 'org-set-property))
13978 (call-interactively 'org-delete-property))
13980 (call-interactively 'org-delete-property-globally))
13982 (call-interactively 'org-compute-property-at-point))
13983 (t (error "No such property action %c" c)))))
13985 (defun org-set-effort (&optional value)
13986 "Set the effort property of the current entry.
13987 With numerical prefix arg, use the nth allowed value, 0 stands for the 10th
13990 (if (equal value 0) (setq value 10))
13991 (let* ((completion-ignore-case t)
13992 (prop org-effort-property)
13993 (cur (org-entry-get nil prop))
13994 (allowed (org-property-get-allowed-values nil prop 'table))
13995 (existing (mapcar 'list (org-property-values prop)))
13998 ((stringp value) value)
13999 ((and allowed (integerp value))
14000 (or (car (nth (1- value) allowed))
14001 (car (org-last allowed))))
14003 (message "Select 1-9,0, [RET%s]: %s"
14004 (if cur (concat "=" cur) "")
14005 (mapconcat 'car allowed " "))
14006 (setq rpl (read-char-exclusive))
14007 (if (equal rpl ?\r)
14009 (setq rpl (- rpl ?0))
14010 (if (equal rpl 0) (setq rpl 10))
14011 (if (and (> rpl 0) (<= rpl (length allowed)))
14012 (car (nth (1- rpl) allowed))
14013 (org-completing-read "Effort: " allowed nil))))
14015 (let (org-completion-use-ido org-completion-use-iswitchb)
14016 (org-completing-read
14017 (concat "Effort " (if (and cur (string-match "\\S-" cur))
14018 (concat "[" cur "]") "")
14020 existing nil nil "" nil cur))))))
14021 (unless (equal (org-entry-get nil prop) val)
14022 (org-entry-put nil prop val))
14023 (message "%s is now %s" prop val)))
14025 (defun org-at-property-p ()
14026 "Is cursor inside a property drawer?"
14028 (beginning-of-line 1)
14029 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
14030 (save-match-data ;; Used by calling procedures
14032 (range (unless (org-before-first-heading-p)
14033 (org-get-property-block))))
14034 (and range (<= (car range) p) (< p (cdr range))))))))
14036 (defun org-get-property-block (&optional beg end force)
14037 "Return the (beg . end) range of the body of the property drawer.
14038 BEG and END can be beginning and end of subtree, if not given
14039 they will be found.
14040 If the drawer does not exist and FORCE is non-nil, create the drawer."
14043 (let* ((beg (or beg (progn (org-back-to-heading t) (point))))
14044 (end (or end (progn (outline-next-heading) (point)))))
14046 (if (re-search-forward org-property-start-re end t)
14047 (setq beg (1+ (match-end 0)))
14050 (org-insert-property-drawer)
14051 (setq end (progn (outline-next-heading) (point))))
14054 (if (re-search-forward org-property-start-re end t)
14055 (setq beg (1+ (match-end 0)))))
14056 (if (re-search-forward org-property-end-re end t)
14057 (setq end (match-beginning 0))
14058 (or force (throw 'exit nil))
14061 (org-indent-line-function)
14062 (insert ":END:\n"))
14065 (defun org-entry-properties (&optional pom which specific)
14066 "Get all properties of the entry at point-or-marker POM.
14067 This includes the TODO keyword, the tags, time strings for deadline,
14068 scheduled, and clocking, and any additional properties defined in the
14069 entry. The return value is an alist, keys may occur multiple times
14070 if the property key was used several times.
14071 POM may also be nil, in which case the current entry is used.
14072 If WHICH is nil or `all', get all properties. If WHICH is
14073 `special' or `standard', only get that subclass. If WHICH
14074 is a string only get exactly this property. SPECIFIC can be a string, the
14075 specific property we are interested in. Specifying it can speed
14076 things up because then unnecessary parsing is avoided."
14077 (setq which (or which 'all))
14078 (org-with-point-at pom
14079 (let ((clockstr (substring org-clock-string 0 -1))
14080 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
14081 (case-fold-search nil)
14082 beg end range props sum-props key key1 value string clocksum)
14084 (when (condition-case nil
14085 (and (eq major-mode 'org-mode) (org-back-to-heading t))
14088 (setq sum-props (get-text-property (point) 'org-summaries))
14089 (setq clocksum (get-text-property (point) :org-clock-minutes))
14090 (outline-next-heading)
14092 (when (memq which '(all special))
14093 ;; Get the special properties, like TODO and tags
14095 (when (and (or (not specific) (string= specific "TODO"))
14096 (looking-at org-todo-line-regexp) (match-end 2))
14097 (push (cons "TODO" (org-match-string-no-properties 2)) props))
14098 (when (and (or (not specific) (string= specific "PRIORITY"))
14099 (looking-at org-priority-regexp))
14100 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
14101 (when (or (not specific) (string= specific "FILE"))
14102 (push (cons "FILE" buffer-file-name) props))
14103 (when (and (or (not specific) (string= specific "TAGS"))
14104 (setq value (org-get-tags-string))
14105 (string-match "\\S-" value))
14106 (push (cons "TAGS" value) props))
14107 (when (and (or (not specific) (string= specific "ALLTAGS"))
14108 (setq value (org-get-tags-at)))
14109 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
14112 (when (or (not specific) (string= specific "BLOCKED"))
14113 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
14114 (when (or (not specific)
14116 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
14117 "TIMESTAMP" "TIMESTAMP_IA")))
14119 (while (re-search-forward org-maybe-keyword-time-regexp end t)
14120 (setq key (if (match-end 1)
14121 (substring (org-match-string-no-properties 1)
14123 string (if (equal key clockstr)
14127 (match-beginning 3) (goto-char
14129 (substring (org-match-string-no-properties 3)
14131 ;; Get the correct property name from the key. This is
14132 ;; necessary if the user has configured time keywords.
14133 (setq key1 (concat key ":"))
14137 (if (= (char-after (match-beginning 3)) ?\[)
14138 "TIMESTAMP_IA" "TIMESTAMP")))
14139 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
14140 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
14141 ((equal key1 org-closed-string) (setq key "CLOSED"))
14142 ((equal key1 org-clock-string) (setq key "CLOCK")))
14143 (if (and specific (equal key specific) (not (equal key "CLOCK")))
14145 (push (cons key string) props)
14146 ;; no need to search further if match is found
14148 (when (or (equal key "CLOCK") (not (assoc key props)))
14149 (push (cons key string) props))))))
14152 (when (memq which '(all standard))
14153 ;; Get the standard properties, like :PROP: ...
14154 (setq range (org-get-property-block beg end))
14156 (goto-char (car range))
14157 (while (re-search-forward
14158 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
14160 (setq key (org-match-string-no-properties 1)
14161 value (org-trim (or (org-match-string-no-properties 2) "")))
14162 (unless (member key excluded)
14163 (push (cons key (or value "")) props)))))
14165 (push (cons "CLOCKSUM"
14166 (org-columns-number-to-string (/ (float clocksum) 60.)
14169 (unless (assoc "CATEGORY" props)
14170 (push (cons "CATEGORY" (org-get-category)) props))
14171 (append sum-props (nreverse props)))))))
14173 (defun org-entry-get (pom property &optional inherit literal-nil)
14174 "Get value of PROPERTY for entry at point-or-marker POM.
14175 If INHERIT is non-nil and the entry does not have the property,
14176 then also check higher levels of the hierarchy.
14177 If INHERIT is the symbol `selective', use inheritance only if the setting
14178 in `org-use-property-inheritance' selects PROPERTY for inheritance.
14179 If the property is present but empty, the return value is the empty string.
14180 If the property is not present at all, nil is returned.
14182 If LITERAL-NIL is set, return the string value \"nil\" as a string,
14183 do not interpret it as the list atom nil. This is used for inheritance
14184 when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
14185 (org-with-point-at pom
14186 (if (and inherit (if (eq inherit 'selective)
14187 (org-property-inherit-p property)
14189 (org-entry-get-with-inheritance property literal-nil)
14190 (if (member property org-special-properties)
14191 ;; We need a special property. Use `org-entry-properties' to
14192 ;; retrieve it, but specify the wanted property
14193 (cdr (assoc property (org-entry-properties nil 'special property)))
14194 (let ((range (unless (org-before-first-heading-p)
14195 (org-get-property-block)))
14196 (props (list (or (assoc property org-file-properties)
14197 (assoc property org-global-properties)
14198 (assoc property org-global-properties-fixed))))
14201 (when (re-search-forward
14202 (org-re-property key) (cdr range) t)
14204 (org-update-property-plist
14207 (org-match-string-no-properties 1) "")
14209 (when (and range (goto-char (car range)))
14211 (goto-char (car range))
14212 (while (ap (concat property "+")))
14213 (setq val (cdr (assoc property props)))
14214 (when val (if literal-nil val (org-not-nil val))))))))))
14216 (defun org-property-or-variable-value (var &optional inherit)
14217 "Check if there is a property fixing the value of VAR.
14218 If yes, return this value. If not, return the current value of the variable."
14219 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
14220 (if (and prop (stringp prop) (string-match "\\S-" prop))
14222 (symbol-value var))))
14224 (defun org-entry-delete (pom property)
14225 "Delete the property PROPERTY from entry at point-or-marker POM."
14226 (org-with-point-at pom
14227 (if (member property org-special-properties)
14228 nil ; cannot delete these properties.
14229 (let ((range (org-get-property-block)))
14231 (goto-char (car range))
14233 (org-re-property property)
14236 (delete-region (match-beginning 0) (1+ (point-at-eol)))
14240 ;; Multi-values properties are properties that contain multiple values
14241 ;; These values are assumed to be single words, separated by whitespace.
14242 (defun org-entry-add-to-multivalued-property (pom property value)
14243 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
14244 (let* ((old (org-entry-get pom property))
14245 (values (and old (org-split-string old "[ \t]"))))
14246 (setq value (org-entry-protect-space value))
14247 (unless (member value values)
14248 (setq values (cons value values))
14249 (org-entry-put pom property
14250 (mapconcat 'identity values " ")))))
14252 (defun org-entry-remove-from-multivalued-property (pom property value)
14253 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
14254 (let* ((old (org-entry-get pom property))
14255 (values (and old (org-split-string old "[ \t]"))))
14256 (setq value (org-entry-protect-space value))
14257 (when (member value values)
14258 (setq values (delete value values))
14259 (org-entry-put pom property
14260 (mapconcat 'identity values " ")))))
14262 (defun org-entry-member-in-multivalued-property (pom property value)
14263 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
14264 (let* ((old (org-entry-get pom property))
14265 (values (and old (org-split-string old "[ \t]"))))
14266 (setq value (org-entry-protect-space value))
14267 (member value values)))
14269 (defun org-entry-get-multivalued-property (pom property)
14270 "Return a list of values in a multivalued property."
14271 (let* ((value (org-entry-get pom property))
14272 (values (and value (org-split-string value "[ \t]"))))
14273 (mapcar 'org-entry-restore-space values)))
14275 (defun org-entry-put-multivalued-property (pom property &rest values)
14276 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
14277 VALUES should be a list of strings. Spaces will be protected."
14278 (org-entry-put pom property
14279 (mapconcat 'org-entry-protect-space values " "))
14280 (let* ((value (org-entry-get pom property))
14281 (values (and value (org-split-string value "[ \t]"))))
14282 (mapcar 'org-entry-restore-space values)))
14284 (defun org-entry-protect-space (s)
14285 "Protect spaces and newline in string S."
14286 (while (string-match " " s)
14287 (setq s (replace-match "%20" t t s)))
14288 (while (string-match "\n" s)
14289 (setq s (replace-match "%0A" t t s)))
14292 (defun org-entry-restore-space (s)
14293 "Restore spaces and newline in string S."
14294 (while (string-match "%20" s)
14295 (setq s (replace-match " " t t s)))
14296 (while (string-match "%0A" s)
14297 (setq s (replace-match "\n" t t s)))
14300 (defvar org-entry-property-inherited-from (make-marker)
14301 "Marker pointing to the entry from where a property was inherited.
14302 Each call to `org-entry-get-with-inheritance' will set this marker to the
14303 location of the entry where the inheritance search matched. If there was
14304 no match, the marker will point nowhere.
14305 Note that also `org-entry-get' calls this function, if the INHERIT flag
14308 (defun org-entry-get-with-inheritance (property &optional literal-nil)
14309 "Get entry property, and search higher levels if not present.
14310 The search will stop at the first ancestor which has the property defined.
14311 If the value found is \"nil\", return nil to show that the property
14312 should be considered as undefined (this is the meaning of nil here).
14313 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
14314 (move-marker org-entry-property-inherited-from nil)
14316 (unless (org-before-first-heading-p)
14322 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
14323 (org-back-to-heading t)
14324 (move-marker org-entry-property-inherited-from (point))
14326 (or (org-up-heading-safe) (throw 'ex nil)))))))
14328 (cdr (assoc property org-file-properties))
14329 (cdr (assoc property org-global-properties))
14330 (cdr (assoc property org-global-properties-fixed))))
14331 (if literal-nil tmp (org-not-nil tmp))))
14333 (defvar org-property-changed-functions nil
14334 "Hook called when the value of a property has changed.
14335 Each hook function should accept two arguments, the name of the property
14336 and the new value.")
14338 (defun org-entry-put (pom property value)
14339 "Set PROPERTY to VALUE for entry at point-or-marker POM."
14340 (org-with-point-at pom
14341 (org-back-to-heading t)
14342 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
14345 ((equal property "TODO")
14346 (when (and (stringp value) (string-match "\\S-" value)
14347 (not (member value org-todo-keywords-1)))
14348 (error "\"%s\" is not a valid TODO state" value))
14349 (if (or (not value)
14350 (not (string-match "\\S-" value)))
14351 (setq value 'none))
14353 (org-set-tags nil 'align))
14354 ((equal property "PRIORITY")
14355 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
14356 (string-to-char value) ?\ ))
14357 (org-set-tags nil 'align))
14358 ((equal property "SCHEDULED")
14359 (if (re-search-forward org-scheduled-time-regexp end t)
14361 ((eq value 'earlier) (org-timestamp-change -1 'day))
14362 ((eq value 'later) (org-timestamp-change 1 'day))
14363 (t (call-interactively 'org-schedule)))
14364 (call-interactively 'org-schedule)))
14365 ((equal property "DEADLINE")
14366 (if (re-search-forward org-deadline-time-regexp end t)
14368 ((eq value 'earlier) (org-timestamp-change -1 'day))
14369 ((eq value 'later) (org-timestamp-change 1 'day))
14370 (t (call-interactively 'org-deadline)))
14371 (call-interactively 'org-deadline)))
14372 ((member property org-special-properties)
14373 (error "The %s property can not yet be set with `org-entry-put'"
14375 (t ; a non-special property
14376 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
14377 (setq range (org-get-property-block beg end 'force))
14378 (goto-char (car range))
14379 (if (re-search-forward
14380 (org-re-property property) (cdr range) t)
14382 (delete-region (match-beginning 0) (match-end 0))
14383 (goto-char (match-beginning 0)))
14384 (goto-char (cdr range))
14387 (org-indent-line-function))
14388 (insert ":" property ":")
14389 (and value (insert " " value))
14390 (org-indent-line-function)))))
14391 (run-hook-with-args 'org-property-changed-functions property value)))
14393 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
14394 "Get all property keys in the current buffer.
14395 With INCLUDE-SPECIALS, also list the special properties that reflect things
14396 like tags and TODO state.
14397 With INCLUDE-DEFAULTS, also include properties that has special meaning
14398 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING
14400 With INCLUDE-COLUMNS, also include property names given in COLUMN
14401 formats in the current buffer."
14402 (let (rtn range cfmt s p)
14406 (goto-char (point-min))
14407 (while (re-search-forward org-property-start-re nil t)
14408 (setq range (org-get-property-block))
14409 (goto-char (car range))
14410 (while (re-search-forward
14411 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
14413 (add-to-list 'rtn (org-match-string-no-properties 1)))
14414 (outline-next-heading))))
14416 (when include-specials
14417 (setq rtn (append org-special-properties rtn)))
14419 (when include-defaults
14420 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
14421 (add-to-list 'rtn org-effort-property))
14423 (when include-columns
14427 (goto-char (point-min))
14428 (while (re-search-forward
14429 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
14431 (setq cfmt (match-string 2) s 0)
14432 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
14434 (setq s (match-end 0)
14435 p (match-string 1 cfmt))
14436 (unless (or (equal p "ITEM")
14437 (member p org-special-properties))
14438 (add-to-list 'rtn (match-string 1 cfmt))))))))
14440 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
14442 (defun org-property-values (key)
14443 "Return a list of all values of property KEY in the current buffer."
14447 (goto-char (point-min))
14448 (let ((re (org-re-property key))
14450 (while (re-search-forward re nil t)
14451 (add-to-list 'values (org-trim (match-string 1))))
14452 (delete "" values)))))
14454 (defun org-insert-property-drawer ()
14455 "Insert a property drawer into the current entry."
14456 (org-back-to-heading t)
14457 (looking-at org-outline-regexp)
14458 (let ((indent (if org-adapt-indentation
14459 (- (match-end 0) (match-beginning 0))
14462 (re (concat "^[ \t]*" org-keyword-time-regexp))
14464 (outline-next-heading)
14467 (while (re-search-forward re end t))
14468 (setq hiddenp (outline-invisible-p))
14470 (and (equal (char-after) ?\n) (forward-char 1))
14471 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
14472 (if (member (match-string 1) '("CLOCK:" ":END:"))
14473 ;; just skip this line
14474 (beginning-of-line 2)
14475 ;; Drawer start, find the end
14476 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
14477 (beginning-of-line 1)))
14478 (org-skip-over-state-notes)
14479 (skip-chars-backward " \t\n\r")
14480 (if (eq (char-before) ?*) (forward-char 1))
14481 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
14482 (beginning-of-line 0)
14483 (org-indent-to-column indent)
14484 (beginning-of-line 2)
14485 (org-indent-to-column indent)
14486 (beginning-of-line 0)
14489 (org-back-to-heading t)
14491 (org-flag-drawer t))))
14493 (defun org-insert-drawer (&optional arg drawer)
14494 "Insert a drawer at point.
14496 Optional argument DRAWER, when non-nil, is a string representing
14497 drawer's name. Otherwise, the user is prompted for a name.
14499 If a region is active, insert the drawer around that region
14502 Point is left between drawer's boundaries."
14504 (let* ((logbook (if (stringp org-log-into-drawer) org-log-into-drawer
14506 ;; SYSTEM-DRAWERS is a list of drawer names that are used
14507 ;; internally by Org. They are meant to be inserted
14509 (system-drawers `("CLOCK" ,logbook "PROPERTIES"))
14510 ;; Remove system drawers from list. Note: For some reason,
14511 ;; `org-completing-read' ignores the predicate while
14512 ;; `completing-read' handles it fine.
14513 (drawer (if arg "PROPERTIES"
14516 "Drawer: " org-drawers
14517 (lambda (d) (not (member d system-drawers))))))))
14519 ;; With C-u, fall back on `org-insert-property-drawer'
14520 (arg (org-insert-property-drawer))
14521 ;; With an active region, insert a drawer at point.
14522 ((not (org-region-active-p))
14524 (unless (bolp) (insert "\n"))
14525 (insert (format ":%s:\n\n:END:\n" drawer))
14526 (forward-line -2)))
14527 ;; Otherwise, insert the drawer at point
14529 (let ((rbeg (region-beginning))
14530 (rend (copy-marker (region-end))))
14534 (beginning-of-line)
14535 (when (save-excursion
14536 (re-search-forward org-outline-regexp-bol rend t))
14537 (error "Drawers cannot contain headlines"))
14538 ;; Position point at the beginning of the first
14539 ;; non-blank line in region. Insert drawer's opening
14540 ;; there, then indent it.
14541 (org-skip-whitespace)
14542 (beginning-of-line)
14543 (insert ":" drawer ":\n")
14545 (indent-for-tab-command)
14546 ;; Move point to the beginning of the first blank line
14547 ;; after the last non-blank line in region. Insert
14548 ;; drawer's closing, then indent it.
14550 (skip-chars-backward " \r\t\n")
14552 (indent-for-tab-command)
14553 (unless (eolp) (insert "\n")))
14554 ;; Clear marker, whatever the outcome of insertion is.
14555 (set-marker rend nil)))))))
14557 (defvar org-property-set-functions-alist nil
14558 "Property set function alist.
14559 Each entry should have the following format:
14561 (PROPERTY . READ-FUNCTION)
14563 The read function will be called with the same argument as
14564 `org-completing-read'.")
14566 (defun org-set-property-function (property)
14567 "Get the function that should be used to set PROPERTY.
14568 This is computed according to `org-property-set-functions-alist'."
14569 (or (cdr (assoc property org-property-set-functions-alist))
14570 'org-completing-read))
14572 (defun org-read-property-value (property)
14573 "Read PROPERTY value from user."
14574 (let* ((completion-ignore-case t)
14575 (allowed (org-property-get-allowed-values nil property 'table))
14576 (cur (org-entry-get nil property))
14577 (prompt (concat property " value"
14578 (if (and cur (string-match "\\S-" cur))
14579 (concat " [" cur "]") "") ": "))
14580 (set-function (org-set-property-function property))
14582 (funcall set-function prompt allowed nil
14583 (not (get-text-property 0 'org-unrestricted
14585 (let (org-completion-use-ido org-completion-use-iswitchb)
14586 (funcall set-function prompt
14587 (mapcar 'list (org-property-values property))
14588 nil nil "" nil cur)))))
14593 (defvar org-last-set-property nil)
14594 (defun org-read-property-name ()
14595 "Read a property name."
14596 (let* ((completion-ignore-case t)
14597 (keys (org-buffer-property-keys nil t t))
14598 (default-prop (or (save-excursion
14600 (beginning-of-line)
14601 (and (looking-at "^\\s-*:\\([^:\n]+\\):")
14602 (null (string= (match-string 1) "END"))
14603 (match-string 1))))
14604 org-last-set-property))
14605 (property (org-icompleting-read
14607 (if default-prop (concat " [" default-prop "]") "")
14609 (mapcar 'list keys)
14613 (if (member property keys)
14615 (or (cdr (assoc (downcase property)
14616 (mapcar (lambda (x) (cons (downcase x) x))
14620 (defun org-set-property (property value)
14621 "In the current entry, set PROPERTY to VALUE.
14622 When called interactively, this will prompt for a property name, offering
14623 completion on existing and default properties. And then it will prompt
14624 for a value, offering completion either on allowed values (via an inherited
14625 xxx_ALL property) or on existing values in other instances of this property
14626 in the current file."
14627 (interactive (list nil nil))
14628 (let* ((property (or property (org-read-property-name)))
14629 (value (or value (org-read-property-value property)))
14630 (fn (assoc property org-properties-postprocess-alist)))
14631 (setq org-last-set-property property)
14632 ;; Possibly postprocess the inserted value:
14633 (when fn (setq value (funcall (cadr fn) value)))
14634 (unless (equal (org-entry-get nil property) value)
14635 (org-entry-put nil property value))))
14637 (defun org-delete-property (property)
14638 "In the current entry, delete PROPERTY."
14640 (let* ((completion-ignore-case t)
14641 (prop (org-icompleting-read "Property: "
14642 (org-entry-properties nil 'standard))))
14644 (message "Property %s %s" property
14645 (if (org-entry-delete nil property)
14647 "was not present in the entry")))
14649 (defun org-delete-property-globally (property)
14650 "Remove PROPERTY globally, from all entries."
14652 (let* ((completion-ignore-case t)
14653 (prop (org-icompleting-read
14654 "Globally remove property: "
14655 (mapcar 'list (org-buffer-property-keys)))))
14660 (goto-char (point-min))
14662 (while (re-search-forward
14663 (org-re-property property)
14665 (setq cnt (1+ cnt))
14666 (replace-match ""))
14667 (message "Property \"%s\" removed from %d entries" property cnt)))))
14669 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
14671 (defun org-compute-property-at-point ()
14672 "Compute the property at point.
14673 This looks for an enclosing column format, extracts the operator and
14674 then applies it to the property in the column format's scope."
14676 (unless (org-at-property-p)
14677 (error "Not at a property"))
14678 (let ((prop (org-match-string-no-properties 2)))
14679 (org-columns-get-format-and-top-level)
14680 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
14681 (error "No operator defined for property %s" prop))
14682 (org-columns-compute prop)))
14684 (defvar org-property-allowed-value-functions nil
14685 "Hook for functions supplying allowed values for a specific property.
14686 The functions must take a single argument, the name of the property, and
14687 return a flat list of allowed values. If \":ETC\" is one of
14688 the values, this means that these values are intended as defaults for
14689 completion, but that other values should be allowed too.
14690 The functions must return nil if they are not responsible for this
14693 (defun org-property-get-allowed-values (pom property &optional table)
14694 "Get allowed values for the property PROPERTY.
14695 When TABLE is non-nil, return an alist that can directly be used for
14699 ((equal property "TODO")
14700 (setq vals (org-with-point-at pom
14701 (append org-todo-keywords-1 '("")))))
14702 ((equal property "PRIORITY")
14703 (let ((n org-lowest-priority))
14704 (while (>= n org-highest-priority)
14705 (push (char-to-string n) vals)
14707 ((member property org-special-properties))
14708 ((setq vals (run-hook-with-args-until-success
14709 'org-property-allowed-value-functions property)))
14711 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
14712 (when (and vals (string-match "\\S-" vals))
14713 (setq vals (car (read-from-string (concat "(" vals ")"))))
14714 (setq vals (mapcar (lambda (x)
14715 (cond ((stringp x) x)
14716 ((numberp x) (number-to-string x))
14717 ((symbolp x) (symbol-name x))
14720 (when (member ":ETC" vals)
14721 (setq vals (remove ":ETC" vals))
14722 (org-add-props (car vals) '(org-unrestricted t)))
14723 (if table (mapcar 'list vals) vals)))
14725 (defun org-property-previous-allowed-value (&optional previous)
14726 "Switch to the next allowed value for this property."
14728 (org-property-next-allowed-value t))
14730 (defun org-property-next-allowed-value (&optional previous)
14731 "Switch to the next allowed value for this property."
14733 (unless (org-at-property-p)
14734 (error "Not at a property"))
14735 (let* ((key (match-string 2))
14736 (value (match-string 3))
14737 (allowed (or (org-property-get-allowed-values (point) key)
14738 (and (member value '("[ ]" "[-]" "[X]"))
14742 (error "Allowed values for this property have not been defined"))
14743 (if previous (setq allowed (reverse allowed)))
14744 (if (member value allowed)
14745 (setq nval (car (cdr (member value allowed)))))
14746 (setq nval (or nval (car allowed)))
14747 (if (equal nval value)
14748 (error "Only one allowed value for this property"))
14749 (org-at-property-p)
14750 (replace-match (concat " :" key ": " nval) t t)
14751 (org-indent-line-function)
14752 (beginning-of-line 1)
14753 (skip-chars-forward " \t")
14754 (run-hook-with-args 'org-property-changed-functions key nval)))
14756 (defun org-find-olp (path &optional this-buffer)
14757 "Return a marker pointing to the entry at outline path OLP.
14758 If anything goes wrong, throw an error.
14759 You can wrap this call to catch the error like this:
14761 (condition-case msg
14762 (org-mobile-locate-entry (match-string 4))
14763 (error (nth 1 msg)))
14765 The return value will then be either a string with the error message,
14766 or a marker if everything is OK.
14768 If THIS-BUFFER is set, the outline path does not contain a file,
14770 (let* ((file (if this-buffer buffer-file-name (pop path)))
14771 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
14775 limit re end found pos heading cnt flevel)
14776 (unless buffer (error "File not found :%s" file))
14777 (with-current-buffer buffer
14781 (setq limit (point-max))
14782 (goto-char (point-min))
14783 (while (setq heading (pop path))
14784 (setq re (format org-complex-heading-regexp-format
14785 (regexp-quote heading)))
14786 (setq cnt 0 pos (point))
14787 (while (re-search-forward re end t)
14788 (setq level (- (match-end 1) (match-beginning 1)))
14789 (if (and (>= level lmin) (<= level lmax))
14790 (setq found (match-beginning 0) flevel level cnt (1+ cnt))))
14791 (when (= cnt 0) (error "Heading not found on level %d: %s"
14793 (when (> cnt 1) (error "Heading not unique on level %d: %s"
14796 (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
14797 (setq end (save-excursion (org-end-of-subtree t t))))
14798 (when (org-at-heading-p)
14799 (move-marker (make-marker) (point))))))))
14801 (defun org-find-exact-headline-in-buffer (heading &optional buffer pos-only)
14802 "Find node HEADING in BUFFER.
14803 Return a marker to the heading if it was found, or nil if not.
14804 If POS-ONLY is set, return just the position instead of a marker.
14806 The heading text must match exact, but it may have a TODO keyword,
14807 a priority cookie and tags in the standard locations."
14808 (with-current-buffer (or buffer (current-buffer))
14812 (goto-char (point-min))
14813 (let (case-fold-search)
14814 (if (re-search-forward
14815 (format org-complex-heading-regexp-format
14816 (regexp-quote heading)) nil t)
14818 (match-beginning 0)
14819 (move-marker (make-marker) (match-beginning 0)))))))))
14821 (defun org-find-exact-heading-in-directory (heading &optional dir)
14822 "Find Org node headline HEADING in all .org files in directory DIR.
14823 When the target headline is found, return a marker to this location."
14824 (let ((files (directory-files (or dir default-directory)
14825 nil "\\`[^.#].*\\.org\\'"))
14826 file visiting m buffer)
14828 (while (setq file (pop files))
14829 (message "trying %s" file)
14830 (setq visiting (org-find-base-buffer-visiting file))
14831 (setq buffer (or visiting (find-file-noselect file)))
14832 (setq m (org-find-exact-headline-in-buffer
14834 (when (and (not m) (not visiting)) (kill-buffer buffer))
14835 (and m (throw 'found m))))))
14837 (defun org-find-entry-with-id (ident)
14838 "Locate the entry that contains the ID property with exact value IDENT.
14839 IDENT can be a string, a symbol or a number, this function will search for
14840 the string representation of it.
14841 Return the position where this entry starts, or nil if there is no such entry."
14842 (interactive "sID: ")
14844 ((stringp ident) ident)
14845 ((symbol-name ident) (symbol-name ident))
14846 ((numberp ident) (number-to-string ident))
14847 (t (error "IDENT %s must be a string, symbol or number" ident))))
14848 (case-fold-search nil))
14852 (goto-char (point-min))
14853 (when (re-search-forward
14854 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
14856 (org-back-to-heading t)
14861 (defvar org-last-changed-timestamp nil)
14862 (defvar org-last-inserted-timestamp nil
14863 "The last time stamp inserted with `org-insert-time-stamp'.")
14864 (defvar org-time-was-given) ; dynamically scoped parameter
14865 (defvar org-end-time-was-given) ; dynamically scoped parameter
14866 (defvar org-ts-what) ; dynamically scoped parameter
14868 (defun org-time-stamp (arg &optional inactive)
14869 "Prompt for a date/time and insert a time stamp.
14870 If the user specifies a time like HH:MM, or if this command is called
14871 with a prefix argument, the time stamp will contain date and time.
14872 Otherwise, only the date will be included. All parts of a date not
14873 specified by the user will be filled in from the current date/time.
14874 So if you press just return without typing anything, the time stamp
14875 will represent the current date/time. If there is already a timestamp
14876 at the cursor, it will be modified."
14880 ;; Default time is either today, or, when entering a range,
14881 ;; the range start.
14882 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
14884 (re-search-backward
14885 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
14886 (- (point) 20) t)))
14887 (apply 'encode-time (org-parse-time-string (match-string 1)))
14889 (default-input (and ts (org-get-compact-tod ts)))
14890 (repeater (save-excursion
14892 (beginning-of-line)
14893 (when (re-search-forward
14894 "\\([.+-]+[0-9]+[dwmy] ?\\)+" ;;\\(?:[/ ][-+]?[0-9]+[dwmy]\\)?\\) ?"
14895 (save-excursion (progn (end-of-line) (point))) t)
14896 (match-string 0)))))
14897 org-time-was-given org-end-time-was-given time)
14899 ((and (org-at-timestamp-p t)
14900 (memq last-command '(org-time-stamp org-time-stamp-inactive))
14901 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
14903 (setq time (let ((this-command this-command))
14904 (org-read-date arg 'totime nil nil
14905 default-time default-input inactive)))
14906 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
14907 ((org-at-timestamp-p t)
14908 (setq time (let ((this-command this-command))
14909 (org-read-date arg 'totime nil nil default-time default-input inactive)))
14910 (when (org-at-timestamp-p t) ; just to get the match data
14911 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
14913 (setq org-last-changed-timestamp
14914 (org-insert-time-stamp
14915 time (or org-time-was-given arg)
14916 inactive nil nil (list org-end-time-was-given)))
14917 (when repeater (goto-char (1- (point))) (insert " " repeater)
14918 (setq org-last-changed-timestamp
14919 (concat (substring org-last-inserted-timestamp 0 -1)
14920 " " repeater ">"))))
14921 (message "Timestamp updated"))
14923 (setq time (let ((this-command this-command))
14924 (org-read-date arg 'totime nil nil default-time default-input inactive)))
14925 (org-insert-time-stamp time (or org-time-was-given arg) inactive
14926 nil nil (list org-end-time-was-given))))))
14928 ;; FIXME: can we use this for something else, like computing time differences?
14929 (defun org-get-compact-tod (s)
14930 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
14931 (let* ((t1 (match-string 1 s))
14932 (h1 (string-to-number (match-string 2 s)))
14933 (m1 (string-to-number (match-string 3 s)))
14934 (t2 (and (match-end 4) (match-string 5 s)))
14935 (h2 (and t2 (string-to-number (match-string 6 s))))
14936 (m2 (and t2 (string-to-number (match-string 7 s))))
14940 (setq dh (- h2 h1) dm (- m2 m1))
14941 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
14942 (concat t1 "+" (number-to-string dh)
14943 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
14945 (defun org-time-stamp-inactive (&optional arg)
14946 "Insert an inactive time stamp.
14947 An inactive time stamp is enclosed in square brackets instead of angle
14948 brackets. It is inactive in the sense that it does not trigger agenda entries,
14949 does not link to the calendar and cannot be changed with the S-cursor keys.
14950 So these are more for recording a certain time/date."
14952 (org-time-stamp arg 'inactive))
14954 (defvar org-date-ovl (make-overlay 1 1))
14955 (overlay-put org-date-ovl 'face 'org-warning)
14956 (org-detach-overlay org-date-ovl)
14958 (defvar org-ans1) ; dynamically scoped parameter
14959 (defvar org-ans2) ; dynamically scoped parameter
14961 (defvar org-plain-time-of-day-regexp) ; defined below
14963 (defvar org-overriding-default-time nil) ; dynamically scoped
14964 (defvar org-read-date-overlay nil)
14965 (defvar org-dcst nil) ; dynamically scoped
14966 (defvar org-read-date-history nil)
14967 (defvar org-read-date-final-answer nil)
14968 (defvar org-read-date-analyze-futurep nil)
14969 (defvar org-read-date-analyze-forced-year nil)
14971 (defun org-read-date (&optional with-time to-time from-string prompt
14972 default-time default-input inactive)
14973 "Read a date, possibly a time, and make things smooth for the user.
14974 The prompt will suggest to enter an ISO date, but you can also enter anything
14975 which will at least partially be understood by `parse-time-string'.
14976 Unrecognized parts of the date will default to the current day, month, year,
14977 hour and minute. If this command is called to replace a timestamp at point,
14978 or to enter the second timestamp of a range, the default time is taken
14979 from the existing stamp. Furthermore, the command prefers the future,
14980 so if you are giving a date where the year is not given, and the day-month
14981 combination is already past in the current year, it will assume you
14982 mean next year. For details, see the manual. A few examples:
14984 3-2-5 --> 2003-02-05
14985 feb 15 --> currentyear-02-15
14986 2/15 --> currentyear-02-15
14987 sep 12 9 --> 2009-09-12
14988 12:45 --> today 12:45
14989 22 sept 0:34 --> currentyear-09-22 0:34
14990 12 --> currentyear-currentmonth-12
14991 Fri --> nearest Friday (today or later)
14994 Furthermore you can specify a relative date by giving, as the *first* thing
14995 in the input: a plus/minus sign, a number and a letter [dwmy] to indicate
14996 change in days weeks, months, years.
14997 With a single plus or minus, the date is relative to today. With a double
14998 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
14999 +4d --> four days from today
15000 +4 --> same as above
15001 +2w --> two weeks from today
15002 ++5 --> five days from default date
15004 The function understands only English month and weekday abbreviations,
15005 but this can be configured with the variables `parse-time-months' and
15006 `parse-time-weekdays'.
15008 While prompting, a calendar is popped up - you can also select the
15009 date with the mouse (button 1). The calendar shows a period of three
15010 months. To scroll it to other months, use the keys `>' and `<'.
15011 If you don't like the calendar, turn it off with
15012 \(setq org-read-date-popup-calendar nil)
15014 With optional argument TO-TIME, the date will immediately be converted
15015 to an internal time.
15016 With an optional argument WITH-TIME, the prompt will suggest to also
15017 insert a time. Note that when WITH-TIME is not set, you can still
15018 enter a time, and this function will inform the calling routine about
15019 this change. The calling routine may then choose to change the format
15020 used to insert the time stamp into the buffer to include the time.
15021 With optional argument FROM-STRING, read from this string instead from
15022 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
15023 the time/date that is used for everything that is not specified by the
15025 (require 'parse-time)
15026 (let* ((org-time-stamp-rounding-minutes
15027 (if (equal with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
15028 (org-dcst org-display-custom-times)
15029 (ct (org-current-time))
15030 (def (or org-overriding-default-time default-time ct))
15031 (defdecode (decode-time def))
15033 (when (< (nth 2 defdecode) org-extend-today-until)
15034 (setcar (nthcdr 2 defdecode) -1)
15035 (setcar (nthcdr 1 defdecode) 59)
15036 (setq def (apply 'encode-time defdecode)
15037 defdecode (decode-time def)))))
15038 (calendar-frame-setup nil)
15039 (calendar-setup nil)
15040 (calendar-move-hook nil)
15041 (calendar-view-diary-initially-flag nil)
15042 (calendar-view-holidays-initially-flag nil)
15043 (timestr (format-time-string
15044 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") def))
15045 (prompt (concat (if prompt (concat prompt " ") "")
15046 (format "Date+time [%s]: " timestr)))
15047 ans (org-ans0 "") org-ans1 org-ans2 final)
15050 (from-string (setq ans from-string))
15051 (org-read-date-popup-calendar
15053 (save-window-excursion
15057 (calendar-forward-day (- (time-to-days def)
15058 (calendar-absolute-from-gregorian
15059 (calendar-current-date))))
15060 (org-eval-in-calendar nil t)
15061 (let* ((old-map (current-local-map))
15062 (map (copy-keymap calendar-mode-map))
15063 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
15064 (org-defkey map (kbd "RET") 'org-calendar-select)
15065 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
15066 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
15067 (org-defkey minibuffer-local-map [(meta shift left)]
15068 (lambda () (interactive)
15069 (org-eval-in-calendar '(calendar-backward-month 1))))
15070 (org-defkey minibuffer-local-map [(meta shift right)]
15071 (lambda () (interactive)
15072 (org-eval-in-calendar '(calendar-forward-month 1))))
15073 (org-defkey minibuffer-local-map [(meta shift up)]
15074 (lambda () (interactive)
15075 (org-eval-in-calendar '(calendar-backward-year 1))))
15076 (org-defkey minibuffer-local-map [(meta shift down)]
15077 (lambda () (interactive)
15078 (org-eval-in-calendar '(calendar-forward-year 1))))
15079 (org-defkey minibuffer-local-map [?\e (shift left)]
15080 (lambda () (interactive)
15081 (org-eval-in-calendar '(calendar-backward-month 1))))
15082 (org-defkey minibuffer-local-map [?\e (shift right)]
15083 (lambda () (interactive)
15084 (org-eval-in-calendar '(calendar-forward-month 1))))
15085 (org-defkey minibuffer-local-map [?\e (shift up)]
15086 (lambda () (interactive)
15087 (org-eval-in-calendar '(calendar-backward-year 1))))
15088 (org-defkey minibuffer-local-map [?\e (shift down)]
15089 (lambda () (interactive)
15090 (org-eval-in-calendar '(calendar-forward-year 1))))
15091 (org-defkey minibuffer-local-map [(shift up)]
15092 (lambda () (interactive)
15093 (org-eval-in-calendar '(calendar-backward-week 1))))
15094 (org-defkey minibuffer-local-map [(shift down)]
15095 (lambda () (interactive)
15096 (org-eval-in-calendar '(calendar-forward-week 1))))
15097 (org-defkey minibuffer-local-map [(shift left)]
15098 (lambda () (interactive)
15099 (org-eval-in-calendar '(calendar-backward-day 1))))
15100 (org-defkey minibuffer-local-map [(shift right)]
15101 (lambda () (interactive)
15102 (org-eval-in-calendar '(calendar-forward-day 1))))
15103 (org-defkey minibuffer-local-map ">"
15104 (lambda () (interactive)
15105 (org-eval-in-calendar '(scroll-calendar-left 1))))
15106 (org-defkey minibuffer-local-map "<"
15107 (lambda () (interactive)
15108 (org-eval-in-calendar '(scroll-calendar-right 1))))
15109 (org-defkey minibuffer-local-map "\C-v"
15110 (lambda () (interactive)
15111 (org-eval-in-calendar
15112 '(calendar-scroll-left-three-months 1))))
15113 (org-defkey minibuffer-local-map "\M-v"
15114 (lambda () (interactive)
15115 (org-eval-in-calendar
15116 '(calendar-scroll-right-three-months 1))))
15117 (run-hooks 'org-read-date-minibuffer-setup-hook)
15120 (use-local-map map)
15121 (setq org-read-date-inactive inactive)
15122 (add-hook 'post-command-hook 'org-read-date-display)
15123 (setq org-ans0 (read-string prompt default-input
15124 'org-read-date-history nil))
15125 ;; org-ans0: from prompt
15126 ;; org-ans1: from mouse click
15127 ;; org-ans2: from calendar motion
15128 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
15129 (remove-hook 'post-command-hook 'org-read-date-display)
15130 (use-local-map old-map)
15131 (when org-read-date-overlay
15132 (delete-overlay org-read-date-overlay)
15133 (setq org-read-date-overlay nil)))))
15134 (bury-buffer "*Calendar*")))))
15136 (t ; Naked prompt only
15138 (setq ans (read-string prompt default-input
15139 'org-read-date-history timestr))
15140 (when org-read-date-overlay
15141 (delete-overlay org-read-date-overlay)
15142 (setq org-read-date-overlay nil)))))
15144 (setq final (org-read-date-analyze ans def defdecode))
15146 (when org-read-date-analyze-forced-year
15147 (message "Year was forced into %s"
15148 (if org-read-date-force-compatible-dates
15149 "compatible range (1970-2037)"
15150 "range representable on this machine"))
15153 ;; One round trip to get rid of 34th of August and stuff like that....
15154 (setq final (decode-time (apply 'encode-time final)))
15156 (setq org-read-date-final-answer ans)
15159 (apply 'encode-time final)
15160 (if (and (boundp 'org-time-was-given) org-time-was-given)
15161 (format "%04d-%02d-%02d %02d:%02d"
15162 (nth 5 final) (nth 4 final) (nth 3 final)
15163 (nth 2 final) (nth 1 final))
15164 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
15169 (defvar org-read-date-inactive)
15170 (defun org-read-date-display ()
15171 "Display the current date prompt interpretation in the minibuffer."
15172 (when org-read-date-display-live
15173 (when org-read-date-overlay
15174 (delete-overlay org-read-date-overlay))
15177 (while (not (equal (buffer-substring
15178 (max (point-min) (- (point) 4)) (point))
15182 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
15183 " " (or org-ans1 org-ans2)))
15184 (org-end-time-was-given nil)
15185 (f (org-read-date-analyze ans def defdecode))
15187 org-time-stamp-custom-formats
15188 org-time-stamp-formats))
15189 (fmt (if (or with-time
15190 (and (boundp 'org-time-was-given) org-time-was-given))
15193 (txt (format-time-string fmt (apply 'encode-time f)))
15194 (txt (if org-read-date-inactive (concat "[" (substring txt 1 -1) "]") txt))
15195 (txt (concat "=> " txt)))
15196 (when (and org-end-time-was-given
15197 (string-match org-plain-time-of-day-regexp txt))
15198 (setq txt (concat (substring txt 0 (match-end 0)) "-"
15199 org-end-time-was-given
15200 (substring txt (match-end 0)))))
15201 (when org-read-date-analyze-futurep
15202 (setq txt (concat txt " (=>F)")))
15203 (setq org-read-date-overlay
15204 (make-overlay (1- (point-at-eol)) (point-at-eol)))
15205 (org-overlay-display org-read-date-overlay txt 'secondary-selection))))
15207 (defun org-read-date-analyze (ans def defdecode)
15208 "Analyze the combined answer of the date prompt."
15209 ;; FIXME: cleanup and comment
15210 (let ((nowdecode (decode-time (current-time)))
15211 delta deltan deltaw deltadef year month day
15212 hour minute second wday pm h2 m2 tl wday1
15213 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
15214 (setq org-read-date-analyze-futurep nil
15215 org-read-date-analyze-forced-year nil)
15216 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
15219 (when (setq delta (org-read-date-get-relative ans (current-time) def))
15220 (setq ans (replace-match "" t t ans)
15222 deltaw (nth 1 delta)
15223 deltadef (nth 2 delta)))
15225 ;; Check if there is an iso week date in there
15226 ;; If yes, store the info and postpone interpreting it until the rest
15227 ;; of the parsing is done
15228 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
15229 (setq iso-year (if (match-end 1)
15230 (org-small-year-to-year
15231 (string-to-number (match-string 1 ans))))
15232 iso-weekday (if (match-end 3)
15233 (string-to-number (match-string 3 ans)))
15234 iso-week (string-to-number (match-string 2 ans)))
15235 (setq ans (replace-match "" t t ans)))
15237 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
15238 (when (string-match
15239 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
15240 (setq year (if (match-end 2)
15241 (string-to-number (match-string 2 ans))
15242 (progn (setq kill-year t)
15243 (string-to-number (format-time-string "%Y"))))
15244 month (string-to-number (match-string 3 ans))
15245 day (string-to-number (match-string 4 ans)))
15246 (if (< year 100) (setq year (+ 2000 year)))
15247 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15250 ;; Help matching dotted european dates
15251 (when (string-match
15252 "^ *\\(3[01]\\|0?[1-9]\\|[12][0-9]\\)\\. ?\\(0?[1-9]\\|1[012]\\)\\. ?\\([1-9][0-9][0-9][0-9]\\)?" ans)
15253 (setq year (if (match-end 3)
15254 (string-to-number (match-string 3 ans))
15255 (progn (setq kill-year t)
15256 (string-to-number (format-time-string "%Y"))))
15257 day (string-to-number (match-string 1 ans))
15258 month (string-to-number (match-string 2 ans))
15259 ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15262 ;; Help matching american dates, like 5/30 or 5/30/7
15263 (when (string-match
15264 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
15265 (setq year (if (match-end 4)
15266 (string-to-number (match-string 4 ans))
15267 (progn (setq kill-year t)
15268 (string-to-number (format-time-string "%Y"))))
15269 month (string-to-number (match-string 1 ans))
15270 day (string-to-number (match-string 2 ans)))
15271 (if (< year 100) (setq year (+ 2000 year)))
15272 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15274 ;; Help matching am/pm times, because `parse-time-string' does not do that.
15275 ;; If there is a time with am/pm, and *no* time without it, we convert
15276 ;; so that matching will be successful.
15277 (loop for i from 1 to 2 do ; twice, for end time as well
15278 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
15279 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
15280 (setq hour (string-to-number (match-string 1 ans))
15281 minute (if (match-end 3)
15282 (string-to-number (match-string 3 ans))
15285 (string-to-char (downcase (match-string 4 ans)))))
15286 (if (and (= hour 12) (not pm))
15288 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
15289 (setq ans (replace-match (format "%02d:%02d" hour minute)
15292 ;; Check if a time range is given as a duration
15293 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
15294 (setq hour (string-to-number (match-string 1 ans))
15295 h2 (+ hour (string-to-number (match-string 3 ans)))
15296 minute (string-to-number (match-string 2 ans))
15297 m2 (+ minute (if (match-end 5) (string-to-number
15298 (match-string 5 ans))0)))
15299 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
15300 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
15303 ;; Check if there is a time range
15304 (when (boundp 'org-end-time-was-given)
15305 (setq org-time-was-given nil)
15306 (when (and (string-match org-plain-time-of-day-regexp ans)
15308 (setq org-end-time-was-given (match-string 8 ans))
15309 (setq ans (concat (substring ans 0 (match-beginning 7))
15310 (substring ans (match-end 7))))))
15312 (setq tl (parse-time-string ans)
15313 day (or (nth 3 tl) (nth 3 defdecode))
15314 month (or (nth 4 tl)
15315 (if (and org-read-date-prefer-future
15316 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
15317 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
15318 (nth 4 defdecode)))
15319 year (or (and (not kill-year) (nth 5 tl))
15320 (if (and org-read-date-prefer-future
15321 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
15322 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
15323 (nth 5 defdecode)))
15324 hour (or (nth 2 tl) (nth 2 defdecode))
15325 minute (or (nth 1 tl) (nth 1 defdecode))
15326 second (or (nth 0 tl) 0)
15329 (when (and (eq org-read-date-prefer-future 'time)
15330 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
15331 (equal day (nth 3 nowdecode))
15332 (equal month (nth 4 nowdecode))
15333 (equal year (nth 5 nowdecode))
15335 (or (< (nth 2 tl) (nth 2 nowdecode))
15336 (and (= (nth 2 tl) (nth 2 nowdecode))
15338 (< (nth 1 tl) (nth 1 nowdecode)))))
15342 ;; Special date definitions below
15345 ;; There was an iso week
15348 (setq year (or iso-year year)
15349 day (or iso-weekday wday 1)
15350 wday nil ; to make sure that the trigger below does not match
15351 iso-date (calendar-gregorian-from-absolute
15352 (calendar-absolute-from-iso
15353 (list iso-week day year))))
15354 ; FIXME: Should we also push ISO weeks into the future?
15355 ; (when (and org-read-date-prefer-future
15357 ; (< (calendar-absolute-from-gregorian iso-date)
15358 ; (time-to-days (current-time))))
15359 ; (setq year (1+ year)
15360 ; iso-date (calendar-gregorian-from-absolute
15361 ; (calendar-absolute-from-iso
15362 ; (list iso-week day year)))))
15363 (setq month (car iso-date)
15364 year (nth 2 iso-date)
15365 day (nth 1 iso-date)))
15369 (let ((now (decode-time (current-time))))
15370 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
15371 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
15372 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
15373 ((equal deltaw "m") (setq month (+ month deltan)))
15374 ((equal deltaw "y") (setq year (+ year deltan)))))
15375 ((and wday (not (nth 3 tl)))
15377 ;; Weekday was given, but no day, so pick that day in the week
15378 ;; on or after the derived date.
15379 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
15380 (unless (equal wday wday1)
15381 (setq day (+ day (% (- wday wday1 -7) 7))))))
15382 (if (and (boundp 'org-time-was-given)
15384 (setq org-time-was-given t))
15385 (if (< year 100) (setq year (+ 2000 year)))
15386 ;; Check of the date is representable
15387 (if org-read-date-force-compatible-dates
15390 (setq year 1970 org-read-date-analyze-forced-year t))
15392 (setq year 2037 org-read-date-analyze-forced-year t)))
15393 (condition-case nil
15394 (ignore (encode-time second minute hour day month year))
15396 (setq year (nth 5 defdecode))
15397 (setq org-read-date-analyze-forced-year t))))
15398 (setq org-read-date-analyze-futurep futurep)
15399 (list second minute hour day month year)))
15401 (defvar parse-time-weekdays)
15403 (defun org-read-date-get-relative (s today default)
15404 "Check string S for special relative date string.
15405 TODAY and DEFAULT are internal times, for today and for a default.
15406 Return shift list (N what def-flag)
15407 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
15408 N is the number of WHATs to shift.
15409 DEF-FLAG is t when a double ++ or -- indicates shift relative to
15410 the DEFAULT date rather than TODAY."
15411 (require 'parse-time)
15415 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
15417 "\\([dwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
15418 "\\([ \t]\\|$\\)") s)
15419 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
15420 (let* ((dir (if (> (match-end 1) (match-beginning 1))
15421 (string-to-char (substring (match-string 1 s) -1))
15423 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
15424 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
15425 (what (if (match-end 3) (match-string 3 s) "d"))
15426 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
15427 (date (if rel default today))
15428 (wday (nth 6 (decode-time date)))
15432 (setq delta (mod (+ 7 (- wday1 wday)) 7))
15433 (if (= dir ?-) (setq delta (- delta 7)))
15434 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
15435 (list delta "d" rel))
15436 (list (* n (if (= dir ?-) -1 1)) what rel)))))
15438 (defun org-order-calendar-date-args (arg1 arg2 arg3)
15439 "Turn a user-specified date into the internal representation.
15440 The internal representation needed by the calendar is (month day year).
15441 This is a wrapper to handle the brain-dead convention in calendar that
15442 user function argument order change dependent on argument order."
15443 (if (boundp 'calendar-date-style)
15445 ((eq calendar-date-style 'american)
15446 (list arg1 arg2 arg3))
15447 ((eq calendar-date-style 'european)
15448 (list arg2 arg1 arg3))
15449 ((eq calendar-date-style 'iso)
15450 (list arg2 arg3 arg1)))
15451 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
15452 (if (org-bound-and-true-p european-calendar-style)
15453 (list arg2 arg1 arg3)
15454 (list arg1 arg2 arg3)))))
15456 (defun org-eval-in-calendar (form &optional keepdate)
15457 "Eval FORM in the calendar window and return to current window.
15458 Also, store the cursor date in variable org-ans2."
15459 (let ((sf (selected-frame))
15460 (sw (selected-window)))
15461 (select-window (get-buffer-window "*Calendar*" t))
15463 (when (and (not keepdate) (calendar-cursor-to-date))
15464 (let* ((date (calendar-cursor-to-date))
15465 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
15466 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
15467 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
15469 (org-select-frame-set-input-focus sf)))
15471 (defun org-calendar-select ()
15472 "Return to `org-read-date' with the date currently selected.
15473 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
15475 (when (calendar-cursor-to-date)
15476 (let* ((date (calendar-cursor-to-date))
15477 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
15478 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
15479 (if (active-minibuffer-window) (exit-minibuffer))))
15481 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
15482 "Insert a date stamp for the date given by the internal TIME.
15483 WITH-HM means use the stamp format that includes the time of the day.
15484 INACTIVE means use square brackets instead of angular ones, so that the
15485 stamp will not contribute to the agenda.
15486 PRE and POST are optional strings to be inserted before and after the
15488 The command returns the inserted time stamp."
15489 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
15491 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
15492 (insert-before-markers (or pre ""))
15493 (when (listp extra)
15494 (setq extra (car extra))
15495 (if (and (stringp extra)
15496 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
15497 (setq extra (format "-%02d:%02d"
15498 (string-to-number (match-string 1 extra))
15499 (string-to-number (match-string 2 extra))))
15502 (setq fmt (concat (substring fmt 0 -1) extra (substring fmt -1))))
15503 (insert-before-markers (setq stamp (format-time-string fmt time)))
15504 (insert-before-markers (or post ""))
15505 (setq org-last-inserted-timestamp stamp)))
15507 (defun org-toggle-time-stamp-overlays ()
15508 "Toggle the use of custom time stamp formats."
15510 (setq org-display-custom-times (not org-display-custom-times))
15511 (unless org-display-custom-times
15512 (let ((p (point-min)) (bmp (buffer-modified-p)))
15513 (while (setq p (next-single-property-change p 'display))
15514 (if (and (get-text-property p 'display)
15515 (eq (get-text-property p 'face) 'org-date))
15516 (remove-text-properties
15517 p (setq p (next-single-property-change p 'display))
15519 (set-buffer-modified-p bmp)))
15520 (if (featurep 'xemacs)
15521 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
15522 (org-restart-font-lock)
15523 (setq org-table-may-need-update t)
15524 (if org-display-custom-times
15525 (message "Time stamps are overlaid with custom format")
15526 (message "Time stamp overlays removed")))
15528 (defun org-display-custom-time (beg end)
15529 "Overlay modified time stamp format over timestamp between BEG and END."
15530 (let* ((ts (buffer-substring beg end))
15531 t1 w1 with-hm tf time str w2 (off 0))
15533 (setq t1 (org-parse-time-string ts t))
15534 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)?\\'" ts)
15535 (setq off (- (match-end 0) (match-beginning 0)))))
15536 (setq end (- end off))
15537 (setq w1 (- end beg)
15538 with-hm (and (nth 1 t1) (nth 2 t1))
15539 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
15540 time (org-fix-decoded-time t1)
15542 (format-time-string
15543 (substring tf 1 -1) (apply 'encode-time time))
15544 nil 'mouse-face 'highlight)
15546 (if (not (= w2 w1))
15547 (add-text-properties (1+ beg) (+ 2 beg)
15548 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
15549 (if (featurep 'xemacs)
15551 (put-text-property beg end 'invisible t)
15552 (put-text-property beg end 'end-glyph (make-glyph str)))
15553 (put-text-property beg end 'display str))))
15555 (defun org-translate-time (string)
15556 "Translate all timestamps in STRING to custom format.
15557 But do this only if the variable `org-display-custom-times' is set."
15558 (when org-display-custom-times
15561 (re org-ts-regexp-both)
15562 t1 with-hm inactive tf time str beg end)
15563 (while (setq start (string-match re string start))
15564 (setq beg (match-beginning 0)
15566 t1 (save-match-data
15567 (org-parse-time-string (substring string beg end) t))
15568 with-hm (and (nth 1 t1) (nth 2 t1))
15569 inactive (equal (substring string beg (1+ beg)) "[")
15570 tf (funcall (if with-hm 'cdr 'car)
15571 org-time-stamp-custom-formats)
15572 time (org-fix-decoded-time t1)
15573 str (format-time-string
15575 (if inactive "[" "<") (substring tf 1 -1)
15576 (if inactive "]" ">"))
15577 (apply 'encode-time time))
15578 string (replace-match str t t string)
15579 start (+ start (length str)))))))
15582 (defun org-fix-decoded-time (time)
15583 "Set 0 instead of nil for the first 6 elements of time.
15584 Don't touch the rest."
15586 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
15588 (defun org-days-to-time (timestamp-string)
15589 "Difference between TIMESTAMP-STRING and now in days."
15590 (- (time-to-days (org-time-string-to-time timestamp-string))
15591 (time-to-days (current-time))))
15593 (defun org-deadline-close (timestamp-string &optional ndays)
15594 "Is the time in TIMESTAMP-STRING close to the current date?"
15595 (setq ndays (or ndays (org-get-wdays timestamp-string)))
15596 (and (< (org-days-to-time timestamp-string) ndays)
15597 (not (org-entry-is-done-p))))
15599 (defun org-get-wdays (ts)
15600 "Get the deadline lead time appropriate for timestring TS."
15602 ((<= org-deadline-warning-days 0)
15603 ;; 0 or negative, enforce this value no matter what
15604 (- org-deadline-warning-days))
15605 ((string-match "-\\([0-9]+\\)\\([dwmy]\\)\\(\\'\\|>\\| \\)" ts)
15606 ;; lead time is specified.
15607 (floor (* (string-to-number (match-string 1 ts))
15608 (cdr (assoc (match-string 2 ts)
15609 '(("d" . 1) ("w" . 7)
15610 ("m" . 30.4) ("y" . 365.25)))))))
15611 ;; go for the default.
15612 (t org-deadline-warning-days)))
15614 (defun org-calendar-select-mouse (ev)
15615 "Return to `org-read-date' with the date currently selected.
15616 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
15618 (mouse-set-point ev)
15619 (when (calendar-cursor-to-date)
15620 (let* ((date (calendar-cursor-to-date))
15621 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
15622 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
15623 (if (active-minibuffer-window) (exit-minibuffer))))
15625 (defun org-check-deadlines (ndays)
15626 "Check if there are any deadlines due or past due.
15627 A deadline is considered due if it happens within `org-deadline-warning-days'
15628 days from today's date. If the deadline appears in an entry marked DONE,
15629 it is not shown. The prefix arg NDAYS can be used to test that many
15630 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
15632 (let* ((org-warn-days
15634 ((equal ndays '(4)) 100000)
15635 (ndays (prefix-numeric-value ndays))
15636 (t (abs org-deadline-warning-days))))
15637 (case-fold-search nil)
15638 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
15640 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
15642 (message "%d deadlines past-due or due within %d days"
15643 (org-occur regexp nil callback)
15646 (defun org-check-before-date (date)
15647 "Check if there are deadlines or scheduled entries before DATE."
15648 (interactive (list (org-read-date)))
15649 (let ((case-fold-search nil)
15650 (regexp (concat "\\<\\(" org-deadline-string
15651 "\\|" org-scheduled-string
15652 "\\) *<\\([^>]+\\)>"))
15654 (lambda () (time-less-p
15655 (org-time-string-to-time (match-string 2))
15656 (org-time-string-to-time date)))))
15657 (message "%d entries before %s"
15658 (org-occur regexp nil callback) date)))
15660 (defun org-check-after-date (date)
15661 "Check if there are deadlines or scheduled entries after DATE."
15662 (interactive (list (org-read-date)))
15663 (let ((case-fold-search nil)
15664 (regexp (concat "\\<\\(" org-deadline-string
15665 "\\|" org-scheduled-string
15666 "\\) *<\\([^>]+\\)>"))
15670 (org-time-string-to-time (match-string 2))
15671 (org-time-string-to-time date))))))
15672 (message "%d entries after %s"
15673 (org-occur regexp nil callback) date)))
15675 (defun org-check-dates-range (start-date end-date)
15676 "Check for deadlines/scheduled entries between START-DATE and END-DATE."
15677 (interactive (list (org-read-date nil nil nil "Range starts")
15678 (org-read-date nil nil nil "Range end")))
15679 (let ((case-fold-search nil)
15680 (regexp (concat "\\<\\(" org-deadline-string
15681 "\\|" org-scheduled-string
15682 "\\) *<\\([^>]+\\)>"))
15685 (let ((match (match-string 2)))
15688 (org-time-string-to-time match)
15689 (org-time-string-to-time start-date)))
15691 (org-time-string-to-time match)
15692 (org-time-string-to-time end-date)))))))
15693 (message "%d entries between %s and %s"
15694 (org-occur regexp nil callback) start-date end-date)))
15696 (defun org-evaluate-time-range (&optional to-buffer)
15697 "Evaluate a time range by computing the difference between start and end.
15698 Normally the result is just printed in the echo area, but with prefix arg
15699 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
15700 If the time range is actually in a table, the result is inserted into the
15702 For time difference computation, a year is assumed to be exactly 365
15703 days in order to avoid rounding problems."
15706 (org-clock-update-time-maybe)
15708 (unless (org-at-date-range-p t)
15709 (goto-char (point-at-bol))
15710 (re-search-forward org-tr-regexp-both (point-at-eol) t))
15711 (if (not (org-at-date-range-p t))
15712 (error "Not at a time-stamp range, and none found in current line")))
15713 (let* ((ts1 (match-string 1))
15714 (ts2 (match-string 2))
15715 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
15716 (match-end (match-end 0))
15717 (time1 (org-time-string-to-time ts1))
15718 (time2 (org-time-string-to-time ts2))
15719 (t1 (org-float-time time1))
15720 (t2 (org-float-time time2))
15721 (diff (abs (- t2 t1)))
15722 (negative (< (- t2 t1) 0))
15723 ;; (ys (floor (* 365 24 60 60)))
15726 (fy "%dy %dd %02d:%02d")
15728 (fd "%dd %02d:%02d")
15733 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
15735 d (floor (/ diff ds)) diff (mod diff ds)
15736 h (floor (/ diff hs)) diff (mod diff hs)
15737 m (floor (/ diff 60)))
15738 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
15740 d (floor (+ (/ diff ds) 0.5))
15742 (if (not to-buffer)
15743 (message "%s" (org-make-tdiff-string y d h m))
15744 (if (org-at-table-p)
15746 (goto-char match-end)
15748 (and (looking-at " *|") (goto-char (match-end 0))))
15749 (goto-char match-end))
15751 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
15752 (replace-match ""))
15753 (if negative (insert " -"))
15754 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
15755 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
15756 (insert " " (format fh h m))))
15757 (if align (org-table-align))
15758 (message "Time difference inserted")))))
15760 (defun org-make-tdiff-string (y d h m)
15763 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
15765 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
15767 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
15769 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
15771 (apply 'format fmt (nreverse l))))
15773 (defun org-time-string-to-time (s &optional buffer pos)
15774 (condition-case errdata
15775 (apply 'encode-time (org-parse-time-string s))
15776 (error (error "Bad timestamp `%s'%s\nError was: %s"
15777 s (if (not (and buffer pos))
15779 (format " at %d in buffer `%s'" pos buffer))
15782 (defun org-time-string-to-seconds (s)
15783 (org-float-time (org-time-string-to-time s)))
15785 (defun org-time-string-to-absolute (s &optional daynr prefer show-all buffer pos)
15786 "Convert a time stamp to an absolute day number.
15787 If there is a specifier for a cyclic time stamp, get the closest date to
15789 PREFER and SHOW-ALL are passed through to `org-closest-date'.
15790 The variable date is bound by the calendar when this is called."
15792 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
15793 (if (org-diary-sexp-entry (match-string 1 s) "" date)
15796 ((and daynr (string-match "\\+[0-9]+[dwmy]" s))
15797 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
15798 (time-to-days (current-time))) (match-string 0 s)
15801 (condition-case errdata
15802 (apply 'encode-time (org-parse-time-string s))
15803 (error (error "Bad timestamp `%s'%s\nError was: %s"
15804 s (if (not (and buffer pos))
15806 (format " at %d in buffer `%s'" pos buffer))
15807 (cdr errdata))))))))
15809 (defun org-days-to-iso-week (days)
15810 "Return the iso week number."
15812 (car (calendar-iso-from-absolute days)))
15814 (defun org-small-year-to-year (year)
15815 "Convert 2-digit years into 4-digit years.
15816 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
15817 The year 2000 cannot be abbreviated. Any year larger than 99
15818 is returned unchanged."
15820 (setq year (+ 2000 year))
15822 (setq year (+ 1900 year))))
15825 (defun org-time-from-absolute (d)
15826 "Return the time corresponding to date D.
15827 D may be an absolute day number, or a calendar-type list (month day year)."
15828 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
15829 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
15831 (defun org-calendar-holiday ()
15832 "List of holidays, for Diary display in Org-mode."
15833 (require 'holidays)
15835 (if (fboundp 'calendar-check-holidays)
15836 'calendar-check-holidays 'check-calendar-holidays) date)))
15837 (if hl (mapconcat 'identity hl "; "))))
15839 (defun org-diary-sexp-entry (sexp entry date)
15840 "Process a SEXP diary ENTRY for DATE."
15841 (require 'diary-lib)
15842 (let ((result (if calendar-debug-sexp
15843 (let ((stack-trace-on-error t))
15844 (eval (car (read-from-string sexp))))
15845 (condition-case nil
15846 (eval (car (read-from-string sexp)))
15849 (message "Bad sexp at line %d in %s: %s"
15851 (buffer-file-name) sexp)
15853 (cond ((stringp result) (split-string result "; "))
15854 ((and (consp result)
15855 (not (consp (cdr result)))
15856 (stringp (cdr result))) (cdr result))
15857 ((and (consp result)
15858 (stringp (car result))) result)
15862 (defun org-diary-to-ical-string (frombuf)
15863 "Get iCalendar entries from diary entries in buffer FROMBUF.
15864 This uses the icalendar.el library."
15865 (let* ((tmpdir (if (featurep 'xemacs)
15867 temporary-file-directory))
15868 (tmpfile (make-temp-name
15869 (expand-file-name "orgics" tmpdir)))
15871 (with-current-buffer frombuf
15872 (icalendar-export-region (point-min) (point-max) tmpfile)
15873 (setq buf (find-buffer-visiting tmpfile))
15875 (goto-char (point-min))
15876 (if (re-search-forward "^BEGIN:VEVENT" nil t)
15877 (setq b (match-beginning 0)))
15878 (goto-char (point-max))
15879 (if (re-search-backward "^END:VEVENT" nil t)
15880 (setq e (match-end 0)))
15881 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
15883 (delete-file tmpfile)
15886 (defun org-closest-date (start current change prefer show-all)
15887 "Find the date closest to CURRENT that is consistent with START and CHANGE.
15888 When PREFER is `past', return a date that is either CURRENT or past.
15889 When PREFER is `future', return a date that is either CURRENT or future.
15890 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
15891 ;; Make the proper lists from the dates
15893 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
15894 dn dw sday cday n1 n2 n0
15895 d m y y1 y2 date1 date2 nmonths nm ny m2)
15897 (setq start (org-date-to-gregorian start)
15898 current (org-date-to-gregorian
15901 (time-to-days (current-time))))
15902 sday (calendar-absolute-from-gregorian start)
15903 cday (calendar-absolute-from-gregorian current))
15905 (if (<= cday sday) (throw 'exit sday))
15907 (if (string-match "\\(\\+[0-9]+\\)\\([dwmy]\\)" change)
15908 (setq dn (string-to-number (match-string 1 change))
15909 dw (cdr (assoc (match-string 2 change) a1)))
15910 (error "Invalid change specifier: %s" change))
15911 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
15914 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
15917 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
15918 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
15919 (setq date1 (list m d y1)
15920 n1 (calendar-absolute-from-gregorian date1)
15921 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
15922 n2 (calendar-absolute-from-gregorian date2)))
15924 ;; approx number of month between the two dates
15925 (setq nmonths (floor (/ (- cday sday) 30.436875)))
15926 ;; How often does dn fit in there?
15927 (setq d (nth 1 start) m (car start) y (nth 2 start)
15928 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
15930 ny (floor (/ m 12))
15933 (while (> m 12) (setq m (- m 12) y (1+ y)))
15934 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
15935 (setq m2 (+ m dn) y2 y)
15936 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
15937 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
15938 (while (<= n2 cday)
15939 (setq n1 n2 m m2 y y2)
15940 (setq m2 (+ m dn) y2 y)
15941 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
15942 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
15943 ;; Make sure n1 is the earlier date
15944 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
15947 ((eq prefer 'past) (if (= cday n2) n2 n1))
15948 ((eq prefer 'future) (if (= cday n1) n1 n2))
15949 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
15951 ((eq prefer 'past) (if (= cday n2) n2 n1))
15952 ((eq prefer 'future) (if (= cday n1) n1 n2))
15953 (t (if (= cday n1) n1 n2)))))))
15955 (defun org-date-to-gregorian (date)
15956 "Turn any specification of DATE into a Gregorian date for the calendar."
15957 (cond ((integerp date) (calendar-gregorian-from-absolute date))
15958 ((and (listp date) (= (length date) 3)) date)
15960 (setq date (org-parse-time-string date))
15961 (list (nth 4 date) (nth 3 date) (nth 5 date)))
15963 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
15965 (defun org-parse-time-string (s &optional nodefault)
15966 "Parse the standard Org-mode time string.
15967 This should be a lot faster than the normal `parse-time-string'.
15968 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
15969 hour and minute fields will be nil if not given."
15970 (if (string-match org-ts-regexp0 s)
15972 (if (or (match-beginning 8) (not nodefault))
15973 (string-to-number (or (match-string 8 s) "0")))
15974 (if (or (match-beginning 7) (not nodefault))
15975 (string-to-number (or (match-string 7 s) "0")))
15976 (string-to-number (match-string 4 s))
15977 (string-to-number (match-string 3 s))
15978 (string-to-number (match-string 2 s))
15980 (error "Not a standard Org-mode time string: %s" s)))
15982 (defun org-timestamp-up (&optional arg)
15983 "Increase the date item at the cursor by one.
15984 If the cursor is on the year, change the year. If it is on the month,
15985 the day or the time, change that.
15986 With prefix ARG, change by that many units."
15988 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
15990 (defun org-timestamp-down (&optional arg)
15991 "Decrease the date item at the cursor by one.
15992 If the cursor is on the year, change the year. If it is on the month,
15993 the day or the time, change that.
15994 With prefix ARG, change by that many units."
15996 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
15998 (defun org-timestamp-up-day (&optional arg)
15999 "Increase the date in the time stamp by one day.
16000 With prefix ARG, change that many days."
16002 (if (and (not (org-at-timestamp-p t))
16003 (org-at-heading-p))
16005 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
16007 (defun org-timestamp-down-day (&optional arg)
16008 "Decrease the date in the time stamp by one day.
16009 With prefix ARG, change that many days."
16011 (if (and (not (org-at-timestamp-p t))
16012 (org-at-heading-p))
16014 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
16016 (defun org-at-timestamp-p (&optional inactive-ok)
16017 "Determine if the cursor is in or at a timestamp."
16019 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
16021 (ans (or (looking-at tsr)
16023 (skip-chars-backward "^[<\n\r\t")
16024 (if (> (point) (point-min)) (backward-char 1))
16025 (and (looking-at tsr)
16026 (> (- (match-end 0) pos) -1))))))
16028 (boundp 'org-ts-what)
16031 ((= pos (match-beginning 0)) 'bracket)
16032 ;; Point is considered to be "on the bracket" whether
16033 ;; it's really on it or right after it.
16034 ((or (= pos (1- (match-end 0)))
16035 (= pos (match-end 0))) 'bracket)
16036 ((org-pos-in-match-range pos 2) 'year)
16037 ((org-pos-in-match-range pos 3) 'month)
16038 ((org-pos-in-match-range pos 7) 'hour)
16039 ((org-pos-in-match-range pos 8) 'minute)
16040 ((or (org-pos-in-match-range pos 4)
16041 (org-pos-in-match-range pos 5)) 'day)
16042 ((and (> pos (or (match-end 8) (match-end 5)))
16043 (< pos (match-end 0)))
16044 (- pos (or (match-end 8) (match-end 5))))
16048 (defun org-toggle-timestamp-type ()
16049 "Toggle the type (<active> or [inactive]) of a time stamp."
16051 (when (org-at-timestamp-p t)
16052 (let ((beg (match-beginning 0)) (end (match-end 0))
16053 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
16056 (while (re-search-forward "[][<>]" end t)
16057 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
16059 (message "Timestamp is now %sactive"
16060 (if (equal (char-after beg) ?<) "" "in")))))
16062 (defun org-timestamp-change (n &optional what updown)
16063 "Change the date in the time stamp at point.
16064 The date will be changed by N times WHAT. WHAT can be `day', `month',
16065 `year', `minute', `second'. If WHAT is not given, the cursor position
16066 in the timestamp determines what will be changed."
16067 (let ((origin (point)) origin-cat
16069 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
16073 (if (not (org-at-timestamp-p t))
16074 (error "Not at a timestamp"))
16075 (if (and (not what) (eq org-ts-what 'bracket))
16076 (org-toggle-timestamp-type)
16077 ;; Point isn't on brackets. Remember the part of the time-stamp
16078 ;; the point was in. Indeed, size of time-stamps may change,
16079 ;; but point must be kept in the same category nonetheless.
16080 (setq origin-cat org-ts-what)
16081 (if (and (not what) (not (eq org-ts-what 'day))
16082 org-display-custom-times
16083 (get-text-property (point) 'display)
16084 (not (get-text-property (1- (point)) 'display)))
16085 (setq org-ts-what 'day))
16086 (setq org-ts-what (or what org-ts-what)
16087 inactive (= (char-after (match-beginning 0)) ?\[)
16088 ts (match-string 0))
16091 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[dwmy]\\(/[0-9]+[dwmy]\\)?\\)*\\)[]>]"
16093 (setq extra (match-string 1 ts)))
16094 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
16096 (setq time0 (org-parse-time-string ts))
16098 (eq org-ts-what 'minute)
16099 (not current-prefix-arg))
16100 ;; This looks like s-up and s-down. Change by one rounding step.
16101 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
16102 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
16103 (setcar (cdr time0) (+ (nth 1 time0)
16104 (if (> n 0) (- rem) (- dm rem))))))
16106 (encode-time (or (car time0) 0)
16107 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
16108 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
16109 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
16110 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
16111 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
16113 (when (and (member org-ts-what '(hour minute))
16115 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
16116 (setq extra (org-modify-ts-extra
16118 (if (eq org-ts-what 'hour) 2 5)
16120 (when (integerp org-ts-what)
16121 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
16122 (if (eq what 'calendar)
16123 (let ((cal-date (org-get-date-from-calendar)))
16124 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
16125 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
16126 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
16127 (setcar time0 (or (car time0) 0))
16128 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
16129 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
16130 (setq time (apply 'encode-time time0))))
16131 ;; Insert the new time-stamp, and ensure point stays in the same
16132 ;; category as before (i.e. not after the last position in that
16134 (let ((pos (point)))
16135 ;; Stay before inserted string. `save-excursion' is of no use.
16136 (setq org-last-changed-timestamp
16137 (org-insert-time-stamp time with-hm inactive nil nil extra))
16140 (looking-at org-ts-regexp3)
16142 ;; `day' category ends before `hour' if any, or at
16143 ;; the end of the day name.
16144 ((eq origin-cat 'day)
16145 (min (or (match-beginning 7) (1- (match-end 5))) origin))
16146 ((eq origin-cat 'hour) (min (match-end 7) origin))
16147 ((eq origin-cat 'minute) (min (1- (match-end 8)) origin))
16148 ((integerp origin-cat) (min (1- (match-end 0)) origin))
16149 ;; `year' and `month' have both fixed size: point
16150 ;; couldn't have moved into another part.
16152 ;; Update clock if on a CLOCK line.
16153 (org-clock-update-time-maybe)
16154 ;; Try to recenter the calendar window, if any.
16155 (if (and org-calendar-follow-timestamp-change
16156 (get-buffer-window "*Calendar*" t)
16157 (memq org-ts-what '(day month year)))
16158 (org-recenter-calendar (time-to-days time))))))
16160 (defun org-modify-ts-extra (s pos n dm)
16161 "Change the different parts of the lead-time and repeat fields in timestamp."
16162 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
16164 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
16166 ((or (org-pos-in-match-range pos 2)
16167 (org-pos-in-match-range pos 3))
16168 (setq m (string-to-number (match-string 3 s))
16169 h (string-to-number (match-string 2 s)))
16170 (if (org-pos-in-match-range pos 2)
16172 (setq n (* dm (org-no-warnings (signum n))))
16173 (when (not (= 0 (setq rem (% m dm))))
16174 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
16176 (if (< m 0) (setq m (+ m 60) h (1- h)))
16177 (if (> m 59) (setq m (- m 60) h (1+ h)))
16178 (setq h (min 24 (max 0 h)))
16179 (setq ng 1 new (format "-%02d:%02d" h m)))
16180 ((org-pos-in-match-range pos 6)
16181 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
16182 ((org-pos-in-match-range pos 5)
16183 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
16185 ((org-pos-in-match-range pos 9)
16186 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
16187 ((org-pos-in-match-range pos 8)
16188 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
16192 (substring s 0 (match-beginning ng))
16194 (substring s (match-end ng))))))
16197 (defun org-recenter-calendar (date)
16198 "If the calendar is visible, recenter it to DATE."
16199 (let ((cwin (get-buffer-window "*Calendar*" t)))
16201 (let ((calendar-move-hook nil))
16202 (with-selected-window cwin
16203 (calendar-goto-date (if (listp date) date
16204 (calendar-gregorian-from-absolute date))))))))
16206 (defun org-goto-calendar (&optional arg)
16207 "Go to the Emacs calendar at the current date.
16208 If there is a time stamp in the current line, go to that date.
16209 A prefix ARG can be used to force the current date."
16211 (let ((tsr org-ts-regexp) diff
16212 (calendar-move-hook nil)
16213 (calendar-view-holidays-initially-flag nil)
16214 (calendar-view-diary-initially-flag nil))
16215 (if (or (org-at-timestamp-p)
16217 (beginning-of-line 1)
16218 (looking-at (concat ".*" tsr))))
16219 (let ((d1 (time-to-days (current-time)))
16221 (org-time-string-to-time (match-string 1)))))
16222 (setq diff (- d2 d1))))
16224 (calendar-goto-today)
16225 (if (and diff (not arg)) (calendar-forward-day diff))))
16227 (defun org-get-date-from-calendar ()
16228 "Return a list (month day year) of date at point in calendar."
16229 (with-current-buffer "*Calendar*"
16231 (calendar-cursor-to-date))))
16233 (defun org-date-from-calendar ()
16234 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
16235 If there is already a time stamp at the cursor position, update it."
16237 (if (org-at-timestamp-p t)
16238 (org-timestamp-change 0 'calendar)
16239 (let ((cal-date (org-get-date-from-calendar)))
16240 (org-insert-time-stamp
16241 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
16243 (defun org-minutes-to-hh:mm-string (m)
16244 "Compute H:MM from a number of minutes."
16245 (let ((h (/ m 60)))
16246 (setq m (- m (* 60 h)))
16247 (format org-time-clocksum-format h m)))
16249 (defun org-hh:mm-string-to-minutes (s)
16250 "Convert a string H:MM to a number of minutes.
16251 If the string is just a number, interpret it as minutes.
16252 In fact, the first hh:mm or number in the string will be taken,
16253 there can be extra stuff in the string.
16254 If no number is found, the return value is 0."
16257 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
16258 (+ (* (string-to-number (match-string 1 s)) 60)
16259 (string-to-number (match-string 2 s))))
16260 ((string-match "\\([0-9]+\\)" s)
16261 (string-to-number (match-string 1 s)))
16264 (defcustom org-effort-durations
16267 ("w" . ,(* 60 8 5))
16268 ("m" . ,(* 60 8 5 4))
16269 ("y" . ,(* 60 8 5 40)))
16270 "Conversion factor to minutes for an effort modifier.
16272 Each entry has the form (MODIFIER . MINUTES).
16274 In an effort string, a number followed by MODIFIER is multiplied
16275 by the specified number of MINUTES to obtain an effort in
16278 For example, if the value of this variable is ((\"hours\" . 60)), then an
16279 effort string \"2hours\" is equivalent to 120 minutes."
16282 :type '(alist :key-type (string :tag "Modifier")
16283 :value-type (number :tag "Minutes")))
16285 (defun org-duration-string-to-minutes (s)
16286 "Convert a duration string S to minutes.
16288 A bare number is interpreted as minutes, modifiers can be set by
16289 customizing `org-effort-durations' (which see).
16291 Entries containing a colon are interpreted as H:MM by
16292 `org-hh:mm-string-to-minutes'."
16294 (re (concat "\\([0-9]+\\) *\\("
16295 (regexp-opt (mapcar 'car org-effort-durations))
16297 (while (string-match re s)
16298 (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
16299 (string-to-number (match-string 1 s))))
16300 (setq s (replace-match "" nil t s)))
16301 (incf result (org-hh:mm-string-to-minutes s))
16306 (defun org-save-all-org-buffers ()
16307 "Save all Org-mode buffers without user confirmation."
16309 (message "Saving all Org-mode buffers...")
16310 (save-some-buffers t (lambda () (eq major-mode 'org-mode)))
16311 (when (featurep 'org-id) (org-id-locations-save))
16312 (message "Saving all Org-mode buffers... done"))
16314 (defun org-revert-all-org-buffers ()
16315 "Revert all Org-mode buffers.
16316 Prompt for confirmation when there are unsaved changes.
16317 Be sure you know what you are doing before letting this function
16318 overwrite your changes.
16320 This function is useful in a setup where one tracks org files
16321 with a version control system, to revert on one machine after pulling
16322 changes from another. I believe the procedure must be like this:
16324 1. M-x org-save-all-org-buffers
16325 2. Pull changes from the other machine, resolve conflicts
16326 3. M-x org-revert-all-org-buffers"
16328 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
16331 (save-window-excursion
16334 (when (and (with-current-buffer b (eq major-mode 'org-mode))
16335 (with-current-buffer b buffer-file-name))
16336 (org-pop-to-buffer-same-window b)
16337 (revert-buffer t 'no-confirm)))
16339 (when (and (featurep 'org-id) org-id-track-globally)
16340 (org-id-locations-load)))))
16345 (defun org-switchb (&optional arg)
16346 "Switch between Org buffers.
16347 With one prefix argument, restrict available buffers to files.
16348 With two prefix arguments, restrict available buffers to agenda files.
16350 Defaults to `iswitchb' for buffer name completion.
16351 Set `org-completion-use-ido' to make it use ido instead."
16353 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
16354 ((equal arg '(16)) (org-buffer-list 'agenda))
16355 (t (org-buffer-list))))
16356 (org-completion-use-iswitchb org-completion-use-iswitchb)
16357 (org-completion-use-ido org-completion-use-ido))
16358 (unless (or org-completion-use-ido org-completion-use-iswitchb)
16359 (setq org-completion-use-iswitchb t))
16360 (org-pop-to-buffer-same-window
16361 (org-icompleting-read "Org buffer: "
16362 (mapcar 'list (mapcar 'buffer-name blist))
16365 ;;; Define some older names previously used for this functionality
16367 (defalias 'org-ido-switchb 'org-switchb)
16369 (defalias 'org-iswitchb 'org-switchb)
16371 (defun org-buffer-list (&optional predicate exclude-tmp)
16372 "Return a list of Org buffers.
16373 PREDICATE can be `export', `files' or `agenda'.
16375 export restrict the list to Export buffers.
16376 files restrict the list to buffers visiting Org files.
16377 agenda restrict the list to buffers visiting agenda files.
16379 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
16381 (agenda-files (and (eq predicate 'agenda)
16382 (mapcar 'file-truename (org-agenda-files t))))
16385 ((eq predicate 'files)
16386 (lambda (b) (with-current-buffer b (eq major-mode 'org-mode))))
16387 ((eq predicate 'export)
16388 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
16389 ((eq predicate 'agenda)
16391 (with-current-buffer b
16392 (and (eq major-mode 'org-mode)
16393 (setq bfn (buffer-file-name b))
16394 (member (file-truename bfn) agenda-files)))))
16395 (t (lambda (b) (with-current-buffer b
16396 (or (eq major-mode 'org-mode)
16397 (string-match "\*Org .*Export"
16398 (buffer-name b)))))))))
16402 (if (and (funcall filter b)
16403 (or (not exclude-tmp)
16404 (not (string-match "tmp" (buffer-name b)))))
16409 (defun org-agenda-files (&optional unrestricted archives)
16410 "Get the list of agenda files.
16411 Optional UNRESTRICTED means return the full list even if a restriction
16412 is currently in place.
16413 When ARCHIVES is t, include all archive files that are really being
16414 used by the agenda files. If ARCHIVE is `ifmode', do this only if
16415 `org-agenda-archives-mode' is t."
16418 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
16419 ((stringp org-agenda-files) (org-read-agenda-file-list))
16420 ((listp org-agenda-files) org-agenda-files)
16421 (t (error "Invalid value of `org-agenda-files'")))))
16422 (setq files (apply 'append
16423 (mapcar (lambda (f)
16424 (if (file-directory-p f)
16426 f t org-agenda-file-regexp)
16429 (when org-agenda-skip-unavailable-files
16430 (setq files (delq nil
16433 (and (file-readable-p file) file)))
16435 (when (or (eq archives t)
16436 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
16437 (setq files (org-add-archive-files files)))
16440 (defun org-agenda-file-p (&optional file)
16441 "Return non-nil, if FILE is an agenda file.
16442 If FILE is omitted, use the file associated with the current
16444 (member (or file (buffer-file-name))
16445 (org-agenda-files t)))
16447 (defun org-edit-agenda-file-list ()
16448 "Edit the list of agenda files.
16449 Depending on setup, this either uses customize to edit the variable
16450 `org-agenda-files', or it visits the file that is holding the list. In the
16451 latter case, the buffer is set up in a way that saving it automatically kills
16452 the buffer and restores the previous window configuration."
16454 (if (stringp org-agenda-files)
16455 (let ((cw (current-window-configuration)))
16456 (find-file org-agenda-files)
16457 (org-set-local 'org-window-configuration cw)
16458 (org-add-hook 'after-save-hook
16460 (set-window-configuration
16461 (prog1 org-window-configuration
16462 (kill-buffer (current-buffer))))
16463 (org-install-agenda-files-menu)
16464 (message "New agenda file list installed"))
16466 (message "%s" (substitute-command-keys
16467 "Edit list and finish with \\[save-buffer]")))
16468 (customize-variable 'org-agenda-files)))
16470 (defun org-store-new-agenda-file-list (list)
16471 "Set new value for the agenda file list and save it correctly."
16472 (if (stringp org-agenda-files)
16473 (let ((fe (org-read-agenda-file-list t)) b u)
16474 (while (setq b (find-buffer-visiting org-agenda-files))
16476 (with-temp-file org-agenda-files
16479 (lambda (f) ;; Keep un-expanded entries.
16480 (if (setq u (assoc f fe))
16485 (let ((org-mode-hook nil) (org-inhibit-startup t)
16486 (org-insert-mode-line-in-empty-file nil))
16487 (setq org-agenda-files list)
16488 (customize-save-variable 'org-agenda-files org-agenda-files))))
16490 (defun org-read-agenda-file-list (&optional pair-with-expansion)
16491 "Read the list of agenda files from a file.
16492 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
16493 filenames, used by `org-store-new-agenda-file-list' to write back
16494 un-expanded file names."
16495 (when (file-directory-p org-agenda-files)
16496 (error "`org-agenda-files' cannot be a single directory"))
16497 (when (stringp org-agenda-files)
16499 (insert-file-contents org-agenda-files)
16502 (let ((e (expand-file-name (substitute-in-file-name f)
16504 (if pair-with-expansion
16507 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
16510 (defun org-cycle-agenda-files ()
16511 "Cycle through the files in `org-agenda-files'.
16512 If the current buffer visits an agenda file, find the next one in the list.
16513 If the current buffer does not, find the first agenda file."
16515 (let* ((fs (org-agenda-files t))
16516 (files (append fs (list (car fs))))
16517 (tcf (if buffer-file-name (file-truename buffer-file-name)))
16519 (unless files (error "No agenda files"))
16521 (while (setq file (pop files))
16522 (if (equal (file-truename file) tcf)
16524 (find-file (car files))
16526 (find-file (car fs)))
16527 (if (buffer-base-buffer) (org-pop-to-buffer-same-window (buffer-base-buffer)))))
16529 (defun org-agenda-file-to-front (&optional to-end)
16530 "Move/add the current file to the top of the agenda file list.
16531 If the file is not present in the list, it is added to the front. If it is
16532 present, it is moved there. With optional argument TO-END, add/move to the
16535 (let ((org-agenda-skip-unavailable-files nil)
16536 (file-alist (mapcar (lambda (x)
16537 (cons (file-truename x) x))
16538 (org-agenda-files t)))
16539 (ctf (file-truename buffer-file-name))
16541 (setq x (assoc ctf file-alist) had x)
16543 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
16545 (setq file-alist (append (delq x file-alist) (list x)))
16546 (setq file-alist (cons x (delq x file-alist))))
16547 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
16548 (org-install-agenda-files-menu)
16549 (message "File %s to %s of agenda file list"
16550 (if had "moved" "added") (if to-end "end" "front"))))
16552 (defun org-remove-file (&optional file)
16553 "Remove current file from the list of files in variable `org-agenda-files'.
16554 These are the files which are being checked for agenda entries.
16555 Optional argument FILE means use this file instead of the current."
16557 (let* ((org-agenda-skip-unavailable-files nil)
16558 (file (or file buffer-file-name))
16559 (true-file (file-truename file))
16560 (afile (abbreviate-file-name file))
16561 (files (delq nil (mapcar
16563 (if (equal true-file
16566 (org-agenda-files t)))))
16567 (if (not (= (length files) (length (org-agenda-files t))))
16569 (org-store-new-agenda-file-list files)
16570 (org-install-agenda-files-menu)
16571 (message "Removed file: %s" afile))
16572 (message "File was not in list: %s (not removed)" afile))))
16574 (defun org-file-menu-entry (file)
16575 (vector file (list 'find-file file) t))
16577 (defun org-check-agenda-file (file)
16578 "Make sure FILE exists. If not, ask user what to do."
16579 (when (not (file-exists-p file))
16580 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
16581 (abbreviate-file-name file))
16582 (let ((r (downcase (read-char-exclusive))))
16585 (org-remove-file file)
16586 (throw 'nextfile t))
16587 (t (error "Abort"))))))
16589 (defun org-get-agenda-file-buffer (file)
16590 "Get a buffer visiting FILE. If the buffer needs to be created, add
16591 it to the list of buffers which might be released later."
16592 (let ((buf (org-find-base-buffer-visiting file)))
16594 buf ; just return it
16595 ;; Make a new buffer and remember it
16596 (setq buf (find-file-noselect file))
16597 (if buf (push buf org-agenda-new-buffers))
16600 (defun org-release-buffers (blist)
16601 "Release all buffers in list, asking the user for confirmation when needed.
16602 When a buffer is unmodified, it is just killed. When modified, it is saved
16603 \(if the user agrees) and then killed."
16605 (while (setq buf (pop blist))
16606 (setq file (buffer-file-name buf))
16607 (when (and (buffer-modified-p buf)
16609 (y-or-n-p (format "Save file %s? " file)))
16610 (with-current-buffer buf (save-buffer)))
16611 (kill-buffer buf))))
16613 (defun org-prepare-agenda-buffers (files)
16614 "Create buffers for all agenda files, protect archived trees and comments."
16616 (let ((pa '(:org-archived t))
16617 (pc '(:org-comment t))
16618 (pall '(:org-archived t :org-comment t))
16619 (inhibit-read-only t)
16620 (rea (concat ":" org-archive-tag ":"))
16624 (while (setq file (pop files))
16628 (org-check-agenda-file file)
16629 (set-buffer (org-get-agenda-file-buffer file)))
16631 (setq bmp (buffer-modified-p))
16632 (org-refresh-category-properties)
16633 (setq org-todo-keywords-for-agenda
16634 (append org-todo-keywords-for-agenda org-todo-keywords-1))
16635 (setq org-done-keywords-for-agenda
16636 (append org-done-keywords-for-agenda org-done-keywords))
16637 (setq org-todo-keyword-alist-for-agenda
16638 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
16639 (setq org-drawers-for-agenda
16640 (append org-drawers-for-agenda org-drawers))
16641 (setq org-tag-alist-for-agenda
16642 (append org-tag-alist-for-agenda org-tag-alist))
16645 (remove-text-properties (point-min) (point-max) pall)
16646 (when org-agenda-skip-archived-trees
16647 (goto-char (point-min))
16648 (while (re-search-forward rea nil t)
16649 (if (org-at-heading-p t)
16650 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
16651 (goto-char (point-min))
16652 (setq re (format org-heading-keyword-regexp-format
16653 org-comment-string))
16654 (while (re-search-forward re nil t)
16655 (add-text-properties
16656 (match-beginning 0) (org-end-of-subtree t) pc)))
16657 (set-buffer-modified-p bmp)))))
16658 (setq org-todo-keywords-for-agenda
16659 (org-uniquify org-todo-keywords-for-agenda))
16660 (setq org-todo-keyword-alist-for-agenda
16661 (org-uniquify org-todo-keyword-alist-for-agenda)
16662 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
16664 ;;;; Embedded LaTeX
16666 (defvar org-cdlatex-mode-map (make-sparse-keymap)
16667 "Keymap for the minor `org-cdlatex-mode'.")
16669 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
16670 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
16671 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
16672 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
16673 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
16675 (defvar org-cdlatex-texmathp-advice-is-done nil
16676 "Flag remembering if we have applied the advice to texmathp already.")
16678 (define-minor-mode org-cdlatex-mode
16679 "Toggle the minor `org-cdlatex-mode'.
16680 This mode supports entering LaTeX environment and math in LaTeX fragments
16682 \\{org-cdlatex-mode-map}"
16684 (when org-cdlatex-mode
16686 (run-hooks 'cdlatex-mode-hook)
16687 (cdlatex-compute-tables))
16688 (unless org-cdlatex-texmathp-advice-is-done
16689 (setq org-cdlatex-texmathp-advice-is-done t)
16690 (defadvice texmathp (around org-math-always-on activate)
16691 "Always return t in org-mode buffers.
16692 This is because we want to insert math symbols without dollars even outside
16693 the LaTeX math segments. If Orgmode thinks that point is actually inside
16694 an embedded LaTeX fragment, let texmathp do its job.
16695 \\[org-cdlatex-mode-map]"
16699 ((not (eq major-mode 'org-mode)) ad-do-it)
16700 ((eq this-command 'cdlatex-math-symbol)
16701 (setq ad-return-value t
16702 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
16704 (let ((p (org-inside-LaTeX-fragment-p)))
16705 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
16706 (setq ad-return-value t
16707 texmathp-why '("Org-mode embedded math" . 0))
16708 (if p ad-do-it)))))))))
16710 (defun turn-on-org-cdlatex ()
16711 "Unconditionally turn on `org-cdlatex-mode'."
16712 (org-cdlatex-mode 1))
16714 (defun org-inside-LaTeX-fragment-p ()
16715 "Test if point is inside a LaTeX fragment.
16716 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
16717 sequence appearing also before point.
16718 Even though the matchers for math are configurable, this function assumes
16719 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
16720 delimiters are skipped when they have been removed by customization.
16721 The return value is nil, or a cons cell with the delimiter and the
16722 position of this delimiter.
16724 This function does a reasonably good job, but can locally be fooled by
16725 for example currency specifications. For example it will assume being in
16726 inline math after \"$22.34\". The LaTeX fragment formatter will only format
16727 fragments that are properly closed, but during editing, we have to live
16728 with the uncertainty caused by missing closing delimiters. This function
16729 looks only before point, not after."
16731 (let ((pos (point))
16732 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
16734 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
16736 dd-on str (start 0) m re)
16739 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
16740 re (nth 1 (assoc "$" org-latex-regexps)))
16741 (while (string-match re str start)
16743 ((= (match-end 0) (length str))
16744 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
16745 ((= (match-end 0) (- (length str) 5))
16747 (t (setq start (match-end 0))))))
16748 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
16750 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
16751 (and (match-beginning 2) (throw 'exit nil))
16753 (while (re-search-backward "\\$\\$" lim t)
16754 (setq dd-on (not dd-on)))
16756 (if dd-on (cons "$$" m))))))
16758 (defun org-inside-latex-macro-p ()
16759 "Is point inside a LaTeX macro or its arguments?"
16762 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
16764 (defun org-try-cdlatex-tab ()
16765 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
16766 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
16767 - inside a LaTeX fragment, or
16768 - after the first word in a line, where an abbreviation expansion could
16769 insert a LaTeX environment."
16770 (when org-cdlatex-mode
16772 ;; Before any word on the line: No expansion possible.
16773 ((save-excursion (skip-chars-backward " \t") (bolp)) nil)
16774 ;; Just after first word on the line: Expand it. Make sure it
16775 ;; cannot happen on headlines, though.
16777 (skip-chars-backward "a-zA-Z0-9*")
16778 (skip-chars-backward " \t")
16779 (and (bolp) (not (org-at-heading-p))))
16781 ((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
16783 (defun org-cdlatex-underscore-caret (&optional arg)
16784 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
16785 Revert to the normal definition outside of these fragments."
16787 (if (org-inside-LaTeX-fragment-p)
16788 (call-interactively 'cdlatex-sub-superscript)
16789 (let (org-cdlatex-mode)
16790 (call-interactively (key-binding (vector last-input-event))))))
16792 (defun org-cdlatex-math-modify (&optional arg)
16793 "Execute `cdlatex-math-modify' in LaTeX fragments.
16794 Revert to the normal definition outside of these fragments."
16796 (if (org-inside-LaTeX-fragment-p)
16797 (call-interactively 'cdlatex-math-modify)
16798 (let (org-cdlatex-mode)
16799 (call-interactively (key-binding (vector last-input-event))))))
16801 (defvar org-latex-fragment-image-overlays nil
16802 "List of overlays carrying the images of latex fragments.")
16803 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
16805 (defun org-remove-latex-fragment-image-overlays ()
16806 "Remove all overlays with LaTeX fragment images in current buffer."
16807 (mapc 'delete-overlay org-latex-fragment-image-overlays)
16808 (setq org-latex-fragment-image-overlays nil))
16810 (defun org-preview-latex-fragment (&optional subtree)
16811 "Preview the LaTeX fragment at point, or all locally or globally.
16812 If the cursor is in a LaTeX fragment, create the image and overlay
16813 it over the source code. If there is no fragment at point, display
16814 all fragments in the current text, from one headline to the next. With
16815 prefix SUBTREE, display all fragments in the current subtree. With a
16816 double prefix arg \\[universal-argument] \\[universal-argument], or when \
16817 the cursor is before the first headline,
16818 display all fragments in the buffer.
16819 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
16821 (unless buffer-file-name
16822 (error "Can't preview LaTeX fragment in a non-file buffer"))
16823 (org-remove-latex-fragment-image-overlays)
16826 (let (beg end at msg)
16828 ((or (equal subtree '(16))
16829 (not (save-excursion
16830 (re-search-backward org-outline-regexp-bol nil t))))
16831 (setq beg (point-min) end (point-max)
16832 msg "Creating images for buffer...%s"))
16833 ((equal subtree '(4))
16834 (org-back-to-heading)
16835 (setq beg (point) end (org-end-of-subtree t)
16836 msg "Creating images for subtree...%s"))
16838 (if (setq at (org-inside-LaTeX-fragment-p))
16839 (goto-char (max (point-min) (- (cdr at) 2)))
16840 (org-back-to-heading))
16841 (setq beg (point) end (progn (outline-next-heading) (point))
16842 msg (if at "Creating image...%s"
16843 "Creating images for entry...%s"))))
16845 (narrow-to-region beg end)
16848 (concat "ltxpng/" (file-name-sans-extension
16849 (file-name-nondirectory
16850 buffer-file-name)))
16851 default-directory 'overlays msg at 'forbuffer 'dvipng)
16852 (message msg "done. Use `C-c C-c' to remove images.")))))
16854 (defvar org-latex-regexps
16855 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
16856 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
16857 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
16858 ("$1" "\\([^$]\\|^\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
16859 ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
16860 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
16861 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
16862 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
16863 "Regular expressions for matching embedded LaTeX.")
16865 (defvar org-export-have-math nil) ;; dynamic scoping
16866 (defun org-format-latex (prefix &optional dir overlays msg at
16867 forbuffer processing-type)
16868 "Replace LaTeX fragments with links to an image, and produce images.
16869 Some of the options can be changed using the variable
16870 `org-format-latex-options'."
16871 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
16872 (let* ((prefixnodir (file-name-nondirectory prefix))
16873 (absprefix (expand-file-name prefix dir))
16874 (todir (file-name-directory absprefix))
16875 (opt org-format-latex-options)
16876 (matchers (plist-get opt :matchers))
16877 (re-list org-latex-regexps)
16878 (org-format-latex-header-extra
16879 (plist-get (org-infile-export-plist) :latex-header-extra))
16880 (cnt 0) txt hash link beg end re e checkdir
16881 executables-checked string
16882 m n block-type block linkfile movefile ov)
16883 ;; Check the different regular expressions
16884 (while (setq e (pop re-list))
16885 (setq m (car e) re (nth 1 e) n (nth 2 e) block-type (nth 3 e)
16886 block (if block-type "\n\n" ""))
16887 (when (member m matchers)
16888 (goto-char (point-min))
16889 (while (re-search-forward re nil t)
16890 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
16891 (not (get-text-property (match-beginning n)
16894 (not (eq (get-char-property (match-beginning n)
16896 'org-latex-overlay))))
16897 (setq org-export-have-math t)
16899 ((eq processing-type 'verbatim)
16900 ;; Leave the text verbatim, just protect it
16901 (add-text-properties (match-beginning n) (match-end n)
16902 '(org-protected t)))
16903 ((eq processing-type 'mathjax)
16904 ;; Prepare for MathJax processing
16905 (setq string (match-string n))
16906 (if (member m '("$" "$1"))
16908 (delete-region (match-beginning n) (match-end n))
16909 (goto-char (match-beginning n))
16910 (insert (org-add-props (concat "\\(" (substring string 1 -1)
16912 '(org-protected t))))
16913 (add-text-properties (match-beginning n) (match-end n)
16914 '(org-protected t))))
16915 ((eq processing-type 'dvipng)
16916 ;; Process to an image
16917 (setq txt (match-string n)
16918 beg (match-beginning n) end (match-end n)
16920 (let (print-length print-level) ; make sure full list is printed
16921 (setq hash (sha1 (prin1-to-string
16922 (list org-format-latex-header
16923 org-format-latex-header-extra
16924 org-export-latex-default-packages-alist
16925 org-export-latex-packages-alist
16926 org-format-latex-options
16928 linkfile (format "%s_%s.png" prefix hash)
16929 movefile (format "%s_%s.png" absprefix hash)))
16930 (setq link (concat block "[[file:" linkfile "]]" block))
16931 (if msg (message msg cnt))
16933 (unless checkdir ; make sure the directory exists
16935 (or (file-directory-p todir) (make-directory todir t)))
16937 (unless executables-checked
16938 (org-check-external-command
16939 "latex" "needed to convert LaTeX fragments to images")
16940 (org-check-external-command
16941 "dvipng" "needed to convert LaTeX fragments to images")
16942 (setq executables-checked t))
16944 (unless (file-exists-p movefile)
16945 (org-create-formula-image
16946 txt movefile opt forbuffer))
16950 (if (eq (overlay-get o 'org-overlay-type)
16951 'org-latex-overlay)
16952 (delete-overlay o)))
16953 (overlays-in beg end))
16954 (setq ov (make-overlay beg end))
16955 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
16956 (if (featurep 'xemacs)
16958 (overlay-put ov 'invisible t)
16961 (make-glyph (vector 'png :file movefile))))
16964 (list 'image :type 'png :file movefile :ascent 'center)))
16965 (push ov org-latex-fragment-image-overlays)
16967 (delete-region beg end)
16968 (insert (org-add-props link
16969 (list 'org-latex-src
16970 (replace-regexp-in-string
16972 'org-latex-src-embed-type
16973 (if block-type 'paragraph 'character))))))
16974 ((eq processing-type 'mathml)
16975 ;; Process to MathML
16976 (unless executables-checked
16977 (unless (save-match-data (org-format-latex-mathml-available-p))
16978 (error "LaTeX to MathML converter not configured"))
16979 (setq executables-checked t))
16980 (setq txt (match-string n)
16981 beg (match-beginning n) end (match-end n)
16983 (if msg (message msg cnt))
16985 (delete-region beg end)
16986 (insert (org-format-latex-as-mathml
16987 txt block-type prefix dir)))
16989 (error "Unknown conversion type %s for latex fragments"
16990 processing-type)))))))))
16992 (defun org-create-math-formula (latex-frag &optional mathml-file)
16993 "Convert LATEX-FRAG to MathML and store it in MATHML-FILE.
16994 Use `org-latex-to-mathml-convert-command'. If the conversion is
16995 sucessful, return the portion between \"<math...> </math>\"
16996 elements otherwise return nil. When MATHML-FILE is specified,
16997 write the results in to that file. When invoked as an
16998 interactive command, prompt for LATEX-FRAG, with initial value
16999 set to the current active region and echo the results for user
17001 (interactive (list (let ((frag (when (region-active-p)
17002 (buffer-substring-no-properties
17003 (region-beginning) (region-end)))))
17004 (read-string "LaTeX Fragment: " frag nil frag))))
17005 (unless latex-frag (error "Invalid latex-frag"))
17006 (let* ((tmp-in-file (file-relative-name
17007 (make-temp-name (expand-file-name "ltxmathml-in"))))
17008 (ignore (write-region latex-frag nil tmp-in-file))
17009 (tmp-out-file (file-relative-name
17010 (make-temp-name (expand-file-name "ltxmathml-out"))))
17012 org-latex-to-mathml-convert-command
17013 `((?j . ,(shell-quote-argument
17014 (expand-file-name org-latex-to-mathml-jar-file)))
17015 (?I . ,(shell-quote-argument tmp-in-file))
17016 (?o . ,(shell-quote-argument tmp-out-file)))))
17017 mathml shell-command-output)
17018 (when (org-called-interactively-p 'any)
17019 (unless (org-format-latex-mathml-available-p)
17020 (error "LaTeX to MathML converter not configured")))
17021 (message "Running %s" cmd)
17022 (setq shell-command-output (shell-command-to-string cmd))
17024 (when (file-readable-p tmp-out-file)
17025 (with-current-buffer (find-file-noselect tmp-out-file t)
17026 (goto-char (point-min))
17027 (when (re-search-forward
17030 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">")
17032 (regexp-quote "</math>")) nil t)
17033 (prog1 (match-string 0) (kill-buffer))))))
17037 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" mathml))
17039 (write-region mathml nil mathml-file))
17040 (when (org-called-interactively-p 'any)
17042 ((message "LaTeX to MathML conversion failed")
17043 (message shell-command-output)))
17044 (delete-file tmp-in-file)
17045 (when (file-exists-p tmp-out-file)
17046 (delete-file tmp-out-file))
17049 (defun org-format-latex-as-mathml (latex-frag latex-frag-type
17050 prefix &optional dir)
17051 "Use `org-create-math-formula' but check local cache first."
17052 (let* ((absprefix (expand-file-name prefix dir))
17053 (print-length nil) (print-level nil)
17054 (formula-id (concat
17059 org-latex-to-mathml-convert-command)))))
17060 (formula-cache (format "%s-%s.mathml" absprefix formula-id))
17061 (formula-cache-dir (file-name-directory formula-cache)))
17063 (unless (file-directory-p formula-cache-dir)
17064 (make-directory formula-cache-dir t))
17066 (unless (file-exists-p formula-cache)
17067 (org-create-math-formula latex-frag formula-cache))
17069 (if (file-exists-p formula-cache)
17070 ;; Successful conversion. Return the link to MathML file.
17072 (format "[[file:%s]]" (file-relative-name formula-cache dir))
17073 (list 'org-latex-src (replace-regexp-in-string "\"" "" latex-frag)
17074 'org-latex-src-embed-type (if latex-frag-type
17075 'paragraph 'character)))
17076 ;; Failed conversion. Return the LaTeX fragment verbatim
17077 (add-text-properties
17078 0 (1- (length latex-frag)) '(org-protected t) latex-frag)
17081 ;; This function borrows from Ganesh Swami's latex2png.el
17082 (defun org-create-formula-image (string tofile options buffer)
17083 "This calls dvipng."
17084 (require 'org-latex)
17085 (let* ((tmpdir (if (featurep 'xemacs)
17087 temporary-file-directory))
17088 (texfilebase (make-temp-name
17089 (expand-file-name "orgtex" tmpdir)))
17090 (texfile (concat texfilebase ".tex"))
17091 (dvifile (concat texfilebase ".dvi"))
17092 (pngfile (concat texfilebase ".png"))
17093 (fnh (if (featurep 'xemacs)
17094 (font-height (get-face-font 'default))
17095 (face-attribute 'default :height nil)))
17096 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
17097 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
17098 (fg (or (plist-get options (if buffer :foreground :html-foreground))
17100 (bg (or (plist-get options (if buffer :background :html-background))
17102 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
17103 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
17104 (with-temp-file texfile
17105 (insert (org-splice-latex-header
17106 org-format-latex-header
17107 org-export-latex-default-packages-alist
17108 org-export-latex-packages-alist t
17109 org-format-latex-header-extra))
17110 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
17111 (require 'org-latex)
17112 (org-export-latex-fix-inputenc))
17113 (let ((dir default-directory))
17114 (condition-case nil
17117 (call-process "latex" nil nil nil texfile))
17120 (if (not (file-exists-p dvifile))
17121 (progn (message "Failed to create dvi file from %s" texfile) nil)
17122 (condition-case nil
17123 (call-process "dvipng" nil nil nil
17126 ;;"-x" scale "-y" scale
17131 (if (not (file-exists-p pngfile))
17132 (if org-format-latex-signal-error
17133 (error "Failed to create png file from %s" texfile)
17134 (message "Failed to create png file from %s" texfile)
17136 ;; Use the requested file name and clean up
17137 (copy-file pngfile tofile 'replace)
17138 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
17139 (delete-file (concat texfilebase e)))
17142 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
17143 "Fill a LaTeX header template TPL.
17144 In the template, the following place holders will be recognized:
17146 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
17147 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
17148 [PACKAGES] \\usepackage statements for PKG
17149 [NO-PACKAGES] do not include PKG
17150 [EXTRA] the string EXTRA
17151 [NO-EXTRA] do not include EXTRA
17153 For backward compatibility, if both the positive and the negative place
17154 holder is missing, the positive one (without the \"NO-\") will be
17155 assumed to be present at the end of the template.
17156 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
17158 SNIPPETS-P indicates if this is run to create snippet images for HTML."
17159 (let (rpl (end ""))
17160 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
17161 (setq rpl (if (or (match-end 1) (not def-pkg))
17162 "" (org-latex-packages-to-string def-pkg snippets-p t))
17163 tpl (replace-match rpl t t tpl))
17164 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
17166 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
17167 (setq rpl (if (or (match-end 1) (not pkg))
17168 "" (org-latex-packages-to-string pkg snippets-p t))
17169 tpl (replace-match rpl t t tpl))
17172 (org-latex-packages-to-string pkg snippets-p)))))
17174 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
17175 (setq rpl (if (or (match-end 1) (not extra))
17176 "" (concat extra "\n"))
17177 tpl (replace-match rpl t t tpl))
17178 (if (and extra (string-match "\\S-" extra))
17179 (setq end (concat end "\n" extra))))
17181 (if (string-match "\\S-" end)
17182 (concat tpl "\n" end)
17185 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
17186 "Turn an alist of packages into a string with the \\usepackage macros."
17187 (setq pkg (mapconcat (lambda(p)
17190 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
17191 (format "%% Package %s omitted" (cadr p)))
17192 ((equal "" (car p))
17193 (format "\\usepackage{%s}" (cadr p)))
17195 (format "\\usepackage[%s]{%s}"
17196 (car p) (cadr p)))))
17199 (if newline (concat pkg "\n") pkg))
17201 (defun org-dvipng-color (attr)
17202 "Return an rgb color specification for dvipng."
17203 (apply 'format "rgb %s %s %s"
17204 (mapcar 'org-normalize-color
17205 (color-values (face-attribute 'default attr nil)))))
17207 (defun org-normalize-color (value)
17208 "Return string to be used as color value for an RGB component."
17209 (format "%g" (/ value 65535.0)))
17214 (defvar org-inline-image-overlays nil)
17215 (make-variable-buffer-local 'org-inline-image-overlays)
17217 (defun org-toggle-inline-images (&optional include-linked)
17218 "Toggle the display of inline images.
17219 INCLUDE-LINKED is passed to `org-display-inline-images'."
17221 (if org-inline-image-overlays
17223 (org-remove-inline-images)
17224 (message "Inline image display turned off"))
17225 (org-display-inline-images include-linked)
17226 (if org-inline-image-overlays
17227 (message "%d images displayed inline"
17228 (length org-inline-image-overlays))
17229 (message "No images to display inline"))))
17231 (defun org-display-inline-images (&optional include-linked refresh beg end)
17232 "Display inline images.
17233 Normally only links without a description part are inlined, because this
17234 is how it will work for export. When INCLUDE-LINKED is set, also links
17235 with a description part will be inlined. This can be nice for a quick
17236 look at those images, but it does not reflect what exported files will look
17238 When REFRESH is set, refresh existing images between BEG and END.
17239 This will create new image displays only if necessary.
17240 BEG and END default to the buffer boundaries."
17243 (org-remove-inline-images)
17244 (if (fboundp 'clear-image-cache) (clear-image-cache)))
17248 (setq beg (or beg (point-min)) end (or end (point-max)))
17249 (goto-char (point-min))
17250 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
17251 (substring (org-image-file-name-regexp) 0 -2)
17252 "\\)\\]" (if include-linked "" "\\]")))
17254 (while (re-search-forward re end t)
17255 (setq old (get-char-property-and-overlay (match-beginning 1)
17256 'org-image-overlay))
17257 (setq file (expand-file-name
17258 (concat (or (match-string 3) "") (match-string 4))))
17259 (when (file-exists-p file)
17260 (if (and (car-safe old) refresh)
17261 (image-refresh (overlay-get (cdr old) 'display))
17262 (setq img (save-match-data (create-image file)))
17264 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
17265 (overlay-put ov 'display img)
17266 (overlay-put ov 'face 'default)
17267 (overlay-put ov 'org-image-overlay t)
17268 (overlay-put ov 'modification-hooks
17269 (list 'org-display-inline-modification-hook))
17270 (push ov org-inline-image-overlays)))))))))
17272 (defun org-display-inline-modification-hook (ov after beg end &optional len)
17273 "Remove inline-display overlay if a corresponding region is modified."
17274 (let ((inhibit-modification-hooks t))
17275 (when (and ov after)
17276 (delete ov org-inline-image-overlays)
17277 (delete-overlay ov))))
17279 (defun org-remove-inline-images ()
17280 "Remove inline display of images."
17282 (mapc 'delete-overlay org-inline-image-overlays)
17283 (setq org-inline-image-overlays nil))
17287 ;; Outline functions from `outline-mode-prefix-map'
17288 ;; that can be remapped in Org:
17289 (define-key org-mode-map [remap outline-mark-subtree] 'org-mark-subtree)
17290 (define-key org-mode-map [remap show-subtree] 'org-show-subtree)
17291 (define-key org-mode-map [remap outline-forward-same-level]
17292 'org-forward-same-level)
17293 (define-key org-mode-map [remap outline-backward-same-level]
17294 'org-backward-same-level)
17295 (define-key org-mode-map [remap show-branches]
17296 'org-kill-note-or-show-branches)
17297 (define-key org-mode-map [remap outline-promote] 'org-promote-subtree)
17298 (define-key org-mode-map [remap outline-demote] 'org-demote-subtree)
17299 (define-key org-mode-map [remap outline-insert-heading] 'org-ctrl-c-ret)
17301 ;; Outline functions from `outline-mode-prefix-map'
17302 ;; that can not be remapped in Org:
17303 ;; - the column "key binding" shows whether the Outline function is still
17304 ;; available in Org mode on the same key that it has been bound to in
17306 ;; - "overridden": key used for a different functionality in Org mode
17307 ;; - else: key still bound to the same Outline function in Org mode
17308 ;; | Outline function | key binding | Org replacement |
17309 ;; |------------------------------------+-------------+-----------------------|
17310 ;; | `outline-next-visible-heading' | `C-c C-n' | still same function |
17311 ;; | `outline-previous-visible-heading' | `C-c C-p' | still same function |
17312 ;; | `show-children' | `C-c C-i' | visibility cycling |
17313 ;; | `hide-subtree' | overridden | visibility cycling |
17314 ;; | `outline-up-heading' | `C-c C-u' | still same function |
17315 ;; | `hide-body' | overridden | no replacement |
17316 ;; | `show-all' | overridden | no replacement |
17317 ;; | `hide-entry' | overridden | visibility cycling |
17318 ;; | `show-entry' | overridden | no replacement |
17319 ;; | `hide-leaves' | overridden | no replacement |
17320 ;; | `hide-sublevels' | overridden | no replacement |
17321 ;; | `hide-other' | overridden | no replacement |
17322 ;; | `outline-move-subtree-up' | `C-c C-^' | better: org-shiftup |
17323 ;; | `outline-move-subtree-down' | overridden | better: org-shiftdown |
17325 ;; Make `C-c C-x' a prefix key
17326 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
17328 ;; TAB key with modifiers
17329 (org-defkey org-mode-map "\C-i" 'org-cycle)
17330 (org-defkey org-mode-map [(tab)] 'org-cycle)
17331 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
17332 (org-defkey org-mode-map [(meta tab)] 'pcomplete)
17333 (org-defkey org-mode-map "\M-\t" 'pcomplete)
17334 (org-defkey org-mode-map "\M-\C-i" 'pcomplete)
17335 ;; The following line is necessary under Suse GNU/Linux
17336 (unless (featurep 'xemacs)
17337 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
17338 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
17339 (define-key org-mode-map [backtab] 'org-shifttab)
17341 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
17342 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
17343 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
17345 ;; Cursor keys with modifiers
17346 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
17347 (org-defkey org-mode-map [(meta right)] 'org-metaright)
17348 (org-defkey org-mode-map [(meta up)] 'org-metaup)
17349 (org-defkey org-mode-map [(meta down)] 'org-metadown)
17351 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
17352 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
17353 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
17354 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
17356 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
17357 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
17358 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
17359 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
17361 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
17362 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
17363 (org-defkey org-mode-map [(control shift up)] 'org-shiftcontrolup)
17364 (org-defkey org-mode-map [(control shift down)] 'org-shiftcontroldown)
17367 (define-key org-mode-map org-babel-key-prefix org-babel-map)
17368 (mapc (lambda (pair)
17369 (define-key org-babel-map (car pair) (cdr pair)))
17370 org-babel-key-bindings)
17372 ;;; Extra keys for tty access.
17373 ;; We only set them when really needed because otherwise the
17374 ;; menus don't show the simple keys
17376 (when (or org-use-extra-keys
17377 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
17378 (not window-system))
17379 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
17380 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
17381 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
17382 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
17383 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
17384 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
17385 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
17386 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
17387 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
17388 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
17389 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
17390 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
17391 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
17392 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
17393 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
17394 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
17395 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
17396 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
17397 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
17398 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
17399 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
17400 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
17401 (org-defkey org-mode-map [?\e (tab)] 'pcomplete)
17402 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
17403 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
17404 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
17405 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
17406 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
17408 ;; All the other keys
17410 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
17411 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
17412 (if (boundp 'narrow-map)
17413 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
17414 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
17415 (if (boundp 'narrow-map)
17416 (org-defkey narrow-map "b" 'org-narrow-to-block)
17417 (org-defkey org-mode-map "\C-xnb" 'org-narrow-to-block))
17418 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-same-level)
17419 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-same-level)
17420 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
17421 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
17422 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
17423 (org-defkey org-mode-map "\C-c\C-xd" 'org-insert-drawer)
17424 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
17425 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
17426 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
17427 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
17428 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
17429 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
17430 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
17431 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
17432 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
17433 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
17434 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
17435 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
17436 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
17437 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
17438 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
17439 (org-defkey org-mode-map "\C-c\C-xv" 'org-copy-visible)
17440 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
17441 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
17442 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
17443 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
17444 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
17445 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
17446 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
17447 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
17448 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
17449 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
17450 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
17451 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
17452 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
17453 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
17454 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
17455 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
17456 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
17457 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
17458 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
17459 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
17460 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
17461 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
17462 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
17463 (org-defkey org-mode-map "\C-c^" 'org-sort)
17464 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
17465 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
17466 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
17467 (org-defkey org-mode-map "\C-m" 'org-return)
17468 (org-defkey org-mode-map "\C-j" 'org-return-indent)
17469 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
17470 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
17471 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
17472 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
17473 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
17474 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
17475 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
17476 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
17477 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
17478 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
17479 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
17480 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
17481 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
17482 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
17483 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
17484 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
17485 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
17486 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
17487 (org-defkey org-mode-map "\C-c@" 'org-mark-subtree)
17488 (org-defkey org-mode-map "\C-c\C-@" 'org-mark-list)
17489 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
17490 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
17492 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
17493 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
17494 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
17495 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
17497 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
17498 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
17499 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
17500 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
17501 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-cancel)
17502 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
17503 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
17504 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
17505 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
17506 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
17507 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
17508 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
17509 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
17510 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
17511 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
17512 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
17513 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
17514 (org-defkey org-mode-map [(control ?c) (control ?x) ?\:] 'org-timer-cancel-timer)
17516 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
17517 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
17518 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
17519 (org-defkey org-mode-map "\C-c\C-x_" 'org-timer-stop)
17520 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
17522 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
17524 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
17526 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
17527 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
17529 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
17532 (when (featurep 'xemacs)
17533 (org-defkey org-mode-map 'button3 'popup-mode-menu))
17536 (defconst org-speed-commands-default
17538 ("Outline Navigation")
17539 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
17540 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
17541 ("f" . (org-speed-move-safe 'org-forward-same-level))
17542 ("b" . (org-speed-move-safe 'org-backward-same-level))
17543 ("u" . (org-speed-move-safe 'outline-up-heading))
17545 ("g" . (org-refile t))
17546 ("Outline Visibility")
17548 ("C" . org-shifttab)
17549 (" " . org-display-outline-path)
17550 ("Outline Structure Editing")
17551 ("U" . org-shiftmetaup)
17552 ("D" . org-shiftmetadown)
17553 ("r" . org-metaright)
17554 ("l" . org-metaleft)
17555 ("R" . org-shiftmetaright)
17556 ("L" . org-shiftmetaleft)
17557 ("i" . (progn (forward-char 1) (call-interactively
17558 'org-insert-heading-respect-content)))
17561 ("a" . org-archive-subtree-default-with-confirmation)
17562 ("." . org-mark-subtree)
17564 ("I" . org-clock-in)
17565 ("O" . org-clock-out)
17566 ("Meta Data Editing")
17568 ("0" . (org-priority ?\ ))
17569 ("1" . (org-priority ?A))
17570 ("2" . (org-priority ?B))
17571 ("3" . (org-priority ?C))
17572 (";" . org-set-tags-command)
17573 ("e" . org-set-effort)
17574 ("Agenda Views etc")
17576 ("/" . org-sparse-tree)
17578 ("o" . org-open-at-point)
17579 ("?" . org-speed-command-help)
17580 ("<" . (org-agenda-set-restriction-lock 'subtree))
17581 (">" . (org-agenda-remove-restriction-lock))
17583 "The default speed commands.")
17585 (defun org-print-speed-command (e)
17586 (if (> (length (car e)) 1)
17591 (princ (make-string (length (car e)) ?-))
17595 (if (symbolp (cdr e))
17596 (princ (symbol-name (cdr e)))
17600 (defun org-speed-command-help ()
17601 "Show the available speed commands."
17603 (if (not org-use-speed-commands)
17604 (error "Speed commands are not activated, customize `org-use-speed-commands'")
17605 (with-output-to-temp-buffer "*Help*"
17606 (princ "User-defined Speed commands\n===========================\n")
17607 (mapc 'org-print-speed-command org-speed-commands-user)
17609 (princ "Built-in Speed commands\n=======================\n")
17610 (mapc 'org-print-speed-command org-speed-commands-default))
17611 (with-current-buffer "*Help*"
17612 (setq truncate-lines t))))
17614 (defun org-speed-move-safe (cmd)
17615 "Execute CMD, but make sure that the cursor always ends up in a headline.
17616 If not, return to the original position and throw an error."
17618 (let ((pos (point)))
17619 (call-interactively cmd)
17620 (unless (and (bolp) (org-at-heading-p))
17622 (error "Boundary reached while executing %s" cmd))))
17624 (defvar org-self-insert-command-undo-counter 0)
17626 (defvar org-table-auto-blank-field) ; defined in org-table.el
17627 (defvar org-speed-command nil)
17629 (defun org-speed-command-default-hook (keys)
17630 "Hook for activating single-letter speed commands.
17631 `org-speed-commands-default' specifies a minimal command set.
17632 Use `org-speed-commands-user' for further customization."
17633 (when (or (and (bolp) (looking-at org-outline-regexp))
17634 (and (functionp org-use-speed-commands)
17635 (funcall org-use-speed-commands)))
17636 (cdr (assoc keys (append org-speed-commands-user
17637 org-speed-commands-default)))))
17639 (defun org-babel-speed-command-hook (keys)
17640 "Hook for activating single-letter code block commands."
17641 (when (and (bolp) (looking-at org-babel-src-block-regexp))
17642 (cdr (assoc keys org-babel-key-bindings))))
17644 (defcustom org-speed-command-hook
17645 '(org-speed-command-default-hook org-babel-speed-command-hook)
17646 "Hook for activating speed commands at strategic locations.
17647 Hook functions are called in sequence until a valid handler is
17650 Each hook takes a single argument, a user-pressed command key
17651 which is also a `self-insert-command' from the global map.
17653 Within the hook, examine the cursor position and the command key
17654 and return nil or a valid handler as appropriate. Handler could
17655 be one of an interactive command, a function, or a form.
17657 Set `org-use-speed-commands' to non-nil value to enable this
17658 hook. The default setting is `org-speed-command-default-hook'."
17659 :group 'org-structure
17663 (defun org-self-insert-command (N)
17664 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
17665 If the cursor is in a table looking at whitespace, the whitespace is
17666 overwritten, and the table is not marked as requiring realignment."
17668 (org-check-before-invisible-edit 'insert)
17670 ((and org-use-speed-commands
17671 (setq org-speed-command
17672 (run-hook-with-args-until-success
17673 'org-speed-command-hook (this-command-keys))))
17675 ((commandp org-speed-command)
17676 (setq this-command org-speed-command)
17677 (call-interactively org-speed-command))
17678 ((functionp org-speed-command)
17679 (funcall org-speed-command))
17680 ((and org-speed-command (listp org-speed-command))
17681 (eval org-speed-command))
17682 (t (let (org-use-speed-commands)
17683 (call-interactively 'org-self-insert-command)))))
17687 ;; check if we blank the field, and if that triggers align
17688 (and (featurep 'org-table) org-table-auto-blank-field
17689 (member last-command
17690 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
17691 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
17692 ;; got extra space, this field does not determine column width
17693 (let (org-table-may-need-update) (org-table-blank-field))
17694 ;; no extra space, this field may determine column width
17695 (org-table-blank-field)))
17698 (looking-at "[^|\n]* |"))
17699 (let (org-table-may-need-update)
17700 (goto-char (1- (match-end 0)))
17702 (goto-char (match-beginning 0))
17703 (self-insert-command N)))
17705 (setq org-table-may-need-update t)
17706 (self-insert-command N)
17707 (org-fix-tags-on-the-fly)
17708 (if org-self-insert-cluster-for-undo
17709 (if (not (eq last-command 'org-self-insert-command))
17710 (setq org-self-insert-command-undo-counter 1)
17711 (if (>= org-self-insert-command-undo-counter 20)
17712 (setq org-self-insert-command-undo-counter 1)
17713 (and (> org-self-insert-command-undo-counter 0)
17714 buffer-undo-list (listp buffer-undo-list)
17715 (not (cadr buffer-undo-list)) ; remove nil entry
17716 (setcdr buffer-undo-list (cddr buffer-undo-list)))
17717 (setq org-self-insert-command-undo-counter
17718 (1+ org-self-insert-command-undo-counter))))))))
17720 (defun org-check-before-invisible-edit (kind)
17721 "Check is editing if kind KIND would be dangerous with invisible text around.
17722 The detailed reaction depends on the user option `org-catch-invisible-edits'."
17723 ;; First, try to get out of here as quickly as possible, to reduce overhead
17724 (if (and org-catch-invisible-edits
17725 (or (not (boundp 'visible-mode)) (not visible-mode))
17726 (or (get-char-property (point) 'invisible)
17727 (get-char-property (max (point-min) (1- (point))) 'invisible)))
17728 ;; OK, we need to take a closer look
17729 (let* ((invisible-at-point (get-char-property (point) 'invisible))
17730 (invisible-before-point (if (bobp) nil (get-char-property
17731 (1- (point)) 'invisible)))
17732 (border-and-ok-direction
17734 ;; Check if we are acting predictably before invisible text
17735 (and invisible-at-point (not invisible-before-point)
17736 (memq kind '(insert delete-backward)))
17737 ;; Check if we are acting predictably after invisible text
17738 ;; This works not well, and I have turned it off. It seems
17739 ;; better to always show and stop after invisible text.
17740 ;; (and (not invisible-at-point) invisible-before-point
17741 ;; (memq kind '(insert delete)))
17744 (when (or (memq invisible-at-point '(outline org-hide-block))
17745 (memq invisible-before-point '(outline org-hide-block)))
17746 (if (eq org-catch-invisible-edits 'error)
17747 (error "Editing in invisible areas is prohibited - make visible first"))
17748 ;; Make the area visible
17750 (if invisible-before-point
17751 (goto-char (previous-single-char-property-change
17752 (point) 'invisible)))
17755 ((eq org-catch-invisible-edits 'show)
17756 ;; That's it, we do the edit after showing
17758 "Unfolding invisible region around point before editing")
17760 ((and (eq org-catch-invisible-edits 'smart)
17761 border-and-ok-direction)
17762 (message "Unfolding invisible region around point before editing"))
17764 ;; Don't do the edit, make the user repeat it in full visibility
17765 (error "Edit in invisible region aborted, repeat to confirm with text visible")))))))
17767 (defun org-fix-tags-on-the-fly ()
17768 (when (and (equal (char-after (point-at-bol)) ?*)
17769 (org-at-heading-p))
17770 (org-align-tags-here org-tags-column)))
17772 (defun org-delete-backward-char (N)
17773 "Like `delete-backward-char', insert whitespace at field end in tables.
17774 When deleting backwards, in tables this function will insert whitespace in
17775 front of the next \"|\" separator, to keep the table aligned. The table will
17776 still be marked for re-alignment if the field did fill the entire column,
17777 because, in this case the deletion might narrow the column."
17779 (org-check-before-invisible-edit 'delete-backward)
17780 (if (and (org-table-p)
17782 (string-match "|" (buffer-substring (point-at-bol) (point)))
17783 (looking-at ".*?|"))
17784 (let ((pos (point))
17785 (noalign (looking-at "[^|\n\r]* |"))
17786 (c org-table-may-need-update))
17787 (backward-delete-char N)
17788 (if (not overwrite-mode)
17790 (skip-chars-forward "^|")
17792 (goto-char (1- pos))))
17793 ;; noalign: if there were two spaces at the end, this field
17794 ;; does not determine the width of the column.
17795 (if noalign (setq org-table-may-need-update c)))
17796 (backward-delete-char N)
17797 (org-fix-tags-on-the-fly)))
17799 (defun org-delete-char (N)
17800 "Like `delete-char', but insert whitespace at field end in tables.
17801 When deleting characters, in tables this function will insert whitespace in
17802 front of the next \"|\" separator, to keep the table aligned. The table will
17803 still be marked for re-alignment if the field did fill the entire column,
17804 because, in this case the deletion might narrow the column."
17806 (org-check-before-invisible-edit 'delete)
17807 (if (and (org-table-p)
17809 (not (= (char-after) ?|))
17811 (if (looking-at ".*?|")
17812 (let ((pos (point))
17813 (noalign (looking-at "[^|\n\r]* |"))
17814 (c org-table-may-need-update))
17815 (replace-match (concat
17816 (substring (match-string 0) 1 -1)
17819 ;; noalign: if there were two spaces at the end, this field
17820 ;; does not determine the width of the column.
17821 (if noalign (setq org-table-may-need-update c)))
17824 (org-fix-tags-on-the-fly)))
17826 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
17827 (put 'org-self-insert-command 'delete-selection t)
17828 (put 'orgtbl-self-insert-command 'delete-selection t)
17829 (put 'org-delete-char 'delete-selection 'supersede)
17830 (put 'org-delete-backward-char 'delete-selection 'supersede)
17831 (put 'org-yank 'delete-selection 'yank)
17833 ;; Make `flyspell-mode' delay after some commands
17834 (put 'org-self-insert-command 'flyspell-delayed t)
17835 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
17836 (put 'org-delete-char 'flyspell-delayed t)
17837 (put 'org-delete-backward-char 'flyspell-delayed t)
17839 ;; Make pabbrev-mode expand after org-mode commands
17840 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
17841 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
17843 ;; How to do this: Measure non-white length of current string
17844 ;; If equal to column width, we should realign.
17846 (defun org-remap (map &rest commands)
17847 "In MAP, remap the functions given in COMMANDS.
17848 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
17851 (setq old (pop commands) new (pop commands))
17852 (if (fboundp 'command-remapping)
17853 (org-defkey map (vector 'remap old) new)
17854 (substitute-key-definition old new map global-map)))))
17856 (when (eq org-enable-table-editor 'optimized)
17857 ;; If the user wants maximum table support, we need to hijack
17858 ;; some standard editing functions
17859 (org-remap org-mode-map
17860 'self-insert-command 'org-self-insert-command
17861 'delete-char 'org-delete-char
17862 'delete-backward-char 'org-delete-backward-char)
17863 (org-defkey org-mode-map "|" 'org-force-self-insert))
17865 (defvar org-ctrl-c-ctrl-c-hook nil
17866 "Hook for functions attaching themselves to `C-c C-c'.
17868 This can be used to add additional functionality to the C-c C-c
17869 key which executes context-dependent commands. This hook is run
17870 before any other test, while `org-ctrl-c-ctrl-c-final-hook' is
17871 run after the last test.
17873 Each function will be called with no arguments. The function
17874 must check if the context is appropriate for it to act. If yes,
17875 it should do its thing and then return a non-nil value. If the
17876 context is wrong, just do nothing and return nil.")
17878 (defvar org-ctrl-c-ctrl-c-final-hook nil
17879 "Hook for functions attaching themselves to `C-c C-c'.
17881 This can be used to add additional functionality to the C-c C-c
17882 key which executes context-dependent commands. This hook is run
17883 after any other test, while `org-ctrl-c-ctrl-c-hook' is run
17884 before the first test.
17886 Each function will be called with no arguments. The function
17887 must check if the context is appropriate for it to act. If yes,
17888 it should do its thing and then return a non-nil value. If the
17889 context is wrong, just do nothing and return nil.")
17891 (defvar org-tab-first-hook nil
17892 "Hook for functions to attach themselves to TAB.
17893 See `org-ctrl-c-ctrl-c-hook' for more information.
17894 This hook runs as the first action when TAB is pressed, even before
17895 `org-cycle' messes around with the `outline-regexp' to cater for
17896 inline tasks and plain list item folding.
17897 If any function in this hook returns t, any other actions that
17898 would have been caused by TAB (such as table field motion or visibility
17899 cycling) will not occur.")
17901 (defvar org-tab-after-check-for-table-hook nil
17902 "Hook for functions to attach themselves to TAB.
17903 See `org-ctrl-c-ctrl-c-hook' for more information.
17904 This hook runs after it has been established that the cursor is not in a
17905 table, but before checking if the cursor is in a headline or if global cycling
17907 If any function in this hook returns t, not other actions like visibility
17908 cycling will be done.")
17910 (defvar org-tab-after-check-for-cycling-hook nil
17911 "Hook for functions to attach themselves to TAB.
17912 See `org-ctrl-c-ctrl-c-hook' for more information.
17913 This hook runs after it has been established that not table field motion and
17914 not visibility should be done because of current context. This is probably
17915 the place where a package like yasnippets can hook in.")
17917 (defvar org-tab-before-tab-emulation-hook nil
17918 "Hook for functions to attach themselves to TAB.
17919 See `org-ctrl-c-ctrl-c-hook' for more information.
17920 This hook runs after every other options for TAB have been exhausted, but
17921 before indentation and \t insertion takes place.")
17923 (defvar org-metaleft-hook nil
17924 "Hook for functions attaching themselves to `M-left'.
17925 See `org-ctrl-c-ctrl-c-hook' for more information.")
17926 (defvar org-metaright-hook nil
17927 "Hook for functions attaching themselves to `M-right'.
17928 See `org-ctrl-c-ctrl-c-hook' for more information.")
17929 (defvar org-metaup-hook nil
17930 "Hook for functions attaching themselves to `M-up'.
17931 See `org-ctrl-c-ctrl-c-hook' for more information.")
17932 (defvar org-metadown-hook nil
17933 "Hook for functions attaching themselves to `M-down'.
17934 See `org-ctrl-c-ctrl-c-hook' for more information.")
17935 (defvar org-shiftmetaleft-hook nil
17936 "Hook for functions attaching themselves to `M-S-left'.
17937 See `org-ctrl-c-ctrl-c-hook' for more information.")
17938 (defvar org-shiftmetaright-hook nil
17939 "Hook for functions attaching themselves to `M-S-right'.
17940 See `org-ctrl-c-ctrl-c-hook' for more information.")
17941 (defvar org-shiftmetaup-hook nil
17942 "Hook for functions attaching themselves to `M-S-up'.
17943 See `org-ctrl-c-ctrl-c-hook' for more information.")
17944 (defvar org-shiftmetadown-hook nil
17945 "Hook for functions attaching themselves to `M-S-down'.
17946 See `org-ctrl-c-ctrl-c-hook' for more information.")
17947 (defvar org-metareturn-hook nil
17948 "Hook for functions attaching themselves to `M-RET'.
17949 See `org-ctrl-c-ctrl-c-hook' for more information.")
17950 (defvar org-shiftup-hook nil
17951 "Hook for functions attaching themselves to `S-up'.
17952 See `org-ctrl-c-ctrl-c-hook' for more information.")
17953 (defvar org-shiftup-final-hook nil
17954 "Hook for functions attaching themselves to `S-up'.
17955 This one runs after all other options except shift-select have been excluded.
17956 See `org-ctrl-c-ctrl-c-hook' for more information.")
17957 (defvar org-shiftdown-hook nil
17958 "Hook for functions attaching themselves to `S-down'.
17959 See `org-ctrl-c-ctrl-c-hook' for more information.")
17960 (defvar org-shiftdown-final-hook nil
17961 "Hook for functions attaching themselves to `S-down'.
17962 This one runs after all other options except shift-select have been excluded.
17963 See `org-ctrl-c-ctrl-c-hook' for more information.")
17964 (defvar org-shiftleft-hook nil
17965 "Hook for functions attaching themselves to `S-left'.
17966 See `org-ctrl-c-ctrl-c-hook' for more information.")
17967 (defvar org-shiftleft-final-hook nil
17968 "Hook for functions attaching themselves to `S-left'.
17969 This one runs after all other options except shift-select have been excluded.
17970 See `org-ctrl-c-ctrl-c-hook' for more information.")
17971 (defvar org-shiftright-hook nil
17972 "Hook for functions attaching themselves to `S-right'.
17973 See `org-ctrl-c-ctrl-c-hook' for more information.")
17974 (defvar org-shiftright-final-hook nil
17975 "Hook for functions attaching themselves to `S-right'.
17976 This one runs after all other options except shift-select have been excluded.
17977 See `org-ctrl-c-ctrl-c-hook' for more information.")
17979 (defun org-modifier-cursor-error ()
17980 "Throw an error, a modified cursor command was applied in wrong context."
17981 (error "This command is active in special context like tables, headlines or items"))
17983 (defun org-shiftselect-error ()
17984 "Throw an error because Shift-Cursor command was applied in wrong context."
17985 (if (and (boundp 'shift-select-mode) shift-select-mode)
17986 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
17987 (error "This command works only in special context like headlines or timestamps")))
17989 (defun org-call-for-shift-select (cmd)
17990 (let ((this-command-keys-shift-translated t))
17991 (call-interactively cmd)))
17993 (defun org-shifttab (&optional arg)
17994 "Global visibility cycling or move to previous table field.
17995 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
17997 See the individual commands for more information."
18000 ((org-at-table-p) (call-interactively 'org-table-previous-field))
18002 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
18003 (message "Content view to level: %d" arg)
18004 (org-content (prefix-numeric-value arg2))
18005 (setq org-cycle-global-status 'overview)))
18006 (t (call-interactively 'org-global-cycle))))
18008 (defun org-shiftmetaleft ()
18009 "Promote subtree or delete table column.
18010 Calls `org-promote-subtree', `org-outdent-item',
18011 or `org-table-delete-column', depending on context.
18012 See the individual commands for more information."
18015 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
18016 ((org-at-table-p) (call-interactively 'org-table-delete-column))
18017 ((org-at-heading-p) (call-interactively 'org-promote-subtree))
18018 ((org-at-item-p) (call-interactively 'org-outdent-item-tree))
18019 (t (org-modifier-cursor-error))))
18021 (defun org-shiftmetaright ()
18022 "Demote subtree or insert table column.
18023 Calls `org-demote-subtree', `org-indent-item',
18024 or `org-table-insert-column', depending on context.
18025 See the individual commands for more information."
18028 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
18029 ((org-at-table-p) (call-interactively 'org-table-insert-column))
18030 ((org-at-heading-p) (call-interactively 'org-demote-subtree))
18031 ((org-at-item-p) (call-interactively 'org-indent-item-tree))
18032 (t (org-modifier-cursor-error))))
18034 (defun org-shiftmetaup (&optional arg)
18035 "Move subtree up or kill table row.
18036 Calls `org-move-subtree-up' or `org-table-kill-row' or
18037 `org-move-item-up' depending on context. See the individual commands
18038 for more information."
18041 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
18042 ((org-at-table-p) (call-interactively 'org-table-kill-row))
18043 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
18044 ((org-at-item-p) (call-interactively 'org-move-item-up))
18045 (t (org-modifier-cursor-error))))
18047 (defun org-shiftmetadown (&optional arg)
18048 "Move subtree down or insert table row.
18049 Calls `org-move-subtree-down' or `org-table-insert-row' or
18050 `org-move-item-down', depending on context. See the individual
18051 commands for more information."
18054 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
18055 ((org-at-table-p) (call-interactively 'org-table-insert-row))
18056 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
18057 ((org-at-item-p) (call-interactively 'org-move-item-down))
18058 (t (org-modifier-cursor-error))))
18060 (defsubst org-hidden-tree-error ()
18062 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
18064 (defun org-metaleft (&optional arg)
18065 "Promote heading or move table column to left.
18066 Calls `org-do-promote' or `org-table-move-column', depending on context.
18067 With no specific context, calls the Emacs default `backward-word'.
18068 See the individual commands for more information."
18071 ((run-hook-with-args-until-success 'org-metaleft-hook))
18072 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
18073 ((org-with-limited-levels
18074 (or (org-at-heading-p)
18075 (and (org-region-active-p)
18077 (goto-char (region-beginning))
18078 (org-at-heading-p)))))
18079 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
18080 (call-interactively 'org-do-promote))
18081 ;; At an inline task.
18082 ((org-at-heading-p)
18083 (call-interactively 'org-inlinetask-promote))
18084 ((or (org-at-item-p)
18085 (and (org-region-active-p)
18087 (goto-char (region-beginning))
18089 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
18090 (call-interactively 'org-outdent-item))
18091 (t (call-interactively 'backward-word))))
18093 (defun org-metaright (&optional arg)
18094 "Demote a subtree, a list item or move table column to right.
18095 In front of a drawer or a block keyword, indent it correctly.
18096 With no specific context, calls the Emacs default `forward-word'.
18097 See the individual commands for more information."
18100 ((run-hook-with-args-until-success 'org-metaright-hook))
18101 ((org-at-table-p) (call-interactively 'org-table-move-column))
18102 ((org-at-drawer-p) (call-interactively 'org-indent-drawer))
18103 ((org-at-block-p) (call-interactively 'org-indent-block))
18104 ((org-with-limited-levels
18105 (or (org-at-heading-p)
18106 (and (org-region-active-p)
18108 (goto-char (region-beginning))
18109 (org-at-heading-p)))))
18110 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
18111 (call-interactively 'org-do-demote))
18112 ;; At an inline task.
18113 ((org-at-heading-p)
18114 (call-interactively 'org-inlinetask-demote))
18115 ((or (org-at-item-p)
18116 (and (org-region-active-p)
18118 (goto-char (region-beginning))
18120 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
18121 (call-interactively 'org-indent-item))
18122 (t (call-interactively 'forward-word))))
18124 (defun org-check-for-hidden (what)
18125 "Check if there are hidden headlines/items in the current visual line.
18126 WHAT can be either `headlines' or `items'. If the current line is
18127 an outline or item heading and it has a folded subtree below it,
18128 this function returns t, nil otherwise."
18130 ((eq what 'headlines) org-outline-regexp-bol)
18131 ((eq what 'items) (org-item-beginning-re))
18132 (t (error "This should not happen"))))
18136 (unless (org-region-active-p)
18137 (setq beg (point-at-bol))
18138 (beginning-of-line 2)
18139 (while (and (not (eobp)) ;; this is like `next-line'
18140 (get-char-property (1- (point)) 'invisible))
18141 (beginning-of-line 2))
18144 (goto-char (point-at-eol))
18145 (setq end (max end (point)))
18146 (while (re-search-forward re end t)
18147 (if (get-char-property (match-beginning 0) 'invisible)
18151 (defun org-metaup (&optional arg)
18152 "Move subtree up or move table row up.
18153 Calls `org-move-subtree-up' or `org-table-move-row' or
18154 `org-move-item-up', depending on context. See the individual commands
18155 for more information."
18158 ((run-hook-with-args-until-success 'org-metaup-hook))
18159 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
18160 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
18161 ((org-at-item-p) (call-interactively 'org-move-item-up))
18162 (t (transpose-lines 1) (beginning-of-line -1))))
18164 (defun org-metadown (&optional arg)
18165 "Move subtree down or move table row down.
18166 Calls `org-move-subtree-down' or `org-table-move-row' or
18167 `org-move-item-down', depending on context. See the individual
18168 commands for more information."
18171 ((run-hook-with-args-until-success 'org-metadown-hook))
18172 ((org-at-table-p) (call-interactively 'org-table-move-row))
18173 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
18174 ((org-at-item-p) (call-interactively 'org-move-item-down))
18175 (t (beginning-of-line 2) (transpose-lines 1) (beginning-of-line 0))))
18177 (defun org-shiftup (&optional arg)
18178 "Increase item in timestamp or increase priority of current headline.
18179 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
18180 depending on context. See the individual commands for more information."
18183 ((run-hook-with-args-until-success 'org-shiftup-hook))
18184 ((and org-support-shift-select (org-region-active-p))
18185 (org-call-for-shift-select 'previous-line))
18186 ((org-at-timestamp-p t)
18187 (call-interactively (if org-edit-timestamp-down-means-later
18188 'org-timestamp-down 'org-timestamp-up)))
18189 ((and (not (eq org-support-shift-select 'always))
18190 org-enable-priority-commands
18191 (org-at-heading-p))
18192 (call-interactively 'org-priority-up))
18193 ((and (not org-support-shift-select) (org-at-item-p))
18194 (call-interactively 'org-previous-item))
18195 ((org-clocktable-try-shift 'up arg))
18196 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
18197 (org-support-shift-select
18198 (org-call-for-shift-select 'previous-line))
18199 (t (org-shiftselect-error))))
18201 (defun org-shiftdown (&optional arg)
18202 "Decrease item in timestamp or decrease priority of current headline.
18203 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
18204 depending on context. See the individual commands for more information."
18207 ((run-hook-with-args-until-success 'org-shiftdown-hook))
18208 ((and org-support-shift-select (org-region-active-p))
18209 (org-call-for-shift-select 'next-line))
18210 ((org-at-timestamp-p t)
18211 (call-interactively (if org-edit-timestamp-down-means-later
18212 'org-timestamp-up 'org-timestamp-down)))
18213 ((and (not (eq org-support-shift-select 'always))
18214 org-enable-priority-commands
18215 (org-at-heading-p))
18216 (call-interactively 'org-priority-down))
18217 ((and (not org-support-shift-select) (org-at-item-p))
18218 (call-interactively 'org-next-item))
18219 ((org-clocktable-try-shift 'down arg))
18220 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
18221 (org-support-shift-select
18222 (org-call-for-shift-select 'next-line))
18223 (t (org-shiftselect-error))))
18225 (defun org-shiftright (&optional arg)
18226 "Cycle the thing at point or in the current line, depending on context.
18227 Depending on context, this does one of the following:
18229 - switch a timestamp at point one day into the future
18230 - on a headline, switch to the next TODO keyword.
18231 - on an item, switch entire list to the next bullet type
18232 - on a property line, switch to the next allowed value
18233 - on a clocktable definition line, move time block into the future"
18236 ((run-hook-with-args-until-success 'org-shiftright-hook))
18237 ((and org-support-shift-select (org-region-active-p))
18238 (org-call-for-shift-select 'forward-char))
18239 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
18240 ((and (not (eq org-support-shift-select 'always))
18241 (org-at-heading-p))
18242 (let ((org-inhibit-logging
18243 (not org-treat-S-cursor-todo-selection-as-state-change))
18244 (org-inhibit-blocking
18245 (not org-treat-S-cursor-todo-selection-as-state-change)))
18246 (org-call-with-arg 'org-todo 'right)))
18247 ((or (and org-support-shift-select
18248 (not (eq org-support-shift-select 'always))
18249 (org-at-item-bullet-p))
18250 (and (not org-support-shift-select) (org-at-item-p)))
18251 (org-call-with-arg 'org-cycle-list-bullet nil))
18252 ((and (not (eq org-support-shift-select 'always))
18253 (org-at-property-p))
18254 (call-interactively 'org-property-next-allowed-value))
18255 ((org-clocktable-try-shift 'right arg))
18256 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
18257 (org-support-shift-select
18258 (org-call-for-shift-select 'forward-char))
18259 (t (org-shiftselect-error))))
18261 (defun org-shiftleft (&optional arg)
18262 "Cycle the thing at point or in the current line, depending on context.
18263 Depending on context, this does one of the following:
18265 - switch a timestamp at point one day into the past
18266 - on a headline, switch to the previous TODO keyword.
18267 - on an item, switch entire list to the previous bullet type
18268 - on a property line, switch to the previous allowed value
18269 - on a clocktable definition line, move time block into the past"
18272 ((run-hook-with-args-until-success 'org-shiftleft-hook))
18273 ((and org-support-shift-select (org-region-active-p))
18274 (org-call-for-shift-select 'backward-char))
18275 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
18276 ((and (not (eq org-support-shift-select 'always))
18277 (org-at-heading-p))
18278 (let ((org-inhibit-logging
18279 (not org-treat-S-cursor-todo-selection-as-state-change))
18280 (org-inhibit-blocking
18281 (not org-treat-S-cursor-todo-selection-as-state-change)))
18282 (org-call-with-arg 'org-todo 'left)))
18283 ((or (and org-support-shift-select
18284 (not (eq org-support-shift-select 'always))
18285 (org-at-item-bullet-p))
18286 (and (not org-support-shift-select) (org-at-item-p)))
18287 (org-call-with-arg 'org-cycle-list-bullet 'previous))
18288 ((and (not (eq org-support-shift-select 'always))
18289 (org-at-property-p))
18290 (call-interactively 'org-property-previous-allowed-value))
18291 ((org-clocktable-try-shift 'left arg))
18292 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
18293 (org-support-shift-select
18294 (org-call-for-shift-select 'backward-char))
18295 (t (org-shiftselect-error))))
18297 (defun org-shiftcontrolright ()
18298 "Switch to next TODO set."
18301 ((and org-support-shift-select (org-region-active-p))
18302 (org-call-for-shift-select 'forward-word))
18303 ((and (not (eq org-support-shift-select 'always))
18304 (org-at-heading-p))
18305 (org-call-with-arg 'org-todo 'nextset))
18306 (org-support-shift-select
18307 (org-call-for-shift-select 'forward-word))
18308 (t (org-shiftselect-error))))
18310 (defun org-shiftcontrolleft ()
18311 "Switch to previous TODO set."
18314 ((and org-support-shift-select (org-region-active-p))
18315 (org-call-for-shift-select 'backward-word))
18316 ((and (not (eq org-support-shift-select 'always))
18317 (org-at-heading-p))
18318 (org-call-with-arg 'org-todo 'previousset))
18319 (org-support-shift-select
18320 (org-call-for-shift-select 'backward-word))
18321 (t (org-shiftselect-error))))
18323 (defun org-shiftcontrolup ()
18324 "Change timestamps synchronously up in CLOCK log lines."
18326 (cond ((and (not org-support-shift-select)
18327 (org-at-clock-log-p)
18328 (org-at-timestamp-p t))
18329 (org-clock-timestamps-up))
18330 (t (org-shiftselect-error))))
18332 (defun org-shiftcontroldown ()
18333 "Change timestamps synchronously down in CLOCK log lines."
18335 (cond ((and (not org-support-shift-select)
18336 (org-at-clock-log-p)
18337 (org-at-timestamp-p t))
18338 (org-clock-timestamps-down))
18339 (t (org-shiftselect-error))))
18341 (defun org-ctrl-c-ret ()
18342 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
18345 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
18346 (t (call-interactively 'org-insert-heading))))
18348 (defun org-find-visible ()
18350 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
18351 (get-char-property s 'invisible)))
18353 (defun org-find-invisible ()
18355 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
18356 (not (get-char-property s 'invisible))))
18359 (defun org-copy-visible (beg end)
18360 "Copy the visible parts of the region."
18365 (narrow-to-region beg end)
18366 (setq s (goto-char (point-min)))
18367 (while (not (= (point) (point-max)))
18368 (goto-char (org-find-invisible))
18369 (push (buffer-substring s (point)) snippets)
18370 (setq s (goto-char (org-find-visible))))))
18371 (kill-new (apply 'concat (nreverse snippets)))))
18373 (defun org-copy-special ()
18374 "Copy region in table or copy current subtree.
18375 Calls `org-table-copy' or `org-copy-subtree', depending on context.
18376 See the individual commands for more information."
18378 (call-interactively
18379 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
18381 (defun org-cut-special ()
18382 "Cut region in table or cut current subtree.
18383 Calls `org-table-copy' or `org-cut-subtree', depending on context.
18384 See the individual commands for more information."
18386 (call-interactively
18387 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
18389 (defun org-paste-special (arg)
18390 "Paste rectangular region into table, or past subtree relative to level.
18391 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
18392 See the individual commands for more information."
18394 (if (org-at-table-p)
18395 (org-table-paste-rectangle)
18396 (org-paste-subtree arg)))
18398 (defun org-edit-special (&optional arg)
18399 "Call a special editor for the stuff at point.
18400 When at a table, call the formula editor with `org-table-edit-formulas'.
18401 When at the first line of an src example, call `org-edit-src-code'.
18402 When in an #+include line, visit the include file. Otherwise call
18403 `ffap' to visit the file at point."
18405 ;; possibly prep session before editing source
18407 (let* ((info (org-babel-get-src-block-info))
18408 (lang (nth 0 info))
18409 (params (nth 2 info))
18410 (session (cdr (assoc :session params))))
18411 (when (and info session) ;; we are in a source-code block with a session
18413 (intern (concat "org-babel-prep-session:" lang)) session params))))
18414 (cond ;; proceed with `org-edit-special'
18416 (beginning-of-line 1)
18417 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
18418 (find-file (org-trim (match-string 1))))
18419 ((org-edit-src-code))
18420 ((org-edit-fixed-width-region))
18421 ((org-at-table.el-p)
18422 (org-edit-src-code))
18423 ((or (org-at-table-p)
18425 (beginning-of-line 1)
18426 (looking-at "[ \t]*#\\+TBLFM:")))
18427 (call-interactively 'org-table-edit-formulas))
18428 (t (call-interactively 'ffap))))
18430 (defvar org-table-coordinate-overlays) ; defined in org-table.el
18431 (defun org-ctrl-c-ctrl-c (&optional arg)
18432 "Set tags in headline, or update according to changed information at point.
18434 This command does many different things, depending on context:
18436 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
18437 this is what we do.
18439 - If the cursor is on a statistics cookie, update it.
18441 - If the cursor is in a headline, prompt for tags and insert them
18442 into the current line, aligned to `org-tags-column'. When called
18443 with prefix arg, realign all tags in the current buffer.
18445 - If the cursor is in one of the special #+KEYWORD lines, this
18446 triggers scanning the buffer for these lines and updating the
18449 - If the cursor is inside a table, realign the table. This command
18450 works even if the automatic table editor has been turned off.
18452 - If the cursor is on a #+TBLFM line, re-apply the formulas to
18455 - If the cursor is at a footnote reference or definition, jump to
18456 the corresponding definition or references, respectively.
18458 - If the cursor is a the beginning of a dynamic block, update it.
18460 - If the current buffer is a capture buffer, close note and file it.
18462 - If the cursor is on a <<<target>>>, update radio targets and
18463 corresponding links in this buffer.
18465 - If the cursor is on a numbered item in a plain list, renumber the
18468 - If the cursor is on a checkbox, toggle it.
18470 - If the cursor is on a code block, evaluate it. The variable
18471 `org-confirm-babel-evaluate' can be used to control prompting
18472 before code block evaluation, by default every code block
18473 evaluation requires confirmation. Code block evaluation can be
18474 inhibited by setting `org-babel-no-eval-on-ctrl-c-ctrl-c'."
18476 (let ((org-enable-table-editor t))
18478 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
18479 org-occur-highlights
18480 org-latex-fragment-image-overlays)
18481 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
18482 (org-remove-occur-highlights)
18483 (org-remove-latex-fragment-image-overlays)
18484 (message "Temporary highlights/overlays removed from current buffer"))
18485 ((and (local-variable-p 'org-finish-function (current-buffer))
18486 (fboundp org-finish-function))
18487 (funcall org-finish-function))
18488 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
18489 ((org-in-regexp org-ts-regexp-both)
18490 (org-timestamp-change 0 'day))
18491 ((or (looking-at org-property-start-re)
18492 (org-at-property-p))
18493 (call-interactively 'org-property-action))
18494 ((org-at-target-p) (call-interactively 'org-update-radio-target-regexp))
18495 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
18496 (or (org-at-heading-p) (org-at-item-p)))
18497 (call-interactively 'org-update-statistics-cookies))
18498 ((org-at-heading-p) (call-interactively 'org-set-tags))
18499 ((org-at-table.el-p)
18500 (message "Use C-c ' to edit table.el tables"))
18502 (org-table-maybe-eval-formula)
18504 (call-interactively 'org-table-recalculate)
18505 (org-table-maybe-recalculate-line))
18506 (call-interactively 'org-table-align)
18507 (orgtbl-send-table 'maybe))
18508 ((or (org-footnote-at-reference-p)
18509 (org-footnote-at-definition-p))
18510 (call-interactively 'org-footnote-action))
18511 ((org-at-item-checkbox-p)
18512 ;; Cursor at a checkbox: repair list and update checkboxes. Send
18513 ;; list only if at top item.
18514 (let* ((cbox (match-string 1))
18515 (struct (org-list-struct))
18516 (old-struct (copy-tree struct))
18517 (parents (org-list-parents-alist struct))
18518 (orderedp (org-entry-get nil "ORDERED"))
18519 (firstp (= (org-list-get-top-point struct) (point-at-bol)))
18521 ;; Use a light version of `org-toggle-checkbox' to avoid
18522 ;; computing list structure twice.
18523 (let ((new-box (cond
18524 ((equal arg '(16)) "[-]")
18525 ((equal arg '(4)) nil)
18526 ((equal "[X]" cbox) "[ ]")
18528 (if (and firstp arg)
18529 ;; If at first item of sub-list, remove check-box from
18530 ;; every item at the same level.
18532 (lambda (pos) (org-list-set-checkbox pos struct new-box))
18533 (org-list-get-all-items
18534 (point-at-bol) struct (org-list-prevs-alist struct)))
18535 (org-list-set-checkbox (point-at-bol) struct new-box)))
18536 ;; Replicate `org-list-write-struct', while grabbing a return
18537 ;; value from `org-list-struct-fix-box'.
18538 (org-list-struct-fix-ind struct parents 2)
18539 (org-list-struct-fix-item-end struct)
18540 (let ((prevs (org-list-prevs-alist struct)))
18541 (org-list-struct-fix-bul struct prevs)
18542 (org-list-struct-fix-ind struct parents)
18544 (org-list-struct-fix-box struct parents prevs orderedp)))
18545 (org-list-struct-apply-struct struct old-struct)
18546 (org-update-checkbox-count-maybe)
18549 "Checkboxes were removed due to unchecked box at line %d"
18550 (org-current-line block-item)))
18551 (when firstp (org-list-send-list 'maybe))))
18553 ;; Cursor at an item: repair list. Do checkbox related actions
18554 ;; only if function was called with an argument. Send list only
18556 (let* ((struct (org-list-struct))
18557 (firstp (= (org-list-get-top-point struct) (point-at-bol)))
18560 (setq old-struct (copy-tree struct))
18562 ;; If at first item of sub-list, add check-box to every
18563 ;; item at the same level.
18566 (unless (org-list-get-checkbox pos struct)
18567 (org-list-set-checkbox pos struct "[ ]")))
18568 (org-list-get-all-items
18569 (point-at-bol) struct (org-list-prevs-alist struct)))
18570 (org-list-set-checkbox (point-at-bol) struct "[ ]")))
18571 (org-list-write-struct
18572 struct (org-list-parents-alist struct) old-struct)
18573 (when arg (org-update-checkbox-count-maybe))
18574 (when firstp (org-list-send-list 'maybe))))
18575 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
18577 (beginning-of-line 1)
18578 (save-excursion (org-update-dblock)))
18580 (beginning-of-line 1)
18581 (looking-at "[ \t]*#\\+\\([A-Z]+\\)"))
18583 ((equal (match-string 1) "TBLFM")
18584 ;; Recalculate the table before this line
18586 (beginning-of-line 1)
18587 (skip-chars-backward " \r\n\t")
18588 (if (org-at-table-p)
18589 (org-call-with-arg 'org-table-recalculate (or arg t)))))
18591 (let ((org-inhibit-startup-visibility-stuff t)
18592 (org-startup-align-all-tables nil))
18593 (when (boundp 'org-table-coordinate-overlays)
18594 (mapc 'delete-overlay org-table-coordinate-overlays)
18595 (setq org-table-coordinate-overlays nil))
18596 (org-save-outline-visibility 'use-markers (org-mode-restart)))
18597 (message "Local setup has been refreshed"))))
18598 ((org-clock-update-time-maybe))
18600 (or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
18601 (error "C-c C-c can do nothing useful at this location"))))))
18603 (defun org-mode-restart ()
18604 "Restart Org-mode, to scan again for special lines.
18605 Also updates the keyword regular expressions."
18608 (message "Org-mode restarted"))
18610 (defun org-kill-note-or-show-branches ()
18611 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
18613 (if (not org-finish-function)
18616 (call-interactively 'show-branches))
18617 (let ((org-note-abort t))
18618 (funcall org-finish-function))))
18620 (defun org-return (&optional indent)
18621 "Goto next table row or insert a newline.
18622 Calls `org-table-next-row' or `newline', depending on context.
18623 See the individual commands for more information."
18626 ((or (bobp) (org-in-src-block-p))
18627 (if indent (newline-and-indent) (newline)))
18629 (org-table-justify-field-maybe)
18630 (call-interactively 'org-table-next-row))
18631 ;; when `newline-and-indent' is called within a list, make sure
18632 ;; text moved stays inside the item.
18633 ((and (org-in-item-p) indent)
18634 (if (and (org-at-item-p) (>= (point) (match-end 0)))
18636 (save-match-data (newline))
18637 (org-indent-line-to (length (match-string 0))))
18638 (let ((ind (org-get-indentation)))
18640 (if (org-looking-back org-list-end-re)
18641 (org-indent-line-function)
18642 (org-indent-line-to ind)))))
18643 ((and org-return-follows-link
18644 (let ((tprop (get-text-property (point) 'face)))
18645 (or (eq tprop 'org-link)
18646 (and (listp tprop) (memq 'org-link tprop)))))
18647 (call-interactively 'org-open-at-point))
18648 ((and (org-at-heading-p)
18650 (org-re "\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")))
18654 (t (if indent (newline-and-indent) (newline)))))
18656 (defun org-return-indent ()
18657 "Goto next table row or insert a newline and indent.
18658 Calls `org-table-next-row' or `newline-and-indent', depending on
18659 context. See the individual commands for more information."
18663 (defun org-ctrl-c-star ()
18664 "Compute table, or change heading status of lines.
18665 Calls `org-table-recalculate' or `org-toggle-heading',
18666 depending on context."
18670 (call-interactively 'org-table-recalculate))
18672 ;; Convert all lines in region to list items
18673 (call-interactively 'org-toggle-heading))))
18675 (defun org-ctrl-c-minus ()
18676 "Insert separator line in table or modify bullet status of line.
18677 Also turns a plain line or a region of lines into list items.
18678 Calls `org-table-insert-hline', `org-toggle-item', or
18679 `org-cycle-list-bullet', depending on context."
18683 (call-interactively 'org-table-insert-hline))
18684 ((org-region-active-p)
18685 (call-interactively 'org-toggle-item))
18687 (call-interactively 'org-cycle-list-bullet))
18689 (call-interactively 'org-toggle-item))))
18691 (defun org-toggle-item (arg)
18692 "Convert headings or normal lines to items, items to normal lines.
18693 If there is no active region, only the current line is considered.
18695 If the first non blank line in the region is an headline, convert
18696 all headlines to items, shifting text accordingly.
18698 If it is an item, convert all items to normal lines.
18700 If it is normal text, change region into an item. With a prefix
18701 argument ARG, change each line in region into an item."
18705 ;; Shift text in current section to IND, from point to END.
18706 ;; The function leaves point to END line.
18708 (let ((min-i 1000) (end (copy-marker end)))
18709 ;; First determine the minimum indentation (MIN-I) of
18713 (while (< (point) end)
18714 (let ((i (org-get-indentation)))
18716 ;; Skip blank lines and inline tasks.
18717 ((looking-at "^[ \t]*$"))
18718 ((looking-at org-outline-regexp-bol))
18719 ;; We can't find less than 0 indentation.
18720 ((zerop i) (throw 'exit (setq min-i 0)))
18721 ((< i min-i) (setq min-i i))))
18723 ;; Then indent each line so that a line indented to
18724 ;; MIN-I becomes indented to IND. Ignore blank lines
18725 ;; and inline tasks in the process.
18726 (let ((delta (- ind min-i)))
18727 (while (< (point) end)
18728 (unless (or (looking-at "^[ \t]*$")
18729 (looking-at org-outline-regexp-bol))
18730 (org-indent-line-to (+ (org-get-indentation) delta)))
18731 (forward-line)))))))
18734 ;; Return beginning of first non-blank line, starting from
18739 (skip-chars-forward " \r\t\n")
18742 ;; Determine boundaries of changes.
18743 (if (org-region-active-p)
18744 (setq beg (funcall skip-blanks (region-beginning))
18745 end (copy-marker (region-end)))
18746 (setq beg (funcall skip-blanks (point-at-bol))
18747 end (copy-marker (point-at-eol))))
18748 ;; Depending on the starting line, choose an action on the text
18749 ;; between BEG and END.
18750 (org-with-limited-levels
18754 ;; Case 1. Start at an item: de-itemize. Note that it only
18755 ;; happens when a region is active: `org-ctrl-c-minus'
18756 ;; would call `org-cycle-list-bullet' otherwise.
18758 (while (< (point) end)
18759 (when (org-at-item-p)
18760 (skip-chars-forward " \t")
18761 (delete-region (point) (match-end 0)))
18763 ;; Case 2. Start at an heading: convert to items.
18764 ((org-at-heading-p)
18765 (let* ((bul (org-list-bullet-string "-"))
18766 (bul-len (length bul))
18767 ;; Indentation of the first heading. It should be
18768 ;; relative to the indentation of its parent, if any.
18769 (start-ind (save-excursion
18771 ((not org-adapt-indentation) 0)
18772 ((not (outline-previous-heading)) 0)
18773 (t (length (match-string 0))))))
18774 ;; Level of first heading. Further headings will be
18775 ;; compared to it to determine hierarchy in the list.
18776 (ref-level (org-reduced-level (org-outline-level))))
18777 (while (< (point) end)
18778 (let* ((level (org-reduced-level (org-outline-level)))
18779 (delta (max 0 (- level ref-level))))
18780 ;; If current headline is less indented than the first
18781 ;; one, set it as reference, in order to preserve
18783 (when (< level ref-level) (setq ref-level level))
18784 (replace-match bul t t)
18785 (org-indent-line-to (+ start-ind (* delta bul-len)))
18786 ;; Ensure all text down to END (or SECTION-END) belongs
18787 ;; to the newly created item.
18788 (let ((section-end (save-excursion
18789 (or (outline-next-heading) (point)))))
18791 (funcall shift-text
18792 (+ start-ind (* (1+ delta) bul-len))
18793 (min end section-end)))))))
18794 ;; Case 3. Normal line with ARG: turn each non-item line into
18797 (while (< (point) end)
18798 (unless (or (org-at-heading-p) (org-at-item-p))
18799 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
18801 (concat "\\1" (org-list-bullet-string "-") "\\2"))))
18803 ;; Case 4. Normal line without ARG: make the first line of
18804 ;; region an item, and shift indentation of others
18805 ;; lines to set them as item's body.
18806 (t (let* ((bul (org-list-bullet-string "-"))
18807 (bul-len (length bul))
18808 (ref-ind (org-get-indentation)))
18809 (skip-chars-forward " \t")
18812 (while (< (point) end)
18813 ;; Ensure that lines less indented than first one
18814 ;; still get included in item body.
18815 (funcall shift-text
18816 (+ ref-ind bul-len)
18817 (min end (save-excursion (or (outline-next-heading)
18819 (forward-line)))))))))
18821 (defun org-toggle-heading (&optional nstars)
18822 "Convert headings to normal text, or items or text to headings.
18823 If there is no active region, only the current line is considered.
18825 If the first non blank line is an headline, remove the stars from
18826 all headlines in the region.
18828 If it is a plain list item, turn all plain list items into headings.
18830 If it is a normal line, turn each and every normal line (i.e. not
18831 an heading or an item) in the region into a heading.
18833 When converting a line into a heading, the number of stars is chosen
18834 such that the lines become children of the current entry. However,
18835 when a prefix argument is given, its value determines the number of
18840 ;; Return beginning of first non-blank line, starting from
18845 (skip-chars-forward " \r\t\n")
18848 ;; Determine boundaries of changes. If region ends at a bol, do
18849 ;; not consider the last line to be in the region.
18850 (if (org-region-active-p)
18851 (setq beg (funcall skip-blanks (region-beginning))
18852 end (copy-marker (save-excursion
18853 (goto-char (region-end))
18854 (if (bolp) (point) (point-at-eol)))))
18855 (setq beg (funcall skip-blanks (point-at-bol))
18856 end (copy-marker (point-at-eol))))
18857 ;; Ensure inline tasks don't count as headings.
18858 (org-with-limited-levels
18862 ;; Case 1. Started at an heading: de-star headings.
18863 ((org-at-heading-p)
18864 (while (< (point) end)
18865 (when (org-at-heading-p t)
18866 (looking-at org-outline-regexp) (replace-match ""))
18868 ;; Case 2. Started at an item: change items into headlines.
18869 ;; One star will be added by `org-list-to-subtree'.
18871 (let* ((stars (make-string
18873 ;; subtract the star that will be added again by
18874 ;; `org-list-to-subtree'
18875 (1- (prefix-numeric-value current-prefix-arg))
18876 (or (org-current-level) 0))
18879 (cond (nstars "") ; stars from prefix only
18880 ((equal stars "") "") ; before first heading
18881 (org-odd-levels-only "*") ; inside heading, odd
18882 (t "")))) ; inside heading, oddeven
18883 (while (< (point) end)
18884 (when (org-at-item-p)
18885 ;; Pay attention to cases when region ends before list.
18886 (let* ((struct (org-list-struct))
18887 (list-end (min (org-list-get-bottom-point struct) (1+ end))))
18889 (narrow-to-region (point) list-end)
18891 (org-list-to-subtree
18892 (org-list-parse-list t)
18893 '(:istart (concat stars add-stars (funcall get-stars depth))
18894 :icount (concat stars add-stars (funcall get-stars depth))))))))
18896 ;; Case 3. Started at normal text: make every line an heading,
18897 ;; skipping headlines and items.
18898 (t (let* ((stars (make-string
18900 (prefix-numeric-value current-prefix-arg)
18901 (or (org-current-level) 0))
18904 (cond (nstars "") ; stars from prefix only
18905 ((equal stars "") "*") ; before first heading
18906 (org-odd-levels-only "**") ; inside heading, odd
18907 (t "*"))) ; inside heading, oddeven
18908 (rpl (concat stars add-stars " ")))
18909 (while (< (point) end)
18910 (when (and (not (org-at-heading-p)) (not (org-at-item-p))
18911 (looking-at "\\([ \t]*\\)\\(\\S-\\)"))
18912 (replace-match (concat rpl (match-string 2))))
18913 (forward-line)))))))))
18915 (defun org-meta-return (&optional arg)
18916 "Insert a new heading or wrap a region in a table.
18917 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
18918 See the individual commands for more information."
18921 ((run-hook-with-args-until-success 'org-metareturn-hook))
18922 ((or (org-at-drawer-p) (org-at-property-p))
18923 (newline-and-indent))
18925 (call-interactively 'org-table-wrap-region))
18926 (t (call-interactively 'org-insert-heading))))
18930 ;; Define the Org-mode menus
18931 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
18933 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
18934 ["Next Field" org-cycle (org-at-table-p)]
18935 ["Previous Field" org-shifttab (org-at-table-p)]
18936 ["Next Row" org-return (org-at-table-p)]
18938 ["Blank Field" org-table-blank-field (org-at-table-p)]
18939 ["Edit Field" org-table-edit-field (org-at-table-p)]
18940 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
18943 ["Move Column Left" org-metaleft (org-at-table-p)]
18944 ["Move Column Right" org-metaright (org-at-table-p)]
18945 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
18946 ["Insert Column" org-shiftmetaright (org-at-table-p)])
18948 ["Move Row Up" org-metaup (org-at-table-p)]
18949 ["Move Row Down" org-metadown (org-at-table-p)]
18950 ["Delete Row" org-shiftmetaup (org-at-table-p)]
18951 ["Insert Row" org-shiftmetadown (org-at-table-p)]
18952 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
18954 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
18956 ["Copy Rectangle" org-copy-special (org-at-table-p)]
18957 ["Cut Rectangle" org-cut-special (org-at-table-p)]
18958 ["Paste Rectangle" org-paste-special (org-at-table-p)]
18959 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
18962 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
18963 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
18964 ["Edit Formulas" org-edit-special (org-at-table-p)]
18966 ["Recalculate line" org-table-recalculate (org-at-table-p)]
18967 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
18968 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
18970 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
18972 ["Sum Column/Rectangle" org-table-sum
18973 (or (org-at-table-p) (org-region-active-p))]
18974 ["Which Column?" org-table-current-column (org-at-table-p)])
18976 org-table-toggle-formula-debugger
18977 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
18978 ["Show Col/Row Numbers"
18979 org-table-toggle-coordinate-overlays
18981 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
18983 ["Create" org-table-create (and (not (org-at-table-p))
18984 org-enable-table-editor)]
18985 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
18986 ["Import from File" org-table-import (not (org-at-table-p))]
18987 ["Export to File" org-table-export (org-at-table-p)]
18989 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
18991 (easy-menu-define org-org-menu org-mode-map "Org menu"
18994 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
18995 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
18996 ["Sparse Tree..." org-sparse-tree t]
18997 ["Reveal Context" org-reveal t]
18998 ["Show All" show-all t]
19000 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
19002 ["New Heading" org-insert-heading t]
19003 ("Navigate Headings"
19004 ["Up" outline-up-heading t]
19005 ["Next" outline-next-visible-heading t]
19006 ["Previous" outline-previous-visible-heading t]
19007 ["Next Same Level" outline-forward-same-level t]
19008 ["Previous Same Level" outline-backward-same-level t]
19010 ["Jump" org-goto t])
19012 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
19013 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
19015 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
19016 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
19017 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
19019 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
19021 ["Copy visible text" org-copy-visible t]
19023 ["Promote Heading" org-metaleft (not (org-at-table-p))]
19024 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
19025 ["Demote Heading" org-metaright (not (org-at-table-p))]
19026 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
19028 ["Sort Region/Children" org-sort (not (org-at-table-p))]
19030 ["Convert to odd levels" org-convert-to-odd-levels t]
19031 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
19033 ["Emphasis..." org-emphasize t]
19034 ["Edit Source Example" org-edit-special t]
19036 ["Footnote new/jump" org-footnote-action t]
19037 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
19039 ["Archive (default method)" org-archive-subtree-default t]
19041 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
19042 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
19043 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
19047 ["Store Link (Global)" org-store-link t]
19048 ["Find existing link to here" org-occur-link-in-agenda-files t]
19049 ["Insert Link" org-insert-link t]
19050 ["Follow Link" org-open-at-point t]
19052 ["Next link" org-next-link t]
19053 ["Previous link" org-previous-link t]
19055 ["Descriptive Links"
19056 org-toggle-link-display
19058 :selected org-descriptive-links
19061 org-toggle-link-display
19063 :selected (not org-descriptive-links)])
19066 ["TODO/DONE/-" org-todo t]
19068 ["Next keyword" org-shiftright (org-at-heading-p)]
19069 ["Previous keyword" org-shiftleft (org-at-heading-p)]
19070 ["Complete Keyword" pcomplete (assq :todo-keyword (org-context))]
19071 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))]
19072 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))])
19073 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
19074 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
19076 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
19077 :selected org-enforce-todo-dependencies :style toggle :active t]
19078 "Settings for tree at point"
19079 ["Do Children sequentially" org-toggle-ordered-property :style radio
19080 :selected (org-entry-get nil "ORDERED")
19081 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
19082 ["Do Children parallel" org-toggle-ordered-property :style radio
19083 :selected (not (org-entry-get nil "ORDERED"))
19084 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
19086 ["Set Priority" org-priority t]
19087 ["Priority Up" org-shiftup t]
19088 ["Priority Down" org-shiftdown t]
19090 ["Get news from all feeds" org-feed-update-all t]
19091 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
19092 ["Customize feeds" (customize-variable 'org-feed-alist) t])
19093 ("TAGS and Properties"
19094 ["Set Tags" org-set-tags-command t]
19095 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
19097 ["Set property" org-set-property t]
19098 ["Column view of properties" org-columns t]
19099 ["Insert Column View DBlock" org-insert-columns-dblock t])
19100 ("Dates and Scheduling"
19101 ["Timestamp" org-time-stamp t]
19102 ["Timestamp (inactive)" org-time-stamp-inactive t]
19104 ["1 Day Later" org-shiftright t]
19105 ["1 Day Earlier" org-shiftleft t]
19106 ["1 ... Later" org-shiftup t]
19107 ["1 ... Earlier" org-shiftdown t])
19108 ["Compute Time Range" org-evaluate-time-range t]
19109 ["Schedule Item" org-schedule t]
19110 ["Deadline" org-deadline t]
19112 ["Custom time format" org-toggle-time-stamp-overlays
19113 :style radio :selected org-display-custom-times]
19115 ["Goto Calendar" org-goto-calendar t]
19116 ["Date from Calendar" org-date-from-calendar t]
19118 ["Start/Restart Timer" org-timer-start t]
19119 ["Pause/Continue Timer" org-timer-pause-or-continue t]
19120 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
19121 ["Insert Timer String" org-timer t]
19122 ["Insert Timer Item" org-timer-item t])
19124 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
19125 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
19126 ["Clock out" org-clock-out t]
19127 ["Clock cancel" org-clock-cancel t]
19129 ["Mark as default task" org-clock-mark-default-task t]
19130 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
19131 ["Goto running clock" org-clock-goto t]
19133 ["Display times" org-clock-display t]
19134 ["Create clock table" org-clock-report t]
19136 ["Record DONE time"
19137 (progn (setq org-log-done (not org-log-done))
19138 (message "Switching to %s will %s record a timestamp"
19139 (car org-done-keywords)
19140 (if org-log-done "automatically" "not")))
19141 :style toggle :selected org-log-done])
19143 ["Agenda Command..." org-agenda t]
19144 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
19145 ("File List for Agenda")
19146 ("Special views current file"
19147 ["TODO Tree" org-show-todo-tree t]
19148 ["Check Deadlines" org-check-deadlines t]
19149 ["Timeline" org-timeline t]
19150 ["Tags/Property tree" org-match-sparse-tree t])
19152 ["Export/Publish..." org-export t]
19154 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
19155 :selected org-cdlatex-mode]
19156 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
19157 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
19158 ["Modify math symbol" org-cdlatex-math-modify
19159 (org-inside-LaTeX-fragment-p)]
19160 ["Insert citation" org-reftex-citation t]
19162 ["Template for BEAMER" org-insert-beamer-options-template t])
19165 ["Push Files and Views" org-mobile-push t]
19166 ["Get Captured and Flagged" org-mobile-pull t]
19167 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
19169 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
19172 ["Show Version" org-version t]
19173 ["Info Documentation" org-info t])
19175 ["Browse Org Group" org-customize t]
19177 ["Expand This Menu" org-create-customize-menu
19178 (fboundp 'customize-menu-create)])
19179 ["Send bug report" org-submit-bug-report t]
19182 ["Refresh setup current buffer" org-mode-restart t]
19183 ["Reload Org (after update)" org-reload t]
19184 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
19187 (defun org-info (&optional node)
19188 "Read documentation for Org-mode in the info system.
19189 With optional NODE, go directly to that node."
19191 (info (format "(org)%s" (or node ""))))
19194 (defun org-submit-bug-report ()
19195 "Submit a bug report on Org-mode via mail.
19197 Don't hesitate to report any problems or inaccurate documentation.
19199 If you don't have setup sending mail from (X)Emacs, please copy the
19200 output buffer into your mail program, as it gives us important
19201 information about your Org-mode version and configuration."
19203 (require 'reporter)
19204 (org-load-modules-maybe)
19205 (org-require-autoloaded-modules)
19206 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
19207 (reporter-submit-bug-report
19208 "emacs-orgmode@gnu.org"
19211 (save-window-excursion
19212 (org-pop-to-buffer-same-window (get-buffer-create "*Warn about privacy*"))
19213 (delete-other-windows)
19215 (insert "You are about to submit a bug report to the Org-mode mailing list.
19217 We would like to add your full Org-mode and Outline configuration to the
19218 bug report. This greatly simplifies the work of the maintainer and
19219 other experts on the mailing list.
19221 HOWEVER, some variables you have customized may contain private
19222 information. The names of customers, colleagues, or friends, might
19223 appear in the form of file names, tags, todo states, or search strings.
19224 If you answer yes to the prompt, you might want to check and remove
19225 such private information before sending the email.")
19226 (add-text-properties (point-min) (point-max) '(face org-warning))
19227 (when (yes-or-no-p "Include your Org-mode configuration ")
19231 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
19232 (or (and (symbol-value v)
19233 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
19235 (get v 'custom-type) (get v 'standard-value)
19236 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
19238 (kill-buffer (get-buffer "*Warn about privacy*"))
19241 "Remember to cover the basics, that is, what you expected to happen and
19242 what in fact did happen. You don't know how to make a good report? See
19244 http://orgmode.org/manual/Feedback.html#Feedback
19246 Your bug report will be posted to the Org-mode mailing list.
19247 ------------------------------------------------------------------------")
19249 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
19250 (replace-match "\\1Bug: \\3 [\\2]")))))
19253 (defun org-install-agenda-files-menu ()
19254 (let ((bl (buffer-list)))
19257 (set-buffer (pop bl))
19258 (if (eq major-mode 'org-mode) (setq bl nil)))
19259 (when (eq major-mode 'org-mode)
19261 '("Org") "File List for Agenda"
19264 ["Edit File List" (org-edit-agenda-file-list) t]
19265 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
19266 ["Remove Current File from List" org-remove-file t]
19267 ["Cycle through agenda files" org-cycle-agenda-files t]
19268 ["Occur in all agenda files" org-occur-in-agenda-files t]
19270 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
19275 (defun org-require-autoloaded-modules ()
19278 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
19279 org-docbook org-exp org-html org-icalendar
19281 org-publish org-remember org-table
19282 org-timer org-xoxo)))
19285 (defun org-reload (&optional uncompiled)
19286 "Reload all org lisp files.
19287 With prefix arg UNCOMPILED, load the uncompiled versions."
19289 (require 'find-func)
19290 (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
19291 (dir-org (file-name-directory (org-find-library-name "org")))
19292 (dir-org-contrib (ignore-errors
19293 (file-name-directory
19294 (org-find-library-name "org-contribdir"))))
19296 (mapcar (lambda (el) (concat "ob" (when el (format "-%s" el)) ".el"))
19297 (append (list nil "comint" "eval" "exp" "keys"
19298 "lob" "ref" "table" "tangle")
19302 (when (cdr lang) (symbol-name (car lang))))
19303 org-babel-load-languages)))))
19305 (append (directory-files dir-org t file-re)
19307 (and dir-org-contrib
19308 (directory-files dir-org-contrib t file-re))))
19309 (remove-re (concat (if (featurep 'xemacs)
19310 "org-colview" "org-colview-xemacs")
19312 (setq files (mapcar 'file-name-sans-extension files))
19313 (setq files (mapcar
19314 (lambda (x) (if (string-match remove-re x) nil x))
19316 (setq files (delq nil files))
19319 (when (featurep (intern (file-name-nondirectory f)))
19320 (if (and (not uncompiled)
19321 (file-exists-p (concat f ".elc")))
19322 (load (concat f ".elc") nil nil t)
19323 (load (concat f ".el") nil nil t))))
19328 (defun org-customize ()
19329 "Call the customize function with org as argument."
19331 (org-load-modules-maybe)
19332 (org-require-autoloaded-modules)
19333 (customize-browse 'org))
19335 (defun org-create-customize-menu ()
19336 "Create a full customization menu for Org-mode, insert it into the menu."
19338 (org-load-modules-maybe)
19339 (org-require-autoloaded-modules)
19340 (if (fboundp 'customize-menu-create)
19343 '("Org") "Customize"
19344 `(["Browse Org group" org-customize t]
19346 ,(customize-menu-create 'org)
19347 ["Set" Custom-set t]
19348 ["Save" Custom-save t]
19349 ["Reset to Current" Custom-reset-current t]
19350 ["Reset to Saved" Custom-reset-saved t]
19351 ["Reset to Standard Settings" Custom-reset-standard t]))
19352 (message "\"Org\"-menu now contains full customization menu"))
19353 (error "Cannot expand menu (outdated version of cus-edit.el)")))
19355 ;;;; Miscellaneous stuff
19357 ;;; Generally useful functions
19359 (defun org-get-at-bol (property)
19360 "Get text property PROPERTY at beginning of line."
19361 (get-text-property (point-at-bol) property))
19363 (defun org-find-text-property-in-string (prop s)
19364 "Return the first non-nil value of property PROP in string S."
19365 (or (get-text-property 0 prop s)
19366 (get-text-property (or (next-single-property-change 0 prop s) 0)
19369 (defun org-display-warning (message) ;; Copied from Emacs-Muse
19370 "Display the given MESSAGE as a warning."
19371 (if (fboundp 'display-warning)
19372 (display-warning 'org message
19373 (if (featurep 'xemacs) 'warning :warning))
19374 (let ((buf (get-buffer-create "*Org warnings*")))
19375 (with-current-buffer buf
19376 (goto-char (point-max))
19377 (insert "Warning (Org): " message)
19380 (display-buffer buf)
19383 (defun org-eval (form)
19384 "Eval FORM and return result."
19385 (condition-case error
19387 (error (format "%%![Error: %s]" error))))
19389 (defun org-in-clocktable-p ()
19390 "Check if the cursor is in a clocktable."
19391 (let ((pos (point)) start)
19394 (and (re-search-backward "^[ \t]*#\\+BEGIN:[ \t]+clocktable" nil t)
19395 (setq start (match-beginning 0))
19396 (re-search-forward "^[ \t]*#\\+END:.*" nil t)
19397 (>= (match-end 0) pos)
19400 (defun org-in-commented-line ()
19401 "Is point in a line starting with `#'?"
19402 (equal (char-after (point-at-bol)) ?#))
19404 (defun org-in-indented-comment-line ()
19405 "Is point in a line starting with `#' after some white space?"
19408 (goto-char (point-at-bol))
19409 (looking-at "[ \t]*#"))))
19411 (defun org-in-verbatim-emphasis ()
19413 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
19415 (defun org-goto-marker-or-bmk (marker &optional bookmark)
19416 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
19417 (if (and marker (marker-buffer marker)
19418 (buffer-live-p (marker-buffer marker)))
19420 (org-pop-to-buffer-same-window (marker-buffer marker))
19421 (if (or (> marker (point-max)) (< marker (point-min)))
19424 (org-show-context 'org-goto))
19426 (bookmark-jump bookmark)
19427 (error "Cannot find location"))))
19429 (defun org-quote-csv-field (s)
19430 "Quote field for inclusion in CSV material."
19431 (if (string-match "[\",]" s)
19432 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
19435 (defun org-force-self-insert (N)
19436 "Needed to enforce self-insert under remapping."
19438 (self-insert-command N))
19440 (defun org-string-width (s)
19441 "Compute width of string, ignoring invisible characters.
19442 This ignores character with invisibility property `org-link', and also
19443 characters with property `org-cwidth', because these will become invisible
19444 upon the next fontification round."
19446 (when (or (eq t buffer-invisibility-spec)
19447 (assq 'org-link buffer-invisibility-spec))
19448 (while (setq b (text-property-any 0 (length s)
19449 'invisible 'org-link s))
19450 (setq s (concat (substring s 0 b)
19451 (substring s (or (next-single-property-change
19452 b 'invisible s) (length s)))))))
19453 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
19454 (setq s (concat (substring s 0 b)
19455 (substring s (or (next-single-property-change
19456 b 'org-cwidth s) (length s))))))
19457 (setq l (string-width s) b -1)
19458 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
19459 (setq l (- l (get-text-property b 'org-dwidth-n s))))
19462 (defun org-shorten-string (s maxlength)
19463 "Shorten string S so tht it is no longer than MAXLENGTH characters.
19464 If the string is shorter or has length MAXLENGTH, just return the
19465 original string. If it is longer, the functions finds a space in the
19466 string, breaks this string off at that locations and adds three dots
19467 as ellipsis. Including the ellipsis, the string will not be longer
19468 than MAXLENGTH. If finding a good breaking point in the string does
19469 not work, the string is just chopped off in the middle of a word
19471 (if (<= (length s) maxlength)
19473 (let* ((n (max (- maxlength 4) 1))
19474 (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
19475 (if (string-match re s)
19476 (concat (match-string 1 s) "...")
19477 (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
19479 (defun org-get-indentation (&optional line)
19480 "Get the indentation of the current line, interpreting tabs.
19481 When LINE is given, assume it represents a line and compute its indentation."
19483 (if (string-match "^ *" (org-remove-tabs line))
19486 (beginning-of-line 1)
19487 (skip-chars-forward " \t")
19488 (current-column))))
19490 (defun org-get-string-indentation (s)
19491 "What indentation has S due to SPACE and TAB at the beginning of the string?"
19492 (let ((n -1) (i 0) (w tab-width) c)
19494 (while (< (setq n (1+ n)) (length s))
19495 (setq c (aref s n))
19496 (cond ((= c ?\ ) (setq i (1+ i)))
19497 ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
19498 (t (throw 'exit t)))))
19501 (defun org-remove-tabs (s &optional width)
19502 "Replace tabulators in S with spaces.
19503 Assumes that s is a single line, starting in column 0."
19504 (setq width (or width tab-width))
19505 (while (string-match "\t" s)
19506 (setq s (replace-match
19508 (- (* width (/ (+ (match-beginning 0) width) width))
19509 (match-beginning 0)) ?\ )
19513 (defun org-fix-indentation (line ind)
19514 "Fix indentation in LINE.
19515 IND is a cons cell with target and minimum indentation.
19516 If the current indentation in LINE is smaller than the minimum,
19517 leave it alone. If it is larger than ind, set it to the target."
19518 (let* ((l (org-remove-tabs line))
19519 (i (org-get-indentation l))
19520 (i1 (car ind)) (i2 (cdr ind)))
19521 (if (>= i i2) (setq l (substring line i2)))
19523 (concat (make-string i1 ?\ ) l)
19526 (defun org-remove-indentation (code &optional n)
19527 "Remove the maximum common indentation from the lines in CODE.
19528 N may optionally be the number of spaces to remove."
19531 (org-do-remove-indentation n)
19534 (defun org-do-remove-indentation (&optional n)
19535 "Remove the maximum common indentation from the buffer."
19536 (untabify (point-min) (point-max))
19537 (let ((min 10000) re)
19540 (goto-char (point-min))
19541 (while (re-search-forward "^ *[^ \n]" nil t)
19542 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
19543 (unless (or (= min 0) (= min 10000))
19544 (setq re (format "^ \\{%d\\}" min))
19545 (goto-char (point-min))
19546 (while (re-search-forward re nil t)
19551 (defun org-fill-template (template alist)
19552 "Find each %key of ALIST in TEMPLATE and replace it."
19553 (let ((case-fold-search nil)
19555 (setq alist (sort (copy-sequence alist)
19556 (lambda (a b) (< (length (car a)) (length (car b))))))
19557 (while (setq entry (pop alist))
19559 (replace-regexp-in-string
19560 (concat "%" (regexp-quote (car entry)))
19561 (cdr entry) template t t)))
19564 (defun org-base-buffer (buffer)
19565 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
19568 (or (buffer-base-buffer buffer)
19571 (defun org-trim (s)
19572 "Remove whitespace at beginning and end of string."
19573 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
19574 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
19577 (defun org-wrap (string &optional width lines)
19578 "Wrap string to either a number of lines, or a width in characters.
19579 If WIDTH is non-nil, the string is wrapped to that width, however many lines
19580 that costs. If there is a word longer than WIDTH, the text is actually
19581 wrapped to the length of that word.
19582 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
19583 many lines, whatever width that takes.
19584 The return value is a list of lines, without newlines at the end."
19585 (let* ((words (org-split-string string "[ \t\n]+"))
19586 (maxword (apply 'max (mapcar 'org-string-width words)))
19589 (org-do-wrap words (max maxword width)))
19592 (setq ll (org-do-wrap words maxword))
19593 (if (<= (length ll) lines)
19596 (while (> (length ll) lines)
19598 (setq ll (org-do-wrap words w)))
19600 (t (error "Cannot wrap this")))))
19602 (defun org-do-wrap (words width)
19603 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
19606 (setq line (pop words))
19607 (while (and words (< (+ (length line) (length (car words))) width))
19608 (setq line (concat line " " (pop words))))
19609 (setq lines (push line lines)))
19612 (defun org-split-string (string &optional separators)
19613 "Splits STRING into substrings at SEPARATORS.
19614 No empty strings are returned if there are matches at the beginning
19615 and end of string."
19616 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
19620 (while (and (string-match rexp string
19622 (= start (match-beginning 0))
19623 (< start (length string)))
19625 (< (match-beginning 0) (length string)))
19627 (or (eq (match-beginning 0) 0)
19628 (and (eq (match-beginning 0) (match-end 0))
19629 (eq (match-beginning 0) start))
19631 (cons (substring string start (match-beginning 0))
19633 (setq start (match-end 0)))
19634 (or (eq start (length string))
19636 (cons (substring string start)
19640 (defun org-quote-vert (s)
19641 "Replace \"|\" with \"\\vert\"."
19642 (while (string-match "|" s)
19643 (setq s (replace-match "\\vert" t t s)))
19646 (defun org-uuidgen-p (s)
19647 "Is S an ID created by UUIDGEN?"
19648 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
19650 (defun org-in-src-block-p nil
19651 "Whether point is in a code source block."
19653 (when (setq ov (overlays-at (point)))
19654 (memq 'org-block-background
19655 (overlay-properties
19658 (defun org-context ()
19659 "Return a list of contexts of the current cursor position.
19660 If several contexts apply, all are returned.
19661 Each context entry is a list with a symbol naming the context, and
19662 two positions indicating start and end of the context. Possible
19665 :headline anywhere in a headline
19666 :headline-stars on the leading stars in a headline
19667 :todo-keyword on a TODO keyword (including DONE) in a headline
19668 :tags on the TAGS in a headline
19669 :priority on the priority cookie in a headline
19670 :item on the first line of a plain list item
19671 :item-bullet on the bullet/number of a plain list item
19672 :checkbox on the checkbox in a plain list item
19673 :table in an org-mode table
19674 :table-special on a special filed in a table
19675 :table-table in a table.el table
19676 :clocktable in a clocktable
19677 :src-block in a source block
19678 :link on a hyperlink
19679 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE, COMMENT, QUOTE.
19680 :target on a <<target>>
19681 :radio-target on a <<<radio-target>>>
19682 :latex-fragment on a LaTeX fragment
19683 :latex-preview on a LaTeX fragment with overlaid preview image
19685 This function expects the position to be visible because it uses font-lock
19686 faces as a help to recognize the following contexts: :table-special, :link,
19688 (let* ((f (get-text-property (point) 'face))
19689 (faces (if (listp f) f (list f)))
19690 (case-fold-search t)
19691 (p (point)) clist o)
19692 ;; First the large context
19694 ((org-at-heading-p t)
19695 (push (list :headline (point-at-bol) (point-at-eol)) clist)
19697 (beginning-of-line 1)
19698 (looking-at org-todo-line-tags-regexp))
19699 (push (org-point-in-group p 1 :headline-stars) clist)
19700 (push (org-point-in-group p 2 :todo-keyword) clist)
19701 (push (org-point-in-group p 4 :tags) clist))
19703 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
19704 (if (looking-at "\\[#[A-Z0-9]\\]")
19705 (push (org-point-in-group p 0 :priority) clist)))
19708 (push (org-point-in-group p 2 :item-bullet) clist)
19709 (push (list :item (point-at-bol)
19710 (save-excursion (org-end-of-item) (point)))
19712 (and (org-at-item-checkbox-p)
19713 (push (org-point-in-group p 0 :checkbox) clist)))
19716 (push (list :table (org-table-begin) (org-table-end)) clist)
19717 (if (memq 'org-formula faces)
19718 (push (list :table-special
19719 (previous-single-property-change p 'face)
19720 (next-single-property-change p 'face)) clist)))
19721 ((org-at-table-p 'any)
19722 (push (list :table-table) clist)))
19725 ;; New the "medium" contexts: clocktables, source blocks
19726 (cond ((org-in-clocktable-p)
19727 (push (list :clocktable
19728 (and (or (looking-at "#\\+BEGIN: clocktable")
19729 (search-backward "#+BEGIN: clocktable" nil t))
19730 (match-beginning 0))
19731 (and (re-search-forward "#\\+END:?" nil t)
19732 (match-end 0))) clist))
19733 ((org-in-src-block-p)
19734 (push (list :src-block
19735 (and (or (looking-at "#\\+BEGIN_SRC")
19736 (search-backward "#+BEGIN_SRC" nil t))
19737 (match-beginning 0))
19738 (and (search-forward "#+END_SRC" nil t)
19739 (match-beginning 0))) clist)))
19742 ;; Now the small context
19744 ((org-at-timestamp-p)
19745 (push (org-point-in-group p 0 :timestamp) clist))
19746 ((memq 'org-link faces)
19748 (previous-single-property-change p 'face)
19749 (next-single-property-change p 'face)) clist))
19750 ((memq 'org-special-keyword faces)
19751 (push (list :keyword
19752 (previous-single-property-change p 'face)
19753 (next-single-property-change p 'face)) clist))
19755 (push (org-point-in-group p 0 :target) clist)
19756 (goto-char (1- (match-beginning 0)))
19757 (if (looking-at org-radio-target-regexp)
19758 (push (org-point-in-group p 0 :radio-target) clist))
19760 ((setq o (car (delq nil
19763 (if (memq x org-latex-fragment-image-overlays) x))
19764 (overlays-at (point))))))
19765 (push (list :latex-fragment
19766 (overlay-start o) (overlay-end o)) clist)
19767 (push (list :latex-preview
19768 (overlay-start o) (overlay-end o)) clist))
19769 ((org-inside-LaTeX-fragment-p)
19770 ;; FIXME: positions wrong.
19771 (push (list :latex-fragment (point) (point)) clist)))
19773 (setq clist (nreverse (delq nil clist)))
19776 ;; FIXME: Compare with at-regexp-p Do we need both?
19777 (defun org-in-regexp (re &optional nlines visually)
19778 "Check if point is inside a match of regexp.
19779 Normally only the current line is checked, but you can include NLINES extra
19780 lines both before and after point into the search.
19781 If VISUALLY is set, require that the cursor is not after the match but
19782 really on, so that the block visually is on the match."
19784 (let ((pos (point))
19785 (eol (point-at-eol (+ 1 (or nlines 0))))
19786 (inc (if visually 1 0)))
19788 (beginning-of-line (- 1 (or nlines 0)))
19789 (while (re-search-forward re eol t)
19790 (if (and (<= (match-beginning 0) pos)
19791 (>= (+ inc (match-end 0)) pos))
19792 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
19794 (defun org-at-regexp-p (regexp)
19795 "Is point inside a match of REGEXP in the current line?"
19798 (let ((pos (point)) (end (point-at-eol)))
19799 (beginning-of-line 1)
19800 (while (re-search-forward regexp end t)
19801 (if (and (<= (match-beginning 0) pos)
19802 (>= (match-end 0) pos))
19806 (defun org-between-regexps-p (start-re end-re &optional lim-up lim-down)
19807 "Non-nil when point is between matches of START-RE and END-RE.
19809 Also return a non-nil value when point is on one of the matches.
19811 Optional arguments LIM-UP and LIM-DOWN bound the search; they are
19812 buffer positions. Default values are the positions of headlines
19813 surrounding the point.
19815 The functions returns a cons cell whose car (resp. cdr) is the
19816 position before START-RE (resp. after END-RE)."
19818 (let ((pos (point))
19819 (limit-up (or lim-up (save-excursion (outline-previous-heading))))
19820 (limit-down (or lim-down (save-excursion (outline-next-heading))))
19823 ;; Point is on a block when on START-RE or if START-RE can be
19824 ;; found before it...
19825 (and (or (org-at-regexp-p start-re)
19826 (re-search-backward start-re limit-up t))
19827 (setq beg (match-beginning 0))
19828 ;; ... and END-RE after it...
19829 (goto-char (match-end 0))
19830 (re-search-forward end-re limit-down t)
19831 (> (setq end (match-end 0)) pos)
19832 ;; ... without another START-RE in-between.
19833 (goto-char (match-beginning 0))
19834 (not (re-search-backward start-re (1+ beg) t))
19836 (cons beg end))))))
19838 (defun org-in-block-p (names)
19839 "Non-nil when point belongs to a block whose name belongs to NAMES.
19841 NAMES is a list of strings containing names of blocks.
19843 Return first block name matched, or nil. Beware that in case of
19844 nested blocks, the returned name may not belong to the closest
19848 (let ((case-fold-search t)
19849 (lim-up (save-excursion (outline-previous-heading)))
19850 (lim-down (save-excursion (outline-next-heading))))
19851 (mapc (lambda (name)
19852 (let ((n (regexp-quote name)))
19853 (when (org-between-regexps-p
19854 (concat "^[ \t]*#\\+begin_" n)
19855 (concat "^[ \t]*#\\+end_" n)
19861 (defun org-occur-in-agenda-files (regexp &optional nlines)
19862 "Call `multi-occur' with buffers for all agenda files."
19863 (interactive "sOrg-files matching: \np")
19864 (let* ((files (org-agenda-files))
19865 (tnames (mapcar 'file-truename files))
19866 (extra org-agenda-text-search-extra-files)
19868 (when (eq (car extra) 'agenda-archives)
19869 (setq extra (cdr extra))
19870 (setq files (org-add-archive-files files)))
19871 (while (setq f (pop extra))
19872 (unless (member (file-truename f) tnames)
19873 (add-to-list 'files f 'append)
19874 (add-to-list 'tnames (file-truename f) 'append)))
19876 (mapcar (lambda (x)
19877 (with-current-buffer
19878 (or (get-file-buffer x) (find-file-noselect x))
19884 (if (boundp 'occur-mode-find-occurrence-hook)
19886 (add-hook 'occur-mode-find-occurrence-hook
19888 (when (eq major-mode 'org-mode)
19891 (defadvice occur-mode-goto-occurrence
19892 (after org-occur-reveal activate)
19893 (and (eq major-mode 'org-mode) (org-reveal)))
19894 (defadvice occur-mode-goto-occurrence-other-window
19895 (after org-occur-reveal activate)
19896 (and (eq major-mode 'org-mode) (org-reveal)))
19897 (defadvice occur-mode-display-occurrence
19898 (after org-occur-reveal activate)
19899 (when (eq major-mode 'org-mode)
19900 (let ((pos (occur-mode-find-occurrence)))
19901 (with-current-buffer (marker-buffer pos)
19906 (defun org-occur-link-in-agenda-files ()
19907 "Create a link and search for it in the agendas.
19908 The link is not stored in `org-stored-links', it is just created
19909 for the search purpose."
19911 (let ((link (condition-case nil
19912 (org-store-link nil)
19913 (error "Unable to create a link to here"))))
19914 (org-occur-in-agenda-files (regexp-quote link))))
19916 (defun org-uniquify (list)
19917 "Remove duplicate elements from LIST."
19919 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
19922 (defun org-delete-all (elts list)
19923 "Remove all elements in ELTS from LIST."
19925 (setq list (delete (pop elts) list)))
19928 (defun org-count (cl-item cl-seq)
19929 "Count the number of occurrences of ITEM in SEQ.
19930 Taken from `count' in cl-seq.el with all keyword arguments removed."
19931 (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0) cl-x)
19932 (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
19933 (while (< cl-start cl-end)
19934 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
19935 (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
19936 (setq cl-start (1+ cl-start)))
19939 (defun org-remove-if (predicate seq)
19940 "Remove everything from SEQ that fulfills PREDICATE."
19944 (if (not (funcall predicate e)) (push e res)))
19947 (defun org-remove-if-not (predicate seq)
19948 "Remove everything from SEQ that does not fulfill PREDICATE."
19952 (if (funcall predicate e) (push e res)))
19955 (defun org-reduce (cl-func cl-seq &rest cl-keys)
19956 "Reduce two-argument FUNCTION across SEQ.
19957 Taken from `reduce' in cl-seq.el with all keyword arguments but
19958 \":initial-value\" removed."
19959 (let ((cl-accum (cond ((memq :initial-value cl-keys)
19960 (cadr (memq :initial-value cl-keys)))
19961 (cl-seq (pop cl-seq))
19962 (t (funcall cl-func)))))
19964 (setq cl-accum (funcall cl-func cl-accum (pop cl-seq))))
19967 (defun org-back-over-empty-lines ()
19968 "Move backwards over whitespace, to the beginning of the first empty line.
19969 Returns the number of empty lines passed."
19970 (let ((pos (point)))
19971 (if (cdr (assoc 'heading org-blank-before-new-entry))
19972 (skip-chars-backward " \t\n\r")
19974 (forward-line -1)))
19975 (beginning-of-line 2)
19976 (goto-char (min (point) pos))
19977 (count-lines (point) pos)))
19979 (defun org-skip-whitespace ()
19980 (skip-chars-forward " \t\n\r"))
19982 (defun org-point-in-group (point group &optional context)
19983 "Check if POINT is in match-group GROUP.
19984 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
19985 match. If the match group does not exist or point is not inside it,
19987 (and (match-beginning group)
19988 (>= point (match-beginning group))
19989 (<= point (match-end group))
19991 (list context (match-beginning group) (match-end group))
19994 (defun org-switch-to-buffer-other-window (&rest args)
19995 "Switch to buffer in a second window on the current frame.
19996 In particular, do not allow pop-up frames.
19997 Returns the newly created buffer."
19998 (let (pop-up-frames special-display-buffer-names special-display-regexps
19999 special-display-function)
20000 (apply 'switch-to-buffer-other-window args)))
20002 (defun org-combine-plists (&rest plists)
20003 "Create a single property list from all plists in PLISTS.
20004 The process starts by copying the first list, and then setting properties
20005 from the other lists. Settings in the last list are the most significant
20006 ones and overrule settings in the other lists."
20007 (let ((rtn (copy-sequence (pop plists)))
20010 (setq ls (pop plists))
20012 (setq p (pop ls) v (pop ls))
20013 (setq rtn (plist-put rtn p v))))
20016 (defun org-move-line-down (arg)
20017 "Move the current line down. With prefix argument, move it past ARG lines."
20019 (let ((col (current-column))
20021 (beginning-of-line 1) (setq beg (point))
20022 (beginning-of-line 2) (setq end (point))
20023 (beginning-of-line (+ 1 arg))
20024 (setq pos (move-marker (make-marker) (point)))
20025 (insert (delete-and-extract-region beg end))
20027 (org-move-to-column col)))
20029 (defun org-move-line-up (arg)
20030 "Move the current line up. With prefix argument, move it past ARG lines."
20032 (let ((col (current-column))
20034 (beginning-of-line 1) (setq beg (point))
20035 (beginning-of-line 2) (setq end (point))
20036 (beginning-of-line (- arg))
20037 (setq pos (move-marker (make-marker) (point)))
20038 (insert (delete-and-extract-region beg end))
20040 (org-move-to-column col)))
20042 (defun org-replace-escapes (string table)
20043 "Replace %-escapes in STRING with values in TABLE.
20044 TABLE is an association list with keys like \"%a\" and string values.
20045 The sequences in STRING may contain normal field width and padding information,
20046 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
20047 so values can contain further %-escapes if they are define later in TABLE."
20048 (let ((tbl (copy-alist table))
20049 (case-fold-search nil)
20052 (while (setq e (pop tbl))
20053 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
20054 (when (and (cdr e) (string-match re (cdr e)))
20055 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
20057 (add-text-properties 0 3 (list 'sref sref) safe)
20058 (setcdr e (replace-match safe t t (cdr e)))))
20059 (while (string-match re string)
20060 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
20062 (setq string (replace-match rpl t t string))))
20063 (while (setq pchg (next-property-change pchg string))
20064 (let ((sref (get-text-property pchg 'sref string)))
20065 (when (and sref (string-match "SREF" string pchg))
20066 (setq string (replace-match sref t t string)))))
20069 (defun org-sublist (list start end)
20070 "Return a section of LIST, from START to END.
20071 Counting starts at 1."
20072 (let (rtn (c start))
20073 (setq list (nthcdr (1- start) list))
20074 (while (and list (<= c end))
20075 (push (pop list) rtn)
20079 (defun org-find-base-buffer-visiting (file)
20080 "Like `find-buffer-visiting' but always return the base buffer and
20081 not an indirect buffer."
20082 (let ((buf (or (get-file-buffer file)
20083 (find-buffer-visiting file))))
20085 (or (buffer-base-buffer buf) buf)
20088 (defun org-image-file-name-regexp (&optional extensions)
20089 "Return regexp matching the file names of images.
20090 If EXTENSIONS is given, only match these."
20091 (if (and (not extensions) (fboundp 'image-file-name-regexp))
20092 (image-file-name-regexp)
20093 (let ((image-file-name-extensions
20095 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
20096 "xbm" "xpm" "pbm" "pgm" "ppm"))))
20098 (regexp-opt (nconc (mapcar 'upcase
20099 image-file-name-extensions)
20100 image-file-name-extensions)
20104 (defun org-file-image-p (file &optional extensions)
20105 "Return non-nil if FILE is an image."
20107 (string-match (org-image-file-name-regexp extensions) file)))
20109 (defun org-get-cursor-date ()
20110 "Return the date at cursor in as a time.
20111 This works in the calendar and in the agenda, anywhere else it just
20112 returns the current time."
20113 (let (date day defd)
20115 ((eq major-mode 'calendar-mode)
20116 (setq date (calendar-cursor-to-date)
20117 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
20118 ((eq major-mode 'org-agenda-mode)
20119 (setq day (get-text-property (point) 'day))
20121 (setq date (calendar-gregorian-from-absolute day)
20122 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
20124 (or defd (current-time))))
20126 (defvar org-agenda-action-marker (make-marker)
20127 "Marker pointing to the entry for the next agenda action.")
20129 (defun org-mark-entry-for-agenda-action ()
20130 "Mark the current entry as target of an agenda action.
20131 Agenda actions are actions executed from the agenda with the key `k',
20132 which make use of the date at the cursor."
20134 (move-marker org-agenda-action-marker
20135 (save-excursion (org-back-to-heading t) (point))
20138 "Entry marked for action; press `k' at desired date in agenda or calendar"))
20140 (defun org-mark-subtree ()
20141 "Mark the current subtree.
20142 This puts point at the start of the current subtree, and mark at the end.
20144 If point is in an inline task, mark that task instead."
20146 (let ((inline-task-p
20147 (and (featurep 'org-inlinetask)
20148 (org-inlinetask-in-task-p)))
20150 ;; Get beginning of subtree
20152 (inline-task-p (org-inlinetask-goto-beginning))
20153 ((org-at-heading-p) (beginning-of-line))
20154 (t (org-with-limited-levels (outline-previous-visible-heading 1))))
20158 (org-inlinetask-goto-end)
20159 (org-end-of-subtree))
20161 (push-mark (point) nil t)
20164 ;;; Paragraph filling stuff.
20165 ;; We want this to be just right, so use the full arsenal.
20167 (defun org-indent-line-function ()
20168 "Indent line depending on context."
20170 (let* ((pos (point))
20171 (itemp (org-at-item-p))
20172 (case-fold-search t)
20173 (org-drawer-regexp (or org-drawer-regexp "\000"))
20174 (inline-task-p (and (featurep 'org-inlinetask)
20175 (org-inlinetask-in-task-p)))
20176 (inline-re (and inline-task-p
20177 (org-inlinetask-outline-regexp)))
20179 (beginning-of-line 1)
20182 ((looking-at "# ") (setq column 0))
20184 ((looking-at org-outline-regexp) (setq column 0))
20186 ((looking-at "#\\+include:") (setq column 0))
20187 ;; Footnote definition
20188 ((looking-at org-footnote-definition-re) (setq column 0))
20189 ;; Literal examples
20190 ((looking-at "[ \t]*:\\( \\|$\\)")
20191 (setq column (org-get-indentation))) ; do nothing
20193 ((ignore-errors (goto-char (org-in-item-p)))
20194 (setq column (if itemp
20195 (org-get-indentation)
20196 (org-list-item-body-column (point))))
20199 ((and (looking-at "[ \t]*:END:")
20200 (save-excursion (re-search-backward org-drawer-regexp nil t)))
20202 (goto-char (1- (match-beginning 1)))
20203 (setq column (current-column))))
20205 ((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
20207 (re-search-backward
20208 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
20209 (setq column (org-get-indentation (match-string 0))))
20210 ((and (not (looking-at "[ \t]*#\\+begin_"))
20211 (org-between-regexps-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
20213 (re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
20215 (cond ((equal (downcase (match-string 1)) "src")
20216 ;; src blocks: let `org-edit-src-exit' handle them
20217 (org-get-indentation))
20218 ((equal (downcase (match-string 1)) "example")
20219 (max (org-get-indentation)
20220 (org-get-indentation (match-string 0))))
20222 (org-get-indentation (match-string 0))))))
20223 ;; This line has nothing special, look at the previous relevant
20224 ;; line to compute indentation
20226 (beginning-of-line 0)
20227 (while (and (not (bobp))
20228 (not (looking-at org-drawer-regexp))
20229 ;; When point started in an inline task, do not move
20230 ;; above task starting line.
20231 (not (and inline-task-p (looking-at inline-re)))
20232 ;; Skip drawers, blocks, empty lines, verbatim,
20233 ;; comments, tables, footnotes definitions, lists,
20235 (or (and (looking-at "[ \t]*:END:")
20236 (re-search-backward org-drawer-regexp nil t))
20237 (and (looking-at "[ \t]*#\\+end_")
20238 (re-search-backward "[ \t]*#\\+begin_"nil t))
20239 (looking-at "[ \t]*[\n:#|]")
20240 (looking-at org-footnote-definition-re)
20241 (and (ignore-errors (goto-char (org-in-item-p)))
20243 (org-list-get-top-point (org-list-struct))))
20244 (and (not inline-task-p)
20245 (featurep 'org-inlinetask)
20246 (org-inlinetask-in-task-p)
20247 (or (org-inlinetask-goto-beginning) t))))
20248 (beginning-of-line 0))
20250 ;; There was an heading above.
20251 ((looking-at "\\*+[ \t]+")
20252 (if (not org-adapt-indentation)
20254 (goto-char (match-end 0))
20255 (setq column (current-column))))
20256 ;; A drawer had started and is unfinished
20257 ((looking-at org-drawer-regexp)
20258 (goto-char (1- (match-beginning 1)))
20259 (setq column (current-column)))
20260 ;; Else, nothing noticeable found: get indentation and go on.
20261 (t (setq column (org-get-indentation))))))
20262 ;; Now apply indentation and move cursor accordingly
20264 (if (<= (current-column) (current-indentation))
20265 (org-indent-line-to column)
20266 (save-excursion (org-indent-line-to column)))
20267 ;; Special polishing for properties, see `org-property-format'
20268 (setq column (current-column))
20269 (beginning-of-line 1)
20271 "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
20272 (replace-match (concat (match-string 1)
20273 (format org-property-format
20274 (match-string 2) (match-string 3)))
20276 (org-move-to-column column)))
20278 (defun org-indent-drawer ()
20279 "Indent the drawer at point."
20282 (e (and (save-excursion (re-search-forward ":END:" nil t))
20287 (when (overlays-at (point))
20288 (member 'invisible (overlay-properties
20289 (car (overlays-at (point)))))))))
20290 (when folded (org-cycle))
20291 (indent-for-tab-command)
20292 (while (and (move-beginning-of-line 2) (< (point) e))
20293 (indent-for-tab-command))
20295 (when folded (org-cycle)))
20296 (message "Drawer at point indented"))
20298 (defun org-indent-block ()
20299 "Indent the block at point."
20302 (case-fold-search t)
20303 (e (and (save-excursion (re-search-forward "#\\+end_?\\(?:[a-z]+\\)?" nil t))
20308 (when (overlays-at (point))
20309 (member 'invisible (overlay-properties
20310 (car (overlays-at (point)))))))))
20311 (when folded (org-cycle))
20312 (indent-for-tab-command)
20313 (while (and (move-beginning-of-line 2) (< (point) e))
20314 (indent-for-tab-command))
20316 (when folded (org-cycle)))
20317 (message "Block at point indented"))
20319 (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp
20320 "Variable to store copy of `adaptive-fill-regexp'.
20321 Since `adaptive-fill-regexp' is set to never match, we need to
20322 store a backup of its value before entering `org-mode' so that
20323 the functionality can be provided as a fall-back.")
20325 (defun org-set-autofill-regexps ()
20327 ;; In the paragraph separator we include headlines, because filling
20328 ;; text in a line directly attached to a headline would otherwise
20329 ;; fill the headline as well.
20330 (org-set-local 'comment-start-skip "^#+[ \t]*")
20331 (org-set-local 'paragraph-separate "\f\\|\\*+ \\|[ ]*$\\|[ \t]*[:|#]")
20332 ;; The paragraph starter includes hand-formatted lists.
20338 org-outline-regexp "\\|"
20340 (org-item-re) "\\|"
20343 "\\\\\\(begin\\|end\\|[][]\\)"))
20344 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
20345 ;; But only if the user has not turned off tables or fixed-width regions
20347 'auto-fill-inhibit-regexp
20348 (concat org-outline-regexp
20350 "\\|[ \t]*" org-keyword-time-regexp
20351 (if (or org-enable-table-editor org-enable-fixed-width-editor)
20354 (if org-enable-table-editor "|" "")
20355 (if org-enable-fixed-width-editor ":" "")
20357 ;; We use our own fill-paragraph function, to make sure that tables
20358 ;; and fixed-width regions are not wrapped. That function will pass
20359 ;; through to `fill-paragraph' when appropriate.
20360 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
20361 ;; Prevent auto-fill from inserting unwanted new items.
20362 (if (boundp 'fill-nobreak-predicate)
20364 'fill-nobreak-predicate
20366 (append fill-nobreak-predicate
20367 '(org-fill-item-nobreak-p org-fill-line-break-nobreak-p)))))
20368 ;; Adaptive filling: To get full control, first make sure that
20369 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
20370 (unless (local-variable-p 'adaptive-fill-regexp (current-buffer))
20371 (org-set-local 'org-adaptive-fill-regexp-backup
20372 adaptive-fill-regexp))
20373 (org-set-local 'adaptive-fill-regexp "\000")
20374 (org-set-local 'normal-auto-fill-function 'org-auto-fill-function)
20375 (org-set-local 'adaptive-fill-function
20376 'org-adaptive-fill-function)
20378 'align-mode-rules-list
20379 '((org-in-buffer-settings
20380 (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
20381 (modes . '(org-mode))))))
20383 (defun org-fill-item-nobreak-p ()
20384 "Non-nil when a line break at point would insert a new item."
20385 (and (looking-at (org-item-re)) (org-list-in-valid-context-p)))
20387 (defun org-fill-line-break-nobreak-p ()
20388 "Non-nil when a line break at point would create an Org line break."
20390 (skip-chars-backward "[ \t]")
20391 (skip-chars-backward "\\\\")
20392 (looking-at "\\\\\\\\\\($\\|[^\\\\]\\)")))
20394 (defun org-fill-paragraph (&optional justify)
20395 "Re-align a table, pass through to fill-paragraph if no table."
20396 (let ((table-p (org-at-table-p))
20397 (table.el-p (org-at-table.el-p))
20398 (itemp (org-in-item-p)))
20399 (cond ((and (equal (char-after (point-at-bol)) ?*)
20400 (save-excursion (goto-char (point-at-bol))
20401 (looking-at org-outline-regexp)))
20402 t) ; skip headlines
20403 (table.el-p t) ; skip table.el tables
20404 (table-p (org-table-align) t) ; align Org tables
20405 (itemp ; align text in items
20406 (let* ((struct (save-excursion (goto-char itemp)
20407 (org-list-struct)))
20408 (parents (org-list-parents-alist struct))
20409 (children (org-list-get-children itemp struct parents))
20410 beg end prev next prefix)
20411 ;; Determine in which part of item point is: before
20412 ;; first child, after last child, between two
20413 ;; sub-lists, or simply in item if there's no child.
20416 (setq prefix (make-string (org-list-item-body-column itemp) ?\ )
20418 end (org-list-get-item-end itemp struct)))
20419 ((< (point) (setq next (car children)))
20420 (setq prefix (make-string (org-list-item-body-column itemp) ?\ )
20423 ((> (point) (setq prev (car (last children))))
20424 (setq beg (org-list-get-item-end prev struct)
20425 end (org-list-get-item-end itemp struct)
20426 prefix (save-excursion
20428 (skip-chars-forward " \t")
20429 (make-string (current-column) ?\ ))))
20431 (while (setq next (pop children))
20432 (if (> (point) next)
20434 (setq beg (org-list-get-item-end prev struct)
20436 prefix (save-excursion
20438 (skip-chars-forward " \t")
20439 (make-string (current-column) ?\ )))
20440 (throw 'exit nil))))))
20441 ;; Use `fill-paragraph' with buffer narrowed to item
20442 ;; without any child, and with our computed PREFIX.
20443 (flet ((fill-context-prefix (from to &optional flr) prefix))
20445 (narrow-to-region beg end)
20446 (save-excursion (fill-paragraph justify)))) t))
20447 ;; Special case where point is not in a list but is on
20448 ;; a paragraph adjacent to a list: make sure this paragraph
20449 ;; doesn't get merged with the end of the list by narrowing
20451 ((save-excursion (forward-paragraph -1)
20452 (setq itemp (org-in-item-p)))
20453 (let ((struct (save-excursion (goto-char itemp)
20454 (org-list-struct))))
20456 (narrow-to-region (org-list-get-bottom-point struct)
20457 (save-excursion (forward-paragraph 1)
20459 (fill-paragraph justify) t)))
20460 ;; Else simply call `fill-paragraph'.
20463 ;; For reference, this is the default value of adaptive-fill-regexp
20464 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
20466 (defun org-adaptive-fill-function ()
20467 "Return a fill prefix for org-mode files."
20472 ((looking-at "#[ \t]+")
20473 (match-string-no-properties 0))
20476 (make-string (org-list-item-body-column (point-at-bol)) ?\ ))
20477 ;; Point is in a list after `backward-paragraph': original
20478 ;; point wasn't in the list, or filling would have been taken
20479 ;; care of by `org-auto-fill-function', but the list and the
20480 ;; real paragraph are not separated by a blank line. Thus, move
20481 ;; point after the list to go back to real paragraph and
20482 ;; determine fill-prefix.
20483 ((setq itemp (org-in-item-p))
20485 (let* ((struct (org-list-struct))
20486 (bottom (org-list-get-bottom-point struct)))
20488 (make-string (org-get-indentation) ?\ )))
20490 ((looking-at org-adaptive-fill-regexp-backup)
20491 (match-string-no-properties 0))))))
20493 (defun org-auto-fill-function ()
20494 "Auto-fill function."
20495 (let (itemp prefix)
20496 ;; When in a list, compute an appropriate fill-prefix and make
20497 ;; sure it will be used by `do-auto-fill'.
20498 (if (setq itemp (org-in-item-p))
20500 (setq prefix (make-string (org-list-item-body-column itemp) ?\ ))
20501 (flet ((fill-context-prefix (from to &optional flr) prefix))
20503 ;; Else just use `do-auto-fill'.
20508 (defun org-toggle-fixed-width-section (arg)
20509 "Toggle the fixed-width export.
20510 If there is no active region, the QUOTE keyword at the current headline is
20511 inserted or removed. When present, it causes the text between this headline
20512 and the next to be exported as fixed-width text, and unmodified.
20513 If there is an active region, this command adds or removes a colon as the
20514 first character of this line. If the first character of a line is a colon,
20515 this line is also exported in fixed-width font."
20518 (regionp (org-region-active-p))
20519 (beg (if regionp (region-beginning) (point)))
20520 (end (if regionp (region-end)))
20521 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
20522 (case-fold-search nil)
20523 (re "[ \t]*\\(:\\(?: \\|$\\)\\)")
20528 (setq cc (current-column))
20529 (beginning-of-line 1)
20530 (setq off (looking-at re))
20531 (while (> nlines 0)
20532 (setq nlines (1- nlines))
20533 (beginning-of-line 1)
20536 (org-move-to-column cc t)
20539 ((and off (looking-at re))
20540 (replace-match "" t t nil 1))
20541 ((not off) (org-move-to-column cc t) (insert ": ")))
20544 (org-back-to-heading)
20546 ((looking-at (format org-heading-keyword-regexp-format
20548 (goto-char (match-end 1))
20549 (looking-at (concat " +" org-quote-string))
20550 (replace-match "" t t)
20551 (when (eolp) (insert " ")))
20552 ((looking-at org-outline-regexp)
20553 (goto-char (match-end 0))
20554 (insert org-quote-string " ")))))))
20556 (defun org-reftex-citation ()
20557 "Use reftex-citation to insert a citation into the buffer.
20558 This looks for a line like
20560 #+BIBLIOGRAPHY: foo plain option:-d
20562 and derives from it that foo.bib is the bibliography file relevant
20563 for this document. It then installs the necessary environment for RefTeX
20564 to work in this buffer and calls `reftex-citation' to insert a citation
20567 Export of such citations to both LaTeX and HTML is handled by the contributed
20568 package org-exp-bibtex by Taru Karttunen."
20570 (let ((reftex-docstruct-symbol 'rds)
20571 (reftex-cite-format "\\cite{%l}")
20576 (let ((case-fold-search t)
20577 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
20578 (if (not (save-excursion
20579 (or (re-search-forward re nil t)
20580 (re-search-backward re nil t))))
20581 (error "No bibliography defined in file")
20582 (setq bib (concat (match-string 1) ".bib")
20583 rds (list (list 'bib bib)))))))
20584 (call-interactively 'reftex-citation)))
20586 ;;;; Functions extending outline functionality
20588 (defun org-beginning-of-line (&optional arg)
20589 "Go to the beginning of the current line. If that is invisible, continue
20590 to a visible line beginning. This makes the function of C-a more intuitive.
20591 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
20592 first attempt, and only move to after the tags when the cursor is already
20593 beyond the end of the headline."
20595 (let ((pos (point))
20596 (special (if (consp org-special-ctrl-a/e)
20597 (car org-special-ctrl-a/e)
20598 org-special-ctrl-a/e))
20600 (if (org-bound-and-true-p line-move-visual)
20601 (beginning-of-visual-line 1)
20602 (beginning-of-line 1))
20603 (if (and arg (fboundp 'move-beginning-of-line))
20604 (call-interactively 'move-beginning-of-line)
20608 (if (org-truely-invisible-p)
20609 (while (and (not (bobp)) (org-truely-invisible-p))
20611 (beginning-of-line 1))
20612 (forward-char 1))))
20615 ((and (looking-at org-complex-heading-regexp)
20616 (= (char-after (match-end 1)) ?\ ))
20617 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
20621 (cond ((> pos refpos) refpos)
20622 ((= pos (point)) refpos)
20624 (cond ((> pos (point)) (point))
20625 ((not (eq last-command this-command)) (point))
20628 ;; Being at an item and not looking at an the item means point
20629 ;; was previously moved to beginning of a visual line, whiche
20630 ;; doesn't contain the item. Therefore, do nothing special,
20632 (when (looking-at org-list-full-item-re)
20633 ;; Set special position at first white space character after
20634 ;; bullet, and check-box, if any.
20635 (let ((after-bullet
20636 (let ((box (match-end 3)))
20637 (if (not box) (match-end 1)
20638 (let ((after (char-after box)))
20639 (if (and after (= after ? )) (1+ box) box))))))
20640 ;; Special case: Move point to special position when
20641 ;; currently after it or at beginning of line.
20643 (when (or (> pos after-bullet) (= (point) pos))
20644 (goto-char after-bullet))
20645 ;; Reversed case: Move point to special position when
20646 ;; point was already at beginning of line and command is
20648 (when (and (= (point) pos) (eq last-command this-command))
20649 (goto-char after-bullet))))))))
20651 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
20653 (defun org-end-of-line (&optional arg)
20654 "Go to the end of the line.
20655 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
20656 first attempt, and only move to after the tags when the cursor is already
20657 beyond the end of the headline."
20659 (let ((special (if (consp org-special-ctrl-a/e)
20660 (cdr org-special-ctrl-a/e)
20661 org-special-ctrl-a/e)))
20663 ((or (not special) arg
20664 (not (or (org-at-heading-p) (org-at-item-p) (org-at-drawer-p))))
20665 (call-interactively
20666 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
20667 ((fboundp 'move-end-of-line) 'move-end-of-line)
20668 (t 'end-of-line))))
20669 ((org-at-heading-p)
20670 (let ((pos (point)))
20671 (beginning-of-line 1)
20672 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$"))
20674 (if (or (< pos (match-beginning 1))
20675 (= pos (match-end 0)))
20676 (goto-char (match-beginning 1))
20677 (goto-char (match-end 0)))
20678 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
20679 (goto-char (match-end 0))
20680 (goto-char (match-beginning 1))))
20681 (call-interactively (if (fboundp 'move-end-of-line)
20685 (move-end-of-line 1)
20686 (when (overlays-at (1- (point))) (backward-char 1)))
20687 ;; At an item: Move before any hidden text.
20688 (t (call-interactively
20689 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
20690 ((fboundp 'move-end-of-line) 'move-end-of-line)
20691 (t 'end-of-line)))))
20693 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
20695 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
20696 (define-key org-mode-map "\C-e" 'org-end-of-line)
20698 (defun org-backward-sentence (&optional arg)
20699 "Go to beginning of sentence, or beginning of table field.
20700 This will call `backward-sentence' or `org-table-beginning-of-field',
20701 depending on context."
20704 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
20705 (t (call-interactively 'backward-sentence))))
20707 (defun org-forward-sentence (&optional arg)
20708 "Go to end of sentence, or end of table field.
20709 This will call `forward-sentence' or `org-table-end-of-field',
20710 depending on context."
20713 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
20714 (t (call-interactively 'forward-sentence))))
20716 (define-key org-mode-map "\M-a" 'org-backward-sentence)
20717 (define-key org-mode-map "\M-e" 'org-forward-sentence)
20719 (defun org-kill-line (&optional arg)
20720 "Kill line, to tags or end of line."
20723 ((or (not org-special-ctrl-k)
20725 (not (org-at-heading-p)))
20726 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
20727 org-ctrl-k-protect-subtree)
20728 (if (or (eq org-ctrl-k-protect-subtree 'error)
20729 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
20730 (error "C-k aborted - would kill hidden subtree")))
20731 (call-interactively
20732 (if visual-line-mode 'kill-visual-line 'kill-line)))
20733 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$"))
20734 (kill-region (point) (match-beginning 1))
20735 (org-set-tags nil t))
20736 (t (kill-region (point) (point-at-eol)))))
20738 (define-key org-mode-map "\C-k" 'org-kill-line)
20740 (defun org-yank (&optional arg)
20741 "Yank. If the kill is a subtree, treat it specially.
20742 This command will look at the current kill and check if is a single
20743 subtree, or a series of subtrees[1]. If it passes the test, and if the
20744 cursor is at the beginning of a line or after the stars of a currently
20745 empty headline, then the yank is handled specially. How exactly depends
20746 on the value of the following variables, both set by default.
20748 org-yank-folded-subtrees
20749 When set, the subtree(s) will be folded after insertion, but only
20750 if doing so would now swallow text after the yanked text.
20752 org-yank-adjusted-subtrees
20753 When set, the subtree will be promoted or demoted in order to
20754 fit into the local outline tree structure, which means that the level
20755 will be adjusted so that it becomes the smaller one of the two
20756 *visible* surrounding headings.
20758 Any prefix to this command will cause `yank' to be called directly with
20759 no special treatment. In particular, a simple \\[universal-argument] prefix \
20761 plainly yank the text as it is.
20763 \[1] The test checks if the first non-white line is a heading
20764 and if there are no other headings with fewer stars."
20766 (org-yank-generic 'yank arg))
20768 (defun org-yank-generic (command arg)
20769 "Perform some yank-like command.
20771 This function implements the behavior described in the `org-yank'
20772 documentation. However, it has been generalized to work for any
20773 interactive command with similar behavior."
20775 ;; pretend to be command COMMAND
20776 (setq this-command command)
20779 (call-interactively command)
20781 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
20782 (and (org-kill-is-subtree-p)
20784 (and (looking-at "[ \t]*$")
20787 (buffer-substring (point-at-bol) (point)))))))
20790 ((and subtreep org-yank-folded-subtrees)
20791 (let ((beg (point))
20793 (if (and subtreep org-yank-adjusted-subtrees)
20794 (org-paste-subtree nil nil 'for-yank)
20795 (call-interactively command))
20799 (when (and (bolp) subtreep
20800 (not (setq swallowp
20801 (org-yank-folding-would-swallow-text beg end))))
20802 (org-with-limited-levels
20803 (or (looking-at org-outline-regexp)
20804 (re-search-forward org-outline-regexp-bol end t))
20805 (while (and (< (point) end) (looking-at org-outline-regexp))
20807 (org-cycle-show-empty-lines 'folded)
20808 (condition-case nil
20809 (outline-forward-same-level 1)
20810 (error (goto-char end))))))
20813 "Inserted text not folded because that would swallow text"))
20816 (skip-chars-forward " \t\n\r")
20817 (beginning-of-line 1)
20818 (push-mark beg 'nomsg)))
20819 ((and subtreep org-yank-adjusted-subtrees)
20820 (let ((beg (point-at-bol)))
20821 (org-paste-subtree nil nil 'for-yank)
20822 (push-mark beg 'nomsg)))
20824 (call-interactively command))))))
20826 (defun org-yank-folding-would-swallow-text (beg end)
20827 "Would hide-subtree at BEG swallow any text after END?"
20829 (org-with-limited-levels
20832 (when (or (looking-at org-outline-regexp)
20833 (re-search-forward org-outline-regexp-bol end t))
20834 (setq level (org-outline-level)))
20836 (skip-chars-forward " \t\r\n\v\f")
20838 (and (bolp) (looking-at org-outline-regexp)
20839 (<= (org-outline-level) level)))
20840 nil ; Nothing would be swallowed
20841 t))))) ; something would swallow
20843 (define-key org-mode-map "\C-y" 'org-yank)
20845 (defun org-truely-invisible-p ()
20846 "Check if point is at a character currently not visible.
20847 This version does not only check the character property, but also
20849 ;; Early versions of noutline don't have `outline-invisible-p'.
20850 (if (org-bound-and-true-p visible-mode)
20852 (outline-invisible-p)))
20854 (defun org-invisible-p2 ()
20855 "Check if point is at a character currently not visible."
20857 (if (and (eolp) (not (bobp))) (backward-char 1))
20858 ;; Early versions of noutline don't have `outline-invisible-p'.
20859 (outline-invisible-p)))
20861 (defun org-back-to-heading (&optional invisible-ok)
20862 "Call `outline-back-to-heading', but provide a better error message."
20863 (condition-case nil
20864 (outline-back-to-heading invisible-ok)
20865 (error (error "Before first headline at position %d in buffer %s"
20866 (point) (current-buffer)))))
20868 (defun org-beginning-of-defun ()
20869 "Go to the beginning of the subtree, i.e. back to the heading."
20870 (org-back-to-heading))
20871 (defun org-end-of-defun ()
20872 "Go to the end of the subtree."
20873 (org-end-of-subtree nil t))
20875 (defun org-before-first-heading-p ()
20876 "Before first heading?"
20879 (null (re-search-backward org-outline-regexp-bol nil t))))
20881 (defun org-at-heading-p (&optional ignored)
20882 (outline-on-heading-p t))
20883 ;; Compatibility alias with Org versions < 7.8.03
20884 (defalias 'org-on-heading-p 'org-at-heading-p)
20886 (defun org-at-drawer-p nil
20887 "Is cursor at a drawer keyword?"
20889 (move-beginning-of-line 1)
20890 (looking-at org-drawer-regexp)))
20892 (defun org-at-block-p nil
20893 "Is cursor at a block keyword?"
20895 (move-beginning-of-line 1)
20896 (looking-at org-block-regexp)))
20898 (defun org-point-at-end-of-empty-headline ()
20899 "If point is at the end of an empty headline, return t, else nil.
20900 If the heading only contains a TODO keyword, it is still still considered
20902 (and (looking-at "[ \t]*$")
20904 (beginning-of-line 1)
20905 (let ((case-fold-search nil))
20906 (looking-at org-todo-line-regexp)))
20907 (string= (match-string 3) "")))
20909 (defun org-at-heading-or-item-p ()
20910 (or (org-at-heading-p) (org-at-item-p)))
20912 (defun org-at-target-p ()
20913 (or (org-in-regexp org-radio-target-regexp)
20914 (org-in-regexp org-target-regexp)))
20915 ;; Compatibility alias with Org versions < 7.8.03
20916 (defalias 'org-on-target-p 'org-at-target-p)
20918 (defun org-up-heading-all (arg)
20919 "Move to the heading line of which the present line is a subheading.
20920 This function considers both visible and invisible heading lines.
20921 With argument, move up ARG levels."
20922 (if (fboundp 'outline-up-heading-all)
20923 (outline-up-heading-all arg) ; emacs 21 version of outline.el
20924 (outline-up-heading arg t))) ; emacs 22 version of outline.el
20926 (defun org-up-heading-safe ()
20927 "Move to the heading line of which the present line is a subheading.
20928 This version will not throw an error. It will return the level of the
20929 headline found, or nil if no higher level is found.
20931 Also, this function will be a lot faster than `outline-up-heading',
20932 because it relies on stars being the outline starters. This can really
20933 make a significant difference in outlines with very many siblings."
20934 (let (start-level re)
20935 (org-back-to-heading t)
20936 (setq start-level (funcall outline-level))
20937 (if (equal start-level 1)
20939 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
20940 (if (re-search-backward re nil t)
20941 (funcall outline-level)))))
20943 (defun org-first-sibling-p ()
20944 "Is this heading the first child of its parents?"
20946 (let ((re org-outline-regexp-bol)
20948 (unless (org-at-heading-p t)
20949 (error "Not at a heading"))
20950 (setq level (funcall outline-level))
20952 (if (not (re-search-backward re nil t))
20954 (setq l (funcall outline-level))
20957 (defun org-goto-sibling (&optional previous)
20958 "Goto the next sibling, even if it is invisible.
20959 When PREVIOUS is set, go to the previous sibling instead. Returns t
20960 when a sibling was found. When none is found, return nil and don't
20962 (let ((fun (if previous 're-search-backward 're-search-forward))
20964 (re org-outline-regexp-bol)
20966 (when (condition-case nil (org-back-to-heading t) (error nil))
20967 (setq level (funcall outline-level))
20969 (or previous (forward-char 1))
20970 (while (funcall fun re nil t)
20971 (setq l (funcall outline-level))
20972 (when (< l level) (goto-char pos) (throw 'exit nil))
20973 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
20977 (defun org-show-siblings ()
20978 "Show all siblings of the current headline."
20980 (while (org-goto-sibling) (org-flag-heading nil)))
20982 (while (org-goto-sibling 'previous)
20983 (org-flag-heading nil))))
20985 (defun org-goto-first-child ()
20986 "Goto the first child, even if it is invisible.
20987 Return t when a child was found. Otherwise don't move point and
20989 (let (level (pos (point)) (re org-outline-regexp-bol))
20990 (when (condition-case nil (org-back-to-heading t) (error nil))
20991 (setq level (outline-level))
20993 (if (and (re-search-forward re nil t) (> (outline-level) level))
20994 (progn (goto-char (match-beginning 0)) t)
20995 (goto-char pos) nil))))
20997 (defun org-show-hidden-entry ()
20998 "Show an entry where even the heading is hidden."
21002 (defun org-flag-heading (flag &optional entry)
21003 "Flag the current heading. FLAG non-nil means make invisible.
21004 When ENTRY is non-nil, show the entire entry."
21006 (org-back-to-heading t)
21007 ;; Check if we should show the entire entry
21012 (and (outline-next-heading)
21013 (org-flag-heading nil))))
21014 (outline-flag-region (max (point-min) (1- (point)))
21015 (save-excursion (outline-end-of-heading) (point))
21018 (defun org-get-next-sibling ()
21019 "Move to next heading of the same level, and return point.
21020 If there is no such heading, return nil.
21021 This is like outline-next-sibling, but invisible headings are ok."
21022 (let ((level (funcall outline-level)))
21023 (outline-next-heading)
21024 (while (and (not (eobp)) (> (funcall outline-level) level))
21025 (outline-next-heading))
21026 (if (or (eobp) (< (funcall outline-level) level))
21030 (defun org-get-last-sibling ()
21031 "Move to previous heading of the same level, and return point.
21032 If there is no such heading, return nil."
21033 (let ((opoint (point))
21034 (level (funcall outline-level)))
21035 (outline-previous-heading)
21036 (when (and (/= (point) opoint) (outline-on-heading-p t))
21037 (while (and (> (funcall outline-level) level)
21039 (outline-previous-heading))
21040 (if (< (funcall outline-level) level)
21044 (defun org-end-of-subtree (&optional invisible-OK to-heading)
21045 ;; This contains an exact copy of the original function, but it uses
21046 ;; `org-back-to-heading', to make it work also in invisible
21047 ;; trees. And is uses an invisible-OK argument.
21048 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
21049 ;; Furthermore, when used inside Org, finding the end of a large subtree
21050 ;; with many children and grandchildren etc, this can be much faster
21051 ;; than the outline version.
21052 (org-back-to-heading invisible-OK)
21054 (level (funcall outline-level)))
21055 (if (and (eq major-mode 'org-mode) (< level 1000))
21056 ;; A true heading (not a plain list item), in Org-mode
21057 ;; This means we can easily find the end by looking
21058 ;; only for the right number of stars. Using a regexp to do
21059 ;; this is so much faster than using a Lisp loop.
21060 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
21062 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
21063 ;; something else, do it the slow way
21064 (while (and (not (eobp))
21065 (or first (> (funcall outline-level) level)))
21067 (outline-next-heading)))
21069 (if (memq (preceding-char) '(?\n ?\^M))
21071 ;; Go to end of line before heading
21073 (if (memq (preceding-char) '(?\n ?\^M))
21074 ;; leave blank line before heading
21075 (forward-char -1))))))
21078 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
21079 "Use Org version in org-mode, for dramatic speed-up."
21080 (if (eq major-mode 'org-mode)
21082 (org-end-of-subtree nil t)
21083 (unless (eobp) (backward-char 1)))
21086 (defun org-end-of-meta-data-and-drawers ()
21087 "Jump to the first text after meta data and drawers in the current entry.
21088 This will move over empty lines, lines with planning time stamps,
21089 clocking lines, and drawers."
21090 (org-back-to-heading t)
21091 (let ((end (save-excursion (outline-next-heading) (point)))
21092 (re (concat "\\(" org-drawer-regexp "\\)"
21093 "\\|" "[ \t]*" org-keyword-time-regexp)))
21095 (while (re-search-forward re end t)
21096 (if (not (match-end 1))
21097 ;; empty or planning line
21099 ;; a drawer, find the end
21100 (re-search-forward "^[ \t]*:END:" end 'move)
21102 (and (re-search-forward "[^\n]" nil t) (backward-char 1))
21105 (defun org-forward-same-level (arg &optional invisible-ok)
21106 "Move forward to the arg'th subheading at same level as this one.
21107 Stop at the first and last subheadings of a superior heading.
21108 Normally this only looks at visible headings, but when INVISIBLE-OK is non-nil
21109 it wil also look at invisible ones."
21111 (org-back-to-heading invisible-ok)
21113 (let* ((level (- (match-end 0) (match-beginning 0) 1))
21114 (re (format "^\\*\\{1,%d\\} " level))
21118 (while (and (re-search-forward re nil 'move)
21119 (setq l (- (match-end 0) (match-beginning 0) 1))
21122 (progn (backward-char 1) (outline-invisible-p)))
21123 (if (< l level) (setq arg 1)))
21124 (setq arg (1- arg)))
21125 (beginning-of-line 1)))
21127 (defun org-backward-same-level (arg &optional invisible-ok)
21128 "Move backward to the arg'th subheading at same level as this one.
21129 Stop at the first and last subheadings of a superior heading."
21131 (org-back-to-heading)
21133 (let* ((level (- (match-end 0) (match-beginning 0) 1))
21134 (re (format "^\\*\\{1,%d\\} " level))
21137 (while (and (re-search-backward re nil 'move)
21138 (setq l (- (match-end 0) (match-beginning 0) 1))
21141 (outline-invisible-p))
21142 (if (< l level) (setq arg 1)))
21143 (setq arg (1- arg)))))
21145 (defun org-show-subtree ()
21146 "Show everything after this heading at deeper levels."
21147 (outline-flag-region
21150 (org-end-of-subtree t t))
21153 (defun org-show-entry ()
21154 "Show the body directly following this heading.
21155 Show the heading too, if it is currently invisible."
21158 (condition-case nil
21160 (org-back-to-heading t)
21161 (outline-flag-region
21162 (max (point-min) (1- (point)))
21164 (if (re-search-forward
21165 (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
21166 (match-beginning 1)
21169 (org-cycle-hide-drawers 'children))
21172 (defun org-make-options-regexp (kwds &optional extra)
21173 "Make a regular expression for keyword lines."
21177 (mapconcat 'regexp-quote kwds "\\|")
21178 (if extra (concat "\\|" extra))
21182 ;; Make isearch reveal the necessary context
21183 (defun org-isearch-end ()
21184 "Reveal context after isearch exits."
21185 (when isearch-success ; only if search was successful
21186 (if (featurep 'xemacs)
21187 ;; Under XEmacs, the hook is run in the correct place,
21188 ;; we directly show the context.
21189 (org-show-context 'isearch)
21190 ;; In Emacs the hook runs *before* restoring the overlays.
21191 ;; So we have to use a one-time post-command-hook to do this.
21192 ;; (Emacs 22 has a special variable, see function `org-mode')
21193 (unless (and (boundp 'isearch-mode-end-hook-quit)
21194 isearch-mode-end-hook-quit)
21195 ;; Only when the isearch was not quitted.
21196 (org-add-hook 'post-command-hook 'org-isearch-post-command
21197 'append 'local)))))
21199 (defun org-isearch-post-command ()
21200 "Remove self from hook, and show context."
21201 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
21202 (org-show-context 'isearch))
21205 ;;;; Integration with and fixes for other packages
21209 (defvar org-imenu-markers nil
21210 "All markers currently used by Imenu.")
21211 (make-variable-buffer-local 'org-imenu-markers)
21213 (defun org-imenu-new-marker (&optional pos)
21214 "Return a new marker for use by Imenu, and remember the marker."
21215 (let ((m (make-marker)))
21216 (move-marker m (or pos (point)))
21217 (push m org-imenu-markers)
21220 (defun org-imenu-get-tree ()
21221 "Produce the index for Imenu."
21222 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
21223 (setq org-imenu-markers nil)
21224 (let* ((n org-imenu-depth)
21225 (re (concat "^" (org-get-limited-outline-regexp)))
21226 (subs (make-vector (1+ n) nil))
21232 (goto-char (point-max))
21233 (while (re-search-backward re nil t)
21234 (setq level (org-reduced-level (funcall outline-level)))
21236 (looking-at org-complex-heading-regexp)
21237 (setq head (org-link-display-format
21238 (org-match-string-no-properties 4))
21239 m (org-imenu-new-marker))
21240 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
21241 (if (>= level last-level)
21242 (push (cons head m) (aref subs level))
21243 (push (cons head (aref subs (1+ level))) (aref subs level))
21244 (loop for i from (1+ level) to n do (aset subs i nil)))
21245 (setq last-level level)))))
21248 (eval-after-load "imenu"
21250 (add-hook 'imenu-after-jump-hook
21252 (if (eq major-mode 'org-mode)
21253 (org-show-context 'org-goto))))))
21255 (defun org-link-display-format (link)
21256 "Replace a link with either the description, or the link target
21257 if no description is present"
21259 (if (string-match org-bracket-link-analytic-regexp link)
21260 (replace-match (if (match-end 5)
21261 (match-string 5 link)
21262 (concat (match-string 1 link)
21263 (match-string 3 link)))
21267 (defun org-toggle-link-display ()
21268 "Toggle the literal or descriptive display of links."
21270 (if org-descriptive-links
21271 (progn (org-remove-from-invisibility-spec '(org-link))
21272 (org-restart-font-lock)
21273 (setq org-descriptive-links nil))
21274 (progn (add-to-invisibility-spec '(org-link))
21275 (org-restart-font-lock)
21276 (setq org-descriptive-links t))))
21278 ;; Speedbar support
21280 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
21281 "Overlay marking the agenda restriction line in speedbar.")
21282 (overlay-put org-speedbar-restriction-lock-overlay
21283 'face 'org-agenda-restriction-lock)
21284 (overlay-put org-speedbar-restriction-lock-overlay
21285 'help-echo "Agendas are currently limited to this item.")
21286 (org-detach-overlay org-speedbar-restriction-lock-overlay)
21288 (defun org-speedbar-set-agenda-restriction ()
21289 "Restrict future agenda commands to the location at point in speedbar.
21290 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
21292 (require 'org-agenda)
21293 (let (p m tp np dir txt)
21295 ((setq p (text-property-any (point-at-bol) (point-at-eol)
21297 (setq m (get-text-property p 'org-imenu-marker))
21298 (with-current-buffer (marker-buffer m)
21300 (org-agenda-set-restriction-lock 'subtree)))
21301 ((setq p (text-property-any (point-at-bol) (point-at-eol)
21302 'speedbar-function 'speedbar-find-file))
21303 (setq tp (previous-single-property-change
21304 (1+ p) 'speedbar-function)
21305 np (next-single-property-change
21306 tp 'speedbar-function)
21307 dir (speedbar-line-directory)
21308 txt (buffer-substring-no-properties (or tp (point-min))
21309 (or np (point-max))))
21310 (with-current-buffer (find-file-noselect
21311 (let ((default-directory dir))
21312 (expand-file-name txt)))
21313 (unless (eq major-mode 'org-mode)
21314 (error "Cannot restrict to non-Org-mode file"))
21315 (org-agenda-set-restriction-lock 'file)))
21316 (t (error "Don't know how to restrict Org-mode's agenda")))
21317 (move-overlay org-speedbar-restriction-lock-overlay
21318 (point-at-bol) (point-at-eol))
21319 (setq current-prefix-arg nil)
21320 (org-agenda-maybe-redo)))
21322 (eval-after-load "speedbar"
21324 (speedbar-add-supported-extension ".org")
21325 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
21326 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
21327 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
21328 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
21329 (add-hook 'speedbar-visiting-tag-hook
21330 (lambda () (and (eq major-mode 'org-mode) (org-show-context 'org-goto))))))
21332 ;;; Fixes and Hacks for problems with other packages
21334 ;; Make flyspell not check words in links, to not mess up our keymap
21335 (defun org-mode-flyspell-verify ()
21336 "Don't let flyspell put overlays at active buttons, or on
21337 {todo,all-time,additional-option-like}-keywords."
21338 (let ((pos (max (1- (point)) (point-min)))
21339 (word (thing-at-point 'word)))
21340 (and (not (get-text-property pos 'keymap))
21341 (not (get-text-property pos 'org-no-flyspell))
21342 (not (member word org-todo-keywords-1))
21343 (not (member word org-all-time-keywords))
21344 (not (member word org-additional-option-like-keywords)))))
21346 (defun org-remove-flyspell-overlays-in (beg end)
21347 "Remove flyspell overlays in region."
21348 (and (org-bound-and-true-p flyspell-mode)
21349 (fboundp 'flyspell-delete-region-overlays)
21350 (flyspell-delete-region-overlays beg end))
21351 (add-text-properties beg end '(org-no-flyspell t)))
21353 ;; Make `bookmark-jump' shows the jump location if it was hidden.
21354 (eval-after-load "bookmark"
21355 '(if (boundp 'bookmark-after-jump-hook)
21356 ;; We can use the hook
21357 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
21358 ;; Hook not available, use advice
21359 (defadvice bookmark-jump (after org-make-visible activate)
21360 "Make the position visible."
21361 (org-bookmark-jump-unhide))))
21363 ;; Make sure saveplace shows the location if it was hidden
21364 (eval-after-load "saveplace"
21365 '(defadvice save-place-find-file-hook (after org-make-visible activate)
21366 "Make the position visible."
21367 (org-bookmark-jump-unhide)))
21369 ;; Make sure ecb shows the location if it was hidden
21370 (eval-after-load "ecb"
21371 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
21372 "Make hierarchy visible when jumping into location from ECB tree buffer."
21373 (if (eq major-mode 'org-mode)
21374 (org-show-context))))
21376 (defun org-bookmark-jump-unhide ()
21377 "Unhide the current position, to show the bookmark location."
21378 (and (eq major-mode 'org-mode)
21379 (or (outline-invisible-p)
21380 (save-excursion (goto-char (max (point-min) (1- (point))))
21381 (outline-invisible-p)))
21382 (org-show-context 'bookmark-jump)))
21384 ;; Make session.el ignore our circular variable
21385 (eval-after-load "session"
21386 '(add-to-list 'session-globals-exclude 'org-mark-ring))
21388 ;;;; Experimental code
21390 (defun org-closed-in-range ()
21391 "Sparse tree of items closed in a certain time range.
21392 Still experimental, may disappear in the future."
21394 ;; Get the time interval from the user.
21395 (let* ((time1 (org-float-time
21396 (org-read-date nil 'to-time nil "Starting date: ")))
21397 (time2 (org-float-time
21398 (org-read-date nil 'to-time nil "End date:")))
21399 ;; callback function
21400 (callback (lambda ()
21403 (apply 'encode-time
21404 (org-parse-time-string
21405 (match-string 1))))))
21406 ;; check if time in interval
21407 (and (>= time time1) (<= time time2))))))
21408 ;; make tree, check each match with the callback
21409 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
21415 (run-hooks 'org-load-hook)
21417 ;;; org.el ends here