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
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
30 ;; project planning with a fast and effective plain-text system.
32 ;; Org-mode develops organizational tasks around NOTES files that contain
33 ;; information about projects as plain text. Org-mode is implemented on
34 ;; top of outline-mode, which makes it possible to keep the content of
35 ;; large files well structured. Visibility cycling and structure editing
36 ;; help to work with the tree. Tables are easily created with a built-in
37 ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
38 ;; and scheduling. It dynamically compiles entries into an agenda that
39 ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
40 ;; Plain text URL-like links connect to websites, emails, Usenet
41 ;; messages, BBDB entries, and any files related to the projects. For
42 ;; printing and sharing of notes, an Org-mode file can be exported as a
43 ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
44 ;; iCalendar file. It can also serve as a publishing tool for a set of
47 ;; Installation and Activation
48 ;; ---------------------------
49 ;; See the corresponding sections in the manual at
51 ;; http://orgmode.org/org.html#Installation
55 ;; The documentation of Org-mode can be found in the TeXInfo file. The
56 ;; distribution also contains a PDF version of it. At the homepage of
57 ;; Org-mode, you can read the same text online as HTML. There is also an
58 ;; excellent reference card made by Philip Rooke. This card can be found
59 ;; in the etc/ directory of Emacs 22.
61 ;; A list of recent changes can be found at
62 ;; http://orgmode.org/Changes.html
66 (defvar org-inhibit-highlight-removal nil
) ; dynamically scoped param
67 (defvar org-table-formula-constants-local nil
68 "Local version of `org-table-formula-constants'.")
69 (make-variable-buffer-local 'org-table-formula-constants-local
)
71 ;;;; Require other packages
79 (require 'format-spec
)
81 ;; `org-outline-regexp' ought to be a defconst but is let-binding in
82 ;; some places -- e.g. see the macro org-with-limited-levels.
84 ;; In Org buffers, the value of `outline-regexp' is that of
85 ;; `org-outline-regexp'. The only function still directly relying on
86 ;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
87 ;; job when `orgstruct-mode' is active.
88 (defvar org-outline-regexp
"\\*+ "
89 "Regexp to match Org headlines.")
91 (defvar org-outline-regexp-bol
"^\\*+ "
92 "Regexp to match Org headlines.
93 This is similar to `org-outline-regexp' but additionally makes
94 sure that we are at the beginning of the line.")
96 (defvar org-heading-regexp
"^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
97 "Matches an headline, putting stars and text into groups.
98 Stars are put in group 1 and the trimmed body in group 2.")
100 ;; Emacs 22 calendar compatibility: Make sure the new variables are available
101 (when (fboundp 'defvaralias
)
102 (unless (boundp 'calendar-view-holidays-initially-flag
)
103 (defvaralias 'calendar-view-holidays-initially-flag
104 'view-calendar-holidays-initially
))
105 (unless (boundp 'calendar-view-diary-initially-flag
)
106 (defvaralias 'calendar-view-diary-initially-flag
107 'view-diary-entries-initially
))
108 (unless (boundp 'diary-fancy-buffer
)
109 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
)))
111 (declare-function org-inlinetask-at-task-p
"org-inlinetask" ())
112 (declare-function org-inlinetask-outline-regexp
"org-inlinetask" ())
113 (declare-function org-inlinetask-toggle-visibility
"org-inlinetask" ())
114 (declare-function org-pop-to-buffer-same-window
"org-compat" (&optional buffer-or-name norecord label
))
115 (declare-function org-at-clock-log-p
"org-clock" ())
116 (declare-function org-clock-timestamps-up
"org-clock" ())
117 (declare-function org-clock-timestamps-down
"org-clock" ())
119 ;; load languages based on value of `org-babel-load-languages'
120 (defvar org-babel-load-languages
)
122 (defun org-babel-do-load-languages (sym value
)
123 "Load the languages defined in `org-babel-load-languages'."
124 (set-default sym value
)
126 (let ((active (cdr pair
)) (lang (symbol-name (car pair
))))
129 (require (intern (concat "ob-" lang
))))
131 (funcall 'fmakunbound
132 (intern (concat "org-babel-execute:" lang
)))
133 (funcall 'fmakunbound
134 (intern (concat "org-babel-expand-body:" lang
)))))))
135 org-babel-load-languages
))
137 (defcustom org-babel-load-languages
'((emacs-lisp . t
))
138 "Languages which can be evaluated in Org-mode buffers.
139 This list can be used to load support for any of the languages
140 below, note that each language will depend on a different set of
141 system executables and/or Emacs modes. When a language is
142 \"loaded\", then code blocks in that language can be evaluated
143 with `org-babel-execute-src-block' bound by default to C-c
144 C-c (note the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can
145 be set to remove code block evaluation from the C-c C-c
146 keybinding. By default only Emacs Lisp (which has no
147 requirements) is loaded."
149 :set
'org-babel-do-load-languages
151 :type
'(alist :tag
"Babel Languages"
154 (const :tag
"Awk" awk
)
157 (const :tag
"Asymptote" asymptote
)
158 (const :tag
"Calc" calc
)
159 (const :tag
"Clojure" clojure
)
160 (const :tag
"CSS" css
)
161 (const :tag
"Ditaa" ditaa
)
162 (const :tag
"Dot" dot
)
163 (const :tag
"Emacs Lisp" emacs-lisp
)
164 (const :tag
"Fortran" fortran
)
165 (const :tag
"Gnuplot" gnuplot
)
166 (const :tag
"Haskell" haskell
)
168 (const :tag
"Java" java
)
169 (const :tag
"Javascript" js
)
170 (const :tag
"LaTeX" latex
)
171 (const :tag
"Ledger" ledger
)
172 (const :tag
"Lilypond" lilypond
)
173 (const :tag
"Lisp" lisp
)
174 (const :tag
"Maxima" maxima
)
175 (const :tag
"Matlab" matlab
)
176 (const :tag
"Mscgen" mscgen
)
177 (const :tag
"Ocaml" ocaml
)
178 (const :tag
"Octave" octave
)
179 (const :tag
"Org" org
)
180 (const :tag
"Perl" perl
)
181 (const :tag
"Pico Lisp" picolisp
)
182 (const :tag
"PlantUML" plantuml
)
183 (const :tag
"Python" python
)
184 (const :tag
"Ruby" ruby
)
185 (const :tag
"Sass" sass
)
186 (const :tag
"Scala" scala
)
187 (const :tag
"Scheme" scheme
)
188 (const :tag
"Screen" screen
)
189 (const :tag
"Shell Script" sh
)
190 (const :tag
"Shen" shen
)
191 (const :tag
"Sql" sql
)
192 (const :tag
"Sqlite" sqlite
))
193 :value-type
(boolean :tag
"Activate" :value t
)))
195 ;;;; Customization variables
196 (defcustom org-clone-delete-id nil
197 "Remove ID property of clones of a subtree.
198 When non-nil, clones of a subtree don't inherit the ID property.
199 Otherwise they inherit the ID property with a new unique
206 (require 'org-compat
)
209 (defun org-version (&optional here full message
)
210 "Show the org-mode version in the echo area.
211 With prefix argument HERE, insert it at point.
212 When FULL is non-nil, use a verbose version string.
213 When MESSAGE is non-nil, display a message with the version."
215 (let* ((org-dir (ignore-errors (org-find-library-dir "org")))
216 (org-install-dir (ignore-errors (org-find-library-dir "org-install.el")))
218 (and (fboundp 'org-release
) (fboundp 'org-git-version
))
219 (load (concat org-dir
"org-version.el")
220 'noerror
'nomessage
'nosuffix
)))
221 (org-version (org-release))
222 (git-version (org-git-version))
223 (version (format "Org-mode version %s (%s @ %s)"
227 (if (string= org-dir org-install-dir
)
229 (concat "mixed installation! " org-install-dir
" and " org-dir
))
230 "org-install.el can not be found!")))
231 (_version (if full version org-version
)))
232 (if (org-called-interactively-p 'interactive
)
236 (if message
(message _version
))
239 (defconst org-version
(org-version))
241 ;;; Compatibility constants
243 ;;; The custom variables
246 "Outline-based notes management and organizer."
251 (defcustom org-mode-hook nil
252 "Mode hook for Org-mode, run after the mode was turned on."
256 (defcustom org-load-hook nil
257 "Hook that is run after org.el has been loaded."
261 (defcustom org-log-buffer-setup-hook nil
262 "Hook that is run after an Org log buffer is created."
267 (defvar org-modules
) ; defined below
268 (defvar org-modules-loaded nil
269 "Have the modules been loaded already?")
271 (defun org-load-modules-maybe (&optional force
)
272 "Load all extensions listed in `org-modules'."
273 (when (or force
(not org-modules-loaded
))
275 (condition-case nil
(require ext
)
276 (error (message "Problems while trying to load feature `%s'" ext
))))
278 (setq org-modules-loaded t
)))
280 (defun org-set-modules (var value
)
281 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
283 (when (featurep 'org
)
284 (org-load-modules-maybe 'force
)))
286 (when (org-bound-and-true-p org-modules
)
287 (let ((a (member 'org-infojs org-modules
)))
288 (and a
(setcar a
'org-jsinfo
))))
290 (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
)
291 "Modules that should always be loaded together with org.el.
292 If a description starts with <C>, the file is not part of Emacs
293 and loading it will require that you have downloaded and properly installed
294 the org-mode distribution.
296 You can also use this system to load external packages (i.e. neither Org
297 core modules, nor modules from the CONTRIB directory). Just add symbols
298 to the end of the list. If the package is called org-xyz.el, then you need
299 to add the symbol `xyz', and the package must have a call to
303 :set
'org-set-modules
306 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
307 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
308 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
309 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
310 (const :tag
" docview: Links to doc-view buffers" org-docview
)
311 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
312 (const :tag
" id: Global IDs for identifying entries" org-id
)
313 (const :tag
" info: Links to Info nodes" org-info
)
314 (const :tag
" jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo
)
315 (const :tag
" habit: Track your consistency with habits" org-habit
)
316 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
317 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
318 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
319 (const :tag
" mew Links to Mew folders/messages" org-mew
)
320 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
321 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
322 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
323 (const :tag
" special-blocks: Turn blocks into LaTeX envs and HTML divs" org-special-blocks
)
324 (const :tag
" vm: Links to VM folders/messages" org-vm
)
325 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
326 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
327 (const :tag
" mouse: Additional mouse support" org-mouse
)
328 (const :tag
" TaskJuggler: Export tasks to a TaskJuggler project" org-taskjuggler
)
330 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
331 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
332 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
333 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
334 (const :tag
"C collector: Collect properties into tables" org-collector
)
335 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
336 (const :tag
"C drill: Flashcards and spaced repetition for Org-mode" org-drill
)
337 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
338 (const :tag
"C eshell Support for links to working directories in eshell" org-eshell
)
339 (const :tag
"C eval: Include command output as text" org-eval
)
340 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
341 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
342 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
343 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
344 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
346 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
348 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
349 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
350 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
351 (const :tag
"C notmuch: Provide org links to notmuch searches or messages" org-notmuch
)
352 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
353 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
354 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
355 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
356 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
357 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
358 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
359 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
360 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
361 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
362 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
363 (const :tag
"C track: Keep up with Org-mode development" org-track
)
364 (const :tag
"C velocity Something like Notational Velocity for Org" org-velocity
)
365 (const :tag
"C wikinodes: CamelCase wiki-like links" org-wikinodes
)
366 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
368 (defcustom org-support-shift-select nil
369 "Non-nil means make shift-cursor commands select text when possible.
371 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys
372 start selecting a region, or enlarge regions started in this way.
373 In Org-mode, in special contexts, these same keys are used for
374 other purposes, important enough to compete with shift selection.
375 Org tries to balance these needs by supporting `shift-select-mode'
376 outside these special contexts, under control of this variable.
378 The default of this variable is nil, to avoid confusing behavior. Shifted
379 cursor keys will then execute Org commands in the following contexts:
380 - on a headline, changing TODO state (left/right) and priority (up/down)
381 - on a time stamp, changing the time
382 - in a plain list item, changing the bullet type
383 - in a property definition line, switching between allowed values
384 - in the BEGIN line of a clock table (changing the time block).
385 Outside these contexts, the commands will throw an error.
387 When this variable is t and the cursor is not in a special
388 context, Org-mode will support shift-selection for making and
389 enlarging regions. To make this more effective, the bullet
390 cycling will no longer happen anywhere in an item line, but only
391 if the cursor is exactly on the bullet.
393 If you set this variable to the symbol `always', then the keys
394 will not be special in headlines, property lines, and item lines,
395 to make shift selection work there as well. If this is what you
396 want, you can use the following alternative commands: `C-c C-t'
397 and `C-c ,' to change TODO state and priority, `C-u C-u C-c C-t'
398 can be used to switch TODO sets, `C-c -' to cycle item bullet
399 types, and properties can be edited by hand or in column view.
401 However, when the cursor is on a timestamp, shift-cursor commands
402 will still edit the time stamp - this is just too good to give up.
404 XEmacs user should have this variable set to nil, because
405 `shift-select-mode' is in Emacs 23 or later only."
408 (const :tag
"Never" nil
)
409 (const :tag
"When outside special context" t
)
410 (const :tag
"Everywhere except timestamps" always
)))
412 (defcustom org-loop-over-headlines-in-active-region nil
413 "Shall some commands act upon headlines in the active region?
415 When set to `t', some commands will be performed in all headlines
416 within the active region.
418 When set to `start-level', some commands will be performed in all
419 headlines within the active region, provided that these headlines
420 are of the same level than the first one.
422 When set to a string, those commands will be performed on the
423 matching headlines within the active region. Such string must be
424 a tags/property/todo match as it is used in the agenda tags view.
426 The list of commands is: `org-schedule', `org-deadline',
427 `org-todo', `org-archive-subtree', `org-archive-set-tag' and
428 `org-archive-to-archive-sibling'. The archiving commands skip
429 already archived entries."
430 :type
'(choice (const :tag
"Don't loop" nil
)
431 (const :tag
"All headlines in active region" t
)
432 (const :tag
"In active region, headlines at the same level than the first one" 'start-level
)
433 (string :tag
"Tags/Property/Todo matcher"))
438 (defgroup org-startup nil
439 "Options concerning startup of Org-mode."
443 (defcustom org-startup-folded t
444 "Non-nil means entering Org-mode will switch to OVERVIEW.
445 This can also be configured on a per-file basis by adding one of
446 the following lines anywhere in the buffer:
448 #+STARTUP: fold (or `overview', this is equivalent)
449 #+STARTUP: nofold (or `showall', this is equivalent)
451 #+STARTUP: showeverything"
454 (const :tag
"nofold: show all" nil
)
455 (const :tag
"fold: overview" t
)
456 (const :tag
"content: all headlines" content
)
457 (const :tag
"show everything, even drawers" showeverything
)))
459 (defcustom org-startup-truncated t
460 "Non-nil means entering Org-mode will set `truncate-lines'.
461 This is useful since some lines containing links can be very long and
462 uninteresting. Also tables look terrible when wrapped."
466 (defcustom org-startup-indented nil
467 "Non-nil means turn on `org-indent-mode' on startup.
468 This can also be configured on a per-file basis by adding one of
469 the following lines anywhere in the buffer:
473 :group
'org-structure
475 (const :tag
"Not" nil
)
476 (const :tag
"Globally (slow on startup in large files)" t
)))
478 (defcustom org-use-sub-superscripts t
479 "Non-nil means interpret \"_\" and \"^\" for export.
480 When this option is turned on, you can use TeX-like syntax for sub- and
481 superscripts. Several characters after \"_\" or \"^\" will be
482 considered as a single item - so grouping with {} is normally not
483 needed. For example, the following things will be parsed as single
484 sub- or superscripts.
486 10^24 or 10^tau several digits will be considered 1 item.
487 10^-12 or 10^-tau a leading sign with digits or a word
488 x^2-y^3 will be read as x^2 - y^3, because items are
489 terminated by almost any nonword/nondigit char.
490 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
492 Still, ambiguity is possible - so when in doubt use {} to enclose the
493 sub/superscript. If you set this variable to the symbol `{}',
494 the braces are *required* in order to trigger interpretations as
495 sub/superscript. This can be helpful in documents that need \"_\"
496 frequently in plain text.
498 Not all export backends support this, but HTML does.
500 This option can also be set with the #+OPTIONS line, e.g. \"^:nil\"."
502 :group
'org-export-translation
505 (const :tag
"Always interpret" t
)
506 (const :tag
"Only with braces" {})
507 (const :tag
"Never interpret" nil
)))
509 (if (fboundp 'defvaralias
)
510 (defvaralias 'org-export-with-sub-superscripts
'org-use-sub-superscripts
))
513 (defcustom org-startup-with-beamer-mode nil
514 "Non-nil means turn on `org-beamer-mode' on startup.
515 This can also be configured on a per-file basis by adding one of
516 the following lines anywhere in the buffer:
523 (defcustom org-startup-align-all-tables nil
524 "Non-nil means align all tables when visiting a file.
525 This is useful when the column width in tables is forced with <N> cookies
526 in table fields. Such tables will look correct only after the first re-align.
527 This can also be configured on a per-file basis by adding one of
528 the following lines anywhere in the buffer:
534 (defcustom org-startup-with-inline-images nil
535 "Non-nil means show inline images when loading a new Org file.
536 This can also be configured on a per-file basis by adding one of
537 the following lines anywhere in the buffer:
538 #+STARTUP: inlineimages
539 #+STARTUP: noinlineimages"
544 (defcustom org-insert-mode-line-in-empty-file nil
545 "Non-nil means insert the first line setting Org-mode in empty files.
546 When the function `org-mode' is called interactively in an empty file, this
547 normally means that the file name does not automatically trigger Org-mode.
548 To ensure that the file will always be in Org-mode in the future, a
549 line enforcing Org-mode will be inserted into the buffer, if this option
554 (defcustom org-replace-disputed-keys nil
555 "Non-nil means use alternative key bindings for some keys.
556 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
557 These keys are also used by other packages like shift-selection-mode'
558 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
559 If you want to use Org-mode together with one of these other modes,
560 or more generally if you would like to move some Org-mode commands to
561 other keys, set this variable and configure the keys with the variable
564 This option is only relevant at load-time of Org-mode, and must be set
565 *before* org.el is loaded. Changing it requires a restart of Emacs to
570 (defcustom org-use-extra-keys nil
571 "Non-nil means use extra key sequence definitions for certain commands.
572 This happens automatically if you run XEmacs or if `window-system'
573 is nil. This variable lets you do the same manually. You must
574 set it before loading org.
576 Example: on Carbon Emacs 22 running graphically, with an external
577 keyboard on a Powerbook, the default way of setting M-left might
578 not work for either Alt or ESC. Setting this variable will make
583 (if (fboundp 'defvaralias
)
584 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
586 (defcustom org-disputed-keys
587 '(([(shift up
)] .
[(meta p
)])
588 ([(shift down
)] .
[(meta n
)])
589 ([(shift left
)] .
[(meta -
)])
590 ([(shift right
)] .
[(meta +)])
591 ([(control shift right
)] .
[(meta shift
+)])
592 ([(control shift left
)] .
[(meta shift -
)]))
593 "Keys for which Org-mode and other modes compete.
594 This is an alist, cars are the default keys, second element specifies
595 the alternative to use when `org-replace-disputed-keys' is t.
597 Keys can be specified in any syntax supported by `define-key'.
598 The value of this option takes effect only at Org-mode's startup,
599 therefore you'll have to restart Emacs to apply it after changing."
604 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
605 Or return the original if not disputed.
606 Also apply the translations defined in `org-xemacs-key-equivalents'."
607 (when org-replace-disputed-keys
608 (let* ((nkey (key-description key
))
609 (x (org-find-if (lambda (x)
610 (equal (key-description (car x
)) nkey
))
612 (setq key
(if x
(cdr x
) key
))))
613 (when (featurep 'xemacs
)
614 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
617 (defun org-find-if (predicate seq
)
620 (if (funcall predicate
(car seq
))
621 (throw 'exit
(car seq
))
624 (defun org-defkey (keymap key def
)
625 "Define a key, possibly translated, as returned by `org-key'."
626 (define-key keymap
(org-key key
) def
))
628 (defcustom org-ellipsis nil
629 "The ellipsis to use in the Org-mode outline.
630 When nil, just use the standard three dots. When a string, use that instead,
631 When a face, use the standard 3 dots, but with the specified face.
632 The change affects only Org-mode (which will then use its own display table).
633 Changing this requires executing `M-x org-mode' in a buffer to become
636 :type
'(choice (const :tag
"Default" nil
)
637 (face :tag
"Face" :value org-warning
)
638 (string :tag
"String" :value
"...#")))
640 (defvar org-display-table nil
641 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
643 (defgroup org-keywords nil
644 "Keywords in Org-mode."
648 (defcustom org-deadline-string
"DEADLINE:"
649 "String to mark deadline entries.
650 A deadline is this string, followed by a time stamp. Should be a word,
651 terminated by a colon. You can insert a schedule keyword and
652 a timestamp with \\[org-deadline].
653 Changes become only effective after restarting Emacs."
657 (defcustom org-scheduled-string
"SCHEDULED:"
658 "String to mark scheduled TODO entries.
659 A schedule is this string, followed by a time stamp. Should be a word,
660 terminated by a colon. You can insert a schedule keyword and
661 a timestamp with \\[org-schedule].
662 Changes become only effective after restarting Emacs."
666 (defcustom org-closed-string
"CLOSED:"
667 "String used as the prefix for timestamps logging closing a TODO entry."
671 (defcustom org-clock-string
"CLOCK:"
672 "String used as prefix for timestamps clocking work hours on an item."
676 (defconst org-planning-or-clock-line-re
(concat "^[ \t]*\\("
677 org-scheduled-string
"\\|"
678 org-deadline-string
"\\|"
679 org-closed-string
"\\|"
680 org-clock-string
"\\)")
681 "Matches a line with planning or clock info.")
683 (defcustom org-comment-string
"COMMENT"
684 "Entries starting with this keyword will never be exported.
685 An entry can be toggled between COMMENT and normal with
686 \\[org-toggle-comment].
687 Changes become only effective after restarting Emacs."
691 (defcustom org-quote-string
"QUOTE"
692 "Entries starting with this keyword will be exported in fixed-width font.
693 Quoting applies only to the text in the entry following the headline, and does
694 not extend beyond the next headline, even if that is lower level.
695 An entry can be toggled between QUOTE and normal with
696 \\[org-toggle-fixed-width-section]."
700 (defconst org-repeat-re
701 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
702 "Regular expression for specifying repeated events.
703 After a match, group 1 contains the repeat expression.")
705 (defgroup org-structure nil
706 "Options concerning the general structure of Org-mode files."
710 (defgroup org-reveal-location nil
711 "Options about how to make context of a location visible."
712 :tag
"Org Reveal Location"
713 :group
'org-structure
)
715 (defconst org-context-choice
717 (const :tag
"Always" t
)
718 (const :tag
"Never" nil
)
719 (repeat :greedy t
:tag
"Individual contexts"
721 (choice :tag
"Context"
728 (const bookmark-jump
)
732 "Contexts for the reveal options.")
734 (defcustom org-show-hierarchy-above
'((default . t
))
735 "Non-nil means show full hierarchy when revealing a location.
736 Org-mode often shows locations in an org-mode file which might have
737 been invisible before. When this is set, the hierarchy of headings
738 above the exposed location is shown.
739 Turning this off for example for sparse trees makes them very compact.
740 Instead of t, this can also be an alist specifying this option for different
741 contexts. Valid contexts are
742 agenda when exposing an entry from the agenda
743 org-goto when using the command `org-goto' on key C-c C-j
744 occur-tree when using the command `org-occur' on key C-c /
745 tags-tree when constructing a sparse tree based on tags matches
746 link-search when exposing search matches associated with a link
747 mark-goto when exposing the jump goal of a mark
748 bookmark-jump when exposing a bookmark location
749 isearch when exiting from an incremental search
750 default default for all contexts not set explicitly"
751 :group
'org-reveal-location
752 :type org-context-choice
)
754 (defcustom org-show-following-heading
'((default . nil
))
755 "Non-nil means show following heading when revealing a location.
756 Org-mode often shows locations in an org-mode file which might have
757 been invisible before. When this is set, the heading following the
759 Turning this off for example for sparse trees makes them very compact,
760 but makes it harder to edit the location of the match. In such a case,
761 use the command \\[org-reveal] to show more context.
762 Instead of t, this can also be an alist specifying this option for different
763 contexts. See `org-show-hierarchy-above' for valid contexts."
764 :group
'org-reveal-location
765 :type org-context-choice
)
767 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
768 "Non-nil means show all sibling heading when revealing a location.
769 Org-mode often shows locations in an org-mode file which might have
770 been invisible before. When this is set, the sibling of the current entry
771 heading are all made visible. If `org-show-hierarchy-above' is t,
772 the same happens on each level of the hierarchy above the current entry.
774 By default this is on for the isearch context, off for all other contexts.
775 Turning this off for example for sparse trees makes them very compact,
776 but makes it harder to edit the location of the match. In such a case,
777 use the command \\[org-reveal] to show more context.
778 Instead of t, this can also be an alist specifying this option for different
779 contexts. See `org-show-hierarchy-above' for valid contexts."
780 :group
'org-reveal-location
781 :type org-context-choice
)
783 (defcustom org-show-entry-below
'((default . nil
))
784 "Non-nil means show the entry below a headline when revealing a location.
785 Org-mode often shows locations in an org-mode file which might have
786 been invisible before. When this is set, the text below the headline that is
787 exposed is also shown.
789 By default this is off for all contexts.
790 Instead of t, this can also be an alist specifying this option for different
791 contexts. See `org-show-hierarchy-above' for valid contexts."
792 :group
'org-reveal-location
793 :type org-context-choice
)
795 (defcustom org-indirect-buffer-display
'other-window
796 "How should indirect tree buffers be displayed?
797 This applies to indirect buffers created with the commands
798 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
800 current-window Display in the current window
801 other-window Just display in another window.
802 dedicated-frame Create one new frame, and re-use it each time.
803 new-frame Make a new frame each time. Note that in this case
804 previously-made indirect buffers are kept, and you need to
805 kill these buffers yourself."
806 :group
'org-structure
807 :group
'org-agenda-windows
809 (const :tag
"In current window" current-window
)
810 (const :tag
"In current frame, other window" other-window
)
811 (const :tag
"Each time a new frame" new-frame
)
812 (const :tag
"One dedicated frame" dedicated-frame
)))
814 (defcustom org-use-speed-commands nil
815 "Non-nil means activate single letter commands at beginning of a headline.
816 This may also be a function to test for appropriate locations where speed
817 commands should be active."
818 :group
'org-structure
820 (const :tag
"Never" nil
)
821 (const :tag
"At beginning of headline stars" t
)
824 (defcustom org-speed-commands-user nil
825 "Alist of additional speed commands.
826 This list will be checked before `org-speed-commands-default'
827 when the variable `org-use-speed-commands' is non-nil
828 and when the cursor is at the beginning of a headline.
829 The car if each entry is a string with a single letter, which must
830 be assigned to `self-insert-command' in the global map.
831 The cdr is either a command to be called interactively, a function
832 to be called, or a form to be evaluated.
833 An entry that is just a list with a single string will be interpreted
834 as a descriptive headline that will be added when listing the speed
835 commands in the Help buffer using the `?' speed command."
836 :group
'org-structure
837 :type
'(repeat :value
("k" . ignore
)
838 (choice :value
("k" . ignore
)
839 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
840 (cons :tag
"Letter and Command"
841 (string :tag
"Command letter")
846 (defgroup org-cycle nil
847 "Options concerning visibility cycling in Org-mode."
849 :group
'org-structure
)
851 (defcustom org-cycle-skip-children-state-if-no-children t
852 "Non-nil means skip CHILDREN state in entries that don't have any."
856 (defcustom org-cycle-max-level nil
857 "Maximum level which should still be subject to visibility cycling.
858 Levels higher than this will, for cycling, be treated as text, not a headline.
859 When `org-odd-levels-only' is set, a value of N in this variable actually
860 means 2N-1 stars as the limiting headline.
861 When nil, cycle all levels.
862 Note that the limiting level of cycling is also influenced by
863 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
864 `org-inlinetask-min-level' is, cycling will be limited to levels one less
868 (const :tag
"No limit" nil
)
869 (integer :tag
"Maximum level")))
871 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK" "RESULTS")
872 "Names of drawers. Drawers are not opened by cycling on the headline above.
873 Drawers only open with a TAB on the drawer line itself. A drawer looks like
878 The drawer \"PROPERTIES\" is special for capturing properties through
881 Drawers can be defined on the per-file basis with a line like:
883 #+DRAWERS: HIDDEN STATE PROPERTIES"
884 :group
'org-structure
886 :type
'(repeat (string :tag
"Drawer Name")))
888 (defcustom org-hide-block-startup nil
889 "Non-nil means entering Org-mode will fold all blocks.
890 This can also be set in on a per-file basis with
892 #+STARTUP: hideblocks
893 #+STARTUP: showblocks"
898 (defcustom org-cycle-global-at-bob nil
899 "Cycle globally if cursor is at beginning of buffer and not at a headline.
900 This makes it possible to do global cycling without having to use S-TAB or
901 \\[universal-argument] TAB. For this special case to work, the first line \
903 must not be a headline - it may be empty or some other text. When used in
904 this way, `org-cycle-hook' is disables temporarily, to make sure the
905 cursor stays at the beginning of the buffer.
906 When this option is nil, don't do anything special at the beginning
911 (defcustom org-cycle-level-after-item
/entry-creation t
912 "Non-nil means cycle entry level or item indentation in new empty entries.
914 When the cursor is at the end of an empty headline, i.e with only stars
915 and maybe a TODO keyword, TAB will then switch the entry to become a child,
916 and then all possible ancestor states, before returning to the original state.
917 This makes data entry extremely fast: M-RET to create a new headline,
918 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
920 When the cursor is at the end of an empty plain list item, one TAB will
921 make it a subitem, two or more tabs will back up to make this an item
922 higher up in the item hierarchy."
926 (defcustom org-cycle-emulate-tab t
927 "Where should `org-cycle' emulate TAB.
929 white Only in completely white lines
930 whitestart Only at the beginning of lines, before the first non-white char
931 t Everywhere except in headlines
932 exc-hl-bol Everywhere except at the start of a headline
933 If TAB is used in a place where it does not emulate TAB, the current subtree
934 visibility is cycled."
936 :type
'(choice (const :tag
"Never" nil
)
937 (const :tag
"Only in completely white lines" white
)
938 (const :tag
"Before first char in a line" whitestart
)
939 (const :tag
"Everywhere except in headlines" t
)
940 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
943 (defcustom org-cycle-separator-lines
2
944 "Number of empty lines needed to keep an empty line between collapsed trees.
945 If you leave an empty line between the end of a subtree and the following
946 headline, this empty line is hidden when the subtree is folded.
947 Org-mode will leave (exactly) one empty line visible if the number of
948 empty lines is equal or larger to the number given in this variable.
949 So the default 2 means at least 2 empty lines after the end of a subtree
950 are needed to produce free space between a collapsed subtree and the
953 If the number is negative, and the number of empty lines is at least -N,
954 all empty lines are shown.
956 Special case: when 0, never leave empty lines in collapsed view."
959 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
961 (defcustom org-pre-cycle-hook nil
962 "Hook that is run before visibility cycling is happening.
963 The function(s) in this hook must accept a single argument which indicates
964 the new state that will be set right after running this hook. The
965 argument is a symbol. Before a global state change, it can have the values
966 `overview', `content', or `all'. Before a local state change, it can have
967 the values `folded', `children', or `subtree'."
971 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
972 org-cycle-hide-drawers
973 org-cycle-show-empty-lines
974 org-optimize-window-after-visibility-change
)
975 "Hook that is run after `org-cycle' has changed the buffer visibility.
976 The function(s) in this hook must accept a single argument which indicates
977 the new state that was set by the most recent `org-cycle' command. The
978 argument is a symbol. After a global state change, it can have the values
979 `overview', `content', or `all'. After a local state change, it can have
980 the values `folded', `children', or `subtree'."
984 (defgroup org-edit-structure nil
985 "Options concerning structure editing in Org-mode."
986 :tag
"Org Edit Structure"
987 :group
'org-structure
)
989 (defcustom org-odd-levels-only nil
990 "Non-nil means skip even levels and only use odd levels for the outline.
991 This has the effect that two stars are being added/taken away in
992 promotion/demotion commands. It also influences how levels are
993 handled by the exporters.
994 Changing it requires restart of `font-lock-mode' to become effective
995 for fontification also in regions already fontified.
996 You may also set this on a per-file basis by adding one of the following
1001 :group
'org-edit-structure
1002 :group
'org-appearance
1005 (defcustom org-adapt-indentation t
1006 "Non-nil means adapt indentation to outline node level.
1008 When this variable is set, Org assumes that you write outlines by
1009 indenting text in each node to align with the headline (after the stars).
1010 The following issues are influenced by this variable:
1012 - When this is set and the *entire* text in an entry is indented, the
1013 indentation is increased by one space in a demotion command, and
1014 decreased by one in a promotion command. If any line in the entry
1015 body starts with text at column 0, indentation is not changed at all.
1017 - Property drawers and planning information is inserted indented when
1018 this variable s set. When nil, they will not be indented.
1020 - TAB indents a line relative to context. The lines below a headline
1021 will be indented when this variable is set.
1023 Note that this is all about true indentation, by adding and removing
1024 space characters. See also `org-indent.el' which does level-dependent
1025 indentation in a virtual way, i.e. at display time in Emacs."
1026 :group
'org-edit-structure
1029 (defcustom org-special-ctrl-a
/e nil
1030 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
1032 When t, `C-a' will bring back the cursor to the beginning of the
1033 headline text, i.e. after the stars and after a possible TODO
1034 keyword. In an item, this will be the position after bullet and
1035 check-box, if any. When the cursor is already at that position,
1036 another `C-a' will bring it to the beginning of the line.
1038 `C-e' will jump to the end of the headline, ignoring the presence
1039 of tags in the headline. A second `C-e' will then jump to the
1040 true end of the line, after any tags. This also means that, when
1041 this variable is non-nil, `C-e' also will never jump beyond the
1042 end of the heading of a folded section, i.e. not after the
1045 When set to the symbol `reversed', the first `C-a' or `C-e' works
1046 normally, going to the true line boundary first. Only a directly
1047 following, identical keypress will bring the cursor to the
1050 This may also be a cons cell where the behavior for `C-a' and
1051 `C-e' is set separately."
1052 :group
'org-edit-structure
1054 (const :tag
"off" nil
)
1055 (const :tag
"on: after stars/bullet and before tags first" t
)
1056 (const :tag
"reversed: true line boundary first" reversed
)
1057 (cons :tag
"Set C-a and C-e separately"
1058 (choice :tag
"Special C-a"
1059 (const :tag
"off" nil
)
1060 (const :tag
"on: after stars/bullet first" t
)
1061 (const :tag
"reversed: before stars/bullet first" reversed
))
1062 (choice :tag
"Special C-e"
1063 (const :tag
"off" nil
)
1064 (const :tag
"on: before tags first" t
)
1065 (const :tag
"reversed: after tags first" reversed
)))))
1066 (if (fboundp 'defvaralias
)
1067 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
1069 (defcustom org-special-ctrl-k nil
1070 "Non-nil means `C-k' will behave specially in headlines.
1071 When nil, `C-k' will call the default `kill-line' command.
1072 When t, the following will happen while the cursor is in the headline:
1074 - When the cursor is at the beginning of a headline, kill the entire
1075 line and possible the folded subtree below the line.
1076 - When in the middle of the headline text, kill the headline up to the tags.
1077 - When after the headline text, kill the tags."
1078 :group
'org-edit-structure
1081 (defcustom org-ctrl-k-protect-subtree nil
1082 "Non-nil means, do not delete a hidden subtree with C-k.
1083 When set to the symbol `error', simply throw an error when C-k is
1084 used to kill (part-of) a headline that has hidden text behind it.
1085 Any other non-nil value will result in a query to the user, if it is
1086 OK to kill that hidden subtree. When nil, kill without remorse."
1087 :group
'org-edit-structure
1090 (const :tag
"Do not protect hidden subtrees" nil
)
1091 (const :tag
"Protect hidden subtrees with a security query" t
)
1092 (const :tag
"Never kill a hidden subtree with C-k" error
)))
1094 (defcustom org-catch-invisible-edits nil
1095 "Check if in invisible region before inserting or deleting a character.
1098 nil Do not check, so just do invisible edits.
1099 error Throw an error and do nothing.
1100 show Make point visible, and do the requested edit.
1101 show-and-error Make point visible, then throw an error and abort the edit.
1102 smart Make point visible, and do insertion/deletion if it is
1103 adjacent to visible text and the change feels predictable.
1104 Never delete a previously invisible character or add in the
1105 middle or right after an invisible region. Basically, this
1106 allows insertion and backward-delete right before ellipses.
1107 FIXME: maybe in this case we should not even show?"
1108 :group
'org-edit-structure
1111 (const :tag
"Do not check" nil
)
1112 (const :tag
"Throw error when trying to edit" error
)
1113 (const :tag
"Unhide, but do not do the edit" show-and-error
)
1114 (const :tag
"Show invisible part and do the edit" show
)
1115 (const :tag
"Be smart and do the right thing" smart
)))
1117 (defcustom org-yank-folded-subtrees t
1118 "Non-nil means when yanking subtrees, fold them.
1119 If the kill is a single subtree, or a sequence of subtrees, i.e. if
1120 it starts with a heading and all other headings in it are either children
1121 or siblings, then fold all the subtrees. However, do this only if no
1122 text after the yank would be swallowed into a folded tree by this action."
1123 :group
'org-edit-structure
1126 (defcustom org-yank-adjusted-subtrees nil
1127 "Non-nil means when yanking subtrees, adjust the level.
1128 With this setting, `org-paste-subtree' is used to insert the subtree, see
1129 this function for details."
1130 :group
'org-edit-structure
1133 (defcustom org-M-RET-may-split-line
'((default . t
))
1134 "Non-nil means M-RET will split the line at the cursor position.
1135 When nil, it will go to the end of the line before making a
1137 You may also set this option in a different way for different
1138 contexts. Valid contexts are:
1140 headline when creating a new headline
1141 item when creating a new item
1142 table in a table field
1143 default the value to be used for all contexts not explicitly
1145 :group
'org-structure
1148 (const :tag
"Always" t
)
1149 (const :tag
"Never" nil
)
1150 (repeat :greedy t
:tag
"Individual contexts"
1152 (choice :tag
"Context"
1160 (defcustom org-insert-heading-respect-content nil
1161 "Non-nil means insert new headings after the current subtree.
1162 When nil, the new heading is created directly after the current line.
1163 The commands \\[org-insert-heading-respect-content] and
1164 \\[org-insert-todo-heading-respect-content] turn this variable on
1165 for the duration of the command."
1166 :group
'org-structure
1169 (defcustom org-blank-before-new-entry
'((heading . auto
)
1170 (plain-list-item . auto
))
1171 "Should `org-insert-heading' leave a blank line before new heading/item?
1172 The value is an alist, with `heading' and `plain-list-item' as CAR,
1173 and a boolean flag as CDR. The cdr may also be the symbol `auto', in
1174 which case Org will look at the surrounding headings/items and try to
1175 make an intelligent decision whether to insert a blank line or not.
1177 For plain lists, if the variable `org-empty-line-terminates-plain-lists' is
1178 set, the setting here is ignored and no empty line is inserted, to avoid
1179 breaking the list structure."
1180 :group
'org-edit-structure
1182 (cons (const heading
)
1183 (choice (const :tag
"Never" nil
)
1184 (const :tag
"Always" t
)
1185 (const :tag
"Auto" auto
)))
1186 (cons (const plain-list-item
)
1187 (choice (const :tag
"Never" nil
)
1188 (const :tag
"Always" t
)
1189 (const :tag
"Auto" auto
)))))
1191 (defcustom org-insert-heading-hook nil
1192 "Hook being run after inserting a new heading."
1193 :group
'org-edit-structure
1196 (defcustom org-enable-fixed-width-editor t
1197 "Non-nil means lines starting with \":\" are treated as fixed-width.
1198 This currently only means they are never auto-wrapped.
1199 When nil, such lines will be treated like ordinary lines.
1200 See also the QUOTE keyword."
1201 :group
'org-edit-structure
1204 (defcustom org-goto-auto-isearch t
1205 "Non-nil means typing characters in `org-goto' starts incremental search."
1206 :group
'org-edit-structure
1209 (defgroup org-sparse-trees nil
1210 "Options concerning sparse trees in Org-mode."
1211 :tag
"Org Sparse Trees"
1212 :group
'org-structure
)
1214 (defcustom org-highlight-sparse-tree-matches t
1215 "Non-nil means highlight all matches that define a sparse tree.
1216 The highlights will automatically disappear the next time the buffer is
1217 changed by an edit command."
1218 :group
'org-sparse-trees
1221 (defcustom org-remove-highlights-with-change t
1222 "Non-nil means any change to the buffer will remove temporary highlights.
1223 Such highlights are created by `org-occur' and `org-clock-display'.
1224 When nil, `C-c C-c needs to be used to get rid of the highlights.
1225 The highlights created by `org-preview-latex-fragment' always need
1226 `C-c C-c' to be removed."
1227 :group
'org-sparse-trees
1232 (defcustom org-occur-hook
'(org-first-headline-recenter)
1233 "Hook that is run after `org-occur' has constructed a sparse tree.
1234 This can be used to recenter the window to show as much of the structure
1236 :group
'org-sparse-trees
1239 (defgroup org-imenu-and-speedbar nil
1240 "Options concerning imenu and speedbar in Org-mode."
1241 :tag
"Org Imenu and Speedbar"
1242 :group
'org-structure
)
1244 (defcustom org-imenu-depth
2
1245 "The maximum level for Imenu access to Org-mode headlines.
1246 This also applied for speedbar access."
1247 :group
'org-imenu-and-speedbar
1250 (defgroup org-table nil
1251 "Options concerning tables in Org-mode."
1255 (defcustom org-enable-table-editor
'optimized
1256 "Non-nil means lines starting with \"|\" are handled by the table editor.
1257 When nil, such lines will be treated like ordinary lines.
1259 When equal to the symbol `optimized', the table editor will be optimized to
1261 - Automatic overwrite mode in front of whitespace in table fields.
1262 This makes the structure of the table stay in tact as long as the edited
1263 field does not exceed the column width.
1264 - Minimize the number of realigns. Normally, the table is aligned each time
1265 TAB or RET are pressed to move to another field. With optimization this
1266 happens only if changes to a field might have changed the column width.
1267 Optimization requires replacing the functions `self-insert-command',
1268 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1269 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1270 very good at guessing when a re-align will be necessary, but you can always
1271 force one with \\[org-ctrl-c-ctrl-c].
1273 If you would like to use the optimized version in Org-mode, but the
1274 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1276 This variable can be used to turn on and off the table editor during a session,
1277 but in order to toggle optimization, a restart is required.
1279 See also the variable `org-table-auto-blank-field'."
1282 (const :tag
"off" nil
)
1284 (const :tag
"on, optimized" optimized
)))
1286 (defcustom org-self-insert-cluster-for-undo
(or (featurep 'xemacs
)
1287 (version<= emacs-version
"24.1"))
1288 "Non-nil means cluster self-insert commands for undo when possible.
1289 If this is set, then, like in the Emacs command loop, 20 consecutive
1290 characters will be undone together.
1291 This is configurable, because there is some impact on typing performance."
1295 (defcustom org-table-tab-recognizes-table.el t
1296 "Non-nil means TAB will automatically notice a table.el table.
1297 When it sees such a table, it moves point into it and - if necessary -
1298 calls `table-recognize-table'."
1299 :group
'org-table-editing
1302 (defgroup org-link nil
1303 "Options concerning links in Org-mode."
1307 (defvar org-link-abbrev-alist-local nil
1308 "Buffer-local version of `org-link-abbrev-alist', which see.
1309 The value of this is taken from the #+LINK lines.")
1310 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1312 (defcustom org-link-abbrev-alist nil
1313 "Alist of link abbreviations.
1314 The car of each element is a string, to be replaced at the start of a link.
1315 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1316 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1318 [[linkkey:tag][description]]
1320 The 'linkkey' must be a word word, starting with a letter, followed
1321 by letters, numbers, '-' or '_'.
1323 If REPLACE is a string, the tag will simply be appended to create the link.
1324 If the string contains \"%s\", the tag will be inserted there. If the string
1325 contains \"%h\", it will cause a url-encoded version of the tag to be inserted
1326 at that point (see the function `url-hexify-string'). If the string contains
1327 the specifier \"%(my-function)\", then the custom function `my-function' will
1328 be invoked: this function takes the tag as its only argument and must return
1331 REPLACE may also be a function that will be called with the tag as the
1332 only argument to create the link, which should be returned as a string.
1334 See the manual for examples."
1338 (string :tag
"Protocol")
1340 (string :tag
"Format")
1343 (defcustom org-descriptive-links t
1344 "Non-nil means Org will display descriptive links.
1345 E.g. [[http://orgmode.org][Org website]] will be displayed as
1346 \"Org Website\", hiding the link itself and just displaying its
1347 description. When set to `nil', Org will display the full links
1350 You can interactively set the value of this variable by calling
1351 `org-toggle-link-display' or from the menu Org>Hyperlinks menu."
1355 (defcustom org-link-file-path-type
'adaptive
1356 "How the path name in file links should be stored.
1359 relative Relative to the current directory, i.e. the directory of the file
1360 into which the link is being inserted.
1361 absolute Absolute path, if possible with ~ for home directory.
1362 noabbrev Absolute path, no abbreviation of home directory.
1363 adaptive Use relative path for files in the current directory and sub-
1364 directories of it. For other files, use an absolute path."
1372 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1373 "Types of links that should be activated in Org-mode files.
1374 This is a list of symbols, each leading to the activation of a certain link
1375 type. In principle, it does not hurt to turn on most link types - there may
1376 be a small gain when turning off unused link types. The types are:
1378 bracket The recommended [[link][description]] or [[link]] links with hiding.
1379 angle Links in angular brackets that may contain whitespace like
1380 <bbdb:Carsten Dominik>.
1381 plain Plain links in normal text, no whitespace, like http://google.com.
1382 radio Text that is matched by a radio target, see manual for details.
1383 tag Tag settings in a headline (link to tag search).
1384 date Time stamps (link to calendar).
1385 footnote Footnote labels.
1387 Changing this variable requires a restart of Emacs to become effective."
1389 :type
'(set :greedy t
1390 (const :tag
"Double bracket links" bracket
)
1391 (const :tag
"Angular bracket links" angle
)
1392 (const :tag
"Plain text links" plain
)
1393 (const :tag
"Radio target matches" radio
)
1394 (const :tag
"Tags" tag
)
1395 (const :tag
"Timestamps" date
)
1396 (const :tag
"Footnotes" footnote
)))
1398 (defcustom org-make-link-description-function nil
1399 "Function to use to generate link descriptions from links.
1400 If nil the link location will be used. This function must take
1401 two parameters; the first is the link and the second the
1402 description `org-insert-link' has generated, and should return the
1403 description to use."
1407 (defgroup org-link-store nil
1408 "Options concerning storing links in Org-mode."
1409 :tag
"Org Store Link"
1412 (defcustom org-url-hexify-p t
1413 "When non-nil, hexify URL when creating a link."
1416 :group
'org-link-store
)
1418 (defcustom org-email-link-description-format
"Email %c: %.30s"
1419 "Format of the description part of a link to an email or usenet message.
1420 The following %-escapes will be replaced by corresponding information:
1422 %F full \"From\" field
1423 %f name, taken from \"From\" field, address if no name
1424 %T full \"To\" field
1425 %t first name in \"To\" field, address if no name
1426 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1427 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1432 You may use normal field width specification between the % and the letter.
1433 This is for example useful to limit the length of the subject.
1435 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1436 :group
'org-link-store
1439 (defcustom org-from-is-user-regexp
1441 (when (and user-mail-address
(not (string= user-mail-address
"")))
1442 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1443 (when (and user-full-name
(not (string= user-full-name
"")))
1444 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1445 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1446 "Regexp matched against the \"From:\" header of an email or usenet message.
1447 It should match if the message is from the user him/herself."
1448 :group
'org-link-store
1451 (defcustom org-link-to-org-use-id
'create-if-interactive-and-no-custom-id
1452 "Non-nil means storing a link to an Org file will use entry IDs.
1454 Note that before this variable is even considered, org-id must be loaded,
1455 so please customize `org-modules' and turn it on.
1457 The variable can have the following values:
1459 t Create an ID if needed to make a link to the current entry.
1461 create-if-interactive
1462 If `org-store-link' is called directly (interactively, as a user
1463 command), do create an ID to support the link. But when doing the
1464 job for remember, only use the ID if it already exists. The
1465 purpose of this setting is to avoid proliferation of unwanted
1466 IDs, just because you happen to be in an Org file when you
1467 call `org-capture' that automatically and preemptively creates a
1468 link. If you do want to get an ID link in a remember template to
1469 an entry not having an ID, create it first by explicitly creating
1470 a link to it, using `C-c C-l' first.
1472 create-if-interactive-and-no-custom-id
1473 Like create-if-interactive, but do not create an ID if there is
1474 a CUSTOM_ID property defined in the entry. This is the default.
1477 Use existing ID, do not create one.
1479 nil Never use an ID to make a link, instead link using a text search for
1481 :group
'org-link-store
1483 (const :tag
"Create ID to make link" t
)
1484 (const :tag
"Create if storing link interactively"
1485 create-if-interactive
)
1486 (const :tag
"Create if storing link interactively and no CUSTOM_ID is present"
1487 create-if-interactive-and-no-custom-id
)
1488 (const :tag
"Only use existing" use-existing
)
1489 (const :tag
"Do not use ID to create link" nil
)))
1491 (defcustom org-context-in-file-links t
1492 "Non-nil means file links from `org-store-link' contain context.
1493 A search string will be added to the file name with :: as separator and
1494 used to find the context when the link is activated by the command
1495 `org-open-at-point'. When this option is t, the entire active region
1496 will be placed in the search string of the file link. If set to a
1497 positive integer, only the first n lines of context will be stored.
1499 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1500 negates this setting for the duration of the command."
1501 :group
'org-link-store
1502 :type
'(choice boolean integer
))
1504 (defcustom org-keep-stored-link-after-insertion nil
1505 "Non-nil means keep link in list for entire session.
1507 The command `org-store-link' adds a link pointing to the current
1508 location to an internal list. These links accumulate during a session.
1509 The command `org-insert-link' can be used to insert links into any
1510 Org-mode file (offering completion for all stored links). When this
1511 option is nil, every link which has been inserted once using \\[org-insert-link]
1512 will be removed from the list, to make completing the unused links
1514 :group
'org-link-store
1517 (defgroup org-link-follow nil
1518 "Options concerning following links in Org-mode."
1519 :tag
"Org Follow Link"
1522 (defcustom org-link-translation-function nil
1523 "Function to translate links with different syntax to Org syntax.
1524 This can be used to translate links created for example by the Planner
1525 or emacs-wiki packages to Org syntax.
1526 The function must accept two parameters, a TYPE containing the link
1527 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1528 which is everything after the link protocol. It should return a cons
1529 with possibly modified values of type and path.
1530 Org contains a function for this, so if you set this variable to
1531 `org-translate-link-from-planner', you should be able follow many
1532 links created by planner."
1533 :group
'org-link-follow
1536 (defcustom org-follow-link-hook nil
1537 "Hook that is run after a link has been followed."
1538 :group
'org-link-follow
1541 (defcustom org-tab-follows-link nil
1542 "Non-nil means on links TAB will follow the link.
1543 Needs to be set before org.el is loaded.
1544 This really should not be used, it does not make sense, and the
1545 implementation is bad."
1546 :group
'org-link-follow
1549 (defcustom org-return-follows-link nil
1550 "Non-nil means on links RET will follow the link."
1551 :group
'org-link-follow
1554 (defcustom org-mouse-1-follows-link
1555 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1556 "Non-nil means mouse-1 on a link will follow the link.
1557 A longer mouse click will still set point. Does not work on XEmacs.
1558 Needs to be set before org.el is loaded."
1559 :group
'org-link-follow
1562 (defcustom org-mark-ring-length
4
1563 "Number of different positions to be recorded in the ring.
1564 Changing this requires a restart of Emacs to work correctly."
1565 :group
'org-link-follow
1568 (defcustom org-link-search-must-match-exact-headline
'query-to-create
1569 "Non-nil means internal links in Org files must exactly match a headline.
1570 When nil, the link search tries to match a phrase with all words
1571 in the search text."
1572 :group
'org-link-follow
1575 (const :tag
"Use fuzzy text search" nil
)
1576 (const :tag
"Match only exact headline" t
)
1577 (const :tag
"Match exact headline or query to create it"
1580 (defcustom org-link-frame-setup
1581 '((vm . vm-visit-folder-other-frame
)
1582 (vm-imap . vm-visit-imap-folder-other-frame
)
1583 (gnus . org-gnus-no-new-news
)
1584 (file . find-file-other-window
)
1585 (wl . wl-other-frame
))
1586 "Setup the frame configuration for following links.
1587 When following a link with Emacs, it may often be useful to display
1588 this link in another window or frame. This variable can be used to
1589 set this up for the different types of links.
1592 `vm-visit-folder-other-window'
1593 `vm-visit-folder-other-frame'
1594 For Gnus, use any of
1597 `org-gnus-no-new-news'
1598 For FILE, use any of
1600 `find-file-other-window'
1601 `find-file-other-frame'
1602 For Wanderlust use any of
1605 For the calendar, use the variable `calendar-setup'.
1606 For BBDB, it is currently only possible to display the matches in
1608 :group
'org-link-follow
1612 (const vm-visit-folder
)
1613 (const vm-visit-folder-other-window
)
1614 (const vm-visit-folder-other-frame
)))
1618 (const gnus-other-frame
)
1619 (const org-gnus-no-new-news
)))
1623 (const find-file-other-window
)
1624 (const find-file-other-frame
)))
1628 (const wl-other-frame
)))))
1630 (defcustom org-display-internal-link-with-indirect-buffer nil
1631 "Non-nil means use indirect buffer to display infile links.
1632 Activating internal links (from one location in a file to another location
1633 in the same file) normally just jumps to the location. When the link is
1634 activated with a \\[universal-argument] prefix (or with mouse-3), the link \
1636 another window. When this option is set, the other window actually displays
1637 an indirect buffer clone of the current buffer, to avoid any visibility
1638 changes to the current buffer."
1639 :group
'org-link-follow
1642 (defcustom org-open-non-existing-files nil
1643 "Non-nil means `org-open-file' will open non-existing files.
1644 When nil, an error will be generated.
1645 This variable applies only to external applications because they
1646 might choke on non-existing files. If the link is to a file that
1647 will be opened in Emacs, the variable is ignored."
1648 :group
'org-link-follow
1651 (defcustom org-open-directory-means-index-dot-org nil
1652 "Non-nil means a link to a directory really means to index.org.
1653 When nil, following a directory link will run dired or open a finder/explorer
1654 window on that directory."
1655 :group
'org-link-follow
1658 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1659 "Function and arguments to call for following mailto links.
1660 This is a list with the first element being a Lisp function, and the
1661 remaining elements being arguments to the function. In string arguments,
1662 %a will be replaced by the address, and %s will be replaced by the subject
1663 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1664 :group
'org-link-follow
1666 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1667 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1668 (const :tag
"message-mail" (message-mail "%a" "%s"))
1669 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1671 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1672 "Non-nil means ask for confirmation before executing shell links.
1673 Shell links can be dangerous: just think about a link
1675 [[shell:rm -rf ~/*][Google Search]]
1677 This link would show up in your Org-mode document as \"Google Search\",
1678 but really it would remove your entire home directory.
1679 Therefore we advise against setting this variable to nil.
1680 Just change it to `y-or-n-p' if you want to confirm with a
1681 single keystroke rather than having to type \"yes\"."
1682 :group
'org-link-follow
1684 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1685 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1686 (const :tag
"no confirmation (dangerous)" nil
)))
1687 (put 'org-confirm-shell-link-function
1688 'safe-local-variable
1689 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1691 (defcustom org-confirm-shell-link-not-regexp
""
1692 "A regexp to skip confirmation for shell links."
1693 :group
'org-link-follow
1697 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1698 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1699 Elisp links can be dangerous: just think about a link
1701 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1703 This link would show up in your Org-mode document as \"Google Search\",
1704 but really it would remove your entire home directory.
1705 Therefore we advise against setting this variable to nil.
1706 Just change it to `y-or-n-p' if you want to confirm with a
1707 single keystroke rather than having to type \"yes\"."
1708 :group
'org-link-follow
1710 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1711 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1712 (const :tag
"no confirmation (dangerous)" nil
)))
1713 (put 'org-confirm-shell-link-function
1714 'safe-local-variable
1715 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1717 (defcustom org-confirm-elisp-link-not-regexp
""
1718 "A regexp to skip confirmation for Elisp links."
1719 :group
'org-link-follow
1723 (defconst org-file-apps-defaults-gnu
1727 "Default file applications on a UNIX or GNU/Linux system.
1728 See `org-file-apps'.")
1730 (defconst org-file-apps-defaults-macosx
1733 (system .
"open %s")
1735 ("eps.gz" .
"gv %s")
1737 ("fig" .
"xfig %s"))
1738 "Default file applications on a MacOS X system.
1739 The system \"open\" is known as a default, but we use X11 applications
1740 for some files for which the OS does not have a good default.
1741 See `org-file-apps'.")
1743 (defconst org-file-apps-defaults-windowsnt
1747 (list (if (featurep 'xemacs
)
1748 'mswindows-shell-execute
1752 (list (if (featurep 'xemacs
)
1753 'mswindows-shell-execute
1756 "Default file applications on a Windows NT system.
1757 The system \"open\" is used for most files.
1758 See `org-file-apps'.")
1760 (defcustom org-file-apps
1763 ("\\.mm\\'" . default
)
1764 ("\\.x?html?\\'" . default
)
1765 ("\\.pdf\\'" . default
)
1767 "External applications for opening `file:path' items in a document.
1768 Org-mode uses system defaults for different file types, but
1769 you can use this variable to set the application for a given file
1770 extension. The entries in this list are cons cells where the car identifies
1771 files and the cdr the corresponding command. Possible values for the
1773 \"string\" A string as a file identifier can be interpreted in different
1774 ways, depending on its contents:
1776 - Alphanumeric characters only:
1777 Match links with this file extension.
1778 Example: (\"pdf\" . \"evince %s\")
1779 to open PDFs with evince.
1781 - Regular expression: Match links where the
1782 filename matches the regexp. If you want to
1783 use groups here, use shy groups.
1785 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1786 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1787 to open *.html and *.xhtml with firefox.
1789 - Regular expression which contains (non-shy) groups:
1790 Match links where the whole link, including \"::\", and
1791 anything after that, matches the regexp.
1792 In a custom command string, %1, %2, etc. are replaced with
1793 the parts of the link that were matched by the groups.
1794 For backwards compatibility, if a command string is given
1795 that does not use any of the group matches, this case is
1796 handled identically to the second one (i.e. match against
1798 In a custom lisp form, you can access the group matches with
1799 (match-string n link).
1801 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1802 to open [[file:document.pdf::5]] with evince at page 5.
1804 `directory' Matches a directory
1805 `remote' Matches a remote file, accessible through tramp or efs.
1806 Remote files most likely should be visited through Emacs
1807 because external applications cannot handle such paths.
1808 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1809 so all files Emacs knows how to handle. Using this with
1810 command `emacs' will open most files in Emacs. Beware that this
1811 will also open html files inside Emacs, unless you add
1812 (\"html\" . default) to the list as well.
1813 t Default for files not matched by any of the other options.
1814 `system' The system command to open files, like `open' on Windows
1815 and Mac OS X, and mailcap under GNU/Linux. This is the command
1816 that will be selected if you call `C-c C-o' with a double
1817 \\[universal-argument] \\[universal-argument] prefix.
1819 Possible values for the command are:
1820 `emacs' The file will be visited by the current Emacs process.
1821 `default' Use the default application for this file type, which is the
1822 association for t in the list, most likely in the system-specific
1824 This can be used to overrule an unwanted setting in the
1825 system-specific variable.
1826 `system' Use the system command for opening files, like \"open\".
1827 This command is specified by the entry whose car is `system'.
1828 Most likely, the system-specific version of this variable
1829 does define this command, but you can overrule/replace it
1831 string A command to be executed by a shell; %s will be replaced
1832 by the path to the file.
1833 sexp A Lisp form which will be evaluated. The file path will
1834 be available in the Lisp variable `file'.
1835 For more examples, see the system specific constants
1836 `org-file-apps-defaults-macosx'
1837 `org-file-apps-defaults-windowsnt'
1838 `org-file-apps-defaults-gnu'."
1839 :group
'org-link-follow
1841 (cons (choice :value
""
1842 (string :tag
"Extension")
1843 (const :tag
"System command to open files" system
)
1844 (const :tag
"Default for unrecognized files" t
)
1845 (const :tag
"Remote file" remote
)
1846 (const :tag
"Links to a directory" directory
)
1847 (const :tag
"Any files that have Emacs modes"
1850 (const :tag
"Visit with Emacs" emacs
)
1851 (const :tag
"Use default" default
)
1852 (const :tag
"Use the system command" system
)
1853 (string :tag
"Command")
1854 (sexp :tag
"Lisp form")))))
1856 (defcustom org-doi-server-url
"http://dx.doi.org/"
1857 "The URL of the DOI server."
1860 :group
'org-link-follow
)
1862 (defgroup org-refile nil
1863 "Options concerning refiling entries in Org-mode."
1867 (defcustom org-directory
"~/org"
1868 "Directory with org files.
1869 This is just a default location to look for Org files. There is no need
1870 at all to put your files into this directory. It is only used in the
1871 following situations:
1873 1. When a remember template specifies a target file that is not an
1874 absolute path. The path will then be interpreted relative to
1876 2. When a remember note is filed away in an interactive way (when exiting the
1877 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1878 with `org-directory' as the default path."
1880 :group
'org-remember
1883 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1884 "Default target for storing notes.
1885 Used as a fall back file for org-remember.el and org-capture.el, for
1886 templates that do not specify a target file."
1888 :group
'org-remember
1890 (const :tag
"Default from remember-data-file" nil
)
1893 (defcustom org-goto-interface
'outline
1894 "The default interface to be used for `org-goto'.
1896 outline The interface shows an outline of the relevant file
1897 and the correct heading is found by moving through
1898 the outline or by searching with incremental search.
1899 outline-path-completion Headlines in the current buffer are offered via
1900 completion. This is the interface also used by
1901 the refile command."
1904 (const :tag
"Outline" outline
)
1905 (const :tag
"Outline-path-completion" outline-path-completion
)))
1907 (defcustom org-goto-max-level
5
1908 "Maximum target level when running `org-goto' with refile interface."
1912 (defcustom org-reverse-note-order nil
1913 "Non-nil means store new notes at the beginning of a file or entry.
1914 When nil, new notes will be filed to the end of a file or entry.
1915 This can also be a list with cons cells of regular expressions that
1916 are matched against file names, and values."
1917 :group
'org-remember
1920 (const :tag
"Reverse always" t
)
1921 (const :tag
"Reverse never" nil
)
1922 (repeat :tag
"By file name regexp"
1923 (cons regexp boolean
))))
1925 (defcustom org-log-refile nil
1926 "Information to record when a task is refiled.
1928 Possible values are:
1930 nil Don't add anything
1931 time Add a time stamp to the task
1932 note Prompt for a note and add it with template `org-log-note-headings'
1934 This option can also be set with on a per-file-basis with
1936 #+STARTUP: nologrefile
1937 #+STARTUP: logrefile
1938 #+STARTUP: lognoterefile
1940 You can have local logging settings for a subtree by setting the LOGGING
1941 property to one or more of these keywords.
1943 When bulk-refiling from the agenda, the value `note' is forbidden and
1944 will temporarily be changed to `time'."
1946 :group
'org-progress
1949 (const :tag
"No logging" nil
)
1950 (const :tag
"Record timestamp" time
)
1951 (const :tag
"Record timestamp with note." note
)))
1953 (defcustom org-refile-targets nil
1954 "Targets for refiling entries with \\[org-refile].
1955 This is a list of cons cells. Each cell contains:
1956 - a specification of the files to be considered, either a list of files,
1957 or a symbol whose function or variable value will be used to retrieve
1958 a file name or a list of file names. If you use `org-agenda-files' for
1959 that, all agenda files will be scanned for targets. Nil means consider
1960 headings in the current buffer.
1961 - A specification of how to find candidate refile targets. This may be
1963 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
1964 This tag has to be present in all target headlines, inheritance will
1966 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
1968 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
1969 headlines that are refiling targets.
1970 - a cons cell (:level . N). Any headline of level N is considered a target.
1971 Note that, when `org-odd-levels-only' is set, level corresponds to
1972 order in hierarchy, not to the number of stars.
1973 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
1974 Note that, when `org-odd-levels-only' is set, level corresponds to
1975 order in hierarchy, not to the number of stars.
1977 Each element of this list generates a set of possible targets.
1978 The union of these sets is presented (with completion) to
1979 the user by `org-refile'.
1981 You can set the variable `org-refile-target-verify-function' to a function
1982 to verify each headline found by the simple criteria above.
1984 When this variable is nil, all top-level headlines in the current buffer
1985 are used, equivalent to the value `((nil . (:level . 1))'."
1989 (choice :value org-agenda-files
1990 (const :tag
"All agenda files" org-agenda-files
)
1991 (const :tag
"Current buffer" nil
)
1992 (function) (variable) (file))
1993 (choice :tag
"Identify target headline by"
1994 (cons :tag
"Specific tag" (const :value
:tag
) (string))
1995 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
1996 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
1997 (cons :tag
"Level number" (const :value
:level
) (integer))
1998 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
2000 (defcustom org-refile-target-verify-function nil
2001 "Function to verify if the headline at point should be a refile target.
2002 The function will be called without arguments, with point at the
2003 beginning of the headline. It should return t and leave point
2004 where it is if the headline is a valid target for refiling.
2006 If the target should not be selected, the function must return nil.
2007 In addition to this, it may move point to a place from where the search
2008 should be continued. For example, the function may decide that the entire
2009 subtree of the current entry should be excluded and move point to the end
2014 (defcustom org-refile-use-cache nil
2015 "Non-nil means cache refile targets to speed up the process.
2016 The cache for a particular file will be updated automatically when
2017 the buffer has been killed, or when any of the marker used for flagging
2018 refile targets no longer points at a live buffer.
2019 If you have added new entries to a buffer that might themselves be targets,
2020 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
2021 find that easier, `C-u C-u C-u C-c C-w'."
2026 (defcustom org-refile-use-outline-path nil
2027 "Non-nil means provide refile targets as paths.
2028 So a level 3 headline will be available as level1/level2/level3.
2030 When the value is `file', also include the file name (without directory)
2031 into the path. In this case, you can also stop the completion after
2032 the file name, to get entries inserted as top level in the file.
2034 When `full-file-path', include the full file path."
2037 (const :tag
"Not" nil
)
2038 (const :tag
"Yes" t
)
2039 (const :tag
"Start with file name" file
)
2040 (const :tag
"Start with full file path" full-file-path
)))
2042 (defcustom org-outline-path-complete-in-steps t
2043 "Non-nil means complete the outline path in hierarchical steps.
2044 When Org-mode uses the refile interface to select an outline path
2045 \(see variable `org-refile-use-outline-path'), the completion of
2046 the path can be done is a single go, or if can be done in steps down
2047 the headline hierarchy. Going in steps is probably the best if you
2048 do not use a special completion package like `ido' or `icicles'.
2049 However, when using these packages, going in one step can be very
2050 fast, while still showing the whole path to the entry."
2054 (defcustom org-refile-allow-creating-parent-nodes nil
2055 "Non-nil means allow to create new nodes as refile targets.
2056 New nodes are then created by adding \"/new node name\" to the completion
2057 of an existing node. When the value of this variable is `confirm',
2058 new node creation must be confirmed by the user (recommended)
2059 When nil, the completion must match an existing entry.
2061 Note that, if the new heading is not seen by the criteria
2062 listed in `org-refile-targets', multiple instances of the same
2063 heading would be created by trying again to file under the new
2067 (const :tag
"Never" nil
)
2068 (const :tag
"Always" t
)
2069 (const :tag
"Prompt for confirmation" confirm
)))
2071 (defcustom org-refile-active-region-within-subtree nil
2072 "Non-nil means also refile active region within a subtree.
2074 By default `org-refile' doesn't allow refiling regions if they
2075 don't contain a set of subtrees, but it might be convenient to
2076 do so sometimes: in that case, the first line of the region is
2077 converted to a headline before refiling."
2082 (defgroup org-todo nil
2083 "Options concerning TODO items in Org-mode."
2087 (defgroup org-progress nil
2088 "Options concerning Progress logging in Org-mode."
2092 (defvar org-todo-interpretation-widgets
2093 '((:tag
"Sequence (cycling hits every state)" sequence
)
2094 (:tag
"Type (cycling directly to DONE)" type
))
2095 "The available interpretation symbols for customizing `org-todo-keywords'.
2096 Interested libraries should add to this list.")
2098 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
2099 "List of TODO entry keyword sequences and their interpretation.
2100 \\<org-mode-map>This is a list of sequences.
2102 Each sequence starts with a symbol, either `sequence' or `type',
2103 indicating if the keywords should be interpreted as a sequence of
2104 action steps, or as different types of TODO items. The first
2105 keywords are states requiring action - these states will select a headline
2106 for inclusion into the global TODO list Org-mode produces. If one of
2107 the \"keywords\" is the vertical bar, \"|\", the remaining keywords
2108 signify that no further action is necessary. If \"|\" is not found,
2109 the last keyword is treated as the only DONE state of the sequence.
2111 The command \\[org-todo] cycles an entry through these states, and one
2112 additional state where no keyword is present. For details about this
2113 cycling, see the manual.
2115 TODO keywords and interpretation can also be set on a per-file basis with
2116 the special #+SEQ_TODO and #+TYP_TODO lines.
2118 Each keyword can optionally specify a character for fast state selection
2119 \(in combination with the variable `org-use-fast-todo-selection')
2120 and specifiers for state change logging, using the same syntax that
2121 is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says that
2122 the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
2123 indicates to record a time stamp each time this state is selected.
2125 Each keyword may also specify if a timestamp or a note should be
2126 recorded when entering or leaving the state, by adding additional
2127 characters in the parenthesis after the keyword. This looks like this:
2128 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
2129 record only the time of the state change. With X and Y being either
2130 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
2131 Y when leaving the state if and only if the *target* state does not
2132 define X. You may omit any of the fast-selection key or X or /Y,
2133 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
2135 For backward compatibility, this variable may also be just a list
2136 of keywords. In this case the interpretation (sequence or type) will be
2137 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
2139 :group
'org-keywords
2141 (repeat :tag
"Old syntax, just keywords"
2142 (string :tag
"Keyword"))
2143 (repeat :tag
"New syntax"
2146 :tag
"Interpretation"
2147 ;;Quick and dirty way to see
2148 ;;`org-todo-interpretations'. This takes the
2149 ;;place of item arguments
2157 org-todo-interpretation-widgets
))
2160 (string :tag
"Keyword"))))))
2162 (defvar org-todo-keywords-1 nil
2163 "All TODO and DONE keywords active in a buffer.")
2164 (make-variable-buffer-local 'org-todo-keywords-1
)
2165 (defvar org-todo-keywords-for-agenda nil
)
2166 (defvar org-done-keywords-for-agenda nil
)
2167 (defvar org-drawers-for-agenda nil
)
2168 (defvar org-todo-keyword-alist-for-agenda nil
)
2169 (defvar org-tag-alist-for-agenda nil
)
2170 (defvar org-agenda-contributing-files nil
)
2171 (defvar org-not-done-keywords nil
)
2172 (make-variable-buffer-local 'org-not-done-keywords
)
2173 (defvar org-done-keywords nil
)
2174 (make-variable-buffer-local 'org-done-keywords
)
2175 (defvar org-todo-heads nil
)
2176 (make-variable-buffer-local 'org-todo-heads
)
2177 (defvar org-todo-sets nil
)
2178 (make-variable-buffer-local 'org-todo-sets
)
2179 (defvar org-todo-log-states nil
)
2180 (make-variable-buffer-local 'org-todo-log-states
)
2181 (defvar org-todo-kwd-alist nil
)
2182 (make-variable-buffer-local 'org-todo-kwd-alist
)
2183 (defvar org-todo-key-alist nil
)
2184 (make-variable-buffer-local 'org-todo-key-alist
)
2185 (defvar org-todo-key-trigger nil
)
2186 (make-variable-buffer-local 'org-todo-key-trigger
)
2188 (defcustom org-todo-interpretation
'sequence
2189 "Controls how TODO keywords are interpreted.
2190 This variable is in principle obsolete and is only used for
2191 backward compatibility, if the interpretation of todo keywords is
2192 not given already in `org-todo-keywords'. See that variable for
2195 :group
'org-keywords
2196 :type
'(choice (const sequence
)
2199 (defcustom org-use-fast-todo-selection t
2200 "Non-nil means use the fast todo selection scheme with C-c C-t.
2201 This variable describes if and under what circumstances the cycling
2202 mechanism for TODO keywords will be replaced by a single-key, direct
2205 When nil, fast selection is never used.
2207 When the symbol `prefix', it will be used when `org-todo' is called
2208 with a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and
2209 `C-u t' in an agenda buffer.
2211 When t, fast selection is used by default. In this case, the prefix
2212 argument forces cycling instead.
2214 In all cases, the special interface is only used if access keys have
2215 actually been assigned by the user, i.e. if keywords in the configuration
2216 are followed by a letter in parenthesis, like TODO(t)."
2219 (const :tag
"Never" nil
)
2220 (const :tag
"By default" t
)
2221 (const :tag
"Only with C-u C-c C-t" prefix
)))
2223 (defcustom org-provide-todo-statistics t
2224 "Non-nil means update todo statistics after insert and toggle.
2225 ALL-HEADLINES means update todo statistics by including headlines
2226 with no TODO keyword as well, counting them as not done.
2227 A list of TODO keywords means the same, but skip keywords that are
2230 When this is set, todo statistics is updated in the parent of the
2231 current entry each time a todo state is changed."
2234 (const :tag
"Yes, only for TODO entries" t
)
2235 (const :tag
"Yes, including all entries" 'all-headlines
)
2236 (repeat :tag
"Yes, for TODOs in this list"
2237 (string :tag
"TODO keyword"))
2238 (other :tag
"No TODO statistics" nil
)))
2240 (defcustom org-hierarchical-todo-statistics t
2241 "Non-nil means TODO statistics covers just direct children.
2242 When nil, all entries in the subtree are considered.
2243 This has only an effect if `org-provide-todo-statistics' is set.
2244 To set this to nil for only a single subtree, use a COOKIE_DATA
2245 property and include the word \"recursive\" into the value."
2249 (defcustom org-after-todo-state-change-hook nil
2250 "Hook which is run after the state of a TODO item was changed.
2251 The new state (a string with a TODO keyword, or nil) is available in the
2252 Lisp variable `org-state'."
2256 (defvar org-blocker-hook nil
2257 "Hook for functions that are allowed to block a state change.
2259 Each function gets as its single argument a property list, see
2260 `org-trigger-hook' for more information about this list.
2262 If any of the functions in this hook returns nil, the state change
2265 (defvar org-trigger-hook nil
2266 "Hook for functions that are triggered by a state change.
2268 Each function gets as its single argument a property list with at least
2269 the following elements:
2271 (:type type-of-change :position pos-at-entry-start
2272 :from old-state :to new-state)
2274 Depending on the type, more properties may be present.
2276 This mechanism is currently implemented for:
2280 :type todo-state-change
2281 :from previous state (keyword as a string), or nil, or a symbol
2282 'todo' or 'done', to indicate the general type of state.
2283 :to new state, like in :from")
2285 (defcustom org-enforce-todo-dependencies nil
2286 "Non-nil means undone TODO entries will block switching the parent to DONE.
2287 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2288 be blocked if any prior sibling is not yet done.
2289 Finally, if the parent is blocked because of ordered siblings of its own,
2290 the child will also be blocked."
2291 :set
(lambda (var val
)
2294 (add-hook 'org-blocker-hook
2295 'org-block-todo-from-children-or-siblings-or-parent
)
2296 (remove-hook 'org-blocker-hook
2297 'org-block-todo-from-children-or-siblings-or-parent
)))
2301 (defcustom org-enforce-todo-checkbox-dependencies nil
2302 "Non-nil means unchecked boxes will block switching the parent to DONE.
2303 When this is nil, checkboxes have no influence on switching TODO states.
2304 When non-nil, you first need to check off all check boxes before the TODO
2305 entry can be switched to DONE.
2306 This variable needs to be set before org.el is loaded, and you need to
2307 restart Emacs after a change to make the change effective. The only way
2308 to change is while Emacs is running is through the customize interface."
2309 :set
(lambda (var val
)
2312 (add-hook 'org-blocker-hook
2313 'org-block-todo-from-checkboxes
)
2314 (remove-hook 'org-blocker-hook
2315 'org-block-todo-from-checkboxes
)))
2319 (defcustom org-treat-insert-todo-heading-as-state-change nil
2320 "Non-nil means inserting a TODO heading is treated as state change.
2321 So when the command \\[org-insert-todo-heading] is used, state change
2322 logging will apply if appropriate. When nil, the new TODO item will
2323 be inserted directly, and no logging will take place."
2327 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2328 "Non-nil means switching TODO states with S-cursor counts as state change.
2329 This is the default behavior. However, setting this to nil allows a
2330 convenient way to select a TODO state and bypass any logging associated
2335 (defcustom org-todo-state-tags-triggers nil
2336 "Tag changes that should be triggered by TODO state changes.
2337 This is a list. Each entry is
2339 (state-change (tag . flag) .......)
2341 State-change can be a string with a state, and empty string to indicate the
2342 state that has no TODO keyword, or it can be one of the symbols `todo'
2343 or `done', meaning any not-done or done state, respectively."
2347 (cons (choice :tag
"When changing to"
2348 (const :tag
"Not-done state" todo
)
2349 (const :tag
"Done state" done
)
2350 (string :tag
"State"))
2352 (cons :tag
"Tag action"
2354 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2356 (defcustom org-log-done nil
2357 "Information to record when a task moves to the DONE state.
2359 Possible values are:
2361 nil Don't add anything, just change the keyword
2362 time Add a time stamp to the task
2363 note Prompt for a note and add it with template `org-log-note-headings'
2365 This option can also be set with on a per-file-basis with
2367 #+STARTUP: nologdone
2369 #+STARTUP: lognotedone
2371 You can have local logging settings for a subtree by setting the LOGGING
2372 property to one or more of these keywords."
2374 :group
'org-progress
2376 (const :tag
"No logging" nil
)
2377 (const :tag
"Record CLOSED timestamp" time
)
2378 (const :tag
"Record CLOSED timestamp with note." note
)))
2380 ;; Normalize old uses of org-log-done.
2382 ((eq org-log-done t
) (setq org-log-done
'time
))
2383 ((and (listp org-log-done
) (memq 'done org-log-done
))
2384 (setq org-log-done
'note
)))
2386 (defcustom org-log-reschedule nil
2387 "Information to record when the scheduling date of a tasks is modified.
2389 Possible values are:
2391 nil Don't add anything, just change the date
2392 time Add a time stamp to the task
2393 note Prompt for a note and add it with template `org-log-note-headings'
2395 This option can also be set with on a per-file-basis with
2397 #+STARTUP: nologreschedule
2398 #+STARTUP: logreschedule
2399 #+STARTUP: lognotereschedule"
2401 :group
'org-progress
2403 (const :tag
"No logging" nil
)
2404 (const :tag
"Record timestamp" time
)
2405 (const :tag
"Record timestamp with note." note
)))
2407 (defcustom org-log-redeadline nil
2408 "Information to record when the deadline date of a tasks is modified.
2410 Possible values are:
2412 nil Don't add anything, just change the date
2413 time Add a time stamp to the task
2414 note Prompt for a note and add it with template `org-log-note-headings'
2416 This option can also be set with on a per-file-basis with
2418 #+STARTUP: nologredeadline
2419 #+STARTUP: logredeadline
2420 #+STARTUP: lognoteredeadline
2422 You can have local logging settings for a subtree by setting the LOGGING
2423 property to one or more of these keywords."
2425 :group
'org-progress
2427 (const :tag
"No logging" nil
)
2428 (const :tag
"Record timestamp" time
)
2429 (const :tag
"Record timestamp with note." note
)))
2431 (defcustom org-log-note-clock-out nil
2432 "Non-nil means record a note when clocking out of an item.
2433 This can also be configured on a per-file basis by adding one of
2434 the following lines anywhere in the buffer:
2436 #+STARTUP: lognoteclock-out
2437 #+STARTUP: nolognoteclock-out"
2439 :group
'org-progress
2442 (defcustom org-log-done-with-time t
2443 "Non-nil means the CLOSED time stamp will contain date and time.
2444 When nil, only the date will be recorded."
2445 :group
'org-progress
2448 (defcustom org-log-note-headings
2449 '((done .
"CLOSING NOTE %t")
2450 (state .
"State %-12s from %-12S %t")
2451 (note .
"Note taken on %t")
2452 (reschedule .
"Rescheduled from %S on %t")
2453 (delschedule .
"Not scheduled, was %S on %t")
2454 (redeadline .
"New deadline from %S on %t")
2455 (deldeadline .
"Removed deadline, was %S on %t")
2456 (refile .
"Refiled on %t")
2458 "Headings for notes added to entries.
2459 The value is an alist, with the car being a symbol indicating the note
2460 context, and the cdr is the heading to be used. The heading may also be the
2462 %t in the heading will be replaced by a time stamp.
2463 %T will be an active time stamp instead the default inactive one
2464 %d will be replaced by a short-format time stamp.
2465 %D will be replaced by an active short-format time stamp.
2466 %s will be replaced by the new TODO state, in double quotes.
2467 %S will be replaced by the old TODO state, in double quotes.
2468 %u will be replaced by the user name.
2469 %U will be replaced by the full user name.
2471 In fact, it is not a good idea to change the `state' entry, because
2472 agenda log mode depends on the format of these entries."
2474 :group
'org-progress
2475 :type
'(list :greedy t
2476 (cons (const :tag
"Heading when closing an item" done
) string
)
2478 "Heading when changing todo state (todo sequence only)"
2480 (cons (const :tag
"Heading when just taking a note" note
) string
)
2481 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2482 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2483 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2484 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2485 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2486 (cons (const :tag
"Heading when refiling" refile
) string
)))
2488 (unless (assq 'note org-log-note-headings
)
2489 (push '(note .
"%t") org-log-note-headings
))
2491 (defcustom org-log-into-drawer nil
2492 "Non-nil means insert state change notes and time stamps into a drawer.
2493 When nil, state changes notes will be inserted after the headline and
2494 any scheduling and clock lines, but not inside a drawer.
2496 The value of this variable should be the name of the drawer to use.
2497 LOGBOOK is proposed as the default drawer for this purpose, you can
2498 also set this to a string to define the drawer of your choice.
2500 A value of t is also allowed, representing \"LOGBOOK\".
2502 If this variable is set, `org-log-state-notes-insert-after-drawers'
2505 You can set the property LOG_INTO_DRAWER to overrule this setting for
2508 :group
'org-progress
2510 (const :tag
"Not into a drawer" nil
)
2511 (const :tag
"LOGBOOK" t
)
2512 (string :tag
"Other")))
2514 (if (fboundp 'defvaralias
)
2515 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2517 (defun org-log-into-drawer ()
2518 "Return the value of `org-log-into-drawer', but let properties overrule.
2519 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2520 used instead of the default value."
2521 (let ((p (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit
)))
2523 ((or (not p
) (equal p
"nil")) org-log-into-drawer
)
2524 ((equal p
"t") "LOGBOOK")
2527 (defcustom org-log-state-notes-insert-after-drawers nil
2528 "Non-nil means insert state change notes after any drawers in entry.
2529 Only the drawers that *immediately* follow the headline and the
2530 deadline/scheduled line are skipped.
2531 When nil, insert notes right after the heading and perhaps the line
2532 with deadline/scheduling if present.
2534 This variable will have no effect if `org-log-into-drawer' is
2537 :group
'org-progress
2540 (defcustom org-log-states-order-reversed t
2541 "Non-nil means the latest state note will be directly after heading.
2542 When nil, the state change notes will be ordered according to time."
2544 :group
'org-progress
2547 (defcustom org-todo-repeat-to-state nil
2548 "The TODO state to which a repeater should return the repeating task.
2549 By default this is the first task in a TODO sequence, or the previous state
2550 in a TODO_TYP set. But you can specify another task here.
2551 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2554 :type
'(choice (const :tag
"Head of sequence" nil
)
2555 (string :tag
"Specific state")))
2557 (defcustom org-log-repeat
'time
2558 "Non-nil means record moving through the DONE state when triggering repeat.
2559 An auto-repeating task is immediately switched back to TODO when
2560 marked DONE. If you are not logging state changes (by adding \"@\"
2561 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2562 record a closing note, there will be no record of the task moving
2563 through DONE. This variable forces taking a note anyway.
2565 nil Don't force a record
2566 time Record a time stamp
2567 note Prompt for a note and add it with template `org-log-note-headings'
2569 This option can also be set with on a per-file-basis with
2571 #+STARTUP: nologrepeat
2572 #+STARTUP: logrepeat
2573 #+STARTUP: lognoterepeat
2575 You can have local logging settings for a subtree by setting the LOGGING
2576 property to one or more of these keywords."
2578 :group
'org-progress
2580 (const :tag
"Don't force a record" nil
)
2581 (const :tag
"Force recording the DONE state" time
)
2582 (const :tag
"Force recording a note with the DONE state" note
)))
2585 (defgroup org-priorities nil
2586 "Priorities in Org-mode."
2587 :tag
"Org Priorities"
2590 (defcustom org-enable-priority-commands t
2591 "Non-nil means priority commands are active.
2592 When nil, these commands will be disabled, so that you never accidentally
2594 :group
'org-priorities
2597 (defcustom org-highest-priority ?A
2598 "The highest priority of TODO items. A character like ?A, ?B etc.
2599 Must have a smaller ASCII number than `org-lowest-priority'."
2600 :group
'org-priorities
2603 (defcustom org-lowest-priority ?C
2604 "The lowest priority of TODO items. A character like ?A, ?B etc.
2605 Must have a larger ASCII number than `org-highest-priority'."
2606 :group
'org-priorities
2609 (defcustom org-default-priority ?B
2610 "The default priority of TODO items.
2611 This is the priority an item gets if no explicit priority is given.
2612 When starting to cycle on an empty priority the first step in the cycle
2613 depends on `org-priority-start-cycle-with-default'. The resulting first
2614 step priority must not exceed the range from `org-highest-priority' to
2615 `org-lowest-priority' which means that `org-default-priority' has to be
2616 in this range exclusive or inclusive the range boundaries. Else the
2617 first step refuses to set the default and the second will fall back
2618 to (depending on the command used) the highest or lowest priority."
2619 :group
'org-priorities
2622 (defcustom org-priority-start-cycle-with-default t
2623 "Non-nil means start with default priority when starting to cycle.
2624 When this is nil, the first step in the cycle will be (depending on the
2625 command used) one higher or lower than the default priority.
2626 See also `org-default-priority'."
2627 :group
'org-priorities
2630 (defcustom org-get-priority-function nil
2631 "Function to extract the priority from a string.
2632 The string is normally the headline. If this is nil Org computes the
2633 priority from the priority cookie like [#A] in the headline. It returns
2634 an integer, increasing by 1000 for each priority level.
2635 The user can set a different function here, which should take a string
2636 as an argument and return the numeric priority."
2637 :group
'org-priorities
2641 (defgroup org-time nil
2642 "Options concerning time stamps and deadlines in Org-mode."
2646 (defcustom org-insert-labeled-timestamps-at-point nil
2647 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2648 When nil, these labeled time stamps are forces into the second line of an
2649 entry, just after the headline. When scheduling from the global TODO list,
2650 the time stamp will always be forced into the second line."
2654 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2655 "Formats for `format-time-string' which are used for time stamps.
2656 It is not recommended to change this constant.")
2658 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2659 "Number of minutes to round time stamps to.
2660 These are two values, the first applies when first creating a time stamp.
2661 The second applies when changing it with the commands `S-up' and `S-down'.
2662 When changing the time stamp, this means that it will change in steps
2663 of N minutes, as given by the second value.
2665 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2666 numbers should be factors of 60, so for example 5, 10, 15.
2668 When this is larger than 1, you can still force an exact time stamp by using
2669 a double prefix argument to a time stamp command like `C-c .' or `C-c !',
2670 and by using a prefix arg to `S-up/down' to specify the exact number
2671 of minutes to shift."
2673 :get
#'(lambda (var) ; Make sure both elements are there
2674 (if (integerp (default-value var
))
2675 (list (default-value var
) 5)
2676 (default-value var
)))
2678 (integer :tag
"when inserting times")
2679 (integer :tag
"when modifying times")))
2681 ;; Normalize old customizations of this variable.
2682 (when (integerp org-time-stamp-rounding-minutes
)
2683 (setq org-time-stamp-rounding-minutes
2684 (list org-time-stamp-rounding-minutes
2685 org-time-stamp-rounding-minutes
)))
2687 (defcustom org-display-custom-times nil
2688 "Non-nil means overlay custom formats over all time stamps.
2689 The formats are defined through the variable `org-time-stamp-custom-formats'.
2690 To turn this on on a per-file basis, insert anywhere in the file:
2691 #+STARTUP: customtime"
2695 (make-variable-buffer-local 'org-display-custom-times
)
2697 (defcustom org-time-stamp-custom-formats
2698 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2699 "Custom formats for time stamps. See `format-time-string' for the syntax.
2700 These are overlaid over the default ISO format if the variable
2701 `org-display-custom-times' is set. Time like %H:%M should be at the
2702 end of the second format. The custom formats are also honored by export
2703 commands, if custom time display is turned on at the time of export."
2707 (defun org-time-stamp-format (&optional long inactive
)
2708 "Get the right format for a time string."
2709 (let ((f (if long
(cdr org-time-stamp-formats
)
2710 (car org-time-stamp-formats
))))
2712 (concat "[" (substring f
1 -
1) "]")
2715 (defcustom org-time-clocksum-format
"%d:%02d"
2716 "The format string used when creating CLOCKSUM lines.
2717 This is also used when org-mode generates a time duration."
2721 (defcustom org-time-clocksum-use-fractional nil
2722 "If non-nil, \\[org-clock-display] uses fractional times.
2723 org-mode generates a time duration."
2727 (defcustom org-time-clocksum-fractional-format
"%.2f"
2728 "The format string used when creating CLOCKSUM lines, or when
2729 org-mode generates a time duration."
2733 (defcustom org-deadline-warning-days
14
2734 "No. of days before expiration during which a deadline becomes active.
2735 This variable governs the display in sparse trees and in the agenda.
2736 When 0 or negative, it means use this number (the absolute value of it)
2737 even if a deadline has a different individual lead time specified.
2739 Custom commands can set this variable in the options section."
2741 :group
'org-agenda-daily
/weekly
2744 (defcustom org-read-date-prefer-future t
2745 "Non-nil means assume future for incomplete date input from user.
2746 This affects the following situations:
2747 1. The user gives a month but not a year.
2748 For example, if it is April and you enter \"feb 2\", this will be read
2749 as Feb 2, *next* year. \"May 5\", however, will be this year.
2750 2. The user gives a day, but no month.
2751 For example, if today is the 15th, and you enter \"3\", Org-mode will
2752 read this as the third of *next* month. However, if you enter \"17\",
2753 it will be considered as *this* month.
2755 If you set this variable to the symbol `time', then also the following
2758 3. If the user gives a time.
2759 If the time is before now, it will be interpreted as tomorrow.
2761 Currently none of this works for ISO week specifications.
2763 When this option is nil, the current day, month and year will always be
2766 See also `org-agenda-jump-prefer-future'."
2769 (const :tag
"Never" nil
)
2770 (const :tag
"Check month and day" t
)
2771 (const :tag
"Check month, day, and time" time
)))
2773 (defcustom org-agenda-jump-prefer-future
'org-read-date-prefer-future
2774 "Should the agenda jump command prefer the future for incomplete dates?
2775 The default is to do the same as configured in `org-read-date-prefer-future'.
2776 But you can also set a deviating value here.
2777 This may t or nil, or the symbol `org-read-date-prefer-future'."
2782 (const :tag
"Use org-read-date-prefer-future"
2783 org-read-date-prefer-future
)
2784 (const :tag
"Never" nil
)
2785 (const :tag
"Always" t
)))
2787 (defcustom org-read-date-force-compatible-dates t
2788 "Should date/time prompt force dates that are guaranteed to work in Emacs?
2790 Depending on the system Emacs is running on, certain dates cannot
2791 be represented with the type used internally to represent time.
2792 Dates between 1970-1-1 and 2038-1-1 can always be represented
2793 correctly. Some systems allow for earlier dates, some for later,
2794 some for both. One way to find out it to insert any date into an
2795 Org buffer, putting the cursor on the year and hitting S-up and
2796 S-down to test the range.
2798 When this variable is set to t, the date/time prompt will not let
2799 you specify dates outside the 1970-2037 range, so it is certain that
2800 these dates will work in whatever version of Emacs you are
2801 running, and also that you can move a file from one Emacs implementation
2802 to another. WHenever Org is forcing the year for you, it will display
2805 When this variable is nil, Org will check if the date is
2806 representable in the specific Emacs implementation you are using.
2807 If not, it will force a year, usually the current year, and beep
2808 to remind you. Currently this setting is not recommended because
2809 the likelihood that you will open your Org files in an Emacs that
2810 has limited date range is not negligible.
2812 A workaround for this problem is to use diary sexp dates for time
2813 stamps outside of this range."
2818 (defcustom org-read-date-display-live t
2819 "Non-nil means display current interpretation of date prompt live.
2820 This display will be in an overlay, in the minibuffer."
2824 (defcustom org-read-date-popup-calendar t
2825 "Non-nil means pop up a calendar when prompting for a date.
2826 In the calendar, the date can be selected with mouse-1. However, the
2827 minibuffer will also be active, and you can simply enter the date as well.
2828 When nil, only the minibuffer will be available."
2831 (if (fboundp 'defvaralias
)
2832 (defvaralias 'org-popup-calendar-for-date-prompt
2833 'org-read-date-popup-calendar
))
2835 (defcustom org-read-date-minibuffer-setup-hook nil
2836 "Hook to be used to set up keys for the date/time interface.
2837 Add key definitions to `minibuffer-local-map', which will be a temporary
2842 (defcustom org-extend-today-until
0
2843 "The hour when your day really ends. Must be an integer.
2844 This has influence for the following applications:
2845 - When switching the agenda to \"today\". It it is still earlier than
2846 the time given here, the day recognized as TODAY is actually yesterday.
2847 - When a date is read from the user and it is still before the time given
2848 here, the current date and time will be assumed to be yesterday, 23:59.
2849 Also, timestamps inserted in remember templates follow this rule.
2851 IMPORTANT: This is a feature whose implementation is and likely will
2852 remain incomplete. Really, it is only here because past midnight seems to
2853 be the favorite working time of John Wiegley :-)"
2857 (defcustom org-use-effective-time nil
2858 "If non-nil, consider `org-extend-today-until' when creating timestamps.
2859 For example, if `org-extend-today-until' is 8, and it's 4am, then the
2860 \"effective time\" of any timestamps between midnight and 8am will be
2861 23:59 of the previous day."
2866 (defcustom org-edit-timestamp-down-means-later nil
2867 "Non-nil means S-down will increase the time in a time stamp.
2868 When nil, S-up will increase."
2872 (defcustom org-calendar-follow-timestamp-change t
2873 "Non-nil means make the calendar window follow timestamp changes.
2874 When a timestamp is modified and the calendar window is visible, it will be
2875 moved to the new date."
2879 (defgroup org-tags nil
2880 "Options concerning tags in Org-mode."
2884 (defcustom org-tag-alist nil
2885 "List of tags allowed in Org-mode files.
2886 When this list is nil, Org-mode will base TAG input on what is already in the
2888 The value of this variable is an alist, the car of each entry must be a
2889 keyword as a string, the cdr may be a character that is used to select
2890 that tag through the fast-tag-selection interface.
2891 See the manual for details."
2895 (cons (string :tag
"Tag name")
2896 (character :tag
"Access char"))
2897 (list :tag
"Start radio group"
2899 (option (string :tag
"Group description")))
2900 (list :tag
"End radio group"
2902 (option (string :tag
"Group description")))
2903 (const :tag
"New line" (:newline
)))))
2905 (defcustom org-tag-persistent-alist nil
2906 "List of tags that will always appear in all Org-mode files.
2907 This is in addition to any in buffer settings or customizations
2909 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
2910 The value of this variable is an alist, the car of each entry must be a
2911 keyword as a string, the cdr may be a character that is used to select
2912 that tag through the fast-tag-selection interface.
2913 See the manual for details.
2914 To disable these tags on a per-file basis, insert anywhere in the file:
2919 (cons (string :tag
"Tag name")
2920 (character :tag
"Access char"))
2921 (const :tag
"Start radio group" (:startgroup
))
2922 (const :tag
"End radio group" (:endgroup
))
2923 (const :tag
"New line" (:newline
)))))
2925 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
2926 "If non-nil, always offer completion for all tags of all agenda files.
2927 Instead of customizing this variable directly, you might want to
2928 set it locally for capture buffers, because there no list of
2929 tags in that file can be created dynamically (there are none).
2931 (add-hook 'org-capture-mode-hook
2933 (set (make-local-variable
2934 'org-complete-tags-always-offer-all-agenda-tags)
2940 (defvar org-file-tags nil
2941 "List of tags that can be inherited by all entries in the file.
2942 The tags will be inherited if the variable `org-use-tag-inheritance'
2943 says they should be.
2944 This variable is populated from #+FILETAGS lines.")
2946 (defcustom org-use-fast-tag-selection
'auto
2947 "Non-nil means use fast tag selection scheme.
2948 This is a special interface to select and deselect tags with single keys.
2949 When nil, fast selection is never used.
2950 When the symbol `auto', fast selection is used if and only if selection
2951 characters for tags have been configured, either through the variable
2952 `org-tag-alist' or through a #+TAGS line in the buffer.
2953 When t, fast selection is always used and selection keys are assigned
2954 automatically if necessary."
2957 (const :tag
"Always" t
)
2958 (const :tag
"Never" nil
)
2959 (const :tag
"When selection characters are configured" 'auto
)))
2961 (defcustom org-fast-tag-selection-single-key nil
2962 "Non-nil means fast tag selection exits after first change.
2963 When nil, you have to press RET to exit it.
2964 During fast tag selection, you can toggle this flag with `C-c'.
2965 This variable can also have the value `expert'. In this case, the window
2966 displaying the tags menu is not even shown, until you press C-c again."
2969 (const :tag
"No" nil
)
2970 (const :tag
"Yes" t
)
2971 (const :tag
"Expert" expert
)))
2973 (defvar org-fast-tag-selection-include-todo nil
2974 "Non-nil means fast tags selection interface will also offer TODO states.
2975 This is an undocumented feature, you should not rely on it.")
2977 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
2978 "The column to which tags should be indented in a headline.
2979 If this number is positive, it specifies the column. If it is negative,
2980 it means that the tags should be flushright to that column. For example,
2981 -80 works well for a normal 80 character screen.
2982 When 0, place tags directly after headline text, with only one space in
2987 (defcustom org-auto-align-tags t
2988 "Non-nil keeps tags aligned when modifying headlines.
2989 Some operations (i.e. demoting) change the length of a headline and
2990 therefore shift the tags around. With this option turned on, after
2991 each such operation the tags are again aligned to `org-tags-column'."
2995 (defcustom org-use-tag-inheritance t
2996 "Non-nil means tags in levels apply also for sublevels.
2997 When nil, only the tags directly given in a specific line apply there.
2998 This may also be a list of tags that should be inherited, or a regexp that
2999 matches tags that should be inherited. Additional control is possible
3000 with the variable `org-tags-exclude-from-inheritance' which gives an
3001 explicit list of tags to be excluded from inheritance., even if the value of
3002 `org-use-tag-inheritance' would select it for inheritance.
3004 If this option is t, a match early-on in a tree can lead to a large
3005 number of matches in the subtree when constructing the agenda or creating
3006 a sparse tree. If you only want to see the first match in a tree during
3007 a search, check out the variable `org-tags-match-list-sublevels'."
3010 (const :tag
"Not" nil
)
3011 (const :tag
"Always" t
)
3012 (repeat :tag
"Specific tags" (string :tag
"Tag"))
3013 (regexp :tag
"Tags matched by regexp")))
3015 (defcustom org-tags-exclude-from-inheritance nil
3016 "List of tags that should never be inherited.
3017 This is a way to exclude a few tags from inheritance. For way to do
3018 the opposite, to actively allow inheritance for selected tags,
3019 see the variable `org-use-tag-inheritance'."
3021 :type
'(repeat (string :tag
"Tag")))
3023 (defun org-tag-inherit-p (tag)
3024 "Check if TAG is one that should be inherited."
3026 ((member tag org-tags-exclude-from-inheritance
) nil
)
3027 ((eq org-use-tag-inheritance t
) t
)
3028 ((not org-use-tag-inheritance
) nil
)
3029 ((stringp org-use-tag-inheritance
)
3030 (string-match org-use-tag-inheritance tag
))
3031 ((listp org-use-tag-inheritance
)
3032 (member tag org-use-tag-inheritance
))
3033 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
3035 (defcustom org-tags-match-list-sublevels t
3036 "Non-nil means list also sublevels of headlines matching a search.
3037 This variable applies to tags/property searches, and also to stuck
3038 projects because this search is based on a tags match as well.
3040 When set to the symbol `indented', sublevels are indented with
3043 Because of tag inheritance (see variable `org-use-tag-inheritance'),
3044 the sublevels of a headline matching a tag search often also match
3045 the same search. Listing all of them can create very long lists.
3046 Setting this variable to nil causes subtrees of a match to be skipped.
3048 This variable is semi-obsolete and probably should always be true. It
3049 is better to limit inheritance to certain tags using the variables
3050 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
3053 (const :tag
"No, don't list them" nil
)
3054 (const :tag
"Yes, do list them" t
)
3055 (const :tag
"List them, indented with leading dots" indented
)))
3057 (defcustom org-tags-sort-function nil
3058 "When set, tags are sorted using this function as a comparator."
3061 (const :tag
"No sorting" nil
)
3062 (const :tag
"Alphabetical" string
<)
3063 (const :tag
"Reverse alphabetical" string
>)
3064 (function :tag
"Custom function" nil
)))
3066 (defvar org-tags-history nil
3067 "History of minibuffer reads for tags.")
3068 (defvar org-last-tags-completion-table nil
3069 "The last used completion table for tags.")
3070 (defvar org-after-tags-change-hook nil
3071 "Hook that is run after the tags in a line have changed.")
3073 (defgroup org-properties nil
3074 "Options concerning properties in Org-mode."
3075 :tag
"Org Properties"
3078 (defcustom org-property-format
"%-10s %s"
3079 "How property key/value pairs should be formatted by `indent-line'.
3080 When `indent-line' hits a property definition, it will format the line
3081 according to this format, mainly to make sure that the values are
3082 lined-up with respect to each other."
3083 :group
'org-properties
3086 (defcustom org-properties-postprocess-alist nil
3087 "Alist of properties and functions to adjust inserted values.
3088 Elements of this alist must be of the form
3090 ([string] [function])
3092 where [string] must be a property name and [function] must be a
3093 lambda expression: this lambda expression must take one argument,
3094 the value to adjust, and return the new value as a string.
3096 For example, this element will allow the property \"Remaining\"
3097 to be updated wrt the relation between the \"Effort\" property
3098 and the clock summary:
3100 ((\"Remaining\" (lambda(value)
3101 (let ((clocksum (org-clock-sum-current-item))
3102 (effort (org-duration-string-to-minutes
3103 (org-entry-get (point) \"Effort\"))))
3104 (org-minutes-to-hh:mm-string (- effort clocksum))))))"
3105 :group
'org-properties
3107 :type
'(alist :key-type
(string :tag
"Property")
3108 :value-type
(function :tag
"Function")))
3110 (defcustom org-use-property-inheritance nil
3111 "Non-nil means properties apply also for sublevels.
3113 This setting is chiefly used during property searches. Turning it on can
3114 cause significant overhead when doing a search, which is why it is not
3117 When nil, only the properties directly given in the current entry count.
3118 When t, every property is inherited. The value may also be a list of
3119 properties that should have inheritance, or a regular expression matching
3120 properties that should be inherited.
3122 However, note that some special properties use inheritance under special
3123 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
3124 and the properties ending in \"_ALL\" when they are used as descriptor
3125 for valid values of a property.
3127 Note for programmers:
3128 When querying an entry with `org-entry-get', you can control if inheritance
3129 should be used. By default, `org-entry-get' looks only at the local
3130 properties. You can request inheritance by setting the inherit argument
3131 to t (to force inheritance) or to `selective' (to respect the setting
3133 :group
'org-properties
3135 (const :tag
"Not" nil
)
3136 (const :tag
"Always" t
)
3137 (repeat :tag
"Specific properties" (string :tag
"Property"))
3138 (regexp :tag
"Properties matched by regexp")))
3140 (defun org-property-inherit-p (property)
3141 "Check if PROPERTY is one that should be inherited."
3143 ((eq org-use-property-inheritance t
) t
)
3144 ((not org-use-property-inheritance
) nil
)
3145 ((stringp org-use-property-inheritance
)
3146 (string-match org-use-property-inheritance property
))
3147 ((listp org-use-property-inheritance
)
3148 (member property org-use-property-inheritance
))
3149 (t (error "Invalid setting of `org-use-property-inheritance'"))))
3151 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
3152 "The default column format, if no other format has been defined.
3153 This variable can be set on the per-file basis by inserting a line
3155 #+COLUMNS: %25ITEM ....."
3156 :group
'org-properties
3159 (defcustom org-columns-ellipses
".."
3160 "The ellipses to be used when a field in column view is truncated.
3161 When this is the empty string, as many characters as possible are shown,
3162 but then there will be no visual indication that the field has been truncated.
3163 When this is a string of length N, the last N characters of a truncated
3164 field are replaced by this string. If the column is narrower than the
3165 ellipses string, only part of the ellipses string will be shown."
3166 :group
'org-properties
3169 (defcustom org-columns-modify-value-for-display-function nil
3170 "Function that modifies values for display in column view.
3171 For example, it can be used to cut out a certain part from a time stamp.
3172 The function must take 2 arguments:
3174 column-title The title of the column (*not* the property name)
3175 value The value that should be modified.
3177 The function should return the value that should be displayed,
3178 or nil if the normal value should be used."
3179 :group
'org-properties
3182 (defcustom org-effort-property
"Effort"
3183 "The property that is being used to keep track of effort estimates.
3184 Effort estimates given in this property need to have the format H:MM."
3185 :group
'org-properties
3186 :group
'org-progress
3187 :type
'(string :tag
"Property"))
3189 (defconst org-global-properties-fixed
3190 '(("VISIBILITY_ALL" .
"folded children content all")
3191 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
3192 "List of property/value pairs that can be inherited by any entry.
3194 These are fixed values, for the preset properties. The user variable
3195 that can be used to add to this list is `org-global-properties'.
3197 The entries in this list are cons cells where the car is a property
3198 name and cdr is a string with the value. If the value represents
3199 multiple items like an \"_ALL\" property, separate the items by
3202 (defcustom org-global-properties nil
3203 "List of property/value pairs that can be inherited by any entry.
3205 This list will be combined with the constant `org-global-properties-fixed'.
3207 The entries in this list are cons cells where the car is a property
3208 name and cdr is a string with the value.
3210 You can set buffer-local values for the same purpose in the variable
3211 `org-file-properties' this by adding lines like
3213 #+PROPERTY: NAME VALUE"
3214 :group
'org-properties
3216 (cons (string :tag
"Property")
3217 (string :tag
"Value"))))
3219 (defvar org-file-properties nil
3220 "List of property/value pairs that can be inherited by any entry.
3221 Valid for the current buffer.
3222 This variable is populated from #+PROPERTY lines.")
3223 (make-variable-buffer-local 'org-file-properties
)
3225 (defgroup org-agenda nil
3226 "Options concerning agenda views in Org-mode."
3230 (defvar org-category nil
3231 "Variable used by org files to set a category for agenda display.
3232 Such files should use a file variable to set it, for example
3234 # -*- mode: org; org-category: \"ELisp\"
3236 or contain a special line
3240 If the file does not specify a category, then file's base name
3242 (make-variable-buffer-local 'org-category
)
3243 (put 'org-category
'safe-local-variable
#'(lambda (x) (or (symbolp x
) (stringp x
))))
3245 (defcustom org-agenda-files nil
3246 "The files to be used for agenda display.
3247 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
3248 \\[org-remove-file]. You can also use customize to edit the list.
3250 If an entry is a directory, all files in that directory that are matched by
3251 `org-agenda-file-regexp' will be part of the file list.
3253 If the value of the variable is not a list but a single file name, then
3254 the list of agenda files is actually stored and maintained in that file, one
3255 agenda file per line. In this file paths can be given relative to
3256 `org-directory'. Tilde expansion and environment variable substitution
3260 (repeat :tag
"List of files and directories" file
)
3261 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
3263 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
3264 "Regular expression to match files for `org-agenda-files'.
3265 If any element in the list in that variable contains a directory instead
3266 of a normal file, all files in that directory that are matched by this
3267 regular expression will be included."
3271 (defcustom org-agenda-text-search-extra-files nil
3272 "List of extra files to be searched by text search commands.
3273 These files will be search in addition to the agenda files by the
3274 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
3275 Note that these files will only be searched for text search commands,
3276 not for the other agenda views like todo lists, tag searches or the weekly
3277 agenda. This variable is intended to list notes and possibly archive files
3278 that should also be searched by these two commands.
3279 In fact, if the first element in the list is the symbol `agenda-archives',
3280 than all archive files of all agenda files will be added to the search
3283 :type
'(set :greedy t
3284 (const :tag
"Agenda Archives" agenda-archives
)
3285 (repeat :inline t
(file))))
3287 (if (fboundp 'defvaralias
)
3288 (defvaralias 'org-agenda-multi-occur-extra-files
3289 'org-agenda-text-search-extra-files
))
3291 (defcustom org-agenda-skip-unavailable-files nil
3292 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
3293 A nil value means to remove them, after a query, from the list."
3297 (defcustom org-calendar-to-agenda-key
[?c
]
3298 "The key to be installed in `calendar-mode-map' for switching to the agenda.
3299 The command `org-calendar-goto-agenda' will be bound to this key. The
3300 default is the character `c' because then `c' can be used to switch back and
3301 forth between agenda and calendar."
3305 (defcustom org-calendar-agenda-action-key
[?k
]
3306 "The key to be installed in `calendar-mode-map' for agenda-action.
3307 The command `org-agenda-action' will be bound to this key. The
3308 default is the character `k' because we use the same key in the agenda."
3312 (defcustom org-calendar-insert-diary-entry-key
[?i
]
3313 "The key to be installed in `calendar-mode-map' for adding diary entries.
3314 This option is irrelevant until `org-agenda-diary-file' has been configured
3315 to point to an Org-mode file. When that is the case, the command
3316 `org-agenda-diary-entry' will be bound to the key given here, by default
3317 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
3318 if you want to continue doing this, you need to change this to a different
3323 (defcustom org-agenda-diary-file
'diary-file
3324 "File to which to add new entries with the `i' key in agenda and calendar.
3325 When this is the symbol `diary-file', the functionality in the Emacs
3326 calendar will be used to add entries to the `diary-file'. But when this
3327 points to a file, `org-agenda-diary-entry' will be used instead."
3330 (const :tag
"The standard Emacs diary file" diary-file
)
3331 (file :tag
"Special Org file diary entries")))
3333 (eval-after-load "calendar"
3335 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3336 'org-calendar-goto-agenda
)
3337 (org-defkey calendar-mode-map org-calendar-agenda-action-key
3339 (add-hook 'calendar-mode-hook
3341 (unless (eq org-agenda-diary-file
'diary-file
)
3342 (define-key calendar-mode-map
3343 org-calendar-insert-diary-entry-key
3344 'org-agenda-diary-entry
))))))
3346 (defgroup org-latex nil
3347 "Options for embedding LaTeX code into Org-mode."
3351 (defcustom org-format-latex-options
3352 '(:foreground default
:background default
:scale
1.0
3353 :html-foreground
"Black" :html-background
"Transparent"
3354 :html-scale
1.0 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3355 "Options for creating images from LaTeX fragments.
3356 This is a property list with the following properties:
3357 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3358 `default' means use the foreground of the default face.
3359 :background the background color, or \"Transparent\".
3360 `default' means use the background of the default face.
3361 :scale a scaling factor for the size of the images, to get more pixels
3362 :html-foreground, :html-background, :html-scale
3363 the same numbers for HTML export.
3364 :matchers a list indicating which matchers should be used to
3365 find LaTeX fragments. Valid members of this list are:
3366 \"begin\" find environments
3367 \"$1\" find single characters surrounded by $.$
3368 \"$\" find math expressions surrounded by $...$
3369 \"$$\" find math expressions surrounded by $$....$$
3370 \"\\(\" find math expressions surrounded by \\(...\\)
3371 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3375 (defcustom org-format-latex-signal-error t
3376 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3377 When nil, just push out a message."
3382 (defcustom org-latex-to-mathml-jar-file nil
3383 "Value of\"%j\" in `org-latex-to-mathml-convert-command'.
3384 Use this to specify additional executable file say a jar file.
3386 When using MathToWeb as the converter, specify the full-path to
3387 your mathtoweb.jar file."
3391 (const :tag
"None" nil
)
3392 (file :tag
"JAR file" :must-match t
)))
3394 (defcustom org-latex-to-mathml-convert-command nil
3395 "Command to convert LaTeX fragments to MathML.
3396 Replace format-specifiers in the command as noted below and use
3397 `shell-command' to convert LaTeX to MathML.
3398 %j: Executable file in fully expanded form as specified by
3399 `org-latex-to-mathml-jar-file'.
3400 %I: Input LaTeX file in fully expanded form
3401 %o: Output MathML file
3402 This command is used by `org-create-math-formula'.
3404 When using MathToWeb as the converter, set this to
3405 \"java -jar %j -unicode -force -df %o %I\"."
3409 (const :tag
"None" nil
)
3410 (string :tag
"\nShell command")))
3412 (defcustom org-latex-create-formula-image-program
'dvipng
3413 "Program to convert LaTeX fragments with.
3415 dvipng Process the LaTeX fragments to dvi file, then convert
3416 dvi files to png files using dvipng.
3417 This will also include processing of non-math environments.
3418 imagemagick Convert the LaTeX fragments to pdf files and use imagemagick
3419 to convert pdf files to png files"
3423 (const :tag
"dvipng" dvipng
)
3424 (const :tag
"imagemagick" imagemagick
)))
3426 (defcustom org-latex-preview-ltxpng-directory
"ltxpng/"
3427 "Path to store latex preview images. A relative path here creates many
3428 directories relative to the processed org files paths. An absolute path
3429 puts all preview images at the same place."
3434 (defun org-format-latex-mathml-available-p ()
3435 "Return t if `org-latex-to-mathml-convert-command' is usable."
3437 (when (and (boundp 'org-latex-to-mathml-convert-command
)
3438 org-latex-to-mathml-convert-command
)
3439 (let ((executable (car (split-string
3440 org-latex-to-mathml-convert-command
))))
3441 (when (executable-find executable
)
3443 "%j" org-latex-to-mathml-convert-command
)
3444 (file-readable-p org-latex-to-mathml-jar-file
)
3447 (defcustom org-format-latex-header
"\\documentclass{article}
3448 \\usepackage[usenames]{color}
3449 \\usepackage{amsmath}
3450 \\usepackage[mathscr]{eucal}
3451 \\pagestyle{empty} % do not remove
3454 % The settings below are copied from fullpage.sty
3455 \\setlength{\\textwidth}{\\paperwidth}
3456 \\addtolength{\\textwidth}{-3cm}
3457 \\setlength{\\oddsidemargin}{1.5cm}
3458 \\addtolength{\\oddsidemargin}{-2.54cm}
3459 \\setlength{\\evensidemargin}{\\oddsidemargin}
3460 \\setlength{\\textheight}{\\paperheight}
3461 \\addtolength{\\textheight}{-\\headheight}
3462 \\addtolength{\\textheight}{-\\headsep}
3463 \\addtolength{\\textheight}{-\\footskip}
3464 \\addtolength{\\textheight}{-3cm}
3465 \\setlength{\\topmargin}{1.5cm}
3466 \\addtolength{\\topmargin}{-2.54cm}"
3467 "The document header used for processing LaTeX fragments.
3468 It is imperative that this header make sure that no page number
3469 appears on the page. The package defined in the variables
3470 `org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
3471 will either replace the placeholder \"[PACKAGES]\" in this header, or they
3476 (defvar org-format-latex-header-extra nil
)
3478 (defun org-set-packages-alist (var val
)
3479 "Set the packages alist and make sure it has 3 elements per entry."
3480 (set var
(mapcar (lambda (x)
3481 (if (and (consp x
) (= (length x
) 2))
3482 (list (car x
) (nth 1 x
) t
)
3486 (defun org-get-packages-alist (var)
3488 "Get the packages alist and make sure it has 3 elements per entry."
3490 (if (and (consp x
) (= (length x
) 2))
3491 (list (car x
) (nth 1 x
) t
)
3493 (default-value var
)))
3495 ;; The following variables are defined here because is it also used
3496 ;; when formatting latex fragments. Originally it was part of the
3497 ;; LaTeX exporter, which is why the name includes "export".
3498 (defcustom org-export-latex-default-packages-alist
3499 '(("AUTO" "inputenc" t
)
3503 ("" "longtable" nil
)
3515 "Alist of default packages to be inserted in the header.
3516 Change this only if one of the packages here causes an incompatibility
3517 with another package you are using.
3518 The packages in this list are needed by one part or another of Org-mode
3519 to function properly.
3521 - inputenc, fontenc: for basic font and character selection
3522 - textcomp, marvosymb, wasysym, latexsym, amssym: for various symbols used
3523 for interpreting the entities in `org-entities'. You can skip some of these
3524 packages if you don't use any of the symbols in it.
3525 - graphicx: for including images
3526 - float, wrapfig: for figure placement
3527 - longtable: for long tables
3528 - hyperref: for cross references
3530 Therefore you should not modify this variable unless you know what you
3531 are doing. The one reason to change it anyway is that you might be loading
3532 some other package that conflicts with one of the default packages.
3533 Each cell is of the format \( \"options\" \"package\" snippet-flag\).
3534 If SNIPPET-FLAG is t, the package also needs to be included when
3535 compiling LaTeX snippets into images for inclusion into HTML."
3536 :group
'org-export-latex
3537 :set
'org-set-packages-alist
3538 :get
'org-get-packages-alist
3542 (list :tag
"options/package pair"
3543 (string :tag
"options")
3544 (string :tag
"package")
3545 (boolean :tag
"Snippet"))
3546 (string :tag
"A line of LaTeX"))))
3548 (defcustom org-export-latex-packages-alist nil
3549 "Alist of packages to be inserted in every LaTeX header.
3550 These will be inserted after `org-export-latex-default-packages-alist'.
3551 Each cell is of the format \( \"options\" \"package\" snippet-flag \).
3552 SNIPPET-FLAG, when t, indicates that this package is also needed when
3553 turning LaTeX snippets into images for inclusion into HTML.
3554 Make sure that you only list packages here which:
3555 - you want in every file
3556 - do not conflict with the default packages in
3557 `org-export-latex-default-packages-alist'
3558 - do not conflict with the setup in `org-format-latex-header'."
3559 :group
'org-export-latex
3560 :set
'org-set-packages-alist
3561 :get
'org-get-packages-alist
3564 (list :tag
"options/package pair"
3565 (string :tag
"options")
3566 (string :tag
"package")
3567 (boolean :tag
"Snippet"))
3568 (string :tag
"A line of LaTeX"))))
3571 (defgroup org-appearance nil
3572 "Settings for Org-mode appearance."
3573 :tag
"Org Appearance"
3576 (defcustom org-level-color-stars-only nil
3577 "Non-nil means fontify only the stars in each headline.
3578 When nil, the entire headline is fontified.
3579 Changing it requires restart of `font-lock-mode' to become effective
3580 also in regions already fontified."
3581 :group
'org-appearance
3584 (defcustom org-hide-leading-stars nil
3585 "Non-nil means hide the first N-1 stars in a headline.
3586 This works by using the face `org-hide' for these stars. This
3587 face is white for a light background, and black for a dark
3588 background. You may have to customize the face `org-hide' to
3590 Changing it requires restart of `font-lock-mode' to become effective
3591 also in regions already fontified.
3592 You may also set this on a per-file basis by adding one of the following
3593 lines to the buffer:
3595 #+STARTUP: hidestars
3596 #+STARTUP: showstars"
3597 :group
'org-appearance
3600 (defcustom org-hidden-keywords nil
3601 "List of symbols corresponding to keywords to be hidden the org buffer.
3602 For example, a value '(title) for this list will make the document's title
3603 appear in the buffer without the initial #+TITLE: keyword."
3604 :group
'org-appearance
3606 :type
'(set (const :tag
"#+AUTHOR" author
)
3607 (const :tag
"#+DATE" date
)
3608 (const :tag
"#+EMAIL" email
)
3609 (const :tag
"#+TITLE" title
)))
3611 (defcustom org-custom-properties nil
3612 "List of properties (as strings) with a special meaning.
3613 The default use of these custom properties is to let the user
3614 hide them with `org-toggle-custom-properties-visibility'."
3615 :group
'org-properties
3616 :group
'org-appearance
3618 :type
'(repeat (string :tag
"Property Name")))
3620 (defcustom org-fontify-done-headline nil
3621 "Non-nil means change the face of a headline if it is marked DONE.
3622 Normally, only the TODO/DONE keyword indicates the state of a headline.
3623 When this is non-nil, the headline after the keyword is set to the
3624 `org-headline-done' as an additional indication."
3625 :group
'org-appearance
3628 (defcustom org-fontify-emphasized-text t
3629 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3630 Changing this variable requires a restart of Emacs to take effect."
3631 :group
'org-appearance
3634 (defcustom org-fontify-whole-heading-line nil
3635 "Non-nil means fontify the whole line for headings.
3636 This is useful when setting a background color for the
3638 :group
'org-appearance
3641 (defcustom org-highlight-latex-fragments-and-specials nil
3642 "Non-nil means fontify what is treated specially by the exporters."
3643 :group
'org-appearance
3646 (defcustom org-hide-emphasis-markers nil
3647 "Non-nil mean font-lock should hide the emphasis marker characters."
3648 :group
'org-appearance
3651 (defcustom org-pretty-entities nil
3652 "Non-nil means show entities as UTF8 characters.
3653 When nil, the \\name form remains in the buffer."
3654 :group
'org-appearance
3658 (defcustom org-pretty-entities-include-sub-superscripts t
3659 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3660 :group
'org-appearance
3664 (defvar org-emph-re nil
3665 "Regular expression for matching emphasis.
3666 After a match, the match groups contain these elements:
3667 0 The match of the full regular expression, including the characters
3668 before and after the proper match
3669 1 The character before the proper match, or empty at beginning of line
3670 2 The proper match, including the leading and trailing markers
3671 3 The leading marker like * or /, indicating the type of highlighting
3672 4 The text between the emphasis markers, not including the markers
3673 5 The character after the match, empty at the end of a line")
3674 (defvar org-verbatim-re nil
3675 "Regular expression for matching verbatim text.")
3676 (defvar org-emphasis-regexp-components
) ; defined just below
3677 (defvar org-emphasis-alist
) ; defined just below
3678 (defun org-set-emph-re (var val
)
3679 "Set variable and compute the emphasis regular expression."
3681 (when (and (boundp 'org-emphasis-alist
)
3682 (boundp 'org-emphasis-regexp-components
)
3683 org-emphasis-alist org-emphasis-regexp-components
)
3684 (let* ((e org-emphasis-regexp-components
)
3690 (body1 (concat body
"*?"))
3691 (markers (mapconcat 'car org-emphasis-alist
""))
3692 (vmarkers (mapconcat
3693 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3694 org-emphasis-alist
"")))
3695 ;; make sure special characters appear at the right position in the class
3696 (if (string-match "\\^" markers
)
3697 (setq markers
(concat (replace-match "" t t markers
) "^")))
3698 (if (string-match "-" markers
)
3699 (setq markers
(concat (replace-match "" t t markers
) "-")))
3700 (if (string-match "\\^" vmarkers
)
3701 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3702 (if (string-match "-" vmarkers
)
3703 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3705 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3706 (int-to-string nl
) "\\}")))
3709 (concat "\\([" pre
"]\\|^\\)"
3711 "\\([" markers
"]\\)"
3719 "\\([" post
"]\\|$\\)"))
3720 (setq org-verbatim-re
3721 (concat "\\([" pre
"]\\|^\\)"
3723 "\\([" vmarkers
"]\\)"
3731 "\\([" post
"]\\|$\\)")))))
3733 (defcustom org-emphasis-regexp-components
3734 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
3735 "Components used to build the regular expression for emphasis.
3736 This is a list with five entries. Terminology: In an emphasis string
3737 like \" *strong word* \", we call the initial space PREMATCH, the final
3738 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
3739 and \"trong wor\" is the body. The different components in this variable
3740 specify what is allowed/forbidden in each part:
3742 pre Chars allowed as prematch. Beginning of line will be allowed too.
3743 post Chars allowed as postmatch. End of line will be allowed too.
3744 border The chars *forbidden* as border characters.
3745 body-regexp A regexp like \".\" to match a body character. Don't use
3746 non-shy groups here, and don't allow newline here.
3747 newline The maximum number of newlines allowed in an emphasis exp.
3749 Use customize to modify this, or restart Emacs after changing it."
3750 :group
'org-appearance
3751 :set
'org-set-emph-re
3753 (sexp :tag
"Allowed chars in pre ")
3754 (sexp :tag
"Allowed chars in post ")
3755 (sexp :tag
"Forbidden chars in border ")
3756 (sexp :tag
"Regexp for body ")
3757 (integer :tag
"number of newlines allowed")
3758 (option (boolean :tag
"Please ignore this button"))))
3760 (defcustom org-emphasis-alist
3761 `(("*" bold
"<b>" "</b>")
3762 ("/" italic
"<i>" "</i>")
3763 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
3764 ("=" org-code
"<code>" "</code>" verbatim
)
3765 ("~" org-verbatim
"<code>" "</code>" verbatim
)
3766 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
3769 "Special syntax for emphasized text.
3770 Text starting and ending with a special character will be emphasized, for
3771 example *bold*, _underlined_ and /italic/. This variable sets the marker
3772 characters, the face to be used by font-lock for highlighting in Org-mode
3773 Emacs buffers, and the HTML tags to be used for this.
3774 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
3775 For DocBook export, see the variable `org-export-docbook-emphasis-alist'.
3776 Use customize to modify this, or restart Emacs after changing it."
3777 :group
'org-appearance
3778 :set
'org-set-emph-re
3781 (string :tag
"Marker character")
3783 (face :tag
"Font-lock-face")
3784 (plist :tag
"Face property list"))
3785 (string :tag
"HTML start tag")
3786 (string :tag
"HTML end tag")
3787 (option (const verbatim
)))))
3789 (defvar org-protecting-blocks
3790 '("src" "example" "latex" "ascii" "html" "docbook" "ditaa" "dot" "r" "R")
3791 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
3792 This is needed for font-lock setup.")
3794 ;;; Miscellaneous options
3796 (defgroup org-completion nil
3797 "Completion in Org-mode."
3798 :tag
"Org Completion"
3801 (defcustom org-completion-use-ido nil
3802 "Non-nil means use ido completion wherever possible.
3803 Note that `ido-mode' must be active for this variable to be relevant.
3804 If you decide to turn this variable on, you might well want to turn off
3805 `org-outline-path-complete-in-steps'.
3806 See also `org-completion-use-iswitchb'."
3807 :group
'org-completion
3810 (defcustom org-completion-use-iswitchb nil
3811 "Non-nil means use iswitchb completion wherever possible.
3812 Note that `iswitchb-mode' must be active for this variable to be relevant.
3813 If you decide to turn this variable on, you might well want to turn off
3814 `org-outline-path-complete-in-steps'.
3815 Note that this variable has only an effect if `org-completion-use-ido' is nil."
3816 :group
'org-completion
3819 (defcustom org-completion-fallback-command
'hippie-expand
3820 "The expansion command called by \\[pcomplete] in normal context.
3821 Normal means, no org-mode-specific context."
3822 :group
'org-completion
3825 ;;; Functions and variables from their packages
3826 ;; Declared here to avoid compiler warnings
3829 (defvar outline-mode-menu-heading
)
3830 (defvar outline-mode-menu-show
)
3831 (defvar outline-mode-menu-hide
)
3832 (defvar zmacs-regions
) ; XEmacs regions
3835 (defvar mark-active
)
3838 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
3839 (declare-function calendar-forward-day
"cal-move" (arg))
3840 (declare-function calendar-goto-date
"cal-move" (date))
3841 (declare-function calendar-goto-today
"cal-move" ())
3842 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
3843 (defvar calc-embedded-close-formula
)
3844 (defvar calc-embedded-open-formula
)
3845 (declare-function cdlatex-tab
"ext:cdlatex" ())
3846 (declare-function cdlatex-compute-tables
"ext:cdlatex" ())
3847 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
3848 (defvar font-lock-unfontify-region-function
)
3849 (declare-function iswitchb-read-buffer
"iswitchb"
3850 (prompt &optional default require-match start matches-set
))
3851 (defvar iswitchb-temp-buflist
)
3852 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
3853 (defvar org-agenda-tags-todo-honor-ignore-options
)
3854 (declare-function org-agenda-skip
"org-agenda" ())
3856 org-agenda-format-item
"org-agenda"
3857 (extra txt
&optional category tags dotime noprefix remove-re habitp
))
3858 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
3859 (declare-function org-agenda-change-all-lines
"org-agenda"
3860 (newhead hdmarker
&optional fixface just-this
))
3861 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
3862 (declare-function org-agenda-maybe-redo
"org-agenda" ())
3863 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
3865 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
3866 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
3867 "org-agenda" (&optional end
))
3868 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
3869 (declare-function org-inlinetask-in-task-p
"org-inlinetask" ())
3870 (declare-function org-inlinetask-goto-beginning
"org-inlinetask" ())
3871 (declare-function org-inlinetask-goto-end
"org-inlinetask" ())
3872 (declare-function org-indent-mode
"org-indent" (&optional arg
))
3873 (declare-function parse-time-string
"parse-time" (string))
3874 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
3875 (declare-function org-export-latex-fix-inputenc
"org-latex" ())
3876 (declare-function orgtbl-send-table
"org-table" (&optional maybe
))
3877 (defvar remember-data-file
)
3878 (defvar texmathp-why
)
3879 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
3880 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
3882 (defvar w3m-current-url
)
3883 (defvar w3m-current-title
)
3885 (defvar org-latex-regexps
)
3887 ;;; Autoload and prepare some org modules
3889 ;; Some table stuff that needs to be defined here, because it is used
3890 ;; by the functions setting up org-mode or checking for table context.
3892 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
3893 "Detect an org-type or table-type table.")
3894 (defconst org-table-line-regexp
"^[ \t]*|"
3895 "Detect an org-type table line.")
3896 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
3897 "Detect an org-type table line.")
3898 (defconst org-table-hline-regexp
"^[ \t]*|-"
3899 "Detect an org-type table hline.")
3900 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
3901 "Detect a table-type table hline.")
3902 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
3903 "Detect the first line outside a table when searching from within it.
3904 This works for both table types.")
3906 ;; Autoload the functions in org-table.el that are needed by functions here.
3909 (org-autoload "org-table"
3910 '(org-table-align org-table-begin org-table-blank-field
3911 org-table-convert org-table-convert-region org-table-copy-down
3912 org-table-copy-region org-table-create
3913 org-table-create-or-convert-from-region
3914 org-table-create-with-table.el org-table-current-dline
3915 org-table-cut-region org-table-delete-column org-table-edit-field
3916 org-table-edit-formulas org-table-end org-table-eval-formula
3917 org-table-export org-table-field-info
3918 org-table-get-stored-formulas org-table-goto-column
3919 org-table-hline-and-move org-table-import org-table-insert-column
3920 org-table-insert-hline org-table-insert-row org-table-iterate
3921 org-table-justify-field-maybe org-table-kill-row
3922 org-table-maybe-eval-formula org-table-maybe-recalculate-line
3923 org-table-move-column org-table-move-column-left
3924 org-table-move-column-right org-table-move-row
3925 org-table-move-row-down org-table-move-row-up
3926 org-table-next-field org-table-next-row org-table-paste-rectangle
3927 org-table-previous-field org-table-recalculate
3928 org-table-rotate-recalc-marks org-table-sort-lines org-table-sum
3929 org-table-toggle-coordinate-overlays
3930 org-table-toggle-formula-debugger org-table-wrap-region
3931 orgtbl-mode turn-on-orgtbl org-table-to-lisp
3932 orgtbl-to-generic orgtbl-to-tsv orgtbl-to-csv orgtbl-to-latex
3933 orgtbl-to-orgtbl orgtbl-to-html orgtbl-to-texinfo
)))
3935 (defun org-at-table-p (&optional table-type
)
3936 "Return t if the cursor is inside an org-type table.
3937 If TABLE-TYPE is non-nil, also check for table.el-type tables."
3938 (if org-enable-table-editor
3940 (beginning-of-line 1)
3941 (looking-at (if table-type org-table-any-line-regexp
3942 org-table-line-regexp
)))
3944 (defsubst org-table-p
() (org-at-table-p))
3946 (defun org-at-table.el-p
()
3947 "Return t if and only if we are at a table.el table."
3948 (and (org-at-table-p 'any
)
3950 (goto-char (org-table-begin 'any
))
3951 (looking-at org-table1-hline-regexp
))))
3952 (defun org-table-recognize-table.el
()
3953 "If there is a table.el table nearby, recognize it and move into it."
3954 (if org-table-tab-recognizes-table.el
3955 (if (org-at-table.el-p
)
3957 (beginning-of-line 1)
3958 (if (looking-at org-table-dataline-regexp
)
3960 (if (looking-at org-table1-hline-regexp
)
3962 (beginning-of-line 2)
3963 (if (looking-at org-table-any-border-regexp
)
3964 (beginning-of-line -
1)))))
3965 (if (re-search-forward "|" (org-table-end t
) t
)
3968 (if (table--at-cell-p (point))
3970 (message "recognizing table.el table...")
3971 (table-recognize-table)
3972 (message "recognizing table.el table...done")))
3973 (error "This should not happen"))
3978 (defun org-at-table-hline-p ()
3979 "Return t if the cursor is inside a hline in a table."
3980 (if org-enable-table-editor
3982 (beginning-of-line 1)
3983 (looking-at org-table-hline-regexp
))
3986 (defvar org-table-clean-did-remove-column nil
)
3988 (defun org-table-map-tables (function &optional quietly
)
3989 "Apply FUNCTION to the start of all tables in the buffer."
3993 (goto-char (point-min))
3994 (while (re-search-forward org-table-any-line-regexp nil t
)
3996 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
3997 (beginning-of-line 1)
3998 (when (and (looking-at org-table-line-regexp
)
3999 ;; Exclude tables in src/example/verbatim/clocktable blocks
4000 (not (org-in-block-p '("src" "example"))))
4001 (save-excursion (funcall function
))
4002 (or (looking-at org-table-line-regexp
)
4004 (re-search-forward org-table-any-border-regexp nil
1))))
4005 (unless quietly
(message "Mapping tables: done")))
4007 ;; Declare and autoload functions from org-exp.el & Co
4009 (declare-function org-default-export-plist
"org-exp")
4010 (declare-function org-infile-export-plist
"org-exp")
4011 (declare-function org-get-current-options
"org-exp")
4013 (org-autoload "org-exp"
4014 '(org-export org-export-visible
4015 org-insert-export-options-template
4016 org-table-clean-before-export
))
4017 (org-autoload "org-ascii"
4018 '(org-export-as-ascii org-export-ascii-preprocess
4019 org-export-as-ascii-to-buffer org-replace-region-by-ascii
4020 org-export-region-as-ascii
))
4021 (org-autoload "org-latex"
4022 '(org-export-as-latex-batch org-export-as-latex-to-buffer
4023 org-replace-region-by-latex org-export-region-as-latex
4024 org-export-as-latex org-export-as-pdf
4025 org-export-as-pdf-and-open
))
4026 (org-autoload "org-html"
4027 '(org-export-as-html-and-open
4028 org-export-as-html-batch org-export-as-html-to-buffer
4029 org-replace-region-by-html org-export-region-as-html
4030 org-export-as-html
))
4031 (org-autoload "org-docbook"
4032 '(org-export-as-docbook-batch org-export-as-docbook-to-buffer
4033 org-replace-region-by-docbook org-export-region-as-docbook
4034 org-export-as-docbook-pdf org-export-as-docbook-pdf-and-open
4035 org-export-as-docbook
))
4036 (org-autoload "org-icalendar"
4037 '(org-export-icalendar-this-file
4038 org-export-icalendar-all-agenda-files
4039 org-export-icalendar-combine-agenda-files
))
4040 (org-autoload "org-xoxo" '(org-export-as-xoxo))
4041 (org-autoload "org-beamer" '(org-beamer-mode org-beamer-sectioning
)))
4043 ;; Declare and autoload functions from org-agenda.el
4046 (org-autoload "org-agenda"
4047 '(org-agenda org-agenda-list org-search-view
4048 org-todo-list org-tags-view org-agenda-list-stuck-projects
4049 org-diary org-agenda-to-appt
4050 org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
)))
4052 ;; Autoload org-remember
4055 (org-autoload "org-remember"
4056 '(org-remember-insinuate org-remember-annotation
4057 org-remember-apply-template org-remember org-remember-handler
)))
4060 (org-autoload "org-capture"
4061 '(org-capture org-capture-insert-template-here
4062 org-capture-import-remember-templates
)))
4064 ;; Autoload org-clock.el
4066 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock"
4068 (declare-function org-clock-update-mode-line
"org-clock" ())
4069 (declare-function org-resolve-clocks
"org-clock"
4070 (&optional also-non-dangling-p prompt last-valid
))
4071 (defvar org-clock-start-time
)
4072 (defvar org-clock-marker
(make-marker)
4073 "Marker recording the last clock-in.")
4074 (defvar org-clock-hd-marker
(make-marker)
4075 "Marker recording the last clock-in, but the headline position.")
4076 (defvar org-clock-heading
""
4077 "The heading of the current clock entry.")
4078 (defun org-clock-is-active ()
4079 "Return non-nil if clock is currently running.
4080 The return value is actually the clock marker."
4081 (marker-buffer org-clock-marker
))
4086 '(org-clock-in org-clock-out org-clock-cancel
4087 org-clock-goto org-clock-sum org-clock-display
4088 org-clock-remove-overlays org-clock-report
4089 org-clocktable-shift org-dblock-write
:clocktable
4090 org-get-clocktable org-resolve-clocks
)))
4092 (defun org-clock-update-time-maybe ()
4093 "If this is a CLOCK line, update it and return t.
4094 Otherwise, return nil."
4097 (beginning-of-line 1)
4098 (skip-chars-forward " \t")
4099 (when (looking-at org-clock-string
)
4100 (let ((re (concat "[ \t]*" org-clock-string
4101 " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
4102 "\\([ \t]*=>.*\\)?\\)?"))
4105 ((not (looking-at re
))
4107 ((not (match-end 2))
4108 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
4109 (> org-clock-marker
(point))
4110 (<= org-clock-marker
(point-at-eol)))
4111 ;; The clock is running here
4112 (setq org-clock-start-time
4114 (org-parse-time-string (match-string 1))))
4115 (org-clock-update-mode-line)))
4117 (and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
4119 (setq ts
(match-string 1)
4120 te
(match-string 3))
4121 (setq s
(- (org-float-time
4122 (apply 'encode-time
(org-parse-time-string te
)))
4124 (apply 'encode-time
(org-parse-time-string ts
))))
4127 h
(floor (/ s
3600))
4131 (insert " => " (format (if neg
"-%d:%02d" "%2d:%02d") h m
))
4134 (defun org-check-running-clock ()
4135 "Check if the current buffer contains the running clock.
4136 If yes, offer to stop it and to save the buffer with the changes."
4137 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
4138 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
4141 (when (y-or-n-p "Save changed buffer?")
4144 (defun org-clocktable-try-shift (dir n
)
4145 "Check if this line starts a clock table, if yes, shift the time block."
4146 (when (org-match-line "^[ \t]*#\\+BEGIN:[ \t]+clocktable\\>")
4147 (org-clocktable-shift dir n
)))
4149 ;; Autoload org-timer.el
4154 '(org-timer-start org-timer org-timer-item
4155 org-timer-change-times-in-region
4157 org-timer-reset-timers
4158 org-timer-show-remaining-time
)))
4160 ;; Autoload org-feed.el
4165 '(org-feed-update org-feed-update-all org-feed-goto-inbox
)))
4168 ;; Autoload org-indent.el
4170 ;; Define the variable already here, to make sure we have it.
4171 (defvar org-indent-mode nil
4172 "Non-nil if Org-Indent mode is enabled.
4173 Use the command `org-indent-mode' to change this variable.")
4178 '(org-indent-mode)))
4180 ;; Autoload org-mobile.el
4185 '(org-mobile-push org-mobile-pull org-mobile-create-sumo-agenda
)))
4187 ;; Autoload archiving code
4188 ;; The stuff that is needed for cycling and tags has to be defined here.
4190 (defgroup org-archive nil
4191 "Options concerning archiving in Org-mode."
4193 :group
'org-structure
)
4195 (defcustom org-archive-location
"%s_archive::"
4196 "The location where subtrees should be archived.
4198 The value of this variable is a string, consisting of two parts,
4199 separated by a double-colon. The first part is a filename and
4200 the second part is a headline.
4202 When the filename is omitted, archiving happens in the same file.
4203 %s in the filename will be replaced by the current file
4204 name (without the directory part). Archiving to a different file
4205 is useful to keep archived entries from contributing to the
4208 The archived entries will be filed as subtrees of the specified
4209 headline. When the headline is omitted, the subtrees are simply
4210 filed away at the end of the file, as top-level entries. Also in
4211 the heading you can use %s to represent the file name, this can be
4212 useful when using the same archive for a number of different files.
4214 Here are a few examples:
4216 If the current file is Projects.org, archive in file
4217 Projects.org_archive, as top-level trees. This is the default.
4219 \"::* Archived Tasks\"
4220 Archive in the current file, under the top-level headline
4221 \"* Archived Tasks\".
4223 \"~/org/archive.org::\"
4224 Archive in file ~/org/archive.org (absolute path), as top-level trees.
4226 \"~/org/archive.org::* From %s\"
4227 Archive in file ~/org/archive.org (absolute path), under headlines
4228 \"From FILENAME\" where file name is the current file name.
4230 \"~/org/datetree.org::datetree/* Finished Tasks\"
4231 The \"datetree/\" string is special, signifying to archive
4232 items to the datetree. Items are placed in either the CLOSED
4233 date of the item, or the current date if there is no CLOSED date.
4234 The heading will be a subentry to the current date. There doesn't
4235 need to be a heading, but there always needs to be a slash after
4236 datetree. For example, to store archived items directly in the
4237 datetree, use \"~/org/datetree.org::datetree/\".
4239 \"basement::** Finished Tasks\"
4240 Archive in file ./basement (relative path), as level 3 trees
4241 below the level 2 heading \"** Finished Tasks\".
4243 You may set this option on a per-file basis by adding to the buffer a
4246 #+ARCHIVE: basement::** Finished Tasks
4248 You may also define it locally for a subtree by setting an ARCHIVE property
4249 in the entry. If such a property is found in an entry, or anywhere up
4250 the hierarchy, it will be used."
4254 (defcustom org-archive-tag
"ARCHIVE"
4255 "The tag that marks a subtree as archived.
4256 An archived subtree does not open during visibility cycling, and does
4257 not contribute to the agenda listings.
4258 After changing this, font-lock must be restarted in the relevant buffers to
4259 get the proper fontification."
4261 :group
'org-keywords
4264 (defcustom org-agenda-skip-archived-trees t
4265 "Non-nil means the agenda will skip any items located in archived trees.
4266 An archived tree is a tree marked with the tag ARCHIVE. The use of this
4267 variable is no longer recommended, you should leave it at the value t.
4268 Instead, use the key `v' to cycle the archives-mode in the agenda."
4270 :group
'org-agenda-skip
4273 (defcustom org-columns-skip-archived-trees t
4274 "Non-nil means ignore archived trees when creating column view."
4276 :group
'org-properties
4279 (defcustom org-cycle-open-archived-trees nil
4280 "Non-nil means `org-cycle' will open archived trees.
4281 An archived tree is a tree marked with the tag ARCHIVE.
4282 When nil, archived trees will stay folded. You can still open them with
4283 normal outline commands like `show-all', but not with the cycling commands."
4288 (defcustom org-sparse-tree-open-archived-trees nil
4289 "Non-nil means sparse tree construction shows matches in archived trees.
4290 When nil, matches in these trees are highlighted, but the trees are kept in
4293 :group
'org-sparse-trees
4296 (defcustom org-sparse-tree-default-date-type
'scheduled-or-deadline
4297 "The default date type when building a sparse tree.
4298 When this is nil, a date is a scheduled or a deadline timestamp.
4299 Otherwise, these types are allowed:
4302 active: only active timestamps (<...>)
4303 inactive: only inactive timestamps (<...)
4304 scheduled: only scheduled timestamps
4305 deadline: only deadline timestamps"
4306 :type
'(choice (const :tag
"Scheduled or deadline" 'scheduled-or-deadline
)
4307 (const :tag
"All timestamps" all
)
4308 (const :tag
"Only active timestamps" active
)
4309 (const :tag
"Only inactive timestamps" inactive
)
4310 (const :tag
"Only scheduled timestamps" scheduled
)
4311 (const :tag
"Only deadline timestamps" deadline
))
4313 :group
'org-sparse-trees
)
4315 (defun org-cycle-hide-archived-subtrees (state)
4316 "Re-hide all archived subtrees after a visibility state change."
4317 (when (and (not org-cycle-open-archived-trees
)
4318 (not (memq state
'(overview folded
))))
4320 (let* ((globalp (memq state
'(contents all
)))
4321 (beg (if globalp
(point-min) (point)))
4322 (end (if globalp
(point-max) (org-end-of-subtree t
))))
4323 (org-hide-archived-subtrees beg end
)
4325 (if (looking-at (concat ".*:" org-archive-tag
":"))
4326 (message "%s" (substitute-command-keys
4327 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
4329 (defun org-force-cycle-archived ()
4330 "Cycle subtree even if it is archived."
4332 (setq this-command
'org-cycle
)
4333 (let ((org-cycle-open-archived-trees t
))
4334 (call-interactively 'org-cycle
)))
4336 (defun org-hide-archived-subtrees (beg end
)
4337 "Re-hide all archived subtrees after a visibility state change."
4339 (let* ((re (concat ":" org-archive-tag
":")))
4341 (while (re-search-forward re end t
)
4342 (when (org-at-heading-p)
4343 (org-flag-subtree t
)
4344 (org-end-of-subtree t
))))))
4346 (declare-function outline-end-of-heading
"outline" ())
4347 (declare-function outline-flag-region
"outline" (from to flag
))
4348 (defun org-flag-subtree (flag)
4350 (org-back-to-heading t
)
4351 (outline-end-of-heading)
4352 (outline-flag-region (point)
4353 (progn (org-end-of-subtree t
) (point))
4356 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
4359 (org-autoload "org-archive"
4360 '(org-add-archive-files org-archive-subtree
4361 org-archive-to-archive-sibling org-toggle-archive-tag
4362 org-archive-subtree-default
4363 org-archive-subtree-default-with-confirmation
)))
4365 ;; Autoload Column View Code
4367 (declare-function org-columns-number-to-string
"org-colview" (n fmt
&optional printf
))
4368 (declare-function org-columns-get-format-and-top-level
"org-colview" ())
4369 (declare-function org-columns-compute
"org-colview" (property))
4371 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
4372 '(org-columns-number-to-string org-columns-get-format-and-top-level
4373 org-columns-compute org-agenda-columns org-columns-remove-overlays
4374 org-columns org-insert-columns-dblock org-dblock-write
:columnview
))
4378 (declare-function org-id-store-link
"org-id")
4379 (declare-function org-id-locations-load
"org-id")
4380 (declare-function org-id-locations-save
"org-id")
4381 (defvar org-id-track-globally
)
4382 (org-autoload "org-id"
4383 '(org-id-get-create org-id-new org-id-copy org-id-get
4384 org-id-get-with-outline-path-completion
4385 org-id-get-with-outline-drilling org-id-store-link
4386 org-id-goto org-id-find org-id-store-link
))
4388 ;; Autoload Plotting Code
4390 (org-autoload "org-plot"
4391 '(org-plot/gnuplot
))
4393 ;;; Variables for pre-computed regular expressions, all buffer local
4395 (defvar org-drawer-regexp
"^[ \t]*:PROPERTIES:[ \t]*$"
4396 "Matches first line of a hidden block.")
4397 (make-variable-buffer-local 'org-drawer-regexp
)
4398 (defvar org-todo-regexp nil
4399 "Matches any of the TODO state keywords.")
4400 (make-variable-buffer-local 'org-todo-regexp
)
4401 (defvar org-not-done-regexp nil
4402 "Matches any of the TODO state keywords except the last one.")
4403 (make-variable-buffer-local 'org-not-done-regexp
)
4404 (defvar org-not-done-heading-regexp nil
4405 "Matches a TODO headline that is not done.")
4406 (make-variable-buffer-local 'org-not-done-regexp
)
4407 (defvar org-todo-line-regexp nil
4408 "Matches a headline and puts TODO state into group 2 if present.")
4409 (make-variable-buffer-local 'org-todo-line-regexp
)
4410 (defvar org-complex-heading-regexp nil
4411 "Matches a headline and puts everything into groups:
4413 group 2: The todo keyword, maybe
4414 group 3: Priority cookie
4415 group 4: True headline
4417 (make-variable-buffer-local 'org-complex-heading-regexp
)
4418 (defvar org-complex-heading-regexp-format nil
4419 "Printf format to make regexp to match an exact headline.
4420 This regexp will match the headline of any node which has the
4421 exact headline text that is put into the format, but may have any
4422 TODO state, priority and tags.")
4423 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
4424 (defvar org-todo-line-tags-regexp nil
4425 "Matches a headline and puts TODO state into group 2 if present.
4426 Also put tags into group 4 if tags are present.")
4427 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
4428 (defvar org-ds-keyword-length
12
4429 "Maximum length of the DEADLINE and SCHEDULED keywords.")
4430 (make-variable-buffer-local 'org-ds-keyword-length
)
4431 (defvar org-deadline-regexp nil
4432 "Matches the DEADLINE keyword.")
4433 (make-variable-buffer-local 'org-deadline-regexp
)
4434 (defvar org-deadline-time-regexp nil
4435 "Matches the DEADLINE keyword together with a time stamp.")
4436 (make-variable-buffer-local 'org-deadline-time-regexp
)
4437 (defvar org-deadline-line-regexp nil
4438 "Matches the DEADLINE keyword and the rest of the line.")
4439 (make-variable-buffer-local 'org-deadline-line-regexp
)
4440 (defvar org-scheduled-regexp nil
4441 "Matches the SCHEDULED keyword.")
4442 (make-variable-buffer-local 'org-scheduled-regexp
)
4443 (defvar org-scheduled-time-regexp nil
4444 "Matches the SCHEDULED keyword together with a time stamp.")
4445 (make-variable-buffer-local 'org-scheduled-time-regexp
)
4446 (defvar org-closed-time-regexp nil
4447 "Matches the CLOSED keyword together with a time stamp.")
4448 (make-variable-buffer-local 'org-closed-time-regexp
)
4450 (defvar org-keyword-time-regexp nil
4451 "Matches any of the 4 keywords, together with the time stamp.")
4452 (make-variable-buffer-local 'org-keyword-time-regexp
)
4453 (defvar org-keyword-time-not-clock-regexp nil
4454 "Matches any of the 3 keywords, together with the time stamp.")
4455 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4456 (defvar org-maybe-keyword-time-regexp nil
4457 "Matches a timestamp, possibly preceded by a keyword.")
4458 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4459 (defvar org-all-time-keywords nil
4460 "List of time keywords.")
4461 (make-variable-buffer-local 'org-all-time-keywords
)
4463 (defconst org-plain-time-of-day-regexp
4466 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4469 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4471 "Regular expression to match a plain time or time range.
4472 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4473 groups carry important information:
4475 1 the first time, range or not
4476 8 the second time, if it is a range.")
4478 (defconst org-plain-time-extension-regexp
4481 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4482 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4483 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4484 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4485 groups carry important information:
4488 9 minutes of duration")
4490 (defconst org-stamp-time-of-day-regexp
4492 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4493 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4495 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4496 "Regular expression to match a timestamp time or time range.
4497 After a match, the following groups carry important information:
4499 1 date plus weekday, for back referencing to make sure both times are on the same day
4500 2 the first time, range or not
4501 4 the second time, if it is a range.")
4503 (defconst org-startup-options
4504 '(("fold" org-startup-folded t
)
4505 ("overview" org-startup-folded t
)
4506 ("nofold" org-startup-folded nil
)
4507 ("showall" org-startup-folded nil
)
4508 ("showeverything" org-startup-folded showeverything
)
4509 ("content" org-startup-folded content
)
4510 ("indent" org-startup-indented t
)
4511 ("noindent" org-startup-indented nil
)
4512 ("hidestars" org-hide-leading-stars t
)
4513 ("showstars" org-hide-leading-stars nil
)
4514 ("odd" org-odd-levels-only t
)
4515 ("oddeven" org-odd-levels-only nil
)
4516 ("align" org-startup-align-all-tables t
)
4517 ("noalign" org-startup-align-all-tables nil
)
4518 ("inlineimages" org-startup-with-inline-images t
)
4519 ("noinlineimages" org-startup-with-inline-images nil
)
4520 ("customtime" org-display-custom-times t
)
4521 ("logdone" org-log-done time
)
4522 ("lognotedone" org-log-done note
)
4523 ("nologdone" org-log-done nil
)
4524 ("lognoteclock-out" org-log-note-clock-out t
)
4525 ("nolognoteclock-out" org-log-note-clock-out nil
)
4526 ("logrepeat" org-log-repeat state
)
4527 ("lognoterepeat" org-log-repeat note
)
4528 ("nologrepeat" org-log-repeat nil
)
4529 ("logreschedule" org-log-reschedule time
)
4530 ("lognotereschedule" org-log-reschedule note
)
4531 ("nologreschedule" org-log-reschedule nil
)
4532 ("logredeadline" org-log-redeadline time
)
4533 ("lognoteredeadline" org-log-redeadline note
)
4534 ("nologredeadline" org-log-redeadline nil
)
4535 ("logrefile" org-log-refile time
)
4536 ("lognoterefile" org-log-refile note
)
4537 ("nologrefile" org-log-refile nil
)
4538 ("fninline" org-footnote-define-inline t
)
4539 ("nofninline" org-footnote-define-inline nil
)
4540 ("fnlocal" org-footnote-section nil
)
4541 ("fnauto" org-footnote-auto-label t
)
4542 ("fnprompt" org-footnote-auto-label nil
)
4543 ("fnconfirm" org-footnote-auto-label confirm
)
4544 ("fnplain" org-footnote-auto-label plain
)
4545 ("fnadjust" org-footnote-auto-adjust t
)
4546 ("nofnadjust" org-footnote-auto-adjust nil
)
4547 ("constcgs" constants-unit-system cgs
)
4548 ("constSI" constants-unit-system SI
)
4549 ("noptag" org-tag-persistent-alist nil
)
4550 ("hideblocks" org-hide-block-startup t
)
4551 ("nohideblocks" org-hide-block-startup nil
)
4552 ("beamer" org-startup-with-beamer-mode t
)
4553 ("entitiespretty" org-pretty-entities t
)
4554 ("entitiesplain" org-pretty-entities nil
))
4555 "Variable associated with STARTUP options for org-mode.
4556 Each element is a list of three items: the startup options (as written
4557 in the #+STARTUP line), the corresponding variable, and the value to set
4558 this variable to if the option is found. An optional forth element PUSH
4559 means to push this value onto the list in the variable.")
4561 (defun org-update-property-plist (key val props
)
4562 "Update PROPS with KEY and VAL."
4563 (let* ((appending (string= "+" (substring key
(- (length key
) 1))))
4564 (key (if appending
(substring key
0 (- (length key
) 1)) key
))
4565 (remainder (org-remove-if (lambda (p) (string= (car p
) key
)) props
))
4566 (previous (cdr (assoc key props
))))
4568 (cons (cons key
(if previous
(concat previous
" " val
) val
)) remainder
)
4569 (cons (cons key val
) remainder
))))
4571 (defconst org-block-regexp
4572 "^[ \t]*#\\+begin_?\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_?\\1[ \t]*$"
4573 "Regular expression for hiding blocks.")
4574 (defconst org-heading-keyword-regexp-format
4575 "^\\(\\*+\\)\\(?: +%s\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
4576 "Printf format for a regexp matching an headline with some keyword.
4577 This regexp will match the headline of any node which has the
4578 exact keyword that is put into the format. The keyword isn't in
4579 any group by default, but the stars and the body are.")
4580 (defconst org-heading-keyword-maybe-regexp-format
4581 "^\\(\\*+\\)\\(?: +%s\\)?\\(?: +\\(.*?\\)\\)?[ \t]*$"
4582 "Printf format for a regexp matching an headline, possibly with some keyword.
4583 This regexp can match any headline with the specified keyword, or
4584 without a keyword. The keyword isn't in any group by default,
4585 but the stars and the body are.")
4587 (defun org-set-regexps-and-options ()
4588 "Precompute regular expressions for current buffer."
4589 (when (derived-mode-p 'org-mode
)
4590 (org-set-local 'org-todo-kwd-alist nil
)
4591 (org-set-local 'org-todo-key-alist nil
)
4592 (org-set-local 'org-todo-key-trigger nil
)
4593 (org-set-local 'org-todo-keywords-1 nil
)
4594 (org-set-local 'org-done-keywords nil
)
4595 (org-set-local 'org-todo-heads nil
)
4596 (org-set-local 'org-todo-sets nil
)
4597 (org-set-local 'org-todo-log-states nil
)
4598 (org-set-local 'org-file-properties nil
)
4599 (org-set-local 'org-file-tags nil
)
4600 (let ((re (org-make-options-regexp
4601 '("CATEGORY" "TODO" "COLUMNS"
4602 "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES"
4603 "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE" "LATEX_CLASS"
4605 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4607 (scripts org-use-sub-superscripts
)
4608 kwds kws0 kwsa key log value cat arch tags const links hw dws
4609 tail sep kws1 prio props ftags drawers beamer-p
4610 ext-setup-or-nil setup-contents
(start 0))
4614 (goto-char (point-min))
4615 (while (or (and ext-setup-or-nil
4616 (string-match re ext-setup-or-nil start
)
4617 (setq start
(match-end 0)))
4618 (and (setq ext-setup-or-nil nil start
0)
4619 (re-search-forward re nil t
)))
4620 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4621 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4622 (if (stringp value
) (setq value
(org-trim value
)))
4624 ((equal key
"CATEGORY")
4626 ((member key
'("SEQ_TODO" "TODO"))
4627 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4628 ((equal key
"TYP_TODO")
4629 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4630 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4631 ;; general TODO-like setup
4632 (push (cons (intern (downcase (match-string 1 key
)))
4633 (org-split-string value splitre
)) kwds
))
4635 (setq tags
(append tags
(if tags
'("\\n") nil
)
4636 (org-split-string value splitre
))))
4637 ((equal key
"COLUMNS")
4638 (org-set-local 'org-columns-default-format value
))
4640 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4641 (push (cons (match-string 1 value
)
4642 (org-trim (match-string 2 value
)))
4644 ((equal key
"PRIORITIES")
4645 (setq prio
(org-split-string value
" +")))
4646 ((equal key
"PROPERTY")
4647 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4648 (setq props
(org-update-property-plist (match-string 1 value
)
4649 (match-string 2 value
)
4651 ((equal key
"FILETAGS")
4652 (when (string-match "\\S-" value
)
4657 (mapcar (lambda (x) (org-split-string x
":"))
4658 (org-split-string value
)))))))
4659 ((equal key
"DRAWERS")
4660 (setq drawers
(delete-dups (append org-drawers
(org-split-string value splitre
)))))
4661 ((equal key
"CONSTANTS")
4662 (setq const
(append const
(org-split-string value splitre
))))
4663 ((equal key
"STARTUP")
4664 (let ((opts (org-split-string value splitre
))
4666 (while (setq l
(pop opts
))
4667 (when (setq l
(assoc l org-startup-options
))
4668 (setq var
(nth 1 l
) val
(nth 2 l
))
4670 (set (make-local-variable var
) val
)
4671 (if (not (listp (symbol-value var
)))
4672 (set (make-local-variable var
) nil
))
4673 (set (make-local-variable var
) (symbol-value var
))
4674 (add-to-list var val
))))))
4675 ((equal key
"ARCHIVE")
4677 (remove-text-properties 0 (length arch
)
4678 '(face t fontified t
) arch
))
4679 ((equal key
"LATEX_CLASS")
4680 (setq beamer-p
(equal value
"beamer")))
4681 ((equal key
"OPTIONS")
4682 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4683 (setq scripts
(read (match-string 2 value
)))))
4684 ((equal key
"SETUPFILE")
4685 (setq setup-contents
(org-file-contents
4687 (org-remove-double-quotes value
))
4689 (if (not ext-setup-or-nil
)
4690 (setq ext-setup-or-nil setup-contents start
0)
4691 (setq ext-setup-or-nil
4692 (concat (substring ext-setup-or-nil
0 start
)
4693 "\n" setup-contents
"\n"
4694 (substring ext-setup-or-nil start
)))))))
4695 ;; search for property blocks
4696 (goto-char (point-min))
4697 (while (re-search-forward org-block-regexp nil t
)
4698 (when (equal "PROPERTY" (upcase (match-string 1)))
4699 (setq value
(replace-regexp-in-string
4700 "[\n\r]" " " (match-string 4)))
4701 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4702 (setq props
(org-update-property-plist (match-string 1 value
)
4703 (match-string 2 value
)
4705 (org-set-local 'org-use-sub-superscripts scripts
)
4707 (org-set-local 'org-category
(intern cat
))
4708 (push (cons "CATEGORY" cat
) props
))
4710 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4711 (setq prio
(mapcar 'string-to-char prio
))
4712 (org-set-local 'org-highest-priority
(nth 0 prio
))
4713 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4714 (org-set-local 'org-default-priority
(nth 2 prio
)))
4715 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4716 (and ftags
(org-set-local 'org-file-tags
4717 (mapcar 'org-add-prop-inherited ftags
)))
4718 (and drawers
(org-set-local 'org-drawers drawers
))
4719 (and arch
(org-set-local 'org-archive-location arch
))
4720 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4721 ;; Process the TODO keywords
4723 ;; Use the global values as if they had been given locally.
4724 (setq kwds
(default-value 'org-todo-keywords
))
4725 (if (stringp (car kwds
))
4726 (setq kwds
(list (cons org-todo-interpretation
4727 (default-value 'org-todo-keywords
)))))
4728 (setq kwds
(reverse kwds
)))
4729 (setq kwds
(nreverse kwds
))
4731 (while (setq kws
(pop kwds
))
4733 (run-hook-with-args-until-success
4734 'org-todo-setup-filter-hook kws
)
4736 (setq inter
(pop kws
) sep
(member "|" kws
)
4737 kws0
(delete "|" (copy-sequence kws
))
4742 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4744 (setq kw
(match-string 1 x
)
4745 key
(and (match-end 2) (match-string 2 x
))
4746 log
(org-extract-log-state-settings x
))
4747 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4748 (and log
(push log org-todo-log-states
))
4750 (error "Invalid TODO keyword %s" x
)))
4752 kwsa
(if kwsa
(append '((:startgroup
))
4756 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4757 tail
(list inter hw
(car dws
) (org-last dws
))))
4758 (add-to-list 'org-todo-heads hw
'append
)
4759 (push kws1 org-todo-sets
)
4760 (setq org-done-keywords
(append org-done-keywords dws nil
))
4761 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4762 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4763 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4764 (setq org-todo-sets
(nreverse org-todo-sets
)
4765 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4766 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4767 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4768 ;; Process the constants
4771 (while (setq e
(pop const
))
4772 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4773 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4774 (setq org-table-formula-constants-local cst
)))
4776 ;; Process the tags.
4779 (while (setq e
(pop tags
))
4781 ((equal e
"{") (push '(:startgroup
) tgs
))
4782 ((equal e
"}") (push '(:endgroup
) tgs
))
4783 ((equal e
"\\n") (push '(:newline
) tgs
))
4784 ((string-match (org-re "^\\([[:alnum:]_@#%]+\\)(\\(.\\))$") e
)
4785 (push (cons (match-string 1 e
)
4786 (string-to-char (match-string 2 e
)))
4788 (t (push (list e
) tgs
))))
4789 (org-set-local 'org-tag-alist nil
)
4790 (while (setq e
(pop tgs
))
4791 (or (and (stringp (car e
))
4792 (assoc (car e
) org-tag-alist
))
4793 (push e org-tag-alist
)))))
4795 ;; Compute the regular expressions and other local variables.
4796 ;; Using `org-outline-regexp-bol' would complicate them much,
4797 ;; because of the fixed white space at the end of that string.
4798 (if (not org-done-keywords
)
4799 (setq org-done-keywords
(and org-todo-keywords-1
4800 (list (org-last org-todo-keywords-1
)))))
4801 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4802 (length org-scheduled-string
)
4803 (length org-clock-string
)
4804 (length org-closed-string
)))
4806 (concat "^[ \t]*:\\("
4807 (mapconcat 'regexp-quote org-drawers
"\\|")
4809 org-not-done-keywords
4810 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4813 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4817 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4819 org-not-done-heading-regexp
4820 (format org-heading-keyword-regexp-format org-not-done-regexp
)
4821 org-todo-line-regexp
4822 (format org-heading-keyword-maybe-regexp-format org-todo-regexp
)
4823 org-complex-heading-regexp
4824 (concat "^\\(\\*+\\)"
4825 "\\(?: +" org-todo-regexp
"\\)?"
4826 "\\(?: +\\(\\[#.\\]\\)\\)?"
4827 "\\(?: +\\(.*?\\)\\)??"
4828 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?")
4830 org-complex-heading-regexp-format
4831 (concat "^\\(\\*+\\)"
4832 "\\(?: +" org-todo-regexp
"\\)?"
4833 "\\(?: +\\(\\[#.\\]\\)\\)?"
4835 ;; Stats cookies can be stuck to body.
4836 "\\(?:\\[[0-9%%/]+\\] *\\)?"
4838 "\\(?: *\\[[0-9%%/]+\\]\\)?"
4840 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?")
4842 org-todo-line-tags-regexp
4843 (concat "^\\(\\*+\\)"
4844 "\\(?: +" org-todo-regexp
"\\)?"
4845 "\\(?: +\\(.*?\\)\\)??"
4846 (org-re "\\(?:[ \t]+\\(:[[:alnum:]:_@#%]+:\\)\\)?")
4848 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4849 org-deadline-time-regexp
4850 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4851 org-deadline-line-regexp
4852 (concat "\\<\\(" org-deadline-string
"\\).*")
4853 org-scheduled-regexp
4854 (concat "\\<" org-scheduled-string
)
4855 org-scheduled-time-regexp
4856 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4857 org-closed-time-regexp
4858 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4859 org-keyword-time-regexp
4860 (concat "\\<\\(" org-scheduled-string
4861 "\\|" org-deadline-string
4862 "\\|" org-closed-string
4863 "\\|" org-clock-string
"\\)"
4864 " *[[<]\\([^]>]+\\)[]>]")
4865 org-keyword-time-not-clock-regexp
4866 (concat "\\<\\(" org-scheduled-string
4867 "\\|" org-deadline-string
4868 "\\|" org-closed-string
4870 " *[[<]\\([^]>]+\\)[]>]")
4871 org-maybe-keyword-time-regexp
4872 (concat "\\(\\<\\(" org-scheduled-string
4873 "\\|" org-deadline-string
4874 "\\|" org-closed-string
4875 "\\|" org-clock-string
"\\)\\)?"
4876 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
4877 org-all-time-keywords
4878 (mapcar (lambda (w) (substring w
0 -
1))
4879 (list org-scheduled-string org-deadline-string
4880 org-clock-string org-closed-string
))
4882 (org-compute-latex-and-specials-regexp)
4883 (org-set-font-lock-defaults))))
4885 (defun org-file-contents (file &optional noerror
)
4886 "Return the contents of FILE, as a string."
4888 (not (file-readable-p file
)))
4891 (message "Cannot read file \"%s\"" file
)
4894 (error "Cannot read file \"%s\"" file
))
4896 (insert-file-contents file
)
4899 (defun org-extract-log-state-settings (x)
4900 "Extract the log state setting from a TODO keyword string.
4901 This will extract info from a string like \"WAIT(w@/!)\"."
4902 (let (kw key log1 log2
)
4903 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
4904 (setq kw
(match-string 1 x
)
4905 key
(and (match-end 2) (match-string 2 x
))
4906 log1
(and (match-end 3) (match-string 3 x
))
4907 log2
(and (match-end 4) (match-string 4 x
)))
4910 (and log1
(if (equal log1
"!") 'time
'note
))
4911 (and log2
(if (equal log2
"!") 'time
'note
)))))))
4913 (defun org-remove-keyword-keys (list)
4914 "Remove a pair of parenthesis at the end of each string in LIST."
4916 (if (string-match "(.*)$" x
)
4917 (substring x
0 (match-beginning 0))
4921 (defun org-assign-fast-keys (alist)
4922 "Assign fast keys to a keyword-key alist.
4923 Respect keys that are already there."
4924 (let (new e
(alt ?
0))
4925 (while (setq e
(pop alist
))
4926 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
4927 (cdr e
)) ;; Key already assigned.
4929 (let ((clist (string-to-list (downcase (car e
))))
4930 (used (append new alist
)))
4931 (when (= (car clist
) ?
@)
4933 (while (and clist
(rassoc (car clist
) used
))
4936 (while (rassoc alt used
)
4938 (push (cons (car e
) (or (car clist
) alt
)) new
))))
4941 ;;; Some variables used in various places
4943 (defvar org-window-configuration nil
4944 "Used in various places to store a window configuration.")
4945 (defvar org-selected-window nil
4946 "Used in various places to store a window configuration.")
4947 (defvar org-finish-function nil
4948 "Function to be called when `C-c C-c' is used.
4949 This is for getting out of special buffers like remember.")
4952 ;; FIXME: Occasionally check by commenting these, to make sure
4953 ;; no other functions uses these, forgetting to let-bind them.
4954 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
4955 (defvar org-last-state
)
4956 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
4958 ;; Defined somewhere in this file, but used before definition.
4959 (defvar org-entities
) ;; defined in org-entities.el
4960 (defvar org-struct-menu
)
4961 (defvar org-org-menu
)
4962 (defvar org-tbl-menu
)
4964 ;;;; Define the Org-mode
4966 ;; We use a before-change function to check if a table might need
4968 (defvar org-table-may-need-update t
4969 "Indicates that a table might need an update.
4970 This variable is set by `org-before-change-function'.
4971 `org-table-align' sets it back to nil.")
4972 (defun org-before-change-function (beg end
)
4973 "Every change indicates that a table might need an update."
4974 (setq org-table-may-need-update t
))
4975 (defvar org-mode-map
)
4976 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
4977 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
4978 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
4979 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
4980 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
4981 (defvar org-table-buffer-is-an nil
)
4983 (defvar bidi-paragraph-direction
)
4984 (defvar buffer-face-mode-face
)
4987 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
4988 (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"))
4989 (require 'noutline
"noutline" 'noerror
) ;; stock XEmacs does not have it
4991 ;; Other stuff we need.
4992 (require 'time-date
)
4993 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
4998 (require 'org-entities
)
4999 ;; (require 'org-compat) moved higher up in the file before it is first used
5000 (require 'org-faces
)
5002 (require 'org-pcomplete
)
5004 (require 'org-footnote
)
5011 (require 'ob-tangle
)
5012 (require 'ob-comint
)
5016 (define-derived-mode org-mode outline-mode
"Org"
5017 "Outline-based notes management and organizer, alias
5018 \"Carsten's outline-mode for keeping track of everything.\"
5020 Org-mode develops organizational tasks around a NOTES file which
5021 contains information about projects as plain text. Org-mode is
5022 implemented on top of outline-mode, which is ideal to keep the content
5023 of large files well structured. It supports ToDo items, deadlines and
5024 time stamps, which magically appear in the diary listing of the Emacs
5025 calendar. Tables are easily created with a built-in table editor.
5026 Plain text URL-like links connect to websites, emails (VM), Usenet
5027 messages (Gnus), BBDB entries, and any files related to the project.
5028 For printing and sharing of notes, an Org-mode file (or a part of it)
5029 can be exported as a structured ASCII or HTML file.
5031 The following commands are available:
5035 ;; Get rid of Outline menus, they are not needed
5036 ;; Need to do this here because define-derived-mode sets up
5037 ;; the keymap so late. Still, it is a waste to call this each time
5038 ;; we switch another buffer into org-mode.
5039 (if (featurep 'xemacs
)
5040 (when (boundp 'outline-mode-menu-heading
)
5041 ;; Assume this is Greg's port, it uses easymenu
5042 (easy-menu-remove outline-mode-menu-heading
)
5043 (easy-menu-remove outline-mode-menu-show
)
5044 (easy-menu-remove outline-mode-menu-hide
))
5045 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
5046 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
5047 (define-key org-mode-map
[menu-bar show
] 'undefined
))
5049 (org-load-modules-maybe)
5050 (easy-menu-add org-org-menu
)
5051 (easy-menu-add org-tbl-menu
)
5052 (org-install-agenda-files-menu)
5053 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
5054 (add-to-invisibility-spec '(org-cwidth))
5055 (add-to-invisibility-spec '(org-hide-block . t
))
5056 (when (featurep 'xemacs
)
5057 (org-set-local 'line-move-ignore-invisible t
))
5058 (org-set-local 'outline-regexp org-outline-regexp
)
5059 (org-set-local 'outline-level
'org-outline-level
)
5060 (setq bidi-paragraph-direction
'left-to-right
)
5061 (when (and org-ellipsis
5062 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
5063 (fboundp 'make-glyph-code
))
5064 (unless org-display-table
5065 (setq org-display-table
(make-display-table)))
5066 (set-display-table-slot
5069 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
5071 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
5072 (setq buffer-display-table org-display-table
))
5073 (org-set-regexps-and-options)
5074 (when (and org-tag-faces
(not org-tags-special-faces-re
))
5075 ;; tag faces set outside customize.... force initialization.
5076 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
5078 (org-set-local 'calc-embedded-open-mode
"# ")
5079 (modify-syntax-entry ?
@ "w")
5080 (if org-startup-truncated
(setq truncate-lines t
))
5081 (org-set-local 'font-lock-unfontify-region-function
5082 'org-unfontify-region
)
5083 ;; Activate before-change-function
5084 (org-set-local 'org-table-may-need-update t
)
5085 (org-add-hook 'before-change-functions
'org-before-change-function nil
5087 ;; Check for running clock before killing a buffer
5088 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
5090 (org-set-local 'indent-line-function
'org-indent-line
)
5091 (org-set-local 'indent-region-function
'org-indent-region
)
5092 ;; Initialize radio targets.
5093 (org-update-radio-target-regexp)
5094 ;; Filling and auto-filling.
5097 (org-setup-comments-handling)
5098 ;; Beginning/end of defun
5099 (org-set-local 'beginning-of-defun-function
'org-back-to-heading
)
5100 (org-set-local 'end-of-defun-function
(lambda () (interactive) (org-end-of-subtree nil t
)))
5101 ;; Next error for sparse trees
5102 (org-set-local 'next-error-function
'org-occur-next-match
)
5103 ;; Make sure dependence stuff works reliably, even for users who set it
5105 (if org-enforce-todo-dependencies
5106 (add-hook 'org-blocker-hook
5107 'org-block-todo-from-children-or-siblings-or-parent
)
5108 (remove-hook 'org-blocker-hook
5109 'org-block-todo-from-children-or-siblings-or-parent
))
5110 (if org-enforce-todo-checkbox-dependencies
5111 (add-hook 'org-blocker-hook
5112 'org-block-todo-from-checkboxes
)
5113 (remove-hook 'org-blocker-hook
5114 'org-block-todo-from-checkboxes
))
5116 ;; Align options lines
5118 'align-mode-rules-list
5119 '((org-in-buffer-settings
5120 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
5121 (modes .
'(org-mode)))))
5124 (org-set-local 'imenu-create-index-function
5125 'org-imenu-get-tree
)
5127 ;; Make isearch reveal context
5128 (if (or (featurep 'xemacs
)
5129 (not (boundp 'outline-isearch-open-invisible-function
)))
5130 ;; Emacs 21 and XEmacs make use of the hook
5131 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
5132 ;; Emacs 22 deals with this through a special variable
5133 (org-set-local 'outline-isearch-open-invisible-function
5134 (lambda (&rest ignore
) (org-show-context 'isearch
))))
5136 ;; Turn on org-beamer-mode?
5137 (and org-startup-with-beamer-mode
(org-beamer-mode 1))
5139 ;; Setup the pcomplete hooks
5140 (set (make-local-variable 'pcomplete-command-completion-function
)
5141 'org-pcomplete-initial
)
5142 (set (make-local-variable 'pcomplete-command-name-function
)
5143 'org-command-at-point
)
5144 (set (make-local-variable 'pcomplete-default-completion-function
)
5146 (set (make-local-variable 'pcomplete-parse-arguments-function
)
5147 'org-parse-arguments
)
5148 (set (make-local-variable 'pcomplete-termination-string
) "")
5149 (when (>= emacs-major-version
23)
5150 (set (make-local-variable 'buffer-face-mode-face
) 'org-default
))
5152 ;; If empty file that did not turn on org-mode automatically, make it to.
5153 (if (and org-insert-mode-line-in-empty-file
5154 (org-called-interactively-p 'any
)
5155 (= (point-min) (point-max)))
5156 (insert "# -*- mode: org -*-\n\n"))
5157 (unless org-inhibit-startup
5158 (when org-startup-align-all-tables
5159 (let ((bmp (buffer-modified-p)))
5160 (org-table-map-tables 'org-table-align
'quietly
)
5161 (set-buffer-modified-p bmp
)))
5162 (when org-startup-with-inline-images
5163 (org-display-inline-images))
5164 (when org-startup-indented
5165 (require 'org-indent
)
5166 (org-indent-mode 1))
5167 (unless org-inhibit-startup-visibility-stuff
5168 (org-set-startup-visibility))))
5170 (when (fboundp 'abbrev-table-put
)
5171 (abbrev-table-put org-mode-abbrev-table
5172 :parents
(list text-mode-abbrev-table
)))
5174 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
5176 (defun org-current-time ()
5177 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
5178 (if (> (car org-time-stamp-rounding-minutes
) 1)
5179 (let ((r (car org-time-stamp-rounding-minutes
))
5180 (time (decode-time)))
5182 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
5187 "Return today date, considering `org-extend-today-until'."
5189 (time-subtract (current-time)
5190 (list 0 (* 3600 org-extend-today-until
) 0))))
5192 ;;;; Font-Lock stuff, including the activators
5194 (defvar org-mouse-map
(make-sparse-keymap))
5195 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
5196 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
5197 (when org-mouse-1-follows-link
5198 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
5199 (when org-tab-follows-link
5200 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
5201 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
5203 (require 'font-lock
)
5205 (defconst org-non-link-chars
"]\t\n\r<>")
5206 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
5207 "shell" "elisp" "doi" "message"))
5208 (defvar org-link-types-re nil
5209 "Matches a link that has a url-like prefix like \"http:\"")
5210 (defvar org-link-re-with-space nil
5211 "Matches a link with spaces, optional angular brackets around it.")
5212 (defvar org-link-re-with-space2 nil
5213 "Matches a link with spaces, optional angular brackets around it.")
5214 (defvar org-link-re-with-space3 nil
5215 "Matches a link with spaces, only for internal part in bracket links.")
5216 (defvar org-angle-link-re nil
5217 "Matches link with angular brackets, spaces are allowed.")
5218 (defvar org-plain-link-re nil
5219 "Matches plain link, without spaces.")
5220 (defvar org-bracket-link-regexp nil
5221 "Matches a link in double brackets.")
5222 (defvar org-bracket-link-analytic-regexp nil
5223 "Regular expression used to analyze links.
5224 Here is what the match groups contain after a match:
5230 (defvar org-bracket-link-analytic-regexp
++ nil
5231 "Like `org-bracket-link-analytic-regexp', but include coderef internal type.")
5232 (defvar org-any-link-re nil
5233 "Regular expression matching any link.")
5235 (defcustom org-match-sexp-depth
3
5236 "Number of stacked braces for sub/superscript matching.
5237 This has to be set before loading org.el to be effective."
5238 :group
'org-export-translation
; ??????????????????????????/
5241 (defun org-create-multibrace-regexp (left right n
)
5242 "Create a regular expression which will match a balanced sexp.
5243 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
5244 as single character strings.
5245 The regexp returned will match the entire expression including the
5246 delimiters. It will also define a single group which contains the
5247 match except for the outermost delimiters. The maximum depth of
5248 stacked delimiters is N. Escaping delimiters is not possible."
5249 (let* ((nothing (concat "[^" left right
"]*?"))
5252 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
5255 re
(concat re or next
)
5256 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
5257 (concat left
"\\(" re
"\\)" right
)))
5259 (defvar org-match-substring-regexp
5261 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5262 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5264 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
5266 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
5267 "The regular expression matching a sub- or superscript.")
5269 (defvar org-match-substring-with-braces-regexp
5271 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5272 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5274 "The regular expression matching a sub- or superscript, forcing braces.")
5276 (defun org-make-link-regexps ()
5277 "Update the link regular expressions.
5278 This should be called after the variable `org-link-types' has changed."
5279 (setq org-link-types-re
5281 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
5282 org-link-re-with-space
5284 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5285 "\\([^" org-non-link-chars
" ]"
5286 "[^" org-non-link-chars
"]*"
5287 "[^" org-non-link-chars
" ]\\)>?")
5288 org-link-re-with-space2
5290 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5291 "\\([^" org-non-link-chars
" ]"
5293 "[^" org-non-link-chars
" ]\\)>?")
5294 org-link-re-with-space3
5296 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5297 "\\([^" org-non-link-chars
" ]"
5301 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5302 "\\([^" org-non-link-chars
" ]"
5303 "[^" org-non-link-chars
"]*"
5307 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5308 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
5309 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
5310 org-bracket-link-regexp
5311 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
5312 org-bracket-link-analytic-regexp
5315 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
5318 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5320 org-bracket-link-analytic-regexp
++
5323 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
5326 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5329 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
5330 org-angle-link-re
"\\)\\|\\("
5331 org-plain-link-re
"\\)")))
5333 (org-make-link-regexps)
5335 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)>"
5336 "Regular expression for fast time stamp matching.")
5337 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?\\)[]>]"
5338 "Regular expression for fast time stamp matching.")
5339 (defconst org-ts-regexp0
5340 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9>\r\n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5341 "Regular expression matching time strings for analysis.
5342 This one does not require the space after the date, so it can be used
5343 on a string that terminates immediately after the date.")
5344 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5345 "Regular expression matching time strings for analysis.")
5346 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
5347 "Regular expression matching time stamps, with groups.")
5348 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
5349 "Regular expression matching time stamps (also [..]), with groups.")
5350 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
5351 "Regular expression matching a time stamp range.")
5352 (defconst org-tr-regexp-both
5353 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
5354 "Regular expression matching a time stamp range.")
5355 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
5356 org-ts-regexp
"\\)?")
5357 "Regular expression matching a time stamp or time stamp range.")
5358 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
5359 org-ts-regexp-both
"\\)?")
5360 "Regular expression matching a time stamp or time stamp range.
5361 The time stamps may be either active or inactive.")
5363 (defvar org-emph-face nil
)
5365 (defun org-do-emphasis-faces (limit)
5366 "Run through the buffer and add overlays to emphasized strings."
5368 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
5369 (if (not (= (char-after (match-beginning 3))
5370 (char-after (match-beginning 4))))
5373 (setq a
(assoc (match-string 3) org-emphasis-alist
))
5374 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
5378 (org-remove-flyspell-overlays-in
5379 (match-beginning 0) (match-end 0)))
5380 (add-text-properties (match-beginning 2) (match-end 2)
5381 '(font-lock-multiline t org-emphasis t
))
5382 (when org-hide-emphasis-markers
5383 (add-text-properties (match-end 4) (match-beginning 5)
5384 '(invisible org-link
))
5385 (add-text-properties (match-beginning 3) (match-end 3)
5386 '(invisible org-link
)))))
5390 (defun org-emphasize (&optional char
)
5391 "Insert or change an emphasis, i.e. a font like bold or italic.
5392 If there is an active region, change that region to a new emphasis.
5393 If there is no region, just insert the marker characters and position
5394 the cursor between them.
5395 CHAR should be either the marker character, or the first character of the
5396 HTML tag associated with that emphasis. If CHAR is a space, the means
5397 to remove the emphasis of the selected region.
5398 If char is not given (for example in an interactive call) it
5399 will be prompted for."
5401 (let ((eal org-emphasis-alist
) e det
5402 (erc org-emphasis-regexp-components
)
5404 (string "") beg end move tag c s
)
5405 (if (org-region-active-p)
5406 (setq beg
(region-beginning) end
(region-end)
5407 string
(buffer-substring beg end
))
5410 (while (setq e
(pop eal
))
5411 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
5413 (push (cons c
(string-to-char (car e
))) det
)
5414 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
5415 (substring tag
1)))))
5416 (setq det
(nreverse det
))
5418 (message "%s" (concat "Emphasis marker or tag:" prompt
))
5419 (setq char
(read-char-exclusive)))
5420 (setq char
(or (cdr (assoc char det
)) char
))
5421 (if (equal char ?\
)
5422 (setq s
"" move nil
)
5423 (unless (assoc (char-to-string char
) org-emphasis-alist
)
5424 (error "No such emphasis marker: \"%c\"" char
))
5425 (setq s
(char-to-string char
)))
5426 (while (and (> (length string
) 1)
5427 (equal (substring string
0 1) (substring string -
1))
5428 (assoc (substring string
0 1) org-emphasis-alist
))
5429 (setq string
(substring string
1 -
1)))
5430 (setq string
(concat s string s
))
5431 (if beg
(delete-region beg end
))
5433 (string-match (concat "[" (nth 0 erc
) "\n]")
5434 (char-to-string (char-before (point)))))
5437 (string-match (concat "[" (nth 1 erc
) "\n]")
5438 (char-to-string (char-after (point)))))
5439 (insert " ") (backward-char 1))
5441 (and move
(backward-char 1))))
5443 (defconst org-nonsticky-props
5444 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text
))
5446 (defsubst org-rear-nonsticky-at
(pos)
5447 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
5449 (defun org-activate-plain-links (limit)
5450 "Run through the buffer and add overlays to links."
5453 (when (re-search-forward (concat org-plain-link-re
) limit t
)
5454 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5455 (setq f
(get-text-property (match-beginning 0) 'face
))
5456 (if (or (eq f
'org-tag
)
5457 (and (listp f
) (memq 'org-tag f
)))
5459 (add-text-properties (match-beginning 0) (match-end 0)
5460 (list 'mouse-face
'highlight
5462 'keymap org-mouse-map
))
5463 (org-rear-nonsticky-at (match-end 0)))
5466 (defun org-activate-code (limit)
5467 (if (re-search-forward "^[ \t]*\\(:\\(?: .*\\|$\\)\n?\\)" limit t
)
5469 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5470 (remove-text-properties (match-beginning 0) (match-end 0)
5471 '(display t invisible t intangible t
))
5474 (defcustom org-src-fontify-natively nil
5475 "When non-nil, fontify code in code blocks."
5478 :group
'org-appearance
5481 (defcustom org-allow-promoting-top-level-subtree nil
5482 "When non-nil, allow promoting a top level subtree.
5483 The leading star of the top level headline will be replaced
5487 :group
'org-appearance
)
5489 (defun org-fontify-meta-lines-and-blocks (limit)
5491 (org-fontify-meta-lines-and-blocks-1 limit
)
5492 (error (message "org-mode fontification error"))))
5494 (defun org-fontify-meta-lines-and-blocks-1 (limit)
5495 "Fontify #+ lines and blocks, in the correct ways."
5496 (let ((case-fold-search t
))
5497 (if (re-search-forward
5498 "^\\([ \t]*#\\(\\(\\+[a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
5500 (let ((beg (match-beginning 0))
5501 (block-start (match-end 0))
5503 (lang (match-string 7))
5504 (beg1 (line-beginning-position 2))
5505 (dc1 (downcase (match-string 2)))
5506 (dc3 (downcase (match-string 3)))
5507 end end1 quoting block-type ovl
)
5509 ((member dc1
'("+html:" "+ascii:" "+latex:" "+docbook:"))
5510 ;; a single line of backend-specific content
5511 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5512 (remove-text-properties (match-beginning 0) (match-end 0)
5513 '(display t invisible t intangible t
))
5514 (add-text-properties (match-beginning 1) (match-end 3)
5515 '(font-lock-fontified t face org-meta-line
))
5516 (add-text-properties (match-beginning 6) (+ (match-end 6) 1)
5517 '(font-lock-fontified t face org-block
))
5518 ; for backend-specific code
5520 ((and (match-end 4) (equal dc3
"+begin"))
5522 (setq block-type
(downcase (match-string 5))
5523 quoting
(member block-type org-protecting-blocks
))
5524 (when (re-search-forward
5525 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
5526 nil t
) ;; on purpose, we look further than LIMIT
5527 (setq end
(min (point-max) (match-end 0))
5528 end1
(min (point-max) (1- (match-beginning 0))))
5529 (setq block-end
(match-beginning 0))
5531 (remove-text-properties beg end
5532 '(display t invisible t intangible t
)))
5533 (add-text-properties
5535 '(font-lock-fontified t font-lock-multiline t
))
5536 (add-text-properties beg beg1
'(face org-meta-line
))
5537 (add-text-properties end1
(min (point-max) (1+ end
))
5538 '(face org-meta-line
)) ; for end_src
5540 ((and lang
(not (string= lang
"")) org-src-fontify-natively
)
5541 (org-src-font-lock-fontify-block lang block-start block-end
)
5542 ;; remove old background overlays
5544 (if (eq (overlay-get ov
'face
) 'org-block-background
)
5545 (delete-overlay ov
)))
5546 (overlays-at (/ (+ beg1 block-end
) 2)))
5547 ;; add a background overlay
5548 (setq ovl
(make-overlay beg1 block-end
))
5549 (overlay-put ovl
'face
'org-block-background
)
5550 (overlay-put ovl
'evaporate t
)) ;; make it go away when empty
5552 (add-text-properties beg1
(min (point-max) (1+ end1
))
5553 '(face org-block
))) ; end of source block
5554 ((not org-fontify-quote-and-verse-blocks
))
5555 ((string= block-type
"quote")
5556 (add-text-properties beg1
(min (point-max) (1+ end1
)) '(face org-quote
)))
5557 ((string= block-type
"verse")
5558 (add-text-properties beg1
(min (point-max) (1+ end1
)) '(face org-verse
))))
5559 (add-text-properties beg beg1
'(face org-block-begin-line
))
5560 (add-text-properties (min (point-max) (1+ end
)) (min (point-max) (1+ end1
))
5561 '(face org-block-end-line
))
5563 ((member dc1
'("+title:" "+author:" "+email:" "+date:"))
5564 (add-text-properties
5566 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
5567 '(font-lock-fontified t invisible t
)
5568 '(font-lock-fontified t face org-document-info-keyword
)))
5569 (add-text-properties
5570 (match-beginning 6) (match-end 6)
5571 (if (string-equal dc1
"+title:")
5572 '(font-lock-fontified t face org-document-title
)
5573 '(font-lock-fontified t face org-document-info
))))
5574 ((or (equal dc1
"+results")
5575 (member dc1
'("+begin:" "+end:" "+caption:" "+label:"
5576 "+orgtbl:" "+tblfm:" "+tblname:" "+results:"
5577 "+call:" "+header:" "+headers:" "+name:"))
5578 (and (match-end 4) (equal dc3
"+attr")))
5579 (add-text-properties
5581 '(font-lock-fontified t face org-meta-line
))
5583 ((member dc3
'(" " ""))
5584 (add-text-properties
5586 '(font-lock-fontified t face font-lock-comment-face
)))
5587 ((not (member (char-after beg
) '(?\ ?
\t)))
5588 ;; just any other in-buffer setting, but not indented
5589 (add-text-properties
5591 '(font-lock-fontified t face org-meta-line
))
5595 (defun org-strip-protective-commas (beg end
)
5596 "Strip protective commas between BEG and END in the current buffer."
5601 (let ((front-line (save-excursion
5603 "[^[:space:]]" end t
)
5604 (goto-char (match-beginning 0))
5606 (while (re-search-forward "^[ \t]*\\(,\\)\\([*]\\|#\\)" end t
)
5607 (goto-char (match-beginning 1))
5608 (when (= (current-column) front-line
)
5609 (replace-match "" nil nil nil
1)))))))
5611 (defun org-activate-angle-links (limit)
5612 "Run through the buffer and add overlays to links."
5613 (if (re-search-forward org-angle-link-re limit t
)
5615 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5616 (add-text-properties (match-beginning 0) (match-end 0)
5617 (list 'mouse-face
'highlight
5618 'keymap org-mouse-map
))
5619 (org-rear-nonsticky-at (match-end 0))
5622 (defun org-activate-footnote-links (limit)
5623 "Run through the buffer and add overlays to footnotes."
5624 (let ((fn (org-footnote-next-reference-or-definition limit
)))
5626 (let ((beg (nth 1 fn
)) (end (nth 2 fn
)))
5627 (org-remove-flyspell-overlays-in beg end
)
5628 (add-text-properties beg end
5629 (list 'mouse-face
'highlight
5630 'keymap org-mouse-map
5632 (if (= (point-at-bol) beg
)
5633 "Footnote definition"
5634 "Footnote reference")
5635 'font-lock-fontified t
5636 'font-lock-multiline t
5637 'face
'org-footnote
))))))
5639 (defun org-activate-bracket-links (limit)
5640 "Run through the buffer and add overlays to bracketed links."
5641 (if (re-search-forward org-bracket-link-regexp limit t
)
5642 (let* ((help (concat "LINK: "
5643 (org-match-string-no-properties 1)))
5644 ;; FIXME: above we should remove the escapes.
5645 ;; but that requires another match, protecting match data,
5646 ;; a lot of overhead for font-lock.
5647 (ip (org-maybe-intangible
5648 (list 'invisible
'org-link
5649 'keymap org-mouse-map
'mouse-face
'highlight
5650 'font-lock-multiline t
'help-echo help
)))
5651 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5652 'font-lock-multiline t
'help-echo help
)))
5653 ;; We need to remove the invisible property here. Table narrowing
5654 ;; may have made some of this invisible.
5655 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5656 (remove-text-properties (match-beginning 0) (match-end 0)
5660 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5661 (org-rear-nonsticky-at (match-beginning 3))
5662 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5663 (org-rear-nonsticky-at (match-end 3))
5664 (add-text-properties (match-end 3) (match-end 0) ip
)
5665 (org-rear-nonsticky-at (match-end 0)))
5666 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5667 (org-rear-nonsticky-at (match-beginning 1))
5668 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5669 (org-rear-nonsticky-at (match-end 1))
5670 (add-text-properties (match-end 1) (match-end 0) ip
)
5671 (org-rear-nonsticky-at (match-end 0)))
5674 (defun org-activate-dates (limit)
5675 "Run through the buffer and add overlays to dates."
5676 (if (re-search-forward org-tsr-regexp-both limit t
)
5678 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5679 (add-text-properties (match-beginning 0) (match-end 0)
5680 (list 'mouse-face
'highlight
5681 'keymap org-mouse-map
))
5682 (org-rear-nonsticky-at (match-end 0))
5683 (when org-display-custom-times
5685 (org-display-custom-time (match-beginning 3) (match-end 3)))
5686 (org-display-custom-time (match-beginning 1) (match-end 1)))
5689 (defvar org-target-link-regexp nil
5690 "Regular expression matching radio targets in plain text.")
5691 (make-variable-buffer-local 'org-target-link-regexp
)
5692 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5693 "Regular expression matching a link target.")
5694 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5695 "Regular expression matching a radio target.")
5696 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5697 "Regular expression matching any target.")
5699 (defun org-activate-target-links (limit)
5700 "Run through the buffer and add overlays to target matches."
5701 (when org-target-link-regexp
5702 (let ((case-fold-search t
))
5703 (if (re-search-forward org-target-link-regexp limit t
)
5705 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5706 (add-text-properties (match-beginning 0) (match-end 0)
5707 (list 'mouse-face
'highlight
5708 'keymap org-mouse-map
5709 'help-echo
"Radio target link"
5710 'org-linked-text t
))
5711 (org-rear-nonsticky-at (match-end 0))
5714 (defun org-update-radio-target-regexp ()
5715 "Find all radio targets in this file and update the regular expression."
5717 (when (memq 'radio org-activate-links
)
5718 (setq org-target-link-regexp
5719 (org-make-target-link-regexp (org-all-targets 'radio
)))
5720 (org-restart-font-lock)))
5722 (defun org-hide-wide-columns (limit)
5724 (setq s
(text-property-any (point) (or limit
(point-max))
5727 (setq e
(next-single-property-change s
'org-cwidth
))
5728 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5732 (defvar org-latex-and-specials-regexp nil
5733 "Regular expression for highlighting export special stuff.")
5734 (defvar org-match-substring-regexp
)
5735 (defvar org-match-substring-with-braces-regexp
)
5737 ;; This should be with the exporter code, but we also use if for font-locking
5738 (defconst org-export-html-special-string-regexps
5739 '(("\\\\-" .
"­")
5740 ("---\\([^-]\\)" .
"—\\1")
5741 ("--\\([^-]\\)" .
"–\\1")
5742 ("\\.\\.\\." .
"…"))
5743 "Regular expressions for special string conversion.")
5746 (defun org-compute-latex-and-specials-regexp ()
5747 "Compute regular expression for stuff treated specially by exporters."
5748 (if (not org-highlight-latex-fragments-and-specials
)
5749 (org-set-local 'org-latex-and-specials-regexp nil
)
5752 ((matchers (plist-get org-format-latex-options
:matchers
))
5753 (latexs (delq nil
(mapcar (lambda (x) (if (member (car x
) matchers
) x
))
5754 org-latex-regexps
)))
5755 (org-export-allow-BIND nil
)
5756 (options (org-combine-plists (org-default-export-plist)
5757 (org-infile-export-plist)))
5758 (org-export-with-sub-superscripts (plist-get options
:sub-superscript
))
5759 (org-export-with-LaTeX-fragments (plist-get options
:LaTeX-fragments
))
5760 (org-export-with-TeX-macros (plist-get options
:TeX-macros
))
5761 (org-export-html-expand (plist-get options
:expand-quoted-html
))
5762 (org-export-with-special-strings (plist-get options
:special-strings
))
5765 ((equal org-export-with-sub-superscripts
'{})
5766 (list org-match-substring-with-braces-regexp
))
5767 (org-export-with-sub-superscripts
5768 (list org-match-substring-regexp
))))
5770 (if org-export-with-LaTeX-fragments
5771 (mapcar (lambda (x) (nth 1 x
)) latexs
)))
5773 (if org-export-with-TeX-macros
5774 (list (concat "\\\\"
5780 (append org-entities-user
5782 (if (boundp 'org-latex-entities
)
5784 (or (car-safe x
) x
))
5789 ;; (list "\\\\\\(?:[a-zA-Z]+\\)")))
5790 (re-special (if org-export-with-special-strings
5791 (mapcar (lambda (x) (car x
))
5792 org-export-html-special-string-regexps
)))
5796 (if org-export-html-expand
"@<[^>\n]+>")
5799 'org-latex-and-specials-regexp
5800 (mapconcat 'identity
(append re-latex re-sub re-macros re-special
5803 (defun org-do-latex-and-special-faces (limit)
5804 "Run through the buffer and add overlays to links."
5805 (when org-latex-and-specials-regexp
5807 (while (and (not rtn
) (re-search-forward org-latex-and-specials-regexp
5809 (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0))
5811 '(org-code org-verbatim underline
)))
5814 d
(cond ((member (char-after (1+ (match-beginning 0)))
5817 (font-lock-prepend-text-property
5818 (+ d
(match-beginning 0)) (match-end 0)
5819 'face
'org-latex-and-export-specials
)
5820 (add-text-properties (+ d
(match-beginning 0)) (match-end 0)
5821 '(font-lock-multiline t
)))))
5824 (defun org-restart-font-lock ()
5825 "Restart `font-lock-mode', to force refontification."
5826 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5828 (font-lock-mode 1)))
5830 (defun org-all-targets (&optional radio
)
5831 "Return a list of all targets in this file.
5832 With optional argument RADIO, only find radio targets."
5833 (let ((re (if radio org-radio-target-regexp org-target-regexp
))
5836 (goto-char (point-min))
5837 (while (re-search-forward re nil t
)
5838 (add-to-list 'rtn
(downcase (org-match-string-no-properties 1))))
5841 (defun org-make-target-link-regexp (targets)
5842 "Make regular expression matching all strings in TARGETS.
5843 The regular expression finds the targets also if there is a line break
5850 (setq x
(regexp-quote x
))
5851 (while (string-match " +" x
)
5852 (setq x
(replace-match "\\s-+" t t x
)))
5858 (defun org-activate-tags (limit)
5859 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t
)
5861 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5862 (add-text-properties (match-beginning 1) (match-end 1)
5863 (list 'mouse-face
'highlight
5864 'keymap org-mouse-map
))
5865 (org-rear-nonsticky-at (match-end 1))
5868 (defun org-outline-level ()
5869 "Compute the outline level of the heading at point.
5870 This function assumes that the cursor is at the beginning of a line matched
5871 by `outline-regexp'. Otherwise it returns garbage.
5872 If this is called at a normal headline, the level is the number of stars.
5873 Use `org-reduced-level' to remove the effect of `org-odd-levels'."
5875 (looking-at org-outline-regexp
)
5876 (1- (- (match-end 0) (match-beginning 0)))))
5878 (defvar org-font-lock-keywords nil
)
5880 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\+?\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5881 "Regular expression matching a property line.")
5883 (defvar org-font-lock-hook nil
5884 "Functions to be called for special font lock stuff.")
5886 (defvar org-font-lock-set-keywords-hook nil
5887 "Functions that can manipulate `org-font-lock-extra-keywords'.
5888 This is called after `org-font-lock-extra-keywords' is defined, but before
5889 it is installed to be used by font lock. This can be useful if something
5890 needs to be inserted at a specific position in the font-lock sequence.")
5892 (defun org-font-lock-hook (limit)
5893 (run-hook-with-args 'org-font-lock-hook limit
))
5895 (defun org-set-font-lock-defaults ()
5896 (let* ((em org-fontify-emphasized-text
)
5897 (lk org-activate-links
)
5898 (org-font-lock-extra-keywords
5901 '(org-font-lock-hook)
5903 `(,(if org-fontify-whole-heading-line
5904 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
5905 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
5906 (1 (org-get-level-face 1))
5907 (2 (org-get-level-face 2))
5908 (3 (org-get-level-face 3)))
5910 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
5913 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
5914 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
5915 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
5916 '("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t
))
5918 (list org-drawer-regexp
'(0 'org-special-keyword t
))
5919 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
5921 (list org-property-re
5922 '(1 'org-special-keyword t
)
5923 '(3 'org-property-value t
))
5925 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
5926 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
5927 (if (memq 'plain lk
) '(org-activate-plain-links))
5928 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
5929 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
5930 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
5931 (if (memq 'footnote lk
) '(org-activate-footnote-links))
5932 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
5933 '(org-hide-wide-columns (0 nil append
))
5935 (list (format org-heading-keyword-regexp-format
5937 '(2 (org-get-todo-face 2) t
))
5939 (if org-fontify-done-headline
5940 (list (format org-heading-keyword-regexp-format
5943 (mapconcat 'regexp-quote org-done-keywords
"\\|")
5945 '(2 'org-headline-done t
))
5948 '(org-font-lock-add-priority-faces)
5950 '(org-font-lock-add-tag-faces)
5952 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
5953 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
5954 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
5955 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
5958 (if (featurep 'xemacs
)
5959 '(org-do-emphasis-faces (0 nil append
))
5960 '(org-do-emphasis-faces)))
5962 '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
5963 1 'org-checkbox prepend
)
5964 (if (cdr (assq 'checkbox org-list-automatic-rules
))
5965 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
5966 (0 (org-get-checkbox-statistics-face) t
)))
5967 ;; Description list items
5968 '("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+::\\)\\([ \t]+\\|$\\)"
5969 1 'org-list-dt prepend
)
5970 ;; ARCHIVEd headings
5972 org-outline-regexp-bol
5973 "\\(.*:" org-archive-tag
":.*\\)")
5974 '(1 'org-archived prepend
))
5976 '(org-do-latex-and-special-faces)
5977 '(org-fontify-entities)
5978 '(org-raise-scripts)
5980 '(org-activate-code (1 'org-code t
))
5982 (list (format org-heading-keyword-regexp-format
5984 org-comment-string
"\\|" org-quote-string
5986 '(2 'org-special-keyword t
))
5987 ;; Blocks and meta lines
5988 '(org-fontify-meta-lines-and-blocks)
5990 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
5991 (run-hooks 'org-font-lock-set-keywords-hook
)
5992 ;; Now set the full font-lock-keywords
5993 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
5994 (org-set-local 'font-lock-defaults
5995 '(org-font-lock-keywords t nil nil backward-paragraph
))
5996 (kill-local-variable 'font-lock-keywords
) nil
))
5998 (defun org-toggle-pretty-entities ()
5999 "Toggle the composition display of entities as UTF8 characters."
6001 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
6002 (org-restart-font-lock)
6003 (if org-pretty-entities
6004 (message "Entities are displayed as UTF8 characters")
6007 (org-decompose-region (point-min) (point-max))
6008 (message "Entities are displayed plain"))))
6010 (defvar org-custom-properties-overlays nil
6011 "List of overlays used for custom properties.")
6012 (make-variable-buffer-local 'org-custom-properties-overlays
)
6014 (defun org-toggle-custom-properties-visibility ()
6015 "Display or hide properties in `org-custom-properties'."
6017 (if org-custom-properties-overlays
6018 (progn (mapc 'delete-overlay org-custom-properties-overlays
)
6019 (setq org-custom-properties-overlays nil
))
6020 (unless (not org-custom-properties
)
6024 (goto-char (point-min))
6025 (while (re-search-forward org-property-re nil t
)
6027 (when (equal p
(substring (match-string 1) 1 -
1))
6028 (let ((o (make-overlay (match-beginning 0) (1+ (match-end 0)))))
6029 (overlay-put o
'invisible t
)
6030 (overlay-put o
'org-custom-property t
)
6031 (push o org-custom-properties-overlays
))))
6032 org-custom-properties
)))))))
6034 (defun org-fontify-entities (limit)
6035 "Find an entity to fontify."
6037 (when org-pretty-entities
6039 (while (re-search-forward
6040 "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]\n]\\)"
6042 (if (and (not (org-in-indented-comment-line))
6043 (setq ee
(org-entity-get (match-string 1)))
6044 (= (length (nth 6 ee
)) 1))
6046 ((end (if (equal (match-string 2) "{}")
6049 (add-text-properties
6050 (match-beginning 0) end
6051 (list 'font-lock-fontified t
))
6052 (compose-region (match-beginning 0) end
6058 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
6059 "Fontify string S like in Org-mode."
6062 (let ((org-odd-levels-only odd-levels
))
6064 (font-lock-fontify-buffer)
6070 (defun org-get-level-face (n)
6071 "Get the right face for match N in font-lock matching of headlines."
6072 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
6073 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
6074 (if org-cycle-level-faces
6075 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
6076 (setq org-f
(nth (1- (min org-l org-n-level-faces
)) org-level-faces
)))
6078 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
6080 (t (if org-level-color-stars-only nil org-f
))))
6083 (defun org-get-todo-face (kwd)
6084 "Get the right face for a TODO keyword KWD.
6085 If KWD is a number, get the corresponding match group."
6086 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
6087 (or (org-face-from-face-or-color
6088 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
6089 (and (member kwd org-done-keywords
) 'org-done
)
6092 (defun org-face-from-face-or-color (context inherit face-or-color
)
6093 "Create a face list that inherits INHERIT, but sets the foreground color.
6094 When FACE-OR-COLOR is not a string, just return it."
6095 (if (stringp face-or-color
)
6096 (list :inherit inherit
6097 (cdr (assoc context org-faces-easy-properties
))
6101 (defun org-font-lock-add-tag-faces (limit)
6102 "Add the special tag faces."
6103 (when (and org-tag-faces org-tags-special-faces-re
)
6104 (while (re-search-forward org-tags-special-faces-re limit t
)
6105 (add-text-properties (match-beginning 1) (match-end 1)
6106 (list 'face
(org-get-tag-face 1)
6107 'font-lock-fontified t
))
6108 (backward-char 1))))
6110 (defun org-font-lock-add-priority-faces (limit)
6111 "Add the special priority faces."
6112 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
6113 (when (save-match-data (org-at-heading-p))
6114 (add-text-properties
6115 (match-beginning 0) (match-end 0)
6116 (list 'face
(or (org-face-from-face-or-color
6117 'priority
'org-special-keyword
6118 (cdr (assoc (char-after (match-beginning 1))
6119 org-priority-faces
)))
6120 'org-special-keyword
)
6121 'font-lock-fontified t
)))))
6123 (defun org-get-tag-face (kwd)
6124 "Get the right face for a TODO keyword KWD.
6125 If KWD is a number, get the corresponding match group."
6126 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
6127 (or (org-face-from-face-or-color
6128 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
6131 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
6132 "Remove fontification and activation overlays from links."
6133 (font-lock-default-unfontify-region beg end
)
6134 (let* ((buffer-undo-list t
)
6135 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
6136 (inhibit-modification-hooks t
)
6137 deactivate-mark buffer-file-name buffer-file-truename
)
6138 (org-decompose-region beg end
)
6139 (remove-text-properties beg end
6140 '(mouse-face t keymap t org-linked-text t
6141 invisible t intangible t
6142 org-no-flyspell t org-emphasis t
))
6143 (org-remove-font-lock-display-properties beg end
)))
6145 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
6146 ((raise 0.3) (height 0.7))
6149 "Display properties for showing superscripts and subscripts.")
6151 (defun org-remove-font-lock-display-properties (beg end
)
6152 "Remove specific display properties that have been added by font lock.
6153 The will remove the raise properties that are used to show superscripts
6157 (setq next
(next-single-property-change beg
'display nil end
)
6158 prop
(get-text-property beg
'display
))
6159 (if (member prop org-script-display
)
6160 (put-text-property beg next
'display nil
))
6163 (defun org-raise-scripts (limit)
6164 "Add raise properties to sub/superscripts."
6165 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
6166 (if (re-search-forward
6167 (if (eq org-use-sub-superscripts t
)
6168 org-match-substring-regexp
6169 org-match-substring-with-braces-regexp
)
6171 (let* ((pos (point)) table-p comment-p
6172 (mpos (match-beginning 3))
6173 (emph-p (get-text-property mpos
'org-emphasis
))
6174 (link-p (get-text-property mpos
'mouse-face
))
6175 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
6176 (goto-char (point-at-bol))
6177 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
6178 comment-p
(org-looking-at-p "[ \t]*#"))
6180 ;; FIXME: Should we go back one character here, for a_b^c
6181 ;; (goto-char (1- pos)) ;????????????????????
6182 (if (or comment-p emph-p link-p keyw-p
)
6184 (put-text-property (match-beginning 3) (match-end 0)
6186 (if (equal (char-after (match-beginning 2)) ?^
)
6187 (nth (if table-p
3 1) org-script-display
)
6188 (nth (if table-p
2 0) org-script-display
)))
6189 (add-text-properties (match-beginning 2) (match-end 2)
6191 'org-dwidth t
'org-dwidth-n
1))
6192 (if (and (eq (char-after (match-beginning 3)) ?
{)
6193 (eq (char-before (match-end 3)) ?
}))
6195 (add-text-properties
6196 (match-beginning 3) (1+ (match-beginning 3))
6197 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
6198 (add-text-properties
6199 (1- (match-end 3)) (match-end 3)
6200 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
6203 ;;;; Visibility cycling, including org-goto and indirect buffer
6207 (defvar org-cycle-global-status nil
)
6208 (make-variable-buffer-local 'org-cycle-global-status
)
6209 (defvar org-cycle-subtree-status nil
)
6210 (make-variable-buffer-local 'org-cycle-subtree-status
)
6214 (defvar org-inlinetask-min-level
)
6216 (defun org-cycle (&optional arg
)
6217 "TAB-action and visibility cycling for Org-mode.
6219 This is the command invoked in Org-mode by the TAB key. Its main purpose
6220 is outline visibility cycling, but it also invokes other actions
6221 in special contexts.
6223 - When this function is called with a prefix argument, rotate the entire
6224 buffer through 3 states (global cycling)
6225 1. OVERVIEW: Show only top-level headlines.
6226 2. CONTENTS: Show all headlines of all levels, but no body text.
6227 3. SHOW ALL: Show everything.
6228 When called with two `C-u C-u' prefixes, switch to the startup visibility,
6229 determined by the variable `org-startup-folded', and by any VISIBILITY
6230 properties in the buffer.
6231 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
6232 including any drawers.
6234 - When inside a table, re-align the table and move to the next field.
6236 - When point is at the beginning of a headline, rotate the subtree started
6237 by this line through 3 different states (local cycling)
6238 1. FOLDED: Only the main headline is shown.
6239 2. CHILDREN: The main headline and the direct children are shown.
6240 From this state, you can move to one of the children
6241 and zoom in further.
6242 3. SUBTREE: Show the entire subtree, including body text.
6243 If there is no subtree, switch directly from CHILDREN to FOLDED.
6245 - When point is at the beginning of an empty headline and the variable
6246 `org-cycle-level-after-item/entry-creation' is set, cycle the level
6247 of the headline by demoting and promoting it to likely levels. This
6248 speeds up creation document structure by pressing TAB once or several
6249 times right after creating a new headline.
6251 - When there is a numeric prefix, go up to a heading with level ARG, do
6252 a `show-subtree' and return to the previous cursor position. If ARG
6253 is negative, go up that many levels.
6255 - When point is not at the beginning of a headline, execute the global
6256 binding for TAB, which is re-indenting the line. See the option
6257 `org-cycle-emulate-tab' for details.
6259 - Special case: if point is at the beginning of the buffer and there is
6260 no headline in line 1, this function will act as if called with prefix arg
6261 (C-u TAB, same as S-TAB) also when called without prefix arg.
6262 But only if also the variable `org-cycle-global-at-bob' is t."
6264 (org-load-modules-maybe)
6265 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
6266 (and org-cycle-level-after-item
/entry-creation
6267 (or (org-cycle-level)
6268 (org-cycle-item-indentation))))
6270 (or org-cycle-max-level
6271 (and (boundp 'org-inlinetask-min-level
)
6272 org-inlinetask-min-level
6273 (1- org-inlinetask-min-level
))))
6274 (nstars (and limit-level
6275 (if org-odd-levels-only
6276 (and limit-level
(1- (* limit-level
2)))
6279 (if (not (derived-mode-p 'org-mode
))
6281 (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ "))))
6282 (bob-special (and org-cycle-global-at-bob
(not arg
) (bobp)
6283 (not (looking-at org-outline-regexp
))))
6286 (delq 'org-optimize-window-after-visibility-change
6287 (copy-sequence org-cycle-hook
))
6291 (if (or bob-special
(equal arg
'(4)))
6292 ;; special case: use global cycling
6298 (setq last-command
'dummy
)
6299 (org-set-startup-visibility)
6300 (message "Startup visibility, plus VISIBILITY properties"))
6304 (message "Entire buffer visible, including drawers"))
6306 ;; Table: enter it or move to the next field.
6307 ((org-at-table-p 'any
)
6308 (if (org-at-table.el-p
)
6309 (message "Use C-c ' to edit table.el tables")
6310 (if arg
(org-table-edit-field t
)
6311 (org-table-justify-field-maybe)
6312 (call-interactively 'org-table-next-field
))))
6314 ((run-hook-with-args-until-success
6315 'org-tab-after-check-for-table-hook
))
6317 ;; Global cycling: delegate to `org-cycle-internal-global'.
6318 ((eq arg t
) (org-cycle-internal-global))
6320 ;; Drawers: delegate to `org-flag-drawer'.
6321 ((and org-drawers org-drawer-regexp
6323 (beginning-of-line 1)
6324 (looking-at org-drawer-regexp
)))
6325 (org-flag-drawer ; toggle block visibility
6326 (not (get-char-property (match-end 0) 'invisible
))))
6328 ;; Show-subtree, ARG levels up from here.
6331 (org-back-to-heading)
6332 (outline-up-heading (if (< arg
0) (- arg
)
6333 (- (funcall outline-level
) arg
)))
6334 (org-show-subtree)))
6336 ;; Inline task: delegate to `org-inlinetask-toggle-visibility'.
6337 ((and (featurep 'org-inlinetask
)
6338 (org-inlinetask-at-task-p)
6339 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6340 (org-inlinetask-toggle-visibility))
6342 ((org-try-cdlatex-tab))
6344 ;; At an item/headline: delegate to `org-cycle-internal-local'.
6345 ((and (or (and org-cycle-include-plain-lists
(org-at-item-p))
6346 (save-excursion (beginning-of-line 1)
6347 (looking-at org-outline-regexp
)))
6348 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6349 (org-cycle-internal-local))
6351 ;; From there: TAB emulation and template completion.
6352 (buffer-read-only (org-back-to-heading))
6354 ((run-hook-with-args-until-success
6355 'org-tab-after-check-for-cycling-hook
))
6357 ((org-try-structure-completion))
6359 ((run-hook-with-args-until-success
6360 'org-tab-before-tab-emulation-hook
))
6362 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
6364 (not (looking-at org-outline-regexp
))))
6365 (call-interactively (global-key-binding "\t")))
6367 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
6368 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
6369 (or (and (eq org-cycle-emulate-tab
'white
)
6370 (= (match-end 0) (point-at-eol)))
6371 (and (eq org-cycle-emulate-tab
'whitestart
)
6372 (>= (match-end 0) pos
))))
6374 (eq org-cycle-emulate-tab t
))
6375 (call-interactively (global-key-binding "\t")))
6378 (org-back-to-heading)
6381 (defun org-cycle-internal-global ()
6382 "Do the global cycling action."
6383 ;; Hack to avoid display of messages for .org attachments in Gnus
6384 (let ((ga (string-match "\\*fontification" (buffer-name))))
6386 ((and (eq last-command this-command
)
6387 (eq org-cycle-global-status
'overview
))
6388 ;; We just created the overview - now do table of contents
6389 ;; This can be slow in very large buffers, so indicate action
6390 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
6391 (unless ga
(message "CONTENTS..."))
6393 (unless ga
(message "CONTENTS...done"))
6394 (setq org-cycle-global-status
'contents
)
6395 (run-hook-with-args 'org-cycle-hook
'contents
))
6397 ((and (eq last-command this-command
)
6398 (eq org-cycle-global-status
'contents
))
6399 ;; We just showed the table of contents - now show everything
6400 (run-hook-with-args 'org-pre-cycle-hook
'all
)
6402 (unless ga
(message "SHOW ALL"))
6403 (setq org-cycle-global-status
'all
)
6404 (run-hook-with-args 'org-cycle-hook
'all
))
6407 ;; Default action: go to overview
6408 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
6410 (unless ga
(message "OVERVIEW"))
6411 (setq org-cycle-global-status
'overview
)
6412 (run-hook-with-args 'org-cycle-hook
'overview
)))))
6414 (defun org-cycle-internal-local ()
6415 "Do the local cycling action."
6416 (let ((goal-column 0) eoh eol eos has-children children-skipped struct
)
6417 ;; First, determine end of headline (EOH), end of subtree or item
6418 ;; (EOS), and if item or heading has children (HAS-CHILDREN).
6423 (setq struct
(org-list-struct))
6424 (setq eoh
(point-at-eol))
6425 (setq eos
(org-list-get-item-end-before-blank (point) struct
))
6426 (setq has-children
(org-list-has-child-p (point) struct
)))
6427 (org-back-to-heading)
6428 (setq eoh
(save-excursion (outline-end-of-heading) (point)))
6429 (setq eos
(save-excursion
6430 (org-end-of-subtree t
)
6432 (skip-chars-forward " \t\n"))
6433 (if (eobp) (point) (1- (point)))))
6436 (let ((level (funcall outline-level
)))
6437 (outline-next-heading)
6438 (and (org-at-heading-p t
)
6439 (> (funcall outline-level
) level
))))
6441 (org-list-search-forward (org-item-beginning-re) eos t
)))))
6442 ;; Determine end invisible part of buffer (EOL)
6443 (beginning-of-line 2)
6444 ;; XEmacs doesn't have `next-single-char-property-change'
6445 (if (featurep 'xemacs
)
6446 (while (and (not (eobp)) ;; this is like `next-line'
6447 (get-char-property (1- (point)) 'invisible
))
6448 (beginning-of-line 2))
6449 (while (and (not (eobp)) ;; this is like `next-line'
6450 (get-char-property (1- (point)) 'invisible
))
6451 (goto-char (next-single-char-property-change (point) 'invisible
))
6452 (and (eolp) (beginning-of-line 2))))
6454 ;; Find out what to do next and set `this-command'
6457 ;; Nothing is hidden behind this heading
6458 (run-hook-with-args 'org-pre-cycle-hook
'empty
)
6459 (message "EMPTY ENTRY")
6460 (setq org-cycle-subtree-status nil
)
6463 (outline-next-heading)
6464 (if (outline-invisible-p) (org-flag-heading nil
))))
6465 ((and (or (>= eol eos
)
6466 (not (string-match "\\S-" (buffer-substring eol eos
))))
6468 (not (setq children-skipped
6469 org-cycle-skip-children-state-if-no-children
))))
6470 ;; Entire subtree is hidden in one line: children view
6471 (run-hook-with-args 'org-pre-cycle-hook
'children
)
6473 (org-list-set-item-visibility (point-at-bol) struct
'children
)
6475 (org-with-limited-levels (show-children))
6476 ;; FIXME: This slows down the func way too much.
6477 ;; How keep drawers hidden in subtree anyway?
6478 ;; (when (memq 'org-cycle-hide-drawers org-cycle-hook)
6479 ;; (org-cycle-hide-drawers 'subtree))
6481 ;; Fold every list in subtree to top-level items.
6482 (when (eq org-cycle-include-plain-lists
'integrate
)
6484 (org-back-to-heading)
6485 (while (org-list-search-forward (org-item-beginning-re) eos t
)
6486 (beginning-of-line 1)
6487 (let* ((struct (org-list-struct))
6488 (prevs (org-list-prevs-alist struct
))
6489 (end (org-list-get-bottom-point struct
)))
6490 (mapc (lambda (e) (org-list-set-item-visibility e struct
'folded
))
6491 (org-list-get-all-items (point) struct prevs
))
6492 (goto-char end
))))))
6493 (message "CHILDREN")
6496 (outline-next-heading)
6497 (if (outline-invisible-p) (org-flag-heading nil
)))
6498 (setq org-cycle-subtree-status
'children
)
6499 (run-hook-with-args 'org-cycle-hook
'children
))
6500 ((or children-skipped
6501 (and (eq last-command this-command
)
6502 (eq org-cycle-subtree-status
'children
)))
6503 ;; We just showed the children, or no children are there,
6504 ;; now show everything.
6505 (run-hook-with-args 'org-pre-cycle-hook
'subtree
)
6506 (outline-flag-region eoh eos nil
)
6507 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
6508 (setq org-cycle-subtree-status
'subtree
)
6509 (run-hook-with-args 'org-cycle-hook
'subtree
))
6511 ;; Default action: hide the subtree.
6512 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
6513 (outline-flag-region eoh eos t
)
6515 (setq org-cycle-subtree-status
'folded
)
6516 (run-hook-with-args 'org-cycle-hook
'folded
)))))
6519 (defun org-global-cycle (&optional arg
)
6520 "Cycle the global visibility. For details see `org-cycle'.
6521 With \\[universal-argument] prefix arg, switch to startup visibility.
6522 With a numeric prefix, show all headlines up to that level."
6524 (let ((org-cycle-include-plain-lists
6525 (if (derived-mode-p 'org-mode
) org-cycle-include-plain-lists nil
)))
6529 (hide-sublevels arg
)
6530 (setq org-cycle-global-status
'contents
))
6532 (org-set-startup-visibility)
6533 (message "Startup visibility, plus VISIBILITY properties."))
6535 (org-cycle '(4))))))
6537 (defun org-set-startup-visibility ()
6538 "Set the visibility required by startup options and properties."
6540 ((eq org-startup-folded t
)
6542 ((eq org-startup-folded
'content
)
6543 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
6544 (org-cycle '(4)) (org-cycle '(4)))))
6545 (unless (eq org-startup-folded
'showeverything
)
6546 (if org-hide-block-startup
(org-hide-block-all))
6547 (org-set-visibility-according-to-property 'no-cleanup
)
6548 (org-cycle-hide-archived-subtrees 'all
)
6549 (org-cycle-hide-drawers 'all
)
6550 (org-cycle-show-empty-lines t
)))
6552 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
6553 "Switch subtree visibilities according to :VISIBILITY: property."
6555 (let (org-show-entry-below state
)
6557 (goto-char (point-min))
6558 (while (re-search-forward
6559 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
6561 (setq state
(match-string 1))
6563 (org-back-to-heading t
)
6567 ((equal state
'("fold" "folded"))
6569 ((equal state
"children")
6570 (org-show-hidden-entry)
6572 ((equal state
"content")
6575 (org-narrow-to-subtree)
6577 ((member state
'("all" "showall"))
6580 (org-cycle-hide-archived-subtrees 'all
)
6581 (org-cycle-hide-drawers 'all
)
6582 (org-cycle-show-empty-lines 'all
)))))
6584 ;; This function uses outline-regexp instead of the more fundamental
6585 ;; org-outline-regexp so that org-cycle-global works outside of Org
6586 ;; buffers, where outline-regexp is needed.
6587 (defun org-overview ()
6588 "Switch to overview mode, showing only top-level headlines.
6589 Really, this shows all headlines with level equal or greater than the level
6590 of the first headline in the buffer. This is important, because if the
6591 first headline is not level one, then (hide-sublevels 1) gives confusing
6594 (let ((level (save-excursion
6595 (goto-char (point-min))
6596 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
6598 (goto-char (match-beginning 0))
6599 (funcall outline-level
))))))
6600 (and level
(hide-sublevels level
))))
6602 (defun org-content (&optional arg
)
6603 "Show all headlines in the buffer, like a table of contents.
6604 With numerical argument N, show content up to level N."
6607 ;; Visit all headings and show their offspring
6608 (and (integerp arg
) (org-overview))
6609 (goto-char (point-max))
6611 (while (and (progn (condition-case nil
6612 (outline-previous-visible-heading 1)
6613 (error (goto-char (point-min))))
6615 (looking-at org-outline-regexp
))
6617 (show-children (1- arg
))
6619 (if (bobp) (throw 'exit nil
))))))
6622 (defun org-optimize-window-after-visibility-change (state)
6623 "Adjust the window after a change in outline visibility.
6624 This function is the default value of the hook `org-cycle-hook'."
6625 (when (get-buffer-window (current-buffer))
6627 ((eq state
'content
) nil
)
6628 ((eq state
'all
) nil
)
6629 ((eq state
'folded
) nil
)
6630 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
6631 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
6633 (defun org-remove-empty-overlays-at (pos)
6634 "Remove outline overlays that do not contain non-white stuff."
6637 (and (eq 'outline
(overlay-get o
'invisible
))
6638 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
6640 (delete-overlay o
)))
6643 (defun org-clean-visibility-after-subtree-move ()
6644 "Fix visibility issues after moving a subtree."
6645 ;; First, find a reasonable region to look at:
6646 ;; Start two siblings above, end three below
6647 (let* ((beg (save-excursion
6648 (and (org-get-last-sibling)
6649 (org-get-last-sibling))
6651 (end (save-excursion
6652 (and (org-get-next-sibling)
6653 (org-get-next-sibling)
6654 (org-get-next-sibling))
6655 (if (org-at-heading-p)
6658 (level (looking-at "\\*+"))
6659 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6662 (narrow-to-region beg end
)
6664 ;; Properly fold already folded siblings
6665 (goto-char (point-min))
6666 (while (re-search-forward re nil t
)
6667 (if (and (not (outline-invisible-p))
6669 (goto-char (point-at-eol)) (outline-invisible-p)))
6671 (org-cycle-show-empty-lines 'overview
)
6672 (org-cycle-hide-drawers 'overview
)))))
6674 (defun org-cycle-show-empty-lines (state)
6675 "Show empty lines above all visible headlines.
6676 The region to be covered depends on STATE when called through
6677 `org-cycle-hook'. Lisp program can use t for STATE to get the
6678 entire buffer covered. Note that an empty line is only shown if there
6679 are at least `org-cycle-separator-lines' empty lines before the headline."
6680 (when (not (= org-cycle-separator-lines
0))
6682 (let* ((n (abs org-cycle-separator-lines
))
6684 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6685 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6686 (t (let ((ns (number-to-string (- n
2))))
6687 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6688 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6691 ((memq state
'(overview contents t
))
6692 (setq beg
(point-min) end
(point-max)))
6693 ((memq state
'(children folded
))
6694 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6695 (beginning-of-line 2)
6699 (while (re-search-forward re end t
)
6700 (unless (get-char-property (match-end 1) 'invisible
)
6701 (setq e
(match-end 1))
6702 (if (< org-cycle-separator-lines
0)
6703 (setq b
(save-excursion
6704 (goto-char (match-beginning 0))
6705 (org-back-over-empty-lines)
6707 (goto-char (max (point-min) (1- (point))))
6711 (setq b
(match-beginning 1)))
6712 (outline-flag-region b e nil
)))))))
6713 ;; Never hide empty lines at the end of the file.
6715 (goto-char (point-max))
6716 (outline-previous-heading)
6717 (outline-end-of-heading)
6718 (if (and (looking-at "[ \t\n]+")
6719 (= (match-end 0) (point-max)))
6720 (outline-flag-region (point) (match-end 0) nil
))))
6722 (defun org-show-empty-lines-in-parent ()
6723 "Move to the parent and re-show empty lines before visible headlines."
6725 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6726 (org-cycle-show-empty-lines context
))))
6728 (defun org-files-list ()
6729 "Return `org-agenda-files' list, plus all open org-mode files.
6730 This is useful for operations that need to scan all of a user's
6731 open and agenda-wise Org files."
6732 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6733 (dolist (buf (buffer-list))
6734 (with-current-buffer buf
6735 (if (and (derived-mode-p 'org-mode
) (buffer-file-name))
6736 (let ((file (expand-file-name (buffer-file-name))))
6737 (unless (member file files
)
6738 (push file files
))))))
6741 (defsubst org-entry-beginning-position
()
6742 "Return the beginning position of the current entry."
6743 (save-excursion (outline-back-to-heading t
) (point)))
6745 (defsubst org-entry-end-position
()
6746 "Return the end position of the current entry."
6747 (save-excursion (outline-next-heading) (point)))
6749 (defun org-cycle-hide-drawers (state)
6750 "Re-hide all drawers after a visibility state change."
6751 (when (and (derived-mode-p 'org-mode
)
6752 (not (memq state
'(overview folded contents
))))
6754 (let* ((globalp (memq state
'(contents all
)))
6755 (beg (if globalp
(point-min) (point)))
6756 (end (if globalp
(point-max)
6757 (if (eq state
'children
)
6758 (save-excursion (outline-next-heading) (point))
6759 (org-end-of-subtree t
)))))
6761 (while (re-search-forward org-drawer-regexp end t
)
6762 (org-flag-drawer t
))))))
6764 (defun org-flag-drawer (flag)
6765 "When FLAG is non-nil, hide the drawer we are within.
6766 Otherwise make it visible."
6768 (beginning-of-line 1)
6769 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6770 (let ((b (match-end 0)))
6771 (if (re-search-forward
6773 (save-excursion (outline-next-heading) (point)) t
)
6774 (outline-flag-region b
(point-at-eol) flag
)
6775 (error ":END: line missing at position %s" b
))))))
6777 (defun org-subtree-end-visible-p ()
6778 "Is the end of the current subtree visible?"
6779 (pos-visible-in-window-p
6780 (save-excursion (org-end-of-subtree t
) (point))))
6782 (defun org-first-headline-recenter (&optional N
)
6783 "Move cursor to the first headline and recenter the headline.
6784 Optional argument N means put the headline into the Nth line of the window."
6785 (goto-char (point-min))
6786 (when (re-search-forward (concat "^\\(" org-outline-regexp
"\\)") nil t
)
6788 (recenter (prefix-numeric-value N
))))
6790 ;;; Saving and restoring visibility
6792 (defun org-outline-overlay-data (&optional use-markers
)
6793 "Return a list of the locations of all outline overlays.
6794 These are overlays with the `invisible' property value `outline'.
6795 The return value is a list of cons cells, with start and stop
6796 positions for each overlay.
6797 If USE-MARKERS is set, return the positions as markers."
6804 (when (eq (overlay-get o
'invisible
) 'outline
)
6805 (setq beg
(overlay-start o
)
6806 end
(overlay-end o
))
6807 (and beg end
(> end beg
)
6809 (cons (move-marker (make-marker) beg
)
6810 (move-marker (make-marker) end
))
6812 (overlays-in (point-min) (point-max))))))))
6814 (defun org-set-outline-overlay-data (data)
6815 "Create visibility overlays for all positions in DATA.
6816 DATA should have been made by `org-outline-overlay-data'."
6823 (outline-flag-region (car c
) (cdr c
) t
))
6826 ;;; Folding of blocks
6828 (defvar org-hide-block-overlays nil
6829 "Overlays hiding blocks.")
6830 (make-variable-buffer-local 'org-hide-block-overlays
)
6832 (defun org-block-map (function &optional start end
)
6833 "Call FUNCTION at the head of all source blocks in the current buffer.
6834 Optional arguments START and END can be used to limit the range."
6835 (let ((start (or start
(point-min)))
6836 (end (or end
(point-max))))
6839 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6842 (goto-char (match-beginning 0))
6843 (funcall function
)))))))
6845 (defun org-hide-block-toggle-all ()
6846 "Toggle the visibility of all blocks in the current buffer."
6847 (org-block-map #'org-hide-block-toggle
))
6849 (defun org-hide-block-all ()
6850 "Fold all blocks in the current buffer."
6852 (org-show-block-all)
6853 (org-block-map #'org-hide-block-toggle-maybe
))
6855 (defun org-show-block-all ()
6856 "Unfold all blocks in the current buffer."
6858 (mapc 'delete-overlay org-hide-block-overlays
)
6859 (setq org-hide-block-overlays nil
))
6861 (defun org-hide-block-toggle-maybe ()
6862 "Toggle visibility of block at point."
6864 (let ((case-fold-search t
))
6866 (beginning-of-line 1)
6867 (looking-at org-block-regexp
))
6868 (progn (org-hide-block-toggle)
6869 t
) ;; to signal that we took action
6870 nil
))) ;; to signal that we did not
6872 (defun org-hide-block-toggle (&optional force
)
6873 "Toggle the visibility of the current block."
6877 (if (re-search-forward org-block-regexp nil t
)
6878 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
6879 (end (match-end 0)) ;; end of entire body
6881 (if (memq t
(mapcar (lambda (overlay)
6882 (eq (overlay-get overlay
'invisible
)
6884 (overlays-at start
)))
6885 (if (or (not force
) (eq force
'off
))
6887 (when (member ov org-hide-block-overlays
)
6888 (setq org-hide-block-overlays
6889 (delq ov org-hide-block-overlays
)))
6890 (when (eq (overlay-get ov
'invisible
)
6892 (delete-overlay ov
)))
6893 (overlays-at start
)))
6894 (setq ov
(make-overlay start end
))
6895 (overlay-put ov
'invisible
'org-hide-block
)
6896 ;; make the block accessible to isearch
6898 ov
'isearch-open-invisible
6900 (when (member ov org-hide-block-overlays
)
6901 (setq org-hide-block-overlays
6902 (delq ov org-hide-block-overlays
)))
6903 (when (eq (overlay-get ov
'invisible
)
6905 (delete-overlay ov
))))
6906 (push ov org-hide-block-overlays
)))
6907 (error "Not looking at a source block"))))
6909 ;; org-tab-after-check-for-cycling-hook
6910 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
6911 ;; Remove overlays when changing major mode
6912 (add-hook 'org-mode-hook
6913 (lambda () (org-add-hook 'change-major-mode-hook
6914 'org-show-block-all
'append
'local
)))
6918 (defvar org-goto-window-configuration nil
)
6919 (defvar org-goto-marker nil
)
6920 (defvar org-goto-map
6921 (let ((map (make-sparse-keymap)))
6922 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur
)) cmd
)
6923 (while (setq cmd
(pop cmds
))
6924 (substitute-key-definition cmd cmd map global-map
)))
6925 (suppress-keymap map
)
6926 (org-defkey map
"\C-m" 'org-goto-ret
)
6927 (org-defkey map
[(return)] 'org-goto-ret
)
6928 (org-defkey map
[(left)] 'org-goto-left
)
6929 (org-defkey map
[(right)] 'org-goto-right
)
6930 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
6931 (org-defkey map
"\C-i" 'org-cycle
)
6932 (org-defkey map
[(tab)] 'org-cycle
)
6933 (org-defkey map
[(down)] 'outline-next-visible-heading
)
6934 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
6935 (if org-goto-auto-isearch
6936 (if (fboundp 'define-key-after
)
6937 (define-key-after map
[t] 'org-goto-local-auto-isearch)
6939 (org-defkey map "q" 'org-goto-quit)
6940 (org-defkey map "n" 'outline-next-visible-heading)
6941 (org-defkey map "p" 'outline-previous-visible-heading)
6942 (org-defkey map "f" 'outline-forward-same-level)
6943 (org-defkey map "b" 'outline-backward-same-level)
6944 (org-defkey map "u" 'outline-up-heading))
6945 (org-defkey map "/" 'org-occur)
6946 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
6947 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
6948 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
6949 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
6950 (org-defkey map "\C-c\C-u" 'outline-up-heading)
6953 (defconst org-goto-help
6954 "Browse buffer copy, to find location or copy text. Just type for auto-isearch.
6955 RET=jump to location [Q]uit and return to previous location
6956 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
6958 (defvar org-goto-start-pos) ; dynamically scoped parameter
6960 ;; FIXME: Docstring does not mention both interfaces
6961 (defun org-goto (&optional alternative-interface)
6962 "Look up a different location in the current file, keeping current visibility.
6964 When you want look-up or go to a different location in a
6965 document, the fastest way is often to fold the entire buffer and
6966 then dive into the tree. This method has the disadvantage, that
6967 the previous location will be folded, which may not be what you
6970 This command works around this by showing a copy of the current
6971 buffer in an indirect buffer, in overview mode. You can dive
6972 into the tree in that copy, use org-occur and incremental search
6973 to find a location. When pressing RET or `Q', the command
6974 returns to the original buffer in which the visibility is still
6975 unchanged. After RET it will also jump to the location selected
6976 in the indirect buffer and expose the headline hierarchy above.
6978 With a prefix argument, use the alternative interface: e.g. if
6979 `org-goto-interface' is 'outline use 'outline-path-completion."
6981 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
6982 (org-refile-use-outline-path t)
6983 (org-refile-target-verify-function nil)
6985 (if (not alternative-interface)
6987 (if (eq org-goto-interface 'outline)
6988 'outline-path-completion
6990 (org-goto-start-pos (point))
6992 (if (eq interface 'outline)
6993 (car (org-get-location (current-buffer) org-goto-help))
6994 (let ((pa (org-refile-get-location "Goto" nil nil t)))
6995 (org-refile-check-position pa)
6999 (org-mark-ring-push org-goto-start-pos)
7000 (goto-char selected-point)
7001 (if (or (outline-invisible-p) (org-invisible-p2))
7002 (org-show-context 'org-goto)))
7005 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
7006 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
7007 (defvar org-goto-local-auto-isearch-map) ; defined below
7009 (defun org-get-location (buf help)
7010 "Let the user select a location in the Org-mode buffer BUF.
7011 This function uses a recursive edit. It returns the selected position
7013 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
7014 (isearch-hide-immediately nil)
7015 (isearch-search-fun-function
7016 (lambda () 'org-goto-local-search-headings))
7017 (org-goto-selected-point org-goto-exit-command)
7019 (special-display-buffer-names nil)
7020 (special-display-regexps nil)
7021 (special-display-function nil))
7023 (save-window-excursion
7024 (delete-other-windows)
7025 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
7026 (org-pop-to-buffer-same-window
7028 (make-indirect-buffer (current-buffer) "*org-goto*")
7029 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
7030 (with-output-to-temp-buffer "*Help*"
7032 (org-fit-window-to-buffer (get-buffer-window "*Help*"))
7033 (setq buffer-read-only nil)
7034 (let ((org-startup-truncated t)
7035 (org-startup-folded nil)
7036 (org-startup-align-all-tables nil))
7039 (setq buffer-read-only t)
7040 (if (and (boundp 'org-goto-start-pos)
7041 (integer-or-marker-p org-goto-start-pos))
7042 (let ((org-show-hierarchy-above t)
7043 (org-show-siblings t)
7044 (org-show-following-heading t))
7045 (goto-char org-goto-start-pos)
7046 (and (outline-invisible-p) (org-show-context)))
7047 (goto-char (point-min)))
7048 (let (org-special-ctrl-a/e) (org-beginning-of-line))
7049 (message "Select location and press RET")
7050 (use-local-map org-goto-map)
7053 (kill-buffer "*org-goto*")
7054 (cons org-goto-selected-point org-goto-exit-command)))
7056 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
7057 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
7058 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
7059 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
7061 (defun org-goto-local-search-headings (string bound noerror)
7062 "Search and make sure that any matches are in headlines."
7064 (while (if isearch-forward
7065 (search-forward string bound noerror)
7066 (search-backward string bound noerror))
7067 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
7068 (and (member :headline context)
7069 (not (member :tags context))))
7070 (throw 'return (point))))))
7072 (defun org-goto-local-auto-isearch ()
7075 (goto-char (point-min))
7076 (let ((keys (this-command-keys)))
7077 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
7079 (isearch-process-search-char (string-to-char keys)))))
7081 (defun org-goto-ret (&optional arg)
7082 "Finish `org-goto' by going to the new location."
7084 (setq org-goto-selected-point (point)
7085 org-goto-exit-command 'return)
7088 (defun org-goto-left ()
7089 "Finish `org-goto' by going to the new location."
7091 (if (org-at-heading-p)
7093 (beginning-of-line 1)
7094 (setq org-goto-selected-point (point)
7095 org-goto-exit-command 'left)
7097 (error "Not on a heading")))
7099 (defun org-goto-right ()
7100 "Finish `org-goto' by going to the new location."
7102 (if (org-at-heading-p)
7104 (setq org-goto-selected-point (point)
7105 org-goto-exit-command 'right)
7107 (error "Not on a heading")))
7109 (defun org-goto-quit ()
7110 "Finish `org-goto' without cursor motion."
7112 (setq org-goto-selected-point nil)
7113 (setq org-goto-exit-command 'quit)
7116 ;;; Indirect buffer display of subtrees
7118 (defvar org-indirect-dedicated-frame nil
7119 "This is the frame being used for indirect tree display.")
7120 (defvar org-last-indirect-buffer nil)
7122 (defun org-tree-to-indirect-buffer (&optional arg)
7123 "Create indirect buffer and narrow it to current subtree.
7124 With numerical prefix ARG, go up to this level and then take that tree.
7125 If ARG is negative, go up that many levels.
7126 If `org-indirect-buffer-display' is not `new-frame', the command removes the
7127 indirect buffer previously made with this command, to avoid proliferation of
7128 indirect buffers. However, when you call the command with a \
7129 \\[universal-argument] prefix, or
7130 when `org-indirect-buffer-display' is `new-frame', the last buffer
7131 is kept so that you can work with several indirect buffers at the same time.
7132 If `org-indirect-buffer-display' is `dedicated-frame', the \
7133 \\[universal-argument] prefix also
7134 requests that a new frame be made for the new buffer, so that the dedicated
7135 frame is not changed."
7137 (let ((cbuf (current-buffer))
7138 (cwin (selected-window))
7140 beg end level heading ibuf)
7142 (org-back-to-heading t)
7144 (setq level (org-outline-level))
7145 (if (< arg 0) (setq arg (+ level arg)))
7146 (while (> (setq level (org-outline-level)) arg)
7147 (outline-up-heading 1 t)))
7149 heading (org-get-heading))
7150 (org-end-of-subtree t t)
7151 (if (org-at-heading-p) (backward-char 1))
7153 (if (and (buffer-live-p org-last-indirect-buffer)
7154 (not (eq org-indirect-buffer-display 'new-frame))
7156 (kill-buffer org-last-indirect-buffer))
7157 (setq ibuf (org-get-indirect-buffer cbuf)
7158 org-last-indirect-buffer ibuf)
7160 ((or (eq org-indirect-buffer-display 'new-frame)
7161 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
7162 (select-frame (make-frame))
7163 (delete-other-windows)
7164 (org-pop-to-buffer-same-window ibuf)
7165 (org-set-frame-title heading))
7166 ((eq org-indirect-buffer-display 'dedicated-frame)
7168 (select-frame (or (and org-indirect-dedicated-frame
7169 (frame-live-p org-indirect-dedicated-frame)
7170 org-indirect-dedicated-frame)
7171 (setq org-indirect-dedicated-frame (make-frame)))))
7172 (delete-other-windows)
7173 (org-pop-to-buffer-same-window ibuf)
7174 (org-set-frame-title (concat "Indirect: " heading)))
7175 ((eq org-indirect-buffer-display 'current-window)
7176 (org-pop-to-buffer-same-window ibuf))
7177 ((eq org-indirect-buffer-display 'other-window)
7178 (pop-to-buffer ibuf))
7179 (t (error "Invalid value")))
7180 (if (featurep 'xemacs)
7181 (save-excursion (org-mode) (turn-on-font-lock)))
7182 (narrow-to-region beg end)
7185 (run-hook-with-args 'org-cycle-hook 'all)
7186 (and (window-live-p cwin) (select-window cwin))))
7188 (defun org-get-indirect-buffer (&optional buffer)
7189 (setq buffer (or buffer (current-buffer)))
7190 (let ((n 1) (base (buffer-name buffer)) bname)
7191 (while (buffer-live-p
7192 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
7195 (make-indirect-buffer buffer bname 'clone)
7196 (error (make-indirect-buffer buffer bname)))))
7198 (defun org-set-frame-title (title)
7199 "Set the title of the current frame to the string TITLE."
7200 ;; FIXME: how to name a single frame in XEmacs???
7201 (unless (featurep 'xemacs)
7202 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
7204 ;;;; Structure editing
7206 ;;; Inserting headlines
7208 (defun org-previous-line-empty-p ()
7211 (or (beginning-of-line 0) t)
7213 (looking-at "[ \t]*$")))))
7215 (defun org-insert-heading (&optional force-heading invisible-ok)
7216 "Insert a new heading or item with same depth at point.
7217 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
7218 If point is at the beginning of a headline, insert a sibling before the
7219 current headline. If point is not at the beginning, split the line,
7220 create the new headline with the text in the current line after point
7221 \(but see also the variable `org-M-RET-may-split-line').
7223 When INVISIBLE-OK is set, stop at invisible headlines when going back.
7224 This is important for non-interactive uses of the command."
7226 (if (or (= (buffer-size) 0)
7227 (and (not (save-excursion
7228 (and (ignore-errors (org-back-to-heading invisible-ok))
7229 (org-at-heading-p))))
7230 (or force-heading (not (org-in-item-p)))))
7233 (run-hooks 'org-insert-heading-hook))
7234 (when (or force-heading (not (org-insert-item)))
7235 (let* ((empty-line-p nil)
7237 (on-heading (org-at-heading-p))
7238 (head (save-excursion
7241 (org-back-to-heading invisible-ok)
7242 (when (and (not on-heading)
7243 (featurep 'org-inlinetask)
7244 (integerp org-inlinetask-min-level)
7245 (>= (length (match-string 0))
7246 org-inlinetask-min-level))
7247 ;; Find a heading level before the inline task
7248 (while (and (setq level (org-up-heading-safe))
7249 (>= level org-inlinetask-min-level)))
7250 (if (org-at-heading-p)
7251 (org-back-to-heading invisible-ok)
7252 (error "This should not happen")))
7253 (setq empty-line-p (org-previous-line-empty-p))
7256 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
7257 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
7258 pos hide-previous previous-pos)
7260 ((and (org-at-heading-p) (bolp)
7262 (save-excursion (backward-char 1) (not (outline-invisible-p)))))
7263 ;; insert before the current line
7264 (open-line (if blank 2 1)))
7266 (not org-insert-heading-respect-content)
7269 (backward-char 1) (not (outline-invisible-p)))))
7270 ;; insert right here
7273 ;; somewhere in the line
7275 (setq previous-pos (point-at-bol))
7277 (setq hide-previous (outline-invisible-p)))
7278 (and org-insert-heading-respect-content (org-show-subtree))
7280 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
7283 (goto-char (point-at-bol))
7284 (and (looking-at org-complex-heading-regexp)
7286 (> p (match-beginning 4)))))))
7289 (org-insert-heading-respect-content
7290 (org-end-of-subtree nil t)
7291 (when (featurep 'org-inlinetask)
7292 (while (and (not (eobp))
7293 (looking-at "\\(\\*+\\)[ \t]+")
7294 (>= (length (match-string 1))
7295 org-inlinetask-min-level))
7296 (org-end-of-subtree nil t)))
7297 (or (bolp) (newline))
7298 (or (org-previous-line-empty-p)
7299 (and blank (newline)))
7305 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ \t]*$")
7306 (setq tags (and (match-end 2) (match-string 2)))
7308 (delete-region (match-beginning 1) (match-end 1)))
7309 (setq pos (point-at-bol))
7310 (or split (end-of-line 1))
7311 (delete-horizontal-space)
7312 (if (string-match "\\`\\*+\\'"
7313 (buffer-substring (point-at-bol) (point)))
7315 (newline (if blank 2 1))
7321 (org-set-tags nil 'align))))
7323 (or split (end-of-line 1))
7324 (newline (if blank 2 1)))))))
7325 (insert head) (just-one-space)
7328 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
7329 (when (and org-insert-heading-respect-content hide-previous)
7331 (goto-char previous-pos)
7333 (run-hooks 'org-insert-heading-hook)))))
7335 (defun org-get-heading (&optional no-tags no-todo)
7336 "Return the heading of the current entry, without the stars.
7337 When NO-TAGS is non-nil, don't include tags.
7338 When NO-TODO is non-nil, don't include TODO keywords."
7340 (org-back-to-heading t)
7342 ((and no-tags no-todo)
7343 (looking-at org-complex-heading-regexp)
7346 (looking-at (concat org-outline-regexp
7348 "\\(?:[ \t]+:[[:alnum:]:_@#%]+:\\)?[ \t]*$"))
7351 (looking-at org-todo-line-regexp)
7353 (t (looking-at org-heading-regexp)
7354 (match-string 2)))))
7356 (defun org-heading-components ()
7357 "Return the components of the current heading.
7358 This is a list with the following elements:
7359 - the level as an integer
7360 - the reduced level, different if `org-odd-levels-only' is set.
7361 - the TODO keyword, or nil
7362 - the priority character, like ?A, or nil if no priority is given
7363 - the headline text itself, or the tags string if no headline text
7364 - the tags string, or nil."
7366 (org-back-to-heading t)
7367 (if (let (case-fold-search) (looking-at org-complex-heading-regexp))
7368 (list (length (match-string 1))
7369 (org-reduced-level (length (match-string 1)))
7370 (org-match-string-no-properties 2)
7371 (and (match-end 3) (aref (match-string 3) 2))
7372 (org-match-string-no-properties 4)
7373 (org-match-string-no-properties 5)))))
7375 (defun org-get-entry ()
7376 "Get the entry text, after heading, entire subtree."
7378 (org-back-to-heading t)
7379 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
7381 (defun org-insert-heading-after-current ()
7382 "Insert a new heading with same level as current, after current subtree."
7384 (org-back-to-heading)
7385 (org-insert-heading)
7386 (org-move-subtree-down)
7389 (defun org-insert-heading-respect-content ()
7391 (let ((org-insert-heading-respect-content t))
7392 (org-insert-heading t)))
7394 (defun org-insert-todo-heading-respect-content (&optional force-state)
7396 (let ((org-insert-heading-respect-content t))
7397 (org-insert-todo-heading force-state t)))
7399 (defun org-insert-todo-heading (arg &optional force-heading)
7400 "Insert a new heading with the same level and TODO state as current heading.
7401 If the heading has no TODO state, or if the state is DONE, use the first
7402 state (TODO by default). Also with prefix arg, force first state."
7404 (when (or force-heading (not (org-insert-item 'checkbox)))
7405 (org-insert-heading force-heading)
7407 (org-back-to-heading)
7408 (outline-previous-heading)
7409 (looking-at org-todo-line-regexp))
7413 (not (match-beginning 2))
7414 (member (match-string 2) org-done-keywords))
7415 (car org-todo-keywords-1)
7419 (run-hook-with-args-until-success
7420 'org-todo-get-default-hook new-mark-x nil)
7422 (beginning-of-line 1)
7423 (and (looking-at org-outline-regexp) (goto-char (match-end 0))
7424 (if org-treat-insert-todo-heading-as-state-change
7426 (insert new-mark " "))))
7427 (when org-provide-todo-statistics
7428 (org-update-parent-todo-statistics))))
7430 (defun org-insert-subheading (arg)
7431 "Insert a new subheading and demote it.
7432 Works for outline headings and for plain lists alike."
7434 (org-insert-heading arg)
7436 ((org-at-heading-p) (org-do-demote))
7437 ((org-at-item-p) (org-indent-item))))
7439 (defun org-insert-todo-subheading (arg)
7440 "Insert a new subheading with TODO keyword or checkbox and demote it.
7441 Works for outline headings and for plain lists alike."
7443 (org-insert-todo-heading arg)
7445 ((org-at-heading-p) (org-do-demote))
7446 ((org-at-item-p) (org-indent-item))))
7448 ;;; Promotion and Demotion
7450 (defvar org-after-demote-entry-hook nil
7451 "Hook run after an entry has been demoted.
7452 The cursor will be at the beginning of the entry.
7453 When a subtree is being demoted, the hook will be called for each node.")
7455 (defvar org-after-promote-entry-hook nil
7456 "Hook run after an entry has been promoted.
7457 The cursor will be at the beginning of the entry.
7458 When a subtree is being promoted, the hook will be called for each node.")
7460 (defun org-promote-subtree ()
7461 "Promote the entire subtree.
7462 See also `org-promote'."
7465 (org-with-limited-levels (org-map-tree 'org-promote)))
7466 (org-fix-position-after-promote))
7468 (defun org-demote-subtree ()
7469 "Demote the entire subtree. See `org-demote'.
7470 See also `org-promote'."
7473 (org-with-limited-levels (org-map-tree 'org-demote)))
7474 (org-fix-position-after-promote))
7477 (defun org-do-promote ()
7478 "Promote the current heading higher up the tree.
7479 If the region is active in `transient-mark-mode', promote all headings
7483 (if (org-region-active-p)
7484 (org-map-region 'org-promote (region-beginning) (region-end))
7486 (org-fix-position-after-promote))
7488 (defun org-do-demote ()
7489 "Demote the current heading lower down the tree.
7490 If the region is active in `transient-mark-mode', demote all headings
7494 (if (org-region-active-p)
7495 (org-map-region 'org-demote (region-beginning) (region-end))
7497 (org-fix-position-after-promote))
7499 (defun org-fix-position-after-promote ()
7500 "Make sure that after pro/demotion cursor position is right."
7501 (let ((pos (point)))
7502 (when (save-excursion
7503 (beginning-of-line 1)
7504 (looking-at org-todo-line-regexp)
7505 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
7506 (cond ((eobp) (insert " "))
7507 ((eolp) (insert " "))
7508 ((equal (char-after) ?\ ) (forward-char 1))))))
7510 (defun org-current-level ()
7511 "Return the level of the current entry, or nil if before the first headline.
7512 The level is the number of stars at the beginning of the headline."
7514 (org-with-limited-levels
7515 (if (ignore-errors (org-back-to-heading t))
7516 (funcall outline-level)))))
7518 (defun org-get-previous-line-level ()
7519 "Return the outline depth of the last headline before the current line.
7520 Returns 0 for the first headline in the buffer, and nil if before the
7522 (let ((current-level (org-current-level))
7523 (prev-level (when (> (line-number-at-pos) 1)
7525 (beginning-of-line 0)
7526 (org-current-level)))))
7527 (cond ((null current-level) nil) ; Before first headline
7528 ((null prev-level) 0) ; At first headline
7531 (defun org-reduced-level (l)
7532 "Compute the effective level of a heading.
7533 This takes into account the setting of `org-odd-levels-only'."
7536 (org-odd-levels-only (1+ (floor (/ l 2))))
7539 (defun org-level-increment ()
7540 "Return the number of stars that will be added or removed at a
7541 time to headlines when structure editing, based on the value of
7542 `org-odd-levels-only'."
7543 (if org-odd-levels-only 2 1))
7545 (defun org-get-valid-level (level &optional change)
7546 "Rectify a level change under the influence of `org-odd-levels-only'
7547 LEVEL is a current level, CHANGE is by how much the level should be
7548 modified. Even if CHANGE is nil, LEVEL may be returned modified because
7549 even level numbers will become the next higher odd number."
7550 (if org-odd-levels-only
7551 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
7552 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
7553 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
7554 (max 1 (+ level (or change 0)))))
7556 (if (boundp 'define-obsolete-function-alias)
7557 (if (or (featurep 'xemacs) (< emacs-major-version 23))
7558 (define-obsolete-function-alias 'org-get-legal-level
7559 'org-get-valid-level)
7560 (define-obsolete-function-alias 'org-get-legal-level
7561 'org-get-valid-level "23.1")))
7563 (defvar org-called-with-limited-levels nil) ;; Dynamically bound in
7564 ;; ̀org-with-limited-levels'
7565 (defun org-promote ()
7566 "Promote the current heading higher up the tree.
7567 If the region is active in `transient-mark-mode', promote all headings
7569 (org-back-to-heading t)
7570 (let* ((level (save-match-data (funcall outline-level)))
7571 (after-change-functions (remove 'flyspell-after-change-function
7572 after-change-functions))
7573 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
7574 (diff (abs (- level (length up-head) -1))))
7575 (cond ((and (= level 1) org-called-with-limited-levels
7576 org-allow-promoting-top-level-subtree)
7577 (replace-match "# " nil t))
7579 (error "Cannot promote to level 0. UNDO to recover if necessary"))
7580 (t (replace-match up-head nil t)))
7581 ;; Fixup tag positioning
7583 (and org-auto-align-tags (org-set-tags nil t))
7584 (if org-adapt-indentation (org-fixup-indentation (- diff))))
7585 (run-hooks 'org-after-promote-entry-hook)))
7587 (defun org-demote ()
7588 "Demote the current heading lower down the tree.
7589 If the region is active in `transient-mark-mode', demote all headings
7591 (org-back-to-heading t)
7592 (let* ((level (save-match-data (funcall outline-level)))
7593 (after-change-functions (remove 'flyspell-after-change-function
7594 after-change-functions))
7595 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
7596 (diff (abs (- level (length down-head) -1))))
7597 (replace-match down-head nil t)
7598 ;; Fixup tag positioning
7599 (and org-auto-align-tags (org-set-tags nil t))
7600 (if org-adapt-indentation (org-fixup-indentation diff))
7601 (run-hooks 'org-after-demote-entry-hook)))
7603 (defun org-cycle-level ()
7604 "Cycle the level of an empty headline through possible states.
7605 This goes first to child, then to parent, level, then up the hierarchy.
7606 After top level, it switches back to sibling level."
7608 (let ((org-adapt-indentation nil))
7609 (when (org-point-at-end-of-empty-headline)
7610 (setq this-command 'org-cycle-level) ; Only needed for caching
7611 (let ((cur-level (org-current-level))
7612 (prev-level (org-get-previous-line-level)))
7614 ;; If first headline in file, promote to top-level.
7616 (loop repeat (/ (- cur-level 1) (org-level-increment))
7617 do (org-do-promote)))
7618 ;; If same level as prev, demote one.
7619 ((= prev-level cur-level)
7621 ;; If parent is top-level, promote to top level if not already.
7623 (loop repeat (/ (- cur-level 1) (org-level-increment))
7624 do (org-do-promote)))
7625 ;; If top-level, return to prev-level.
7627 (loop repeat (/ (- prev-level 1) (org-level-increment))
7628 do (org-do-demote)))
7629 ;; If less than prev-level, promote one.
7630 ((< cur-level prev-level)
7632 ;; If deeper than prev-level, promote until higher than
7634 ((> cur-level prev-level)
7635 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
7636 do (org-do-promote))))
7639 (defun org-map-tree (fun)
7640 "Call FUN for every heading underneath the current one."
7641 (org-back-to-heading)
7642 (let ((level (funcall outline-level)))
7646 (outline-next-heading)
7647 (> (funcall outline-level) level))
7651 (defun org-map-region (fun beg end)
7652 "Call FUN for every heading between BEG and END."
7653 (let ((org-ignore-region t))
7655 (setq end (copy-marker end))
7657 (if (and (re-search-forward org-outline-regexp-bol nil t)
7661 (outline-next-heading)
7666 (defvar org-property-end-re) ; silence byte-compiler
7667 (defun org-fixup-indentation (diff)
7668 "Change the indentation in the current entry by DIFF.
7669 However, if any line in the current entry has no indentation, or if it
7670 would end up with no indentation after the change, nothing at all is done."
7672 (let ((end (save-excursion (outline-next-heading)
7674 (prohibit (if (> diff 0)
7676 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
7678 (unless (save-excursion (end-of-line 1)
7679 (re-search-forward prohibit end t))
7680 (while (and (< (point) end)
7681 (re-search-forward "^[ \t]+" end t))
7682 (goto-char (match-end 0))
7683 (setq col (current-column))
7684 (if (< diff 0) (replace-match ""))
7685 (org-indent-to-column (+ diff col))))
7686 (move-marker end nil))))
7688 (defun org-convert-to-odd-levels ()
7689 "Convert an org-mode file with all levels allowed to one with odd levels.
7690 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7693 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7694 (let ((outline-level 'org-outline-level)
7695 (org-odd-levels-only nil) n)
7697 (goto-char (point-min))
7698 (while (re-search-forward "^\\*\\*+ " nil t)
7699 (setq n (- (length (match-string 0)) 2))
7700 (while (>= (setq n (1- n)) 0)
7702 (end-of-line 1))))))
7704 (defun org-convert-to-oddeven-levels ()
7705 "Convert an org-mode file with only odd levels to one with odd/even levels.
7706 This promotes level 3 to level 2, level 5 to level 3 etc. If the
7707 file contains a section with an even level, conversion would
7708 destroy the structure of the file. An error is signaled in this
7711 (goto-char (point-min))
7712 ;; First check if there are no even levels
7713 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7714 (org-show-context t)
7715 (error "Not all levels are odd in this file. Conversion not possible"))
7716 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7717 (let ((outline-regexp org-outline-regexp)
7718 (outline-level 'org-outline-level)
7719 (org-odd-levels-only nil) n)
7721 (goto-char (point-min))
7722 (while (re-search-forward "^\\*\\*+ " nil t)
7723 (setq n (/ (1- (length (match-string 0))) 2))
7724 (while (>= (setq n (1- n)) 0)
7726 (end-of-line 1))))))
7728 (defun org-tr-level (n)
7729 "Make N odd if required."
7730 (if org-odd-levels-only (1+ (/ n 2)) n))
7732 ;;; Vertical tree motion, cutting and pasting of subtrees
7734 (defun org-move-subtree-up (&optional arg)
7735 "Move the current subtree up past ARG headlines of the same level."
7737 (org-move-subtree-down (- (prefix-numeric-value arg))))
7739 (defun org-move-subtree-down (&optional arg)
7740 "Move the current subtree down past ARG headlines of the same level."
7742 (setq arg (prefix-numeric-value arg))
7743 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7744 'org-get-last-sibling))
7745 (ins-point (make-marker))
7747 (col (current-column))
7748 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7750 (org-back-to-heading)
7753 (setq ne-beg (org-back-over-empty-lines))
7756 (save-excursion (outline-end-of-heading)
7757 (setq folded (outline-invisible-p)))
7758 (outline-end-of-subtree))
7759 (outline-next-heading)
7760 (setq ne-end (org-back-over-empty-lines))
7763 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7764 ;; include less whitespace
7767 (forward-line (- ne-beg ne-end))
7768 (setq beg (point))))
7769 ;; Find insertion point, with error handling
7771 (or (and (funcall movfunc) (looking-at org-outline-regexp))
7772 (progn (goto-char beg0)
7773 (error "Cannot move past superior level or buffer limit")))
7774 (setq cnt (1- cnt)))
7776 ;; Moving forward - still need to move over subtree
7777 (progn (org-end-of-subtree t t)
7779 (org-back-over-empty-lines)
7780 (or (bolp) (newline)))))
7781 (setq ne-ins (org-back-over-empty-lines))
7782 (move-marker ins-point (point))
7783 (setq txt (buffer-substring beg end))
7784 (org-save-markers-in-region beg end)
7785 (delete-region beg end)
7786 (org-remove-empty-overlays-at beg)
7787 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7788 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7789 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7790 (let ((bbb (point)))
7791 (insert-before-markers txt)
7792 (org-reinstall-markers-in-region bbb)
7793 (move-marker ins-point bbb))
7794 (or (bolp) (insert "\n"))
7795 (setq ins-end (point))
7796 (goto-char ins-point)
7797 (org-skip-whitespace)
7798 (when (and (< arg 0)
7799 (org-first-sibling-p)
7801 ;; Move whitespace back to beginning
7804 (let ((kill-whole-line t))
7805 (kill-line (- ne-ins ne-beg)) (point)))
7806 (insert (make-string (- ne-ins ne-beg) ?\n)))
7807 (move-marker ins-point nil)
7812 (org-cycle-hide-drawers 'children))
7813 (org-clean-visibility-after-subtree-move)
7814 ;; move back to the initial column we were at
7815 (move-to-column col)))
7817 (defvar org-subtree-clip ""
7818 "Clipboard for cut and paste of subtrees.
7819 This is actually only a copy of the kill, because we use the normal kill
7820 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7822 (defvar org-subtree-clip-folded nil
7823 "Was the last copied subtree folded?
7824 This is used to fold the tree back after pasting.")
7826 (defun org-cut-subtree (&optional n)
7827 "Cut the current subtree into the clipboard.
7828 With prefix arg N, cut this many sequential subtrees.
7829 This is a short-hand for marking the subtree and then cutting it."
7831 (org-copy-subtree n 'cut))
7833 (defun org-copy-subtree (&optional n cut force-store-markers)
7834 "Cut the current subtree into the clipboard.
7835 With prefix arg N, cut this many sequential subtrees.
7836 This is a short-hand for marking the subtree and then copying it.
7837 If CUT is non-nil, actually cut the subtree.
7838 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7839 of some markers in the region, even if CUT is non-nil. This is
7840 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7842 (let (beg end folded (beg0 (point)))
7843 (if (org-called-interactively-p 'any)
7844 (org-back-to-heading nil) ; take what looks like a subtree
7845 (org-back-to-heading t)) ; take what is really there
7846 (org-back-over-empty-lines)
7848 (skip-chars-forward " \t\r\n")
7850 (save-excursion (outline-end-of-heading)
7851 (setq folded (outline-invisible-p)))
7853 (org-forward-heading-same-level (1- n) t)
7855 (org-end-of-subtree t t))
7856 (org-back-over-empty-lines)
7860 (setq org-subtree-clip-folded folded)
7861 (when (or cut force-store-markers)
7862 (org-save-markers-in-region beg end))
7863 (if cut (kill-region beg end) (copy-region-as-kill beg end))
7864 (setq org-subtree-clip (current-kill 0))
7865 (message "%s: Subtree(s) with %d characters"
7866 (if cut "Cut" "Copied")
7867 (length org-subtree-clip)))))
7869 (defun org-paste-subtree (&optional level tree for-yank)
7870 "Paste the clipboard as a subtree, with modification of headline level.
7871 The entire subtree is promoted or demoted in order to match a new headline
7874 If the cursor is at the beginning of a headline, the same level as
7875 that headline is used to paste the tree
7877 If not, the new level is derived from the *visible* headings
7878 before and after the insertion point, and taken to be the inferior headline
7879 level of the two. So if the previous visible heading is level 3 and the
7880 next is level 4 (or vice versa), level 4 will be used for insertion.
7881 This makes sure that the subtree remains an independent subtree and does
7882 not swallow low level entries.
7884 You can also force a different level, either by using a numeric prefix
7885 argument, or by inserting the heading marker by hand. For example, if the
7886 cursor is after \"*****\", then the tree will be shifted to level 5.
7888 If optional TREE is given, use this text instead of the kill ring.
7890 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
7891 move back over whitespace before inserting, and move point to the end of
7892 the inserted text when done."
7894 (setq tree (or tree (and kill-ring (current-kill 0))))
7895 (unless (org-kill-is-subtree-p tree)
7897 (substitute-command-keys
7898 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
7899 (org-with-limited-levels
7900 (let* ((visp (not (outline-invisible-p)))
7902 (^re_ "\\(\\*+\\)[ \t]*")
7903 (old-level (if (string-match org-outline-regexp-bol txt)
7904 (- (match-end 0) (match-beginning 0) 1)
7906 (force-level (cond (level (prefix-numeric-value level))
7907 ((and (looking-at "[ \t]*$")
7909 "^\\*+$" (buffer-substring
7910 (point-at-bol) (point))))
7911 (- (match-end 1) (match-beginning 1)))
7913 (looking-at org-outline-regexp))
7914 (- (match-end 0) (point) 1))))
7915 (previous-level (save-excursion
7918 (outline-previous-visible-heading 1)
7919 (if (looking-at ^re_)
7920 (- (match-end 0) (match-beginning 0) 1)
7923 (next-level (save-excursion
7926 (or (looking-at org-outline-regexp)
7927 (outline-next-visible-heading 1))
7928 (if (looking-at ^re_)
7929 (- (match-end 0) (match-beginning 0) 1)
7932 (new-level (or force-level (max previous-level next-level)))
7933 (shift (if (or (= old-level -1)
7935 (= old-level new-level))
7937 (- new-level old-level)))
7938 (delta (if (> shift 0) -1 1))
7939 (func (if (> shift 0) 'org-demote 'org-promote))
7940 (org-odd-levels-only nil)
7942 ;; Remove the forced level indicator
7944 (delete-region (point-at-bol) (point)))
7946 (beginning-of-line (if (bolp) 1 2))
7947 (unless for-yank (org-back-over-empty-lines))
7949 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
7950 (insert-before-markers txt)
7951 (unless (string-match "\n\\'" txt) (insert "\n"))
7952 (setq newend (point))
7953 (org-reinstall-markers-in-region beg)
7956 (skip-chars-forward " \t\n\r")
7958 (if (and (outline-invisible-p) visp)
7959 (save-excursion (outline-show-heading)))
7960 ;; Shift if necessary
7963 (narrow-to-region beg end)
7964 (while (not (= shift 0))
7965 (org-map-region func (point-min) (point-max))
7966 (setq shift (+ delta shift)))
7967 (goto-char (point-min))
7968 (setq newend (point-max))))
7969 (when (or (org-called-interactively-p 'interactive) for-yank)
7970 (message "Clipboard pasted as level %d subtree" new-level))
7971 (if (and (not for-yank) ; in this case, org-yank will decide about folding
7973 (eq org-subtree-clip (current-kill 0))
7974 org-subtree-clip-folded)
7975 ;; The tree was folded before it was killed/copied
7977 (and for-yank (goto-char newend)))))
7979 (defun org-kill-is-subtree-p (&optional txt)
7980 "Check if the current kill is an outline subtree, or a set of trees.
7981 Returns nil if kill does not start with a headline, or if the first
7982 headline level is not the largest headline level in the tree.
7983 So this will actually accept several entries of equal levels as well,
7984 which is OK for `org-paste-subtree'.
7985 If optional TXT is given, check this string instead of the current kill."
7986 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
7987 (re (org-get-limited-outline-regexp))
7988 (^re (concat "^" re))
7989 (start-level (and kill
7991 (concat "\\`\\([ \t\n\r]*?\n\\)?\\(" re "\\)")
7993 (- (match-end 2) (match-beginning 2) 1)))
7994 (start (1+ (or (match-beginning 2) -1))))
7995 (if (not start-level)
7997 nil) ;; does not even start with a heading
7999 (while (setq start (string-match ^re kill (1+ start)))
8000 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
8004 (defvar org-markers-to-move nil
8005 "Markers that should be moved with a cut-and-paste operation.
8006 Those markers are stored together with their positions relative to
8007 the start of the region.")
8009 (defun org-save-markers-in-region (beg end)
8010 "Check markers in region.
8011 If these markers are between BEG and END, record their position relative
8012 to BEG, so that after moving the block of text, we can put the markers back
8014 This function gets called just before an entry or tree gets cut from the
8015 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
8016 called immediately, to move the markers with the entries."
8017 (setq org-markers-to-move nil)
8018 (when (featurep 'org-clock)
8019 (org-clock-save-markers-for-cut-and-paste beg end))
8020 (when (featurep 'org-agenda)
8021 (org-agenda-save-markers-for-cut-and-paste beg end)))
8023 (defun org-check-and-save-marker (marker beg end)
8024 "Check if MARKER is between BEG and END.
8025 If yes, remember the marker and the distance to BEG."
8026 (when (and (marker-buffer marker)
8027 (equal (marker-buffer marker) (current-buffer)))
8028 (if (and (>= marker beg) (< marker end))
8029 (push (cons marker (- marker beg)) org-markers-to-move))))
8031 (defun org-reinstall-markers-in-region (beg)
8032 "Move all remembered markers to their position relative to BEG."
8034 (move-marker (car x) (+ beg (cdr x))))
8035 org-markers-to-move)
8036 (setq org-markers-to-move nil))
8038 (defun org-narrow-to-subtree ()
8039 "Narrow buffer to the current subtree."
8043 (org-with-limited-levels
8045 (progn (org-back-to-heading t) (point))
8046 (progn (org-end-of-subtree t t)
8047 (if (and (org-at-heading-p) (not (eobp))) (backward-char 1))
8050 (defun org-narrow-to-block ()
8051 "Narrow buffer to the current block."
8053 (let* ((case-fold-search t)
8054 (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
8055 "^[ \t]*#\\+end_.*")))
8057 (narrow-to-region (car blockp) (cdr blockp))
8058 (error "Not in a block"))))
8061 (defvar org-property-drawer-re))
8063 (defvar org-property-start-re) ;; defined below
8064 (defun org-clone-subtree-with-time-shift (n &optional shift)
8065 "Clone the task (subtree) at point N times.
8066 The clones will be inserted as siblings.
8068 In interactive use, the user will be prompted for the number of
8069 clones to be produced, and for a time SHIFT, which may be a
8070 repeater as used in time stamps, for example `+3d'.
8072 When a valid repeater is given and the entry contains any time
8073 stamps, the clones will become a sequence in time, with time
8074 stamps in the subtree shifted for each clone produced. If SHIFT
8075 is nil or the empty string, time stamps will be left alone. The
8076 ID property of the original subtree is removed.
8078 If the original subtree did contain time stamps with a repeater,
8079 the following will happen:
8080 - the repeater will be removed in each clone
8081 - an additional clone will be produced, with the current, unshifted
8082 date(s) in the entry.
8083 - the original entry will be placed *after* all the clones, with
8085 - the start days in the repeater in the original entry will be shifted
8086 to past the last clone.
8087 In this way you can spell out a number of instances of a repeating task,
8088 and still retain the repeater to cover future instances of the task."
8089 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
8090 (let (beg end template task idprop
8091 shift-n shift-what doshift nmin nmax (n-no-remove -1)
8092 (drawer-re org-drawer-regexp))
8093 (if (not (and (integerp n) (> n 0)))
8094 (error "Invalid number of replications %s" n))
8095 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
8096 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([hdwmy]\\)[ \t]*\\'"
8098 (error "Invalid shift specification %s" shift))
8100 (setq shift-n (string-to-number (match-string 1 shift))
8101 shift-what (cdr (assoc (match-string 2 shift)
8102 '(("d" . day) ("w" . week)
8103 ("m" . month) ("y" . year))))))
8104 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
8105 (setq nmin 1 nmax n)
8106 (org-back-to-heading t)
8108 (setq idprop (org-entry-get nil "ID"))
8109 (org-end-of-subtree t t)
8110 (or (bolp) (insert "\n"))
8112 (setq template (buffer-substring beg end))
8114 (string-match "<[^<>\n]+ [.+]?\\+[0-9]+[hdwmy][^<>\n]*>" template))
8115 (delete-region beg end)
8117 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
8119 (loop for n from nmin to nmax do
8124 (goto-char (point-min))
8126 (and idprop (if org-clone-delete-id
8127 (org-entry-delete nil "ID")
8128 (org-id-get-create t)))
8130 (while (re-search-forward "^[ \t]*CLOCK:.*$" nil t)
8132 (goto-char (point-min))
8133 (while (re-search-forward drawer-re nil t)
8135 (org-remove-empty-drawer-at d (point))) org-drawers)))
8136 (goto-char (point-min))
8138 (while (re-search-forward org-ts-regexp-both nil t)
8139 (org-timestamp-change (* n shift-n) shift-what))
8140 (unless (= n n-no-remove)
8141 (goto-char (point-min))
8142 (while (re-search-forward org-ts-regexp nil t)
8144 (goto-char (match-beginning 0))
8145 (if (looking-at "<[^<>\n]+\\( +[.+]?\\+[0-9]+[hdwmy]\\)")
8146 (delete-region (match-beginning 1) (match-end 1)))))))
8147 (setq task (buffer-string)))
8153 (defun org-sort (with-case)
8154 "Call `org-sort-entries', `org-table-sort-lines' or `org-sort-list'.
8155 Optional argument WITH-CASE means sort case-sensitively."
8158 ((org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case))
8159 ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case))
8161 (org-call-with-arg 'org-sort-entries with-case))))
8163 (defun org-sort-remove-invisible (s)
8164 (remove-text-properties 0 (length s) org-rm-props s)
8165 (while (string-match org-bracket-link-regexp s)
8166 (setq s (replace-match (if (match-end 2)
8168 (match-string 1 s)) t t s)))
8171 (defvar org-priority-regexp) ; defined later in the file
8173 (defvar org-after-sorting-entries-or-items-hook nil
8174 "Hook that is run after a bunch of entries or items have been sorted.
8175 When children are sorted, the cursor is in the parent line when this
8176 hook gets called. When a region or a plain list is sorted, the cursor
8177 will be in the first entry of the sorted region/list.")
8179 (defun org-sort-entries
8180 (&optional with-case sorting-type getkey-func compare-func property)
8181 "Sort entries on a certain level of an outline tree.
8182 If there is an active region, the entries in the region are sorted.
8183 Else, if the cursor is before the first entry, sort the top-level items.
8184 Else, the children of the entry at point are sorted.
8186 Sorting can be alphabetically, numerically, by date/time as given by
8187 a time stamp, by a property or by priority.
8189 The command prompts for the sorting type unless it has been given to the
8190 function through the SORTING-TYPE argument, which needs to be a character,
8191 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?r ?R ?f ?F). Here is the
8192 precise meaning of each character:
8194 n Numerically, by converting the beginning of the entry/item to a number.
8195 a Alphabetically, ignoring the TODO keyword and the priority, if any.
8196 t By date/time, either the first active time stamp in the entry, or, if
8197 none exist, by the first inactive one.
8198 s By the scheduled date/time.
8199 d By deadline date/time.
8200 c By creation time, which is assumed to be the first inactive time stamp
8201 at the beginning of a line.
8202 p By priority according to the cookie.
8203 r By the value of a property.
8205 Capital letters will reverse the sort order.
8207 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
8208 called with point at the beginning of the record. It must return either
8209 a string or a number that should serve as the sorting key for that record.
8211 Comparing entries ignores case by default. However, with an optional argument
8212 WITH-CASE, the sorting considers case as well."
8214 (let ((case-func (if with-case 'identity 'downcase))
8215 start beg end stars re re2
8217 ;; Find beginning and end of region to sort
8219 ((org-region-active-p)
8220 ;; we will sort the region
8221 (setq end (region-end)
8223 (goto-char (region-beginning))
8224 (if (not (org-at-heading-p)) (outline-next-heading))
8225 (setq start (point)))
8226 ((or (org-at-heading-p)
8227 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
8228 ;; we will sort the children of the current headline
8229 (org-back-to-heading)
8231 end (progn (org-end-of-subtree t t)
8232 (or (bolp) (insert "\n"))
8233 (org-back-over-empty-lines)
8238 (outline-next-heading))
8240 ;; we will sort the top-level entries in this file
8241 (goto-char (point-min))
8242 (or (org-at-heading-p) (outline-next-heading))
8243 (setq start (point))
8244 (goto-char (point-max))
8245 (beginning-of-line 1)
8246 (when (looking-at ".*?\\S-")
8247 ;; File ends in a non-white line
8250 (setq end (point-max))
8251 (setq what "top-level")
8256 (if (>= beg end) (error "Nothing to sort"))
8258 (looking-at "\\(\\*+\\)")
8259 (setq stars (match-string 1)
8260 re (concat "^" (regexp-quote stars) " +")
8261 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[ \t\n]")
8262 txt (buffer-substring beg end))
8263 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
8264 (if (and (not (equal stars "*")) (string-match re2 txt))
8265 (error "Region to sort contains a level above the first entry"))
8267 (unless sorting-type
8269 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
8270 [t]ime
[s]cheduled [d]eadline [c]reated
8271 A/N/T/S/D/C/P/O/F means reversed:"
8273 (setq sorting-type (read-char-exclusive))
8275 (and (= (downcase sorting-type) ?f)
8277 (org-icompleting-read "Sort using function: "
8278 obarray 'fboundp t nil nil))
8279 (setq getkey-func (intern getkey-func)))
8281 (and (= (downcase sorting-type) ?r)
8283 (org-icompleting-read "Property: "
8284 (mapcar 'list (org-buffer-property-keys t))
8287 (message "Sorting entries...")
8290 (narrow-to-region start end)
8291 (let ((dcst (downcase sorting-type))
8292 (case-fold-search nil)
8293 (now (current-time)))
8295 (/= dcst sorting-type)
8296 ;; This function moves to the beginning character of the "record" to
8299 (if (re-search-forward re nil t)
8300 (goto-char (match-beginning 0))
8301 (goto-char (point-max))))
8302 ;; This function moves to the last character of the "record" being
8307 (outline-forward-same-level 1)
8309 (goto-char (point-max))))))
8310 ;; This function returns the value that gets sorted against.
8314 (if (looking-at org-complex-heading-regexp)
8315 (string-to-number (match-string 4))
8318 (if (looking-at org-complex-heading-regexp)
8319 (funcall case-func (match-string 4))
8322 (let ((end (save-excursion (outline-next-heading) (point))))
8323 (if (or (re-search-forward org-ts-regexp end t)
8324 (re-search-forward org-ts-regexp-both end t))
8325 (org-time-string-to-seconds (match-string 0))
8326 (org-float-time now))))
8328 (let ((end (save-excursion (outline-next-heading) (point))))
8329 (if (re-search-forward
8330 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
8332 (org-time-string-to-seconds (match-string 0))
8333 (org-float-time now))))
8335 (let ((end (save-excursion (outline-next-heading) (point))))
8336 (if (re-search-forward org-scheduled-time-regexp end t)
8337 (org-time-string-to-seconds (match-string 1))
8338 (org-float-time now))))
8340 (let ((end (save-excursion (outline-next-heading) (point))))
8341 (if (re-search-forward org-deadline-time-regexp end t)
8342 (org-time-string-to-seconds (match-string 1))
8343 (org-float-time now))))
8345 (if (re-search-forward org-priority-regexp (point-at-eol) t)
8346 (string-to-char (match-string 2))
8347 org-default-priority))
8349 (or (org-entry-get nil property) ""))
8351 (if (looking-at org-complex-heading-regexp)
8352 (- 9999 (length (member (match-string 2)
8353 org-todo-keywords-1)))))
8357 (setq tmp (funcall getkey-func))
8358 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
8360 (error "Invalid key function `%s'" getkey-func)))
8361 (t (error "Invalid sorting type `%c'" sorting-type))))
8364 ((= dcst ?a) 'string<)
8365 ((= dcst ?f) compare-func)
8366 ((member dcst '(?p ?t ?s ?d ?c)) '<)))))
8367 (run-hooks 'org-after-sorting-entries-or-items-hook)
8368 (message "Sorting entries...done")))
8370 (defun org-do-sort (table what &optional with-case sorting-type)
8371 "Sort TABLE of WHAT according to SORTING-TYPE.
8372 The user will be prompted for the SORTING-TYPE if the call to this
8373 function does not specify it. WHAT is only for the prompt, to indicate
8374 what is being sorted. The sorting key will be extracted from
8375 the car of the elements of the table.
8376 If WITH-CASE is non-nil, the sorting will be case-sensitive."
8377 (unless sorting-type
8379 "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:"
8381 (setq sorting-type (read-char-exclusive)))
8382 (let ((dcst (downcase sorting-type))
8383 extractfun comparefun)
8384 ;; Define the appropriate functions
8387 (setq extractfun 'string-to-number
8388 comparefun (if (= dcst sorting-type) '< '>)))
8390 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
8391 (lambda(x) (downcase (org-sort-remove-invisible x))))
8392 comparefun (if (= dcst sorting-type)
8394 (lambda (a b) (and (not (string< a b))
8395 (not (string= a b)))))))
8399 (if (or (string-match org-ts-regexp x)
8400 (string-match org-ts-regexp-both x))
8402 (org-time-string-to-time (match-string 0 x)))
8404 comparefun (if (= dcst sorting-type) '< '>)))
8405 (t (error "Invalid sorting type `%c'" sorting-type)))
8407 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
8409 (lambda (a b) (funcall comparefun (car a) (car b))))))
8412 ;;; The orgstruct minor mode
8414 ;; Define a minor mode which can be used in other modes in order to
8415 ;; integrate the org-mode structure editing commands.
8417 ;; This is really a hack, because the org-mode structure commands use
8418 ;; keys which normally belong to the major mode. Here is how it
8419 ;; works: The minor mode defines all the keys necessary to operate the
8420 ;; structure commands, but wraps the commands into a function which
8421 ;; tests if the cursor is currently at a headline or a plain list
8422 ;; item. If that is the case, the structure command is used,
8423 ;; temporarily setting many Org-mode variables like regular
8424 ;; expressions for filling etc. However, when any of those keys is
8425 ;; used at a different location, function uses `key-binding' to look
8426 ;; up if the key has an associated command in another currently active
8427 ;; keymap (minor modes, major mode, global), and executes that
8428 ;; command. There might be problems if any of the keys is otherwise
8429 ;; used as a prefix key.
8431 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
8432 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
8433 ;; addresses this by checking explicitly for both bindings.
8435 (defvar orgstruct-mode-map (make-sparse-keymap)
8436 "Keymap for the minor `orgstruct-mode'.")
8438 (defvar org-local-vars nil
8439 "List of local variables, for use by `orgstruct-mode'.")
8442 (define-minor-mode orgstruct-mode
8443 "Toggle the minor mode `orgstruct-mode'.
8444 This mode is for using Org-mode structure commands in other
8445 modes. The following keys behave as if Org-mode were active, if
8446 the cursor is on a headline, or on a plain list item (both as
8447 defined by Org-mode).
8449 M-up Move entry/item up
8450 M-down Move entry/item down
8453 M-S-up Move entry/item up
8454 M-S-down Move entry/item down
8455 M-S-left Promote subtree
8456 M-S-right Demote subtree
8457 M-q Fill paragraph and items like in Org-mode
8459 C-c - Cycle list bullet
8460 TAB Cycle item visibility
8461 M-RET Insert new heading/item
8462 S-M-RET Insert new TODO heading / Checkbox item
8463 C-c C-c Set tags / toggle checkbox"
8464 nil " OrgStruct" nil
8465 (org-load-modules-maybe)
8466 (and (orgstruct-setup) (defun orgstruct-setup () nil)))
8469 (defun turn-on-orgstruct ()
8470 "Unconditionally turn on `orgstruct-mode'."
8473 (defvar org-fb-vars nil)
8474 (make-variable-buffer-local 'org-fb-vars)
8475 (defun orgstruct++-mode (&optional arg)
8476 "Toggle `orgstruct-mode', the enhanced version of it.
8477 In addition to setting orgstruct-mode, this also exports all
8478 indentation and autofilling variables from org-mode into the
8479 buffer. It will also recognize item context in multiline items."
8481 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
8483 (progn (orgstruct-mode -1)
8485 (org-set-local (car v)
8486 (if (eq (car-safe (cadr v)) 'quote) (cadadr v) (cadr v))))
8489 (setq org-fb-vars nil)
8494 "^\\(paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|fill-prefix\\|indent-\\)"
8495 (symbol-name (car x)))
8496 (setq var (car x) val (nth 1 x))
8497 (push (list var `(quote ,(eval var))) org-fb-vars)
8498 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
8500 (org-set-local 'orgstruct-is-++ t))))
8502 (defvar orgstruct-is-++ nil
8503 "Is `orgstruct-mode' in ++ version in the current-buffer?")
8504 (make-variable-buffer-local 'orgstruct-is-++)
8507 (defun turn-on-orgstruct++ ()
8508 "Unconditionally turn on `orgstruct++-mode'."
8509 (orgstruct++-mode 1))
8511 (defun orgstruct-error ()
8512 "Error when there is no default binding for a structure key."
8514 (error "This key has no function outside structure elements"))
8516 (defun orgstruct-setup ()
8517 "Setup orgstruct keymaps."
8521 '([(meta up)] org-metaup)
8522 '([(meta down)] org-metadown)
8523 '([(meta left)] org-metaleft)
8524 '([(meta right)] org-metaright)
8525 '([(meta shift up)] org-shiftmetaup)
8526 '([(meta shift down)] org-shiftmetadown)
8527 '([(meta shift left)] org-shiftmetaleft)
8528 '([(meta shift right)] org-shiftmetaright)
8529 '([?\e (up)] org-metaup)
8530 '([?\e (down)] org-metadown)
8531 '([?\e (left)] org-metaleft)
8532 '([?\e (right)] org-metaright)
8533 '([?\e (shift up)] org-shiftmetaup)
8534 '([?\e (shift down)] org-shiftmetadown)
8535 '([?\e (shift left)] org-shiftmetaleft)
8536 '([?\e (shift right)] org-shiftmetaright)
8537 '([(shift up)] org-shiftup)
8538 '([(shift down)] org-shiftdown)
8539 '([(shift left)] org-shiftleft)
8540 '([(shift right)] org-shiftright)
8541 '("\C-c\C-c" org-ctrl-c-ctrl-c)
8542 '("\M-q" fill-paragraph)
8544 '("\C-c-" org-cycle-list-bullet)))
8546 (while (setq elt (pop bindings))
8547 (setq nfunc (1+ nfunc))
8548 (setq key (org-key (car elt))
8550 cmd (orgstruct-make-binding fun nfunc key))
8551 (org-defkey orgstruct-mode-map key cmd))
8553 ;; Prevent an error for users who forgot to make autoloads
8554 (require 'org-element)
8556 ;; Special treatment needed for TAB and RET
8557 (org-defkey orgstruct-mode-map [(tab)]
8558 (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i"))
8559 (org-defkey orgstruct-mode-map "\C-i"
8560 (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)]))
8562 (org-defkey orgstruct-mode-map "\M-\C-m"
8563 (orgstruct-make-binding 'org-insert-heading 105
8564 "\M-\C-m" [(meta return)]))
8565 (org-defkey orgstruct-mode-map [(meta return)]
8566 (orgstruct-make-binding 'org-insert-heading 106
8567 [(meta return)] "\M-\C-m"))
8569 (org-defkey orgstruct-mode-map [(shift meta return)]
8570 (orgstruct-make-binding 'org-insert-todo-heading 107
8571 [(meta return)] "\M-\C-m"))
8573 (org-defkey orgstruct-mode-map "\e\C-m"
8574 (orgstruct-make-binding 'org-insert-heading 108
8575 "\e\C-m" [?\e (return)]))
8576 (org-defkey orgstruct-mode-map [?\e (return)]
8577 (orgstruct-make-binding 'org-insert-heading 109
8578 [?\e (return)] "\e\C-m"))
8579 (org-defkey orgstruct-mode-map [?\e (shift return)]
8580 (orgstruct-make-binding 'org-insert-todo-heading 110
8581 [?\e (return)] "\e\C-m"))
8583 (unless org-local-vars
8584 (setq org-local-vars (org-get-local-variables)))
8588 (defun orgstruct-make-binding (fun n &rest keys)
8589 "Create a function for binding in the structure minor mode.
8590 FUN is the command to call inside a table. N is used to create a unique
8591 command name. KEYS are keys that should be checked in for a command
8592 to execute outside of tables."
8595 (intern (concat "orgstruct-hijacker-command-" (int-to-string n)))
8597 (concat "In Structure, run `" (symbol-name fun) "'.\n"
8598 "Outside of structure, run the binding of `"
8599 (mapconcat (lambda (x) (format "%s" x)) keys "' or `")
8603 `(org-context-p 'headline 'item
8604 (and orgstruct-is-++
8605 ,(and (memq fun '(org-insert-heading org-insert-todo-heading)) t)
8607 (list 'org-run-like-in-org-mode (list 'quote fun))
8608 (list 'let '(orgstruct-mode)
8609 (list 'call-interactively
8612 (list 'key-binding k))
8614 '('orgstruct-error))))))))
8616 (defun org-contextualize-keys (alist contexts)
8617 "Return valid elements in ALIST depending on CONTEXTS.
8619 `org-agenda-custom-commands' or `org-capture-templates' are the
8620 values used for ALIST, and `org-agenda-custom-commands-contexts'
8621 or `org-capture-templates-contexts' are the associated contexts
8624 ;; normalize contexts
8626 (lambda(c) (cond ((listp (cadr c))
8627 (list (car c) (car c) (cadr c)))
8628 ((string= "" (cadr c))
8629 (list (car c) (car c) (caddr c)))
8632 ;; loop over all commands or templates
8633 (while (setq c (pop a))
8636 ((not (assoc (car c) contexts))
8638 ((and (assoc (car c) contexts)
8639 (setq vrules (org-contextualize-validate-key
8642 (when (not (equal (car vr) (cadr vr)))
8643 (setq repl vr))) vrules)
8644 (if (not repl) (push c r)
8645 (push (cadr repl) s)
8648 (cdr (or (assoc (cadr repl) alist)
8649 (error "Undefined key `%s' as contextual replacement for `%s'"
8650 (cadr repl) (car c)))))
8652 ;; Return limited ALIST, possibly with keys modified, and deduplicated
8657 (let ((tpl (car x)))
8661 (equal y tpl)) s))) x)))
8664 (defun org-contextualize-validate-key (key contexts)
8665 "Check CONTEXTS for agenda or capture KEY."
8667 (while (setq r (pop contexts))
8671 (and (equal key (car r))
8672 (if (functionp rr) (funcall rr)
8673 (or (and (eq (car rr) 'in-file)
8675 (string-match (cdr rr) (buffer-file-name)))
8676 (and (eq (car rr) 'in-mode)
8677 (string-match (cdr rr) (symbol-name major-mode)))
8678 (when (and (eq (car rr) 'not-in-file)
8680 (not (string-match (cdr rr) (buffer-file-name))))
8681 (when (eq (car rr) 'not-in-mode)
8682 (not (string-match (cdr rr) (symbol-name major-mode)))))))
8685 (delete-dups (delq nil res))))
8687 (defun org-context-p (&rest contexts)
8688 "Check if local context is any of CONTEXTS.
8689 Possible values in the list of contexts are `table', `headline', and `item'."
8690 (let ((pos (point)))
8691 (goto-char (point-at-bol))
8692 (prog1 (or (and (memq 'table contexts)
8693 (looking-at "[ \t]*|"))
8694 (and (memq 'headline contexts)
8695 (looking-at org-outline-regexp))
8696 (and (memq 'item contexts)
8697 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
8698 (and (memq 'item-body contexts)
8702 (defun org-get-local-variables ()
8703 "Return a list of all local variables in an Org mode buffer."
8705 (with-current-buffer (get-buffer-create "*Org tmp*")
8708 (setq varlist (buffer-local-variables)))
8709 (kill-buffer "*Org tmp*")
8716 (list (car x) (list 'quote (cdr x)))))
8718 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)"
8719 (symbol-name (car x)))
8723 (defun org-clone-local-variables (from-buffer &optional regexp)
8724 "Clone local variables from FROM-BUFFER.
8725 Optional argument REGEXP selects variables to clone."
8728 (and (symbolp (car pair))
8730 (string-match regexp (symbol-name (car pair))))
8731 (set (make-local-variable (car pair))
8733 (buffer-local-variables from-buffer)))
8736 (defun org-run-like-in-org-mode (cmd)
8737 "Run a command, pretending that the current buffer is in Org-mode.
8738 This will temporarily bind local variables that are typically bound in
8739 Org-mode to the values they have in Org-mode, and then interactively
8741 (org-load-modules-maybe)
8742 (unless org-local-vars
8743 (setq org-local-vars (org-get-local-variables)))
8744 (eval (list 'let org-local-vars
8745 (list 'call-interactively (list 'quote cmd)))))
8749 (defun org-get-category (&optional pos force-refresh)
8750 "Get the category applying to position POS."
8752 (if force-refresh (org-refresh-category-properties))
8753 (let ((pos (or pos (point))))
8754 (or (get-text-property pos 'org-category)
8755 (progn (org-refresh-category-properties)
8756 (get-text-property pos 'org-category))))))
8758 (defun org-refresh-category-properties ()
8759 "Refresh category text properties in the buffer."
8760 (let ((case-fold-search t)
8761 (inhibit-read-only t)
8763 ((null org-category)
8764 (if buffer-file-name
8765 (file-name-sans-extension
8766 (file-name-nondirectory buffer-file-name))
8768 ((symbolp org-category) (symbol-name org-category))
8770 beg end cat pos optionp)
8775 (goto-char (point-min))
8776 (put-text-property (point) (point-max) 'org-category def-cat)
8777 (while (re-search-forward
8778 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
8779 (setq pos (match-end 0)
8780 optionp (equal (char-after (match-beginning 0)) ?#)
8781 cat (org-trim (match-string 2)))
8783 (setq beg (point-at-bol) end (point-max))
8784 (org-back-to-heading t)
8785 (setq beg (point) end (org-end-of-subtree t t)))
8786 (put-text-property beg end 'org-category cat)
8787 (put-text-property beg end 'org-category-position beg)
8788 (goto-char pos)))))))
8793 ;;; Link abbreviations
8795 (defun org-link-expand-abbrev (link)
8796 "Apply replacements as defined in `org-link-abbrev-alist'."
8797 (if (string-match "^\\([^:]*\\)\\(::?\\(.*\\)\\)?$" link)
8798 (let* ((key (match-string 1 link))
8799 (as (or (assoc key org-link-abbrev-alist-local)
8800 (assoc key org-link-abbrev-alist)))
8801 (tag (and (match-end 2) (match-string 3 link)))
8807 ((symbolp rpl) (funcall rpl tag))
8808 ((string-match "%(\\([^)]+\\))" rpl)
8809 (replace-match (funcall (intern-soft (match-string 1 rpl)) tag) t t rpl))
8810 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
8811 ((string-match "%h" rpl)
8812 (replace-match (url-hexify-string (or tag "")) t t rpl))
8813 (t (concat rpl tag)))))
8816 ;;; Storing and inserting links
8818 (defvar org-insert-link-history nil
8819 "Minibuffer history for links inserted with `org-insert-link'.")
8821 (defvar org-stored-links nil
8822 "Contains the links stored with `org-store-link'.")
8824 (defvar org-store-link-plist nil
8825 "Plist with info about the most recently link created with `org-store-link'.")
8827 (defvar org-link-protocols nil
8828 "Link protocols added to Org-mode using `org-add-link-type'.")
8830 (defvar org-store-link-functions nil
8831 "List of functions that are called to create and store a link.
8832 Each function will be called in turn until one returns a non-nil
8833 value. Each function should check if it is responsible for creating
8834 this link (for example by looking at the major mode).
8835 If not, it must exit and return nil.
8836 If yes, it should return a non-nil value after a calling
8837 `org-store-link-props' with a list of properties and values.
8838 Special properties are:
8840 :type The link prefix, like \"http\". This must be given.
8841 :link The link, like \"http://www.astro.uva.nl/~dominik\".
8842 This is obligatory as well.
8843 :description Optional default description for the second pair
8844 of brackets in an Org-mode link. The user can still change
8845 this when inserting this link into an Org-mode buffer.
8847 In addition to these, any additional properties can be specified
8848 and then used in remember templates.")
8850 (defun org-add-link-type (type &optional follow export)
8851 "Add TYPE to the list of `org-link-types'.
8852 Re-compute all regular expressions depending on `org-link-types'
8854 FOLLOW and EXPORT are two functions.
8856 FOLLOW should take the link path as the single argument and do whatever
8857 is necessary to follow the link, for example find a file or display
8860 EXPORT should format the link path for export to one of the export formats.
8861 It should be a function accepting three arguments:
8863 path the path of the link, the text after the prefix (like \"http:\")
8864 desc the description of the link, if any, or a description added by
8865 org-export-normalize-links if there is none
8866 format the export format, a symbol like `html' or `latex' or `ascii'..
8868 The function may use the FORMAT information to return different values
8869 depending on the format. The return value will be put literally into
8870 the exported file. If the return value is nil, this means Org should
8871 do what it normally does with links which do not have EXPORT defined.
8873 Org-mode has a built-in default for exporting links. If you are happy with
8874 this default, there is no need to define an export function for the link
8875 type. For a simple example of an export function, see `org-bbdb.el'."
8876 (add-to-list 'org-link-types type t)
8877 (org-make-link-regexps)
8878 (if (assoc type org-link-protocols)
8879 (setcdr (assoc type org-link-protocols) (list follow export))
8880 (push (list type follow export) org-link-protocols)))
8882 (defvar org-agenda-buffer-name)
8885 (defun org-store-link (arg)
8886 "\\<org-mode-map>Store an org-link to the current location.
8887 This link is added to `org-stored-links' and can later be inserted
8888 into an org-buffer with \\[org-insert-link].
8890 For some link types, a prefix arg is interpreted:
8891 For links to usenet articles, arg negates `org-gnus-prefer-web-links'.
8892 For file links, arg negates `org-context-in-file-links'."
8894 (org-load-modules-maybe)
8895 (setq org-store-link-plist nil) ; reset
8896 (org-with-limited-levels
8897 (let (link cpltxt desc description search txt custom-id agenda-link)
8900 ((run-hook-with-args-until-success 'org-store-link-functions)
8901 (setq link (plist-get org-store-link-plist :link)
8902 desc (or (plist-get org-store-link-plist :description) link)))
8904 ((org-src-edit-buffer-p)
8906 (while (or (not label)
8910 (goto-char (point-min))
8912 (regexp-quote (format org-coderef-label-format label))
8914 (when label (message "Label exists already") (sit-for 2))
8915 (setq label (read-string "Code line label: " label)))
8917 (setq link (format org-coderef-label-format label))
8918 (setq gc (- 79 (length link)))
8919 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
8921 (setq link (concat "(" label ")") desc nil)))
8923 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
8924 ;; We are in the agenda, link to referenced location
8925 (let ((m (or (get-text-property (point) 'org-hd-marker)
8926 (get-text-property (point) 'org-marker))))
8928 (org-with-point-at m
8930 (if (org-called-interactively-p 'any)
8931 (call-interactively 'org-store-link)
8932 (org-store-link nil)))))))
8934 ((eq major-mode 'calendar-mode)
8935 (let ((cd (calendar-cursor-to-date)))
8938 (car org-time-stamp-formats)
8940 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
8942 (org-store-link-props :type "calendar" :date cd)))
8944 ((eq major-mode 'help-mode)
8945 (setq link (concat "help:" (save-excursion
8946 (goto-char (point-min))
8947 (looking-at "^[^ ]+")
8949 (org-store-link-props :type "help"))
8951 ((eq major-mode 'w3-mode)
8952 (setq cpltxt (if (and (buffer-name)
8953 (not (string-match "Untitled" (buffer-name))))
8956 link (url-view-url t))
8957 (org-store-link-props :type "w3" :url (url-view-url t)))
8959 ((eq major-mode 'w3m-mode)
8960 (setq cpltxt (or w3m-current-title w3m-current-url)
8961 link w3m-current-url)
8962 (org-store-link-props :type "w3m" :url (url-view-url t)))
8964 ((setq search (run-hook-with-args-until-success
8965 'org-create-file-search-functions))
8966 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
8968 (setq cpltxt (or description link)))
8970 ((eq major-mode 'image-mode)
8971 (setq cpltxt (concat "file:"
8972 (abbreviate-file-name buffer-file-name))
8974 (org-store-link-props :type "image" :file buffer-file-name))
8976 ((eq major-mode 'dired-mode)
8977 ;; link to the file in the current line
8978 (let ((file (dired-get-filename nil t)))
8980 (abbreviate-file-name
8981 (expand-file-name (dired-get-filename nil t)))
8982 ;; otherwise, no file so use current directory.
8984 (setq cpltxt (concat "file:" file)
8987 ((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode))
8988 (setq custom-id (org-entry-get nil "CUSTOM_ID"))
8990 ((org-in-regexp "<<\\(.*?\\)>>")
8993 (abbreviate-file-name
8994 (buffer-file-name (buffer-base-buffer)))
8995 "::" (match-string 1))
8997 ((and (featurep 'org-id)
8998 (or (eq org-link-to-org-use-id t)
8999 (and (org-called-interactively-p 'any)
9000 (or (eq org-link-to-org-use-id 'create-if-interactive)
9001 (and (eq org-link-to-org-use-id
9002 'create-if-interactive-and-no-custom-id)
9004 (and org-link-to-org-use-id (org-entry-get nil "ID"))))
9005 ;; We can make a link using the ID.
9006 (setq link (condition-case nil
9007 (prog1 (org-id-store-link)
9008 (setq desc (plist-get org-store-link-plist :description)))
9010 ;; probably before first headline, link to file only
9012 (abbreviate-file-name
9013 (buffer-file-name (buffer-base-buffer))))))))
9015 ;; Just link to current headline
9016 (setq cpltxt (concat "file:"
9017 (abbreviate-file-name
9018 (buffer-file-name (buffer-base-buffer)))))
9019 ;; Add a context search string
9020 (when (org-xor org-context-in-file-links arg)
9022 ((org-at-heading-p) nil)
9023 ((org-region-active-p)
9024 (buffer-substring (region-beginning) (region-end)))))
9025 (when (or (null txt) (string-match "\\S-" txt))
9029 (org-make-org-heading-search-string txt)
9031 desc (or (nth 4 (ignore-errors
9032 (org-heading-components))) "NONE"))))
9033 (if (string-match "::\\'" cpltxt)
9034 (setq cpltxt (substring cpltxt 0 -2)))
9035 (setq link cpltxt))))
9037 ((buffer-file-name (buffer-base-buffer))
9038 ;; Just link to this file here.
9039 (setq cpltxt (concat "file:"
9040 (abbreviate-file-name
9041 (buffer-file-name (buffer-base-buffer)))))
9042 ;; Add a context string
9043 (when (org-xor org-context-in-file-links arg)
9044 (setq txt (if (org-region-active-p)
9045 (buffer-substring (region-beginning) (region-end))
9046 (buffer-substring (point-at-bol) (point-at-eol))))
9047 ;; Only use search option if there is some text.
9048 (when (string-match "\\S-" txt)
9050 (concat cpltxt "::" (org-make-org-heading-search-string txt))
9054 ((org-called-interactively-p 'interactive)
9055 (error "Cannot link to a buffer which is not visiting a file"))
9057 (t (setq link nil)))
9059 (if (consp link) (setq cpltxt (car link) link (cdr link)))
9060 (setq link (or link cpltxt)
9061 desc (or desc cpltxt))
9062 (if (equal desc "NONE") (setq desc nil))
9064 (if (and (or (org-called-interactively-p 'any) executing-kbd-macro) link)
9066 (setq org-stored-links
9067 (cons (list link desc) org-stored-links))
9068 (message "Stored: %s" (or desc link))
9070 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
9072 (setq org-stored-links
9073 (cons (list link desc) org-stored-links))))
9074 (or agenda-link (and link (org-make-link-string link desc)))))))
9076 (defun org-store-link-props (&rest plist)
9077 "Store link properties, extract names and addresses."
9079 (when (setq x (plist-get plist :from))
9080 (setq adr (mail-extract-address-components x))
9081 (setq plist (plist-put plist :fromname (car adr)))
9082 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
9083 (when (setq x (plist-get plist :to))
9084 (setq adr (mail-extract-address-components x))
9085 (setq plist (plist-put plist :toname (car adr)))
9086 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
9087 (let ((from (plist-get plist :from))
9088 (to (plist-get plist :to)))
9089 (when (and from to org-from-is-user-regexp)
9091 (plist-put plist :fromto
9092 (if (string-match org-from-is-user-regexp from)
9094 (concat "from %f"))))))
9095 (setq org-store-link-plist plist))
9097 (defun org-add-link-props (&rest plist)
9098 "Add these properties to the link property list."
9101 (setq key (pop plist) value (pop plist))
9102 (setq org-store-link-plist
9103 (plist-put org-store-link-plist key value)))))
9105 (defun org-email-link-description (&optional fmt)
9106 "Return the description part of an email link.
9107 This takes information from `org-store-link-plist' and formats it
9108 according to FMT (default from `org-email-link-description-format')."
9109 (setq fmt (or fmt org-email-link-description-format))
9110 (let* ((p org-store-link-plist)
9111 (to (plist-get p :toaddress))
9112 (from (plist-get p :fromaddress))
9115 (cons "%c" (plist-get p :fromto))
9116 (cons "%F" (plist-get p :from))
9117 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
9118 (cons "%T" (plist-get p :to))
9119 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
9120 (cons "%s" (plist-get p :subject))
9121 (cons "%d" (plist-get p :date))
9122 (cons "%m" (plist-get p :message-id)))))
9123 (when (string-match "%c" fmt)
9124 ;; Check if the user wrote this message
9125 (if (and org-from-is-user-regexp from to
9126 (save-match-data (string-match org-from-is-user-regexp from)))
9127 (setq fmt (replace-match "to %t" t t fmt))
9128 (setq fmt (replace-match "from %f" t t fmt))))
9129 (org-replace-escapes fmt table)))
9131 (defun org-make-org-heading-search-string (&optional string heading)
9132 "Make search string for STRING or current headline."
9134 (let ((s (or string (org-get-heading)))
9135 (lines org-context-in-file-links))
9136 (unless (and string (not heading))
9137 ;; We are using a headline, clean up garbage in there.
9138 (if (string-match org-todo-regexp s)
9139 (setq s (replace-match "" t t s)))
9140 (if (string-match (org-re ":[[:alnum:]_@#%:]+:[ \t]*$") s)
9141 (setq s (replace-match "" t t s)))
9142 (setq s (org-trim s))
9143 (if (string-match (concat "^\\(" org-quote-string "\\|"
9144 org-comment-string "\\)") s)
9145 (setq s (replace-match "" t t s)))
9146 (while (string-match org-ts-regexp s)
9147 (setq s (replace-match "" t t s))))
9148 (or string (setq s (concat "*" s))) ; Add * for headlines
9149 (when (and string (integerp lines) (> lines 0))
9150 (let ((slines (org-split-string s "\n")))
9151 (when (< lines (length slines))
9154 (reverse (nthcdr (- (length slines) lines)
9155 (reverse slines))) "\n")))))
9156 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
9158 (defun org-make-link-string (link &optional description)
9159 "Make a link with brackets, consisting of LINK and DESCRIPTION."
9160 (unless (string-match "\\S-" link)
9161 (error "Empty link"))
9162 (when (and description
9163 (stringp description)
9164 (not (string-match "\\S-" description)))
9165 (setq description nil))
9166 (when (stringp description)
9167 ;; Remove brackets from the description, they are fatal.
9168 (while (string-match "\\[" description)
9169 (setq description (replace-match "{" t t description)))
9170 (while (string-match "\\]" description)
9171 (setq description (replace-match "}" t t description))))
9172 (when (equal link description)
9173 ;; No description needed, it is identical
9174 (setq description nil))
9175 (when (and (not description)
9176 (not (string-match (org-image-file-name-regexp) link))
9177 (not (equal link (org-link-escape link))))
9178 (setq description (org-extract-attributes link)))
9180 (cond ((string-match (org-image-file-name-regexp) link) link)
9181 ((string-match org-link-types-re link)
9182 (concat (match-string 1 link)
9183 (org-link-escape (substring link (match-end 1)))))
9184 (t (org-link-escape link))))
9185 (concat "[[" link "]"
9186 (if description (concat "[" description "]") "")
9189 (defconst org-link-escape-chars
9190 '(?\ ?\[ ?\] ?\; ?\= ?\+)
9191 "List of characters that should be escaped in link.
9192 This is the list that is used for internal purposes.")
9194 (defconst org-link-escape-chars-browser
9196 "List of escapes for characters that are problematic in links.
9197 This is the list that is used before handing over to the browser.")
9199 (defun org-link-escape (text &optional table merge)
9200 "Return percent escaped representation of TEXT.
9201 TEXT is a string with the text to escape.
9202 Optional argument TABLE is a list with characters that should be
9203 escaped. When nil, `org-link-escape-chars' is used.
9204 If optional argument MERGE is set, merge TABLE into
9205 `org-link-escape-chars'."
9208 (mapc (lambda (defchr)
9209 (unless (member defchr table)
9210 (setq table (cons defchr table)))) org-link-escape-chars))
9212 (setq table org-link-escape-chars)))
9215 (if (or (member char table)
9216 (and (or (< char 32) (= char 37) (> char 126))
9218 (mapconcat (lambda (sequence-element)
9219 (format "%%%.2X" sequence-element))
9220 (or (encode-coding-char char 'utf-8)
9221 (error "Unable to percent escape character: %s"
9222 (char-to-string char))) "")
9223 (char-to-string char))) text ""))
9225 (defun org-link-unescape (str)
9226 "Unhex hexified Unicode strings as returned from the JavaScript function
9227 encodeURIComponent. E.g. `%C3%B6' is the german Umlaut `ö'."
9228 (unless (and (null str) (string= "" str))
9229 (let ((pos 0) (case-fold-search t) unhexed)
9230 (while (setq pos (string-match "\\(%[0-9a-f][0-9a-f]\\)+" str pos))
9231 (setq unhexed (org-link-unescape-compound (match-string 0 str)))
9232 (setq str (replace-match unhexed t t str))
9233 (setq pos (+ pos (length unhexed))))))
9236 (defun org-link-unescape-compound (hex)
9237 "Unhexify Unicode hex-chars. E.g. `%C3%B6' is the German Umlaut `ö'.
9238 Note: this function also decodes single byte encodings like
9239 `%E1' (\"á\") if not followed by another `%[A-F0-9]{2}' group."
9241 (let* ((bytes (cdr (split-string hex "%")))
9246 (let* ((val (string-to-number (pop bytes) 16))
9250 ((>= val 252) (cons 6 252))
9251 ((>= val 248) (cons 5 248))
9252 ((>= val 240) (cons 4 240))
9253 ((>= val 224) (cons 3 224))
9254 ((>= val 192) (cons 2 192))
9257 (if (>= val 192) (setq eat (car shift-xor)))
9258 (setq val (logxor val (cdr shift-xor)))
9259 (setq sum (+ (lsh sum (car shift-xor)) val))
9260 (if (> eat 0) (setq eat (- eat 1)))
9262 ((= 0 eat) ;multi byte
9263 (setq ret (concat ret (org-char-to-string sum)))
9265 ((not bytes) ; single byte(s)
9266 (setq ret (org-link-unescape-single-byte-sequence hex))))
9267 )) ;; end (while bytes
9270 (defun org-link-unescape-single-byte-sequence (hex)
9271 "Unhexify hex-encoded single byte character sequences."
9272 (mapconcat (lambda (byte)
9273 (char-to-string (string-to-number byte 16)))
9274 (cdr (split-string hex "%")) ""))
9276 (defun org-xor (a b)
9280 (defun org-fixup-message-id-for-http (s)
9281 "Replace special characters in a message id, so it can be used in an http query."
9282 (when (string-match "%" s)
9283 (setq s (mapconcat (lambda (c)
9286 (char-to-string c)))
9288 (while (string-match "<" s)
9289 (setq s (replace-match "%3C" t t s)))
9290 (while (string-match ">" s)
9291 (setq s (replace-match "%3E" t t s)))
9292 (while (string-match "@" s)
9293 (setq s (replace-match "%40" t t s)))
9296 (defun org-link-prettify (link)
9297 "Return a human-readable representation of LINK.
9298 The car of LINK must be a raw link the cdr of LINK must be either
9299 a link description or nil."
9300 (let ((desc (or (cadr link) "<no description>")))
9301 (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
9302 "<" (car link) ">")))
9305 (defun org-insert-link-global ()
9306 "Insert a link like Org-mode does.
9307 This command can be called in any mode to insert a link in Org-mode syntax."
9309 (org-load-modules-maybe)
9310 (org-run-like-in-org-mode 'org-insert-link))
9312 (defun org-insert-all-links (&optional keep)
9313 "Insert all links in `org-stored-links'."
9315 (let ((links (copy-sequence org-stored-links)) l)
9316 (while (setq l (if keep (pop links) (pop org-stored-links)))
9318 (org-insert-link nil (car l) (cadr l))
9321 (defun org-link-fontify-links-to-this-file ()
9322 "Fontify links to the current file in `org-stored-links'."
9323 (let ((f (buffer-file-name)) a b)
9324 (setq a (mapcar (lambda(l)
9326 (when (and (string-match "^file:\\(.+\\)::" ll)
9327 (equal f (expand-file-name (match-string 1 ll))))
9330 (when (featurep 'org-id)
9331 (setq b (mapcar (lambda(l)
9333 (when (and (string-match "^id:\\(.+\\)$" ll)
9334 (equal f (expand-file-name
9335 (or (org-id-find-id-file
9336 (match-string 1 ll)) ""))))
9340 (put-text-property 0 (length l) 'face 'font-lock-comment-face l))
9341 (delq nil (append a b)))))
9343 (defvar org-link-links-in-this-file nil)
9344 (defun org-insert-link (&optional complete-file link-location default-description)
9345 "Insert a link. At the prompt, enter the link.
9347 Completion can be used to insert any of the link protocol prefixes like
9350 The history can be used to select a link previously stored with
9351 `org-store-link'. When the empty string is entered (i.e. if you just
9352 press RET at the prompt), the link defaults to the most recently
9353 stored link. As SPC triggers completion in the minibuffer, you need to
9354 use M-SPC or C-q SPC to force the insertion of a space character.
9356 You will also be prompted for a description, and if one is given, it will
9357 be displayed in the buffer instead of the link.
9359 If there is already a link at point, this command will allow you to edit link
9360 and description parts.
9362 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
9363 be selected using completion. The path to the file will be relative to the
9364 current directory if the file is in the current directory or a subdirectory.
9365 Otherwise, the link will be the absolute path as completed in the minibuffer
9366 \(i.e. normally ~/path/to/file). You can configure this behavior using the
9367 option `org-link-file-path-type'.
9369 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
9370 the current directory or below.
9372 With three \\[universal-argument] prefixes, negate the meaning of
9373 `org-keep-stored-link-after-insertion'.
9375 If `org-make-link-description-function' is non-nil, this function will be
9376 called with the link target, and the result will be the default
9379 If the LINK-LOCATION parameter is non-nil, this value will be
9380 used as the link location instead of reading one interactively.
9382 If the DEFAULT-DESCRIPTION parameter is non-nil, this value will
9383 be used as the default description."
9385 (let* ((wcf (current-window-configuration))
9386 (region (if (org-region-active-p)
9387 (buffer-substring (region-beginning) (region-end))))
9388 (remove (and region (list (region-beginning) (region-end))))
9390 tmphist ; byte-compile incorrectly complains about this
9391 (link link-location)
9392 (abbrevs org-link-abbrev-alist-local)
9393 entry file all-prefixes auto-desc)
9395 (link-location) ; specified by arg, just use it.
9396 ((org-in-regexp org-bracket-link-regexp 1)
9397 ;; We do have a link at point, and we are going to edit it.
9398 (setq remove (list (match-beginning 0) (match-end 0)))
9399 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
9400 (setq link (read-string "Link: "
9402 (org-match-string-no-properties 1)))))
9403 ((or (org-in-regexp org-angle-link-re)
9404 (org-in-regexp org-plain-link-re))
9405 ;; Convert to bracket link
9406 (setq remove (list (match-beginning 0) (match-end 0))
9407 link (read-string "Link: "
9408 (org-remove-angle-brackets (match-string 0)))))
9409 ((member complete-file '((4) (16)))
9410 ;; Completing read for file names.
9411 (setq link (org-file-complete-link complete-file)))
9413 ;; Read link, with completion for stored links.
9414 (org-link-fontify-links-to-this-file)
9415 (org-switch-to-buffer-other-window "*Org Links*")
9416 (with-current-buffer "*Org Links*"
9418 (insert "Insert a link.
9419 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
9420 (when org-stored-links
9421 (insert "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
9422 (insert (mapconcat 'org-link-prettify
9423 (reverse org-stored-links) "\n")))
9424 (goto-char (point-min)))
9425 (let ((cw (selected-window)))
9426 (select-window (get-buffer-window "*Org Links*" 'visible))
9427 (with-current-buffer "*Org Links*" (setq truncate-lines t))
9428 (unless (pos-visible-in-window-p (point-max))
9429 (org-fit-window-to-buffer))
9430 (and (window-live-p cw) (select-window cw)))
9431 ;; Fake a link history, containing the stored links.
9432 (setq tmphist (append (mapcar 'car org-stored-links)
9433 org-insert-link-history))
9434 (setq all-prefixes (append (mapcar 'car abbrevs)
9435 (mapcar 'car org-link-abbrev-alist)
9440 (let ((org-completion-use-ido nil)
9441 (org-completion-use-iswitchb nil))
9442 (org-completing-read
9445 (mapcar (lambda (x) (list (concat x ":")))
9447 (mapcar 'car org-stored-links)
9448 (mapcar 'cadr org-stored-links))
9451 (caar org-stored-links))))
9452 (if (not (string-match "\\S-" link))
9453 (error "No link selected"))
9455 (when (equal link (cadr l)) (setq link (car l) auto-desc t)))
9457 (if (or (member link all-prefixes)
9458 (and (equal ":" (substring link -1))
9459 (member (substring link 0 -1) all-prefixes)
9460 (setq link (substring link 0 -1))))
9461 (setq link (org-link-try-special-completion link))))
9462 (set-window-configuration wcf)
9463 (kill-buffer "*Org Links*"))
9464 (setq entry (assoc link org-stored-links))
9465 (or entry (push link org-insert-link-history))
9466 (setq desc (or desc (nth 1 entry)))))
9468 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
9469 (not org-keep-stored-link-after-insertion))
9470 (setq org-stored-links (delq (assoc link org-stored-links)
9473 (if (string-match org-plain-link-re link)
9474 ;; URL-like link, normalize the use of angular brackets.
9475 (setq link (org-remove-angle-brackets link)))
9477 ;; Check if we are linking to the current file with a search option
9478 ;; If yes, simplify the link by using only the search option.
9479 (when (and buffer-file-name
9480 (string-match "^file:\\(.+?\\)::\\([^>]+\\)" link))
9481 (let* ((path (match-string 1 link))
9482 (case-fold-search nil)
9483 (search (match-string 2 link)))
9485 (if (equal (file-truename buffer-file-name) (file-truename path))
9486 ;; We are linking to this same file, with a search option
9487 (setq link search)))))
9489 ;; Check if we can/should use a relative path. If yes, simplify the link
9490 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
9491 (let* ((type (match-string 1 link))
9492 (path (match-string 2 link))
9494 (case-fold-search nil))
9496 ((or (eq org-link-file-path-type 'absolute)
9497 (equal complete-file '(16)))
9498 (setq path (abbreviate-file-name (expand-file-name path))))
9499 ((eq org-link-file-path-type 'noabbrev)
9500 (setq path (expand-file-name path)))
9501 ((eq org-link-file-path-type 'relative)
9502 (setq path (file-relative-name path)))
9505 (if (string-match (concat "^" (regexp-quote
9507 (file-name-as-directory
9508 default-directory))))
9509 (expand-file-name path))
9510 ;; We are linking a file with relative path name.
9511 (setq path (substring (expand-file-name path)
9513 (setq path (abbreviate-file-name (expand-file-name path)))))))
9514 (setq link (concat type path))
9515 (if (equal desc origpath)
9518 (if org-make-link-description-function
9519 (setq desc (funcall org-make-link-description-function link desc))
9520 (if default-description (setq desc default-description)
9521 (setq desc (or (and auto-desc desc)
9522 (read-string "Description: " desc)))))
9524 (unless (string-match "\\S-" desc) (setq desc nil))
9525 (if remove (apply 'delete-region remove))
9526 (insert (org-make-link-string link desc))))
9528 (defun org-link-try-special-completion (type)
9529 "If there is completion support for link type TYPE, offer it."
9530 (let ((fun (intern (concat "org-" type "-complete-link"))))
9533 (read-string "Link (no completion support): " (concat type ":")))))
9535 (defun org-file-complete-link (&optional arg)
9536 "Create a file link using completion."
9538 (setq file (read-file-name "File: "))
9539 (let ((pwd (file-name-as-directory (expand-file-name ".")))
9540 (pwd1 (file-name-as-directory (abbreviate-file-name
9541 (expand-file-name ".")))))
9546 (abbreviate-file-name (expand-file-name file)))))
9547 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
9548 (setq link (concat "file:" (match-string 1 file))))
9549 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
9550 (expand-file-name file))
9552 "file:" (match-string 1 (expand-file-name file)))))
9553 (t (setq link (concat "file:" file)))))
9556 (defun org-completing-read (&rest args)
9557 "Completing-read with SPACE being a normal character."
9558 (let ((enable-recursive-minibuffers t)
9559 (minibuffer-local-completion-map
9560 (copy-keymap minibuffer-local-completion-map)))
9561 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
9562 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
9563 (org-defkey minibuffer-local-completion-map (kbd "C-c !") 'org-time-stamp-inactive)
9564 (apply 'org-icompleting-read args)))
9566 (defun org-completing-read-no-i (&rest args)
9567 (let (org-completion-use-ido org-completion-use-iswitchb)
9568 (apply 'org-completing-read args)))
9570 (defun org-iswitchb-completing-read (prompt choices &rest args)
9571 "Use iswitch as a completing-read replacement to choose from choices.
9572 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
9574 (let* ((iswitchb-use-virtual-buffers nil)
9575 (iswitchb-make-buflist-hook
9577 (setq iswitchb-temp-buflist choices))))
9578 (iswitchb-read-buffer prompt)))
9580 (defun org-icompleting-read (&rest args)
9581 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
9582 (org-without-partial-completion
9583 (if (and org-completion-use-ido
9584 (fboundp 'ido-completing-read)
9585 (boundp 'ido-mode) ido-mode
9586 (listp (second args)))
9587 (let ((ido-enter-matching-directory nil))
9588 (apply 'ido-completing-read (concat (car args))
9589 (if (consp (car (nth 1 args)))
9590 (mapcar 'car (nth 1 args))
9593 (if (and org-completion-use-iswitchb
9594 (boundp 'iswitchb-mode) iswitchb-mode
9595 (listp (second args)))
9596 (apply 'org-iswitchb-completing-read (concat (car args))
9597 (if (consp (car (nth 1 args)))
9598 (mapcar 'car (nth 1 args))
9601 (apply 'completing-read args)))))
9603 (defun org-extract-attributes (s)
9604 "Extract the attributes cookie from a string and set as text property."
9605 (let (a attr (start 0) key value)
9607 (when (string-match "{{\\([^}]+\\)}}$" s)
9608 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
9609 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
9610 (setq key (match-string 1 a) value (match-string 2 a)
9612 attr (plist-put attr (intern key) value))))
9613 (org-add-props s nil 'org-attr attr))
9616 (defun org-extract-attributes-from-string (tag)
9617 (let (key value attr)
9618 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
9619 (setq key (match-string 1 tag) value (match-string 2 tag)
9620 tag (replace-match "" t t tag)
9621 attr (plist-put attr (intern key) value)))
9624 (defun org-attributes-to-string (plist)
9625 "Format a property list into an HTML attribute list."
9626 (let ((s "") key value)
9628 (setq key (pop plist) value (pop plist))
9630 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
9633 ;;; Opening/following a link
9635 (defvar org-link-search-failed nil)
9637 (defvar org-open-link-functions nil
9638 "Hook for functions finding a plain text link.
9639 These functions must take a single argument, the link content.
9640 They will be called for links that look like [[link text][description]]
9641 when LINK TEXT does not have a protocol like \"http:\" and does not look
9642 like a filename (e.g. \"./blue.png\").
9644 These functions will be called *before* Org attempts to resolve the
9645 link by doing text searches in the current buffer - so if you want a
9646 link \"[[target]]\" to still find \"<<target>>\", your function should
9647 handle this as a special case.
9649 When the function does handle the link, it must return a non-nil value.
9650 If it decides that it is not responsible for this link, it must return
9651 nil to indicate that that Org-mode can continue with other options
9652 like exact and fuzzy text search.")
9654 (defun org-next-link ()
9655 "Move forward to the next link.
9656 If the link is in hidden text, expose it."
9658 (when (and org-link-search-failed (eq this-command last-command))
9659 (goto-char (point-min))
9660 (message "Link search wrapped back to beginning of buffer"))
9661 (setq org-link-search-failed nil)
9662 (let* ((pos (point))
9664 (a (assoc :link ct)))
9665 (if a (goto-char (nth 2 a)))
9666 (if (re-search-forward org-any-link-re nil t)
9668 (goto-char (match-beginning 0))
9669 (if (outline-invisible-p) (org-show-context)))
9671 (setq org-link-search-failed t)
9672 (error "No further link found"))))
9674 (defun org-previous-link ()
9675 "Move backward to the previous link.
9676 If the link is in hidden text, expose it."
9678 (when (and org-link-search-failed (eq this-command last-command))
9679 (goto-char (point-max))
9680 (message "Link search wrapped back to end of buffer"))
9681 (setq org-link-search-failed nil)
9682 (let* ((pos (point))
9684 (a (assoc :link ct)))
9685 (if a (goto-char (nth 1 a)))
9686 (if (re-search-backward org-any-link-re nil t)
9688 (goto-char (match-beginning 0))
9689 (if (outline-invisible-p) (org-show-context)))
9691 (setq org-link-search-failed t)
9692 (error "No further link found"))))
9694 (defun org-translate-link (s)
9695 "Translate a link string if a translation function has been defined."
9696 (if (and org-link-translation-function
9697 (fboundp org-link-translation-function)
9698 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
9700 (setq s (funcall org-link-translation-function
9701 (match-string 1 s) (match-string 2 s)))
9702 (concat (car s) ":" (cdr s)))
9705 (defun org-translate-link-from-planner (type path)
9706 "Translate a link from Emacs Planner syntax so that Org can follow it.
9707 This is still an experimental function, your mileage may vary."
9709 ((member type '("http" "https" "news" "ftp"))
9710 ;; standard Internet links are the same.
9712 ((and (equal type "irc") (string-match "^//" path))
9713 ;; Planner has two / at the beginning of an irc link, we have 1.
9714 ;; We should have zero, actually....
9715 (setq path (substring path 1)))
9716 ((and (equal type "lisp") (string-match "^/" path))
9717 ;; Planner has a slash, we do not.
9718 (setq type "elisp" path (substring path 1)))
9719 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
9720 ;; A typical message link. Planner has the id after the final slash,
9721 ;; we separate it with a hash mark
9722 (setq path (concat (match-string 1 path) "#"
9723 (org-remove-angle-brackets (match-string 2 path)))))
9727 (defun org-find-file-at-mouse (ev)
9728 "Open file link or URL at mouse."
9730 (mouse-set-point ev)
9731 (org-open-at-point 'in-emacs))
9733 (defun org-open-at-mouse (ev)
9734 "Open file link or URL at mouse.
9735 See the docstring of `org-open-file' for details."
9737 (mouse-set-point ev)
9738 (if (eq major-mode 'org-agenda-mode)
9739 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
9740 (org-open-at-point))
9742 (defvar org-window-config-before-follow-link nil
9743 "The window configuration before following a link.
9744 This is saved in case the need arises to restore it.")
9746 (defvar org-open-link-marker (make-marker)
9747 "Marker pointing to the location where `org-open-at-point; was called.")
9750 (defun org-open-at-point-global ()
9751 "Follow a link like Org-mode does.
9752 This command can be called in any mode to follow a link that has
9755 (org-run-like-in-org-mode 'org-open-at-point))
9758 (defun org-open-link-from-string (s &optional arg reference-buffer)
9759 "Open a link in the string S, as if it was in Org-mode."
9760 (interactive "sLink: \nP")
9761 (let ((reference-buffer (or reference-buffer (current-buffer))))
9763 (let ((org-inhibit-startup (not reference-buffer)))
9766 (goto-char (point-min))
9767 (when reference-buffer
9768 (setq org-link-abbrev-alist-local
9769 (with-current-buffer reference-buffer
9770 org-link-abbrev-alist-local)))
9771 (org-open-at-point arg reference-buffer)))))
9773 (defvar org-open-at-point-functions nil
9774 "Hook that is run when following a link at point.
9776 Functions in this hook must return t if they identify and follow
9777 a link at point. If they don't find anything interesting at point,
9778 they must return nil.")
9780 (defvar clean-buffer-list-kill-buffer-names) ; Defined in midnight.el
9781 (defun org-open-at-point (&optional arg reference-buffer)
9782 "Open link at or after point.
9783 If there is no link at point, this function will search forward up to
9784 the end of the current line.
9785 Normally, files will be opened by an appropriate application. If the
9786 optional prefix argument ARG is non-nil, Emacs will visit the file.
9787 With a double prefix argument, try to open outside of Emacs, in the
9788 application the system uses for this file type."
9790 ;; if in a code block, then open the block's results
9791 (unless (call-interactively #'org-babel-open-src-block-result)
9792 (org-load-modules-maybe)
9793 (move-marker org-open-link-marker (point))
9794 (setq org-window-config-before-follow-link (current-window-configuration))
9795 (org-remove-occur-highlights nil nil t)
9797 ((and (org-at-heading-p)
9798 (not (org-at-timestamp-p t))
9800 (concat org-plain-link-re "\\|"
9801 org-bracket-link-regexp "\\|"
9802 org-angle-link-re "\\|"
9803 "[ \t]:[^ \t\n]+:[ \t]*$")))
9804 (not (get-text-property (point) 'org-linked-text)))
9805 (or (org-offer-links-in-entry arg)
9806 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
9807 ((run-hook-with-args-until-success 'org-open-at-point-functions))
9808 ((org-at-timestamp-p t) (org-follow-timestamp-link))
9809 ((and (or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
9810 (not (org-in-regexp org-bracket-link-regexp)))
9811 (org-footnote-action))
9813 (let (type path link line search (pos (point)))
9816 (skip-chars-forward "^]\n\r")
9817 (when (org-in-regexp org-bracket-link-regexp 1)
9818 (setq link (org-extract-attributes
9819 (org-link-unescape (org-match-string-no-properties 1))))
9820 (while (string-match " *\n *" link)
9821 (setq link (replace-match " " t t link)))
9822 (setq link (org-link-expand-abbrev link))
9824 ((or (file-name-absolute-p link)
9825 (string-match "^\\.\\.?/" link))
9826 (setq type "file" path link))
9827 ((string-match org-link-re-with-space3 link)
9828 (setq type (match-string 1 link) path (match-string 2 link)))
9829 ((string-match "^help:+\\(.+\\)" link)
9830 (setq type "help" path (match-string 1 link)))
9831 (t (setq type "thisfile" path link)))
9834 (when (get-text-property (point) 'org-linked-text)
9835 (setq type "thisfile"
9836 pos (if (get-text-property (1+ (point)) 'org-linked-text)
9837 (1+ (point)) (point))
9838 path (buffer-substring
9839 (or (previous-single-property-change pos 'org-linked-text)
9841 (or (next-single-property-change pos 'org-linked-text)
9846 (when (or (org-in-regexp org-angle-link-re)
9847 (and (goto-char (car (org-in-regexp org-plain-link-re)))
9848 (save-match-data (not (looking-back "\\[\\[")))))
9849 (setq type (match-string 1)
9850 path (org-link-unescape (match-string 2)))
9853 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@#%:]+\\):[ \t]*$"))
9855 path (match-string 1))
9856 (while (string-match ":" path)
9857 (setq path (replace-match "+" t t path)))
9859 (when (org-in-regexp "<\\([^><\n]+\\)>")
9860 (setq type "tree-match"
9861 path (match-string 1))
9864 (error "No link found"))
9866 ;; switch back to reference buffer
9867 ;; needed when if called in a temporary buffer through
9868 ;; org-open-link-from-string
9869 (with-current-buffer (or reference-buffer (current-buffer))
9871 ;; Remove any trailing spaces in path
9872 (if (string-match " +\\'" path)
9873 (setq path (replace-match "" t t path)))
9874 (if (and org-link-translation-function
9875 (fboundp org-link-translation-function))
9876 ;; Check if we need to translate the link
9877 (let ((tmp (funcall org-link-translation-function type path)))
9878 (setq type (car tmp) path (cdr tmp))))
9882 ((assoc type org-link-protocols)
9883 (funcall (nth 1 (assoc type org-link-protocols)) path))
9885 ((equal type "help")
9886 (let ((f-or-v (intern path)))
9887 (cond ((fboundp f-or-v)
9888 (describe-function f-or-v))
9890 (describe-variable f-or-v))
9891 (t (error "Not a known function or variable")))))
9893 ((equal type "mailto")
9894 (let ((cmd (car org-link-mailto-program))
9895 (args (cdr org-link-mailto-program)) args1
9896 (address path) (subject "") a)
9897 (if (string-match "\\(.*\\)::\\(.*\\)" path)
9898 (setq address (match-string 1 path)
9899 subject (org-link-escape (match-string 2 path))))
9902 ((not (stringp (car args))) (push (pop args) args1))
9903 (t (setq a (pop args))
9904 (if (string-match "%a" a)
9905 (setq a (replace-match address t t a)))
9906 (if (string-match "%s" a)
9907 (setq a (replace-match subject t t a)))
9909 (apply cmd (nreverse args1))))
9911 ((member type '("http" "https" "ftp" "news"))
9912 (browse-url (concat type ":" (if (org-string-match-p "[[:nonascii:] ]" path)
9914 path org-link-escape-chars-browser)
9917 ((string= type "doi")
9918 (browse-url (concat org-doi-server-url (if (org-string-match-p "[[:nonascii:] ]" path)
9920 path org-link-escape-chars-browser)
9923 ((member type '("message"))
9924 (browse-url (concat type ":" path)))
9926 ((string= type "tags")
9927 (org-tags-view arg path))
9929 ((string= type "tree-match")
9930 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
9932 ((string= type "file")
9933 (if (string-match "::\\([0-9]+\\)\\'" path)
9934 (setq line (string-to-number (match-string 1 path))
9935 path (substring path 0 (match-beginning 0)))
9936 (if (string-match "::\\(.+\\)\\'" path)
9937 (setq search (match-string 1 path)
9938 path (substring path 0 (match-beginning 0)))))
9939 (if (string-match "[*?{]" (file-name-nondirectory path))
9941 (org-open-file path arg line search)))
9943 ((string= type "shell")
9944 (let ((buf (generate-new-buffer "*Org Shell Output"))
9946 (if (or (and (not (string= org-confirm-shell-link-not-regexp ""))
9947 (string-match org-confirm-shell-link-not-regexp cmd))
9948 (not org-confirm-shell-link-function)
9949 (funcall org-confirm-shell-link-function
9950 (format "Execute \"%s\" in shell? "
9951 (org-add-props cmd nil
9952 'face 'org-warning))))
9954 (message "Executing %s" cmd)
9955 (shell-command cmd buf)
9956 (if (featurep 'midnight)
9957 (setq clean-buffer-list-kill-buffer-names
9958 (cons buf clean-buffer-list-kill-buffer-names))))
9961 ((string= type "elisp")
9963 (if (or (and (not (string= org-confirm-elisp-link-not-regexp ""))
9964 (string-match org-confirm-elisp-link-not-regexp cmd))
9965 (not org-confirm-elisp-link-function)
9966 (funcall org-confirm-elisp-link-function
9967 (format "Execute \"%s\" as elisp? "
9968 (org-add-props cmd nil
9969 'face 'org-warning))))
9970 (message "%s => %s" cmd
9971 (if (equal (string-to-char cmd) ?\()
9973 (call-interactively (read cmd))))
9976 ((and (string= type "thisfile")
9977 (run-hook-with-args-until-success
9978 'org-open-link-functions path)))
9980 ((string= type "thisfile")
9982 (switch-to-buffer-other-window
9983 (org-get-buffer-for-internal-link (current-buffer)))
9984 (org-mark-ring-push))
9985 (let ((cmd `(org-link-search
9987 ,(cond ((equal arg '(4)) ''occur)
9988 ((equal arg '(16)) ''org-occur))
9990 (condition-case nil (let ((org-link-search-inhibit-query t))
9992 (error (progn (widen) (eval cmd))))))
9994 (t (browse-url-at-point)))))))
9995 (move-marker org-open-link-marker nil)
9996 (run-hook-with-args 'org-follow-link-hook)))
9998 (defun org-offer-links-in-entry (&optional nth zero)
9999 "Offer links in the current entry and follow the selected link.
10000 If there is only one link, follow it immediately as well.
10001 If NTH is an integer, immediately pick the NTH link found.
10002 If ZERO is a string, check also this string for a link, and if
10003 there is one, offer it as link number zero."
10004 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
10005 "\\(" org-angle-link-re "\\)\\|"
10006 "\\(" org-plain-link-re "\\)"))
10008 (in-emacs (if (integerp nth) nil nth))
10009 have-zero end links link c)
10010 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
10011 (push (match-string 0 zero) links)
10012 (setq cnt (1- cnt) have-zero t))
10014 (org-back-to-heading t)
10015 (setq end (save-excursion (outline-next-heading) (point)))
10016 (while (re-search-forward re end t)
10017 (push (match-string 0) links))
10018 (setq links (org-uniquify (reverse links))))
10022 (message "No links"))
10023 ((equal (length links) 1)
10024 (setq link (list (car links))))
10025 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
10026 (setq link (list (nth (if have-zero nth (1- nth)) links))))
10027 (t ; we have to select a link
10029 (save-window-excursion
10030 (delete-other-windows)
10031 (with-output-to-temp-buffer "*Select Link*"
10033 (if (not (string-match org-bracket-link-regexp l))
10034 (princ (format "[%c] %s\n" (incf cnt)
10035 (org-remove-angle-brackets l)))
10037 (princ (format "[%c] %s (%s)\n" (incf cnt)
10038 (match-string 3 l) (match-string 1 l)))
10039 (princ (format "[%c] %s\n" (incf cnt)
10040 (match-string 1 l))))))
10042 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
10043 (message "Select link to open, RET to open all:")
10044 (setq c (read-char-exclusive))
10045 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
10046 (when (equal c ?q) (error "Abort"))
10047 (if (equal c ?\C-m)
10049 (setq nth (- c ?0))
10050 (if have-zero (setq nth (1+ nth)))
10051 (unless (and (integerp nth) (>= (length links) nth))
10052 (error "Invalid link selection"))
10053 (setq link (list (nth (1- nth) links))))))
10055 (let ((buf (current-buffer)))
10057 (org-open-link-from-string l in-emacs buf))
10061 ;; Add special file links that specify the way of opening
10063 (org-add-link-type "file+sys" 'org-open-file-with-system)
10064 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
10065 (defun org-open-file-with-system (path)
10066 "Open file at PATH using the system way of opening it."
10067 (org-open-file path 'system))
10068 (defun org-open-file-with-emacs (path)
10069 "Open file at PATH in Emacs."
10070 (org-open-file path 'emacs))
10071 (defun org-remove-file-link-modifiers ()
10072 "Remove the file link modifiers in `file+sys:' and `file+emacs:' links."
10073 (goto-char (point-min))
10074 (while (re-search-forward "\\<file\\+\\(sys\\|emacs\\):" nil t)
10075 (org-if-unprotected
10076 (replace-match "file:" t t))))
10077 (eval-after-load "org-exp"
10078 '(add-hook 'org-export-preprocess-before-normalizing-links-hook
10079 'org-remove-file-link-modifiers))
10081 ;;;; Time estimates
10083 (defun org-get-effort (&optional pom)
10084 "Get the effort estimate for the current entry."
10085 (org-entry-get pom org-effort-property))
10089 (defvar org-create-file-search-functions nil
10090 "List of functions to construct the right search string for a file link.
10091 These functions are called in turn with point at the location to
10092 which the link should point.
10094 A function in the hook should first test if it would like to
10095 handle this file type, for example by checking the `major-mode'
10096 or the file extension. If it decides not to handle this file, it
10097 should just return nil to give other functions a chance. If it
10098 does handle the file, it must return the search string to be used
10099 when following the link. The search string will be part of the
10100 file link, given after a double colon, and `org-open-at-point'
10101 will automatically search for it. If special measures must be
10102 taken to make the search successful, another function should be
10103 added to the companion hook `org-execute-file-search-functions',
10106 A function in this hook may also use `setq' to set the variable
10107 `description' to provide a suggestion for the descriptive text to
10108 be used for this link when it gets inserted into an Org-mode
10109 buffer with \\[org-insert-link].")
10111 (defvar org-execute-file-search-functions nil
10112 "List of functions to execute a file search triggered by a link.
10114 Functions added to this hook must accept a single argument, the
10115 search string that was part of the file link, the part after the
10116 double colon. The function must first check if it would like to
10117 handle this search, for example by checking the `major-mode' or
10118 the file extension. If it decides not to handle this search, it
10119 should just return nil to give other functions a chance. If it
10120 does handle the search, it must return a non-nil value to keep
10121 other functions from trying.
10123 Each function can access the current prefix argument through the
10124 variable `current-prefix-argument'. Note that a single prefix is
10125 used to force opening a link in Emacs, so it may be good to only
10126 use a numeric or double prefix to guide the search function.
10128 In case this is needed, a function in this hook can also restore
10129 the window configuration before `org-open-at-point' was called using:
10131 (set-window-configuration org-window-config-before-follow-link)")
10133 (defvar org-link-search-inhibit-query nil) ;; dynamically scoped
10134 (defun org-link-search (s &optional type avoid-pos stealth)
10135 "Search for a link search option.
10136 If S is surrounded by forward slashes, it is interpreted as a
10137 regular expression. In org-mode files, this will create an `org-occur'
10138 sparse tree. In ordinary files, `occur' will be used to list matches.
10139 If the current buffer is in `dired-mode', grep will be used to search
10140 in all files. If AVOID-POS is given, ignore matches near that position.
10142 When optional argument STEALTH is non-nil, do not modify
10143 visibility around point, thus ignoring
10144 `org-show-hierarchy-above', `org-show-following-heading' and
10145 `org-show-siblings' variables."
10146 (let ((case-fold-search t)
10147 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
10148 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
10149 (append '(("") (" ") ("\t") ("\n"))
10150 org-emphasis-alist)
10153 (pre nil) (post nil)
10154 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
10156 ;; First check if there are any special search functions
10157 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
10158 ;; Now try the builtin stuff
10159 ((and (equal (string-to-char s0) ?#)
10162 (goto-char (point-min))
10165 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
10166 (setq type 'dedicated
10167 pos (match-beginning 0))))
10168 ;; There is an exact target for this
10170 (org-back-to-heading t)))
10172 (goto-char (point-min))
10175 (concat "<<" (regexp-quote s0) ">>") nil t)
10176 (setq type 'dedicated
10177 pos (match-beginning 0))))
10178 ;; There is an exact target for this
10181 (goto-char (point-min))
10184 (format "^[ \t]*#\\+TARGET: %s" (regexp-quote s0)) nil t)
10185 (setq type 'dedicated pos (match-beginning 0))))
10186 ;; Found an invisible target.
10189 (goto-char (point-min))
10192 (format "^[ \t]*#\\+NAME: %s" (regexp-quote s0)) nil t)
10193 (setq type 'dedicated pos (match-beginning 0))))
10194 ;; Found an element with a matching #+name affiliated keyword.
10196 ((and (string-match "^(\\(.*\\))$" s0)
10198 (goto-char (point-min))
10201 (concat "[^[]" (regexp-quote
10202 (format org-coderef-label-format
10203 (match-string 1 s0))))
10205 (setq type 'dedicated
10206 pos (1+ (match-beginning 0))))))
10207 ;; There is a coderef target for this
10209 ((string-match "^/\\(.*\\)/$" s)
10210 ;; A regular expression
10212 ((derived-mode-p 'org-mode)
10213 (org-occur (match-string 1 s)))
10214 ;;((eq major-mode 'dired-mode)
10215 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
10216 (t (org-do-occur (match-string 1 s)))))
10217 ((and (derived-mode-p 'org-mode) org-link-search-must-match-exact-headline)
10218 (and (equal (string-to-char s) ?*) (setq s (substring s 1)))
10219 (goto-char (point-min))
10221 ((let (case-fold-search)
10222 (re-search-forward (format org-complex-heading-regexp-format
10225 ;; OK, found a match
10226 (setq type 'dedicated)
10227 (goto-char (match-beginning 0)))
10228 ((and (not org-link-search-inhibit-query)
10229 (eq org-link-search-must-match-exact-headline 'query-to-create)
10230 (y-or-n-p "No match - create this as a new heading? "))
10231 (goto-char (point-max))
10232 (or (bolp) (newline))
10233 (insert "* " s "\n")
10234 (beginning-of-line 0))
10237 (error "No match"))))
10239 ;; A normal search string
10240 (when (equal (string-to-char s) ?*)
10241 ;; Anchor on headlines, post may include tags.
10242 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
10243 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@#%:+]:[ \t]*\\)?$")
10244 s (substring s 1)))
10245 (remove-text-properties
10247 '(face nil mouse-face nil keymap nil fontified nil) s)
10248 ;; Make a series of regular expressions to find a match
10249 (setq words (org-split-string s "[ \n\r\t]+")
10251 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
10252 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
10254 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
10255 re2a (concat "[ \t\r\n]" re2a_)
10256 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
10257 re4 (concat "[^a-zA-Z_]" re4_)
10259 re1 (concat pre re2 post)
10260 re3 (concat pre (if pre re4_ re4) post)
10261 re5 (concat pre ".*" re4)
10262 re2 (concat pre re2)
10263 re2a (concat pre (if pre re2a_ re2a))
10264 re4 (concat pre (if pre re4_ re4))
10265 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
10266 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
10270 ((eq type 'org-occur) (org-occur reall))
10271 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
10272 (t (goto-char (point-min))
10274 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
10275 (org-search-not-self 1 re1 nil t)
10276 (org-search-not-self 1 re2 nil t)
10277 (org-search-not-self 1 re2a nil t)
10278 (org-search-not-self 1 re3 nil t)
10279 (org-search-not-self 1 re4 nil t)
10280 (org-search-not-self 1 re5 nil t)
10282 (goto-char (match-beginning 1))
10284 (error "No match"))))))
10285 (and (derived-mode-p 'org-mode)
10287 (org-show-context 'link-search))
10290 (defun org-search-not-self (group &rest args)
10291 "Execute `re-search-forward', but only accept matches that do not
10292 enclose the position of `org-open-link-marker'."
10293 (let ((m org-open-link-marker))
10295 (while (apply 're-search-forward args)
10296 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
10297 (goto-char (match-end group))
10298 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
10299 (> (match-beginning 0) (marker-position m))
10300 (< (match-end 0) (marker-position m)))
10302 (or (not (org-in-regexp
10303 org-bracket-link-analytic-regexp 1))
10304 (not (match-end 4)) ; no description
10305 (and (<= (match-beginning 4) (point))
10306 (>= (match-end 4) (point))))))
10307 (throw 'exit (point))))))))
10309 (defun org-get-buffer-for-internal-link (buffer)
10310 "Return a buffer to be used for displaying the link target of internal links."
10312 ((not org-display-internal-link-with-indirect-buffer)
10314 ((string-match "(Clone)$" (buffer-name buffer))
10315 (message "Buffer is already a clone, not making another one")
10316 ;; we also do not modify visibility in this case
10318 (t ; make a new indirect buffer for displaying the link
10319 (let* ((bn (buffer-name buffer))
10320 (ibn (concat bn "(Clone)"))
10321 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
10322 (with-current-buffer ib (org-overview))
10325 (defun org-do-occur (regexp &optional cleanup)
10326 "Call the Emacs command `occur'.
10327 If CLEANUP is non-nil, remove the printout of the regular expression
10328 in the *Occur* buffer. This is useful if the regex is long and not useful
10332 (let ((cwin (selected-window)) win beg end)
10333 (when (setq win (get-buffer-window "*Occur*"))
10334 (select-window win))
10335 (goto-char (point-min))
10336 (when (re-search-forward "match[a-z]+" nil t)
10337 (setq beg (match-end 0))
10338 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
10339 (setq end (1- (match-beginning 0)))))
10340 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
10341 (goto-char (point-min))
10342 (select-window cwin))))
10344 ;;; The mark ring for links jumps
10346 (defvar org-mark-ring nil
10347 "Mark ring for positions before jumps in Org-mode.")
10348 (defvar org-mark-ring-last-goto nil
10349 "Last position in the mark ring used to go back.")
10350 ;; Fill and close the ring
10351 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
10352 (loop for i from 1 to org-mark-ring-length do
10353 (push (make-marker) org-mark-ring))
10354 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
10357 (defun org-mark-ring-push (&optional pos buffer)
10358 "Put the current position or POS into the mark ring and rotate it."
10360 (setq pos (or pos (point)))
10361 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
10362 (move-marker (car org-mark-ring)
10364 (or buffer (current-buffer)))
10366 (substitute-command-keys
10367 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
10369 (defun org-mark-ring-goto (&optional n)
10370 "Jump to the previous position in the mark ring.
10371 With prefix arg N, jump back that many stored positions. When
10372 called several times in succession, walk through the entire ring.
10373 Org-mode commands jumping to a different position in the current file,
10374 or to another Org-mode file, automatically push the old position
10378 (if (eq last-command this-command)
10379 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
10380 (setq p org-mark-ring))
10381 (setq org-mark-ring-last-goto p)
10383 (org-pop-to-buffer-same-window (marker-buffer m))
10385 (if (or (outline-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
10387 (defun org-remove-angle-brackets (s)
10388 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
10389 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
10391 (defun org-add-angle-brackets (s)
10392 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
10393 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
10395 (defun org-remove-double-quotes (s)
10396 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
10397 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
10400 ;;; Following specific links
10402 (defun org-follow-timestamp-link ()
10404 ((org-at-date-range-p t)
10405 (let ((org-agenda-start-on-weekday)
10406 (t1 (match-string 1))
10407 (t2 (match-string 2)))
10408 (setq t1 (time-to-days (org-time-string-to-time t1))
10409 t2 (time-to-days (org-time-string-to-time t2)))
10410 (org-agenda-list nil t1 (1+ (- t2 t1)))))
10411 ((org-at-timestamp-p t)
10412 (org-agenda-list nil (time-to-days (org-time-string-to-time
10413 (substring (match-string 1) 0 10)))
10415 (t (error "This should not happen"))))
10418 ;;; Following file links
10419 (declare-function mailcap-parse-mailcaps "mailcap" (&optional path force))
10420 (declare-function mailcap-extension-to-mime "mailcap" (extn))
10421 (declare-function mailcap-mime-info
10422 "mailcap" (string &optional request no-decode))
10423 (defvar org-wait nil)
10424 (defun org-open-file (path &optional in-emacs line search)
10425 "Open the file at PATH.
10426 First, this expands any special file name abbreviations. Then the
10427 configuration variable `org-file-apps' is checked if it contains an
10428 entry for this file type, and if yes, the corresponding command is launched.
10430 If no application is found, Emacs simply visits the file.
10432 With optional prefix argument IN-EMACS, Emacs will visit the file.
10433 With a double \\[universal-argument] \\[universal-argument] \
10434 prefix arg, Org tries to avoid opening in Emacs
10435 and to use an external application to visit the file.
10437 Optional LINE specifies a line to go to, optional SEARCH a string
10438 to search for. If LINE or SEARCH is given, the file will be
10439 opened in Emacs, unless an entry from org-file-apps that makes
10440 use of groups in a regexp matches.
10442 If you want to change the way frames are used when following a
10443 link, please customize `org-link-frame-setup'.
10445 If the file does not exist, an error is thrown."
10446 (let* ((file (if (equal path "")
10448 (substitute-in-file-name (expand-file-name path))))
10449 (file-apps (append org-file-apps (org-default-apps)))
10450 (apps (org-remove-if
10451 'org-file-apps-entry-match-against-dlink-p file-apps))
10452 (apps-dlink (org-remove-if-not
10453 'org-file-apps-entry-match-against-dlink-p file-apps))
10454 (remp (and (assq 'remote apps) (org-file-remote-p file)))
10455 (dirp (if remp nil (file-directory-p file)))
10456 (file (if (and dirp org-open-directory-means-index-dot-org)
10457 (concat (file-name-as-directory file) "index.org")
10459 (a-m-a-p (assq 'auto-mode apps))
10460 (dfile (downcase file))
10461 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
10462 (link (cond ((and (eq line nil)
10466 (concat file "::" (number-to-string line)))
10468 (concat file "::" search))))
10469 (dlink (downcase link))
10470 (old-buffer (current-buffer))
10472 (old-mode major-mode)
10473 ext cmd link-match-data)
10474 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
10475 (setq ext (match-string 1 dfile))
10476 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
10477 (setq ext (match-string 1 dfile))))
10479 ((member in-emacs '((16) system))
10480 (setq cmd (cdr (assoc 'system apps))))
10481 (in-emacs (setq cmd 'emacs))
10483 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
10484 (and dirp (cdr (assoc 'directory apps)))
10485 ; first, try matching against apps-dlink
10486 ; if we get a match here, store the match data for later
10487 (let ((match (assoc-default dlink apps-dlink
10490 (progn (setq link-match-data (match-data))
10492 (progn (setq in-emacs (or in-emacs line search))
10493 nil))) ; if we have no match in apps-dlink,
10494 ; always open the file in emacs if line or search
10495 ; is given (for backwards compatibility)
10496 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
10498 (cdr (assoc ext apps))
10499 (cdr (assoc t apps))))))
10500 (when (eq cmd 'system)
10501 (setq cmd (cdr (assoc 'system apps))))
10502 (when (eq cmd 'default)
10503 (setq cmd (cdr (assoc t apps))))
10504 (when (eq cmd 'mailcap)
10506 (mailcap-parse-mailcaps)
10507 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
10508 (command (mailcap-mime-info mime-type)))
10509 (if (stringp command)
10511 (setq cmd 'emacs))))
10512 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
10513 (not (file-exists-p file))
10514 (not org-open-non-existing-files))
10515 (error "No such file: %s" file))
10517 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
10518 ;; Remove quotes around the file name - we'll use shell-quote-argument.
10519 (while (string-match "['\"]%s['\"]" cmd)
10520 (setq cmd (replace-match "%s" t t cmd)))
10521 (while (string-match "%s" cmd)
10522 (setq cmd (replace-match
10524 (shell-quote-argument
10525 (convert-standard-filename file)))
10528 ;; Replace "%1", "%2" etc. in command with group matches from regex
10530 (let ((match-index 1)
10531 (number-of-groups (- (/ (length link-match-data) 2) 1)))
10532 (set-match-data link-match-data)
10533 (while (<= match-index number-of-groups)
10534 (let ((regex (concat "%" (number-to-string match-index)))
10535 (replace-with (match-string match-index dlink)))
10536 (while (string-match regex cmd)
10537 (setq cmd (replace-match replace-with t t cmd))))
10538 (setq match-index (+ match-index 1)))))
10540 (save-window-excursion
10541 (start-process-shell-command cmd nil cmd)
10542 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
10546 (funcall (cdr (assq 'file org-link-frame-setup)) file)
10548 (if line (org-goto-line line)
10549 (if search (org-link-search search))))
10551 (let ((file (convert-standard-filename file)))
10553 (set-match-data link-match-data)
10555 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
10556 (and (derived-mode-p 'org-mode) (eq old-mode 'org-mode)
10557 (or (not (equal old-buffer (current-buffer)))
10558 (not (equal old-pos (point))))
10559 (org-mark-ring-push old-pos old-buffer))))
10561 (defun org-file-apps-entry-match-against-dlink-p (entry)
10562 "This function returns non-nil if `entry' uses a regular
10563 expression which should be matched against the whole link by
10566 It assumes that is the case when the entry uses a regular
10567 expression which has at least one grouping construct and the
10568 action is either a lisp form or a command string containing
10569 '%1', i.e. using at least one subexpression match as a
10571 (let ((selector (car entry))
10572 (action (cdr entry)))
10573 (if (stringp selector)
10574 (and (> (regexp-opt-depth selector) 0)
10575 (or (and (stringp action)
10576 (string-match "%[0-9]" action))
10580 (defun org-default-apps ()
10581 "Return the default applications for this operating system."
10583 ((eq system-type 'darwin)
10584 org-file-apps-defaults-macosx)
10585 ((eq system-type 'windows-nt)
10586 org-file-apps-defaults-windowsnt)
10587 (t org-file-apps-defaults-gnu)))
10589 (defun org-apps-regexp-alist (list &optional add-auto-mode)
10590 "Convert extensions to regular expressions in the cars of LIST.
10591 Also, weed out any non-string entries, because the return value is used
10592 only for regexp matching.
10593 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
10594 point to the symbol `emacs', indicating that the file should
10595 be opened in Emacs."
10598 (mapcar (lambda (x)
10599 (if (not (stringp (car x)))
10601 (if (string-match "\\W" (car x))
10603 (cons (concat "\\." (car x) "\\'") (cdr x)))))
10606 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
10608 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
10609 (defun org-file-remote-p (file)
10610 "Test whether FILE specifies a location on a remote system.
10611 Return non-nil if the location is indeed remote.
10613 For example, the filename \"/user@host:/foo\" specifies a location
10614 on the system \"/user@host:\"."
10615 (cond ((fboundp 'file-remote-p)
10616 (file-remote-p file))
10617 ((fboundp 'tramp-handle-file-remote-p)
10618 (tramp-handle-file-remote-p file))
10619 ((and (boundp 'ange-ftp-name-format)
10620 (string-match (car ange-ftp-name-format) file))
10626 (defun org-get-org-file ()
10627 "Read a filename, with default directory `org-directory'."
10628 (let ((default (or org-default-notes-file remember-data-file)))
10629 (read-file-name (format "File name [%s]: " default)
10630 (file-name-as-directory org-directory)
10633 (defun org-notes-order-reversed-p ()
10634 "Check if the current file should receive notes in reversed order."
10636 ((not org-reverse-note-order) nil)
10637 ((eq t org-reverse-note-order) t)
10638 ((not (listp org-reverse-note-order)) nil)
10640 (let ((all org-reverse-note-order)
10642 (while (setq entry (pop all))
10643 (if (string-match (car entry) buffer-file-name)
10644 (throw 'exit (cdr entry))))
10647 (defvar org-refile-target-table nil
10648 "The list of refile targets, created by `org-refile'.")
10650 (defvar org-agenda-new-buffers nil
10651 "Buffers created to visit agenda files.")
10653 (defvar org-refile-cache nil
10654 "Cache for refile targets.")
10656 (defvar org-refile-markers nil
10657 "All the markers used for caching refile locations.")
10659 (defun org-refile-marker (pos)
10660 "Get a new refile marker, but only if caching is in use."
10661 (if (not org-refile-use-cache)
10663 (let ((m (make-marker)))
10664 (move-marker m pos)
10665 (push m org-refile-markers)
10668 (defun org-refile-cache-clear ()
10669 "Clear the refile cache and disable all the markers."
10670 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
10671 (setq org-refile-markers nil)
10672 (setq org-refile-cache nil)
10673 (message "Refile cache has been cleared"))
10675 (defun org-refile-cache-check-set (set)
10676 "Check if all the markers in the cache still have live buffers."
10679 (while (and set (setq marker (nth 3 (pop set))))
10680 ;; if org-refile-use-outline-path is 'file, marker may be nil
10681 (when (and marker (null (marker-buffer marker)))
10682 (message "not found") (sit-for 3)
10683 (throw 'exit nil)))
10686 (defun org-refile-cache-put (set &rest identifiers)
10687 "Push the refile targets SET into the cache, under IDENTIFIERS."
10688 (let* ((key (sha1 (prin1-to-string identifiers)))
10689 (entry (assoc key org-refile-cache)))
10692 (push (cons key set) org-refile-cache))))
10694 (defun org-refile-cache-get (&rest identifiers)
10695 "Retrieve the cached value for refile targets given by IDENTIFIERS."
10697 ((not org-refile-cache) nil)
10698 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
10700 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
10701 org-refile-cache))))
10702 (and set (org-refile-cache-check-set set) set)))))
10704 (defun org-refile-get-targets (&optional default-buffer excluded-entries)
10705 "Produce a table with refile targets."
10706 (let ((case-fold-search nil)
10707 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
10708 (entries (or org-refile-targets '((nil . (:level . 1)))))
10709 targets tgs txt re files f desc descre fast-path-p level pos0)
10710 (message "Getting targets...")
10711 (with-current-buffer (or default-buffer (current-buffer))
10712 (while (setq entry (pop entries))
10713 (setq files (car entry) desc (cdr entry))
10714 (setq fast-path-p nil)
10716 ((null files) (setq files (list (current-buffer))))
10717 ((eq files 'org-agenda-files)
10718 (setq files (org-agenda-files 'unrestricted)))
10719 ((and (symbolp files) (fboundp files))
10720 (setq files (funcall files)))
10721 ((and (symbolp files) (boundp files))
10722 (setq files (symbol-value files))))
10723 (if (stringp files) (setq files (list files)))
10725 ((eq (car desc) :tag)
10726 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
10727 ((eq (car desc) :todo)
10728 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
10729 ((eq (car desc) :regexp)
10730 (setq descre (cdr desc)))
10731 ((eq (car desc) :level)
10732 (setq descre (concat "^\\*\\{" (number-to-string
10733 (if org-odd-levels-only
10734 (1- (* 2 (cdr desc)))
10737 ((eq (car desc) :maxlevel)
10738 (setq fast-path-p t)
10739 (setq descre (concat "^\\*\\{1," (number-to-string
10740 (if org-odd-levels-only
10741 (1- (* 2 (cdr desc)))
10744 (t (error "Bad refiling target description %s" desc)))
10745 (while (setq f (pop files))
10746 (with-current-buffer
10747 (if (bufferp f) f (org-get-agenda-file-buffer f))
10749 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
10751 (if (bufferp f) (setq f (buffer-file-name
10752 (buffer-base-buffer f))))
10753 (setq f (and f (expand-file-name f)))
10754 (if (eq org-refile-use-outline-path 'file)
10755 (push (list (file-name-nondirectory f) f nil nil) tgs))
10759 (goto-char (point-min))
10760 (while (re-search-forward descre nil t)
10761 (goto-char (setq pos0 (point-at-bol)))
10763 (when org-refile-target-verify-function
10765 (or (funcall org-refile-target-verify-function)
10767 (when (and (looking-at org-complex-heading-regexp)
10768 (not (member (match-string 4) excluded-entries))
10770 (setq level (org-reduced-level
10771 (- (match-end 1) (match-beginning 1)))
10772 txt (org-link-display-format (match-string 4))
10773 txt (replace-regexp-in-string "\\( *\[[0-9]+/?[0-9]*%?\]\\)+$" "" txt)
10774 re (format org-complex-heading-regexp-format
10775 (regexp-quote (match-string 4))))
10776 (when org-refile-use-outline-path
10777 (setq txt (mapconcat
10780 (if (eq org-refile-use-outline-path
10782 (list (file-name-nondirectory
10784 (buffer-base-buffer))))
10785 (if (eq org-refile-use-outline-path
10787 (list (buffer-file-name
10788 (buffer-base-buffer)))))
10789 (org-get-outline-path fast-path-p
10793 (push (list txt f re (org-refile-marker (point)))
10795 (when (= (point) pos0)
10796 ;; verification function has not moved point
10797 (goto-char (point-at-eol))))))))
10798 (when org-refile-use-cache
10799 (org-refile-cache-put tgs (buffer-file-name) descre))
10800 (setq targets (append tgs targets))
10802 (message "Getting targets...done")
10803 (nreverse targets)))
10805 (defun org-protect-slash (s)
10806 (while (string-match "/" s)
10807 (setq s (replace-match "\\" t t s)))
10810 (defvar org-olpa (make-vector 20 nil))
10812 (defun org-get-outline-path (&optional fastp level heading)
10813 "Return the outline path to the current entry, as a list.
10815 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
10816 routine which makes outline path derivations for an entire file,
10817 avoiding backtracing. Refile target collection makes use of that."
10821 (error "Outline path failure, more than 19 levels"))
10822 (loop for i from level upto 19 do
10823 (aset org-olpa i nil))
10825 (delq nil (append org-olpa nil))
10826 (aset org-olpa level heading)))
10827 (let (rtn case-fold-search)
10831 (while (org-up-heading-safe)
10832 (when (looking-at org-complex-heading-regexp)
10833 (push (org-match-string-no-properties 4) rtn)))
10836 (defun org-format-outline-path (path &optional width prefix)
10837 "Format the outline path PATH for display.
10838 Width is the maximum number of characters that is available.
10839 Prefix is a prefix to be included in the returned string,
10840 such as the file name."
10841 (setq width (or width 79))
10842 (if prefix (setq width (- width (length prefix))))
10845 (let* ((nsteps (length path))
10846 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
10847 (maxwidth (if (<= total-width width)
10848 10000 ;; everything fits
10849 ;; we need to shorten the level headings
10850 (/ (- width nsteps) nsteps)))
10851 (org-odd-levels-only nil)
10853 (total (1+ (length prefix))))
10854 (setq maxwidth (max maxwidth 10))
10859 (if (and (= n nsteps) (< maxwidth 10000))
10860 (setq maxwidth (- total-width total)))
10861 (if (< (length h) maxwidth)
10862 (progn (setq total (+ total (length h) 1)) h)
10863 (setq h (substring h 0 (- maxwidth 2))
10864 total (+ total maxwidth 1))
10865 (if (string-match "[ \t]+\\'" h)
10866 (setq h (substring h 0 (match-beginning 0))))
10867 (setq h (concat h "..")))
10868 (org-add-props h nil 'face
10869 (nth (% (1- n) org-n-level-faces)
10874 (defun org-display-outline-path (&optional file current)
10875 "Display the current outline path in the echo area."
10877 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
10878 (case-fold-search nil)
10879 (path (and (derived-mode-p 'org-mode) (org-get-outline-path))))
10880 (if current (setq path (append path
10882 (org-back-to-heading t)
10883 (if (looking-at org-complex-heading-regexp)
10884 (list (match-string 4)))))))
10886 (org-format-outline-path
10889 (and file bfn (concat (file-name-nondirectory bfn) "/"))))))
10891 (defvar org-refile-history nil
10892 "History for refiling operations.")
10894 (defvar org-after-refile-insert-hook nil
10895 "Hook run after `org-refile' has inserted its stuff at the new location.
10896 Note that this is still *before* the stuff will be removed from
10897 the *old* location.")
10899 (defvar org-capture-last-stored-marker)
10900 (defun org-refile (&optional goto default-buffer rfloc)
10901 "Move the entry or entries at point to another heading.
10902 The list of target headings is compiled using the information in
10903 `org-refile-targets', which see.
10905 At the target location, the entry is filed as a subitem of the target
10906 heading. Depending on `org-reverse-note-order', the new subitem will
10907 either be the first or the last subitem.
10909 If there is an active region, all entries in that region will be moved.
10910 However, the region must fulfill the requirement that the first heading
10911 is the first one sets the top-level of the moved text - at most siblings
10912 below it are allowed.
10914 With prefix arg GOTO, the command will only visit the target location
10915 and not actually move anything.
10917 With a double prefix arg \\[universal-argument] \\[universal-argument], \
10918 go to the location where the last refiling operation has put the subtree.
10919 With a prefix argument of `2', refile to the running clock.
10921 RFLOC can be a refile location obtained in a different way.
10923 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
10925 If you are using target caching (see `org-refile-use-cache'),
10926 you have to clear the target cache in order to find new targets.
10927 This can be done with a 0 prefix (`C-0 C-c C-w') or a triple
10928 prefix argument (`C-u C-u C-u C-c C-w')."
10931 (if (member goto '(0 (64)))
10932 (org-refile-cache-clear)
10933 (let* ((cbuf (current-buffer))
10934 (regionp (org-region-active-p))
10935 (region-start (and regionp (region-beginning)))
10936 (region-end (and regionp (region-end)))
10937 (region-length (and regionp (- region-end region-start)))
10938 (filename (buffer-file-name (buffer-base-buffer cbuf)))
10939 pos it nbuf file re level reversed)
10940 (setq last-command nil)
10942 (goto-char region-start)
10943 (or (bolp) (goto-char (point-at-bol)))
10944 (setq region-start (point))
10945 (unless (or (org-kill-is-subtree-p
10946 (buffer-substring region-start region-end))
10947 (prog1 org-refile-active-region-within-subtree
10948 (org-toggle-heading)))
10949 (error "The region is not a (sequence of) subtree(s)")))
10950 (if (equal goto '(16))
10951 (org-refile-goto-last-stored)
10953 (and (equal goto 2)
10954 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
10956 (setq it (list (or org-clock-heading "running clock")
10958 (marker-buffer org-clock-hd-marker))
10960 (marker-position org-clock-hd-marker)))
10963 (let (heading-text)
10966 (org-back-to-heading t)
10968 (nth 4 (org-heading-components))))
10969 (org-refile-get-location
10970 (cond (goto "Goto")
10971 (regionp "Refile region to")
10972 (t (concat "Refile subtree \""
10973 heading-text "\" to")))
10975 (and (not (equal '(4) goto))
10976 org-refile-allow-creating-parent-nodes)
10978 (setq file (nth 1 it)
10981 (if (and (not goto)
10983 (equal (buffer-file-name) file)
10985 (and (>= pos region-start)
10986 (<= pos region-end))
10987 (and (>= pos (point))
10988 (< pos (save-excursion
10989 (org-end-of-subtree t t))))))
10990 (error "Cannot refile to position inside the tree or region"))
10992 (setq nbuf (or (find-buffer-visiting file)
10993 (find-file-noselect file)))
10996 (org-pop-to-buffer-same-window nbuf)
10998 (org-show-context 'org-goto))
11001 (org-kill-new (buffer-substring region-start region-end))
11002 (org-save-markers-in-region region-start region-end))
11003 (org-copy-subtree 1 nil t))
11004 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
11005 (find-file-noselect file)))
11006 (setq reversed (org-notes-order-reversed-p))
11013 (looking-at org-outline-regexp)
11014 (setq level (org-get-valid-level (funcall outline-level) 1))
11017 (or (outline-next-heading) (point-max))
11018 (or (save-excursion (org-get-next-sibling))
11019 (org-end-of-subtree t t)
11023 (goto-char (point-max))
11024 (goto-char (point-min))
11025 (or (outline-next-heading) (goto-char (point-max)))))
11026 (if (not (bolp)) (newline))
11027 (org-paste-subtree level)
11028 (when org-log-refile
11029 (org-add-log-setup 'refile nil nil 'findpos
11031 (unless (eq org-log-refile 'note)
11032 (save-excursion (org-add-log-note))))
11033 (and org-auto-align-tags
11034 (let ((org-loop-over-headlines-in-active-region nil))
11035 (org-set-tags nil t)))
11036 (bookmark-set "org-refile-last-stored")
11037 ;; If we are refiling for capture, make sure that the
11038 ;; last-capture pointers point here
11039 (when (org-bound-and-true-p org-refile-for-capture)
11040 (bookmark-set "org-capture-last-stored-marker")
11041 (move-marker org-capture-last-stored-marker (point)))
11042 (if (fboundp 'deactivate-mark) (deactivate-mark))
11043 (run-hooks 'org-after-refile-insert-hook))))
11045 (delete-region (point) (+ (point) region-length))
11047 (when (featurep 'org-inlinetask)
11048 (org-inlinetask-remove-END-maybe))
11049 (setq org-markers-to-move nil)
11050 (message "Refiled to \"%s\" in file %s" (car it) file)))))))
11052 (defun org-refile-goto-last-stored ()
11053 "Go to the location where the last refile was stored."
11055 (bookmark-jump "org-refile-last-stored")
11056 (message "This is the location of the last refile"))
11058 (defun org-refile-get-location (&optional prompt default-buffer new-nodes
11060 "Prompt the user for a refile location, using PROMPT.
11061 PROMPT should not be suffixed with a colon and a space, because
11062 this function appends the default value from
11063 `org-refile-history' automatically, if that is not empty.
11064 When NO-EXCLUDE is set, do not exclude headlines in the current subtree,
11065 this is used for the GOTO interface."
11066 (let ((org-refile-targets org-refile-targets)
11067 (org-refile-use-outline-path org-refile-use-outline-path)
11069 (when (and (derived-mode-p 'org-mode)
11070 (not org-refile-use-cache)
11074 (setq excluded-entries
11075 (append excluded-entries (list (org-get-heading t t)))))))
11076 (setq org-refile-target-table
11077 (org-refile-get-targets default-buffer excluded-entries)))
11078 (unless org-refile-target-table
11079 (error "No refile targets"))
11080 (let* ((prompt (concat prompt
11081 (and (car org-refile-history)
11082 (concat " (default " (car org-refile-history) ")"))
11084 (cbuf (current-buffer))
11085 (partial-completion-mode nil)
11086 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
11087 (cfunc (if (and org-refile-use-outline-path
11088 org-outline-path-complete-in-steps)
11089 'org-olpath-completing-read
11090 'org-icompleting-read))
11091 (extra (if org-refile-use-outline-path "/" ""))
11092 (filename (and cfn (expand-file-name cfn)))
11095 (if (and (not (member org-refile-use-outline-path
11096 '(file full-file-path)))
11097 (not (equal filename (nth 1 x))))
11098 (cons (concat (car x) extra " ("
11099 (file-name-nondirectory (nth 1 x)) ")")
11101 (cons (concat (car x) extra) (cdr x))))
11102 org-refile-target-table))
11103 (completion-ignore-case t)
11104 pa answ parent-target child parent old-hist)
11105 (setq old-hist org-refile-history)
11106 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
11107 nil 'org-refile-history (car org-refile-history)))
11108 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
11109 (org-refile-check-position pa)
11112 (when (or (not org-refile-history)
11113 (not (eq old-hist org-refile-history))
11114 (not (equal (car pa) (car org-refile-history))))
11115 (setq org-refile-history
11116 (cons (car pa) (if (assoc (car org-refile-history) tbl)
11118 (cdr org-refile-history))))
11119 (if (equal (car org-refile-history) (nth 1 org-refile-history))
11120 (pop org-refile-history)))
11122 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
11124 (setq parent (match-string 1 answ)
11125 child (match-string 2 answ))
11126 (setq parent-target (or (assoc parent tbl)
11127 (assoc (concat parent "/") tbl)))
11128 (when (and parent-target
11129 (or (eq new-nodes t)
11130 (and (eq new-nodes 'confirm)
11131 (y-or-n-p (format "Create new node \"%s\"? "
11133 (org-refile-new-child parent-target child)))
11134 (error "Invalid target location")))))
11136 (declare-function org-string-nw-p "org-macs.el" (s))
11137 (defun org-refile-check-position (refile-pointer)
11138 "Check if the refile pointer matches the readline to which it points."
11139 (let* ((file (nth 1 refile-pointer))
11140 (re (nth 2 refile-pointer))
11141 (pos (nth 3 refile-pointer))
11143 (when (org-string-nw-p re)
11144 (setq buffer (if (markerp pos)
11145 (marker-buffer pos)
11146 (or (find-buffer-visiting file)
11147 (find-file-noselect file))))
11148 (with-current-buffer buffer
11153 (beginning-of-line 1)
11154 (unless (org-looking-at-p re)
11155 (error "Invalid refile position, please clear the cache with `C-0 C-c C-w' before refiling"))))))))
11157 (defun org-refile-new-child (parent-target child)
11158 "Use refile target PARENT-TARGET to add new CHILD below it."
11159 (unless parent-target
11160 (error "Cannot find parent for new node"))
11161 (let ((file (nth 1 parent-target))
11162 (pos (nth 3 parent-target))
11164 (with-current-buffer (or (find-buffer-visiting file)
11165 (find-file-noselect file))
11171 (goto-char (point-max))
11172 (if (not (bolp)) (newline)))
11173 (when (looking-at org-outline-regexp)
11174 (setq level (funcall outline-level))
11175 (org-end-of-subtree t t))
11176 (org-back-over-empty-lines)
11177 (insert "\n" (make-string
11178 (if pos (org-get-valid-level level 1) 1) ?*)
11180 (beginning-of-line 0)
11181 (list (concat (car parent-target) "/" child) file "" (point)))))))
11183 (defun org-olpath-completing-read (prompt collection &rest args)
11184 "Read an outline path like a file name."
11185 (let ((thetable collection)
11186 (org-completion-use-ido nil) ; does not work with ido.
11187 (org-completion-use-iswitchb nil)) ; or iswitchb
11189 'org-icompleting-read prompt
11190 (lambda (string predicate &optional flag)
11191 (let (rtn r f (l (length string)))
11195 (try-completion string thetable))
11198 (setq rtn (all-completions string thetable predicate))
11201 (setq r (substring x l))
11202 (if (string-match " ([^)]*)$" x)
11203 (setq f (match-string 0 x))
11205 (if (string-match "/" r)
11206 (concat string (substring r 0 (match-end 0)) f)
11211 (assoc string thetable)))))
11214 ;;;; Dynamic blocks
11216 (defun org-find-dblock (name)
11217 "Find the first dynamic block with name NAME in the buffer.
11218 If not found, stay at current position and return nil."
11219 (let ((case-fold-search t) pos)
11221 (goto-char (point-min))
11222 (setq pos (and (re-search-forward
11223 (concat "^[ \t]*#\\+\\(?:BEGIN\\|begin\\):[ \t]+" name "\\>") nil t)
11224 (match-beginning 0))))
11225 (if pos (goto-char pos))
11228 (defconst org-dblock-start-re
11229 "^[ \t]*#\\+\\(?:BEGIN\\|begin\\):[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
11230 "Matches the start line of a dynamic block, with parameters.")
11232 (defconst org-dblock-end-re "^[ \t]*#\\+\\(?:END\\|end\\)\\([: \t\r\n]\\|$\\)"
11233 "Matches the end of a dynamic block.")
11235 (defun org-create-dblock (plist)
11236 "Create a dynamic block section, with parameters taken from PLIST.
11237 PLIST must contain a :name entry which is used as name of the block."
11238 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
11241 (let ((col (current-column))
11242 (name (plist-get plist :name)))
11243 (insert "#+BEGIN: " name)
11245 (if (eq (car plist) :name)
11246 (setq plist (cddr plist))
11247 (insert " " (prin1-to-string (pop plist)))))
11248 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
11249 (beginning-of-line -2)))
11251 (defun org-prepare-dblock ()
11252 "Prepare dynamic block for refresh.
11253 This empties the block, puts the cursor at the insert position and returns
11254 the property list including an extra property :name with the block name."
11255 (unless (looking-at org-dblock-start-re)
11256 (error "Not at a dynamic block"))
11257 (let* ((begdel (1+ (match-end 0)))
11258 (name (org-no-properties (match-string 1)))
11259 (params (append (list :name name)
11260 (read (concat "(" (match-string 3) ")")))))
11262 (beginning-of-line 1)
11263 (skip-chars-forward " \t")
11264 (setq params (plist-put params :indentation-column (current-column))))
11265 (unless (re-search-forward org-dblock-end-re nil t)
11266 (error "Dynamic block not terminated"))
11269 (list :content (buffer-substring
11270 begdel (match-beginning 0)))))
11271 (delete-region begdel (match-beginning 0))
11276 (defun org-map-dblocks (&optional command)
11277 "Apply COMMAND to all dynamic blocks in the current buffer.
11278 If COMMAND is not given, use `org-update-dblock'."
11279 (let ((cmd (or command 'org-update-dblock)))
11281 (goto-char (point-min))
11282 (while (re-search-forward org-dblock-start-re nil t)
11283 (goto-char (match-beginning 0))
11285 (condition-case nil
11287 (error (message "Error during update of dynamic block"))))
11288 (unless (re-search-forward org-dblock-end-re nil t)
11289 (error "Dynamic block not terminated"))))))
11291 (defun org-dblock-update (&optional arg)
11292 "User command for updating dynamic blocks.
11293 Update the dynamic block at point. With prefix ARG, update all dynamic
11294 blocks in the buffer."
11297 (org-update-all-dblocks)
11298 (or (looking-at org-dblock-start-re)
11299 (org-beginning-of-dblock))
11300 (org-update-dblock)))
11302 (defun org-update-dblock ()
11303 "Update the dynamic block at point.
11304 This means to empty the block, parse for parameters and then call
11305 the correct writing function."
11307 (save-window-excursion
11308 (let* ((pos (point))
11309 (line (org-current-line))
11310 (params (org-prepare-dblock))
11311 (name (plist-get params :name))
11312 (indent (plist-get params :indentation-column))
11313 (cmd (intern (concat "org-dblock-write:" name))))
11314 (message "Updating dynamic block `%s' at line %d..." name line)
11315 (funcall cmd params)
11316 (message "Updating dynamic block `%s' at line %d...done" name line)
11318 (when (and indent (> indent 0))
11319 (setq indent (make-string indent ?\ ))
11321 (org-beginning-of-dblock)
11323 (while (not (looking-at org-dblock-end-re))
11325 (beginning-of-line 2))
11326 (when (looking-at org-dblock-end-re)
11327 (and (looking-at "[ \t]+")
11328 (replace-match ""))
11329 (insert indent)))))))
11331 (defun org-beginning-of-dblock ()
11332 "Find the beginning of the dynamic block at point.
11333 Error if there is no such block at point."
11334 (let ((pos (point))
11337 (if (and (re-search-backward org-dblock-start-re nil t)
11338 (setq beg (match-beginning 0))
11339 (re-search-forward org-dblock-end-re nil t)
11340 (> (match-end 0) pos))
11343 (error "Not in a dynamic block"))))
11346 (defun org-update-all-dblocks ()
11347 "Update all dynamic blocks in the buffer.
11348 This function can be used in a hook."
11350 (when (derived-mode-p 'org-mode)
11351 (org-map-dblocks 'org-update-dblock)))
11356 (defconst org-additional-option-like-keywords
11357 '("BEGIN_HTML" "END_HTML" "HTML:" "ATTR_HTML:"
11358 "BEGIN_DocBook" "END_DocBook" "DocBook:" "ATTR_DocBook:"
11359 "BEGIN_LaTeX" "END_LaTeX" "LaTeX:" "LATEX_HEADER:"
11360 "LATEX_CLASS:" "LATEX_CLASS_OPTIONS:" "ATTR_LaTeX:"
11362 "ORGTBL" "TBLFM:" "TBLNAME:"
11363 "BEGIN_EXAMPLE" "END_EXAMPLE"
11364 "BEGIN_VERBATIM" "END_VERBATIM"
11365 "BEGIN_QUOTE" "END_QUOTE"
11366 "BEGIN_VERSE" "END_VERSE"
11367 "BEGIN_CENTER" "END_CENTER"
11368 "BEGIN_SRC" "END_SRC"
11369 "BEGIN_RESULT" "END_RESULT"
11370 "BEGIN_lstlisting" "END_lstlisting"
11372 "HEADER:" "HEADERS:"
11373 "COLUMNS:" "PROPERTY:"
11374 "CAPTION:" "LABEL:"
11380 (defconst org-options-keywords
11381 '("TITLE:" "AUTHOR:" "EMAIL:" "DATE:"
11382 "DESCRIPTION:" "KEYWORDS:" "LANGUAGE:" "OPTIONS:"
11383 "EXPORT_SELECT_TAGS:" "EXPORT_EXCLUDE_TAGS:"
11384 "LINK_UP:" "LINK_HOME:" "LINK:" "TODO:"
11385 "XSLT:" "MATHJAX:" "CATEGORY:" "SEQ_TODO:" "TYP_TODO:"
11386 "PRIORITIES:" "DRAWERS:" "STARTUP:" "TAGS:"
11387 "FILETAGS:" "ARCHIVE:" "INFOJS_OPT:"))
11389 (defconst org-additional-option-like-keywords-for-flyspell
11392 (mapconcat (lambda(k)
11393 (replace-regexp-in-string
11395 (concat k " " (downcase k) " " (upcase k))))
11396 (append org-options-keywords org-additional-option-like-keywords)
11400 (defcustom org-structure-template-alist
11402 ("s" "#+BEGIN_SRC ?\n\n#+END_SRC"
11403 "<src lang=\"?\">\n\n</src>")
11404 ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE"
11405 "<example>\n?\n</example>")
11406 ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE"
11407 "<quote>\n?\n</quote>")
11408 ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE"
11409 "<verse>\n?\n</verse>")
11410 ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER"
11411 "<center>\n?\n</center>")
11412 ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX"
11413 "<literal style=\"latex\">\n?\n</literal>")
11415 "<literal style=\"latex\">?</literal>")
11416 ("h" "#+BEGIN_HTML\n?\n#+END_HTML"
11417 "<literal style=\"html\">\n?\n</literal>")
11419 "<literal style=\"html\">?</literal>")
11420 ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII")
11424 ("I" "#+INCLUDE: %file ?"
11425 "<include file=%file markup=\"?\">")
11427 "Structure completion elements.
11428 This is a list of abbreviation keys and values. The value gets inserted
11429 if you type `<' followed by the key and then press the completion key,
11430 usually `M-TAB'. %file will be replaced by a file name after prompting
11431 for the file using completion. The cursor will be placed at the position
11432 of the `?` in the template.
11433 There are two templates for each key, the first uses the original Org syntax,
11434 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
11435 the default when the /org-mtags.el/ module has been loaded. See also the
11436 variable `org-mtags-prefer-muse-templates'."
11437 :group 'org-completion
11439 (string :tag "Key")
11440 (string :tag "Template")
11441 (string :tag "Muse Template")))
11443 (defun org-try-structure-completion ()
11444 "Try to complete a structure template before point.
11445 This looks for strings like \"<e\" on an otherwise empty line and
11447 (let ((l (buffer-substring (point-at-bol) (point)))
11449 (when (and (looking-at "[ \t]*$")
11450 (string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l)
11451 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
11452 (org-complete-expand-structure-template (+ -1 (point-at-bol)
11453 (match-beginning 1)) a)
11456 (defun org-complete-expand-structure-template (start cell)
11457 "Expand a structure template."
11458 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
11459 (rpl (nth (if musep 2 1) cell))
11461 (delete-region start (point))
11462 (when (string-match "\\`#\\+" rpl)
11465 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
11466 (setq ind (buffer-substring (point-at-bol) (point))))
11468 (setq start (point))
11469 (if (string-match "%file" rpl)
11470 (setq rpl (replace-match
11474 (abbreviate-file-name (read-file-name "Include file: ")))
11477 (setq rpl (mapconcat 'identity (split-string rpl "\n")
11478 (concat "\n" ind)))
11480 (if (re-search-backward "\\?" start t) (delete-char 1))))
11482 ;;;; TODO, DEADLINE, Comments
11484 (defun org-toggle-comment ()
11485 "Change the COMMENT state of an entry."
11488 (org-back-to-heading)
11489 (let (case-fold-search)
11491 ((looking-at (format org-heading-keyword-regexp-format
11492 org-comment-string))
11493 (goto-char (match-end 1))
11494 (looking-at (concat " +" org-comment-string))
11495 (replace-match "" t t)
11496 (when (eolp) (insert " ")))
11497 ((looking-at org-outline-regexp)
11498 (goto-char (match-end 0))
11499 (insert org-comment-string " "))))))
11501 (defvar org-last-todo-state-is-todo nil
11502 "This is non-nil when the last TODO state change led to a TODO state.
11503 If the last change removed the TODO tag or switched to DONE, then
11506 (defvar org-setting-tags nil) ; dynamically skipped
11508 (defvar org-todo-setup-filter-hook nil
11509 "Hook for functions that pre-filter todo specs.
11510 Each function takes a todo spec and returns either nil or the spec
11511 transformed into canonical form." )
11513 (defvar org-todo-get-default-hook nil
11514 "Hook for functions that get a default item for todo.
11515 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
11516 nil or a string to be used for the todo mark." )
11518 (defvar org-agenda-headline-snapshot-before-repeat)
11520 (defun org-current-effective-time ()
11521 "Return current time adjusted for `org-extend-today-until' variable."
11522 (let* ((ct (org-current-time))
11523 (dct (decode-time ct))
11525 (if (and org-use-effective-time
11526 (< (nth 2 dct) org-extend-today-until))
11527 (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
11531 (defun org-todo-yesterday (&optional arg)
11532 "Like `org-todo' but the time of change will be 23:59 of yesterday."
11534 (if (eq major-mode 'org-agenda-mode)
11535 (apply 'org-agenda-todo-yesterday arg)
11536 (let* ((hour (third (decode-time
11537 (org-current-time))))
11538 (org-extend-today-until (1+ hour)))
11541 (defun org-todo (&optional arg)
11542 "Change the TODO state of an item.
11543 The state of an item is given by a keyword at the start of the heading,
11545 *** TODO Write paper
11548 The different keywords are specified in the variable `org-todo-keywords'.
11549 By default the available states are \"TODO\" and \"DONE\".
11550 So for this example: when the item starts with TODO, it is changed to DONE.
11551 When it starts with DONE, the DONE is removed. And when neither TODO nor
11552 DONE are present, add TODO at the beginning of the heading.
11554 With \\[universal-argument] prefix arg, use completion to determine the new \
11556 With numeric prefix arg, switch to that state.
11557 With a double \\[universal-argument] prefix, switch to the next set of TODO \
11558 keywords (nextset).
11559 With a triple \\[universal-argument] prefix, circumvent any state blocking.
11560 With a numeric prefix arg of 0, inhibit note taking for the change.
11562 For calling through lisp, arg is also interpreted in the following way:
11563 'none -> empty state
11564 \"\"(empty string) -> switch to empty state
11565 'done -> switch to DONE
11566 'nextset -> switch to the next set of keywords
11567 'previousset -> switch to the previous set of keywords
11568 \"WAITING\" -> switch to the specified keyword, but only if it
11569 really is a member of `org-todo-keywords'."
11571 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
11572 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
11573 'region-start-level 'region))
11574 org-loop-over-headlines-in-active-region)
11577 org-loop-over-headlines-in-active-region
11578 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
11579 (if (equal arg '(16)) (setq arg 'nextset))
11580 (let ((org-blocker-hook org-blocker-hook)
11581 (case-fold-search nil))
11582 (when (equal arg '(64))
11583 (setq arg nil org-blocker-hook nil))
11584 (when (and org-blocker-hook
11585 (or org-inhibit-blocking
11586 (org-entry-get nil "NOBLOCKING")))
11587 (setq org-blocker-hook nil))
11590 (org-back-to-heading t)
11591 (if (looking-at org-outline-regexp) (goto-char (1- (match-end 0))))
11592 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|[ \t]*$\\)"))
11593 (looking-at "\\(?: *\\|[ \t]*$\\)"))
11594 (let* ((match-data (match-data))
11595 (startpos (point-at-bol))
11596 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
11597 (org-log-done org-log-done)
11598 (org-log-repeat org-log-repeat)
11599 (org-todo-log-states org-todo-log-states)
11600 (org-inhibit-logging
11602 (progn (setq arg nil) 'note) org-inhibit-logging))
11603 (this (match-string 1))
11604 (hl-pos (match-beginning 0))
11605 (head (org-get-todo-sequence-head this))
11606 (ass (assoc head org-todo-kwd-alist))
11607 (interpret (nth 1 ass))
11608 (done-word (nth 3 ass))
11609 (final-done-word (nth 4 ass))
11610 (org-last-state (or this ""))
11611 (completion-ignore-case t)
11612 (member (member this org-todo-keywords-1))
11613 (tail (cdr member))
11615 ((and org-todo-key-trigger
11616 (or (and (equal arg '(4))
11617 (eq org-use-fast-todo-selection 'prefix))
11618 (and (not arg) org-use-fast-todo-selection
11619 (not (eq org-use-fast-todo-selection
11621 ;; Use fast selection
11622 (org-fast-todo-selection))
11623 ((and (equal arg '(4))
11624 (or (not org-use-fast-todo-selection)
11625 (not org-todo-key-trigger)))
11626 ;; Read a state with completion
11627 (org-icompleting-read
11628 "State: " (mapcar (lambda(x) (list x))
11629 org-todo-keywords-1)
11633 (if tail (car tail) nil)
11634 (car org-todo-keywords-1)))
11636 (if (equal member org-todo-keywords-1)
11639 (nth (- (length org-todo-keywords-1)
11641 org-todo-keywords-1)
11642 (org-last org-todo-keywords-1))))
11643 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
11644 (setq arg nil))) ; hack to fall back to cycling
11646 ;; user or caller requests a specific state
11648 ((equal arg "") nil)
11649 ((eq arg 'none) nil)
11650 ((eq arg 'done) (or done-word (car org-done-keywords)))
11652 (or (car (cdr (member head org-todo-heads)))
11653 (car org-todo-heads)))
11654 ((eq arg 'previousset)
11655 (let ((org-todo-heads (reverse org-todo-heads)))
11656 (or (car (cdr (member head org-todo-heads)))
11657 (car org-todo-heads))))
11658 ((car (member arg org-todo-keywords-1)))
11660 (error "State `%s' not valid in this file" arg))
11661 ((nth (1- (prefix-numeric-value arg))
11662 org-todo-keywords-1))))
11663 ((null member) (or head (car org-todo-keywords-1)))
11664 ((equal this final-done-word) nil) ;; -> make empty
11665 ((null tail) nil) ;; -> first entry
11666 ((memq interpret '(type priority))
11667 (if (eq this-command last-command)
11669 (if (> (length tail) 0)
11670 (or done-word (car org-done-keywords))
11675 (run-hook-with-args-until-success
11676 'org-todo-get-default-hook org-state org-last-state)
11678 (next (if org-state (concat " " org-state " ") " "))
11679 (change-plist (list :type 'todo-state-change :from this :to org-state
11680 :position startpos))
11682 (when org-blocker-hook
11683 (setq org-last-todo-state-is-todo
11684 (not (member this org-done-keywords)))
11685 (unless (save-excursion
11687 (org-with-wide-buffer
11688 (run-hook-with-args-until-failure
11689 'org-blocker-hook change-plist))))
11690 (if (org-called-interactively-p 'interactive)
11691 (error "TODO state change from %s to %s blocked" this org-state)
11693 (message "TODO state change from %s to %s blocked" this org-state)
11694 (throw 'exit nil))))
11695 (store-match-data match-data)
11696 (replace-match next t t)
11697 (unless (pos-visible-in-window-p hl-pos)
11698 (message "TODO state changed to %s" (org-trim next)))
11700 (setq head (org-get-todo-sequence-head org-state)
11701 ass (assoc head org-todo-kwd-alist)
11702 interpret (nth 1 ass)
11703 done-word (nth 3 ass)
11704 final-done-word (nth 4 ass)))
11705 (when (memq arg '(nextset previousset))
11706 (message "Keyword-Set %d/%d: %s"
11707 (- (length org-todo-sets) -1
11708 (length (memq (assoc org-state org-todo-sets) org-todo-sets)))
11709 (length org-todo-sets)
11710 (mapconcat 'identity (assoc org-state org-todo-sets) " ")))
11711 (setq org-last-todo-state-is-todo
11712 (not (member org-state org-done-keywords)))
11713 (setq now-done-p (and (member org-state org-done-keywords)
11714 (not (member this org-done-keywords))))
11715 (and logging (org-local-logging logging))
11716 (when (and (or org-todo-log-states org-log-done)
11717 (not (eq org-inhibit-logging t))
11718 (not (memq arg '(nextset previousset))))
11719 ;; we need to look at recording a time and note
11720 (setq dolog (or (nth 1 (assoc org-state org-todo-log-states))
11721 (nth 2 (assoc this org-todo-log-states))))
11722 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
11723 (setq dolog 'time))
11724 (when (and org-state
11725 (member org-state org-not-done-keywords)
11726 (not (member this org-not-done-keywords)))
11727 ;; This is now a todo state and was not one before
11728 ;; If there was a CLOSED time stamp, get rid of it.
11729 (org-add-planning-info nil nil 'closed))
11730 (when (and now-done-p org-log-done)
11731 ;; It is now done, and it was not done before
11732 (org-add-planning-info 'closed (org-current-effective-time))
11733 (if (and (not dolog) (eq 'note org-log-done))
11734 (org-add-log-setup 'done org-state this 'findpos 'note)))
11735 (when (and org-state dolog)
11736 ;; This is a non-nil state, and we need to log it
11737 (org-add-log-setup 'state org-state this 'findpos dolog)))
11738 ;; Fixup tag positioning
11739 (org-todo-trigger-tag-changes org-state)
11740 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
11741 (when org-provide-todo-statistics
11742 (org-update-parent-todo-statistics))
11743 (run-hooks 'org-after-todo-state-change-hook)
11744 (if (and arg (not (member org-state org-done-keywords)))
11745 (setq head (org-get-todo-sequence-head org-state)))
11746 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
11747 ;; Do we need to trigger a repeat?
11749 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
11750 ;; This is for the agenda, take a snapshot of the headline.
11752 (setq org-agenda-headline-snapshot-before-repeat
11753 (org-get-heading))))
11754 (org-auto-repeat-maybe org-state))
11755 ;; Fixup cursor location if close to the keyword
11756 (if (and (outline-on-heading-p)
11758 (save-excursion (beginning-of-line 1)
11759 (looking-at org-todo-line-regexp))
11760 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
11762 (goto-char (or (match-end 2) (match-end 1)))
11763 (and (looking-at " ") (just-one-space))))
11764 (when org-trigger-hook
11766 (run-hook-with-args 'org-trigger-hook change-plist)))))))))
11768 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
11769 "Block turning an entry into a TODO, using the hierarchy.
11770 This checks whether the current task should be blocked from state
11771 changes. Such blocking occurs when:
11773 1. The task has children which are not all in a completed state.
11775 2. A task has a parent with the property :ORDERED:, and there
11776 are siblings prior to the current task with incomplete
11779 3. The parent of the task is blocked because it has siblings that should
11780 be done first, or is child of a block grandparent TODO entry."
11782 (if (not org-enforce-todo-dependencies)
11783 t ; if locally turned off don't block
11785 ;; If this is not a todo state change, or if this entry is already DONE,
11787 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
11788 (member (plist-get change-plist :from)
11789 (cons 'done org-done-keywords))
11790 (member (plist-get change-plist :to)
11791 (cons 'todo org-not-done-keywords))
11792 (not (plist-get change-plist :to)))
11793 (throw 'dont-block t))
11794 ;; If this task has children, and any are undone, it's blocked
11796 (org-back-to-heading t)
11797 (let ((this-level (funcall outline-level)))
11798 (outline-next-heading)
11799 (let ((child-level (funcall outline-level)))
11800 (while (and (not (eobp))
11801 (> child-level this-level))
11802 ;; this todo has children, check whether they are all
11804 (if (and (not (org-entry-is-done-p))
11805 (org-entry-is-todo-p))
11806 (throw 'dont-block nil))
11807 (outline-next-heading)
11808 (setq child-level (funcall outline-level))))))
11809 ;; Otherwise, if the task's parent has the :ORDERED: property, and
11810 ;; any previous siblings are undone, it's blocked
11812 (org-back-to-heading t)
11813 (let* ((pos (point))
11814 (parent-pos (and (org-up-heading-safe) (point))))
11815 (if (not parent-pos) (throw 'dont-block t)) ; no parent
11816 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
11818 (re-search-forward org-not-done-heading-regexp pos t))
11819 (throw 'dont-block nil)) ; block, there is an older sibling not done.
11820 ;; Search further up the hierarchy, to see if an ancestor is blocked
11822 (goto-char parent-pos)
11823 (if (not (looking-at org-not-done-heading-regexp))
11824 (throw 'dont-block t)) ; do not block, parent is not a TODO
11826 (setq parent-pos (and (org-up-heading-safe) (point)))
11827 (if (not parent-pos) (throw 'dont-block t)) ; no parent
11828 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
11830 (re-search-forward org-not-done-heading-regexp pos t))
11831 (throw 'dont-block nil)))))))) ; block, older sibling not done.
11833 (defcustom org-track-ordered-property-with-tag nil
11834 "Should the ORDERED property also be shown as a tag?
11835 The ORDERED property decides if an entry should require subtasks to be
11836 completed in sequence. Since a property is not very visible, setting
11837 this option means that toggling the ORDERED property with the command
11838 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
11839 not relevant for the behavior, but it makes things more visible.
11841 Note that toggling the tag with tags commands will not change the property
11842 and therefore not influence behavior!
11844 This can be t, meaning the tag ORDERED should be used, It can also be a
11845 string to select a different tag for this task."
11848 (const :tag "No tracking" nil)
11849 (const :tag "Track with ORDERED tag" t)
11850 (string :tag "Use other tag")))
11852 (defun org-toggle-ordered-property ()
11853 "Toggle the ORDERED property of the current entry.
11854 For better visibility, you can track the value of this property with a tag.
11855 See variable `org-track-ordered-property-with-tag'."
11857 (let* ((t1 org-track-ordered-property-with-tag)
11858 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
11860 (org-back-to-heading)
11861 (if (org-entry-get nil "ORDERED")
11863 (org-delete-property "ORDERED")
11864 (and tag (org-toggle-tag tag 'off))
11865 (message "Subtasks can be completed in arbitrary order"))
11866 (org-entry-put nil "ORDERED" "t")
11867 (and tag (org-toggle-tag tag 'on))
11868 (message "Subtasks must be completed in sequence")))))
11870 (defvar org-blocked-by-checkboxes) ; dynamically scoped
11871 (defun org-block-todo-from-checkboxes (change-plist)
11872 "Block turning an entry into a TODO, using checkboxes.
11873 This checks whether the current task should be blocked from state
11874 changes because there are unchecked boxes in this entry."
11875 (if (not org-enforce-todo-checkbox-dependencies)
11876 t ; if locally turned off don't block
11878 ;; If this is not a todo state change, or if this entry is already DONE,
11880 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
11881 (member (plist-get change-plist :from)
11882 (cons 'done org-done-keywords))
11883 (member (plist-get change-plist :to)
11884 (cons 'todo org-not-done-keywords))
11885 (not (plist-get change-plist :to)))
11886 (throw 'dont-block t))
11887 ;; If this task has checkboxes that are not checked, it's blocked
11889 (org-back-to-heading t)
11890 (let ((beg (point)) end)
11891 (outline-next-heading)
11894 (if (org-list-search-forward
11895 (concat (org-item-beginning-re)
11896 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
11900 (if (boundp 'org-blocked-by-checkboxes)
11901 (setq org-blocked-by-checkboxes t))
11902 (throw 'dont-block nil)))))
11903 t))) ; do not block
11905 (defun org-entry-blocked-p ()
11906 "Is the current entry blocked?"
11907 (if (org-entry-get nil "NOBLOCKING")
11908 nil ;; Never block this entry
11910 (run-hook-with-args-until-failure
11912 (list :type 'todo-state-change
11917 (defun org-update-statistics-cookies (all)
11918 "Update the statistics cookie, either from TODO or from checkboxes.
11919 This should be called with the cursor in a line with a statistics cookie."
11923 (org-update-checkbox-count 'all)
11924 (org-map-entries 'org-update-parent-todo-statistics))
11925 (if (not (org-at-heading-p))
11926 (org-update-checkbox-count)
11927 (let ((pos (move-marker (make-marker) (point)))
11929 (ignore-errors (org-back-to-heading t))
11930 (if (not (org-at-heading-p))
11931 (org-update-checkbox-count)
11932 (setq l1 (org-outline-level))
11933 (setq end (save-excursion
11934 (outline-next-heading)
11935 (if (org-at-heading-p) (setq l2 (org-outline-level)))
11937 (if (and (save-excursion
11939 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
11940 (not (save-excursion (re-search-forward
11941 ":COOKIE_DATA:.*\\<todo\\>" end t))))
11942 (org-update-checkbox-count)
11943 (if (and l2 (> l2 l1))
11946 (org-update-parent-todo-statistics))
11948 (beginning-of-line 1)
11949 (while (re-search-forward
11950 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
11952 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
11954 (move-marker pos nil)))))
11956 (defvar org-entry-property-inherited-from) ;; defined below
11957 (defun org-update-parent-todo-statistics ()
11958 "Update any statistics cookie in the parent of the current headline.
11959 When `org-hierarchical-todo-statistics' is nil, statistics will cover
11960 the entire subtree and this will travel up the hierarchy and update
11961 statistics everywhere."
11962 (let* ((prop (save-excursion (org-up-heading-safe)
11963 (org-entry-get nil "COOKIE_DATA" 'inherit)))
11964 (recursive (or (not org-hierarchical-todo-statistics)
11965 (and prop (string-match "\\<recursive\\>" prop))))
11966 (lim (or (and prop (marker-position org-entry-property-inherited-from))
11969 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
11970 level ltoggle l1 new ndel
11971 (cnt-all 0) (cnt-done 0) is-percent kwd
11972 checkbox-beg ov ovs ove cookie-present)
11975 (beginning-of-line 1)
11976 (setq ltoggle (funcall outline-level))
11977 ;; Three situations are to consider:
11979 ;; 1. if `org-hierarchical-todo-statistics' is nil, repeat up
11980 ;; to the top-level ancestor on the headline;
11982 ;; 2. If parent has "recursive" property, repeat up to the
11983 ;; headline setting that property, taking inheritance into
11986 ;; 3. Else, move up to direct parent and proceed only once.
11987 (while (and (setq level (org-up-heading-safe))
11988 (or recursive first)
11990 (setq first nil cookie-present nil)
11994 (downcase (or (org-entry-get nil "COOKIE_DATA")
11997 (while (re-search-forward box-re (point-at-eol) t)
11998 (setq cnt-all 0 cnt-done 0 cookie-present t)
11999 (setq is-percent (match-end 2) checkbox-beg (match-beginning 0))
12001 (unless (outline-next-heading) (throw 'exit nil))
12002 (while (and (looking-at org-complex-heading-regexp)
12003 (> (setq l1 (length (match-string 1))) level))
12004 (setq kwd (and (or recursive (= l1 ltoggle))
12006 (if (or (eq org-provide-todo-statistics 'all-headlines)
12007 (and (listp org-provide-todo-statistics)
12008 (or (member kwd org-provide-todo-statistics)
12009 (member kwd org-done-keywords))))
12010 (setq cnt-all (1+ cnt-all))
12011 (if (eq org-provide-todo-statistics t)
12012 (and kwd (setq cnt-all (1+ cnt-all)))))
12013 (and (member kwd org-done-keywords)
12014 (setq cnt-done (1+ cnt-done)))
12015 (outline-next-heading)))
12018 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
12019 (format "[%d/%d]" cnt-done cnt-all))
12020 ndel (- (match-end 0) checkbox-beg))
12021 ;; handle overlays when updating cookie from column view
12022 (when (setq ov (car (overlays-at checkbox-beg)))
12023 (setq ovs (overlay-start ov) ove (overlay-end ov))
12024 (delete-overlay ov))
12025 (goto-char checkbox-beg)
12027 (delete-region (point) (+ (point) ndel))
12028 (when org-auto-align-tags (org-fix-tags-on-the-fly))
12029 (when ov (move-overlay ov ovs ove)))
12030 (when cookie-present
12031 (run-hook-with-args 'org-after-todo-statistics-hook
12032 cnt-done (- cnt-all cnt-done))))))
12033 (run-hooks 'org-todo-statistics-hook)))
12035 (defvar org-after-todo-statistics-hook nil
12036 "Hook that is called after a TODO statistics cookie has been updated.
12037 Each function is called with two arguments: the number of not-done entries
12038 and the number of done entries.
12040 For example, the following function, when added to this hook, will switch
12041 an entry to DONE when all children are done, and back to TODO when new
12042 entries are set to a TODO status. Note that this hook is only called
12043 when there is a statistics cookie in the headline!
12045 (defun org-summary-todo (n-done n-not-done)
12046 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
12047 (let (org-log-done org-log-states) ; turn off logging
12048 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
12051 (defvar org-todo-statistics-hook nil
12052 "Hook that is run whenever Org thinks TODO statistics should be updated.
12053 This hook runs even if there is no statistics cookie present, in which case
12054 `org-after-todo-statistics-hook' would not run.")
12056 (defun org-todo-trigger-tag-changes (state)
12057 "Apply the changes defined in `org-todo-state-tags-triggers'."
12058 (let ((l org-todo-state-tags-triggers)
12060 (when (or (not state) (equal state ""))
12061 (setq changes (append changes (cdr (assoc "" l)))))
12062 (when (and (stringp state) (> (length state) 0))
12063 (setq changes (append changes (cdr (assoc state l)))))
12064 (when (member state org-not-done-keywords)
12065 (setq changes (append changes (cdr (assoc 'todo l)))))
12066 (when (member state org-done-keywords)
12067 (setq changes (append changes (cdr (assoc 'done l)))))
12068 (dolist (c changes)
12069 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
12071 (defun org-local-logging (value)
12072 "Get logging settings from a property VALUE."
12074 ;; directly set the variables, they are already local.
12075 (setq org-log-done nil
12077 org-todo-log-states nil)
12078 (setq words (org-split-string value))
12079 (while (setq w (pop words))
12081 ((setq a (assoc w org-startup-options))
12082 (and (member (nth 1 a) '(org-log-done org-log-repeat))
12083 (set (nth 1 a) (nth 2 a))))
12084 ((setq a (org-extract-log-state-settings w))
12085 (and (member (car a) org-todo-keywords-1)
12086 (push a org-todo-log-states)))))))
12088 (defun org-get-todo-sequence-head (kwd)
12089 "Return the head of the TODO sequence to which KWD belongs.
12090 If KWD is not set, check if there is a text property remembering the
12095 (or (get-text-property (point-at-bol) 'org-todo-head)
12097 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
12098 nil (point-at-eol)))
12099 (get-text-property p 'org-todo-head))))
12100 ((not (member kwd org-todo-keywords-1))
12101 (car org-todo-keywords-1))
12102 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
12104 (defun org-fast-todo-selection ()
12105 "Fast TODO keyword selection with single keys.
12106 Returns the new TODO keyword, or nil if no state change should occur."
12107 (let* ((fulltable org-todo-key-alist)
12108 (done-keywords org-done-keywords) ;; needed for the faces.
12109 (maxlen (apply 'max (mapcar
12111 (if (stringp (car x)) (string-width (car x)) 0))
12114 (fwidth (+ maxlen 3 1 3))
12115 (ncol (/ (- (window-width) 4) fwidth))
12119 (save-window-excursion
12121 (set-buffer (get-buffer-create " *Org todo*"))
12122 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
12124 (org-set-local 'org-done-keywords done-keywords)
12125 (setq tbl fulltable cnt 0)
12126 (while (setq e (pop tbl))
12128 ((equal e '(:startgroup))
12129 (push '() groups) (setq ingroup t)
12130 (when (not (= cnt 0))
12134 ((equal e '(:endgroup))
12135 (setq ingroup nil cnt 0)
12137 ((equal e '(:newline))
12138 (when (not (= cnt 0))
12142 (while (equal (car tbl) '(:newline))
12144 (setq tbl (cdr tbl)))))
12146 (setq tg (car e) c (cdr e))
12147 (if ingroup (push tg (car groups)))
12148 (setq tg (org-add-props tg nil 'face
12149 (org-get-todo-face tg)))
12150 (if (and (= cnt 0) (not ingroup)) (insert " "))
12151 (insert "[" c "] " tg (make-string
12152 (- fwidth 4 (length tg)) ?\ ))
12153 (when (= (setq cnt (1+ cnt)) ncol)
12155 (if ingroup (insert " "))
12158 (goto-char (point-min))
12159 (if (not expert) (org-fit-window-to-buffer))
12160 (message "[a-z..]:Set [SPC]:clear")
12161 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12164 (and (= c ?q) (not (rassoc c fulltable))))
12165 (setq quit-flag t))
12167 ((setq e (rassoc c fulltable) tg (car e))
12169 (t (setq quit-flag t)))))))
12171 (defun org-entry-is-todo-p ()
12172 (member (org-get-todo-state) org-not-done-keywords))
12174 (defun org-entry-is-done-p ()
12175 (member (org-get-todo-state) org-done-keywords))
12177 (defun org-get-todo-state ()
12179 (org-back-to-heading t)
12180 (and (looking-at org-todo-line-regexp)
12182 (match-string 2))))
12184 (defun org-at-date-range-p (&optional inactive-ok)
12185 "Is the cursor inside a date range?"
12189 (let ((pos (point)))
12190 (skip-chars-backward "^[<\r\n")
12191 (skip-chars-backward "<[")
12192 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
12193 (>= (match-end 0) pos)
12195 (skip-chars-backward "^<[\r\n")
12196 (skip-chars-backward "<[")
12197 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
12198 (>= (match-end 0) pos)
12202 (defun org-get-repeat (&optional tagline)
12203 "Check if there is a deadline/schedule with repeater in this entry."
12206 (org-back-to-heading t)
12207 (and (re-search-forward (if tagline
12208 (concat tagline "\\s-*" org-repeat-re)
12210 (org-entry-end-position) t)
12211 (match-string-no-properties 1)))))
12213 (defvar org-last-changed-timestamp)
12214 (defvar org-last-inserted-timestamp)
12215 (defvar org-log-post-message)
12216 (defvar org-log-note-purpose)
12217 (defvar org-log-note-how)
12218 (defvar org-log-note-extra)
12219 (defun org-auto-repeat-maybe (done-word)
12220 "Check if the current headline contains a repeated deadline/schedule.
12221 If yes, set TODO state back to what it was and change the base date
12222 of repeating deadline/scheduled time stamps to new date.
12223 This function is run automatically after each state change to a DONE state."
12224 ;; last-state is dynamically scoped into this function
12225 (let* ((repeat (org-get-repeat))
12226 (aa (assoc org-last-state org-todo-kwd-alist))
12227 (interpret (nth 1 aa))
12229 (whata '(("h" . hour) ("d" . day) ("m" . month) ("y" . year)))
12230 (msg "Entry repeats: ")
12232 (org-todo-log-states nil)
12233 re type n what ts time to-state)
12235 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
12236 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
12237 org-todo-repeat-to-state))
12238 (unless (and to-state (member to-state org-todo-keywords-1))
12239 (setq to-state (if (eq interpret 'type) org-last-state head)))
12240 (org-todo to-state)
12241 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
12242 (org-entry-put nil "LAST_REPEAT" (format-time-string
12243 (org-time-stamp-format t t))))
12244 (when org-log-repeat
12245 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
12246 (memq 'org-add-log-note post-command-hook))
12247 ;; OK, we are already setup for some record
12248 (if (eq org-log-repeat 'note)
12249 ;; make sure we take a note, not only a time stamp
12250 (setq org-log-note-how 'note))
12251 ;; Set up for taking a record
12252 (org-add-log-setup 'state (or done-word (car org-done-keywords))
12254 'findpos org-log-repeat)))
12255 (org-back-to-heading t)
12256 (org-add-planning-info nil nil 'closed)
12257 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
12258 org-deadline-time-regexp "\\)\\|\\("
12259 org-ts-regexp "\\)"))
12260 (while (re-search-forward
12261 re (save-excursion (outline-next-heading) (point)) t)
12262 (setq type (if (match-end 1) org-scheduled-string
12263 (if (match-end 3) org-deadline-string "Plain:"))
12264 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
12265 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" ts)
12266 (setq n (string-to-number (match-string 2 ts))
12267 what (match-string 3 ts))
12268 (if (equal what "w") (setq n (* n 7) what "d"))
12269 (if (and (equal what "h") (not (string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts)))
12270 (error "Cannot repeat in Repeat in %d hour(s) because no hour has been set" n))
12271 ;; Preparation, see if we need to modify the start date for the change
12272 (when (match-end 1)
12273 (setq time (save-match-data (org-time-string-to-time ts)))
12275 ((equal (match-string 1 ts) ".")
12276 ;; Shift starting date to today
12277 (org-timestamp-change
12278 (- (org-today) (time-to-days time))
12280 ((equal (match-string 1 ts) "+")
12281 (let ((nshiftmax 10) (nshift 0))
12282 (while (or (= nshift 0)
12283 (<= (time-to-days time)
12284 (time-to-days (current-time))))
12285 (when (= (incf nshift) nshiftmax)
12286 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
12288 (org-timestamp-change n (cdr (assoc what whata)))
12289 (org-at-timestamp-p t)
12290 (setq ts (match-string 1))
12291 (setq time (save-match-data (org-time-string-to-time ts)))))
12292 (org-timestamp-change (- n) (cdr (assoc what whata)))
12293 ;; rematch, so that we have everything in place for the real shift
12294 (org-at-timestamp-p t)
12295 (setq ts (match-string 1))
12296 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" ts))))
12297 (org-timestamp-change n (cdr (assoc what whata)))
12298 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
12299 (setq org-log-post-message msg)
12300 (message "%s" msg))))
12302 (defun org-show-todo-tree (arg)
12303 "Make a compact tree which shows all headlines marked with TODO.
12304 The tree will show the lines where the regexp matches, and all higher
12305 headlines above the match.
12306 With a \\[universal-argument] prefix, prompt for a regexp to match.
12307 With a numeric prefix N, construct a sparse tree for the Nth element
12308 of `org-todo-keywords-1'."
12310 (let ((case-fold-search nil)
12312 (cond ((null arg) org-not-done-regexp)
12314 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
12315 (mapcar 'list org-todo-keywords-1))))
12317 (mapconcat 'identity (org-split-string kwd "|") "\\|")
12319 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
12320 (regexp-quote (nth (1- (prefix-numeric-value arg))
12321 org-todo-keywords-1)))
12322 (t (error "Invalid prefix argument: %s" arg)))))
12323 (message "%d TODO entries found"
12324 (org-occur (concat "^" org-outline-regexp " *" kwd-re )))))
12326 (defun org-deadline (&optional remove time)
12327 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
12328 With argument REMOVE, remove any deadline from the item.
12329 With argument TIME, set the deadline at the corresponding date. TIME
12330 can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12332 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12333 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12334 'region-start-level 'region))
12335 org-loop-over-headlines-in-active-region)
12337 `(org-deadline ',remove ,time)
12338 org-loop-over-headlines-in-active-region
12339 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12340 (let* ((old-date (org-entry-get nil "DEADLINE"))
12341 (repeater (and old-date
12343 "\\([.+-]+[0-9]+[hdwmy]\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
12345 (match-string 1 old-date))))
12348 (when (and old-date org-log-redeadline)
12349 (org-add-log-setup 'deldeadline nil old-date 'findpos
12350 org-log-redeadline))
12351 (org-remove-timestamp-with-keyword org-deadline-string)
12352 (message "Item no longer has a deadline."))
12353 (org-add-planning-info 'deadline time 'closed)
12354 (when (and old-date org-log-redeadline
12355 (not (equal old-date
12356 (substring org-last-inserted-timestamp 1 -1))))
12357 (org-add-log-setup 'redeadline nil old-date 'findpos
12358 org-log-redeadline))
12361 (org-back-to-heading t)
12362 (when (re-search-forward (concat org-deadline-string " "
12363 org-last-inserted-timestamp)
12365 (outline-next-heading) (point)) t)
12366 (goto-char (1- (match-end 0)))
12367 (insert " " repeater)
12368 (setq org-last-inserted-timestamp
12369 (concat (substring org-last-inserted-timestamp 0 -1)
12371 (substring org-last-inserted-timestamp -1))))))
12372 (message "Deadline on %s" org-last-inserted-timestamp)))))
12374 (defun org-schedule (&optional remove time)
12375 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
12376 With argument REMOVE, remove any scheduling date from the item.
12377 With argument TIME, scheduled at the corresponding date. TIME can
12378 either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12380 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12381 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12382 'region-start-level 'region))
12383 org-loop-over-headlines-in-active-region)
12385 `(org-schedule ',remove ,time)
12386 org-loop-over-headlines-in-active-region
12387 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12388 (let* ((old-date (org-entry-get nil "SCHEDULED"))
12389 (repeater (and old-date
12391 "\\([.+-]+[0-9]+[hdwmy]\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
12393 (match-string 1 old-date))))
12396 (when (and old-date org-log-reschedule)
12397 (org-add-log-setup 'delschedule nil old-date 'findpos
12398 org-log-reschedule))
12399 (org-remove-timestamp-with-keyword org-scheduled-string)
12400 (message "Item is no longer scheduled."))
12401 (org-add-planning-info 'scheduled time 'closed)
12402 (when (and old-date org-log-reschedule
12403 (not (equal old-date
12404 (substring org-last-inserted-timestamp 1 -1))))
12405 (org-add-log-setup 'reschedule nil old-date 'findpos
12406 org-log-reschedule))
12409 (org-back-to-heading t)
12410 (when (re-search-forward (concat org-scheduled-string " "
12411 org-last-inserted-timestamp)
12413 (outline-next-heading) (point)) t)
12414 (goto-char (1- (match-end 0)))
12415 (insert " " repeater)
12416 (setq org-last-inserted-timestamp
12417 (concat (substring org-last-inserted-timestamp 0 -1)
12419 (substring org-last-inserted-timestamp -1))))))
12420 (message "Scheduled to %s" org-last-inserted-timestamp)))))
12422 (defun org-get-scheduled-time (pom &optional inherit)
12423 "Get the scheduled time as a time tuple, of a format suitable
12424 for calling org-schedule with, or if there is no scheduling,
12426 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
12428 (apply 'encode-time (org-parse-time-string time)))))
12430 (defun org-get-deadline-time (pom &optional inherit)
12431 "Get the deadline as a time tuple, of a format suitable for
12432 calling org-deadline with, or if there is no scheduling, returns
12434 (let ((time (org-entry-get pom "DEADLINE" inherit)))
12436 (apply 'encode-time (org-parse-time-string time)))))
12438 (defun org-remove-timestamp-with-keyword (keyword)
12439 "Remove all time stamps with KEYWORD in the current entry."
12440 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
12443 (org-back-to-heading t)
12445 (outline-next-heading)
12446 (while (re-search-backward re beg t)
12448 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
12449 (equal (char-before) ?\ ))
12450 (backward-delete-char 1)
12451 (if (string-match "^[ \t]*$" (buffer-substring
12452 (point-at-bol) (point-at-eol)))
12453 (delete-region (point-at-bol)
12454 (min (point-max) (1+ (point-at-eol))))))))))
12456 (defun org-add-planning-info (what &optional time &rest remove)
12457 "Insert new timestamp with keyword in the line directly after the headline.
12458 WHAT indicates what kind of time stamp to add. TIME indicates the time to use.
12459 If non is given, the user is prompted for a date.
12460 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
12463 (let (org-time-was-given org-end-time-was-given ts
12464 end default-time default-input)
12467 (when (and (memq what '(scheduled deadline))
12469 (and (stringp time)
12470 (string-match "^[-+]+[0-9]" time))))
12471 ;; Try to get a default date/time from existing timestamp
12473 (org-back-to-heading t)
12474 (setq end (save-excursion (outline-next-heading) (point)))
12475 (when (re-search-forward (if (eq what 'scheduled)
12476 org-scheduled-time-regexp
12477 org-deadline-time-regexp)
12479 (setq ts (match-string 1)
12481 (apply 'encode-time (org-parse-time-string ts))
12482 default-input (and ts (org-get-compact-tod ts))))))
12486 ;; This is a string (relative or absolute), set proper date
12487 (apply 'encode-time
12488 (org-read-date-analyze
12489 time default-time (decode-time default-time)))
12490 ;; If necessary, get the time from the user
12491 (or time (org-read-date nil 'to-time nil nil
12492 default-time default-input)))))
12494 (when (and org-insert-labeled-timestamps-at-point
12495 (member what '(scheduled deadline)))
12497 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
12498 (org-insert-time-stamp time org-time-was-given
12499 nil nil nil (list org-end-time-was-given))
12503 (let (col list elt ts buffer-invisibility-spec)
12504 (org-back-to-heading t)
12505 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"))
12506 (goto-char (match-end 1))
12507 (setq col (current-column))
12508 (goto-char (match-end 0))
12509 (if (eobp) (insert "\n") (forward-char 1))
12510 (when (and (not what)
12513 org-keyword-time-not-clock-regexp))))
12514 ;; Nothing to add, nothing to remove...... :-)
12516 (if (and (not (looking-at org-outline-regexp))
12517 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
12519 (not (equal (match-string 1) org-clock-string)))
12520 (narrow-to-region (match-beginning 0) (match-end 0))
12521 (insert-before-markers "\n")
12523 (narrow-to-region (point) (point))
12524 (and org-adapt-indentation (org-indent-to-column col)))
12525 ;; Check if we have to remove something.
12526 (setq list (cons what remove))
12528 (setq elt (pop list))
12529 (when (or (and (eq elt 'scheduled)
12530 (re-search-forward org-scheduled-time-regexp nil t))
12531 (and (eq elt 'deadline)
12532 (re-search-forward org-deadline-time-regexp nil t))
12533 (and (eq elt 'closed)
12534 (re-search-forward org-closed-time-regexp nil t)))
12536 (if (looking-at "--+<[^>]+>") (replace-match ""))))
12537 (and (looking-at "[ \t]+") (replace-match ""))
12538 (and org-adapt-indentation (bolp) (org-indent-to-column col))
12541 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
12542 (cond ((eq what 'scheduled) org-scheduled-string)
12543 ((eq what 'deadline) org-deadline-string)
12544 ((eq what 'closed) org-closed-string))
12546 (setq ts (org-insert-time-stamp
12548 (or org-time-was-given
12549 (and (eq what 'closed) org-log-done-with-time))
12551 nil nil (list org-end-time-was-given)))
12553 (if (not (or (bolp) (eq (char-before) ?\ )
12554 (memq (char-after) '(32 10))
12557 (goto-char (point-min))
12559 (if (and (looking-at "[ \t]*\n")
12560 (equal (char-before) ?\n))
12561 (delete-region (1- (point)) (point-at-eol)))
12564 (defvar org-log-note-marker (make-marker))
12565 (defvar org-log-note-purpose nil)
12566 (defvar org-log-note-state nil)
12567 (defvar org-log-note-previous-state nil)
12568 (defvar org-log-note-how nil)
12569 (defvar org-log-note-extra nil)
12570 (defvar org-log-note-window-configuration nil)
12571 (defvar org-log-note-return-to (make-marker))
12572 (defvar org-log-note-effective-time nil
12573 "Remembered current time so that dynamically scoped
12574 `org-extend-today-until' affects tha timestamps in state change
12577 (defvar org-log-post-message nil
12578 "Message to be displayed after a log note has been stored.
12579 The auto-repeater uses this.")
12581 (defun org-add-note ()
12582 "Add a note to the current entry.
12583 This is done in the same way as adding a state change note."
12585 (org-add-log-setup 'note nil nil 'findpos nil))
12587 (defvar org-property-end-re)
12588 (defun org-add-log-setup (&optional purpose state prev-state
12590 "Set up the post command hook to take a note.
12591 If this is about to TODO state change, the new state is expected in STATE.
12592 When FINDPOS is non-nil, find the correct position for the note in
12593 the current entry. If not, assume that it can be inserted at point.
12594 HOW is an indicator what kind of note should be created.
12595 EXTRA is additional text that will be inserted into the notes buffer."
12596 (let* ((org-log-into-drawer (org-log-into-drawer))
12597 (drawer (cond ((stringp org-log-into-drawer)
12598 org-log-into-drawer)
12599 (org-log-into-drawer "LOGBOOK"))))
12603 (org-back-to-heading t)
12604 (narrow-to-region (point) (save-excursion
12605 (outline-next-heading) (point)))
12606 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"
12607 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
12609 (goto-char (match-end 0))
12612 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
12615 (goto-char (match-end 0))
12616 (or org-log-states-order-reversed
12617 (and (re-search-forward org-property-end-re nil t)
12618 (goto-char (1- (match-beginning 0))))))
12619 (insert "\n:" drawer ":\n:END:")
12620 (beginning-of-line 0)
12622 (beginning-of-line 2)
12625 ((and org-log-state-notes-insert-after-drawers
12627 (forward-line) (looking-at org-drawer-regexp)))
12629 (while (looking-at org-drawer-regexp)
12630 (goto-char (match-end 0))
12631 (re-search-forward org-property-end-re (point-max) t)
12633 (forward-line -1)))
12634 (unless org-log-states-order-reversed
12635 (and (= (char-after) ?\n) (forward-char 1))
12636 (org-skip-over-state-notes)
12637 (skip-chars-backward " \t\n\r")))
12638 (move-marker org-log-note-marker (point))
12639 (setq org-log-note-purpose purpose
12640 org-log-note-state state
12641 org-log-note-previous-state prev-state
12642 org-log-note-how how
12643 org-log-note-extra extra
12644 org-log-note-effective-time (org-current-effective-time))
12645 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
12647 (defun org-skip-over-state-notes ()
12648 "Skip past the list of State notes in an entry."
12649 (if (looking-at "\n[ \t]*- State") (forward-char 1))
12650 (when (ignore-errors (goto-char (org-in-item-p)))
12651 (let* ((struct (org-list-struct))
12652 (prevs (org-list-prevs-alist struct)))
12653 (while (looking-at "[ \t]*- State")
12654 (goto-char (or (org-list-get-next-item (point) struct prevs)
12655 (org-list-get-item-end (point) struct)))))))
12657 (defun org-add-log-note (&optional purpose)
12658 "Pop up a window for taking a note, and add this note later at point."
12659 (remove-hook 'post-command-hook 'org-add-log-note)
12660 (setq org-log-note-window-configuration (current-window-configuration))
12661 (delete-other-windows)
12662 (move-marker org-log-note-return-to (point))
12663 (org-pop-to-buffer-same-window (marker-buffer org-log-note-marker))
12664 (goto-char org-log-note-marker)
12665 (org-switch-to-buffer-other-window "*Org Note*")
12667 (if (memq org-log-note-how '(time state))
12668 (let (current-prefix-arg) (org-store-log-note))
12669 (let ((org-inhibit-startup t)) (org-mode))
12670 (insert (format "# Insert note for %s.
12671 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
12673 ((eq org-log-note-purpose 'clock-out) "stopped clock")
12674 ((eq org-log-note-purpose 'done) "closed todo item")
12675 ((eq org-log-note-purpose 'state)
12676 (format "state change from \"%s\" to \"%s\""
12677 (or org-log-note-previous-state "")
12678 (or org-log-note-state "")))
12679 ((eq org-log-note-purpose 'reschedule)
12681 ((eq org-log-note-purpose 'delschedule)
12682 "no longer scheduled")
12683 ((eq org-log-note-purpose 'redeadline)
12684 "changing deadline")
12685 ((eq org-log-note-purpose 'deldeadline)
12686 "removing deadline")
12687 ((eq org-log-note-purpose 'refile)
12689 ((eq org-log-note-purpose 'note)
12691 (t (error "This should not happen")))))
12692 (if org-log-note-extra (insert org-log-note-extra))
12693 (org-set-local 'org-finish-function 'org-store-log-note)
12694 (run-hooks 'org-log-buffer-setup-hook)))
12696 (defvar org-note-abort nil) ; dynamically scoped
12697 (defun org-store-log-note ()
12698 "Finish taking a log note, and insert it to where it belongs."
12699 (let ((txt (buffer-string))
12700 (note (cdr (assq org-log-note-purpose org-log-note-headings)))
12702 (kill-buffer (current-buffer))
12703 (while (string-match "\\`# .*\n[ \t\n]*" txt)
12704 (setq txt (replace-match "" t t txt)))
12705 (if (string-match "\\s-+\\'" txt)
12706 (setq txt (replace-match "" t t txt)))
12707 (setq lines (org-split-string txt "\n"))
12708 (when (and note (string-match "\\S-" note))
12710 (org-replace-escapes
12712 (list (cons "%u" (user-login-name))
12713 (cons "%U" user-full-name)
12714 (cons "%t" (format-time-string
12715 (org-time-stamp-format 'long 'inactive)
12716 org-log-note-effective-time))
12717 (cons "%T" (format-time-string
12718 (org-time-stamp-format 'long nil)
12719 org-log-note-effective-time))
12720 (cons "%d" (format-time-string
12721 (org-time-stamp-format nil 'inactive)
12722 org-log-note-effective-time))
12723 (cons "%D" (format-time-string
12724 (org-time-stamp-format nil nil)
12725 org-log-note-effective-time))
12726 (cons "%s" (if org-log-note-state
12727 (concat "\"" org-log-note-state "\"")
12729 (cons "%S" (if org-log-note-previous-state
12730 (concat "\"" org-log-note-previous-state "\"")
12732 (if lines (setq note (concat note " \\\\")))
12734 (when (or current-prefix-arg org-note-abort)
12735 (when org-log-into-drawer
12736 (org-remove-empty-drawer-at
12737 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
12738 org-log-note-marker))
12741 (with-current-buffer (marker-buffer org-log-note-marker)
12743 (goto-char org-log-note-marker)
12744 (move-marker org-log-note-marker nil)
12746 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
12747 (setq ind (save-excursion
12748 (if (ignore-errors (goto-char (org-in-item-p)))
12749 (let ((struct (org-list-struct)))
12751 (org-list-get-top-point struct) struct))
12752 (skip-chars-backward " \r\t\n")
12754 ((and (org-at-heading-p)
12755 org-adapt-indentation)
12756 (1+ (org-current-level)))
12757 ((org-at-heading-p) 0)
12758 (t (org-get-indentation))))))
12759 (setq bul (org-list-bullet-string "-"))
12760 (org-indent-line-to ind)
12761 (insert bul (pop lines))
12762 (let ((ind-body (+ (length bul) ind)))
12765 (org-indent-line-to ind-body)
12766 (insert (pop lines))))
12767 (message "Note stored")
12768 (org-back-to-heading t)
12769 (org-cycle-hide-drawers 'children)))))
12770 (set-window-configuration org-log-note-window-configuration)
12771 (with-current-buffer (marker-buffer org-log-note-return-to)
12772 (goto-char org-log-note-return-to))
12773 (move-marker org-log-note-return-to nil)
12774 (and org-log-post-message (message "%s" org-log-post-message)))
12776 (defun org-remove-empty-drawer-at (drawer pos)
12777 "Remove an empty drawer DRAWER at position POS.
12778 POS may also be a marker."
12779 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
12785 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
12786 (replace-match ""))))))
12788 (defvar org-ts-type nil)
12789 (defun org-sparse-tree (&optional arg type)
12790 "Create a sparse tree, prompt for the details.
12791 This command can create sparse trees. You first need to select the type
12792 of match used to create the tree:
12794 t Show all TODO entries.
12795 T Show entries with a specific TODO keyword.
12796 m Show entries selected by a tags/property match.
12797 p Enter a property name and its value (both with completion on existing
12798 names/values) and show entries with that property.
12799 r Show entries matching a regular expression (`/' can be used as well).
12800 b Show deadlines and scheduled items before a date.
12801 a Show deadlines and scheduled items after a date.
12802 d Show deadlines due within `org-deadline-warning-days'.
12803 D Show deadlines and scheduled items between a date range."
12805 (let (ans kwd value ts-type)
12806 (setq type (or type org-sparse-tree-default-date-type))
12807 (setq org-ts-type type)
12808 (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\n [c]ycle through date types: %s"
12809 (cond ((eq type 'all) "all timestamps")
12810 ((eq type 'scheduled) "only scheduled")
12811 ((eq type 'deadline) "only deadline")
12812 ((eq type 'active) "only active timestamps")
12813 ((eq type 'inactive) "only inactive timestamps")
12814 ((eq type 'scheduled-or-deadline) "scheduled/deadline")
12815 (t "scheduled/deadline")))
12816 (setq ans (read-char-exclusive))
12819 (org-sparse-tree arg (cadr (member type '(scheduled-or-deadline all scheduled deadline active inactive)))))
12821 (call-interactively 'org-check-deadlines))
12823 (call-interactively 'org-check-before-date))
12825 (call-interactively 'org-check-after-date))
12827 (call-interactively 'org-check-dates-range))
12829 (org-show-todo-tree nil))
12831 (org-show-todo-tree '(4)))
12832 ((member ans '(?T ?m))
12833 (call-interactively 'org-match-sparse-tree))
12834 ((member ans '(?p ?P))
12835 (setq kwd (org-icompleting-read "Property: "
12836 (mapcar 'list (org-buffer-property-keys))))
12837 (setq value (org-icompleting-read "Value: "
12838 (mapcar 'list (org-property-values kwd))))
12839 (unless (string-match "\\`{.*}\\'" value)
12840 (setq value (concat "\"" value "\"")))
12841 (org-match-sparse-tree arg (concat kwd "=" value)))
12842 ((member ans '(?r ?R ?/))
12843 (call-interactively 'org-occur))
12844 (t (error "No such sparse tree command \"%c\"" ans)))))
12846 (defvar org-occur-highlights nil
12847 "List of overlays used for occur matches.")
12848 (make-variable-buffer-local 'org-occur-highlights)
12849 (defvar org-occur-parameters nil
12850 "Parameters of the active org-occur calls.
12851 This is a list, each call to org-occur pushes as cons cell,
12852 containing the regular expression and the callback, onto the list.
12853 The list can contain several entries if `org-occur' has been called
12854 several time with the KEEP-PREVIOUS argument. Otherwise, this list
12855 will only contain one set of parameters. When the highlights are
12856 removed (for example with `C-c C-c', or with the next edit (depending
12857 on `org-remove-highlights-with-change'), this variable is emptied
12859 (make-variable-buffer-local 'org-occur-parameters)
12861 (defun org-occur (regexp &optional keep-previous callback)
12862 "Make a compact tree which shows all matches of REGEXP.
12863 The tree will show the lines where the regexp matches, and all higher
12864 headlines above the match. It will also show the heading after the match,
12865 to make sure editing the matching entry is easy.
12866 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
12867 call to `org-occur' will be kept, to allow stacking of calls to this
12869 If CALLBACK is non-nil, it is a function which is called to confirm
12870 that the match should indeed be shown."
12871 (interactive "sRegexp: \nP")
12872 (when (equal regexp "")
12873 (error "Regexp cannot be empty"))
12874 (unless keep-previous
12875 (org-remove-occur-highlights nil nil t))
12876 (push (cons regexp callback) org-occur-parameters)
12879 (goto-char (point-min))
12880 (if (or (not keep-previous) ; do not want to keep
12881 (not org-occur-highlights)) ; no previous matches
12884 (while (re-search-forward regexp nil t)
12885 (when (or (not callback)
12886 (save-match-data (funcall callback)))
12887 (setq cnt (1+ cnt))
12888 (when org-highlight-sparse-tree-matches
12889 (org-highlight-new-match (match-beginning 0) (match-end 0)))
12890 (org-show-context 'occur-tree))))
12891 (when org-remove-highlights-with-change
12892 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
12894 (unless org-sparse-tree-open-archived-trees
12895 (org-hide-archived-subtrees (point-min) (point-max)))
12896 (run-hooks 'org-occur-hook)
12897 (if (org-called-interactively-p 'interactive)
12898 (message "%d match(es) for regexp %s" cnt regexp))
12901 (defun org-occur-next-match (&optional n reset)
12902 "Function for `next-error-function' to find sparse tree matches.
12903 N is the number of matches to move, when negative move backwards.
12904 RESET is entirely ignored - this function always goes back to the
12905 starting point when no match is found."
12906 (let* ((limit (if (< n 0) (point-min) (point-max)))
12907 (search-func (if (< n 0)
12908 'previous-single-char-property-change
12909 'next-single-char-property-change))
12914 (while (setq p1 (funcall search-func (point) 'org-type))
12915 (when (equal p1 limit)
12917 (error "No more matches"))
12918 (when (equal (get-char-property p1 'org-type) 'org-occur)
12922 (throw 'exit (point))))
12925 (error "No more matches"))))
12927 (defun org-show-context (&optional key)
12928 "Make sure point and context are visible.
12929 How much context is shown depends upon the variables
12930 `org-show-hierarchy-above', `org-show-following-heading',
12931 `org-show-entry-below' and `org-show-siblings'."
12932 (let ((heading-p (org-at-heading-p t))
12933 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
12934 (following-p (org-get-alist-option org-show-following-heading key))
12935 (entry-p (org-get-alist-option org-show-entry-below key))
12936 (siblings-p (org-get-alist-option org-show-siblings key)))
12938 ;; Show heading or entry text
12939 (if (and heading-p (not entry-p))
12940 (org-flag-heading nil) ; only show the heading
12941 (and (or entry-p (outline-invisible-p) (org-invisible-p2))
12942 (org-show-hidden-entry))) ; show entire entry
12944 ;; Show next sibling, or heading below text
12946 (and (if heading-p (org-goto-sibling) (outline-next-heading))
12947 (org-flag-heading nil))))
12948 (when siblings-p (org-show-siblings))
12950 ;; show all higher headings, possibly with siblings
12952 (while (and (condition-case nil
12953 (progn (org-up-heading-all 1) t)
12956 (org-flag-heading nil)
12957 (when siblings-p (org-show-siblings))))))))
12959 (defvar org-reveal-start-hook nil
12960 "Hook run before revealing a location.")
12962 (defun org-reveal (&optional siblings)
12963 "Show current entry, hierarchy above it, and the following headline.
12964 This can be used to show a consistent set of context around locations
12965 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
12966 not t for the search context.
12968 With optional argument SIBLINGS, on each level of the hierarchy all
12969 siblings are shown. This repairs the tree structure to what it would
12970 look like when opened with hierarchical calls to `org-cycle'.
12971 With double optional argument \\[universal-argument] \\[universal-argument], \
12972 go to the parent and show the
12975 (run-hooks 'org-reveal-start-hook)
12976 (let ((org-show-hierarchy-above t)
12977 (org-show-following-heading t)
12978 (org-show-siblings (if siblings t org-show-siblings)))
12979 (org-show-context nil))
12980 (when (equal siblings '(16))
12982 (when (org-up-heading-safe)
12984 (run-hook-with-args 'org-cycle-hook 'subtree)))))
12986 (defun org-highlight-new-match (beg end)
12987 "Highlight from BEG to END and mark the highlight is an occur headline."
12988 (let ((ov (make-overlay beg end)))
12989 (overlay-put ov 'face 'secondary-selection)
12990 (overlay-put ov 'org-type 'org-occur)
12991 (push ov org-occur-highlights)))
12993 (defun org-remove-occur-highlights (&optional beg end noremove)
12994 "Remove the occur highlights from the buffer.
12995 BEG and END are ignored. If NOREMOVE is nil, remove this function
12996 from the `before-change-functions' in the current buffer."
12998 (unless org-inhibit-highlight-removal
12999 (mapc 'delete-overlay org-occur-highlights)
13000 (setq org-occur-highlights nil)
13001 (setq org-occur-parameters nil)
13003 (remove-hook 'before-change-functions
13004 'org-remove-occur-highlights 'local))))
13008 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
13009 "Regular expression matching the priority indicator.")
13011 (defvar org-remove-priority-next-time nil)
13013 (defun org-priority-up ()
13014 "Increase the priority of the current item."
13016 (org-priority 'up))
13018 (defun org-priority-down ()
13019 "Decrease the priority of the current item."
13021 (org-priority 'down))
13023 (defun org-priority (&optional action)
13024 "Change the priority of an item.
13025 ACTION can be `set', `up', `down', or a character."
13027 (unless org-enable-priority-commands
13028 (error "Priority commands are disabled"))
13029 (setq action (or action 'set))
13030 (let (current new news have remove)
13032 (org-back-to-heading t)
13033 (if (looking-at org-priority-regexp)
13034 (setq current (string-to-char (match-string 2))
13037 ((eq action 'remove)
13038 (setq remove t new ?\ ))
13039 ((or (eq action 'set)
13040 (if (featurep 'xemacs) (characterp action) (integerp action)))
13041 (if (not (eq action 'set))
13043 (message "Priority %c-%c, SPC to remove: "
13044 org-highest-priority org-lowest-priority)
13046 (setq new (read-char-exclusive))))
13047 (if (and (= (upcase org-highest-priority) org-highest-priority)
13048 (= (upcase org-lowest-priority) org-lowest-priority))
13049 (setq new (upcase new)))
13050 (cond ((equal new ?\ ) (setq remove t))
13051 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
13052 (error "Priority must be between `%c' and `%c'"
13053 org-highest-priority org-lowest-priority))))
13056 (1- current) ; normal cycling
13057 ;; last priority was empty
13058 (if (eq last-command this-command)
13059 org-lowest-priority ; wrap around empty to lowest
13061 (if org-priority-start-cycle-with-default
13062 org-default-priority
13063 (1- org-default-priority))))))
13066 (1+ current) ; normal cycling
13067 ;; last priority was empty
13068 (if (eq last-command this-command)
13069 org-highest-priority ; wrap around empty to highest
13071 (if org-priority-start-cycle-with-default
13072 org-default-priority
13073 (1+ org-default-priority))))))
13074 (t (error "Invalid action")))
13075 (if (or (< (upcase new) org-highest-priority)
13076 (> (upcase new) org-lowest-priority))
13077 (if (and (memq action '(up down))
13078 (not have) (not (eq last-command this-command)))
13079 ;; `new' is from default priority
13081 "The default can not be set, see `org-default-priority' why")
13082 ;; normal cycling: `new' is beyond highest/lowest priority
13083 ;; and is wrapped around to the empty priority
13085 (setq news (format "%c" new))
13088 (replace-match "" t t nil 1)
13089 (replace-match news t t nil 2))
13091 (error "No priority cookie found in line")
13092 (let ((case-fold-search nil))
13093 (looking-at org-todo-line-regexp))
13096 (goto-char (match-end 2))
13097 (insert " [#" news "]"))
13098 (goto-char (match-beginning 3))
13099 (insert "[#" news "] "))))
13100 (org-preserve-lc (org-set-tags nil 'align)))
13102 (message "Priority removed")
13103 (message "Priority of current item set to %s" news))))
13105 (defun org-get-priority (s)
13106 "Find priority cookie and return priority."
13107 (if (functionp org-get-priority-function)
13108 (funcall org-get-priority-function)
13110 (if (not (string-match org-priority-regexp s))
13111 (* 1000 (- org-lowest-priority org-default-priority))
13112 (* 1000 (- org-lowest-priority
13113 (string-to-char (match-string 2 s))))))))
13117 (defvar org-agenda-archives-mode)
13118 (defvar org-map-continue-from nil
13119 "Position from where mapping should continue.
13120 Can be set by the action argument to `org-scan-tags' and `org-map-entries'.")
13122 (defvar org-scanner-tags nil
13123 "The current tag list while the tags scanner is running.")
13124 (defvar org-trust-scanner-tags nil
13125 "Should `org-get-tags-at' use the tags for the scanner.
13126 This is for internal dynamical scoping only.
13127 When this is non-nil, the function `org-get-tags-at' will return the value
13128 of `org-scanner-tags' instead of building the list by itself. This
13129 can lead to large speed-ups when the tags scanner is used in a file with
13130 many entries, and when the list of tags is retrieved, for example to
13131 obtain a list of properties. Building the tags list for each entry in such
13132 a file becomes an N^2 operation - but with this variable set, it scales
13135 (defun org-scan-tags (action matcher todo-only &optional start-level)
13136 "Scan headline tags with inheritance and produce output ACTION.
13138 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
13139 or `agenda' to produce an entry list for an agenda view. It can also be
13140 a Lisp form or a function that should be called at each matched headline, in
13141 this case the return value is a list of all return values from these calls.
13143 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
13144 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
13145 only lines with a not-done TODO keyword are included in the output.
13146 This should be the same variable that was scoped into
13147 and set by `org-make-tags-matcher' when it constructed MATCHER.
13149 START-LEVEL can be a string with asterisks, reducing the scope to
13150 headlines matching this string."
13151 (require 'org-agenda)
13152 (let* ((re (concat "^"
13154 ;; Get the correct level to match
13155 (concat "\\*\\{" (number-to-string start-level) "\\} ")
13156 org-outline-regexp)
13158 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
13159 (org-re "\\)\\>\\)? *\\(.*?\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*$")))
13160 (props (list 'face 'default
13161 'done-face 'org-agenda-done
13162 'undone-face 'default
13163 'mouse-face 'highlight
13164 'org-not-done-regexp org-not-done-regexp
13165 'org-todo-regexp org-todo-regexp
13166 'org-complex-heading-regexp org-complex-heading-regexp
13168 (format "mouse-2 or RET jump to org file %s"
13169 (abbreviate-file-name
13170 (or (buffer-file-name (buffer-base-buffer))
13171 (buffer-name (buffer-base-buffer)))))))
13172 (case-fold-search nil)
13173 (org-map-continue-from nil)
13174 lspos tags tags-list
13175 (tags-alist (list (cons 0 org-file-tags)))
13176 (llast 0) rtn rtn1 level category i txt
13177 todo marker entry priority)
13178 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
13179 (setq action (list 'lambda nil action)))
13181 (goto-char (point-min))
13182 (when (eq action 'sparse-tree)
13184 (org-remove-occur-highlights))
13185 (while (re-search-forward re nil t)
13186 (setq org-map-continue-from nil)
13188 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
13189 tags (if (match-end 4) (org-match-string-no-properties 4)))
13190 (goto-char (setq lspos (match-beginning 0)))
13191 (setq level (org-reduced-level (funcall outline-level))
13192 category (org-get-category))
13193 (setq i llast llast level)
13194 ;; remove tag lists from same and sublevels
13195 (while (>= i level)
13196 (when (setq entry (assoc i tags-alist))
13197 (setq tags-alist (delete entry tags-alist)))
13199 ;; add the next tags
13201 (setq tags (org-split-string tags ":")
13203 (cons (cons level tags) tags-alist)))
13204 ;; compile tags for current headline
13206 (if org-use-tag-inheritance
13207 (apply 'append (mapcar 'cdr (reverse tags-alist)))
13209 org-scanner-tags tags-list)
13210 (when org-use-tag-inheritance
13211 (setcdr (car tags-alist)
13212 (mapcar (lambda (x)
13213 (setq x (copy-sequence x))
13214 (org-add-prop-inherited x))
13215 (cdar tags-alist))))
13216 (when (and tags org-use-tag-inheritance
13217 (or (not (eq t org-use-tag-inheritance))
13218 org-tags-exclude-from-inheritance))
13219 ;; selective inheritance, remove uninherited ones
13220 (setcdr (car tags-alist)
13221 (org-remove-uninherited-tags (cdar tags-alist))))
13224 ;; eval matcher only when the todo condition is OK
13225 (and (or (not todo-only) (member todo org-not-done-keywords))
13226 (let ((case-fold-search t) (org-trust-scanner-tags t))
13229 ;; Call the skipper, but return t if it does not skip,
13230 ;; so that the `and' form continues evaluating
13232 (unless (eq action 'sparse-tree) (org-agenda-skip))
13235 ;; Check if timestamps are deselecting this entry
13236 (or (not todo-only)
13237 (and (member todo org-not-done-keywords)
13238 (or (not org-agenda-tags-todo-honor-ignore-options)
13239 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))))
13241 ;; Extra check for the archive tag
13242 ;; FIXME: Does the skipper already do this????
13244 (not (member org-archive-tag tags-list))
13245 ;; we have an archive tag, should we use this anyway?
13246 (or (not org-agenda-skip-archived-trees)
13247 (and (eq action 'agenda) org-agenda-archives-mode))))
13249 ;; select this headline
13252 ((eq action 'sparse-tree)
13253 (and org-highlight-sparse-tree-matches
13254 (org-get-heading) (match-end 0)
13255 (org-highlight-new-match
13256 (match-beginning 1) (match-end 1)))
13257 (org-show-context 'tags-tree))
13258 ((eq action 'agenda)
13259 (setq txt (org-agenda-format-item
13262 (if (eq org-tags-match-list-sublevels 'indented)
13263 (make-string (1- level) ?.) "")
13267 priority (org-get-priority txt))
13269 (setq marker (org-agenda-new-marker))
13270 (org-add-props txt props
13271 'org-marker marker 'org-hd-marker marker 'org-category category
13273 'priority priority 'type "tagsmatch")
13275 ((functionp action)
13276 (setq org-map-continue-from nil)
13278 (setq rtn1 (funcall action))
13280 (t (error "Invalid action")))
13282 ;; if we are to skip sublevels, jump to end of subtree
13283 (unless org-tags-match-list-sublevels
13284 (org-end-of-subtree t)
13285 (backward-char 1))))
13286 ;; Get the correct position from where to continue
13287 (if org-map-continue-from
13288 (goto-char org-map-continue-from)
13289 (and (= (point) lspos) (end-of-line 1)))))
13290 (when (and (eq action 'sparse-tree)
13291 (not org-sparse-tree-open-archived-trees))
13292 (org-hide-archived-subtrees (point-min) (point-max)))
13295 (defun org-remove-uninherited-tags (tags)
13296 "Remove all tags that are not inherited from the list TAGS."
13298 ((eq org-use-tag-inheritance t)
13299 (if org-tags-exclude-from-inheritance
13300 (org-delete-all org-tags-exclude-from-inheritance tags)
13302 ((not org-use-tag-inheritance) nil)
13303 ((stringp org-use-tag-inheritance)
13306 (if (and (string-match org-use-tag-inheritance x)
13307 (not (member x org-tags-exclude-from-inheritance)))
13310 ((listp org-use-tag-inheritance)
13313 (if (member x org-use-tag-inheritance) x nil))
13316 (defun org-match-sparse-tree (&optional todo-only match)
13317 "Create a sparse tree according to tags string MATCH.
13318 MATCH can contain positive and negative selection of tags, like
13319 \"+WORK+URGENT-WITHBOSS\".
13320 If optional argument TODO-ONLY is non-nil, only select lines that are
13323 (org-agenda-prepare-buffers (list (current-buffer)))
13324 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
13326 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
13328 (defvar org-cached-props nil)
13329 (defun org-cached-entry-get (pom property)
13330 (if (or (eq t org-use-property-inheritance)
13331 (and (stringp org-use-property-inheritance)
13332 (string-match org-use-property-inheritance property))
13333 (and (listp org-use-property-inheritance)
13334 (member property org-use-property-inheritance)))
13335 ;; Caching is not possible, check it directly
13336 (org-entry-get pom property 'inherit)
13337 ;; Get all properties, so that we can do complicated checks easily
13338 (cdr (assoc property (or org-cached-props
13339 (setq org-cached-props
13340 (org-entry-properties pom)))))))
13342 (defun org-global-tags-completion-table (&optional files)
13343 "Return the list of all tags in all agenda buffer/files.
13344 Optional FILES argument is a list of files which can be used
13345 instead of the agenda files."
13352 (set-buffer (find-file-noselect file))
13353 (append (org-get-buffer-tags)
13354 (mapcar (lambda (x) (if (stringp (car-safe x))
13355 (list (car-safe x)) nil))
13357 (if (and files (car files))
13359 (org-agenda-files))))))))
13361 (defun org-make-tags-matcher (match)
13362 "Create the TAGS/TODO matcher form for the selection string MATCH.
13364 The variable `todo-only' is scoped dynamically into this function.
13365 It will be set to t if the matcher restricts matching to TODO entries,
13366 otherwise will not be touched.
13368 Returns a cons of the selection string MATCH and the constructed
13369 lisp form implementing the matcher. The matcher is to be evaluated
13370 at an Org entry, with point on the headline, and returns t if the
13371 entry matches the selection string MATCH. The returned lisp form
13372 references two variables with information about the entry, which
13373 must be bound around the form's evaluation: todo, the TODO keyword
13374 at the entry (or nil of none); and tags-list, the list of all tags
13375 at the entry including inherited ones. Additionally, the category
13376 of the entry (if any) must be specified as the text property
13377 'org-category on the headline.
13379 See also `org-scan-tags'.
13381 (declare (special todo-only))
13382 (unless (boundp 'todo-only)
13383 (error "org-make-tags-matcher expects todo-only to be scoped in"))
13385 ;; Get a new match request, with completion
13386 (let ((org-last-tags-completion-table
13387 (org-global-tags-completion-table)))
13388 (setq match (org-completing-read-no-i
13389 "Match: " 'org-tags-completion-function nil nil nil
13390 'org-tags-history))))
13392 ;; Parse the string and create a lisp form
13393 (let ((match0 match)
13394 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@#%]+\\)"))
13396 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
13397 orterms term orlist re-p str-p level-p level-op time-p
13398 prop-p pn pv po gv rest)
13399 (if (string-match "/+" match)
13400 ;; match contains also a todo-matching request
13402 (setq tagsmatch (substring match 0 (match-beginning 0))
13403 todomatch (substring match (match-end 0)))
13404 (if (string-match "^!" todomatch)
13405 (setq todo-only t todomatch (substring todomatch 1)))
13406 (if (string-match "^\\s-*$" todomatch)
13407 (setq todomatch nil)))
13408 ;; only matching tags
13409 (setq tagsmatch match todomatch nil))
13411 ;; Make the tags matcher
13412 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
13413 (setq tagsmatcher t)
13414 (setq orterms (org-split-string tagsmatch "|") orlist nil)
13415 (while (setq term (pop orterms))
13416 (while (and (equal (substring term -1) "\\") orterms)
13417 (setq term (concat term "|" (pop orterms)))) ; repair bad split
13418 (while (string-match re term)
13419 (setq rest (substring term (match-end 0))
13420 minus (and (match-end 1)
13421 (equal (match-string 1 term) "-"))
13422 tag (save-match-data (replace-regexp-in-string
13424 (match-string 2 term)))
13425 re-p (equal (string-to-char tag) ?{)
13426 level-p (match-end 4)
13427 prop-p (match-end 5)
13429 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
13431 (setq level-op (org-op-to-function (match-string 3 term)))
13432 `(,level-op level ,(string-to-number
13433 (match-string 4 term))))
13435 (setq pn (match-string 5 term)
13436 po (match-string 6 term)
13437 pv (match-string 7 term)
13438 re-p (equal (string-to-char pv) ?{)
13439 str-p (equal (string-to-char pv) ?\")
13440 time-p (save-match-data
13441 (string-match "^\"[[<].*[]>]\"$" pv))
13442 pv (if (or re-p str-p) (substring pv 1 -1) pv))
13443 (if time-p (setq pv (org-matcher-time pv)))
13444 (setq po (org-op-to-function po (if time-p 'time str-p)))
13446 ((equal pn "CATEGORY")
13447 (setq gv '(get-text-property (point) 'org-category)))
13451 (setq gv `(org-cached-entry-get nil ,pn))))
13454 `(not (string-match ,pv (or ,gv "")))
13455 `(string-match ,pv (or ,gv "")))
13457 `(,po (or ,gv "") ,pv)
13458 `(,po (string-to-number (or ,gv ""))
13459 ,(string-to-number pv) ))))
13460 (t `(member ,tag tags-list)))
13461 mm (if minus (list 'not mm) mm)
13463 (push mm tagsmatcher))
13464 (push (if (> (length tagsmatcher) 1)
13465 (cons 'and tagsmatcher)
13468 (setq tagsmatcher nil))
13469 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
13471 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
13472 ;; Make the todo matcher
13473 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
13474 (setq todomatcher t)
13475 (setq orterms (org-split-string todomatch "|") orlist nil)
13476 (while (setq term (pop orterms))
13477 (while (string-match re term)
13478 (setq minus (and (match-end 1)
13479 (equal (match-string 1 term) "-"))
13480 kwd (match-string 2 term)
13481 re-p (equal (string-to-char kwd) ?{)
13482 term (substring term (match-end 0))
13484 `(string-match ,(substring kwd 1 -1) todo)
13485 (list 'equal 'todo kwd))
13486 mm (if minus (list 'not mm) mm))
13487 (push mm todomatcher))
13488 (push (if (> (length todomatcher) 1)
13489 (cons 'and todomatcher)
13492 (setq todomatcher nil))
13493 (setq todomatcher (if (> (length orlist) 1)
13494 (cons 'or orlist) (car orlist))))
13496 ;; Return the string and lisp forms of the matcher
13497 (setq matcher (if todomatcher
13498 (list 'and tagsmatcher todomatcher)
13501 (setq matcher (list 'and '(member todo org-not-done-keywords)
13503 (cons match0 matcher)))
13505 (defun org-op-to-function (op &optional stringp)
13506 "Turn an operator into the appropriate function."
13509 ((equal op "<" ) '(< string< org-time<))
13510 ((equal op ">" ) '(> org-string> org-time>))
13511 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
13512 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
13513 ((member op '("=" "==")) '(= string= org-time=))
13514 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
13515 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
13517 (defun org<> (a b) (not (= a b)))
13518 (defun org-string<= (a b) (or (string= a b) (string< a b)))
13519 (defun org-string>= (a b) (not (string< a b)))
13520 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
13521 (defun org-string<> (a b) (not (string= a b)))
13522 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
13523 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
13524 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
13525 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
13526 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
13527 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
13529 "Convert S to a floating point time.
13530 If S is already a number, just return it. If it is a string, parse
13531 it as a time string and apply `float-time' to it. If S is nil, just return 0."
13535 (condition-case nil
13536 (float-time (apply 'encode-time (org-parse-time-string s)))
13540 (defun org-time-today ()
13541 "Time in seconds today at 0:00.
13542 Returns the float number of seconds since the beginning of the
13543 epoch to the beginning of today (00:00)."
13544 (float-time (apply 'encode-time
13545 (append '(0 0 0) (nthcdr 3 (decode-time))))))
13547 (defun org-matcher-time (s)
13548 "Interpret a time comparison value."
13551 ((string= s "<now>") (float-time))
13552 ((string= s "<today>") (org-time-today))
13553 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
13554 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
13555 ((string-match "^<\\([-+][0-9]+\\)\\([hdwmy]\\)>$" s)
13556 (+ (org-time-today)
13557 (* (string-to-number (match-string 1 s))
13558 (cdr (assoc (match-string 2 s)
13559 '(("d" . 86400.0) ("w" . 604800.0)
13560 ("m" . 2678400.0) ("y" . 31557600.0)))))))
13563 (defun org-match-any-p (re list)
13564 "Does re match any element of list?"
13565 (setq list (mapcar (lambda (x) (string-match re x)) list))
13568 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
13569 (defvar org-tags-overlay (make-overlay 1 1))
13570 (org-detach-overlay org-tags-overlay)
13572 (defun org-get-local-tags-at (&optional pos)
13573 "Get a list of tags defined in the current headline."
13574 (org-get-tags-at pos 'local))
13576 (defun org-get-local-tags ()
13577 "Get a list of tags defined in the current headline."
13578 (org-get-tags-at nil 'local))
13580 (defun org-get-tags-at (&optional pos local)
13581 "Get a list of all headline tags applicable at POS.
13582 POS defaults to point. If tags are inherited, the list contains
13583 the targets in the same sequence as the headlines appear, i.e.
13584 the tags of the current headline come last.
13585 When LOCAL is non-nil, only return tags from the current headline,
13586 ignore inherited ones."
13588 (if (and org-trust-scanner-tags
13589 (or (not pos) (equal pos (point)))
13592 (let (tags ltags lastpos parent)
13596 (goto-char (or pos (point)))
13599 (condition-case nil
13601 (org-back-to-heading t)
13602 (while (not (equal lastpos (point)))
13603 (setq lastpos (point))
13605 (org-re "[^\r\n]+?:\\([[:alnum:]_@#%:]+\\):[ \t]*$"))
13606 (setq ltags (org-split-string
13607 (org-match-string-no-properties 1) ":"))
13609 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
13612 (org-remove-uninherited-tags ltags)
13615 (or org-use-tag-inheritance (throw 'done t))
13616 (if local (throw 'done t))
13617 (or (org-up-heading-safe) (error nil))
13622 (append (org-remove-uninherited-tags org-file-tags) tags))))))
13624 (defun org-add-prop-inherited (s)
13625 (add-text-properties 0 (length s) '(inherited t) s)
13628 (defun org-toggle-tag (tag &optional onoff)
13629 "Toggle the tag TAG for the current line.
13630 If ONOFF is `on' or `off', don't toggle but set to this state."
13633 (org-back-to-heading t)
13634 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$")
13637 (setq current (match-string 1))
13638 (replace-match ""))
13640 (setq current (nreverse (org-split-string current ":")))
13644 (or (member tag current) (push tag current)))
13646 (or (not (member tag current)) (setq current (delete tag current))))
13647 (t (if (member tag current)
13648 (setq current (delete tag current))
13650 (push tag current))))
13654 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
13655 (org-set-tags nil t))
13656 (delete-horizontal-space))
13657 (run-hooks 'org-after-tags-change-hook))
13660 (defun org-align-tags-here (to-col)
13661 ;; Assumes that this is a headline
13662 (let ((pos (point)) (col (current-column)) ncol tags-l p)
13663 (beginning-of-line 1)
13664 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13665 (< pos (match-beginning 2)))
13667 (setq tags-l (- (match-end 2) (match-beginning 2)))
13668 (goto-char (match-beginning 1))
13670 (delete-region (point) (1+ (match-beginning 2)))
13671 (setq ncol (max (current-column)
13675 (- (abs to-col) tags-l))))
13677 (insert (make-string (- ncol (current-column)) ?\ ))
13678 (setq ncol (current-column))
13679 (when indent-tabs-mode (tabify p (point-at-eol)))
13680 (org-move-to-column (min ncol col) t))
13683 (defun org-set-tags-command (&optional arg just-align)
13684 "Call the set-tags command for the current entry."
13686 (if (or (org-at-heading-p) (and arg (org-before-first-heading-p)))
13687 (org-set-tags arg just-align)
13689 (org-back-to-heading t)
13690 (org-set-tags arg just-align))))
13692 (defun org-set-tags-to (data)
13693 "Set the tags of the current entry to DATA, replacing the current tags.
13694 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
13695 If DATA is nil or the empty string, any tags will be removed."
13696 (interactive "sTags: ")
13700 ((equal data "") "")
13702 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
13705 (concat ":" (mapconcat 'identity data ":") ":"))))
13708 (org-back-to-heading t)
13709 (when (looking-at org-complex-heading-regexp)
13712 (goto-char (match-beginning 5))
13714 (delete-region (point) (point-at-eol))
13715 (org-set-tags nil 'align))
13716 (goto-char (point-at-eol))
13718 (org-set-tags nil 'align)))
13719 (beginning-of-line 1)
13720 (if (looking-at ".*?\\([ \t]+\\)$")
13721 (delete-region (match-beginning 1) (match-end 1))))))
13723 (defun org-align-all-tags ()
13724 "Align the tags i all headings."
13727 (or (ignore-errors (org-back-to-heading t))
13728 (outline-next-heading))
13729 (if (org-at-heading-p)
13731 (message "No headings"))))
13733 (defvar org-indent-indentation-per-level)
13734 (defun org-set-tags (&optional arg just-align)
13735 "Set the tags for the current headline.
13736 With prefix ARG, realign all tags in headings in the current buffer."
13738 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
13739 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
13740 'region-start-level 'region))
13741 org-loop-over-headlines-in-active-region)
13743 ;; We don't use ARG and JUST-ALIGN here these args are not
13744 ;; useful when looping over headlines
13746 org-loop-over-headlines-in-active-region
13747 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
13748 (let* ((re org-outline-regexp-bol)
13749 (current (unless arg (org-get-tags-string)))
13750 (col (current-column))
13751 (org-setting-tags t)
13752 table current-tags inherited-tags ; computed below when needed
13753 tags p0 c0 c1 rpl di tc level)
13756 (goto-char (point-min))
13757 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
13758 (while (re-search-forward re nil t)
13759 (org-set-tags nil t)
13761 (message "All tags realigned to column %d" org-tags-column))
13763 (setq tags current)
13764 ;; Get a new set of tags from the user
13766 (setq table (append org-tag-persistent-alist
13767 (or org-tag-alist (org-get-buffer-tags))
13769 org-complete-tags-always-offer-all-agenda-tags
13770 (org-global-tags-completion-table
13771 (org-agenda-files))))
13772 org-last-tags-completion-table table
13773 current-tags (org-split-string current ":")
13774 inherited-tags (nreverse
13775 (nthcdr (length current-tags)
13776 (nreverse (org-get-tags-at))))
13778 (if (or (eq t org-use-fast-tag-selection)
13779 (and org-use-fast-tag-selection
13780 (delq nil (mapcar 'cdr table))))
13781 (org-fast-tag-selection
13782 current-tags inherited-tags table
13783 (if org-fast-tag-selection-include-todo
13784 org-todo-key-alist))
13785 (let ((org-add-colon-after-tag-completion (< 1 (length table))))
13787 (org-icompleting-read "Tags: "
13788 'org-tags-completion-function
13789 nil nil current 'org-tags-history))))))
13790 (while (string-match "[-+&]+" tags)
13791 ;; No boolean logic, just a list
13792 (setq tags (replace-match ":" t t tags))))
13794 (setq tags (replace-regexp-in-string "[,]" ":" tags))
13796 (if org-tags-sort-function
13797 (setq tags (mapconcat 'identity
13798 (sort (org-split-string
13799 tags (org-re "[^[:alnum:]_@#%]+"))
13800 org-tags-sort-function) ":")))
13802 (if (string-match "\\`[\t ]*\\'" tags)
13804 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
13805 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
13807 ;; Insert new tags at the correct column
13808 (beginning-of-line 1)
13809 (setq level (or (and (looking-at org-outline-regexp)
13810 (- (match-end 0) (point) 1))
13813 ((and (equal current "") (equal tags "")))
13814 ((re-search-forward
13815 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
13817 (if (equal tags "")
13819 (goto-char (match-beginning 0))
13820 (setq c0 (current-column)
13821 ;; compute offset for the case of org-indent-mode active
13822 di (if org-indent-mode
13823 (* (1- org-indent-indentation-per-level) (1- level))
13825 p0 (if (equal (char-before) ?*) (1+ (point)) (point))
13826 tc (+ org-tags-column (if (> org-tags-column 0) (- di) di))
13827 c1 (max (1+ c0) (if (> tc 0) tc (- (- tc) (length tags))))
13828 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
13829 (replace-match rpl t t)
13830 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
13832 (t (error "Tags alignment failed")))
13833 (org-move-to-column col)
13835 (run-hooks 'org-after-tags-change-hook))))))
13837 (defun org-change-tag-in-region (beg end tag off)
13838 "Add or remove TAG for each entry in the region.
13839 This works in the agenda, and also in an org-mode buffer."
13841 (list (region-beginning) (region-end)
13842 (let ((org-last-tags-completion-table
13843 (if (derived-mode-p 'org-mode)
13844 (org-get-buffer-tags)
13845 (org-global-tags-completion-table))))
13846 (org-icompleting-read
13847 "Tag: " 'org-tags-completion-function nil nil nil
13848 'org-tags-history))
13850 (message "[s]et or
[r]emove? ")
13851 (equal (read-char-exclusive) ?r))))
13852 (if (fboundp 'deactivate-mark) (deactivate-mark))
13853 (let ((agendap (equal major-mode 'org-agenda-mode))
13854 l1 l2 m buf pos newhead (cnt 0))
13856 (setq l2 (1- (org-current-line)))
13858 (setq l1 (org-current-line))
13859 (loop for l from l1 to l2 do
13861 (setq m (get-text-property (point) 'org-hd-marker))
13862 (when (or (and (derived-mode-p 'org-mode) (org-at-heading-p))
13864 (setq buf (if agendap (marker-buffer m) (current-buffer))
13865 pos (if agendap m (point)))
13866 (with-current-buffer buf
13870 (setq cnt (1+ cnt))
13871 (org-toggle-tag tag (if off 'off 'on))
13872 (setq newhead (org-get-heading)))))
13873 (and agendap (org-agenda-change-all-lines newhead m))))
13874 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
13876 (defun org-tags-completion-function (string predicate &optional flag)
13877 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
13878 (confirm (lambda (x) (stringp (car x)))))
13879 (if (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
13880 (setq s1 (match-string 1 string)
13881 s2 (match-string 2 string))
13882 (setq s1 "" s2 string))
13886 (setq rtn (try-completion s2 ctable confirm))
13889 (concat s1 s2 (substring rtn (length s2))
13890 (if (and org-add-colon-after-tag-completion
13891 (assoc rtn ctable))
13896 (all-completions s2 ctable confirm)
13900 (assoc s2 ctable)))
13903 (defun org-fast-tag-insert (kwd tags face &optional end)
13904 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
13905 (insert (format "%-12s" (concat kwd ":"))
13906 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
13909 (defun org-fast-tag-show-exit (flag)
13912 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
13913 (replace-match ""))
13916 (org-move-to-column (- (window-width) 19) t)
13917 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
13919 (defun org-set-current-tags-overlay (current prefix)
13920 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
13921 (if (featurep 'xemacs)
13922 (org-overlay-display org-tags-overlay (concat prefix s)
13923 'secondary-selection)
13924 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
13925 (org-overlay-display org-tags-overlay (concat prefix s)))))
13927 (defvar org-last-tag-selection-key nil)
13928 (defun org-fast-tag-selection (current inherited table &optional todo-table)
13929 "Fast tag selection with single keys.
13930 CURRENT is the current list of tags in the headline, INHERITED is the
13931 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
13932 possibly with grouping information. TODO-TABLE is a similar table with
13933 TODO keywords, should these have keys assigned to them.
13934 If the keys are nil, a-z are automatically assigned.
13935 Returns the new tags string, or nil to not change the current settings."
13936 (let* ((fulltable (append table todo-table))
13937 (maxlen (apply 'max (mapcar
13939 (if (stringp (car x)) (string-width (car x)) 0))
13941 (buf (current-buffer))
13942 (expert (eq org-fast-tag-selection-single-key 'expert))
13944 (fwidth (+ maxlen 3 1 3))
13945 (ncol (/ (- (window-width) 4) fwidth))
13948 tg cnt e c char c1 c2 ntable tbl rtn
13949 ov-start ov-end ov-prefix
13950 (exit-after-next org-fast-tag-selection-single-key)
13951 (done-keywords org-done-keywords)
13954 (beginning-of-line 1)
13956 (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13957 (setq ov-start (match-beginning 1)
13958 ov-end (match-end 1)
13960 (setq ov-start (1- (point-at-eol))
13961 ov-end (1+ ov-start))
13962 (skip-chars-forward "^\n\r")
13965 (buffer-substring (1- (point)) (point))
13966 (if (> (current-column) org-tags-column)
13968 (make-string (- org-tags-column (current-column)) ?\ ))))))
13969 (move-overlay org-tags-overlay ov-start ov-end)
13970 (save-window-excursion
13972 (set-buffer (get-buffer-create " *Org tags*"))
13973 (delete-other-windows)
13974 (split-window-vertically)
13975 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
13977 (org-set-local 'org-done-keywords done-keywords)
13978 (org-fast-tag-insert "Inherited" inherited i-face "\n")
13979 (org-fast-tag-insert "Current" current c-face "\n\n")
13980 (org-fast-tag-show-exit exit-after-next)
13981 (org-set-current-tags-overlay current ov-prefix)
13982 (setq tbl fulltable char ?a cnt 0)
13983 (while (setq e (pop tbl))
13985 ((equal (car e) :startgroup)
13986 (push '() groups) (setq ingroup t)
13987 (when (not (= cnt 0))
13990 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
13991 ((equal (car e) :endgroup)
13992 (setq ingroup nil cnt 0)
13993 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
13994 ((equal e '(:newline))
13995 (when (not (= cnt 0))
13999 (while (equal (car tbl) '(:newline))
14001 (setq tbl (cdr tbl)))))
14003 (setq tg (copy-sequence (car e)) c2 nil)
14006 ;; automatically assign a character.
14007 (setq c1 (string-to-char
14008 (downcase (substring
14009 tg (if (= (string-to-char tg) ?@) 1 0)))))
14010 (if (or (rassoc c1 ntable) (rassoc c1 table))
14011 (while (or (rassoc char ntable) (rassoc char table))
14012 (setq char (1+ char)))
14014 (setq c (or c2 char)))
14015 (if ingroup (push tg (car groups)))
14016 (setq tg (org-add-props tg nil 'face
14018 ((not (assoc tg table))
14019 (org-get-todo-face tg))
14020 ((member tg current) c-face)
14021 ((member tg inherited) i-face))))
14022 (if (and (= cnt 0) (not ingroup)) (insert " "))
14023 (insert "[" c "] " tg (make-string
14024 (- fwidth 4 (length tg)) ?\ ))
14025 (push (cons tg c) ntable)
14026 (when (= (setq cnt (1+ cnt)) ncol)
14028 (if ingroup (insert " "))
14030 (setq ntable (nreverse ntable))
14032 (goto-char (point-min))
14033 (if (not expert) (org-fit-window-to-buffer))
14037 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
14038 (if (not groups) "no " "")
14039 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
14040 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
14041 (setq org-last-tag-selection-key c)
14043 ((= c ?\r) (throw 'exit t))
14045 (setq groups (not groups))
14046 (goto-char (point-min))
14047 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
14050 (org-fast-tag-show-exit
14051 (setq exit-after-next (not exit-after-next)))
14053 (delete-other-windows)
14054 (set-window-buffer (split-window-vertically) " *Org tags*")
14055 (org-switch-to-buffer-other-window " *Org tags*")
14056 (org-fit-window-to-buffer)))
14058 (and (= c ?q) (not (rassoc c ntable))))
14059 (org-detach-overlay org-tags-overlay)
14060 (setq quit-flag t))
14063 (if exit-after-next (setq exit-after-next 'now)))
14065 (condition-case nil
14066 (setq tg (org-icompleting-read
14069 (with-current-buffer buf
14070 (org-get-buffer-tags)))))
14071 (quit (setq tg "")))
14072 (when (string-match "\\S-" tg)
14073 (add-to-list 'buffer-tags (list tg))
14074 (if (member tg current)
14075 (setq current (delete tg current))
14076 (push tg current)))
14077 (if exit-after-next (setq exit-after-next 'now)))
14078 ((setq e (rassoc c todo-table) tg (car e))
14079 (with-current-buffer buf
14080 (save-excursion (org-todo tg)))
14081 (if exit-after-next (setq exit-after-next 'now)))
14082 ((setq e (rassoc c ntable) tg (car e))
14083 (if (member tg current)
14084 (setq current (delete tg current))
14085 (loop for g in groups do
14088 (setq current (delete x current)))
14091 (if exit-after-next (setq exit-after-next 'now))))
14093 ;; Create a sorted list
14097 (assoc b (cdr (memq (assoc a ntable) ntable))))))
14098 (if (eq exit-after-next 'now) (throw 'exit t))
14099 (goto-char (point-min))
14100 (beginning-of-line 2)
14101 (delete-region (point) (point-at-eol))
14102 (org-fast-tag-insert "Current" current c-face)
14103 (org-set-current-tags-overlay current ov-prefix)
14104 (while (re-search-forward
14105 (org-re "\\[.\\] \\([[:alnum:]_@#%]+\\)") nil t)
14106 (setq tg (match-string 1))
14107 (add-text-properties
14108 (match-beginning 1) (match-end 1)
14111 ((member tg current) c-face)
14112 ((member tg inherited) i-face)
14113 (t (get-text-property (match-beginning 1) 'face))))))
14114 (goto-char (point-min)))))
14115 (org-detach-overlay org-tags-overlay)
14117 (mapconcat 'identity current ":")
14120 (defun org-get-tags-string ()
14121 "Get the TAGS string in the current headline."
14122 (unless (org-at-heading-p t)
14123 (error "Not on a heading"))
14125 (beginning-of-line 1)
14126 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
14127 (org-match-string-no-properties 1)
14130 (defun org-get-tags ()
14131 "Get the list of tags specified in the current headline."
14132 (org-split-string (org-get-tags-string) ":"))
14134 (defun org-get-buffer-tags ()
14135 "Get a table of all tags used in the buffer, for completion."
14138 (goto-char (point-min))
14139 (while (re-search-forward
14140 (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t\r\n]") nil t)
14141 (when (equal (char-after (point-at-bol 0)) ?*)
14142 (mapc (lambda (x) (add-to-list 'tags x))
14143 (org-split-string (org-match-string-no-properties 1) ":")))))
14144 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
14145 (mapcar 'list tags)))
14147 ;;;; The mapping API
14150 (defun org-map-entries (func &optional match scope &rest skip)
14151 "Call FUNC at each headline selected by MATCH in SCOPE.
14153 FUNC is a function or a lisp form. The function will be called without
14154 arguments, with the cursor positioned at the beginning of the headline.
14155 The return values of all calls to the function will be collected and
14156 returned as a list.
14158 The call to FUNC will be wrapped into a save-excursion form, so FUNC
14159 does not need to preserve point. After evaluation, the cursor will be
14160 moved to the end of the line (presumably of the headline of the
14161 processed entry) and search continues from there. Under some
14162 circumstances, this may not produce the wanted results. For example,
14163 if you have removed (e.g. archived) the current (sub)tree it could
14164 mean that the next entry will be skipped entirely. In such cases, you
14165 can specify the position from where search should continue by making
14166 FUNC set the variable `org-map-continue-from' to the desired buffer
14169 MATCH is a tags/property/todo match as it is used in the agenda tags view.
14170 Only headlines that are matched by this query will be considered during
14171 the iteration. When MATCH is nil or t, all headlines will be
14172 visited by the iteration.
14174 SCOPE determines the scope of this command. It can be any of:
14176 nil The current buffer, respecting the restriction if any
14177 tree The subtree started with the entry at point
14178 region The entries within the active region, if any
14180 The entries within the active region, but only those at
14181 the same level than the first one.
14182 file The current buffer, without restriction
14184 The current buffer, and any archives associated with it
14185 agenda All agenda files
14186 agenda-with-archives
14187 All agenda files with any archive files associated with them
14189 If this is a list, all files in the list will be scanned
14191 The remaining args are treated as settings for the skipping facilities of
14192 the scanner. The following items can be given here:
14194 archive skip trees with the archive tag.
14195 comment skip trees with the COMMENT keyword
14196 function or Emacs Lisp form:
14197 will be used as value for `org-agenda-skip-function', so whenever
14198 the function returns t, FUNC will not be called for that
14199 entry and search will continue from the point where the
14200 function leaves it.
14202 If your function needs to retrieve the tags including inherited tags
14203 at the *current* entry, you can use the value of the variable
14204 `org-scanner-tags' which will be much faster than getting the value
14205 with `org-get-tags-at'. If your function gets properties with
14206 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
14207 to t around the call to `org-entry-properties' to get the same speedup.
14208 Note that if your function moves around to retrieve tags and properties at
14209 a *different* entry, you cannot use these techniques."
14210 (unless (and (or (eq scope 'region) (eq scope 'region-start-level))
14211 (not (org-region-active-p)))
14212 (let* ((org-agenda-archives-mode nil) ; just to make sure
14213 (org-agenda-skip-archived-trees (memq 'archive skip))
14214 (org-agenda-skip-comment-trees (memq 'comment skip))
14215 (org-agenda-skip-function
14216 (car (org-delete-all '(comment archive) skip)))
14217 (org-tags-match-list-sublevels t)
14218 (start-level (eq scope 'region-start-level))
14220 org-todo-keywords-for-agenda
14221 org-done-keywords-for-agenda
14222 org-todo-keyword-alist-for-agenda
14223 org-drawers-for-agenda
14224 org-tag-alist-for-agenda
14228 ((eq match t) (setq matcher t))
14229 ((eq match nil) (setq matcher t))
14230 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
14234 (cond ((eq scope 'tree)
14235 (org-back-to-heading t)
14236 (org-narrow-to-subtree)
14238 ((and (or (eq scope 'region) (eq scope 'region-start-level))
14239 (org-region-active-p))
14240 ;; If needed, set start-level to a string like "2"
14243 (goto-char (region-beginning))
14244 (unless (org-at-heading-p) (outline-next-heading))
14245 (setq start-level (org-current-level))))
14246 (narrow-to-region (region-beginning)
14248 (goto-char (region-end))
14249 (unless (and (bolp) (org-at-heading-p))
14250 (outline-next-heading))
14256 (org-agenda-prepare-buffers
14257 (list (buffer-file-name (current-buffer))))
14258 (setq res (org-scan-tags func matcher todo-only start-level)))
14259 ;; Get the right scope
14261 ((and scope (listp scope) (symbolp (car scope)))
14262 (setq scope (eval scope)))
14263 ((eq scope 'agenda)
14264 (setq scope (org-agenda-files t)))
14265 ((eq scope 'agenda-with-archives)
14266 (setq scope (org-agenda-files t))
14267 (setq scope (org-add-archive-files scope)))
14269 (setq scope (list (buffer-file-name))))
14270 ((eq scope 'file-with-archives)
14271 (setq scope (org-add-archive-files (list (buffer-file-name))))))
14272 (org-agenda-prepare-buffers scope)
14273 (while (setq file (pop scope))
14274 (with-current-buffer (org-find-base-buffer-visiting file)
14278 (goto-char (point-min))
14279 (setq res (append res (org-scan-tags func matcher todo-only))))))))))
14284 ;;; Setting and retrieving properties
14286 (defconst org-special-properties
14287 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
14288 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED" "FILE" "CLOCKSUM" "CLOCKSUM_T")
14289 "The special properties valid in Org-mode.
14291 These are properties that are not defined in the property drawer,
14292 but in some other way.")
14294 (defconst org-default-properties
14295 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
14296 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
14297 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
14298 "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME"
14299 "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
14300 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
14301 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
14302 "Some properties that are used by Org-mode for various purposes.
14303 Being in this list makes sure that they are offered for completion.")
14305 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
14306 "Regular expression matching the first line of a property drawer.")
14308 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
14309 "Regular expression matching the last line of a property drawer.")
14311 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
14312 "Regular expression matching the first line of a property drawer.")
14314 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
14315 "Regular expression matching the first line of a property drawer.")
14317 (defconst org-property-drawer-re
14318 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
14319 org-property-end-re "\\)\n?")
14320 "Matches an entire property drawer.")
14322 (defconst org-clock-drawer-re
14323 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
14324 org-property-end-re "\\)\n?")
14325 "Matches an entire clock drawer.")
14327 (defsubst org-re-property (property)
14328 "Return a regexp matching a PROPERTY line.
14329 Match group 1 will be set to the value."
14330 (concat "^[ \t]*:" (regexp-quote property) ":[ \t]*\\(\\S-.*\\)"))
14332 (defsubst org-re-property-keyword (property)
14333 "Return a regexp matching a PROPERTY line, possibly with no
14334 value for the property."
14335 (concat "^[ \t]*:" (regexp-quote property) ":[ \t]*\\(\\S-.*\\)?"))
14337 (defun org-property-action ()
14338 "Do an action on properties."
14341 (org-at-property-p)
14342 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
14343 (setq c (read-char-exclusive))
14346 (call-interactively 'org-set-property))
14348 (call-interactively 'org-delete-property))
14350 (call-interactively 'org-delete-property-globally))
14352 (call-interactively 'org-compute-property-at-point))
14353 (t (error "No such property action %c" c)))))
14355 (defun org-inc-effort ()
14356 "Increment the value of the effort property in the current entry."
14358 (org-set-effort nil t))
14360 (defun org-set-effort (&optional value increment)
14361 "Set the effort property of the current entry.
14362 With numerical prefix arg, use the nth allowed value, 0 stands for the
14363 10th allowed value.
14365 When INCREMENT is non-nil, set the property to the next allowed value."
14367 (if (equal value 0) (setq value 10))
14368 (let* ((completion-ignore-case t)
14369 (prop org-effort-property)
14370 (cur (org-entry-get nil prop))
14371 (allowed (org-property-get-allowed-values nil prop 'table))
14372 (existing (mapcar 'list (org-property-values prop)))
14375 ((stringp value) value)
14376 ((and allowed (integerp value))
14377 (or (car (nth (1- value) allowed))
14378 (car (org-last allowed))))
14379 ((and allowed increment)
14380 (or (caadr (member (list cur) allowed))
14381 (error "Allowed effort values are not set")))
14383 (message "Select 1-9,0, [RET%s]: %s"
14384 (if cur (concat "=" cur) "")
14385 (mapconcat 'car allowed " "))
14386 (setq rpl (read-char-exclusive))
14387 (if (equal rpl ?\r)
14389 (setq rpl (- rpl ?0))
14390 (if (equal rpl 0) (setq rpl 10))
14391 (if (and (> rpl 0) (<= rpl (length allowed)))
14392 (car (nth (1- rpl) allowed))
14393 (org-completing-read "Effort: " allowed nil))))
14395 (let (org-completion-use-ido org-completion-use-iswitchb)
14396 (org-completing-read
14397 (concat "Effort " (if (and cur (string-match "\\S-" cur))
14398 (concat "[" cur "]") "")
14400 existing nil nil "" nil cur))))))
14401 (unless (equal (org-entry-get nil prop) val)
14402 (org-entry-put nil prop val))
14403 (message "%s is now %s" prop val)))
14405 (defun org-at-property-p ()
14406 "Is cursor inside a property drawer?"
14408 (beginning-of-line 1)
14409 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
14410 (save-match-data ;; Used by calling procedures
14412 (range (unless (org-before-first-heading-p)
14413 (org-get-property-block))))
14414 (and range (<= (car range) p) (< p (cdr range))))))))
14416 (defun org-get-property-block (&optional beg end force)
14417 "Return the (beg . end) range of the body of the property drawer.
14418 BEG and END are the beginning and end of the current subtree, or of
14419 the part before the first headline. If they are not given, they will
14420 be found. If the drawer does not exist and FORCE is non-nil, create
14424 (let* ((beg (or beg (and (org-before-first-heading-p) (point-min))
14425 (progn (org-back-to-heading t) (point))))
14426 (end (or end (and (not (outline-next-heading)) (point-max))
14429 (if (re-search-forward org-property-start-re end t)
14430 (setq beg (1+ (match-end 0)))
14433 (org-insert-property-drawer)
14434 (setq end (progn (outline-next-heading) (point))))
14437 (if (re-search-forward org-property-start-re end t)
14438 (setq beg (1+ (match-end 0)))))
14439 (if (re-search-forward org-property-end-re end t)
14440 (setq end (match-beginning 0))
14441 (or force (throw 'exit nil))
14445 (insert ":END:\n"))
14448 (defun org-entry-properties (&optional pom which specific)
14449 "Get all properties of the entry at point-or-marker POM.
14450 This includes the TODO keyword, the tags, time strings for deadline,
14451 scheduled, and clocking, and any additional properties defined in the
14452 entry. The return value is an alist, keys may occur multiple times
14453 if the property key was used several times.
14454 POM may also be nil, in which case the current entry is used.
14455 If WHICH is nil or `all', get all properties. If WHICH is
14456 `special' or `standard', only get that subclass. If WHICH
14457 is a string only get exactly this property. SPECIFIC can be a string, the
14458 specific property we are interested in. Specifying it can speed
14459 things up because then unnecessary parsing is avoided."
14460 (setq which (or which 'all))
14461 (org-with-point-at pom
14462 (let ((clockstr (substring org-clock-string 0 -1))
14463 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
14464 (case-fold-search nil)
14465 beg end range props sum-props key key1 value string clocksum clocksumt)
14467 (when (condition-case nil
14468 (and (derived-mode-p 'org-mode) (org-back-to-heading t))
14471 (setq sum-props (get-text-property (point) 'org-summaries))
14472 (setq clocksum (get-text-property (point) :org-clock-minutes)
14473 clocksumt (get-text-property (point) :org-clock-minutes-today))
14474 (outline-next-heading)
14476 (when (memq which '(all special))
14477 ;; Get the special properties, like TODO and tags
14479 (when (and (or (not specific) (string= specific "TODO"))
14480 (looking-at org-todo-line-regexp) (match-end 2))
14481 (push (cons "TODO" (org-match-string-no-properties 2)) props))
14482 (when (and (or (not specific) (string= specific "PRIORITY"))
14483 (looking-at org-priority-regexp))
14484 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
14485 (when (or (not specific) (string= specific "FILE"))
14486 (push (cons "FILE" buffer-file-name) props))
14487 (when (and (or (not specific) (string= specific "TAGS"))
14488 (setq value (org-get-tags-string))
14489 (string-match "\\S-" value))
14490 (push (cons "TAGS" value) props))
14491 (when (and (or (not specific) (string= specific "ALLTAGS"))
14492 (setq value (org-get-tags-at)))
14493 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
14496 (when (or (not specific) (string= specific "BLOCKED"))
14497 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
14498 (when (or (not specific)
14500 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
14501 "TIMESTAMP" "TIMESTAMP_IA")))
14503 (while (re-search-forward org-maybe-keyword-time-regexp end t)
14504 (setq key (if (match-end 1)
14505 (substring (org-match-string-no-properties 1)
14507 string (if (equal key clockstr)
14509 (buffer-substring-no-properties
14510 (match-beginning 3) (goto-char
14512 (substring (org-match-string-no-properties 3)
14514 ;; Get the correct property name from the key. This is
14515 ;; necessary if the user has configured time keywords.
14516 (setq key1 (concat key ":"))
14520 (if (= (char-after (match-beginning 3)) ?\[)
14521 "TIMESTAMP_IA" "TIMESTAMP")))
14522 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
14523 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
14524 ((equal key1 org-closed-string) (setq key "CLOSED"))
14525 ((equal key1 org-clock-string) (setq key "CLOCK")))
14526 (if (and specific (equal key specific) (not (equal key "CLOCK")))
14528 (push (cons key string) props)
14529 ;; no need to search further if match is found
14531 (when (or (equal key "CLOCK") (not (assoc key props)))
14532 (push (cons key string) props)))))))
14534 (when (memq which '(all standard))
14535 ;; Get the standard properties, like :PROP: ...
14536 (setq range (org-get-property-block beg end))
14538 (goto-char (car range))
14539 (while (re-search-forward
14540 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
14542 (setq key (org-match-string-no-properties 1)
14543 value (org-trim (or (org-match-string-no-properties 2) "")))
14544 (unless (member key excluded)
14545 (push (cons key (or value "")) props)))))
14547 (push (cons "CLOCKSUM"
14548 (org-columns-number-to-string (/ (float clocksum) 60.)
14552 (push (cons "CLOCKSUM_T"
14553 (org-columns-number-to-string (/ (float clocksumt) 60.)
14556 (unless (assoc "CATEGORY" props)
14557 (push (cons "CATEGORY" (org-get-category)) props))
14558 (append sum-props (nreverse props)))))))
14560 (defun org-entry-get (pom property &optional inherit literal-nil)
14561 "Get value of PROPERTY for entry or content at point-or-marker POM.
14562 If INHERIT is non-nil and the entry does not have the property,
14563 then also check higher levels of the hierarchy.
14564 If INHERIT is the symbol `selective', use inheritance only if the setting
14565 in `org-use-property-inheritance' selects PROPERTY for inheritance.
14566 If the property is present but empty, the return value is the empty string.
14567 If the property is not present at all, nil is returned.
14569 If LITERAL-NIL is set, return the string value \"nil\" as a string,
14570 do not interpret it as the list atom nil. This is used for inheritance
14571 when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
14572 (org-with-point-at pom
14573 (if (and inherit (if (eq inherit 'selective)
14574 (org-property-inherit-p property)
14576 (org-entry-get-with-inheritance property literal-nil)
14577 (if (member property org-special-properties)
14578 ;; We need a special property. Use `org-entry-properties' to
14579 ;; retrieve it, but specify the wanted property
14580 (cdr (assoc property (org-entry-properties nil 'special property)))
14581 (let* ((range (org-get-property-block))
14582 (props (list (or (assoc property org-file-properties)
14583 (assoc property org-global-properties)
14584 (assoc property org-global-properties-fixed))))
14586 (when (re-search-forward
14587 (org-re-property key) (cdr range) t)
14589 (org-update-property-plist
14592 (org-match-string-no-properties 1) "")
14595 (when (and range (goto-char (car range)))
14596 (funcall ap property)
14597 (goto-char (car range))
14598 (while (funcall ap (concat property "+")))
14599 (setq val (cdr (assoc property props)))
14600 (when val (if literal-nil val (org-not-nil val)))))))))
14602 (defun org-property-or-variable-value (var &optional inherit)
14603 "Check if there is a property fixing the value of VAR.
14604 If yes, return this value. If not, return the current value of the variable."
14605 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
14606 (if (and prop (stringp prop) (string-match "\\S-" prop))
14608 (symbol-value var))))
14610 (defun org-entry-delete (pom property)
14611 "Delete the property PROPERTY from entry at point-or-marker POM."
14612 (org-with-point-at pom
14613 (if (member property org-special-properties)
14614 nil ; cannot delete these properties.
14615 (let ((range (org-get-property-block)))
14617 (goto-char (car range))
14619 (org-re-property property)
14622 (delete-region (match-beginning 0) (1+ (point-at-eol)))
14626 ;; Multi-values properties are properties that contain multiple values
14627 ;; These values are assumed to be single words, separated by whitespace.
14628 (defun org-entry-add-to-multivalued-property (pom property value)
14629 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
14630 (let* ((old (org-entry-get pom property))
14631 (values (and old (org-split-string old "[ \t]"))))
14632 (setq value (org-entry-protect-space value))
14633 (unless (member value values)
14634 (setq values (cons value values))
14635 (org-entry-put pom property
14636 (mapconcat 'identity values " ")))))
14638 (defun org-entry-remove-from-multivalued-property (pom property value)
14639 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
14640 (let* ((old (org-entry-get pom property))
14641 (values (and old (org-split-string old "[ \t]"))))
14642 (setq value (org-entry-protect-space value))
14643 (when (member value values)
14644 (setq values (delete value values))
14645 (org-entry-put pom property
14646 (mapconcat 'identity values " ")))))
14648 (defun org-entry-member-in-multivalued-property (pom property value)
14649 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
14650 (let* ((old (org-entry-get pom property))
14651 (values (and old (org-split-string old "[ \t]"))))
14652 (setq value (org-entry-protect-space value))
14653 (member value values)))
14655 (defun org-entry-get-multivalued-property (pom property)
14656 "Return a list of values in a multivalued property."
14657 (let* ((value (org-entry-get pom property))
14658 (values (and value (org-split-string value "[ \t]"))))
14659 (mapcar 'org-entry-restore-space values)))
14661 (defun org-entry-put-multivalued-property (pom property &rest values)
14662 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
14663 VALUES should be a list of strings. Spaces will be protected."
14664 (org-entry-put pom property
14665 (mapconcat 'org-entry-protect-space values " "))
14666 (let* ((value (org-entry-get pom property))
14667 (values (and value (org-split-string value "[ \t]"))))
14668 (mapcar 'org-entry-restore-space values)))
14670 (defun org-entry-protect-space (s)
14671 "Protect spaces and newline in string S."
14672 (while (string-match " " s)
14673 (setq s (replace-match "%20" t t s)))
14674 (while (string-match "\n" s)
14675 (setq s (replace-match "%0A" t t s)))
14678 (defun org-entry-restore-space (s)
14679 "Restore spaces and newline in string S."
14680 (while (string-match "%20" s)
14681 (setq s (replace-match " " t t s)))
14682 (while (string-match "%0A" s)
14683 (setq s (replace-match "\n" t t s)))
14686 (defvar org-entry-property-inherited-from (make-marker)
14687 "Marker pointing to the entry from where a property was inherited.
14688 Each call to `org-entry-get-with-inheritance' will set this marker to the
14689 location of the entry where the inheritance search matched. If there was
14690 no match, the marker will point nowhere.
14691 Note that also `org-entry-get' calls this function, if the INHERIT flag
14694 (defun org-entry-get-with-inheritance (property &optional literal-nil)
14695 "Get PROPERTY of entry or content at point, search higher levels if needed.
14696 The search will stop at the first ancestor which has the property defined.
14697 If the value found is \"nil\", return nil to show that the property
14698 should be considered as undefined (this is the meaning of nil here).
14699 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
14700 (move-marker org-entry-property-inherited-from nil)
14707 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
14708 (or (ignore-errors (org-back-to-heading t))
14709 (goto-char (point-min)))
14710 (move-marker org-entry-property-inherited-from (point))
14712 (or (ignore-errors (org-up-heading-safe))
14713 (throw 'ex nil))))))
14715 (cdr (assoc property org-file-properties))
14716 (cdr (assoc property org-global-properties))
14717 (cdr (assoc property org-global-properties-fixed))))
14718 (if literal-nil tmp (org-not-nil tmp))))
14720 (defvar org-property-changed-functions nil
14721 "Hook called when the value of a property has changed.
14722 Each hook function should accept two arguments, the name of the property
14723 and the new value.")
14725 (defun org-entry-put (pom property value)
14726 "Set PROPERTY to VALUE for entry at point-or-marker POM."
14727 (org-with-point-at pom
14728 (org-back-to-heading t)
14729 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
14732 ((equal property "TODO")
14733 (when (and (stringp value) (string-match "\\S-" value)
14734 (not (member value org-todo-keywords-1)))
14735 (error "\"%s\" is not a valid TODO state" value))
14736 (if (or (not value)
14737 (not (string-match "\\S-" value)))
14738 (setq value 'none))
14740 (org-set-tags nil 'align))
14741 ((equal property "PRIORITY")
14742 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
14743 (string-to-char value) ?\ ))
14744 (org-set-tags nil 'align))
14745 ((equal property "SCHEDULED")
14746 (if (re-search-forward org-scheduled-time-regexp end t)
14748 ((eq value 'earlier) (org-timestamp-change -1 'day))
14749 ((eq value 'later) (org-timestamp-change 1 'day))
14750 (t (call-interactively 'org-schedule)))
14751 (call-interactively 'org-schedule)))
14752 ((equal property "DEADLINE")
14753 (if (re-search-forward org-deadline-time-regexp end t)
14755 ((eq value 'earlier) (org-timestamp-change -1 'day))
14756 ((eq value 'later) (org-timestamp-change 1 'day))
14757 (t (call-interactively 'org-deadline)))
14758 (call-interactively 'org-deadline)))
14759 ((member property org-special-properties)
14760 (error "The %s property can not yet be set with `org-entry-put'"
14762 (t ; a non-special property
14763 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
14764 (setq range (org-get-property-block beg end 'force))
14765 (goto-char (car range))
14766 (if (re-search-forward
14767 (org-re-property-keyword property) (cdr range) t)
14769 (delete-region (match-beginning 0) (match-end 0))
14770 (goto-char (match-beginning 0)))
14771 (goto-char (cdr range))
14775 (insert ":" property ":")
14776 (and value (insert " " value))
14777 (org-indent-line)))))
14778 (run-hook-with-args 'org-property-changed-functions property value)))
14780 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
14781 "Get all property keys in the current buffer.
14782 With INCLUDE-SPECIALS, also list the special properties that reflect things
14783 like tags and TODO state.
14784 With INCLUDE-DEFAULTS, also include properties that has special meaning
14785 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING
14787 With INCLUDE-COLUMNS, also include property names given in COLUMN
14788 formats in the current buffer."
14789 (let (rtn range cfmt s p)
14793 (goto-char (point-min))
14794 (while (re-search-forward org-property-start-re nil t)
14795 (setq range (org-get-property-block))
14796 (goto-char (car range))
14797 (while (re-search-forward
14798 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
14800 (add-to-list 'rtn (org-match-string-no-properties 1)))
14801 (outline-next-heading))))
14803 (when include-specials
14804 (setq rtn (append org-special-properties rtn)))
14806 (when include-defaults
14807 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
14808 (add-to-list 'rtn org-effort-property))
14810 (when include-columns
14814 (goto-char (point-min))
14815 (while (re-search-forward
14816 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
14818 (setq cfmt (match-string 2) s 0)
14819 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
14821 (setq s (match-end 0)
14822 p (match-string 1 cfmt))
14823 (unless (or (equal p "ITEM")
14824 (member p org-special-properties))
14825 (add-to-list 'rtn (match-string 1 cfmt))))))))
14827 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
14829 (defun org-property-values (key)
14830 "Return a list of all values of property KEY in the current buffer."
14834 (goto-char (point-min))
14835 (let ((re (org-re-property key))
14837 (while (re-search-forward re nil t)
14838 (add-to-list 'values (org-trim (match-string 1))))
14839 (delete "" values)))))
14841 (defun org-insert-property-drawer ()
14842 "Insert a property drawer into the current entry."
14843 (org-back-to-heading t)
14844 (looking-at org-outline-regexp)
14845 (let ((indent (if org-adapt-indentation
14846 (- (match-end 0) (match-beginning 0))
14849 (re (concat "^[ \t]*" org-keyword-time-regexp))
14851 (outline-next-heading)
14854 (while (re-search-forward re end t))
14855 (setq hiddenp (outline-invisible-p))
14857 (and (equal (char-after) ?\n) (forward-char 1))
14858 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
14859 (if (member (match-string 1) '("CLOCK:" ":END:"))
14860 ;; just skip this line
14861 (beginning-of-line 2)
14862 ;; Drawer start, find the end
14863 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
14864 (beginning-of-line 1)))
14865 (org-skip-over-state-notes)
14866 (skip-chars-backward " \t\n\r")
14867 (if (eq (char-before) ?*) (forward-char 1))
14868 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
14869 (beginning-of-line 0)
14870 (org-indent-to-column indent)
14871 (beginning-of-line 2)
14872 (org-indent-to-column indent)
14873 (beginning-of-line 0)
14876 (org-back-to-heading t)
14878 (org-flag-drawer t))))
14880 (defun org-insert-drawer (&optional arg drawer)
14881 "Insert a drawer at point.
14883 Optional argument DRAWER, when non-nil, is a string representing
14884 drawer's name. Otherwise, the user is prompted for a name.
14886 If a region is active, insert the drawer around that region
14889 Point is left between drawer's boundaries."
14891 (let* ((logbook (if (stringp org-log-into-drawer) org-log-into-drawer
14893 ;; SYSTEM-DRAWERS is a list of drawer names that are used
14894 ;; internally by Org. They are meant to be inserted
14896 (system-drawers `("CLOCK" ,logbook "PROPERTIES"))
14897 ;; Remove system drawers from list. Note: For some reason,
14898 ;; `org-completing-read' ignores the predicate while
14899 ;; `completing-read' handles it fine.
14900 (drawer (if arg "PROPERTIES"
14903 "Drawer: " org-drawers
14904 (lambda (d) (not (member d system-drawers))))))))
14906 ;; With C-u, fall back on `org-insert-property-drawer'
14907 (arg (org-insert-property-drawer))
14908 ;; With an active region, insert a drawer at point.
14909 ((not (org-region-active-p))
14911 (unless (bolp) (insert "\n"))
14912 (insert (format ":%s:\n\n:END:\n" drawer))
14913 (forward-line -2)))
14914 ;; Otherwise, insert the drawer at point
14916 (let ((rbeg (region-beginning))
14917 (rend (copy-marker (region-end))))
14921 (beginning-of-line)
14922 (when (save-excursion
14923 (re-search-forward org-outline-regexp-bol rend t))
14924 (error "Drawers cannot contain headlines"))
14925 ;; Position point at the beginning of the first
14926 ;; non-blank line in region. Insert drawer's opening
14927 ;; there, then indent it.
14928 (org-skip-whitespace)
14929 (beginning-of-line)
14930 (insert ":" drawer ":\n")
14932 (indent-for-tab-command)
14933 ;; Move point to the beginning of the first blank line
14934 ;; after the last non-blank line in region. Insert
14935 ;; drawer's closing, then indent it.
14937 (skip-chars-backward " \r\t\n")
14939 (indent-for-tab-command)
14940 (unless (eolp) (insert "\n")))
14941 ;; Clear marker, whatever the outcome of insertion is.
14942 (set-marker rend nil)))))))
14944 (defvar org-property-set-functions-alist nil
14945 "Property set function alist.
14946 Each entry should have the following format:
14948 (PROPERTY . READ-FUNCTION)
14950 The read function will be called with the same argument as
14951 `org-completing-read'.")
14953 (defun org-set-property-function (property)
14954 "Get the function that should be used to set PROPERTY.
14955 This is computed according to `org-property-set-functions-alist'."
14956 (or (cdr (assoc property org-property-set-functions-alist))
14957 'org-completing-read))
14959 (defun org-read-property-value (property)
14960 "Read PROPERTY value from user."
14961 (let* ((completion-ignore-case t)
14962 (allowed (org-property-get-allowed-values nil property 'table))
14963 (cur (org-entry-get nil property))
14964 (prompt (concat property " value"
14965 (if (and cur (string-match "\\S-" cur))
14966 (concat " [" cur "]") "") ": "))
14967 (set-function (org-set-property-function property))
14969 (funcall set-function prompt allowed nil
14970 (not (get-text-property 0 'org-unrestricted
14972 (let (org-completion-use-ido org-completion-use-iswitchb)
14973 (funcall set-function prompt
14974 (mapcar 'list (org-property-values property))
14975 nil nil "" nil cur)))))
14980 (defvar org-last-set-property nil)
14981 (defun org-read-property-name ()
14982 "Read a property name."
14983 (let* ((completion-ignore-case t)
14984 (keys (org-buffer-property-keys nil t t))
14985 (default-prop (or (save-excursion
14987 (beginning-of-line)
14988 (and (looking-at "^\\s-*:\\([^:\n]+\\):")
14989 (null (string= (match-string 1) "END"))
14990 (match-string 1))))
14991 org-last-set-property))
14992 (property (org-icompleting-read
14994 (if default-prop (concat " [" default-prop "]") "")
14996 (mapcar 'list keys)
15000 (if (member property keys)
15002 (or (cdr (assoc (downcase property)
15003 (mapcar (lambda (x) (cons (downcase x) x))
15007 (defun org-set-property (property value)
15008 "In the current entry, set PROPERTY to VALUE.
15009 When called interactively, this will prompt for a property name, offering
15010 completion on existing and default properties. And then it will prompt
15011 for a value, offering completion either on allowed values (via an inherited
15012 xxx_ALL property) or on existing values in other instances of this property
15013 in the current file."
15014 (interactive (list nil nil))
15015 (let* ((property (or property (org-read-property-name)))
15016 (value (or value (org-read-property-value property)))
15017 (fn (cdr (assoc property org-properties-postprocess-alist))))
15018 (setq org-last-set-property property)
15019 ;; Possibly postprocess the inserted value:
15020 (when fn (setq value (funcall fn value)))
15021 (unless (equal (org-entry-get nil property) value)
15022 (org-entry-put nil property value))))
15024 (defun org-delete-property (property)
15025 "In the current entry, delete PROPERTY."
15027 (let* ((completion-ignore-case t)
15028 (prop (org-icompleting-read "Property: "
15029 (org-entry-properties nil 'standard))))
15031 (message "Property %s %s" property
15032 (if (org-entry-delete nil property)
15034 "was not present in the entry")))
15036 (defun org-delete-property-globally (property)
15037 "Remove PROPERTY globally, from all entries."
15039 (let* ((completion-ignore-case t)
15040 (prop (org-icompleting-read
15041 "Globally remove property: "
15042 (mapcar 'list (org-buffer-property-keys)))))
15047 (goto-char (point-min))
15049 (while (re-search-forward
15050 (org-re-property property)
15052 (setq cnt (1+ cnt))
15053 (delete-region (match-beginning 0) (1+ (point-at-eol))))
15054 (message "Property \"%s\" removed from %d entries" property cnt)))))
15056 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
15058 (defun org-compute-property-at-point ()
15059 "Compute the property at point.
15060 This looks for an enclosing column format, extracts the operator and
15061 then applies it to the property in the column format's scope."
15063 (unless (org-at-property-p)
15064 (error "Not at a property"))
15065 (let ((prop (org-match-string-no-properties 2)))
15066 (org-columns-get-format-and-top-level)
15067 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
15068 (error "No operator defined for property %s" prop))
15069 (org-columns-compute prop)))
15071 (defvar org-property-allowed-value-functions nil
15072 "Hook for functions supplying allowed values for a specific property.
15073 The functions must take a single argument, the name of the property, and
15074 return a flat list of allowed values. If \":ETC\" is one of
15075 the values, this means that these values are intended as defaults for
15076 completion, but that other values should be allowed too.
15077 The functions must return nil if they are not responsible for this
15080 (defun org-property-get-allowed-values (pom property &optional table)
15081 "Get allowed values for the property PROPERTY.
15082 When TABLE is non-nil, return an alist that can directly be used for
15086 ((equal property "TODO")
15087 (setq vals (org-with-point-at pom
15088 (append org-todo-keywords-1 '("")))))
15089 ((equal property "PRIORITY")
15090 (let ((n org-lowest-priority))
15091 (while (>= n org-highest-priority)
15092 (push (char-to-string n) vals)
15094 ((member property org-special-properties))
15095 ((setq vals (run-hook-with-args-until-success
15096 'org-property-allowed-value-functions property)))
15098 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
15099 (when (and vals (string-match "\\S-" vals))
15100 (setq vals (car (read-from-string (concat "(" vals ")"))))
15101 (setq vals (mapcar (lambda (x)
15102 (cond ((stringp x) x)
15103 ((numberp x) (number-to-string x))
15104 ((symbolp x) (symbol-name x))
15107 (when (member ":ETC" vals)
15108 (setq vals (remove ":ETC" vals))
15109 (org-add-props (car vals) '(org-unrestricted t)))
15110 (if table (mapcar 'list vals) vals)))
15112 (defun org-property-previous-allowed-value (&optional previous)
15113 "Switch to the next allowed value for this property."
15115 (org-property-next-allowed-value t))
15117 (defun org-property-next-allowed-value (&optional previous)
15118 "Switch to the next allowed value for this property."
15120 (unless (org-at-property-p)
15121 (error "Not at a property"))
15122 (let* ((key (match-string 2))
15123 (value (match-string 3))
15124 (allowed (or (org-property-get-allowed-values (point) key)
15125 (and (member value '("[ ]" "[-]" "[X]"))
15129 (error "Allowed values for this property have not been defined"))
15130 (if previous (setq allowed (reverse allowed)))
15131 (if (member value allowed)
15132 (setq nval (car (cdr (member value allowed)))))
15133 (setq nval (or nval (car allowed)))
15134 (if (equal nval value)
15135 (error "Only one allowed value for this property"))
15136 (org-at-property-p)
15137 (replace-match (concat " :" key ": " nval) t t)
15139 (beginning-of-line 1)
15140 (skip-chars-forward " \t")
15141 (run-hook-with-args 'org-property-changed-functions key nval)))
15143 (defun org-find-olp (path &optional this-buffer)
15144 "Return a marker pointing to the entry at outline path OLP.
15145 If anything goes wrong, throw an error.
15146 You can wrap this call to catch the error like this:
15148 (condition-case msg
15149 (org-mobile-locate-entry (match-string 4))
15150 (error (nth 1 msg)))
15152 The return value will then be either a string with the error message,
15153 or a marker if everything is OK.
15155 If THIS-BUFFER is set, the outline path does not contain a file,
15157 (let* ((file (if this-buffer buffer-file-name (pop path)))
15158 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
15162 limit re end found pos heading cnt flevel)
15163 (unless buffer (error "File not found :%s" file))
15164 (with-current-buffer buffer
15168 (setq limit (point-max))
15169 (goto-char (point-min))
15170 (while (setq heading (pop path))
15171 (setq re (format org-complex-heading-regexp-format
15172 (regexp-quote heading)))
15173 (setq cnt 0 pos (point))
15174 (while (re-search-forward re end t)
15175 (setq level (- (match-end 1) (match-beginning 1)))
15176 (if (and (>= level lmin) (<= level lmax))
15177 (setq found (match-beginning 0) flevel level cnt (1+ cnt))))
15178 (when (= cnt 0) (error "Heading not found on level %d: %s"
15180 (when (> cnt 1) (error "Heading not unique on level %d: %s"
15183 (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
15184 (setq end (save-excursion (org-end-of-subtree t t))))
15185 (when (org-at-heading-p)
15186 (move-marker (make-marker) (point))))))))
15188 (defun org-find-exact-headline-in-buffer (heading &optional buffer pos-only)
15189 "Find node HEADING in BUFFER.
15190 Return a marker to the heading if it was found, or nil if not.
15191 If POS-ONLY is set, return just the position instead of a marker.
15193 The heading text must match exact, but it may have a TODO keyword,
15194 a priority cookie and tags in the standard locations."
15195 (with-current-buffer (or buffer (current-buffer))
15199 (goto-char (point-min))
15200 (let (case-fold-search)
15201 (if (re-search-forward
15202 (format org-complex-heading-regexp-format
15203 (regexp-quote heading)) nil t)
15205 (match-beginning 0)
15206 (move-marker (make-marker) (match-beginning 0)))))))))
15208 (defun org-find-exact-heading-in-directory (heading &optional dir)
15209 "Find Org node headline HEADING in all .org files in directory DIR.
15210 When the target headline is found, return a marker to this location."
15211 (let ((files (directory-files (or dir default-directory)
15212 nil "\\`[^.#].*\\.org\\'"))
15213 file visiting m buffer)
15215 (while (setq file (pop files))
15216 (message "trying %s" file)
15217 (setq visiting (org-find-base-buffer-visiting file))
15218 (setq buffer (or visiting (find-file-noselect file)))
15219 (setq m (org-find-exact-headline-in-buffer
15221 (when (and (not m) (not visiting)) (kill-buffer buffer))
15222 (and m (throw 'found m))))))
15224 (defun org-find-entry-with-id (ident)
15225 "Locate the entry that contains the ID property with exact value IDENT.
15226 IDENT can be a string, a symbol or a number, this function will search for
15227 the string representation of it.
15228 Return the position where this entry starts, or nil if there is no such entry."
15229 (interactive "sID: ")
15231 ((stringp ident) ident)
15232 ((symbol-name ident) (symbol-name ident))
15233 ((numberp ident) (number-to-string ident))
15234 (t (error "IDENT %s must be a string, symbol or number" ident))))
15235 (case-fold-search nil))
15239 (goto-char (point-min))
15240 (when (re-search-forward
15241 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
15243 (org-back-to-heading t)
15248 (defvar org-last-changed-timestamp nil)
15249 (defvar org-last-inserted-timestamp nil
15250 "The last time stamp inserted with `org-insert-time-stamp'.")
15251 (defvar org-time-was-given) ; dynamically scoped parameter
15252 (defvar org-end-time-was-given) ; dynamically scoped parameter
15253 (defvar org-ts-what) ; dynamically scoped parameter
15255 (defun org-time-stamp (arg &optional inactive)
15256 "Prompt for a date/time and insert a time stamp.
15257 If the user specifies a time like HH:MM or if this command is
15258 called with at least one prefix argument, the time stamp contains
15259 the date and the time. Otherwise, only the date is be included.
15261 All parts of a date not specified by the user is filled in from
15262 the current date/time. So if you just press return without
15263 typing anything, the time stamp will represent the current
15266 If there is already a timestamp at the cursor, it will be
15269 With two universal prefix arguments, insert an active timestamp
15270 with the current time without prompting the user."
15274 ;; Default time is either today, or, when entering a range,
15275 ;; the range start.
15276 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
15278 (re-search-backward
15279 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
15280 (- (point) 20) t)))
15281 (apply 'encode-time (org-parse-time-string (match-string 1)))
15283 (default-input (and ts (org-get-compact-tod ts)))
15284 (repeater (save-excursion
15286 (beginning-of-line)
15287 (when (re-search-forward
15288 "\\([.+-]+[0-9]+[hdwmy] ?\\)+" ;;\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
15289 (save-excursion (progn (end-of-line) (point))) t)
15290 (match-string 0)))))
15291 org-time-was-given org-end-time-was-given time)
15293 ((and (org-at-timestamp-p t)
15294 (memq last-command '(org-time-stamp org-time-stamp-inactive))
15295 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
15297 (setq time (let ((this-command this-command))
15298 (org-read-date arg 'totime nil nil
15299 default-time default-input inactive)))
15300 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
15301 ((org-at-timestamp-p t)
15302 (setq time (let ((this-command this-command))
15303 (org-read-date arg 'totime nil nil default-time default-input inactive)))
15304 (when (org-at-timestamp-p t) ; just to get the match data
15305 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
15307 (setq org-last-changed-timestamp
15308 (org-insert-time-stamp
15309 time (or org-time-was-given arg)
15310 inactive nil nil (list org-end-time-was-given)))
15311 (when repeater (goto-char (1- (point))) (insert " " repeater)
15312 (setq org-last-changed-timestamp
15313 (concat (substring org-last-inserted-timestamp 0 -1)
15314 " " repeater ">"))))
15315 (message "Timestamp updated"))
15317 (org-insert-time-stamp (current-time) t))
15319 (setq time (let ((this-command this-command))
15320 (org-read-date arg 'totime nil nil default-time default-input inactive)))
15321 (org-insert-time-stamp time (or org-time-was-given arg) inactive
15322 nil nil (list org-end-time-was-given))))))
15324 ;; FIXME: can we use this for something else, like computing time differences?
15325 (defun org-get-compact-tod (s)
15326 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
15327 (let* ((t1 (match-string 1 s))
15328 (h1 (string-to-number (match-string 2 s)))
15329 (m1 (string-to-number (match-string 3 s)))
15330 (t2 (and (match-end 4) (match-string 5 s)))
15331 (h2 (and t2 (string-to-number (match-string 6 s))))
15332 (m2 (and t2 (string-to-number (match-string 7 s))))
15336 (setq dh (- h2 h1) dm (- m2 m1))
15337 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
15338 (concat t1 "+" (number-to-string dh)
15339 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
15341 (defun org-time-stamp-inactive (&optional arg)
15342 "Insert an inactive time stamp.
15343 An inactive time stamp is enclosed in square brackets instead of angle
15344 brackets. It is inactive in the sense that it does not trigger agenda entries,
15345 does not link to the calendar and cannot be changed with the S-cursor keys.
15346 So these are more for recording a certain time/date."
15348 (org-time-stamp arg 'inactive))
15350 (defvar org-date-ovl (make-overlay 1 1))
15351 (overlay-put org-date-ovl 'face 'org-date-selected)
15352 (org-detach-overlay org-date-ovl)
15354 (defvar org-ans1) ; dynamically scoped parameter
15355 (defvar org-ans2) ; dynamically scoped parameter
15357 (defvar org-plain-time-of-day-regexp) ; defined below
15359 (defvar org-overriding-default-time nil) ; dynamically scoped
15360 (defvar org-read-date-overlay nil)
15361 (defvar org-dcst nil) ; dynamically scoped
15362 (defvar org-read-date-history nil)
15363 (defvar org-read-date-final-answer nil)
15364 (defvar org-read-date-analyze-futurep nil)
15365 (defvar org-read-date-analyze-forced-year nil)
15366 (defvar org-read-date-inactive)
15368 (defun org-read-date (&optional org-with-time to-time from-string prompt
15369 default-time default-input inactive)
15370 "Read a date, possibly a time, and make things smooth for the user.
15371 The prompt will suggest to enter an ISO date, but you can also enter anything
15372 which will at least partially be understood by `parse-time-string'.
15373 Unrecognized parts of the date will default to the current day, month, year,
15374 hour and minute. If this command is called to replace a timestamp at point,
15375 or to enter the second timestamp of a range, the default time is taken
15376 from the existing stamp. Furthermore, the command prefers the future,
15377 so if you are giving a date where the year is not given, and the day-month
15378 combination is already past in the current year, it will assume you
15379 mean next year. For details, see the manual. A few examples:
15381 3-2-5 --> 2003-02-05
15382 feb 15 --> currentyear-02-15
15383 2/15 --> currentyear-02-15
15384 sep 12 9 --> 2009-09-12
15385 12:45 --> today 12:45
15386 22 sept 0:34 --> currentyear-09-22 0:34
15387 12 --> currentyear-currentmonth-12
15388 Fri --> nearest Friday (today or later)
15391 Furthermore you can specify a relative date by giving, as the *first* thing
15392 in the input: a plus/minus sign, a number and a letter [hdwmy] to indicate
15393 change in days weeks, months, years.
15394 With a single plus or minus, the date is relative to today. With a double
15395 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
15396 +4d --> four days from today
15397 +4 --> same as above
15398 +2w --> two weeks from today
15399 ++5 --> five days from default date
15401 The function understands only English month and weekday abbreviations.
15403 While prompting, a calendar is popped up - you can also select the
15404 date with the mouse (button 1). The calendar shows a period of three
15405 months. To scroll it to other months, use the keys `>' and `<'.
15406 If you don't like the calendar, turn it off with
15407 \(setq org-read-date-popup-calendar nil)
15409 With optional argument TO-TIME, the date will immediately be converted
15410 to an internal time.
15411 With an optional argument ORG-WITH-TIME, the prompt will suggest to
15412 also insert a time. Note that when ORG-WITH-TIME is not set, you can
15413 still enter a time, and this function will inform the calling routine
15414 about this change. The calling routine may then choose to change the
15415 format used to insert the time stamp into the buffer to include the time.
15416 With optional argument FROM-STRING, read from this string instead from
15417 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
15418 the time/date that is used for everything that is not specified by the
15420 (require 'parse-time)
15421 (let* ((org-time-stamp-rounding-minutes
15422 (if (equal org-with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
15423 (org-dcst org-display-custom-times)
15424 (ct (org-current-time))
15425 (org-def (or org-overriding-default-time default-time ct))
15426 (org-defdecode (decode-time org-def))
15428 (when (< (nth 2 org-defdecode) org-extend-today-until)
15429 (setcar (nthcdr 2 org-defdecode) -1)
15430 (setcar (nthcdr 1 org-defdecode) 59)
15431 (setq org-def (apply 'encode-time org-defdecode)
15432 org-defdecode (decode-time org-def)))))
15433 (calendar-frame-setup nil)
15434 (calendar-setup nil)
15435 (calendar-move-hook nil)
15436 (calendar-view-diary-initially-flag nil)
15437 (calendar-view-holidays-initially-flag nil)
15438 (timestr (format-time-string
15439 (if org-with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") org-def))
15440 (prompt (concat (if prompt (concat prompt " ") "")
15441 (format "Date+time [%s]: " timestr)))
15442 ans (org-ans0 "") org-ans1 org-ans2 final)
15445 (from-string (setq ans from-string))
15446 (org-read-date-popup-calendar
15448 (save-window-excursion
15450 (org-eval-in-calendar '(setq cursor-type nil) t)
15453 (calendar-forward-day (- (time-to-days org-def)
15454 (calendar-absolute-from-gregorian
15455 (calendar-current-date))))
15456 (org-eval-in-calendar nil t)
15457 (let* ((old-map (current-local-map))
15458 (map (copy-keymap calendar-mode-map))
15459 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
15460 (org-defkey map (kbd "RET") 'org-calendar-select)
15461 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
15462 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
15463 (org-defkey minibuffer-local-map [(meta shift left)]
15464 (lambda () (interactive)
15465 (org-eval-in-calendar '(calendar-backward-month 1))))
15466 (org-defkey minibuffer-local-map [(meta shift right)]
15467 (lambda () (interactive)
15468 (org-eval-in-calendar '(calendar-forward-month 1))))
15469 (org-defkey minibuffer-local-map [(meta shift up)]
15470 (lambda () (interactive)
15471 (org-eval-in-calendar '(calendar-backward-year 1))))
15472 (org-defkey minibuffer-local-map [(meta shift down)]
15473 (lambda () (interactive)
15474 (org-eval-in-calendar '(calendar-forward-year 1))))
15475 (org-defkey minibuffer-local-map [?\e (shift left)]
15476 (lambda () (interactive)
15477 (org-eval-in-calendar '(calendar-backward-month 1))))
15478 (org-defkey minibuffer-local-map [?\e (shift right)]
15479 (lambda () (interactive)
15480 (org-eval-in-calendar '(calendar-forward-month 1))))
15481 (org-defkey minibuffer-local-map [?\e (shift up)]
15482 (lambda () (interactive)
15483 (org-eval-in-calendar '(calendar-backward-year 1))))
15484 (org-defkey minibuffer-local-map [?\e (shift down)]
15485 (lambda () (interactive)
15486 (org-eval-in-calendar '(calendar-forward-year 1))))
15487 (org-defkey minibuffer-local-map [(shift up)]
15488 (lambda () (interactive)
15489 (org-eval-in-calendar '(calendar-backward-week 1))))
15490 (org-defkey minibuffer-local-map [(shift down)]
15491 (lambda () (interactive)
15492 (org-eval-in-calendar '(calendar-forward-week 1))))
15493 (org-defkey minibuffer-local-map [(shift left)]
15494 (lambda () (interactive)
15495 (org-eval-in-calendar '(calendar-backward-day 1))))
15496 (org-defkey minibuffer-local-map [(shift right)]
15497 (lambda () (interactive)
15498 (org-eval-in-calendar '(calendar-forward-day 1))))
15499 (org-defkey minibuffer-local-map ">"
15500 (lambda () (interactive)
15501 (org-eval-in-calendar '(scroll-calendar-left 1))))
15502 (org-defkey minibuffer-local-map "<"
15503 (lambda () (interactive)
15504 (org-eval-in-calendar '(scroll-calendar-right 1))))
15505 (org-defkey minibuffer-local-map "\C-v"
15506 (lambda () (interactive)
15507 (org-eval-in-calendar
15508 '(calendar-scroll-left-three-months 1))))
15509 (org-defkey minibuffer-local-map "\M-v"
15510 (lambda () (interactive)
15511 (org-eval-in-calendar
15512 '(calendar-scroll-right-three-months 1))))
15513 (run-hooks 'org-read-date-minibuffer-setup-hook)
15516 (use-local-map map)
15517 (setq org-read-date-inactive inactive)
15518 (add-hook 'post-command-hook 'org-read-date-display)
15519 (setq org-ans0 (read-string prompt default-input
15520 'org-read-date-history nil))
15521 ;; org-ans0: from prompt
15522 ;; org-ans1: from mouse click
15523 ;; org-ans2: from calendar motion
15524 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
15525 (remove-hook 'post-command-hook 'org-read-date-display)
15526 (use-local-map old-map)
15527 (when org-read-date-overlay
15528 (delete-overlay org-read-date-overlay)
15529 (setq org-read-date-overlay nil)))))
15530 (bury-buffer "*Calendar*")))))
15532 (t ; Naked prompt only
15534 (setq ans (read-string prompt default-input
15535 'org-read-date-history timestr))
15536 (when org-read-date-overlay
15537 (delete-overlay org-read-date-overlay)
15538 (setq org-read-date-overlay nil)))))
15540 (setq final (org-read-date-analyze ans org-def org-defdecode))
15542 (when org-read-date-analyze-forced-year
15543 (message "Year was forced into %s"
15544 (if org-read-date-force-compatible-dates
15545 "compatible range (1970-2037)"
15546 "range representable on this machine"))
15549 ;; One round trip to get rid of 34th of August and stuff like that....
15550 (setq final (decode-time (apply 'encode-time final)))
15552 (setq org-read-date-final-answer ans)
15555 (apply 'encode-time final)
15556 (if (and (boundp 'org-time-was-given) org-time-was-given)
15557 (format "%04d-%02d-%02d %02d:%02d"
15558 (nth 5 final) (nth 4 final) (nth 3 final)
15559 (nth 2 final) (nth 1 final))
15560 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
15563 (defvar org-defdecode)
15564 (defvar org-with-time)
15565 (defun org-read-date-display ()
15566 "Display the current date prompt interpretation in the minibuffer."
15567 (when org-read-date-display-live
15568 (when org-read-date-overlay
15569 (delete-overlay org-read-date-overlay))
15570 (when (minibufferp (current-buffer))
15573 (while (not (equal (buffer-substring
15574 (max (point-min) (- (point) 4)) (point))
15577 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
15578 " " (or org-ans1 org-ans2)))
15579 (org-end-time-was-given nil)
15580 (f (org-read-date-analyze ans org-def org-defdecode))
15582 org-time-stamp-custom-formats
15583 org-time-stamp-formats))
15584 (fmt (if (or org-with-time
15585 (and (boundp 'org-time-was-given) org-time-was-given))
15588 (txt (format-time-string fmt (apply 'encode-time f)))
15589 (txt (if org-read-date-inactive (concat "[" (substring txt 1 -1) "]") txt))
15590 (txt (concat "=> " txt)))
15591 (when (and org-end-time-was-given
15592 (string-match org-plain-time-of-day-regexp txt))
15593 (setq txt (concat (substring txt 0 (match-end 0)) "-"
15594 org-end-time-was-given
15595 (substring txt (match-end 0)))))
15596 (when org-read-date-analyze-futurep
15597 (setq txt (concat txt " (=>F)")))
15598 (setq org-read-date-overlay
15599 (make-overlay (1- (point-at-eol)) (point-at-eol)))
15600 (org-overlay-display org-read-date-overlay txt 'secondary-selection)))))
15602 (defun org-read-date-analyze (ans org-def org-defdecode)
15603 "Analyze the combined answer of the date prompt."
15604 ;; FIXME: cleanup and comment
15605 (let ((nowdecode (decode-time (current-time)))
15606 delta deltan deltaw deltadef year month day
15607 hour minute second wday pm h2 m2 tl wday1
15608 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
15609 (setq org-read-date-analyze-futurep nil
15610 org-read-date-analyze-forced-year nil)
15611 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
15614 (when (setq delta (org-read-date-get-relative ans (current-time) org-def))
15615 (setq ans (replace-match "" t t ans)
15617 deltaw (nth 1 delta)
15618 deltadef (nth 2 delta)))
15620 ;; Check if there is an iso week date in there. If yes, store the
15621 ;; info and postpone interpreting it until the rest of the parsing
15623 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
15624 (setq iso-year (if (match-end 1)
15625 (org-small-year-to-year
15626 (string-to-number (match-string 1 ans))))
15627 iso-weekday (if (match-end 3)
15628 (string-to-number (match-string 3 ans)))
15629 iso-week (string-to-number (match-string 2 ans)))
15630 (setq ans (replace-match "" t t ans)))
15632 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
15633 (when (string-match
15634 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
15635 (setq year (if (match-end 2)
15636 (string-to-number (match-string 2 ans))
15637 (progn (setq kill-year t)
15638 (string-to-number (format-time-string "%Y"))))
15639 month (string-to-number (match-string 3 ans))
15640 day (string-to-number (match-string 4 ans)))
15641 (if (< year 100) (setq year (+ 2000 year)))
15642 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15645 ;; Help matching dotted european dates
15646 (when (string-match
15647 "^ *\\(3[01]\\|0?[1-9]\\|[12][0-9]\\)\\. ?\\(0?[1-9]\\|1[012]\\)\\. ?\\([1-9][0-9][0-9][0-9]\\)?" ans)
15648 (setq year (if (match-end 3)
15649 (string-to-number (match-string 3 ans))
15650 (progn (setq kill-year t)
15651 (string-to-number (format-time-string "%Y"))))
15652 day (string-to-number (match-string 1 ans))
15653 month (string-to-number (match-string 2 ans))
15654 ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15657 ;; Help matching american dates, like 5/30 or 5/30/7
15658 (when (string-match
15659 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
15660 (setq year (if (match-end 4)
15661 (string-to-number (match-string 4 ans))
15662 (progn (setq kill-year t)
15663 (string-to-number (format-time-string "%Y"))))
15664 month (string-to-number (match-string 1 ans))
15665 day (string-to-number (match-string 2 ans)))
15666 (if (< year 100) (setq year (+ 2000 year)))
15667 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
15669 ;; Help matching am/pm times, because `parse-time-string' does not do that.
15670 ;; If there is a time with am/pm, and *no* time without it, we convert
15671 ;; so that matching will be successful.
15672 (loop for i from 1 to 2 do ; twice, for end time as well
15673 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
15674 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
15675 (setq hour (string-to-number (match-string 1 ans))
15676 minute (if (match-end 3)
15677 (string-to-number (match-string 3 ans))
15680 (string-to-char (downcase (match-string 4 ans)))))
15681 (if (and (= hour 12) (not pm))
15683 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
15684 (setq ans (replace-match (format "%02d:%02d" hour minute)
15687 ;; Check if a time range is given as a duration
15688 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
15689 (setq hour (string-to-number (match-string 1 ans))
15690 h2 (+ hour (string-to-number (match-string 3 ans)))
15691 minute (string-to-number (match-string 2 ans))
15692 m2 (+ minute (if (match-end 5) (string-to-number
15693 (match-string 5 ans))0)))
15694 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
15695 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
15698 ;; Check if there is a time range
15699 (when (boundp 'org-end-time-was-given)
15700 (setq org-time-was-given nil)
15701 (when (and (string-match org-plain-time-of-day-regexp ans)
15703 (setq org-end-time-was-given (match-string 8 ans))
15704 (setq ans (concat (substring ans 0 (match-beginning 7))
15705 (substring ans (match-end 7))))))
15707 (setq tl (parse-time-string ans)
15708 day (or (nth 3 tl) (nth 3 org-defdecode))
15709 month (or (nth 4 tl)
15710 (if (and org-read-date-prefer-future
15711 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
15712 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
15713 (nth 4 org-defdecode)))
15714 year (or (and (not kill-year) (nth 5 tl))
15715 (if (and org-read-date-prefer-future
15716 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
15717 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
15718 (nth 5 org-defdecode)))
15719 hour (or (nth 2 tl) (nth 2 org-defdecode))
15720 minute (or (nth 1 tl) (nth 1 org-defdecode))
15721 second (or (nth 0 tl) 0)
15724 (when (and (eq org-read-date-prefer-future 'time)
15725 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
15726 (equal day (nth 3 nowdecode))
15727 (equal month (nth 4 nowdecode))
15728 (equal year (nth 5 nowdecode))
15730 (or (< (nth 2 tl) (nth 2 nowdecode))
15731 (and (= (nth 2 tl) (nth 2 nowdecode))
15733 (< (nth 1 tl) (nth 1 nowdecode)))))
15737 ;; Special date definitions below
15740 ;; There was an iso week
15743 (setq year (or iso-year year)
15744 day (or iso-weekday wday 1)
15745 wday nil ; to make sure that the trigger below does not match
15746 iso-date (calendar-gregorian-from-absolute
15747 (calendar-absolute-from-iso
15748 (list iso-week day year))))
15749 ; FIXME: Should we also push ISO weeks into the future?
15750 ; (when (and org-read-date-prefer-future
15752 ; (< (calendar-absolute-from-gregorian iso-date)
15753 ; (time-to-days (current-time))))
15754 ; (setq year (1+ year)
15755 ; iso-date (calendar-gregorian-from-absolute
15756 ; (calendar-absolute-from-iso
15757 ; (list iso-week day year)))))
15758 (setq month (car iso-date)
15759 year (nth 2 iso-date)
15760 day (nth 1 iso-date)))
15764 (let ((now (decode-time (current-time))))
15765 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
15766 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
15767 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
15768 ((equal deltaw "m") (setq month (+ month deltan)))
15769 ((equal deltaw "y") (setq year (+ year deltan)))))
15770 ((and wday (not (nth 3 tl)))
15771 ;; Weekday was given, but no day, so pick that day in the week
15772 ;; on or after the derived date.
15773 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
15774 (unless (equal wday wday1)
15775 (setq day (+ day (% (- wday wday1 -7) 7))))))
15776 (if (and (boundp 'org-time-was-given)
15778 (setq org-time-was-given t))
15779 (if (< year 100) (setq year (+ 2000 year)))
15780 ;; Check of the date is representable
15781 (if org-read-date-force-compatible-dates
15784 (setq year 1970 org-read-date-analyze-forced-year t))
15786 (setq year 2037 org-read-date-analyze-forced-year t)))
15787 (condition-case nil
15788 (ignore (encode-time second minute hour day month year))
15790 (setq year (nth 5 org-defdecode))
15791 (setq org-read-date-analyze-forced-year t))))
15792 (setq org-read-date-analyze-futurep futurep)
15793 (list second minute hour day month year)))
15795 (defvar parse-time-weekdays)
15796 (defun org-read-date-get-relative (s today default)
15797 "Check string S for special relative date string.
15798 TODAY and DEFAULT are internal times, for today and for a default.
15799 Return shift list (N what def-flag)
15800 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
15801 N is the number of WHATs to shift.
15802 DEF-FLAG is t when a double ++ or -- indicates shift relative to
15803 the DEFAULT date rather than TODAY."
15804 (require 'parse-time)
15808 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
15810 "\\([hdwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
15811 "\\([ \t]\\|$\\)") s)
15812 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
15813 (let* ((dir (if (> (match-end 1) (match-beginning 1))
15814 (string-to-char (substring (match-string 1 s) -1))
15816 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
15817 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
15818 (what (if (match-end 3) (match-string 3 s) "d"))
15819 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
15820 (date (if rel default today))
15821 (wday (nth 6 (decode-time date)))
15825 (setq delta (mod (+ 7 (- wday1 wday)) 7))
15826 (if (= dir ?-) (setq delta (- delta 7)))
15827 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
15828 (list delta "d" rel))
15829 (list (* n (if (= dir ?-) -1 1)) what rel)))))
15831 (defun org-order-calendar-date-args (arg1 arg2 arg3)
15832 "Turn a user-specified date into the internal representation.
15833 The internal representation needed by the calendar is (month day year).
15834 This is a wrapper to handle the brain-dead convention in calendar that
15835 user function argument order change dependent on argument order."
15836 (if (boundp 'calendar-date-style)
15838 ((eq calendar-date-style 'american)
15839 (list arg1 arg2 arg3))
15840 ((eq calendar-date-style 'european)
15841 (list arg2 arg1 arg3))
15842 ((eq calendar-date-style 'iso)
15843 (list arg2 arg3 arg1)))
15844 (org-no-warnings ;; european-calendar-style is obsolete as of version 23.1
15845 (if (org-bound-and-true-p european-calendar-style)
15846 (list arg2 arg1 arg3)
15847 (list arg1 arg2 arg3)))))
15849 (defun org-eval-in-calendar (form &optional keepdate)
15850 "Eval FORM in the calendar window and return to current window.
15851 When KEEPDATE is non-nil, update `org-ans2' from the cursor date,
15852 otherwise stick to the current value of `org-ans2'."
15853 (let ((sf (selected-frame))
15854 (sw (selected-window)))
15855 (select-window (get-buffer-window "*Calendar*" t))
15857 (when (and (not keepdate) (calendar-cursor-to-date))
15858 (let* ((date (calendar-cursor-to-date))
15859 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
15860 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
15861 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
15863 (org-select-frame-set-input-focus sf)))
15865 (defun org-calendar-select ()
15866 "Return to `org-read-date' with the date currently selected.
15867 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
15869 (when (calendar-cursor-to-date)
15870 (let* ((date (calendar-cursor-to-date))
15871 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
15872 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
15873 (if (active-minibuffer-window) (exit-minibuffer))))
15875 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
15876 "Insert a date stamp for the date given by the internal TIME.
15877 WITH-HM means use the stamp format that includes the time of the day.
15878 INACTIVE means use square brackets instead of angular ones, so that the
15879 stamp will not contribute to the agenda.
15880 PRE and POST are optional strings to be inserted before and after the
15882 The command returns the inserted time stamp."
15883 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
15885 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
15886 (insert-before-markers (or pre ""))
15887 (when (listp extra)
15888 (setq extra (car extra))
15889 (if (and (stringp extra)
15890 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
15891 (setq extra (format "-%02d:%02d"
15892 (string-to-number (match-string 1 extra))
15893 (string-to-number (match-string 2 extra))))
15896 (setq fmt (concat (substring fmt 0 -1) extra (substring fmt -1))))
15897 (insert-before-markers (setq stamp (format-time-string fmt time)))
15898 (insert-before-markers (or post ""))
15899 (setq org-last-inserted-timestamp stamp)))
15901 (defun org-toggle-time-stamp-overlays ()
15902 "Toggle the use of custom time stamp formats."
15904 (setq org-display-custom-times (not org-display-custom-times))
15905 (unless org-display-custom-times
15906 (let ((p (point-min)) (bmp (buffer-modified-p)))
15907 (while (setq p (next-single-property-change p 'display))
15908 (if (and (get-text-property p 'display)
15909 (eq (get-text-property p 'face) 'org-date))
15910 (remove-text-properties
15911 p (setq p (next-single-property-change p 'display))
15913 (set-buffer-modified-p bmp)))
15914 (if (featurep 'xemacs)
15915 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
15916 (org-restart-font-lock)
15917 (setq org-table-may-need-update t)
15918 (if org-display-custom-times
15919 (message "Time stamps are overlaid with custom format")
15920 (message "Time stamp overlays removed")))
15922 (defun org-display-custom-time (beg end)
15923 "Overlay modified time stamp format over timestamp between BEG and END."
15924 (let* ((ts (buffer-substring beg end))
15925 t1 w1 with-hm tf time str w2 (off 0))
15927 (setq t1 (org-parse-time-string ts t))
15928 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)?\\'" ts)
15929 (setq off (- (match-end 0) (match-beginning 0)))))
15930 (setq end (- end off))
15931 (setq w1 (- end beg)
15932 with-hm (and (nth 1 t1) (nth 2 t1))
15933 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
15934 time (org-fix-decoded-time t1)
15936 (format-time-string
15937 (substring tf 1 -1) (apply 'encode-time time))
15938 nil 'mouse-face 'highlight)
15940 (if (not (= w2 w1))
15941 (add-text-properties (1+ beg) (+ 2 beg)
15942 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
15943 (if (featurep 'xemacs)
15945 (put-text-property beg end 'invisible t)
15946 (put-text-property beg end 'end-glyph (make-glyph str)))
15947 (put-text-property beg end 'display str))))
15949 (defun org-translate-time (string)
15950 "Translate all timestamps in STRING to custom format.
15951 But do this only if the variable `org-display-custom-times' is set."
15952 (when org-display-custom-times
15955 (re org-ts-regexp-both)
15956 t1 with-hm inactive tf time str beg end)
15957 (while (setq start (string-match re string start))
15958 (setq beg (match-beginning 0)
15960 t1 (save-match-data
15961 (org-parse-time-string (substring string beg end) t))
15962 with-hm (and (nth 1 t1) (nth 2 t1))
15963 inactive (equal (substring string beg (1+ beg)) "[")
15964 tf (funcall (if with-hm 'cdr 'car)
15965 org-time-stamp-custom-formats)
15966 time (org-fix-decoded-time t1)
15967 str (format-time-string
15969 (if inactive "[" "<") (substring tf 1 -1)
15970 (if inactive "]" ">"))
15971 (apply 'encode-time time))
15972 string (replace-match str t t string)
15973 start (+ start (length str)))))))
15976 (defun org-fix-decoded-time (time)
15977 "Set 0 instead of nil for the first 6 elements of time.
15978 Don't touch the rest."
15980 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
15982 (defun org-days-to-time (timestamp-string)
15983 "Difference between TIMESTAMP-STRING and now in days."
15984 (- (time-to-days (org-time-string-to-time timestamp-string))
15985 (time-to-days (current-time))))
15987 (defun org-deadline-close (timestamp-string &optional ndays)
15988 "Is the time in TIMESTAMP-STRING close to the current date?"
15989 (setq ndays (or ndays (org-get-wdays timestamp-string)))
15990 (and (< (org-days-to-time timestamp-string) ndays)
15991 (not (org-entry-is-done-p))))
15993 (defun org-get-wdays (ts)
15994 "Get the deadline lead time appropriate for timestring TS."
15996 ((<= org-deadline-warning-days 0)
15997 ;; 0 or negative, enforce this value no matter what
15998 (- org-deadline-warning-days))
15999 ((string-match "-\\([0-9]+\\)\\([hdwmy]\\)\\(\\'\\|>\\| \\)" ts)
16000 ;; lead time is specified.
16001 (floor (* (string-to-number (match-string 1 ts))
16002 (cdr (assoc (match-string 2 ts)
16003 '(("d" . 1) ("w" . 7)
16004 ("m" . 30.4) ("y" . 365.25)))))))
16005 ;; go for the default.
16006 (t org-deadline-warning-days)))
16008 (defun org-calendar-select-mouse (ev)
16009 "Return to `org-read-date' with the date currently selected.
16010 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
16012 (mouse-set-point ev)
16013 (when (calendar-cursor-to-date)
16014 (let* ((date (calendar-cursor-to-date))
16015 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
16016 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
16017 (if (active-minibuffer-window) (exit-minibuffer))))
16019 (defun org-check-deadlines (ndays)
16020 "Check if there are any deadlines due or past due.
16021 A deadline is considered due if it happens within `org-deadline-warning-days'
16022 days from today's date. If the deadline appears in an entry marked DONE,
16023 it is not shown. The prefix arg NDAYS can be used to test that many
16024 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
16026 (let* ((org-warn-days
16028 ((equal ndays '(4)) 100000)
16029 (ndays (prefix-numeric-value ndays))
16030 (t (abs org-deadline-warning-days))))
16031 (case-fold-search nil)
16032 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
16034 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
16036 (message "%d deadlines past-due or due within %d days"
16037 (org-occur regexp nil callback)
16040 (defsubst org-re-timestamp (type)
16041 "Return a regexp for timestamp TYPE.
16042 Allowed values for TYPE are:
16044 all: all timestamps
16045 active: only active timestamps (<...>)
16046 inactive: only inactive timestamps ([...])
16047 scheduled: only scheduled timestamps
16048 deadline: only deadline timestamps
16050 When TYPE is nil, fall back on returning a regexp that matches
16051 both scheduled and deadline timestamps."
16052 (cond ((eq type 'all) "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\(?: +[^]+0-9>
\n -]+\\)?\\(?: +[0-9]\\{1,2\\}:[0-9]\\{2\\}\\)?\\)")
16053 ((eq type 'active) org-ts-regexp)
16054 ((eq type 'inactive) "\\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^
\n>]*?\\)\\]")
16055 ((eq type 'scheduled) (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>"))
16056 ((eq type 'deadline) (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
16057 ((eq type 'scheduled-or-deadline)
16058 (concat "\\<\\(?:" org-deadline-string "\\|" org-scheduled-string "\\) *<\\([^>]+\\)>"))))
16060 (defun org-check-before-date (date)
16061 "Check if there are deadlines or scheduled entries before DATE."
16062 (interactive (list (org-read-date)))
16063 (let ((case-fold-search nil)
16064 (regexp (org-re-timestamp org-ts-type))
16066 (lambda () (time-less-p
16067 (org-time-string-to-time (match-string 1))
16068 (org-time-string-to-time date)))))
16069 (message "%d entries before %s"
16070 (org-occur regexp nil callback) date)))
16072 (defun org-check-after-date (date)
16073 "Check if there are deadlines or scheduled entries after DATE."
16074 (interactive (list (org-read-date)))
16075 (let ((case-fold-search nil)
16076 (regexp (org-re-timestamp org-ts-type))
16080 (org-time-string-to-time (match-string 1))
16081 (org-time-string-to-time date))))))
16082 (message "%d entries after %s"
16083 (org-occur regexp nil callback) date)))
16085 (defun org-check-dates-range (start-date end-date)
16086 "Check for deadlines/scheduled entries between START-DATE and END-DATE."
16087 (interactive (list (org-read-date nil nil nil "Range starts")
16088 (org-read-date nil nil nil "Range end")))
16089 (let ((case-fold-search nil)
16090 (regexp (org-re-timestamp org-ts-type))
16093 (let ((match (match-string 1)))
16096 (org-time-string-to-time match)
16097 (org-time-string-to-time start-date)))
16099 (org-time-string-to-time match)
16100 (org-time-string-to-time end-date)))))))
16101 (message "%d entries between %s and %s"
16102 (org-occur regexp nil callback) start-date end-date)))
16104 (defun org-evaluate-time-range (&optional to-buffer)
16105 "Evaluate a time range by computing the difference between start and end.
16106 Normally the result is just printed in the echo area, but with prefix arg
16107 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
16108 If the time range is actually in a table, the result is inserted into the
16110 For time difference computation, a year is assumed to be exactly 365
16111 days in order to avoid rounding problems."
16114 (org-clock-update-time-maybe)
16116 (unless (org-at-date-range-p t)
16117 (goto-char (point-at-bol))
16118 (re-search-forward org-tr-regexp-both (point-at-eol) t))
16119 (if (not (org-at-date-range-p t))
16120 (error "Not at a time-stamp range, and none found in current line")))
16121 (let* ((ts1 (match-string 1))
16122 (ts2 (match-string 2))
16123 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
16124 (match-end (match-end 0))
16125 (time1 (org-time-string-to-time ts1))
16126 (time2 (org-time-string-to-time ts2))
16127 (t1 (org-float-time time1))
16128 (t2 (org-float-time time2))
16129 (diff (abs (- t2 t1)))
16130 (negative (< (- t2 t1) 0))
16131 ;; (ys (floor (* 365 24 60 60)))
16134 (fy "%dy %dd %02d:%02d")
16136 (fd "%dd %02d:%02d")
16141 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
16143 d (floor (/ diff ds)) diff (mod diff ds)
16144 h (floor (/ diff hs)) diff (mod diff hs)
16145 m (floor (/ diff 60)))
16146 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
16148 d (floor (+ (/ diff ds) 0.5))
16150 (if (not to-buffer)
16151 (message "%s" (org-make-tdiff-string y d h m))
16152 (if (org-at-table-p)
16154 (goto-char match-end)
16156 (and (looking-at " *|") (goto-char (match-end 0))))
16157 (goto-char match-end))
16159 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
16160 (replace-match ""))
16161 (if negative (insert " -"))
16162 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
16163 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
16164 (insert " " (format fh h m))))
16165 (if align (org-table-align))
16166 (message "Time difference inserted")))))
16168 (defun org-make-tdiff-string (y d h m)
16171 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
16173 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
16175 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
16177 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
16179 (apply 'format fmt (nreverse l))))
16181 (defun org-time-string-to-time (s &optional buffer pos)
16182 (condition-case errdata
16183 (apply 'encode-time (org-parse-time-string s))
16184 (error (error "Bad timestamp `%s'%s\nError was: %s"
16185 s (if (not (and buffer pos))
16187 (format " at %d in buffer `%s'" pos buffer))
16190 (defun org-time-string-to-seconds (s)
16191 (org-float-time (org-time-string-to-time s)))
16193 (defun org-time-string-to-absolute (s &optional daynr prefer show-all buffer pos)
16194 "Convert a time stamp to an absolute day number.
16195 If there is a specifier for a cyclic time stamp, get the closest date to
16197 PREFER and SHOW-ALL are passed through to `org-closest-date'.
16198 The variable date is bound by the calendar when this is called."
16200 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
16201 (if (org-diary-sexp-entry (match-string 1 s) "" date)
16204 ((and daynr (string-match "\\+[0-9]+[hdwmy]" s))
16205 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
16206 (time-to-days (current-time))) (match-string 0 s)
16209 (condition-case errdata
16210 (apply 'encode-time (org-parse-time-string s))
16211 (error (error "Bad timestamp `%s'%s\nError was: %s"
16212 s (if (not (and buffer pos))
16214 (format " at %d in buffer `%s'" pos buffer))
16215 (cdr errdata))))))))
16217 (defun org-days-to-iso-week (days)
16218 "Return the iso week number."
16220 (car (calendar-iso-from-absolute days)))
16222 (defun org-small-year-to-year (year)
16223 "Convert 2-digit years into 4-digit years.
16224 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
16225 The year 2000 cannot be abbreviated. Any year larger than 99
16226 is returned unchanged."
16228 (setq year (+ 2000 year))
16230 (setq year (+ 1900 year))))
16233 (defun org-time-from-absolute (d)
16234 "Return the time corresponding to date D.
16235 D may be an absolute day number, or a calendar-type list (month day year)."
16236 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
16237 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
16239 (defun org-calendar-holiday ()
16240 "List of holidays, for Diary display in Org-mode."
16241 (require 'holidays)
16243 (if (fboundp 'calendar-check-holidays)
16244 'calendar-check-holidays 'check-calendar-holidays) date)))
16245 (if hl (mapconcat 'identity hl "; "))))
16247 (defun org-diary-sexp-entry (sexp entry date)
16248 "Process a SEXP diary ENTRY for DATE."
16249 (require 'diary-lib)
16250 (let ((result (if calendar-debug-sexp
16251 (let ((stack-trace-on-error t))
16252 (eval (car (read-from-string sexp))))
16253 (condition-case nil
16254 (eval (car (read-from-string sexp)))
16257 (message "Bad sexp at line %d in %s: %s"
16259 (buffer-file-name) sexp)
16261 (cond ((stringp result) (split-string result "; "))
16262 ((and (consp result)
16263 (not (consp (cdr result)))
16264 (stringp (cdr result))) (cdr result))
16265 ((and (consp result)
16266 (stringp (car result))) result)
16269 (defun org-diary-to-ical-string (frombuf)
16270 "Get iCalendar entries from diary entries in buffer FROMBUF.
16271 This uses the icalendar.el library."
16272 (let* ((tmpdir (if (featurep 'xemacs)
16274 temporary-file-directory))
16275 (tmpfile (make-temp-name
16276 (expand-file-name "orgics" tmpdir)))
16278 (with-current-buffer frombuf
16279 (icalendar-export-region (point-min) (point-max) tmpfile)
16280 (setq buf (find-buffer-visiting tmpfile))
16282 (goto-char (point-min))
16283 (if (re-search-forward "^BEGIN:VEVENT" nil t)
16284 (setq b (match-beginning 0)))
16285 (goto-char (point-max))
16286 (if (re-search-backward "^END:VEVENT" nil t)
16287 (setq e (match-end 0)))
16288 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
16290 (delete-file tmpfile)
16293 (defun org-closest-date (start current change prefer show-all)
16294 "Find the date closest to CURRENT that is consistent with START and CHANGE.
16295 When PREFER is `past', return a date that is either CURRENT or past.
16296 When PREFER is `future', return a date that is either CURRENT or future.
16297 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
16298 ;; Make the proper lists from the dates
16300 (let ((a1 '(("d" . day) ("w" . week) ("m" . month) ("y" . year)))
16301 dn dw sday cday n1 n2 n0
16302 d m y y1 y2 date1 date2 nmonths nm ny m2)
16304 (setq start (org-date-to-gregorian start)
16305 current (org-date-to-gregorian
16308 (time-to-days (current-time))))
16309 sday (calendar-absolute-from-gregorian start)
16310 cday (calendar-absolute-from-gregorian current))
16312 (if (<= cday sday) (throw 'exit sday))
16314 (if (string-match "\\(\\+[0-9]+\\)\\([hdwmy]\\)" change)
16315 (setq dn (string-to-number (match-string 1 change))
16316 dw (cdr (assoc (match-string 2 change) a1)))
16317 (error "Invalid change specifier: %s" change))
16318 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
16321 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
16324 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
16325 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
16326 (setq date1 (list m d y1)
16327 n1 (calendar-absolute-from-gregorian date1)
16328 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
16329 n2 (calendar-absolute-from-gregorian date2)))
16331 ;; approx number of month between the two dates
16332 (setq nmonths (floor (/ (- cday sday) 30.436875)))
16333 ;; How often does dn fit in there?
16334 (setq d (nth 1 start) m (car start) y (nth 2 start)
16335 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
16337 ny (floor (/ m 12))
16340 (while (> m 12) (setq m (- m 12) y (1+ y)))
16341 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
16342 (setq m2 (+ m dn) y2 y)
16343 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
16344 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
16345 (while (<= n2 cday)
16346 (setq n1 n2 m m2 y y2)
16347 (setq m2 (+ m dn) y2 y)
16348 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
16349 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
16350 ;; Make sure n1 is the earlier date
16351 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
16354 ((eq prefer 'past) (if (= cday n2) n2 n1))
16355 ((eq prefer 'future) (if (= cday n1) n1 n2))
16356 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
16358 ((eq prefer 'past) (if (= cday n2) n2 n1))
16359 ((eq prefer 'future) (if (= cday n1) n1 n2))
16360 (t (if (= cday n1) n1 n2)))))))
16362 (defun org-date-to-gregorian (date)
16363 "Turn any specification of DATE into a Gregorian date for the calendar."
16364 (cond ((integerp date) (calendar-gregorian-from-absolute date))
16365 ((and (listp date) (= (length date) 3)) date)
16367 (setq date (org-parse-time-string date))
16368 (list (nth 4 date) (nth 3 date) (nth 5 date)))
16370 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
16372 (defun org-parse-time-string (s &optional nodefault)
16373 "Parse the standard Org-mode time string.
16374 This should be a lot faster than the normal `parse-time-string'.
16375 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
16376 hour and minute fields will be nil if not given."
16377 (if (string-match org-ts-regexp0 s)
16379 (if (or (match-beginning 8) (not nodefault))
16380 (string-to-number (or (match-string 8 s) "0")))
16381 (if (or (match-beginning 7) (not nodefault))
16382 (string-to-number (or (match-string 7 s) "0")))
16383 (string-to-number (match-string 4 s))
16384 (string-to-number (match-string 3 s))
16385 (string-to-number (match-string 2 s))
16387 (error "Not a standard Org-mode time string: %s" s)))
16389 (defun org-timestamp-up (&optional arg)
16390 "Increase the date item at the cursor by one.
16391 If the cursor is on the year, change the year. If it is on the month,
16392 the day or the time, change that.
16393 With prefix ARG, change by that many units."
16395 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
16397 (defun org-timestamp-down (&optional arg)
16398 "Decrease the date item at the cursor by one.
16399 If the cursor is on the year, change the year. If it is on the month,
16400 the day or the time, change that.
16401 With prefix ARG, change by that many units."
16403 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
16405 (defun org-timestamp-up-day (&optional arg)
16406 "Increase the date in the time stamp by one day.
16407 With prefix ARG, change that many days."
16409 (if (and (not (org-at-timestamp-p t))
16410 (org-at-heading-p))
16412 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
16414 (defun org-timestamp-down-day (&optional arg)
16415 "Decrease the date in the time stamp by one day.
16416 With prefix ARG, change that many days."
16418 (if (and (not (org-at-timestamp-p t))
16419 (org-at-heading-p))
16421 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
16423 (defun org-at-timestamp-p (&optional inactive-ok)
16424 "Determine if the cursor is in or at a timestamp."
16426 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
16428 (ans (or (looking-at tsr)
16430 (skip-chars-backward "^[<\n\r\t")
16431 (if (> (point) (point-min)) (backward-char 1))
16432 (and (looking-at tsr)
16433 (> (- (match-end 0) pos) -1))))))
16435 (boundp 'org-ts-what)
16438 ((= pos (match-beginning 0)) 'bracket)
16439 ;; Point is considered to be "on the bracket" whether
16440 ;; it's really on it or right after it.
16441 ((= pos (1- (match-end 0))) 'bracket)
16442 ((= pos (match-end 0)) 'after)
16443 ((org-pos-in-match-range pos 2) 'year)
16444 ((org-pos-in-match-range pos 3) 'month)
16445 ((org-pos-in-match-range pos 7) 'hour)
16446 ((org-pos-in-match-range pos 8) 'minute)
16447 ((or (org-pos-in-match-range pos 4)
16448 (org-pos-in-match-range pos 5)) 'day)
16449 ((and (> pos (or (match-end 8) (match-end 5)))
16450 (< pos (match-end 0)))
16451 (- pos (or (match-end 8) (match-end 5))))
16455 (defun org-toggle-timestamp-type ()
16456 "Toggle the type (<active> or [inactive]) of a time stamp."
16458 (when (org-at-timestamp-p t)
16459 (let ((beg (match-beginning 0)) (end (match-end 0))
16460 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
16463 (while (re-search-forward "[][<>]" end t)
16464 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
16466 (message "Timestamp is now %sactive"
16467 (if (equal (char-after beg) ?<) "" "in")))))
16469 (defvar org-clock-history) ; defined in org-clock.el
16470 (defvar org-clock-adjust-closest nil) ; defined in org-clock.el
16471 (defun org-timestamp-change (n &optional what updown)
16472 "Change the date in the time stamp at point.
16473 The date will be changed by N times WHAT. WHAT can be `day', `month',
16474 `year', `minute', `second'. If WHAT is not given, the cursor position
16475 in the timestamp determines what will be changed."
16476 (let ((origin (point)) origin-cat
16478 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
16481 ts time time0 fixnext clrgx)
16482 (if (not (org-at-timestamp-p t))
16483 (error "Not at a timestamp"))
16484 (if (and (not what) (eq org-ts-what 'bracket))
16485 (org-toggle-timestamp-type)
16486 ;; Point isn't on brackets. Remember the part of the time-stamp
16487 ;; the point was in. Indeed, size of time-stamps may change,
16488 ;; but point must be kept in the same category nonetheless.
16489 (setq origin-cat org-ts-what)
16490 (if (and (not what) (not (eq org-ts-what 'day))
16491 org-display-custom-times
16492 (get-text-property (point) 'display)
16493 (not (get-text-property (1- (point)) 'display)))
16494 (setq org-ts-what 'day))
16495 (setq org-ts-what (or what org-ts-what)
16496 inactive (= (char-after (match-beginning 0)) ?\[)
16497 ts (match-string 0))
16500 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?[-+][0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)*\\)[]>]"
16502 (setq extra (match-string 1 ts)))
16503 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
16505 (setq time0 (org-parse-time-string ts))
16507 (eq org-ts-what 'minute)
16508 (not current-prefix-arg))
16509 ;; This looks like s-up and s-down. Change by one rounding step.
16510 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
16511 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
16512 (setcar (cdr time0) (+ (nth 1 time0)
16513 (if (> n 0) (- rem) (- dm rem))))))
16515 (encode-time (or (car time0) 0)
16516 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
16517 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
16518 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
16519 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
16520 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
16522 (when (and (member org-ts-what '(hour minute))
16524 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
16525 (setq extra (org-modify-ts-extra
16527 (if (eq org-ts-what 'hour) 2 5)
16529 (when (integerp org-ts-what)
16530 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
16531 (if (eq what 'calendar)
16532 (let ((cal-date (org-get-date-from-calendar)))
16533 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
16534 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
16535 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
16536 (setcar time0 (or (car time0) 0))
16537 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
16538 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
16539 (setq time (apply 'encode-time time0))))
16540 ;; Insert the new time-stamp, and ensure point stays in the same
16541 ;; category as before (i.e. not after the last position in that
16543 (let ((pos (point)))
16544 ;; Stay before inserted string. `save-excursion' is of no use.
16545 (setq org-last-changed-timestamp
16546 (org-insert-time-stamp time with-hm inactive nil nil extra))
16549 (looking-at org-ts-regexp3)
16551 ;; `day' category ends before `hour' if any, or at
16552 ;; the end of the day name.
16553 ((eq origin-cat 'day)
16554 (min (or (match-beginning 7) (1- (match-end 5))) origin))
16555 ((eq origin-cat 'hour) (min (match-end 7) origin))
16556 ((eq origin-cat 'minute) (min (1- (match-end 8)) origin))
16557 ((integerp origin-cat) (min (1- (match-end 0)) origin))
16558 ;; `year' and `month' have both fixed size: point
16559 ;; couldn't have moved into another part.
16561 ;; Update clock if on a CLOCK line.
16562 (org-clock-update-time-maybe)
16563 ;; Maybe adjust the closest clock in `org-clock-history'
16564 (when org-clock-adjust-closest
16565 (if (not (and (org-at-clock-log-p)
16566 (< 1 (length (delq nil (mapcar (lambda(m) (marker-position m))
16567 org-clock-history))))))
16568 (message "No clock to adjust")
16569 (cond ((save-excursion ; fix previous clock?
16570 (re-search-backward org-ts-regexp0 nil t)
16571 (org-looking-back (concat org-clock-string " \\[")))
16572 (setq fixnext 1 clrgx (concat org-ts-regexp0 "\\] =>.*$")))
16573 ((save-excursion ; fix next clock?
16574 (re-search-backward org-ts-regexp0 nil t)
16575 (looking-at (concat org-ts-regexp0 "\\] =>")))
16576 (setq fixnext -1 clrgx (concat org-clock-string " \\[" org-ts-regexp0))))
16577 (save-window-excursion
16578 ;; Find closest clock to point, adjust the previous/next one in history
16579 (let* ((p (save-excursion (org-back-to-heading t)))
16580 (cl (mapcar (lambda(c) (abs (- (marker-position c) p))) org-clock-history))
16582 (+ fixnext (- (length cl) (or (length (member (apply #'min cl) cl)) 100))))
16583 (clfixpos (if (> 0 clfixnth) nil (nth clfixnth org-clock-history))))
16585 (message "No clock to adjust")
16587 (org-goto-marker-or-bmk clfixpos)
16589 (when (re-search-forward clrgx nil t)
16590 (goto-char (match-beginning 1))
16591 (let (org-clock-adjust-closest)
16592 (org-timestamp-change n org-ts-what updown))
16593 (message "Clock adjusted in %s for heading: %s"
16594 (file-name-nondirectory (buffer-file-name))
16595 (org-get-heading t t)))))))))
16596 ;; Try to recenter the calendar window, if any.
16597 (if (and org-calendar-follow-timestamp-change
16598 (get-buffer-window "*Calendar*" t)
16599 (memq org-ts-what '(day month year)))
16600 (org-recenter-calendar (time-to-days time))))))
16602 (defun org-modify-ts-extra (s pos n dm)
16603 "Change the different parts of the lead-time and repeat fields in timestamp."
16604 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
16606 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
16608 ((or (org-pos-in-match-range pos 2)
16609 (org-pos-in-match-range pos 3))
16610 (setq m (string-to-number (match-string 3 s))
16611 h (string-to-number (match-string 2 s)))
16612 (if (org-pos-in-match-range pos 2)
16614 (setq n (* dm (org-no-warnings (signum n))))
16615 (when (not (= 0 (setq rem (% m dm))))
16616 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
16618 (if (< m 0) (setq m (+ m 60) h (1- h)))
16619 (if (> m 59) (setq m (- m 60) h (1+ h)))
16620 (setq h (min 24 (max 0 h)))
16621 (setq ng 1 new (format "-%02d:%02d" h m)))
16622 ((org-pos-in-match-range pos 6)
16623 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
16624 ((org-pos-in-match-range pos 5)
16625 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
16627 ((org-pos-in-match-range pos 9)
16628 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
16629 ((org-pos-in-match-range pos 8)
16630 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
16634 (substring s 0 (match-beginning ng))
16636 (substring s (match-end ng))))))
16639 (defun org-recenter-calendar (date)
16640 "If the calendar is visible, recenter it to DATE."
16641 (let ((cwin (get-buffer-window "*Calendar*" t)))
16643 (let ((calendar-move-hook nil))
16644 (with-selected-window cwin
16645 (calendar-goto-date (if (listp date) date
16646 (calendar-gregorian-from-absolute date))))))))
16648 (defun org-goto-calendar (&optional arg)
16649 "Go to the Emacs calendar at the current date.
16650 If there is a time stamp in the current line, go to that date.
16651 A prefix ARG can be used to force the current date."
16653 (let ((tsr org-ts-regexp) diff
16654 (calendar-move-hook nil)
16655 (calendar-view-holidays-initially-flag nil)
16656 (calendar-view-diary-initially-flag nil))
16657 (if (or (org-at-timestamp-p)
16659 (beginning-of-line 1)
16660 (looking-at (concat ".*" tsr))))
16661 (let ((d1 (time-to-days (current-time)))
16663 (org-time-string-to-time (match-string 1)))))
16664 (setq diff (- d2 d1))))
16666 (calendar-goto-today)
16667 (if (and diff (not arg)) (calendar-forward-day diff))))
16669 (defun org-get-date-from-calendar ()
16670 "Return a list (month day year) of date at point in calendar."
16671 (with-current-buffer "*Calendar*"
16673 (calendar-cursor-to-date))))
16675 (defun org-date-from-calendar ()
16676 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
16677 If there is already a time stamp at the cursor position, update it."
16679 (if (org-at-timestamp-p t)
16680 (org-timestamp-change 0 'calendar)
16681 (let ((cal-date (org-get-date-from-calendar)))
16682 (org-insert-time-stamp
16683 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
16685 (defun org-minutes-to-hh:mm-string (m)
16686 "Compute H:MM from a number of minutes."
16687 (let ((h (/ m 60)))
16688 (setq m (- m (* 60 h)))
16689 (format org-time-clocksum-format h m)))
16691 (defun org-hh:mm-string-to-minutes (s)
16692 "Convert a string H:MM to a number of minutes.
16693 If the string is just a number, interpret it as minutes.
16694 In fact, the first hh:mm or number in the string will be taken,
16695 there can be extra stuff in the string.
16696 If no number is found, the return value is 0."
16699 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
16700 (+ (* (string-to-number (match-string 1 s)) 60)
16701 (string-to-number (match-string 2 s))))
16702 ((string-match "\\([0-9]+\\)" s)
16703 (string-to-number (match-string 1 s)))
16706 (defcustom org-effort-durations
16709 ("w" . ,(* 60 8 5))
16710 ("m" . ,(* 60 8 5 4))
16711 ("y" . ,(* 60 8 5 40)))
16712 "Conversion factor to minutes for an effort modifier.
16714 Each entry has the form (MODIFIER . MINUTES).
16716 In an effort string, a number followed by MODIFIER is multiplied
16717 by the specified number of MINUTES to obtain an effort in
16720 For example, if the value of this variable is ((\"hours\" . 60)), then an
16721 effort string \"2hours\" is equivalent to 120 minutes."
16724 :type '(alist :key-type (string :tag "Modifier")
16725 :value-type (number :tag "Minutes")))
16727 (defun org-duration-string-to-minutes (s &optional output-to-string)
16728 "Convert a duration string S to minutes.
16730 A bare number is interpreted as minutes, modifiers can be set by
16731 customizing `org-effort-durations' (which see).
16733 Entries containing a colon are interpreted as H:MM by
16734 `org-hh:mm-string-to-minutes'."
16736 (re (concat "\\([0-9.]+\\) *\\("
16737 (regexp-opt (mapcar 'car org-effort-durations))
16739 (while (string-match re s)
16740 (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
16741 (string-to-number (match-string 1 s))))
16742 (setq s (replace-match "" nil t s)))
16743 (setq result (floor result))
16744 (incf result (org-hh:mm-string-to-minutes s))
16745 (if output-to-string (number-to-string result) result)))
16749 (defun org-save-all-org-buffers ()
16750 "Save all Org-mode buffers without user confirmation."
16752 (message "Saving all Org-mode buffers...")
16753 (save-some-buffers t (lambda () (derived-mode-p 'org-mode)))
16754 (when (featurep 'org-id) (org-id-locations-save))
16755 (message "Saving all Org-mode buffers... done"))
16757 (defun org-revert-all-org-buffers ()
16758 "Revert all Org-mode buffers.
16759 Prompt for confirmation when there are unsaved changes.
16760 Be sure you know what you are doing before letting this function
16761 overwrite your changes.
16763 This function is useful in a setup where one tracks org files
16764 with a version control system, to revert on one machine after pulling
16765 changes from another. I believe the procedure must be like this:
16767 1. M-x org-save-all-org-buffers
16768 2. Pull changes from the other machine, resolve conflicts
16769 3. M-x org-revert-all-org-buffers"
16771 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
16774 (save-window-excursion
16777 (when (and (with-current-buffer b (derived-mode-p 'org-mode))
16778 (with-current-buffer b buffer-file-name))
16779 (org-pop-to-buffer-same-window b)
16780 (revert-buffer t 'no-confirm)))
16782 (when (and (featurep 'org-id) org-id-track-globally)
16783 (org-id-locations-load)))))
16788 (defun org-switchb (&optional arg)
16789 "Switch between Org buffers.
16790 With one prefix argument, restrict available buffers to files.
16791 With two prefix arguments, restrict available buffers to agenda files.
16793 Defaults to `iswitchb' for buffer name completion.
16794 Set `org-completion-use-ido' to make it use ido instead."
16796 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
16797 ((equal arg '(16)) (org-buffer-list 'agenda))
16798 (t (org-buffer-list))))
16799 (org-completion-use-iswitchb org-completion-use-iswitchb)
16800 (org-completion-use-ido org-completion-use-ido))
16801 (unless (or org-completion-use-ido org-completion-use-iswitchb)
16802 (setq org-completion-use-iswitchb t))
16803 (org-pop-to-buffer-same-window
16804 (org-icompleting-read "Org buffer: "
16805 (mapcar 'list (mapcar 'buffer-name blist))
16808 ;;; Define some older names previously used for this functionality
16810 (defalias 'org-ido-switchb 'org-switchb)
16812 (defalias 'org-iswitchb 'org-switchb)
16814 (defun org-buffer-list (&optional predicate exclude-tmp)
16815 "Return a list of Org buffers.
16816 PREDICATE can be `export', `files' or `agenda'.
16818 export restrict the list to Export buffers.
16819 files restrict the list to buffers visiting Org files.
16820 agenda restrict the list to buffers visiting agenda files.
16822 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
16824 (agenda-files (and (eq predicate 'agenda)
16825 (mapcar 'file-truename (org-agenda-files t))))
16828 ((eq predicate 'files)
16829 (lambda (b) (with-current-buffer b (derived-mode-p 'org-mode))))
16830 ((eq predicate 'export)
16831 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
16832 ((eq predicate 'agenda)
16834 (with-current-buffer b
16835 (and (derived-mode-p 'org-mode)
16836 (setq bfn (buffer-file-name b))
16837 (member (file-truename bfn) agenda-files)))))
16838 (t (lambda (b) (with-current-buffer b
16839 (or (derived-mode-p 'org-mode)
16840 (string-match "\*Org .*Export"
16841 (buffer-name b)))))))))
16845 (if (and (funcall filter b)
16846 (or (not exclude-tmp)
16847 (not (string-match "tmp" (buffer-name b)))))
16852 (defun org-agenda-files (&optional unrestricted archives)
16853 "Get the list of agenda files.
16854 Optional UNRESTRICTED means return the full list even if a restriction
16855 is currently in place.
16856 When ARCHIVES is t, include all archive files that are really being
16857 used by the agenda files. If ARCHIVE is `ifmode', do this only if
16858 `org-agenda-archives-mode' is t."
16861 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
16862 ((stringp org-agenda-files) (org-read-agenda-file-list))
16863 ((listp org-agenda-files) org-agenda-files)
16864 (t (error "Invalid value of `org-agenda-files'")))))
16865 (setq files (apply 'append
16866 (mapcar (lambda (f)
16867 (if (file-directory-p f)
16869 f t org-agenda-file-regexp)
16872 (when org-agenda-skip-unavailable-files
16873 (setq files (delq nil
16876 (and (file-readable-p file) file)))
16878 (when (or (eq archives t)
16879 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
16880 (setq files (org-add-archive-files files)))
16883 (defun org-agenda-file-p (&optional file)
16884 "Return non-nil, if FILE is an agenda file.
16885 If FILE is omitted, use the file associated with the current
16887 (member (or file (buffer-file-name))
16888 (org-agenda-files t)))
16890 (defun org-edit-agenda-file-list ()
16891 "Edit the list of agenda files.
16892 Depending on setup, this either uses customize to edit the variable
16893 `org-agenda-files', or it visits the file that is holding the list. In the
16894 latter case, the buffer is set up in a way that saving it automatically kills
16895 the buffer and restores the previous window configuration."
16897 (if (stringp org-agenda-files)
16898 (let ((cw (current-window-configuration)))
16899 (find-file org-agenda-files)
16900 (org-set-local 'org-window-configuration cw)
16901 (org-add-hook 'after-save-hook
16903 (set-window-configuration
16904 (prog1 org-window-configuration
16905 (kill-buffer (current-buffer))))
16906 (org-install-agenda-files-menu)
16907 (message "New agenda file list installed"))
16909 (message "%s" (substitute-command-keys
16910 "Edit list and finish with \\[save-buffer]")))
16911 (customize-variable 'org-agenda-files)))
16913 (defun org-store-new-agenda-file-list (list)
16914 "Set new value for the agenda file list and save it correctly."
16915 (if (stringp org-agenda-files)
16916 (let ((fe (org-read-agenda-file-list t)) b u)
16917 (while (setq b (find-buffer-visiting org-agenda-files))
16919 (with-temp-file org-agenda-files
16922 (lambda (f) ;; Keep un-expanded entries.
16923 (if (setq u (assoc f fe))
16928 (let ((org-mode-hook nil) (org-inhibit-startup t)
16929 (org-insert-mode-line-in-empty-file nil))
16930 (setq org-agenda-files list)
16931 (customize-save-variable 'org-agenda-files org-agenda-files))))
16933 (defun org-read-agenda-file-list (&optional pair-with-expansion)
16934 "Read the list of agenda files from a file.
16935 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
16936 filenames, used by `org-store-new-agenda-file-list' to write back
16937 un-expanded file names."
16938 (when (file-directory-p org-agenda-files)
16939 (error "`org-agenda-files' cannot be a single directory"))
16940 (when (stringp org-agenda-files)
16942 (insert-file-contents org-agenda-files)
16945 (let ((e (expand-file-name (substitute-in-file-name f)
16947 (if pair-with-expansion
16950 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
16953 (defun org-cycle-agenda-files ()
16954 "Cycle through the files in `org-agenda-files'.
16955 If the current buffer visits an agenda file, find the next one in the list.
16956 If the current buffer does not, find the first agenda file."
16958 (let* ((fs (org-agenda-files t))
16959 (files (append fs (list (car fs))))
16960 (tcf (if buffer-file-name (file-truename buffer-file-name)))
16962 (unless files (error "No agenda files"))
16964 (while (setq file (pop files))
16965 (if (equal (file-truename file) tcf)
16967 (find-file (car files))
16969 (find-file (car fs)))
16970 (if (buffer-base-buffer) (org-pop-to-buffer-same-window (buffer-base-buffer)))))
16972 (defun org-agenda-file-to-front (&optional to-end)
16973 "Move/add the current file to the top of the agenda file list.
16974 If the file is not present in the list, it is added to the front. If it is
16975 present, it is moved there. With optional argument TO-END, add/move to the
16978 (let ((org-agenda-skip-unavailable-files nil)
16979 (file-alist (mapcar (lambda (x)
16980 (cons (file-truename x) x))
16981 (org-agenda-files t)))
16982 (ctf (file-truename buffer-file-name))
16984 (setq x (assoc ctf file-alist) had x)
16986 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
16988 (setq file-alist (append (delq x file-alist) (list x)))
16989 (setq file-alist (cons x (delq x file-alist))))
16990 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
16991 (org-install-agenda-files-menu)
16992 (message "File %s to %s of agenda file list"
16993 (if had "moved" "added") (if to-end "end" "front"))))
16995 (defun org-remove-file (&optional file)
16996 "Remove current file from the list of files in variable `org-agenda-files'.
16997 These are the files which are being checked for agenda entries.
16998 Optional argument FILE means use this file instead of the current."
17000 (let* ((org-agenda-skip-unavailable-files nil)
17001 (file (or file buffer-file-name))
17002 (true-file (file-truename file))
17003 (afile (abbreviate-file-name file))
17004 (files (delq nil (mapcar
17006 (if (equal true-file
17009 (org-agenda-files t)))))
17010 (if (not (= (length files) (length (org-agenda-files t))))
17012 (org-store-new-agenda-file-list files)
17013 (org-install-agenda-files-menu)
17014 (message "Removed file: %s" afile))
17015 (message "File was not in list: %s (not removed)" afile))))
17017 (defun org-file-menu-entry (file)
17018 (vector file (list 'find-file file) t))
17020 (defun org-check-agenda-file (file)
17021 "Make sure FILE exists. If not, ask user what to do."
17022 (when (not (file-exists-p file))
17023 (message "non-existent agenda file %s. [R]emove from list or [A]bort?"
17024 (abbreviate-file-name file))
17025 (let ((r (downcase (read-char-exclusive))))
17028 (org-remove-file file)
17029 (throw 'nextfile t))
17030 (t (error "Abort"))))))
17032 (defun org-get-agenda-file-buffer (file)
17033 "Get a buffer visiting FILE. If the buffer needs to be created, add
17034 it to the list of buffers which might be released later."
17035 (let ((buf (org-find-base-buffer-visiting file)))
17037 buf ; just return it
17038 ;; Make a new buffer and remember it
17039 (setq buf (find-file-noselect file))
17040 (if buf (push buf org-agenda-new-buffers))
17043 (defun org-release-buffers (blist)
17044 "Release all buffers in list, asking the user for confirmation when needed.
17045 When a buffer is unmodified, it is just killed. When modified, it is saved
17046 \(if the user agrees) and then killed."
17048 (while (setq buf (pop blist))
17049 (setq file (buffer-file-name buf))
17050 (when (and (buffer-modified-p buf)
17052 (y-or-n-p (format "Save file %s? " file)))
17053 (with-current-buffer buf (save-buffer)))
17054 (kill-buffer buf))))
17056 (defun org-agenda-prepare-buffers (files)
17057 "Create buffers for all agenda files, protect archived trees and comments."
17059 (let ((pa '(:org-archived t))
17060 (pc '(:org-comment t))
17061 (pall '(:org-archived t :org-comment t))
17062 (inhibit-read-only t)
17063 (rea (concat ":" org-archive-tag ":"))
17067 (while (setq file (pop files))
17071 (org-check-agenda-file file)
17072 (set-buffer (org-get-agenda-file-buffer file)))
17074 (setq bmp (buffer-modified-p))
17075 (org-refresh-category-properties)
17076 (setq org-todo-keywords-for-agenda
17077 (append org-todo-keywords-for-agenda org-todo-keywords-1))
17078 (setq org-done-keywords-for-agenda
17079 (append org-done-keywords-for-agenda org-done-keywords))
17080 (setq org-todo-keyword-alist-for-agenda
17081 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
17082 (setq org-drawers-for-agenda
17083 (append org-drawers-for-agenda org-drawers))
17084 (setq org-tag-alist-for-agenda
17085 (append org-tag-alist-for-agenda org-tag-alist))
17088 (remove-text-properties (point-min) (point-max) pall)
17089 (when org-agenda-skip-archived-trees
17090 (goto-char (point-min))
17091 (while (re-search-forward rea nil t)
17092 (if (org-at-heading-p t)
17093 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
17094 (goto-char (point-min))
17095 (setq re (format org-heading-keyword-regexp-format
17096 org-comment-string))
17097 (while (re-search-forward re nil t)
17098 (add-text-properties
17099 (match-beginning 0) (org-end-of-subtree t) pc)))
17100 (set-buffer-modified-p bmp)))))
17101 (setq org-todo-keywords-for-agenda
17102 (org-uniquify org-todo-keywords-for-agenda))
17103 (setq org-todo-keyword-alist-for-agenda
17104 (org-uniquify org-todo-keyword-alist-for-agenda)
17105 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
17107 ;;;; Embedded LaTeX
17109 (defvar org-cdlatex-mode-map (make-sparse-keymap)
17110 "Keymap for the minor `org-cdlatex-mode'.")
17112 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
17113 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
17114 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
17115 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
17116 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
17118 (defvar org-cdlatex-texmathp-advice-is-done nil
17119 "Flag remembering if we have applied the advice to texmathp already.")
17121 (define-minor-mode org-cdlatex-mode
17122 "Toggle the minor `org-cdlatex-mode'.
17123 This mode supports entering LaTeX environment and math in LaTeX fragments
17125 \\{org-cdlatex-mode-map}"
17127 (when org-cdlatex-mode
17129 (run-hooks 'cdlatex-mode-hook)
17130 (cdlatex-compute-tables))
17131 (unless org-cdlatex-texmathp-advice-is-done
17132 (setq org-cdlatex-texmathp-advice-is-done t)
17133 (defadvice texmathp (around org-math-always-on activate)
17134 "Always return t in org-mode buffers.
17135 This is because we want to insert math symbols without dollars even outside
17136 the LaTeX math segments. If Orgmode thinks that point is actually inside
17137 an embedded LaTeX fragment, let texmathp do its job.
17138 \\[org-cdlatex-mode-map]"
17142 ((not (derived-mode-p 'org-mode)) ad-do-it)
17143 ((eq this-command 'cdlatex-math-symbol)
17144 (setq ad-return-value t
17145 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
17147 (let ((p (org-inside-LaTeX-fragment-p)))
17148 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
17149 (setq ad-return-value t
17150 texmathp-why '("Org-mode embedded math" . 0))
17151 (if p ad-do-it)))))))))
17153 (defun turn-on-org-cdlatex ()
17154 "Unconditionally turn on `org-cdlatex-mode'."
17155 (org-cdlatex-mode 1))
17157 (defun org-inside-LaTeX-fragment-p ()
17158 "Test if point is inside a LaTeX fragment.
17159 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
17160 sequence appearing also before point.
17161 Even though the matchers for math are configurable, this function assumes
17162 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
17163 delimiters are skipped when they have been removed by customization.
17164 The return value is nil, or a cons cell with the delimiter and the
17165 position of this delimiter.
17167 This function does a reasonably good job, but can locally be fooled by
17168 for example currency specifications. For example it will assume being in
17169 inline math after \"$22.34\". The LaTeX fragment formatter will only format
17170 fragments that are properly closed, but during editing, we have to live
17171 with the uncertainty caused by missing closing delimiters. This function
17172 looks only before point, not after."
17174 (let ((pos (point))
17175 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
17177 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
17179 dd-on str (start 0) m re)
17182 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
17183 re (nth 1 (assoc "$" org-latex-regexps)))
17184 (while (string-match re str start)
17186 ((= (match-end 0) (length str))
17187 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
17188 ((= (match-end 0) (- (length str) 5))
17190 (t (setq start (match-end 0))))))
17191 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
17193 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
17194 (and (match-beginning 2) (throw 'exit nil))
17196 (while (re-search-backward "\\$\\$" lim t)
17197 (setq dd-on (not dd-on)))
17199 (if dd-on (cons "$$" m))))))
17201 (defun org-inside-latex-macro-p ()
17202 "Is point inside a LaTeX macro or its arguments?"
17205 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
17207 (defun org-try-cdlatex-tab ()
17208 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
17209 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
17210 - inside a LaTeX fragment, or
17211 - after the first word in a line, where an abbreviation expansion could
17212 insert a LaTeX environment."
17213 (when org-cdlatex-mode
17215 ;; Before any word on the line: No expansion possible.
17216 ((save-excursion (skip-chars-backward " \t") (bolp)) nil)
17217 ;; Just after first word on the line: Expand it. Make sure it
17218 ;; cannot happen on headlines, though.
17220 (skip-chars-backward "a-zA-Z0-9*")
17221 (skip-chars-backward " \t")
17222 (and (bolp) (not (org-at-heading-p))))
17224 ((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
17226 (defun org-cdlatex-underscore-caret (&optional arg)
17227 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
17228 Revert to the normal definition outside of these fragments."
17230 (if (org-inside-LaTeX-fragment-p)
17231 (call-interactively 'cdlatex-sub-superscript)
17232 (let (org-cdlatex-mode)
17233 (call-interactively (key-binding (vector last-input-event))))))
17235 (defun org-cdlatex-math-modify (&optional arg)
17236 "Execute `cdlatex-math-modify' in LaTeX fragments.
17237 Revert to the normal definition outside of these fragments."
17239 (if (org-inside-LaTeX-fragment-p)
17240 (call-interactively 'cdlatex-math-modify)
17241 (let (org-cdlatex-mode)
17242 (call-interactively (key-binding (vector last-input-event))))))
17244 (defvar org-latex-fragment-image-overlays nil
17245 "List of overlays carrying the images of latex fragments.")
17246 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
17248 (defun org-remove-latex-fragment-image-overlays ()
17249 "Remove all overlays with LaTeX fragment images in current buffer."
17250 (mapc 'delete-overlay org-latex-fragment-image-overlays)
17251 (setq org-latex-fragment-image-overlays nil))
17253 (defun org-preview-latex-fragment (&optional subtree)
17254 "Preview the LaTeX fragment at point, or all locally or globally.
17255 If the cursor is in a LaTeX fragment, create the image and overlay
17256 it over the source code. If there is no fragment at point, display
17257 all fragments in the current text, from one headline to the next. With
17258 prefix SUBTREE, display all fragments in the current subtree. With a
17259 double prefix arg \\[universal-argument] \\[universal-argument], or when \
17260 the cursor is before the first headline,
17261 display all fragments in the buffer.
17262 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
17264 (unless buffer-file-name
17265 (error "Can't preview LaTeX fragment in a non-file buffer"))
17266 (org-remove-latex-fragment-image-overlays)
17269 (let (beg end at msg)
17271 ((or (equal subtree '(16))
17272 (not (save-excursion
17273 (re-search-backward org-outline-regexp-bol nil t))))
17274 (setq beg (point-min) end (point-max)
17275 msg "Creating images for buffer...%s"))
17276 ((equal subtree '(4))
17277 (org-back-to-heading)
17278 (setq beg (point) end (org-end-of-subtree t)
17279 msg "Creating images for subtree...%s"))
17281 (if (setq at (org-inside-LaTeX-fragment-p))
17282 (goto-char (max (point-min) (- (cdr at) 2)))
17283 (org-back-to-heading))
17284 (setq beg (point) end (progn (outline-next-heading) (point))
17285 msg (if at "Creating image...%s"
17286 "Creating images for entry...%s"))))
17288 (narrow-to-region beg end)
17291 (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
17292 (file-name-nondirectory
17293 buffer-file-name)))
17294 default-directory 'overlays msg at 'forbuffer
17295 org-latex-create-formula-image-program)
17296 (message msg "done. Use `C-c C-c' to remove images.")))))
17298 (defvar org-latex-regexps
17299 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
17300 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
17301 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
17302 ("$1" "\\([^$]\\|^\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
17303 ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
17304 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
17305 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
17306 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
17307 "Regular expressions for matching embedded LaTeX.")
17309 (defvar org-export-have-math nil) ;; dynamic scoping
17310 (defun org-format-latex (prefix &optional dir overlays msg at
17311 forbuffer processing-type)
17312 "Replace LaTeX fragments with links to an image, and produce images.
17313 Some of the options can be changed using the variable
17314 `org-format-latex-options'."
17315 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
17316 (let* ((prefixnodir (file-name-nondirectory prefix))
17317 (absprefix (expand-file-name prefix dir))
17318 (todir (file-name-directory absprefix))
17319 (opt org-format-latex-options)
17320 (matchers (plist-get opt :matchers))
17321 (re-list org-latex-regexps)
17322 (org-format-latex-header-extra
17323 (plist-get (org-infile-export-plist) :latex-header-extra))
17324 (cnt 0) txt hash link beg end re e checkdir
17325 executables-checked string
17326 m n block-type block linkfile movefile ov)
17327 ;; Check the different regular expressions
17328 (while (setq e (pop re-list))
17329 (setq m (car e) re (nth 1 e) n (nth 2 e) block-type (nth 3 e)
17330 block (if block-type "\n\n" ""))
17331 (when (member m matchers)
17332 (goto-char (point-min))
17333 (while (re-search-forward re nil t)
17334 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
17335 (not (get-text-property (match-beginning n)
17338 (not (eq (get-char-property (match-beginning n)
17340 'org-latex-overlay))))
17341 (setq org-export-have-math t)
17343 ((eq processing-type 'verbatim)
17344 ;; Leave the text verbatim, just protect it
17345 (add-text-properties (match-beginning n) (match-end n)
17346 '(org-protected t)))
17347 ((eq processing-type 'mathjax)
17348 ;; Prepare for MathJax processing
17349 (setq string (match-string n))
17350 (if (member m '("$" "$1"))
17352 (delete-region (match-beginning n) (match-end n))
17353 (goto-char (match-beginning n))
17354 (insert (org-add-props (concat "\\(" (substring string 1 -1)
17356 '(org-protected t))))
17357 (add-text-properties (match-beginning n) (match-end n)
17358 '(org-protected t))))
17359 ((or (eq processing-type 'dvipng)
17360 (eq processing-type 'imagemagick))
17361 ;; Process to an image
17362 (setq txt (match-string n)
17363 beg (match-beginning n) end (match-end n)
17365 (let (print-length print-level) ; make sure full list is printed
17366 (setq hash (sha1 (prin1-to-string
17367 (list org-format-latex-header
17368 org-format-latex-header-extra
17369 org-export-latex-default-packages-alist
17370 org-export-latex-packages-alist
17371 org-format-latex-options
17373 linkfile (format "%s_%s.png" prefix hash)
17374 movefile (format "%s_%s.png" absprefix hash)))
17375 (setq link (concat block "[[file:" linkfile "]]" block))
17376 (if msg (message msg cnt))
17378 (unless checkdir ; make sure the directory exists
17380 (or (file-directory-p todir) (make-directory todir t)))
17382 ((eq processing-type 'dvipng)
17383 (unless executables-checked
17384 (org-check-external-command
17385 "latex" "needed to convert LaTeX fragments to images")
17386 (org-check-external-command
17387 "dvipng" "needed to convert LaTeX fragments to images")
17388 (setq executables-checked t))
17389 (unless (file-exists-p movefile)
17390 (org-create-formula-image-with-dvipng
17391 txt movefile opt forbuffer)))
17392 ((eq processing-type 'imagemagick)
17393 (unless executables-checked
17394 (org-check-external-command
17395 "convert" "you need to install imagemagick")
17396 (setq executables-checked t))
17397 (unless (file-exists-p movefile)
17398 (org-create-formula-image-with-imagemagick
17399 txt movefile opt forbuffer))))
17403 (if (eq (overlay-get o 'org-overlay-type)
17404 'org-latex-overlay)
17405 (delete-overlay o)))
17406 (overlays-in beg end))
17407 (setq ov (make-overlay beg end))
17408 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
17409 (if (featurep 'xemacs)
17411 (overlay-put ov 'invisible t)
17414 (make-glyph (vector 'png :file movefile))))
17417 (list 'image :type 'png :file movefile :ascent 'center)))
17418 (push ov org-latex-fragment-image-overlays)
17420 (delete-region beg end)
17421 (insert (org-add-props link
17422 (list 'org-latex-src
17423 (replace-regexp-in-string
17425 'org-latex-src-embed-type
17426 (if block-type 'paragraph 'character))))))
17427 ((eq processing-type 'mathml)
17428 ;; Process to MathML
17429 (unless executables-checked
17430 (unless (save-match-data (org-format-latex-mathml-available-p))
17431 (error "LaTeX to MathML converter not configured"))
17432 (setq executables-checked t))
17433 (setq txt (match-string n)
17434 beg (match-beginning n) end (match-end n)
17436 (if msg (message msg cnt))
17438 (delete-region beg end)
17439 (insert (org-format-latex-as-mathml
17440 txt block-type prefix dir)))
17442 (error "Unknown conversion type %s for latex fragments"
17443 processing-type)))))))))
17445 (defun org-create-math-formula (latex-frag &optional mathml-file)
17446 "Convert LATEX-FRAG to MathML and store it in MATHML-FILE.
17447 Use `org-latex-to-mathml-convert-command'. If the conversion is
17448 sucessful, return the portion between \"<math...> </math>\"
17449 elements otherwise return nil. When MATHML-FILE is specified,
17450 write the results in to that file. When invoked as an
17451 interactive command, prompt for LATEX-FRAG, with initial value
17452 set to the current active region and echo the results for user
17454 (interactive (list (let ((frag (when (org-region-active-p)
17455 (buffer-substring-no-properties
17456 (region-beginning) (region-end)))))
17457 (read-string "LaTeX Fragment: " frag nil frag))))
17458 (unless latex-frag (error "Invalid latex-frag"))
17459 (let* ((tmp-in-file (file-relative-name
17460 (make-temp-name (expand-file-name "ltxmathml-in"))))
17461 (ignore (write-region latex-frag nil tmp-in-file))
17462 (tmp-out-file (file-relative-name
17463 (make-temp-name (expand-file-name "ltxmathml-out"))))
17465 org-latex-to-mathml-convert-command
17466 `((?j . ,(shell-quote-argument
17467 (expand-file-name org-latex-to-mathml-jar-file)))
17468 (?I . ,(shell-quote-argument tmp-in-file))
17469 (?o . ,(shell-quote-argument tmp-out-file)))))
17470 mathml shell-command-output)
17471 (when (org-called-interactively-p 'any)
17472 (unless (org-format-latex-mathml-available-p)
17473 (error "LaTeX to MathML converter not configured")))
17474 (message "Running %s" cmd)
17475 (setq shell-command-output (shell-command-to-string cmd))
17477 (when (file-readable-p tmp-out-file)
17478 (with-current-buffer (find-file-noselect tmp-out-file t)
17479 (goto-char (point-min))
17480 (when (re-search-forward
17483 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">")
17485 (regexp-quote "</math>")) nil t)
17486 (prog1 (match-string 0) (kill-buffer))))))
17490 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" mathml))
17492 (write-region mathml nil mathml-file))
17493 (when (org-called-interactively-p 'any)
17495 ((message "LaTeX to MathML conversion failed")
17496 (message shell-command-output)))
17497 (delete-file tmp-in-file)
17498 (when (file-exists-p tmp-out-file)
17499 (delete-file tmp-out-file))
17502 (defun org-format-latex-as-mathml (latex-frag latex-frag-type
17503 prefix &optional dir)
17504 "Use `org-create-math-formula' but check local cache first."
17505 (let* ((absprefix (expand-file-name prefix dir))
17506 (print-length nil) (print-level nil)
17507 (formula-id (concat
17512 org-latex-to-mathml-convert-command)))))
17513 (formula-cache (format "%s-%s.mathml" absprefix formula-id))
17514 (formula-cache-dir (file-name-directory formula-cache)))
17516 (unless (file-directory-p formula-cache-dir)
17517 (make-directory formula-cache-dir t))
17519 (unless (file-exists-p formula-cache)
17520 (org-create-math-formula latex-frag formula-cache))
17522 (if (file-exists-p formula-cache)
17523 ;; Successful conversion. Return the link to MathML file.
17525 (format "[[file:%s]]" (file-relative-name formula-cache dir))
17526 (list 'org-latex-src (replace-regexp-in-string "\"" "" latex-frag)
17527 'org-latex-src-embed-type (if latex-frag-type
17528 'paragraph 'character)))
17529 ;; Failed conversion. Return the LaTeX fragment verbatim
17530 (add-text-properties
17531 0 (1- (length latex-frag)) '(org-protected t) latex-frag)
17534 ;; This function borrows from Ganesh Swami's latex2png.el
17535 (defun org-create-formula-image-with-dvipng (string tofile options buffer)
17536 "This calls dvipng."
17537 (require 'org-latex)
17538 (let* ((tmpdir (if (featurep 'xemacs)
17540 temporary-file-directory))
17541 (texfilebase (make-temp-name
17542 (expand-file-name "orgtex" tmpdir)))
17543 (texfile (concat texfilebase ".tex"))
17544 (dvifile (concat texfilebase ".dvi"))
17545 (pngfile (concat texfilebase ".png"))
17546 (fnh (if (featurep 'xemacs)
17547 (font-height (face-font 'default))
17548 (face-attribute 'default :height nil)))
17549 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
17550 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
17551 (fg (or (plist-get options (if buffer :foreground :html-foreground))
17553 (bg (or (plist-get options (if buffer :background :html-background))
17555 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
17556 (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
17557 (with-temp-file texfile
17558 (insert (org-splice-latex-header
17559 org-format-latex-header
17560 org-export-latex-default-packages-alist
17561 org-export-latex-packages-alist t
17562 org-format-latex-header-extra))
17563 (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
17564 (require 'org-latex)
17565 (org-export-latex-fix-inputenc))
17566 (let ((dir default-directory))
17567 (condition-case nil
17570 (call-process "latex" nil nil nil texfile))
17573 (if (not (file-exists-p dvifile))
17574 (progn (message "Failed to create dvi file from %s" texfile) nil)
17575 (condition-case nil
17576 (if (featurep 'xemacs)
17577 (call-process "dvipng" nil nil nil
17582 (call-process "dvipng" nil nil nil
17585 ;;"-x" scale "-y" scale
17590 (if (not (file-exists-p pngfile))
17591 (if org-format-latex-signal-error
17592 (error "Failed to create png file from %s" texfile)
17593 (message "Failed to create png file from %s" texfile)
17595 ;; Use the requested file name and clean up
17596 (copy-file pngfile tofile 'replace)
17597 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png" ".out") do
17598 (if (file-exists-p (concat texfilebase e))
17599 (delete-file (concat texfilebase e))))
17602 (defvar org-latex-to-pdf-process) ;; Defined in org-latex.el
17603 (defun org-create-formula-image-with-imagemagick (string tofile options buffer)
17604 "This calls convert, which is included into imagemagick."
17605 (require 'org-latex)
17606 (let* ((tmpdir (if (featurep 'xemacs)
17608 temporary-file-directory))
17609 (texfilebase (make-temp-name
17610 (expand-file-name "orgtex" tmpdir)))
17611 (texfile (concat texfilebase ".tex"))
17612 (pdffile (concat texfilebase ".pdf"))
17613 (pngfile (concat texfilebase ".png"))
17614 (fnh (if (featurep 'xemacs)
17615 (font-height (face-font 'default))
17616 (face-attribute 'default :height nil)))
17617 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
17618 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
17619 (fg (or (plist-get options (if buffer :foreground :html-foreground))
17621 (bg (or (plist-get options (if buffer :background :html-background))
17623 (if (eq fg 'default) (setq fg (org-latex-color :foreground))
17624 (setq fg (org-latex-color-format fg)))
17625 (if (eq bg 'default) (setq bg (org-latex-color :background))
17626 (setq bg (org-latex-color-format
17627 (if (string= bg "Transparent")(setq bg "white")))))
17628 (with-temp-file texfile
17629 (insert (org-splice-latex-header
17630 org-format-latex-header
17631 org-export-latex-default-packages-alist
17632 org-export-latex-packages-alist t
17633 org-format-latex-header-extra))
17634 (insert "\n\\begin{document}\n"
17635 "\\definecolor{fg}{rgb}{" fg "}\n"
17636 "\\definecolor{bg}{rgb}{" bg "}\n"
17637 "\n\\pagecolor{bg}\n"
17641 "\n\\end{document}\n" )
17642 (require 'org-latex)
17643 (org-export-latex-fix-inputenc))
17644 (let ((dir default-directory) cmd cmds latex-frags-cmds)
17645 (condition-case nil
17648 (setq cmds org-latex-to-pdf-process)
17650 (setq latex-frags-cmds (pop cmds))
17651 (if (listp latex-frags-cmds)
17653 (setq latex-frags-cmds (list (car org-latex-to-pdf-process)))))
17654 (while latex-frags-cmds
17655 (setq cmd (pop latex-frags-cmds))
17656 (while (string-match "%b" cmd)
17657 (setq cmd (replace-match
17659 (shell-quote-argument texfile))
17661 (while (string-match "%f" cmd)
17662 (setq cmd (replace-match
17664 (shell-quote-argument (file-name-nondirectory texfile)))
17666 (while (string-match "%o" cmd)
17667 (setq cmd (replace-match
17669 (shell-quote-argument (file-name-directory texfile)))
17671 (setq cmd (split-string cmd))
17672 (eval (append (list 'call-process (pop cmd) nil nil nil) cmd))))
17675 (if (not (file-exists-p pdffile))
17676 (progn (message "Failed to create pdf file from %s" texfile) nil)
17677 (condition-case nil
17678 (if (featurep 'xemacs)
17679 (call-process "convert" nil nil nil
17685 ;; "-sharpen" "0x1.0"
17687 (call-process "convert" nil nil nil
17693 ; "-sharpen" "0x1.0"
17696 (if (not (file-exists-p pngfile))
17697 (if org-format-latex-signal-error
17698 (error "Failed to create png file from %s" texfile)
17699 (message "Failed to create png file from %s" texfile)
17701 ;; Use the requested file name and clean up
17702 (copy-file pngfile tofile 'replace)
17703 (loop for e in '(".pdf" ".tex" ".aux" ".log" ".png") do
17704 (if (file-exists-p (concat texfilebase e))
17705 (delete-file (concat texfilebase e))))
17708 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
17709 "Fill a LaTeX header template TPL.
17710 In the template, the following place holders will be recognized:
17712 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
17713 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
17714 [PACKAGES] \\usepackage statements for PKG
17715 [NO-PACKAGES] do not include PKG
17716 [EXTRA] the string EXTRA
17717 [NO-EXTRA] do not include EXTRA
17719 For backward compatibility, if both the positive and the negative place
17720 holder is missing, the positive one (without the \"NO-\") will be
17721 assumed to be present at the end of the template.
17722 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
17724 SNIPPETS-P indicates if this is run to create snippet images for HTML."
17725 (let (rpl (end ""))
17726 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
17727 (setq rpl (if (or (match-end 1) (not def-pkg))
17728 "" (org-latex-packages-to-string def-pkg snippets-p t))
17729 tpl (replace-match rpl t t tpl))
17730 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
17732 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
17733 (setq rpl (if (or (match-end 1) (not pkg))
17734 "" (org-latex-packages-to-string pkg snippets-p t))
17735 tpl (replace-match rpl t t tpl))
17738 (org-latex-packages-to-string pkg snippets-p)))))
17740 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
17741 (setq rpl (if (or (match-end 1) (not extra))
17742 "" (concat extra "\n"))
17743 tpl (replace-match rpl t t tpl))
17744 (if (and extra (string-match "\\S-" extra))
17745 (setq end (concat end "\n" extra))))
17747 (if (string-match "\\S-" end)
17748 (concat tpl "\n" end)
17751 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
17752 "Turn an alist of packages into a string with the \\usepackage macros."
17753 (setq pkg (mapconcat (lambda(p)
17756 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
17757 (format "%% Package %s omitted" (cadr p)))
17758 ((equal "" (car p))
17759 (format "\\usepackage{%s}" (cadr p)))
17761 (format "\\usepackage[%s]{%s}"
17762 (car p) (cadr p)))))
17765 (if newline (concat pkg "\n") pkg))
17767 (defun org-dvipng-color (attr)
17768 "Return a RGB color specification for dvipng."
17769 (apply 'format "rgb %s %s %s"
17770 (mapcar 'org-normalize-color
17771 (if (featurep 'xemacs)
17772 (color-rgb-components
17773 (face-property 'default
17774 (cond ((eq attr :foreground) 'foreground)
17775 ((eq attr :background) 'background))))
17776 (color-values (face-attribute 'default attr nil))))))
17778 (defun org-latex-color (attr)
17779 "Return a RGB color for the LaTeX color package."
17780 (apply 'format "%s,%s,%s"
17781 (mapcar 'org-normalize-color
17782 (if (featurep 'xemacs)
17783 (color-rgb-components
17784 (face-property 'default
17785 (cond ((eq attr :foreground) 'foreground)
17786 ((eq attr :background) 'background))))
17787 (color-values (face-attribute 'default attr nil))))))
17789 (defun org-latex-color-format (color-name)
17790 "Convert COLOR-NAME to a RGB color value."
17791 (apply 'format "%s,%s,%s"
17792 (mapcar 'org-normalize-color
17793 (color-values color-name))))
17795 (defun org-normalize-color (value)
17796 "Return string to be used as color value for an RGB component."
17797 (format "%g" (/ value 65535.0)))
17802 (defvar org-inline-image-overlays nil)
17803 (make-variable-buffer-local 'org-inline-image-overlays)
17805 (defun org-toggle-inline-images (&optional include-linked)
17806 "Toggle the display of inline images.
17807 INCLUDE-LINKED is passed to `org-display-inline-images'."
17809 (if org-inline-image-overlays
17811 (org-remove-inline-images)
17812 (message "Inline image display turned off"))
17813 (org-display-inline-images include-linked)
17814 (if org-inline-image-overlays
17815 (message "%d images displayed inline"
17816 (length org-inline-image-overlays))
17817 (message "No images to display inline"))))
17819 (defun org-redisplay-inline-images ()
17820 "Refresh the display of inline images."
17822 (if (not org-inline-image-overlays)
17823 (org-toggle-inline-images)
17824 (org-toggle-inline-images)
17825 (org-toggle-inline-images)))
17827 (defun org-display-inline-images (&optional include-linked refresh beg end)
17828 "Display inline images.
17829 Normally only links without a description part are inlined, because this
17830 is how it will work for export. When INCLUDE-LINKED is set, also links
17831 with a description part will be inlined. This can be nice for a quick
17832 look at those images, but it does not reflect what exported files will look
17834 When REFRESH is set, refresh existing images between BEG and END.
17835 This will create new image displays only if necessary.
17836 BEG and END default to the buffer boundaries."
17839 (org-remove-inline-images)
17840 (if (fboundp 'clear-image-cache) (clear-image-cache)))
17844 (setq beg (or beg (point-min)) end (or end (point-max)))
17846 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
17847 (substring (org-image-file-name-regexp) 0 -2)
17848 "\\)\\]" (if include-linked "" "\\]")))
17850 (while (re-search-forward re end t)
17851 (setq old (get-char-property-and-overlay (match-beginning 1)
17852 'org-image-overlay))
17853 (setq file (expand-file-name
17854 (concat (or (match-string 3) "") (match-string 4))))
17855 (when (file-exists-p file)
17856 (if (and (car-safe old) refresh)
17857 (image-refresh (overlay-get (cdr old) 'display))
17858 (setq img (save-match-data (create-image file)))
17860 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
17861 (overlay-put ov 'display img)
17862 (overlay-put ov 'face 'default)
17863 (overlay-put ov 'org-image-overlay t)
17864 (overlay-put ov 'modification-hooks
17865 (list 'org-display-inline-modification-hook))
17866 (push ov org-inline-image-overlays)))))))))
17868 (defun org-display-inline-modification-hook (ov after beg end &optional len)
17869 "Remove inline-display overlay if a corresponding region is modified."
17870 (let ((inhibit-modification-hooks t))
17871 (when (and ov after)
17872 (delete ov org-inline-image-overlays)
17873 (delete-overlay ov))))
17875 (defun org-remove-inline-images ()
17876 "Remove inline display of images."
17878 (mapc 'delete-overlay org-inline-image-overlays)
17879 (setq org-inline-image-overlays nil))
17883 ;; Outline functions from `outline-mode-prefix-map'
17884 ;; that can be remapped in Org:
17885 (define-key org-mode-map [remap outline-mark-subtree] 'org-mark-subtree)
17886 (define-key org-mode-map [remap show-subtree] 'org-show-subtree)
17887 (define-key org-mode-map [remap outline-forward-same-level]
17888 'org-forward-heading-same-level)
17889 (define-key org-mode-map [remap outline-backward-same-level]
17890 'org-backward-heading-same-level)
17891 (define-key org-mode-map [remap show-branches]
17892 'org-kill-note-or-show-branches)
17893 (define-key org-mode-map [remap outline-promote] 'org-promote-subtree)
17894 (define-key org-mode-map [remap outline-demote] 'org-demote-subtree)
17895 (define-key org-mode-map [remap outline-insert-heading] 'org-ctrl-c-ret)
17897 ;; Outline functions from `outline-mode-prefix-map' that can not
17898 ;; be remapped in Org:
17900 ;; - the column "key binding" shows whether the Outline function is still
17901 ;; available in Org mode on the same key that it has been bound to in
17903 ;; - "overridden": key used for a different functionality in Org mode
17904 ;; - else: key still bound to the same Outline function in Org mode
17906 ;; | Outline function | key binding | Org replacement |
17907 ;; |------------------------------------+-------------+-----------------------|
17908 ;; | `outline-next-visible-heading' | `C-c C-n' | still same function |
17909 ;; | `outline-previous-visible-heading' | `C-c C-p' | still same function |
17910 ;; | `outline-up-heading' | `C-c C-u' | still same function |
17911 ;; | `outline-move-subtree-up' | overridden | better: org-shiftup |
17912 ;; | `outline-move-subtree-down' | overridden | better: org-shiftdown |
17913 ;; | `show-entry' | overridden | no replacement |
17914 ;; | `show-children' | `C-c C-i' | visibility cycling |
17915 ;; | `show-branches' | `C-c C-k' | still same function |
17916 ;; | `show-subtree' | overridden | visibility cycling |
17917 ;; | `show-all' | overridden | no replacement |
17918 ;; | `hide-subtree' | overridden | visibility cycling |
17919 ;; | `hide-body' | overridden | no replacement |
17920 ;; | `hide-entry' | overridden | visibility cycling |
17921 ;; | `hide-leaves' | overridden | no replacement |
17922 ;; | `hide-sublevels' | overridden | no replacement |
17923 ;; | `hide-other' | overridden | no replacement |
17925 ;; Make `C-c C-x' a prefix key
17926 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
17928 ;; TAB key with modifiers
17929 (org-defkey org-mode-map "\C-i" 'org-cycle)
17930 (org-defkey org-mode-map [(tab)] 'org-cycle)
17931 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
17932 (org-defkey org-mode-map "\M-\t" 'pcomplete)
17933 ;; The following line is necessary under Suse GNU/Linux
17934 (unless (featurep 'xemacs)
17935 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
17936 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
17937 (define-key org-mode-map [backtab] 'org-shifttab)
17939 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
17940 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
17941 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
17943 ;; Cursor keys with modifiers
17944 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
17945 (org-defkey org-mode-map [(meta right)] 'org-metaright)
17946 (org-defkey org-mode-map [(meta up)] 'org-metaup)
17947 (org-defkey org-mode-map [(meta down)] 'org-metadown)
17949 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
17950 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
17951 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
17952 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
17954 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
17955 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
17956 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
17957 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
17959 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
17960 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
17961 (org-defkey org-mode-map [(control shift up)] 'org-shiftcontrolup)
17962 (org-defkey org-mode-map [(control shift down)] 'org-shiftcontroldown)
17965 (define-key org-mode-map org-babel-key-prefix org-babel-map)
17966 (mapc (lambda (pair)
17967 (define-key org-babel-map (car pair) (cdr pair)))
17968 org-babel-key-bindings)
17970 ;;; Extra keys for tty access.
17971 ;; We only set them when really needed because otherwise the
17972 ;; menus don't show the simple keys
17974 (when (or org-use-extra-keys
17975 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
17976 (not window-system))
17977 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
17978 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
17979 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
17980 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
17981 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
17982 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
17983 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
17984 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
17985 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
17986 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
17987 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
17988 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
17989 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
17990 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
17991 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
17992 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
17993 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
17994 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
17995 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
17996 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
17997 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
17998 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
17999 (org-defkey org-mode-map [?\e (tab)] 'pcomplete)
18000 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
18001 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
18002 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
18003 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
18004 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
18006 ;; All the other keys
18008 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
18009 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
18010 (if (boundp 'narrow-map)
18011 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
18012 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
18013 (if (boundp 'narrow-map)
18014 (org-defkey narrow-map "b" 'org-narrow-to-block)
18015 (org-defkey org-mode-map "\C-xnb" 'org-narrow-to-block))
18016 (if (boundp 'narrow-map)
18017 (org-defkey narrow-map "e" 'org-narrow-to-element)
18018 (org-defkey org-mode-map "\C-xne" 'org-narrow-to-element))
18019 (org-defkey org-mode-map "\C-\M-t" 'org-transpose-element)
18020 (org-defkey org-mode-map "\M-}" 'org-forward-element)
18021 (org-defkey org-mode-map "\M-{" 'org-backward-element)
18022 (org-defkey org-mode-map "\C-c\C-^" 'org-up-element)
18023 (org-defkey org-mode-map "\C-c\C-_" 'org-down-element)
18024 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-heading-same-level)
18025 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-heading-same-level)
18026 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
18027 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
18028 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
18029 (org-defkey org-mode-map "\C-c\C-xd" 'org-insert-drawer)
18030 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
18031 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
18032 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
18033 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
18034 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
18035 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
18036 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
18037 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
18038 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
18039 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
18040 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
18041 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
18042 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
18043 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
18044 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
18045 (org-defkey org-mode-map "\C-c\C-xv" 'org-copy-visible)
18046 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
18047 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
18048 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
18049 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
18050 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
18051 (org-defkey org-mode-map "\C-c\C-\M-l" 'org-insert-all-links)
18052 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
18053 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
18054 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
18055 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
18056 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
18057 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
18058 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
18059 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
18060 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
18061 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
18062 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
18063 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
18064 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
18065 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
18066 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
18067 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
18068 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
18069 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
18070 (org-defkey org-mode-map "\C-c^" 'org-sort)
18071 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
18072 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
18073 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
18074 (org-defkey org-mode-map "\C-m" 'org-return)
18075 (org-defkey org-mode-map "\C-j" 'org-return-indent)
18076 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
18077 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
18078 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
18079 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
18080 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
18081 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
18082 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
18083 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
18084 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
18085 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
18086 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
18087 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
18088 (org-defkey org-mode-map "\C-c\C-e" 'org-export)
18089 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
18090 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
18091 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
18092 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
18093 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
18094 (org-defkey org-mode-map "\C-c@" 'org-mark-subtree)
18095 (org-defkey org-mode-map "\M-h" 'org-mark-element)
18096 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
18097 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
18099 (org-defkey org-mode-map "\C-c\C-x\C-k" 'org-mark-entry-for-agenda-action)
18100 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
18101 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
18102 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
18104 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
18105 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
18106 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-in-last)
18107 (org-defkey org-mode-map "\C-c\C-x\C-z" 'org-resolve-clocks)
18108 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
18109 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
18110 (org-defkey org-mode-map "\C-c\C-x\C-q" 'org-clock-cancel)
18111 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
18112 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
18113 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
18114 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
18115 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
18116 (org-defkey org-mode-map "\C-c\C-x\C-\M-v" 'org-redisplay-inline-images)
18117 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
18118 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
18119 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
18120 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
18121 (org-defkey org-mode-map "\C-c\C-xE" 'org-inc-effort)
18122 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
18123 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
18124 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
18125 (org-defkey org-mode-map [(control ?c) (control ?x) ?\:] 'org-timer-cancel-timer)
18127 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
18128 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
18129 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
18130 (org-defkey org-mode-map "\C-c\C-x_" 'org-timer-stop)
18131 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
18133 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
18135 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
18137 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
18138 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
18140 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
18143 (when (featurep 'xemacs)
18144 (org-defkey org-mode-map 'button3 'popup-mode-menu))
18147 (defconst org-speed-commands-default
18149 ("Outline Navigation")
18150 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
18151 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
18152 ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
18153 ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
18154 ("u" . (org-speed-move-safe 'outline-up-heading))
18156 ("g" . (org-refile t))
18157 ("Outline Visibility")
18159 ("C" . org-shifttab)
18160 (" " . org-display-outline-path)
18161 (":" . org-columns)
18162 ("Outline Structure Editing")
18163 ("U" . org-shiftmetaup)
18164 ("D" . org-shiftmetadown)
18165 ("r" . org-metaright)
18166 ("l" . org-metaleft)
18167 ("R" . org-shiftmetaright)
18168 ("L" . org-shiftmetaleft)
18169 ("i" . (progn (forward-char 1) (call-interactively
18170 'org-insert-heading-respect-content)))
18173 ("a" . org-archive-subtree-default-with-confirmation)
18174 ("." . org-mark-subtree)
18175 ("#" . org-toggle-comment)
18177 ("I" . org-clock-in)
18178 ("O" . org-clock-out)
18179 ("Meta Data Editing")
18181 ("0" . (org-priority ?\ ))
18182 ("1" . (org-priority ?A))
18183 ("2" . (org-priority ?B))
18184 ("3" . (org-priority ?C))
18185 (";" . org-set-tags-command)
18186 ("e" . org-set-effort)
18187 ("E" . org-inc-effort)
18188 ("W" . (lambda(m) (interactive "sMinutes before warning: ")
18189 (org-entry-put (point) "APPT_WARNTIME" m)))
18190 ("Agenda Views etc")
18192 ("/" . org-sparse-tree)
18194 ("o" . org-open-at-point)
18195 ("?" . org-speed-command-help)
18196 ("<" . (org-agenda-set-restriction-lock 'subtree))
18197 (">" . (org-agenda-remove-restriction-lock))
18199 "The default speed commands.")
18201 (defun org-print-speed-command (e)
18202 (if (> (length (car e)) 1)
18207 (princ (make-string (length (car e)) ?-))
18211 (if (symbolp (cdr e))
18212 (princ (symbol-name (cdr e)))
18216 (defun org-speed-command-help ()
18217 "Show the available speed commands."
18219 (if (not org-use-speed-commands)
18220 (error "Speed commands are not activated, customize `org-use-speed-commands'")
18221 (with-output-to-temp-buffer "*Help*"
18222 (princ "User-defined Speed commands\n===========================\n")
18223 (mapc 'org-print-speed-command org-speed-commands-user)
18225 (princ "Built-in Speed commands\n=======================\n")
18226 (mapc 'org-print-speed-command org-speed-commands-default))
18227 (with-current-buffer "*Help*"
18228 (setq truncate-lines t))))
18230 (defun org-speed-move-safe (cmd)
18231 "Execute CMD, but make sure that the cursor always ends up in a headline.
18232 If not, return to the original position and throw an error."
18234 (let ((pos (point)))
18235 (call-interactively cmd)
18236 (unless (and (bolp) (org-at-heading-p))
18238 (error "Boundary reached while executing %s" cmd))))
18240 (defvar org-self-insert-command-undo-counter 0)
18242 (defvar org-table-auto-blank-field) ; defined in org-table.el
18243 (defvar org-speed-command nil)
18245 (defun org-speed-command-default-hook (keys)
18246 "Hook for activating single-letter speed commands.
18247 `org-speed-commands-default' specifies a minimal command set.
18248 Use `org-speed-commands-user' for further customization."
18249 (when (or (and (bolp) (looking-at org-outline-regexp))
18250 (and (functionp org-use-speed-commands)
18251 (funcall org-use-speed-commands)))
18252 (cdr (assoc keys (append org-speed-commands-user
18253 org-speed-commands-default)))))
18255 (defun org-babel-speed-command-hook (keys)
18256 "Hook for activating single-letter code block commands."
18257 (when (and (bolp) (looking-at org-babel-src-block-regexp))
18258 (cdr (assoc keys org-babel-key-bindings))))
18260 (defcustom org-speed-command-hook
18261 '(org-speed-command-default-hook org-babel-speed-command-hook)
18262 "Hook for activating speed commands at strategic locations.
18263 Hook functions are called in sequence until a valid handler is
18266 Each hook takes a single argument, a user-pressed command key
18267 which is also a `self-insert-command' from the global map.
18269 Within the hook, examine the cursor position and the command key
18270 and return nil or a valid handler as appropriate. Handler could
18271 be one of an interactive command, a function, or a form.
18273 Set `org-use-speed-commands' to non-nil value to enable this
18274 hook. The default setting is `org-speed-command-default-hook'."
18275 :group 'org-structure
18279 (defun org-self-insert-command (N)
18280 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
18281 If the cursor is in a table looking at whitespace, the whitespace is
18282 overwritten, and the table is not marked as requiring realignment."
18284 (org-check-before-invisible-edit 'insert)
18286 ((and org-use-speed-commands
18287 (setq org-speed-command
18288 (run-hook-with-args-until-success
18289 'org-speed-command-hook (this-command-keys))))
18291 ((commandp org-speed-command)
18292 (setq this-command org-speed-command)
18293 (call-interactively org-speed-command))
18294 ((functionp org-speed-command)
18295 (funcall org-speed-command))
18296 ((and org-speed-command (listp org-speed-command))
18297 (eval org-speed-command))
18298 (t (let (org-use-speed-commands)
18299 (call-interactively 'org-self-insert-command)))))
18303 ;; check if we blank the field, and if that triggers align
18304 (and (featurep 'org-table) org-table-auto-blank-field
18305 (member last-command
18306 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
18307 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
18308 ;; got extra space, this field does not determine column width
18309 (let (org-table-may-need-update) (org-table-blank-field))
18310 ;; no extra space, this field may determine column width
18311 (org-table-blank-field)))
18314 (looking-at "[^|\n]* |"))
18315 (let (org-table-may-need-update)
18316 (goto-char (1- (match-end 0)))
18317 (backward-delete-char 1)
18318 (goto-char (match-beginning 0))
18319 (self-insert-command N)))
18321 (setq org-table-may-need-update t)
18322 (self-insert-command N)
18323 (org-fix-tags-on-the-fly)
18324 (if org-self-insert-cluster-for-undo
18325 (if (not (eq last-command 'org-self-insert-command))
18326 (setq org-self-insert-command-undo-counter 1)
18327 (if (>= org-self-insert-command-undo-counter 20)
18328 (setq org-self-insert-command-undo-counter 1)
18329 (and (> org-self-insert-command-undo-counter 0)
18330 buffer-undo-list (listp buffer-undo-list)
18331 (not (cadr buffer-undo-list)) ; remove nil entry
18332 (setcdr buffer-undo-list (cddr buffer-undo-list)))
18333 (setq org-self-insert-command-undo-counter
18334 (1+ org-self-insert-command-undo-counter))))))))
18336 (defun org-check-before-invisible-edit (kind)
18337 "Check is editing if kind KIND would be dangerous with invisible text around.
18338 The detailed reaction depends on the user option `org-catch-invisible-edits'."
18339 ;; First, try to get out of here as quickly as possible, to reduce overhead
18340 (if (and org-catch-invisible-edits
18341 (or (not (boundp 'visible-mode)) (not visible-mode))
18342 (or (get-char-property (point) 'invisible)
18343 (get-char-property (max (point-min) (1- (point))) 'invisible)))
18344 ;; OK, we need to take a closer look
18345 (let* ((invisible-at-point (get-char-property (point) 'invisible))
18346 (invisible-before-point (if (bobp) nil (get-char-property
18347 (1- (point)) 'invisible)))
18348 (border-and-ok-direction
18350 ;; Check if we are acting predictably before invisible text
18351 (and invisible-at-point (not invisible-before-point)
18352 (memq kind '(insert delete-backward)))
18353 ;; Check if we are acting predictably after invisible text
18354 ;; This works not well, and I have turned it off. It seems
18355 ;; better to always show and stop after invisible text.
18356 ;; (and (not invisible-at-point) invisible-before-point
18357 ;; (memq kind '(insert delete)))
18359 (when (or (memq invisible-at-point '(outline org-hide-block t))
18360 (memq invisible-before-point '(outline org-hide-block t)))
18361 (if (eq org-catch-invisible-edits 'error)
18362 (error "Editing in invisible areas is prohibited - make visible first"))
18363 (if (and org-custom-properties-overlays
18364 (y-or-n-p "Display invisible properties in this buffer? "))
18365 (org-toggle-custom-properties-visibility)
18366 ;; Make the area visible
18368 (if invisible-before-point
18369 (goto-char (previous-single-char-property-change
18370 (point) 'invisible)))
18373 ((eq org-catch-invisible-edits 'show)
18374 ;; That's it, we do the edit after showing
18376 "Unfolding invisible region around point before editing")
18378 ((and (eq org-catch-invisible-edits 'smart)
18379 border-and-ok-direction)
18380 (message "Unfolding invisible region around point before editing"))
18382 ;; Don't do the edit, make the user repeat it in full visibility
18383 (error "Edit in invisible region aborted, repeat to confirm with text visible"))))))))
18385 (defun org-fix-tags-on-the-fly ()
18386 (when (and (equal (char-after (point-at-bol)) ?*)
18387 (org-at-heading-p))
18388 (org-align-tags-here org-tags-column)))
18390 (defun org-delete-backward-char (N)
18391 "Like `delete-backward-char', insert whitespace at field end in tables.
18392 When deleting backwards, in tables this function will insert whitespace in
18393 front of the next \"|\" separator, to keep the table aligned. The table will
18394 still be marked for re-alignment if the field did fill the entire column,
18395 because, in this case the deletion might narrow the column."
18397 (org-check-before-invisible-edit 'delete-backward)
18398 (if (and (org-table-p)
18400 (string-match "|" (buffer-substring (point-at-bol) (point)))
18401 (looking-at ".*?|"))
18402 (let ((pos (point))
18403 (noalign (looking-at "[^|\n\r]* |"))
18404 (c org-table-may-need-update))
18405 (backward-delete-char N)
18406 (if (not overwrite-mode)
18408 (skip-chars-forward "^|")
18410 (goto-char (1- pos))))
18411 ;; noalign: if there were two spaces at the end, this field
18412 ;; does not determine the width of the column.
18413 (if noalign (setq org-table-may-need-update c)))
18414 (backward-delete-char N)
18415 (org-fix-tags-on-the-fly)))
18417 (defun org-delete-char (N)
18418 "Like `delete-char', but insert whitespace at field end in tables.
18419 When deleting characters, in tables this function will insert whitespace in
18420 front of the next \"|\" separator, to keep the table aligned. The table will
18421 still be marked for re-alignment if the field did fill the entire column,
18422 because, in this case the deletion might narrow the column."
18424 (org-check-before-invisible-edit 'delete)
18425 (if (and (org-table-p)
18427 (not (= (char-after) ?|))
18429 (if (looking-at ".*?|")
18430 (let ((pos (point))
18431 (noalign (looking-at "[^|\n\r]* |"))
18432 (c org-table-may-need-update))
18433 (replace-match (concat
18434 (substring (match-string 0) 1 -1)
18437 ;; noalign: if there were two spaces at the end, this field
18438 ;; does not determine the width of the column.
18439 (if noalign (setq org-table-may-need-update c)))
18442 (org-fix-tags-on-the-fly)))
18444 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
18445 (put 'org-self-insert-command 'delete-selection t)
18446 (put 'orgtbl-self-insert-command 'delete-selection t)
18447 (put 'org-delete-char 'delete-selection 'supersede)
18448 (put 'org-delete-backward-char 'delete-selection 'supersede)
18449 (put 'org-yank 'delete-selection 'yank)
18451 ;; Make `flyspell-mode' delay after some commands
18452 (put 'org-self-insert-command 'flyspell-delayed t)
18453 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
18454 (put 'org-delete-char 'flyspell-delayed t)
18455 (put 'org-delete-backward-char 'flyspell-delayed t)
18457 ;; Make pabbrev-mode expand after org-mode commands
18458 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
18459 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
18461 ;; How to do this: Measure non-white length of current string
18462 ;; If equal to column width, we should realign.
18464 (defun org-remap (map &rest commands)
18465 "In MAP, remap the functions given in COMMANDS.
18466 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
18469 (setq old (pop commands) new (pop commands))
18470 (if (fboundp 'command-remapping)
18471 (org-defkey map (vector 'remap old) new)
18472 (substitute-key-definition old new map global-map)))))
18474 (when (eq org-enable-table-editor 'optimized)
18475 ;; If the user wants maximum table support, we need to hijack
18476 ;; some standard editing functions
18477 (org-remap org-mode-map
18478 'self-insert-command 'org-self-insert-command
18479 'delete-char 'org-delete-char
18480 'delete-backward-char 'org-delete-backward-char)
18481 (org-defkey org-mode-map "|" 'org-force-self-insert))
18483 (defvar org-ctrl-c-ctrl-c-hook nil
18484 "Hook for functions attaching themselves to `C-c C-c'.
18486 This can be used to add additional functionality to the C-c C-c
18487 key which executes context-dependent commands. This hook is run
18488 before any other test, while `org-ctrl-c-ctrl-c-final-hook' is
18489 run after the last test.
18491 Each function will be called with no arguments. The function
18492 must check if the context is appropriate for it to act. If yes,
18493 it should do its thing and then return a non-nil value. If the
18494 context is wrong, just do nothing and return nil.")
18496 (defvar org-ctrl-c-ctrl-c-final-hook nil
18497 "Hook for functions attaching themselves to `C-c C-c'.
18499 This can be used to add additional functionality to the C-c C-c
18500 key which executes context-dependent commands. This hook is run
18501 after any other test, while `org-ctrl-c-ctrl-c-hook' is run
18502 before the first test.
18504 Each function will be called with no arguments. The function
18505 must check if the context is appropriate for it to act. If yes,
18506 it should do its thing and then return a non-nil value. If the
18507 context is wrong, just do nothing and return nil.")
18509 (defvar org-tab-first-hook nil
18510 "Hook for functions to attach themselves to TAB.
18511 See `org-ctrl-c-ctrl-c-hook' for more information.
18512 This hook runs as the first action when TAB is pressed, even before
18513 `org-cycle' messes around with the `outline-regexp' to cater for
18514 inline tasks and plain list item folding.
18515 If any function in this hook returns t, any other actions that
18516 would have been caused by TAB (such as table field motion or visibility
18517 cycling) will not occur.")
18519 (defvar org-tab-after-check-for-table-hook nil
18520 "Hook for functions to attach themselves to TAB.
18521 See `org-ctrl-c-ctrl-c-hook' for more information.
18522 This hook runs after it has been established that the cursor is not in a
18523 table, but before checking if the cursor is in a headline or if global cycling
18525 If any function in this hook returns t, not other actions like visibility
18526 cycling will be done.")
18528 (defvar org-tab-after-check-for-cycling-hook nil
18529 "Hook for functions to attach themselves to TAB.
18530 See `org-ctrl-c-ctrl-c-hook' for more information.
18531 This hook runs after it has been established that not table field motion and
18532 not visibility should be done because of current context. This is probably
18533 the place where a package like yasnippets can hook in.")
18535 (defvar org-tab-before-tab-emulation-hook nil
18536 "Hook for functions to attach themselves to TAB.
18537 See `org-ctrl-c-ctrl-c-hook' for more information.
18538 This hook runs after every other options for TAB have been exhausted, but
18539 before indentation and \t insertion takes place.")
18541 (defvar org-metaleft-hook nil
18542 "Hook for functions attaching themselves to `M-left'.
18543 See `org-ctrl-c-ctrl-c-hook' for more information.")
18544 (defvar org-metaright-hook nil
18545 "Hook for functions attaching themselves to `M-right'.
18546 See `org-ctrl-c-ctrl-c-hook' for more information.")
18547 (defvar org-metaup-hook nil
18548 "Hook for functions attaching themselves to `M-up'.
18549 See `org-ctrl-c-ctrl-c-hook' for more information.")
18550 (defvar org-metadown-hook nil
18551 "Hook for functions attaching themselves to `M-down'.
18552 See `org-ctrl-c-ctrl-c-hook' for more information.")
18553 (defvar org-shiftmetaleft-hook nil
18554 "Hook for functions attaching themselves to `M-S-left'.
18555 See `org-ctrl-c-ctrl-c-hook' for more information.")
18556 (defvar org-shiftmetaright-hook nil
18557 "Hook for functions attaching themselves to `M-S-right'.
18558 See `org-ctrl-c-ctrl-c-hook' for more information.")
18559 (defvar org-shiftmetaup-hook nil
18560 "Hook for functions attaching themselves to `M-S-up'.
18561 See `org-ctrl-c-ctrl-c-hook' for more information.")
18562 (defvar org-shiftmetadown-hook nil
18563 "Hook for functions attaching themselves to `M-S-down'.
18564 See `org-ctrl-c-ctrl-c-hook' for more information.")
18565 (defvar org-metareturn-hook nil
18566 "Hook for functions attaching themselves to `M-RET'.
18567 See `org-ctrl-c-ctrl-c-hook' for more information.")
18568 (defvar org-shiftup-hook nil
18569 "Hook for functions attaching themselves to `S-up'.
18570 See `org-ctrl-c-ctrl-c-hook' for more information.")
18571 (defvar org-shiftup-final-hook nil
18572 "Hook for functions attaching themselves to `S-up'.
18573 This one runs after all other options except shift-select have been excluded.
18574 See `org-ctrl-c-ctrl-c-hook' for more information.")
18575 (defvar org-shiftdown-hook nil
18576 "Hook for functions attaching themselves to `S-down'.
18577 See `org-ctrl-c-ctrl-c-hook' for more information.")
18578 (defvar org-shiftdown-final-hook nil
18579 "Hook for functions attaching themselves to `S-down'.
18580 This one runs after all other options except shift-select have been excluded.
18581 See `org-ctrl-c-ctrl-c-hook' for more information.")
18582 (defvar org-shiftleft-hook nil
18583 "Hook for functions attaching themselves to `S-left'.
18584 See `org-ctrl-c-ctrl-c-hook' for more information.")
18585 (defvar org-shiftleft-final-hook nil
18586 "Hook for functions attaching themselves to `S-left'.
18587 This one runs after all other options except shift-select have been excluded.
18588 See `org-ctrl-c-ctrl-c-hook' for more information.")
18589 (defvar org-shiftright-hook nil
18590 "Hook for functions attaching themselves to `S-right'.
18591 See `org-ctrl-c-ctrl-c-hook' for more information.")
18592 (defvar org-shiftright-final-hook nil
18593 "Hook for functions attaching themselves to `S-right'.
18594 This one runs after all other options except shift-select have been excluded.
18595 See `org-ctrl-c-ctrl-c-hook' for more information.")
18597 (defun org-modifier-cursor-error ()
18598 "Throw an error, a modified cursor command was applied in wrong context."
18599 (error "This command is active in special context like tables, headlines or items"))
18601 (defun org-shiftselect-error ()
18602 "Throw an error because Shift-Cursor command was applied in wrong context."
18603 (if (and (boundp 'shift-select-mode) shift-select-mode)
18604 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
18605 (error "This command works only in special context like headlines or timestamps")))
18607 (defun org-call-for-shift-select (cmd)
18608 (let ((this-command-keys-shift-translated t))
18609 (call-interactively cmd)))
18611 (defun org-shifttab (&optional arg)
18612 "Global visibility cycling or move to previous table field.
18613 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
18615 See the individual commands for more information."
18618 ((org-at-table-p) (call-interactively 'org-table-previous-field))
18620 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
18621 (message "Content view to level: %d" arg)
18622 (org-content (prefix-numeric-value arg2))
18623 (setq org-cycle-global-status 'overview)))
18624 (t (call-interactively 'org-global-cycle))))
18626 (defun org-shiftmetaleft ()
18627 "Promote subtree or delete table column.
18628 Calls `org-promote-subtree', `org-outdent-item-tree', or
18629 `org-table-delete-column', depending on context. See the
18630 individual commands for more information."
18633 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
18634 ((org-at-table-p) (call-interactively 'org-table-delete-column))
18635 ((org-at-heading-p) (call-interactively 'org-promote-subtree))
18636 ((if (not (org-region-active-p)) (org-at-item-p)
18637 (save-excursion (goto-char (region-beginning))
18639 (call-interactively 'org-outdent-item-tree))
18640 (t (org-modifier-cursor-error))))
18642 (defun org-shiftmetaright ()
18643 "Demote subtree or insert table column.
18644 Calls `org-demote-subtree', `org-indent-item-tree', or
18645 `org-table-insert-column', depending on context. See the
18646 individual commands for more information."
18649 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
18650 ((org-at-table-p) (call-interactively 'org-table-insert-column))
18651 ((org-at-heading-p) (call-interactively 'org-demote-subtree))
18652 ((if (not (org-region-active-p)) (org-at-item-p)
18653 (save-excursion (goto-char (region-beginning))
18655 (call-interactively 'org-indent-item-tree))
18656 (t (org-modifier-cursor-error))))
18658 (defun org-shiftmetaup (&optional arg)
18659 "Move subtree up or kill table row.
18660 Calls `org-move-subtree-up' or `org-table-kill-row' or
18661 `org-move-item-up' or `org-timestamp-up', depending on context.
18662 See the individual commands for more information."
18665 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
18666 ((org-at-table-p) (call-interactively 'org-table-kill-row))
18667 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
18668 ((org-at-item-p) (call-interactively 'org-move-item-up))
18669 ((org-at-clock-log-p) (let ((org-clock-adjust-closest t))
18670 (call-interactively 'org-timestamp-up)))
18671 (t (org-modifier-cursor-error))))
18673 (defun org-shiftmetadown (&optional arg)
18674 "Move subtree down or insert table row.
18675 Calls `org-move-subtree-down' or `org-table-insert-row' or
18676 `org-move-item-down' or `org-timestamp-up', depending on context.
18677 See the individual commands for more information."
18680 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
18681 ((org-at-table-p) (call-interactively 'org-table-insert-row))
18682 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
18683 ((org-at-item-p) (call-interactively 'org-move-item-down))
18684 ((org-at-clock-log-p) (let ((org-clock-adjust-closest t))
18685 (call-interactively 'org-timestamp-down)))
18686 (t (org-modifier-cursor-error))))
18688 (defsubst org-hidden-tree-error ()
18690 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
18692 (defun org-metaleft (&optional arg)
18693 "Promote heading or move table column to left.
18694 Calls `org-do-promote' or `org-table-move-column', depending on context.
18695 With no specific context, calls the Emacs default `backward-word'.
18696 See the individual commands for more information."
18699 ((run-hook-with-args-until-success 'org-metaleft-hook))
18700 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
18701 ((org-with-limited-levels
18702 (or (org-at-heading-p)
18703 (and (org-region-active-p)
18705 (goto-char (region-beginning))
18706 (org-at-heading-p)))))
18707 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
18708 (call-interactively 'org-do-promote))
18709 ;; At an inline task.
18710 ((org-at-heading-p)
18711 (call-interactively 'org-inlinetask-promote))
18712 ((or (org-at-item-p)
18713 (and (org-region-active-p)
18715 (goto-char (region-beginning))
18717 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
18718 (call-interactively 'org-outdent-item))
18719 (t (call-interactively 'backward-word))))
18721 (defun org-metaright (&optional arg)
18722 "Demote a subtree, a list item or move table column to right.
18723 In front of a drawer or a block keyword, indent it correctly.
18724 With no specific context, calls the Emacs default `forward-word'.
18725 See the individual commands for more information."
18728 ((run-hook-with-args-until-success 'org-metaright-hook))
18729 ((org-at-table-p) (call-interactively 'org-table-move-column))
18730 ((org-at-drawer-p) (call-interactively 'org-indent-drawer))
18731 ((org-at-block-p) (call-interactively 'org-indent-block))
18732 ((org-with-limited-levels
18733 (or (org-at-heading-p)
18734 (and (org-region-active-p)
18736 (goto-char (region-beginning))
18737 (org-at-heading-p)))))
18738 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
18739 (call-interactively 'org-do-demote))
18740 ;; At an inline task.
18741 ((org-at-heading-p)
18742 (call-interactively 'org-inlinetask-demote))
18743 ((or (org-at-item-p)
18744 (and (org-region-active-p)
18746 (goto-char (region-beginning))
18748 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
18749 (call-interactively 'org-indent-item))
18750 (t (call-interactively 'forward-word))))
18752 (defun org-check-for-hidden (what)
18753 "Check if there are hidden headlines/items in the current visual line.
18754 WHAT can be either `headlines' or `items'. If the current line is
18755 an outline or item heading and it has a folded subtree below it,
18756 this function returns t, nil otherwise."
18758 ((eq what 'headlines) org-outline-regexp-bol)
18759 ((eq what 'items) (org-item-beginning-re))
18760 (t (error "This should not happen"))))
18764 (unless (org-region-active-p)
18765 (setq beg (point-at-bol))
18766 (beginning-of-line 2)
18767 (while (and (not (eobp)) ;; this is like `next-line'
18768 (get-char-property (1- (point)) 'invisible))
18769 (beginning-of-line 2))
18772 (goto-char (point-at-eol))
18773 (setq end (max end (point)))
18774 (while (re-search-forward re end t)
18775 (if (get-char-property (match-beginning 0) 'invisible)
18779 (autoload 'org-element-at-point "org-element")
18781 (declare-function org-element-at-point "org-element" (&optional keep-trail))
18782 (declare-function org-element-type "org-element" (element))
18783 (declare-function org-element-contents "org-element" (element))
18784 (declare-function org-element-property "org-element" (property element))
18785 (declare-function org-element-paragraph-parser "org-element" (limit))
18786 (declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion))
18787 (declare-function org-element-nested-p "org-element" (elem-a elem-b))
18788 (declare-function org-element-swap-A-B "org-element" (elem-a elem-b))
18789 (declare-function org-element--parse-objects "org-element" (beg end acc restriction))
18790 (declare-function org-element-parse-buffer "org-element" (&optional granularity visible-only))
18792 (defun org-metaup (&optional arg)
18793 "Move subtree up or move table row up.
18794 Calls `org-move-subtree-up' or `org-table-move-row' or
18795 `org-move-item-up', depending on context. See the individual commands
18796 for more information."
18799 ((run-hook-with-args-until-success 'org-metaup-hook))
18800 ((org-region-active-p)
18801 (let* ((a (min (region-beginning) (region-end)))
18802 (b (1- (max (region-beginning) (region-end))))
18803 (c (save-excursion (goto-char a)
18804 (move-beginning-of-line 0)))
18805 (d (save-excursion (goto-char a)
18806 (move-end-of-line 0) (point))))
18807 (transpose-regions a b c d)
18809 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
18810 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
18811 ((org-at-item-p) (call-interactively 'org-move-item-up))
18812 (t (org-drag-element-backward))))
18814 (defun org-metadown (&optional arg)
18815 "Move subtree down or move table row down.
18816 Calls `org-move-subtree-down' or `org-table-move-row' or
18817 `org-move-item-down', depending on context. See the individual
18818 commands for more information."
18821 ((run-hook-with-args-until-success 'org-metadown-hook))
18822 ((org-region-active-p)
18823 (let* ((a (min (region-beginning) (region-end)))
18824 (b (max (region-beginning) (region-end)))
18825 (c (save-excursion (goto-char b)
18826 (move-beginning-of-line 1)))
18827 (d (save-excursion (goto-char b)
18828 (move-end-of-line 1) (1+ (point)))))
18829 (transpose-regions a b c d)
18831 ((org-at-table-p) (call-interactively 'org-table-move-row))
18832 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
18833 ((org-at-item-p) (call-interactively 'org-move-item-down))
18834 (t (org-drag-element-forward))))
18836 (defun org-shiftup (&optional arg)
18837 "Increase item in timestamp or increase priority of current headline.
18838 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
18839 depending on context. See the individual commands for more information."
18842 ((run-hook-with-args-until-success 'org-shiftup-hook))
18843 ((and org-support-shift-select (org-region-active-p))
18844 (org-call-for-shift-select 'previous-line))
18845 ((org-at-timestamp-p t)
18846 (call-interactively (if org-edit-timestamp-down-means-later
18847 'org-timestamp-down 'org-timestamp-up)))
18848 ((and (not (eq org-support-shift-select 'always))
18849 org-enable-priority-commands
18850 (org-at-heading-p))
18851 (call-interactively 'org-priority-up))
18852 ((and (not org-support-shift-select) (org-at-item-p))
18853 (call-interactively 'org-previous-item))
18854 ((org-clocktable-try-shift 'up arg))
18855 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
18856 (org-support-shift-select
18857 (org-call-for-shift-select 'previous-line))
18858 (t (org-shiftselect-error))))
18860 (defun org-shiftdown (&optional arg)
18861 "Decrease item in timestamp or decrease priority of current headline.
18862 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
18863 depending on context. See the individual commands for more information."
18866 ((run-hook-with-args-until-success 'org-shiftdown-hook))
18867 ((and org-support-shift-select (org-region-active-p))
18868 (org-call-for-shift-select 'next-line))
18869 ((org-at-timestamp-p t)
18870 (call-interactively (if org-edit-timestamp-down-means-later
18871 'org-timestamp-up 'org-timestamp-down)))
18872 ((and (not (eq org-support-shift-select 'always))
18873 org-enable-priority-commands
18874 (org-at-heading-p))
18875 (call-interactively 'org-priority-down))
18876 ((and (not org-support-shift-select) (org-at-item-p))
18877 (call-interactively 'org-next-item))
18878 ((org-clocktable-try-shift 'down arg))
18879 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
18880 (org-support-shift-select
18881 (org-call-for-shift-select 'next-line))
18882 (t (org-shiftselect-error))))
18884 (defun org-shiftright (&optional arg)
18885 "Cycle the thing at point or in the current line, depending on context.
18886 Depending on context, this does one of the following:
18888 - switch a timestamp at point one day into the future
18889 - on a headline, switch to the next TODO keyword.
18890 - on an item, switch entire list to the next bullet type
18891 - on a property line, switch to the next allowed value
18892 - on a clocktable definition line, move time block into the future"
18895 ((run-hook-with-args-until-success 'org-shiftright-hook))
18896 ((and org-support-shift-select (org-region-active-p))
18897 (org-call-for-shift-select 'forward-char))
18898 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
18899 ((and (not (eq org-support-shift-select 'always))
18900 (org-at-heading-p))
18901 (let ((org-inhibit-logging
18902 (not org-treat-S-cursor-todo-selection-as-state-change))
18903 (org-inhibit-blocking
18904 (not org-treat-S-cursor-todo-selection-as-state-change)))
18905 (org-call-with-arg 'org-todo 'right)))
18906 ((or (and org-support-shift-select
18907 (not (eq org-support-shift-select 'always))
18908 (org-at-item-bullet-p))
18909 (and (not org-support-shift-select) (org-at-item-p)))
18910 (org-call-with-arg 'org-cycle-list-bullet nil))
18911 ((and (not (eq org-support-shift-select 'always))
18912 (org-at-property-p))
18913 (call-interactively 'org-property-next-allowed-value))
18914 ((org-clocktable-try-shift 'right arg))
18915 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
18916 (org-support-shift-select
18917 (org-call-for-shift-select 'forward-char))
18918 (t (org-shiftselect-error))))
18920 (defun org-shiftleft (&optional arg)
18921 "Cycle the thing at point or in the current line, depending on context.
18922 Depending on context, this does one of the following:
18924 - switch a timestamp at point one day into the past
18925 - on a headline, switch to the previous TODO keyword.
18926 - on an item, switch entire list to the previous bullet type
18927 - on a property line, switch to the previous allowed value
18928 - on a clocktable definition line, move time block into the past"
18931 ((run-hook-with-args-until-success 'org-shiftleft-hook))
18932 ((and org-support-shift-select (org-region-active-p))
18933 (org-call-for-shift-select 'backward-char))
18934 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
18935 ((and (not (eq org-support-shift-select 'always))
18936 (org-at-heading-p))
18937 (let ((org-inhibit-logging
18938 (not org-treat-S-cursor-todo-selection-as-state-change))
18939 (org-inhibit-blocking
18940 (not org-treat-S-cursor-todo-selection-as-state-change)))
18941 (org-call-with-arg 'org-todo 'left)))
18942 ((or (and org-support-shift-select
18943 (not (eq org-support-shift-select 'always))
18944 (org-at-item-bullet-p))
18945 (and (not org-support-shift-select) (org-at-item-p)))
18946 (org-call-with-arg 'org-cycle-list-bullet 'previous))
18947 ((and (not (eq org-support-shift-select 'always))
18948 (org-at-property-p))
18949 (call-interactively 'org-property-previous-allowed-value))
18950 ((org-clocktable-try-shift 'left arg))
18951 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
18952 (org-support-shift-select
18953 (org-call-for-shift-select 'backward-char))
18954 (t (org-shiftselect-error))))
18956 (defun org-shiftcontrolright ()
18957 "Switch to next TODO set."
18960 ((and org-support-shift-select (org-region-active-p))
18961 (org-call-for-shift-select 'forward-word))
18962 ((and (not (eq org-support-shift-select 'always))
18963 (org-at-heading-p))
18964 (org-call-with-arg 'org-todo 'nextset))
18965 (org-support-shift-select
18966 (org-call-for-shift-select 'forward-word))
18967 (t (org-shiftselect-error))))
18969 (defun org-shiftcontrolleft ()
18970 "Switch to previous TODO set."
18973 ((and org-support-shift-select (org-region-active-p))
18974 (org-call-for-shift-select 'backward-word))
18975 ((and (not (eq org-support-shift-select 'always))
18976 (org-at-heading-p))
18977 (org-call-with-arg 'org-todo 'previousset))
18978 (org-support-shift-select
18979 (org-call-for-shift-select 'backward-word))
18980 (t (org-shiftselect-error))))
18982 (defun org-shiftcontrolup ()
18983 "Change timestamps synchronously up in CLOCK log lines."
18985 (cond ((and (not org-support-shift-select)
18986 (org-at-clock-log-p)
18987 (org-at-timestamp-p t))
18988 (org-clock-timestamps-up))
18989 (t (org-shiftselect-error))))
18991 (defun org-shiftcontroldown ()
18992 "Change timestamps synchronously down in CLOCK log lines."
18994 (cond ((and (not org-support-shift-select)
18995 (org-at-clock-log-p)
18996 (org-at-timestamp-p t))
18997 (org-clock-timestamps-down))
18998 (t (org-shiftselect-error))))
19000 (defun org-ctrl-c-ret ()
19001 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
19004 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
19005 (t (call-interactively 'org-insert-heading))))
19007 (defun org-find-visible ()
19009 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
19010 (get-char-property s 'invisible)))
19012 (defun org-find-invisible ()
19014 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
19015 (not (get-char-property s 'invisible))))
19018 (defun org-copy-visible (beg end)
19019 "Copy the visible parts of the region."
19024 (narrow-to-region beg end)
19025 (setq s (goto-char (point-min)))
19026 (while (not (= (point) (point-max)))
19027 (goto-char (org-find-invisible))
19028 (push (buffer-substring s (point)) snippets)
19029 (setq s (goto-char (org-find-visible))))))
19030 (kill-new (apply 'concat (nreverse snippets)))))
19032 (defun org-copy-special ()
19033 "Copy region in table or copy current subtree.
19034 Calls `org-table-copy' or `org-copy-subtree', depending on context.
19035 See the individual commands for more information."
19037 (call-interactively
19038 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
19040 (defun org-cut-special ()
19041 "Cut region in table or cut current subtree.
19042 Calls `org-table-copy' or `org-cut-subtree', depending on context.
19043 See the individual commands for more information."
19045 (call-interactively
19046 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
19048 (defun org-paste-special (arg)
19049 "Paste rectangular region into table, or past subtree relative to level.
19050 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
19051 See the individual commands for more information."
19053 (if (org-at-table-p)
19054 (org-table-paste-rectangle)
19055 (org-paste-subtree arg)))
19057 (defun org-edit-special (&optional arg)
19058 "Call a special editor for the stuff at point.
19059 When at a table, call the formula editor with `org-table-edit-formulas'.
19060 When at the first line of an src example, call `org-edit-src-code'.
19061 When in an #+include line, visit the include file. Otherwise call
19062 `ffap' to visit the file at point."
19064 ;; possibly prep session before editing source
19066 (let* ((info (org-babel-get-src-block-info))
19067 (lang (nth 0 info))
19068 (params (nth 2 info))
19069 (session (cdr (assoc :session params))))
19070 (when (and info session) ;; we are in a source-code block with a session
19072 (intern (concat "org-babel-prep-session:" lang)) session params))))
19073 (cond ;; proceed with `org-edit-special'
19075 (beginning-of-line 1)
19076 (looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
19077 (find-file (org-trim (match-string 1))))
19078 ((org-edit-src-code))
19079 ((org-edit-fixed-width-region))
19080 ((org-at-table.el-p)
19081 (org-edit-src-code))
19082 ((or (org-at-table-p)
19084 (beginning-of-line 1)
19085 (let ((case-fold-search )) (looking-at "[ \t]*#\\+tblfm:"))))
19086 (call-interactively 'org-table-edit-formulas))
19087 (t (call-interactively 'ffap))))
19089 (defvar org-table-coordinate-overlays) ; defined in org-table.el
19090 (defun org-ctrl-c-ctrl-c (&optional arg)
19091 "Set tags in headline, or update according to changed information at point.
19093 This command does many different things, depending on context:
19095 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
19096 this is what we do.
19098 - If the cursor is on a statistics cookie, update it.
19100 - If the cursor is in a headline, prompt for tags and insert them
19101 into the current line, aligned to `org-tags-column'. When called
19102 with prefix arg, realign all tags in the current buffer.
19104 - If the cursor is in one of the special #+KEYWORD lines, this
19105 triggers scanning the buffer for these lines and updating the
19108 - If the cursor is inside a table, realign the table. This command
19109 works even if the automatic table editor has been turned off.
19111 - If the cursor is on a #+TBLFM line, re-apply the formulas to
19114 - If the cursor is at a footnote reference or definition, jump to
19115 the corresponding definition or references, respectively.
19117 - If the cursor is a the beginning of a dynamic block, update it.
19119 - If the current buffer is a capture buffer, close note and file it.
19121 - If the cursor is on a <<<target>>>, update radio targets and
19122 corresponding links in this buffer.
19124 - If the cursor is on a numbered item in a plain list, renumber the
19127 - If the cursor is on a checkbox, toggle it.
19129 - If the cursor is on a code block, evaluate it. The variable
19130 `org-confirm-babel-evaluate' can be used to control prompting
19131 before code block evaluation, by default every code block
19132 evaluation requires confirmation. Code block evaluation can be
19133 inhibited by setting `org-babel-no-eval-on-ctrl-c-ctrl-c'."
19135 (let ((org-enable-table-editor t))
19137 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
19138 org-occur-highlights
19139 org-latex-fragment-image-overlays)
19140 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
19141 (org-remove-occur-highlights)
19142 (org-remove-latex-fragment-image-overlays)
19143 (message "Temporary highlights/overlays removed from current buffer"))
19144 ((and (local-variable-p 'org-finish-function (current-buffer))
19145 (fboundp org-finish-function))
19146 (funcall org-finish-function))
19147 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
19148 ((org-in-regexp org-ts-regexp-both)
19149 (org-timestamp-change 0 'day))
19150 ((or (looking-at org-property-start-re)
19151 (org-at-property-p))
19152 (call-interactively 'org-property-action))
19153 ((org-at-target-p) (call-interactively 'org-update-radio-target-regexp))
19154 ((and (org-in-regexp "\\[\\([0-9]*%\\|[0-9]*/[0-9]*\\)\\]")
19155 (or (org-at-heading-p) (org-at-item-p)))
19156 (call-interactively 'org-update-statistics-cookies))
19157 ((org-at-heading-p) (call-interactively 'org-set-tags))
19158 ((org-at-table.el-p)
19159 (message "Use C-c ' to edit table.el tables"))
19161 (org-table-maybe-eval-formula)
19163 (call-interactively 'org-table-recalculate)
19164 (org-table-maybe-recalculate-line))
19165 (call-interactively 'org-table-align)
19166 (orgtbl-send-table 'maybe))
19167 ((or (org-footnote-at-reference-p)
19168 (org-footnote-at-definition-p))
19169 (call-interactively 'org-footnote-action))
19170 ((org-at-item-checkbox-p)
19171 ;; Cursor at a checkbox: repair list and update checkboxes. Send
19172 ;; list only if at top item.
19173 (let* ((cbox (match-string 1))
19174 (struct (org-list-struct))
19175 (old-struct (copy-tree struct))
19176 (parents (org-list-parents-alist struct))
19177 (orderedp (org-entry-get nil "ORDERED"))
19178 (firstp (= (org-list-get-top-point struct) (point-at-bol)))
19180 ;; Use a light version of `org-toggle-checkbox' to avoid
19181 ;; computing list structure twice.
19182 (let ((new-box (cond
19183 ((equal arg '(16)) "[-]")
19184 ((equal arg '(4)) nil)
19185 ((equal "[X]" cbox) "[ ]")
19187 (if (and firstp arg)
19188 ;; If at first item of sub-list, remove check-box from
19189 ;; every item at the same level.
19191 (lambda (pos) (org-list-set-checkbox pos struct new-box))
19192 (org-list-get-all-items
19193 (point-at-bol) struct (org-list-prevs-alist struct)))
19194 (org-list-set-checkbox (point-at-bol) struct new-box)))
19195 ;; Replicate `org-list-write-struct', while grabbing a return
19196 ;; value from `org-list-struct-fix-box'.
19197 (org-list-struct-fix-ind struct parents 2)
19198 (org-list-struct-fix-item-end struct)
19199 (let ((prevs (org-list-prevs-alist struct)))
19200 (org-list-struct-fix-bul struct prevs)
19201 (org-list-struct-fix-ind struct parents)
19203 (org-list-struct-fix-box struct parents prevs orderedp)))
19204 (org-list-struct-apply-struct struct old-struct)
19205 (org-update-checkbox-count-maybe)
19208 "Checkboxes were removed due to unchecked box at line %d"
19209 (org-current-line block-item)))
19210 (when firstp (org-list-send-list 'maybe))))
19212 ;; Cursor at an item: repair list. Do checkbox related actions
19213 ;; only if function was called with an argument. Send list only
19215 (let* ((struct (org-list-struct))
19216 (firstp (= (org-list-get-top-point struct) (point-at-bol)))
19219 (setq old-struct (copy-tree struct))
19221 ;; If at first item of sub-list, add check-box to every
19222 ;; item at the same level.
19225 (unless (org-list-get-checkbox pos struct)
19226 (org-list-set-checkbox pos struct "[ ]")))
19227 (org-list-get-all-items
19228 (point-at-bol) struct (org-list-prevs-alist struct)))
19229 (org-list-set-checkbox (point-at-bol) struct "[ ]")))
19230 (org-list-write-struct
19231 struct (org-list-parents-alist struct) old-struct)
19232 (when arg (org-update-checkbox-count-maybe))
19233 (when firstp (org-list-send-list 'maybe))))
19234 ((save-excursion (beginning-of-line 1) (looking-at org-dblock-start-re))
19236 (beginning-of-line 1)
19237 (save-excursion (org-update-dblock)))
19239 (let ((case-fold-search t))
19240 (beginning-of-line 1)
19241 (looking-at "[ \t]*#\\+\\([a-z]+\\)")))
19243 ((or (equal (match-string 1) "TBLFM")
19244 (equal (match-string 1) "tblfm"))
19245 ;; Recalculate the table before this line
19247 (beginning-of-line 1)
19248 (skip-chars-backward " \r\n\t")
19249 (if (org-at-table-p)
19250 (org-call-with-arg 'org-table-recalculate (or arg t)))))
19252 (let ((org-inhibit-startup-visibility-stuff t)
19253 (org-startup-align-all-tables nil))
19254 (when (boundp 'org-table-coordinate-overlays)
19255 (mapc 'delete-overlay org-table-coordinate-overlays)
19256 (setq org-table-coordinate-overlays nil))
19257 (org-save-outline-visibility 'use-markers (org-mode-restart)))
19258 (message "Local setup has been refreshed"))))
19259 ((org-clock-update-time-maybe))
19261 (or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
19262 (error "C-c C-c can do nothing useful at this location"))))))
19264 (defun org-mode-restart ()
19265 "Restart Org-mode, to scan again for special lines.
19266 Also updates the keyword regular expressions."
19269 (message "Org-mode restarted"))
19271 (defun org-kill-note-or-show-branches ()
19272 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
19274 (if (not org-finish-function)
19277 (call-interactively 'show-branches))
19278 (let ((org-note-abort t))
19279 (funcall org-finish-function))))
19281 (defun org-return (&optional indent)
19282 "Goto next table row or insert a newline.
19283 Calls `org-table-next-row' or `newline', depending on context.
19284 See the individual commands for more information."
19288 ((or (bobp) (org-in-src-block-p))
19289 (if indent (newline-and-indent) (newline)))
19291 (org-table-justify-field-maybe)
19292 (call-interactively 'org-table-next-row))
19293 ;; when `newline-and-indent' is called within a list, make sure
19294 ;; text moved stays inside the item.
19295 ((and (org-in-item-p) indent)
19296 (if (and (org-at-item-p) (>= (point) (match-end 0)))
19298 (save-match-data (newline))
19299 (org-indent-line-to (length (match-string 0))))
19300 (let ((ind (org-get-indentation)))
19302 (if (org-looking-back org-list-end-re)
19304 (org-indent-line-to ind)))))
19305 ((and org-return-follows-link
19306 (org-at-timestamp-p t)
19307 (not (eq org-ts-what 'after)))
19308 (org-follow-timestamp-link))
19309 ((and org-return-follows-link
19310 (let ((tprop (get-text-property (point) 'face)))
19311 (or (eq tprop 'org-link)
19312 (and (listp tprop) (memq 'org-link tprop)))))
19313 (call-interactively 'org-open-at-point))
19314 ((and (org-at-heading-p)
19316 (org-re "\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")))
19320 (t (if indent (newline-and-indent) (newline))))))
19322 (defun org-return-indent ()
19323 "Goto next table row or insert a newline and indent.
19324 Calls `org-table-next-row' or `newline-and-indent', depending on
19325 context. See the individual commands for more information."
19329 (defun org-ctrl-c-star ()
19330 "Compute table, or change heading status of lines.
19331 Calls `org-table-recalculate' or `org-toggle-heading',
19332 depending on context."
19336 (call-interactively 'org-table-recalculate))
19338 ;; Convert all lines in region to list items
19339 (call-interactively 'org-toggle-heading))))
19341 (defun org-ctrl-c-minus ()
19342 "Insert separator line in table or modify bullet status of line.
19343 Also turns a plain line or a region of lines into list items.
19344 Calls `org-table-insert-hline', `org-toggle-item', or
19345 `org-cycle-list-bullet', depending on context."
19349 (call-interactively 'org-table-insert-hline))
19350 ((org-region-active-p)
19351 (call-interactively 'org-toggle-item))
19353 (call-interactively 'org-cycle-list-bullet))
19355 (call-interactively 'org-toggle-item))))
19357 (defun org-toggle-item (arg)
19358 "Convert headings or normal lines to items, items to normal lines.
19359 If there is no active region, only the current line is considered.
19361 If the first non blank line in the region is an headline, convert
19362 all headlines to items, shifting text accordingly.
19364 If it is an item, convert all items to normal lines.
19366 If it is normal text, change region into an item. With a prefix
19367 argument ARG, change each line in region into an item."
19371 ;; Shift text in current section to IND, from point to END.
19372 ;; The function leaves point to END line.
19374 (let ((min-i 1000) (end (copy-marker end)))
19375 ;; First determine the minimum indentation (MIN-I) of
19379 (while (< (point) end)
19380 (let ((i (org-get-indentation)))
19382 ;; Skip blank lines and inline tasks.
19383 ((looking-at "^[ \t]*$"))
19384 ((looking-at org-outline-regexp-bol))
19385 ;; We can't find less than 0 indentation.
19386 ((zerop i) (throw 'exit (setq min-i 0)))
19387 ((< i min-i) (setq min-i i))))
19389 ;; Then indent each line so that a line indented to
19390 ;; MIN-I becomes indented to IND. Ignore blank lines
19391 ;; and inline tasks in the process.
19392 (let ((delta (- ind min-i)))
19393 (while (< (point) end)
19394 (unless (or (looking-at "^[ \t]*$")
19395 (looking-at org-outline-regexp-bol))
19396 (org-indent-line-to (+ (org-get-indentation) delta)))
19397 (forward-line)))))))
19400 ;; Return beginning of first non-blank line, starting from
19405 (skip-chars-forward " \r\t\n")
19408 ;; Determine boundaries of changes.
19409 (if (org-region-active-p)
19410 (setq beg (funcall skip-blanks (region-beginning))
19411 end (copy-marker (region-end)))
19412 (setq beg (funcall skip-blanks (point-at-bol))
19413 end (copy-marker (point-at-eol))))
19414 ;; Depending on the starting line, choose an action on the text
19415 ;; between BEG and END.
19416 (org-with-limited-levels
19420 ;; Case 1. Start at an item: de-itemize. Note that it only
19421 ;; happens when a region is active: `org-ctrl-c-minus'
19422 ;; would call `org-cycle-list-bullet' otherwise.
19424 (while (< (point) end)
19425 (when (org-at-item-p)
19426 (skip-chars-forward " \t")
19427 (delete-region (point) (match-end 0)))
19429 ;; Case 2. Start at an heading: convert to items.
19430 ((org-at-heading-p)
19431 (let* ((bul (org-list-bullet-string "-"))
19432 (bul-len (length bul))
19433 ;; Indentation of the first heading. It should be
19434 ;; relative to the indentation of its parent, if any.
19435 (start-ind (save-excursion
19437 ((not org-adapt-indentation) 0)
19438 ((not (outline-previous-heading)) 0)
19439 (t (length (match-string 0))))))
19440 ;; Level of first heading. Further headings will be
19441 ;; compared to it to determine hierarchy in the list.
19442 (ref-level (org-reduced-level (org-outline-level))))
19443 (while (< (point) end)
19444 (let* ((level (org-reduced-level (org-outline-level)))
19445 (delta (max 0 (- level ref-level))))
19446 ;; If current headline is less indented than the first
19447 ;; one, set it as reference, in order to preserve
19449 (when (< level ref-level) (setq ref-level level))
19450 (replace-match bul t t)
19451 (org-indent-line-to (+ start-ind (* delta bul-len)))
19452 ;; Ensure all text down to END (or SECTION-END) belongs
19453 ;; to the newly created item.
19454 (let ((section-end (save-excursion
19455 (or (outline-next-heading) (point)))))
19457 (funcall shift-text
19458 (+ start-ind (* (1+ delta) bul-len))
19459 (min end section-end)))))))
19460 ;; Case 3. Normal line with ARG: turn each non-item line into
19463 (while (< (point) end)
19464 (unless (or (org-at-heading-p) (org-at-item-p))
19465 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
19467 (concat "\\1" (org-list-bullet-string "-") "\\2"))))
19469 ;; Case 4. Normal line without ARG: make the first line of
19470 ;; region an item, and shift indentation of others
19471 ;; lines to set them as item's body.
19472 (t (let* ((bul (org-list-bullet-string "-"))
19473 (bul-len (length bul))
19474 (ref-ind (org-get-indentation)))
19475 (skip-chars-forward " \t")
19478 (while (< (point) end)
19479 ;; Ensure that lines less indented than first one
19480 ;; still get included in item body.
19481 (funcall shift-text
19482 (+ ref-ind bul-len)
19483 (min end (save-excursion (or (outline-next-heading)
19485 (forward-line)))))))))
19487 (defun org-toggle-heading (&optional nstars)
19488 "Convert headings to normal text, or items or text to headings.
19489 If there is no active region, only the current line is considered.
19491 With a \\[universal-argument] prefix, convert the whole list at
19492 point into heading.
19496 - If the first non blank line is an headline, remove the stars
19497 from all headlines in the region.
19499 - If it is a normal line turn each and every normal line (i.e. not an
19500 heading or an item) in the region into a heading.
19502 - If it is a plain list item, turn all plain list items into headings.
19504 When converting a line into a heading, the number of stars is chosen
19505 such that the lines become children of the current entry. However,
19506 when a prefix argument is given, its value determines the number of
19511 ;; Return beginning of first non-blank line, starting from
19516 (while (org-at-comment-p) (forward-line))
19517 (skip-chars-forward " \r\t\n")
19520 ;; Determine boundaries of changes. If a universal prefix has
19521 ;; been given, put the list in a region. If region ends at a bol,
19522 ;; do not consider the last line to be in the region.
19524 (when (and current-prefix-arg (org-at-item-p))
19525 (if (equal current-prefix-arg '(4)) (setq current-prefix-arg 1))
19526 (org-mark-element))
19528 (if (org-region-active-p)
19529 (setq beg (funcall skip-blanks (region-beginning))
19530 end (copy-marker (save-excursion
19531 (goto-char (region-end))
19532 (if (bolp) (point) (point-at-eol)))))
19533 (setq beg (funcall skip-blanks (point-at-bol))
19534 end (copy-marker (point-at-eol))))
19535 ;; Ensure inline tasks don't count as headings.
19536 (org-with-limited-levels
19540 ;; Case 1. Started at an heading: de-star headings.
19541 ((org-at-heading-p)
19542 (while (< (point) end)
19543 (when (org-at-heading-p t)
19544 (looking-at org-outline-regexp) (replace-match "")
19547 ;; Case 2. Started at an item: change items into headlines.
19548 ;; One star will be added by `org-list-to-subtree'.
19550 (let* ((stars (make-string
19552 ;; subtract the star that will be added again by
19553 ;; `org-list-to-subtree'
19554 (1- (prefix-numeric-value current-prefix-arg))
19555 (or (org-current-level) 0))
19558 (cond (nstars "") ; stars from prefix only
19559 ((equal stars "") "") ; before first heading
19560 (org-odd-levels-only "*") ; inside heading, odd
19561 (t "")))) ; inside heading, oddeven
19562 (while (< (point) end)
19563 (when (org-at-item-p)
19564 ;; Pay attention to cases when region ends before list.
19565 (let* ((struct (org-list-struct))
19566 (list-end (min (org-list-get-bottom-point struct) (1+ end))))
19568 (narrow-to-region (point) list-end)
19570 (org-list-to-subtree
19571 (org-list-parse-list t)
19572 '(:istart (concat stars add-stars (funcall get-stars depth))
19573 :icount (concat stars add-stars (funcall get-stars depth)))))))
19576 ;; Case 3. Started at normal text: make every line an heading,
19577 ;; skipping headlines and items.
19578 (t (let* ((stars (make-string
19580 (prefix-numeric-value current-prefix-arg)
19581 (or (org-current-level) 0))
19584 (cond (nstars "") ; stars from prefix only
19585 ((equal stars "") "*") ; before first heading
19586 (org-odd-levels-only "**") ; inside heading, odd
19587 (t "*"))) ; inside heading, oddeven
19588 (rpl (concat stars add-stars " ")))
19589 (while (< (point) end)
19590 (when (and (not (or (org-at-heading-p) (org-at-item-p) (org-at-comment-p)))
19591 (looking-at "\\([ \t]*\\)\\(\\S-\\)"))
19592 (replace-match (concat rpl (match-string 2))) (setq toggled t))
19593 (forward-line)))))))
19594 (unless toggled (message "Cannot toggle heading from here"))))
19596 (defun org-meta-return (&optional arg)
19597 "Insert a new heading or wrap a region in a table.
19598 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
19599 See the individual commands for more information."
19602 ((run-hook-with-args-until-success 'org-metareturn-hook))
19603 ((or (org-at-drawer-p) (org-at-property-p))
19604 (newline-and-indent))
19606 (call-interactively 'org-table-wrap-region))
19607 (t (call-interactively 'org-insert-heading))))
19611 ;; Define the Org-mode menus
19612 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
19614 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
19615 ["Next Field" org-cycle (org-at-table-p)]
19616 ["Previous Field" org-shifttab (org-at-table-p)]
19617 ["Next Row" org-return (org-at-table-p)]
19619 ["Blank Field" org-table-blank-field (org-at-table-p)]
19620 ["Edit Field" org-table-edit-field (org-at-table-p)]
19621 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
19624 ["Move Column Left" org-metaleft (org-at-table-p)]
19625 ["Move Column Right" org-metaright (org-at-table-p)]
19626 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
19627 ["Insert Column" org-shiftmetaright (org-at-table-p)])
19629 ["Move Row Up" org-metaup (org-at-table-p)]
19630 ["Move Row Down" org-metadown (org-at-table-p)]
19631 ["Delete Row" org-shiftmetaup (org-at-table-p)]
19632 ["Insert Row" org-shiftmetadown (org-at-table-p)]
19633 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
19635 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
19637 ["Copy Rectangle" org-copy-special (org-at-table-p)]
19638 ["Cut Rectangle" org-cut-special (org-at-table-p)]
19639 ["Paste Rectangle" org-paste-special (org-at-table-p)]
19640 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
19643 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
19644 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
19645 ["Edit Formulas" org-edit-special (org-at-table-p)]
19647 ["Recalculate line" org-table-recalculate (org-at-table-p)]
19648 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
19649 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
19651 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
19653 ["Sum Column/Rectangle" org-table-sum
19654 (or (org-at-table-p) (org-region-active-p))]
19655 ["Which Column?" org-table-current-column (org-at-table-p)])
19657 org-table-toggle-formula-debugger
19658 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
19659 ["Show Col/Row Numbers"
19660 org-table-toggle-coordinate-overlays
19662 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
19664 ["Create" org-table-create (and (not (org-at-table-p))
19665 org-enable-table-editor)]
19666 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
19667 ["Import from File" org-table-import (not (org-at-table-p))]
19668 ["Export to File" org-table-export (org-at-table-p)]
19670 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
19672 (easy-menu-define org-org-menu org-mode-map "Org menu"
19675 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
19676 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
19677 ["Sparse Tree..." org-sparse-tree t]
19678 ["Reveal Context" org-reveal t]
19679 ["Show All" show-all t]
19681 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
19683 ["New Heading" org-insert-heading t]
19684 ("Navigate Headings"
19685 ["Up" outline-up-heading t]
19686 ["Next" outline-next-visible-heading t]
19687 ["Previous" outline-previous-visible-heading t]
19688 ["Next Same Level" outline-forward-same-level t]
19689 ["Previous Same Level" outline-backward-same-level t]
19691 ["Jump" org-goto t])
19693 ["Move Subtree Up" org-shiftmetaup (not (org-at-table-p))]
19694 ["Move Subtree Down" org-shiftmetadown (not (org-at-table-p))]
19696 ["Copy Subtree" org-copy-special (not (org-at-table-p))]
19697 ["Cut Subtree" org-cut-special (not (org-at-table-p))]
19698 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
19700 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
19702 ["Copy visible text" org-copy-visible t]
19704 ["Promote Heading" org-metaleft (not (org-at-table-p))]
19705 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
19706 ["Demote Heading" org-metaright (not (org-at-table-p))]
19707 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
19709 ["Sort Region/Children" org-sort (not (org-at-table-p))]
19711 ["Convert to odd levels" org-convert-to-odd-levels t]
19712 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
19714 ["Emphasis..." org-emphasize t]
19715 ["Edit Source Example" org-edit-special t]
19717 ["Footnote new/jump" org-footnote-action t]
19718 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
19720 ["Archive (default method)" org-archive-subtree-default t]
19722 ["Move Subtree to Archive file" org-advertized-archive-subtree t]
19723 ["Toggle ARCHIVE tag" org-toggle-archive-tag t]
19724 ["Move subtree to Archive sibling" org-archive-to-archive-sibling t]
19728 ["Store Link (Global)" org-store-link t]
19729 ["Find existing link to here" org-occur-link-in-agenda-files t]
19730 ["Insert Link" org-insert-link t]
19731 ["Follow Link" org-open-at-point t]
19733 ["Next link" org-next-link t]
19734 ["Previous link" org-previous-link t]
19736 ["Descriptive Links"
19737 org-toggle-link-display
19739 :selected org-descriptive-links
19742 org-toggle-link-display
19744 :selected (not org-descriptive-links)])
19747 ["TODO/DONE/-" org-todo t]
19749 ["Next keyword" org-shiftright (org-at-heading-p)]
19750 ["Previous keyword" org-shiftleft (org-at-heading-p)]
19751 ["Complete Keyword" pcomplete (assq :todo-keyword (org-context))]
19752 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))]
19753 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))])
19754 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
19755 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
19757 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
19758 :selected org-enforce-todo-dependencies :style toggle :active t]
19759 "Settings for tree at point"
19760 ["Do Children sequentially" org-toggle-ordered-property :style radio
19761 :selected (org-entry-get nil "ORDERED")
19762 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
19763 ["Do Children parallel" org-toggle-ordered-property :style radio
19764 :selected (not (org-entry-get nil "ORDERED"))
19765 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
19767 ["Set Priority" org-priority t]
19768 ["Priority Up" org-shiftup t]
19769 ["Priority Down" org-shiftdown t]
19771 ["Get news from all feeds" org-feed-update-all t]
19772 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
19773 ["Customize feeds" (customize-variable 'org-feed-alist) t])
19774 ("TAGS and Properties"
19775 ["Set Tags" org-set-tags-command t]
19776 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
19778 ["Set property" org-set-property t]
19779 ["Column view of properties" org-columns t]
19780 ["Insert Column View DBlock" org-insert-columns-dblock t])
19781 ("Dates and Scheduling"
19782 ["Timestamp" org-time-stamp t]
19783 ["Timestamp (inactive)" org-time-stamp-inactive t]
19785 ["1 Day Later" org-shiftright t]
19786 ["1 Day Earlier" org-shiftleft t]
19787 ["1 ... Later" org-shiftup t]
19788 ["1 ... Earlier" org-shiftdown t])
19789 ["Compute Time Range" org-evaluate-time-range t]
19790 ["Schedule Item" org-schedule t]
19791 ["Deadline" org-deadline t]
19793 ["Custom time format" org-toggle-time-stamp-overlays
19794 :style radio :selected org-display-custom-times]
19796 ["Goto Calendar" org-goto-calendar t]
19797 ["Date from Calendar" org-date-from-calendar t]
19799 ["Start/Restart Timer" org-timer-start t]
19800 ["Pause/Continue Timer" org-timer-pause-or-continue t]
19801 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
19802 ["Insert Timer String" org-timer t]
19803 ["Insert Timer Item" org-timer-item t])
19805 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
19806 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
19807 ["Clock out" org-clock-out t]
19808 ["Clock cancel" org-clock-cancel t]
19810 ["Mark as default task" org-clock-mark-default-task t]
19811 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
19812 ["Goto running clock" org-clock-goto t]
19814 ["Display times" org-clock-display t]
19815 ["Create clock table" org-clock-report t]
19817 ["Record DONE time"
19818 (progn (setq org-log-done (not org-log-done))
19819 (message "Switching to %s will %s record a timestamp"
19820 (car org-done-keywords)
19821 (if org-log-done "automatically" "not")))
19822 :style toggle :selected org-log-done])
19824 ["Agenda Command..." org-agenda t]
19825 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
19826 ("File List for Agenda")
19827 ("Special views current file"
19828 ["TODO Tree" org-show-todo-tree t]
19829 ["Check Deadlines" org-check-deadlines t]
19830 ["Timeline" org-timeline t]
19831 ["Tags/Property tree" org-match-sparse-tree t])
19833 ["Export/Publish..." org-export t]
19835 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
19836 :selected org-cdlatex-mode]
19837 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
19838 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
19839 ["Modify math symbol" org-cdlatex-math-modify
19840 (org-inside-LaTeX-fragment-p)]
19841 ["Insert citation" org-reftex-citation t]
19843 ["Template for BEAMER" (progn (require 'org-beamer)
19844 (org-insert-beamer-options-template)) t])
19847 ["Push Files and Views" org-mobile-push t]
19848 ["Get Captured and Flagged" org-mobile-pull t]
19849 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
19851 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
19854 ["Show Version" org-version t]
19855 ["Info Documentation" org-info t])
19857 ["Browse Org Group" org-customize t]
19859 ["Expand This Menu" org-create-customize-menu
19860 (fboundp 'customize-menu-create)])
19861 ["Send bug report" org-submit-bug-report t]
19864 ["Refresh setup current buffer" org-mode-restart t]
19865 ["Reload Org (after update)" org-reload t]
19866 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x r"])
19869 (defun org-info (&optional node)
19870 "Read documentation for Org-mode in the info system.
19871 With optional NODE, go directly to that node."
19873 (info (format "(org)%s" (or node ""))))
19876 (defun org-submit-bug-report ()
19877 "Submit a bug report on Org-mode via mail.
19879 Don't hesitate to report any problems or inaccurate documentation.
19881 If you don't have setup sending mail from (X)Emacs, please copy the
19882 output buffer into your mail program, as it gives us important
19883 information about your Org-mode version and configuration."
19885 (require 'reporter)
19886 (org-load-modules-maybe)
19887 (org-require-autoloaded-modules)
19888 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
19889 (reporter-submit-bug-report
19890 "emacs-orgmode@gnu.org"
19891 (org-version nil 'full)
19893 (save-window-excursion
19894 (org-pop-to-buffer-same-window (get-buffer-create "*Warn about privacy*"))
19895 (delete-other-windows)
19897 (insert "You are about to submit a bug report to the Org-mode mailing list.
19899 We would like to add your full Org-mode and Outline configuration to the
19900 bug report. This greatly simplifies the work of the maintainer and
19901 other experts on the mailing list.
19903 HOWEVER, some variables you have customized may contain private
19904 information. The names of customers, colleagues, or friends, might
19905 appear in the form of file names, tags, todo states, or search strings.
19906 If you answer yes to the prompt, you might want to check and remove
19907 such private information before sending the email.")
19908 (add-text-properties (point-min) (point-max) '(face org-warning))
19909 (when (yes-or-no-p "Include your Org-mode configuration ")
19913 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
19914 (or (and (symbol-value v)
19915 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
19917 (get v 'custom-type) (get v 'standard-value)
19918 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
19920 (kill-buffer (get-buffer "*Warn about privacy*"))
19923 "Remember to cover the basics, that is, what you expected to happen and
19924 what in fact did happen. You don't know how to make a good report? See
19926 http://orgmode.org/manual/Feedback.html#Feedback
19928 Your bug report will be posted to the Org-mode mailing list.
19929 ------------------------------------------------------------------------")
19931 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
19932 (replace-match "\\1Bug: \\3 [\\2]")))))
19935 (defun org-install-agenda-files-menu ()
19936 (let ((bl (buffer-list)))
19939 (set-buffer (pop bl))
19940 (if (derived-mode-p 'org-mode) (setq bl nil)))
19941 (when (derived-mode-p 'org-mode)
19943 '("Org") "File List for Agenda"
19946 ["Edit File List" (org-edit-agenda-file-list) t]
19947 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
19948 ["Remove Current File from List" org-remove-file t]
19949 ["Cycle through agenda files" org-cycle-agenda-files t]
19950 ["Occur in all agenda files" org-occur-in-agenda-files t]
19952 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
19957 (defun org-require-autoloaded-modules ()
19960 '(org-agenda org-archive org-ascii org-attach org-clock org-colview
19961 org-docbook org-exp org-html org-icalendar
19963 org-publish org-remember org-table
19964 org-timer org-xoxo)))
19967 (defun org-reload (&optional uncompiled)
19968 "Reload all org lisp files.
19969 With prefix arg UNCOMPILED, load the uncompiled versions."
19971 (require 'find-func)
19972 (let* ((file-re "^org\\(-.*\\)?\\.el")
19973 (dir-org (file-name-directory (org-find-library-dir "org")))
19974 (dir-org-contrib (ignore-errors
19975 (file-name-directory
19976 (org-find-library-dir "org-contribdir"))))
19978 (mapcar (lambda (el) (concat "ob" (when el (format "-%s" el)) ".el"))
19979 (append (list nil "comint" "eval" "exp" "keys"
19980 "lob" "ref" "table" "tangle")
19984 (when (cdr lang) (symbol-name (car lang))))
19985 org-babel-load-languages)))))
19987 (append babel-files
19988 (and dir-org-contrib
19989 (directory-files dir-org-contrib t file-re))
19990 (directory-files dir-org t file-re)))
19991 (remove-re (concat (if (featurep 'xemacs)
19992 "org-colview" "org-colview-xemacs")
19994 (setq files (mapcar 'file-name-sans-extension files))
19995 (setq files (mapcar
19996 (lambda (x) (if (string-match remove-re x) nil x))
19998 (setq files (delq nil files))
20001 (when (featurep (intern (file-name-nondirectory f)))
20002 (if (and (not uncompiled)
20003 (file-exists-p (concat f ".elc")))
20004 (load (concat f ".elc") nil nil 'nosuffix)
20005 (load (concat f ".el") nil nil 'nosuffix))))
20007 (load (concat dir-org "org-version.el") 'noerror nil 'nosuffix))
20008 (org-version nil 'full 'message))
20011 (defun org-customize ()
20012 "Call the customize function with org as argument."
20014 (org-load-modules-maybe)
20015 (org-require-autoloaded-modules)
20016 (customize-browse 'org))
20018 (defun org-create-customize-menu ()
20019 "Create a full customization menu for Org-mode, insert it into the menu."
20021 (org-load-modules-maybe)
20022 (org-require-autoloaded-modules)
20023 (if (fboundp 'customize-menu-create)
20026 '("Org") "Customize"
20027 `(["Browse Org group" org-customize t]
20029 ,(customize-menu-create 'org)
20030 ["Set" Custom-set t]
20031 ["Save" Custom-save t]
20032 ["Reset to Current" Custom-reset-current t]
20033 ["Reset to Saved" Custom-reset-saved t]
20034 ["Reset to Standard Settings" Custom-reset-standard t]))
20035 (message "\"Org\"-menu now contains full customization menu"))
20036 (error "Cannot expand menu (outdated version of cus-edit.el)")))
20038 ;;;; Miscellaneous stuff
20040 ;;; Generally useful functions
20042 (defun org-get-at-bol (property)
20043 "Get text property PROPERTY at beginning of line."
20044 (get-text-property (point-at-bol) property))
20046 (defun org-find-text-property-in-string (prop s)
20047 "Return the first non-nil value of property PROP in string S."
20048 (or (get-text-property 0 prop s)
20049 (get-text-property (or (next-single-property-change 0 prop s) 0)
20052 (defun org-display-warning (message) ;; Copied from Emacs-Muse
20053 "Display the given MESSAGE as a warning."
20054 (if (fboundp 'display-warning)
20055 (display-warning 'org message
20056 (if (featurep 'xemacs) 'warning :warning))
20057 (let ((buf (get-buffer-create "*Org warnings*")))
20058 (with-current-buffer buf
20059 (goto-char (point-max))
20060 (insert "Warning (Org): " message)
20063 (display-buffer buf)
20066 (defun org-eval (form)
20067 "Eval FORM and return result."
20068 (condition-case error
20070 (error (format "%%![Error: %s]" error))))
20072 (defun org-in-clocktable-p ()
20073 "Check if the cursor is in a clocktable."
20074 (let ((pos (point)) start)
20077 (and (re-search-backward "^[ \t]*#\\+BEGIN:[ \t]+clocktable" nil t)
20078 (setq start (match-beginning 0))
20079 (re-search-forward "^[ \t]*#\\+END:.*" nil t)
20080 (>= (match-end 0) pos)
20083 (defun org-in-commented-line ()
20084 "Is point in a line starting with `#'?"
20085 (equal (char-after (point-at-bol)) ?#))
20087 (defun org-in-indented-comment-line ()
20088 "Is point in a line starting with `#' after some white space?"
20091 (goto-char (point-at-bol))
20092 (looking-at "[ \t]*#"))))
20094 (defun org-in-verbatim-emphasis ()
20096 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
20098 (defun org-goto-marker-or-bmk (marker &optional bookmark)
20099 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
20100 (if (and marker (marker-buffer marker)
20101 (buffer-live-p (marker-buffer marker)))
20103 (org-pop-to-buffer-same-window (marker-buffer marker))
20104 (if (or (> marker (point-max)) (< marker (point-min)))
20107 (org-show-context 'org-goto))
20109 (bookmark-jump bookmark)
20110 (error "Cannot find location"))))
20112 (defun org-quote-csv-field (s)
20113 "Quote field for inclusion in CSV material."
20114 (if (string-match "[\",]" s)
20115 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
20118 (defun org-force-self-insert (N)
20119 "Needed to enforce self-insert under remapping."
20121 (self-insert-command N))
20123 (defun org-string-width (s)
20124 "Compute width of string, ignoring invisible characters.
20125 This ignores character with invisibility property `org-link', and also
20126 characters with property `org-cwidth', because these will become invisible
20127 upon the next fontification round."
20129 (when (or (eq t buffer-invisibility-spec)
20130 (assq 'org-link buffer-invisibility-spec))
20131 (while (setq b (text-property-any 0 (length s)
20132 'invisible 'org-link s))
20133 (setq s (concat (substring s 0 b)
20134 (substring s (or (next-single-property-change
20135 b 'invisible s) (length s)))))))
20136 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
20137 (setq s (concat (substring s 0 b)
20138 (substring s (or (next-single-property-change
20139 b 'org-cwidth s) (length s))))))
20140 (setq l (string-width s) b -1)
20141 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
20142 (setq l (- l (get-text-property b 'org-dwidth-n s))))
20145 (defun org-shorten-string (s maxlength)
20146 "Shorten string S so tht it is no longer than MAXLENGTH characters.
20147 If the string is shorter or has length MAXLENGTH, just return the
20148 original string. If it is longer, the functions finds a space in the
20149 string, breaks this string off at that locations and adds three dots
20150 as ellipsis. Including the ellipsis, the string will not be longer
20151 than MAXLENGTH. If finding a good breaking point in the string does
20152 not work, the string is just chopped off in the middle of a word
20154 (if (<= (length s) maxlength)
20156 (let* ((n (max (- maxlength 4) 1))
20157 (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
20158 (if (string-match re s)
20159 (concat (match-string 1 s) "...")
20160 (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
20162 (defun org-get-indentation (&optional line)
20163 "Get the indentation of the current line, interpreting tabs.
20164 When LINE is given, assume it represents a line and compute its indentation."
20166 (if (string-match "^ *" (org-remove-tabs line))
20169 (beginning-of-line 1)
20170 (skip-chars-forward " \t")
20171 (current-column))))
20173 (defun org-get-string-indentation (s)
20174 "What indentation has S due to SPACE and TAB at the beginning of the string?"
20175 (let ((n -1) (i 0) (w tab-width) c)
20177 (while (< (setq n (1+ n)) (length s))
20178 (setq c (aref s n))
20179 (cond ((= c ?\ ) (setq i (1+ i)))
20180 ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
20181 (t (throw 'exit t)))))
20184 (defun org-remove-tabs (s &optional width)
20185 "Replace tabulators in S with spaces.
20186 Assumes that s is a single line, starting in column 0."
20187 (setq width (or width tab-width))
20188 (while (string-match "\t" s)
20189 (setq s (replace-match
20191 (- (* width (/ (+ (match-beginning 0) width) width))
20192 (match-beginning 0)) ?\ )
20196 (defun org-fix-indentation (line ind)
20197 "Fix indentation in LINE.
20198 IND is a cons cell with target and minimum indentation.
20199 If the current indentation in LINE is smaller than the minimum,
20200 leave it alone. If it is larger than ind, set it to the target."
20201 (let* ((l (org-remove-tabs line))
20202 (i (org-get-indentation l))
20203 (i1 (car ind)) (i2 (cdr ind)))
20204 (if (>= i i2) (setq l (substring line i2)))
20206 (concat (make-string i1 ?\ ) l)
20209 (defun org-remove-indentation (code &optional n)
20210 "Remove the maximum common indentation from the lines in CODE.
20211 N may optionally be the number of spaces to remove."
20214 (org-do-remove-indentation n)
20217 (defun org-do-remove-indentation (&optional n)
20218 "Remove the maximum common indentation from the buffer."
20219 (untabify (point-min) (point-max))
20220 (let ((min 10000) re)
20223 (goto-char (point-min))
20224 (while (re-search-forward "^ *[^ \n]" nil t)
20225 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
20226 (unless (or (= min 0) (= min 10000))
20227 (setq re (format "^ \\{%d\\}" min))
20228 (goto-char (point-min))
20229 (while (re-search-forward re nil t)
20234 (defun org-fill-template (template alist)
20235 "Find each %key of ALIST in TEMPLATE and replace it."
20236 (let ((case-fold-search nil)
20238 (setq alist (sort (copy-sequence alist)
20239 (lambda (a b) (< (length (car a)) (length (car b))))))
20240 (while (setq entry (pop alist))
20242 (replace-regexp-in-string
20243 (concat "%" (regexp-quote (car entry)))
20244 (or (cdr entry) "") template t t)))
20247 (defun org-base-buffer (buffer)
20248 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
20251 (or (buffer-base-buffer buffer)
20254 (defun org-trim (s)
20255 "Remove whitespace at beginning and end of string."
20256 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
20257 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
20260 (defun org-wrap (string &optional width lines)
20261 "Wrap string to either a number of lines, or a width in characters.
20262 If WIDTH is non-nil, the string is wrapped to that width, however many lines
20263 that costs. If there is a word longer than WIDTH, the text is actually
20264 wrapped to the length of that word.
20265 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
20266 many lines, whatever width that takes.
20267 The return value is a list of lines, without newlines at the end."
20268 (let* ((words (org-split-string string "[ \t\n]+"))
20269 (maxword (apply 'max (mapcar 'org-string-width words)))
20272 (org-do-wrap words (max maxword width)))
20275 (setq ll (org-do-wrap words maxword))
20276 (if (<= (length ll) lines)
20279 (while (> (length ll) lines)
20281 (setq ll (org-do-wrap words w)))
20283 (t (error "Cannot wrap this")))))
20285 (defun org-do-wrap (words width)
20286 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
20289 (setq line (pop words))
20290 (while (and words (< (+ (length line) (length (car words))) width))
20291 (setq line (concat line " " (pop words))))
20292 (setq lines (push line lines)))
20295 (defun org-split-string (string &optional separators)
20296 "Splits STRING into substrings at SEPARATORS.
20297 No empty strings are returned if there are matches at the beginning
20298 and end of string."
20299 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
20303 (while (and (string-match rexp string
20305 (= start (match-beginning 0))
20306 (< start (length string)))
20308 (< (match-beginning 0) (length string)))
20310 (or (eq (match-beginning 0) 0)
20311 (and (eq (match-beginning 0) (match-end 0))
20312 (eq (match-beginning 0) start))
20314 (cons (substring string start (match-beginning 0))
20316 (setq start (match-end 0)))
20317 (or (eq start (length string))
20319 (cons (substring string start)
20323 (defun org-quote-vert (s)
20324 "Replace \"|\" with \"\\vert\"."
20325 (while (string-match "|" s)
20326 (setq s (replace-match "\\vert" t t s)))
20329 (defun org-uuidgen-p (s)
20330 "Is S an ID created by UUIDGEN?"
20331 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
20333 (defun org-in-src-block-p nil
20334 "Whether point is in a code source block."
20336 (when (setq ov (overlays-at (point)))
20337 (memq 'org-block-background
20338 (overlay-properties
20341 (defun org-context ()
20342 "Return a list of contexts of the current cursor position.
20343 If several contexts apply, all are returned.
20344 Each context entry is a list with a symbol naming the context, and
20345 two positions indicating start and end of the context. Possible
20348 :headline anywhere in a headline
20349 :headline-stars on the leading stars in a headline
20350 :todo-keyword on a TODO keyword (including DONE) in a headline
20351 :tags on the TAGS in a headline
20352 :priority on the priority cookie in a headline
20353 :item on the first line of a plain list item
20354 :item-bullet on the bullet/number of a plain list item
20355 :checkbox on the checkbox in a plain list item
20356 :table in an org-mode table
20357 :table-special on a special filed in a table
20358 :table-table in a table.el table
20359 :clocktable in a clocktable
20360 :src-block in a source block
20361 :link on a hyperlink
20362 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE, COMMENT, QUOTE.
20363 :target on a <<target>>
20364 :radio-target on a <<<radio-target>>>
20365 :latex-fragment on a LaTeX fragment
20366 :latex-preview on a LaTeX fragment with overlaid preview image
20368 This function expects the position to be visible because it uses font-lock
20369 faces as a help to recognize the following contexts: :table-special, :link,
20371 (let* ((f (get-text-property (point) 'face))
20372 (faces (if (listp f) f (list f)))
20373 (case-fold-search t)
20374 (p (point)) clist o)
20375 ;; First the large context
20377 ((org-at-heading-p t)
20378 (push (list :headline (point-at-bol) (point-at-eol)) clist)
20380 (beginning-of-line 1)
20381 (looking-at org-todo-line-tags-regexp))
20382 (push (org-point-in-group p 1 :headline-stars) clist)
20383 (push (org-point-in-group p 2 :todo-keyword) clist)
20384 (push (org-point-in-group p 4 :tags) clist))
20386 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
20387 (if (looking-at "\\[#[A-Z0-9]\\]")
20388 (push (org-point-in-group p 0 :priority) clist)))
20391 (push (org-point-in-group p 2 :item-bullet) clist)
20392 (push (list :item (point-at-bol)
20393 (save-excursion (org-end-of-item) (point)))
20395 (and (org-at-item-checkbox-p)
20396 (push (org-point-in-group p 0 :checkbox) clist)))
20399 (push (list :table (org-table-begin) (org-table-end)) clist)
20400 (if (memq 'org-formula faces)
20401 (push (list :table-special
20402 (previous-single-property-change p 'face)
20403 (next-single-property-change p 'face)) clist)))
20404 ((org-at-table-p 'any)
20405 (push (list :table-table) clist)))
20408 (let ((case-fold-search t))
20409 ;; New the "medium" contexts: clocktables, source blocks
20410 (cond ((org-in-clocktable-p)
20411 (push (list :clocktable
20412 (and (or (looking-at "#\\+BEGIN: clocktable")
20413 (search-backward "#+BEGIN: clocktable" nil t))
20414 (match-beginning 0))
20415 (and (re-search-forward "#\\+END:?" nil t)
20416 (match-end 0))) clist))
20417 ((org-in-src-block-p)
20418 (push (list :src-block
20419 (and (or (looking-at "#\\+BEGIN_SRC")
20420 (search-backward "#+BEGIN_SRC" nil t))
20421 (match-beginning 0))
20422 (and (search-forward "#+END_SRC" nil t)
20423 (match-beginning 0))) clist))))
20426 ;; Now the small context
20428 ((org-at-timestamp-p)
20429 (push (org-point-in-group p 0 :timestamp) clist))
20430 ((memq 'org-link faces)
20432 (previous-single-property-change p 'face)
20433 (next-single-property-change p 'face)) clist))
20434 ((memq 'org-special-keyword faces)
20435 (push (list :keyword
20436 (previous-single-property-change p 'face)
20437 (next-single-property-change p 'face)) clist))
20439 (push (org-point-in-group p 0 :target) clist)
20440 (goto-char (1- (match-beginning 0)))
20441 (if (looking-at org-radio-target-regexp)
20442 (push (org-point-in-group p 0 :radio-target) clist))
20444 ((setq o (car (delq nil
20447 (if (memq x org-latex-fragment-image-overlays) x))
20448 (overlays-at (point))))))
20449 (push (list :latex-fragment
20450 (overlay-start o) (overlay-end o)) clist)
20451 (push (list :latex-preview
20452 (overlay-start o) (overlay-end o)) clist))
20453 ((org-inside-LaTeX-fragment-p)
20454 ;; FIXME: positions wrong.
20455 (push (list :latex-fragment (point) (point)) clist)))
20457 (setq clist (nreverse (delq nil clist)))
20460 ;; FIXME: Compare with at-regexp-p Do we need both?
20461 (defun org-in-regexp (re &optional nlines visually)
20462 "Check if point is inside a match of regexp.
20463 Normally only the current line is checked, but you can include NLINES extra
20464 lines both before and after point into the search.
20465 If VISUALLY is set, require that the cursor is not after the match but
20466 really on, so that the block visually is on the match."
20468 (let ((pos (point))
20469 (eol (point-at-eol (+ 1 (or nlines 0))))
20470 (inc (if visually 1 0)))
20472 (beginning-of-line (- 1 (or nlines 0)))
20473 (while (re-search-forward re eol t)
20474 (if (and (<= (match-beginning 0) pos)
20475 (>= (+ inc (match-end 0)) pos))
20476 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
20478 (defun org-at-regexp-p (regexp)
20479 "Is point inside a match of REGEXP in the current line?"
20482 (let ((pos (point)) (end (point-at-eol)))
20483 (beginning-of-line 1)
20484 (while (re-search-forward regexp end t)
20485 (if (and (<= (match-beginning 0) pos)
20486 (>= (match-end 0) pos))
20490 (defun org-between-regexps-p (start-re end-re &optional lim-up lim-down)
20491 "Non-nil when point is between matches of START-RE and END-RE.
20493 Also return a non-nil value when point is on one of the matches.
20495 Optional arguments LIM-UP and LIM-DOWN bound the search; they are
20496 buffer positions. Default values are the positions of headlines
20497 surrounding the point.
20499 The functions returns a cons cell whose car (resp. cdr) is the
20500 position before START-RE (resp. after END-RE)."
20502 (let ((pos (point))
20503 (limit-up (or lim-up (save-excursion (outline-previous-heading))))
20504 (limit-down (or lim-down (save-excursion (outline-next-heading))))
20507 ;; Point is on a block when on START-RE or if START-RE can be
20508 ;; found before it...
20509 (and (or (org-at-regexp-p start-re)
20510 (re-search-backward start-re limit-up t))
20511 (setq beg (match-beginning 0))
20512 ;; ... and END-RE after it...
20513 (goto-char (match-end 0))
20514 (re-search-forward end-re limit-down t)
20515 (> (setq end (match-end 0)) pos)
20516 ;; ... without another START-RE in-between.
20517 (goto-char (match-beginning 0))
20518 (not (re-search-backward start-re (1+ beg) t))
20520 (cons beg end))))))
20522 (defun org-in-block-p (names)
20523 "Non-nil when point belongs to a block whose name belongs to NAMES.
20525 NAMES is a list of strings containing names of blocks.
20527 Return first block name matched, or nil. Beware that in case of
20528 nested blocks, the returned name may not belong to the closest
20532 (let ((case-fold-search t)
20533 (lim-up (save-excursion (outline-previous-heading)))
20534 (lim-down (save-excursion (outline-next-heading))))
20535 (mapc (lambda (name)
20536 (let ((n (regexp-quote name)))
20537 (when (org-between-regexps-p
20538 (concat "^[ \t]*#\\+begin_" n)
20539 (concat "^[ \t]*#\\+end_" n)
20545 (defun org-occur-in-agenda-files (regexp &optional nlines)
20546 "Call `multi-occur' with buffers for all agenda files."
20547 (interactive "sOrg-files matching: \np")
20548 (let* ((files (org-agenda-files))
20549 (tnames (mapcar 'file-truename files))
20550 (extra org-agenda-text-search-extra-files)
20552 (when (eq (car extra) 'agenda-archives)
20553 (setq extra (cdr extra))
20554 (setq files (org-add-archive-files files)))
20555 (while (setq f (pop extra))
20556 (unless (member (file-truename f) tnames)
20557 (add-to-list 'files f 'append)
20558 (add-to-list 'tnames (file-truename f) 'append)))
20560 (mapcar (lambda (x)
20561 (with-current-buffer
20562 (or (get-file-buffer x) (find-file-noselect x))
20568 (if (boundp 'occur-mode-find-occurrence-hook)
20570 (add-hook 'occur-mode-find-occurrence-hook
20572 (when (derived-mode-p 'org-mode)
20575 (defadvice occur-mode-goto-occurrence
20576 (after org-occur-reveal activate)
20577 (and (derived-mode-p 'org-mode) (org-reveal)))
20578 (defadvice occur-mode-goto-occurrence-other-window
20579 (after org-occur-reveal activate)
20580 (and (derived-mode-p 'org-mode) (org-reveal)))
20581 (defadvice occur-mode-display-occurrence
20582 (after org-occur-reveal activate)
20583 (when (derived-mode-p 'org-mode)
20584 (let ((pos (occur-mode-find-occurrence)))
20585 (with-current-buffer (marker-buffer pos)
20590 (defun org-occur-link-in-agenda-files ()
20591 "Create a link and search for it in the agendas.
20592 The link is not stored in `org-stored-links', it is just created
20593 for the search purpose."
20595 (let ((link (condition-case nil
20596 (org-store-link nil)
20597 (error "Unable to create a link to here"))))
20598 (org-occur-in-agenda-files (regexp-quote link))))
20600 (defun org-uniquify (list)
20601 "Remove duplicate elements from LIST."
20603 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
20606 (defun org-delete-all (elts list)
20607 "Remove all elements in ELTS from LIST."
20609 (setq list (delete (pop elts) list)))
20612 (defun org-count (cl-item cl-seq)
20613 "Count the number of occurrences of ITEM in SEQ.
20614 Taken from `count' in cl-seq.el with all keyword arguments removed."
20615 (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0) cl-x)
20616 (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
20617 (while (< cl-start cl-end)
20618 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
20619 (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
20620 (setq cl-start (1+ cl-start)))
20623 (defun org-remove-if (predicate seq)
20624 "Remove everything from SEQ that fulfills PREDICATE."
20628 (if (not (funcall predicate e)) (push e res)))
20631 (defun org-remove-if-not (predicate seq)
20632 "Remove everything from SEQ that does not fulfill PREDICATE."
20636 (if (funcall predicate e) (push e res)))
20639 (defun org-reduce (cl-func cl-seq &rest cl-keys)
20640 "Reduce two-argument FUNCTION across SEQ.
20641 Taken from `reduce' in cl-seq.el with all keyword arguments but
20642 \":initial-value\" removed."
20643 (let ((cl-accum (cond ((memq :initial-value cl-keys)
20644 (cadr (memq :initial-value cl-keys)))
20645 (cl-seq (pop cl-seq))
20646 (t (funcall cl-func)))))
20648 (setq cl-accum (funcall cl-func cl-accum (pop cl-seq))))
20651 (defun org-back-over-empty-lines ()
20652 "Move backwards over whitespace, to the beginning of the first empty line.
20653 Returns the number of empty lines passed."
20654 (let ((pos (point)))
20655 (if (cdr (assoc 'heading org-blank-before-new-entry))
20656 (skip-chars-backward " \t\n\r")
20658 (forward-line -1)))
20659 (beginning-of-line 2)
20660 (goto-char (min (point) pos))
20661 (count-lines (point) pos)))
20663 (defun org-skip-whitespace ()
20664 (skip-chars-forward " \t\n\r"))
20666 (defun org-point-in-group (point group &optional context)
20667 "Check if POINT is in match-group GROUP.
20668 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
20669 match. If the match group does not exist or point is not inside it,
20671 (and (match-beginning group)
20672 (>= point (match-beginning group))
20673 (<= point (match-end group))
20675 (list context (match-beginning group) (match-end group))
20678 (defun org-switch-to-buffer-other-window (&rest args)
20679 "Switch to buffer in a second window on the current frame.
20680 In particular, do not allow pop-up frames.
20681 Returns the newly created buffer."
20682 (let (pop-up-frames special-display-buffer-names special-display-regexps
20683 special-display-function)
20684 (apply 'switch-to-buffer-other-window args)))
20686 (defun org-combine-plists (&rest plists)
20687 "Create a single property list from all plists in PLISTS.
20688 The process starts by copying the first list, and then setting properties
20689 from the other lists. Settings in the last list are the most significant
20690 ones and overrule settings in the other lists."
20691 (let ((rtn (copy-sequence (pop plists)))
20694 (setq ls (pop plists))
20696 (setq p (pop ls) v (pop ls))
20697 (setq rtn (plist-put rtn p v))))
20700 (defun org-replace-escapes (string table)
20701 "Replace %-escapes in STRING with values in TABLE.
20702 TABLE is an association list with keys like \"%a\" and string values.
20703 The sequences in STRING may contain normal field width and padding information,
20704 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
20705 so values can contain further %-escapes if they are define later in TABLE."
20706 (let ((tbl (copy-alist table))
20707 (case-fold-search nil)
20710 (while (setq e (pop tbl))
20711 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
20712 (when (and (cdr e) (string-match re (cdr e)))
20713 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
20715 (add-text-properties 0 3 (list 'sref sref) safe)
20716 (setcdr e (replace-match safe t t (cdr e)))))
20717 (while (string-match re string)
20718 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
20720 (setq string (replace-match rpl t t string))))
20721 (while (setq pchg (next-property-change pchg string))
20722 (let ((sref (get-text-property pchg 'sref string)))
20723 (when (and sref (string-match "SREF" string pchg))
20724 (setq string (replace-match sref t t string)))))
20727 (defun org-sublist (list start end)
20728 "Return a section of LIST, from START to END.
20729 Counting starts at 1."
20730 (let (rtn (c start))
20731 (setq list (nthcdr (1- start) list))
20732 (while (and list (<= c end))
20733 (push (pop list) rtn)
20737 (defun org-find-base-buffer-visiting (file)
20738 "Like `find-buffer-visiting' but always return the base buffer and
20739 not an indirect buffer."
20740 (let ((buf (or (get-file-buffer file)
20741 (find-buffer-visiting file))))
20743 (or (buffer-base-buffer buf) buf)
20746 (defun org-image-file-name-regexp (&optional extensions)
20747 "Return regexp matching the file names of images.
20748 If EXTENSIONS is given, only match these."
20749 (if (and (not extensions) (fboundp 'image-file-name-regexp))
20750 (image-file-name-regexp)
20751 (let ((image-file-name-extensions
20753 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
20754 "xbm" "xpm" "pbm" "pgm" "ppm"))))
20756 (regexp-opt (nconc (mapcar 'upcase
20757 image-file-name-extensions)
20758 image-file-name-extensions)
20762 (defun org-file-image-p (file &optional extensions)
20763 "Return non-nil if FILE is an image."
20765 (string-match (org-image-file-name-regexp extensions) file)))
20767 (defun org-get-cursor-date ()
20768 "Return the date at cursor in as a time.
20769 This works in the calendar and in the agenda, anywhere else it just
20770 returns the current time."
20771 (let (date day defd)
20773 ((eq major-mode 'calendar-mode)
20774 (setq date (calendar-cursor-to-date)
20775 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
20776 ((eq major-mode 'org-agenda-mode)
20777 (setq day (get-text-property (point) 'day))
20779 (setq date (calendar-gregorian-from-absolute day)
20780 defd (encode-time 0 0 0 (nth 1 date) (nth 0 date)
20782 (or defd (current-time))))
20784 (defvar org-agenda-action-marker (make-marker)
20785 "Marker pointing to the entry for the next agenda action.")
20787 (defun org-mark-entry-for-agenda-action ()
20788 "Mark the current entry as target of an agenda action.
20789 Agenda actions are actions executed from the agenda with the key `k',
20790 which make use of the date at the cursor."
20792 (move-marker org-agenda-action-marker
20793 (save-excursion (org-back-to-heading t) (point))
20796 "Entry marked for action; press `k' at desired date in agenda or calendar"))
20798 (defun org-mark-subtree (&optional up)
20799 "Mark the current subtree.
20800 This puts point at the start of the current subtree, and mark at
20801 the end. If a numeric prefix UP is given, move up into the
20802 hierarchy of headlines by UP levels before marking the subtree."
20804 (org-with-limited-levels
20805 (cond ((org-at-heading-p) (beginning-of-line))
20806 ((org-before-first-heading-p) (error "Not in a subtree"))
20807 (t (outline-previous-visible-heading 1))))
20808 (when up (while (and (> up 0) (org-up-heading-safe)) (decf up)))
20809 (if (org-called-interactively-p 'any)
20810 (call-interactively 'org-mark-element)
20811 (org-mark-element)))
20815 (defun org-indent-line ()
20816 "Indent line depending on context."
20818 (let* ((pos (point))
20819 (itemp (org-at-item-p))
20820 (case-fold-search t)
20821 (org-drawer-regexp (or org-drawer-regexp "\000"))
20822 (inline-task-p (and (featurep 'org-inlinetask)
20823 (org-inlinetask-in-task-p)))
20824 (inline-re (and inline-task-p
20825 (org-inlinetask-outline-regexp)))
20827 (if (and orgstruct-is-++ (eq pos (point)))
20828 (let ((indent-line-function (cadadr (assoc 'indent-line-function org-fb-vars))))
20829 (indent-according-to-mode))
20830 (beginning-of-line 1)
20833 ((looking-at org-outline-regexp) (setq column 0))
20835 ((looking-at "#\\+include:") (setq column 0))
20836 ;; Footnote definition
20837 ((looking-at org-footnote-definition-re) (setq column 0))
20838 ;; Literal examples
20839 ((looking-at "[ \t]*:\\( \\|$\\)")
20840 (setq column (org-get-indentation))) ; do nothing
20842 ((ignore-errors (goto-char (org-in-item-p)))
20843 (setq column (if itemp
20844 (org-get-indentation)
20845 (org-list-item-body-column (point))))
20848 ((and (looking-at "[ \t]*:END:")
20849 (save-excursion (re-search-backward org-drawer-regexp nil t)))
20851 (goto-char (1- (match-beginning 1)))
20852 (setq column (current-column))))
20854 ((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
20856 (re-search-backward
20857 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
20858 (setq column (org-get-indentation (match-string 0))))
20859 ((and (not (looking-at "[ \t]*#\\+begin_"))
20860 (org-between-regexps-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
20862 (re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
20864 (cond ((equal (downcase (match-string 1)) "src")
20865 ;; src blocks: let `org-edit-src-exit' handle them
20866 (org-get-indentation))
20867 ((equal (downcase (match-string 1)) "example")
20868 (max (org-get-indentation)
20869 (org-get-indentation (match-string 0))))
20871 (org-get-indentation (match-string 0))))))
20872 ;; This line has nothing special, look at the previous relevant
20873 ;; line to compute indentation
20875 (beginning-of-line 0)
20876 (while (and (not (bobp))
20877 (not (looking-at org-drawer-regexp))
20878 ;; When point started in an inline task, do not move
20879 ;; above task starting line.
20880 (not (and inline-task-p (looking-at inline-re)))
20881 ;; Skip drawers, blocks, empty lines, verbatim,
20882 ;; comments, tables, footnotes definitions, lists,
20884 (or (and (looking-at "[ \t]*:END:")
20885 (re-search-backward org-drawer-regexp nil t))
20886 (and (looking-at "[ \t]*#\\+end_")
20887 (re-search-backward "[ \t]*#\\+begin_"nil t))
20888 (looking-at "[ \t]*[\n:#|]")
20889 (looking-at org-footnote-definition-re)
20890 (and (ignore-errors (goto-char (org-in-item-p)))
20892 (org-list-get-top-point (org-list-struct))))
20893 (and (not inline-task-p)
20894 (featurep 'org-inlinetask)
20895 (org-inlinetask-in-task-p)
20896 (or (org-inlinetask-goto-beginning) t))))
20897 (beginning-of-line 0))
20899 ;; There was an heading above.
20900 ((looking-at "\\*+[ \t]+")
20901 (if (not org-adapt-indentation)
20903 (goto-char (match-end 0))
20904 (setq column (current-column))))
20905 ;; A drawer had started and is unfinished
20906 ((looking-at org-drawer-regexp)
20907 (goto-char (1- (match-beginning 1)))
20908 (setq column (current-column)))
20909 ;; Else, nothing noticeable found: get indentation and go on.
20910 (t (setq column (org-get-indentation))))))
20911 ;; Now apply indentation and move cursor accordingly
20913 (if (<= (current-column) (current-indentation))
20914 (org-indent-line-to column)
20915 (save-excursion (org-indent-line-to column)))
20916 ;; Special polishing for properties, see `org-property-format'
20917 (setq column (current-column))
20918 (beginning-of-line 1)
20920 "\\([ \t]*\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
20921 (replace-match (concat (match-string 1)
20922 (format org-property-format
20923 (match-string 2) (match-string 3)))
20925 (org-move-to-column column))))
20927 (defun org-indent-drawer ()
20928 "Indent the drawer at point."
20931 (e (and (save-excursion (re-search-forward ":END:" nil t))
20936 (when (overlays-at (point))
20937 (member 'invisible (overlay-properties
20938 (car (overlays-at (point)))))))))
20939 (when folded (org-cycle))
20940 (indent-for-tab-command)
20941 (while (and (move-beginning-of-line 2) (< (point) e))
20942 (indent-for-tab-command))
20944 (when folded (org-cycle)))
20945 (message "Drawer at point indented"))
20947 (defun org-indent-block ()
20948 "Indent the block at point."
20951 (case-fold-search t)
20952 (e (and (save-excursion (re-search-forward "#\\+end_?\\(?:[a-z]+\\)?" nil t))
20957 (when (overlays-at (point))
20958 (member 'invisible (overlay-properties
20959 (car (overlays-at (point)))))))))
20960 (when folded (org-cycle))
20961 (indent-for-tab-command)
20962 (while (and (move-beginning-of-line 2) (< (point) e))
20963 (indent-for-tab-command))
20965 (when folded (org-cycle)))
20966 (message "Block at point indented"))
20968 (defun org-indent-region (start end)
20972 (let ((line-end (org-current-line end)))
20974 (while (< (org-current-line) line-end)
20975 (cond ((org-in-src-block-p) (org-src-native-tab-command-maybe))
20976 (t (call-interactively 'org-indent-line)))
20977 (move-beginning-of-line 2)))))
20982 ;; We use our own fill-paragraph and auto-fill functions.
20984 ;; `org-fill-paragraph' relies on adaptive filling and context
20985 ;; checking. Appropriate `fill-prefix' is computed with
20986 ;; `org-adaptive-fill-function'.
20988 ;; `org-auto-fill-function' takes care of auto-filling. It calls
20989 ;; `do-auto-fill' only on valid areas with `fill-prefix' shadowed with
20990 ;; `org-adaptive-fill-function' value. Internally,
20991 ;; `org-comment-line-break-function' breaks the line.
20993 ;; `org-setup-filling' installs filling and auto-filling related
20994 ;; variables during `org-mode' initialization.
20996 (defun org-setup-filling ()
20998 ;; Prevent auto-fill from inserting unwanted new items.
20999 (when (boundp 'fill-nobreak-predicate)
21001 'fill-nobreak-predicate
21003 (append fill-nobreak-predicate
21004 '(org-fill-paragraph-separate-nobreak-p
21005 org-fill-line-break-nobreak-p)))))
21006 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
21007 (org-set-local 'adaptive-fill-function 'org-adaptive-fill-function)
21008 (org-set-local 'normal-auto-fill-function 'org-auto-fill-function)
21009 (org-set-local 'comment-line-break-function 'org-comment-line-break-function))
21011 (defvar org-element-paragraph-separate) ; org-element.el
21012 (defun org-fill-paragraph-separate-nobreak-p ()
21013 "Non-nil when a line break at point would insert a new item."
21014 (looking-at (substring org-element-paragraph-separate 1)))
21016 (defun org-fill-line-break-nobreak-p ()
21017 "Non-nil when a line break at point would create an Org line break."
21019 (skip-chars-backward "[ \t]")
21020 (skip-chars-backward "\\\\")
21021 (looking-at "\\\\\\\\\\($\\|[^\\\\]\\)")))
21023 (declare-function message-in-body-p "message" ())
21024 (defvar org-element--affiliated-re) ; From org-element.el
21025 (defun org-adaptive-fill-function ()
21026 "Compute a fill prefix for the current line.
21027 Return fill prefix, as a string, or nil if current line isn't
21028 meant to be filled."
21029 (org-with-wide-buffer
21030 (unless (and (derived-mode-p 'message-mode) (not (message-in-body-p)))
21031 ;; FIXME: This is really the job of orgstruct++-mode
21032 (let* ((p (line-beginning-position))
21033 (element (save-excursion (beginning-of-line)
21034 (org-element-at-point)))
21035 (type (org-element-type element))
21038 (goto-char (org-element-property :begin element))
21039 (while (looking-at org-element--affiliated-re) (forward-line))
21041 (unless (< p post-affiliated)
21043 (comment (looking-at "[ \t]*# ?") (match-string 0))
21044 (footnote-definition "")
21046 (make-string (org-list-item-body-column post-affiliated) ? ))
21048 ;; Fill prefix is usually the same as the current line,
21049 ;; except if the paragraph is at the beginning of an item.
21050 (let ((parent (org-element-property :parent element)))
21051 (cond ((eq (org-element-type parent) 'item)
21052 (make-string (org-list-item-body-column
21053 (org-element-property :begin parent))
21055 ((save-excursion (beginning-of-line) (looking-at "[ \t]+"))
21059 ;; Only fill contents if P is within block boundaries.
21060 (let* ((cbeg (save-excursion (goto-char post-affiliated)
21063 (cend (save-excursion
21064 (goto-char (org-element-property :end element))
21065 (skip-chars-backward " \r\t\n")
21066 (line-beginning-position))))
21067 (when (and (>= p cbeg) (< p cend))
21068 (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
21072 (declare-function message-goto-body "message" ())
21073 (defvar message-cite-prefix-regexp) ; From message.el
21074 (defvar org-element-all-objects) ; From org-element.el
21075 (defun org-fill-paragraph (&optional justify)
21076 "Fill element at point, when applicable.
21078 This function only applies to comment blocks, comments, example
21079 blocks and paragraphs. Also, as a special case, re-align table
21080 when point is at one.
21082 If JUSTIFY is non-nil (interactively, with prefix argument),
21083 justify as well. If `sentence-end-double-space' is non-nil, then
21084 period followed by one space does not end a sentence, so don't
21085 break a line there. The variable `fill-column' controls the
21088 For convenience, when point is at a plain list, an item or
21089 a footnote definition, try to fill the first paragraph within."
21090 ;; Falls back on message-fill-paragraph when necessary
21092 (if (and (derived-mode-p 'message-mode)
21093 (or (not (message-in-body-p))
21094 (save-excursion (move-beginning-of-line 1)
21095 (looking-at message-cite-prefix-regexp))))
21096 (let ((fill-paragraph-function
21097 (cadadr (assoc 'fill-paragraph-function org-fb-vars)))
21098 (fill-prefix (cadadr (assoc 'fill-prefix org-fb-vars)))
21099 (paragraph-start (cadadr (assoc 'paragraph-start org-fb-vars)))
21100 (paragraph-separate
21101 (cadadr (assoc 'paragraph-separate org-fb-vars))))
21102 (fill-paragraph nil))
21104 ;; Move to end of line in order to get the first paragraph
21105 ;; within a plain list or a footnote definition.
21107 (let ((element (org-element-at-point)))
21108 ;; First check if point is in a blank line at the beginning of
21109 ;; the buffer. In that case, ignore filling.
21110 (if (< (point) (org-element-property :begin element)) t
21111 (case (org-element-type element)
21112 ;; Align Org tables, leave table.el tables as-is.
21113 (table-row (org-table-align) t)
21115 (when (eq (org-element-property :type element) 'org)
21119 ;; Paragraphs may contain `line-break' type objects.
21120 (let ((beg (max (point-min)
21121 (org-element-property :contents-begin element)))
21122 (end (min (point-max)
21123 (org-element-property :contents-end element))))
21124 ;; Do nothing if point is at an affiliated keyword.
21125 (if (< (point) beg) t
21126 (when (derived-mode-p 'message-mode)
21127 ;; In `message-mode', do not fill following
21128 ;; citation in current paragraph nor text before
21130 (let ((body-start (save-excursion (message-goto-body))))
21131 (when body-start (setq beg (max body-start beg))))
21132 (when (save-excursion
21134 (concat "^" message-cite-prefix-regexp) end t))
21135 (setq end (match-beginning 0))))
21136 ;; Fill paragraph, taking line breaks into
21137 ;; consideration. For that, slice the paragraph
21138 ;; using line breaks as separators, and fill the
21139 ;; parts in reverse order to avoid messing with
21145 (fill-region-as-paragraph pos (point) justify)
21147 ;; Find the list of ending positions for line
21148 ;; breaks in the current paragraph. Add paragraph
21149 ;; beginning to include first slice.
21154 (org-element--parse-objects
21155 beg end nil org-element-all-objects)
21157 (lambda (lb) (org-element-property :end lb)))))))
21159 ;; Contents of `comment-block' type elements should be
21160 ;; filled as plain text, but only if point is within block
21163 (let* ((case-fold-search t)
21164 (beg (save-excursion
21165 (goto-char (org-element-property :begin element))
21166 (re-search-forward "^[ \t]*#\\+begin_comment" nil t)
21169 (end (save-excursion
21170 (goto-char (org-element-property :end element))
21171 (re-search-backward "^[ \t]*#\\+end_comment" nil t)
21172 (line-beginning-position))))
21173 (when (and (>= (point) beg) (< (point) end))
21174 (fill-region-as-paragraph
21177 (re-search-backward "^[ \t]*$" beg 'move)
21178 (line-beginning-position))
21180 (beginning-of-line)
21181 (re-search-forward "^[ \t]*$" end 'move)
21182 (line-beginning-position))
21186 (comment (fill-comment-paragraph justify))
21187 ;; Ignore every other element.
21188 (otherwise t)))))))
21190 (defun org-auto-fill-function ()
21191 "Auto-fill function."
21192 ;; Check if auto-filling is meaningful.
21193 (let ((fc (current-fill-column)))
21194 (when (and fc (> (current-column) fc))
21195 (let ((fill-prefix (org-adaptive-fill-function)))
21196 (when fill-prefix (do-auto-fill))))))
21198 (defun org-comment-line-break-function (&optional soft)
21199 "Break line at point and indent, continuing comment if within one.
21200 The inserted newline is marked hard if variable
21201 `use-hard-newlines' is true, unless optional argument SOFT is
21203 (if soft (insert-and-inherit ?\n) (newline 1))
21204 (save-excursion (forward-char -1) (delete-horizontal-space))
21205 (delete-horizontal-space)
21206 (indent-to-left-margin)
21207 (insert-before-markers-and-inherit fill-prefix))
21212 ;; Org comments syntax is quite complex. It requires the entire line
21213 ;; to be just a comment. Also, even with the right syntax at the
21214 ;; beginning of line, some some elements (i.e. verse-block or
21215 ;; example-block) don't accept comments. Usual Emacs comment commands
21216 ;; cannot cope with those requirements. Therefore, Org replaces them.
21218 ;; Org still relies on `comment-dwim', but cannot trust
21219 ;; `comment-only-p'. So, `comment-region-function' and
21220 ;; `uncomment-region-function' both point
21221 ;; to`org-comment-or-uncomment-region'. Eventually,
21222 ;; `org-insert-comment' takes care of insertion of comments at the
21223 ;; beginning of line.
21225 ;; `org-setup-comments-handling' install comments related variables
21226 ;; during `org-mode' initialization.
21228 (defun org-setup-comments-handling ()
21230 (org-set-local 'comment-use-syntax nil)
21231 (org-set-local 'comment-start "# ")
21232 (org-set-local 'comment-start-skip "^\\s-*#\\(?: \\|$\\)")
21233 (org-set-local 'comment-insert-comment-function 'org-insert-comment)
21234 (org-set-local 'comment-region-function 'org-comment-or-uncomment-region)
21235 (org-set-local 'uncomment-region-function 'org-comment-or-uncomment-region))
21237 (defun org-insert-comment ()
21238 "Insert an empty comment above current line.
21239 If the line is empty, insert comment at its beginning."
21240 (beginning-of-line)
21241 (if (looking-at "\\s-*$") (replace-match "") (open-line 1))
21245 (defvar comment-empty-lines) ; From newcomment.el.
21246 (defun org-comment-or-uncomment-region (beg end &rest ignore)
21247 "Comment or uncomment each non-blank line in the region.
21248 Uncomment each non-blank line between BEG and END if it only
21249 contains commented lines. Otherwise, comment them."
21252 (narrow-to-region (save-excursion (goto-char beg)
21253 (skip-chars-forward " \r\t\n" end)
21254 (line-beginning-position))
21255 (save-excursion (goto-char end)
21256 (skip-chars-backward " \r\t\n" beg)
21257 (line-end-position)))
21259 ;; UNCOMMENTP is non-nil when every non blank line between
21260 ;; BEG and END is a comment.
21262 (goto-char (point-min))
21263 (while (and (not (eobp))
21264 (let ((element (org-element-at-point)))
21265 (and (eq (org-element-type element) 'comment)
21266 (goto-char (min (point-max)
21267 (org-element-property
21268 :end element)))))))
21271 ;; Only blank lines and comments in region: uncomment it.
21273 (goto-char (point-min))
21274 (while (not (eobp))
21275 (when (looking-at "[ \t]*\\(#\\(?: \\|$\\)\\)")
21276 (replace-match "" nil nil nil 1))
21278 ;; Comment each line in region.
21279 (let ((min-indent (point-max)))
21280 ;; First find the minimum indentation across all lines.
21282 (goto-char (point-min))
21283 (while (and (not (eobp)) (not (zerop min-indent)))
21284 (unless (looking-at "[ \t]*$")
21285 (setq min-indent (min min-indent (current-indentation))))
21287 ;; Then loop over all lines.
21289 (goto-char (point-min))
21290 (while (not (eobp))
21291 (unless (and (not comment-empty-lines) (looking-at "[ \t]*$"))
21292 (org-move-to-column min-indent t)
21293 (insert comment-start))
21294 (forward-line))))))))
21299 (defun org-toggle-fixed-width-section (arg)
21300 "Toggle the fixed-width export.
21301 If there is no active region, the QUOTE keyword at the current headline is
21302 inserted or removed. When present, it causes the text between this headline
21303 and the next to be exported as fixed-width text, and unmodified.
21304 If there is an active region, this command adds or removes a colon as the
21305 first character of this line. If the first character of a line is a colon,
21306 this line is also exported in fixed-width font."
21309 (regionp (org-region-active-p))
21310 (beg (if regionp (region-beginning) (point)))
21311 (end (if regionp (region-end)))
21312 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
21313 (case-fold-search nil)
21314 (re "[ \t]*\\(:\\(?: \\|$\\)\\)")
21319 (setq cc (current-column))
21320 (beginning-of-line 1)
21321 (setq off (looking-at re))
21322 (while (> nlines 0)
21323 (setq nlines (1- nlines))
21324 (beginning-of-line 1)
21327 (org-move-to-column cc t)
21330 ((and off (looking-at re))
21331 (replace-match "" t t nil 1))
21332 ((not off) (org-move-to-column cc t) (insert ": ")))
21335 (org-back-to-heading)
21337 ((looking-at (format org-heading-keyword-regexp-format
21339 (goto-char (match-end 1))
21340 (looking-at (concat " +" org-quote-string))
21341 (replace-match "" t t)
21342 (when (eolp) (insert " ")))
21343 ((looking-at org-outline-regexp)
21344 (goto-char (match-end 0))
21345 (insert org-quote-string " ")))))))
21347 (defun org-reftex-citation ()
21348 "Use reftex-citation to insert a citation into the buffer.
21349 This looks for a line like
21351 #+BIBLIOGRAPHY: foo plain option:-d
21353 and derives from it that foo.bib is the bibliography file relevant
21354 for this document. It then installs the necessary environment for RefTeX
21355 to work in this buffer and calls `reftex-citation' to insert a citation
21358 Export of such citations to both LaTeX and HTML is handled by the contributed
21359 package org-exp-bibtex by Taru Karttunen."
21361 (let ((reftex-docstruct-symbol 'rds)
21362 (reftex-cite-format "\\cite{%l}")
21367 (let ((case-fold-search t)
21368 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
21369 (if (not (save-excursion
21370 (or (re-search-forward re nil t)
21371 (re-search-backward re nil t))))
21372 (error "No bibliography defined in file")
21373 (setq bib (concat (match-string 1) ".bib")
21374 rds (list (list 'bib bib)))))))
21375 (call-interactively 'reftex-citation)))
21377 ;;;; Functions extending outline functionality
21379 (defun org-beginning-of-line (&optional arg)
21380 "Go to the beginning of the current line. If that is invisible, continue
21381 to a visible line beginning. This makes the function of C-a more intuitive.
21382 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
21383 first attempt, and only move to after the tags when the cursor is already
21384 beyond the end of the headline."
21386 (let ((pos (point))
21387 (special (if (consp org-special-ctrl-a/e)
21388 (car org-special-ctrl-a/e)
21389 org-special-ctrl-a/e))
21391 (if (org-bound-and-true-p line-move-visual)
21392 (beginning-of-visual-line 1)
21393 (beginning-of-line 1))
21394 (if (and arg (fboundp 'move-beginning-of-line))
21395 (call-interactively 'move-beginning-of-line)
21399 (if (org-truely-invisible-p)
21400 (while (and (not (bobp)) (org-truely-invisible-p))
21402 (beginning-of-line 1))
21403 (forward-char 1))))
21406 ((and (looking-at org-complex-heading-regexp)
21407 (= (char-after (match-end 1)) ?\ ))
21408 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
21412 (cond ((> pos refpos) refpos)
21413 ((= pos (point)) refpos)
21415 (cond ((> pos (point)) (point))
21416 ((not (eq last-command this-command)) (point))
21419 ;; Being at an item and not looking at an the item means point
21420 ;; was previously moved to beginning of a visual line, which
21421 ;; doesn't contain the item. Therefore, do nothing special,
21423 (when (looking-at org-list-full-item-re)
21424 ;; Set special position at first white space character after
21425 ;; bullet, and check-box, if any.
21426 (let ((after-bullet
21427 (let ((box (match-end 3)))
21428 (if (not box) (match-end 1)
21429 (let ((after (char-after box)))
21430 (if (and after (= after ? )) (1+ box) box))))))
21431 ;; Special case: Move point to special position when
21432 ;; currently after it or at beginning of line.
21434 (when (or (> pos after-bullet) (= (point) pos))
21435 (goto-char after-bullet))
21436 ;; Reversed case: Move point to special position when
21437 ;; point was already at beginning of line and command is
21439 (when (and (= (point) pos) (eq last-command this-command))
21440 (goto-char after-bullet))))))))
21442 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
21444 (defun org-end-of-line (&optional arg)
21445 "Go to the end of the line.
21446 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
21447 first attempt, and only move to after the tags when the cursor is already
21448 beyond the end of the headline."
21450 (let ((special (if (consp org-special-ctrl-a/e)
21451 (cdr org-special-ctrl-a/e)
21452 org-special-ctrl-a/e)))
21454 ((or (not special) arg
21455 (not (or (org-at-heading-p) (org-at-item-p) (org-at-drawer-p))))
21456 (call-interactively
21457 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
21458 ((fboundp 'move-end-of-line) 'move-end-of-line)
21459 (t 'end-of-line))))
21460 ((org-at-heading-p)
21461 (let ((pos (point)))
21462 (beginning-of-line 1)
21463 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$"))
21465 (if (or (< pos (match-beginning 1))
21466 (= pos (match-end 0)))
21467 (goto-char (match-beginning 1))
21468 (goto-char (match-end 0)))
21469 (if (or (< pos (match-end 0)) (not (eq this-command last-command)))
21470 (goto-char (match-end 0))
21471 (goto-char (match-beginning 1))))
21472 (call-interactively (if (fboundp 'move-end-of-line)
21476 (move-end-of-line 1)
21477 (when (overlays-at (1- (point))) (backward-char 1)))
21478 ;; At an item: Move before any hidden text.
21479 (t (call-interactively
21480 (cond ((org-bound-and-true-p line-move-visual) 'end-of-visual-line)
21481 ((fboundp 'move-end-of-line) 'move-end-of-line)
21482 (t 'end-of-line)))))
21484 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
21486 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
21487 (define-key org-mode-map "\C-e" 'org-end-of-line)
21489 (defun org-backward-sentence (&optional arg)
21490 "Go to beginning of sentence, or beginning of table field.
21491 This will call `backward-sentence' or `org-table-beginning-of-field',
21492 depending on context."
21495 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
21496 (t (call-interactively 'backward-sentence))))
21498 (defun org-forward-sentence (&optional arg)
21499 "Go to end of sentence, or end of table field.
21500 This will call `forward-sentence' or `org-table-end-of-field',
21501 depending on context."
21504 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
21505 (t (call-interactively 'forward-sentence))))
21507 (define-key org-mode-map "\M-a" 'org-backward-sentence)
21508 (define-key org-mode-map "\M-e" 'org-forward-sentence)
21510 (defun org-kill-line (&optional arg)
21511 "Kill line, to tags or end of line."
21514 ((or (not org-special-ctrl-k)
21516 (not (org-at-heading-p)))
21517 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
21518 org-ctrl-k-protect-subtree)
21519 (if (or (eq org-ctrl-k-protect-subtree 'error)
21520 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
21521 (error "C-k aborted - would kill hidden subtree")))
21522 (call-interactively
21523 (if (and (boundp 'visual-line-mode) visual-line-mode) 'kill-visual-line 'kill-line)))
21524 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$"))
21525 (kill-region (point) (match-beginning 1))
21526 (org-set-tags nil t))
21527 (t (kill-region (point) (point-at-eol)))))
21529 (define-key org-mode-map "\C-k" 'org-kill-line)
21531 (defun org-yank (&optional arg)
21532 "Yank. If the kill is a subtree, treat it specially.
21533 This command will look at the current kill and check if is a single
21534 subtree, or a series of subtrees[1]. If it passes the test, and if the
21535 cursor is at the beginning of a line or after the stars of a currently
21536 empty headline, then the yank is handled specially. How exactly depends
21537 on the value of the following variables, both set by default.
21539 org-yank-folded-subtrees
21540 When set, the subtree(s) will be folded after insertion, but only
21541 if doing so would now swallow text after the yanked text.
21543 org-yank-adjusted-subtrees
21544 When set, the subtree will be promoted or demoted in order to
21545 fit into the local outline tree structure, which means that the level
21546 will be adjusted so that it becomes the smaller one of the two
21547 *visible* surrounding headings.
21549 Any prefix to this command will cause `yank' to be called directly with
21550 no special treatment. In particular, a simple \\[universal-argument] prefix \
21552 plainly yank the text as it is.
21554 \[1] The test checks if the first non-white line is a heading
21555 and if there are no other headings with fewer stars."
21557 (org-yank-generic 'yank arg))
21559 (defun org-yank-generic (command arg)
21560 "Perform some yank-like command.
21562 This function implements the behavior described in the `org-yank'
21563 documentation. However, it has been generalized to work for any
21564 interactive command with similar behavior."
21566 ;; pretend to be command COMMAND
21567 (setq this-command command)
21570 (call-interactively command)
21572 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
21573 (and (org-kill-is-subtree-p)
21575 (and (looking-at "[ \t]*$")
21578 (buffer-substring (point-at-bol) (point)))))))
21581 ((and subtreep org-yank-folded-subtrees)
21582 (let ((beg (point))
21584 (if (and subtreep org-yank-adjusted-subtrees)
21585 (org-paste-subtree nil nil 'for-yank)
21586 (call-interactively command))
21590 (when (and (bolp) subtreep
21591 (not (setq swallowp
21592 (org-yank-folding-would-swallow-text beg end))))
21593 (org-with-limited-levels
21594 (or (looking-at org-outline-regexp)
21595 (re-search-forward org-outline-regexp-bol end t))
21596 (while (and (< (point) end) (looking-at org-outline-regexp))
21598 (org-cycle-show-empty-lines 'folded)
21599 (condition-case nil
21600 (outline-forward-same-level 1)
21601 (error (goto-char end))))))
21604 "Inserted text not folded because that would swallow text"))
21607 (skip-chars-forward " \t\n\r")
21608 (beginning-of-line 1)
21609 (push-mark beg 'nomsg)))
21610 ((and subtreep org-yank-adjusted-subtrees)
21611 (let ((beg (point-at-bol)))
21612 (org-paste-subtree nil nil 'for-yank)
21613 (push-mark beg 'nomsg)))
21615 (call-interactively command))))))
21617 (defun org-yank-folding-would-swallow-text (beg end)
21618 "Would hide-subtree at BEG swallow any text after END?"
21620 (org-with-limited-levels
21623 (when (or (looking-at org-outline-regexp)
21624 (re-search-forward org-outline-regexp-bol end t))
21625 (setq level (org-outline-level)))
21627 (skip-chars-forward " \t\r\n\v\f")
21629 (and (bolp) (looking-at org-outline-regexp)
21630 (<= (org-outline-level) level)))
21631 nil ; Nothing would be swallowed
21632 t))))) ; something would swallow
21634 (define-key org-mode-map "\C-y" 'org-yank)
21636 (defun org-truely-invisible-p ()
21637 "Check if point is at a character currently not visible.
21638 This version does not only check the character property, but also
21640 ;; Early versions of noutline don't have `outline-invisible-p'.
21641 (if (org-bound-and-true-p visible-mode)
21643 (outline-invisible-p)))
21645 (defun org-invisible-p2 ()
21646 "Check if point is at a character currently not visible."
21648 (if (and (eolp) (not (bobp))) (backward-char 1))
21649 ;; Early versions of noutline don't have `outline-invisible-p'.
21650 (outline-invisible-p)))
21652 (defun org-back-to-heading (&optional invisible-ok)
21653 "Call `outline-back-to-heading', but provide a better error message."
21654 (condition-case nil
21655 (outline-back-to-heading invisible-ok)
21656 (error (error "Before first headline at position %d in buffer %s"
21657 (point) (current-buffer)))))
21659 (defun org-before-first-heading-p ()
21660 "Before first heading?"
21663 (null (re-search-backward org-outline-regexp-bol nil t))))
21665 (defun org-at-heading-p (&optional ignored)
21666 (outline-on-heading-p t))
21667 ;; Compatibility alias with Org versions < 7.8.03
21668 (defalias 'org-on-heading-p 'org-at-heading-p)
21670 (defun org-at-comment-p nil
21671 "Is cursor in a line starting with a # character?"
21673 (beginning-of-line)
21674 (looking-at "^#")))
21676 (defun org-at-drawer-p nil
21677 "Is cursor at a drawer keyword?"
21679 (move-beginning-of-line 1)
21680 (looking-at org-drawer-regexp)))
21682 (defun org-at-block-p nil
21683 "Is cursor at a block keyword?"
21685 (move-beginning-of-line 1)
21686 (looking-at org-block-regexp)))
21688 (defun org-point-at-end-of-empty-headline ()
21689 "If point is at the end of an empty headline, return t, else nil.
21690 If the heading only contains a TODO keyword, it is still still considered
21692 (and (looking-at "[ \t]*$")
21693 (when org-todo-line-regexp
21695 (beginning-of-line 1)
21696 (let ((case-fold-search nil))
21697 (looking-at org-todo-line-regexp)
21698 (string= (match-string 3) ""))))))
21700 (defun org-at-heading-or-item-p ()
21701 (or (org-at-heading-p) (org-at-item-p)))
21703 (defun org-at-target-p ()
21704 (or (org-in-regexp org-radio-target-regexp)
21705 (org-in-regexp org-target-regexp)))
21706 ;; Compatibility alias with Org versions < 7.8.03
21707 (defalias 'org-on-target-p 'org-at-target-p)
21709 (defun org-up-heading-all (arg)
21710 "Move to the heading line of which the present line is a subheading.
21711 This function considers both visible and invisible heading lines.
21712 With argument, move up ARG levels."
21713 (if (fboundp 'outline-up-heading-all)
21714 (outline-up-heading-all arg) ; emacs 21 version of outline.el
21715 (outline-up-heading arg t))) ; emacs 22 version of outline.el
21717 (defun org-up-heading-safe ()
21718 "Move to the heading line of which the present line is a subheading.
21719 This version will not throw an error. It will return the level of the
21720 headline found, or nil if no higher level is found.
21722 Also, this function will be a lot faster than `outline-up-heading',
21723 because it relies on stars being the outline starters. This can really
21724 make a significant difference in outlines with very many siblings."
21725 (let (start-level re)
21726 (org-back-to-heading t)
21727 (setq start-level (funcall outline-level))
21728 (if (equal start-level 1)
21730 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
21731 (if (re-search-backward re nil t)
21732 (funcall outline-level)))))
21734 (defun org-first-sibling-p ()
21735 "Is this heading the first child of its parents?"
21737 (let ((re org-outline-regexp-bol)
21739 (unless (org-at-heading-p t)
21740 (error "Not at a heading"))
21741 (setq level (funcall outline-level))
21743 (if (not (re-search-backward re nil t))
21745 (setq l (funcall outline-level))
21748 (defun org-goto-sibling (&optional previous)
21749 "Goto the next sibling, even if it is invisible.
21750 When PREVIOUS is set, go to the previous sibling instead. Returns t
21751 when a sibling was found. When none is found, return nil and don't
21753 (let ((fun (if previous 're-search-backward 're-search-forward))
21755 (re org-outline-regexp-bol)
21757 (when (condition-case nil (org-back-to-heading t) (error nil))
21758 (setq level (funcall outline-level))
21760 (or previous (forward-char 1))
21761 (while (funcall fun re nil t)
21762 (setq l (funcall outline-level))
21763 (when (< l level) (goto-char pos) (throw 'exit nil))
21764 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
21768 (defun org-show-siblings ()
21769 "Show all siblings of the current headline."
21771 (while (org-goto-sibling) (org-flag-heading nil)))
21773 (while (org-goto-sibling 'previous)
21774 (org-flag-heading nil))))
21776 (defun org-goto-first-child ()
21777 "Goto the first child, even if it is invisible.
21778 Return t when a child was found. Otherwise don't move point and
21780 (let (level (pos (point)) (re org-outline-regexp-bol))
21781 (when (condition-case nil (org-back-to-heading t) (error nil))
21782 (setq level (outline-level))
21784 (if (and (re-search-forward re nil t) (> (outline-level) level))
21785 (progn (goto-char (match-beginning 0)) t)
21786 (goto-char pos) nil))))
21788 (defun org-show-hidden-entry ()
21789 "Show an entry where even the heading is hidden."
21793 (defun org-flag-heading (flag &optional entry)
21794 "Flag the current heading. FLAG non-nil means make invisible.
21795 When ENTRY is non-nil, show the entire entry."
21797 (org-back-to-heading t)
21798 ;; Check if we should show the entire entry
21803 (and (outline-next-heading)
21804 (org-flag-heading nil))))
21805 (outline-flag-region (max (point-min) (1- (point)))
21806 (save-excursion (outline-end-of-heading) (point))
21809 (defun org-get-next-sibling ()
21810 "Move to next heading of the same level, and return point.
21811 If there is no such heading, return nil.
21812 This is like outline-next-sibling, but invisible headings are ok."
21813 (let ((level (funcall outline-level)))
21814 (outline-next-heading)
21815 (while (and (not (eobp)) (> (funcall outline-level) level))
21816 (outline-next-heading))
21817 (if (or (eobp) (< (funcall outline-level) level))
21821 (defun org-get-last-sibling ()
21822 "Move to previous heading of the same level, and return point.
21823 If there is no such heading, return nil."
21824 (let ((opoint (point))
21825 (level (funcall outline-level)))
21826 (outline-previous-heading)
21827 (when (and (/= (point) opoint) (outline-on-heading-p t))
21828 (while (and (> (funcall outline-level) level)
21830 (outline-previous-heading))
21831 (if (< (funcall outline-level) level)
21835 (defun org-end-of-subtree (&optional invisible-OK to-heading)
21836 ;; This contains an exact copy of the original function, but it uses
21837 ;; `org-back-to-heading', to make it work also in invisible
21838 ;; trees. And is uses an invisible-OK argument.
21839 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
21840 ;; Furthermore, when used inside Org, finding the end of a large subtree
21841 ;; with many children and grandchildren etc, this can be much faster
21842 ;; than the outline version.
21843 (org-back-to-heading invisible-OK)
21845 (level (funcall outline-level)))
21846 (if (and (derived-mode-p 'org-mode) (< level 1000))
21847 ;; A true heading (not a plain list item), in Org-mode
21848 ;; This means we can easily find the end by looking
21849 ;; only for the right number of stars. Using a regexp to do
21850 ;; this is so much faster than using a Lisp loop.
21851 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
21853 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
21854 ;; something else, do it the slow way
21855 (while (and (not (eobp))
21856 (or first (> (funcall outline-level) level)))
21858 (outline-next-heading)))
21860 (if (memq (preceding-char) '(?\n ?\^M))
21862 ;; Go to end of line before heading
21864 (if (memq (preceding-char) '(?\n ?\^M))
21865 ;; leave blank line before heading
21866 (forward-char -1))))))
21869 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
21870 "Use Org version in org-mode, for dramatic speed-up."
21871 (if (derived-mode-p 'org-mode)
21873 (org-end-of-subtree nil t)
21874 (unless (eobp) (backward-char 1)))
21877 (defun org-end-of-meta-data-and-drawers ()
21878 "Jump to the first text after meta data and drawers in the current entry.
21879 This will move over empty lines, lines with planning time stamps,
21880 clocking lines, and drawers."
21881 (org-back-to-heading t)
21882 (let ((end (save-excursion (outline-next-heading) (point)))
21883 (re (concat "\\(" org-drawer-regexp "\\)"
21884 "\\|" "[ \t]*" org-keyword-time-regexp)))
21886 (while (re-search-forward re end t)
21887 (if (not (match-end 1))
21888 ;; empty or planning line
21890 ;; a drawer, find the end
21891 (re-search-forward "^[ \t]*:END:" end 'move)
21893 (and (re-search-forward "[^\n]" nil t) (backward-char 1))
21896 (defun org-forward-heading-same-level (arg &optional invisible-ok)
21897 "Move forward to the arg'th subheading at same level as this one.
21898 Stop at the first and last subheadings of a superior heading.
21899 Normally this only looks at visible headings, but when INVISIBLE-OK is
21900 non-nil it will also look at invisible ones."
21902 (org-back-to-heading invisible-ok)
21904 (let* ((level (- (match-end 0) (match-beginning 0) 1))
21905 (re (format "^\\*\\{1,%d\\} " level))
21909 (while (and (re-search-forward re nil 'move)
21910 (setq l (- (match-end 0) (match-beginning 0) 1))
21913 (progn (backward-char 1) (outline-invisible-p)))
21914 (if (< l level) (setq arg 1)))
21915 (setq arg (1- arg)))
21916 (beginning-of-line 1)))
21918 (defun org-backward-heading-same-level (arg &optional invisible-ok)
21919 "Move backward to the arg'th subheading at same level as this one.
21920 Stop at the first and last subheadings of a superior heading."
21922 (org-back-to-heading)
21924 (let* ((level (- (match-end 0) (match-beginning 0) 1))
21925 (re (format "^\\*\\{1,%d\\} " level))
21928 (while (and (re-search-backward re nil 'move)
21929 (setq l (- (match-end 0) (match-beginning 0) 1))
21932 (outline-invisible-p))
21933 (if (< l level) (setq arg 1)))
21934 (setq arg (1- arg)))))
21937 (defun org-forward-element ()
21938 "Move forward by one element.
21939 Move to the next element at the same level, when possible."
21941 (cond ((eobp) (error "Cannot move further down"))
21942 ((org-with-limited-levels (org-at-heading-p))
21943 (let ((origin (point)))
21944 (org-forward-heading-same-level 1)
21945 (unless (org-with-limited-levels (org-at-heading-p))
21947 (error "Cannot move further down"))))
21949 (let* ((elem (org-element-at-point))
21950 (end (org-element-property :end elem))
21951 (parent (org-element-property :parent elem)))
21952 (if (and parent (= (org-element-property :contents-end parent) end))
21953 (goto-char (org-element-property :end parent))
21954 (goto-char end))))))
21957 (defun org-backward-element ()
21958 "Move backward by one element.
21959 Move to the previous element at the same level, when possible."
21961 (cond ((bobp) (error "Cannot move further up"))
21962 ((org-with-limited-levels (org-at-heading-p))
21963 ;; At an headline, move to the previous one, if any, or stay
21965 (let ((origin (point)))
21966 (org-backward-heading-same-level 1)
21967 (unless (org-with-limited-levels (org-at-heading-p))
21969 (error "Cannot move further up"))))
21971 (let* ((trail (org-element-at-point 'keep-trail))
21973 (prev-elem (nth 1 trail))
21974 (beg (org-element-property :begin elem)))
21976 ;; Move to beginning of current element if point isn't
21978 ((/= (point) beg) (goto-char beg))
21979 (prev-elem (goto-char (org-element-property :begin prev-elem)))
21980 ((org-before-first-heading-p) (goto-char (point-min)))
21981 (t (org-back-to-heading)))))))
21984 (defun org-up-element ()
21985 "Move to upper element."
21987 (if (org-with-limited-levels (org-at-heading-p))
21988 (unless (org-up-heading-safe) (error "No surrounding element"))
21989 (let* ((elem (org-element-at-point))
21990 (parent (org-element-property :parent elem)))
21991 (if parent (goto-char (org-element-property :begin parent))
21992 (if (org-with-limited-levels (org-before-first-heading-p))
21993 (error "No surrounding element")
21994 (org-with-limited-levels (org-back-to-heading)))))))
21997 (defvar org-element-greater-elements)
21998 (defun org-down-element ()
21999 "Move to inner element."
22001 (let ((element (org-element-at-point)))
22003 ((memq (org-element-type element) '(plain-list table))
22004 (goto-char (org-element-property :contents-begin element))
22006 ((memq (org-element-type element) org-element-greater-elements)
22007 ;; If contents are hidden, first disclose them.
22008 (when (org-element-property :hiddenp element) (org-cycle))
22009 (goto-char (or (org-element-property :contents-begin element)
22010 (error "No content for this element"))))
22011 (t (error "No inner element")))))
22014 (defun org-drag-element-backward ()
22015 "Move backward element at point."
22017 (if (org-with-limited-levels (org-at-heading-p)) (org-move-subtree-up)
22018 (let* ((trail (org-element-at-point 'keep-trail))
22020 (prev-elem (nth 1 trail)))
22021 ;; Error out if no previous element or previous element is
22022 ;; a parent of the current one.
22023 (if (or (not prev-elem) (org-element-nested-p elem prev-elem))
22024 (error "Cannot drag element backward")
22025 (let ((pos (point)))
22026 (org-element-swap-A-B prev-elem elem)
22027 (goto-char (+ (org-element-property :begin prev-elem)
22028 (- pos (org-element-property :begin elem)))))))))
22031 (defun org-drag-element-forward ()
22032 "Move forward element at point."
22034 (let* ((pos (point))
22035 (elem (org-element-at-point)))
22036 (when (= (point-max) (org-element-property :end elem))
22037 (error "Cannot drag element forward"))
22038 (goto-char (org-element-property :end elem))
22039 (let ((next-elem (org-element-at-point)))
22040 (when (or (org-element-nested-p elem next-elem)
22041 (and (eq (org-element-type next-elem) 'headline)
22042 (not (eq (org-element-type elem) 'headline))))
22044 (error "Cannot drag element forward"))
22045 ;; Compute new position of point: it's shifted by NEXT-ELEM
22046 ;; body's length (without final blanks) and by the length of
22047 ;; blanks between ELEM and NEXT-ELEM.
22048 (let ((size-next (- (save-excursion
22049 (goto-char (org-element-property :end next-elem))
22050 (skip-chars-backward " \r\t\n")
22052 ;; Small correction if buffer doesn't end
22053 ;; with a newline character.
22054 (if (and (eolp) (not (bolp))) (1+ (point)) (point)))
22055 (org-element-property :begin next-elem)))
22056 (size-blank (- (org-element-property :end elem)
22058 (goto-char (org-element-property :end elem))
22059 (skip-chars-backward " \r\t\n")
22062 (org-element-swap-A-B elem next-elem)
22063 (goto-char (+ pos size-next size-blank))))))
22066 (defun org-mark-element ()
22067 "Put point at beginning of this element, mark at end.
22069 Interactively, if this command is repeated or (in Transient Mark
22070 mode) if the mark is active, it marks the next element after the
22071 ones already marked."
22073 (let (deactivate-mark)
22074 (if (and (org-called-interactively-p 'any)
22075 (or (and (eq last-command this-command) (mark t))
22076 (and transient-mark-mode mark-active)))
22080 (goto-char (org-element-property :end (org-element-at-point)))))
22081 (let ((element (org-element-at-point)))
22083 (push-mark (org-element-property :end element) t t)
22084 (goto-char (org-element-property :begin element))))))
22087 (defun org-narrow-to-element ()
22088 "Narrow buffer to current element."
22090 (let ((elem (org-element-at-point)))
22092 ((eq (car elem) 'headline)
22094 (org-element-property :begin elem)
22095 (org-element-property :end elem)))
22096 ((memq (car elem) org-element-greater-elements)
22098 (org-element-property :contents-begin elem)
22099 (org-element-property :contents-end elem)))
22102 (org-element-property :begin elem)
22103 (org-element-property :end elem))))))
22106 (defun org-transpose-element ()
22107 "Transpose current and previous elements, keeping blank lines between.
22108 Point is moved after both elements."
22110 (org-skip-whitespace)
22111 (let ((end (org-element-property :end (org-element-at-point))))
22112 (org-drag-element-backward)
22116 (defun org-unindent-buffer ()
22117 "Un-indent the visible part of the buffer.
22118 Relative indentation (between items, inside blocks, etc.) isn't
22121 (unless (eq major-mode 'org-mode)
22122 (error "Cannot un-indent a buffer not in Org mode"))
22123 (let* ((parse-tree (org-element-parse-buffer 'greater-element))
22124 unindent-tree ; For byte-compiler.
22130 (if (memq (org-element-type element) '(headline section))
22131 (funcall unindent-tree (org-element-contents element))
22135 (org-element-property :begin element)
22136 (org-element-property :end element))
22137 (org-do-remove-indentation)))))
22138 (reverse contents))))))
22139 (funcall unindent-tree (org-element-contents parse-tree))))
22141 (defun org-show-subtree ()
22142 "Show everything after this heading at deeper levels."
22144 (outline-flag-region
22147 (org-end-of-subtree t t))
22150 (defun org-show-entry ()
22151 "Show the body directly following this heading.
22152 Show the heading too, if it is currently invisible."
22155 (condition-case nil
22157 (org-back-to-heading t)
22158 (outline-flag-region
22159 (max (point-min) (1- (point)))
22161 (if (re-search-forward
22162 (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
22163 (match-beginning 1)
22166 (org-cycle-hide-drawers 'children))
22169 (defun org-make-options-regexp (kwds &optional extra)
22170 "Make a regular expression for keyword lines."
22173 (mapconcat 'regexp-quote kwds "\\|")
22174 (if extra (concat "\\|" extra))
22175 "\\):[ \t]*\\(.*\\)"))
22177 ;; Make isearch reveal the necessary context
22178 (defun org-isearch-end ()
22179 "Reveal context after isearch exits."
22180 (when isearch-success ; only if search was successful
22181 (if (featurep 'xemacs)
22182 ;; Under XEmacs, the hook is run in the correct place,
22183 ;; we directly show the context.
22184 (org-show-context 'isearch)
22185 ;; In Emacs the hook runs *before* restoring the overlays.
22186 ;; So we have to use a one-time post-command-hook to do this.
22187 ;; (Emacs 22 has a special variable, see function `org-mode')
22188 (unless (and (boundp 'isearch-mode-end-hook-quit)
22189 isearch-mode-end-hook-quit)
22190 ;; Only when the isearch was not quitted.
22191 (org-add-hook 'post-command-hook 'org-isearch-post-command
22192 'append 'local)))))
22194 (defun org-isearch-post-command ()
22195 "Remove self from hook, and show context."
22196 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
22197 (org-show-context 'isearch))
22200 ;;;; Integration with and fixes for other packages
22204 (defvar org-imenu-markers nil
22205 "All markers currently used by Imenu.")
22206 (make-variable-buffer-local 'org-imenu-markers)
22208 (defun org-imenu-new-marker (&optional pos)
22209 "Return a new marker for use by Imenu, and remember the marker."
22210 (let ((m (make-marker)))
22211 (move-marker m (or pos (point)))
22212 (push m org-imenu-markers)
22215 (defun org-imenu-get-tree ()
22216 "Produce the index for Imenu."
22217 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
22218 (setq org-imenu-markers nil)
22219 (let* ((n org-imenu-depth)
22220 (re (concat "^" (org-get-limited-outline-regexp)))
22221 (subs (make-vector (1+ n) nil))
22227 (goto-char (point-max))
22228 (while (re-search-backward re nil t)
22229 (setq level (org-reduced-level (funcall outline-level)))
22230 (when (and (<= level n)
22231 (looking-at org-complex-heading-regexp))
22232 (setq head (org-link-display-format
22233 (org-match-string-no-properties 4))
22234 m (org-imenu-new-marker))
22235 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
22236 (if (>= level last-level)
22237 (push (cons head m) (aref subs level))
22238 (push (cons head (aref subs (1+ level))) (aref subs level))
22239 (loop for i from (1+ level) to n do (aset subs i nil)))
22240 (setq last-level level)))))
22243 (eval-after-load "imenu"
22245 (add-hook 'imenu-after-jump-hook
22247 (if (derived-mode-p 'org-mode)
22248 (org-show-context 'org-goto))))))
22250 (defun org-link-display-format (link)
22251 "Replace a link with either the description, or the link target
22252 if no description is present"
22254 (if (string-match org-bracket-link-analytic-regexp link)
22255 (replace-match (if (match-end 5)
22256 (match-string 5 link)
22257 (concat (match-string 1 link)
22258 (match-string 3 link)))
22262 (defun org-toggle-link-display ()
22263 "Toggle the literal or descriptive display of links."
22265 (if org-descriptive-links
22266 (progn (org-remove-from-invisibility-spec '(org-link))
22267 (org-restart-font-lock)
22268 (setq org-descriptive-links nil))
22269 (progn (add-to-invisibility-spec '(org-link))
22270 (org-restart-font-lock)
22271 (setq org-descriptive-links t))))
22273 ;; Speedbar support
22275 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
22276 "Overlay marking the agenda restriction line in speedbar.")
22277 (overlay-put org-speedbar-restriction-lock-overlay
22278 'face 'org-agenda-restriction-lock)
22279 (overlay-put org-speedbar-restriction-lock-overlay
22280 'help-echo "Agendas are currently limited to this item.")
22281 (org-detach-overlay org-speedbar-restriction-lock-overlay)
22283 (defun org-speedbar-set-agenda-restriction ()
22284 "Restrict future agenda commands to the location at point in speedbar.
22285 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
22287 (require 'org-agenda)
22288 (let (p m tp np dir txt)
22290 ((setq p (text-property-any (point-at-bol) (point-at-eol)
22292 (setq m (get-text-property p 'org-imenu-marker))
22293 (with-current-buffer (marker-buffer m)
22295 (org-agenda-set-restriction-lock 'subtree)))
22296 ((setq p (text-property-any (point-at-bol) (point-at-eol)
22297 'speedbar-function 'speedbar-find-file))
22298 (setq tp (previous-single-property-change
22299 (1+ p) 'speedbar-function)
22300 np (next-single-property-change
22301 tp 'speedbar-function)
22302 dir (speedbar-line-directory)
22303 txt (buffer-substring-no-properties (or tp (point-min))
22304 (or np (point-max))))
22305 (with-current-buffer (find-file-noselect
22306 (let ((default-directory dir))
22307 (expand-file-name txt)))
22308 (unless (derived-mode-p 'org-mode)
22309 (error "Cannot restrict to non-Org-mode file"))
22310 (org-agenda-set-restriction-lock 'file)))
22311 (t (error "Don't know how to restrict Org-mode's agenda")))
22312 (move-overlay org-speedbar-restriction-lock-overlay
22313 (point-at-bol) (point-at-eol))
22314 (setq current-prefix-arg nil)
22315 (org-agenda-maybe-redo)))
22317 (eval-after-load "speedbar"
22319 (speedbar-add-supported-extension ".org")
22320 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
22321 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
22322 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
22323 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
22324 (add-hook 'speedbar-visiting-tag-hook
22325 (lambda () (and (derived-mode-p 'org-mode) (org-show-context 'org-goto))))))
22327 ;;; Fixes and Hacks for problems with other packages
22329 ;; Make flyspell not check words in links, to not mess up our keymap
22330 (defun org-mode-flyspell-verify ()
22331 "Don't let flyspell put overlays at active buttons, or on
22332 {todo,all-time,additional-option-like}-keywords."
22333 (let ((pos (max (1- (point)) (point-min)))
22334 (word (thing-at-point 'word)))
22335 (and (not (get-text-property pos 'keymap))
22336 (not (get-text-property pos 'org-no-flyspell))
22337 (not (member word org-todo-keywords-1))
22338 (not (member word org-all-time-keywords))
22339 (not (member word org-options-keywords))
22340 (not (member word (mapcar 'car org-startup-options)))
22341 (not (member word org-additional-option-like-keywords-for-flyspell)))))
22343 (defun org-remove-flyspell-overlays-in (beg end)
22344 "Remove flyspell overlays in region."
22345 (and (org-bound-and-true-p flyspell-mode)
22346 (fboundp 'flyspell-delete-region-overlays)
22347 (flyspell-delete-region-overlays beg end))
22348 (add-text-properties beg end '(org-no-flyspell t)))
22350 ;; Make `bookmark-jump' shows the jump location if it was hidden.
22351 (eval-after-load "bookmark"
22352 '(if (boundp 'bookmark-after-jump-hook)
22353 ;; We can use the hook
22354 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
22355 ;; Hook not available, use advice
22356 (defadvice bookmark-jump (after org-make-visible activate)
22357 "Make the position visible."
22358 (org-bookmark-jump-unhide))))
22360 ;; Make sure saveplace shows the location if it was hidden
22361 (eval-after-load "saveplace"
22362 '(defadvice save-place-find-file-hook (after org-make-visible activate)
22363 "Make the position visible."
22364 (org-bookmark-jump-unhide)))
22366 ;; Make sure ecb shows the location if it was hidden
22367 (eval-after-load "ecb"
22368 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
22369 "Make hierarchy visible when jumping into location from ECB tree buffer."
22370 (if (derived-mode-p 'org-mode)
22371 (org-show-context))))
22373 (defun org-bookmark-jump-unhide ()
22374 "Unhide the current position, to show the bookmark location."
22375 (and (derived-mode-p 'org-mode)
22376 (or (outline-invisible-p)
22377 (save-excursion (goto-char (max (point-min) (1- (point))))
22378 (outline-invisible-p)))
22379 (org-show-context 'bookmark-jump)))
22381 ;; Make session.el ignore our circular variable
22382 (eval-after-load "session"
22383 '(add-to-list 'session-globals-exclude 'org-mark-ring))
22385 ;;;; Experimental code
22387 (defun org-closed-in-range ()
22388 "Sparse tree of items closed in a certain time range.
22389 Still experimental, may disappear in the future."
22391 ;; Get the time interval from the user.
22392 (let* ((time1 (org-float-time
22393 (org-read-date nil 'to-time nil "Starting date: ")))
22394 (time2 (org-float-time
22395 (org-read-date nil 'to-time nil "End date:")))
22396 ;; callback function
22397 (callback (lambda ()
22400 (apply 'encode-time
22401 (org-parse-time-string
22402 (match-string 1))))))
22403 ;; check if time in interval
22404 (and (>= time time1) (<= time time2))))))
22405 ;; make tree, check each match with the callback
22406 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
22412 (run-hooks 'org-load-hook)
22414 ;;; org.el ends here