1 ;;; org.el --- Outline-based notes management and organizer
3 ;; Carstens outline-mode for keeping track of everything.
4 ;; Copyright (C) 2004-2013 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 (load "org-loaddefs.el" t t t
)
86 ;; `org-outline-regexp' ought to be a defconst but is let-binding in
87 ;; some places -- e.g. see the macro org-with-limited-levels.
89 ;; In Org buffers, the value of `outline-regexp' is that of
90 ;; `org-outline-regexp'. The only function still directly relying on
91 ;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
92 ;; job when `orgstruct-mode' is active.
93 (defvar org-outline-regexp
"\\*+ "
94 "Regexp to match Org headlines.")
96 (defvar org-outline-regexp-bol
"^\\*+ "
97 "Regexp to match Org headlines.
98 This is similar to `org-outline-regexp' but additionally makes
99 sure that we are at the beginning of the line.")
101 (defvar org-heading-regexp
"^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
102 "Matches an headline, putting stars and text into groups.
103 Stars are put in group 1 and the trimmed body in group 2.")
105 ;; Emacs 22 calendar compatibility: Make sure the new variables are available
106 (when (fboundp 'defvaralias
)
107 (unless (boundp 'calendar-view-holidays-initially-flag
)
108 (defvaralias 'calendar-view-holidays-initially-flag
109 'view-calendar-holidays-initially
))
110 (unless (boundp 'calendar-view-diary-initially-flag
)
111 (defvaralias 'calendar-view-diary-initially-flag
112 'view-diary-entries-initially
))
113 (unless (boundp 'diary-fancy-buffer
)
114 (defvaralias 'diary-fancy-buffer
'fancy-diary-buffer
)))
116 (declare-function org-inlinetask-at-task-p
"org-inlinetask" ())
117 (declare-function org-inlinetask-outline-regexp
"org-inlinetask" ())
118 (declare-function org-inlinetask-toggle-visibility
"org-inlinetask" ())
119 (declare-function org-pop-to-buffer-same-window
"org-compat" (&optional buffer-or-name norecord label
))
120 (declare-function org-at-clock-log-p
"org-clock" ())
121 (declare-function org-clock-get-last-clock-out-time
"org-clock" ())
122 (declare-function org-clock-timestamps-up
"org-clock" (&optional n
))
123 (declare-function org-clock-timestamps-down
"org-clock" (&optional n
))
124 (declare-function org-clock-sum-current-item
"org-clock" (&optional tstart
))
126 (declare-function orgtbl-mode
"org-table" (&optional arg
))
127 (declare-function org-clock-out
"org-clock" (&optional switch-to-state fail-quietly at-time
))
128 (declare-function org-beamer-mode
"ox-beamer" ())
129 (declare-function org-table-edit-field
"org-table" (arg))
130 (declare-function org-table-justify-field-maybe
"org-table" (&optional new
))
131 (declare-function org-id-get-create
"org-id" (&optional force
))
132 (declare-function org-id-find-id-file
"org-id" (id))
133 (declare-function org-tags-view
"org-agenda" (&optional todo-only match
))
134 (declare-function org-agenda-list
"org-agenda" (&optional arg start-day span
))
135 (declare-function org-table-align
"org-table" ())
136 (declare-function org-table-paste-rectangle
"org-table" ())
137 (declare-function org-table-maybe-eval-formula
"org-table" ())
138 (declare-function org-table-maybe-recalculate-line
"org-table" ())
140 (declare-function org-element--parse-objects
"org-element"
141 (beg end acc restriction
))
142 (declare-function org-element-at-point
"org-element" (&optional keep-trail
))
143 (declare-function org-element-contents
"org-element" (element))
144 (declare-function org-element-context
"org-element" (&optional element
))
145 (declare-function org-element-interpret-data
"org-element"
146 (data &optional parent
))
147 (declare-function org-element-map
"org-element"
148 (data types fun
&optional info first-match no-recursion
))
149 (declare-function org-element-nested-p
"org-element" (elem-a elem-b
))
150 (declare-function org-element-parse-buffer
"org-element"
151 (&optional granularity visible-only
))
152 (declare-function org-element-property
"org-element" (property element
))
153 (declare-function org-element-put-property
"org-element"
154 (element property value
))
155 (declare-function org-element-swap-A-B
"org-element" (elem-a elem-b
))
156 (declare-function org-element--parse-objects
"org-element"
157 (beg end acc restriction
))
158 (declare-function org-element-parse-buffer
"org-element"
159 (&optional granularity visible-only
))
160 (declare-function org-element-type
"org-element" (element))
162 ;; load languages based on value of `org-babel-load-languages'
163 (defvar org-babel-load-languages
)
166 (defun org-babel-do-load-languages (sym value
)
167 "Load the languages defined in `org-babel-load-languages'."
168 (set-default sym value
)
170 (let ((active (cdr pair
)) (lang (symbol-name (car pair
))))
173 (require (intern (concat "ob-" lang
))))
175 (funcall 'fmakunbound
176 (intern (concat "org-babel-execute:" lang
)))
177 (funcall 'fmakunbound
178 (intern (concat "org-babel-expand-body:" lang
)))))))
179 org-babel-load-languages
))
181 (defcustom org-babel-load-languages
'((emacs-lisp . t
))
182 "Languages which can be evaluated in Org-mode buffers.
183 This list can be used to load support for any of the languages
184 below, note that each language will depend on a different set of
185 system executables and/or Emacs modes. When a language is
186 \"loaded\", then code blocks in that language can be evaluated
187 with `org-babel-execute-src-block' bound by default to C-c
188 C-c (note the `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can
189 be set to remove code block evaluation from the C-c C-c
190 keybinding. By default only Emacs Lisp (which has no
191 requirements) is loaded."
193 :set
'org-babel-do-load-languages
195 :type
'(alist :tag
"Babel Languages"
198 (const :tag
"Awk" awk
)
201 (const :tag
"Asymptote" asymptote
)
202 (const :tag
"Calc" calc
)
203 (const :tag
"Clojure" clojure
)
204 (const :tag
"CSS" css
)
205 (const :tag
"Ditaa" ditaa
)
206 (const :tag
"Dot" dot
)
207 (const :tag
"Emacs Lisp" emacs-lisp
)
208 (const :tag
"Fortran" fortran
)
209 (const :tag
"Gnuplot" gnuplot
)
210 (const :tag
"Haskell" haskell
)
212 (const :tag
"Java" java
)
213 (const :tag
"Javascript" js
)
214 (const :tag
"LaTeX" latex
)
215 (const :tag
"Ledger" ledger
)
216 (const :tag
"Lilypond" lilypond
)
217 (const :tag
"Lisp" lisp
)
218 (const :tag
"Makefile" makefile
)
219 (const :tag
"Maxima" maxima
)
220 (const :tag
"Matlab" matlab
)
221 (const :tag
"Mscgen" mscgen
)
222 (const :tag
"Ocaml" ocaml
)
223 (const :tag
"Octave" octave
)
224 (const :tag
"Org" org
)
225 (const :tag
"Perl" perl
)
226 (const :tag
"Pico Lisp" picolisp
)
227 (const :tag
"PlantUML" plantuml
)
228 (const :tag
"Python" python
)
229 (const :tag
"Ruby" ruby
)
230 (const :tag
"Sass" sass
)
231 (const :tag
"Scala" scala
)
232 (const :tag
"Scheme" scheme
)
233 (const :tag
"Screen" screen
)
234 (const :tag
"Shell Script" sh
)
235 (const :tag
"Shen" shen
)
236 (const :tag
"Sql" sql
)
237 (const :tag
"Sqlite" sqlite
))
238 :value-type
(boolean :tag
"Activate" :value t
)))
240 ;;;; Customization variables
241 (defcustom org-clone-delete-id nil
242 "Remove ID property of clones of a subtree.
243 When non-nil, clones of a subtree don't inherit the ID property.
244 Otherwise they inherit the ID property with a new unique
254 (defun org-version (&optional here full message
)
255 "Show the org-mode version in the echo area.
256 With prefix argument HERE, insert it at point.
257 When FULL is non-nil, use a verbose version string.
258 When MESSAGE is non-nil, display a message with the version."
260 (let* ((org-dir (ignore-errors (org-find-library-dir "org")))
261 (save-load-suffixes (when (boundp 'load-suffixes
) load-suffixes
))
262 (load-suffixes (list ".el"))
263 (org-install-dir (ignore-errors (org-find-library-dir "org-loaddefs")))
265 (and (fboundp 'org-release
) (fboundp 'org-git-version
))
266 (org-load-noerror-mustsuffix (concat org-dir
"org-version"))))
267 (load-suffixes save-load-suffixes
)
268 (org-version (org-release))
269 (git-version (org-git-version))
270 (version (format "Org-mode version %s (%s @ %s)"
274 (if (string= org-dir org-install-dir
)
276 (concat "mixed installation! " org-install-dir
" and " org-dir
))
277 "org-loaddefs.el can not be found!")))
278 (_version (if full version org-version
)))
279 (if (org-called-interactively-p 'interactive
)
283 (if message
(message _version
))
286 (defconst org-version
(org-version))
288 ;;; Compatibility constants
290 ;;; The custom variables
293 "Outline-based notes management and organizer."
298 (defcustom org-mode-hook nil
299 "Mode hook for Org-mode, run after the mode was turned on."
303 (defcustom org-load-hook nil
304 "Hook that is run after org.el has been loaded."
308 (defcustom org-log-buffer-setup-hook nil
309 "Hook that is run after an Org log buffer is created."
314 (defvar org-modules
) ; defined below
315 (defvar org-modules-loaded nil
316 "Have the modules been loaded already?")
318 (defun org-load-modules-maybe (&optional force
)
319 "Load all extensions listed in `org-modules'."
320 (when (or force
(not org-modules-loaded
))
322 (condition-case nil
(require ext
)
323 (error (message "Problems while trying to load feature `%s'" ext
))))
325 (setq org-modules-loaded t
)))
327 (defun org-set-modules (var value
)
328 "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag."
330 (when (featurep 'org
)
331 (org-load-modules-maybe 'force
)))
333 (defcustom org-modules
'(org-bbdb org-bibtex org-docview org-gnus org-info org-irc org-mew org-mhe org-rmail org-vm org-w3m org-wl
)
334 "Modules that should always be loaded together with org.el.
336 If a description starts with <C>, the file is not part of Emacs
337 and loading it will require that you have downloaded and properly
338 installed the Org mode distribution.
340 You can also use this system to load external packages (i.e. neither Org
341 core modules, nor modules from the CONTRIB directory). Just add symbols
342 to the end of the list. If the package is called org-xyz.el, then you need
343 to add the symbol `xyz', and the package must have a call to:
347 For export specific modules, see also `org-export-backends'."
349 :set
'org-set-modules
352 (const :tag
" bbdb: Links to BBDB entries" org-bbdb
)
353 (const :tag
" bibtex: Links to BibTeX entries" org-bibtex
)
354 (const :tag
" crypt: Encryption of subtrees" org-crypt
)
355 (const :tag
" ctags: Access to Emacs tags with links" org-ctags
)
356 (const :tag
" docview: Links to doc-view buffers" org-docview
)
357 (const :tag
" gnus: Links to GNUS folders/messages" org-gnus
)
358 (const :tag
" id: Global IDs for identifying entries" org-id
)
359 (const :tag
" info: Links to Info nodes" org-info
)
360 (const :tag
" habit: Track your consistency with habits" org-habit
)
361 (const :tag
" inlinetask: Tasks independent of outline hierarchy" org-inlinetask
)
362 (const :tag
" irc: Links to IRC/ERC chat sessions" org-irc
)
363 (const :tag
" mac-message: Links to messages in Apple Mail" org-mac-message
)
364 (const :tag
" mew Links to Mew folders/messages" org-mew
)
365 (const :tag
" mhe: Links to MHE folders/messages" org-mhe
)
366 (const :tag
" protocol: Intercept calls from emacsclient" org-protocol
)
367 (const :tag
" rmail: Links to RMAIL folders/messages" org-rmail
)
368 (const :tag
" vm: Links to VM folders/messages" org-vm
)
369 (const :tag
" wl: Links to Wanderlust folders/messages" org-wl
)
370 (const :tag
" w3m: Special cut/paste from w3m to Org-mode." org-w3m
)
371 (const :tag
" mouse: Additional mouse support" org-mouse
)
373 (const :tag
"C annotate-file: Annotate a file with org syntax" org-annotate-file
)
374 (const :tag
"C bookmark: Org-mode links to bookmarks" org-bookmark
)
375 (const :tag
"C checklist: Extra functions for checklists in repeated tasks" org-checklist
)
376 (const :tag
"C choose: Use TODO keywords to mark decisions states" org-choose
)
377 (const :tag
"C collector: Collect properties into tables" org-collector
)
378 (const :tag
"C depend: TODO dependencies for Org-mode\n\t\t\t(PARTIALLY OBSOLETE, see built-in dependency support))" org-depend
)
379 (const :tag
"C drill: Flashcards and spaced repetition for Org-mode" org-drill
)
380 (const :tag
"C elisp-symbol: Org-mode links to emacs-lisp symbols" org-elisp-symbol
)
381 (const :tag
"C eshell Support for links to working directories in eshell" org-eshell
)
382 (const :tag
"C eval: Include command output as text" org-eval
)
383 (const :tag
"C eval-light: Evaluate inbuffer-code on demand" org-eval-light
)
384 (const :tag
"C expiry: Expiry mechanism for Org-mode entries" org-expiry
)
385 (const :tag
"C exp-bibtex: Export citations using BibTeX" org-exp-bibtex
)
386 (const :tag
"C git-link: Provide org links to specific file version" org-git-link
)
387 (const :tag
"C interactive-query: Interactive modification of tags query\n\t\t\t(PARTIALLY OBSOLETE, see secondary filtering)" org-interactive-query
)
389 (const :tag
"C invoice: Help manage client invoices in Org-mode" org-invoice
)
391 (const :tag
"C jira: Add a jira:ticket protocol to Org-mode" org-jira
)
392 (const :tag
"C learn: SuperMemo's incremental learning algorithm" org-learn
)
393 (const :tag
"C mairix: Hook mairix search into Org-mode for different MUAs" org-mairix
)
394 (const :tag
"C notmuch: Provide org links to notmuch searches or messages" org-notmuch
)
395 (const :tag
"C mac-iCal Imports events from iCal.app to the Emacs diary" org-mac-iCal
)
396 (const :tag
"C mac-link-grabber Grab links and URLs from various Mac applications" org-mac-link-grabber
)
397 (const :tag
"C man: Support for links to manpages in Org-mode" org-man
)
398 (const :tag
"C mtags: Support for muse-like tags" org-mtags
)
399 (const :tag
"C panel: Simple routines for us with bad memory" org-panel
)
400 (const :tag
"C registry: A registry for Org-mode links" org-registry
)
401 (const :tag
"C org2rem: Convert org appointments into reminders" org2rem
)
402 (const :tag
"C screen: Visit screen sessions through Org-mode links" org-screen
)
403 (const :tag
"C secretary: Team management with org-mode" org-secretary
)
404 (const :tag
"C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert
)
405 (const :tag
"C toc: Table of contents for Org-mode buffer" org-toc
)
406 (const :tag
"C track: Keep up with Org-mode development" org-track
)
407 (const :tag
"C velocity Something like Notational Velocity for Org" org-velocity
)
408 (const :tag
"C wikinodes: CamelCase wiki-like links" org-wikinodes
)
409 (repeat :tag
"External packages" :inline t
(symbol :tag
"Package"))))
411 (defvar org-export-registered-backends
) ; From ox.el
412 (declare-function org-export-derived-backend-p
"ox" (backend &rest backends
))
413 (defcustom org-export-backends
'(ascii html icalendar latex
)
414 "List of export back-ends that should be always available.
416 If a description starts with <C>, the file is not part of Emacs
417 and loading it will require that you have downloaded and properly
418 installed the Org mode distribution.
420 Unlike to `org-modules', libraries in this list will not be
421 loaded along with Org, but only once the export framework is
424 This variable needs to be set before org.el is loaded. If you
425 need to make a change while Emacs is running, use the customize
426 interface or run the following code, where VALUE stands for the
427 new value of the variable, after updating it:
430 \(setq org-export-registered-backends
433 \(or (memq backend val)
437 \(and (org-export-derived-backend-p b (car backend))
438 \(throw 'parentp t)))
441 org-export-registered-backends))
442 \(let ((new-list (mapcar 'car org-export-registered-backends)))
443 \(dolist (backend val)
445 \((not (load (format \"ox-%s\" backend) t t))
446 \(message \"Problems while trying to load export back-end `%s'\"
448 \((not (memq backend new-list)) (push backend new-list))))
449 \(set-default var new-list)))
451 Adding a back-end to this list will also pull the back-end it
455 :set
(lambda (var val
)
456 (if (not (featurep 'ox
)) (set-default var val
)
457 ;; Any back-end not required anymore (not present in VAL and not
458 ;; a parent of any back-end in the new value) is removed from the
459 ;; list of registered back-ends.
460 (setq org-export-registered-backends
463 (or (memq backend val
)
467 (and (org-export-derived-backend-p b
(car backend
))
471 org-export-registered-backends
))
472 ;; Now build NEW-LIST of both new back-ends and required
474 (let ((new-list (mapcar 'car org-export-registered-backends
)))
475 (dolist (backend val
)
477 ((not (load (format "ox-%s" backend
) t t
))
478 (message "Problems while trying to load export back-end `%s'"
480 ((not (memq backend new-list
)) (push backend new-list
))))
481 ;; Set VAR to that list with fixed dependencies.
482 (set-default var new-list
))))
483 :type
'(set :greedy t
484 (const :tag
" ascii Export buffer to ASCII format" ascii
)
485 (const :tag
" beamer Export buffer to Beamer presentation" beamer
)
486 (const :tag
" html Export buffer to HTML format" html
)
487 (const :tag
" icalendar Export buffer to iCalendar format" icalendar
)
488 (const :tag
" latex Export buffer to LaTeX format" latex
)
489 (const :tag
" man Export buffer to MAN format" man
)
490 (const :tag
" md Export buffer to Markdown format" md
)
491 (const :tag
" odt Export buffer to ODT format" odt
)
492 (const :tag
" texinfo Export buffer to Texinfo format" texinfo
)
493 (const :tag
" infojs: Set up Sebastian Rose's JavaScript org-info.js" jsinfo
)
494 (const :tag
"C confluence Export buffer to Confluence Wiki format" confluence
)
495 (const :tag
"C groff Export buffer to Groff format" groff
)
496 (const :tag
"C koma-letter Export buffer to KOMA Scrlttrl2 format" koma-letter
)
497 (const :tag
"C taskjuggler Export buffer to TaskJuggler format" taskjuggler
)))
502 (condition-case nil
(require (intern (format "ox-%s" backend
)))
503 (error (message "Problems while trying to load export back-end `%s'"
505 org-export-backends
))
507 (defcustom org-support-shift-select nil
508 "Non-nil means make shift-cursor commands select text when possible.
510 In Emacs 23, when `shift-select-mode' is on, shifted cursor keys
511 start selecting a region, or enlarge regions started in this way.
512 In Org-mode, in special contexts, these same keys are used for
513 other purposes, important enough to compete with shift selection.
514 Org tries to balance these needs by supporting `shift-select-mode'
515 outside these special contexts, under control of this variable.
517 The default of this variable is nil, to avoid confusing behavior. Shifted
518 cursor keys will then execute Org commands in the following contexts:
519 - on a headline, changing TODO state (left/right) and priority (up/down)
520 - on a time stamp, changing the time
521 - in a plain list item, changing the bullet type
522 - in a property definition line, switching between allowed values
523 - in the BEGIN line of a clock table (changing the time block).
524 Outside these contexts, the commands will throw an error.
526 When this variable is t and the cursor is not in a special
527 context, Org-mode will support shift-selection for making and
528 enlarging regions. To make this more effective, the bullet
529 cycling will no longer happen anywhere in an item line, but only
530 if the cursor is exactly on the bullet.
532 If you set this variable to the symbol `always', then the keys
533 will not be special in headlines, property lines, and item lines,
534 to make shift selection work there as well. If this is what you
535 want, you can use the following alternative commands: `C-c C-t'
536 and `C-c ,' to change TODO state and priority, `C-u C-u C-c C-t'
537 can be used to switch TODO sets, `C-c -' to cycle item bullet
538 types, and properties can be edited by hand or in column view.
540 However, when the cursor is on a timestamp, shift-cursor commands
541 will still edit the time stamp - this is just too good to give up.
543 XEmacs user should have this variable set to nil, because
544 `shift-select-mode' is in Emacs 23 or later only."
547 (const :tag
"Never" nil
)
548 (const :tag
"When outside special context" t
)
549 (const :tag
"Everywhere except timestamps" always
)))
551 (defcustom org-loop-over-headlines-in-active-region nil
552 "Shall some commands act upon headlines in the active region?
554 When set to `t', some commands will be performed in all headlines
555 within the active region.
557 When set to `start-level', some commands will be performed in all
558 headlines within the active region, provided that these headlines
559 are of the same level than the first one.
561 When set to a string, those commands will be performed on the
562 matching headlines within the active region. Such string must be
563 a tags/property/todo match as it is used in the agenda tags view.
565 The list of commands is: `org-schedule', `org-deadline',
566 `org-todo', `org-archive-subtree', `org-archive-set-tag' and
567 `org-archive-to-archive-sibling'. The archiving commands skip
568 already archived entries."
569 :type
'(choice (const :tag
"Don't loop" nil
)
570 (const :tag
"All headlines in active region" t
)
571 (const :tag
"In active region, headlines at the same level than the first one" 'start-level
)
572 (string :tag
"Tags/Property/Todo matcher"))
577 (defgroup org-startup nil
578 "Options concerning startup of Org-mode."
582 (defcustom org-startup-folded t
583 "Non-nil means entering Org-mode will switch to OVERVIEW.
584 This can also be configured on a per-file basis by adding one of
585 the following lines anywhere in the buffer:
587 #+STARTUP: fold (or `overview', this is equivalent)
588 #+STARTUP: nofold (or `showall', this is equivalent)
590 #+STARTUP: showeverything
592 By default, this option is ignored when Org opens agenda files
593 for the first time. If you want the agenda to honor the startup
594 option, set `org-agenda-inhibit-startup' to nil."
597 (const :tag
"nofold: show all" nil
)
598 (const :tag
"fold: overview" t
)
599 (const :tag
"content: all headlines" content
)
600 (const :tag
"show everything, even drawers" showeverything
)))
602 (defcustom org-startup-truncated t
603 "Non-nil means entering Org-mode will set `truncate-lines'.
604 This is useful since some lines containing links can be very long and
605 uninteresting. Also tables look terrible when wrapped."
609 (defcustom org-startup-indented nil
610 "Non-nil means turn on `org-indent-mode' on startup.
611 This can also be configured on a per-file basis by adding one of
612 the following lines anywhere in the buffer:
616 :group
'org-structure
618 (const :tag
"Not" nil
)
619 (const :tag
"Globally (slow on startup in large files)" t
)))
621 (defcustom org-use-sub-superscripts t
622 "Non-nil means interpret \"_\" and \"^\" for display.
623 When this option is turned on, you can use TeX-like syntax for sub- and
624 superscripts. Several characters after \"_\" or \"^\" will be
625 considered as a single item - so grouping with {} is normally not
626 needed. For example, the following things will be parsed as single
627 sub- or superscripts.
629 10^24 or 10^tau several digits will be considered 1 item.
630 10^-12 or 10^-tau a leading sign with digits or a word
631 x^2-y^3 will be read as x^2 - y^3, because items are
632 terminated by almost any nonword/nondigit char.
633 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
635 Still, ambiguity is possible - so when in doubt use {} to enclose
636 the sub/superscript. If you set this variable to the symbol
637 `{}', the braces are *required* in order to trigger
638 interpretations as sub/superscript. This can be helpful in
639 documents that need \"_\" frequently in plain text."
643 (const :tag
"Always interpret" t
)
644 (const :tag
"Only with braces" {})
645 (const :tag
"Never interpret" nil
)))
647 (defcustom org-startup-with-beamer-mode nil
648 "Non-nil means turn on `org-beamer-mode' on startup.
649 This can also be configured on a per-file basis by adding one of
650 the following lines anywhere in the buffer:
657 (defcustom org-startup-align-all-tables nil
658 "Non-nil means align all tables when visiting a file.
659 This is useful when the column width in tables is forced with <N> cookies
660 in table fields. Such tables will look correct only after the first re-align.
661 This can also be configured on a per-file basis by adding one of
662 the following lines anywhere in the buffer:
668 (defcustom org-startup-with-inline-images nil
669 "Non-nil means show inline images when loading a new Org file.
670 This can also be configured on a per-file basis by adding one of
671 the following lines anywhere in the buffer:
672 #+STARTUP: inlineimages
673 #+STARTUP: noinlineimages"
678 (defcustom org-startup-with-latex-preview nil
679 "Non-nil means preview LaTeX fragments when loading a new Org file.
681 This can also be configured on a per-file basis by adding one of
682 the followinglines anywhere in the buffer:
683 #+STARTUP: latexpreview
684 #+STARTUP: nolatexpreview"
689 (defcustom org-insert-mode-line-in-empty-file nil
690 "Non-nil means insert the first line setting Org-mode in empty files.
691 When the function `org-mode' is called interactively in an empty file, this
692 normally means that the file name does not automatically trigger Org-mode.
693 To ensure that the file will always be in Org-mode in the future, a
694 line enforcing Org-mode will be inserted into the buffer, if this option
699 (defcustom org-replace-disputed-keys nil
700 "Non-nil means use alternative key bindings for some keys.
701 Org-mode uses S-<cursor> keys for changing timestamps and priorities.
702 These keys are also used by other packages like shift-selection-mode'
703 \(built into Emacs 23), `CUA-mode' or `windmove.el'.
704 If you want to use Org-mode together with one of these other modes,
705 or more generally if you would like to move some Org-mode commands to
706 other keys, set this variable and configure the keys with the variable
709 This option is only relevant at load-time of Org-mode, and must be set
710 *before* org.el is loaded. Changing it requires a restart of Emacs to
715 (defcustom org-use-extra-keys nil
716 "Non-nil means use extra key sequence definitions for certain commands.
717 This happens automatically if you run XEmacs or if `window-system'
718 is nil. This variable lets you do the same manually. You must
719 set it before loading org.
721 Example: on Carbon Emacs 22 running graphically, with an external
722 keyboard on a Powerbook, the default way of setting M-left might
723 not work for either Alt or ESC. Setting this variable will make
728 (if (fboundp 'defvaralias
)
729 (defvaralias 'org-CUA-compatible
'org-replace-disputed-keys
))
731 (defcustom org-disputed-keys
732 '(([(shift up
)] .
[(meta p
)])
733 ([(shift down
)] .
[(meta n
)])
734 ([(shift left
)] .
[(meta -
)])
735 ([(shift right
)] .
[(meta +)])
736 ([(control shift right
)] .
[(meta shift
+)])
737 ([(control shift left
)] .
[(meta shift -
)]))
738 "Keys for which Org-mode and other modes compete.
739 This is an alist, cars are the default keys, second element specifies
740 the alternative to use when `org-replace-disputed-keys' is t.
742 Keys can be specified in any syntax supported by `define-key'.
743 The value of this option takes effect only at Org-mode's startup,
744 therefore you'll have to restart Emacs to apply it after changing."
749 "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'.
750 Or return the original if not disputed.
751 Also apply the translations defined in `org-xemacs-key-equivalents'."
752 (when org-replace-disputed-keys
753 (let* ((nkey (key-description key
))
754 (x (org-find-if (lambda (x)
755 (equal (key-description (car x
)) nkey
))
757 (setq key
(if x
(cdr x
) key
))))
758 (when (featurep 'xemacs
)
759 (setq key
(or (cdr (assoc key org-xemacs-key-equivalents
)) key
)))
762 (defun org-find-if (predicate seq
)
765 (if (funcall predicate
(car seq
))
766 (throw 'exit
(car seq
))
769 (defun org-defkey (keymap key def
)
770 "Define a key, possibly translated, as returned by `org-key'."
771 (define-key keymap
(org-key key
) def
))
773 (defcustom org-ellipsis nil
774 "The ellipsis to use in the Org-mode outline.
775 When nil, just use the standard three dots. When a string, use that instead,
776 When a face, use the standard 3 dots, but with the specified face.
777 The change affects only Org-mode (which will then use its own display table).
778 Changing this requires executing `M-x org-mode' in a buffer to become
781 :type
'(choice (const :tag
"Default" nil
)
782 (face :tag
"Face" :value org-warning
)
783 (string :tag
"String" :value
"...#")))
785 (defvar org-display-table nil
786 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
788 (defgroup org-keywords nil
789 "Keywords in Org-mode."
793 (defcustom org-deadline-string
"DEADLINE:"
794 "String to mark deadline entries.
795 A deadline is this string, followed by a time stamp. Should be a word,
796 terminated by a colon. You can insert a schedule keyword and
797 a timestamp with \\[org-deadline].
798 Changes become only effective after restarting Emacs."
802 (defcustom org-scheduled-string
"SCHEDULED:"
803 "String to mark scheduled TODO entries.
804 A schedule is this string, followed by a time stamp. Should be a word,
805 terminated by a colon. You can insert a schedule keyword and
806 a timestamp with \\[org-schedule].
807 Changes become only effective after restarting Emacs."
811 (defcustom org-closed-string
"CLOSED:"
812 "String used as the prefix for timestamps logging closing a TODO entry."
816 (defcustom org-clock-string
"CLOCK:"
817 "String used as prefix for timestamps clocking work hours on an item."
821 (defconst org-planning-or-clock-line-re
(concat "^[ \t]*\\("
822 org-scheduled-string
"\\|"
823 org-deadline-string
"\\|"
824 org-closed-string
"\\|"
825 org-clock-string
"\\)")
826 "Matches a line with planning or clock info.")
828 (defcustom org-comment-string
"COMMENT"
829 "Entries starting with this keyword will never be exported.
830 An entry can be toggled between COMMENT and normal with
831 \\[org-toggle-comment].
832 Changes become only effective after restarting Emacs."
836 (defcustom org-quote-string
"QUOTE"
837 "Entries starting with this keyword will be exported in fixed-width font.
838 Quoting applies only to the text in the entry following the headline, and does
839 not extend beyond the next headline, even if that is lower level.
840 An entry can be toggled between QUOTE and normal with
841 \\[org-toggle-fixed-width-section]."
845 (defconst org-repeat-re
846 "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
847 "Regular expression for specifying repeated events.
848 After a match, group 1 contains the repeat expression.")
850 (defgroup org-structure nil
851 "Options concerning the general structure of Org-mode files."
855 (defgroup org-reveal-location nil
856 "Options about how to make context of a location visible."
857 :tag
"Org Reveal Location"
858 :group
'org-structure
)
860 (defconst org-context-choice
862 (const :tag
"Always" t
)
863 (const :tag
"Never" nil
)
864 (repeat :greedy t
:tag
"Individual contexts"
866 (choice :tag
"Context"
873 (const bookmark-jump
)
877 "Contexts for the reveal options.")
879 (defcustom org-show-hierarchy-above
'((default . t
))
880 "Non-nil means show full hierarchy when revealing a location.
881 Org-mode often shows locations in an org-mode file which might have
882 been invisible before. When this is set, the hierarchy of headings
883 above the exposed location is shown.
884 Turning this off for example for sparse trees makes them very compact.
885 Instead of t, this can also be an alist specifying this option for different
886 contexts. Valid contexts are
887 agenda when exposing an entry from the agenda
888 org-goto when using the command `org-goto' on key C-c C-j
889 occur-tree when using the command `org-occur' on key C-c /
890 tags-tree when constructing a sparse tree based on tags matches
891 link-search when exposing search matches associated with a link
892 mark-goto when exposing the jump goal of a mark
893 bookmark-jump when exposing a bookmark location
894 isearch when exiting from an incremental search
895 default default for all contexts not set explicitly"
896 :group
'org-reveal-location
897 :type org-context-choice
)
899 (defcustom org-show-following-heading
'((default . nil
))
900 "Non-nil means show following heading when revealing a location.
901 Org-mode often shows locations in an org-mode file which might have
902 been invisible before. When this is set, the heading following the
904 Turning this off for example for sparse trees makes them very compact,
905 but makes it harder to edit the location of the match. In such a case,
906 use the command \\[org-reveal] to show more context.
907 Instead of t, this can also be an alist specifying this option for different
908 contexts. See `org-show-hierarchy-above' for valid contexts."
909 :group
'org-reveal-location
910 :type org-context-choice
)
912 (defcustom org-show-siblings
'((default . nil
) (isearch t
))
913 "Non-nil means show all sibling heading when revealing a location.
914 Org-mode often shows locations in an org-mode file which might have
915 been invisible before. When this is set, the sibling of the current entry
916 heading are all made visible. If `org-show-hierarchy-above' is t,
917 the same happens on each level of the hierarchy above the current entry.
919 By default this is on for the isearch context, off for all other contexts.
920 Turning this off for example for sparse trees makes them very compact,
921 but makes it harder to edit the location of the match. In such a case,
922 use the command \\[org-reveal] to show more context.
923 Instead of t, this can also be an alist specifying this option for different
924 contexts. See `org-show-hierarchy-above' for valid contexts."
925 :group
'org-reveal-location
926 :type org-context-choice
)
928 (defcustom org-show-entry-below
'((default . nil
))
929 "Non-nil means show the entry below a headline when revealing a location.
930 Org-mode often shows locations in an org-mode file which might have
931 been invisible before. When this is set, the text below the headline that is
932 exposed is also shown.
934 By default this is off for all contexts.
935 Instead of t, this can also be an alist specifying this option for different
936 contexts. See `org-show-hierarchy-above' for valid contexts."
937 :group
'org-reveal-location
938 :type org-context-choice
)
940 (defcustom org-indirect-buffer-display
'other-window
941 "How should indirect tree buffers be displayed?
942 This applies to indirect buffers created with the commands
943 \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer].
945 current-window Display in the current window
946 other-window Just display in another window.
947 dedicated-frame Create one new frame, and re-use it each time.
948 new-frame Make a new frame each time. Note that in this case
949 previously-made indirect buffers are kept, and you need to
950 kill these buffers yourself."
951 :group
'org-structure
952 :group
'org-agenda-windows
954 (const :tag
"In current window" current-window
)
955 (const :tag
"In current frame, other window" other-window
)
956 (const :tag
"Each time a new frame" new-frame
)
957 (const :tag
"One dedicated frame" dedicated-frame
)))
959 (defcustom org-use-speed-commands nil
960 "Non-nil means activate single letter commands at beginning of a headline.
961 This may also be a function to test for appropriate locations where speed
962 commands should be active."
963 :group
'org-structure
965 (const :tag
"Never" nil
)
966 (const :tag
"At beginning of headline stars" t
)
969 (defcustom org-speed-commands-user nil
970 "Alist of additional speed commands.
971 This list will be checked before `org-speed-commands-default'
972 when the variable `org-use-speed-commands' is non-nil
973 and when the cursor is at the beginning of a headline.
974 The car if each entry is a string with a single letter, which must
975 be assigned to `self-insert-command' in the global map.
976 The cdr is either a command to be called interactively, a function
977 to be called, or a form to be evaluated.
978 An entry that is just a list with a single string will be interpreted
979 as a descriptive headline that will be added when listing the speed
980 commands in the Help buffer using the `?' speed command."
981 :group
'org-structure
982 :type
'(repeat :value
("k" . ignore
)
983 (choice :value
("k" . ignore
)
984 (list :tag
"Descriptive Headline" (string :tag
"Headline"))
985 (cons :tag
"Letter and Command"
986 (string :tag
"Command letter")
991 (defgroup org-cycle nil
992 "Options concerning visibility cycling in Org-mode."
994 :group
'org-structure
)
996 (defcustom org-cycle-skip-children-state-if-no-children t
997 "Non-nil means skip CHILDREN state in entries that don't have any."
1001 (defcustom org-cycle-max-level nil
1002 "Maximum level which should still be subject to visibility cycling.
1003 Levels higher than this will, for cycling, be treated as text, not a headline.
1004 When `org-odd-levels-only' is set, a value of N in this variable actually
1005 means 2N-1 stars as the limiting headline.
1006 When nil, cycle all levels.
1007 Note that the limiting level of cycling is also influenced by
1008 `org-inlinetask-min-level'. When `org-cycle-max-level' is not set but
1009 `org-inlinetask-min-level' is, cycling will be limited to levels one less
1013 (const :tag
"No limit" nil
)
1014 (integer :tag
"Maximum level")))
1016 (defcustom org-drawers
'("PROPERTIES" "CLOCK" "LOGBOOK" "RESULTS")
1017 "Names of drawers. Drawers are not opened by cycling on the headline above.
1018 Drawers only open with a TAB on the drawer line itself. A drawer looks like
1023 The drawer \"PROPERTIES\" is special for capturing properties through
1026 Drawers can be defined on the per-file basis with a line like:
1028 #+DRAWERS: HIDDEN STATE PROPERTIES"
1029 :group
'org-structure
1031 :type
'(repeat (string :tag
"Drawer Name")))
1033 (defcustom org-hide-block-startup nil
1034 "Non-nil means entering Org-mode will fold all blocks.
1035 This can also be set in on a per-file basis with
1037 #+STARTUP: hideblocks
1038 #+STARTUP: showblocks"
1043 (defcustom org-cycle-global-at-bob nil
1044 "Cycle globally if cursor is at beginning of buffer and not at a headline.
1045 This makes it possible to do global cycling without having to use S-TAB or
1046 \\[universal-argument] TAB. For this special case to work, the first line
1047 of the buffer must not be a headline -- it may be empty or some other text.
1048 When used in this way, `org-cycle-hook' is disabled temporarily to make
1049 sure the cursor stays at the beginning of the buffer. When this option is
1050 nil, don't do anything special at the beginning of the buffer."
1054 (defcustom org-cycle-level-after-item
/entry-creation t
1055 "Non-nil means cycle entry level or item indentation in new empty entries.
1057 When the cursor is at the end of an empty headline, i.e., with only stars
1058 and maybe a TODO keyword, TAB will then switch the entry to become a child,
1059 and then all possible ancestor states, before returning to the original state.
1060 This makes data entry extremely fast: M-RET to create a new headline,
1061 on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
1063 When the cursor is at the end of an empty plain list item, one TAB will
1064 make it a subitem, two or more tabs will back up to make this an item
1065 higher up in the item hierarchy."
1069 (defcustom org-cycle-emulate-tab t
1070 "Where should `org-cycle' emulate TAB.
1072 white Only in completely white lines
1073 whitestart Only at the beginning of lines, before the first non-white char
1074 t Everywhere except in headlines
1075 exc-hl-bol Everywhere except at the start of a headline
1076 If TAB is used in a place where it does not emulate TAB, the current subtree
1077 visibility is cycled."
1079 :type
'(choice (const :tag
"Never" nil
)
1080 (const :tag
"Only in completely white lines" white
)
1081 (const :tag
"Before first char in a line" whitestart
)
1082 (const :tag
"Everywhere except in headlines" t
)
1083 (const :tag
"Everywhere except at bol in headlines" exc-hl-bol
)
1086 (defcustom org-cycle-separator-lines
2
1087 "Number of empty lines needed to keep an empty line between collapsed trees.
1088 If you leave an empty line between the end of a subtree and the following
1089 headline, this empty line is hidden when the subtree is folded.
1090 Org-mode will leave (exactly) one empty line visible if the number of
1091 empty lines is equal or larger to the number given in this variable.
1092 So the default 2 means at least 2 empty lines after the end of a subtree
1093 are needed to produce free space between a collapsed subtree and the
1096 If the number is negative, and the number of empty lines is at least -N,
1097 all empty lines are shown.
1099 Special case: when 0, never leave empty lines in collapsed view."
1102 (put 'org-cycle-separator-lines
'safe-local-variable
'integerp
)
1104 (defcustom org-pre-cycle-hook nil
1105 "Hook that is run before visibility cycling is happening.
1106 The function(s) in this hook must accept a single argument which indicates
1107 the new state that will be set right after running this hook. The
1108 argument is a symbol. Before a global state change, it can have the values
1109 `overview', `content', or `all'. Before a local state change, it can have
1110 the values `folded', `children', or `subtree'."
1114 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
1115 org-cycle-hide-drawers
1116 org-cycle-hide-inline-tasks
1117 org-cycle-show-empty-lines
1118 org-optimize-window-after-visibility-change
)
1119 "Hook that is run after `org-cycle' has changed the buffer visibility.
1120 The function(s) in this hook must accept a single argument which indicates
1121 the new state that was set by the most recent `org-cycle' command. The
1122 argument is a symbol. After a global state change, it can have the values
1123 `overview', `contents', or `all'. After a local state change, it can have
1124 the values `folded', `children', or `subtree'."
1128 (defgroup org-edit-structure nil
1129 "Options concerning structure editing in Org-mode."
1130 :tag
"Org Edit Structure"
1131 :group
'org-structure
)
1133 (defcustom org-odd-levels-only nil
1134 "Non-nil means skip even levels and only use odd levels for the outline.
1135 This has the effect that two stars are being added/taken away in
1136 promotion/demotion commands. It also influences how levels are
1137 handled by the exporters.
1138 Changing it requires restart of `font-lock-mode' to become effective
1139 for fontification also in regions already fontified.
1140 You may also set this on a per-file basis by adding one of the following
1141 lines to the buffer:
1145 :group
'org-edit-structure
1146 :group
'org-appearance
1149 (defcustom org-adapt-indentation t
1150 "Non-nil means adapt indentation to outline node level.
1152 When this variable is set, Org assumes that you write outlines by
1153 indenting text in each node to align with the headline (after the stars).
1154 The following issues are influenced by this variable:
1156 - When this is set and the *entire* text in an entry is indented, the
1157 indentation is increased by one space in a demotion command, and
1158 decreased by one in a promotion command. If any line in the entry
1159 body starts with text at column 0, indentation is not changed at all.
1161 - Property drawers and planning information is inserted indented when
1162 this variable s set. When nil, they will not be indented.
1164 - TAB indents a line relative to context. The lines below a headline
1165 will be indented when this variable is set.
1167 Note that this is all about true indentation, by adding and removing
1168 space characters. See also `org-indent.el' which does level-dependent
1169 indentation in a virtual way, i.e. at display time in Emacs."
1170 :group
'org-edit-structure
1173 (defcustom org-special-ctrl-a
/e nil
1174 "Non-nil means `C-a' and `C-e' behave specially in headlines and items.
1176 When t, `C-a' will bring back the cursor to the beginning of the
1177 headline text, i.e. after the stars and after a possible TODO
1178 keyword. In an item, this will be the position after bullet and
1179 check-box, if any. When the cursor is already at that position,
1180 another `C-a' will bring it to the beginning of the line.
1182 `C-e' will jump to the end of the headline, ignoring the presence
1183 of tags in the headline. A second `C-e' will then jump to the
1184 true end of the line, after any tags. This also means that, when
1185 this variable is non-nil, `C-e' also will never jump beyond the
1186 end of the heading of a folded section, i.e. not after the
1189 When set to the symbol `reversed', the first `C-a' or `C-e' works
1190 normally, going to the true line boundary first. Only a directly
1191 following, identical keypress will bring the cursor to the
1194 This may also be a cons cell where the behavior for `C-a' and
1195 `C-e' is set separately."
1196 :group
'org-edit-structure
1198 (const :tag
"off" nil
)
1199 (const :tag
"on: after stars/bullet and before tags first" t
)
1200 (const :tag
"reversed: true line boundary first" reversed
)
1201 (cons :tag
"Set C-a and C-e separately"
1202 (choice :tag
"Special C-a"
1203 (const :tag
"off" nil
)
1204 (const :tag
"on: after stars/bullet first" t
)
1205 (const :tag
"reversed: before stars/bullet first" reversed
))
1206 (choice :tag
"Special C-e"
1207 (const :tag
"off" nil
)
1208 (const :tag
"on: before tags first" t
)
1209 (const :tag
"reversed: after tags first" reversed
)))))
1210 (if (fboundp 'defvaralias
)
1211 (defvaralias 'org-special-ctrl-a
'org-special-ctrl-a
/e
))
1213 (defcustom org-special-ctrl-k nil
1214 "Non-nil means `C-k' will behave specially in headlines.
1215 When nil, `C-k' will call the default `kill-line' command.
1216 When t, the following will happen while the cursor is in the headline:
1218 - When the cursor is at the beginning of a headline, kill the entire
1219 line and possible the folded subtree below the line.
1220 - When in the middle of the headline text, kill the headline up to the tags.
1221 - When after the headline text, kill the tags."
1222 :group
'org-edit-structure
1225 (defcustom org-ctrl-k-protect-subtree nil
1226 "Non-nil means, do not delete a hidden subtree with C-k.
1227 When set to the symbol `error', simply throw an error when C-k is
1228 used to kill (part-of) a headline that has hidden text behind it.
1229 Any other non-nil value will result in a query to the user, if it is
1230 OK to kill that hidden subtree. When nil, kill without remorse."
1231 :group
'org-edit-structure
1234 (const :tag
"Do not protect hidden subtrees" nil
)
1235 (const :tag
"Protect hidden subtrees with a security query" t
)
1236 (const :tag
"Never kill a hidden subtree with C-k" error
)))
1238 (defcustom org-catch-invisible-edits nil
1239 "Check if in invisible region before inserting or deleting a character.
1242 nil Do not check, so just do invisible edits.
1243 error Throw an error and do nothing.
1244 show Make point visible, and do the requested edit.
1245 show-and-error Make point visible, then throw an error and abort the edit.
1246 smart Make point visible, and do insertion/deletion if it is
1247 adjacent to visible text and the change feels predictable.
1248 Never delete a previously invisible character or add in the
1249 middle or right after an invisible region. Basically, this
1250 allows insertion and backward-delete right before ellipses.
1251 FIXME: maybe in this case we should not even show?"
1252 :group
'org-edit-structure
1255 (const :tag
"Do not check" nil
)
1256 (const :tag
"Throw error when trying to edit" error
)
1257 (const :tag
"Unhide, but do not do the edit" show-and-error
)
1258 (const :tag
"Show invisible part and do the edit" show
)
1259 (const :tag
"Be smart and do the right thing" smart
)))
1261 (defcustom org-yank-folded-subtrees t
1262 "Non-nil means when yanking subtrees, fold them.
1263 If the kill is a single subtree, or a sequence of subtrees, i.e. if
1264 it starts with a heading and all other headings in it are either children
1265 or siblings, then fold all the subtrees. However, do this only if no
1266 text after the yank would be swallowed into a folded tree by this action."
1267 :group
'org-edit-structure
1270 (defcustom org-yank-adjusted-subtrees nil
1271 "Non-nil means when yanking subtrees, adjust the level.
1272 With this setting, `org-paste-subtree' is used to insert the subtree, see
1273 this function for details."
1274 :group
'org-edit-structure
1277 (defcustom org-M-RET-may-split-line
'((default . t
))
1278 "Non-nil means M-RET will split the line at the cursor position.
1279 When nil, it will go to the end of the line before making a
1281 You may also set this option in a different way for different
1282 contexts. Valid contexts are:
1284 headline when creating a new headline
1285 item when creating a new item
1286 table in a table field
1287 default the value to be used for all contexts not explicitly
1289 :group
'org-structure
1292 (const :tag
"Always" t
)
1293 (const :tag
"Never" nil
)
1294 (repeat :greedy t
:tag
"Individual contexts"
1296 (choice :tag
"Context"
1304 (defcustom org-insert-heading-respect-content nil
1305 "Non-nil means insert new headings after the current subtree.
1306 When nil, the new heading is created directly after the current line.
1307 The commands \\[org-insert-heading-respect-content] and
1308 \\[org-insert-todo-heading-respect-content] turn this variable on
1309 for the duration of the command."
1310 :group
'org-structure
1313 (defcustom org-blank-before-new-entry
'((heading . auto
)
1314 (plain-list-item . auto
))
1315 "Should `org-insert-heading' leave a blank line before new heading/item?
1316 The value is an alist, with `heading' and `plain-list-item' as CAR,
1317 and a boolean flag as CDR. The cdr may also be the symbol `auto', in
1318 which case Org will look at the surrounding headings/items and try to
1319 make an intelligent decision whether to insert a blank line or not.
1321 For plain lists, if the variable `org-empty-line-terminates-plain-lists' is
1322 set, the setting here is ignored and no empty line is inserted, to avoid
1323 breaking the list structure."
1324 :group
'org-edit-structure
1326 (cons (const heading
)
1327 (choice (const :tag
"Never" nil
)
1328 (const :tag
"Always" t
)
1329 (const :tag
"Auto" auto
)))
1330 (cons (const plain-list-item
)
1331 (choice (const :tag
"Never" nil
)
1332 (const :tag
"Always" t
)
1333 (const :tag
"Auto" auto
)))))
1335 (defcustom org-insert-heading-hook nil
1336 "Hook being run after inserting a new heading."
1337 :group
'org-edit-structure
1340 (defcustom org-enable-fixed-width-editor t
1341 "Non-nil means lines starting with \":\" are treated as fixed-width.
1342 This currently only means they are never auto-wrapped.
1343 When nil, such lines will be treated like ordinary lines.
1344 See also the QUOTE keyword."
1345 :group
'org-edit-structure
1348 (defcustom org-goto-auto-isearch t
1349 "Non-nil means typing characters in `org-goto' starts incremental search.
1350 When nil, you can use these keybindings to navigate the buffer:
1352 q Quit the org-goto interface
1353 n Go to the next visible heading
1354 p Go to the previous visible heading
1355 f Go one heading forward on same level
1356 b Go one heading backward on same level
1357 u Go one heading up"
1358 :group
'org-edit-structure
1361 (defgroup org-sparse-trees nil
1362 "Options concerning sparse trees in Org-mode."
1363 :tag
"Org Sparse Trees"
1364 :group
'org-structure
)
1366 (defcustom org-highlight-sparse-tree-matches t
1367 "Non-nil means highlight all matches that define a sparse tree.
1368 The highlights will automatically disappear the next time the buffer is
1369 changed by an edit command."
1370 :group
'org-sparse-trees
1373 (defcustom org-remove-highlights-with-change t
1374 "Non-nil means any change to the buffer will remove temporary highlights.
1375 Such highlights are created by `org-occur' and `org-clock-display'.
1376 When nil, `C-c C-c needs to be used to get rid of the highlights.
1377 The highlights created by `org-preview-latex-fragment' always need
1378 `C-c C-c' to be removed."
1379 :group
'org-sparse-trees
1384 (defcustom org-occur-hook
'(org-first-headline-recenter)
1385 "Hook that is run after `org-occur' has constructed a sparse tree.
1386 This can be used to recenter the window to show as much of the structure
1388 :group
'org-sparse-trees
1391 (defgroup org-imenu-and-speedbar nil
1392 "Options concerning imenu and speedbar in Org-mode."
1393 :tag
"Org Imenu and Speedbar"
1394 :group
'org-structure
)
1396 (defcustom org-imenu-depth
2
1397 "The maximum level for Imenu access to Org-mode headlines.
1398 This also applied for speedbar access."
1399 :group
'org-imenu-and-speedbar
1402 (defgroup org-table nil
1403 "Options concerning tables in Org-mode."
1407 (defcustom org-enable-table-editor
'optimized
1408 "Non-nil means lines starting with \"|\" are handled by the table editor.
1409 When nil, such lines will be treated like ordinary lines.
1411 When equal to the symbol `optimized', the table editor will be optimized to
1413 - Automatic overwrite mode in front of whitespace in table fields.
1414 This makes the structure of the table stay in tact as long as the edited
1415 field does not exceed the column width.
1416 - Minimize the number of realigns. Normally, the table is aligned each time
1417 TAB or RET are pressed to move to another field. With optimization this
1418 happens only if changes to a field might have changed the column width.
1419 Optimization requires replacing the functions `self-insert-command',
1420 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
1421 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
1422 very good at guessing when a re-align will be necessary, but you can always
1423 force one with \\[org-ctrl-c-ctrl-c].
1425 If you would like to use the optimized version in Org-mode, but the
1426 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
1428 This variable can be used to turn on and off the table editor during a session,
1429 but in order to toggle optimization, a restart is required.
1431 See also the variable `org-table-auto-blank-field'."
1434 (const :tag
"off" nil
)
1436 (const :tag
"on, optimized" optimized
)))
1438 (defcustom org-self-insert-cluster-for-undo
(or (featurep 'xemacs
)
1439 (version<= emacs-version
"24.1"))
1440 "Non-nil means cluster self-insert commands for undo when possible.
1441 If this is set, then, like in the Emacs command loop, 20 consecutive
1442 characters will be undone together.
1443 This is configurable, because there is some impact on typing performance."
1447 (defcustom org-table-tab-recognizes-table.el t
1448 "Non-nil means TAB will automatically notice a table.el table.
1449 When it sees such a table, it moves point into it and - if necessary -
1450 calls `table-recognize-table'."
1451 :group
'org-table-editing
1454 (defgroup org-link nil
1455 "Options concerning links in Org-mode."
1459 (defvar org-link-abbrev-alist-local nil
1460 "Buffer-local version of `org-link-abbrev-alist', which see.
1461 The value of this is taken from the #+LINK lines.")
1462 (make-variable-buffer-local 'org-link-abbrev-alist-local
)
1464 (defcustom org-link-abbrev-alist nil
1465 "Alist of link abbreviations.
1466 The car of each element is a string, to be replaced at the start of a link.
1467 The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated
1468 links in Org-mode buffers can have an optional tag after a double colon, e.g.
1470 [[linkkey:tag][description]]
1472 The 'linkkey' must be a word word, starting with a letter, followed
1473 by letters, numbers, '-' or '_'.
1475 If REPLACE is a string, the tag will simply be appended to create the link.
1476 If the string contains \"%s\", the tag will be inserted there. If the string
1477 contains \"%h\", it will cause a url-encoded version of the tag to be inserted
1478 at that point (see the function `url-hexify-string'). If the string contains
1479 the specifier \"%(my-function)\", then the custom function `my-function' will
1480 be invoked: this function takes the tag as its only argument and must return
1483 REPLACE may also be a function that will be called with the tag as the
1484 only argument to create the link, which should be returned as a string.
1486 See the manual for examples."
1490 (string :tag
"Protocol")
1492 (string :tag
"Format")
1495 (defcustom org-descriptive-links t
1496 "Non-nil means Org will display descriptive links.
1497 E.g. [[http://orgmode.org][Org website]] will be displayed as
1498 \"Org Website\", hiding the link itself and just displaying its
1499 description. When set to `nil', Org will display the full links
1502 You can interactively set the value of this variable by calling
1503 `org-toggle-link-display' or from the menu Org>Hyperlinks menu."
1507 (defcustom org-link-file-path-type
'adaptive
1508 "How the path name in file links should be stored.
1511 relative Relative to the current directory, i.e. the directory of the file
1512 into which the link is being inserted.
1513 absolute Absolute path, if possible with ~ for home directory.
1514 noabbrev Absolute path, no abbreviation of home directory.
1515 adaptive Use relative path for files in the current directory and sub-
1516 directories of it. For other files, use an absolute path."
1524 (defcustom org-activate-links
'(bracket angle plain radio tag date footnote
)
1525 "Types of links that should be activated in Org-mode files.
1526 This is a list of symbols, each leading to the activation of a certain link
1527 type. In principle, it does not hurt to turn on most link types - there may
1528 be a small gain when turning off unused link types. The types are:
1530 bracket The recommended [[link][description]] or [[link]] links with hiding.
1531 angle Links in angular brackets that may contain whitespace like
1532 <bbdb:Carsten Dominik>.
1533 plain Plain links in normal text, no whitespace, like http://google.com.
1534 radio Text that is matched by a radio target, see manual for details.
1535 tag Tag settings in a headline (link to tag search).
1536 date Time stamps (link to calendar).
1537 footnote Footnote labels.
1539 Changing this variable requires a restart of Emacs to become effective."
1541 :type
'(set :greedy t
1542 (const :tag
"Double bracket links" bracket
)
1543 (const :tag
"Angular bracket links" angle
)
1544 (const :tag
"Plain text links" plain
)
1545 (const :tag
"Radio target matches" radio
)
1546 (const :tag
"Tags" tag
)
1547 (const :tag
"Timestamps" date
)
1548 (const :tag
"Footnotes" footnote
)))
1550 (defcustom org-make-link-description-function nil
1551 "Function to use for generating link descriptions from links.
1552 When nil, the link location will be used. This function must take
1553 two parameters: the first one is the link, the second one is the
1554 description generated by `org-insert-link'. The function should
1555 return the description to use."
1559 (defgroup org-link-store nil
1560 "Options concerning storing links in Org-mode."
1561 :tag
"Org Store Link"
1564 (defcustom org-url-hexify-p t
1565 "When non-nil, hexify URL when creating a link."
1568 :group
'org-link-store
)
1570 (defcustom org-email-link-description-format
"Email %c: %.30s"
1571 "Format of the description part of a link to an email or usenet message.
1572 The following %-escapes will be replaced by corresponding information:
1574 %F full \"From\" field
1575 %f name, taken from \"From\" field, address if no name
1576 %T full \"To\" field
1577 %t first name in \"To\" field, address if no name
1578 %c correspondent. Usually \"from NAME\", but if you sent it yourself, it
1579 will be \"to NAME\". See also the variable `org-from-is-user-regexp'.
1584 You may use normal field width specification between the % and the letter.
1585 This is for example useful to limit the length of the subject.
1587 Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\""
1588 :group
'org-link-store
1591 (defcustom org-from-is-user-regexp
1593 (when (and user-mail-address
(not (string= user-mail-address
"")))
1594 (setq r1
(concat "\\<" (regexp-quote user-mail-address
) "\\>")))
1595 (when (and user-full-name
(not (string= user-full-name
"")))
1596 (setq r2
(concat "\\<" (regexp-quote user-full-name
) "\\>")))
1597 (if (and r1 r2
) (concat r1
"\\|" r2
) (or r1 r2
)))
1598 "Regexp matched against the \"From:\" header of an email or usenet message.
1599 It should match if the message is from the user him/herself."
1600 :group
'org-link-store
1603 (defcustom org-context-in-file-links t
1604 "Non-nil means file links from `org-store-link' contain context.
1605 A search string will be added to the file name with :: as separator and
1606 used to find the context when the link is activated by the command
1607 `org-open-at-point'. When this option is t, the entire active region
1608 will be placed in the search string of the file link. If set to a
1609 positive integer, only the first n lines of context will be stored.
1611 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
1612 negates this setting for the duration of the command."
1613 :group
'org-link-store
1614 :type
'(choice boolean integer
))
1616 (defcustom org-keep-stored-link-after-insertion nil
1617 "Non-nil means keep link in list for entire session.
1619 The command `org-store-link' adds a link pointing to the current
1620 location to an internal list. These links accumulate during a session.
1621 The command `org-insert-link' can be used to insert links into any
1622 Org-mode file (offering completion for all stored links). When this
1623 option is nil, every link which has been inserted once using \\[org-insert-link]
1624 will be removed from the list, to make completing the unused links
1626 :group
'org-link-store
1629 (defgroup org-link-follow nil
1630 "Options concerning following links in Org-mode."
1631 :tag
"Org Follow Link"
1634 (defcustom org-link-translation-function nil
1635 "Function to translate links with different syntax to Org syntax.
1636 This can be used to translate links created for example by the Planner
1637 or emacs-wiki packages to Org syntax.
1638 The function must accept two parameters, a TYPE containing the link
1639 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
1640 which is everything after the link protocol. It should return a cons
1641 with possibly modified values of type and path.
1642 Org contains a function for this, so if you set this variable to
1643 `org-translate-link-from-planner', you should be able follow many
1644 links created by planner."
1645 :group
'org-link-follow
1648 (defcustom org-follow-link-hook nil
1649 "Hook that is run after a link has been followed."
1650 :group
'org-link-follow
1653 (defcustom org-tab-follows-link nil
1654 "Non-nil means on links TAB will follow the link.
1655 Needs to be set before org.el is loaded.
1656 This really should not be used, it does not make sense, and the
1657 implementation is bad."
1658 :group
'org-link-follow
1661 (defcustom org-return-follows-link nil
1662 "Non-nil means on links RET will follow the link.
1663 In tables, the special behavior of RET has precedence."
1664 :group
'org-link-follow
1667 (defcustom org-mouse-1-follows-link
1668 (if (boundp 'mouse-1-click-follows-link
) mouse-1-click-follows-link t
)
1669 "Non-nil means mouse-1 on a link will follow the link.
1670 A longer mouse click will still set point. Does not work on XEmacs.
1671 Needs to be set before org.el is loaded."
1672 :group
'org-link-follow
1675 (defcustom org-mark-ring-length
4
1676 "Number of different positions to be recorded in the ring.
1677 Changing this requires a restart of Emacs to work correctly."
1678 :group
'org-link-follow
1681 (defcustom org-link-search-must-match-exact-headline
'query-to-create
1682 "Non-nil means internal links in Org files must exactly match a headline.
1683 When nil, the link search tries to match a phrase with all words
1684 in the search text."
1685 :group
'org-link-follow
1688 (const :tag
"Use fuzzy text search" nil
)
1689 (const :tag
"Match only exact headline" t
)
1690 (const :tag
"Match exact headline or query to create it"
1693 (defcustom org-link-frame-setup
1694 '((vm . vm-visit-folder-other-frame
)
1695 (vm-imap . vm-visit-imap-folder-other-frame
)
1696 (gnus . org-gnus-no-new-news
)
1697 (file . find-file-other-window
)
1698 (wl . wl-other-frame
))
1699 "Setup the frame configuration for following links.
1700 When following a link with Emacs, it may often be useful to display
1701 this link in another window or frame. This variable can be used to
1702 set this up for the different types of links.
1705 `vm-visit-folder-other-window'
1706 `vm-visit-folder-other-frame'
1707 For Gnus, use any of
1710 `org-gnus-no-new-news'
1711 For FILE, use any of
1713 `find-file-other-window'
1714 `find-file-other-frame'
1715 For Wanderlust use any of
1718 For the calendar, use the variable `calendar-setup'.
1719 For BBDB, it is currently only possible to display the matches in
1721 :group
'org-link-follow
1725 (const vm-visit-folder
)
1726 (const vm-visit-folder-other-window
)
1727 (const vm-visit-folder-other-frame
)))
1731 (const gnus-other-frame
)
1732 (const org-gnus-no-new-news
)))
1736 (const find-file-other-window
)
1737 (const find-file-other-frame
)))
1741 (const wl-other-frame
)))))
1743 (defcustom org-display-internal-link-with-indirect-buffer nil
1744 "Non-nil means use indirect buffer to display infile links.
1745 Activating internal links (from one location in a file to another location
1746 in the same file) normally just jumps to the location. When the link is
1747 activated with a \\[universal-argument] prefix (or with mouse-3), the link \
1749 another window. When this option is set, the other window actually displays
1750 an indirect buffer clone of the current buffer, to avoid any visibility
1751 changes to the current buffer."
1752 :group
'org-link-follow
1755 (defcustom org-open-non-existing-files nil
1756 "Non-nil means `org-open-file' will open non-existing files.
1757 When nil, an error will be generated.
1758 This variable applies only to external applications because they
1759 might choke on non-existing files. If the link is to a file that
1760 will be opened in Emacs, the variable is ignored."
1761 :group
'org-link-follow
1764 (defcustom org-open-directory-means-index-dot-org nil
1765 "Non-nil means a link to a directory really means to index.org.
1766 When nil, following a directory link will run dired or open a finder/explorer
1767 window on that directory."
1768 :group
'org-link-follow
1771 (defcustom org-link-mailto-program
'(browse-url "mailto:%a?subject=%s")
1772 "Function and arguments to call for following mailto links.
1773 This is a list with the first element being a Lisp function, and the
1774 remaining elements being arguments to the function. In string arguments,
1775 %a will be replaced by the address, and %s will be replaced by the subject
1776 if one was given like in <mailto:arthur@galaxy.org::this subject>."
1777 :group
'org-link-follow
1779 (const :tag
"browse-url" (browse-url-mail "mailto:%a?subject=%s"))
1780 (const :tag
"compose-mail" (compose-mail "%a" "%s"))
1781 (const :tag
"message-mail" (message-mail "%a" "%s"))
1782 (cons :tag
"other" (function) (repeat :tag
"argument" sexp
))))
1784 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1785 "Non-nil means ask for confirmation before executing shell links.
1786 Shell links can be dangerous: just think about a link
1788 [[shell:rm -rf ~/*][Google Search]]
1790 This link would show up in your Org-mode document as \"Google Search\",
1791 but really it would remove your entire home directory.
1792 Therefore we advise against setting this variable to nil.
1793 Just change it to `y-or-n-p' if you want to confirm with a
1794 single keystroke rather than having to type \"yes\"."
1795 :group
'org-link-follow
1797 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1798 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1799 (const :tag
"no confirmation (dangerous)" nil
)))
1800 (put 'org-confirm-shell-link-function
1801 'safe-local-variable
1802 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1804 (defcustom org-confirm-shell-link-not-regexp
""
1805 "A regexp to skip confirmation for shell links."
1806 :group
'org-link-follow
1810 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1811 "Non-nil means ask for confirmation before executing Emacs Lisp links.
1812 Elisp links can be dangerous: just think about a link
1814 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1816 This link would show up in your Org-mode document as \"Google Search\",
1817 but really it would remove your entire home directory.
1818 Therefore we advise against setting this variable to nil.
1819 Just change it to `y-or-n-p' if you want to confirm with a
1820 single keystroke rather than having to type \"yes\"."
1821 :group
'org-link-follow
1823 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1824 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1825 (const :tag
"no confirmation (dangerous)" nil
)))
1826 (put 'org-confirm-shell-link-function
1827 'safe-local-variable
1828 #'(lambda (x) (member x
'(yes-or-no-p y-or-n-p
))))
1830 (defcustom org-confirm-elisp-link-not-regexp
""
1831 "A regexp to skip confirmation for Elisp links."
1832 :group
'org-link-follow
1836 (defconst org-file-apps-defaults-gnu
1840 "Default file applications on a UNIX or GNU/Linux system.
1841 See `org-file-apps'.")
1843 (defconst org-file-apps-defaults-macosx
1846 (system .
"open %s")
1848 ("eps.gz" .
"gv %s")
1850 ("fig" .
"xfig %s"))
1851 "Default file applications on a MacOS X system.
1852 The system \"open\" is known as a default, but we use X11 applications
1853 for some files for which the OS does not have a good default.
1854 See `org-file-apps'.")
1856 (defconst org-file-apps-defaults-windowsnt
1860 (list (if (featurep 'xemacs
)
1861 'mswindows-shell-execute
1865 (list (if (featurep 'xemacs
)
1866 'mswindows-shell-execute
1869 "Default file applications on a Windows NT system.
1870 The system \"open\" is used for most files.
1871 See `org-file-apps'.")
1873 (defcustom org-file-apps
1876 ("\\.mm\\'" . default
)
1877 ("\\.x?html?\\'" . default
)
1878 ("\\.pdf\\'" . default
)
1880 "External applications for opening `file:path' items in a document.
1881 Org-mode uses system defaults for different file types, but
1882 you can use this variable to set the application for a given file
1883 extension. The entries in this list are cons cells where the car identifies
1884 files and the cdr the corresponding command. Possible values for the
1886 \"string\" A string as a file identifier can be interpreted in different
1887 ways, depending on its contents:
1889 - Alphanumeric characters only:
1890 Match links with this file extension.
1891 Example: (\"pdf\" . \"evince %s\")
1892 to open PDFs with evince.
1894 - Regular expression: Match links where the
1895 filename matches the regexp. If you want to
1896 use groups here, use shy groups.
1898 Example: (\"\\.x?html\\'\" . \"firefox %s\")
1899 (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
1900 to open *.html and *.xhtml with firefox.
1902 - Regular expression which contains (non-shy) groups:
1903 Match links where the whole link, including \"::\", and
1904 anything after that, matches the regexp.
1905 In a custom command string, %1, %2, etc. are replaced with
1906 the parts of the link that were matched by the groups.
1907 For backwards compatibility, if a command string is given
1908 that does not use any of the group matches, this case is
1909 handled identically to the second one (i.e. match against
1911 In a custom lisp form, you can access the group matches with
1912 (match-string n link).
1914 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
1915 to open [[file:document.pdf::5]] with evince at page 5.
1917 `directory' Matches a directory
1918 `remote' Matches a remote file, accessible through tramp or efs.
1919 Remote files most likely should be visited through Emacs
1920 because external applications cannot handle such paths.
1921 `auto-mode' Matches files that are matched by any entry in `auto-mode-alist',
1922 so all files Emacs knows how to handle. Using this with
1923 command `emacs' will open most files in Emacs. Beware that this
1924 will also open html files inside Emacs, unless you add
1925 (\"html\" . default) to the list as well.
1926 t Default for files not matched by any of the other options.
1927 `system' The system command to open files, like `open' on Windows
1928 and Mac OS X, and mailcap under GNU/Linux. This is the command
1929 that will be selected if you call `C-c C-o' with a double
1930 \\[universal-argument] \\[universal-argument] prefix.
1932 Possible values for the command are:
1933 `emacs' The file will be visited by the current Emacs process.
1934 `default' Use the default application for this file type, which is the
1935 association for t in the list, most likely in the system-specific
1937 This can be used to overrule an unwanted setting in the
1938 system-specific variable.
1939 `system' Use the system command for opening files, like \"open\".
1940 This command is specified by the entry whose car is `system'.
1941 Most likely, the system-specific version of this variable
1942 does define this command, but you can overrule/replace it
1944 string A command to be executed by a shell; %s will be replaced
1945 by the path to the file.
1946 sexp A Lisp form which will be evaluated. The file path will
1947 be available in the Lisp variable `file'.
1948 For more examples, see the system specific constants
1949 `org-file-apps-defaults-macosx'
1950 `org-file-apps-defaults-windowsnt'
1951 `org-file-apps-defaults-gnu'."
1952 :group
'org-link-follow
1954 (cons (choice :value
""
1955 (string :tag
"Extension")
1956 (const :tag
"System command to open files" system
)
1957 (const :tag
"Default for unrecognized files" t
)
1958 (const :tag
"Remote file" remote
)
1959 (const :tag
"Links to a directory" directory
)
1960 (const :tag
"Any files that have Emacs modes"
1963 (const :tag
"Visit with Emacs" emacs
)
1964 (const :tag
"Use default" default
)
1965 (const :tag
"Use the system command" system
)
1966 (string :tag
"Command")
1967 (sexp :tag
"Lisp form")))))
1969 (defcustom org-doi-server-url
"http://dx.doi.org/"
1970 "The URL of the DOI server."
1973 :group
'org-link-follow
)
1975 (defgroup org-refile nil
1976 "Options concerning refiling entries in Org-mode."
1980 (defcustom org-directory
"~/org"
1981 "Directory with org files.
1982 This is just a default location to look for Org files. There is no need
1983 at all to put your files into this directory. It is only used in the
1984 following situations:
1986 1. When a capture template specifies a target file that is not an
1987 absolute path. The path will then be interpreted relative to
1989 2. When a capture note is filed away in an interactive way (when exiting the
1990 note buffer with `C-1 C-c C-c'. The user is prompted for an org file,
1991 with `org-directory' as the default path."
1993 :group
'org-remember
1997 (defcustom org-default-notes-file
(convert-standard-filename "~/.notes")
1998 "Default target for storing notes.
1999 Used as a fall back file for org-remember.el and org-capture.el, for
2000 templates that do not specify a target file."
2002 :group
'org-remember
2005 (const :tag
"Default from remember-data-file" nil
)
2008 (defcustom org-goto-interface
'outline
2009 "The default interface to be used for `org-goto'.
2011 outline The interface shows an outline of the relevant file
2012 and the correct heading is found by moving through
2013 the outline or by searching with incremental search.
2014 outline-path-completion Headlines in the current buffer are offered via
2015 completion. This is the interface also used by
2016 the refile command."
2019 (const :tag
"Outline" outline
)
2020 (const :tag
"Outline-path-completion" outline-path-completion
)))
2022 (defcustom org-goto-max-level
5
2023 "Maximum target level when running `org-goto' with refile interface."
2027 (defcustom org-reverse-note-order nil
2028 "Non-nil means store new notes at the beginning of a file or entry.
2029 When nil, new notes will be filed to the end of a file or entry.
2030 This can also be a list with cons cells of regular expressions that
2031 are matched against file names, and values."
2032 :group
'org-remember
2036 (const :tag
"Reverse always" t
)
2037 (const :tag
"Reverse never" nil
)
2038 (repeat :tag
"By file name regexp"
2039 (cons regexp boolean
))))
2041 (defcustom org-log-refile nil
2042 "Information to record when a task is refiled.
2044 Possible values are:
2046 nil Don't add anything
2047 time Add a time stamp to the task
2048 note Prompt for a note and add it with template `org-log-note-headings'
2050 This option can also be set with on a per-file-basis with
2052 #+STARTUP: nologrefile
2053 #+STARTUP: logrefile
2054 #+STARTUP: lognoterefile
2056 You can have local logging settings for a subtree by setting the LOGGING
2057 property to one or more of these keywords.
2059 When bulk-refiling from the agenda, the value `note' is forbidden and
2060 will temporarily be changed to `time'."
2062 :group
'org-progress
2065 (const :tag
"No logging" nil
)
2066 (const :tag
"Record timestamp" time
)
2067 (const :tag
"Record timestamp with note." note
)))
2069 (defcustom org-refile-targets nil
2070 "Targets for refiling entries with \\[org-refile].
2071 This is a list of cons cells. Each cell contains:
2072 - a specification of the files to be considered, either a list of files,
2073 or a symbol whose function or variable value will be used to retrieve
2074 a file name or a list of file names. If you use `org-agenda-files' for
2075 that, all agenda files will be scanned for targets. Nil means consider
2076 headings in the current buffer.
2077 - A specification of how to find candidate refile targets. This may be
2079 - a cons cell (:tag . \"TAG\") to identify refile targets by a tag.
2080 This tag has to be present in all target headlines, inheritance will
2082 - a cons cell (:todo . \"KEYWORD\") to identify refile targets by
2084 - a cons cell (:regexp . \"REGEXP\") with a regular expression matching
2085 headlines that are refiling targets.
2086 - a cons cell (:level . N). Any headline of level N is considered a target.
2087 Note that, when `org-odd-levels-only' is set, level corresponds to
2088 order in hierarchy, not to the number of stars.
2089 - a cons cell (:maxlevel . N). Any headline with level <= N is a target.
2090 Note that, when `org-odd-levels-only' is set, level corresponds to
2091 order in hierarchy, not to the number of stars.
2093 Each element of this list generates a set of possible targets.
2094 The union of these sets is presented (with completion) to
2095 the user by `org-refile'.
2097 You can set the variable `org-refile-target-verify-function' to a function
2098 to verify each headline found by the simple criteria above.
2100 When this variable is nil, all top-level headlines in the current buffer
2101 are used, equivalent to the value `((nil . (:level . 1))'."
2105 (choice :value org-agenda-files
2106 (const :tag
"All agenda files" org-agenda-files
)
2107 (const :tag
"Current buffer" nil
)
2108 (function) (variable) (file))
2109 (choice :tag
"Identify target headline by"
2110 (cons :tag
"Specific tag" (const :value
:tag
) (string))
2111 (cons :tag
"TODO keyword" (const :value
:todo
) (string))
2112 (cons :tag
"Regular expression" (const :value
:regexp
) (regexp))
2113 (cons :tag
"Level number" (const :value
:level
) (integer))
2114 (cons :tag
"Max Level number" (const :value
:maxlevel
) (integer))))))
2116 (defcustom org-refile-target-verify-function nil
2117 "Function to verify if the headline at point should be a refile target.
2118 The function will be called without arguments, with point at the
2119 beginning of the headline. It should return t and leave point
2120 where it is if the headline is a valid target for refiling.
2122 If the target should not be selected, the function must return nil.
2123 In addition to this, it may move point to a place from where the search
2124 should be continued. For example, the function may decide that the entire
2125 subtree of the current entry should be excluded and move point to the end
2130 (defcustom org-refile-use-cache nil
2131 "Non-nil means cache refile targets to speed up the process.
2132 The cache for a particular file will be updated automatically when
2133 the buffer has been killed, or when any of the marker used for flagging
2134 refile targets no longer points at a live buffer.
2135 If you have added new entries to a buffer that might themselves be targets,
2136 you need to clear the cache manually by pressing `C-0 C-c C-w' or, if you
2137 find that easier, `C-u C-u C-u C-c C-w'."
2142 (defcustom org-refile-use-outline-path nil
2143 "Non-nil means provide refile targets as paths.
2144 So a level 3 headline will be available as level1/level2/level3.
2146 When the value is `file', also include the file name (without directory)
2147 into the path. In this case, you can also stop the completion after
2148 the file name, to get entries inserted as top level in the file.
2150 When `full-file-path', include the full file path."
2153 (const :tag
"Not" nil
)
2154 (const :tag
"Yes" t
)
2155 (const :tag
"Start with file name" file
)
2156 (const :tag
"Start with full file path" full-file-path
)))
2158 (defcustom org-outline-path-complete-in-steps t
2159 "Non-nil means complete the outline path in hierarchical steps.
2160 When Org-mode uses the refile interface to select an outline path
2161 \(see variable `org-refile-use-outline-path'), the completion of
2162 the path can be done is a single go, or if can be done in steps down
2163 the headline hierarchy. Going in steps is probably the best if you
2164 do not use a special completion package like `ido' or `icicles'.
2165 However, when using these packages, going in one step can be very
2166 fast, while still showing the whole path to the entry."
2170 (defcustom org-refile-allow-creating-parent-nodes nil
2171 "Non-nil means allow to create new nodes as refile targets.
2172 New nodes are then created by adding \"/new node name\" to the completion
2173 of an existing node. When the value of this variable is `confirm',
2174 new node creation must be confirmed by the user (recommended)
2175 When nil, the completion must match an existing entry.
2177 Note that, if the new heading is not seen by the criteria
2178 listed in `org-refile-targets', multiple instances of the same
2179 heading would be created by trying again to file under the new
2183 (const :tag
"Never" nil
)
2184 (const :tag
"Always" t
)
2185 (const :tag
"Prompt for confirmation" confirm
)))
2187 (defcustom org-refile-active-region-within-subtree nil
2188 "Non-nil means also refile active region within a subtree.
2190 By default `org-refile' doesn't allow refiling regions if they
2191 don't contain a set of subtrees, but it might be convenient to
2192 do so sometimes: in that case, the first line of the region is
2193 converted to a headline before refiling."
2198 (defgroup org-todo nil
2199 "Options concerning TODO items in Org-mode."
2203 (defgroup org-progress nil
2204 "Options concerning Progress logging in Org-mode."
2208 (defvar org-todo-interpretation-widgets
2209 '((:tag
"Sequence (cycling hits every state)" sequence
)
2210 (:tag
"Type (cycling directly to DONE)" type
))
2211 "The available interpretation symbols for customizing `org-todo-keywords'.
2212 Interested libraries should add to this list.")
2214 (defcustom org-todo-keywords
'((sequence "TODO" "DONE"))
2215 "List of TODO entry keyword sequences and their interpretation.
2216 \\<org-mode-map>This is a list of sequences.
2218 Each sequence starts with a symbol, either `sequence' or `type',
2219 indicating if the keywords should be interpreted as a sequence of
2220 action steps, or as different types of TODO items. The first
2221 keywords are states requiring action - these states will select a headline
2222 for inclusion into the global TODO list Org-mode produces. If one of
2223 the \"keywords\" is the vertical bar, \"|\", the remaining keywords
2224 signify that no further action is necessary. If \"|\" is not found,
2225 the last keyword is treated as the only DONE state of the sequence.
2227 The command \\[org-todo] cycles an entry through these states, and one
2228 additional state where no keyword is present. For details about this
2229 cycling, see the manual.
2231 TODO keywords and interpretation can also be set on a per-file basis with
2232 the special #+SEQ_TODO and #+TYP_TODO lines.
2234 Each keyword can optionally specify a character for fast state selection
2235 \(in combination with the variable `org-use-fast-todo-selection')
2236 and specifiers for state change logging, using the same syntax that
2237 is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says that
2238 the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\"
2239 indicates to record a time stamp each time this state is selected.
2241 Each keyword may also specify if a timestamp or a note should be
2242 recorded when entering or leaving the state, by adding additional
2243 characters in the parenthesis after the keyword. This looks like this:
2244 \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to
2245 record only the time of the state change. With X and Y being either
2246 \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use
2247 Y when leaving the state if and only if the *target* state does not
2248 define X. You may omit any of the fast-selection key or X or /Y,
2249 so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid.
2251 For backward compatibility, this variable may also be just a list
2252 of keywords. In this case the interpretation (sequence or type) will be
2253 taken from the (otherwise obsolete) variable `org-todo-interpretation'."
2255 :group
'org-keywords
2257 (repeat :tag
"Old syntax, just keywords"
2258 (string :tag
"Keyword"))
2259 (repeat :tag
"New syntax"
2262 :tag
"Interpretation"
2263 ;;Quick and dirty way to see
2264 ;;`org-todo-interpretations'. This takes the
2265 ;;place of item arguments
2273 org-todo-interpretation-widgets
))
2276 (string :tag
"Keyword"))))))
2278 (defvar org-todo-keywords-1 nil
2279 "All TODO and DONE keywords active in a buffer.")
2280 (make-variable-buffer-local 'org-todo-keywords-1
)
2281 (defvar org-todo-keywords-for-agenda nil
)
2282 (defvar org-done-keywords-for-agenda nil
)
2283 (defvar org-drawers-for-agenda nil
)
2284 (defvar org-todo-keyword-alist-for-agenda nil
)
2285 (defvar org-tag-alist-for-agenda nil
)
2286 (defvar org-agenda-contributing-files nil
)
2287 (defvar org-not-done-keywords nil
)
2288 (make-variable-buffer-local 'org-not-done-keywords
)
2289 (defvar org-done-keywords nil
)
2290 (make-variable-buffer-local 'org-done-keywords
)
2291 (defvar org-todo-heads nil
)
2292 (make-variable-buffer-local 'org-todo-heads
)
2293 (defvar org-todo-sets nil
)
2294 (make-variable-buffer-local 'org-todo-sets
)
2295 (defvar org-todo-log-states nil
)
2296 (make-variable-buffer-local 'org-todo-log-states
)
2297 (defvar org-todo-kwd-alist nil
)
2298 (make-variable-buffer-local 'org-todo-kwd-alist
)
2299 (defvar org-todo-key-alist nil
)
2300 (make-variable-buffer-local 'org-todo-key-alist
)
2301 (defvar org-todo-key-trigger nil
)
2302 (make-variable-buffer-local 'org-todo-key-trigger
)
2304 (defcustom org-todo-interpretation
'sequence
2305 "Controls how TODO keywords are interpreted.
2306 This variable is in principle obsolete and is only used for
2307 backward compatibility, if the interpretation of todo keywords is
2308 not given already in `org-todo-keywords'. See that variable for
2311 :group
'org-keywords
2312 :type
'(choice (const sequence
)
2315 (defcustom org-use-fast-todo-selection t
2316 "Non-nil means use the fast todo selection scheme with C-c C-t.
2317 This variable describes if and under what circumstances the cycling
2318 mechanism for TODO keywords will be replaced by a single-key, direct
2321 When nil, fast selection is never used.
2323 When the symbol `prefix', it will be used when `org-todo' is called
2324 with a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and
2325 `C-u t' in an agenda buffer.
2327 When t, fast selection is used by default. In this case, the prefix
2328 argument forces cycling instead.
2330 In all cases, the special interface is only used if access keys have
2331 actually been assigned by the user, i.e. if keywords in the configuration
2332 are followed by a letter in parenthesis, like TODO(t)."
2335 (const :tag
"Never" nil
)
2336 (const :tag
"By default" t
)
2337 (const :tag
"Only with C-u C-c C-t" prefix
)))
2339 (defcustom org-provide-todo-statistics t
2340 "Non-nil means update todo statistics after insert and toggle.
2341 ALL-HEADLINES means update todo statistics by including headlines
2342 with no TODO keyword as well, counting them as not done.
2343 A list of TODO keywords means the same, but skip keywords that are
2346 When this is set, todo statistics is updated in the parent of the
2347 current entry each time a todo state is changed."
2350 (const :tag
"Yes, only for TODO entries" t
)
2351 (const :tag
"Yes, including all entries" 'all-headlines
)
2352 (repeat :tag
"Yes, for TODOs in this list"
2353 (string :tag
"TODO keyword"))
2354 (other :tag
"No TODO statistics" nil
)))
2356 (defcustom org-hierarchical-todo-statistics t
2357 "Non-nil means TODO statistics covers just direct children.
2358 When nil, all entries in the subtree are considered.
2359 This has only an effect if `org-provide-todo-statistics' is set.
2360 To set this to nil for only a single subtree, use a COOKIE_DATA
2361 property and include the word \"recursive\" into the value."
2365 (defcustom org-after-todo-state-change-hook nil
2366 "Hook which is run after the state of a TODO item was changed.
2367 The new state (a string with a TODO keyword, or nil) is available in the
2368 Lisp variable `org-state'."
2372 (defvar org-blocker-hook nil
2373 "Hook for functions that are allowed to block a state change.
2375 Functions in this hook should not modify the buffer.
2376 Each function gets as its single argument a property list,
2377 see `org-trigger-hook' for more information about this list.
2379 If any of the functions in this hook returns nil, the state change
2382 (defvar org-trigger-hook nil
2383 "Hook for functions that are triggered by a state change.
2385 Each function gets as its single argument a property list with at
2386 least the following elements:
2388 (:type type-of-change :position pos-at-entry-start
2389 :from old-state :to new-state)
2391 Depending on the type, more properties may be present.
2393 This mechanism is currently implemented for:
2397 :type todo-state-change
2398 :from previous state (keyword as a string), or nil, or a symbol
2399 'todo' or 'done', to indicate the general type of state.
2400 :to new state, like in :from")
2402 (defcustom org-enforce-todo-dependencies nil
2403 "Non-nil means undone TODO entries will block switching the parent to DONE.
2404 Also, if a parent has an :ORDERED: property, switching an entry to DONE will
2405 be blocked if any prior sibling is not yet done.
2406 Finally, if the parent is blocked because of ordered siblings of its own,
2407 the child will also be blocked."
2408 :set
(lambda (var val
)
2411 (add-hook 'org-blocker-hook
2412 'org-block-todo-from-children-or-siblings-or-parent
)
2413 (remove-hook 'org-blocker-hook
2414 'org-block-todo-from-children-or-siblings-or-parent
)))
2418 (defcustom org-enforce-todo-checkbox-dependencies nil
2419 "Non-nil means unchecked boxes will block switching the parent to DONE.
2420 When this is nil, checkboxes have no influence on switching TODO states.
2421 When non-nil, you first need to check off all check boxes before the TODO
2422 entry can be switched to DONE.
2423 This variable needs to be set before org.el is loaded, and you need to
2424 restart Emacs after a change to make the change effective. The only way
2425 to change is while Emacs is running is through the customize interface."
2426 :set
(lambda (var val
)
2429 (add-hook 'org-blocker-hook
2430 'org-block-todo-from-checkboxes
)
2431 (remove-hook 'org-blocker-hook
2432 'org-block-todo-from-checkboxes
)))
2436 (defcustom org-treat-insert-todo-heading-as-state-change nil
2437 "Non-nil means inserting a TODO heading is treated as state change.
2438 So when the command \\[org-insert-todo-heading] is used, state change
2439 logging will apply if appropriate. When nil, the new TODO item will
2440 be inserted directly, and no logging will take place."
2444 (defcustom org-treat-S-cursor-todo-selection-as-state-change t
2445 "Non-nil means switching TODO states with S-cursor counts as state change.
2446 This is the default behavior. However, setting this to nil allows a
2447 convenient way to select a TODO state and bypass any logging associated
2452 (defcustom org-todo-state-tags-triggers nil
2453 "Tag changes that should be triggered by TODO state changes.
2454 This is a list. Each entry is
2456 (state-change (tag . flag) .......)
2458 State-change can be a string with a state, and empty string to indicate the
2459 state that has no TODO keyword, or it can be one of the symbols `todo'
2460 or `done', meaning any not-done or done state, respectively."
2464 (cons (choice :tag
"When changing to"
2465 (const :tag
"Not-done state" todo
)
2466 (const :tag
"Done state" done
)
2467 (string :tag
"State"))
2469 (cons :tag
"Tag action"
2471 (choice (const :tag
"Add" t
) (const :tag
"Remove" nil
)))))))
2473 (defcustom org-log-done nil
2474 "Information to record when a task moves to the DONE state.
2476 Possible values are:
2478 nil Don't add anything, just change the keyword
2479 time Add a time stamp to the task
2480 note Prompt for a note and add it with template `org-log-note-headings'
2482 This option can also be set with on a per-file-basis with
2484 #+STARTUP: nologdone
2486 #+STARTUP: lognotedone
2488 You can have local logging settings for a subtree by setting the LOGGING
2489 property to one or more of these keywords."
2491 :group
'org-progress
2493 (const :tag
"No logging" nil
)
2494 (const :tag
"Record CLOSED timestamp" time
)
2495 (const :tag
"Record CLOSED timestamp with note." note
)))
2497 ;; Normalize old uses of org-log-done.
2499 ((eq org-log-done t
) (setq org-log-done
'time
))
2500 ((and (listp org-log-done
) (memq 'done org-log-done
))
2501 (setq org-log-done
'note
)))
2503 (defcustom org-log-reschedule nil
2504 "Information to record when the scheduling date of a tasks is modified.
2506 Possible values are:
2508 nil Don't add anything, just change the date
2509 time Add a time stamp to the task
2510 note Prompt for a note and add it with template `org-log-note-headings'
2512 This option can also be set with on a per-file-basis with
2514 #+STARTUP: nologreschedule
2515 #+STARTUP: logreschedule
2516 #+STARTUP: lognotereschedule"
2518 :group
'org-progress
2520 (const :tag
"No logging" nil
)
2521 (const :tag
"Record timestamp" time
)
2522 (const :tag
"Record timestamp with note." note
)))
2524 (defcustom org-log-redeadline nil
2525 "Information to record when the deadline date of a tasks is modified.
2527 Possible values are:
2529 nil Don't add anything, just change the date
2530 time Add a time stamp to the task
2531 note Prompt for a note and add it with template `org-log-note-headings'
2533 This option can also be set with on a per-file-basis with
2535 #+STARTUP: nologredeadline
2536 #+STARTUP: logredeadline
2537 #+STARTUP: lognoteredeadline
2539 You can have local logging settings for a subtree by setting the LOGGING
2540 property to one or more of these keywords."
2542 :group
'org-progress
2544 (const :tag
"No logging" nil
)
2545 (const :tag
"Record timestamp" time
)
2546 (const :tag
"Record timestamp with note." note
)))
2548 (defcustom org-log-note-clock-out nil
2549 "Non-nil means record a note when clocking out of an item.
2550 This can also be configured on a per-file basis by adding one of
2551 the following lines anywhere in the buffer:
2553 #+STARTUP: lognoteclock-out
2554 #+STARTUP: nolognoteclock-out"
2556 :group
'org-progress
2559 (defcustom org-log-done-with-time t
2560 "Non-nil means the CLOSED time stamp will contain date and time.
2561 When nil, only the date will be recorded."
2562 :group
'org-progress
2565 (defcustom org-log-note-headings
2566 '((done .
"CLOSING NOTE %t")
2567 (state .
"State %-12s from %-12S %t")
2568 (note .
"Note taken on %t")
2569 (reschedule .
"Rescheduled from %S on %t")
2570 (delschedule .
"Not scheduled, was %S on %t")
2571 (redeadline .
"New deadline from %S on %t")
2572 (deldeadline .
"Removed deadline, was %S on %t")
2573 (refile .
"Refiled on %t")
2575 "Headings for notes added to entries.
2576 The value is an alist, with the car being a symbol indicating the note
2577 context, and the cdr is the heading to be used. The heading may also be the
2579 %t in the heading will be replaced by a time stamp.
2580 %T will be an active time stamp instead the default inactive one
2581 %d will be replaced by a short-format time stamp.
2582 %D will be replaced by an active short-format time stamp.
2583 %s will be replaced by the new TODO state, in double quotes.
2584 %S will be replaced by the old TODO state, in double quotes.
2585 %u will be replaced by the user name.
2586 %U will be replaced by the full user name.
2588 In fact, it is not a good idea to change the `state' entry, because
2589 agenda log mode depends on the format of these entries."
2591 :group
'org-progress
2592 :type
'(list :greedy t
2593 (cons (const :tag
"Heading when closing an item" done
) string
)
2595 "Heading when changing todo state (todo sequence only)"
2597 (cons (const :tag
"Heading when just taking a note" note
) string
)
2598 (cons (const :tag
"Heading when clocking out" clock-out
) string
)
2599 (cons (const :tag
"Heading when an item is no longer scheduled" delschedule
) string
)
2600 (cons (const :tag
"Heading when rescheduling" reschedule
) string
)
2601 (cons (const :tag
"Heading when changing deadline" redeadline
) string
)
2602 (cons (const :tag
"Heading when deleting a deadline" deldeadline
) string
)
2603 (cons (const :tag
"Heading when refiling" refile
) string
)))
2605 (unless (assq 'note org-log-note-headings
)
2606 (push '(note .
"%t") org-log-note-headings
))
2608 (defcustom org-log-into-drawer nil
2609 "Non-nil means insert state change notes and time stamps into a drawer.
2610 When nil, state changes notes will be inserted after the headline and
2611 any scheduling and clock lines, but not inside a drawer.
2613 The value of this variable should be the name of the drawer to use.
2614 LOGBOOK is proposed as the default drawer for this purpose, you can
2615 also set this to a string to define the drawer of your choice.
2617 A value of t is also allowed, representing \"LOGBOOK\".
2619 A value of t or nil can also be set with on a per-file-basis with
2621 #+STARTUP: logdrawer
2622 #+STARTUP: nologdrawer
2624 If this variable is set, `org-log-state-notes-insert-after-drawers'
2627 You can set the property LOG_INTO_DRAWER to overrule this setting for
2630 :group
'org-progress
2632 (const :tag
"Not into a drawer" nil
)
2633 (const :tag
"LOGBOOK" t
)
2634 (string :tag
"Other")))
2636 (if (fboundp 'defvaralias
)
2637 (defvaralias 'org-log-state-notes-into-drawer
'org-log-into-drawer
))
2639 (defun org-log-into-drawer ()
2640 "Return the value of `org-log-into-drawer', but let properties overrule.
2641 If the current entry has or inherits a LOG_INTO_DRAWER property, it will be
2642 used instead of the default value."
2643 (let ((p (org-entry-get nil
"LOG_INTO_DRAWER" 'inherit t
)))
2645 ((not p
) org-log-into-drawer
)
2646 ((equal p
"nil") nil
)
2647 ((equal p
"t") "LOGBOOK")
2650 (defcustom org-log-state-notes-insert-after-drawers nil
2651 "Non-nil means insert state change notes after any drawers in entry.
2652 Only the drawers that *immediately* follow the headline and the
2653 deadline/scheduled line are skipped.
2654 When nil, insert notes right after the heading and perhaps the line
2655 with deadline/scheduling if present.
2657 This variable will have no effect if `org-log-into-drawer' is
2660 :group
'org-progress
2663 (defcustom org-log-states-order-reversed t
2664 "Non-nil means the latest state note will be directly after heading.
2665 When nil, the state change notes will be ordered according to time.
2667 This option can also be set with on a per-file-basis with
2669 #+STARTUP: logstatesreversed
2670 #+STARTUP: nologstatesreversed"
2672 :group
'org-progress
2675 (defcustom org-todo-repeat-to-state nil
2676 "The TODO state to which a repeater should return the repeating task.
2677 By default this is the first task in a TODO sequence, or the previous state
2678 in a TODO_TYP set. But you can specify another task here.
2679 alternatively, set the :REPEAT_TO_STATE: property of the entry."
2682 :type
'(choice (const :tag
"Head of sequence" nil
)
2683 (string :tag
"Specific state")))
2685 (defcustom org-log-repeat
'time
2686 "Non-nil means record moving through the DONE state when triggering repeat.
2687 An auto-repeating task is immediately switched back to TODO when
2688 marked DONE. If you are not logging state changes (by adding \"@\"
2689 or \"!\" to the TODO keyword definition), or set `org-log-done' to
2690 record a closing note, there will be no record of the task moving
2691 through DONE. This variable forces taking a note anyway.
2693 nil Don't force a record
2694 time Record a time stamp
2695 note Prompt for a note and add it with template `org-log-note-headings'
2697 This option can also be set with on a per-file-basis with
2699 #+STARTUP: nologrepeat
2700 #+STARTUP: logrepeat
2701 #+STARTUP: lognoterepeat
2703 You can have local logging settings for a subtree by setting the LOGGING
2704 property to one or more of these keywords."
2706 :group
'org-progress
2708 (const :tag
"Don't force a record" nil
)
2709 (const :tag
"Force recording the DONE state" time
)
2710 (const :tag
"Force recording a note with the DONE state" note
)))
2713 (defgroup org-priorities nil
2714 "Priorities in Org-mode."
2715 :tag
"Org Priorities"
2718 (defcustom org-enable-priority-commands t
2719 "Non-nil means priority commands are active.
2720 When nil, these commands will be disabled, so that you never accidentally
2722 :group
'org-priorities
2725 (defcustom org-highest-priority ?A
2726 "The highest priority of TODO items. A character like ?A, ?B etc.
2727 Must have a smaller ASCII number than `org-lowest-priority'."
2728 :group
'org-priorities
2731 (defcustom org-lowest-priority ?C
2732 "The lowest priority of TODO items. A character like ?A, ?B etc.
2733 Must have a larger ASCII number than `org-highest-priority'."
2734 :group
'org-priorities
2737 (defcustom org-default-priority ?B
2738 "The default priority of TODO items.
2739 This is the priority an item gets if no explicit priority is given.
2740 When starting to cycle on an empty priority the first step in the cycle
2741 depends on `org-priority-start-cycle-with-default'. The resulting first
2742 step priority must not exceed the range from `org-highest-priority' to
2743 `org-lowest-priority' which means that `org-default-priority' has to be
2744 in this range exclusive or inclusive the range boundaries. Else the
2745 first step refuses to set the default and the second will fall back
2746 to (depending on the command used) the highest or lowest priority."
2747 :group
'org-priorities
2750 (defcustom org-priority-start-cycle-with-default t
2751 "Non-nil means start with default priority when starting to cycle.
2752 When this is nil, the first step in the cycle will be (depending on the
2753 command used) one higher or lower than the default priority.
2754 See also `org-default-priority'."
2755 :group
'org-priorities
2758 (defcustom org-get-priority-function nil
2759 "Function to extract the priority from a string.
2760 The string is normally the headline. If this is nil Org computes the
2761 priority from the priority cookie like [#A] in the headline. It returns
2762 an integer, increasing by 1000 for each priority level.
2763 The user can set a different function here, which should take a string
2764 as an argument and return the numeric priority."
2765 :group
'org-priorities
2769 (defgroup org-time nil
2770 "Options concerning time stamps and deadlines in Org-mode."
2774 (defcustom org-insert-labeled-timestamps-at-point nil
2775 "Non-nil means SCHEDULED and DEADLINE timestamps are inserted at point.
2776 When nil, these labeled time stamps are forces into the second line of an
2777 entry, just after the headline. When scheduling from the global TODO list,
2778 the time stamp will always be forced into the second line."
2782 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
2783 "Formats for `format-time-string' which are used for time stamps.
2784 It is not recommended to change this constant.")
2786 (defcustom org-time-stamp-rounding-minutes
'(0 5)
2787 "Number of minutes to round time stamps to.
2788 These are two values, the first applies when first creating a time stamp.
2789 The second applies when changing it with the commands `S-up' and `S-down'.
2790 When changing the time stamp, this means that it will change in steps
2791 of N minutes, as given by the second value.
2793 When a setting is 0 or 1, insert the time unmodified. Useful rounding
2794 numbers should be factors of 60, so for example 5, 10, 15.
2796 When this is larger than 1, you can still force an exact time stamp by using
2797 a double prefix argument to a time stamp command like `C-c .' or `C-c !',
2798 and by using a prefix arg to `S-up/down' to specify the exact number
2799 of minutes to shift."
2801 :get
#'(lambda (var) ; Make sure both elements are there
2802 (if (integerp (default-value var
))
2803 (list (default-value var
) 5)
2804 (default-value var
)))
2806 (integer :tag
"when inserting times")
2807 (integer :tag
"when modifying times")))
2809 ;; Normalize old customizations of this variable.
2810 (when (integerp org-time-stamp-rounding-minutes
)
2811 (setq org-time-stamp-rounding-minutes
2812 (list org-time-stamp-rounding-minutes
2813 org-time-stamp-rounding-minutes
)))
2815 (defcustom org-display-custom-times nil
2816 "Non-nil means overlay custom formats over all time stamps.
2817 The formats are defined through the variable `org-time-stamp-custom-formats'.
2818 To turn this on on a per-file basis, insert anywhere in the file:
2819 #+STARTUP: customtime"
2823 (make-variable-buffer-local 'org-display-custom-times
)
2825 (defcustom org-time-stamp-custom-formats
2826 '("<%m/%d/%y %a>" .
"<%m/%d/%y %a %H:%M>") ; american
2827 "Custom formats for time stamps. See `format-time-string' for the syntax.
2828 These are overlaid over the default ISO format if the variable
2829 `org-display-custom-times' is set. Time like %H:%M should be at the
2830 end of the second format. The custom formats are also honored by export
2831 commands, if custom time display is turned on at the time of export."
2835 (defun org-time-stamp-format (&optional long inactive
)
2836 "Get the right format for a time string."
2837 (let ((f (if long
(cdr org-time-stamp-formats
)
2838 (car org-time-stamp-formats
))))
2840 (concat "[" (substring f
1 -
1) "]")
2843 (defcustom org-time-clocksum-format
2844 '(:days
"%dd " :hours
"%d" :require-hours t
:minutes
":%02d" :require-minutes t
)
2845 "The format string used when creating CLOCKSUM lines.
2846 This is also used when Org mode generates a time duration.
2848 The value can be a single format string containing two
2849 %-sequences, which will be filled with the number of hours and
2850 minutes in that order.
2852 Alternatively, the value can be a plist associating any of the
2853 keys :years, :months, :weeks, :days, :hours or :minutes with
2854 format strings. The time duration is formatted using only the
2855 time components that are needed and concatenating the results.
2856 If a time unit in absent, it falls back to the next smallest
2859 The keys :require-years, :require-months, :require-days,
2860 :require-weeks, :require-hours, :require-minutes are also
2861 meaningful. A non-nil value for these keys indicates that the
2862 corresponding time component should always be included, even if
2868 \(:days \"%dd\" :hours \"%d\" :require-hours t :minutes \":%02d\"
2871 means durations longer than a day will be expressed in days,
2872 hours and minutes, and durations less than a day will always be
2873 expressed in hours and minutes (even for durations less than an
2878 \(:days \"%dd\" :minutes \"%dm\")
2880 means durations longer than a day will be expressed in days and
2881 minutes, and durations less than a day will be expressed entirely
2882 in minutes (even for durations longer than an hour)."
2886 :type
'(choice (string :tag
"Format string")
2888 (group :inline t
(const :tag
"Years" :years
)
2889 (string :tag
"Format string"))
2891 (const :tag
"Always show years" :require-years
)
2893 (group :inline t
(const :tag
"Months" :months
)
2894 (string :tag
"Format string"))
2896 (const :tag
"Always show months" :require-months
)
2898 (group :inline t
(const :tag
"Weeks" :weeks
)
2899 (string :tag
"Format string"))
2901 (const :tag
"Always show weeks" :require-weeks
)
2903 (group :inline t
(const :tag
"Days" :days
)
2904 (string :tag
"Format string"))
2906 (const :tag
"Always show days" :require-days
)
2908 (group :inline t
(const :tag
"Hours" :hours
)
2909 (string :tag
"Format string"))
2911 (const :tag
"Always show hours" :require-hours
)
2913 (group :inline t
(const :tag
"Minutes" :minutes
)
2914 (string :tag
"Format string"))
2916 (const :tag
"Always show minutes" :require-minutes
)
2919 (defcustom org-time-clocksum-use-fractional nil
2920 "When non-nil, \\[org-clock-display] uses fractional times.
2921 See `org-time-clocksum-format' for more on time clock formats."
2927 (defcustom org-time-clocksum-use-effort-durations t
2928 "When non-nil, \\[org-clock-display] uses effort durations.
2929 E.g. by default, one day is considered to be a 8 hours effort,
2930 so a task that has been clocked for 16 hours will be displayed
2931 as during 2 days in the clock display or in the clocktable.
2933 See `org-effort-durations' on how to set effort durations
2934 and `org-time-clocksum-format' for more on time clock formats."
2940 (defcustom org-time-clocksum-fractional-format
"%.2f"
2941 "The format string used when creating CLOCKSUM lines,
2942 or when Org mode generates a time duration, if
2943 `org-time-clocksum-use-fractional' is enabled.
2945 The value can be a single format string containing one
2946 %-sequence, which will be filled with the number of hours as
2949 Alternatively, the value can be a plist associating any of the
2950 keys :years, :months, :weeks, :days, :hours or :minutes with
2951 a format string. The time duration is formatted using the
2952 largest time unit which gives a non-zero integer part. If all
2953 specified formats have zero integer part, the smallest time unit
2956 :type
'(choice (string :tag
"Format string")
2957 (set (group :inline t
(const :tag
"Years" :years
)
2958 (string :tag
"Format string"))
2959 (group :inline t
(const :tag
"Months" :months
)
2960 (string :tag
"Format string"))
2961 (group :inline t
(const :tag
"Weeks" :weeks
)
2962 (string :tag
"Format string"))
2963 (group :inline t
(const :tag
"Days" :days
)
2964 (string :tag
"Format string"))
2965 (group :inline t
(const :tag
"Hours" :hours
)
2966 (string :tag
"Format string"))
2967 (group :inline t
(const :tag
"Minutes" :minutes
)
2968 (string :tag
"Format string")))))
2970 (defcustom org-deadline-warning-days
14
2971 "Number of days before expiration during which a deadline becomes active.
2972 This variable governs the display in sparse trees and in the agenda.
2973 When 0 or negative, it means use this number (the absolute value of it)
2974 even if a deadline has a different individual lead time specified.
2976 Custom commands can set this variable in the options section."
2978 :group
'org-agenda-daily
/weekly
2981 (defcustom org-scheduled-delay-days
0
2982 "Number of days before a scheduled item becomes active.
2983 This variable governs the display in sparse trees and in the agenda.
2984 The default value (i.e. 0) means: don't delay scheduled item.
2985 When negative, it means use this number (the absolute value of it)
2986 even if a scheduled item has a different individual delay time
2989 Custom commands can set this variable in the options section."
2991 :group
'org-agenda-daily
/weekly
2995 (defcustom org-read-date-prefer-future t
2996 "Non-nil means assume future for incomplete date input from user.
2997 This affects the following situations:
2998 1. The user gives a month but not a year.
2999 For example, if it is April and you enter \"feb 2\", this will be read
3000 as Feb 2, *next* year. \"May 5\", however, will be this year.
3001 2. The user gives a day, but no month.
3002 For example, if today is the 15th, and you enter \"3\", Org-mode will
3003 read this as the third of *next* month. However, if you enter \"17\",
3004 it will be considered as *this* month.
3006 If you set this variable to the symbol `time', then also the following
3009 3. If the user gives a time.
3010 If the time is before now, it will be interpreted as tomorrow.
3012 Currently none of this works for ISO week specifications.
3014 When this option is nil, the current day, month and year will always be
3017 See also `org-agenda-jump-prefer-future'."
3020 (const :tag
"Never" nil
)
3021 (const :tag
"Check month and day" t
)
3022 (const :tag
"Check month, day, and time" time
)))
3024 (defcustom org-agenda-jump-prefer-future
'org-read-date-prefer-future
3025 "Should the agenda jump command prefer the future for incomplete dates?
3026 The default is to do the same as configured in `org-read-date-prefer-future'.
3027 But you can also set a deviating value here.
3028 This may t or nil, or the symbol `org-read-date-prefer-future'."
3033 (const :tag
"Use org-read-date-prefer-future"
3034 org-read-date-prefer-future
)
3035 (const :tag
"Never" nil
)
3036 (const :tag
"Always" t
)))
3038 (defcustom org-read-date-force-compatible-dates t
3039 "Should date/time prompt force dates that are guaranteed to work in Emacs?
3041 Depending on the system Emacs is running on, certain dates cannot
3042 be represented with the type used internally to represent time.
3043 Dates between 1970-1-1 and 2038-1-1 can always be represented
3044 correctly. Some systems allow for earlier dates, some for later,
3045 some for both. One way to find out it to insert any date into an
3046 Org buffer, putting the cursor on the year and hitting S-up and
3047 S-down to test the range.
3049 When this variable is set to t, the date/time prompt will not let
3050 you specify dates outside the 1970-2037 range, so it is certain that
3051 these dates will work in whatever version of Emacs you are
3052 running, and also that you can move a file from one Emacs implementation
3053 to another. WHenever Org is forcing the year for you, it will display
3056 When this variable is nil, Org will check if the date is
3057 representable in the specific Emacs implementation you are using.
3058 If not, it will force a year, usually the current year, and beep
3059 to remind you. Currently this setting is not recommended because
3060 the likelihood that you will open your Org files in an Emacs that
3061 has limited date range is not negligible.
3063 A workaround for this problem is to use diary sexp dates for time
3064 stamps outside of this range."
3069 (defcustom org-read-date-display-live t
3070 "Non-nil means display current interpretation of date prompt live.
3071 This display will be in an overlay, in the minibuffer."
3075 (defcustom org-read-date-popup-calendar t
3076 "Non-nil means pop up a calendar when prompting for a date.
3077 In the calendar, the date can be selected with mouse-1. However, the
3078 minibuffer will also be active, and you can simply enter the date as well.
3079 When nil, only the minibuffer will be available."
3082 (if (fboundp 'defvaralias
)
3083 (defvaralias 'org-popup-calendar-for-date-prompt
3084 'org-read-date-popup-calendar
))
3086 (make-obsolete-variable
3087 'org-read-date-minibuffer-setup-hook
3088 "Set `org-read-date-minibuffer-local-map' instead." "24.3")
3089 (defcustom org-read-date-minibuffer-setup-hook nil
3090 "Hook to be used to set up keys for the date/time interface.
3091 Add key definitions to `minibuffer-local-map', which will be a
3094 WARNING: This option is obsolete, you should use
3095 `org-read-date-minibuffer-local-map' to set up keys."
3099 (defcustom org-extend-today-until
0
3100 "The hour when your day really ends. Must be an integer.
3101 This has influence for the following applications:
3102 - When switching the agenda to \"today\". It it is still earlier than
3103 the time given here, the day recognized as TODAY is actually yesterday.
3104 - When a date is read from the user and it is still before the time given
3105 here, the current date and time will be assumed to be yesterday, 23:59.
3106 Also, timestamps inserted in capture templates follow this rule.
3108 IMPORTANT: This is a feature whose implementation is and likely will
3109 remain incomplete. Really, it is only here because past midnight seems to
3110 be the favorite working time of John Wiegley :-)"
3114 (defcustom org-use-effective-time nil
3115 "If non-nil, consider `org-extend-today-until' when creating timestamps.
3116 For example, if `org-extend-today-until' is 8, and it's 4am, then the
3117 \"effective time\" of any timestamps between midnight and 8am will be
3118 23:59 of the previous day."
3123 (defcustom org-use-last-clock-out-time-as-effective-time nil
3124 "When non-nil, use the last clock out time for `org-todo'.
3125 Note that this option has precedence over the combined use of
3126 `org-use-effective-time' and `org-extend-today-until'."
3131 (defcustom org-edit-timestamp-down-means-later nil
3132 "Non-nil means S-down will increase the time in a time stamp.
3133 When nil, S-up will increase."
3137 (defcustom org-calendar-follow-timestamp-change t
3138 "Non-nil means make the calendar window follow timestamp changes.
3139 When a timestamp is modified and the calendar window is visible, it will be
3140 moved to the new date."
3144 (defgroup org-tags nil
3145 "Options concerning tags in Org-mode."
3149 (defcustom org-tag-alist nil
3150 "List of tags allowed in Org-mode files.
3151 When this list is nil, Org-mode will base TAG input on what is already in the
3153 The value of this variable is an alist, the car of each entry must be a
3154 keyword as a string, the cdr may be a character that is used to select
3155 that tag through the fast-tag-selection interface.
3156 See the manual for details."
3160 (cons (string :tag
"Tag name")
3161 (character :tag
"Access char"))
3162 (list :tag
"Start radio group"
3164 (option (string :tag
"Group description")))
3165 (list :tag
"End radio group"
3167 (option (string :tag
"Group description")))
3168 (const :tag
"New line" (:newline
)))))
3170 (defcustom org-tag-persistent-alist nil
3171 "List of tags that will always appear in all Org-mode files.
3172 This is in addition to any in buffer settings or customizations
3174 When this list is nil, Org-mode will base TAG input on `org-tag-alist'.
3175 The value of this variable is an alist, the car of each entry must be a
3176 keyword as a string, the cdr may be a character that is used to select
3177 that tag through the fast-tag-selection interface.
3178 See the manual for details.
3179 To disable these tags on a per-file basis, insert anywhere in the file:
3184 (cons (string :tag
"Tag name")
3185 (character :tag
"Access char"))
3186 (const :tag
"Start radio group" (:startgroup
))
3187 (const :tag
"End radio group" (:endgroup
))
3188 (const :tag
"New line" (:newline
)))))
3190 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
3191 "If non-nil, always offer completion for all tags of all agenda files.
3192 Instead of customizing this variable directly, you might want to
3193 set it locally for capture buffers, because there no list of
3194 tags in that file can be created dynamically (there are none).
3196 (add-hook 'org-capture-mode-hook
3198 (set (make-local-variable
3199 'org-complete-tags-always-offer-all-agenda-tags)
3205 (defvar org-file-tags nil
3206 "List of tags that can be inherited by all entries in the file.
3207 The tags will be inherited if the variable `org-use-tag-inheritance'
3208 says they should be.
3209 This variable is populated from #+FILETAGS lines.")
3211 (defcustom org-use-fast-tag-selection
'auto
3212 "Non-nil means use fast tag selection scheme.
3213 This is a special interface to select and deselect tags with single keys.
3214 When nil, fast selection is never used.
3215 When the symbol `auto', fast selection is used if and only if selection
3216 characters for tags have been configured, either through the variable
3217 `org-tag-alist' or through a #+TAGS line in the buffer.
3218 When t, fast selection is always used and selection keys are assigned
3219 automatically if necessary."
3222 (const :tag
"Always" t
)
3223 (const :tag
"Never" nil
)
3224 (const :tag
"When selection characters are configured" 'auto
)))
3226 (defcustom org-fast-tag-selection-single-key nil
3227 "Non-nil means fast tag selection exits after first change.
3228 When nil, you have to press RET to exit it.
3229 During fast tag selection, you can toggle this flag with `C-c'.
3230 This variable can also have the value `expert'. In this case, the window
3231 displaying the tags menu is not even shown, until you press C-c again."
3234 (const :tag
"No" nil
)
3235 (const :tag
"Yes" t
)
3236 (const :tag
"Expert" expert
)))
3238 (defvar org-fast-tag-selection-include-todo nil
3239 "Non-nil means fast tags selection interface will also offer TODO states.
3240 This is an undocumented feature, you should not rely on it.")
3242 (defcustom org-tags-column
(if (featurep 'xemacs
) -
76 -
77)
3243 "The column to which tags should be indented in a headline.
3244 If this number is positive, it specifies the column. If it is negative,
3245 it means that the tags should be flushright to that column. For example,
3246 -80 works well for a normal 80 character screen.
3247 When 0, place tags directly after headline text, with only one space in
3252 (defcustom org-auto-align-tags t
3253 "Non-nil keeps tags aligned when modifying headlines.
3254 Some operations (i.e. demoting) change the length of a headline and
3255 therefore shift the tags around. With this option turned on, after
3256 each such operation the tags are again aligned to `org-tags-column'."
3260 (defcustom org-use-tag-inheritance t
3261 "Non-nil means tags in levels apply also for sublevels.
3262 When nil, only the tags directly given in a specific line apply there.
3263 This may also be a list of tags that should be inherited, or a regexp that
3264 matches tags that should be inherited. Additional control is possible
3265 with the variable `org-tags-exclude-from-inheritance' which gives an
3266 explicit list of tags to be excluded from inheritance, even if the value of
3267 `org-use-tag-inheritance' would select it for inheritance.
3269 If this option is t, a match early-on in a tree can lead to a large
3270 number of matches in the subtree when constructing the agenda or creating
3271 a sparse tree. If you only want to see the first match in a tree during
3272 a search, check out the variable `org-tags-match-list-sublevels'."
3275 (const :tag
"Not" nil
)
3276 (const :tag
"Always" t
)
3277 (repeat :tag
"Specific tags" (string :tag
"Tag"))
3278 (regexp :tag
"Tags matched by regexp")))
3280 (defcustom org-tags-exclude-from-inheritance nil
3281 "List of tags that should never be inherited.
3282 This is a way to exclude a few tags from inheritance. For way to do
3283 the opposite, to actively allow inheritance for selected tags,
3284 see the variable `org-use-tag-inheritance'."
3286 :type
'(repeat (string :tag
"Tag")))
3288 (defun org-tag-inherit-p (tag)
3289 "Check if TAG is one that should be inherited."
3291 ((member tag org-tags-exclude-from-inheritance
) nil
)
3292 ((eq org-use-tag-inheritance t
) t
)
3293 ((not org-use-tag-inheritance
) nil
)
3294 ((stringp org-use-tag-inheritance
)
3295 (string-match org-use-tag-inheritance tag
))
3296 ((listp org-use-tag-inheritance
)
3297 (member tag org-use-tag-inheritance
))
3298 (t (error "Invalid setting of `org-use-tag-inheritance'"))))
3300 (defcustom org-tags-match-list-sublevels t
3301 "Non-nil means list also sublevels of headlines matching a search.
3302 This variable applies to tags/property searches, and also to stuck
3303 projects because this search is based on a tags match as well.
3305 When set to the symbol `indented', sublevels are indented with
3308 Because of tag inheritance (see variable `org-use-tag-inheritance'),
3309 the sublevels of a headline matching a tag search often also match
3310 the same search. Listing all of them can create very long lists.
3311 Setting this variable to nil causes subtrees of a match to be skipped.
3313 This variable is semi-obsolete and probably should always be true. It
3314 is better to limit inheritance to certain tags using the variables
3315 `org-use-tag-inheritance' and `org-tags-exclude-from-inheritance'."
3318 (const :tag
"No, don't list them" nil
)
3319 (const :tag
"Yes, do list them" t
)
3320 (const :tag
"List them, indented with leading dots" indented
)))
3322 (defcustom org-tags-sort-function nil
3323 "When set, tags are sorted using this function as a comparator."
3326 (const :tag
"No sorting" nil
)
3327 (const :tag
"Alphabetical" string
<)
3328 (const :tag
"Reverse alphabetical" string
>)
3329 (function :tag
"Custom function" nil
)))
3331 (defvar org-tags-history nil
3332 "History of minibuffer reads for tags.")
3333 (defvar org-last-tags-completion-table nil
3334 "The last used completion table for tags.")
3335 (defvar org-after-tags-change-hook nil
3336 "Hook that is run after the tags in a line have changed.")
3338 (defgroup org-properties nil
3339 "Options concerning properties in Org-mode."
3340 :tag
"Org Properties"
3343 (defcustom org-property-format
"%-10s %s"
3344 "How property key/value pairs should be formatted by `indent-line'.
3345 When `indent-line' hits a property definition, it will format the line
3346 according to this format, mainly to make sure that the values are
3347 lined-up with respect to each other."
3348 :group
'org-properties
3351 (defcustom org-properties-postprocess-alist nil
3352 "Alist of properties and functions to adjust inserted values.
3353 Elements of this alist must be of the form
3355 ([string] [function])
3357 where [string] must be a property name and [function] must be a
3358 lambda expression: this lambda expression must take one argument,
3359 the value to adjust, and return the new value as a string.
3361 For example, this element will allow the property \"Remaining\"
3362 to be updated wrt the relation between the \"Effort\" property
3363 and the clock summary:
3365 ((\"Remaining\" (lambda(value)
3366 (let ((clocksum (org-clock-sum-current-item))
3367 (effort (org-duration-string-to-minutes
3368 (org-entry-get (point) \"Effort\"))))
3369 (org-minutes-to-clocksum-string (- effort clocksum))))))"
3370 :group
'org-properties
3372 :type
'(alist :key-type
(string :tag
"Property")
3373 :value-type
(function :tag
"Function")))
3375 (defcustom org-use-property-inheritance nil
3376 "Non-nil means properties apply also for sublevels.
3378 This setting is chiefly used during property searches. Turning it on can
3379 cause significant overhead when doing a search, which is why it is not
3382 When nil, only the properties directly given in the current entry count.
3383 When t, every property is inherited. The value may also be a list of
3384 properties that should have inheritance, or a regular expression matching
3385 properties that should be inherited.
3387 However, note that some special properties use inheritance under special
3388 circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS,
3389 and the properties ending in \"_ALL\" when they are used as descriptor
3390 for valid values of a property.
3392 Note for programmers:
3393 When querying an entry with `org-entry-get', you can control if inheritance
3394 should be used. By default, `org-entry-get' looks only at the local
3395 properties. You can request inheritance by setting the inherit argument
3396 to t (to force inheritance) or to `selective' (to respect the setting
3398 :group
'org-properties
3400 (const :tag
"Not" nil
)
3401 (const :tag
"Always" t
)
3402 (repeat :tag
"Specific properties" (string :tag
"Property"))
3403 (regexp :tag
"Properties matched by regexp")))
3405 (defun org-property-inherit-p (property)
3406 "Check if PROPERTY is one that should be inherited."
3408 ((eq org-use-property-inheritance t
) t
)
3409 ((not org-use-property-inheritance
) nil
)
3410 ((stringp org-use-property-inheritance
)
3411 (string-match org-use-property-inheritance property
))
3412 ((listp org-use-property-inheritance
)
3413 (member property org-use-property-inheritance
))
3414 (t (error "Invalid setting of `org-use-property-inheritance'"))))
3416 (defcustom org-columns-default-format
"%25ITEM %TODO %3PRIORITY %TAGS"
3417 "The default column format, if no other format has been defined.
3418 This variable can be set on the per-file basis by inserting a line
3420 #+COLUMNS: %25ITEM ....."
3421 :group
'org-properties
3424 (defcustom org-columns-ellipses
".."
3425 "The ellipses to be used when a field in column view is truncated.
3426 When this is the empty string, as many characters as possible are shown,
3427 but then there will be no visual indication that the field has been truncated.
3428 When this is a string of length N, the last N characters of a truncated
3429 field are replaced by this string. If the column is narrower than the
3430 ellipses string, only part of the ellipses string will be shown."
3431 :group
'org-properties
3434 (defcustom org-columns-modify-value-for-display-function nil
3435 "Function that modifies values for display in column view.
3436 For example, it can be used to cut out a certain part from a time stamp.
3437 The function must take 2 arguments:
3439 column-title The title of the column (*not* the property name)
3440 value The value that should be modified.
3442 The function should return the value that should be displayed,
3443 or nil if the normal value should be used."
3444 :group
'org-properties
3447 (defcustom org-effort-property
"Effort"
3448 "The property that is being used to keep track of effort estimates.
3449 Effort estimates given in this property need to have the format H:MM."
3450 :group
'org-properties
3451 :group
'org-progress
3452 :type
'(string :tag
"Property"))
3454 (defconst org-global-properties-fixed
3455 '(("VISIBILITY_ALL" .
"folded children content all")
3456 ("CLOCK_MODELINE_TOTAL_ALL" .
"current today repeat all auto"))
3457 "List of property/value pairs that can be inherited by any entry.
3459 These are fixed values, for the preset properties. The user variable
3460 that can be used to add to this list is `org-global-properties'.
3462 The entries in this list are cons cells where the car is a property
3463 name and cdr is a string with the value. If the value represents
3464 multiple items like an \"_ALL\" property, separate the items by
3467 (defcustom org-global-properties nil
3468 "List of property/value pairs that can be inherited by any entry.
3470 This list will be combined with the constant `org-global-properties-fixed'.
3472 The entries in this list are cons cells where the car is a property
3473 name and cdr is a string with the value.
3475 You can set buffer-local values for the same purpose in the variable
3476 `org-file-properties' this by adding lines like
3478 #+PROPERTY: NAME VALUE"
3479 :group
'org-properties
3481 (cons (string :tag
"Property")
3482 (string :tag
"Value"))))
3484 (defvar org-file-properties nil
3485 "List of property/value pairs that can be inherited by any entry.
3486 Valid for the current buffer.
3487 This variable is populated from #+PROPERTY lines.")
3488 (make-variable-buffer-local 'org-file-properties
)
3490 (defgroup org-agenda nil
3491 "Options concerning agenda views in Org-mode."
3495 (defvar org-category nil
3496 "Variable used by org files to set a category for agenda display.
3497 Such files should use a file variable to set it, for example
3499 # -*- mode: org; org-category: \"ELisp\"
3501 or contain a special line
3505 If the file does not specify a category, then file's base name
3507 (make-variable-buffer-local 'org-category
)
3508 (put 'org-category
'safe-local-variable
#'(lambda (x) (or (symbolp x
) (stringp x
))))
3510 (defcustom org-agenda-files nil
3511 "The files to be used for agenda display.
3512 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
3513 \\[org-remove-file]. You can also use customize to edit the list.
3515 If an entry is a directory, all files in that directory that are matched by
3516 `org-agenda-file-regexp' will be part of the file list.
3518 If the value of the variable is not a list but a single file name, then
3519 the list of agenda files is actually stored and maintained in that file, one
3520 agenda file per line. In this file paths can be given relative to
3521 `org-directory'. Tilde expansion and environment variable substitution
3525 (repeat :tag
"List of files and directories" file
)
3526 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
3528 (defcustom org-agenda-file-regexp
"\\`[^.].*\\.org\\'"
3529 "Regular expression to match files for `org-agenda-files'.
3530 If any element in the list in that variable contains a directory instead
3531 of a normal file, all files in that directory that are matched by this
3532 regular expression will be included."
3536 (defcustom org-agenda-text-search-extra-files nil
3537 "List of extra files to be searched by text search commands.
3538 These files will be search in addition to the agenda files by the
3539 commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'.
3540 Note that these files will only be searched for text search commands,
3541 not for the other agenda views like todo lists, tag searches or the weekly
3542 agenda. This variable is intended to list notes and possibly archive files
3543 that should also be searched by these two commands.
3544 In fact, if the first element in the list is the symbol `agenda-archives',
3545 than all archive files of all agenda files will be added to the search
3548 :type
'(set :greedy t
3549 (const :tag
"Agenda Archives" agenda-archives
)
3550 (repeat :inline t
(file))))
3552 (if (fboundp 'defvaralias
)
3553 (defvaralias 'org-agenda-multi-occur-extra-files
3554 'org-agenda-text-search-extra-files
))
3556 (defcustom org-agenda-skip-unavailable-files nil
3557 "Non-nil means to just skip non-reachable files in `org-agenda-files'.
3558 A nil value means to remove them, after a query, from the list."
3562 (defcustom org-calendar-to-agenda-key
[?c
]
3563 "The key to be installed in `calendar-mode-map' for switching to the agenda.
3564 The command `org-calendar-goto-agenda' will be bound to this key. The
3565 default is the character `c' because then `c' can be used to switch back and
3566 forth between agenda and calendar."
3570 (defcustom org-calendar-insert-diary-entry-key
[?i
]
3571 "The key to be installed in `calendar-mode-map' for adding diary entries.
3572 This option is irrelevant until `org-agenda-diary-file' has been configured
3573 to point to an Org-mode file. When that is the case, the command
3574 `org-agenda-diary-entry' will be bound to the key given here, by default
3575 `i'. In the calendar, `i' normally adds entries to `diary-file'. So
3576 if you want to continue doing this, you need to change this to a different
3581 (defcustom org-agenda-diary-file
'diary-file
3582 "File to which to add new entries with the `i' key in agenda and calendar.
3583 When this is the symbol `diary-file', the functionality in the Emacs
3584 calendar will be used to add entries to the `diary-file'. But when this
3585 points to a file, `org-agenda-diary-entry' will be used instead."
3588 (const :tag
"The standard Emacs diary file" diary-file
)
3589 (file :tag
"Special Org file diary entries")))
3591 (eval-after-load "calendar"
3593 (org-defkey calendar-mode-map org-calendar-to-agenda-key
3594 'org-calendar-goto-agenda
)
3595 (add-hook 'calendar-mode-hook
3597 (unless (eq org-agenda-diary-file
'diary-file
)
3598 (define-key calendar-mode-map
3599 org-calendar-insert-diary-entry-key
3600 'org-agenda-diary-entry
))))))
3602 (defgroup org-latex nil
3603 "Options for embedding LaTeX code into Org-mode."
3607 (defcustom org-format-latex-options
3608 '(:foreground default
:background default
:scale
1.0
3609 :html-foreground
"Black" :html-background
"Transparent"
3610 :html-scale
1.0 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))
3611 "Options for creating images from LaTeX fragments.
3612 This is a property list with the following properties:
3613 :foreground the foreground color for images embedded in Emacs, e.g. \"Black\".
3614 `default' means use the foreground of the default face.
3615 `auto' means use the foreground from the text face.
3616 :background the background color, or \"Transparent\".
3617 `default' means use the background of the default face.
3618 `auto' means use the background from the text face.
3619 :scale a scaling factor for the size of the images, to get more pixels
3620 :html-foreground, :html-background, :html-scale
3621 the same numbers for HTML export.
3622 :matchers a list indicating which matchers should be used to
3623 find LaTeX fragments. Valid members of this list are:
3624 \"begin\" find environments
3625 \"$1\" find single characters surrounded by $.$
3626 \"$\" find math expressions surrounded by $...$
3627 \"$$\" find math expressions surrounded by $$....$$
3628 \"\\(\" find math expressions surrounded by \\(...\\)
3629 \"\\ [\" find math expressions surrounded by \\ [...\\]"
3633 (defcustom org-format-latex-signal-error t
3634 "Non-nil means signal an error when image creation of LaTeX snippets fails.
3635 When nil, just push out a message."
3640 (defcustom org-latex-to-mathml-jar-file nil
3641 "Value of\"%j\" in `org-latex-to-mathml-convert-command'.
3642 Use this to specify additional executable file say a jar file.
3644 When using MathToWeb as the converter, specify the full-path to
3645 your mathtoweb.jar file."
3649 (const :tag
"None" nil
)
3650 (file :tag
"JAR file" :must-match t
)))
3652 (defcustom org-latex-to-mathml-convert-command nil
3653 "Command to convert LaTeX fragments to MathML.
3654 Replace format-specifiers in the command as noted below and use
3655 `shell-command' to convert LaTeX to MathML.
3656 %j: Executable file in fully expanded form as specified by
3657 `org-latex-to-mathml-jar-file'.
3658 %I: Input LaTeX file in fully expanded form
3659 %o: Output MathML file
3660 This command is used by `org-create-math-formula'.
3662 When using MathToWeb as the converter, set this to
3663 \"java -jar %j -unicode -force -df %o %I\"."
3667 (const :tag
"None" nil
)
3668 (string :tag
"\nShell command")))
3670 (defcustom org-latex-create-formula-image-program
'dvipng
3671 "Program to convert LaTeX fragments with.
3673 dvipng Process the LaTeX fragments to dvi file, then convert
3674 dvi files to png files using dvipng.
3675 This will also include processing of non-math environments.
3676 imagemagick Convert the LaTeX fragments to pdf files and use imagemagick
3677 to convert pdf files to png files"
3681 (const :tag
"dvipng" dvipng
)
3682 (const :tag
"imagemagick" imagemagick
)))
3684 (defcustom org-latex-preview-ltxpng-directory
"ltxpng/"
3685 "Path to store latex preview images.
3686 A relative path here creates many directories relative to the
3687 processed org files paths. An absolute path puts all preview
3688 images at the same place."
3693 (defun org-format-latex-mathml-available-p ()
3694 "Return t if `org-latex-to-mathml-convert-command' is usable."
3696 (when (and (boundp 'org-latex-to-mathml-convert-command
)
3697 org-latex-to-mathml-convert-command
)
3698 (let ((executable (car (split-string
3699 org-latex-to-mathml-convert-command
))))
3700 (when (executable-find executable
)
3702 "%j" org-latex-to-mathml-convert-command
)
3703 (file-readable-p org-latex-to-mathml-jar-file
)
3706 (defcustom org-format-latex-header
"\\documentclass{article}
3707 \\usepackage[usenames]{color}
3708 \\usepackage{amsmath}
3709 \\usepackage[mathscr]{eucal}
3710 \\pagestyle{empty} % do not remove
3713 % The settings below are copied from fullpage.sty
3714 \\setlength{\\textwidth}{\\paperwidth}
3715 \\addtolength{\\textwidth}{-3cm}
3716 \\setlength{\\oddsidemargin}{1.5cm}
3717 \\addtolength{\\oddsidemargin}{-2.54cm}
3718 \\setlength{\\evensidemargin}{\\oddsidemargin}
3719 \\setlength{\\textheight}{\\paperheight}
3720 \\addtolength{\\textheight}{-\\headheight}
3721 \\addtolength{\\textheight}{-\\headsep}
3722 \\addtolength{\\textheight}{-\\footskip}
3723 \\addtolength{\\textheight}{-3cm}
3724 \\setlength{\\topmargin}{1.5cm}
3725 \\addtolength{\\topmargin}{-2.54cm}"
3726 "The document header used for processing LaTeX fragments.
3727 It is imperative that this header make sure that no page number
3728 appears on the page. The package defined in the variables
3729 `org-latex-default-packages-alist' and `org-latex-packages-alist'
3730 will either replace the placeholder \"[PACKAGES]\" in this
3731 header, or they will be appended."
3735 (defun org-set-packages-alist (var val
)
3736 "Set the packages alist and make sure it has 3 elements per entry."
3737 (set var
(mapcar (lambda (x)
3738 (if (and (consp x
) (= (length x
) 2))
3739 (list (car x
) (nth 1 x
) t
)
3743 (defun org-get-packages-alist (var)
3744 "Get the packages alist and make sure it has 3 elements per entry."
3746 (if (and (consp x
) (= (length x
) 2))
3747 (list (car x
) (nth 1 x
) t
)
3749 (default-value var
)))
3751 (defcustom org-latex-default-packages-alist
3752 '(("AUTO" "inputenc" t
)
3756 ("" "longtable" nil
)
3767 "Alist of default packages to be inserted in the header.
3769 Change this only if one of the packages here causes an
3770 incompatibility with another package you are using.
3772 The packages in this list are needed by one part or another of
3773 Org mode to function properly:
3775 - inputenc, fontenc: for basic font and character selection
3776 - textcomp, marvosymb, wasysym, latexsym, amssym: for various
3777 symbols used for interpreting the entities in `org-entities'.
3778 You can skip some of these packages if you don't use any of the
3780 - graphicx: for including images
3781 - float, wrapfig: for figure placement
3782 - longtable: for long tables
3783 - hyperref: for cross references
3785 Therefore you should not modify this variable unless you know
3786 what you are doing. The one reason to change it anyway is that
3787 you might be loading some other package that conflicts with one
3788 of the default packages. Each cell is of the format
3789 \( \"options\" \"package\" snippet-flag). If SNIPPET-FLAG is t,
3790 the package also needs to be included when compiling LaTeX
3791 snippets into images for inclusion into non-LaTeX output."
3793 :group
'org-export-latex
3794 :set
'org-set-packages-alist
3795 :get
'org-get-packages-alist
3799 (list :tag
"options/package pair"
3800 (string :tag
"options")
3801 (string :tag
"package")
3802 (boolean :tag
"Snippet"))
3803 (string :tag
"A line of LaTeX"))))
3805 (defcustom org-latex-packages-alist nil
3806 "Alist of packages to be inserted in every LaTeX header.
3808 These will be inserted after `org-latex-default-packages-alist'.
3809 Each cell is of the format:
3811 \(\"options\" \"package\" snippet-flag)
3813 SNIPPET-FLAG, when t, indicates that this package is also needed
3814 when turning LaTeX snippets into images for inclusion into
3817 Make sure that you only list packages here which:
3819 - you want in every file
3820 - do not conflict with the setup in `org-format-latex-header'.
3821 - do not conflict with the default packages in
3822 `org-latex-default-packages-alist'."
3824 :group
'org-export-latex
3825 :set
'org-set-packages-alist
3826 :get
'org-get-packages-alist
3829 (list :tag
"options/package pair"
3830 (string :tag
"options")
3831 (string :tag
"package")
3832 (boolean :tag
"Snippet"))
3833 (string :tag
"A line of LaTeX"))))
3835 (defgroup org-appearance nil
3836 "Settings for Org-mode appearance."
3837 :tag
"Org Appearance"
3840 (defcustom org-level-color-stars-only nil
3841 "Non-nil means fontify only the stars in each headline.
3842 When nil, the entire headline is fontified.
3843 Changing it requires restart of `font-lock-mode' to become effective
3844 also in regions already fontified."
3845 :group
'org-appearance
3848 (defcustom org-hide-leading-stars nil
3849 "Non-nil means hide the first N-1 stars in a headline.
3850 This works by using the face `org-hide' for these stars. This
3851 face is white for a light background, and black for a dark
3852 background. You may have to customize the face `org-hide' to
3854 Changing it requires restart of `font-lock-mode' to become effective
3855 also in regions already fontified.
3856 You may also set this on a per-file basis by adding one of the following
3857 lines to the buffer:
3859 #+STARTUP: hidestars
3860 #+STARTUP: showstars"
3861 :group
'org-appearance
3864 (defcustom org-hidden-keywords nil
3865 "List of symbols corresponding to keywords to be hidden the org buffer.
3866 For example, a value '(title) for this list will make the document's title
3867 appear in the buffer without the initial #+TITLE: keyword."
3868 :group
'org-appearance
3870 :type
'(set (const :tag
"#+AUTHOR" author
)
3871 (const :tag
"#+DATE" date
)
3872 (const :tag
"#+EMAIL" email
)
3873 (const :tag
"#+TITLE" title
)))
3875 (defcustom org-custom-properties nil
3876 "List of properties (as strings) with a special meaning.
3877 The default use of these custom properties is to let the user
3878 hide them with `org-toggle-custom-properties-visibility'."
3879 :group
'org-properties
3880 :group
'org-appearance
3882 :type
'(repeat (string :tag
"Property Name")))
3884 (defcustom org-fontify-done-headline nil
3885 "Non-nil means change the face of a headline if it is marked DONE.
3886 Normally, only the TODO/DONE keyword indicates the state of a headline.
3887 When this is non-nil, the headline after the keyword is set to the
3888 `org-headline-done' as an additional indication."
3889 :group
'org-appearance
3892 (defcustom org-fontify-emphasized-text t
3893 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
3894 Changing this variable requires a restart of Emacs to take effect."
3895 :group
'org-appearance
3898 (defcustom org-fontify-whole-heading-line nil
3899 "Non-nil means fontify the whole line for headings.
3900 This is useful when setting a background color for the
3902 :group
'org-appearance
3905 (defcustom org-highlight-latex-and-related nil
3906 "Non-nil means highlight LaTeX related syntax in the buffer.
3907 When non nil, the value should be a list containing any of the
3909 `latex' Highlight LaTeX snippets and environments.
3910 `script' Highlight subscript and superscript.
3911 `entities' Highlight entities."
3912 :group
'org-appearance
3914 (const :tag
"No highlighting" nil
)
3915 (set :greedy t
:tag
"Highlight"
3916 (const :tag
"LaTeX snippets and environments" latex
)
3917 (const :tag
"Subscript and superscript" script
)
3918 (const :tag
"Entities" entities
))))
3920 (defcustom org-hide-emphasis-markers nil
3921 "Non-nil mean font-lock should hide the emphasis marker characters."
3922 :group
'org-appearance
3925 (defcustom org-pretty-entities nil
3926 "Non-nil means show entities as UTF8 characters.
3927 When nil, the \\name form remains in the buffer."
3928 :group
'org-appearance
3932 (defcustom org-pretty-entities-include-sub-superscripts t
3933 "Non-nil means, pretty entity display includes formatting sub/superscripts."
3934 :group
'org-appearance
3938 (defvar org-emph-re nil
3939 "Regular expression for matching emphasis.
3940 After a match, the match groups contain these elements:
3941 0 The match of the full regular expression, including the characters
3942 before and after the proper match
3943 1 The character before the proper match, or empty at beginning of line
3944 2 The proper match, including the leading and trailing markers
3945 3 The leading marker like * or /, indicating the type of highlighting
3946 4 The text between the emphasis markers, not including the markers
3947 5 The character after the match, empty at the end of a line")
3948 (defvar org-verbatim-re nil
3949 "Regular expression for matching verbatim text.")
3950 (defvar org-emphasis-regexp-components
) ; defined just below
3951 (defvar org-emphasis-alist
) ; defined just below
3952 (defun org-set-emph-re (var val
)
3953 "Set variable and compute the emphasis regular expression."
3955 (when (and (boundp 'org-emphasis-alist
)
3956 (boundp 'org-emphasis-regexp-components
)
3957 org-emphasis-alist org-emphasis-regexp-components
)
3958 (let* ((e org-emphasis-regexp-components
)
3964 (body1 (concat body
"*?"))
3965 (markers (mapconcat 'car org-emphasis-alist
""))
3966 (vmarkers (mapconcat
3967 (lambda (x) (if (eq (nth 4 x
) 'verbatim
) (car x
) ""))
3968 org-emphasis-alist
"")))
3969 ;; make sure special characters appear at the right position in the class
3970 (if (string-match "\\^" markers
)
3971 (setq markers
(concat (replace-match "" t t markers
) "^")))
3972 (if (string-match "-" markers
)
3973 (setq markers
(concat (replace-match "" t t markers
) "-")))
3974 (if (string-match "\\^" vmarkers
)
3975 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "^")))
3976 (if (string-match "-" vmarkers
)
3977 (setq vmarkers
(concat (replace-match "" t t vmarkers
) "-")))
3979 (setq body1
(concat body1
"\\(?:\n" body
"*?\\)\\{0,"
3980 (int-to-string nl
) "\\}")))
3983 (concat "\\([" pre
"]\\|^\\)"
3985 "\\([" markers
"]\\)"
3993 "\\([" post
"]\\|$\\)"))
3994 (setq org-verbatim-re
3995 (concat "\\([" pre
"]\\|^\\)"
3997 "\\([" vmarkers
"]\\)"
4005 "\\([" post
"]\\|$\\)")))))
4007 (defcustom org-emphasis-regexp-components
4008 '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1)
4009 "Components used to build the regular expression for emphasis.
4010 This is a list with five entries. Terminology: In an emphasis string
4011 like \" *strong word* \", we call the initial space PREMATCH, the final
4012 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
4013 and \"trong wor\" is the body. The different components in this variable
4014 specify what is allowed/forbidden in each part:
4016 pre Chars allowed as prematch. Beginning of line will be allowed too.
4017 post Chars allowed as postmatch. End of line will be allowed too.
4018 border The chars *forbidden* as border characters.
4019 body-regexp A regexp like \".\" to match a body character. Don't use
4020 non-shy groups here, and don't allow newline here.
4021 newline The maximum number of newlines allowed in an emphasis exp.
4023 Use customize to modify this, or restart Emacs after changing it."
4024 :group
'org-appearance
4025 :set
'org-set-emph-re
4027 (sexp :tag
"Allowed chars in pre ")
4028 (sexp :tag
"Allowed chars in post ")
4029 (sexp :tag
"Forbidden chars in border ")
4030 (sexp :tag
"Regexp for body ")
4031 (integer :tag
"number of newlines allowed")
4032 (option (boolean :tag
"Please ignore this button"))))
4034 (defcustom org-emphasis-alist
4035 `(("*" bold
"<b>" "</b>")
4036 ("/" italic
"<i>" "</i>")
4037 ("_" underline
"<span style=\"text-decoration:underline;\">" "</span>")
4038 ("=" org-code
"<code>" "</code>" verbatim
)
4039 ("~" org-verbatim
"<code>" "</code>" verbatim
)
4040 ("+" ,(if (featurep 'xemacs
) 'org-table
'(:strike-through t
))
4043 "Special syntax for emphasized text.
4044 Text starting and ending with a special character will be emphasized, for
4045 example *bold*, _underlined_ and /italic/. This variable sets the marker
4046 characters, the face to be used by font-lock for highlighting in Org-mode
4047 Emacs buffers, and the HTML tags to be used for this.
4048 For LaTeX export, see the variable `org-export-latex-emphasis-alist'.
4049 Use customize to modify this, or restart Emacs after changing it."
4050 :group
'org-appearance
4051 :set
'org-set-emph-re
4054 (string :tag
"Marker character")
4056 (face :tag
"Font-lock-face")
4057 (plist :tag
"Face property list"))
4058 (string :tag
"HTML start tag")
4059 (string :tag
"HTML end tag")
4060 (option (const verbatim
)))))
4062 (defvar org-protecting-blocks
4063 '("src" "example" "latex" "ascii" "html" "ditaa" "dot" "r" "R")
4064 "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
4065 This is needed for font-lock setup.")
4067 ;;; Miscellaneous options
4069 (defgroup org-completion nil
4070 "Completion in Org-mode."
4071 :tag
"Org Completion"
4074 (defcustom org-completion-use-ido nil
4075 "Non-nil means use ido completion wherever possible.
4076 Note that `ido-mode' must be active for this variable to be relevant.
4077 If you decide to turn this variable on, you might well want to turn off
4078 `org-outline-path-complete-in-steps'.
4079 See also `org-completion-use-iswitchb'."
4080 :group
'org-completion
4083 (defcustom org-completion-use-iswitchb nil
4084 "Non-nil means use iswitchb completion wherever possible.
4085 Note that `iswitchb-mode' must be active for this variable to be relevant.
4086 If you decide to turn this variable on, you might well want to turn off
4087 `org-outline-path-complete-in-steps'.
4088 Note that this variable has only an effect if `org-completion-use-ido' is nil."
4089 :group
'org-completion
4092 (defcustom org-completion-fallback-command
'hippie-expand
4093 "The expansion command called by \\[pcomplete] in normal context.
4094 Normal means, no org-mode-specific context."
4095 :group
'org-completion
4098 ;;; Functions and variables from their packages
4099 ;; Declared here to avoid compiler warnings
4102 (defvar outline-mode-menu-heading
)
4103 (defvar outline-mode-menu-show
)
4104 (defvar outline-mode-menu-hide
)
4105 (defvar zmacs-regions
) ; XEmacs regions
4108 (defvar mark-active
)
4111 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
4112 (declare-function calendar-forward-day
"cal-move" (arg))
4113 (declare-function calendar-goto-date
"cal-move" (date))
4114 (declare-function calendar-goto-today
"cal-move" ())
4115 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
4116 (defvar calc-embedded-close-formula
)
4117 (defvar calc-embedded-open-formula
)
4118 (declare-function cdlatex-tab
"ext:cdlatex" ())
4119 (declare-function cdlatex-compute-tables
"ext:cdlatex" ())
4120 (declare-function dired-get-filename
"dired" (&optional localp no-error-if-not-filep
))
4121 (defvar font-lock-unfontify-region-function
)
4122 (declare-function iswitchb-read-buffer
"iswitchb"
4123 (prompt &optional default require-match start matches-set
))
4124 (defvar iswitchb-temp-buflist
)
4125 (declare-function org-gnus-follow-link
"org-gnus" (&optional group article
))
4126 (defvar org-agenda-tags-todo-honor-ignore-options
)
4127 (declare-function org-agenda-skip
"org-agenda" ())
4129 org-agenda-format-item
"org-agenda"
4130 (extra txt
&optional level category tags dotime noprefix remove-re habitp
))
4131 (declare-function org-agenda-new-marker
"org-agenda" (&optional pos
))
4132 (declare-function org-agenda-change-all-lines
"org-agenda"
4133 (newhead hdmarker
&optional fixface just-this
))
4134 (declare-function org-agenda-set-restriction-lock
"org-agenda" (&optional type
))
4135 (declare-function org-agenda-maybe-redo
"org-agenda" ())
4136 (declare-function org-agenda-save-markers-for-cut-and-paste
"org-agenda"
4138 (declare-function org-agenda-copy-local-variable
"org-agenda" (var))
4139 (declare-function org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4140 "org-agenda" (&optional end
))
4141 (declare-function org-inlinetask-remove-END-maybe
"org-inlinetask" ())
4142 (declare-function org-inlinetask-in-task-p
"org-inlinetask" ())
4143 (declare-function org-inlinetask-goto-beginning
"org-inlinetask" ())
4144 (declare-function org-inlinetask-goto-end
"org-inlinetask" ())
4145 (declare-function org-indent-mode
"org-indent" (&optional arg
))
4146 (declare-function parse-time-string
"parse-time" (string))
4147 (declare-function org-attach-reveal
"org-attach" (&optional if-exists
))
4148 (declare-function orgtbl-send-table
"org-table" (&optional maybe
))
4149 (defvar remember-data-file
)
4150 (defvar texmathp-why
)
4151 (declare-function speedbar-line-directory
"speedbar" (&optional depth
))
4152 (declare-function table--at-cell-p
"table" (position &optional object at-column
))
4154 (defvar org-latex-regexps
)
4156 ;;; Autoload and prepare some org modules
4158 ;; Some table stuff that needs to be defined here, because it is used
4159 ;; by the functions setting up org-mode or checking for table context.
4161 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
4162 "Detect an org-type or table-type table.")
4163 (defconst org-table-line-regexp
"^[ \t]*|"
4164 "Detect an org-type table line.")
4165 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
4166 "Detect an org-type table line.")
4167 (defconst org-table-hline-regexp
"^[ \t]*|-"
4168 "Detect an org-type table hline.")
4169 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
4170 "Detect a table-type table hline.")
4171 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
4172 "Detect the first line outside a table when searching from within it.
4173 This works for both table types.")
4175 ;; Autoload the functions in org-table.el that are needed by functions here.
4178 (org-autoload "org-table"
4179 '(org-table-begin org-table-blank-field org-table-end
)))
4182 (defun turn-on-orgtbl ()
4183 "Unconditionally turn on `orgtbl-mode'."
4184 (require 'org-table
)
4187 (defun org-at-table-p (&optional table-type
)
4188 "Return t if the cursor is inside an org-type table.
4189 If TABLE-TYPE is non-nil, also check for table.el-type tables."
4190 (if org-enable-table-editor
4192 (beginning-of-line 1)
4193 (looking-at (if table-type org-table-any-line-regexp
4194 org-table-line-regexp
)))
4196 (defsubst org-table-p
() (org-at-table-p))
4198 (defun org-at-table.el-p
()
4199 "Return t if and only if we are at a table.el table."
4200 (and (org-at-table-p 'any
)
4202 (goto-char (org-table-begin 'any
))
4203 (looking-at org-table1-hline-regexp
))))
4204 (defun org-table-recognize-table.el
()
4205 "If there is a table.el table nearby, recognize it and move into it."
4206 (if org-table-tab-recognizes-table.el
4207 (if (org-at-table.el-p
)
4209 (beginning-of-line 1)
4210 (if (looking-at org-table-dataline-regexp
)
4212 (if (looking-at org-table1-hline-regexp
)
4214 (beginning-of-line 2)
4215 (if (looking-at org-table-any-border-regexp
)
4216 (beginning-of-line -
1)))))
4217 (if (re-search-forward "|" (org-table-end t
) t
)
4220 (if (table--at-cell-p (point))
4222 (message "recognizing table.el table...")
4223 (table-recognize-table)
4224 (message "recognizing table.el table...done")))
4225 (error "This should not happen"))
4230 (defun org-at-table-hline-p ()
4231 "Return t if the cursor is inside a hline in a table."
4232 (if org-enable-table-editor
4234 (beginning-of-line 1)
4235 (looking-at org-table-hline-regexp
))
4238 (defvar org-table-clean-did-remove-column nil
)
4240 (defun org-table-map-tables (function &optional quietly
)
4241 "Apply FUNCTION to the start of all tables in the buffer."
4245 (goto-char (point-min))
4246 (while (re-search-forward org-table-any-line-regexp nil t
)
4248 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))))
4249 (beginning-of-line 1)
4250 (when (and (looking-at org-table-line-regexp
)
4251 ;; Exclude tables in src/example/verbatim/clocktable blocks
4252 (not (org-in-block-p '("src" "example" "verbatim" "clocktable"))))
4253 (save-excursion (funcall function
))
4254 (or (looking-at org-table-line-regexp
)
4256 (re-search-forward org-table-any-border-regexp nil
1))))
4257 (unless quietly
(message "Mapping tables: done")))
4259 ;; Declare and autoload functions from ox.el and al.
4261 (declare-function org-export-get-environment
"ox"
4262 (&optional backend subtreep ext-plist
))
4263 (declare-function org-latex-guess-inputenc
"ox-latex" (header))
4265 ;; Declare and autoload functions from org-agenda.el
4268 (org-autoload "org-agenda"
4269 '(org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item)))
4271 (declare-function org-clock-save-markers-for-cut-and-paste
"org-clock" (beg end
))
4272 (declare-function org-clock-update-mode-line
"org-clock" ())
4273 (declare-function org-resolve-clocks
"org-clock"
4274 (&optional also-non-dangling-p prompt last-valid
))
4275 (defvar org-clock-start-time
)
4276 (defvar org-clock-marker
(make-marker)
4277 "Marker recording the last clock-in.")
4278 (defvar org-clock-hd-marker
(make-marker)
4279 "Marker recording the last clock-in, but the headline position.")
4280 (defvar org-clock-heading
""
4281 "The heading of the current clock entry.")
4282 (defun org-clock-is-active ()
4283 "Return non-nil if clock is currently running.
4284 The return value is actually the clock marker."
4285 (marker-buffer org-clock-marker
))
4288 (org-autoload "org-clock" '(org-clock-remove-overlays
4289 org-clock-update-time-maybe
4290 org-clocktable-shift
)))
4292 (defun org-check-running-clock ()
4293 "Check if the current buffer contains the running clock.
4294 If yes, offer to stop it and to save the buffer with the changes."
4295 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
4296 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
4299 (when (y-or-n-p "Save changed buffer?")
4302 (defun org-clocktable-try-shift (dir n
)
4303 "Check if this line starts a clock table, if yes, shift the time block."
4304 (when (org-match-line "^[ \t]*#\\+BEGIN:[ \t]+clocktable\\>")
4305 (org-clocktable-shift dir n
)))
4308 (defun org-clock-persistence-insinuate ()
4309 "Set up hooks for clock persistence."
4310 (require 'org-clock
)
4311 (add-hook 'org-mode-hook
'org-clock-load
)
4312 (add-hook 'kill-emacs-hook
'org-clock-save
))
4314 ;; Define the variable already here, to make sure we have it.
4315 (defvar org-indent-mode nil
4316 "Non-nil if Org-Indent mode is enabled.
4317 Use the command `org-indent-mode' to change this variable.")
4319 ;; Autoload archiving code
4320 ;; The stuff that is needed for cycling and tags has to be defined here.
4322 (defgroup org-archive nil
4323 "Options concerning archiving in Org-mode."
4325 :group
'org-structure
)
4327 (defcustom org-archive-location
"%s_archive::"
4328 "The location where subtrees should be archived.
4330 The value of this variable is a string, consisting of two parts,
4331 separated by a double-colon. The first part is a filename and
4332 the second part is a headline.
4334 When the filename is omitted, archiving happens in the same file.
4335 %s in the filename will be replaced by the current file
4336 name (without the directory part). Archiving to a different file
4337 is useful to keep archived entries from contributing to the
4340 The archived entries will be filed as subtrees of the specified
4341 headline. When the headline is omitted, the subtrees are simply
4342 filed away at the end of the file, as top-level entries. Also in
4343 the heading you can use %s to represent the file name, this can be
4344 useful when using the same archive for a number of different files.
4346 Here are a few examples:
4348 If the current file is Projects.org, archive in file
4349 Projects.org_archive, as top-level trees. This is the default.
4351 \"::* Archived Tasks\"
4352 Archive in the current file, under the top-level headline
4353 \"* Archived Tasks\".
4355 \"~/org/archive.org::\"
4356 Archive in file ~/org/archive.org (absolute path), as top-level trees.
4358 \"~/org/archive.org::* From %s\"
4359 Archive in file ~/org/archive.org (absolute path), under headlines
4360 \"From FILENAME\" where file name is the current file name.
4362 \"~/org/datetree.org::datetree/* Finished Tasks\"
4363 The \"datetree/\" string is special, signifying to archive
4364 items to the datetree. Items are placed in either the CLOSED
4365 date of the item, or the current date if there is no CLOSED date.
4366 The heading will be a subentry to the current date. There doesn't
4367 need to be a heading, but there always needs to be a slash after
4368 datetree. For example, to store archived items directly in the
4369 datetree, use \"~/org/datetree.org::datetree/\".
4371 \"basement::** Finished Tasks\"
4372 Archive in file ./basement (relative path), as level 3 trees
4373 below the level 2 heading \"** Finished Tasks\".
4375 You may set this option on a per-file basis by adding to the buffer a
4378 #+ARCHIVE: basement::** Finished Tasks
4380 You may also define it locally for a subtree by setting an ARCHIVE property
4381 in the entry. If such a property is found in an entry, or anywhere up
4382 the hierarchy, it will be used."
4386 (defcustom org-archive-tag
"ARCHIVE"
4387 "The tag that marks a subtree as archived.
4388 An archived subtree does not open during visibility cycling, and does
4389 not contribute to the agenda listings.
4390 After changing this, font-lock must be restarted in the relevant buffers to
4391 get the proper fontification."
4393 :group
'org-keywords
4396 (defcustom org-agenda-skip-archived-trees t
4397 "Non-nil means the agenda will skip any items located in archived trees.
4398 An archived tree is a tree marked with the tag ARCHIVE. The use of this
4399 variable is no longer recommended, you should leave it at the value t.
4400 Instead, use the key `v' to cycle the archives-mode in the agenda."
4402 :group
'org-agenda-skip
4405 (defcustom org-columns-skip-archived-trees t
4406 "Non-nil means ignore archived trees when creating column view."
4408 :group
'org-properties
4411 (defcustom org-cycle-open-archived-trees nil
4412 "Non-nil means `org-cycle' will open archived trees.
4413 An archived tree is a tree marked with the tag ARCHIVE.
4414 When nil, archived trees will stay folded. You can still open them with
4415 normal outline commands like `show-all', but not with the cycling commands."
4420 (defcustom org-sparse-tree-open-archived-trees nil
4421 "Non-nil means sparse tree construction shows matches in archived trees.
4422 When nil, matches in these trees are highlighted, but the trees are kept in
4425 :group
'org-sparse-trees
4428 (defcustom org-sparse-tree-default-date-type
'scheduled-or-deadline
4429 "The default date type when building a sparse tree.
4430 When this is nil, a date is a scheduled or a deadline timestamp.
4431 Otherwise, these types are allowed:
4434 active: only active timestamps (<...>)
4435 inactive: only inactive timestamps (<...)
4436 scheduled: only scheduled timestamps
4437 deadline: only deadline timestamps"
4438 :type
'(choice (const :tag
"Scheduled or deadline" 'scheduled-or-deadline
)
4439 (const :tag
"All timestamps" all
)
4440 (const :tag
"Only active timestamps" active
)
4441 (const :tag
"Only inactive timestamps" inactive
)
4442 (const :tag
"Only scheduled timestamps" scheduled
)
4443 (const :tag
"Only deadline timestamps" deadline
))
4445 :group
'org-sparse-trees
)
4447 (defun org-cycle-hide-archived-subtrees (state)
4448 "Re-hide all archived subtrees after a visibility state change."
4449 (when (and (not org-cycle-open-archived-trees
)
4450 (not (memq state
'(overview folded
))))
4452 (let* ((globalp (memq state
'(contents all
)))
4453 (beg (if globalp
(point-min) (point)))
4454 (end (if globalp
(point-max) (org-end-of-subtree t
))))
4455 (org-hide-archived-subtrees beg end
)
4457 (if (looking-at (concat ".*:" org-archive-tag
":"))
4458 (message "%s" (substitute-command-keys
4459 "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway.")))))))
4461 (defun org-force-cycle-archived ()
4462 "Cycle subtree even if it is archived."
4464 (setq this-command
'org-cycle
)
4465 (let ((org-cycle-open-archived-trees t
))
4466 (call-interactively 'org-cycle
)))
4468 (defun org-hide-archived-subtrees (beg end
)
4469 "Re-hide all archived subtrees after a visibility state change."
4471 (let* ((re (concat ":" org-archive-tag
":")))
4473 (while (re-search-forward re end t
)
4474 (when (org-at-heading-p)
4475 (org-flag-subtree t
)
4476 (org-end-of-subtree t
))))))
4478 (declare-function outline-end-of-heading
"outline" ())
4479 (declare-function outline-flag-region
"outline" (from to flag
))
4480 (defun org-flag-subtree (flag)
4482 (org-back-to-heading t
)
4483 (outline-end-of-heading)
4484 (outline-flag-region (point)
4485 (progn (org-end-of-subtree t
) (point))
4488 (defalias 'org-advertized-archive-subtree
'org-archive-subtree
)
4491 (org-autoload "org-archive"
4492 '(org-add-archive-files)))
4494 ;; Autoload Column View Code
4496 (declare-function org-columns-number-to-string
"org-colview" (n fmt
&optional printf
))
4497 (declare-function org-columns-get-format-and-top-level
"org-colview" ())
4498 (declare-function org-columns-compute
"org-colview" (property))
4500 (org-autoload (if (featurep 'xemacs
) "org-colview-xemacs" "org-colview")
4501 '(org-columns-number-to-string
4502 org-columns-get-format-and-top-level
4504 org-columns-remove-overlays
))
4508 (declare-function org-id-store-link
"org-id")
4509 (declare-function org-id-locations-load
"org-id")
4510 (declare-function org-id-locations-save
"org-id")
4511 (defvar org-id-track-globally
)
4512 (org-autoload "org-id"
4515 org-id-get-with-outline-path-completion
4516 org-id-get-with-outline-drilling
))
4518 ;;; Variables for pre-computed regular expressions, all buffer local
4520 (defvar org-drawer-regexp
"^[ \t]*:PROPERTIES:[ \t]*$"
4521 "Matches first line of a hidden block.")
4522 (make-variable-buffer-local 'org-drawer-regexp
)
4523 (defvar org-todo-regexp nil
4524 "Matches any of the TODO state keywords.")
4525 (make-variable-buffer-local 'org-todo-regexp
)
4526 (defvar org-not-done-regexp nil
4527 "Matches any of the TODO state keywords except the last one.")
4528 (make-variable-buffer-local 'org-not-done-regexp
)
4529 (defvar org-not-done-heading-regexp nil
4530 "Matches a TODO headline that is not done.")
4531 (make-variable-buffer-local 'org-not-done-regexp
)
4532 (defvar org-todo-line-regexp nil
4533 "Matches a headline and puts TODO state into group 2 if present.")
4534 (make-variable-buffer-local 'org-todo-line-regexp
)
4535 (defvar org-complex-heading-regexp nil
4536 "Matches a headline and puts everything into groups:
4538 group 2: The todo keyword, maybe
4539 group 3: Priority cookie
4540 group 4: True headline
4542 (make-variable-buffer-local 'org-complex-heading-regexp
)
4543 (defvar org-complex-heading-regexp-format nil
4544 "Printf format to make regexp to match an exact headline.
4545 This regexp will match the headline of any node which has the
4546 exact headline text that is put into the format, but may have any
4547 TODO state, priority and tags.")
4548 (make-variable-buffer-local 'org-complex-heading-regexp-format
)
4549 (defvar org-todo-line-tags-regexp nil
4550 "Matches a headline and puts TODO state into group 2 if present.
4551 Also put tags into group 4 if tags are present.")
4552 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
4553 (defvar org-ds-keyword-length
12
4554 "Maximum length of the DEADLINE and SCHEDULED keywords.")
4555 (make-variable-buffer-local 'org-ds-keyword-length
)
4556 (defvar org-deadline-regexp nil
4557 "Matches the DEADLINE keyword.")
4558 (make-variable-buffer-local 'org-deadline-regexp
)
4559 (defvar org-deadline-time-regexp nil
4560 "Matches the DEADLINE keyword together with a time stamp.")
4561 (make-variable-buffer-local 'org-deadline-time-regexp
)
4562 (defvar org-deadline-line-regexp nil
4563 "Matches the DEADLINE keyword and the rest of the line.")
4564 (make-variable-buffer-local 'org-deadline-line-regexp
)
4565 (defvar org-scheduled-regexp nil
4566 "Matches the SCHEDULED keyword.")
4567 (make-variable-buffer-local 'org-scheduled-regexp
)
4568 (defvar org-scheduled-time-regexp nil
4569 "Matches the SCHEDULED keyword together with a time stamp.")
4570 (make-variable-buffer-local 'org-scheduled-time-regexp
)
4571 (defvar org-closed-time-regexp nil
4572 "Matches the CLOSED keyword together with a time stamp.")
4573 (make-variable-buffer-local 'org-closed-time-regexp
)
4575 (defvar org-keyword-time-regexp nil
4576 "Matches any of the 4 keywords, together with the time stamp.")
4577 (make-variable-buffer-local 'org-keyword-time-regexp
)
4578 (defvar org-keyword-time-not-clock-regexp nil
4579 "Matches any of the 3 keywords, together with the time stamp.")
4580 (make-variable-buffer-local 'org-keyword-time-not-clock-regexp
)
4581 (defvar org-maybe-keyword-time-regexp nil
4582 "Matches a timestamp, possibly preceded by a keyword.")
4583 (make-variable-buffer-local 'org-maybe-keyword-time-regexp
)
4584 (defvar org-all-time-keywords nil
4585 "List of time keywords.")
4586 (make-variable-buffer-local 'org-all-time-keywords
)
4588 (defconst org-plain-time-of-day-regexp
4591 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4594 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4596 "Regular expression to match a plain time or time range.
4597 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4598 groups carry important information:
4600 1 the first time, range or not
4601 8 the second time, if it is a range.")
4603 (defconst org-plain-time-extension-regexp
4606 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
4607 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
4608 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
4609 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
4610 groups carry important information:
4613 9 minutes of duration")
4615 (defconst org-stamp-time-of-day-regexp
4617 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
4618 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
4620 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
4621 "Regular expression to match a timestamp time or time range.
4622 After a match, the following groups carry important information:
4624 1 date plus weekday, for back referencing to make sure both times are on the same day
4625 2 the first time, range or not
4626 4 the second time, if it is a range.")
4628 (defconst org-startup-options
4629 '(("fold" org-startup-folded t
)
4630 ("overview" org-startup-folded t
)
4631 ("nofold" org-startup-folded nil
)
4632 ("showall" org-startup-folded nil
)
4633 ("showeverything" org-startup-folded showeverything
)
4634 ("content" org-startup-folded content
)
4635 ("indent" org-startup-indented t
)
4636 ("noindent" org-startup-indented nil
)
4637 ("hidestars" org-hide-leading-stars t
)
4638 ("showstars" org-hide-leading-stars nil
)
4639 ("odd" org-odd-levels-only t
)
4640 ("oddeven" org-odd-levels-only nil
)
4641 ("align" org-startup-align-all-tables t
)
4642 ("noalign" org-startup-align-all-tables nil
)
4643 ("inlineimages" org-startup-with-inline-images t
)
4644 ("noinlineimages" org-startup-with-inline-images nil
)
4645 ("latexpreview" org-startup-with-latex-preview t
)
4646 ("nolatexpreview" org-startup-with-latex-preview nil
)
4647 ("customtime" org-display-custom-times t
)
4648 ("logdone" org-log-done time
)
4649 ("lognotedone" org-log-done note
)
4650 ("nologdone" org-log-done nil
)
4651 ("lognoteclock-out" org-log-note-clock-out t
)
4652 ("nolognoteclock-out" org-log-note-clock-out nil
)
4653 ("logrepeat" org-log-repeat state
)
4654 ("lognoterepeat" org-log-repeat note
)
4655 ("logdrawer" org-log-into-drawer t
)
4656 ("nologdrawer" org-log-into-drawer nil
)
4657 ("logstatesreversed" org-log-states-order-reversed t
)
4658 ("nologstatesreversed" org-log-states-order-reversed nil
)
4659 ("nologrepeat" org-log-repeat nil
)
4660 ("logreschedule" org-log-reschedule time
)
4661 ("lognotereschedule" org-log-reschedule note
)
4662 ("nologreschedule" org-log-reschedule nil
)
4663 ("logredeadline" org-log-redeadline time
)
4664 ("lognoteredeadline" org-log-redeadline note
)
4665 ("nologredeadline" org-log-redeadline nil
)
4666 ("logrefile" org-log-refile time
)
4667 ("lognoterefile" org-log-refile note
)
4668 ("nologrefile" org-log-refile nil
)
4669 ("fninline" org-footnote-define-inline t
)
4670 ("nofninline" org-footnote-define-inline nil
)
4671 ("fnlocal" org-footnote-section nil
)
4672 ("fnauto" org-footnote-auto-label t
)
4673 ("fnprompt" org-footnote-auto-label nil
)
4674 ("fnconfirm" org-footnote-auto-label confirm
)
4675 ("fnplain" org-footnote-auto-label plain
)
4676 ("fnadjust" org-footnote-auto-adjust t
)
4677 ("nofnadjust" org-footnote-auto-adjust nil
)
4678 ("constcgs" constants-unit-system cgs
)
4679 ("constSI" constants-unit-system SI
)
4680 ("noptag" org-tag-persistent-alist nil
)
4681 ("hideblocks" org-hide-block-startup t
)
4682 ("nohideblocks" org-hide-block-startup nil
)
4683 ("beamer" org-startup-with-beamer-mode t
)
4684 ("entitiespretty" org-pretty-entities t
)
4685 ("entitiesplain" org-pretty-entities nil
))
4686 "Variable associated with STARTUP options for org-mode.
4687 Each element is a list of three items: the startup options (as written
4688 in the #+STARTUP line), the corresponding variable, and the value to set
4689 this variable to if the option is found. An optional forth element PUSH
4690 means to push this value onto the list in the variable.")
4692 (defun org-update-property-plist (key val props
)
4693 "Update PROPS with KEY and VAL."
4694 (let* ((appending (string= "+" (substring key
(- (length key
) 1))))
4695 (key (if appending
(substring key
0 (- (length key
) 1)) key
))
4696 (remainder (org-remove-if (lambda (p) (string= (car p
) key
)) props
))
4697 (previous (cdr (assoc key props
))))
4699 (cons (cons key
(if previous
(concat previous
" " val
) val
)) remainder
)
4700 (cons (cons key val
) remainder
))))
4702 (defconst org-block-regexp
4703 "^[ \t]*#\\+begin_?\\([^ \n]+\\)\\(\\([^\n]+\\)\\)?\n\\([^\000]+?\\)#\\+end_?\\1[ \t]*$"
4704 "Regular expression for hiding blocks.")
4705 (defconst org-heading-keyword-regexp-format
4706 "^\\(\\*+\\)\\(?: +%s\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
4707 "Printf format for a regexp matching an headline with some keyword.
4708 This regexp will match the headline of any node which has the
4709 exact keyword that is put into the format. The keyword isn't in
4710 any group by default, but the stars and the body are.")
4711 (defconst org-heading-keyword-maybe-regexp-format
4712 "^\\(\\*+\\)\\(?: +%s\\)?\\(?: +\\(.*?\\)\\)?[ \t]*$"
4713 "Printf format for a regexp matching an headline, possibly with some keyword.
4714 This regexp can match any headline with the specified keyword, or
4715 without a keyword. The keyword isn't in any group by default,
4716 but the stars and the body are.")
4718 (defun org-set-regexps-and-options ()
4719 "Precompute regular expressions for current buffer."
4720 (when (derived-mode-p 'org-mode
)
4721 (org-set-local 'org-todo-kwd-alist nil
)
4722 (org-set-local 'org-todo-key-alist nil
)
4723 (org-set-local 'org-todo-key-trigger nil
)
4724 (org-set-local 'org-todo-keywords-1 nil
)
4725 (org-set-local 'org-done-keywords nil
)
4726 (org-set-local 'org-todo-heads nil
)
4727 (org-set-local 'org-todo-sets nil
)
4728 (org-set-local 'org-todo-log-states nil
)
4729 (org-set-local 'org-file-properties nil
)
4730 (org-set-local 'org-file-tags nil
)
4731 (let ((re (org-make-options-regexp
4732 '("CATEGORY" "TODO" "COLUMNS" "STARTUP" "ARCHIVE" "FILETAGS"
4733 "TAGS" "LINK" "PRIORITIES" "CONSTANTS" "PROPERTY" "DRAWERS"
4734 "SETUPFILE" "OPTIONS")
4735 "\\(?:[a-zA-Z][0-9a-zA-Z_]*_TODO\\)"))
4737 (scripts org-use-sub-superscripts
)
4738 kwds kws0 kwsa key log value cat arch tags const links hw dws
4739 tail sep kws1 prio props ftags drawers ext-setup-or-nil setup-contents
4744 (goto-char (point-min))
4745 (while (or (and ext-setup-or-nil
4746 (string-match re ext-setup-or-nil start
)
4747 (setq start
(match-end 0)))
4748 (and (setq ext-setup-or-nil nil start
0)
4749 (re-search-forward re nil t
)))
4750 (setq key
(upcase (match-string 1 ext-setup-or-nil
))
4751 value
(org-match-string-no-properties 2 ext-setup-or-nil
))
4752 (if (stringp value
) (setq value
(org-trim value
)))
4754 ((equal key
"CATEGORY")
4756 ((member key
'("SEQ_TODO" "TODO"))
4757 (push (cons 'sequence
(org-split-string value splitre
)) kwds
))
4758 ((equal key
"TYP_TODO")
4759 (push (cons 'type
(org-split-string value splitre
)) kwds
))
4760 ((string-match "\\`\\([a-zA-Z][0-9a-zA-Z_]*\\)_TODO\\'" key
)
4761 ;; general TODO-like setup
4762 (push (cons (intern (downcase (match-string 1 key
)))
4763 (org-split-string value splitre
)) kwds
))
4765 (setq tags
(append tags
(if tags
'("\\n") nil
)
4766 (org-split-string value splitre
))))
4767 ((equal key
"COLUMNS")
4768 (org-set-local 'org-columns-default-format value
))
4770 (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value
)
4771 (push (cons (match-string 1 value
)
4772 (org-trim (match-string 2 value
)))
4774 ((equal key
"PRIORITIES")
4775 (setq prio
(org-split-string value
" +")))
4776 ((equal key
"PROPERTY")
4777 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4778 (setq props
(org-update-property-plist (match-string 1 value
)
4779 (match-string 2 value
)
4781 ((equal key
"FILETAGS")
4782 (when (string-match "\\S-" value
)
4787 (mapcar (lambda (x) (org-split-string x
":"))
4788 (org-split-string value
)))))))
4789 ((equal key
"DRAWERS")
4790 (setq drawers
(delete-dups (append org-drawers
(org-split-string value splitre
)))))
4791 ((equal key
"CONSTANTS")
4792 (setq const
(append const
(org-split-string value splitre
))))
4793 ((equal key
"STARTUP")
4794 (let ((opts (org-split-string value splitre
))
4796 (while (setq l
(pop opts
))
4797 (when (setq l
(assoc l org-startup-options
))
4798 (setq var
(nth 1 l
) val
(nth 2 l
))
4800 (set (make-local-variable var
) val
)
4801 (if (not (listp (symbol-value var
)))
4802 (set (make-local-variable var
) nil
))
4803 (set (make-local-variable var
) (symbol-value var
))
4804 (add-to-list var val
))))))
4805 ((equal key
"ARCHIVE")
4807 (remove-text-properties 0 (length arch
)
4808 '(face t fontified t
) arch
))
4809 ((equal key
"OPTIONS")
4810 (if (string-match "\\([ \t]\\|\\`\\)\\^:\\(t\\|nil\\|{}\\)" value
)
4811 (setq scripts
(read (match-string 2 value
)))))
4812 ((equal key
"SETUPFILE")
4813 (setq setup-contents
(org-file-contents
4815 (org-remove-double-quotes value
))
4817 (if (not ext-setup-or-nil
)
4818 (setq ext-setup-or-nil setup-contents start
0)
4819 (setq ext-setup-or-nil
4820 (concat (substring ext-setup-or-nil
0 start
)
4821 "\n" setup-contents
"\n"
4822 (substring ext-setup-or-nil start
)))))))
4823 ;; search for property blocks
4824 (goto-char (point-min))
4825 (while (re-search-forward org-block-regexp nil t
)
4826 (when (equal "PROPERTY" (upcase (match-string 1)))
4827 (setq value
(replace-regexp-in-string
4828 "[\n\r]" " " (match-string 4)))
4829 (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value
)
4830 (setq props
(org-update-property-plist (match-string 1 value
)
4831 (match-string 2 value
)
4833 (org-set-local 'org-use-sub-superscripts scripts
)
4835 (org-set-local 'org-category
(intern cat
))
4836 (push (cons "CATEGORY" cat
) props
))
4838 (if (< (length prio
) 3) (setq prio
'("A" "C" "B")))
4839 (setq prio
(mapcar 'string-to-char prio
))
4840 (org-set-local 'org-highest-priority
(nth 0 prio
))
4841 (org-set-local 'org-lowest-priority
(nth 1 prio
))
4842 (org-set-local 'org-default-priority
(nth 2 prio
)))
4843 (and props
(org-set-local 'org-file-properties
(nreverse props
)))
4844 (and ftags
(org-set-local 'org-file-tags
4845 (mapcar 'org-add-prop-inherited ftags
)))
4846 (and drawers
(org-set-local 'org-drawers drawers
))
4847 (and arch
(org-set-local 'org-archive-location arch
))
4848 (and links
(setq org-link-abbrev-alist-local
(nreverse links
)))
4849 ;; Process the TODO keywords
4851 ;; Use the global values as if they had been given locally.
4852 (setq kwds
(default-value 'org-todo-keywords
))
4853 (if (stringp (car kwds
))
4854 (setq kwds
(list (cons org-todo-interpretation
4855 (default-value 'org-todo-keywords
)))))
4856 (setq kwds
(reverse kwds
)))
4857 (setq kwds
(nreverse kwds
))
4859 (while (setq kws
(pop kwds
))
4861 (run-hook-with-args-until-success
4862 'org-todo-setup-filter-hook kws
)
4864 (setq inter
(pop kws
) sep
(member "|" kws
)
4865 kws0
(delete "|" (copy-sequence kws
))
4870 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x
)
4872 (setq kw
(match-string 1 x
)
4873 key
(and (match-end 2) (match-string 2 x
))
4874 log
(org-extract-log-state-settings x
))
4875 (push (cons kw
(and key
(string-to-char key
))) kwsa
)
4876 (and log
(push log org-todo-log-states
))
4878 (error "Invalid TODO keyword %s" x
)))
4880 kwsa
(if kwsa
(append '((:startgroup
))
4884 dws
(if sep
(org-remove-keyword-keys (cdr sep
)) (last kws1
))
4885 tail
(list inter hw
(car dws
) (org-last dws
))))
4886 (add-to-list 'org-todo-heads hw
'append
)
4887 (push kws1 org-todo-sets
)
4888 (setq org-done-keywords
(append org-done-keywords dws nil
))
4889 (setq org-todo-key-alist
(append org-todo-key-alist kwsa
))
4890 (mapc (lambda (x) (push (cons x tail
) org-todo-kwd-alist
)) kws1
)
4891 (setq org-todo-keywords-1
(append org-todo-keywords-1 kws1 nil
)))
4892 (setq org-todo-sets
(nreverse org-todo-sets
)
4893 org-todo-kwd-alist
(nreverse org-todo-kwd-alist
)
4894 org-todo-key-trigger
(delq nil
(mapcar 'cdr org-todo-key-alist
))
4895 org-todo-key-alist
(org-assign-fast-keys org-todo-key-alist
)))
4896 ;; Process the constants
4899 (while (setq e
(pop const
))
4900 (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e
)
4901 (push (cons (match-string 1 e
) (match-string 2 e
)) cst
)))
4902 (setq org-table-formula-constants-local cst
)))
4904 ;; Process the tags.
4907 (while (setq e
(pop tags
))
4909 ((equal e
"{") (push '(:startgroup
) tgs
))
4910 ((equal e
"}") (push '(:endgroup
) tgs
))
4911 ((equal e
"\\n") (push '(:newline
) tgs
))
4912 ((string-match (org-re "^\\([[:alnum:]_@#%]+\\)(\\(.\\))$") e
)
4913 (push (cons (match-string 1 e
)
4914 (string-to-char (match-string 2 e
)))
4916 (t (push (list e
) tgs
))))
4917 (org-set-local 'org-tag-alist nil
)
4918 (while (setq e
(pop tgs
))
4919 (or (and (stringp (car e
))
4920 (assoc (car e
) org-tag-alist
))
4921 (push e org-tag-alist
)))))
4923 ;; Compute the regular expressions and other local variables.
4924 ;; Using `org-outline-regexp-bol' would complicate them much,
4925 ;; because of the fixed white space at the end of that string.
4926 (if (not org-done-keywords
)
4927 (setq org-done-keywords
(and org-todo-keywords-1
4928 (list (org-last org-todo-keywords-1
)))))
4929 (setq org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
4930 (length org-scheduled-string
)
4931 (length org-clock-string
)
4932 (length org-closed-string
)))
4934 (concat "^[ \t]*:\\("
4935 (mapconcat 'regexp-quote org-drawers
"\\|")
4937 org-not-done-keywords
4938 (org-delete-all org-done-keywords
(copy-sequence org-todo-keywords-1
))
4941 (mapconcat 'regexp-quote org-todo-keywords-1
"\\|")
4945 (mapconcat 'regexp-quote org-not-done-keywords
"\\|")
4947 org-not-done-heading-regexp
4948 (format org-heading-keyword-regexp-format org-not-done-regexp
)
4949 org-todo-line-regexp
4950 (format org-heading-keyword-maybe-regexp-format org-todo-regexp
)
4951 org-complex-heading-regexp
4952 (concat "^\\(\\*+\\)"
4953 "\\(?: +" org-todo-regexp
"\\)?"
4954 "\\(?: +\\(\\[#.\\]\\)\\)?"
4955 "\\(?: +\\(.*?\\)\\)??"
4956 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?")
4958 org-complex-heading-regexp-format
4959 (concat "^\\(\\*+\\)"
4960 "\\(?: +" org-todo-regexp
"\\)?"
4961 "\\(?: +\\(\\[#.\\]\\)\\)?"
4963 ;; Stats cookies can be stuck to body.
4964 "\\(?:\\[[0-9%%/]+\\] *\\)?"
4966 "\\(?: *\\[[0-9%%/]+\\]\\)?"
4968 (org-re "\\(?:[ \t]+\\(:[[:alnum:]_@#%%:]+:\\)\\)?")
4970 org-todo-line-tags-regexp
4971 (concat "^\\(\\*+\\)"
4972 "\\(?: +" org-todo-regexp
"\\)?"
4973 "\\(?: +\\(.*?\\)\\)??"
4974 (org-re "\\(?:[ \t]+\\(:[[:alnum:]:_@#%]+:\\)\\)?")
4976 org-deadline-regexp
(concat "\\<" org-deadline-string
)
4977 org-deadline-time-regexp
4978 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
4979 org-deadline-line-regexp
4980 (concat "\\<\\(" org-deadline-string
"\\).*")
4981 org-scheduled-regexp
4982 (concat "\\<" org-scheduled-string
)
4983 org-scheduled-time-regexp
4984 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
4985 org-closed-time-regexp
4986 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
4987 org-keyword-time-regexp
4988 (concat "\\<\\(" org-scheduled-string
4989 "\\|" org-deadline-string
4990 "\\|" org-closed-string
4991 "\\|" org-clock-string
"\\)"
4992 " *[[<]\\([^]>]+\\)[]>]")
4993 org-keyword-time-not-clock-regexp
4994 (concat "\\<\\(" org-scheduled-string
4995 "\\|" org-deadline-string
4996 "\\|" org-closed-string
4998 " *[[<]\\([^]>]+\\)[]>]")
4999 org-maybe-keyword-time-regexp
5000 (concat "\\(\\<\\(" org-scheduled-string
5001 "\\|" org-deadline-string
5002 "\\|" org-closed-string
5003 "\\|" org-clock-string
"\\)\\)?"
5004 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)")
5005 org-all-time-keywords
5006 (mapcar (lambda (w) (substring w
0 -
1))
5007 (list org-scheduled-string org-deadline-string
5008 org-clock-string org-closed-string
)))
5009 (org-compute-latex-and-related-regexp)
5010 (org-set-font-lock-defaults))))
5012 (defun org-file-contents (file &optional noerror
)
5013 "Return the contents of FILE, as a string."
5015 (not (file-readable-p file
)))
5018 (message "Cannot read file \"%s\"" file
)
5021 (error "Cannot read file \"%s\"" file
))
5023 (insert-file-contents file
)
5026 (defun org-extract-log-state-settings (x)
5027 "Extract the log state setting from a TODO keyword string.
5028 This will extract info from a string like \"WAIT(w@/!)\"."
5029 (let (kw key log1 log2
)
5030 (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x
)
5031 (setq kw
(match-string 1 x
)
5032 key
(and (match-end 2) (match-string 2 x
))
5033 log1
(and (match-end 3) (match-string 3 x
))
5034 log2
(and (match-end 4) (match-string 4 x
)))
5037 (and log1
(if (equal log1
"!") 'time
'note
))
5038 (and log2
(if (equal log2
"!") 'time
'note
)))))))
5040 (defun org-remove-keyword-keys (list)
5041 "Remove a pair of parenthesis at the end of each string in LIST."
5043 (if (string-match "(.*)$" x
)
5044 (substring x
0 (match-beginning 0))
5048 (defun org-assign-fast-keys (alist)
5049 "Assign fast keys to a keyword-key alist.
5050 Respect keys that are already there."
5051 (let (new e
(alt ?
0))
5052 (while (setq e
(pop alist
))
5053 (if (or (memq (car e
) '(:newline
:endgroup
:startgroup
))
5054 (cdr e
)) ;; Key already assigned.
5056 (let ((clist (string-to-list (downcase (car e
))))
5057 (used (append new alist
)))
5058 (when (= (car clist
) ?
@)
5060 (while (and clist
(rassoc (car clist
) used
))
5063 (while (rassoc alt used
)
5065 (push (cons (car e
) (or (car clist
) alt
)) new
))))
5068 ;;; Some variables used in various places
5070 (defvar org-window-configuration nil
5071 "Used in various places to store a window configuration.")
5072 (defvar org-selected-window nil
5073 "Used in various places to store a window configuration.")
5074 (defvar org-finish-function nil
5075 "Function to be called when `C-c C-c' is used.
5076 This is for getting out of special buffers like capture.")
5079 ;; FIXME: Occasionally check by commenting these, to make sure
5080 ;; no other functions uses these, forgetting to let-bind them.
5081 (org-no-warnings (defvar entry
)) ;; unprefixed, from calendar.el
5082 (defvar org-last-state
)
5083 (org-no-warnings (defvar date
)) ;; unprefixed, from calendar.el
5085 ;; Defined somewhere in this file, but used before definition.
5086 (defvar org-entities
) ;; defined in org-entities.el
5087 (defvar org-struct-menu
)
5088 (defvar org-org-menu
)
5089 (defvar org-tbl-menu
)
5091 ;;;; Define the Org-mode
5093 ;; We use a before-change function to check if a table might need
5095 (defvar org-table-may-need-update t
5096 "Indicates that a table might need an update.
5097 This variable is set by `org-before-change-function'.
5098 `org-table-align' sets it back to nil.")
5099 (defun org-before-change-function (beg end
)
5100 "Every change indicates that a table might need an update."
5101 (setq org-table-may-need-update t
))
5102 (defvar org-mode-map
)
5103 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
5104 (defvar org-inhibit-startup-visibility-stuff nil
) ; Dynamically-scoped param.
5105 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
5106 (defvar org-inhibit-logging nil
) ; Dynamically-scoped param.
5107 (defvar org-inhibit-blocking nil
) ; Dynamically-scoped param.
5108 (defvar org-table-buffer-is-an nil
)
5110 (defvar bidi-paragraph-direction
)
5111 (defvar buffer-face-mode-face
)
5114 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
5115 (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"))
5116 (require 'noutline
"noutline" 'noerror
) ;; stock XEmacs does not have it
5118 ;; Other stuff we need.
5119 (require 'time-date
)
5120 (unless (fboundp 'time-subtract
) (defalias 'time-subtract
'subtract-time
))
5124 ;; (require 'org-macs) moved higher up in the file before it is first used
5125 (require 'org-entities
)
5126 ;; (require 'org-compat) moved higher up in the file before it is first used
5127 (require 'org-faces
)
5129 (require 'org-pcomplete
)
5131 (require 'org-footnote
)
5132 (require 'org-macro
)
5138 (define-derived-mode org-mode outline-mode
"Org"
5139 "Outline-based notes management and organizer, alias
5140 \"Carsten's outline-mode for keeping track of everything.\"
5142 Org-mode develops organizational tasks around a NOTES file which
5143 contains information about projects as plain text. Org-mode is
5144 implemented on top of outline-mode, which is ideal to keep the content
5145 of large files well structured. It supports ToDo items, deadlines and
5146 time stamps, which magically appear in the diary listing of the Emacs
5147 calendar. Tables are easily created with a built-in table editor.
5148 Plain text URL-like links connect to websites, emails (VM), Usenet
5149 messages (Gnus), BBDB entries, and any files related to the project.
5150 For printing and sharing of notes, an Org-mode file (or a part of it)
5151 can be exported as a structured ASCII or HTML file.
5153 The following commands are available:
5157 ;; Get rid of Outline menus, they are not needed
5158 ;; Need to do this here because define-derived-mode sets up
5159 ;; the keymap so late. Still, it is a waste to call this each time
5160 ;; we switch another buffer into org-mode.
5161 (if (featurep 'xemacs
)
5162 (when (boundp 'outline-mode-menu-heading
)
5163 ;; Assume this is Greg's port, it uses easymenu
5164 (easy-menu-remove outline-mode-menu-heading
)
5165 (easy-menu-remove outline-mode-menu-show
)
5166 (easy-menu-remove outline-mode-menu-hide
))
5167 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
5168 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
5169 (define-key org-mode-map
[menu-bar show
] 'undefined
))
5171 (org-load-modules-maybe)
5172 (easy-menu-add org-org-menu
)
5173 (easy-menu-add org-tbl-menu
)
5174 (org-install-agenda-files-menu)
5175 (if org-descriptive-links
(add-to-invisibility-spec '(org-link)))
5176 (add-to-invisibility-spec '(org-cwidth))
5177 (add-to-invisibility-spec '(org-hide-block . t
))
5178 (when (featurep 'xemacs
)
5179 (org-set-local 'line-move-ignore-invisible t
))
5180 (org-set-local 'outline-regexp org-outline-regexp
)
5181 (org-set-local 'outline-level
'org-outline-level
)
5182 (setq bidi-paragraph-direction
'left-to-right
)
5183 (when (and org-ellipsis
5184 (fboundp 'set-display-table-slot
) (boundp 'buffer-display-table
)
5185 (fboundp 'make-glyph-code
))
5186 (unless org-display-table
5187 (setq org-display-table
(make-display-table)))
5188 (set-display-table-slot
5191 (lambda (c) (make-glyph-code c
(and (not (stringp org-ellipsis
))
5193 (if (stringp org-ellipsis
) org-ellipsis
"..."))))
5194 (setq buffer-display-table org-display-table
))
5195 (org-set-regexps-and-options)
5196 (when (and org-tag-faces
(not org-tags-special-faces-re
))
5197 ;; tag faces set outside customize.... force initialization.
5198 (org-set-tag-faces 'org-tag-faces org-tag-faces
))
5200 (org-set-local 'calc-embedded-open-mode
"# ")
5201 ;; Modify a few syntax entries
5202 (modify-syntax-entry ?
< "(")
5203 (modify-syntax-entry ?
> ")")
5204 (modify-syntax-entry ?
{ "(")
5205 (modify-syntax-entry ?
} ")")
5206 (modify-syntax-entry ?
@ "w")
5207 (modify-syntax-entry ?
\" "\"")
5208 (if org-startup-truncated
(setq truncate-lines t
))
5209 (when org-startup-indented
(require 'org-indent
) (org-indent-mode 1))
5210 (org-set-local 'font-lock-unfontify-region-function
5211 'org-unfontify-region
)
5212 ;; Activate before-change-function
5213 (org-set-local 'org-table-may-need-update t
)
5214 (org-add-hook 'before-change-functions
'org-before-change-function nil
5216 ;; Check for running clock before killing a buffer
5217 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
5218 ;; Initialize macros templates.
5219 (org-macro-initialize-templates)
5220 ;; Initialize radio targets.
5221 (org-update-radio-target-regexp)
5223 (org-set-local 'indent-line-function
'org-indent-line
)
5224 (org-set-local 'indent-region-function
'org-indent-region
)
5225 ;; Filling and auto-filling.
5228 (org-setup-comments-handling)
5229 ;; Beginning/end of defun
5230 (org-set-local 'beginning-of-defun-function
'org-back-to-heading
)
5231 (org-set-local 'end-of-defun-function
(lambda () (interactive) (org-end-of-subtree nil t
)))
5232 ;; Next error for sparse trees
5233 (org-set-local 'next-error-function
'org-occur-next-match
)
5234 ;; Make sure dependence stuff works reliably, even for users who set it
5236 (if org-enforce-todo-dependencies
5237 (add-hook 'org-blocker-hook
5238 'org-block-todo-from-children-or-siblings-or-parent
)
5239 (remove-hook 'org-blocker-hook
5240 'org-block-todo-from-children-or-siblings-or-parent
))
5241 (if org-enforce-todo-checkbox-dependencies
5242 (add-hook 'org-blocker-hook
5243 'org-block-todo-from-checkboxes
)
5244 (remove-hook 'org-blocker-hook
5245 'org-block-todo-from-checkboxes
))
5247 ;; Align options lines
5249 'align-mode-rules-list
5250 '((org-in-buffer-settings
5251 (regexp .
"^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+")
5252 (modes .
'(org-mode)))))
5255 (org-set-local 'imenu-create-index-function
5256 'org-imenu-get-tree
)
5258 ;; Make isearch reveal context
5259 (if (or (featurep 'xemacs
)
5260 (not (boundp 'outline-isearch-open-invisible-function
)))
5261 ;; Emacs 21 and XEmacs make use of the hook
5262 (org-add-hook 'isearch-mode-end-hook
'org-isearch-end
'append
'local
)
5263 ;; Emacs 22 deals with this through a special variable
5264 (org-set-local 'outline-isearch-open-invisible-function
5265 (lambda (&rest ignore
) (org-show-context 'isearch
))))
5267 ;; Setup the pcomplete hooks
5268 (set (make-local-variable 'pcomplete-command-completion-function
)
5269 'org-pcomplete-initial
)
5270 (set (make-local-variable 'pcomplete-command-name-function
)
5271 'org-command-at-point
)
5272 (set (make-local-variable 'pcomplete-default-completion-function
)
5274 (set (make-local-variable 'pcomplete-parse-arguments-function
)
5275 'org-parse-arguments
)
5276 (set (make-local-variable 'pcomplete-termination-string
) "")
5277 (when (>= emacs-major-version
23)
5278 (set (make-local-variable 'buffer-face-mode-face
) 'org-default
))
5280 ;; If empty file that did not turn on org-mode automatically, make it to.
5281 (if (and org-insert-mode-line-in-empty-file
5282 (org-called-interactively-p 'any
)
5283 (= (point-min) (point-max)))
5284 (insert "# -*- mode: org -*-\n\n"))
5285 (unless org-inhibit-startup
5287 (and org-startup-with-beamer-mode
(org-beamer-mode))
5288 (when org-startup-align-all-tables
5289 (org-table-map-tables 'org-table-align
'quietly
))
5290 (when org-startup-with-inline-images
5291 (org-display-inline-images))
5292 (when org-startup-with-latex-preview
5293 (org-preview-latex-fragment))
5294 (unless org-inhibit-startup-visibility-stuff
5295 (org-set-startup-visibility))))
5296 ;; Try to set org-hide correctly
5297 (set-face-foreground 'org-hide
(org-find-invisible-foreground)))
5299 (defvar org-mode-transpose-word-syntax-table
5300 (let ((st (make-syntax-table)))
5301 (mapc (lambda(c) (modify-syntax-entry
5302 (string-to-char (car c
)) "w p" st
))
5306 (when (fboundp 'abbrev-table-put
)
5307 (abbrev-table-put org-mode-abbrev-table
5308 :parents
(list text-mode-abbrev-table
)))
5310 (put 'org-mode
'flyspell-mode-predicate
'org-mode-flyspell-verify
)
5313 (defun org-find-invisible-foreground ()
5314 (let ((candidates (remove
5317 (list (face-background 'default
)
5318 (face-background 'org-default
))
5321 (when (boundp alist
)
5322 (cdr (assoc 'background-color
(symbol-value alist
)))))
5323 '(default-frame-alist initial-frame-alist window-system-default-frame-alist
))
5324 (list (face-foreground 'org-hide
))))))
5325 (car (remove nil candidates
))))
5327 (defun org-current-time (&optional rounding-minutes
)
5328 "Current time, possibly rounded to ROUNDING-MINUTES.
5329 When ROUNDING-MINUTES is not an integer, fall back on the car of
5330 `org-time-stamp-rounding-minutes'."
5331 (let ((r (or (and (integerp rounding-minutes
) rounding-minutes
)
5332 (car org-time-stamp-rounding-minutes
)))
5333 (time (decode-time)))
5336 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
5341 "Return today date, considering `org-extend-today-until'."
5343 (time-subtract (current-time)
5344 (list 0 (* 3600 org-extend-today-until
) 0))))
5346 ;;;; Font-Lock stuff, including the activators
5348 (defvar org-mouse-map
(make-sparse-keymap))
5349 (org-defkey org-mouse-map
[mouse-2
] 'org-open-at-mouse
)
5350 (org-defkey org-mouse-map
[mouse-3
] 'org-find-file-at-mouse
)
5351 (when org-mouse-1-follows-link
5352 (org-defkey org-mouse-map
[follow-link
] 'mouse-face
))
5353 (when org-tab-follows-link
5354 (org-defkey org-mouse-map
[(tab)] 'org-open-at-point
)
5355 (org-defkey org-mouse-map
"\C-i" 'org-open-at-point
))
5357 (require 'font-lock
)
5359 (defconst org-non-link-chars
"]\t\n\r<>")
5360 (defvar org-link-types
'("http" "https" "ftp" "mailto" "file" "news"
5361 "shell" "elisp" "doi" "message"))
5362 (defvar org-link-types-re nil
5363 "Matches a link that has a url-like prefix like \"http:\"")
5364 (defvar org-link-re-with-space nil
5365 "Matches a link with spaces, optional angular brackets around it.")
5366 (defvar org-link-re-with-space2 nil
5367 "Matches a link with spaces, optional angular brackets around it.")
5368 (defvar org-link-re-with-space3 nil
5369 "Matches a link with spaces, only for internal part in bracket links.")
5370 (defvar org-angle-link-re nil
5371 "Matches link with angular brackets, spaces are allowed.")
5372 (defvar org-plain-link-re nil
5373 "Matches plain link, without spaces.")
5374 (defvar org-bracket-link-regexp nil
5375 "Matches a link in double brackets.")
5376 (defvar org-bracket-link-analytic-regexp nil
5377 "Regular expression used to analyze links.
5378 Here is what the match groups contain after a match:
5384 (defvar org-bracket-link-analytic-regexp
++ nil
5385 "Like `org-bracket-link-analytic-regexp', but include coderef internal type.")
5386 (defvar org-any-link-re nil
5387 "Regular expression matching any link.")
5389 (defconst org-match-sexp-depth
3
5390 "Number of stacked braces for sub/superscript matching.")
5392 (defun org-create-multibrace-regexp (left right n
)
5393 "Create a regular expression which will match a balanced sexp.
5394 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
5395 as single character strings.
5396 The regexp returned will match the entire expression including the
5397 delimiters. It will also define a single group which contains the
5398 match except for the outermost delimiters. The maximum depth of
5399 stacked delimiters is N. Escaping delimiters is not possible."
5400 (let* ((nothing (concat "[^" left right
"]*?"))
5403 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
5406 re
(concat re or next
)
5407 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
5408 (concat left
"\\(" re
"\\)" right
)))
5410 (defvar org-match-substring-regexp
5412 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5413 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5415 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
5417 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
5418 "The regular expression matching a sub- or superscript.")
5420 (defvar org-match-substring-with-braces-regexp
5422 "\\([^\\]\\|^\\)\\([_^]\\)\\("
5423 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
5425 "The regular expression matching a sub- or superscript, forcing braces.")
5427 (defun org-make-link-regexps ()
5428 "Update the link regular expressions.
5429 This should be called after the variable `org-link-types' has changed."
5430 (setq org-link-types-re
5432 "\\`\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):")
5433 org-link-re-with-space
5435 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5436 "\\([^" org-non-link-chars
" ]"
5437 "[^" org-non-link-chars
"]*"
5438 "[^" org-non-link-chars
" ]\\)>?")
5439 org-link-re-with-space2
5441 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5442 "\\([^" org-non-link-chars
" ]"
5444 "[^" org-non-link-chars
" ]\\)>?")
5445 org-link-re-with-space3
5447 "<?\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5448 "\\([^" org-non-link-chars
" ]"
5452 "<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5453 "\\([^" org-non-link-chars
" ]"
5454 "[^" org-non-link-chars
"]*"
5458 "\\<\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):"
5459 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
5460 ;; "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
5461 org-bracket-link-regexp
5462 "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
5463 org-bracket-link-analytic-regexp
5466 "\\(\\(" (mapconcat 'regexp-quote org-link-types
"\\|") "\\):\\)?"
5469 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5471 org-bracket-link-analytic-regexp
++
5474 "\\(\\(" (mapconcat 'regexp-quote
(cons "coderef" org-link-types
) "\\|") "\\):\\)?"
5477 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
5480 (concat "\\(" org-bracket-link-regexp
"\\)\\|\\("
5481 org-angle-link-re
"\\)\\|\\("
5482 org-plain-link-re
"\\)")))
5484 (org-make-link-regexps)
5486 (defconst org-ts-regexp
"<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)>"
5487 "Regular expression for fast time stamp matching.")
5488 (defconst org-ts-regexp-both
"[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?\\)[]>]"
5489 "Regular expression for fast time stamp matching.")
5490 (defconst org-ts-regexp0
5491 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9>\r\n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5492 "Regular expression matching time strings for analysis.
5493 This one does not require the space after the date, so it can be used
5494 on a string that terminates immediately after the date.")
5495 (defconst org-ts-regexp1
"\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
5496 "Regular expression matching time strings for analysis.")
5497 (defconst org-ts-regexp2
(concat "<" org-ts-regexp1
"[^>\n]\\{0,16\\}>")
5498 "Regular expression matching time stamps, with groups.")
5499 (defconst org-ts-regexp3
(concat "[[<]" org-ts-regexp1
"[^]>\n]\\{0,16\\}[]>]")
5500 "Regular expression matching time stamps (also [..]), with groups.")
5501 (defconst org-tr-regexp
(concat org-ts-regexp
"--?-?" org-ts-regexp
)
5502 "Regular expression matching a time stamp range.")
5503 (defconst org-tr-regexp-both
5504 (concat org-ts-regexp-both
"--?-?" org-ts-regexp-both
)
5505 "Regular expression matching a time stamp range.")
5506 (defconst org-tsr-regexp
(concat org-ts-regexp
"\\(--?-?"
5507 org-ts-regexp
"\\)?")
5508 "Regular expression matching a time stamp or time stamp range.")
5509 (defconst org-tsr-regexp-both
(concat org-ts-regexp-both
"\\(--?-?"
5510 org-ts-regexp-both
"\\)?")
5511 "Regular expression matching a time stamp or time stamp range.
5512 The time stamps may be either active or inactive.")
5514 (defvar org-emph-face nil
)
5516 (defun org-do-emphasis-faces (limit)
5517 "Run through the buffer and add overlays to emphasized strings."
5519 (while (and (not rtn
) (re-search-forward org-emph-re limit t
))
5520 (if (not (= (char-after (match-beginning 3))
5521 (char-after (match-beginning 4))))
5524 (setq a
(assoc (match-string 3) org-emphasis-alist
))
5525 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
5529 (org-remove-flyspell-overlays-in
5530 (match-beginning 0) (match-end 0)))
5531 (add-text-properties (match-beginning 2) (match-end 2)
5532 '(font-lock-multiline t org-emphasis t
))
5533 (when org-hide-emphasis-markers
5534 (add-text-properties (match-end 4) (match-beginning 5)
5535 '(invisible org-link
))
5536 (add-text-properties (match-beginning 3) (match-end 3)
5537 '(invisible org-link
)))))
5541 (defun org-emphasize (&optional char
)
5542 "Insert or change an emphasis, i.e. a font like bold or italic.
5543 If there is an active region, change that region to a new emphasis.
5544 If there is no region, just insert the marker characters and position
5545 the cursor between them.
5546 CHAR should be either the marker character, or the first character of the
5547 HTML tag associated with that emphasis. If CHAR is a space, the means
5548 to remove the emphasis of the selected region.
5549 If char is not given (for example in an interactive call) it
5550 will be prompted for."
5552 (let ((eal org-emphasis-alist
) e det
5553 (erc org-emphasis-regexp-components
)
5555 (string "") beg end move tag c s
)
5556 (if (org-region-active-p)
5557 (setq beg
(region-beginning) end
(region-end)
5558 string
(buffer-substring beg end
))
5561 (while (setq e
(pop eal
))
5562 (setq tag
(car (org-split-string (nth 2 e
) "[ <>/]+"))
5564 (push (cons c
(string-to-char (car e
))) det
)
5565 (setq prompt
(concat prompt
(format " [%s%c]%s" (car e
) c
5566 (substring tag
1)))))
5567 (setq det
(nreverse det
))
5569 (message "%s" (concat "Emphasis marker or tag:" prompt
))
5570 (setq char
(read-char-exclusive)))
5571 (setq char
(or (cdr (assoc char det
)) char
))
5572 (if (equal char ?\
)
5573 (setq s
"" move nil
)
5574 (unless (assoc (char-to-string char
) org-emphasis-alist
)
5575 (error "No such emphasis marker: \"%c\"" char
))
5576 (setq s
(char-to-string char
)))
5577 (while (and (> (length string
) 1)
5578 (equal (substring string
0 1) (substring string -
1))
5579 (assoc (substring string
0 1) org-emphasis-alist
))
5580 (setq string
(substring string
1 -
1)))
5581 (setq string
(concat s string s
))
5582 (if beg
(delete-region beg end
))
5584 (string-match (concat "[" (nth 0 erc
) "\n]")
5585 (char-to-string (char-before (point)))))
5588 (string-match (concat "[" (nth 1 erc
) "\n]")
5589 (char-to-string (char-after (point)))))
5590 (insert " ") (backward-char 1))
5592 (and move
(backward-char 1))))
5594 (defconst org-nonsticky-props
5595 '(mouse-face highlight keymap invisible intangible help-echo org-linked-text htmlize-link
))
5597 (defsubst org-rear-nonsticky-at
(pos)
5598 (add-text-properties (1- pos
) pos
(list 'rear-nonsticky org-nonsticky-props
)))
5600 (defun org-activate-plain-links (limit)
5601 "Run through the buffer and add overlays to links."
5604 (when (and (re-search-forward (concat org-plain-link-re
) limit t
)
5605 (not (org-in-src-block-p)))
5606 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5607 (setq f
(get-text-property (match-beginning 0) 'face
))
5608 (setq hl
(org-match-string-no-properties 0))
5609 (if (or (eq f
'org-tag
)
5610 (and (listp f
) (memq 'org-tag f
)))
5612 (add-text-properties (match-beginning 0) (match-end 0)
5613 (list 'mouse-face
'highlight
5615 'htmlize-link
`(:uri
,hl
)
5616 'keymap org-mouse-map
))
5617 (org-rear-nonsticky-at (match-end 0)))
5620 (defun org-activate-code (limit)
5621 (if (re-search-forward "^[ \t]*\\(:\\(?: .*\\|$\\)\n?\\)" limit t
)
5623 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5624 (remove-text-properties (match-beginning 0) (match-end 0)
5625 '(display t invisible t intangible t
))
5628 (defcustom org-src-fontify-natively nil
5629 "When non-nil, fontify code in code blocks."
5632 :group
'org-appearance
5635 (defcustom org-allow-promoting-top-level-subtree nil
5636 "When non-nil, allow promoting a top level subtree.
5637 The leading star of the top level headline will be replaced
5641 :group
'org-appearance
)
5643 (defun org-fontify-meta-lines-and-blocks (limit)
5645 (org-fontify-meta-lines-and-blocks-1 limit
)
5646 (error (message "org-mode fontification error"))))
5648 (defun org-fontify-meta-lines-and-blocks-1 (limit)
5649 "Fontify #+ lines and blocks, in the correct ways."
5650 (let ((case-fold-search t
))
5651 (if (re-search-forward
5652 "^\\([ \t]*#\\(\\(\\+[a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
5654 (let ((beg (match-beginning 0))
5655 (block-start (match-end 0))
5657 (lang (match-string 7))
5658 (beg1 (line-beginning-position 2))
5659 (dc1 (downcase (match-string 2)))
5660 (dc3 (downcase (match-string 3)))
5661 end end1 quoting block-type ovl
)
5663 ((member dc1
'("+html:" "+ascii:" "+latex:"))
5664 ;; a single line of backend-specific content
5665 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5666 (remove-text-properties (match-beginning 0) (match-end 0)
5667 '(display t invisible t intangible t
))
5668 (add-text-properties (match-beginning 1) (match-end 3)
5669 '(font-lock-fontified t face org-meta-line
))
5670 (add-text-properties (match-beginning 6) (+ (match-end 6) 1)
5671 '(font-lock-fontified t face org-block
))
5672 ; for backend-specific code
5674 ((and (match-end 4) (equal dc3
"+begin"))
5676 (setq block-type
(downcase (match-string 5))
5677 quoting
(member block-type org-protecting-blocks
))
5678 (when (re-search-forward
5679 (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
5680 nil t
) ;; on purpose, we look further than LIMIT
5681 (setq end
(min (point-max) (match-end 0))
5682 end1
(min (point-max) (1- (match-beginning 0))))
5683 (setq block-end
(match-beginning 0))
5685 (remove-text-properties beg end
5686 '(display t invisible t intangible t
)))
5687 (add-text-properties
5689 '(font-lock-fontified t font-lock-multiline t
))
5690 (add-text-properties beg beg1
'(face org-meta-line
))
5691 (add-text-properties end1
(min (point-max) (1+ end
))
5692 '(face org-meta-line
)) ; for end_src
5694 ((and lang
(not (string= lang
"")) org-src-fontify-natively
)
5695 (org-src-font-lock-fontify-block lang block-start block-end
)
5696 ;; remove old background overlays
5698 (if (eq (overlay-get ov
'face
) 'org-block-background
)
5699 (delete-overlay ov
)))
5700 (overlays-at (/ (+ beg1 block-end
) 2)))
5701 ;; add a background overlay
5702 (setq ovl
(make-overlay beg1 block-end
))
5703 (overlay-put ovl
'face
'org-block-background
)
5704 (overlay-put ovl
'evaporate t
)) ;; make it go away when empty
5706 (add-text-properties beg1
(min (point-max) (1+ end1
))
5707 '(face org-block
))) ; end of source block
5708 ((not org-fontify-quote-and-verse-blocks
))
5709 ((string= block-type
"quote")
5710 (add-text-properties beg1
(min (point-max) (1+ end1
)) '(face org-quote
)))
5711 ((string= block-type
"verse")
5712 (add-text-properties beg1
(min (point-max) (1+ end1
)) '(face org-verse
))))
5713 (add-text-properties beg beg1
'(face org-block-begin-line
))
5714 (add-text-properties (min (point-max) (1+ end
)) (min (point-max) (1+ end1
))
5715 '(face org-block-end-line
))
5717 ((member dc1
'("+title:" "+author:" "+email:" "+date:"))
5718 (add-text-properties
5720 (if (member (intern (substring dc1
0 -
1)) org-hidden-keywords
)
5721 '(font-lock-fontified t invisible t
)
5722 '(font-lock-fontified t face org-document-info-keyword
)))
5723 (add-text-properties
5724 (match-beginning 6) (min (point-max) (1+ (match-end 6)))
5725 (if (string-equal dc1
"+title:")
5726 '(font-lock-fontified t face org-document-title
)
5727 '(font-lock-fontified t face org-document-info
))))
5728 ((or (equal dc1
"+results")
5729 (member dc1
'("+begin:" "+end:" "+caption:" "+label:"
5730 "+orgtbl:" "+tblfm:" "+tblname:" "+results:"
5731 "+call:" "+header:" "+headers:" "+name:"))
5732 (and (match-end 4) (equal dc3
"+attr")))
5733 (add-text-properties
5735 '(font-lock-fontified t face org-meta-line
))
5737 ((member dc3
'(" " ""))
5738 (add-text-properties
5740 '(font-lock-fontified t face font-lock-comment-face
)))
5741 ((not (member (char-after beg
) '(?\ ?
\t)))
5742 ;; just any other in-buffer setting, but not indented
5743 (add-text-properties
5745 '(font-lock-fontified t face org-meta-line
))
5749 (defun org-activate-angle-links (limit)
5750 "Run through the buffer and add overlays to links."
5751 (if (and (re-search-forward org-angle-link-re limit t
)
5752 (not (org-in-src-block-p)))
5754 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5755 (add-text-properties (match-beginning 0) (match-end 0)
5756 (list 'mouse-face
'highlight
5757 'keymap org-mouse-map
))
5758 (org-rear-nonsticky-at (match-end 0))
5761 (defun org-activate-footnote-links (limit)
5762 "Run through the buffer and add overlays to footnotes."
5763 (let ((fn (org-footnote-next-reference-or-definition limit
)))
5765 (let ((beg (nth 1 fn
)) (end (nth 2 fn
)))
5766 (org-remove-flyspell-overlays-in beg end
)
5767 (add-text-properties beg end
5768 (list 'mouse-face
'highlight
5769 'keymap org-mouse-map
5771 (if (= (point-at-bol) beg
)
5772 "Footnote definition"
5773 "Footnote reference")
5774 'font-lock-fontified t
5775 'font-lock-multiline t
5776 'face
'org-footnote
))))))
5778 (defun org-activate-bracket-links (limit)
5779 "Run through the buffer and add overlays to bracketed links."
5780 (if (and (re-search-forward org-bracket-link-regexp limit t
)
5781 (not (org-in-src-block-p)))
5782 (let* ((hl (org-match-string-no-properties 1))
5783 (help (concat "LINK: " hl
))
5784 ;; FIXME: Above we should remove the escapes. But that
5785 ;; requires another match, protecting match data, a lot
5786 ;; of overhead for font-lock.
5787 (ip (org-maybe-intangible
5788 (list 'invisible
'org-link
5789 'keymap org-mouse-map
'mouse-face
'highlight
5790 'font-lock-multiline t
'help-echo help
5791 'htmlize-link
`(:uri
,hl
))))
5792 (vp (list 'keymap org-mouse-map
'mouse-face
'highlight
5793 'font-lock-multiline t
'help-echo help
5794 'htmlize-link
`(:uri
,hl
))))
5795 ;; We need to remove the invisible property here. Table narrowing
5796 ;; may have made some of this invisible.
5797 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5798 (remove-text-properties (match-beginning 0) (match-end 0)
5802 (add-text-properties (match-beginning 0) (match-beginning 3) ip
)
5803 (org-rear-nonsticky-at (match-beginning 3))
5804 (add-text-properties (match-beginning 3) (match-end 3) vp
)
5805 (org-rear-nonsticky-at (match-end 3))
5806 (add-text-properties (match-end 3) (match-end 0) ip
)
5807 (org-rear-nonsticky-at (match-end 0)))
5808 (add-text-properties (match-beginning 0) (match-beginning 1) ip
)
5809 (org-rear-nonsticky-at (match-beginning 1))
5810 (add-text-properties (match-beginning 1) (match-end 1) vp
)
5811 (org-rear-nonsticky-at (match-end 1))
5812 (add-text-properties (match-end 1) (match-end 0) ip
)
5813 (org-rear-nonsticky-at (match-end 0)))
5816 (defun org-activate-dates (limit)
5817 "Run through the buffer and add overlays to dates."
5818 (if (re-search-forward org-tsr-regexp-both limit t
)
5820 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5821 (add-text-properties (match-beginning 0) (match-end 0)
5822 (list 'mouse-face
'highlight
5823 'keymap org-mouse-map
))
5824 (org-rear-nonsticky-at (match-end 0))
5825 (when org-display-custom-times
5827 (org-display-custom-time (match-beginning 3) (match-end 3)))
5828 (org-display-custom-time (match-beginning 1) (match-end 1)))
5831 (defvar org-target-link-regexp nil
5832 "Regular expression matching radio targets in plain text.")
5833 (make-variable-buffer-local 'org-target-link-regexp
)
5834 (defvar org-target-regexp
"<<\\([^<>\n\r]+\\)>>"
5835 "Regular expression matching a link target.")
5836 (defvar org-radio-target-regexp
"<<<\\([^<>\n\r]+\\)>>>"
5837 "Regular expression matching a radio target.")
5838 (defvar org-any-target-regexp
"<<<?\\([^<>\n\r]+\\)>>>?" ; FIXME, not exact, would match <<<aaa>> as a radio target.
5839 "Regular expression matching any target.")
5841 (defun org-activate-target-links (limit)
5842 "Run through the buffer and add overlays to target matches."
5843 (when org-target-link-regexp
5844 (let ((case-fold-search t
))
5845 (if (re-search-forward org-target-link-regexp limit t
)
5847 (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
5848 (add-text-properties (match-beginning 0) (match-end 0)
5849 (list 'mouse-face
'highlight
5850 'keymap org-mouse-map
5851 'help-echo
"Radio target link"
5852 'org-linked-text t
))
5853 (org-rear-nonsticky-at (match-end 0))
5856 (defun org-update-radio-target-regexp ()
5857 "Find all radio targets in this file and update the regular expression."
5859 (when (memq 'radio org-activate-links
)
5860 (setq org-target-link-regexp
5861 (org-make-target-link-regexp (org-all-targets 'radio
)))
5862 (org-restart-font-lock)))
5864 (defun org-hide-wide-columns (limit)
5866 (setq s
(text-property-any (point) (or limit
(point-max))
5869 (setq e
(next-single-property-change s
'org-cwidth
))
5870 (add-text-properties s e
(org-maybe-intangible '(invisible org-cwidth
)))
5874 (defvar org-latex-and-related-regexp nil
5875 "Regular expression for highlighting LaTeX, entities and sub/superscript.")
5876 (defvar org-match-substring-regexp
)
5877 (defvar org-match-substring-with-braces-regexp
)
5879 (defun org-compute-latex-and-related-regexp ()
5880 "Compute regular expression for LaTeX, entities and sub/superscript.
5881 Result depends on variable `org-highlight-latex-and-related'."
5883 'org-latex-and-related-regexp
5885 (cond ((not (memq 'script org-highlight-latex-and-related
)) nil
)
5886 ((eq org-use-sub-superscripts
'{})
5887 (list org-match-substring-with-braces-regexp
))
5888 (org-use-sub-superscripts (list org-match-substring-regexp
))))
5890 (when (memq 'latex org-highlight-latex-and-related
)
5891 (let ((matchers (plist-get org-format-latex-options
:matchers
)))
5894 (and (member (car x
) matchers
) (nth 1 x
)))
5895 org-latex-regexps
)))))
5897 (when (memq 'entities org-highlight-latex-and-related
)
5898 (list "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]]\\)"))))
5899 (mapconcat 'identity
(append re-latex re-entities re-sub
) "\\|"))))
5901 (defun org-do-latex-and-related (limit)
5902 "Highlight LaTeX snippets and environments, entities and sub/superscript.
5903 LIMIT bounds the search for syntax to highlight. Stop at first
5904 highlighted object, if any. Return t if some highlighting was
5905 done, nil otherwise."
5906 (when org-highlight-latex-and-related
5908 (while (re-search-forward org-latex-and-related-regexp limit t
)
5909 (unless (memq (car-safe (get-text-property (1+ (match-beginning 0))
5911 '(org-code org-verbatim underline
))
5912 (let ((offset (if (memq (char-after (1+ (match-beginning 0)))
5916 (font-lock-prepend-text-property
5917 (+ offset
(match-beginning 0)) (match-end 0)
5918 'face
'org-latex-and-related
)
5919 (add-text-properties (+ offset
(match-beginning 0)) (match-end 0)
5920 '(font-lock-multiline t
)))
5924 (defun org-restart-font-lock ()
5925 "Restart `font-lock-mode', to force refontification."
5926 (when (and (boundp 'font-lock-mode
) font-lock-mode
)
5928 (font-lock-mode 1)))
5930 (defun org-all-targets (&optional radio
)
5931 "Return a list of all targets in this file.
5932 When optional argument RADIO is non-nil, only find radio
5934 (let ((re (if radio org-radio-target-regexp org-target-regexp
)) rtn
)
5936 (goto-char (point-min))
5937 (while (re-search-forward re nil t
)
5938 ;; Make sure point is really within the object.
5940 (let ((obj (org-element-context)))
5941 (when (memq (org-element-type obj
) '(radio-target target
))
5942 (add-to-list 'rtn
(downcase (org-element-property :value obj
))))))
5945 (defun org-make-target-link-regexp (targets)
5946 "Make regular expression matching all strings in TARGETS.
5947 The regular expression finds the targets also if there is a line break
5954 (setq x
(regexp-quote x
))
5955 (while (string-match " +" x
)
5956 (setq x
(replace-match "\\s-+" t t x
)))
5962 (defun org-activate-tags (limit)
5963 (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t
)
5965 (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1))
5966 (add-text-properties (match-beginning 1) (match-end 1)
5967 (list 'mouse-face
'highlight
5968 'keymap org-mouse-map
))
5969 (org-rear-nonsticky-at (match-end 1))
5972 (defun org-outline-level ()
5973 "Compute the outline level of the heading at point.
5974 If this is called at a normal headline, the level is the number of stars.
5975 Use `org-reduced-level' to remove the effect of `org-odd-levels'."
5977 (if (not (condition-case nil
5978 (org-back-to-heading t
)
5981 (looking-at org-outline-regexp
)
5982 (1- (- (match-end 0) (match-beginning 0))))))
5984 (defvar org-font-lock-keywords nil
)
5986 (defconst org-property-re
(org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\+?\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
5987 "Regular expression matching a property line.")
5989 (defvar org-font-lock-hook nil
5990 "Functions to be called for special font lock stuff.")
5992 (defvar org-font-lock-set-keywords-hook nil
5993 "Functions that can manipulate `org-font-lock-extra-keywords'.
5994 This is called after `org-font-lock-extra-keywords' is defined, but before
5995 it is installed to be used by font lock. This can be useful if something
5996 needs to be inserted at a specific position in the font-lock sequence.")
5998 (defun org-font-lock-hook (limit)
5999 "Run `org-font-lock-hook' within LIMIT."
6000 (run-hook-with-args 'org-font-lock-hook limit
))
6002 (defun org-set-font-lock-defaults ()
6003 "Set font lock defaults for the current buffer."
6004 (let* ((em org-fontify-emphasized-text
)
6005 (lk org-activate-links
)
6006 (org-font-lock-extra-keywords
6009 '(org-font-lock-hook)
6011 `(,(if org-fontify-whole-heading-line
6012 "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
6013 "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
6014 (1 (org-get-level-face 1))
6015 (2 (org-get-level-face 2))
6016 (3 (org-get-level-face 3)))
6018 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
6021 '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t
))
6022 '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t
))
6023 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t
))
6024 '("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t
))
6026 (list org-drawer-regexp
'(0 'org-special-keyword t
))
6027 (list "^[ \t]*:END:" '(0 'org-special-keyword t
))
6029 (list org-property-re
6030 '(1 'org-special-keyword t
)
6031 '(3 'org-property-value t
))
6033 (if (memq 'tag lk
) '(org-activate-tags (1 'org-tag prepend
)))
6034 (if (memq 'angle lk
) '(org-activate-angle-links (0 'org-link t
)))
6035 (if (memq 'plain lk
) '(org-activate-plain-links))
6036 (if (memq 'bracket lk
) '(org-activate-bracket-links (0 'org-link t
)))
6037 (if (memq 'radio lk
) '(org-activate-target-links (0 'org-link t
)))
6038 (if (memq 'date lk
) '(org-activate-dates (0 'org-date t
)))
6039 (if (memq 'footnote lk
) '(org-activate-footnote-links))
6040 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t
))
6041 '(org-hide-wide-columns (0 nil append
))
6043 (list (format org-heading-keyword-regexp-format
6045 '(2 (org-get-todo-face 2) t
))
6047 (if org-fontify-done-headline
6048 (list (format org-heading-keyword-regexp-format
6051 (mapconcat 'regexp-quote org-done-keywords
"\\|")
6053 '(2 'org-headline-done t
))
6056 '(org-font-lock-add-priority-faces)
6058 '(org-font-lock-add-tag-faces)
6060 (list (concat "\\<" org-deadline-string
) '(0 'org-special-keyword t
))
6061 (list (concat "\\<" org-scheduled-string
) '(0 'org-special-keyword t
))
6062 (list (concat "\\<" org-closed-string
) '(0 'org-special-keyword t
))
6063 (list (concat "\\<" org-clock-string
) '(0 'org-special-keyword t
))
6066 (if (featurep 'xemacs
)
6067 '(org-do-emphasis-faces (0 nil append
))
6068 '(org-do-emphasis-faces)))
6070 '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
6071 1 'org-checkbox prepend
)
6072 (if (cdr (assq 'checkbox org-list-automatic-rules
))
6073 '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
6074 (0 (org-get-checkbox-statistics-face) t
)))
6075 ;; Description list items
6076 '("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+::\\)\\([ \t]+\\|$\\)"
6077 1 'org-list-dt prepend
)
6078 ;; ARCHIVEd headings
6080 org-outline-regexp-bol
6081 "\\(.*:" org-archive-tag
":.*\\)")
6082 '(1 'org-archived prepend
))
6084 '(org-do-latex-and-related)
6085 '(org-fontify-entities)
6086 '(org-raise-scripts)
6088 '(org-activate-code (1 'org-code t
))
6090 (list (format org-heading-keyword-regexp-format
6092 org-comment-string
"\\|" org-quote-string
6094 '(2 'org-special-keyword t
))
6095 ;; Blocks and meta lines
6096 '(org-fontify-meta-lines-and-blocks)
6098 (setq org-font-lock-extra-keywords
(delq nil org-font-lock-extra-keywords
))
6099 (run-hooks 'org-font-lock-set-keywords-hook
)
6100 ;; Now set the full font-lock-keywords
6101 (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords
)
6102 (org-set-local 'font-lock-defaults
6103 '(org-font-lock-keywords t nil nil backward-paragraph
))
6104 (kill-local-variable 'font-lock-keywords
) nil
))
6106 (defun org-toggle-pretty-entities ()
6107 "Toggle the composition display of entities as UTF8 characters."
6109 (org-set-local 'org-pretty-entities
(not org-pretty-entities
))
6110 (org-restart-font-lock)
6111 (if org-pretty-entities
6112 (message "Entities are displayed as UTF8 characters")
6115 (org-decompose-region (point-min) (point-max))
6116 (message "Entities are displayed plain"))))
6118 (defvar org-custom-properties-overlays nil
6119 "List of overlays used for custom properties.")
6120 (make-variable-buffer-local 'org-custom-properties-overlays
)
6122 (defun org-toggle-custom-properties-visibility ()
6123 "Display or hide properties in `org-custom-properties'."
6125 (if org-custom-properties-overlays
6126 (progn (mapc 'delete-overlay org-custom-properties-overlays
)
6127 (setq org-custom-properties-overlays nil
))
6128 (unless (not org-custom-properties
)
6132 (goto-char (point-min))
6133 (while (re-search-forward org-property-re nil t
)
6135 (when (equal p
(substring (match-string 1) 1 -
1))
6136 (let ((o (make-overlay (match-beginning 0) (1+ (match-end 0)))))
6137 (overlay-put o
'invisible t
)
6138 (overlay-put o
'org-custom-property t
)
6139 (push o org-custom-properties-overlays
))))
6140 org-custom-properties
)))))))
6142 (defun org-fontify-entities (limit)
6143 "Find an entity to fontify."
6145 (when org-pretty-entities
6147 (while (re-search-forward
6148 "\\\\\\(there4\\|sup[123]\\|frac[13][24]\\|[a-zA-Z]+\\)\\($\\|{}\\|[^[:alpha:]\n]\\)"
6150 (if (and (not (org-in-indented-comment-line))
6151 (setq ee
(org-entity-get (match-string 1)))
6152 (= (length (nth 6 ee
)) 1))
6154 ((end (if (equal (match-string 2) "{}")
6157 (add-text-properties
6158 (match-beginning 0) end
6159 (list 'font-lock-fontified t
))
6160 (compose-region (match-beginning 0) end
6166 (defun org-fontify-like-in-org-mode (s &optional odd-levels
)
6167 "Fontify string S like in Org-mode."
6170 (let ((org-odd-levels-only odd-levels
))
6172 (font-lock-fontify-buffer)
6178 (defun org-get-level-face (n)
6179 "Get the right face for match N in font-lock matching of headlines."
6180 (setq org-l
(- (match-end 2) (match-beginning 1) 1))
6181 (if org-odd-levels-only
(setq org-l
(1+ (/ org-l
2))))
6182 (if org-cycle-level-faces
6183 (setq org-f
(nth (%
(1- org-l
) org-n-level-faces
) org-level-faces
))
6184 (setq org-f
(nth (1- (min org-l org-n-level-faces
)) org-level-faces
)))
6186 ((eq n
1) (if org-hide-leading-stars
'org-hide org-f
))
6188 (t (if org-level-color-stars-only nil org-f
))))
6191 (defun org-get-todo-face (kwd)
6192 "Get the right face for a TODO keyword KWD.
6193 If KWD is a number, get the corresponding match group."
6194 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
6195 (or (org-face-from-face-or-color
6196 'todo
'org-todo
(cdr (assoc kwd org-todo-keyword-faces
)))
6197 (and (member kwd org-done-keywords
) 'org-done
)
6200 (defun org-face-from-face-or-color (context inherit face-or-color
)
6201 "Create a face list that inherits INHERIT, but sets the foreground color.
6202 When FACE-OR-COLOR is not a string, just return it."
6203 (if (stringp face-or-color
)
6204 (list :inherit inherit
6205 (cdr (assoc context org-faces-easy-properties
))
6209 (defun org-font-lock-add-tag-faces (limit)
6210 "Add the special tag faces."
6211 (when (and org-tag-faces org-tags-special-faces-re
)
6212 (while (re-search-forward org-tags-special-faces-re limit t
)
6213 (add-text-properties (match-beginning 1) (match-end 1)
6214 (list 'face
(org-get-tag-face 1)
6215 'font-lock-fontified t
))
6216 (backward-char 1))))
6218 (defun org-font-lock-add-priority-faces (limit)
6219 "Add the special priority faces."
6220 (while (re-search-forward "\\[#\\([A-Z0-9]\\)\\]" limit t
)
6221 (when (save-match-data (org-at-heading-p))
6222 (add-text-properties
6223 (match-beginning 0) (match-end 0)
6224 (list 'face
(or (org-face-from-face-or-color
6225 'priority
'org-priority
6226 (cdr (assoc (char-after (match-beginning 1))
6227 org-priority-faces
)))
6229 'font-lock-fontified t
)))))
6231 (defun org-get-tag-face (kwd)
6232 "Get the right face for a TODO keyword KWD.
6233 If KWD is a number, get the corresponding match group."
6234 (if (numberp kwd
) (setq kwd
(match-string kwd
)))
6235 (or (org-face-from-face-or-color
6236 'tag
'org-tag
(cdr (assoc kwd org-tag-faces
)))
6239 (defun org-unfontify-region (beg end
&optional maybe_loudly
)
6240 "Remove fontification and activation overlays from links."
6241 (font-lock-default-unfontify-region beg end
)
6242 (let* ((buffer-undo-list t
)
6243 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
6244 (inhibit-modification-hooks t
)
6245 deactivate-mark buffer-file-name buffer-file-truename
)
6246 (org-decompose-region beg end
)
6247 (remove-text-properties beg end
6248 '(mouse-face t keymap t org-linked-text t
6249 invisible t intangible t
6250 org-no-flyspell t org-emphasis t
))
6251 (org-remove-font-lock-display-properties beg end
)))
6253 (defconst org-script-display
'(((raise -
0.3) (height 0.7))
6254 ((raise 0.3) (height 0.7))
6257 "Display properties for showing superscripts and subscripts.")
6259 (defun org-remove-font-lock-display-properties (beg end
)
6260 "Remove specific display properties that have been added by font lock.
6261 The will remove the raise properties that are used to show superscripts
6265 (setq next
(next-single-property-change beg
'display nil end
)
6266 prop
(get-text-property beg
'display
))
6267 (if (member prop org-script-display
)
6268 (put-text-property beg next
'display nil
))
6271 (defun org-raise-scripts (limit)
6272 "Add raise properties to sub/superscripts."
6273 (when (and org-pretty-entities org-pretty-entities-include-sub-superscripts
)
6274 (if (re-search-forward
6275 (if (eq org-use-sub-superscripts t
)
6276 org-match-substring-regexp
6277 org-match-substring-with-braces-regexp
)
6279 (let* ((pos (point)) table-p comment-p
6280 (mpos (match-beginning 3))
6281 (emph-p (get-text-property mpos
'org-emphasis
))
6282 (link-p (get-text-property mpos
'mouse-face
))
6283 (keyw-p (eq 'org-special-keyword
(get-text-property mpos
'face
))))
6284 (goto-char (point-at-bol))
6285 (setq table-p
(org-looking-at-p org-table-dataline-regexp
)
6286 comment-p
(org-looking-at-p "[ \t]*#"))
6288 ;; FIXME: Should we go back one character here, for a_b^c
6289 ;; (goto-char (1- pos)) ;????????????????????
6290 (if (or comment-p emph-p link-p keyw-p
)
6292 (put-text-property (match-beginning 3) (match-end 0)
6294 (if (equal (char-after (match-beginning 2)) ?^
)
6295 (nth (if table-p
3 1) org-script-display
)
6296 (nth (if table-p
2 0) org-script-display
)))
6297 (add-text-properties (match-beginning 2) (match-end 2)
6299 'org-dwidth t
'org-dwidth-n
1))
6300 (if (and (eq (char-after (match-beginning 3)) ?
{)
6301 (eq (char-before (match-end 3)) ?
}))
6303 (add-text-properties
6304 (match-beginning 3) (1+ (match-beginning 3))
6305 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))
6306 (add-text-properties
6307 (1- (match-end 3)) (match-end 3)
6308 (list 'invisible t
'org-dwidth t
'org-dwidth-n
1))))
6311 ;;;; Visibility cycling, including org-goto and indirect buffer
6315 (defvar org-cycle-global-status nil
)
6316 (make-variable-buffer-local 'org-cycle-global-status
)
6317 (put 'org-cycle-global-status
'org-state t
)
6318 (defvar org-cycle-subtree-status nil
)
6319 (make-variable-buffer-local 'org-cycle-subtree-status
)
6320 (put 'org-cycle-subtree-status
'org-state t
)
6322 (defvar org-inlinetask-min-level
)
6325 (defun org-cycle (&optional arg
)
6326 "TAB-action and visibility cycling for Org-mode.
6328 This is the command invoked in Org-mode by the TAB key. Its main purpose
6329 is outline visibility cycling, but it also invokes other actions
6330 in special contexts.
6332 - When this function is called with a prefix argument, rotate the entire
6333 buffer through 3 states (global cycling)
6334 1. OVERVIEW: Show only top-level headlines.
6335 2. CONTENTS: Show all headlines of all levels, but no body text.
6336 3. SHOW ALL: Show everything.
6337 When called with two `C-u C-u' prefixes, switch to the startup visibility,
6338 determined by the variable `org-startup-folded', and by any VISIBILITY
6339 properties in the buffer.
6340 When called with three `C-u C-u C-u' prefixed, show the entire buffer,
6341 including any drawers.
6343 - When inside a table, re-align the table and move to the next field.
6345 - When point is at the beginning of a headline, rotate the subtree started
6346 by this line through 3 different states (local cycling)
6347 1. FOLDED: Only the main headline is shown.
6348 2. CHILDREN: The main headline and the direct children are shown.
6349 From this state, you can move to one of the children
6350 and zoom in further.
6351 3. SUBTREE: Show the entire subtree, including body text.
6352 If there is no subtree, switch directly from CHILDREN to FOLDED.
6354 - When point is at the beginning of an empty headline and the variable
6355 `org-cycle-level-after-item/entry-creation' is set, cycle the level
6356 of the headline by demoting and promoting it to likely levels. This
6357 speeds up creation document structure by pressing TAB once or several
6358 times right after creating a new headline.
6360 - When there is a numeric prefix, go up to a heading with level ARG, do
6361 a `show-subtree' and return to the previous cursor position. If ARG
6362 is negative, go up that many levels.
6364 - When point is not at the beginning of a headline, execute the global
6365 binding for TAB, which is re-indenting the line. See the option
6366 `org-cycle-emulate-tab' for details.
6368 - Special case: if point is at the beginning of the buffer and there is
6369 no headline in line 1, this function will act as if called with prefix arg
6370 (C-u TAB, same as S-TAB) also when called without prefix arg.
6371 But only if also the variable `org-cycle-global-at-bob' is t."
6373 (org-load-modules-maybe)
6374 (unless (or (run-hook-with-args-until-success 'org-tab-first-hook
)
6375 (and org-cycle-level-after-item
/entry-creation
6376 (or (org-cycle-level)
6377 (org-cycle-item-indentation))))
6378 (let* (message-log-max ; Don't populate the *Messages* buffer
6380 (or org-cycle-max-level
6381 (and (boundp 'org-inlinetask-min-level
)
6382 org-inlinetask-min-level
6383 (1- org-inlinetask-min-level
))))
6384 (nstars (and limit-level
6385 (if org-odd-levels-only
6386 (and limit-level
(1- (* limit-level
2)))
6389 (if (not (derived-mode-p 'org-mode
))
6391 (concat "\\*" (if nstars
(format "\\{1,%d\\} " nstars
) "+ "))))
6392 (bob-special (and org-cycle-global-at-bob
(not arg
) (bobp)
6393 (not (looking-at org-outline-regexp
))))
6396 (delq 'org-optimize-window-after-visibility-change
6397 (copy-sequence org-cycle-hook
))
6401 (if (or bob-special
(equal arg
'(4)))
6402 ;; special case: use global cycling
6408 (setq last-command
'dummy
)
6409 (org-set-startup-visibility)
6410 (message "Startup visibility, plus VISIBILITY properties"))
6414 (message "Entire buffer visible, including drawers"))
6416 ;; Table: enter it or move to the next field.
6417 ((org-at-table-p 'any
)
6418 (if (org-at-table.el-p
)
6419 (message "Use C-c ' to edit table.el tables")
6420 (if arg
(org-table-edit-field t
)
6421 (org-table-justify-field-maybe)
6422 (call-interactively 'org-table-next-field
))))
6424 ((run-hook-with-args-until-success
6425 'org-tab-after-check-for-table-hook
))
6427 ;; Global cycling: delegate to `org-cycle-internal-global'.
6428 ((eq arg t
) (org-cycle-internal-global))
6430 ;; Drawers: delegate to `org-flag-drawer'.
6431 ((and org-drawers org-drawer-regexp
6433 (beginning-of-line 1)
6434 (looking-at org-drawer-regexp
)))
6435 (org-flag-drawer ; toggle block visibility
6436 (not (get-char-property (match-end 0) 'invisible
))))
6438 ;; Show-subtree, ARG levels up from here.
6441 (org-back-to-heading)
6442 (outline-up-heading (if (< arg
0) (- arg
)
6443 (- (funcall outline-level
) arg
)))
6444 (org-show-subtree)))
6446 ;; Inline task: delegate to `org-inlinetask-toggle-visibility'.
6447 ((and (featurep 'org-inlinetask
)
6448 (org-inlinetask-at-task-p)
6449 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6450 (org-inlinetask-toggle-visibility))
6452 ((org-try-cdlatex-tab))
6454 ;; At an item/headline: delegate to `org-cycle-internal-local'.
6455 ((and (or (and org-cycle-include-plain-lists
(org-at-item-p))
6456 (save-excursion (beginning-of-line 1)
6457 (looking-at org-outline-regexp
)))
6458 (or (bolp) (not (eq org-cycle-emulate-tab
'exc-hl-bol
))))
6459 (org-cycle-internal-local))
6461 ;; From there: TAB emulation and template completion.
6462 (buffer-read-only (org-back-to-heading))
6464 ((run-hook-with-args-until-success
6465 'org-tab-after-check-for-cycling-hook
))
6467 ((org-try-structure-completion))
6469 ((run-hook-with-args-until-success
6470 'org-tab-before-tab-emulation-hook
))
6472 ((and (eq org-cycle-emulate-tab
'exc-hl-bol
)
6474 (not (looking-at org-outline-regexp
))))
6475 (call-interactively (global-key-binding "\t")))
6477 ((if (and (memq org-cycle-emulate-tab
'(white whitestart
))
6478 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
6479 (or (and (eq org-cycle-emulate-tab
'white
)
6480 (= (match-end 0) (point-at-eol)))
6481 (and (eq org-cycle-emulate-tab
'whitestart
)
6482 (>= (match-end 0) pos
))))
6484 (eq org-cycle-emulate-tab t
))
6485 (call-interactively (global-key-binding "\t")))
6488 (org-back-to-heading)
6491 (defun org-cycle-internal-global ()
6492 "Do the global cycling action."
6493 ;; Hack to avoid display of messages for .org attachments in Gnus
6494 (let (message-log-max ; Don't populate the *Messages* buffer
6495 (ga (string-match "\\*fontification" (buffer-name))))
6497 ((and (eq last-command this-command
)
6498 (eq org-cycle-global-status
'overview
))
6499 ;; We just created the overview - now do table of contents
6500 ;; This can be slow in very large buffers, so indicate action
6501 (run-hook-with-args 'org-pre-cycle-hook
'contents
)
6502 (unless ga
(message "CONTENTS..."))
6504 (unless ga
(message "CONTENTS...done"))
6505 (setq org-cycle-global-status
'contents
)
6506 (run-hook-with-args 'org-cycle-hook
'contents
))
6508 ((and (eq last-command this-command
)
6509 (eq org-cycle-global-status
'contents
))
6510 ;; We just showed the table of contents - now show everything
6511 (run-hook-with-args 'org-pre-cycle-hook
'all
)
6513 (unless ga
(message "SHOW ALL"))
6514 (setq org-cycle-global-status
'all
)
6515 (run-hook-with-args 'org-cycle-hook
'all
))
6518 ;; Default action: go to overview
6519 (run-hook-with-args 'org-pre-cycle-hook
'overview
)
6521 (unless ga
(message "OVERVIEW"))
6522 (setq org-cycle-global-status
'overview
)
6523 (run-hook-with-args 'org-cycle-hook
'overview
)))))
6525 (defun org-cycle-internal-local ()
6526 "Do the local cycling action."
6527 (let (message-log-max ; Don't populate the *Messages* buffer
6528 (goal-column 0) eoh eol eos has-children children-skipped struct
)
6529 ;; First, determine end of headline (EOH), end of subtree or item
6530 ;; (EOS), and if item or heading has children (HAS-CHILDREN).
6535 (setq struct
(org-list-struct))
6536 (setq eoh
(point-at-eol))
6537 (setq eos
(org-list-get-item-end-before-blank (point) struct
))
6538 (setq has-children
(org-list-has-child-p (point) struct
)))
6539 (org-back-to-heading)
6540 (setq eoh
(save-excursion (outline-end-of-heading) (point)))
6541 (setq eos
(save-excursion (1- (org-end-of-subtree t t
))))
6544 (let ((level (funcall outline-level
)))
6545 (outline-next-heading)
6546 (and (org-at-heading-p t
)
6547 (> (funcall outline-level
) level
))))
6549 (org-list-search-forward (org-item-beginning-re) eos t
)))))
6550 ;; Determine end invisible part of buffer (EOL)
6551 (beginning-of-line 2)
6552 ;; XEmacs doesn't have `next-single-char-property-change'
6553 (if (featurep 'xemacs
)
6554 (while (and (not (eobp)) ;; this is like `next-line'
6555 (get-char-property (1- (point)) 'invisible
))
6556 (beginning-of-line 2))
6557 (while (and (not (eobp)) ;; this is like `next-line'
6558 (get-char-property (1- (point)) 'invisible
))
6559 (goto-char (next-single-char-property-change (point) 'invisible
))
6560 (and (eolp) (beginning-of-line 2))))
6562 ;; Find out what to do next and set `this-command'
6565 ;; Nothing is hidden behind this heading
6566 (unless (org-before-first-heading-p)
6567 (run-hook-with-args 'org-pre-cycle-hook
'empty
))
6568 (message "EMPTY ENTRY")
6569 (setq org-cycle-subtree-status nil
)
6572 (outline-next-heading)
6573 (if (outline-invisible-p) (org-flag-heading nil
))))
6574 ((and (or (>= eol eos
)
6575 (not (string-match "\\S-" (buffer-substring eol eos
))))
6577 (not (setq children-skipped
6578 org-cycle-skip-children-state-if-no-children
))))
6579 ;; Entire subtree is hidden in one line: children view
6580 (unless (org-before-first-heading-p)
6581 (run-hook-with-args 'org-pre-cycle-hook
'children
))
6583 (org-list-set-item-visibility (point-at-bol) struct
'children
)
6585 (org-with-limited-levels (show-children))
6586 ;; FIXME: This slows down the func way too much.
6587 ;; How keep drawers hidden in subtree anyway?
6588 ;; (when (memq 'org-cycle-hide-drawers org-cycle-hook)
6589 ;; (org-cycle-hide-drawers 'subtree))
6591 ;; Fold every list in subtree to top-level items.
6592 (when (eq org-cycle-include-plain-lists
'integrate
)
6594 (org-back-to-heading)
6595 (while (org-list-search-forward (org-item-beginning-re) eos t
)
6596 (beginning-of-line 1)
6597 (let* ((struct (org-list-struct))
6598 (prevs (org-list-prevs-alist struct
))
6599 (end (org-list-get-bottom-point struct
)))
6600 (mapc (lambda (e) (org-list-set-item-visibility e struct
'folded
))
6601 (org-list-get-all-items (point) struct prevs
))
6602 (goto-char end
))))))
6603 (message "CHILDREN")
6606 (outline-next-heading)
6607 (if (outline-invisible-p) (org-flag-heading nil
)))
6608 (setq org-cycle-subtree-status
'children
)
6609 (unless (org-before-first-heading-p)
6610 (run-hook-with-args 'org-cycle-hook
'children
)))
6611 ((or children-skipped
6612 (and (eq last-command this-command
)
6613 (eq org-cycle-subtree-status
'children
)))
6614 ;; We just showed the children, or no children are there,
6615 ;; now show everything.
6616 (unless (org-before-first-heading-p)
6617 (run-hook-with-args 'org-pre-cycle-hook
'subtree
))
6618 (outline-flag-region eoh eos nil
)
6619 (message (if children-skipped
"SUBTREE (NO CHILDREN)" "SUBTREE"))
6620 (setq org-cycle-subtree-status
'subtree
)
6621 (unless (org-before-first-heading-p)
6622 (run-hook-with-args 'org-cycle-hook
'subtree
)))
6624 ;; Default action: hide the subtree.
6625 (run-hook-with-args 'org-pre-cycle-hook
'folded
)
6626 (outline-flag-region eoh eos t
)
6628 (setq org-cycle-subtree-status
'folded
)
6629 (unless (org-before-first-heading-p)
6630 (run-hook-with-args 'org-cycle-hook
'folded
))))))
6633 (defun org-global-cycle (&optional arg
)
6634 "Cycle the global visibility. For details see `org-cycle'.
6635 With \\[universal-argument] prefix arg, switch to startup visibility.
6636 With a numeric prefix, show all headlines up to that level."
6638 (let ((org-cycle-include-plain-lists
6639 (if (derived-mode-p 'org-mode
) org-cycle-include-plain-lists nil
)))
6643 (hide-sublevels arg
)
6644 (setq org-cycle-global-status
'contents
))
6646 (org-set-startup-visibility)
6647 (message "Startup visibility, plus VISIBILITY properties."))
6649 (org-cycle '(4))))))
6651 (defun org-set-startup-visibility ()
6652 "Set the visibility required by startup options and properties."
6654 ((eq org-startup-folded t
)
6656 ((eq org-startup-folded
'content
)
6657 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
6658 (org-cycle '(4)) (org-cycle '(4)))))
6659 (unless (eq org-startup-folded
'showeverything
)
6660 (if org-hide-block-startup
(org-hide-block-all))
6661 (org-set-visibility-according-to-property 'no-cleanup
)
6662 (org-cycle-hide-archived-subtrees 'all
)
6663 (org-cycle-hide-drawers 'all
)
6664 (org-cycle-show-empty-lines t
)))
6666 (defun org-set-visibility-according-to-property (&optional no-cleanup
)
6667 "Switch subtree visibilities according to :VISIBILITY: property."
6669 (let (org-show-entry-below state
)
6671 (goto-char (point-min))
6672 (while (re-search-forward
6673 "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
6675 (setq state
(match-string 1))
6677 (org-back-to-heading t
)
6681 ((equal state
'("fold" "folded"))
6683 ((equal state
"children")
6684 (org-show-hidden-entry)
6686 ((equal state
"content")
6689 (org-narrow-to-subtree)
6691 ((member state
'("all" "showall"))
6694 (org-cycle-hide-archived-subtrees 'all
)
6695 (org-cycle-hide-drawers 'all
)
6696 (org-cycle-show-empty-lines 'all
)))))
6698 ;; This function uses outline-regexp instead of the more fundamental
6699 ;; org-outline-regexp so that org-cycle-global works outside of Org
6700 ;; buffers, where outline-regexp is needed.
6701 (defun org-overview ()
6702 "Switch to overview mode, showing only top-level headlines.
6703 Really, this shows all headlines with level equal or greater than the level
6704 of the first headline in the buffer. This is important, because if the
6705 first headline is not level one, then (hide-sublevels 1) gives confusing
6708 (let ((level (save-excursion
6709 (goto-char (point-min))
6710 (if (re-search-forward (concat "^" outline-regexp
) nil t
)
6712 (goto-char (match-beginning 0))
6713 (funcall outline-level
))))))
6714 (and level
(hide-sublevels level
))))
6716 (defun org-content (&optional arg
)
6717 "Show all headlines in the buffer, like a table of contents.
6718 With numerical argument N, show content up to level N."
6721 ;; Visit all headings and show their offspring
6722 (and (integerp arg
) (org-overview))
6723 (goto-char (point-max))
6725 (while (and (progn (condition-case nil
6726 (outline-previous-visible-heading 1)
6727 (error (goto-char (point-min))))
6729 (looking-at org-outline-regexp
))
6731 (show-children (1- arg
))
6733 (if (bobp) (throw 'exit nil
))))))
6736 (defun org-optimize-window-after-visibility-change (state)
6737 "Adjust the window after a change in outline visibility.
6738 This function is the default value of the hook `org-cycle-hook'."
6739 (when (get-buffer-window (current-buffer))
6741 ((eq state
'content
) nil
)
6742 ((eq state
'all
) nil
)
6743 ((eq state
'folded
) nil
)
6744 ((eq state
'children
) (or (org-subtree-end-visible-p) (recenter 1)))
6745 ((eq state
'subtree
) (or (org-subtree-end-visible-p) (recenter 1))))))
6747 (defun org-remove-empty-overlays-at (pos)
6748 "Remove outline overlays that do not contain non-white stuff."
6751 (and (eq 'outline
(overlay-get o
'invisible
))
6752 (not (string-match "\\S-" (buffer-substring (overlay-start o
)
6754 (delete-overlay o
)))
6757 (defun org-clean-visibility-after-subtree-move ()
6758 "Fix visibility issues after moving a subtree."
6759 ;; First, find a reasonable region to look at:
6760 ;; Start two siblings above, end three below
6761 (let* ((beg (save-excursion
6762 (and (org-get-last-sibling)
6763 (org-get-last-sibling))
6765 (end (save-excursion
6766 (and (org-get-next-sibling)
6767 (org-get-next-sibling)
6768 (org-get-next-sibling))
6769 (if (org-at-heading-p)
6772 (level (looking-at "\\*+"))
6773 (re (if level
(concat "^" (regexp-quote (match-string 0)) " "))))
6776 (narrow-to-region beg end
)
6778 ;; Properly fold already folded siblings
6779 (goto-char (point-min))
6780 (while (re-search-forward re nil t
)
6781 (if (and (not (outline-invisible-p))
6783 (goto-char (point-at-eol)) (outline-invisible-p)))
6785 (org-cycle-show-empty-lines 'overview
)
6786 (org-cycle-hide-drawers 'overview
)))))
6788 (defun org-cycle-show-empty-lines (state)
6789 "Show empty lines above all visible headlines.
6790 The region to be covered depends on STATE when called through
6791 `org-cycle-hook'. Lisp program can use t for STATE to get the
6792 entire buffer covered. Note that an empty line is only shown if there
6793 are at least `org-cycle-separator-lines' empty lines before the headline."
6794 (when (not (= org-cycle-separator-lines
0))
6796 (let* ((n (abs org-cycle-separator-lines
))
6798 ((= n
1) "\\(\n[ \t]*\n\\*+\\) ")
6799 ((= n
2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
6800 (t (let ((ns (number-to-string (- n
2))))
6801 (concat "^\\(?:[ \t]*\n\\)\\{" ns
"," ns
"\\}"
6802 "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
6805 ((memq state
'(overview contents t
))
6806 (setq beg
(point-min) end
(point-max)))
6807 ((memq state
'(children folded
))
6808 (setq beg
(point) end
(progn (org-end-of-subtree t t
)
6809 (beginning-of-line 2)
6813 (while (re-search-forward re end t
)
6814 (unless (get-char-property (match-end 1) 'invisible
)
6815 (setq e
(match-end 1))
6816 (if (< org-cycle-separator-lines
0)
6817 (setq b
(save-excursion
6818 (goto-char (match-beginning 0))
6819 (org-back-over-empty-lines)
6821 (goto-char (max (point-min) (1- (point))))
6825 (setq b
(match-beginning 1)))
6826 (outline-flag-region b e nil
)))))))
6827 ;; Never hide empty lines at the end of the file.
6829 (goto-char (point-max))
6830 (outline-previous-heading)
6831 (outline-end-of-heading)
6832 (if (and (looking-at "[ \t\n]+")
6833 (= (match-end 0) (point-max)))
6834 (outline-flag-region (point) (match-end 0) nil
))))
6836 (defun org-show-empty-lines-in-parent ()
6837 "Move to the parent and re-show empty lines before visible headlines."
6839 (let ((context (if (org-up-heading-safe) 'children
'overview
)))
6840 (org-cycle-show-empty-lines context
))))
6842 (defun org-files-list ()
6843 "Return `org-agenda-files' list, plus all open org-mode files.
6844 This is useful for operations that need to scan all of a user's
6845 open and agenda-wise Org files."
6846 (let ((files (mapcar 'expand-file-name
(org-agenda-files))))
6847 (dolist (buf (buffer-list))
6848 (with-current-buffer buf
6849 (if (and (derived-mode-p 'org-mode
) (buffer-file-name))
6850 (let ((file (expand-file-name (buffer-file-name))))
6851 (unless (member file files
)
6852 (push file files
))))))
6855 (defsubst org-entry-beginning-position
()
6856 "Return the beginning position of the current entry."
6857 (save-excursion (outline-back-to-heading t
) (point)))
6859 (defsubst org-entry-end-position
()
6860 "Return the end position of the current entry."
6861 (save-excursion (outline-next-heading) (point)))
6863 (defun org-cycle-hide-drawers (state)
6864 "Re-hide all drawers after a visibility state change."
6865 (when (and (derived-mode-p 'org-mode
)
6866 (not (memq state
'(overview folded contents
))))
6868 (let* ((globalp (memq state
'(contents all
)))
6869 (beg (if globalp
(point-min) (point)))
6870 (end (if globalp
(point-max)
6871 (if (eq state
'children
)
6872 (save-excursion (outline-next-heading) (point))
6873 (org-end-of-subtree t
)))))
6875 (while (re-search-forward org-drawer-regexp end t
)
6876 (org-flag-drawer t
))))))
6878 (defun org-cycle-hide-inline-tasks (state)
6879 "Re-hide inline task when switching to 'contents visibility state."
6880 (when (and (eq state
'contents
)
6881 (boundp 'org-inlinetask-min-level
)
6882 org-inlinetask-min-level
)
6883 (hide-sublevels (1- org-inlinetask-min-level
))))
6885 (defun org-flag-drawer (flag)
6886 "When FLAG is non-nil, hide the drawer we are within.
6887 Otherwise make it visible."
6889 (beginning-of-line 1)
6890 (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:")
6891 (let ((b (match-end 0)))
6892 (if (re-search-forward
6894 (save-excursion (outline-next-heading) (point)) t
)
6895 (outline-flag-region b
(point-at-eol) flag
)
6896 (error ":END: line missing at position %s" b
))))))
6898 (defun org-subtree-end-visible-p ()
6899 "Is the end of the current subtree visible?"
6900 (pos-visible-in-window-p
6901 (save-excursion (org-end-of-subtree t
) (point))))
6903 (defun org-first-headline-recenter (&optional N
)
6904 "Move cursor to the first headline and recenter the headline.
6905 Optional argument N means put the headline into the Nth line of the window."
6906 (goto-char (point-min))
6907 (when (re-search-forward (concat "^\\(" org-outline-regexp
"\\)") nil t
)
6909 (recenter (prefix-numeric-value N
))))
6911 ;;; Saving and restoring visibility
6913 (defun org-outline-overlay-data (&optional use-markers
)
6914 "Return a list of the locations of all outline overlays.
6915 These are overlays with the `invisible' property value `outline'.
6916 The return value is a list of cons cells, with start and stop
6917 positions for each overlay.
6918 If USE-MARKERS is set, return the positions as markers."
6925 (when (eq (overlay-get o
'invisible
) 'outline
)
6926 (setq beg
(overlay-start o
)
6927 end
(overlay-end o
))
6928 (and beg end
(> end beg
)
6930 (cons (move-marker (make-marker) beg
)
6931 (move-marker (make-marker) end
))
6933 (overlays-in (point-min) (point-max))))))))
6935 (defun org-set-outline-overlay-data (data)
6936 "Create visibility overlays for all positions in DATA.
6937 DATA should have been made by `org-outline-overlay-data'."
6944 (outline-flag-region (car c
) (cdr c
) t
))
6947 ;;; Folding of blocks
6949 (defvar org-hide-block-overlays nil
6950 "Overlays hiding blocks.")
6951 (make-variable-buffer-local 'org-hide-block-overlays
)
6953 (defun org-block-map (function &optional start end
)
6954 "Call FUNCTION at the head of all source blocks in the current buffer.
6955 Optional arguments START and END can be used to limit the range."
6956 (let ((start (or start
(point-min)))
6957 (end (or end
(point-max))))
6960 (while (and (< (point) end
) (re-search-forward org-block-regexp end t
))
6963 (goto-char (match-beginning 0))
6964 (funcall function
)))))))
6966 (defun org-hide-block-toggle-all ()
6967 "Toggle the visibility of all blocks in the current buffer."
6968 (org-block-map #'org-hide-block-toggle
))
6970 (defun org-hide-block-all ()
6971 "Fold all blocks in the current buffer."
6973 (org-show-block-all)
6974 (org-block-map #'org-hide-block-toggle-maybe
))
6976 (defun org-show-block-all ()
6977 "Unfold all blocks in the current buffer."
6979 (mapc 'delete-overlay org-hide-block-overlays
)
6980 (setq org-hide-block-overlays nil
))
6982 (defun org-hide-block-toggle-maybe ()
6983 "Toggle visibility of block at point."
6985 (let ((case-fold-search t
))
6987 (beginning-of-line 1)
6988 (looking-at org-block-regexp
))
6989 (progn (org-hide-block-toggle)
6990 t
) ;; to signal that we took action
6991 nil
))) ;; to signal that we did not
6993 (defun org-hide-block-toggle (&optional force
)
6994 "Toggle the visibility of the current block."
6998 (if (re-search-forward org-block-regexp nil t
)
6999 (let ((start (- (match-beginning 4) 1)) ;; beginning of body
7000 (end (match-end 0)) ;; end of entire body
7002 (if (memq t
(mapcar (lambda (overlay)
7003 (eq (overlay-get overlay
'invisible
)
7005 (overlays-at start
)))
7006 (if (or (not force
) (eq force
'off
))
7008 (when (member ov org-hide-block-overlays
)
7009 (setq org-hide-block-overlays
7010 (delq ov org-hide-block-overlays
)))
7011 (when (eq (overlay-get ov
'invisible
)
7013 (delete-overlay ov
)))
7014 (overlays-at start
)))
7015 (setq ov
(make-overlay start end
))
7016 (overlay-put ov
'invisible
'org-hide-block
)
7017 ;; make the block accessible to isearch
7019 ov
'isearch-open-invisible
7021 (when (member ov org-hide-block-overlays
)
7022 (setq org-hide-block-overlays
7023 (delq ov org-hide-block-overlays
)))
7024 (when (eq (overlay-get ov
'invisible
)
7026 (delete-overlay ov
))))
7027 (push ov org-hide-block-overlays
)))
7028 (error "Not looking at a source block"))))
7030 ;; org-tab-after-check-for-cycling-hook
7031 (add-hook 'org-tab-first-hook
'org-hide-block-toggle-maybe
)
7032 ;; Remove overlays when changing major mode
7033 (add-hook 'org-mode-hook
7034 (lambda () (org-add-hook 'change-major-mode-hook
7035 'org-show-block-all
'append
'local
)))
7039 (defvar org-goto-window-configuration nil
)
7040 (defvar org-goto-marker nil
)
7041 (defvar org-goto-map
)
7042 (defun org-goto-map ()
7043 "Set the keymap `org-goto'."
7045 (let ((map (make-sparse-keymap)))
7046 (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command
7047 mouse-drag-region universal-argument org-occur
))
7049 (while (setq cmd
(pop cmds
))
7050 (substitute-key-definition cmd cmd map global-map
)))
7051 (suppress-keymap map
)
7052 (org-defkey map
"\C-m" 'org-goto-ret
)
7053 (org-defkey map
[(return)] 'org-goto-ret
)
7054 (org-defkey map
[(left)] 'org-goto-left
)
7055 (org-defkey map
[(right)] 'org-goto-right
)
7056 (org-defkey map
[(control ?g
)] 'org-goto-quit
)
7057 (org-defkey map
"\C-i" 'org-cycle
)
7058 (org-defkey map
[(tab)] 'org-cycle
)
7059 (org-defkey map
[(down)] 'outline-next-visible-heading
)
7060 (org-defkey map
[(up)] 'outline-previous-visible-heading
)
7061 (if org-goto-auto-isearch
7062 (if (fboundp 'define-key-after
)
7063 (define-key-after map
[t] 'org-goto-local-auto-isearch)
7065 (org-defkey map "q" 'org-goto-quit)
7066 (org-defkey map "n" 'outline-next-visible-heading)
7067 (org-defkey map "p" 'outline-previous-visible-heading)
7068 (org-defkey map "f" 'outline-forward-same-level)
7069 (org-defkey map "b" 'outline-backward-same-level)
7070 (org-defkey map "u" 'outline-up-heading))
7071 (org-defkey map "/" 'org-occur)
7072 (org-defkey map "\C-c\C-n" 'outline-next-visible-heading)
7073 (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading)
7074 (org-defkey map "\C-c\C-f" 'outline-forward-same-level)
7075 (org-defkey map "\C-c\C-b" 'outline-backward-same-level)
7076 (org-defkey map "\C-c\C-u" 'outline-up-heading)
7079 (defconst org-goto-help
7080 "Browse buffer copy, to find location or copy text.%s
7081 RET=jump to location C-g=quit and return to previous location
7082 \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur")
7084 (defvar org-goto-start-pos) ; dynamically scoped parameter
7086 ;; FIXME: Docstring does not mention both interfaces
7087 (defun org-goto (&optional alternative-interface)
7088 "Look up a different location in the current file, keeping current visibility.
7090 When you want look-up or go to a different location in a
7091 document, the fastest way is often to fold the entire buffer and
7092 then dive into the tree. This method has the disadvantage, that
7093 the previous location will be folded, which may not be what you
7096 This command works around this by showing a copy of the current
7097 buffer in an indirect buffer, in overview mode. You can dive
7098 into the tree in that copy, use org-occur and incremental search
7099 to find a location. When pressing RET or `Q', the command
7100 returns to the original buffer in which the visibility is still
7101 unchanged. After RET it will also jump to the location selected
7102 in the indirect buffer and expose the headline hierarchy above.
7104 With a prefix argument, use the alternative interface: e.g. if
7105 `org-goto-interface' is 'outline use 'outline-path-completion."
7108 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
7109 (org-refile-use-outline-path t)
7110 (org-refile-target-verify-function nil)
7112 (if (not alternative-interface)
7114 (if (eq org-goto-interface 'outline)
7115 'outline-path-completion
7117 (org-goto-start-pos (point))
7119 (if (eq interface 'outline)
7120 (car (org-get-location (current-buffer) org-goto-help))
7121 (let ((pa (org-refile-get-location "Goto" nil nil t)))
7122 (org-refile-check-position pa)
7126 (org-mark-ring-push org-goto-start-pos)
7127 (goto-char selected-point)
7128 (if (or (outline-invisible-p) (org-invisible-p2))
7129 (org-show-context 'org-goto)))
7132 (defvar org-goto-selected-point nil) ; dynamically scoped parameter
7133 (defvar org-goto-exit-command nil) ; dynamically scoped parameter
7134 (defvar org-goto-local-auto-isearch-map) ; defined below
7136 (defun org-get-location (buf help)
7137 "Let the user select a location in the Org-mode buffer BUF.
7138 This function uses a recursive edit. It returns the selected position
7141 (let ((isearch-mode-map org-goto-local-auto-isearch-map)
7142 (isearch-hide-immediately nil)
7143 (isearch-search-fun-function
7144 (lambda () 'org-goto-local-search-headings))
7145 (org-goto-selected-point org-goto-exit-command))
7147 (save-window-excursion
7148 (delete-other-windows)
7149 (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
7150 (org-pop-to-buffer-same-window
7152 (make-indirect-buffer (current-buffer) "*org-goto*")
7153 (error (make-indirect-buffer (current-buffer) "*org-goto*"))))
7154 (with-output-to-temp-buffer "*Org Help*"
7155 (princ (format help (if org-goto-auto-isearch
7156 " Just type for auto-isearch."
7157 " n/p/f/b/u to navigate, q to quit."))))
7158 (org-fit-window-to-buffer (get-buffer-window "*Org Help*"))
7159 (setq buffer-read-only nil)
7160 (let ((org-startup-truncated t)
7161 (org-startup-folded nil)
7162 (org-startup-align-all-tables nil))
7165 (setq buffer-read-only t)
7166 (if (and (boundp 'org-goto-start-pos)
7167 (integer-or-marker-p org-goto-start-pos))
7168 (let ((org-show-hierarchy-above t)
7169 (org-show-siblings t)
7170 (org-show-following-heading t))
7171 (goto-char org-goto-start-pos)
7172 (and (outline-invisible-p) (org-show-context)))
7173 (goto-char (point-min)))
7174 (let (org-special-ctrl-a/e) (org-beginning-of-line))
7175 (message "Select location and press RET")
7176 (use-local-map org-goto-map)
7178 (kill-buffer "*org-goto*")
7179 (cons org-goto-selected-point org-goto-exit-command))))
7181 (defvar org-goto-local-auto-isearch-map (make-sparse-keymap))
7182 (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map)
7183 (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char)
7184 (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char)
7186 (defun org-goto-local-search-headings (string bound noerror)
7187 "Search and make sure that any matches are in headlines."
7189 (while (if isearch-forward
7190 (search-forward string bound noerror)
7191 (search-backward string bound noerror))
7192 (when (let ((context (mapcar 'car (save-match-data (org-context)))))
7193 (and (member :headline context)
7194 (not (member :tags context))))
7195 (throw 'return (point))))))
7197 (defun org-goto-local-auto-isearch ()
7200 (goto-char (point-min))
7201 (let ((keys (this-command-keys)))
7202 (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char)
7204 (isearch-process-search-char (string-to-char keys)))))
7206 (defun org-goto-ret (&optional arg)
7207 "Finish `org-goto' by going to the new location."
7209 (setq org-goto-selected-point (point)
7210 org-goto-exit-command 'return)
7213 (defun org-goto-left ()
7214 "Finish `org-goto' by going to the new location."
7216 (if (org-at-heading-p)
7218 (beginning-of-line 1)
7219 (setq org-goto-selected-point (point)
7220 org-goto-exit-command 'left)
7222 (error "Not on a heading")))
7224 (defun org-goto-right ()
7225 "Finish `org-goto' by going to the new location."
7227 (if (org-at-heading-p)
7229 (setq org-goto-selected-point (point)
7230 org-goto-exit-command 'right)
7232 (error "Not on a heading")))
7234 (defun org-goto-quit ()
7235 "Finish `org-goto' without cursor motion."
7237 (setq org-goto-selected-point nil)
7238 (setq org-goto-exit-command 'quit)
7241 ;;; Indirect buffer display of subtrees
7243 (defvar org-indirect-dedicated-frame nil
7244 "This is the frame being used for indirect tree display.")
7245 (defvar org-last-indirect-buffer nil)
7247 (defun org-tree-to-indirect-buffer (&optional arg)
7248 "Create indirect buffer and narrow it to current subtree.
7249 With a numerical prefix ARG, go up to this level and then take that tree.
7250 If ARG is negative, go up that many levels.
7252 If `org-indirect-buffer-display' is not `new-frame', the command removes the
7253 indirect buffer previously made with this command, to avoid proliferation of
7254 indirect buffers. However, when you call the command with a \
7255 \\[universal-argument] prefix, or
7256 when `org-indirect-buffer-display' is `new-frame', the last buffer
7257 is kept so that you can work with several indirect buffers at the same time.
7258 If `org-indirect-buffer-display' is `dedicated-frame', the \
7259 \\[universal-argument] prefix also
7260 requests that a new frame be made for the new buffer, so that the dedicated
7261 frame is not changed."
7263 (let ((cbuf (current-buffer))
7264 (cwin (selected-window))
7266 beg end level heading ibuf)
7268 (org-back-to-heading t)
7270 (setq level (org-outline-level))
7271 (if (< arg 0) (setq arg (+ level arg)))
7272 (while (> (setq level (org-outline-level)) arg)
7273 (org-up-heading-safe)))
7275 heading (org-get-heading))
7276 (org-end-of-subtree t t)
7277 (if (org-at-heading-p) (backward-char 1))
7279 (if (and (buffer-live-p org-last-indirect-buffer)
7280 (not (eq org-indirect-buffer-display 'new-frame))
7282 (kill-buffer org-last-indirect-buffer))
7283 (setq ibuf (org-get-indirect-buffer cbuf)
7284 org-last-indirect-buffer ibuf)
7286 ((or (eq org-indirect-buffer-display 'new-frame)
7287 (and arg (eq org-indirect-buffer-display 'dedicated-frame)))
7288 (select-frame (make-frame))
7289 (delete-other-windows)
7290 (org-pop-to-buffer-same-window ibuf)
7291 (org-set-frame-title heading))
7292 ((eq org-indirect-buffer-display 'dedicated-frame)
7294 (select-frame (or (and org-indirect-dedicated-frame
7295 (frame-live-p org-indirect-dedicated-frame)
7296 org-indirect-dedicated-frame)
7297 (setq org-indirect-dedicated-frame (make-frame)))))
7298 (delete-other-windows)
7299 (org-pop-to-buffer-same-window ibuf)
7300 (org-set-frame-title (concat "Indirect: " heading)))
7301 ((eq org-indirect-buffer-display 'current-window)
7302 (org-pop-to-buffer-same-window ibuf))
7303 ((eq org-indirect-buffer-display 'other-window)
7304 (pop-to-buffer ibuf))
7305 (t (error "Invalid value")))
7306 (if (featurep 'xemacs)
7307 (save-excursion (org-mode) (turn-on-font-lock)))
7308 (narrow-to-region beg end)
7311 (run-hook-with-args 'org-cycle-hook 'all)
7312 (and (window-live-p cwin) (select-window cwin))))
7314 (defun org-get-indirect-buffer (&optional buffer)
7315 (setq buffer (or buffer (current-buffer)))
7316 (let ((n 1) (base (buffer-name buffer)) bname)
7317 (while (buffer-live-p
7318 (get-buffer (setq bname (concat base "-" (number-to-string n)))))
7321 (make-indirect-buffer buffer bname 'clone)
7322 (error (make-indirect-buffer buffer bname)))))
7324 (defun org-set-frame-title (title)
7325 "Set the title of the current frame to the string TITLE."
7326 ;; FIXME: how to name a single frame in XEmacs???
7327 (unless (featurep 'xemacs)
7328 (modify-frame-parameters (selected-frame) (list (cons 'name title)))))
7330 ;;;; Structure editing
7332 ;;; Inserting headlines
7334 (defun org-previous-line-empty-p ()
7337 (or (beginning-of-line 0) t)
7339 (looking-at "[ \t]*$")))))
7341 (defun org-insert-heading (&optional force-heading invisible-ok)
7342 "Insert a new heading or item with same depth at point.
7343 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
7344 If point is at the beginning of a headline, insert a sibling before the
7345 current headline. If point is not at the beginning, split the line,
7346 create the new headline with the text in the current line after point
7347 \(but see also the variable `org-M-RET-may-split-line').
7349 With a double prefix arg, force the heading to be inserted at the
7350 end of the parent subtree.
7352 When INVISIBLE-OK is set, stop at invisible headlines when going back.
7353 This is important for non-interactive uses of the command."
7355 (if (or (= (buffer-size) 0)
7356 (and (not (save-excursion
7357 (and (ignore-errors (org-back-to-heading invisible-ok))
7358 (org-at-heading-p))))
7359 (or force-heading (not (org-in-item-p)))))
7362 (run-hooks 'org-insert-heading-hook))
7363 (when (or force-heading (not (org-insert-item)))
7364 (let* ((empty-line-p nil)
7366 (on-heading (org-at-heading-p))
7367 (head (save-excursion
7370 (org-back-to-heading invisible-ok)
7371 (when (and (not on-heading)
7372 (featurep 'org-inlinetask)
7373 (integerp org-inlinetask-min-level)
7374 (>= (length (match-string 0))
7375 org-inlinetask-min-level))
7376 ;; Find a heading level before the inline task
7377 (while (and (setq level (org-up-heading-safe))
7378 (>= level org-inlinetask-min-level)))
7379 (if (org-at-heading-p)
7380 (org-back-to-heading invisible-ok)
7381 (error "This should not happen")))
7382 (setq empty-line-p (org-previous-line-empty-p))
7385 (blank-a (cdr (assq 'heading org-blank-before-new-entry)))
7386 (blank (if (eq blank-a 'auto) empty-line-p blank-a))
7387 pos hide-previous previous-pos)
7389 ((and (org-at-heading-p) (bolp)
7391 (save-excursion (backward-char 1) (not (outline-invisible-p)))))
7392 ;; insert before the current line
7393 (open-line (if blank 2 1)))
7395 (not org-insert-heading-respect-content)
7398 (backward-char 1) (not (outline-invisible-p)))))
7399 ;; insert right here
7402 ;; somewhere in the line
7404 (setq previous-pos (point-at-bol))
7406 (setq hide-previous (outline-invisible-p)))
7407 (and org-insert-heading-respect-content (org-show-subtree))
7409 (and (org-get-alist-option org-M-RET-may-split-line 'headline)
7412 (goto-char (point-at-bol))
7413 (and (looking-at org-complex-heading-regexp)
7415 (> p (match-beginning 4)))))))
7418 (org-insert-heading-respect-content
7419 (if (not (equal force-heading '(16)))
7421 (org-end-of-subtree nil t)
7422 (and (looking-at "^\\*") (backward-char 1))
7423 (while (and (not (bobp))
7424 (member (char-before) '(?\ ?\t ?\n)))
7425 (backward-delete-char 1)))
7426 (org-up-heading-safe)
7427 (org-end-of-subtree nil t))
7428 (when (featurep 'org-inlinetask)
7429 (while (and (not (eobp))
7430 (looking-at "\\(\\*+\\)[ \t]+")
7431 (>= (length (match-string 1))
7432 org-inlinetask-min-level))
7433 (org-end-of-subtree nil t)))
7434 (or (bolp) (newline))
7435 (or (org-previous-line-empty-p)
7436 (and blank (newline)))
7442 (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)?[ \t]*$")
7443 (setq tags (and (match-end 2) (match-string 2)))
7445 (delete-region (match-beginning 1) (match-end 1)))
7446 (setq pos (point-at-bol))
7447 (or split (end-of-line 1))
7448 (delete-horizontal-space)
7449 (if (string-match "\\`\\*+\\'"
7450 (buffer-substring (point-at-bol) (point)))
7452 (newline (if blank 2 1))
7458 (org-set-tags nil 'align))))
7460 (or split (end-of-line 1))
7461 (newline (if blank 2 1)))))))
7462 (insert head) (just-one-space)
7465 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
7466 (when (and org-insert-heading-respect-content hide-previous)
7468 (goto-char previous-pos)
7470 (run-hooks 'org-insert-heading-hook)))))
7472 (defun org-get-heading (&optional no-tags no-todo)
7473 "Return the heading of the current entry, without the stars.
7474 When NO-TAGS is non-nil, don't include tags.
7475 When NO-TODO is non-nil, don't include TODO keywords."
7477 (org-back-to-heading t)
7479 ((and no-tags no-todo)
7480 (looking-at org-complex-heading-regexp)
7483 (looking-at (concat org-outline-regexp
7485 "\\(?:[ \t]+:[[:alnum:]:_@#%]+:\\)?[ \t]*$"))
7488 (looking-at org-todo-line-regexp)
7490 (t (looking-at org-heading-regexp)
7491 (match-string 2)))))
7493 (defvar orgstruct-mode) ; defined below
7495 (defun org-heading-components ()
7496 "Return the components of the current heading.
7497 This is a list with the following elements:
7498 - the level as an integer
7499 - the reduced level, different if `org-odd-levels-only' is set.
7500 - the TODO keyword, or nil
7501 - the priority character, like ?A, or nil if no priority is given
7502 - the headline text itself, or the tags string if no headline text
7503 - the tags string, or nil."
7505 (org-back-to-heading t)
7506 (if (let (case-fold-search)
7510 org-complex-heading-regexp)))
7512 (list (length (match-string 1))
7513 (org-reduced-level (length (match-string 1)))
7518 (list (length (match-string 1))
7519 (org-reduced-level (length (match-string 1)))
7520 (org-match-string-no-properties 2)
7521 (and (match-end 3) (aref (match-string 3) 2))
7522 (org-match-string-no-properties 4)
7523 (org-match-string-no-properties 5))))))
7525 (defun org-get-entry ()
7526 "Get the entry text, after heading, entire subtree."
7528 (org-back-to-heading t)
7529 (buffer-substring (point-at-bol 2) (org-end-of-subtree t))))
7531 (defun org-insert-heading-after-current ()
7532 "Insert a new heading with same level as current, after current subtree."
7534 (org-back-to-heading)
7535 (org-insert-heading)
7536 (org-move-subtree-down)
7539 (defun org-insert-heading-respect-content (invisible-ok)
7540 "Insert heading with `org-insert-heading-respect-content' set to t."
7542 (let ((org-insert-heading-respect-content t))
7543 (org-insert-heading t invisible-ok)))
7545 (defun org-insert-todo-heading-respect-content (&optional force-state)
7546 "Insert TODO heading with `org-insert-heading-respect-content' set to t."
7548 (let ((org-insert-heading-respect-content t))
7549 (org-insert-todo-heading force-state t)))
7551 (defun org-insert-todo-heading (arg &optional force-heading)
7552 "Insert a new heading with the same level and TODO state as current heading.
7553 If the heading has no TODO state, or if the state is DONE, use the first
7554 state (TODO by default). Also one prefix arg, force first state. With two
7555 prefix args, force inserting at the end of the parent subtree."
7557 (when (or force-heading (not (org-insert-item 'checkbox)))
7558 (org-insert-heading (or (and (equal arg '(16)) '(16))
7561 (org-back-to-heading)
7562 (outline-previous-heading)
7563 (looking-at org-todo-line-regexp))
7567 (not (match-beginning 2))
7568 (member (match-string 2) org-done-keywords))
7569 (car org-todo-keywords-1)
7573 (run-hook-with-args-until-success
7574 'org-todo-get-default-hook new-mark-x nil)
7576 (beginning-of-line 1)
7577 (and (looking-at org-outline-regexp) (goto-char (match-end 0))
7578 (if org-treat-insert-todo-heading-as-state-change
7580 (insert new-mark " "))))
7581 (when org-provide-todo-statistics
7582 (org-update-parent-todo-statistics))))
7584 (defun org-insert-subheading (arg)
7585 "Insert a new subheading and demote it.
7586 Works for outline headings and for plain lists alike."
7588 (org-insert-heading arg)
7590 ((org-at-heading-p) (org-do-demote))
7591 ((org-at-item-p) (org-indent-item))))
7593 (defun org-insert-todo-subheading (arg)
7594 "Insert a new subheading with TODO keyword or checkbox and demote it.
7595 Works for outline headings and for plain lists alike."
7597 (org-insert-todo-heading arg)
7599 ((org-at-heading-p) (org-do-demote))
7600 ((org-at-item-p) (org-indent-item))))
7602 ;;; Promotion and Demotion
7604 (defvar org-after-demote-entry-hook nil
7605 "Hook run after an entry has been demoted.
7606 The cursor will be at the beginning of the entry.
7607 When a subtree is being demoted, the hook will be called for each node.")
7609 (defvar org-after-promote-entry-hook nil
7610 "Hook run after an entry has been promoted.
7611 The cursor will be at the beginning of the entry.
7612 When a subtree is being promoted, the hook will be called for each node.")
7614 (defun org-promote-subtree ()
7615 "Promote the entire subtree.
7616 See also `org-promote'."
7619 (org-with-limited-levels (org-map-tree 'org-promote)))
7620 (org-fix-position-after-promote))
7622 (defun org-demote-subtree ()
7623 "Demote the entire subtree. See `org-demote'.
7624 See also `org-promote'."
7627 (org-with-limited-levels (org-map-tree 'org-demote)))
7628 (org-fix-position-after-promote))
7631 (defun org-do-promote ()
7632 "Promote the current heading higher up the tree.
7633 If the region is active in `transient-mark-mode', promote all headings
7637 (if (org-region-active-p)
7638 (org-map-region 'org-promote (region-beginning) (region-end))
7640 (org-fix-position-after-promote))
7642 (defun org-do-demote ()
7643 "Demote the current heading lower down the tree.
7644 If the region is active in `transient-mark-mode', demote all headings
7648 (if (org-region-active-p)
7649 (org-map-region 'org-demote (region-beginning) (region-end))
7651 (org-fix-position-after-promote))
7653 (defun org-fix-position-after-promote ()
7654 "Make sure that after pro/demotion cursor position is right."
7655 (let ((pos (point)))
7656 (when (save-excursion
7657 (beginning-of-line 1)
7658 (looking-at org-todo-line-regexp)
7659 (or (equal pos (match-end 1)) (equal pos (match-end 2))))
7660 (cond ((eobp) (insert " "))
7661 ((eolp) (insert " "))
7662 ((equal (char-after) ?\ ) (forward-char 1))))))
7664 (defun org-current-level ()
7665 "Return the level of the current entry, or nil if before the first headline.
7666 The level is the number of stars at the beginning of the headline."
7668 (org-with-limited-levels
7669 (if (ignore-errors (org-back-to-heading t))
7670 (funcall outline-level)))))
7672 (defun org-get-previous-line-level ()
7673 "Return the outline depth of the last headline before the current line.
7674 Returns 0 for the first headline in the buffer, and nil if before the
7676 (let ((current-level (org-current-level))
7677 (prev-level (when (> (line-number-at-pos) 1)
7679 (beginning-of-line 0)
7680 (org-current-level)))))
7681 (cond ((null current-level) nil) ; Before first headline
7682 ((null prev-level) 0) ; At first headline
7685 (defun org-reduced-level (l)
7686 "Compute the effective level of a heading.
7687 This takes into account the setting of `org-odd-levels-only'."
7690 (org-odd-levels-only (1+ (floor (/ l 2))))
7693 (defun org-level-increment ()
7694 "Return the number of stars that will be added or removed at a
7695 time to headlines when structure editing, based on the value of
7696 `org-odd-levels-only'."
7697 (if org-odd-levels-only 2 1))
7699 (defun org-get-valid-level (level &optional change)
7700 "Rectify a level change under the influence of `org-odd-levels-only'
7701 LEVEL is a current level, CHANGE is by how much the level should be
7702 modified. Even if CHANGE is nil, LEVEL may be returned modified because
7703 even level numbers will become the next higher odd number."
7704 (if org-odd-levels-only
7705 (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2))))
7706 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
7707 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
7708 (max 1 (+ level (or change 0)))))
7710 (if (boundp 'define-obsolete-function-alias)
7711 (if (or (featurep 'xemacs) (< emacs-major-version 23))
7712 (define-obsolete-function-alias 'org-get-legal-level
7713 'org-get-valid-level)
7714 (define-obsolete-function-alias 'org-get-legal-level
7715 'org-get-valid-level "23.1")))
7717 (defvar org-called-with-limited-levels nil) ;; Dynamically bound in
7718 ;; ̀org-with-limited-levels'
7719 (defun org-promote ()
7720 "Promote the current heading higher up the tree.
7721 If the region is active in `transient-mark-mode', promote all headings
7723 (org-back-to-heading t)
7724 (let* ((level (save-match-data (funcall outline-level)))
7725 (after-change-functions (remove 'flyspell-after-change-function
7726 after-change-functions))
7727 (up-head (concat (make-string (org-get-valid-level level -1) ?*) " "))
7728 (diff (abs (- level (length up-head) -1))))
7729 (cond ((and (= level 1) org-called-with-limited-levels
7730 org-allow-promoting-top-level-subtree)
7731 (replace-match "# " nil t))
7733 (error "Cannot promote to level 0. UNDO to recover if necessary"))
7734 (t (replace-match up-head nil t)))
7735 ;; Fixup tag positioning
7737 (and org-auto-align-tags (org-set-tags nil t))
7738 (if org-adapt-indentation (org-fixup-indentation (- diff))))
7739 (run-hooks 'org-after-promote-entry-hook)))
7741 (defun org-demote ()
7742 "Demote the current heading lower down the tree.
7743 If the region is active in `transient-mark-mode', demote all headings
7745 (org-back-to-heading t)
7746 (let* ((level (save-match-data (funcall outline-level)))
7747 (after-change-functions (remove 'flyspell-after-change-function
7748 after-change-functions))
7749 (down-head (concat (make-string (org-get-valid-level level 1) ?*) " "))
7750 (diff (abs (- level (length down-head) -1))))
7751 (replace-match down-head nil t)
7752 ;; Fixup tag positioning
7753 (and org-auto-align-tags (org-set-tags nil t))
7754 (if org-adapt-indentation (org-fixup-indentation diff))
7755 (run-hooks 'org-after-demote-entry-hook)))
7757 (defun org-cycle-level ()
7758 "Cycle the level of an empty headline through possible states.
7759 This goes first to child, then to parent, level, then up the hierarchy.
7760 After top level, it switches back to sibling level."
7762 (let ((org-adapt-indentation nil))
7763 (when (org-point-at-end-of-empty-headline)
7764 (setq this-command 'org-cycle-level) ; Only needed for caching
7765 (let ((cur-level (org-current-level))
7766 (prev-level (org-get-previous-line-level)))
7768 ;; If first headline in file, promote to top-level.
7770 (loop repeat (/ (- cur-level 1) (org-level-increment))
7771 do (org-do-promote)))
7772 ;; If same level as prev, demote one.
7773 ((= prev-level cur-level)
7775 ;; If parent is top-level, promote to top level if not already.
7777 (loop repeat (/ (- cur-level 1) (org-level-increment))
7778 do (org-do-promote)))
7779 ;; If top-level, return to prev-level.
7781 (loop repeat (/ (- prev-level 1) (org-level-increment))
7782 do (org-do-demote)))
7783 ;; If less than prev-level, promote one.
7784 ((< cur-level prev-level)
7786 ;; If deeper than prev-level, promote until higher than
7788 ((> cur-level prev-level)
7789 (loop repeat (+ 1 (/ (- cur-level prev-level) (org-level-increment)))
7790 do (org-do-promote))))
7793 (defun org-map-tree (fun)
7794 "Call FUN for every heading underneath the current one."
7795 (org-back-to-heading)
7796 (let ((level (funcall outline-level)))
7800 (outline-next-heading)
7801 (> (funcall outline-level) level))
7805 (defun org-map-region (fun beg end)
7806 "Call FUN for every heading between BEG and END."
7807 (let ((org-ignore-region t))
7809 (setq end (copy-marker end))
7811 (if (and (re-search-forward org-outline-regexp-bol nil t)
7815 (outline-next-heading)
7820 (defvar org-property-end-re) ; silence byte-compiler
7821 (defun org-fixup-indentation (diff)
7822 "Change the indentation in the current entry by DIFF.
7823 However, if any line in the current entry has no indentation, or if it
7824 would end up with no indentation after the change, nothing at all is done."
7826 (let ((end (save-excursion (outline-next-heading)
7828 (prohibit (if (> diff 0)
7830 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
7832 (unless (save-excursion (end-of-line 1)
7833 (re-search-forward prohibit end t))
7834 (while (and (< (point) end)
7835 (re-search-forward "^[ \t]+" end t))
7836 (goto-char (match-end 0))
7837 (setq col (current-column))
7838 (if (< diff 0) (replace-match ""))
7839 (org-indent-to-column (+ diff col))))
7840 (move-marker end nil))))
7842 (defun org-convert-to-odd-levels ()
7843 "Convert an org-mode file with all levels allowed to one with odd levels.
7844 This will leave level 1 alone, convert level 2 to level 3, level 3 to
7847 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
7848 (let ((outline-level 'org-outline-level)
7849 (org-odd-levels-only nil) n)
7851 (goto-char (point-min))
7852 (while (re-search-forward "^\\*\\*+ " nil t)
7853 (setq n (- (length (match-string 0)) 2))
7854 (while (>= (setq n (1- n)) 0)
7856 (end-of-line 1))))))
7858 (defun org-convert-to-oddeven-levels ()
7859 "Convert an org-mode file with only odd levels to one with odd/even levels.
7860 This promotes level 3 to level 2, level 5 to level 3 etc. If the
7861 file contains a section with an even level, conversion would
7862 destroy the structure of the file. An error is signaled in this
7865 (goto-char (point-min))
7866 ;; First check if there are no even levels
7867 (when (re-search-forward "^\\(\\*\\*\\)+ " nil t)
7868 (org-show-context t)
7869 (error "Not all levels are odd in this file. Conversion not possible"))
7870 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
7871 (let ((outline-regexp org-outline-regexp)
7872 (outline-level 'org-outline-level)
7873 (org-odd-levels-only nil) n)
7875 (goto-char (point-min))
7876 (while (re-search-forward "^\\*\\*+ " nil t)
7877 (setq n (/ (1- (length (match-string 0))) 2))
7878 (while (>= (setq n (1- n)) 0)
7880 (end-of-line 1))))))
7882 (defun org-tr-level (n)
7883 "Make N odd if required."
7884 (if org-odd-levels-only (1+ (/ n 2)) n))
7886 ;;; Vertical tree motion, cutting and pasting of subtrees
7888 (defun org-move-subtree-up (&optional arg)
7889 "Move the current subtree up past ARG headlines of the same level."
7891 (org-move-subtree-down (- (prefix-numeric-value arg))))
7893 (defun org-move-subtree-down (&optional arg)
7894 "Move the current subtree down past ARG headlines of the same level."
7896 (setq arg (prefix-numeric-value arg))
7897 (let ((movfunc (if (> arg 0) 'org-get-next-sibling
7898 'org-get-last-sibling))
7899 (ins-point (make-marker))
7901 (col (current-column))
7902 beg beg0 end txt folded ne-beg ne-end ne-ins ins-end)
7904 (org-back-to-heading)
7907 (setq ne-beg (org-back-over-empty-lines))
7910 (save-excursion (outline-end-of-heading)
7911 (setq folded (outline-invisible-p)))
7912 (outline-end-of-subtree))
7913 (outline-next-heading)
7914 (setq ne-end (org-back-over-empty-lines))
7917 (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg))
7918 ;; include less whitespace
7921 (forward-line (- ne-beg ne-end))
7922 (setq beg (point))))
7923 ;; Find insertion point, with error handling
7925 (or (and (funcall movfunc) (looking-at org-outline-regexp))
7926 (progn (goto-char beg0)
7927 (error "Cannot move past superior level or buffer limit")))
7928 (setq cnt (1- cnt)))
7930 ;; Moving forward - still need to move over subtree
7931 (progn (org-end-of-subtree t t)
7933 (org-back-over-empty-lines)
7934 (or (bolp) (newline)))))
7935 (setq ne-ins (org-back-over-empty-lines))
7936 (move-marker ins-point (point))
7937 (setq txt (buffer-substring beg end))
7938 (org-save-markers-in-region beg end)
7939 (delete-region beg end)
7940 (org-remove-empty-overlays-at beg)
7941 (or (= beg (point-min)) (outline-flag-region (1- beg) beg nil))
7942 (or (bobp) (outline-flag-region (1- (point)) (point) nil))
7943 (and (not (bolp)) (looking-at "\n") (forward-char 1))
7944 (let ((bbb (point)))
7945 (insert-before-markers txt)
7946 (org-reinstall-markers-in-region bbb)
7947 (move-marker ins-point bbb))
7948 (or (bolp) (insert "\n"))
7949 (setq ins-end (point))
7950 (goto-char ins-point)
7951 (org-skip-whitespace)
7952 (when (and (< arg 0)
7953 (org-first-sibling-p)
7955 ;; Move whitespace back to beginning
7958 (let ((kill-whole-line t))
7959 (kill-line (- ne-ins ne-beg)) (point)))
7960 (insert (make-string (- ne-ins ne-beg) ?\n)))
7961 (move-marker ins-point nil)
7966 (org-cycle-hide-drawers 'children))
7967 (org-clean-visibility-after-subtree-move)
7968 ;; move back to the initial column we were at
7969 (move-to-column col)))
7971 (defvar org-subtree-clip ""
7972 "Clipboard for cut and paste of subtrees.
7973 This is actually only a copy of the kill, because we use the normal kill
7974 ring. We need it to check if the kill was created by `org-copy-subtree'.")
7976 (defvar org-subtree-clip-folded nil
7977 "Was the last copied subtree folded?
7978 This is used to fold the tree back after pasting.")
7980 (defun org-cut-subtree (&optional n)
7981 "Cut the current subtree into the clipboard.
7982 With prefix arg N, cut this many sequential subtrees.
7983 This is a short-hand for marking the subtree and then cutting it."
7985 (org-copy-subtree n 'cut))
7987 (defun org-copy-subtree (&optional n cut force-store-markers nosubtrees)
7988 "Cut the current subtree into the clipboard.
7989 With prefix arg N, cut this many sequential subtrees.
7990 This is a short-hand for marking the subtree and then copying it.
7991 If CUT is non-nil, actually cut the subtree.
7992 If FORCE-STORE-MARKERS is non-nil, store the relative locations
7993 of some markers in the region, even if CUT is non-nil. This is
7994 useful if the caller implements cut-and-paste as copy-then-paste-then-cut."
7996 (let (beg end folded (beg0 (point)))
7997 (if (org-called-interactively-p 'any)
7998 (org-back-to-heading nil) ; take what looks like a subtree
7999 (org-back-to-heading t)) ; take what is really there
8001 (skip-chars-forward " \t\r\n")
8004 (outline-next-heading)
8005 (save-excursion (outline-end-of-heading)
8006 (setq folded (outline-invisible-p)))
8008 (org-forward-heading-same-level (1- n) t)
8010 (org-end-of-subtree t t)))
8014 (setq org-subtree-clip-folded folded)
8015 (when (or cut force-store-markers)
8016 (org-save-markers-in-region beg end))
8017 (if cut (kill-region beg end) (copy-region-as-kill beg end))
8018 (setq org-subtree-clip (current-kill 0))
8019 (message "%s: Subtree(s) with %d characters"
8020 (if cut "Cut" "Copied")
8021 (length org-subtree-clip)))))
8023 (defun org-paste-subtree (&optional level tree for-yank)
8024 "Paste the clipboard as a subtree, with modification of headline level.
8025 The entire subtree is promoted or demoted in order to match a new headline
8028 If the cursor is at the beginning of a headline, the same level as
8029 that headline is used to paste the tree.
8031 If not, the new level is derived from the *visible* headings
8032 before and after the insertion point, and taken to be the inferior headline
8033 level of the two. So if the previous visible heading is level 3 and the
8034 next is level 4 (or vice versa), level 4 will be used for insertion.
8035 This makes sure that the subtree remains an independent subtree and does
8036 not swallow low level entries.
8038 You can also force a different level, either by using a numeric prefix
8039 argument, or by inserting the heading marker by hand. For example, if the
8040 cursor is after \"*****\", then the tree will be shifted to level 5.
8042 If optional TREE is given, use this text instead of the kill ring.
8044 When FOR-YANK is set, this is called by `org-yank'. In this case, do not
8045 move back over whitespace before inserting, and move point to the end of
8046 the inserted text when done."
8048 (setq tree (or tree (and kill-ring (current-kill 0))))
8049 (unless (org-kill-is-subtree-p tree)
8051 (substitute-command-keys
8052 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
8053 (org-with-limited-levels
8054 (let* ((visp (not (outline-invisible-p)))
8056 (^re_ "\\(\\*+\\)[ \t]*")
8057 (old-level (if (string-match org-outline-regexp-bol txt)
8058 (- (match-end 0) (match-beginning 0) 1)
8060 (force-level (cond (level (prefix-numeric-value level))
8061 ((and (looking-at "[ \t]*$")
8063 "^\\*+$" (buffer-substring
8064 (point-at-bol) (point))))
8065 (- (match-end 1) (match-beginning 1)))
8067 (looking-at org-outline-regexp))
8068 (- (match-end 0) (point) 1))))
8069 (previous-level (save-excursion
8072 (outline-previous-visible-heading 1)
8073 (if (looking-at ^re_)
8074 (- (match-end 0) (match-beginning 0) 1)
8077 (next-level (save-excursion
8080 (or (looking-at org-outline-regexp)
8081 (outline-next-visible-heading 1))
8082 (if (looking-at ^re_)
8083 (- (match-end 0) (match-beginning 0) 1)
8086 (new-level (or force-level (max previous-level next-level)))
8087 (shift (if (or (= old-level -1)
8089 (= old-level new-level))
8091 (- new-level old-level)))
8092 (delta (if (> shift 0) -1 1))
8093 (func (if (> shift 0) 'org-demote 'org-promote))
8094 (org-odd-levels-only nil)
8096 ;; Remove the forced level indicator
8098 (delete-region (point-at-bol) (point)))
8100 (beginning-of-line (if (bolp) 1 2))
8102 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
8103 (insert-before-markers txt)
8104 (unless (string-match "\n\\'" txt) (insert "\n"))
8105 (setq newend (point))
8106 (org-reinstall-markers-in-region beg)
8109 (skip-chars-forward " \t\n\r")
8111 (if (and (outline-invisible-p) visp)
8112 (save-excursion (outline-show-heading)))
8113 ;; Shift if necessary
8116 (narrow-to-region beg end)
8117 (while (not (= shift 0))
8118 (org-map-region func (point-min) (point-max))
8119 (setq shift (+ delta shift)))
8120 (goto-char (point-min))
8121 (setq newend (point-max))))
8122 (when (or (org-called-interactively-p 'interactive) for-yank)
8123 (message "Clipboard pasted as level %d subtree" new-level))
8124 (if (and (not for-yank) ; in this case, org-yank will decide about folding
8126 (eq org-subtree-clip (current-kill 0))
8127 org-subtree-clip-folded)
8128 ;; The tree was folded before it was killed/copied
8130 (and for-yank (goto-char newend)))))
8132 (defun org-kill-is-subtree-p (&optional txt)
8133 "Check if the current kill is an outline subtree, or a set of trees.
8134 Returns nil if kill does not start with a headline, or if the first
8135 headline level is not the largest headline level in the tree.
8136 So this will actually accept several entries of equal levels as well,
8137 which is OK for `org-paste-subtree'.
8138 If optional TXT is given, check this string instead of the current kill."
8139 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
8140 (re (org-get-limited-outline-regexp))
8141 (^re (concat "^" re))
8142 (start-level (and kill
8144 (concat "\\`\\([ \t\n\r]*?\n\\)?\\(" re "\\)")
8146 (- (match-end 2) (match-beginning 2) 1)))
8147 (start (1+ (or (match-beginning 2) -1))))
8148 (if (not start-level)
8150 nil) ;; does not even start with a heading
8152 (while (setq start (string-match ^re kill (1+ start)))
8153 (when (< (- (match-end 0) (match-beginning 0) 1) start-level)
8157 (defvar org-markers-to-move nil
8158 "Markers that should be moved with a cut-and-paste operation.
8159 Those markers are stored together with their positions relative to
8160 the start of the region.")
8162 (defun org-save-markers-in-region (beg end)
8163 "Check markers in region.
8164 If these markers are between BEG and END, record their position relative
8165 to BEG, so that after moving the block of text, we can put the markers back
8167 This function gets called just before an entry or tree gets cut from the
8168 buffer. After re-insertion, `org-reinstall-markers-in-region' must be
8169 called immediately, to move the markers with the entries."
8170 (setq org-markers-to-move nil)
8171 (when (featurep 'org-clock)
8172 (org-clock-save-markers-for-cut-and-paste beg end))
8173 (when (featurep 'org-agenda)
8174 (org-agenda-save-markers-for-cut-and-paste beg end)))
8176 (defun org-check-and-save-marker (marker beg end)
8177 "Check if MARKER is between BEG and END.
8178 If yes, remember the marker and the distance to BEG."
8179 (when (and (marker-buffer marker)
8180 (equal (marker-buffer marker) (current-buffer)))
8181 (if (and (>= marker beg) (< marker end))
8182 (push (cons marker (- marker beg)) org-markers-to-move))))
8184 (defun org-reinstall-markers-in-region (beg)
8185 "Move all remembered markers to their position relative to BEG."
8187 (move-marker (car x) (+ beg (cdr x))))
8188 org-markers-to-move)
8189 (setq org-markers-to-move nil))
8191 (defun org-narrow-to-subtree ()
8192 "Narrow buffer to the current subtree."
8196 (org-with-limited-levels
8198 (progn (org-back-to-heading t) (point))
8199 (progn (org-end-of-subtree t t)
8200 (if (and (org-at-heading-p) (not (eobp))) (backward-char 1))
8203 (defun org-narrow-to-block ()
8204 "Narrow buffer to the current block."
8206 (let* ((case-fold-search t)
8207 (blockp (org-between-regexps-p "^[ \t]*#\\+begin_.*"
8208 "^[ \t]*#\\+end_.*")))
8210 (narrow-to-region (car blockp) (cdr blockp))
8211 (error "Not in a block"))))
8214 (defvar org-property-drawer-re))
8216 (defvar org-property-start-re) ;; defined below
8217 (defun org-clone-subtree-with-time-shift (n &optional shift)
8218 "Clone the task (subtree) at point N times.
8219 The clones will be inserted as siblings.
8221 In interactive use, the user will be prompted for the number of
8222 clones to be produced, and for a time SHIFT, which may be a
8223 repeater as used in time stamps, for example `+3d'.
8225 When a valid repeater is given and the entry contains any time
8226 stamps, the clones will become a sequence in time, with time
8227 stamps in the subtree shifted for each clone produced. If SHIFT
8228 is nil or the empty string, time stamps will be left alone. The
8229 ID property of the original subtree is removed.
8231 If the original subtree did contain time stamps with a repeater,
8232 the following will happen:
8233 - the repeater will be removed in each clone
8234 - an additional clone will be produced, with the current, unshifted
8235 date(s) in the entry.
8236 - the original entry will be placed *after* all the clones, with
8238 - the start days in the repeater in the original entry will be shifted
8239 to past the last clone.
8240 In this way you can spell out a number of instances of a repeating task,
8241 and still retain the repeater to cover future instances of the task."
8242 (interactive "nNumber of clones to produce: \nsDate shift per clone (e.g. +1w, empty to copy unchanged): ")
8243 (let (beg end template task idprop
8244 shift-n shift-what doshift nmin nmax (n-no-remove -1)
8245 (drawer-re org-drawer-regexp))
8246 (if (not (and (integerp n) (> n 0)))
8247 (error "Invalid number of replications %s" n))
8248 (if (and (setq doshift (and (stringp shift) (string-match "\\S-" shift)))
8249 (not (string-match "\\`[ \t]*\\+?\\([0-9]+\\)\\([hdwmy]\\)[ \t]*\\'"
8251 (error "Invalid shift specification %s" shift))
8253 (setq shift-n (string-to-number (match-string 1 shift))
8254 shift-what (cdr (assoc (match-string 2 shift)
8255 '(("d" . day) ("w" . week)
8256 ("m" . month) ("y" . year))))))
8257 (if (eq shift-what 'week) (setq shift-n (* 7 shift-n) shift-what 'day))
8258 (setq nmin 1 nmax n)
8259 (org-back-to-heading t)
8261 (setq idprop (org-entry-get nil "ID"))
8262 (org-end-of-subtree t t)
8263 (or (bolp) (insert "\n"))
8265 (setq template (buffer-substring beg end))
8267 (string-match "<[^<>\n]+ [.+]?\\+[0-9]+[hdwmy][^<>\n]*>" template))
8268 (delete-region beg end)
8270 (setq nmin 0 nmax (1+ nmax) n-no-remove nmax))
8272 (loop for n from nmin to nmax do
8277 (goto-char (point-min))
8279 (and idprop (if org-clone-delete-id
8280 (org-entry-delete nil "ID")
8281 (org-id-get-create t)))
8283 (while (re-search-forward "^[ \t]*CLOCK:.*$" nil t)
8285 (goto-char (point-min))
8286 (while (re-search-forward drawer-re nil t)
8288 (org-remove-empty-drawer-at d (point))) org-drawers)))
8289 (goto-char (point-min))
8291 (while (re-search-forward org-ts-regexp-both nil t)
8292 (org-timestamp-change (* n shift-n) shift-what))
8293 (unless (= n n-no-remove)
8294 (goto-char (point-min))
8295 (while (re-search-forward org-ts-regexp nil t)
8297 (goto-char (match-beginning 0))
8298 (if (looking-at "<[^<>\n]+\\( +[.+]?\\+[0-9]+[hdwmy]\\)")
8299 (delete-region (match-beginning 1) (match-end 1)))))))
8300 (setq task (buffer-string)))
8306 (defun org-sort (with-case)
8307 "Call `org-sort-entries', `org-table-sort-lines' or `org-sort-list'.
8308 Optional argument WITH-CASE means sort case-sensitively."
8311 ((org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case))
8312 ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case))
8314 (org-call-with-arg 'org-sort-entries with-case))))
8316 (defun org-sort-remove-invisible (s)
8317 (remove-text-properties 0 (length s) org-rm-props s)
8318 (while (string-match org-bracket-link-regexp s)
8319 (setq s (replace-match (if (match-end 2)
8321 (match-string 1 s)) t t s)))
8324 (defvar org-priority-regexp) ; defined later in the file
8326 (defvar org-after-sorting-entries-or-items-hook nil
8327 "Hook that is run after a bunch of entries or items have been sorted.
8328 When children are sorted, the cursor is in the parent line when this
8329 hook gets called. When a region or a plain list is sorted, the cursor
8330 will be in the first entry of the sorted region/list.")
8332 (defun org-sort-entries
8333 (&optional with-case sorting-type getkey-func compare-func property)
8334 "Sort entries on a certain level of an outline tree.
8335 If there is an active region, the entries in the region are sorted.
8336 Else, if the cursor is before the first entry, sort the top-level items.
8337 Else, the children of the entry at point are sorted.
8339 Sorting can be alphabetically, numerically, by date/time as given by
8340 a time stamp, by a property or by priority.
8342 The command prompts for the sorting type unless it has been given to the
8343 function through the SORTING-TYPE argument, which needs to be a character,
8344 \(?n ?N ?a ?A ?t ?T ?s ?S ?d ?D ?p ?P ?o ?O ?r ?R ?f ?F). Here is the
8345 precise meaning of each character:
8347 n Numerically, by converting the beginning of the entry/item to a number.
8348 a Alphabetically, ignoring the TODO keyword and the priority, if any.
8349 o By order of TODO keywords.
8350 t By date/time, either the first active time stamp in the entry, or, if
8351 none exist, by the first inactive one.
8352 s By the scheduled date/time.
8353 d By deadline date/time.
8354 c By creation time, which is assumed to be the first inactive time stamp
8355 at the beginning of a line.
8356 p By priority according to the cookie.
8357 r By the value of a property.
8359 Capital letters will reverse the sort order.
8361 If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be
8362 called with point at the beginning of the record. It must return either
8363 a string or a number that should serve as the sorting key for that record.
8365 Comparing entries ignores case by default. However, with an optional argument
8366 WITH-CASE, the sorting considers case as well."
8368 (let ((case-func (if with-case 'identity 'downcase))
8370 ;; The clock marker is lost when using `sort-subr', let's
8371 ;; store the clocking string.
8372 (when (equal (marker-buffer org-clock-marker) (current-buffer))
8374 (goto-char org-clock-marker)
8375 (looking-back "^.*") (match-string-no-properties 0))))
8376 start beg end stars re re2
8378 ;; Find beginning and end of region to sort
8380 ((org-region-active-p)
8381 ;; we will sort the region
8382 (setq end (region-end)
8384 (goto-char (region-beginning))
8385 (if (not (org-at-heading-p)) (outline-next-heading))
8386 (setq start (point)))
8387 ((or (org-at-heading-p)
8388 (condition-case nil (progn (org-back-to-heading) t) (error nil)))
8389 ;; we will sort the children of the current headline
8390 (org-back-to-heading)
8392 end (progn (org-end-of-subtree t t)
8393 (or (bolp) (insert "\n"))
8394 (org-back-over-empty-lines)
8399 (outline-next-heading))
8401 ;; we will sort the top-level entries in this file
8402 (goto-char (point-min))
8403 (or (org-at-heading-p) (outline-next-heading))
8404 (setq start (point))
8405 (goto-char (point-max))
8406 (beginning-of-line 1)
8407 (when (looking-at ".*?\\S-")
8408 ;; File ends in a non-white line
8411 (setq end (point-max))
8412 (setq what "top-level")
8417 (if (>= beg end) (error "Nothing to sort"))
8419 (looking-at "\\(\\*+\\)")
8420 (setq stars (match-string 1)
8421 re (concat "^" (regexp-quote stars) " +")
8422 re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[ \t\n]")
8423 txt (buffer-substring beg end))
8424 (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n")))
8425 (if (and (not (equal stars "*")) (string-match re2 txt))
8426 (error "Region to sort contains a level above the first entry"))
8428 (unless sorting-type
8430 "Sort %s: [a]lpha [n]umeric [p]riority p[r]operty todo[o]rder [f]unc
8431 [t]ime
[s]cheduled [d]eadline [c]reated
8432 A/N/P/R/O/F/T/S/D/C means reversed:"
8434 (setq sorting-type (read-char-exclusive))
8437 (and (= (downcase sorting-type) ?f)
8439 (org-icompleting-read "Sort using function: "
8440 obarray 'fboundp t nil nil))
8441 (setq getkey-func (intern getkey-func))))
8443 (and (= (downcase sorting-type) ?r)
8446 (org-icompleting-read "Property: "
8447 (mapcar 'list (org-buffer-property-keys t))
8450 (message "Sorting entries...")
8453 (narrow-to-region start end)
8454 (let ((dcst (downcase sorting-type))
8455 (case-fold-search nil)
8456 (now (current-time)))
8458 (/= dcst sorting-type)
8459 ;; This function moves to the beginning character of the "record" to
8462 (if (re-search-forward re nil t)
8463 (goto-char (match-beginning 0))
8464 (goto-char (point-max))))
8465 ;; This function moves to the last character of the "record" being
8470 (outline-forward-same-level 1)
8472 (goto-char (point-max))))))
8473 ;; This function returns the value that gets sorted against.
8477 (if (looking-at org-complex-heading-regexp)
8478 (string-to-number (match-string 4))
8481 (if (looking-at org-complex-heading-regexp)
8482 (funcall case-func (match-string 4))
8485 (let ((end (save-excursion (outline-next-heading) (point))))
8486 (if (or (re-search-forward org-ts-regexp end t)
8487 (re-search-forward org-ts-regexp-both end t))
8488 (org-time-string-to-seconds (match-string 0))
8489 (org-float-time now))))
8491 (let ((end (save-excursion (outline-next-heading) (point))))
8492 (if (re-search-forward
8493 (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
8495 (org-time-string-to-seconds (match-string 0))
8496 (org-float-time now))))
8498 (let ((end (save-excursion (outline-next-heading) (point))))
8499 (if (re-search-forward org-scheduled-time-regexp end t)
8500 (org-time-string-to-seconds (match-string 1))
8501 (org-float-time now))))
8503 (let ((end (save-excursion (outline-next-heading) (point))))
8504 (if (re-search-forward org-deadline-time-regexp end t)
8505 (org-time-string-to-seconds (match-string 1))
8506 (org-float-time now))))
8508 (if (re-search-forward org-priority-regexp (point-at-eol) t)
8509 (string-to-char (match-string 2))
8510 org-default-priority))
8512 (or (org-entry-get nil property) ""))
8514 (if (looking-at org-complex-heading-regexp)
8515 (- 9999 (length (member (match-string 2)
8516 org-todo-keywords-1)))))
8520 (setq tmp (funcall getkey-func))
8521 (if (stringp tmp) (setq tmp (funcall case-func tmp)))
8523 (error "Invalid key function `%s'" getkey-func)))
8524 (t (error "Invalid sorting type `%c'" sorting-type))))
8527 ((= dcst ?a) 'string<)
8528 ((= dcst ?f) compare-func)
8529 ((member dcst '(?p ?t ?s ?d ?c)) '<)))))
8530 (run-hooks 'org-after-sorting-entries-or-items-hook)
8531 ;; Reset the clock marker if needed
8535 (search-forward cmstr nil t)
8536 (move-marker org-clock-marker (point))))
8537 (message "Sorting entries...done")))
8539 (defun org-do-sort (table what &optional with-case sorting-type)
8540 "Sort TABLE of WHAT according to SORTING-TYPE.
8541 The user will be prompted for the SORTING-TYPE if the call to this
8542 function does not specify it. WHAT is only for the prompt, to indicate
8543 what is being sorted. The sorting key will be extracted from
8544 the car of the elements of the table.
8545 If WITH-CASE is non-nil, the sorting will be case-sensitive."
8546 (unless sorting-type
8548 "Sort %s: [a]lphabetic, [n]umeric, [t]ime. A/N/T means reversed:"
8550 (setq sorting-type (read-char-exclusive)))
8551 (let ((dcst (downcase sorting-type))
8552 extractfun comparefun)
8553 ;; Define the appropriate functions
8556 (setq extractfun 'string-to-number
8557 comparefun (if (= dcst sorting-type) '< '>)))
8559 (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x))
8560 (lambda(x) (downcase (org-sort-remove-invisible x))))
8561 comparefun (if (= dcst sorting-type)
8563 (lambda (a b) (and (not (string< a b))
8564 (not (string= a b)))))))
8568 (if (or (string-match org-ts-regexp x)
8569 (string-match org-ts-regexp-both x))
8571 (org-time-string-to-time (match-string 0 x)))
8573 comparefun (if (= dcst sorting-type) '< '>)))
8574 (t (error "Invalid sorting type `%c'" sorting-type)))
8576 (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x)))
8578 (lambda (a b) (funcall comparefun (car a) (car b))))))
8581 ;;; The orgstruct minor mode
8583 ;; Define a minor mode which can be used in other modes in order to
8584 ;; integrate the org-mode structure editing commands.
8586 ;; This is really a hack, because the org-mode structure commands use
8587 ;; keys which normally belong to the major mode. Here is how it
8588 ;; works: The minor mode defines all the keys necessary to operate the
8589 ;; structure commands, but wraps the commands into a function which
8590 ;; tests if the cursor is currently at a headline or a plain list
8591 ;; item. If that is the case, the structure command is used,
8592 ;; temporarily setting many Org-mode variables like regular
8593 ;; expressions for filling etc. However, when any of those keys is
8594 ;; used at a different location, function uses `key-binding' to look
8595 ;; up if the key has an associated command in another currently active
8596 ;; keymap (minor modes, major mode, global), and executes that
8597 ;; command. There might be problems if any of the keys is otherwise
8598 ;; used as a prefix key.
8600 (defcustom orgstruct-heading-prefix-regexp ""
8601 "Regexp that matches the custom prefix of Org headlines in
8602 orgstruct(++)-mode."
8605 ;;;###autoload(put 'orgstruct-heading-prefix-regexp 'safe-local-variable 'stringp)
8607 (defcustom orgstruct-setup-hook nil
8608 "Hook run after orgstruct-mode-map is filled."
8612 (defvar orgstruct-initialized nil)
8614 (defvar org-local-vars nil
8615 "List of local variables, for use by `orgstruct-mode'.")
8618 (define-minor-mode orgstruct-mode
8619 "Toggle the minor mode `orgstruct-mode'.
8620 This mode is for using Org-mode structure commands in other
8621 modes. The following keys behave as if Org-mode were active, if
8622 the cursor is on a headline, or on a plain list item (both as
8623 defined by Org-mode)."
8624 nil " OrgStruct" (make-sparse-keymap)
8625 (when orgstruct-mode
8626 (org-load-modules-maybe)
8627 (unless orgstruct-initialized
8629 (setq orgstruct-initialized t))))
8632 (defun turn-on-orgstruct ()
8633 "Unconditionally turn on `orgstruct-mode'."
8636 (defvar org-fb-vars nil)
8637 (make-variable-buffer-local 'org-fb-vars)
8638 (defun orgstruct++-mode (&optional arg)
8639 "Toggle `orgstruct-mode', the enhanced version of it.
8640 In addition to setting orgstruct-mode, this also exports all
8641 indentation and autofilling variables from org-mode into the
8642 buffer. It will also recognize item context in multiline items."
8644 (setq arg (prefix-numeric-value (or arg (if orgstruct-mode -1 1))))
8646 (progn (orgstruct-mode -1)
8648 (org-set-local (car v)
8649 (if (eq (car-safe (cadr v)) 'quote) (cadadr v) (cadr v))))
8652 (setq org-fb-vars nil)
8657 "^\\(paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|fill-prefix\\|indent-\\)"
8658 (symbol-name (car x)))
8659 (setq var (car x) val (nth 1 x))
8660 (push (list var `(quote ,(eval var))) org-fb-vars)
8661 (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val))))
8663 (org-set-local 'orgstruct-is-++ t))))
8665 (defvar orgstruct-is-++ nil
8666 "Is `orgstruct-mode' in ++ version in the current-buffer?")
8667 (make-variable-buffer-local 'orgstruct-is-++)
8670 (defun turn-on-orgstruct++ ()
8671 "Unconditionally turn on `orgstruct++-mode'."
8672 (orgstruct++-mode 1))
8674 (defun orgstruct-error ()
8675 "Error when there is no default binding for a structure key."
8677 (error "This key has no function outside structure elements"))
8679 (defun orgstruct-setup ()
8680 "Setup orgstruct keymap."
8685 org-backward-element
8686 org-backward-heading-same-level
8689 org-forward-heading-same-level
8691 org-insert-heading-respect-content
8692 org-kill-note-or-show-branches
8694 org-narrow-to-subtree
8701 outline-next-visible-heading
8702 outline-previous-visible-heading
8706 (dolist (f (if (stringp f)
8709 '("-return" "tab" "left" "right" "up" "down")
8711 (let ((f (intern (concat f postfix))))
8715 (dolist (binding (nconc (where-is-internal f org-mode-map)
8716 (where-is-internal f outline-mode-map)))
8717 ;; TODO use local-function-key-map
8718 (dolist (rep '(("<tab>" . "TAB")
8722 (setq binding (read-kbd-macro (replace-regexp-in-string
8723 (regexp-quote (car rep))
8725 (key-description binding)))))
8726 (let ((key (lookup-key orgstruct-mode-map binding)))
8727 (when (or (not key) (numberp key))
8729 (org-defkey orgstruct-mode-map
8731 (orgstruct-make-binding f binding))
8733 (run-hooks 'orgstruct-setup-hook))
8735 (defun orgstruct-make-binding (fun key)
8736 "Create a function for binding in the structure minor mode.
8737 FUN is the command to call inside a table. KEY is the key that
8738 should be checked in for a command to execute outside of tables."
8739 (let ((name (concat "orgstruct-hijacker-" (symbol-name fun))))
8742 (while (fboundp (intern nname))
8743 (setq nname (format "%s-%d" name (setq i (1+ i)))))
8744 (setq name (intern nname)))
8747 ,(concat "In Structure, run `" (symbol-name fun) "'.\n"
8748 "Outside of structure, run the binding of `"
8749 (key-description key) "'.")
8752 (let* ((org-heading-regexp
8754 orgstruct-heading-prefix-regexp
8755 "\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ ]*$"))
8757 (concat orgstruct-heading-prefix-regexp "\\*+ "))
8758 (org-outline-regexp-bol
8759 (concat "^" org-outline-regexp))
8760 (outline-regexp org-outline-regexp)
8761 (outline-heading-end-regexp "\n")
8762 (outline-level 'outline-level)
8763 (outline-heading-alist))
8764 (when (org-context-p 'headline 'item
8765 ,(when (memq fun '(org-insert-heading))
8766 '(when orgstruct-is-++
8768 (org-run-like-in-org-mode ',fun)
8770 (let* ((orgstruct-mode)
8771 (binding (key-binding ,key)))
8772 (if (keymapp binding)
8773 (set-temporary-overlay-map binding)
8775 (or binding 'orgstruct-error)))))))
8778 (defun org-contextualize-keys (alist contexts)
8779 "Return valid elements in ALIST depending on CONTEXTS.
8781 `org-agenda-custom-commands' or `org-capture-templates' are the
8782 values used for ALIST, and `org-agenda-custom-commands-contexts'
8783 or `org-capture-templates-contexts' are the associated contexts
8786 ;; normalize contexts
8788 (lambda(c) (cond ((listp (cadr c))
8789 (list (car c) (car c) (cadr c)))
8790 ((string= "" (cadr c))
8791 (list (car c) (car c) (caddr c)))
8794 ;; loop over all commands or templates
8795 (while (setq c (pop a))
8798 ((not (assoc (car c) contexts))
8800 ((and (assoc (car c) contexts)
8801 (setq vrules (org-contextualize-validate-key
8804 (when (not (equal (car vr) (cadr vr)))
8805 (setq repl vr))) vrules)
8806 (if (not repl) (push c r)
8807 (push (cadr repl) s)
8810 (cdr (or (assoc (cadr repl) alist)
8811 (error "Undefined key `%s' as contextual replacement for `%s'"
8812 (cadr repl) (car c)))))
8814 ;; Return limited ALIST, possibly with keys modified, and deduplicated
8819 (let ((tpl (car x)))
8823 (equal y tpl)) s))) x)))
8826 (defun org-contextualize-validate-key (key contexts)
8827 "Check CONTEXTS for agenda or capture KEY."
8829 (while (setq r (pop contexts))
8833 (and (equal key (car r))
8834 (if (functionp rr) (funcall rr)
8835 (or (and (eq (car rr) 'in-file)
8837 (string-match (cdr rr) (buffer-file-name)))
8838 (and (eq (car rr) 'in-mode)
8839 (string-match (cdr rr) (symbol-name major-mode)))
8840 (and (eq (car rr) 'in-buffer)
8841 (string-match (cdr rr) (buffer-name)))
8842 (when (and (eq (car rr) 'not-in-file)
8844 (not (string-match (cdr rr) (buffer-file-name))))
8845 (when (eq (car rr) 'not-in-mode)
8846 (not (string-match (cdr rr) (symbol-name major-mode))))
8847 (when (eq (car rr) 'not-in-buffer)
8848 (not (string-match (cdr rr) (buffer-name)))))))
8851 (delete-dups (delq nil res))))
8853 (defun org-context-p (&rest contexts)
8854 "Check if local context is any of CONTEXTS.
8855 Possible values in the list of contexts are `table', `headline', and `item'."
8856 (let ((pos (point)))
8857 (goto-char (point-at-bol))
8858 (prog1 (or (and (memq 'table contexts)
8859 (looking-at "[ \t]*|"))
8860 (and (memq 'headline contexts)
8861 (looking-at org-outline-regexp))
8862 (and (memq 'item contexts)
8863 (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))
8864 (and (memq 'item-body contexts)
8868 (defun org-get-local-variables ()
8869 "Return a list of all local variables in an Org mode buffer."
8871 (with-current-buffer (get-buffer-create "*Org tmp*")
8874 (setq varlist (buffer-local-variables)))
8875 (kill-buffer "*Org tmp*")
8882 (list (car x) (cdr x))))
8883 (if (and (not (get (car x) 'org-state))
8885 "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|normal-auto-fill\\|fill-paragraph\\|indent-\\)"
8886 (symbol-name (car x))))
8890 (defun org-clone-local-variables (from-buffer &optional regexp)
8891 "Clone local variables from FROM-BUFFER.
8892 Optional argument REGEXP selects variables to clone."
8895 (and (symbolp (car pair))
8897 (string-match regexp (symbol-name (car pair))))
8898 (set (make-local-variable (car pair))
8900 (buffer-local-variables from-buffer)))
8903 (defun org-run-like-in-org-mode (cmd)
8904 "Run a command, pretending that the current buffer is in Org-mode.
8905 This will temporarily bind local variables that are typically bound in
8906 Org-mode to the values they have in Org-mode, and then interactively
8908 (org-load-modules-maybe)
8909 (unless org-local-vars
8910 (setq org-local-vars (org-get-local-variables)))
8912 (dolist (var org-local-vars)
8913 (when (or (not (boundp (car var)))
8914 (eq (symbol-value (car var))
8915 (default-value (car var))))
8916 (push (list (car var) `(quote ,(cadr var))) binds)))
8918 (call-interactively (quote ,cmd))))))
8922 (defun org-get-category (&optional pos force-refresh)
8923 "Get the category applying to position POS."
8925 (if force-refresh (org-refresh-category-properties))
8926 (let ((pos (or pos (point))))
8927 (or (get-text-property pos 'org-category)
8928 (progn (org-refresh-category-properties)
8929 (get-text-property pos 'org-category))))))
8931 (defun org-refresh-category-properties ()
8932 "Refresh category text properties in the buffer."
8933 (let ((case-fold-search t)
8934 (inhibit-read-only t)
8936 ((null org-category)
8937 (if buffer-file-name
8938 (file-name-sans-extension
8939 (file-name-nondirectory buffer-file-name))
8941 ((symbolp org-category) (symbol-name org-category))
8943 beg end cat pos optionp)
8948 (goto-char (point-min))
8949 (put-text-property (point) (point-max) 'org-category def-cat)
8950 (while (re-search-forward
8951 "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t)
8952 (setq pos (match-end 0)
8953 optionp (equal (char-after (match-beginning 0)) ?#)
8954 cat (org-trim (match-string 2)))
8956 (setq beg (point-at-bol) end (point-max))
8957 (org-back-to-heading t)
8958 (setq beg (point) end (org-end-of-subtree t t)))
8959 (put-text-property beg end 'org-category cat)
8960 (put-text-property beg end 'org-category-position beg)
8961 (goto-char pos)))))))
8963 (defun org-refresh-properties (dprop tprop)
8964 "Refresh buffer text properties.
8965 DPROP is the drawer property and TPROP is the corresponding text
8967 (let ((case-fold-search t)
8968 (inhibit-read-only t) p)
8973 (goto-char (point-min))
8974 (while (re-search-forward (concat "^[ \t]*:" dprop ": +\\(.*\\)[ \t]*$") nil t)
8975 (setq p (org-match-string-no-properties 1))
8977 (org-back-to-heading t)
8979 (point-at-bol) (point-at-eol) tprop p))))))))
8984 ;;; Link abbreviations
8986 (defun org-link-expand-abbrev (link)
8987 "Apply replacements as defined in `org-link-abbrev-alist'."
8988 (if (string-match "^\\([^:]*\\)\\(::?\\(.*\\)\\)?$" link)
8989 (let* ((key (match-string 1 link))
8990 (as (or (assoc key org-link-abbrev-alist-local)
8991 (assoc key org-link-abbrev-alist)))
8992 (tag (and (match-end 2) (match-string 3 link)))
8998 ((symbolp rpl) (funcall rpl tag))
8999 ((string-match "%(\\([^)]+\\))" rpl)
9000 (replace-match (funcall (intern-soft (match-string 1 rpl)) tag) t t rpl))
9001 ((string-match "%s" rpl) (replace-match (or tag "") t t rpl))
9002 ((string-match "%h" rpl)
9003 (replace-match (url-hexify-string (or tag "")) t t rpl))
9004 (t (concat rpl tag)))))
9007 ;;; Storing and inserting links
9009 (defvar org-insert-link-history nil
9010 "Minibuffer history for links inserted with `org-insert-link'.")
9012 (defvar org-stored-links nil
9013 "Contains the links stored with `org-store-link'.")
9015 (defvar org-store-link-plist nil
9016 "Plist with info about the most recently link created with `org-store-link'.")
9018 (defvar org-link-protocols nil
9019 "Link protocols added to Org-mode using `org-add-link-type'.")
9021 (defvar org-store-link-functions nil
9022 "List of functions that are called to create and store a link.
9023 Each function will be called in turn until one returns a non-nil
9024 value. Each function should check if it is responsible for creating
9025 this link (for example by looking at the major mode).
9026 If not, it must exit and return nil.
9027 If yes, it should return a non-nil value after a calling
9028 `org-store-link-props' with a list of properties and values.
9029 Special properties are:
9031 :type The link prefix, like \"http\". This must be given.
9032 :link The link, like \"http://www.astro.uva.nl/~dominik\".
9033 This is obligatory as well.
9034 :description Optional default description for the second pair
9035 of brackets in an Org-mode link. The user can still change
9036 this when inserting this link into an Org-mode buffer.
9038 In addition to these, any additional properties can be specified
9039 and then used in capture templates.")
9041 (defun org-add-link-type (type &optional follow export)
9042 "Add TYPE to the list of `org-link-types'.
9043 Re-compute all regular expressions depending on `org-link-types'
9045 FOLLOW and EXPORT are two functions.
9047 FOLLOW should take the link path as the single argument and do whatever
9048 is necessary to follow the link, for example find a file or display
9051 EXPORT should format the link path for export to one of the export formats.
9052 It should be a function accepting three arguments:
9054 path the path of the link, the text after the prefix (like \"http:\")
9055 desc the description of the link, if any, or a description added by
9056 org-export-normalize-links if there is none
9057 format the export format, a symbol like `html' or `latex' or `ascii'..
9059 The function may use the FORMAT information to return different values
9060 depending on the format. The return value will be put literally into
9061 the exported file. If the return value is nil, this means Org should
9062 do what it normally does with links which do not have EXPORT defined.
9064 Org-mode has a built-in default for exporting links. If you are happy with
9065 this default, there is no need to define an export function for the link
9066 type. For a simple example of an export function, see `org-bbdb.el'."
9067 (add-to-list 'org-link-types type t)
9068 (org-make-link-regexps)
9069 (if (assoc type org-link-protocols)
9070 (setcdr (assoc type org-link-protocols) (list follow export))
9071 (push (list type follow export) org-link-protocols)))
9073 (defvar org-agenda-buffer-name) ; Defined in org-agenda.el
9074 (defvar org-id-link-to-org-use-id) ; Defined in org-id.el
9077 (defun org-store-link (arg)
9078 "\\<org-mode-map>Store an org-link to the current location.
9079 This link is added to `org-stored-links' and can later be inserted
9080 into an org-buffer with \\[org-insert-link].
9082 For some link types, a prefix arg is interpreted.
9083 For links to Usenet articles, arg negates `org-gnus-prefer-web-links'.
9084 For file links, arg negates `org-context-in-file-links'.
9086 A double prefix arg force skipping storing functions that are not
9087 part of Org's core."
9089 (org-load-modules-maybe)
9090 (setq org-store-link-plist nil) ; reset
9091 (org-with-limited-levels
9092 (let (link cpltxt desc description search txt custom-id agenda-link sfuns sfunsn)
9094 ((and (not (equal arg '(16)))
9097 nil (mapcar (lambda (f) (let (fs) (if (funcall f) (push f fs))))
9098 org-store-link-functions))
9099 sfunsn (mapcar (lambda (fu) (symbol-name (car fu))) sfuns))
9100 (or (and (cdr sfuns)
9102 (completing-read "Which function for creating the link? "
9103 sfunsn t (car sfunsn)))))
9104 (funcall (caar sfuns)))
9105 (setq link (plist-get org-store-link-plist :link)
9106 desc (or (plist-get org-store-link-plist :description) link))))
9107 ((org-src-edit-buffer-p)
9109 (while (or (not label)
9113 (goto-char (point-min))
9115 (regexp-quote (format org-coderef-label-format label))
9117 (when label (message "Label exists already") (sit-for 2))
9118 (setq label (read-string "Code line label: " label)))
9120 (setq link (format org-coderef-label-format label))
9121 (setq gc (- 79 (length link)))
9122 (if (< (current-column) gc) (org-move-to-column gc t) (insert " "))
9124 (setq link (concat "(" label ")") desc nil)))
9126 ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
9127 ;; We are in the agenda, link to referenced location
9128 (let ((m (or (get-text-property (point) 'org-hd-marker)
9129 (get-text-property (point) 'org-marker))))
9131 (org-with-point-at m
9133 (if (org-called-interactively-p 'any)
9134 (call-interactively 'org-store-link)
9135 (org-store-link nil)))))))
9137 ((eq major-mode 'calendar-mode)
9138 (let ((cd (calendar-cursor-to-date)))
9141 (car org-time-stamp-formats)
9143 (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd)
9145 (org-store-link-props :type "calendar" :date cd)))
9147 ((eq major-mode 'help-mode)
9148 (setq link (concat "help:" (save-excursion
9149 (goto-char (point-min))
9150 (looking-at "^[^ ]+")
9152 (org-store-link-props :type "help"))
9154 ((eq major-mode 'w3-mode)
9155 (setq cpltxt (if (and (buffer-name)
9156 (not (string-match "Untitled" (buffer-name))))
9159 link (url-view-url t))
9160 (org-store-link-props :type "w3" :url (url-view-url t)))
9162 ((setq search (run-hook-with-args-until-success
9163 'org-create-file-search-functions))
9164 (setq link (concat "file:" (abbreviate-file-name buffer-file-name)
9166 (setq cpltxt (or description link)))
9168 ((eq major-mode 'image-mode)
9169 (setq cpltxt (concat "file:"
9170 (abbreviate-file-name buffer-file-name))
9172 (org-store-link-props :type "image" :file buffer-file-name))
9174 ((eq major-mode 'dired-mode)
9175 ;; link to the file in the current line
9176 (let ((file (dired-get-filename nil t)))
9178 (abbreviate-file-name
9179 (expand-file-name (dired-get-filename nil t)))
9180 ;; otherwise, no file so use current directory.
9182 (setq cpltxt (concat "file:" file)
9185 ((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode))
9186 (setq custom-id (org-entry-get nil "CUSTOM_ID"))
9188 ((org-in-regexp "<<\\(.*?\\)>>")
9191 (abbreviate-file-name
9192 (buffer-file-name (buffer-base-buffer)))
9193 "::" (match-string 1))
9195 ((and (featurep 'org-id)
9196 (or (eq org-id-link-to-org-use-id t)
9197 (and (org-called-interactively-p 'any)
9198 (or (eq org-id-link-to-org-use-id 'create-if-interactive)
9199 (and (eq org-id-link-to-org-use-id
9200 'create-if-interactive-and-no-custom-id)
9202 (and org-id-link-to-org-use-id (org-entry-get nil "ID"))))
9203 ;; We can make a link using the ID.
9204 (setq link (condition-case nil
9205 (prog1 (org-id-store-link)
9206 (setq desc (plist-get org-store-link-plist :description)))
9208 ;; probably before first headline, link to file only
9210 (abbreviate-file-name
9211 (buffer-file-name (buffer-base-buffer))))))))
9213 ;; Just link to current headline
9214 (setq cpltxt (concat "file:"
9215 (abbreviate-file-name
9216 (buffer-file-name (buffer-base-buffer)))))
9217 ;; Add a context search string
9218 (when (org-xor org-context-in-file-links arg)
9219 (let* ((ee (org-element-at-point))
9220 (et (org-element-type ee))
9221 (ev (plist-get (cadr ee) :value)))
9223 ((org-at-heading-p) nil)
9224 ((eq et 'keyword) ev)
9225 ((org-region-active-p)
9226 (buffer-substring (region-beginning) (region-end)))))
9227 (when (or (null txt) (string-match "\\S-" txt))
9231 (org-make-org-heading-search-string txt)
9233 desc (or (and (eq et 'keyword) ev)
9234 (nth 4 (ignore-errors (org-heading-components)))
9236 (if (string-match "::\\'" cpltxt)
9237 (setq cpltxt (substring cpltxt 0 -2)))
9238 (setq link cpltxt))))
9240 ((buffer-file-name (buffer-base-buffer))
9241 ;; Just link to this file here.
9242 (setq cpltxt (concat "file:"
9243 (abbreviate-file-name
9244 (buffer-file-name (buffer-base-buffer)))))
9245 ;; Add a context string
9246 (when (org-xor org-context-in-file-links arg)
9247 (setq txt (if (org-region-active-p)
9248 (buffer-substring (region-beginning) (region-end))
9249 (buffer-substring (point-at-bol) (point-at-eol))))
9250 ;; Only use search option if there is some text.
9251 (when (string-match "\\S-" txt)
9253 (concat cpltxt "::" (org-make-org-heading-search-string txt))
9257 ((org-called-interactively-p 'interactive)
9258 (user-error "No method for storing a link from this buffer"))
9260 (t (setq link nil)))
9262 (if (consp link) (setq cpltxt (car link) link (cdr link)))
9263 (setq link (or link cpltxt)
9264 desc (or desc cpltxt))
9265 (cond ((equal desc "NONE") (setq desc nil))
9266 ((string-match org-bracket-link-regexp desc)
9267 (setq desc (replace-regexp-in-string
9268 org-bracket-link-regexp
9269 (concat "\\3" (if (equal (length (match-string 0 desc))
9270 (length desc)) "*" "")) desc))))
9272 (if (and (or (org-called-interactively-p 'any) executing-kbd-macro) link)
9274 (setq org-stored-links
9275 (cons (list link desc) org-stored-links))
9276 (message "Stored: %s" (or desc link))
9278 (setq link (concat "file:" (abbreviate-file-name (buffer-file-name))
9280 (setq org-stored-links
9281 (cons (list link desc) org-stored-links))))
9282 (or agenda-link (and link (org-make-link-string link desc)))))))
9284 (defun org-store-link-props (&rest plist)
9285 "Store link properties, extract names and addresses."
9287 (when (setq x (plist-get plist :from))
9288 (setq adr (mail-extract-address-components x))
9289 (setq plist (plist-put plist :fromname (car adr)))
9290 (setq plist (plist-put plist :fromaddress (nth 1 adr))))
9291 (when (setq x (plist-get plist :to))
9292 (setq adr (mail-extract-address-components x))
9293 (setq plist (plist-put plist :toname (car adr)))
9294 (setq plist (plist-put plist :toaddress (nth 1 adr)))))
9295 (let ((from (plist-get plist :from))
9296 (to (plist-get plist :to)))
9297 (when (and from to org-from-is-user-regexp)
9299 (plist-put plist :fromto
9300 (if (string-match org-from-is-user-regexp from)
9302 (concat "from %f"))))))
9303 (setq org-store-link-plist plist))
9305 (defun org-add-link-props (&rest plist)
9306 "Add these properties to the link property list."
9309 (setq key (pop plist) value (pop plist))
9310 (setq org-store-link-plist
9311 (plist-put org-store-link-plist key value)))))
9313 (defun org-email-link-description (&optional fmt)
9314 "Return the description part of an email link.
9315 This takes information from `org-store-link-plist' and formats it
9316 according to FMT (default from `org-email-link-description-format')."
9317 (setq fmt (or fmt org-email-link-description-format))
9318 (let* ((p org-store-link-plist)
9319 (to (plist-get p :toaddress))
9320 (from (plist-get p :fromaddress))
9323 (cons "%c" (plist-get p :fromto))
9324 (cons "%F" (plist-get p :from))
9325 (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?"))
9326 (cons "%T" (plist-get p :to))
9327 (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?"))
9328 (cons "%s" (plist-get p :subject))
9329 (cons "%d" (plist-get p :date))
9330 (cons "%m" (plist-get p :message-id)))))
9331 (when (string-match "%c" fmt)
9332 ;; Check if the user wrote this message
9333 (if (and org-from-is-user-regexp from to
9334 (save-match-data (string-match org-from-is-user-regexp from)))
9335 (setq fmt (replace-match "to %t" t t fmt))
9336 (setq fmt (replace-match "from %f" t t fmt))))
9337 (org-replace-escapes fmt table)))
9339 (defun org-make-org-heading-search-string (&optional string)
9340 "Make search string for the current headline or STRING."
9342 (and (derived-mode-p 'org-mode)
9344 (org-back-to-heading t)
9345 (org-element-property :raw-value (org-element-at-point))))))
9346 (lines org-context-in-file-links))
9347 (or string (setq s (concat "*" s))) ; Add * for headlines
9348 (setq s (replace-regexp-in-string "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" s))
9349 (when (and string (integerp lines) (> lines 0))
9350 (let ((slines (org-split-string s "\n")))
9351 (when (< lines (length slines))
9354 (reverse (nthcdr (- (length slines) lines)
9355 (reverse slines))) "\n")))))
9356 (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
9358 (defun org-make-link-string (link &optional description)
9359 "Make a link with brackets, consisting of LINK and DESCRIPTION."
9360 (unless (string-match "\\S-" link)
9361 (error "Empty link"))
9362 (when (and description
9363 (stringp description)
9364 (not (string-match "\\S-" description)))
9365 (setq description nil))
9366 (when (stringp description)
9367 ;; Remove brackets from the description, they are fatal.
9368 (while (string-match "\\[" description)
9369 (setq description (replace-match "{" t t description)))
9370 (while (string-match "\\]" description)
9371 (setq description (replace-match "}" t t description))))
9372 (when (equal link description)
9373 ;; No description needed, it is identical
9374 (setq description nil))
9375 (when (and (not description)
9376 (not (string-match (org-image-file-name-regexp) link))
9377 (not (equal link (org-link-escape link))))
9378 (setq description (org-extract-attributes link)))
9380 (cond ((string-match (org-image-file-name-regexp) link) link)
9381 ((string-match org-link-types-re link)
9382 (concat (match-string 1 link)
9383 (org-link-escape (substring link (match-end 1)))))
9384 (t (org-link-escape link))))
9385 (concat "[[" link "]"
9386 (if description (concat "[" description "]") "")
9389 (defconst org-link-escape-chars
9390 '(?\ ?\[ ?\] ?\; ?\= ?\+)
9391 "List of characters that should be escaped in link.
9392 This is the list that is used for internal purposes.")
9394 (defconst org-link-escape-chars-browser
9396 "List of escapes for characters that are problematic in links.
9397 This is the list that is used before handing over to the browser.")
9399 (defun org-link-escape (text &optional table merge)
9400 "Return percent escaped representation of TEXT.
9401 TEXT is a string with the text to escape.
9402 Optional argument TABLE is a list with characters that should be
9403 escaped. When nil, `org-link-escape-chars' is used.
9404 If optional argument MERGE is set, merge TABLE into
9405 `org-link-escape-chars'."
9408 (mapc (lambda (defchr)
9409 (unless (member defchr table)
9410 (setq table (cons defchr table)))) org-link-escape-chars))
9412 (setq table org-link-escape-chars)))
9415 (if (or (member char table)
9416 (and (or (< char 32) (= char 37) (> char 126))
9418 (mapconcat (lambda (sequence-element)
9419 (format "%%%.2X" sequence-element))
9420 (or (encode-coding-char char 'utf-8)
9421 (error "Unable to percent escape character: %s"
9422 (char-to-string char))) "")
9423 (char-to-string char))) text ""))
9425 (defun org-link-unescape (str)
9426 "Unhex hexified Unicode strings as returned from the JavaScript function
9427 encodeURIComponent. E.g. `%C3%B6' is the german o-Umlaut."
9428 (unless (and (null str) (string= "" str))
9429 (let ((pos 0) (case-fold-search t) unhexed)
9430 (while (setq pos (string-match "\\(%[0-9a-f][0-9a-f]\\)+" str pos))
9431 (setq unhexed (org-link-unescape-compound (match-string 0 str)))
9432 (setq str (replace-match unhexed t t str))
9433 (setq pos (+ pos (length unhexed))))))
9436 (defun org-link-unescape-compound (hex)
9437 "Unhexify Unicode hex-chars. E.g. `%C3%B6' is the German o-Umlaut.
9438 Note: this function also decodes single byte encodings like
9439 `%E1' (a-acute) if not followed by another `%[A-F0-9]{2}' group."
9441 (let* ((bytes (cdr (split-string hex "%")))
9446 (let* ((val (string-to-number (pop bytes) 16))
9450 ((>= val 252) (cons 6 252))
9451 ((>= val 248) (cons 5 248))
9452 ((>= val 240) (cons 4 240))
9453 ((>= val 224) (cons 3 224))
9454 ((>= val 192) (cons 2 192))
9457 (if (>= val 192) (setq eat (car shift-xor)))
9458 (setq val (logxor val (cdr shift-xor)))
9459 (setq sum (+ (lsh sum (car shift-xor)) val))
9460 (if (> eat 0) (setq eat (- eat 1)))
9462 ((= 0 eat) ;multi byte
9463 (setq ret (concat ret (org-char-to-string sum)))
9465 ((not bytes) ; single byte(s)
9466 (setq ret (org-link-unescape-single-byte-sequence hex))))
9467 )) ;; end (while bytes
9470 (defun org-link-unescape-single-byte-sequence (hex)
9471 "Unhexify hex-encoded single byte character sequences."
9472 (mapconcat (lambda (byte)
9473 (char-to-string (string-to-number byte 16)))
9474 (cdr (split-string hex "%")) ""))
9476 (defun org-xor (a b)
9480 (defun org-fixup-message-id-for-http (s)
9481 "Replace special characters in a message id, so it can be used in an http query."
9482 (when (string-match "%" s)
9483 (setq s (mapconcat (lambda (c)
9486 (char-to-string c)))
9488 (while (string-match "<" s)
9489 (setq s (replace-match "%3C" t t s)))
9490 (while (string-match ">" s)
9491 (setq s (replace-match "%3E" t t s)))
9492 (while (string-match "@" s)
9493 (setq s (replace-match "%40" t t s)))
9496 (defun org-link-prettify (link)
9497 "Return a human-readable representation of LINK.
9498 The car of LINK must be a raw link the cdr of LINK must be either
9499 a link description or nil."
9500 (let ((desc (or (cadr link) "<no description>")))
9501 (concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
9502 "<" (car link) ">")))
9505 (defun org-insert-link-global ()
9506 "Insert a link like Org-mode does.
9507 This command can be called in any mode to insert a link in Org-mode syntax."
9509 (org-load-modules-maybe)
9510 (org-run-like-in-org-mode 'org-insert-link))
9512 (defun org-insert-all-links (&optional keep)
9513 "Insert all links in `org-stored-links'."
9515 (let ((links (copy-sequence org-stored-links)) l)
9516 (while (setq l (if keep (pop links) (pop org-stored-links)))
9518 (org-insert-link nil (car l) (cadr l))
9521 (defun org-link-fontify-links-to-this-file ()
9522 "Fontify links to the current file in `org-stored-links'."
9523 (let ((f (buffer-file-name)) a b)
9524 (setq a (mapcar (lambda(l)
9526 (when (and (string-match "^file:\\(.+\\)::" ll)
9527 (equal f (expand-file-name (match-string 1 ll))))
9530 (when (featurep 'org-id)
9531 (setq b (mapcar (lambda(l)
9533 (when (and (string-match "^id:\\(.+\\)$" ll)
9534 (equal f (expand-file-name
9535 (or (org-id-find-id-file
9536 (match-string 1 ll)) ""))))
9540 (put-text-property 0 (length l) 'face 'font-lock-comment-face l))
9541 (delq nil (append a b)))))
9543 (defvar org-link-links-in-this-file nil)
9544 (defun org-insert-link (&optional complete-file link-location default-description)
9545 "Insert a link. At the prompt, enter the link.
9547 Completion can be used to insert any of the link protocol prefixes like
9550 The history can be used to select a link previously stored with
9551 `org-store-link'. When the empty string is entered (i.e. if you just
9552 press RET at the prompt), the link defaults to the most recently
9553 stored link. As SPC triggers completion in the minibuffer, you need to
9554 use M-SPC or C-q SPC to force the insertion of a space character.
9556 You will also be prompted for a description, and if one is given, it will
9557 be displayed in the buffer instead of the link.
9559 If there is already a link at point, this command will allow you to edit link
9560 and description parts.
9562 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can
9563 be selected using completion. The path to the file will be relative to the
9564 current directory if the file is in the current directory or a subdirectory.
9565 Otherwise, the link will be the absolute path as completed in the minibuffer
9566 \(i.e. normally ~/path/to/file). You can configure this behavior using the
9567 option `org-link-file-path-type'.
9569 With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in
9570 the current directory or below.
9572 With three \\[universal-argument] prefixes, negate the meaning of
9573 `org-keep-stored-link-after-insertion'.
9575 If `org-make-link-description-function' is non-nil, this function will be
9576 called with the link target, and the result will be the default
9579 If the LINK-LOCATION parameter is non-nil, this value will be
9580 used as the link location instead of reading one interactively.
9582 If the DEFAULT-DESCRIPTION parameter is non-nil, this value will
9583 be used as the default description."
9585 (let* ((wcf (current-window-configuration))
9586 (origbuf (current-buffer))
9587 (region (if (org-region-active-p)
9588 (buffer-substring (region-beginning) (region-end))))
9589 (remove (and region (list (region-beginning) (region-end))))
9591 tmphist ; byte-compile incorrectly complains about this
9592 (link link-location)
9593 (abbrevs org-link-abbrev-alist-local)
9594 entry file all-prefixes auto-desc)
9596 (link-location) ; specified by arg, just use it.
9597 ((org-in-regexp org-bracket-link-regexp 1)
9598 ;; We do have a link at point, and we are going to edit it.
9599 (setq remove (list (match-beginning 0) (match-end 0)))
9600 (setq desc (if (match-end 3) (org-match-string-no-properties 3)))
9601 (setq link (read-string "Link: "
9603 (org-match-string-no-properties 1)))))
9604 ((or (org-in-regexp org-angle-link-re)
9605 (org-in-regexp org-plain-link-re))
9606 ;; Convert to bracket link
9607 (setq remove (list (match-beginning 0) (match-end 0))
9608 link (read-string "Link: "
9609 (org-remove-angle-brackets (match-string 0)))))
9610 ((member complete-file '((4) (16)))
9611 ;; Completing read for file names.
9612 (setq link (org-file-complete-link complete-file)))
9614 ;; Read link, with completion for stored links.
9615 (org-link-fontify-links-to-this-file)
9616 (org-switch-to-buffer-other-window "*Org Links*")
9617 (with-current-buffer "*Org Links*"
9619 (insert "Insert a link.
9620 Use TAB to complete link prefixes, then RET for type-specific completion support\n")
9621 (when org-stored-links
9622 (insert "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
9623 (insert (mapconcat 'org-link-prettify
9624 (reverse org-stored-links) "\n")))
9625 (goto-char (point-min)))
9626 (let ((cw (selected-window)))
9627 (select-window (get-buffer-window "*Org Links*" 'visible))
9628 (with-current-buffer "*Org Links*" (setq truncate-lines t))
9629 (unless (pos-visible-in-window-p (point-max))
9630 (org-fit-window-to-buffer))
9631 (and (window-live-p cw) (select-window cw)))
9632 ;; Fake a link history, containing the stored links.
9633 (setq tmphist (append (mapcar 'car org-stored-links)
9634 org-insert-link-history))
9635 (setq all-prefixes (append (mapcar 'car abbrevs)
9636 (mapcar 'car org-link-abbrev-alist)
9641 (org-completing-read
9644 (mapcar (lambda (x) (concat x ":"))
9646 (mapcar 'car org-stored-links))
9649 (caar org-stored-links)))
9650 (if (not (string-match "\\S-" link))
9651 (error "No link selected"))
9653 (when (equal link (cadr l)) (setq link (car l) auto-desc t)))
9655 (if (or (member link all-prefixes)
9656 (and (equal ":" (substring link -1))
9657 (member (substring link 0 -1) all-prefixes)
9658 (setq link (substring link 0 -1))))
9659 (setq link (with-current-buffer origbuf
9660 (org-link-try-special-completion link)))))
9661 (set-window-configuration wcf)
9662 (kill-buffer "*Org Links*"))
9663 (setq entry (assoc link org-stored-links))
9664 (or entry (push link org-insert-link-history))
9665 (setq desc (or desc (nth 1 entry)))))
9667 (if (funcall (if (equal complete-file '(64)) 'not 'identity)
9668 (not org-keep-stored-link-after-insertion))
9669 (setq org-stored-links (delq (assoc link org-stored-links)
9672 (if (string-match org-plain-link-re link)
9673 ;; URL-like link, normalize the use of angular brackets.
9674 (setq link (org-remove-angle-brackets link)))
9676 ;; Check if we are linking to the current file with a search
9677 ;; option If yes, simplify the link by using only the search
9679 (when (and buffer-file-name
9680 (string-match "^file:\\(.+?\\)::\\(.+\\)" link))
9681 (let* ((path (match-string 1 link))
9682 (case-fold-search nil)
9683 (search (match-string 2 link)))
9685 (if (equal (file-truename buffer-file-name) (file-truename path))
9686 ;; We are linking to this same file, with a search option
9687 (setq link search)))))
9689 ;; Check if we can/should use a relative path. If yes, simplify the link
9690 (when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
9691 (let* ((type (match-string 1 link))
9692 (path (match-string 2 link))
9694 (case-fold-search nil))
9696 ((or (eq org-link-file-path-type 'absolute)
9697 (equal complete-file '(16)))
9698 (setq path (abbreviate-file-name (expand-file-name path))))
9699 ((eq org-link-file-path-type 'noabbrev)
9700 (setq path (expand-file-name path)))
9701 ((eq org-link-file-path-type 'relative)
9702 (setq path (file-relative-name path)))
9705 (if (string-match (concat "^" (regexp-quote
9707 (file-name-as-directory
9708 default-directory))))
9709 (expand-file-name path))
9710 ;; We are linking a file with relative path name.
9711 (setq path (substring (expand-file-name path)
9713 (setq path (abbreviate-file-name (expand-file-name path)))))))
9714 (setq link (concat type path))
9715 (if (equal desc origpath)
9718 (if org-make-link-description-function
9720 (or (condition-case nil
9721 (funcall org-make-link-description-function link desc)
9722 (error (progn (message "Can't get link description from `%s'"
9723 (symbol-name org-make-link-description-function))
9725 (read-string "Description: " default-description)))
9726 (if default-description (setq desc default-description)
9727 (setq desc (or (and auto-desc desc)
9728 (read-string "Description: " desc)))))
9730 (unless (string-match "\\S-" desc) (setq desc nil))
9731 (if remove (apply 'delete-region remove))
9732 (insert (org-make-link-string link desc))))
9734 (defun org-link-try-special-completion (type)
9735 "If there is completion support for link type TYPE, offer it."
9736 (let ((fun (intern (concat "org-" type "-complete-link"))))
9739 (read-string "Link (no completion support): " (concat type ":")))))
9741 (defun org-file-complete-link (&optional arg)
9742 "Create a file link using completion."
9744 (setq file (org-iread-file-name "File: "))
9745 (let ((pwd (file-name-as-directory (expand-file-name ".")))
9746 (pwd1 (file-name-as-directory (abbreviate-file-name
9747 (expand-file-name ".")))))
9752 (abbreviate-file-name (expand-file-name file)))))
9753 ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file)
9754 (setq link (concat "file:" (match-string 1 file))))
9755 ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)")
9756 (expand-file-name file))
9758 "file:" (match-string 1 (expand-file-name file)))))
9759 (t (setq link (concat "file:" file)))))
9762 (defun org-iread-file-name (&rest args)
9763 "Read-file-name using `ido-mode' speedup if available.
9764 ARGS are arguments that may be passed to `ido-read-file-name' or `read-file-name'.
9765 See `read-file-name' for a description of parameters."
9766 (org-without-partial-completion
9767 (if (and org-completion-use-ido
9768 (fboundp 'ido-read-file-name)
9769 (boundp 'ido-mode) ido-mode
9770 (listp (second args)))
9771 (let ((ido-enter-matching-directory nil))
9772 (apply 'ido-read-file-name args))
9773 (apply 'read-file-name args))))
9775 (defun org-completing-read (&rest args)
9776 "Completing-read with SPACE being a normal character."
9777 (let ((enable-recursive-minibuffers t)
9778 (minibuffer-local-completion-map
9779 (copy-keymap minibuffer-local-completion-map)))
9780 (org-defkey minibuffer-local-completion-map " " 'self-insert-command)
9781 (org-defkey minibuffer-local-completion-map "?" 'self-insert-command)
9782 (org-defkey minibuffer-local-completion-map (kbd "C-c !") 'org-time-stamp-inactive)
9783 (apply 'org-icompleting-read args)))
9785 (defun org-completing-read-no-i (&rest args)
9786 (let (org-completion-use-ido org-completion-use-iswitchb)
9787 (apply 'org-completing-read args)))
9789 (defun org-iswitchb-completing-read (prompt choices &rest args)
9790 "Use iswitch as a completing-read replacement to choose from choices.
9791 PROMPT is a string to prompt with. CHOICES is a list of strings to choose
9793 (let* ((iswitchb-use-virtual-buffers nil)
9794 (iswitchb-make-buflist-hook
9796 (setq iswitchb-temp-buflist choices))))
9797 (iswitchb-read-buffer prompt)))
9799 (defun org-icompleting-read (&rest args)
9800 "Completing-read using `ido-mode' or `iswitchb' speedups if available."
9801 (org-without-partial-completion
9802 (if (and org-completion-use-ido
9803 (fboundp 'ido-completing-read)
9804 (boundp 'ido-mode) ido-mode
9805 (listp (second args)))
9806 (let ((ido-enter-matching-directory nil))
9807 (apply 'ido-completing-read (concat (car args))
9808 (if (consp (car (nth 1 args)))
9809 (mapcar 'car (nth 1 args))
9812 (if (and org-completion-use-iswitchb
9813 (boundp 'iswitchb-mode) iswitchb-mode
9814 (listp (second args)))
9815 (apply 'org-iswitchb-completing-read (concat (car args))
9816 (if (consp (car (nth 1 args)))
9817 (mapcar 'car (nth 1 args))
9820 (apply 'completing-read args)))))
9822 (defun org-extract-attributes (s)
9823 "Extract the attributes cookie from a string and set as text property."
9824 (let (a attr (start 0) key value)
9826 (when (string-match "{{\\([^}]+\\)}}$" s)
9827 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
9828 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
9829 (setq key (match-string 1 a) value (match-string 2 a)
9831 attr (plist-put attr (intern key) value))))
9832 (org-add-props s nil 'org-attr attr))
9835 (defun org-extract-attributes-from-string (tag)
9836 (let (key value attr)
9837 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"\\s-?" tag)
9838 (setq key (match-string 1 tag) value (match-string 2 tag)
9839 tag (replace-match "" t t tag)
9840 attr (plist-put attr (intern key) value)))
9843 (defun org-attributes-to-string (plist)
9844 "Format a property list into an HTML attribute list."
9845 (let ((s "") key value)
9847 (setq key (pop plist) value (pop plist))
9849 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
9852 ;;; Opening/following a link
9854 (defvar org-link-search-failed nil)
9856 (defvar org-open-link-functions nil
9857 "Hook for functions finding a plain text link.
9858 These functions must take a single argument, the link content.
9859 They will be called for links that look like [[link text][description]]
9860 when LINK TEXT does not have a protocol like \"http:\" and does not look
9861 like a filename (e.g. \"./blue.png\").
9863 These functions will be called *before* Org attempts to resolve the
9864 link by doing text searches in the current buffer - so if you want a
9865 link \"[[target]]\" to still find \"<<target>>\", your function should
9866 handle this as a special case.
9868 When the function does handle the link, it must return a non-nil value.
9869 If it decides that it is not responsible for this link, it must return
9870 nil to indicate that that Org-mode can continue with other options
9871 like exact and fuzzy text search.")
9873 (defun org-next-link (&optional search-backward)
9874 "Move forward to the next link.
9875 If the link is in hidden text, expose it."
9877 (when (and org-link-search-failed (eq this-command last-command))
9878 (goto-char (point-min))
9879 (message "Link search wrapped back to beginning of buffer"))
9880 (setq org-link-search-failed nil)
9881 (let* ((pos (point))
9883 (a (assoc :link ct))
9884 (srch-fun (if search-backward 're-search-backward 're-search-forward)))
9885 (cond (a (goto-char (nth (if search-backward 1 2) a)))
9886 ((looking-at org-any-link-re)
9887 ;; Don't stay stuck at link without an org-link face
9888 (forward-char (if search-backward -1 1))))
9889 (if (funcall srch-fun org-any-link-re nil t)
9891 (goto-char (match-beginning 0))
9892 (if (outline-invisible-p) (org-show-context)))
9894 (setq org-link-search-failed t)
9895 (message "No further link found"))))
9897 (defun org-previous-link ()
9898 "Move backward to the previous link.
9899 If the link is in hidden text, expose it."
9901 (funcall 'org-next-link t))
9903 (defun org-translate-link (s)
9904 "Translate a link string if a translation function has been defined."
9905 (if (and org-link-translation-function
9906 (fboundp org-link-translation-function)
9907 (string-match "\\([a-zA-Z0-9]+\\):\\(.*\\)" s))
9909 (setq s (funcall org-link-translation-function
9910 (match-string 1 s) (match-string 2 s)))
9911 (concat (car s) ":" (cdr s)))
9914 (defun org-translate-link-from-planner (type path)
9915 "Translate a link from Emacs Planner syntax so that Org can follow it.
9916 This is still an experimental function, your mileage may vary."
9918 ((member type '("http" "https" "news" "ftp"))
9919 ;; standard Internet links are the same.
9921 ((and (equal type "irc") (string-match "^//" path))
9922 ;; Planner has two / at the beginning of an irc link, we have 1.
9923 ;; We should have zero, actually....
9924 (setq path (substring path 1)))
9925 ((and (equal type "lisp") (string-match "^/" path))
9926 ;; Planner has a slash, we do not.
9927 (setq type "elisp" path (substring path 1)))
9928 ((string-match "^//\\(.?*\\)/\\(<.*>\\)$" path)
9929 ;; A typical message link. Planner has the id after the final slash,
9930 ;; we separate it with a hash mark
9931 (setq path (concat (match-string 1 path) "#"
9932 (org-remove-angle-brackets (match-string 2 path)))))
9936 (defun org-find-file-at-mouse (ev)
9937 "Open file link or URL at mouse."
9939 (mouse-set-point ev)
9940 (org-open-at-point 'in-emacs))
9942 (defun org-open-at-mouse (ev)
9943 "Open file link or URL at mouse.
9944 See the docstring of `org-open-file' for details."
9946 (mouse-set-point ev)
9947 (if (eq major-mode 'org-agenda-mode)
9948 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local))
9949 (org-open-at-point))
9951 (defvar org-window-config-before-follow-link nil
9952 "The window configuration before following a link.
9953 This is saved in case the need arises to restore it.")
9955 (defvar org-open-link-marker (make-marker)
9956 "Marker pointing to the location where `org-open-at-point; was called.")
9959 (defun org-open-at-point-global ()
9960 "Follow a link like Org-mode does.
9961 This command can be called in any mode to follow a link that has
9964 (org-run-like-in-org-mode 'org-open-at-point))
9967 (defun org-open-link-from-string (s &optional arg reference-buffer)
9968 "Open a link in the string S, as if it was in Org-mode."
9969 (interactive "sLink: \nP")
9970 (let ((reference-buffer (or reference-buffer (current-buffer))))
9972 (let ((org-inhibit-startup (not reference-buffer)))
9975 (goto-char (point-min))
9976 (when reference-buffer
9977 (setq org-link-abbrev-alist-local
9978 (with-current-buffer reference-buffer
9979 org-link-abbrev-alist-local)))
9980 (org-open-at-point arg reference-buffer)))))
9982 (defvar org-open-at-point-functions nil
9983 "Hook that is run when following a link at point.
9985 Functions in this hook must return t if they identify and follow
9986 a link at point. If they don't find anything interesting at point,
9987 they must return nil.")
9989 (defvar clean-buffer-list-kill-buffer-names) ; Defined in midnight.el
9990 (defun org-open-at-point (&optional arg reference-buffer)
9991 "Open link at or after point.
9992 If there is no link at point, this function will search forward up to
9993 the end of the current line.
9994 Normally, files will be opened by an appropriate application. If the
9995 optional prefix argument ARG is non-nil, Emacs will visit the file.
9996 With a double prefix argument, try to open outside of Emacs, in the
9997 application the system uses for this file type."
9999 ;; if in a code block, then open the block's results
10000 (unless (call-interactively #'org-babel-open-src-block-result)
10001 (org-load-modules-maybe)
10002 (move-marker org-open-link-marker (point))
10003 (setq org-window-config-before-follow-link (current-window-configuration))
10004 (org-remove-occur-highlights nil nil t)
10006 ((and (org-at-heading-p)
10007 (not (org-at-timestamp-p t))
10008 (not (org-in-regexp
10009 (concat org-plain-link-re "\\|"
10010 org-bracket-link-regexp "\\|"
10011 org-angle-link-re "\\|"
10012 "[ \t]:[^ \t\n]+:[ \t]*$")))
10013 (not (get-text-property (point) 'org-linked-text)))
10014 (or (let* ((lkall (org-offer-links-in-entry (current-buffer) (point) arg))
10016 (lk (if (stringp lk0) (list lk0) lk0))
10017 (lkend (cdr lkall)))
10019 (search-forward l nil lkend)
10020 (goto-char (match-beginning 0))
10021 (org-open-at-point))
10023 (progn (require 'org-attach) (org-attach-reveal 'if-exists))))
10024 ((run-hook-with-args-until-success 'org-open-at-point-functions))
10025 ((and (org-at-timestamp-p t)
10026 (not (org-in-regexp org-bracket-link-regexp)))
10027 (org-follow-timestamp-link))
10028 ((and (or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
10029 (not (org-in-regexp org-any-link-re)))
10030 (org-footnote-action))
10032 (let (type path link line search (pos (point)))
10035 (skip-chars-forward "^]\n\r")
10036 (when (org-in-regexp org-bracket-link-regexp 1)
10037 (setq link (org-extract-attributes
10038 (org-link-unescape (org-match-string-no-properties 1))))
10039 (while (string-match " *\n *" link)
10040 (setq link (replace-match " " t t link)))
10041 (setq link (org-link-expand-abbrev link))
10043 ((or (file-name-absolute-p link)
10044 (string-match "^\\.\\.?/" link))
10045 (setq type "file" path link))
10046 ((string-match org-link-re-with-space3 link)
10047 (setq type (match-string 1 link) path (match-string 2 link)))
10048 ((string-match "^help:+\\(.+\\)" link)
10049 (setq type "help" path (match-string 1 link)))
10050 (t (setq type "thisfile" path link)))
10053 (when (get-text-property (point) 'org-linked-text)
10054 (setq type "thisfile"
10055 pos (if (get-text-property (1+ (point)) 'org-linked-text)
10056 (1+ (point)) (point))
10057 path (buffer-substring
10058 (or (previous-single-property-change pos 'org-linked-text)
10060 (or (next-single-property-change pos 'org-linked-text)
10065 (when (or (org-in-regexp org-angle-link-re)
10066 (let ((match (org-in-regexp org-plain-link-re)))
10067 ;; Check a plain link is not within a bracket link
10071 (goto-char (car match))
10072 (not (org-in-regexp org-bracket-link-regexp))))))
10073 (let ((line_ending (save-excursion (end-of-line) (point))))
10074 ;; We are in a line before a plain or bracket link
10075 (or (re-search-forward org-plain-link-re line_ending t)
10076 (re-search-forward org-bracket-link-regexp line_ending t))))
10077 (setq type (match-string 1)
10078 path (org-link-unescape (match-string 2)))
10081 (when (org-in-regexp (org-re "\\(:[[:alnum:]_@#%:]+\\):[ \t]*$"))
10083 path (match-string 1))
10084 (while (string-match ":" path)
10085 (setq path (replace-match "+" t t path)))
10087 (when (org-in-regexp "<\\([^><\n]+\\)>")
10088 (setq type "tree-match"
10089 path (match-string 1))
10092 (user-error "No link found"))
10094 ;; switch back to reference buffer
10095 ;; needed when if called in a temporary buffer through
10096 ;; org-open-link-from-string
10097 (with-current-buffer (or reference-buffer (current-buffer))
10099 ;; Remove any trailing spaces in path
10100 (if (string-match " +\\'" path)
10101 (setq path (replace-match "" t t path)))
10102 (if (and org-link-translation-function
10103 (fboundp org-link-translation-function))
10104 ;; Check if we need to translate the link
10105 (let ((tmp (funcall org-link-translation-function type path)))
10106 (setq type (car tmp) path (cdr tmp))))
10110 ((assoc type org-link-protocols)
10111 (funcall (nth 1 (assoc type org-link-protocols)) path))
10113 ((equal type "help")
10114 (let ((f-or-v (intern path)))
10115 (cond ((fboundp f-or-v)
10116 (describe-function f-or-v))
10118 (describe-variable f-or-v))
10119 (t (error "Not a known function or variable")))))
10121 ((equal type "mailto")
10122 (let ((cmd (car org-link-mailto-program))
10123 (args (cdr org-link-mailto-program)) args1
10124 (address path) (subject "") a)
10125 (if (string-match "\\(.*\\)::\\(.*\\)" path)
10126 (setq address (match-string 1 path)
10127 subject (org-link-escape (match-string 2 path))))
10130 ((not (stringp (car args))) (push (pop args) args1))
10131 (t (setq a (pop args))
10132 (if (string-match "%a" a)
10133 (setq a (replace-match address t t a)))
10134 (if (string-match "%s" a)
10135 (setq a (replace-match subject t t a)))
10137 (apply cmd (nreverse args1))))
10139 ((member type '("http" "https" "ftp" "news"))
10140 (browse-url (concat type ":" (if (org-string-match-p "[[:nonascii:] ]" path)
10142 path org-link-escape-chars-browser)
10145 ((string= type "doi")
10146 (browse-url (concat org-doi-server-url (if (org-string-match-p "[[:nonascii:] ]" path)
10148 path org-link-escape-chars-browser)
10151 ((member type '("message"))
10152 (browse-url (concat type ":" path)))
10154 ((string= type "tags")
10155 (org-tags-view arg path))
10157 ((string= type "tree-match")
10158 (org-occur (concat "\\[" (regexp-quote path) "\\]")))
10160 ((string= type "file")
10161 (if (string-match "::\\([0-9]+\\)\\'" path)
10162 (setq line (string-to-number (match-string 1 path))
10163 path (substring path 0 (match-beginning 0)))
10164 (if (string-match "::\\(.+\\)\\'" path)
10165 (setq search (match-string 1 path)
10166 path (substring path 0 (match-beginning 0)))))
10167 (if (string-match "[*?{]" (file-name-nondirectory path))
10169 (org-open-file path arg line search)))
10171 ((string= type "shell")
10172 (let ((buf (generate-new-buffer "*Org Shell Output"))
10174 (if (or (and (not (string= org-confirm-shell-link-not-regexp ""))
10175 (string-match org-confirm-shell-link-not-regexp cmd))
10176 (not org-confirm-shell-link-function)
10177 (funcall org-confirm-shell-link-function
10178 (format "Execute \"%s\" in shell? "
10179 (org-add-props cmd nil
10180 'face 'org-warning))))
10182 (message "Executing %s" cmd)
10183 (shell-command cmd buf)
10184 (if (featurep 'midnight)
10185 (setq clean-buffer-list-kill-buffer-names
10186 (cons buf clean-buffer-list-kill-buffer-names))))
10189 ((string= type "elisp")
10191 (if (or (and (not (string= org-confirm-elisp-link-not-regexp ""))
10192 (string-match org-confirm-elisp-link-not-regexp cmd))
10193 (not org-confirm-elisp-link-function)
10194 (funcall org-confirm-elisp-link-function
10195 (format "Execute \"%s\" as elisp? "
10196 (org-add-props cmd nil
10197 'face 'org-warning))))
10198 (message "%s => %s" cmd
10199 (if (equal (string-to-char cmd) ?\()
10201 (call-interactively (read cmd))))
10204 ((and (string= type "thisfile")
10205 (run-hook-with-args-until-success
10206 'org-open-link-functions path)))
10208 ((string= type "thisfile")
10210 (switch-to-buffer-other-window
10211 (org-get-buffer-for-internal-link (current-buffer)))
10212 (org-mark-ring-push))
10213 (let ((cmd `(org-link-search
10215 ,(cond ((equal arg '(4)) ''occur)
10216 ((equal arg '(16)) ''org-occur))
10218 (condition-case nil (let ((org-link-search-inhibit-query t))
10220 (error (progn (widen) (eval cmd))))))
10222 (t (browse-url-at-point)))))))
10223 (move-marker org-open-link-marker nil)
10224 (run-hook-with-args 'org-follow-link-hook)))
10226 (defun org-offer-links-in-entry (buffer marker &optional nth zero)
10227 "Offer links in the current entry and return the selected link.
10228 If there is only one link, return it.
10229 If NTH is an integer, return the NTH link found.
10230 If ZERO is a string, check also this string for a link, and if
10231 there is one, return it."
10232 (with-current-buffer buffer
10237 (let ((re (concat "\\(" org-bracket-link-regexp "\\)\\|"
10238 "\\(" org-angle-link-re "\\)\\|"
10239 "\\(" org-plain-link-re "\\)"))
10241 (in-emacs (if (integerp nth) nil nth))
10242 have-zero end links link c)
10243 (when (and (stringp zero) (string-match org-bracket-link-regexp zero))
10244 (push (match-string 0 zero) links)
10245 (setq cnt (1- cnt) have-zero t))
10247 (org-back-to-heading t)
10248 (setq end (save-excursion (outline-next-heading) (point)))
10249 (while (re-search-forward re end t)
10250 (push (match-string 0) links))
10251 (setq links (org-uniquify (reverse links))))
10254 (message "No links"))
10255 ((equal (length links) 1)
10256 (setq link (car links)))
10257 ((and (integerp nth) (>= (length links) (if have-zero (1+ nth) nth)))
10258 (setq link (nth (if have-zero nth (1- nth)) links)))
10259 (t ; we have to select a link
10261 (save-window-excursion
10262 (delete-other-windows)
10263 (with-output-to-temp-buffer "*Select Link*"
10265 (if (not (string-match org-bracket-link-regexp l))
10266 (princ (format "[%c] %s\n" (incf cnt)
10267 (org-remove-angle-brackets l)))
10269 (princ (format "[%c] %s (%s)\n" (incf cnt)
10270 (match-string 3 l) (match-string 1 l)))
10271 (princ (format "[%c] %s\n" (incf cnt)
10272 (match-string 1 l))))))
10274 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
10275 (message "Select link to open, RET to open all:")
10276 (setq c (read-char-exclusive))
10277 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
10278 (when (equal c ?q) (error "Abort"))
10279 (if (equal c ?\C-m)
10281 (setq nth (- c ?0))
10282 (if have-zero (setq nth (1+ nth)))
10283 (unless (and (integerp nth) (>= (length links) nth))
10284 (error "Invalid link selection"))
10285 (setq link (nth (1- nth) links)))))
10286 (cons link end))))))
10288 ;; Add special file links that specify the way of opening
10290 (org-add-link-type "file+sys" 'org-open-file-with-system)
10291 (org-add-link-type "file+emacs" 'org-open-file-with-emacs)
10292 (defun org-open-file-with-system (path)
10293 "Open file at PATH using the system way of opening it."
10294 (org-open-file path 'system))
10295 (defun org-open-file-with-emacs (path)
10296 "Open file at PATH in Emacs."
10297 (org-open-file path 'emacs))
10302 (defvar org-create-file-search-functions nil
10303 "List of functions to construct the right search string for a file link.
10304 These functions are called in turn with point at the location to
10305 which the link should point.
10307 A function in the hook should first test if it would like to
10308 handle this file type, for example by checking the `major-mode'
10309 or the file extension. If it decides not to handle this file, it
10310 should just return nil to give other functions a chance. If it
10311 does handle the file, it must return the search string to be used
10312 when following the link. The search string will be part of the
10313 file link, given after a double colon, and `org-open-at-point'
10314 will automatically search for it. If special measures must be
10315 taken to make the search successful, another function should be
10316 added to the companion hook `org-execute-file-search-functions',
10319 A function in this hook may also use `setq' to set the variable
10320 `description' to provide a suggestion for the descriptive text to
10321 be used for this link when it gets inserted into an Org-mode
10322 buffer with \\[org-insert-link].")
10324 (defvar org-execute-file-search-functions nil
10325 "List of functions to execute a file search triggered by a link.
10327 Functions added to this hook must accept a single argument, the
10328 search string that was part of the file link, the part after the
10329 double colon. The function must first check if it would like to
10330 handle this search, for example by checking the `major-mode' or
10331 the file extension. If it decides not to handle this search, it
10332 should just return nil to give other functions a chance. If it
10333 does handle the search, it must return a non-nil value to keep
10334 other functions from trying.
10336 Each function can access the current prefix argument through the
10337 variable `current-prefix-argument'. Note that a single prefix is
10338 used to force opening a link in Emacs, so it may be good to only
10339 use a numeric or double prefix to guide the search function.
10341 In case this is needed, a function in this hook can also restore
10342 the window configuration before `org-open-at-point' was called using:
10344 (set-window-configuration org-window-config-before-follow-link)")
10346 (defvar org-link-search-inhibit-query nil) ;; dynamically scoped
10347 (defun org-link-search (s &optional type avoid-pos stealth)
10348 "Search for a link search option.
10349 If S is surrounded by forward slashes, it is interpreted as a
10350 regular expression. In org-mode files, this will create an `org-occur'
10351 sparse tree. In ordinary files, `occur' will be used to list matches.
10352 If the current buffer is in `dired-mode', grep will be used to search
10353 in all files. If AVOID-POS is given, ignore matches near that position.
10355 When optional argument STEALTH is non-nil, do not modify
10356 visibility around point, thus ignoring
10357 `org-show-hierarchy-above', `org-show-following-heading' and
10358 `org-show-siblings' variables."
10359 (let ((case-fold-search t)
10360 (s0 (mapconcat 'identity (org-split-string s "[ \t\r\n]+") " "))
10361 (markers (concat "\\(?:" (mapconcat (lambda (x) (regexp-quote (car x)))
10362 (append '(("") (" ") ("\t") ("\n"))
10363 org-emphasis-alist)
10366 (pre nil) (post nil)
10367 words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
10369 ;; First check if there are any special search functions
10370 ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
10371 ;; Now try the builtin stuff
10372 ((and (equal (string-to-char s0) ?#)
10375 (goto-char (point-min))
10378 (concat "^[ \t]*:CUSTOM_ID:[ \t]+" (regexp-quote (substring s0 1)) "[ \t]*$") nil t)
10379 (setq type 'dedicated
10380 pos (match-beginning 0))))
10381 ;; There is an exact target for this
10383 (org-back-to-heading t)))
10385 (goto-char (point-min))
10388 (concat "<<" (regexp-quote s0) ">>") nil t)
10389 (setq type 'dedicated
10390 pos (match-beginning 0))))
10391 ;; There is an exact target for this
10394 (goto-char (point-min))
10397 (format "^[ \t]*#\\+TARGET: %s" (regexp-quote s0)) nil t)
10398 (setq type 'dedicated pos (match-beginning 0))))
10399 ;; Found an invisible target.
10402 (goto-char (point-min))
10405 (format "^[ \t]*#\\+NAME: %s" (regexp-quote s0)) nil t)
10406 (setq type 'dedicated pos (match-beginning 0))))
10407 ;; Found an element with a matching #+name affiliated keyword.
10409 ((and (string-match "^(\\(.*\\))$" s0)
10411 (goto-char (point-min))
10414 (concat "[^[]" (regexp-quote
10415 (format org-coderef-label-format
10416 (match-string 1 s0))))
10418 (setq type 'dedicated
10419 pos (1+ (match-beginning 0))))))
10420 ;; There is a coderef target for this
10422 ((string-match "^/\\(.*\\)/$" s)
10423 ;; A regular expression
10425 ((derived-mode-p 'org-mode)
10426 (org-occur (match-string 1 s)))
10427 (t (org-do-occur (match-string 1 s)))))
10428 ((and (derived-mode-p 'org-mode) org-link-search-must-match-exact-headline)
10429 (and (equal (string-to-char s) ?*) (setq s (substring s 1)))
10430 (goto-char (point-min))
10432 ((let (case-fold-search)
10433 (re-search-forward (format org-complex-heading-regexp-format
10436 ;; OK, found a match
10437 (setq type 'dedicated)
10438 (goto-char (match-beginning 0)))
10439 ((and (not org-link-search-inhibit-query)
10440 (eq org-link-search-must-match-exact-headline 'query-to-create)
10441 (y-or-n-p "No match - create this as a new heading? "))
10442 (goto-char (point-max))
10443 (or (bolp) (newline))
10444 (insert "* " s "\n")
10445 (beginning-of-line 0))
10448 (error "No match"))))
10450 ;; A normal search string
10451 (when (equal (string-to-char s) ?*)
10452 ;; Anchor on headlines, post may include tags.
10453 (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
10454 post (org-re "[ \t]*\\(?:[ \t]+:[[:alnum:]_@#%:+]:[ \t]*\\)?$")
10455 s (substring s 1)))
10456 (remove-text-properties
10458 '(face nil mouse-face nil keymap nil fontified nil) s)
10459 ;; Make a series of regular expressions to find a match
10460 (setq words (org-split-string s "[ \n\r\t]+")
10462 re0 (concat "\\(<<" (regexp-quote s0) ">>\\)")
10463 re2 (concat markers "\\(" (mapconcat 'downcase words "[ \t]+")
10465 re2a_ (concat "\\(" (mapconcat 'downcase words "[ \t\r\n]+") "\\)[ \t\r\n]")
10466 re2a (concat "[ \t\r\n]" re2a_)
10467 re4_ (concat "\\(" (mapconcat 'downcase words "[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
10468 re4 (concat "[^a-zA-Z_]" re4_)
10470 re1 (concat pre re2 post)
10471 re3 (concat pre (if pre re4_ re4) post)
10472 re5 (concat pre ".*" re4)
10473 re2 (concat pre re2)
10474 re2a (concat pre (if pre re2a_ re2a))
10475 re4 (concat pre (if pre re4_ re4))
10476 reall (concat "\\(" re0 "\\)\\|\\(" re1 "\\)\\|\\(" re2
10477 "\\)\\|\\(" re3 "\\)\\|\\(" re4 "\\)\\|\\("
10481 ((eq type 'org-occur) (org-occur reall))
10482 ((eq type 'occur) (org-do-occur (downcase reall) 'cleanup))
10483 (t (goto-char (point-min))
10485 (if (or (and (org-search-not-self 1 re0 nil t) (setq type 'dedicated))
10486 (org-search-not-self 1 re1 nil t)
10487 (org-search-not-self 1 re2 nil t)
10488 (org-search-not-self 1 re2a nil t)
10489 (org-search-not-self 1 re3 nil t)
10490 (org-search-not-self 1 re4 nil t)
10491 (org-search-not-self 1 re5 nil t)
10493 (goto-char (match-beginning 1))
10495 (error "No match"))))))
10496 (and (derived-mode-p 'org-mode)
10498 (org-show-context 'link-search))
10501 (defun org-search-not-self (group &rest args)
10502 "Execute `re-search-forward', but only accept matches that do not
10503 enclose the position of `org-open-link-marker'."
10504 (let ((m org-open-link-marker))
10506 (while (apply 're-search-forward args)
10507 (unless (get-text-property (match-end group) 'intangible) ; Emacs 21
10508 (goto-char (match-end group))
10509 (if (and (or (not (eq (marker-buffer m) (current-buffer)))
10510 (> (match-beginning 0) (marker-position m))
10511 (< (match-end 0) (marker-position m)))
10513 (or (not (org-in-regexp
10514 org-bracket-link-analytic-regexp 1))
10515 (not (match-end 4)) ; no description
10516 (and (<= (match-beginning 4) (point))
10517 (>= (match-end 4) (point))))))
10518 (throw 'exit (point))))))))
10520 (defun org-get-buffer-for-internal-link (buffer)
10521 "Return a buffer to be used for displaying the link target of internal links."
10523 ((not org-display-internal-link-with-indirect-buffer)
10525 ((string-match "(Clone)$" (buffer-name buffer))
10526 (message "Buffer is already a clone, not making another one")
10527 ;; we also do not modify visibility in this case
10529 (t ; make a new indirect buffer for displaying the link
10530 (let* ((bn (buffer-name buffer))
10531 (ibn (concat bn "(Clone)"))
10532 (ib (or (get-buffer ibn) (make-indirect-buffer buffer ibn 'clone))))
10533 (with-current-buffer ib (org-overview))
10536 (defun org-do-occur (regexp &optional cleanup)
10537 "Call the Emacs command `occur'.
10538 If CLEANUP is non-nil, remove the printout of the regular expression
10539 in the *Occur* buffer. This is useful if the regex is long and not useful
10543 (let ((cwin (selected-window)) win beg end)
10544 (when (setq win (get-buffer-window "*Occur*"))
10545 (select-window win))
10546 (goto-char (point-min))
10547 (when (re-search-forward "match[a-z]+" nil t)
10548 (setq beg (match-end 0))
10549 (if (re-search-forward "^[ \t]*[0-9]+" nil t)
10550 (setq end (1- (match-beginning 0)))))
10551 (and beg end (let ((inhibit-read-only t)) (delete-region beg end)))
10552 (goto-char (point-min))
10553 (select-window cwin))))
10555 ;;; The mark ring for links jumps
10557 (defvar org-mark-ring nil
10558 "Mark ring for positions before jumps in Org-mode.")
10559 (defvar org-mark-ring-last-goto nil
10560 "Last position in the mark ring used to go back.")
10561 ;; Fill and close the ring
10562 (setq org-mark-ring nil org-mark-ring-last-goto nil) ;; in case file is reloaded
10563 (loop for i from 1 to org-mark-ring-length do
10564 (push (make-marker) org-mark-ring))
10565 (setcdr (nthcdr (1- org-mark-ring-length) org-mark-ring)
10568 (defun org-mark-ring-push (&optional pos buffer)
10569 "Put the current position or POS into the mark ring and rotate it."
10571 (setq pos (or pos (point)))
10572 (setq org-mark-ring (nthcdr (1- org-mark-ring-length) org-mark-ring))
10573 (move-marker (car org-mark-ring)
10575 (or buffer (current-buffer)))
10577 (substitute-command-keys
10578 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
10580 (defun org-mark-ring-goto (&optional n)
10581 "Jump to the previous position in the mark ring.
10582 With prefix arg N, jump back that many stored positions. When
10583 called several times in succession, walk through the entire ring.
10584 Org-mode commands jumping to a different position in the current file,
10585 or to another Org-mode file, automatically push the old position
10589 (if (eq last-command this-command)
10590 (setq p (nthcdr n (or org-mark-ring-last-goto org-mark-ring)))
10591 (setq p org-mark-ring))
10592 (setq org-mark-ring-last-goto p)
10594 (org-pop-to-buffer-same-window (marker-buffer m))
10596 (if (or (outline-invisible-p) (org-invisible-p2)) (org-show-context 'mark-goto))))
10598 (defun org-remove-angle-brackets (s)
10599 (if (equal (substring s 0 1) "<") (setq s (substring s 1)))
10600 (if (equal (substring s -1) ">") (setq s (substring s 0 -1)))
10602 (defun org-add-angle-brackets (s)
10603 (if (equal (substring s 0 1) "<") nil (setq s (concat "<" s)))
10604 (if (equal (substring s -1) ">") nil (setq s (concat s ">")))
10606 (defun org-remove-double-quotes (s)
10607 (if (equal (substring s 0 1) "\"") (setq s (substring s 1)))
10608 (if (equal (substring s -1) "\"") (setq s (substring s 0 -1)))
10611 ;;; Following specific links
10613 (defun org-follow-timestamp-link ()
10614 "Open an agenda view for the time-stamp date/range at point."
10616 ((org-at-date-range-p t)
10617 (let ((org-agenda-start-on-weekday)
10618 (t1 (match-string 1))
10619 (t2 (match-string 2)) tt1 tt2)
10620 (setq tt1 (time-to-days (org-time-string-to-time t1))
10621 tt2 (time-to-days (org-time-string-to-time t2)))
10622 (let ((org-agenda-buffer-tmp-name
10623 (format "*Org Agenda(a:%s)"
10624 (concat (substring t1 0 10) "--" (substring t2 0 10)))))
10625 (org-agenda-list nil tt1 (1+ (- tt2 tt1))))))
10626 ((org-at-timestamp-p t)
10627 (let ((org-agenda-buffer-tmp-name
10628 (format "*Org Agenda(a:%s)" (substring (match-string 1) 0 10))))
10629 (org-agenda-list nil (time-to-days (org-time-string-to-time
10630 (substring (match-string 1) 0 10)))
10632 (t (error "This should not happen"))))
10635 ;;; Following file links
10636 (declare-function mailcap-parse-mailcaps "mailcap" (&optional path force))
10637 (declare-function mailcap-extension-to-mime "mailcap" (extn))
10638 (declare-function mailcap-mime-info
10639 "mailcap" (string &optional request no-decode))
10640 (defvar org-wait nil)
10641 (defun org-open-file (path &optional in-emacs line search)
10642 "Open the file at PATH.
10643 First, this expands any special file name abbreviations. Then the
10644 configuration variable `org-file-apps' is checked if it contains an
10645 entry for this file type, and if yes, the corresponding command is launched.
10647 If no application is found, Emacs simply visits the file.
10649 With optional prefix argument IN-EMACS, Emacs will visit the file.
10650 With a double \\[universal-argument] \\[universal-argument] \
10651 prefix arg, Org tries to avoid opening in Emacs
10652 and to use an external application to visit the file.
10654 Optional LINE specifies a line to go to, optional SEARCH a string
10655 to search for. If LINE or SEARCH is given, the file will be
10656 opened in Emacs, unless an entry from org-file-apps that makes
10657 use of groups in a regexp matches.
10659 If you want to change the way frames are used when following a
10660 link, please customize `org-link-frame-setup'.
10662 If the file does not exist, an error is thrown."
10663 (let* ((file (if (equal path "")
10665 (substitute-in-file-name (expand-file-name path))))
10666 (file-apps (append org-file-apps (org-default-apps)))
10667 (apps (org-remove-if
10668 'org-file-apps-entry-match-against-dlink-p file-apps))
10669 (apps-dlink (org-remove-if-not
10670 'org-file-apps-entry-match-against-dlink-p file-apps))
10671 (remp (and (assq 'remote apps) (org-file-remote-p file)))
10672 (dirp (if remp nil (file-directory-p file)))
10673 (file (if (and dirp org-open-directory-means-index-dot-org)
10674 (concat (file-name-as-directory file) "index.org")
10676 (a-m-a-p (assq 'auto-mode apps))
10677 (dfile (downcase file))
10678 ;; reconstruct the original file: link from the PATH, LINE and SEARCH args
10679 (link (cond ((and (eq line nil)
10683 (concat file "::" (number-to-string line)))
10685 (concat file "::" search))))
10686 (dlink (downcase link))
10687 (old-buffer (current-buffer))
10689 (old-mode major-mode)
10690 ext cmd link-match-data)
10691 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile)
10692 (setq ext (match-string 1 dfile))
10693 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile)
10694 (setq ext (match-string 1 dfile))))
10696 ((member in-emacs '((16) system))
10697 (setq cmd (cdr (assoc 'system apps))))
10698 (in-emacs (setq cmd 'emacs))
10700 (setq cmd (or (and remp (cdr (assoc 'remote apps)))
10701 (and dirp (cdr (assoc 'directory apps)))
10702 ; first, try matching against apps-dlink
10703 ; if we get a match here, store the match data for later
10704 (let ((match (assoc-default dlink apps-dlink
10707 (progn (setq link-match-data (match-data))
10709 (progn (setq in-emacs (or in-emacs line search))
10710 nil))) ; if we have no match in apps-dlink,
10711 ; always open the file in emacs if line or search
10712 ; is given (for backwards compatibility)
10713 (assoc-default dfile (org-apps-regexp-alist apps a-m-a-p)
10715 (cdr (assoc ext apps))
10716 (cdr (assoc t apps))))))
10717 (when (eq cmd 'system)
10718 (setq cmd (cdr (assoc 'system apps))))
10719 (when (eq cmd 'default)
10720 (setq cmd (cdr (assoc t apps))))
10721 (when (eq cmd 'mailcap)
10723 (mailcap-parse-mailcaps)
10724 (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
10725 (command (mailcap-mime-info mime-type)))
10726 (if (stringp command)
10728 (setq cmd 'emacs))))
10729 (if (and (not (eq cmd 'emacs)) ; Emacs has no problems with non-ex files
10730 (not (file-exists-p file))
10731 (not org-open-non-existing-files))
10732 (error "No such file: %s" file))
10734 ((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
10735 ;; Remove quotes around the file name - we'll use shell-quote-argument.
10736 (while (string-match "['\"]%s['\"]" cmd)
10737 (setq cmd (replace-match "%s" t t cmd)))
10738 (while (string-match "%s" cmd)
10739 (setq cmd (replace-match
10741 (shell-quote-argument
10742 (convert-standard-filename file)))
10745 ;; Replace "%1", "%2" etc. in command with group matches from regex
10747 (let ((match-index 1)
10748 (number-of-groups (- (/ (length link-match-data) 2) 1)))
10749 (set-match-data link-match-data)
10750 (while (<= match-index number-of-groups)
10751 (let ((regex (concat "%" (number-to-string match-index)))
10752 (replace-with (match-string match-index dlink)))
10753 (while (string-match regex cmd)
10754 (setq cmd (replace-match replace-with t t cmd))))
10755 (setq match-index (+ match-index 1)))))
10757 (save-window-excursion
10758 (message "Running %s...done" cmd)
10759 (start-process-shell-command cmd nil cmd)
10760 (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
10763 (funcall (cdr (assq 'file org-link-frame-setup)) file)
10765 (if line (org-goto-line line)
10766 (if search (org-link-search search))))
10768 (let ((file (convert-standard-filename file)))
10770 (set-match-data link-match-data)
10772 (t (funcall (cdr (assq 'file org-link-frame-setup)) file)))
10773 (and (derived-mode-p 'org-mode) (eq old-mode 'org-mode)
10774 (or (not (equal old-buffer (current-buffer)))
10775 (not (equal old-pos (point))))
10776 (org-mark-ring-push old-pos old-buffer))))
10778 (defun org-file-apps-entry-match-against-dlink-p (entry)
10779 "This function returns non-nil if `entry' uses a regular
10780 expression which should be matched against the whole link by
10783 It assumes that is the case when the entry uses a regular
10784 expression which has at least one grouping construct and the
10785 action is either a lisp form or a command string containing
10786 '%1', i.e. using at least one subexpression match as a
10788 (let ((selector (car entry))
10789 (action (cdr entry)))
10790 (if (stringp selector)
10791 (and (> (regexp-opt-depth selector) 0)
10792 (or (and (stringp action)
10793 (string-match "%[0-9]" action))
10797 (defun org-default-apps ()
10798 "Return the default applications for this operating system."
10800 ((eq system-type 'darwin)
10801 org-file-apps-defaults-macosx)
10802 ((eq system-type 'windows-nt)
10803 org-file-apps-defaults-windowsnt)
10804 (t org-file-apps-defaults-gnu)))
10806 (defun org-apps-regexp-alist (list &optional add-auto-mode)
10807 "Convert extensions to regular expressions in the cars of LIST.
10808 Also, weed out any non-string entries, because the return value is used
10809 only for regexp matching.
10810 When ADD-AUTO-MODE is set, make all matches in `auto-mode-alist'
10811 point to the symbol `emacs', indicating that the file should
10812 be opened in Emacs."
10815 (mapcar (lambda (x)
10816 (if (not (stringp (car x)))
10818 (if (string-match "\\W" (car x))
10820 (cons (concat "\\." (car x) "\\'") (cdr x)))))
10823 (mapcar (lambda (x) (cons (car x) 'emacs)) auto-mode-alist))))
10825 (defvar ange-ftp-name-format) ; to silence the XEmacs compiler.
10826 (defun org-file-remote-p (file)
10827 "Test whether FILE specifies a location on a remote system.
10828 Return non-nil if the location is indeed remote.
10830 For example, the filename \"/user@host:/foo\" specifies a location
10831 on the system \"/user@host:\"."
10832 (cond ((fboundp 'file-remote-p)
10833 (file-remote-p file))
10834 ((fboundp 'tramp-handle-file-remote-p)
10835 (tramp-handle-file-remote-p file))
10836 ((and (boundp 'ange-ftp-name-format)
10837 (string-match (car ange-ftp-name-format) file))
10843 (defun org-get-org-file ()
10844 "Read a filename, with default directory `org-directory'."
10845 (let ((default (or org-default-notes-file remember-data-file)))
10846 (read-file-name (format "File name [%s]: " default)
10847 (file-name-as-directory org-directory)
10850 (defun org-notes-order-reversed-p ()
10851 "Check if the current file should receive notes in reversed order."
10853 ((not org-reverse-note-order) nil)
10854 ((eq t org-reverse-note-order) t)
10855 ((not (listp org-reverse-note-order)) nil)
10857 (let ((all org-reverse-note-order)
10859 (while (setq entry (pop all))
10860 (if (string-match (car entry) buffer-file-name)
10861 (throw 'exit (cdr entry))))
10864 (defvar org-refile-target-table nil
10865 "The list of refile targets, created by `org-refile'.")
10867 (defvar org-agenda-new-buffers nil
10868 "Buffers created to visit agenda files.")
10870 (defvar org-refile-cache nil
10871 "Cache for refile targets.")
10873 (defvar org-refile-markers nil
10874 "All the markers used for caching refile locations.")
10876 (defun org-refile-marker (pos)
10877 "Get a new refile marker, but only if caching is in use."
10878 (if (not org-refile-use-cache)
10880 (let ((m (make-marker)))
10881 (move-marker m pos)
10882 (push m org-refile-markers)
10885 (defun org-refile-cache-clear ()
10886 "Clear the refile cache and disable all the markers."
10887 (mapc (lambda (m) (move-marker m nil)) org-refile-markers)
10888 (setq org-refile-markers nil)
10889 (setq org-refile-cache nil)
10890 (message "Refile cache has been cleared"))
10892 (defun org-refile-cache-check-set (set)
10893 "Check if all the markers in the cache still have live buffers."
10896 (while (and set (setq marker (nth 3 (pop set))))
10897 ;; if org-refile-use-outline-path is 'file, marker may be nil
10898 (when (and marker (null (marker-buffer marker)))
10899 (message "not found") (sit-for 3)
10900 (throw 'exit nil)))
10903 (defun org-refile-cache-put (set &rest identifiers)
10904 "Push the refile targets SET into the cache, under IDENTIFIERS."
10905 (let* ((key (sha1 (prin1-to-string identifiers)))
10906 (entry (assoc key org-refile-cache)))
10909 (push (cons key set) org-refile-cache))))
10911 (defun org-refile-cache-get (&rest identifiers)
10912 "Retrieve the cached value for refile targets given by IDENTIFIERS."
10914 ((not org-refile-cache) nil)
10915 ((not org-refile-use-cache) (org-refile-cache-clear) nil)
10917 (let ((set (cdr (assoc (sha1 (prin1-to-string identifiers))
10918 org-refile-cache))))
10919 (and set (org-refile-cache-check-set set) set)))))
10921 (defun org-refile-get-targets (&optional default-buffer excluded-entries)
10922 "Produce a table with refile targets."
10923 (let ((case-fold-search nil)
10924 ;; otherwise org confuses "TODO" as a kw and "Todo" as a word
10925 (entries (or org-refile-targets '((nil . (:level . 1)))))
10926 targets tgs txt re files f desc descre fast-path-p level pos0)
10927 (message "Getting targets...")
10928 (with-current-buffer (or default-buffer (current-buffer))
10929 (while (setq entry (pop entries))
10930 (setq files (car entry) desc (cdr entry))
10931 (setq fast-path-p nil)
10933 ((null files) (setq files (list (current-buffer))))
10934 ((eq files 'org-agenda-files)
10935 (setq files (org-agenda-files 'unrestricted)))
10936 ((and (symbolp files) (fboundp files))
10937 (setq files (funcall files)))
10938 ((and (symbolp files) (boundp files))
10939 (setq files (symbol-value files))))
10940 (if (stringp files) (setq files (list files)))
10942 ((eq (car desc) :tag)
10943 (setq descre (concat "^\\*+[ \t]+.*?:" (regexp-quote (cdr desc)) ":")))
10944 ((eq (car desc) :todo)
10945 (setq descre (concat "^\\*+[ \t]+" (regexp-quote (cdr desc)) "[ \t]")))
10946 ((eq (car desc) :regexp)
10947 (setq descre (cdr desc)))
10948 ((eq (car desc) :level)
10949 (setq descre (concat "^\\*\\{" (number-to-string
10950 (if org-odd-levels-only
10951 (1- (* 2 (cdr desc)))
10954 ((eq (car desc) :maxlevel)
10955 (setq fast-path-p t)
10956 (setq descre (concat "^\\*\\{1," (number-to-string
10957 (if org-odd-levels-only
10958 (1- (* 2 (cdr desc)))
10961 (t (error "Bad refiling target description %s" desc)))
10962 (while (setq f (pop files))
10963 (with-current-buffer
10964 (if (bufferp f) f (org-get-agenda-file-buffer f))
10966 (setq tgs (org-refile-cache-get (buffer-file-name) descre))
10968 (if (bufferp f) (setq f (buffer-file-name
10969 (buffer-base-buffer f))))
10970 (setq f (and f (expand-file-name f)))
10971 (if (eq org-refile-use-outline-path 'file)
10972 (push (list (file-name-nondirectory f) f nil nil) tgs))
10976 (goto-char (point-min))
10977 (while (re-search-forward descre nil t)
10978 (goto-char (setq pos0 (point-at-bol)))
10980 (when org-refile-target-verify-function
10982 (or (funcall org-refile-target-verify-function)
10984 (when (and (looking-at org-complex-heading-regexp)
10985 (not (member (match-string 4) excluded-entries))
10987 (setq level (org-reduced-level
10988 (- (match-end 1) (match-beginning 1)))
10989 txt (org-link-display-format (match-string 4))
10990 txt (replace-regexp-in-string "\\( *\[[0-9]+/?[0-9]*%?\]\\)+$" "" txt)
10991 re (format org-complex-heading-regexp-format
10992 (regexp-quote (match-string 4))))
10993 (when org-refile-use-outline-path
10994 (setq txt (mapconcat
10997 (if (eq org-refile-use-outline-path
10999 (list (file-name-nondirectory
11001 (buffer-base-buffer))))
11002 (if (eq org-refile-use-outline-path
11004 (list (buffer-file-name
11005 (buffer-base-buffer)))))
11006 (org-get-outline-path fast-path-p
11010 (push (list txt f re (org-refile-marker (point)))
11012 (when (= (point) pos0)
11013 ;; verification function has not moved point
11014 (goto-char (point-at-eol))))))))
11015 (when org-refile-use-cache
11016 (org-refile-cache-put tgs (buffer-file-name) descre))
11017 (setq targets (append tgs targets))
11019 (message "Getting targets...done")
11020 (nreverse targets)))
11022 (defun org-protect-slash (s)
11023 (while (string-match "/" s)
11024 (setq s (replace-match "\\" t t s)))
11027 (defvar org-olpa (make-vector 20 nil))
11029 (defun org-get-outline-path (&optional fastp level heading)
11030 "Return the outline path to the current entry, as a list.
11032 The parameters FASTP, LEVEL, and HEADING are for use by a scanner
11033 routine which makes outline path derivations for an entire file,
11034 avoiding backtracing. Refile target collection makes use of that."
11038 (error "Outline path failure, more than 19 levels"))
11039 (loop for i from level upto 19 do
11040 (aset org-olpa i nil))
11042 (delq nil (append org-olpa nil))
11043 (aset org-olpa level heading)))
11044 (let (rtn case-fold-search)
11048 (while (org-up-heading-safe)
11049 (when (looking-at org-complex-heading-regexp)
11050 (push (org-match-string-no-properties 4) rtn)))
11053 (defun org-format-outline-path (path &optional width prefix separator)
11054 "Format the outline path PATH for display.
11055 WIDTH is the maximum number of characters that is available.
11056 PREFIX is a prefix to be included in the returned string,
11057 such as the file name.
11058 SEPARATOR is inserted between the different parts of the path,
11059 the default is \"/\"."
11060 (setq width (or width 79))
11061 (if prefix (setq width (- width (length prefix))))
11064 (let* ((nsteps (length path))
11065 (total-width (+ nsteps (apply '+ (mapcar 'length path))))
11066 (maxwidth (if (<= total-width width)
11067 10000 ;; everything fits
11068 ;; we need to shorten the level headings
11069 (/ (- width nsteps) nsteps)))
11070 (org-odd-levels-only nil)
11072 (total (1+ (length prefix))))
11073 (setq maxwidth (max maxwidth 10))
11075 (if prefix (or separator "/"))
11079 (if (and (= n nsteps) (< maxwidth 10000))
11080 (setq maxwidth (- total-width total)))
11081 (if (< (length h) maxwidth)
11082 (progn (setq total (+ total (length h) 1)) h)
11083 (setq h (substring h 0 (- maxwidth 2))
11084 total (+ total maxwidth 1))
11085 (if (string-match "[ \t]+\\'" h)
11086 (setq h (substring h 0 (match-beginning 0))))
11087 (setq h (concat h "..")))
11088 (org-add-props h nil 'face
11089 (nth (% (1- n) org-n-level-faces)
11092 path (or separator "/"))))))
11094 (defun org-display-outline-path (&optional file current separator just-return-string)
11095 "Display the current outline path in the echo area.
11097 If FILE is non-nil, prepend the output with the file name.
11098 If CURRENT is non-nil, append the current heading to the output.
11099 SEPARATOR is passed through to `org-format-outline-path'. It separates
11100 the different parts of the path and defaults to \"/\".
11101 If JUST-RETURN-STRING is non-nil, return a string, don't display a message."
11103 (let* (case-fold-search
11104 message-log-max ; Don't populate the *Messages* buffer
11105 (bfn (buffer-file-name (buffer-base-buffer)))
11106 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
11108 (if current (setq path (append path
11110 (org-back-to-heading t)
11111 (if (looking-at org-complex-heading-regexp)
11112 (list (match-string 4)))))))
11114 (org-format-outline-path
11117 (and file bfn (concat (file-name-nondirectory bfn) separator))
11119 (if just-return-string
11120 (org-no-properties res)
11121 (message "%s" res))))
11123 (defvar org-refile-history nil
11124 "History for refiling operations.")
11126 (defvar org-after-refile-insert-hook nil
11127 "Hook run after `org-refile' has inserted its stuff at the new location.
11128 Note that this is still *before* the stuff will be removed from
11129 the *old* location.")
11131 (defvar org-capture-last-stored-marker)
11132 (defvar org-refile-keep nil
11133 "Non-nil means `org-refile' will copy instead of refile.")
11136 "Like `org-refile', but copy."
11138 (let ((org-refile-keep t))
11139 (funcall 'org-refile nil nil nil "Copy")))
11141 (defun org-refile (&optional goto default-buffer rfloc msg)
11142 "Move the entry or entries at point to another heading.
11143 The list of target headings is compiled using the information in
11144 `org-refile-targets', which see.
11146 At the target location, the entry is filed as a subitem of the target
11147 heading. Depending on `org-reverse-note-order', the new subitem will
11148 either be the first or the last subitem.
11150 If there is an active region, all entries in that region will be moved.
11151 However, the region must fulfill the requirement that the first heading
11152 is the first one sets the top-level of the moved text - at most siblings
11153 below it are allowed.
11155 With prefix arg GOTO, the command will only visit the target location
11156 and not actually move anything.
11158 With a double prefix arg \\[universal-argument] \\[universal-argument], \
11159 go to the location where the last refiling operation has put the subtree.
11160 With a prefix argument of `2', refile to the running clock.
11162 RFLOC can be a refile location obtained in a different way.
11164 MSG is a string to replace \"Refile\" in the default prompt with
11165 another verb. E.g. `org-copy' sets this parameter to \"Copy\".
11167 See also `org-refile-use-outline-path' and `org-completion-use-ido'.
11169 If you are using target caching (see `org-refile-use-cache'),
11170 you have to clear the target cache in order to find new targets.
11171 This can be done with a 0 prefix (`C-0 C-c C-w') or a triple
11172 prefix argument (`C-u C-u C-u C-c C-w')."
11175 (if (member goto '(0 (64)))
11176 (org-refile-cache-clear)
11177 (let* ((actionmsg (or msg "Refile"))
11178 (cbuf (current-buffer))
11179 (regionp (org-region-active-p))
11180 (region-start (and regionp (region-beginning)))
11181 (region-end (and regionp (region-end)))
11182 (region-length (and regionp (- region-end region-start)))
11183 (filename (buffer-file-name (buffer-base-buffer cbuf)))
11184 pos it nbuf file re level reversed)
11185 (setq last-command nil)
11187 (goto-char region-start)
11188 (or (bolp) (goto-char (point-at-bol)))
11189 (setq region-start (point))
11190 (unless (or (org-kill-is-subtree-p
11191 (buffer-substring region-start region-end))
11192 (prog1 org-refile-active-region-within-subtree
11193 (org-toggle-heading)))
11194 (error "The region is not a (sequence of) subtree(s)")))
11195 (if (equal goto '(16))
11196 (org-refile-goto-last-stored)
11198 (and (equal goto 2)
11199 org-clock-hd-marker (marker-buffer org-clock-hd-marker)
11201 (setq it (list (or org-clock-heading "running clock")
11203 (marker-buffer org-clock-hd-marker))
11205 (marker-position org-clock-hd-marker)))
11208 (let (heading-text)
11211 (org-back-to-heading t)
11213 (nth 4 (org-heading-components))))
11215 (org-refile-get-location
11216 (cond (goto "Goto")
11217 (regionp (concat actionmsg " region to"))
11218 (t (concat actionmsg " subtree \""
11219 heading-text "\" to")))
11221 (and (not (equal '(4) goto))
11222 org-refile-allow-creating-parent-nodes)
11224 (setq file (nth 1 it)
11227 (if (and (not goto)
11229 (equal (buffer-file-name) file)
11231 (and (>= pos region-start)
11232 (<= pos region-end))
11233 (and (>= pos (point))
11234 (< pos (save-excursion
11235 (org-end-of-subtree t t))))))
11236 (error "Cannot refile to position inside the tree or region"))
11238 (setq nbuf (or (find-buffer-visiting file)
11239 (find-file-noselect file)))
11242 (org-pop-to-buffer-same-window nbuf)
11244 (org-show-context 'org-goto))
11247 (org-kill-new (buffer-substring region-start region-end))
11248 (org-save-markers-in-region region-start region-end))
11249 (org-copy-subtree 1 nil t))
11250 (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
11251 (find-file-noselect file)))
11252 (setq reversed (org-notes-order-reversed-p))
11259 (looking-at org-outline-regexp)
11260 (setq level (org-get-valid-level (funcall outline-level) 1))
11263 (or (outline-next-heading) (point-max))
11264 (or (save-excursion (org-get-next-sibling))
11265 (org-end-of-subtree t t)
11269 (goto-char (point-max))
11270 (goto-char (point-min))
11271 (or (outline-next-heading) (goto-char (point-max)))))
11272 (if (not (bolp)) (newline))
11273 (org-paste-subtree level)
11274 (when org-log-refile
11275 (org-add-log-setup 'refile nil nil 'findpos
11277 (unless (eq org-log-refile 'note)
11278 (save-excursion (org-add-log-note))))
11279 (and org-auto-align-tags
11280 (let ((org-loop-over-headlines-in-active-region nil))
11281 (org-set-tags nil t)))
11282 (with-demoted-errors
11283 (bookmark-set "org-refile-last-stored"))
11284 ;; If we are refiling for capture, make sure that the
11285 ;; last-capture pointers point here
11286 (when (org-bound-and-true-p org-refile-for-capture)
11287 (with-demoted-errors
11288 (bookmark-set "org-capture-last-stored-marker"))
11289 (move-marker org-capture-last-stored-marker (point)))
11290 (if (fboundp 'deactivate-mark) (deactivate-mark))
11291 (run-hooks 'org-after-refile-insert-hook))))
11292 (unless org-refile-keep
11294 (delete-region (point) (+ (point) region-length))
11295 (org-cut-subtree)))
11296 (when (featurep 'org-inlinetask)
11297 (org-inlinetask-remove-END-maybe))
11298 (setq org-markers-to-move nil)
11299 (message (concat actionmsg " to \"%s\" in file %s: done") (car it) file)))))))
11301 (defun org-refile-goto-last-stored ()
11302 "Go to the location where the last refile was stored."
11304 (bookmark-jump "org-refile-last-stored")
11305 (message "This is the location of the last refile"))
11307 (defun org-refile-get-location (&optional prompt default-buffer new-nodes
11309 "Prompt the user for a refile location, using PROMPT.
11310 PROMPT should not be suffixed with a colon and a space, because
11311 this function appends the default value from
11312 `org-refile-history' automatically, if that is not empty.
11313 When NO-EXCLUDE is set, do not exclude headlines in the current subtree,
11314 this is used for the GOTO interface."
11315 (let ((org-refile-targets org-refile-targets)
11316 (org-refile-use-outline-path org-refile-use-outline-path)
11318 (when (and (derived-mode-p 'org-mode)
11319 (not org-refile-use-cache)
11323 (setq excluded-entries
11324 (append excluded-entries (list (org-get-heading t t)))))))
11325 (setq org-refile-target-table
11326 (org-refile-get-targets default-buffer excluded-entries)))
11327 (unless org-refile-target-table
11328 (error "No refile targets"))
11329 (let* ((cbuf (current-buffer))
11330 (partial-completion-mode nil)
11331 (cfn (buffer-file-name (buffer-base-buffer cbuf)))
11332 (cfunc (if (and org-refile-use-outline-path
11333 org-outline-path-complete-in-steps)
11334 'org-olpath-completing-read
11335 'org-icompleting-read))
11336 (extra (if org-refile-use-outline-path "/" ""))
11337 (cbnex (concat (buffer-name) extra))
11338 (filename (and cfn (expand-file-name cfn)))
11341 (if (and (not (member org-refile-use-outline-path
11342 '(file full-file-path)))
11343 (not (equal filename (nth 1 x))))
11344 (cons (concat (car x) extra " ("
11345 (file-name-nondirectory (nth 1 x)) ")")
11347 (cons (concat (car x) extra) (cdr x))))
11348 org-refile-target-table))
11349 (completion-ignore-case t)
11351 (prompt (concat prompt
11352 (or (and (car org-refile-history)
11353 (concat " (default " (car org-refile-history) ")"))
11354 (and (assoc cbnex tbl) (setq cdef cbnex)
11355 (concat " (default " cbnex ")"))) ": "))
11356 pa answ parent-target child parent old-hist)
11357 (setq old-hist org-refile-history)
11358 (setq answ (funcall cfunc prompt tbl nil (not new-nodes)
11359 nil 'org-refile-history (or cdef (car org-refile-history))))
11360 (setq pa (or (assoc answ tbl) (assoc (concat answ "/") tbl)))
11361 (org-refile-check-position pa)
11364 (when (or (not org-refile-history)
11365 (not (eq old-hist org-refile-history))
11366 (not (equal (car pa) (car org-refile-history))))
11367 (setq org-refile-history
11368 (cons (car pa) (if (assoc (car org-refile-history) tbl)
11370 (cdr org-refile-history))))
11371 (if (equal (car org-refile-history) (nth 1 org-refile-history))
11372 (pop org-refile-history)))
11374 (if (string-match "\\`\\(.*\\)/\\([^/]+\\)\\'" answ)
11376 (setq parent (match-string 1 answ)
11377 child (match-string 2 answ))
11378 (setq parent-target (or (assoc parent tbl)
11379 (assoc (concat parent "/") tbl)))
11380 (when (and parent-target
11381 (or (eq new-nodes t)
11382 (and (eq new-nodes 'confirm)
11383 (y-or-n-p (format "Create new node \"%s\"? "
11385 (org-refile-new-child parent-target child)))
11386 (error "Invalid target location")))))
11388 (declare-function org-string-nw-p "org-macs" (s))
11389 (defun org-refile-check-position (refile-pointer)
11390 "Check if the refile pointer matches the headline to which it points."
11391 (let* ((file (nth 1 refile-pointer))
11392 (re (nth 2 refile-pointer))
11393 (pos (nth 3 refile-pointer))
11395 (if (and (not (markerp pos)) (not file))
11396 (error "Please save the buffer to a file before refiling")
11397 (when (org-string-nw-p re)
11398 (setq buffer (if (markerp pos)
11399 (marker-buffer pos)
11400 (or (find-buffer-visiting file)
11401 (find-file-noselect file))))
11402 (with-current-buffer buffer
11407 (beginning-of-line 1)
11408 (unless (org-looking-at-p re)
11409 (error "Invalid refile position, please clear the cache with `C-0 C-c C-w' before refiling")))))))))
11411 (defun org-refile-new-child (parent-target child)
11412 "Use refile target PARENT-TARGET to add new CHILD below it."
11413 (unless parent-target
11414 (error "Cannot find parent for new node"))
11415 (let ((file (nth 1 parent-target))
11416 (pos (nth 3 parent-target))
11418 (with-current-buffer (or (find-buffer-visiting file)
11419 (find-file-noselect file))
11425 (goto-char (point-max))
11426 (if (not (bolp)) (newline)))
11427 (when (looking-at org-outline-regexp)
11428 (setq level (funcall outline-level))
11429 (org-end-of-subtree t t))
11430 (org-back-over-empty-lines)
11431 (insert "\n" (make-string
11432 (if pos (org-get-valid-level level 1) 1) ?*)
11434 (beginning-of-line 0)
11435 (list (concat (car parent-target) "/" child) file "" (point)))))))
11437 (defun org-olpath-completing-read (prompt collection &rest args)
11438 "Read an outline path like a file name."
11439 (let ((thetable collection)
11440 (org-completion-use-ido nil) ; does not work with ido.
11441 (org-completion-use-iswitchb nil)) ; or iswitchb
11443 'org-icompleting-read prompt
11444 (lambda (string predicate &optional flag)
11445 (let (rtn r f (l (length string)))
11449 (try-completion string thetable))
11452 (setq rtn (all-completions string thetable predicate))
11455 (setq r (substring x l))
11456 (if (string-match " ([^)]*)$" x)
11457 (setq f (match-string 0 x))
11459 (if (string-match "/" r)
11460 (concat string (substring r 0 (match-end 0)) f)
11465 (assoc string thetable)))))
11468 ;;;; Dynamic blocks
11470 (defun org-find-dblock (name)
11471 "Find the first dynamic block with name NAME in the buffer.
11472 If not found, stay at current position and return nil."
11473 (let ((case-fold-search t) pos)
11475 (goto-char (point-min))
11476 (setq pos (and (re-search-forward
11477 (concat "^[ \t]*#\\+\\(?:BEGIN\\|begin\\):[ \t]+" name "\\>") nil t)
11478 (match-beginning 0))))
11479 (if pos (goto-char pos))
11482 (defconst org-dblock-start-re
11483 "^[ \t]*#\\+\\(?:BEGIN\\|begin\\):[ \t]+\\(\\S-+\\)\\([ \t]+\\(.*\\)\\)?"
11484 "Matches the start line of a dynamic block, with parameters.")
11486 (defconst org-dblock-end-re "^[ \t]*#\\+\\(?:END\\|end\\)\\([: \t\r\n]\\|$\\)"
11487 "Matches the end of a dynamic block.")
11489 (defun org-create-dblock (plist)
11490 "Create a dynamic block section, with parameters taken from PLIST.
11491 PLIST must contain a :name entry which is used as name of the block."
11492 (when (string-match "\\S-" (buffer-substring (point-at-bol) (point-at-eol)))
11495 (let ((col (current-column))
11496 (name (plist-get plist :name)))
11497 (insert "#+BEGIN: " name)
11499 (if (eq (car plist) :name)
11500 (setq plist (cddr plist))
11501 (insert " " (prin1-to-string (pop plist)))))
11502 (insert "\n\n" (make-string col ?\ ) "#+END:\n")
11503 (beginning-of-line -2)))
11505 (defun org-prepare-dblock ()
11506 "Prepare dynamic block for refresh.
11507 This empties the block, puts the cursor at the insert position and returns
11508 the property list including an extra property :name with the block name."
11509 (unless (looking-at org-dblock-start-re)
11510 (error "Not at a dynamic block"))
11511 (let* ((begdel (1+ (match-end 0)))
11512 (name (org-no-properties (match-string 1)))
11513 (params (append (list :name name)
11514 (read (concat "(" (match-string 3) ")")))))
11516 (beginning-of-line 1)
11517 (skip-chars-forward " \t")
11518 (setq params (plist-put params :indentation-column (current-column))))
11519 (unless (re-search-forward org-dblock-end-re nil t)
11520 (error "Dynamic block not terminated"))
11523 (list :content (buffer-substring
11524 begdel (match-beginning 0)))))
11525 (delete-region begdel (match-beginning 0))
11530 (defun org-map-dblocks (&optional command)
11531 "Apply COMMAND to all dynamic blocks in the current buffer.
11532 If COMMAND is not given, use `org-update-dblock'."
11533 (let ((cmd (or command 'org-update-dblock)))
11535 (goto-char (point-min))
11536 (while (re-search-forward org-dblock-start-re nil t)
11537 (goto-char (match-beginning 0))
11539 (condition-case nil
11541 (error (message "Error during update of dynamic block"))))
11542 (unless (re-search-forward org-dblock-end-re nil t)
11543 (error "Dynamic block not terminated"))))))
11545 (defun org-dblock-update (&optional arg)
11546 "User command for updating dynamic blocks.
11547 Update the dynamic block at point. With prefix ARG, update all dynamic
11548 blocks in the buffer."
11551 (org-update-all-dblocks)
11552 (or (looking-at org-dblock-start-re)
11553 (org-beginning-of-dblock))
11554 (org-update-dblock)))
11556 (defun org-update-dblock ()
11557 "Update the dynamic block at point.
11558 This means to empty the block, parse for parameters and then call
11559 the correct writing function."
11561 (save-window-excursion
11562 (let* ((pos (point))
11563 (line (org-current-line))
11564 (params (org-prepare-dblock))
11565 (name (plist-get params :name))
11566 (indent (plist-get params :indentation-column))
11567 (cmd (intern (concat "org-dblock-write:" name))))
11568 (message "Updating dynamic block `%s' at line %d..." name line)
11569 (funcall cmd params)
11570 (message "Updating dynamic block `%s' at line %d...done" name line)
11572 (when (and indent (> indent 0))
11573 (setq indent (make-string indent ?\ ))
11575 (org-beginning-of-dblock)
11577 (while (not (looking-at org-dblock-end-re))
11579 (beginning-of-line 2))
11580 (when (looking-at org-dblock-end-re)
11581 (and (looking-at "[ \t]+")
11582 (replace-match ""))
11583 (insert indent)))))))
11585 (defun org-beginning-of-dblock ()
11586 "Find the beginning of the dynamic block at point.
11587 Error if there is no such block at point."
11588 (let ((pos (point))
11591 (if (and (re-search-backward org-dblock-start-re nil t)
11592 (setq beg (match-beginning 0))
11593 (re-search-forward org-dblock-end-re nil t)
11594 (> (match-end 0) pos))
11597 (error "Not in a dynamic block"))))
11599 (defun org-update-all-dblocks ()
11600 "Update all dynamic blocks in the buffer.
11601 This function can be used in a hook."
11603 (when (derived-mode-p 'org-mode)
11604 (org-map-dblocks 'org-update-dblock)))
11609 (defun org-get-export-keywords ()
11610 "Return a list of all currently understood export keywords.
11611 Export keywords include options, block names, attributes and
11612 keywords relative to each registered export back-end."
11617 (let ((props (cdr back-end)))
11618 ;; Back-end name (for keywords, like #+LATEX:)
11619 (push (upcase (symbol-name (car back-end))) keywords)
11620 ;; Back-end options.
11621 (mapc (lambda (option) (push (cadr option) keywords))
11622 (plist-get (cdr back-end) :options-alist))))
11623 (org-bound-and-true-p org-export-registered-backends))
11626 (defconst org-options-keywords
11627 '("ARCHIVE:" "AUTHOR:" "BIND:" "CATEGORY:" "COLUMNS:" "CREATOR:" "DATE:"
11628 "DESCRIPTION:" "DRAWERS:" "EMAIL:" "EXCLUDE_TAGS:" "FILETAGS:" "INCLUDE:"
11629 "INDEX:" "KEYWORDS:" "LANGUAGE:" "MACRO:" "OPTIONS:" "PROPERTY:"
11630 "PRIORITIES:" "SELECT_TAGS:" "SEQ_TODO:" "SETUPFILE:" "STARTUP:" "TAGS:"
11631 "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:" "INFOJS_OPT:"))
11633 (defcustom org-structure-template-alist
11634 '(("s" "#+BEGIN_SRC ?\n\n#+END_SRC"
11635 "<src lang=\"?\">\n\n</src>")
11636 ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE"
11637 "<example>\n?\n</example>")
11638 ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE"
11639 "<quote>\n?\n</quote>")
11640 ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE"
11641 "<verse>\n?\n</verse>")
11642 ("V" "#+BEGIN_VERBATIM\n?\n#+END_VERBATIM"
11643 "<verbatim>\n?\n</verbatim>")
11644 ("c" "#+BEGIN_CENTER\n?\n#+END_CENTER"
11645 "<center>\n?\n</center>")
11646 ("l" "#+BEGIN_LaTeX\n?\n#+END_LaTeX"
11647 "<literal style=\"latex\">\n?\n</literal>")
11649 "<literal style=\"latex\">?</literal>")
11650 ("h" "#+BEGIN_HTML\n?\n#+END_HTML"
11651 "<literal style=\"html\">\n?\n</literal>")
11653 "<literal style=\"html\">?</literal>")
11654 ("a" "#+BEGIN_ASCII\n?\n#+END_ASCII")
11658 ("I" "#+INCLUDE: %file ?"
11659 "<include file=%file markup=\"?\">"))
11660 "Structure completion elements.
11661 This is a list of abbreviation keys and values. The value gets inserted
11662 if you type `<' followed by the key and then press the completion key,
11663 usually `M-TAB'. %file will be replaced by a file name after prompting
11664 for the file using completion. The cursor will be placed at the position
11665 of the `?` in the template.
11666 There are two templates for each key, the first uses the original Org syntax,
11667 the second uses Emacs Muse-like syntax tags. These Muse-like tags become
11668 the default when the /org-mtags.el/ module has been loaded. See also the
11669 variable `org-mtags-prefer-muse-templates'."
11670 :group 'org-completion
11672 (string :tag "Key")
11673 (string :tag "Template")
11674 (string :tag "Muse Template")))
11676 (defun org-try-structure-completion ()
11677 "Try to complete a structure template before point.
11678 This looks for strings like \"<e\" on an otherwise empty line and
11680 (let ((l (buffer-substring (point-at-bol) (point)))
11682 (when (and (looking-at "[ \t]*$")
11683 (string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l)
11684 (setq a (assoc (match-string 1 l) org-structure-template-alist)))
11685 (org-complete-expand-structure-template (+ -1 (point-at-bol)
11686 (match-beginning 1)) a)
11689 (defun org-complete-expand-structure-template (start cell)
11690 "Expand a structure template."
11691 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
11692 (rpl (nth (if musep 2 1) cell))
11694 (delete-region start (point))
11695 (when (string-match "\\`#\\+" rpl)
11698 ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
11699 (setq ind (buffer-substring (point-at-bol) (point))))
11701 (setq start (point))
11702 (if (string-match "%file" rpl)
11703 (setq rpl (replace-match
11707 (abbreviate-file-name (read-file-name "Include file: ")))
11710 (setq rpl (mapconcat 'identity (split-string rpl "\n")
11711 (concat "\n" ind)))
11713 (if (re-search-backward "\\?" start t) (delete-char 1))))
11715 ;;;; TODO, DEADLINE, Comments
11717 (defun org-toggle-comment ()
11718 "Change the COMMENT state of an entry."
11721 (org-back-to-heading)
11722 (let (case-fold-search)
11724 ((looking-at (format org-heading-keyword-regexp-format
11725 org-comment-string))
11726 (goto-char (match-end 1))
11727 (looking-at (concat " +" org-comment-string))
11728 (replace-match "" t t)
11729 (when (eolp) (insert " ")))
11730 ((looking-at org-outline-regexp)
11731 (goto-char (match-end 0))
11732 (insert org-comment-string " "))))))
11734 (defvar org-last-todo-state-is-todo nil
11735 "This is non-nil when the last TODO state change led to a TODO state.
11736 If the last change removed the TODO tag or switched to DONE, then
11739 (defvar org-setting-tags nil) ; dynamically skipped
11741 (defvar org-todo-setup-filter-hook nil
11742 "Hook for functions that pre-filter todo specs.
11743 Each function takes a todo spec and returns either nil or the spec
11744 transformed into canonical form." )
11746 (defvar org-todo-get-default-hook nil
11747 "Hook for functions that get a default item for todo.
11748 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
11749 nil or a string to be used for the todo mark." )
11751 (defvar org-agenda-headline-snapshot-before-repeat)
11753 (defun org-current-effective-time ()
11754 "Return current time adjusted for `org-extend-today-until' variable."
11755 (let* ((ct (org-current-time))
11756 (dct (decode-time ct))
11759 (org-use-last-clock-out-time-as-effective-time
11760 (or (org-clock-get-last-clock-out-time) ct))
11761 ((and org-use-effective-time (< (nth 2 dct) org-extend-today-until))
11762 (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct)))
11766 (defun org-todo-yesterday (&optional arg)
11767 "Like `org-todo' but the time of change will be 23:59 of yesterday."
11769 (if (eq major-mode 'org-agenda-mode)
11770 (apply 'org-agenda-todo-yesterday arg)
11771 (let* ((hour (third (decode-time
11772 (org-current-time))))
11773 (org-extend-today-until (1+ hour)))
11776 (defvar org-block-entry-blocking ""
11777 "First entry preventing the TODO state change.")
11779 (defun org-todo (&optional arg)
11780 "Change the TODO state of an item.
11781 The state of an item is given by a keyword at the start of the heading,
11783 *** TODO Write paper
11786 The different keywords are specified in the variable `org-todo-keywords'.
11787 By default the available states are \"TODO\" and \"DONE\".
11788 So for this example: when the item starts with TODO, it is changed to DONE.
11789 When it starts with DONE, the DONE is removed. And when neither TODO nor
11790 DONE are present, add TODO at the beginning of the heading.
11792 With \\[universal-argument] prefix arg, use completion to determine the new \
11794 With numeric prefix arg, switch to that state.
11795 With a double \\[universal-argument] prefix, switch to the next set of TODO \
11796 keywords (nextset).
11797 With a triple \\[universal-argument] prefix, circumvent any state blocking.
11798 With a numeric prefix arg of 0, inhibit note taking for the change.
11800 For calling through lisp, arg is also interpreted in the following way:
11801 'none -> empty state
11802 \"\"(empty string) -> switch to empty state
11803 'done -> switch to DONE
11804 'nextset -> switch to the next set of keywords
11805 'previousset -> switch to the previous set of keywords
11806 \"WAITING\" -> switch to the specified keyword, but only if it
11807 really is a member of `org-todo-keywords'."
11809 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
11810 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
11811 'region-start-level 'region))
11812 org-loop-over-headlines-in-active-region)
11815 org-loop-over-headlines-in-active-region
11816 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
11817 (if (equal arg '(16)) (setq arg 'nextset))
11818 (let ((org-blocker-hook org-blocker-hook)
11821 (when (equal arg '(64))
11822 (setq arg nil org-blocker-hook nil))
11823 (when (and org-blocker-hook
11824 (or org-inhibit-blocking
11825 (org-entry-get nil "NOBLOCKING")))
11826 (setq org-blocker-hook nil))
11829 (org-back-to-heading t)
11830 (when (looking-at (concat "^\\*+ " org-comment-string))
11831 (org-toggle-comment)
11833 (if (looking-at org-outline-regexp) (goto-char (1- (match-end 0))))
11834 (or (looking-at (concat " +" org-todo-regexp "\\( +\\|[ \t]*$\\)"))
11835 (looking-at "\\(?: *\\|[ \t]*$\\)"))
11836 (let* ((match-data (match-data))
11837 (startpos (point-at-bol))
11838 (logging (save-match-data (org-entry-get nil "LOGGING" t t)))
11839 (org-log-done org-log-done)
11840 (org-log-repeat org-log-repeat)
11841 (org-todo-log-states org-todo-log-states)
11842 (org-inhibit-logging
11844 (progn (setq arg nil) 'note) org-inhibit-logging))
11845 (this (match-string 1))
11846 (hl-pos (match-beginning 0))
11847 (head (org-get-todo-sequence-head this))
11848 (ass (assoc head org-todo-kwd-alist))
11849 (interpret (nth 1 ass))
11850 (done-word (nth 3 ass))
11851 (final-done-word (nth 4 ass))
11852 (org-last-state (or this ""))
11853 (completion-ignore-case t)
11854 (member (member this org-todo-keywords-1))
11855 (tail (cdr member))
11857 ((and org-todo-key-trigger
11858 (or (and (equal arg '(4))
11859 (eq org-use-fast-todo-selection 'prefix))
11860 (and (not arg) org-use-fast-todo-selection
11861 (not (eq org-use-fast-todo-selection
11863 ;; Use fast selection
11864 (org-fast-todo-selection))
11865 ((and (equal arg '(4))
11866 (or (not org-use-fast-todo-selection)
11867 (not org-todo-key-trigger)))
11868 ;; Read a state with completion
11869 (org-icompleting-read
11870 "State: " (mapcar (lambda(x) (list x))
11871 org-todo-keywords-1)
11875 (if tail (car tail) nil)
11876 (car org-todo-keywords-1)))
11878 (if (equal member org-todo-keywords-1)
11881 (nth (- (length org-todo-keywords-1)
11883 org-todo-keywords-1)
11884 (org-last org-todo-keywords-1))))
11885 ((and (eq org-use-fast-todo-selection t) (equal arg '(4))
11886 (setq arg nil))) ; hack to fall back to cycling
11888 ;; user or caller requests a specific state
11890 ((equal arg "") nil)
11891 ((eq arg 'none) nil)
11892 ((eq arg 'done) (or done-word (car org-done-keywords)))
11894 (or (car (cdr (member head org-todo-heads)))
11895 (car org-todo-heads)))
11896 ((eq arg 'previousset)
11897 (let ((org-todo-heads (reverse org-todo-heads)))
11898 (or (car (cdr (member head org-todo-heads)))
11899 (car org-todo-heads))))
11900 ((car (member arg org-todo-keywords-1)))
11902 (error "State `%s' not valid in this file" arg))
11903 ((nth (1- (prefix-numeric-value arg))
11904 org-todo-keywords-1))))
11905 ((null member) (or head (car org-todo-keywords-1)))
11906 ((equal this final-done-word) nil) ;; -> make empty
11907 ((null tail) nil) ;; -> first entry
11908 ((memq interpret '(type priority))
11909 (if (eq this-command last-command)
11911 (if (> (length tail) 0)
11912 (or done-word (car org-done-keywords))
11917 (run-hook-with-args-until-success
11918 'org-todo-get-default-hook org-state org-last-state)
11920 (next (if org-state (concat " " org-state " ") " "))
11921 (change-plist (list :type 'todo-state-change :from this :to org-state
11922 :position startpos))
11924 (when org-blocker-hook
11925 (setq org-last-todo-state-is-todo
11926 (not (member this org-done-keywords)))
11927 (unless (save-excursion
11929 (org-with-wide-buffer
11930 (run-hook-with-args-until-failure
11931 'org-blocker-hook change-plist))))
11932 (if (org-called-interactively-p 'interactive)
11933 (user-error "TODO state change from %s to %s blocked (by \"%s\")"
11934 this org-state org-block-entry-blocking)
11936 (message "TODO state change from %s to %s blocked (by \"%s\")"
11937 this org-state org-block-entry-blocking)
11938 (throw 'exit nil))))
11939 (store-match-data match-data)
11940 (replace-match next t t)
11941 (unless (pos-visible-in-window-p hl-pos)
11942 (message "TODO state changed to %s" (org-trim next)))
11944 (setq head (org-get-todo-sequence-head org-state)
11945 ass (assoc head org-todo-kwd-alist)
11946 interpret (nth 1 ass)
11947 done-word (nth 3 ass)
11948 final-done-word (nth 4 ass)))
11949 (when (memq arg '(nextset previousset))
11950 (message "Keyword-Set %d/%d: %s"
11951 (- (length org-todo-sets) -1
11952 (length (memq (assoc org-state org-todo-sets) org-todo-sets)))
11953 (length org-todo-sets)
11954 (mapconcat 'identity (assoc org-state org-todo-sets) " ")))
11955 (setq org-last-todo-state-is-todo
11956 (not (member org-state org-done-keywords)))
11957 (setq now-done-p (and (member org-state org-done-keywords)
11958 (not (member this org-done-keywords))))
11959 (and logging (org-local-logging logging))
11960 (when (and (or org-todo-log-states org-log-done)
11961 (not (eq org-inhibit-logging t))
11962 (not (memq arg '(nextset previousset))))
11963 ;; we need to look at recording a time and note
11964 (setq dolog (or (nth 1 (assoc org-state org-todo-log-states))
11965 (nth 2 (assoc this org-todo-log-states))))
11966 (if (and (eq dolog 'note) (eq org-inhibit-logging 'note))
11967 (setq dolog 'time))
11968 (when (and org-state
11969 (member org-state org-not-done-keywords)
11970 (not (member this org-not-done-keywords)))
11971 ;; This is now a todo state and was not one before
11972 ;; If there was a CLOSED time stamp, get rid of it.
11973 (org-add-planning-info nil nil 'closed))
11974 (when (and now-done-p org-log-done)
11975 ;; It is now done, and it was not done before
11976 (org-add-planning-info 'closed (org-current-effective-time))
11977 (if (and (not dolog) (eq 'note org-log-done))
11978 (org-add-log-setup 'done org-state this 'findpos 'note)))
11979 (when (and org-state dolog)
11980 ;; This is a non-nil state, and we need to log it
11981 (org-add-log-setup 'state org-state this 'findpos dolog)))
11982 ;; Fixup tag positioning
11983 (org-todo-trigger-tag-changes org-state)
11984 (and org-auto-align-tags (not org-setting-tags) (org-set-tags nil t))
11985 (when org-provide-todo-statistics
11986 (org-update-parent-todo-statistics))
11987 (run-hooks 'org-after-todo-state-change-hook)
11988 (if (and arg (not (member org-state org-done-keywords)))
11989 (setq head (org-get-todo-sequence-head org-state)))
11990 (put-text-property (point-at-bol) (point-at-eol) 'org-todo-head head)
11991 ;; Do we need to trigger a repeat?
11993 (when (boundp 'org-agenda-headline-snapshot-before-repeat)
11994 ;; This is for the agenda, take a snapshot of the headline.
11996 (setq org-agenda-headline-snapshot-before-repeat
11997 (org-get-heading))))
11998 (org-auto-repeat-maybe org-state))
11999 ;; Fixup cursor location if close to the keyword
12000 (if (and (outline-on-heading-p)
12002 (save-excursion (beginning-of-line 1)
12003 (looking-at org-todo-line-regexp))
12004 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
12006 (goto-char (or (match-end 2) (match-end 1)))
12007 (and (looking-at " ") (just-one-space))))
12008 (when org-trigger-hook
12010 (run-hook-with-args 'org-trigger-hook change-plist)))
12011 (when commentp (org-toggle-comment))))))))
12013 (defun org-block-todo-from-children-or-siblings-or-parent (change-plist)
12014 "Block turning an entry into a TODO, using the hierarchy.
12015 This checks whether the current task should be blocked from state
12016 changes. Such blocking occurs when:
12018 1. The task has children which are not all in a completed state.
12020 2. A task has a parent with the property :ORDERED:, and there
12021 are siblings prior to the current task with incomplete
12024 3. The parent of the task is blocked because it has siblings that should
12025 be done first, or is child of a block grandparent TODO entry."
12027 (if (not org-enforce-todo-dependencies)
12028 t ; if locally turned off don't block
12030 ;; If this is not a todo state change, or if this entry is already DONE,
12032 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
12033 (member (plist-get change-plist :from)
12034 (cons 'done org-done-keywords))
12035 (member (plist-get change-plist :to)
12036 (cons 'todo org-not-done-keywords))
12037 (not (plist-get change-plist :to)))
12038 (throw 'dont-block t))
12039 ;; If this task has children, and any are undone, it's blocked
12041 (org-back-to-heading t)
12042 (let ((this-level (funcall outline-level)))
12043 (outline-next-heading)
12044 (let ((child-level (funcall outline-level)))
12045 (while (and (not (eobp))
12046 (> child-level this-level))
12047 ;; this todo has children, check whether they are all
12049 (if (and (not (org-entry-is-done-p))
12050 (org-entry-is-todo-p))
12051 (progn (setq org-block-entry-blocking (org-get-heading))
12052 (throw 'dont-block nil)))
12053 (outline-next-heading)
12054 (setq child-level (funcall outline-level))))))
12055 ;; Otherwise, if the task's parent has the :ORDERED: property, and
12056 ;; any previous siblings are undone, it's blocked
12058 (org-back-to-heading t)
12059 (let* ((pos (point))
12060 (parent-pos (and (org-up-heading-safe) (point))))
12061 (if (not parent-pos) (throw 'dont-block t)) ; no parent
12062 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
12064 (re-search-forward org-not-done-heading-regexp pos t))
12065 (setq org-block-entry-blocking (match-string 0))
12066 (throw 'dont-block nil)) ; block, there is an older sibling not done.
12067 ;; Search further up the hierarchy, to see if an ancestor is blocked
12069 (goto-char parent-pos)
12070 (if (not (looking-at org-not-done-heading-regexp))
12071 (throw 'dont-block t)) ; do not block, parent is not a TODO
12073 (setq parent-pos (and (org-up-heading-safe) (point)))
12074 (if (not parent-pos) (throw 'dont-block t)) ; no parent
12075 (when (and (org-not-nil (org-entry-get (point) "ORDERED"))
12077 (re-search-forward org-not-done-heading-regexp pos t)
12078 (setq org-block-entry-blocking (org-get-heading)))
12079 (throw 'dont-block nil)))))))) ; block, older sibling not done.
12081 (defcustom org-track-ordered-property-with-tag nil
12082 "Should the ORDERED property also be shown as a tag?
12083 The ORDERED property decides if an entry should require subtasks to be
12084 completed in sequence. Since a property is not very visible, setting
12085 this option means that toggling the ORDERED property with the command
12086 `org-toggle-ordered-property' will also toggle a tag ORDERED. That tag is
12087 not relevant for the behavior, but it makes things more visible.
12089 Note that toggling the tag with tags commands will not change the property
12090 and therefore not influence behavior!
12092 This can be t, meaning the tag ORDERED should be used, It can also be a
12093 string to select a different tag for this task."
12096 (const :tag "No tracking" nil)
12097 (const :tag "Track with ORDERED tag" t)
12098 (string :tag "Use other tag")))
12100 (defun org-toggle-ordered-property ()
12101 "Toggle the ORDERED property of the current entry.
12102 For better visibility, you can track the value of this property with a tag.
12103 See variable `org-track-ordered-property-with-tag'."
12105 (let* ((t1 org-track-ordered-property-with-tag)
12106 (tag (and t1 (if (stringp t1) t1 "ORDERED"))))
12108 (org-back-to-heading)
12109 (if (org-entry-get nil "ORDERED")
12111 (org-delete-property "ORDERED" "PROPERTIES")
12112 (and tag (org-toggle-tag tag 'off))
12113 (message "Subtasks can be completed in arbitrary order"))
12114 (org-entry-put nil "ORDERED" "t")
12115 (and tag (org-toggle-tag tag 'on))
12116 (message "Subtasks must be completed in sequence")))))
12118 (defvar org-blocked-by-checkboxes) ; dynamically scoped
12119 (defun org-block-todo-from-checkboxes (change-plist)
12120 "Block turning an entry into a TODO, using checkboxes.
12121 This checks whether the current task should be blocked from state
12122 changes because there are unchecked boxes in this entry."
12123 (if (not org-enforce-todo-checkbox-dependencies)
12124 t ; if locally turned off don't block
12126 ;; If this is not a todo state change, or if this entry is already DONE,
12128 (when (or (not (eq (plist-get change-plist :type) 'todo-state-change))
12129 (member (plist-get change-plist :from)
12130 (cons 'done org-done-keywords))
12131 (member (plist-get change-plist :to)
12132 (cons 'todo org-not-done-keywords))
12133 (not (plist-get change-plist :to)))
12134 (throw 'dont-block t))
12135 ;; If this task has checkboxes that are not checked, it's blocked
12137 (org-back-to-heading t)
12138 (let ((beg (point)) end)
12139 (outline-next-heading)
12142 (if (org-list-search-forward
12143 (concat (org-item-beginning-re)
12144 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
12148 (if (boundp 'org-blocked-by-checkboxes)
12149 (setq org-blocked-by-checkboxes t))
12150 (throw 'dont-block nil)))))
12151 t))) ; do not block
12153 (defun org-entry-blocked-p ()
12154 "Is the current entry blocked?"
12155 (org-with-buffer-modified-unmodified
12156 (if (org-entry-get nil "NOBLOCKING")
12157 nil ;; Never block this entry
12159 (run-hook-with-args-until-failure
12161 (list :type 'todo-state-change
12166 (defun org-update-statistics-cookies (all)
12167 "Update the statistics cookie, either from TODO or from checkboxes.
12168 This should be called with the cursor in a line with a statistics cookie."
12172 (org-update-checkbox-count 'all)
12173 (org-map-entries 'org-update-parent-todo-statistics))
12174 (if (not (org-at-heading-p))
12175 (org-update-checkbox-count)
12176 (let ((pos (point-marker))
12178 (ignore-errors (org-back-to-heading t))
12179 (if (not (org-at-heading-p))
12180 (org-update-checkbox-count)
12181 (setq l1 (org-outline-level))
12182 (setq end (save-excursion
12183 (outline-next-heading)
12184 (if (org-at-heading-p) (setq l2 (org-outline-level)))
12186 (if (and (save-excursion
12188 "^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) \\[[- X]\\]" end t))
12189 (not (save-excursion (re-search-forward
12190 ":COOKIE_DATA:.*\\<todo\\>" end t))))
12191 (org-update-checkbox-count)
12192 (if (and l2 (> l2 l1))
12195 (org-update-parent-todo-statistics))
12197 (beginning-of-line 1)
12198 (while (re-search-forward
12199 "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)"
12201 (replace-match (if (match-end 2) "[100%]" "[0/0]") t t)))))
12203 (move-marker pos nil)))))
12205 (defvar org-entry-property-inherited-from) ;; defined below
12206 (defun org-update-parent-todo-statistics ()
12207 "Update any statistics cookie in the parent of the current headline.
12208 When `org-hierarchical-todo-statistics' is nil, statistics will cover
12209 the entire subtree and this will travel up the hierarchy and update
12210 statistics everywhere."
12211 (let* ((prop (save-excursion (org-up-heading-safe)
12212 (org-entry-get nil "COOKIE_DATA" 'inherit)))
12213 (recursive (or (not org-hierarchical-todo-statistics)
12214 (and prop (string-match "\\<recursive\\>" prop))))
12215 (lim (or (and prop (marker-position org-entry-property-inherited-from))
12218 (box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
12219 level ltoggle l1 new ndel
12220 (cnt-all 0) (cnt-done 0) is-percent kwd
12221 checkbox-beg ov ovs ove cookie-present)
12224 (beginning-of-line 1)
12225 (setq ltoggle (funcall outline-level))
12226 ;; Three situations are to consider:
12228 ;; 1. if `org-hierarchical-todo-statistics' is nil, repeat up
12229 ;; to the top-level ancestor on the headline;
12231 ;; 2. If parent has "recursive" property, repeat up to the
12232 ;; headline setting that property, taking inheritance into
12235 ;; 3. Else, move up to direct parent and proceed only once.
12236 (while (and (setq level (org-up-heading-safe))
12237 (or recursive first)
12239 (setq first nil cookie-present nil)
12243 (downcase (or (org-entry-get nil "COOKIE_DATA")
12246 (while (re-search-forward box-re (point-at-eol) t)
12247 (setq cnt-all 0 cnt-done 0 cookie-present t)
12248 (setq is-percent (match-end 2) checkbox-beg (match-beginning 0))
12250 (unless (outline-next-heading) (throw 'exit nil))
12251 (while (and (looking-at org-complex-heading-regexp)
12252 (> (setq l1 (length (match-string 1))) level))
12253 (setq kwd (and (or recursive (= l1 ltoggle))
12255 (if (or (eq org-provide-todo-statistics 'all-headlines)
12256 (and (listp org-provide-todo-statistics)
12257 (or (member kwd org-provide-todo-statistics)
12258 (member kwd org-done-keywords))))
12259 (setq cnt-all (1+ cnt-all))
12260 (if (eq org-provide-todo-statistics t)
12261 (and kwd (setq cnt-all (1+ cnt-all)))))
12262 (and (member kwd org-done-keywords)
12263 (setq cnt-done (1+ cnt-done)))
12264 (outline-next-heading)))
12267 (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
12268 (format "[%d/%d]" cnt-done cnt-all))
12269 ndel (- (match-end 0) checkbox-beg))
12270 ;; handle overlays when updating cookie from column view
12271 (when (setq ov (car (overlays-at checkbox-beg)))
12272 (setq ovs (overlay-start ov) ove (overlay-end ov))
12273 (delete-overlay ov))
12274 (goto-char checkbox-beg)
12276 (delete-region (point) (+ (point) ndel))
12277 (when org-auto-align-tags (org-fix-tags-on-the-fly))
12278 (when ov (move-overlay ov ovs ove)))
12279 (when cookie-present
12280 (run-hook-with-args 'org-after-todo-statistics-hook
12281 cnt-done (- cnt-all cnt-done))))))
12282 (run-hooks 'org-todo-statistics-hook)))
12284 (defvar org-after-todo-statistics-hook nil
12285 "Hook that is called after a TODO statistics cookie has been updated.
12286 Each function is called with two arguments: the number of not-done entries
12287 and the number of done entries.
12289 For example, the following function, when added to this hook, will switch
12290 an entry to DONE when all children are done, and back to TODO when new
12291 entries are set to a TODO status. Note that this hook is only called
12292 when there is a statistics cookie in the headline!
12294 (defun org-summary-todo (n-done n-not-done)
12295 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
12296 (let (org-log-done org-log-states) ; turn off logging
12297 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
12300 (defvar org-todo-statistics-hook nil
12301 "Hook that is run whenever Org thinks TODO statistics should be updated.
12302 This hook runs even if there is no statistics cookie present, in which case
12303 `org-after-todo-statistics-hook' would not run.")
12305 (defun org-todo-trigger-tag-changes (state)
12306 "Apply the changes defined in `org-todo-state-tags-triggers'."
12307 (let ((l org-todo-state-tags-triggers)
12309 (when (or (not state) (equal state ""))
12310 (setq changes (append changes (cdr (assoc "" l)))))
12311 (when (and (stringp state) (> (length state) 0))
12312 (setq changes (append changes (cdr (assoc state l)))))
12313 (when (member state org-not-done-keywords)
12314 (setq changes (append changes (cdr (assoc 'todo l)))))
12315 (when (member state org-done-keywords)
12316 (setq changes (append changes (cdr (assoc 'done l)))))
12317 (dolist (c changes)
12318 (org-toggle-tag (car c) (if (cdr c) 'on 'off)))))
12320 (defun org-local-logging (value)
12321 "Get logging settings from a property VALUE."
12323 ;; directly set the variables, they are already local.
12324 (setq org-log-done nil
12326 org-todo-log-states nil)
12327 (setq words (org-split-string value))
12328 (while (setq w (pop words))
12330 ((setq a (assoc w org-startup-options))
12331 (and (member (nth 1 a) '(org-log-done org-log-repeat))
12332 (set (nth 1 a) (nth 2 a))))
12333 ((setq a (org-extract-log-state-settings w))
12334 (and (member (car a) org-todo-keywords-1)
12335 (push a org-todo-log-states)))))))
12337 (defun org-get-todo-sequence-head (kwd)
12338 "Return the head of the TODO sequence to which KWD belongs.
12339 If KWD is not set, check if there is a text property remembering the
12344 (or (get-text-property (point-at-bol) 'org-todo-head)
12346 (setq p (next-single-property-change (point-at-bol) 'org-todo-head
12347 nil (point-at-eol)))
12348 (get-text-property p 'org-todo-head))))
12349 ((not (member kwd org-todo-keywords-1))
12350 (car org-todo-keywords-1))
12351 (t (nth 2 (assoc kwd org-todo-kwd-alist))))))
12353 (defun org-fast-todo-selection ()
12354 "Fast TODO keyword selection with single keys.
12355 Returns the new TODO keyword, or nil if no state change should occur."
12356 (let* ((fulltable org-todo-key-alist)
12357 (done-keywords org-done-keywords) ;; needed for the faces.
12358 (maxlen (apply 'max (mapcar
12360 (if (stringp (car x)) (string-width (car x)) 0))
12363 (fwidth (+ maxlen 3 1 3))
12364 (ncol (/ (- (window-width) 4) fwidth))
12368 (save-window-excursion
12370 (set-buffer (get-buffer-create " *Org todo*"))
12371 (org-switch-to-buffer-other-window (get-buffer-create " *Org todo*")))
12373 (org-set-local 'org-done-keywords done-keywords)
12374 (setq tbl fulltable cnt 0)
12375 (while (setq e (pop tbl))
12377 ((equal e '(:startgroup))
12378 (push '() groups) (setq ingroup t)
12379 (when (not (= cnt 0))
12383 ((equal e '(:endgroup))
12384 (setq ingroup nil cnt 0)
12386 ((equal e '(:newline))
12387 (when (not (= cnt 0))
12391 (while (equal (car tbl) '(:newline))
12393 (setq tbl (cdr tbl)))))
12395 (setq tg (car e) c (cdr e))
12396 (if ingroup (push tg (car groups)))
12397 (setq tg (org-add-props tg nil 'face
12398 (org-get-todo-face tg)))
12399 (if (and (= cnt 0) (not ingroup)) (insert " "))
12400 (insert "[" c "] " tg (make-string
12401 (- fwidth 4 (length tg)) ?\ ))
12402 (when (= (setq cnt (1+ cnt)) ncol)
12404 (if ingroup (insert " "))
12407 (goto-char (point-min))
12408 (if (not expert) (org-fit-window-to-buffer))
12409 (message "[a-z..]:Set [SPC]:clear")
12410 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
12413 (and (= c ?q) (not (rassoc c fulltable))))
12414 (setq quit-flag t))
12416 ((setq e (rassoc c fulltable) tg (car e))
12418 (t (setq quit-flag t)))))))
12420 (defun org-entry-is-todo-p ()
12421 (member (org-get-todo-state) org-not-done-keywords))
12423 (defun org-entry-is-done-p ()
12424 (member (org-get-todo-state) org-done-keywords))
12426 (defun org-get-todo-state ()
12428 (org-back-to-heading t)
12429 (and (looking-at org-todo-line-regexp)
12431 (match-string 2))))
12433 (defun org-at-date-range-p (&optional inactive-ok)
12434 "Is the cursor inside a date range?"
12438 (let ((pos (point)))
12439 (skip-chars-backward "^[<\r\n")
12440 (skip-chars-backward "<[")
12441 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
12442 (>= (match-end 0) pos)
12444 (skip-chars-backward "^<[\r\n")
12445 (skip-chars-backward "<[")
12446 (and (looking-at (if inactive-ok org-tr-regexp-both org-tr-regexp))
12447 (>= (match-end 0) pos)
12451 (defun org-get-repeat (&optional tagline)
12452 "Check if there is a deadline/schedule with repeater in this entry."
12455 (org-back-to-heading t)
12456 (and (re-search-forward (if tagline
12457 (concat tagline "\\s-*" org-repeat-re)
12459 (org-entry-end-position) t)
12460 (match-string-no-properties 1)))))
12462 (defvar org-last-changed-timestamp)
12463 (defvar org-last-inserted-timestamp)
12464 (defvar org-log-post-message)
12465 (defvar org-log-note-purpose)
12466 (defvar org-log-note-how)
12467 (defvar org-log-note-extra)
12468 (defun org-auto-repeat-maybe (done-word)
12469 "Check if the current headline contains a repeated deadline/schedule.
12470 If yes, set TODO state back to what it was and change the base date
12471 of repeating deadline/scheduled time stamps to new date.
12472 This function is run automatically after each state change to a DONE state."
12473 ;; last-state is dynamically scoped into this function
12474 (let* ((repeat (org-get-repeat))
12475 (aa (assoc org-last-state org-todo-kwd-alist))
12476 (interpret (nth 1 aa))
12478 (whata '(("h" . hour) ("d" . day) ("m" . month) ("y" . year)))
12479 (msg "Entry repeats: ")
12481 (org-todo-log-states nil)
12482 re type n what ts time to-state)
12484 (if (eq org-log-repeat t) (setq org-log-repeat 'state))
12485 (setq to-state (or (org-entry-get nil "REPEAT_TO_STATE")
12486 org-todo-repeat-to-state))
12487 (unless (and to-state (member to-state org-todo-keywords-1))
12488 (setq to-state (if (eq interpret 'type) org-last-state head)))
12489 (org-todo to-state)
12490 (when (or org-log-repeat (org-entry-get nil "CLOCK"))
12491 (org-entry-put nil "LAST_REPEAT" (format-time-string
12492 (org-time-stamp-format t t))))
12493 (when org-log-repeat
12494 (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
12495 (memq 'org-add-log-note post-command-hook))
12496 ;; OK, we are already setup for some record
12497 (if (eq org-log-repeat 'note)
12498 ;; make sure we take a note, not only a time stamp
12499 (setq org-log-note-how 'note))
12500 ;; Set up for taking a record
12501 (org-add-log-setup 'state (or done-word (car org-done-keywords))
12503 'findpos org-log-repeat)))
12504 (org-back-to-heading t)
12505 (org-add-planning-info nil nil 'closed)
12506 (setq re (concat "\\(" org-scheduled-time-regexp "\\)\\|\\("
12507 org-deadline-time-regexp "\\)\\|\\("
12508 org-ts-regexp "\\)"))
12509 (while (re-search-forward
12510 re (save-excursion (outline-next-heading) (point)) t)
12511 (setq type (if (match-end 1) org-scheduled-string
12512 (if (match-end 3) org-deadline-string "Plain:"))
12513 ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0))))
12514 (when (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" ts)
12515 (setq n (string-to-number (match-string 2 ts))
12516 what (match-string 3 ts))
12517 (if (equal what "w") (setq n (* n 7) what "d"))
12518 (if (and (equal what "h") (not (string-match "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts)))
12519 (error "Cannot repeat in Repeat in %d hour(s) because no hour has been set" n))
12520 ;; Preparation, see if we need to modify the start date for the change
12521 (when (match-end 1)
12522 (setq time (save-match-data (org-time-string-to-time ts)))
12524 ((equal (match-string 1 ts) ".")
12525 ;; Shift starting date to today
12526 (org-timestamp-change
12527 (- (org-today) (time-to-days time))
12529 ((equal (match-string 1 ts) "+")
12530 (let ((nshiftmax 10) (nshift 0))
12531 (while (or (= nshift 0)
12532 (<= (time-to-days time)
12533 (time-to-days (current-time))))
12534 (when (= (incf nshift) nshiftmax)
12535 (or (y-or-n-p (message "%d repeater intervals were not enough to shift date past today. Continue? " nshift))
12537 (org-timestamp-change n (cdr (assoc what whata)))
12538 (org-at-timestamp-p t)
12539 (setq ts (match-string 1))
12540 (setq time (save-match-data (org-time-string-to-time ts)))))
12541 (org-timestamp-change (- n) (cdr (assoc what whata)))
12542 ;; rematch, so that we have everything in place for the real shift
12543 (org-at-timestamp-p t)
12544 (setq ts (match-string 1))
12545 (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)" ts))))
12546 (save-excursion (org-timestamp-change n (cdr (assoc what whata)) nil t))
12547 (setq msg (concat msg type " " org-last-changed-timestamp " "))))
12548 (setq org-log-post-message msg)
12549 (message "%s" msg))))
12551 (defun org-show-todo-tree (arg)
12552 "Make a compact tree which shows all headlines marked with TODO.
12553 The tree will show the lines where the regexp matches, and all higher
12554 headlines above the match.
12555 With a \\[universal-argument] prefix, prompt for a regexp to match.
12556 With a numeric prefix N, construct a sparse tree for the Nth element
12557 of `org-todo-keywords-1'."
12559 (let ((case-fold-search nil)
12561 (cond ((null arg) org-not-done-regexp)
12563 (let ((kwd (org-icompleting-read "Keyword (or KWD1|KWD2|...): "
12564 (mapcar 'list org-todo-keywords-1))))
12566 (mapconcat 'identity (org-split-string kwd "|") "\\|")
12568 ((<= (prefix-numeric-value arg) (length org-todo-keywords-1))
12569 (regexp-quote (nth (1- (prefix-numeric-value arg))
12570 org-todo-keywords-1)))
12571 (t (error "Invalid prefix argument: %s" arg)))))
12572 (message "%d TODO entries found"
12573 (org-occur (concat "^" org-outline-regexp " *" kwd-re )))))
12575 (defun org-deadline (&optional arg time)
12576 "Insert the \"DEADLINE:\" string with a timestamp to make a deadline.
12577 With one universal prefix argument, remove any deadline from the item.
12578 With two universal prefix arguments, prompt for a warning delay.
12579 With argument TIME, set the deadline at the corresponding date. TIME
12580 can either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12582 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12583 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12584 'region-start-level 'region))
12585 org-loop-over-headlines-in-active-region)
12587 `(org-deadline ',arg ,time)
12588 org-loop-over-headlines-in-active-region
12589 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12590 (let* ((old-date (org-entry-get nil "DEADLINE"))
12591 (repeater (and old-date
12593 "\\([.+-]+[0-9]+[hdwmy]\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
12595 (match-string 1 old-date))))
12598 (when (and old-date org-log-redeadline)
12599 (org-add-log-setup 'deldeadline nil old-date 'findpos
12600 org-log-redeadline))
12601 (org-remove-timestamp-with-keyword org-deadline-string)
12602 (message "Item no longer has a deadline."))
12605 (if (re-search-forward
12606 org-deadline-time-regexp
12607 (save-excursion (outline-next-heading) (point)) t)
12608 (let* ((rpl0 (match-string 1))
12609 (rpl (replace-regexp-in-string " -[0-9]+[hdwmy]" "" rpl0)))
12611 (concat org-deadline-string
12613 (format " -%dd" (abs
12616 (org-read-date nil t nil "Warn starting from")))
12617 (time-to-days nil))))
12619 (user-error "No deadline information to update"))))
12621 (org-add-planning-info 'deadline time 'closed)
12622 (when (and old-date org-log-redeadline
12623 (not (equal old-date
12624 (substring org-last-inserted-timestamp 1 -1))))
12625 (org-add-log-setup 'redeadline nil old-date 'findpos
12626 org-log-redeadline))
12629 (org-back-to-heading t)
12630 (when (re-search-forward (concat org-deadline-string " "
12631 org-last-inserted-timestamp)
12633 (outline-next-heading) (point)) t)
12634 (goto-char (1- (match-end 0)))
12635 (insert " " repeater)
12636 (setq org-last-inserted-timestamp
12637 (concat (substring org-last-inserted-timestamp 0 -1)
12639 (substring org-last-inserted-timestamp -1))))))
12640 (message "Deadline on %s" org-last-inserted-timestamp))))))
12642 (defun org-schedule (&optional arg time)
12643 "Insert the SCHEDULED: string with a timestamp to schedule a TODO item.
12644 With one universal prefix argument, remove any scheduling date from the item.
12645 With two universal prefix arguments, prompt for a delay cookie.
12646 With argument TIME, scheduled at the corresponding date. TIME can
12647 either be an Org date like \"2011-07-24\" or a delta like \"+2d\"."
12649 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
12650 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
12651 'region-start-level 'region))
12652 org-loop-over-headlines-in-active-region)
12654 `(org-schedule ',arg ,time)
12655 org-loop-over-headlines-in-active-region
12656 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
12657 (let* ((old-date (org-entry-get nil "SCHEDULED"))
12658 (repeater (and old-date
12660 "\\([.+-]+[0-9]+[hdwmy]\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
12662 (match-string 1 old-date))))
12666 (when (and old-date org-log-reschedule)
12667 (org-add-log-setup 'delschedule nil old-date 'findpos
12668 org-log-reschedule))
12669 (org-remove-timestamp-with-keyword org-scheduled-string)
12670 (message "Item is no longer scheduled.")))
12673 (if (re-search-forward
12674 org-scheduled-time-regexp
12675 (save-excursion (outline-next-heading) (point)) t)
12676 (let* ((rpl0 (match-string 1))
12677 (rpl (replace-regexp-in-string " -[0-9]+[hdwmy]" "" rpl0)))
12679 (concat org-scheduled-string
12681 (format " -%dd" (abs
12684 (org-read-date nil t nil "Delay until")))
12685 (time-to-days nil))))
12687 (user-error "No scheduled information to update"))))
12689 (org-add-planning-info 'scheduled time 'closed)
12690 (when (and old-date org-log-reschedule
12691 (not (equal old-date
12692 (substring org-last-inserted-timestamp 1 -1))))
12693 (org-add-log-setup 'reschedule nil old-date 'findpos
12694 org-log-reschedule))
12697 (org-back-to-heading t)
12698 (when (re-search-forward (concat org-scheduled-string " "
12699 org-last-inserted-timestamp)
12701 (outline-next-heading) (point)) t)
12702 (goto-char (1- (match-end 0)))
12703 (insert " " repeater)
12704 (setq org-last-inserted-timestamp
12705 (concat (substring org-last-inserted-timestamp 0 -1)
12707 (substring org-last-inserted-timestamp -1))))))
12708 (message "Scheduled to %s" org-last-inserted-timestamp))))))
12710 (defun org-get-scheduled-time (pom &optional inherit)
12711 "Get the scheduled time as a time tuple, of a format suitable
12712 for calling org-schedule with, or if there is no scheduling,
12714 (let ((time (org-entry-get pom "SCHEDULED" inherit)))
12716 (apply 'encode-time (org-parse-time-string time)))))
12718 (defun org-get-deadline-time (pom &optional inherit)
12719 "Get the deadline as a time tuple, of a format suitable for
12720 calling org-deadline with, or if there is no scheduling, returns
12722 (let ((time (org-entry-get pom "DEADLINE" inherit)))
12724 (apply 'encode-time (org-parse-time-string time)))))
12726 (defun org-remove-timestamp-with-keyword (keyword)
12727 "Remove all time stamps with KEYWORD in the current entry."
12728 (let ((re (concat "\\<" (regexp-quote keyword) " +<[^>\n]+>[ \t]*"))
12731 (org-back-to-heading t)
12733 (outline-next-heading)
12734 (while (re-search-backward re beg t)
12736 (if (and (string-match "\\S-" (buffer-substring (point-at-bol) (point)))
12737 (equal (char-before) ?\ ))
12738 (backward-delete-char 1)
12739 (if (string-match "^[ \t]*$" (buffer-substring
12740 (point-at-bol) (point-at-eol)))
12741 (delete-region (point-at-bol)
12742 (min (point-max) (1+ (point-at-eol))))))))))
12744 (defun org-add-planning-info (what &optional time &rest remove)
12745 "Insert new timestamp with keyword in the line directly after the headline.
12746 WHAT indicates what kind of time stamp to add. TIME indicates the time to use.
12747 If non is given, the user is prompted for a date.
12748 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
12751 (let (org-time-was-given org-end-time-was-given ts
12752 end default-time default-input)
12755 (when (and (memq what '(scheduled deadline))
12757 (and (stringp time)
12758 (string-match "^[-+]+[0-9]" time))))
12759 ;; Try to get a default date/time from existing timestamp
12761 (org-back-to-heading t)
12762 (setq end (save-excursion (outline-next-heading) (point)))
12763 (when (re-search-forward (if (eq what 'scheduled)
12764 org-scheduled-time-regexp
12765 org-deadline-time-regexp)
12767 (setq ts (match-string 1)
12769 (apply 'encode-time (org-parse-time-string ts))
12770 default-input (and ts (org-get-compact-tod ts))))))
12774 ;; This is a string (relative or absolute), set proper date
12775 (apply 'encode-time
12776 (org-read-date-analyze
12777 time default-time (decode-time default-time)))
12778 ;; If necessary, get the time from the user
12779 (or time (org-read-date nil 'to-time nil nil
12780 default-time default-input)))))
12782 (when (and org-insert-labeled-timestamps-at-point
12783 (member what '(scheduled deadline)))
12785 (if (eq what 'scheduled) org-scheduled-string org-deadline-string) " ")
12786 (org-insert-time-stamp time org-time-was-given
12787 nil nil nil (list org-end-time-was-given))
12791 (let (col list elt ts buffer-invisibility-spec)
12792 (org-back-to-heading t)
12793 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"))
12794 (goto-char (match-end 1))
12795 (setq col (current-column))
12796 (goto-char (match-end 0))
12797 (if (eobp) (insert "\n") (forward-char 1))
12798 (when (and (not what)
12801 org-keyword-time-not-clock-regexp))))
12802 ;; Nothing to add, nothing to remove...... :-)
12804 (if (and (not (looking-at org-outline-regexp))
12805 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
12807 (not (equal (match-string 1) org-clock-string)))
12808 (narrow-to-region (match-beginning 0) (match-end 0))
12809 (insert-before-markers "\n")
12811 (narrow-to-region (point) (point))
12812 (and org-adapt-indentation (org-indent-to-column col)))
12813 ;; Check if we have to remove something.
12814 (setq list (cons what remove))
12816 (setq elt (pop list))
12817 (when (or (and (eq elt 'scheduled)
12818 (re-search-forward org-scheduled-time-regexp nil t))
12819 (and (eq elt 'deadline)
12820 (re-search-forward org-deadline-time-regexp nil t))
12821 (and (eq elt 'closed)
12822 (re-search-forward org-closed-time-regexp nil t)))
12824 (if (looking-at "--+<[^>]+>") (replace-match ""))))
12825 (and (looking-at "[ \t]+") (replace-match ""))
12826 (and org-adapt-indentation (bolp) (org-indent-to-column col))
12829 (if (not (or (bolp) (eq (char-before) ?\ ))) " " "")
12830 (cond ((eq what 'scheduled) org-scheduled-string)
12831 ((eq what 'deadline) org-deadline-string)
12832 ((eq what 'closed) org-closed-string))
12834 (setq ts (org-insert-time-stamp
12836 (or org-time-was-given
12837 (and (eq what 'closed) org-log-done-with-time))
12839 nil nil (list org-end-time-was-given)))
12841 (if (not (or (bolp) (eq (char-before) ?\ )
12842 (memq (char-after) '(32 10))
12845 (goto-char (point-min))
12847 (if (and (looking-at "[ \t]*\n")
12848 (equal (char-before) ?\n))
12849 (delete-region (1- (point)) (point-at-eol)))
12852 (defvar org-log-note-marker (make-marker))
12853 (defvar org-log-note-purpose nil)
12854 (defvar org-log-note-state nil)
12855 (defvar org-log-note-previous-state nil)
12856 (defvar org-log-note-how nil)
12857 (defvar org-log-note-extra nil)
12858 (defvar org-log-note-window-configuration nil)
12859 (defvar org-log-note-return-to (make-marker))
12860 (defvar org-log-note-effective-time nil
12861 "Remembered current time so that dynamically scoped
12862 `org-extend-today-until' affects tha timestamps in state change
12865 (defvar org-log-post-message nil
12866 "Message to be displayed after a log note has been stored.
12867 The auto-repeater uses this.")
12869 (defun org-add-note ()
12870 "Add a note to the current entry.
12871 This is done in the same way as adding a state change note."
12873 (org-add-log-setup 'note nil nil 'findpos nil))
12875 (defvar org-property-end-re)
12876 (defun org-add-log-setup (&optional purpose state prev-state
12878 "Set up the post command hook to take a note.
12879 If this is about to TODO state change, the new state is expected in STATE.
12880 When FINDPOS is non-nil, find the correct position for the note in
12881 the current entry. If not, assume that it can be inserted at point.
12882 HOW is an indicator what kind of note should be created.
12883 EXTRA is additional text that will be inserted into the notes buffer."
12884 (let* ((org-log-into-drawer (org-log-into-drawer))
12885 (drawer (cond ((stringp org-log-into-drawer)
12886 org-log-into-drawer)
12887 (org-log-into-drawer "LOGBOOK"))))
12891 (org-back-to-heading t)
12892 (narrow-to-region (point) (save-excursion
12893 (outline-next-heading) (point)))
12894 (looking-at (concat org-outline-regexp "\\( *\\)[^\r\n]*"
12895 "\\(\n[^\r\n]*?" org-keyword-time-not-clock-regexp
12897 (goto-char (match-end 0))
12900 (if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
12903 (goto-char (match-end 0))
12904 (or org-log-states-order-reversed
12905 (and (re-search-forward org-property-end-re nil t)
12906 (goto-char (1- (match-beginning 0))))))
12907 (insert "\n:" drawer ":\n:END:")
12908 (beginning-of-line 0)
12910 (beginning-of-line 2)
12913 ((and org-log-state-notes-insert-after-drawers
12915 (forward-line) (looking-at org-drawer-regexp)))
12917 (while (looking-at org-drawer-regexp)
12918 (goto-char (match-end 0))
12919 (re-search-forward org-property-end-re (point-max) t)
12921 (forward-line -1)))
12922 (unless org-log-states-order-reversed
12923 (and (= (char-after) ?\n) (forward-char 1))
12924 (org-skip-over-state-notes)
12925 (skip-chars-backward " \t\n\r")))
12926 (move-marker org-log-note-marker (point))
12927 (setq org-log-note-purpose purpose
12928 org-log-note-state state
12929 org-log-note-previous-state prev-state
12930 org-log-note-how how
12931 org-log-note-extra extra
12932 org-log-note-effective-time (org-current-effective-time))
12933 (add-hook 'post-command-hook 'org-add-log-note 'append)))))
12935 (defun org-skip-over-state-notes ()
12936 "Skip past the list of State notes in an entry."
12937 (if (looking-at "\n[ \t]*- State") (forward-char 1))
12938 (when (ignore-errors (goto-char (org-in-item-p)))
12939 (let* ((struct (org-list-struct))
12940 (prevs (org-list-prevs-alist struct)))
12941 (while (looking-at "[ \t]*- State")
12942 (goto-char (or (org-list-get-next-item (point) struct prevs)
12943 (org-list-get-item-end (point) struct)))))))
12945 (defun org-add-log-note (&optional purpose)
12946 "Pop up a window for taking a note, and add this note later at point."
12947 (remove-hook 'post-command-hook 'org-add-log-note)
12948 (setq org-log-note-window-configuration (current-window-configuration))
12949 (delete-other-windows)
12950 (move-marker org-log-note-return-to (point))
12951 (org-pop-to-buffer-same-window (marker-buffer org-log-note-marker))
12952 (goto-char org-log-note-marker)
12953 (org-switch-to-buffer-other-window "*Org Note*")
12955 (if (memq org-log-note-how '(time state))
12956 (let (current-prefix-arg) (org-store-log-note))
12957 (let ((org-inhibit-startup t)) (org-mode))
12958 (insert (format "# Insert note for %s.
12959 # Finish with C-c C-c, or cancel with C-c C-k.\n\n"
12961 ((eq org-log-note-purpose 'clock-out) "stopped clock")
12962 ((eq org-log-note-purpose 'done) "closed todo item")
12963 ((eq org-log-note-purpose 'state)
12964 (format "state change from \"%s\" to \"%s\""
12965 (or org-log-note-previous-state "")
12966 (or org-log-note-state "")))
12967 ((eq org-log-note-purpose 'reschedule)
12969 ((eq org-log-note-purpose 'delschedule)
12970 "no longer scheduled")
12971 ((eq org-log-note-purpose 'redeadline)
12972 "changing deadline")
12973 ((eq org-log-note-purpose 'deldeadline)
12974 "removing deadline")
12975 ((eq org-log-note-purpose 'refile)
12977 ((eq org-log-note-purpose 'note)
12979 (t (error "This should not happen")))))
12980 (if org-log-note-extra (insert org-log-note-extra))
12981 (org-set-local 'org-finish-function 'org-store-log-note)
12982 (run-hooks 'org-log-buffer-setup-hook)))
12984 (defvar org-note-abort nil) ; dynamically scoped
12985 (defun org-store-log-note ()
12986 "Finish taking a log note, and insert it to where it belongs."
12987 (let ((txt (buffer-string)))
12988 (kill-buffer (current-buffer))
12989 (let ((note (cdr (assq org-log-note-purpose org-log-note-headings)))
12991 (while (string-match "\\`# .*\n[ \t\n]*" txt)
12992 (setq txt (replace-match "" t t txt)))
12993 (if (string-match "\\s-+\\'" txt)
12994 (setq txt (replace-match "" t t txt)))
12995 (setq lines (org-split-string txt "\n"))
12996 (when (and note (string-match "\\S-" note))
12998 (org-replace-escapes
13000 (list (cons "%u" (user-login-name))
13001 (cons "%U" user-full-name)
13002 (cons "%t" (format-time-string
13003 (org-time-stamp-format 'long 'inactive)
13004 org-log-note-effective-time))
13005 (cons "%T" (format-time-string
13006 (org-time-stamp-format 'long nil)
13007 org-log-note-effective-time))
13008 (cons "%d" (format-time-string
13009 (org-time-stamp-format nil 'inactive)
13010 org-log-note-effective-time))
13011 (cons "%D" (format-time-string
13012 (org-time-stamp-format nil nil)
13013 org-log-note-effective-time))
13014 (cons "%s" (if org-log-note-state
13015 (concat "\"" org-log-note-state "\"")
13017 (cons "%S" (if org-log-note-previous-state
13018 (concat "\"" org-log-note-previous-state "\"")
13020 (if lines (setq note (concat note " \\\\")))
13022 (when (or current-prefix-arg org-note-abort)
13023 (when org-log-into-drawer
13024 (org-remove-empty-drawer-at
13025 (if (stringp org-log-into-drawer) org-log-into-drawer "LOGBOOK")
13026 org-log-note-marker))
13029 (with-current-buffer (marker-buffer org-log-note-marker)
13031 (goto-char org-log-note-marker)
13032 (move-marker org-log-note-marker nil)
13034 (if (not (bolp)) (let ((inhibit-read-only t)) (insert "\n")))
13035 (setq ind (save-excursion
13036 (if (ignore-errors (goto-char (org-in-item-p)))
13037 (let ((struct (org-list-struct)))
13039 (org-list-get-top-point struct) struct))
13040 (skip-chars-backward " \r\t\n")
13042 ((and (org-at-heading-p)
13043 org-adapt-indentation)
13044 (1+ (org-current-level)))
13045 ((org-at-heading-p) 0)
13046 (t (org-get-indentation))))))
13047 (setq bul (org-list-bullet-string "-"))
13048 (org-indent-line-to ind)
13049 (insert bul (pop lines))
13050 (let ((ind-body (+ (length bul) ind)))
13053 (org-indent-line-to ind-body)
13054 (insert (pop lines))))
13055 (message "Note stored")
13056 (org-back-to-heading t)
13057 (org-cycle-hide-drawers 'children))))))
13058 (set-window-configuration org-log-note-window-configuration)
13059 (with-current-buffer (marker-buffer org-log-note-return-to)
13060 (goto-char org-log-note-return-to))
13061 (move-marker org-log-note-return-to nil)
13062 (and org-log-post-message (message "%s" org-log-post-message)))
13064 (defun org-remove-empty-drawer-at (drawer pos)
13065 "Remove an empty drawer DRAWER at position POS.
13066 POS may also be a marker."
13067 (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
13073 (concat "^[ \t]*:" drawer ":[ \t]*\n[ \t]*:END:[ \t]*\n?") 2)
13074 (replace-match ""))))))
13076 (defvar org-ts-type nil)
13077 (defun org-sparse-tree (&optional arg type)
13078 "Create a sparse tree, prompt for the details.
13079 This command can create sparse trees. You first need to select the type
13080 of match used to create the tree:
13082 t Show all TODO entries.
13083 T Show entries with a specific TODO keyword.
13084 m Show entries selected by a tags/property match.
13085 p Enter a property name and its value (both with completion on existing
13086 names/values) and show entries with that property.
13087 r Show entries matching a regular expression (`/' can be used as well).
13088 b Show deadlines and scheduled items before a date.
13089 a Show deadlines and scheduled items after a date.
13090 d Show deadlines due within `org-deadline-warning-days'.
13091 D Show deadlines and scheduled items between a date range."
13093 (let (ans kwd value ts-type)
13094 (setq type (or type org-sparse-tree-default-date-type))
13095 (setq org-ts-type type)
13096 (message "Sparse tree: [/]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"
13097 (cond ((eq type 'all) "all timestamps")
13098 ((eq type 'scheduled) "only scheduled")
13099 ((eq type 'deadline) "only deadline")
13100 ((eq type 'active) "only active timestamps")
13101 ((eq type 'inactive) "only inactive timestamps")
13102 ((eq type 'scheduled-or-deadline) "scheduled/deadline")
13103 (t "scheduled/deadline")))
13104 (setq ans (read-char-exclusive))
13107 (org-sparse-tree arg (cadr (member type '(scheduled-or-deadline all scheduled deadline active inactive)))))
13109 (call-interactively 'org-check-deadlines))
13111 (call-interactively 'org-check-before-date))
13113 (call-interactively 'org-check-after-date))
13115 (call-interactively 'org-check-dates-range))
13117 (call-interactively 'org-show-todo-tree))
13119 (org-show-todo-tree '(4)))
13120 ((member ans '(?T ?m))
13121 (call-interactively 'org-match-sparse-tree))
13122 ((member ans '(?p ?P))
13123 (setq kwd (org-icompleting-read "Property: "
13124 (mapcar 'list (org-buffer-property-keys))))
13125 (setq value (org-icompleting-read "Value: "
13126 (mapcar 'list (org-property-values kwd))))
13127 (unless (string-match "\\`{.*}\\'" value)
13128 (setq value (concat "\"" value "\"")))
13129 (org-match-sparse-tree arg (concat kwd "=" value)))
13130 ((member ans '(?r ?R ?/))
13131 (call-interactively 'org-occur))
13132 (t (error "No such sparse tree command \"%c\"" ans)))))
13134 (defvar org-occur-highlights nil
13135 "List of overlays used for occur matches.")
13136 (make-variable-buffer-local 'org-occur-highlights)
13137 (defvar org-occur-parameters nil
13138 "Parameters of the active org-occur calls.
13139 This is a list, each call to org-occur pushes as cons cell,
13140 containing the regular expression and the callback, onto the list.
13141 The list can contain several entries if `org-occur' has been called
13142 several time with the KEEP-PREVIOUS argument. Otherwise, this list
13143 will only contain one set of parameters. When the highlights are
13144 removed (for example with `C-c C-c', or with the next edit (depending
13145 on `org-remove-highlights-with-change'), this variable is emptied
13147 (make-variable-buffer-local 'org-occur-parameters)
13149 (defun org-occur (regexp &optional keep-previous callback)
13150 "Make a compact tree which shows all matches of REGEXP.
13151 The tree will show the lines where the regexp matches, and all higher
13152 headlines above the match. It will also show the heading after the match,
13153 to make sure editing the matching entry is easy.
13154 If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
13155 call to `org-occur' will be kept, to allow stacking of calls to this
13157 If CALLBACK is non-nil, it is a function which is called to confirm
13158 that the match should indeed be shown."
13159 (interactive "sRegexp: \nP")
13160 (when (equal regexp "")
13161 (error "Regexp cannot be empty"))
13162 (unless keep-previous
13163 (org-remove-occur-highlights nil nil t))
13164 (push (cons regexp callback) org-occur-parameters)
13167 (goto-char (point-min))
13168 (if (or (not keep-previous) ; do not want to keep
13169 (not org-occur-highlights)) ; no previous matches
13172 (while (re-search-forward regexp nil t)
13173 (when (or (not callback)
13174 (save-match-data (funcall callback)))
13175 (setq cnt (1+ cnt))
13176 (when org-highlight-sparse-tree-matches
13177 (org-highlight-new-match (match-beginning 0) (match-end 0)))
13178 (org-show-context 'occur-tree))))
13179 (when org-remove-highlights-with-change
13180 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
13182 (unless org-sparse-tree-open-archived-trees
13183 (org-hide-archived-subtrees (point-min) (point-max)))
13184 (run-hooks 'org-occur-hook)
13185 (if (org-called-interactively-p 'interactive)
13186 (message "%d match(es) for regexp %s" cnt regexp))
13189 (defun org-occur-next-match (&optional n reset)
13190 "Function for `next-error-function' to find sparse tree matches.
13191 N is the number of matches to move, when negative move backwards.
13192 RESET is entirely ignored - this function always goes back to the
13193 starting point when no match is found."
13194 (let* ((limit (if (< n 0) (point-min) (point-max)))
13195 (search-func (if (< n 0)
13196 'previous-single-char-property-change
13197 'next-single-char-property-change))
13202 (while (setq p1 (funcall search-func (point) 'org-type))
13203 (when (equal p1 limit)
13205 (error "No more matches"))
13206 (when (equal (get-char-property p1 'org-type) 'org-occur)
13210 (throw 'exit (point))))
13213 (error "No more matches"))))
13215 (defun org-show-context (&optional key)
13216 "Make sure point and context are visible.
13217 How much context is shown depends upon the variables
13218 `org-show-hierarchy-above', `org-show-following-heading',
13219 `org-show-entry-below' and `org-show-siblings'."
13220 (let ((heading-p (org-at-heading-p t))
13221 (hierarchy-p (org-get-alist-option org-show-hierarchy-above key))
13222 (following-p (org-get-alist-option org-show-following-heading key))
13223 (entry-p (org-get-alist-option org-show-entry-below key))
13224 (siblings-p (org-get-alist-option org-show-siblings key)))
13226 ;; Show heading or entry text
13227 (if (and heading-p (not entry-p))
13228 (org-flag-heading nil) ; only show the heading
13229 (and (or entry-p (outline-invisible-p) (org-invisible-p2))
13230 (org-show-hidden-entry))) ; show entire entry
13232 ;; Show next sibling, or heading below text
13234 (and (if heading-p (org-goto-sibling) (outline-next-heading))
13235 (org-flag-heading nil))))
13236 (when siblings-p (org-show-siblings))
13238 ;; show all higher headings, possibly with siblings
13240 (while (and (condition-case nil
13241 (progn (org-up-heading-all 1) t)
13244 (org-flag-heading nil)
13245 (when siblings-p (org-show-siblings))))))))
13247 (defvar org-reveal-start-hook nil
13248 "Hook run before revealing a location.")
13250 (defun org-reveal (&optional siblings)
13251 "Show current entry, hierarchy above it, and the following headline.
13252 This can be used to show a consistent set of context around locations
13253 exposed with `org-show-hierarchy-above' or `org-show-following-heading'
13254 not t for the search context.
13256 With optional argument SIBLINGS, on each level of the hierarchy all
13257 siblings are shown. This repairs the tree structure to what it would
13258 look like when opened with hierarchical calls to `org-cycle'.
13259 With double optional argument \\[universal-argument] \\[universal-argument], \
13260 go to the parent and show the
13263 (run-hooks 'org-reveal-start-hook)
13264 (let ((org-show-hierarchy-above t)
13265 (org-show-following-heading t)
13266 (org-show-siblings (if siblings t org-show-siblings)))
13267 (org-show-context nil))
13268 (when (equal siblings '(16))
13270 (when (org-up-heading-safe)
13272 (run-hook-with-args 'org-cycle-hook 'subtree)))))
13274 (defun org-highlight-new-match (beg end)
13275 "Highlight from BEG to END and mark the highlight is an occur headline."
13276 (let ((ov (make-overlay beg end)))
13277 (overlay-put ov 'face 'secondary-selection)
13278 (overlay-put ov 'org-type 'org-occur)
13279 (push ov org-occur-highlights)))
13281 (defun org-remove-occur-highlights (&optional beg end noremove)
13282 "Remove the occur highlights from the buffer.
13283 BEG and END are ignored. If NOREMOVE is nil, remove this function
13284 from the `before-change-functions' in the current buffer."
13286 (unless org-inhibit-highlight-removal
13287 (mapc 'delete-overlay org-occur-highlights)
13288 (setq org-occur-highlights nil)
13289 (setq org-occur-parameters nil)
13291 (remove-hook 'before-change-functions
13292 'org-remove-occur-highlights 'local))))
13296 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)"
13297 "Regular expression matching the priority indicator.")
13299 (defvar org-remove-priority-next-time nil)
13301 (defun org-priority-up ()
13302 "Increase the priority of the current item."
13304 (org-priority 'up))
13306 (defun org-priority-down ()
13307 "Decrease the priority of the current item."
13309 (org-priority 'down))
13311 (defun org-priority (&optional action show)
13312 "Change the priority of an item.
13313 ACTION can be `set', `up', `down', or a character."
13315 (if (equal action '(4))
13316 (org-show-priority)
13317 (unless org-enable-priority-commands
13318 (error "Priority commands are disabled"))
13319 (setq action (or action 'set))
13320 (let (current new news have remove)
13322 (org-back-to-heading t)
13323 (if (looking-at org-priority-regexp)
13324 (setq current (string-to-char (match-string 2))
13327 ((eq action 'remove)
13328 (setq remove t new ?\ ))
13329 ((or (eq action 'set)
13330 (if (featurep 'xemacs) (characterp action) (integerp action)))
13331 (if (not (eq action 'set))
13333 (message "Priority %c-%c, SPC to remove: "
13334 org-highest-priority org-lowest-priority)
13336 (setq new (read-char-exclusive))))
13337 (if (and (= (upcase org-highest-priority) org-highest-priority)
13338 (= (upcase org-lowest-priority) org-lowest-priority))
13339 (setq new (upcase new)))
13340 (cond ((equal new ?\ ) (setq remove t))
13341 ((or (< (upcase new) org-highest-priority) (> (upcase new) org-lowest-priority))
13342 (error "Priority must be between `%c' and `%c'"
13343 org-highest-priority org-lowest-priority))))
13346 (1- current) ; normal cycling
13347 ;; last priority was empty
13348 (if (eq last-command this-command)
13349 org-lowest-priority ; wrap around empty to lowest
13351 (if org-priority-start-cycle-with-default
13352 org-default-priority
13353 (1- org-default-priority))))))
13356 (1+ current) ; normal cycling
13357 ;; last priority was empty
13358 (if (eq last-command this-command)
13359 org-highest-priority ; wrap around empty to highest
13361 (if org-priority-start-cycle-with-default
13362 org-default-priority
13363 (1+ org-default-priority))))))
13364 (t (error "Invalid action")))
13365 (if (or (< (upcase new) org-highest-priority)
13366 (> (upcase new) org-lowest-priority))
13367 (if (and (memq action '(up down))
13368 (not have) (not (eq last-command this-command)))
13369 ;; `new' is from default priority
13371 "The default can not be set, see `org-default-priority' why")
13372 ;; normal cycling: `new' is beyond highest/lowest priority
13373 ;; and is wrapped around to the empty priority
13375 (setq news (format "%c" new))
13378 (replace-match "" t t nil 1)
13379 (replace-match news t t nil 2))
13381 (error "No priority cookie found in line")
13382 (let ((case-fold-search nil))
13383 (looking-at org-todo-line-regexp))
13386 (goto-char (match-end 2))
13387 (insert " [#" news "]"))
13388 (goto-char (match-beginning 3))
13389 (insert "[#" news "] "))))
13390 (org-preserve-lc (org-set-tags nil 'align)))
13392 (message "Priority removed")
13393 (message "Priority of current item set to %s" news)))))
13395 (defun org-show-priority ()
13396 "Show the priority of the current item.
13397 This priority is composed of the main priority given with the [#A] cookies,
13398 and by additional input from the age of a schedules or deadline entry."
13400 (let ((pri (if (eq major-mode 'org-agenda-mode)
13401 (org-get-at-bol 'priority)
13404 (beginning-of-line)
13405 (and (looking-at org-heading-regexp)
13406 (org-get-priority (match-string 0))))))))
13407 (message "Priority is %d" (if pri pri -1000))))
13409 (defun org-get-priority (s)
13410 "Find priority cookie and return priority."
13412 (if (functionp org-get-priority-function)
13413 (funcall org-get-priority-function)
13414 (if (not (string-match org-priority-regexp s))
13415 (* 1000 (- org-lowest-priority org-default-priority))
13416 (* 1000 (- org-lowest-priority
13417 (string-to-char (match-string 2 s))))))))
13421 (defvar org-agenda-archives-mode)
13422 (defvar org-map-continue-from nil
13423 "Position from where mapping should continue.
13424 Can be set by the action argument to `org-scan-tags' and `org-map-entries'.")
13426 (defvar org-scanner-tags nil
13427 "The current tag list while the tags scanner is running.")
13428 (defvar org-trust-scanner-tags nil
13429 "Should `org-get-tags-at' use the tags for the scanner.
13430 This is for internal dynamical scoping only.
13431 When this is non-nil, the function `org-get-tags-at' will return the value
13432 of `org-scanner-tags' instead of building the list by itself. This
13433 can lead to large speed-ups when the tags scanner is used in a file with
13434 many entries, and when the list of tags is retrieved, for example to
13435 obtain a list of properties. Building the tags list for each entry in such
13436 a file becomes an N^2 operation - but with this variable set, it scales
13439 (defun org-scan-tags (action matcher todo-only &optional start-level)
13440 "Scan headline tags with inheritance and produce output ACTION.
13442 ACTION can be `sparse-tree' to produce a sparse tree in the current buffer,
13443 or `agenda' to produce an entry list for an agenda view. It can also be
13444 a Lisp form or a function that should be called at each matched headline, in
13445 this case the return value is a list of all return values from these calls.
13447 MATCHER is a Lisp form to be evaluated, testing if a given set of tags
13448 qualifies a headline for inclusion. When TODO-ONLY is non-nil,
13449 only lines with a not-done TODO keyword are included in the output.
13450 This should be the same variable that was scoped into
13451 and set by `org-make-tags-matcher' when it constructed MATCHER.
13453 START-LEVEL can be a string with asterisks, reducing the scope to
13454 headlines matching this string."
13455 (require 'org-agenda)
13456 (let* ((re (concat "^"
13458 ;; Get the correct level to match
13459 (concat "\\*\\{" (number-to-string start-level) "\\} ")
13460 org-outline-regexp)
13462 (mapconcat 'regexp-quote org-todo-keywords-1 "\\|")
13463 (org-re "\\)\\>\\)? *\\(.*?\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*$")))
13464 (props (list 'face 'default
13465 'done-face 'org-agenda-done
13466 'undone-face 'default
13467 'mouse-face 'highlight
13468 'org-not-done-regexp org-not-done-regexp
13469 'org-todo-regexp org-todo-regexp
13470 'org-complex-heading-regexp org-complex-heading-regexp
13472 (format "mouse-2 or RET jump to org file %s"
13473 (abbreviate-file-name
13474 (or (buffer-file-name (buffer-base-buffer))
13475 (buffer-name (buffer-base-buffer)))))))
13476 (case-fold-search nil)
13477 (org-map-continue-from nil)
13478 lspos tags tags-list
13479 (tags-alist (list (cons 0 org-file-tags)))
13480 (llast 0) rtn rtn1 level category i txt
13481 todo marker entry priority)
13482 (when (not (or (member action '(agenda sparse-tree)) (functionp action)))
13483 (setq action (list 'lambda nil action)))
13485 (goto-char (point-min))
13486 (when (eq action 'sparse-tree)
13488 (org-remove-occur-highlights))
13489 (while (re-search-forward re nil t)
13490 (setq org-map-continue-from nil)
13492 (setq todo (if (match-end 1) (org-match-string-no-properties 2))
13493 tags (if (match-end 4) (org-match-string-no-properties 4)))
13494 (goto-char (setq lspos (match-beginning 0)))
13495 (setq level (org-reduced-level (org-outline-level))
13496 category (org-get-category))
13497 (setq i llast llast level)
13498 ;; remove tag lists from same and sublevels
13499 (while (>= i level)
13500 (when (setq entry (assoc i tags-alist))
13501 (setq tags-alist (delete entry tags-alist)))
13503 ;; add the next tags
13505 (setq tags (org-split-string tags ":")
13507 (cons (cons level tags) tags-alist)))
13508 ;; compile tags for current headline
13510 (if org-use-tag-inheritance
13511 (apply 'append (mapcar 'cdr (reverse tags-alist)))
13513 org-scanner-tags tags-list)
13514 (when org-use-tag-inheritance
13515 (setcdr (car tags-alist)
13516 (mapcar (lambda (x)
13517 (setq x (copy-sequence x))
13518 (org-add-prop-inherited x))
13519 (cdar tags-alist))))
13520 (when (and tags org-use-tag-inheritance
13521 (or (not (eq t org-use-tag-inheritance))
13522 org-tags-exclude-from-inheritance))
13523 ;; selective inheritance, remove uninherited ones
13524 (setcdr (car tags-alist)
13525 (org-remove-uninherited-tags (cdar tags-alist))))
13528 ;; eval matcher only when the todo condition is OK
13529 (and (or (not todo-only) (member todo org-not-done-keywords))
13530 (let ((case-fold-search t) (org-trust-scanner-tags t))
13533 ;; Call the skipper, but return t if it does not skip,
13534 ;; so that the `and' form continues evaluating
13536 (unless (eq action 'sparse-tree) (org-agenda-skip))
13539 ;; Check if timestamps are deselecting this entry
13540 (or (not todo-only)
13541 (and (member todo org-not-done-keywords)
13542 (or (not org-agenda-tags-todo-honor-ignore-options)
13543 (not (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item))))))
13545 ;; select this headline
13547 ((eq action 'sparse-tree)
13548 (and org-highlight-sparse-tree-matches
13549 (org-get-heading) (match-end 0)
13550 (org-highlight-new-match
13551 (match-beginning 1) (match-end 1)))
13552 (org-show-context 'tags-tree))
13553 ((eq action 'agenda)
13554 (setq txt (org-agenda-format-item
13557 (if (eq org-tags-match-list-sublevels 'indented)
13558 (make-string (1- level) ?.) "")
13562 priority (org-get-priority txt))
13564 (setq marker (org-agenda-new-marker))
13565 (org-add-props txt props
13566 'org-marker marker 'org-hd-marker marker 'org-category category
13568 'priority priority 'type "tagsmatch")
13570 ((functionp action)
13571 (setq org-map-continue-from nil)
13573 (setq rtn1 (funcall action))
13575 (t (error "Invalid action")))
13577 ;; if we are to skip sublevels, jump to end of subtree
13578 (unless org-tags-match-list-sublevels
13579 (org-end-of-subtree t)
13580 (backward-char 1))))
13581 ;; Get the correct position from where to continue
13582 (if org-map-continue-from
13583 (goto-char org-map-continue-from)
13584 (and (= (point) lspos) (end-of-line 1)))))
13585 (when (and (eq action 'sparse-tree)
13586 (not org-sparse-tree-open-archived-trees))
13587 (org-hide-archived-subtrees (point-min) (point-max)))
13590 (defun org-remove-uninherited-tags (tags)
13591 "Remove all tags that are not inherited from the list TAGS."
13593 ((eq org-use-tag-inheritance t)
13594 (if org-tags-exclude-from-inheritance
13595 (org-delete-all org-tags-exclude-from-inheritance tags)
13597 ((not org-use-tag-inheritance) nil)
13598 ((stringp org-use-tag-inheritance)
13601 (if (and (string-match org-use-tag-inheritance x)
13602 (not (member x org-tags-exclude-from-inheritance)))
13605 ((listp org-use-tag-inheritance)
13608 (if (member x org-use-tag-inheritance) x nil))
13611 (defun org-match-sparse-tree (&optional todo-only match)
13612 "Create a sparse tree according to tags string MATCH.
13613 MATCH can contain positive and negative selection of tags, like
13614 \"+WORK+URGENT-WITHBOSS\".
13615 If optional argument TODO-ONLY is non-nil, only select lines that are
13618 (org-agenda-prepare-buffers (list (current-buffer)))
13619 (org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match)) todo-only))
13621 (defalias 'org-tags-sparse-tree 'org-match-sparse-tree)
13623 (defvar org-cached-props nil)
13624 (defun org-cached-entry-get (pom property)
13625 (if (or (eq t org-use-property-inheritance)
13626 (and (stringp org-use-property-inheritance)
13627 (string-match org-use-property-inheritance property))
13628 (and (listp org-use-property-inheritance)
13629 (member property org-use-property-inheritance)))
13630 ;; Caching is not possible, check it directly
13631 (org-entry-get pom property 'inherit)
13632 ;; Get all properties, so that we can do complicated checks easily
13633 (cdr (assoc property (or org-cached-props
13634 (setq org-cached-props
13635 (org-entry-properties pom)))))))
13637 (defun org-global-tags-completion-table (&optional files)
13638 "Return the list of all tags in all agenda buffer/files.
13639 Optional FILES argument is a list of files which can be used
13640 instead of the agenda files."
13647 (set-buffer (find-file-noselect file))
13648 (append (org-get-buffer-tags)
13649 (mapcar (lambda (x) (if (stringp (car-safe x))
13650 (list (car-safe x)) nil))
13652 (if (and files (car files))
13654 (org-agenda-files))))))))
13656 (defun org-make-tags-matcher (match)
13657 "Create the TAGS/TODO matcher form for the selection string MATCH.
13659 The variable `todo-only' is scoped dynamically into this function.
13660 It will be set to t if the matcher restricts matching to TODO entries,
13661 otherwise will not be touched.
13663 Returns a cons of the selection string MATCH and the constructed
13664 lisp form implementing the matcher. The matcher is to be evaluated
13665 at an Org entry, with point on the headline, and returns t if the
13666 entry matches the selection string MATCH. The returned lisp form
13667 references two variables with information about the entry, which
13668 must be bound around the form's evaluation: todo, the TODO keyword
13669 at the entry (or nil of none); and tags-list, the list of all tags
13670 at the entry including inherited ones. Additionally, the category
13671 of the entry (if any) must be specified as the text property
13672 'org-category on the headline.
13674 See also `org-scan-tags'.
13676 (declare (special todo-only))
13677 (unless (boundp 'todo-only)
13678 (error "org-make-tags-matcher expects todo-only to be scoped in"))
13680 ;; Get a new match request, with completion
13681 (let ((org-last-tags-completion-table
13682 (org-global-tags-completion-table)))
13683 (setq match (org-completing-read-no-i
13684 "Match: " 'org-tags-completion-function nil nil nil
13685 'org-tags-history))))
13687 ;; Parse the string and create a lisp form
13688 (let ((match0 match)
13689 (re (org-re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@#%]+\\)"))
13691 tagsmatch todomatch tagsmatcher todomatcher kwd matcher
13692 orterms term orlist re-p str-p level-p level-op time-p
13693 prop-p pn pv po gv rest)
13694 (if (string-match "/+" match)
13695 ;; match contains also a todo-matching request
13697 (setq tagsmatch (substring match 0 (match-beginning 0))
13698 todomatch (substring match (match-end 0)))
13699 (if (string-match "^!" todomatch)
13700 (setq todo-only t todomatch (substring todomatch 1)))
13701 (if (string-match "^\\s-*$" todomatch)
13702 (setq todomatch nil)))
13703 ;; only matching tags
13704 (setq tagsmatch match todomatch nil))
13706 ;; Make the tags matcher
13707 (if (or (not tagsmatch) (not (string-match "\\S-" tagsmatch)))
13708 (setq tagsmatcher t)
13709 (setq orterms (org-split-string tagsmatch "|") orlist nil)
13710 (while (setq term (pop orterms))
13711 (while (and (equal (substring term -1) "\\") orterms)
13712 (setq term (concat term "|" (pop orterms)))) ; repair bad split
13713 (while (string-match re term)
13714 (setq rest (substring term (match-end 0))
13715 minus (and (match-end 1)
13716 (equal (match-string 1 term) "-"))
13717 tag (save-match-data (replace-regexp-in-string
13719 (match-string 2 term)))
13720 re-p (equal (string-to-char tag) ?{)
13721 level-p (match-end 4)
13722 prop-p (match-end 5)
13724 (re-p `(org-match-any-p ,(substring tag 1 -1) tags-list))
13726 (setq level-op (org-op-to-function (match-string 3 term)))
13727 `(,level-op level ,(string-to-number
13728 (match-string 4 term))))
13730 (setq pn (match-string 5 term)
13731 po (match-string 6 term)
13732 pv (match-string 7 term)
13733 re-p (equal (string-to-char pv) ?{)
13734 str-p (equal (string-to-char pv) ?\")
13735 time-p (save-match-data
13736 (string-match "^\"[[<].*[]>]\"$" pv))
13737 pv (if (or re-p str-p) (substring pv 1 -1) pv))
13738 (if time-p (setq pv (org-matcher-time pv)))
13739 (setq po (org-op-to-function po (if time-p 'time str-p)))
13741 ((equal pn "CATEGORY")
13742 (setq gv '(get-text-property (point) 'org-category)))
13746 (setq gv `(org-cached-entry-get nil ,pn))))
13749 `(not (string-match ,pv (or ,gv "")))
13750 `(string-match ,pv (or ,gv "")))
13752 `(,po (or ,gv "") ,pv)
13753 `(,po (string-to-number (or ,gv ""))
13754 ,(string-to-number pv) ))))
13755 (t `(member ,tag tags-list)))
13756 mm (if minus (list 'not mm) mm)
13758 (push mm tagsmatcher))
13759 (push (if (> (length tagsmatcher) 1)
13760 (cons 'and tagsmatcher)
13763 (setq tagsmatcher nil))
13764 (setq tagsmatcher (if (> (length orlist) 1) (cons 'or orlist) (car orlist)))
13766 (list 'progn '(setq org-cached-props nil) tagsmatcher)))
13767 ;; Make the todo matcher
13768 (if (or (not todomatch) (not (string-match "\\S-" todomatch)))
13769 (setq todomatcher t)
13770 (setq orterms (org-split-string todomatch "|") orlist nil)
13771 (while (setq term (pop orterms))
13772 (while (string-match re term)
13773 (setq minus (and (match-end 1)
13774 (equal (match-string 1 term) "-"))
13775 kwd (match-string 2 term)
13776 re-p (equal (string-to-char kwd) ?{)
13777 term (substring term (match-end 0))
13779 `(string-match ,(substring kwd 1 -1) todo)
13780 (list 'equal 'todo kwd))
13781 mm (if minus (list 'not mm) mm))
13782 (push mm todomatcher))
13783 (push (if (> (length todomatcher) 1)
13784 (cons 'and todomatcher)
13787 (setq todomatcher nil))
13788 (setq todomatcher (if (> (length orlist) 1)
13789 (cons 'or orlist) (car orlist))))
13791 ;; Return the string and lisp forms of the matcher
13792 (setq matcher (if todomatcher
13793 (list 'and tagsmatcher todomatcher)
13796 (setq matcher (list 'and '(member todo org-not-done-keywords)
13798 (cons match0 matcher)))
13800 (defun org-op-to-function (op &optional stringp)
13801 "Turn an operator into the appropriate function."
13804 ((equal op "<" ) '(< string< org-time<))
13805 ((equal op ">" ) '(> org-string> org-time>))
13806 ((member op '("<=" "=<")) '(<= org-string<= org-time<=))
13807 ((member op '(">=" "=>")) '(>= org-string>= org-time>=))
13808 ((member op '("=" "==")) '(= string= org-time=))
13809 ((member op '("<>" "!=")) '(org<> org-string<> org-time<>))))
13810 (nth (if (eq stringp 'time) 2 (if stringp 1 0)) op))
13812 (defun org<> (a b) (not (= a b)))
13813 (defun org-string<= (a b) (or (string= a b) (string< a b)))
13814 (defun org-string>= (a b) (not (string< a b)))
13815 (defun org-string> (a b) (and (not (string= a b)) (not (string< a b))))
13816 (defun org-string<> (a b) (not (string= a b)))
13817 (defun org-time= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (= a b)))
13818 (defun org-time< (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (< a b)))
13819 (defun org-time<= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (<= a b)))
13820 (defun org-time> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (> a b)))
13821 (defun org-time>= (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (>= a b)))
13822 (defun org-time<> (a b) (setq a (org-2ft a) b (org-2ft b)) (and (> a 0) (> b 0) (org<> a b)))
13824 "Convert S to a floating point time.
13825 If S is already a number, just return it. If it is a string, parse
13826 it as a time string and apply `float-time' to it. If S is nil, just return 0."
13830 (condition-case nil
13831 (float-time (apply 'encode-time (org-parse-time-string s)))
13835 (defun org-time-today ()
13836 "Time in seconds today at 0:00.
13837 Returns the float number of seconds since the beginning of the
13838 epoch to the beginning of today (00:00)."
13839 (float-time (apply 'encode-time
13840 (append '(0 0 0) (nthcdr 3 (decode-time))))))
13842 (defun org-matcher-time (s)
13843 "Interpret a time comparison value."
13846 ((string= s "<now>") (float-time))
13847 ((string= s "<today>") (org-time-today))
13848 ((string= s "<tomorrow>") (+ 86400.0 (org-time-today)))
13849 ((string= s "<yesterday>") (- (org-time-today) 86400.0))
13850 ((string-match "^<\\([-+][0-9]+\\)\\([hdwmy]\\)>$" s)
13851 (+ (org-time-today)
13852 (* (string-to-number (match-string 1 s))
13853 (cdr (assoc (match-string 2 s)
13854 '(("d" . 86400.0) ("w" . 604800.0)
13855 ("m" . 2678400.0) ("y" . 31557600.0)))))))
13858 (defun org-match-any-p (re list)
13859 "Does re match any element of list?"
13860 (setq list (mapcar (lambda (x) (string-match re x)) list))
13863 (defvar org-add-colon-after-tag-completion nil) ;; dynamically scoped param
13864 (defvar org-tags-overlay (make-overlay 1 1))
13865 (org-detach-overlay org-tags-overlay)
13867 (defun org-get-local-tags-at (&optional pos)
13868 "Get a list of tags defined in the current headline."
13869 (org-get-tags-at pos 'local))
13871 (defun org-get-local-tags ()
13872 "Get a list of tags defined in the current headline."
13873 (org-get-tags-at nil 'local))
13875 (defun org-get-tags-at (&optional pos local)
13876 "Get a list of all headline tags applicable at POS.
13877 POS defaults to point. If tags are inherited, the list contains
13878 the targets in the same sequence as the headlines appear, i.e.
13879 the tags of the current headline come last.
13880 When LOCAL is non-nil, only return tags from the current headline,
13881 ignore inherited ones."
13883 (if (and org-trust-scanner-tags
13884 (or (not pos) (equal pos (point)))
13887 (let (tags ltags lastpos parent)
13891 (goto-char (or pos (point)))
13894 (condition-case nil
13896 (org-back-to-heading t)
13897 (while (not (equal lastpos (point)))
13898 (setq lastpos (point))
13900 (org-re "[^\r\n]+?:\\([[:alnum:]_@#%:]+\\):[ \t]*$"))
13901 (setq ltags (org-split-string
13902 (org-match-string-no-properties 1) ":"))
13904 (setq ltags (mapcar 'org-add-prop-inherited ltags)))
13907 (org-remove-uninherited-tags ltags)
13910 (or org-use-tag-inheritance (throw 'done t))
13911 (if local (throw 'done t))
13912 (or (org-up-heading-safe) (error nil))
13917 (reverse (delete-dups
13919 (org-remove-uninherited-tags
13920 org-file-tags) tags)))))))))
13922 (defun org-add-prop-inherited (s)
13923 (add-text-properties 0 (length s) '(inherited t) s)
13926 (defun org-toggle-tag (tag &optional onoff)
13927 "Toggle the tag TAG for the current line.
13928 If ONOFF is `on' or `off', don't toggle but set to this state."
13931 (org-back-to-heading t)
13932 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t]*$")
13935 (setq current (match-string 1))
13936 (replace-match ""))
13938 (setq current (nreverse (org-split-string current ":")))
13942 (or (member tag current) (push tag current)))
13944 (or (not (member tag current)) (setq current (delete tag current))))
13945 (t (if (member tag current)
13946 (setq current (delete tag current))
13948 (push tag current))))
13952 (insert " :" (mapconcat 'identity (nreverse current) ":") ":")
13953 (org-set-tags nil t))
13954 (delete-horizontal-space))
13955 (run-hooks 'org-after-tags-change-hook))
13958 (defun org-align-tags-here (to-col)
13959 ;; Assumes that this is a headline
13960 (let ((pos (point)) (col (current-column)) ncol tags-l p)
13961 (beginning-of-line 1)
13962 (if (and (looking-at (org-re ".*?\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
13963 (< pos (match-beginning 2)))
13965 (setq tags-l (- (match-end 2) (match-beginning 2)))
13966 (goto-char (match-beginning 1))
13968 (delete-region (point) (1+ (match-beginning 2)))
13969 (setq ncol (max (current-column)
13973 (- (abs to-col) tags-l))))
13975 (insert (make-string (- ncol (current-column)) ?\ ))
13976 (setq ncol (current-column))
13977 (when indent-tabs-mode (tabify p (point-at-eol)))
13978 (org-move-to-column (min ncol col) t))
13981 (defun org-set-tags-command (&optional arg just-align)
13982 "Call the set-tags command for the current entry."
13984 (if (or (org-at-heading-p) (and arg (org-before-first-heading-p)))
13985 (org-set-tags arg just-align)
13987 (unless (and (org-region-active-p)
13988 org-loop-over-headlines-in-active-region)
13989 (org-back-to-heading t))
13990 (org-set-tags arg just-align))))
13992 (defun org-set-tags-to (data)
13993 "Set the tags of the current entry to DATA, replacing the current tags.
13994 DATA may be a tags string like :aa:bb:cc:, or a list of tags.
13995 If DATA is nil or the empty string, any tags will be removed."
13996 (interactive "sTags: ")
14000 ((equal data "") "")
14002 (concat ":" (mapconcat 'identity (org-split-string data ":+") ":")
14005 (concat ":" (mapconcat 'identity data ":") ":"))))
14008 (org-back-to-heading t)
14009 (when (looking-at org-complex-heading-regexp)
14012 (goto-char (match-beginning 5))
14014 (delete-region (point) (point-at-eol))
14015 (org-set-tags nil 'align))
14016 (goto-char (point-at-eol))
14018 (org-set-tags nil 'align)))
14019 (beginning-of-line 1)
14020 (if (looking-at ".*?\\([ \t]+\\)$")
14021 (delete-region (match-beginning 1) (match-end 1))))))
14023 (defun org-align-all-tags ()
14024 "Align the tags i all headings."
14027 (or (ignore-errors (org-back-to-heading t))
14028 (outline-next-heading))
14029 (if (org-at-heading-p)
14031 (message "No headings"))))
14033 (defvar org-indent-indentation-per-level)
14034 (defun org-set-tags (&optional arg just-align)
14035 "Set the tags for the current headline.
14036 With prefix ARG, realign all tags in headings in the current buffer."
14038 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
14039 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
14040 'region-start-level 'region))
14041 org-loop-over-headlines-in-active-region)
14043 ;; We don't use ARG and JUST-ALIGN here these args are not
14044 ;; useful when looping over headlines
14046 org-loop-over-headlines-in-active-region
14047 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
14048 (let* ((re org-outline-regexp-bol)
14049 (current (unless arg (org-get-tags-string)))
14050 (col (current-column))
14051 (org-setting-tags t)
14052 table current-tags inherited-tags ; computed below when needed
14053 tags p0 c0 c1 rpl di tc level)
14056 (goto-char (point-min))
14057 (let ((buffer-invisibility-spec (org-inhibit-invisibility)))
14058 (while (re-search-forward re nil t)
14059 (org-set-tags nil t)
14061 (message "All tags realigned to column %d" org-tags-column))
14063 (setq tags current)
14064 ;; Get a new set of tags from the user
14066 (setq table (append org-tag-persistent-alist
14067 (or org-tag-alist (org-get-buffer-tags))
14069 org-complete-tags-always-offer-all-agenda-tags
14070 (org-global-tags-completion-table
14071 (org-agenda-files))))
14072 org-last-tags-completion-table table
14073 current-tags (org-split-string current ":")
14074 inherited-tags (nreverse
14075 (nthcdr (length current-tags)
14076 (nreverse (org-get-tags-at))))
14078 (if (or (eq t org-use-fast-tag-selection)
14079 (and org-use-fast-tag-selection
14080 (delq nil (mapcar 'cdr table))))
14081 (org-fast-tag-selection
14082 current-tags inherited-tags table
14083 (if org-fast-tag-selection-include-todo
14084 org-todo-key-alist))
14085 (let ((org-add-colon-after-tag-completion (< 1 (length table))))
14087 (org-icompleting-read "Tags: "
14088 'org-tags-completion-function
14089 nil nil current 'org-tags-history))))))
14090 (while (string-match "[-+&]+" tags)
14091 ;; No boolean logic, just a list
14092 (setq tags (replace-match ":" t t tags))))
14094 (setq tags (replace-regexp-in-string "[,]" ":" tags))
14096 (if org-tags-sort-function
14097 (setq tags (mapconcat 'identity
14098 (sort (org-split-string
14099 tags (org-re "[^[:alnum:]_@#%]+"))
14100 org-tags-sort-function) ":")))
14102 (if (string-match "\\`[\t ]*\\'" tags)
14104 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
14105 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
14107 ;; Insert new tags at the correct column
14108 (beginning-of-line 1)
14109 (setq level (or (and (looking-at org-outline-regexp)
14110 (- (match-end 0) (point) 1))
14113 ((and (equal current "") (equal tags "")))
14114 ((re-search-forward
14115 (concat "\\([ \t]*" (regexp-quote current) "\\)[ \t]*$")
14117 (if (equal tags "")
14119 (goto-char (match-beginning 0))
14120 (setq c0 (current-column)
14121 ;; compute offset for the case of org-indent-mode active
14122 di (if org-indent-mode
14123 (* (1- org-indent-indentation-per-level) (1- level))
14125 p0 (if (equal (char-before) ?*) (1+ (point)) (point))
14126 tc (+ org-tags-column (if (> org-tags-column 0) (- di) di))
14127 c1 (max (1+ c0) (if (> tc 0) tc (- (- tc) (length tags))))
14128 rpl (concat (make-string (max 0 (- c1 c0)) ?\ ) tags)))
14129 (replace-match rpl t t)
14130 (and (not (featurep 'xemacs)) c0 indent-tabs-mode (tabify p0 (point)))
14132 (t (error "Tags alignment failed")))
14133 (org-move-to-column col)
14135 (run-hooks 'org-after-tags-change-hook))))))
14137 (defun org-change-tag-in-region (beg end tag off)
14138 "Add or remove TAG for each entry in the region.
14139 This works in the agenda, and also in an org-mode buffer."
14141 (list (region-beginning) (region-end)
14142 (let ((org-last-tags-completion-table
14143 (if (derived-mode-p 'org-mode)
14144 (org-get-buffer-tags)
14145 (org-global-tags-completion-table))))
14146 (org-icompleting-read
14147 "Tag: " 'org-tags-completion-function nil nil nil
14148 'org-tags-history))
14150 (message "[s]et or
[r]emove? ")
14151 (equal (read-char-exclusive) ?r))))
14152 (if (fboundp 'deactivate-mark) (deactivate-mark))
14153 (let ((agendap (equal major-mode 'org-agenda-mode))
14154 l1 l2 m buf pos newhead (cnt 0))
14156 (setq l2 (1- (org-current-line)))
14158 (setq l1 (org-current-line))
14159 (loop for l from l1 to l2 do
14161 (setq m (get-text-property (point) 'org-hd-marker))
14162 (when (or (and (derived-mode-p 'org-mode) (org-at-heading-p))
14164 (setq buf (if agendap (marker-buffer m) (current-buffer))
14165 pos (if agendap m (point)))
14166 (with-current-buffer buf
14170 (setq cnt (1+ cnt))
14171 (org-toggle-tag tag (if off 'off 'on))
14172 (setq newhead (org-get-heading)))))
14173 (and agendap (org-agenda-change-all-lines newhead m))))
14174 (message "Tag :%s: %s in %d headings" tag (if off "removed" "set") cnt)))
14176 (defun org-tags-completion-function (string predicate &optional flag)
14177 (let (s1 s2 rtn (ctable org-last-tags-completion-table)
14178 (confirm (lambda (x) (stringp (car x)))))
14179 (if (string-match "^\\(.*[-+:&,|]\\)\\([^-+:&,|]*\\)$" string)
14180 (setq s1 (match-string 1 string)
14181 s2 (match-string 2 string))
14182 (setq s1 "" s2 string))
14186 (setq rtn (try-completion s2 ctable confirm))
14189 (concat s1 s2 (substring rtn (length s2))
14190 (if (and org-add-colon-after-tag-completion
14191 (assoc rtn ctable))
14196 (all-completions s2 ctable confirm)
14200 (assoc s2 ctable)))
14203 (defun org-fast-tag-insert (kwd tags face &optional end)
14204 "Insert KDW, and the TAGS, the latter with face FACE. Also insert END."
14205 (insert (format "%-12s" (concat kwd ":"))
14206 (org-add-props (mapconcat 'identity tags " ") nil 'face face)
14209 (defun org-fast-tag-show-exit (flag)
14212 (if (re-search-forward "[ \t]+Next change exits" (point-at-eol) t)
14213 (replace-match ""))
14216 (org-move-to-column (- (window-width) 19) t)
14217 (insert (org-add-props " Next change exits" nil 'face 'org-warning)))))
14219 (defun org-set-current-tags-overlay (current prefix)
14220 (let ((s (concat ":" (mapconcat 'identity current ":") ":")))
14221 (if (featurep 'xemacs)
14222 (org-overlay-display org-tags-overlay (concat prefix s)
14223 'secondary-selection)
14224 (put-text-property 0 (length s) 'face '(secondary-selection org-tag) s)
14225 (org-overlay-display org-tags-overlay (concat prefix s)))))
14227 (defvar org-last-tag-selection-key nil)
14228 (defun org-fast-tag-selection (current inherited table &optional todo-table)
14229 "Fast tag selection with single keys.
14230 CURRENT is the current list of tags in the headline, INHERITED is the
14231 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
14232 possibly with grouping information. TODO-TABLE is a similar table with
14233 TODO keywords, should these have keys assigned to them.
14234 If the keys are nil, a-z are automatically assigned.
14235 Returns the new tags string, or nil to not change the current settings."
14236 (let* ((fulltable (append table todo-table))
14237 (maxlen (apply 'max (mapcar
14239 (if (stringp (car x)) (string-width (car x)) 0))
14241 (buf (current-buffer))
14242 (expert (eq org-fast-tag-selection-single-key 'expert))
14244 (fwidth (+ maxlen 3 1 3))
14245 (ncol (/ (- (window-width) 4) fwidth))
14248 tg cnt e c char c1 c2 ntable tbl rtn
14249 ov-start ov-end ov-prefix
14250 (exit-after-next org-fast-tag-selection-single-key)
14251 (done-keywords org-done-keywords)
14254 (beginning-of-line 1)
14256 (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
14257 (setq ov-start (match-beginning 1)
14258 ov-end (match-end 1)
14260 (setq ov-start (1- (point-at-eol))
14261 ov-end (1+ ov-start))
14262 (skip-chars-forward "^\n\r")
14265 (buffer-substring (1- (point)) (point))
14266 (if (> (current-column) org-tags-column)
14268 (make-string (- org-tags-column (current-column)) ?\ ))))))
14269 (move-overlay org-tags-overlay ov-start ov-end)
14270 (save-window-excursion
14272 (set-buffer (get-buffer-create " *Org tags*"))
14273 (delete-other-windows)
14274 (split-window-vertically)
14275 (org-switch-to-buffer-other-window (get-buffer-create " *Org tags*")))
14277 (org-set-local 'org-done-keywords done-keywords)
14278 (org-fast-tag-insert "Inherited" inherited i-face "\n")
14279 (org-fast-tag-insert "Current" current c-face "\n\n")
14280 (org-fast-tag-show-exit exit-after-next)
14281 (org-set-current-tags-overlay current ov-prefix)
14282 (setq tbl fulltable char ?a cnt 0)
14283 (while (setq e (pop tbl))
14285 ((equal (car e) :startgroup)
14286 (push '() groups) (setq ingroup t)
14287 (when (not (= cnt 0))
14290 (insert (if (cdr e) (format "%s: " (cdr e)) "") "{ "))
14291 ((equal (car e) :endgroup)
14292 (setq ingroup nil cnt 0)
14293 (insert "}" (if (cdr e) (format " (%s) " (cdr e)) "") "\n"))
14294 ((equal e '(:newline))
14295 (when (not (= cnt 0))
14299 (while (equal (car tbl) '(:newline))
14301 (setq tbl (cdr tbl)))))
14303 (setq tg (copy-sequence (car e)) c2 nil)
14306 ;; automatically assign a character.
14307 (setq c1 (string-to-char
14308 (downcase (substring
14309 tg (if (= (string-to-char tg) ?@) 1 0)))))
14310 (if (or (rassoc c1 ntable) (rassoc c1 table))
14311 (while (or (rassoc char ntable) (rassoc char table))
14312 (setq char (1+ char)))
14314 (setq c (or c2 char)))
14315 (if ingroup (push tg (car groups)))
14316 (setq tg (org-add-props tg nil 'face
14318 ((not (assoc tg table))
14319 (org-get-todo-face tg))
14320 ((member tg current) c-face)
14321 ((member tg inherited) i-face))))
14322 (if (and (= cnt 0) (not ingroup)) (insert " "))
14323 (insert "[" c "] " tg (make-string
14324 (- fwidth 4 (length tg)) ?\ ))
14325 (push (cons tg c) ntable)
14326 (when (= (setq cnt (1+ cnt)) ncol)
14328 (if ingroup (insert " "))
14330 (setq ntable (nreverse ntable))
14332 (goto-char (point-min))
14333 (if (not expert) (org-fit-window-to-buffer))
14337 (message "[a-z..]:Toggle [SPC]:clear [RET]:accept [TAB]:free [!] %sgroups%s"
14338 (if (not groups) "no " "")
14339 (if expert " [C-c]:window" (if exit-after-next " [C-c]:single" " [C-c]:multi")))
14340 (setq c (let ((inhibit-quit t)) (read-char-exclusive)))
14341 (setq org-last-tag-selection-key c)
14343 ((= c ?\r) (throw 'exit t))
14345 (setq groups (not groups))
14346 (goto-char (point-min))
14347 (while (re-search-forward "[{}]" nil t) (replace-match " ")))
14350 (org-fast-tag-show-exit
14351 (setq exit-after-next (not exit-after-next)))
14353 (delete-other-windows)
14354 (set-window-buffer (split-window-vertically) " *Org tags*")
14355 (org-switch-to-buffer-other-window " *Org tags*")
14356 (org-fit-window-to-buffer)))
14358 (and (= c ?q) (not (rassoc c ntable))))
14359 (org-detach-overlay org-tags-overlay)
14360 (setq quit-flag t))
14363 (if exit-after-next (setq exit-after-next 'now)))
14365 (condition-case nil
14366 (setq tg (org-icompleting-read
14369 (with-current-buffer buf
14370 (org-get-buffer-tags)))))
14371 (quit (setq tg "")))
14372 (when (string-match "\\S-" tg)
14373 (add-to-list 'buffer-tags (list tg))
14374 (if (member tg current)
14375 (setq current (delete tg current))
14376 (push tg current)))
14377 (if exit-after-next (setq exit-after-next 'now)))
14378 ((setq e (rassoc c todo-table) tg (car e))
14379 (with-current-buffer buf
14380 (save-excursion (org-todo tg)))
14381 (if exit-after-next (setq exit-after-next 'now)))
14382 ((setq e (rassoc c ntable) tg (car e))
14383 (if (member tg current)
14384 (setq current (delete tg current))
14385 (loop for g in groups do
14388 (setq current (delete x current)))
14391 (if exit-after-next (setq exit-after-next 'now))))
14393 ;; Create a sorted list
14397 (assoc b (cdr (memq (assoc a ntable) ntable))))))
14398 (if (eq exit-after-next 'now) (throw 'exit t))
14399 (goto-char (point-min))
14400 (beginning-of-line 2)
14401 (delete-region (point) (point-at-eol))
14402 (org-fast-tag-insert "Current" current c-face)
14403 (org-set-current-tags-overlay current ov-prefix)
14404 (while (re-search-forward
14405 (org-re "\\[.\\] \\([[:alnum:]_@#%]+\\)") nil t)
14406 (setq tg (match-string 1))
14407 (add-text-properties
14408 (match-beginning 1) (match-end 1)
14411 ((member tg current) c-face)
14412 ((member tg inherited) i-face)
14413 (t (get-text-property (match-beginning 1) 'face))))))
14414 (goto-char (point-min)))))
14415 (org-detach-overlay org-tags-overlay)
14417 (mapconcat 'identity current ":")
14420 (defun org-get-tags-string ()
14421 "Get the TAGS string in the current headline."
14422 (unless (org-at-heading-p t)
14423 (error "Not on a heading"))
14425 (beginning-of-line 1)
14426 (if (looking-at (org-re ".*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$"))
14427 (org-match-string-no-properties 1)
14430 (defun org-get-tags ()
14431 "Get the list of tags specified in the current headline."
14432 (org-split-string (org-get-tags-string) ":"))
14434 (defun org-get-buffer-tags ()
14435 "Get a table of all tags used in the buffer, for completion."
14438 (goto-char (point-min))
14439 (while (re-search-forward
14440 (org-re "[ \t]:\\([[:alnum:]_@#%:]+\\):[ \t\r\n]") nil t)
14441 (when (equal (char-after (point-at-bol 0)) ?*)
14442 (mapc (lambda (x) (add-to-list 'tags x))
14443 (org-split-string (org-match-string-no-properties 1) ":")))))
14444 (mapc (lambda (s) (add-to-list 'tags s)) org-file-tags)
14445 (mapcar 'list tags)))
14447 ;;;; The mapping API
14449 (defun org-map-entries (func &optional match scope &rest skip)
14450 "Call FUNC at each headline selected by MATCH in SCOPE.
14452 FUNC is a function or a lisp form. The function will be called without
14453 arguments, with the cursor positioned at the beginning of the headline.
14454 The return values of all calls to the function will be collected and
14455 returned as a list.
14457 The call to FUNC will be wrapped into a save-excursion form, so FUNC
14458 does not need to preserve point. After evaluation, the cursor will be
14459 moved to the end of the line (presumably of the headline of the
14460 processed entry) and search continues from there. Under some
14461 circumstances, this may not produce the wanted results. For example,
14462 if you have removed (e.g. archived) the current (sub)tree it could
14463 mean that the next entry will be skipped entirely. In such cases, you
14464 can specify the position from where search should continue by making
14465 FUNC set the variable `org-map-continue-from' to the desired buffer
14468 MATCH is a tags/property/todo match as it is used in the agenda tags view.
14469 Only headlines that are matched by this query will be considered during
14470 the iteration. When MATCH is nil or t, all headlines will be
14471 visited by the iteration.
14473 SCOPE determines the scope of this command. It can be any of:
14475 nil The current buffer, respecting the restriction if any
14476 tree The subtree started with the entry at point
14477 region The entries within the active region, if any
14479 The entries within the active region, but only those at
14480 the same level than the first one.
14481 file The current buffer, without restriction
14483 The current buffer, and any archives associated with it
14484 agenda All agenda files
14485 agenda-with-archives
14486 All agenda files with any archive files associated with them
14488 If this is a list, all files in the list will be scanned
14490 The remaining args are treated as settings for the skipping facilities of
14491 the scanner. The following items can be given here:
14493 archive skip trees with the archive tag.
14494 comment skip trees with the COMMENT keyword
14495 function or Emacs Lisp form:
14496 will be used as value for `org-agenda-skip-function', so whenever
14497 the function returns t, FUNC will not be called for that
14498 entry and search will continue from the point where the
14499 function leaves it.
14501 If your function needs to retrieve the tags including inherited tags
14502 at the *current* entry, you can use the value of the variable
14503 `org-scanner-tags' which will be much faster than getting the value
14504 with `org-get-tags-at'. If your function gets properties with
14505 `org-entry-properties' at the *current* entry, bind `org-trust-scanner-tags'
14506 to t around the call to `org-entry-properties' to get the same speedup.
14507 Note that if your function moves around to retrieve tags and properties at
14508 a *different* entry, you cannot use these techniques."
14509 (unless (and (or (eq scope 'region) (eq scope 'region-start-level))
14510 (not (org-region-active-p)))
14511 (let* ((org-agenda-archives-mode nil) ; just to make sure
14512 (org-agenda-skip-archived-trees (memq 'archive skip))
14513 (org-agenda-skip-comment-trees (memq 'comment skip))
14514 (org-agenda-skip-function
14515 (car (org-delete-all '(comment archive) skip)))
14516 (org-tags-match-list-sublevels t)
14517 (start-level (eq scope 'region-start-level))
14519 org-todo-keywords-for-agenda
14520 org-done-keywords-for-agenda
14521 org-todo-keyword-alist-for-agenda
14522 org-drawers-for-agenda
14523 org-tag-alist-for-agenda
14527 ((eq match t) (setq matcher t))
14528 ((eq match nil) (setq matcher t))
14529 (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
14533 (cond ((eq scope 'tree)
14534 (org-back-to-heading t)
14535 (org-narrow-to-subtree)
14537 ((and (or (eq scope 'region) (eq scope 'region-start-level))
14538 (org-region-active-p))
14539 ;; If needed, set start-level to a string like "2"
14542 (goto-char (region-beginning))
14543 (unless (org-at-heading-p) (outline-next-heading))
14544 (setq start-level (org-current-level))))
14545 (narrow-to-region (region-beginning)
14547 (goto-char (region-end))
14548 (unless (and (bolp) (org-at-heading-p))
14549 (outline-next-heading))
14555 (org-agenda-prepare-buffers
14556 (list (buffer-file-name (current-buffer))))
14557 (setq res (org-scan-tags func matcher todo-only start-level)))
14558 ;; Get the right scope
14560 ((and scope (listp scope) (symbolp (car scope)))
14561 (setq scope (eval scope)))
14562 ((eq scope 'agenda)
14563 (setq scope (org-agenda-files t)))
14564 ((eq scope 'agenda-with-archives)
14565 (setq scope (org-agenda-files t))
14566 (setq scope (org-add-archive-files scope)))
14568 (setq scope (list (buffer-file-name))))
14569 ((eq scope 'file-with-archives)
14570 (setq scope (org-add-archive-files (list (buffer-file-name))))))
14571 (org-agenda-prepare-buffers scope)
14572 (while (setq file (pop scope))
14573 (with-current-buffer (org-find-base-buffer-visiting file)
14577 (goto-char (point-min))
14578 (setq res (append res (org-scan-tags func matcher todo-only))))))))))
14583 ;;; Setting and retrieving properties
14585 (defconst org-special-properties
14586 '("TODO" "TAGS" "ALLTAGS" "DEADLINE" "SCHEDULED" "CLOCK" "CLOSED" "PRIORITY"
14587 "TIMESTAMP" "TIMESTAMP_IA" "BLOCKED" "FILE" "CLOCKSUM" "CLOCKSUM_T")
14588 "The special properties valid in Org-mode.
14590 These are properties that are not defined in the property drawer,
14591 but in some other way.")
14593 (defconst org-default-properties
14594 '("ARCHIVE" "CATEGORY" "SUMMARY" "DESCRIPTION" "CUSTOM_ID"
14595 "LOCATION" "LOGGING" "COLUMNS" "VISIBILITY"
14596 "TABLE_EXPORT_FORMAT" "TABLE_EXPORT_FILE"
14597 "EXPORT_OPTIONS" "EXPORT_TEXT" "EXPORT_FILE_NAME"
14598 "EXPORT_TITLE" "EXPORT_AUTHOR" "EXPORT_DATE"
14599 "ORDERED" "NOBLOCKING" "COOKIE_DATA" "LOG_INTO_DRAWER" "REPEAT_TO_STATE"
14600 "CLOCK_MODELINE_TOTAL" "STYLE" "HTML_CONTAINER_CLASS")
14601 "Some properties that are used by Org-mode for various purposes.
14602 Being in this list makes sure that they are offered for completion.")
14604 (defconst org-property-start-re "^[ \t]*:PROPERTIES:[ \t]*$"
14605 "Regular expression matching the first line of a property drawer.")
14607 (defconst org-property-end-re "^[ \t]*:END:[ \t]*$"
14608 "Regular expression matching the last line of a property drawer.")
14610 (defconst org-clock-drawer-start-re "^[ \t]*:CLOCK:[ \t]*$"
14611 "Regular expression matching the first line of a property drawer.")
14613 (defconst org-clock-drawer-end-re "^[ \t]*:END:[ \t]*$"
14614 "Regular expression matching the first line of a property drawer.")
14616 (defconst org-property-drawer-re
14617 (concat "\\(" org-property-start-re "\\)[^\000]*\\("
14618 org-property-end-re "\\)\n?")
14619 "Matches an entire property drawer.")
14621 (defconst org-clock-drawer-re
14622 (concat "\\(" org-clock-drawer-start-re "\\)[^\000]*\\("
14623 org-property-end-re "\\)\n?")
14624 "Matches an entire clock drawer.")
14626 (defsubst org-re-property (property)
14627 "Return a regexp matching a PROPERTY line.
14628 Match group 1 will be set to the value."
14629 (concat "^[ \t]*:" (regexp-quote property) ":[ \t]*\\(\\S-.*\\)"))
14631 (defsubst org-re-property-keyword (property)
14632 "Return a regexp matching a PROPERTY line, possibly with no
14633 value for the property."
14634 (concat "^[ \t]*:" (regexp-quote property) ":[ \t]*\\(\\S-.*\\)?"))
14636 (defun org-property-action ()
14637 "Do an action on properties."
14640 (org-at-property-p)
14641 (message "Property Action: [s]et [d]elete [D]elete globally [c]ompute")
14642 (setq c (read-char-exclusive))
14645 (call-interactively 'org-set-property))
14647 (call-interactively 'org-delete-property))
14649 (call-interactively 'org-delete-property-globally))
14651 (call-interactively 'org-compute-property-at-point))
14652 (t (error "No such property action %c" c)))))
14654 (defun org-inc-effort ()
14655 "Increment the value of the effort property in the current entry."
14657 (org-set-effort nil t))
14659 (defun org-set-effort (&optional value increment)
14660 "Set the effort property of the current entry.
14661 With numerical prefix arg, use the nth allowed value, 0 stands for the
14662 10th allowed value.
14664 When INCREMENT is non-nil, set the property to the next allowed value."
14666 (if (equal value 0) (setq value 10))
14667 (let* ((completion-ignore-case t)
14668 (prop org-effort-property)
14669 (cur (org-entry-get nil prop))
14670 (allowed (org-property-get-allowed-values nil prop 'table))
14671 (existing (mapcar 'list (org-property-values prop)))
14674 ((stringp value) value)
14675 ((and allowed (integerp value))
14676 (or (car (nth (1- value) allowed))
14677 (car (org-last allowed))))
14678 ((and allowed increment)
14679 (or (caadr (member (list cur) allowed))
14680 (error "Allowed effort values are not set")))
14682 (message "Select 1-9,0, [RET%s]: %s"
14683 (if cur (concat "=" cur) "")
14684 (mapconcat 'car allowed " "))
14685 (setq rpl (read-char-exclusive))
14686 (if (equal rpl ?\r)
14688 (setq rpl (- rpl ?0))
14689 (if (equal rpl 0) (setq rpl 10))
14690 (if (and (> rpl 0) (<= rpl (length allowed)))
14691 (car (nth (1- rpl) allowed))
14692 (org-completing-read "Effort: " allowed nil))))
14694 (let (org-completion-use-ido org-completion-use-iswitchb)
14695 (org-completing-read
14696 (concat "Effort " (if (and cur (string-match "\\S-" cur))
14697 (concat "[" cur "]") "")
14699 existing nil nil "" nil cur))))))
14700 (unless (equal (org-entry-get nil prop) val)
14701 (org-entry-put nil prop val))
14703 (org-back-to-heading t)
14704 (put-text-property (point-at-bol) (point-at-eol) 'org-effort val))
14705 (message "%s is now %s" prop val)))
14707 (defun org-at-property-p ()
14708 "Is cursor inside a property drawer?"
14710 (beginning-of-line 1)
14711 (when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
14712 (save-match-data ;; Used by calling procedures
14714 (range (unless (org-before-first-heading-p)
14715 (org-get-property-block))))
14716 (and range (<= (car range) p) (< p (cdr range))))))))
14718 (defun org-get-property-block (&optional beg end force)
14719 "Return the (beg . end) range of the body of the property drawer.
14720 BEG and END are the beginning and end of the current subtree, or of
14721 the part before the first headline. If they are not given, they will
14722 be found. If the drawer does not exist and FORCE is non-nil, create
14726 (let* ((beg (or beg (and (org-before-first-heading-p) (point-min))
14727 (progn (org-back-to-heading t) (point))))
14728 (end (or end (and (not (outline-next-heading)) (point-max))
14731 (if (re-search-forward org-property-start-re end t)
14732 (setq beg (1+ (match-end 0)))
14735 (org-insert-property-drawer)
14736 (setq end (progn (outline-next-heading) (point))))
14739 (if (re-search-forward org-property-start-re end t)
14740 (setq beg (1+ (match-end 0)))))
14741 (if (re-search-forward org-property-end-re end t)
14742 (setq end (match-beginning 0))
14743 (or force (throw 'exit nil))
14747 (insert ":END:\n"))
14750 (defun org-entry-properties (&optional pom which specific)
14751 "Get all properties of the entry at point-or-marker POM.
14752 This includes the TODO keyword, the tags, time strings for deadline,
14753 scheduled, and clocking, and any additional properties defined in the
14754 entry. The return value is an alist, keys may occur multiple times
14755 if the property key was used several times.
14756 POM may also be nil, in which case the current entry is used.
14757 If WHICH is nil or `all', get all properties. If WHICH is
14758 `special' or `standard', only get that subclass. If WHICH
14759 is a string only get exactly this property. SPECIFIC can be a string, the
14760 specific property we are interested in. Specifying it can speed
14761 things up because then unnecessary parsing is avoided."
14762 (setq which (or which 'all))
14763 (org-with-point-at pom
14764 (let ((clockstr (substring org-clock-string 0 -1))
14765 (excluded '("TODO" "TAGS" "ALLTAGS" "PRIORITY" "BLOCKED"))
14766 (case-fold-search nil)
14767 beg end range props sum-props key key1 value string clocksum clocksumt)
14769 (when (condition-case nil
14770 (and (derived-mode-p 'org-mode) (org-back-to-heading t))
14773 (setq sum-props (get-text-property (point) 'org-summaries))
14774 (setq clocksum (get-text-property (point) :org-clock-minutes)
14775 clocksumt (get-text-property (point) :org-clock-minutes-today))
14776 (outline-next-heading)
14778 (when (memq which '(all special))
14779 ;; Get the special properties, like TODO and tags
14781 (when (and (or (not specific) (string= specific "TODO"))
14782 (looking-at org-todo-line-regexp) (match-end 2))
14783 (push (cons "TODO" (org-match-string-no-properties 2)) props))
14784 (when (and (or (not specific) (string= specific "PRIORITY"))
14785 (looking-at org-priority-regexp))
14786 (push (cons "PRIORITY" (org-match-string-no-properties 2)) props))
14787 (when (or (not specific) (string= specific "FILE"))
14788 (push (cons "FILE" buffer-file-name) props))
14789 (when (and (or (not specific) (string= specific "TAGS"))
14790 (setq value (org-get-tags-string))
14791 (string-match "\\S-" value))
14792 (push (cons "TAGS" value) props))
14793 (when (and (or (not specific) (string= specific "ALLTAGS"))
14794 (setq value (org-get-tags-at)))
14795 (push (cons "ALLTAGS" (concat ":" (mapconcat 'identity value ":")
14798 (when (or (not specific) (string= specific "BLOCKED"))
14799 (push (cons "BLOCKED" (if (org-entry-blocked-p) "t" "")) props))
14800 (when (or (not specific)
14802 '("SCHEDULED" "DEADLINE" "CLOCK" "CLOSED"
14803 "TIMESTAMP" "TIMESTAMP_IA")))
14805 (while (re-search-forward org-maybe-keyword-time-regexp end t)
14806 (setq key (if (match-end 1)
14807 (substring (org-match-string-no-properties 1)
14809 string (if (equal key clockstr)
14811 (buffer-substring-no-properties
14812 (match-beginning 3) (goto-char
14814 (substring (org-match-string-no-properties 3)
14816 ;; Get the correct property name from the key. This is
14817 ;; necessary if the user has configured time keywords.
14818 (setq key1 (concat key ":"))
14822 (if (= (char-after (match-beginning 3)) ?\[)
14823 "TIMESTAMP_IA" "TIMESTAMP")))
14824 ((equal key1 org-scheduled-string) (setq key "SCHEDULED"))
14825 ((equal key1 org-deadline-string) (setq key "DEADLINE"))
14826 ((equal key1 org-closed-string) (setq key "CLOSED"))
14827 ((equal key1 org-clock-string) (setq key "CLOCK")))
14828 (if (and specific (equal key specific) (not (equal key "CLOCK")))
14830 (push (cons key string) props)
14831 ;; no need to search further if match is found
14833 (when (or (equal key "CLOCK") (not (assoc key props)))
14834 (push (cons key string) props)))))))
14836 (when (memq which '(all standard))
14837 ;; Get the standard properties, like :PROP: ...
14838 (setq range (org-get-property-block beg end))
14840 (goto-char (car range))
14841 (while (re-search-forward
14842 (org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
14844 (setq key (org-match-string-no-properties 1)
14845 value (org-trim (or (org-match-string-no-properties 2) "")))
14846 (unless (member key excluded)
14847 (push (cons key (or value "")) props)))))
14849 (push (cons "CLOCKSUM"
14850 (org-columns-number-to-string (/ (float clocksum) 60.)
14854 (push (cons "CLOCKSUM_T"
14855 (org-columns-number-to-string (/ (float clocksumt) 60.)
14858 (unless (assoc "CATEGORY" props)
14859 (push (cons "CATEGORY" (org-get-category)) props))
14860 (append sum-props (nreverse props)))))))
14862 (defun org-entry-get (pom property &optional inherit literal-nil)
14863 "Get value of PROPERTY for entry or content at point-or-marker POM.
14864 If INHERIT is non-nil and the entry does not have the property,
14865 then also check higher levels of the hierarchy.
14866 If INHERIT is the symbol `selective', use inheritance only if the setting
14867 in `org-use-property-inheritance' selects PROPERTY for inheritance.
14868 If the property is present but empty, the return value is the empty string.
14869 If the property is not present at all, nil is returned.
14871 If LITERAL-NIL is set, return the string value \"nil\" as a string,
14872 do not interpret it as the list atom nil. This is used for inheritance
14873 when a \"nil\" value can supersede a non-nil value higher up the hierarchy."
14874 (org-with-point-at pom
14875 (if (and inherit (if (eq inherit 'selective)
14876 (org-property-inherit-p property)
14878 (org-entry-get-with-inheritance property literal-nil)
14879 (if (member property org-special-properties)
14880 ;; We need a special property. Use `org-entry-properties' to
14881 ;; retrieve it, but specify the wanted property
14882 (cdr (assoc property (org-entry-properties nil 'special property)))
14883 (let ((range (org-get-property-block)))
14884 (when (and range (not (eq (car range) (cdr range))))
14885 (let* ((props (list (or (assoc property org-file-properties)
14886 (assoc property org-global-properties)
14887 (assoc property org-global-properties-fixed))))
14889 (when (re-search-forward
14890 (org-re-property key) (cdr range) t)
14892 (org-update-property-plist
14895 (org-match-string-no-properties 1) "")
14898 (goto-char (car range))
14899 (funcall ap property)
14900 (goto-char (car range))
14901 (while (funcall ap (concat property "+")))
14902 (setq val (cdr (assoc property props)))
14903 (when val (if literal-nil val (org-not-nil val))))))))))
14905 (defun org-property-or-variable-value (var &optional inherit)
14906 "Check if there is a property fixing the value of VAR.
14907 If yes, return this value. If not, return the current value of the variable."
14908 (let ((prop (org-entry-get nil (symbol-name var) inherit)))
14909 (if (and prop (stringp prop) (string-match "\\S-" prop))
14911 (symbol-value var))))
14913 (defun org-entry-delete (pom property &optional delete-empty-drawer)
14914 "Delete the property PROPERTY from entry at point-or-marker POM.
14915 When optional argument DELETE-EMPTY-DRAWER is a string, it defines
14916 an empty drawer to delete."
14917 (org-with-point-at pom
14918 (if (member property org-special-properties)
14919 nil ; cannot delete these properties.
14920 (let ((range (org-get-property-block)))
14922 (goto-char (car range))
14924 (org-re-property property)
14927 (delete-region (match-beginning 0) (1+ (point-at-eol)))
14928 (and delete-empty-drawer
14929 (org-remove-empty-drawer-at
14930 delete-empty-drawer (car range)))
14934 ;; Multi-values properties are properties that contain multiple values
14935 ;; These values are assumed to be single words, separated by whitespace.
14936 (defun org-entry-add-to-multivalued-property (pom property value)
14937 "Add VALUE to the words in the PROPERTY in entry at point-or-marker POM."
14938 (let* ((old (org-entry-get pom property))
14939 (values (and old (org-split-string old "[ \t]"))))
14940 (setq value (org-entry-protect-space value))
14941 (unless (member value values)
14942 (setq values (cons value values))
14943 (org-entry-put pom property
14944 (mapconcat 'identity values " ")))))
14946 (defun org-entry-remove-from-multivalued-property (pom property value)
14947 "Remove VALUE from words in the PROPERTY in entry at point-or-marker POM."
14948 (let* ((old (org-entry-get pom property))
14949 (values (and old (org-split-string old "[ \t]"))))
14950 (setq value (org-entry-protect-space value))
14951 (when (member value values)
14952 (setq values (delete value values))
14953 (org-entry-put pom property
14954 (mapconcat 'identity values " ")))))
14956 (defun org-entry-member-in-multivalued-property (pom property value)
14957 "Is VALUE one of the words in the PROPERTY in entry at point-or-marker POM?"
14958 (let* ((old (org-entry-get pom property))
14959 (values (and old (org-split-string old "[ \t]"))))
14960 (setq value (org-entry-protect-space value))
14961 (member value values)))
14963 (defun org-entry-get-multivalued-property (pom property)
14964 "Return a list of values in a multivalued property."
14965 (let* ((value (org-entry-get pom property))
14966 (values (and value (org-split-string value "[ \t]"))))
14967 (mapcar 'org-entry-restore-space values)))
14969 (defun org-entry-put-multivalued-property (pom property &rest values)
14970 "Set multivalued PROPERTY at point-or-marker POM to VALUES.
14971 VALUES should be a list of strings. Spaces will be protected."
14972 (org-entry-put pom property
14973 (mapconcat 'org-entry-protect-space values " "))
14974 (let* ((value (org-entry-get pom property))
14975 (values (and value (org-split-string value "[ \t]"))))
14976 (mapcar 'org-entry-restore-space values)))
14978 (defun org-entry-protect-space (s)
14979 "Protect spaces and newline in string S."
14980 (while (string-match " " s)
14981 (setq s (replace-match "%20" t t s)))
14982 (while (string-match "\n" s)
14983 (setq s (replace-match "%0A" t t s)))
14986 (defun org-entry-restore-space (s)
14987 "Restore spaces and newline in string S."
14988 (while (string-match "%20" s)
14989 (setq s (replace-match " " t t s)))
14990 (while (string-match "%0A" s)
14991 (setq s (replace-match "\n" t t s)))
14994 (defvar org-entry-property-inherited-from (make-marker)
14995 "Marker pointing to the entry from where a property was inherited.
14996 Each call to `org-entry-get-with-inheritance' will set this marker to the
14997 location of the entry where the inheritance search matched. If there was
14998 no match, the marker will point nowhere.
14999 Note that also `org-entry-get' calls this function, if the INHERIT flag
15002 (defun org-entry-get-with-inheritance (property &optional literal-nil)
15003 "Get PROPERTY of entry or content at point, search higher levels if needed.
15004 The search will stop at the first ancestor which has the property defined.
15005 If the value found is \"nil\", return nil to show that the property
15006 should be considered as undefined (this is the meaning of nil here).
15007 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
15008 (move-marker org-entry-property-inherited-from nil)
15015 (when (setq tmp (org-entry-get nil property nil 'literal-nil))
15016 (or (ignore-errors (org-back-to-heading t))
15017 (goto-char (point-min)))
15018 (move-marker org-entry-property-inherited-from (point))
15020 (or (ignore-errors (org-up-heading-safe))
15021 (throw 'ex nil))))))
15023 (cdr (assoc property org-file-properties))
15024 (cdr (assoc property org-global-properties))
15025 (cdr (assoc property org-global-properties-fixed))))
15026 (if literal-nil tmp (org-not-nil tmp))))
15028 (defvar org-property-changed-functions nil
15029 "Hook called when the value of a property has changed.
15030 Each hook function should accept two arguments, the name of the property
15031 and the new value.")
15033 (defun org-entry-put (pom property value)
15034 "Set PROPERTY to VALUE for entry at point-or-marker POM."
15035 (org-with-point-at pom
15036 (org-back-to-heading t)
15037 (let ((beg (point)) (end (save-excursion (outline-next-heading) (point)))
15040 ((equal property "TODO")
15041 (when (and (stringp value) (string-match "\\S-" value)
15042 (not (member value org-todo-keywords-1)))
15043 (error "\"%s\" is not a valid TODO state" value))
15044 (if (or (not value)
15045 (not (string-match "\\S-" value)))
15046 (setq value 'none))
15048 (org-set-tags nil 'align))
15049 ((equal property "PRIORITY")
15050 (org-priority (if (and value (stringp value) (string-match "\\S-" value))
15051 (string-to-char value) ?\ ))
15052 (org-set-tags nil 'align))
15053 ((equal property "CLOCKSUM")
15054 (if (not (re-search-forward
15055 (concat org-clock-string ".*\\]--\\(\\[[^]]+\\]\\)") nil t))
15056 (error "Cannot find a clock log")
15057 (goto-char (- (match-end 1) 2))
15059 ((eq value 'earlier) (org-timestamp-down))
15060 ((eq value 'later) (org-timestamp-up)))
15061 (org-clock-sum-current-item)))
15062 ((equal property "SCHEDULED")
15063 (if (re-search-forward org-scheduled-time-regexp end t)
15065 ((eq value 'earlier) (org-timestamp-change -1 'day))
15066 ((eq value 'later) (org-timestamp-change 1 'day))
15067 (t (call-interactively 'org-schedule)))
15068 (call-interactively 'org-schedule)))
15069 ((equal property "DEADLINE")
15070 (if (re-search-forward org-deadline-time-regexp end t)
15072 ((eq value 'earlier) (org-timestamp-change -1 'day))
15073 ((eq value 'later) (org-timestamp-change 1 'day))
15074 (t (call-interactively 'org-deadline)))
15075 (call-interactively 'org-deadline)))
15076 ((member property org-special-properties)
15077 (error "The %s property can not yet be set with `org-entry-put'"
15079 (t ; a non-special property
15080 (let ((buffer-invisibility-spec (org-inhibit-invisibility))) ; Emacs 21
15081 (setq range (org-get-property-block beg end 'force))
15082 (goto-char (car range))
15083 (if (re-search-forward
15084 (org-re-property-keyword property) (cdr range) t)
15086 (delete-region (match-beginning 0) (match-end 0))
15087 (goto-char (match-beginning 0)))
15088 (goto-char (cdr range))
15092 (insert ":" property ":")
15093 (and value (insert " " value))
15094 (org-indent-line)))))
15095 (run-hook-with-args 'org-property-changed-functions property value)))
15097 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
15098 "Get all property keys in the current buffer.
15099 With INCLUDE-SPECIALS, also list the special properties that reflect things
15100 like tags and TODO state.
15101 With INCLUDE-DEFAULTS, also include properties that has special meaning
15102 internally: ARCHIVE, CATEGORY, SUMMARY, DESCRIPTION, LOCATION, and LOGGING
15104 With INCLUDE-COLUMNS, also include property names given in COLUMN
15105 formats in the current buffer."
15106 (let (rtn range cfmt s p)
15110 (goto-char (point-min))
15111 (while (re-search-forward org-property-start-re nil t)
15112 (setq range (org-get-property-block))
15113 (goto-char (car range))
15114 (while (re-search-forward
15115 (org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
15117 (add-to-list 'rtn (org-match-string-no-properties 1)))
15118 (outline-next-heading))))
15120 (when include-specials
15121 (setq rtn (append org-special-properties rtn)))
15123 (when include-defaults
15124 (mapc (lambda (x) (add-to-list 'rtn x)) org-default-properties)
15125 (add-to-list 'rtn org-effort-property))
15127 (when include-columns
15131 (goto-char (point-min))
15132 (while (re-search-forward
15133 "^\\(#\\+COLUMNS:\\|[ \t]*:COLUMNS:\\)[ \t]*\\(.*\\)"
15135 (setq cfmt (match-string 2) s 0)
15136 (while (string-match (org-re "%[0-9]*\\([-[:alnum:]_]+\\)")
15138 (setq s (match-end 0)
15139 p (match-string 1 cfmt))
15140 (unless (or (equal p "ITEM")
15141 (member p org-special-properties))
15142 (add-to-list 'rtn (match-string 1 cfmt))))))))
15144 (sort rtn (lambda (a b) (string< (upcase a) (upcase b))))))
15146 (defun org-property-values (key)
15147 "Return a list of all values of property KEY in the current buffer."
15151 (goto-char (point-min))
15152 (let ((re (org-re-property key))
15154 (while (re-search-forward re nil t)
15155 (add-to-list 'values (org-trim (match-string 1))))
15156 (delete "" values)))))
15158 (defun org-insert-property-drawer ()
15159 "Insert a property drawer into the current entry."
15160 (org-back-to-heading t)
15161 (looking-at org-outline-regexp)
15162 (let ((indent (if org-adapt-indentation
15163 (- (match-end 0) (match-beginning 0))
15166 (re (concat "^[ \t]*" org-keyword-time-regexp))
15168 (outline-next-heading)
15171 (while (re-search-forward re end t))
15172 (setq hiddenp (outline-invisible-p))
15174 (and (equal (char-after) ?\n) (forward-char 1))
15175 (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
15176 (if (member (match-string 1) '("CLOCK:" ":END:"))
15177 ;; just skip this line
15178 (beginning-of-line 2)
15179 ;; Drawer start, find the end
15180 (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
15181 (beginning-of-line 1)))
15182 (org-skip-over-state-notes)
15183 (skip-chars-backward " \t\n\r")
15184 (if (eq (char-before) ?*) (forward-char 1))
15185 (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
15186 (beginning-of-line 0)
15187 (org-indent-to-column indent)
15188 (beginning-of-line 2)
15189 (org-indent-to-column indent)
15190 (beginning-of-line 0)
15193 (org-back-to-heading t)
15195 (org-flag-drawer t))))
15197 (defun org-insert-drawer (&optional arg drawer)
15198 "Insert a drawer at point.
15200 Optional argument DRAWER, when non-nil, is a string representing
15201 drawer's name. Otherwise, the user is prompted for a name.
15203 If a region is active, insert the drawer around that region
15206 Point is left between drawer's boundaries."
15208 (let* ((logbook (if (stringp org-log-into-drawer) org-log-into-drawer
15210 ;; SYSTEM-DRAWERS is a list of drawer names that are used
15211 ;; internally by Org. They are meant to be inserted
15213 (system-drawers `("CLOCK" ,logbook "PROPERTIES"))
15214 ;; Remove system drawers from list. Note: For some reason,
15215 ;; `org-completing-read' ignores the predicate while
15216 ;; `completing-read' handles it fine.
15217 (drawer (if arg "PROPERTIES"
15220 "Drawer: " org-drawers
15221 (lambda (d) (not (member d system-drawers))))))))
15223 ;; With C-u, fall back on `org-insert-property-drawer'
15224 (arg (org-insert-property-drawer))
15225 ;; With an active region, insert a drawer at point.
15226 ((not (org-region-active-p))
15228 (unless (bolp) (insert "\n"))
15229 (insert (format ":%s:\n\n:END:\n" drawer))
15230 (forward-line -2)))
15231 ;; Otherwise, insert the drawer at point
15233 (let ((rbeg (region-beginning))
15234 (rend (copy-marker (region-end))))
15238 (beginning-of-line)
15239 (when (save-excursion
15240 (re-search-forward org-outline-regexp-bol rend t))
15241 (error "Drawers cannot contain headlines"))
15242 ;; Position point at the beginning of the first
15243 ;; non-blank line in region. Insert drawer's opening
15244 ;; there, then indent it.
15245 (org-skip-whitespace)
15246 (beginning-of-line)
15247 (insert ":" drawer ":\n")
15249 (indent-for-tab-command)
15250 ;; Move point to the beginning of the first blank line
15251 ;; after the last non-blank line in region. Insert
15252 ;; drawer's closing, then indent it.
15254 (skip-chars-backward " \r\t\n")
15256 (deactivate-mark t)
15257 (indent-for-tab-command)
15258 (unless (eolp) (insert "\n")))
15259 ;; Clear marker, whatever the outcome of insertion is.
15260 (set-marker rend nil)))))))
15262 (defvar org-property-set-functions-alist nil
15263 "Property set function alist.
15264 Each entry should have the following format:
15266 (PROPERTY . READ-FUNCTION)
15268 The read function will be called with the same argument as
15269 `org-completing-read'.")
15271 (defun org-set-property-function (property)
15272 "Get the function that should be used to set PROPERTY.
15273 This is computed according to `org-property-set-functions-alist'."
15274 (or (cdr (assoc property org-property-set-functions-alist))
15275 'org-completing-read))
15277 (defun org-read-property-value (property)
15278 "Read PROPERTY value from user."
15279 (let* ((completion-ignore-case t)
15280 (allowed (org-property-get-allowed-values nil property 'table))
15281 (cur (org-entry-get nil property))
15282 (prompt (concat property " value"
15283 (if (and cur (string-match "\\S-" cur))
15284 (concat " [" cur "]") "") ": "))
15285 (set-function (org-set-property-function property))
15287 (funcall set-function prompt allowed nil
15288 (not (get-text-property 0 'org-unrestricted
15290 (let (org-completion-use-ido org-completion-use-iswitchb)
15291 (funcall set-function prompt
15292 (mapcar 'list (org-property-values property))
15293 nil nil "" nil cur)))))
15298 (defvar org-last-set-property nil)
15299 (defvar org-last-set-property-value nil)
15300 (defun org-read-property-name ()
15301 "Read a property name."
15302 (let* ((completion-ignore-case t)
15303 (keys (org-buffer-property-keys nil t t))
15304 (default-prop (or (save-excursion
15306 (beginning-of-line)
15307 (and (looking-at "^\\s-*:\\([^:\n]+\\):")
15308 (null (string= (match-string 1) "END"))
15309 (match-string 1))))
15310 org-last-set-property))
15311 (property (org-icompleting-read
15313 (if default-prop (concat " [" default-prop "]") "")
15315 (mapcar 'list keys)
15318 (if (member property keys)
15320 (or (cdr (assoc (downcase property)
15321 (mapcar (lambda (x) (cons (downcase x) x))
15325 (defun org-set-property-and-value (use-last)
15326 "Allow to set [PROPERTY]: [value] direction from prompt.
15327 When use-default, don't even ask, just use the last
15328 \"[PROPERTY]: [value]\" string from the history."
15330 (let* ((completion-ignore-case t)
15331 (pv (or (and use-last org-last-set-property-value)
15332 (org-completing-read
15333 "Enter a \"[Property]: [value]\" pair: "
15334 nil nil nil nil nil
15335 org-last-set-property-value)))
15337 (when (string-match "^[ \t]*\\([^:]+\\):[ \t]*\\(.*\\)[ \t]*$" pv)
15338 (setq prop (match-string 1 pv)
15339 val (match-string 2 pv))
15340 (org-set-property prop val))))
15342 (defun org-set-property (property value)
15343 "In the current entry, set PROPERTY to VALUE.
15344 When called interactively, this will prompt for a property name, offering
15345 completion on existing and default properties. And then it will prompt
15346 for a value, offering completion either on allowed values (via an inherited
15347 xxx_ALL property) or on existing values in other instances of this property
15348 in the current file."
15349 (interactive (list nil nil))
15350 (let* ((property (or property (org-read-property-name)))
15351 (value (or value (org-read-property-value property)))
15352 (fn (cdr (assoc property org-properties-postprocess-alist))))
15353 (setq org-last-set-property property)
15354 (setq org-last-set-property-value (concat property ": " value))
15355 ;; Possibly postprocess the inserted value:
15356 (when fn (setq value (funcall fn value)))
15357 (unless (equal (org-entry-get nil property) value)
15358 (org-entry-put nil property value))))
15360 (defun org-delete-property (property &optional delete-empty-drawer)
15361 "In the current entry, delete PROPERTY.
15362 When optional argument DELETE-EMPTY-DRAWER is a string, it defines
15363 an empty drawer to delete."
15365 (let* ((completion-ignore-case t)
15366 (prop (org-icompleting-read "Property: "
15367 (org-entry-properties nil 'standard))))
15369 (message "Property %s %s" property
15370 (if (org-entry-delete nil property delete-empty-drawer)
15372 "was not present in the entry")))
15374 (defun org-delete-property-globally (property)
15375 "Remove PROPERTY globally, from all entries."
15377 (let* ((completion-ignore-case t)
15378 (prop (org-icompleting-read
15379 "Globally remove property: "
15380 (mapcar 'list (org-buffer-property-keys)))))
15385 (goto-char (point-min))
15387 (while (re-search-forward
15388 (org-re-property property)
15390 (setq cnt (1+ cnt))
15391 (delete-region (match-beginning 0) (1+ (point-at-eol))))
15392 (message "Property \"%s\" removed from %d entries" property cnt)))))
15394 (defvar org-columns-current-fmt-compiled) ; defined in org-colview.el
15396 (defun org-compute-property-at-point ()
15397 "Compute the property at point.
15398 This looks for an enclosing column format, extracts the operator and
15399 then applies it to the property in the column format's scope."
15401 (unless (org-at-property-p)
15402 (error "Not at a property"))
15403 (let ((prop (org-match-string-no-properties 2)))
15404 (org-columns-get-format-and-top-level)
15405 (unless (nth 3 (assoc prop org-columns-current-fmt-compiled))
15406 (error "No operator defined for property %s" prop))
15407 (org-columns-compute prop)))
15409 (defvar org-property-allowed-value-functions nil
15410 "Hook for functions supplying allowed values for a specific property.
15411 The functions must take a single argument, the name of the property, and
15412 return a flat list of allowed values. If \":ETC\" is one of
15413 the values, this means that these values are intended as defaults for
15414 completion, but that other values should be allowed too.
15415 The functions must return nil if they are not responsible for this
15418 (defun org-property-get-allowed-values (pom property &optional table)
15419 "Get allowed values for the property PROPERTY.
15420 When TABLE is non-nil, return an alist that can directly be used for
15424 ((equal property "TODO")
15425 (setq vals (org-with-point-at pom
15426 (append org-todo-keywords-1 '("")))))
15427 ((equal property "PRIORITY")
15428 (let ((n org-lowest-priority))
15429 (while (>= n org-highest-priority)
15430 (push (char-to-string n) vals)
15432 ((member property org-special-properties))
15433 ((setq vals (run-hook-with-args-until-success
15434 'org-property-allowed-value-functions property)))
15436 (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
15437 (when (and vals (string-match "\\S-" vals))
15438 (setq vals (car (read-from-string (concat "(" vals ")"))))
15439 (setq vals (mapcar (lambda (x)
15440 (cond ((stringp x) x)
15441 ((numberp x) (number-to-string x))
15442 ((symbolp x) (symbol-name x))
15445 (when (member ":ETC" vals)
15446 (setq vals (remove ":ETC" vals))
15447 (org-add-props (car vals) '(org-unrestricted t)))
15448 (if table (mapcar 'list vals) vals)))
15450 (defun org-property-previous-allowed-value (&optional previous)
15451 "Switch to the next allowed value for this property."
15453 (org-property-next-allowed-value t))
15455 (defun org-property-next-allowed-value (&optional previous)
15456 "Switch to the next allowed value for this property."
15458 (unless (org-at-property-p)
15459 (error "Not at a property"))
15460 (let* ((prop (car (save-match-data (org-split-string (match-string 1) ":"))))
15461 (key (match-string 2))
15462 (value (match-string 3))
15463 (allowed (or (org-property-get-allowed-values (point) key)
15464 (and (member value '("[ ]" "[-]" "[X]"))
15468 (error "Allowed values for this property have not been defined"))
15469 (if previous (setq allowed (reverse allowed)))
15470 (if (member value allowed)
15471 (setq nval (car (cdr (member value allowed)))))
15472 (setq nval (or nval (car allowed)))
15473 (if (equal nval value)
15474 (error "Only one allowed value for this property"))
15475 (org-at-property-p)
15476 (replace-match (concat " :" key ": " nval) t t)
15478 (beginning-of-line 1)
15479 (skip-chars-forward " \t")
15480 (when (equal prop org-effort-property)
15482 (org-back-to-heading t)
15483 (put-text-property (point-at-bol) (point-at-eol) 'org-effort nval)))
15484 (run-hook-with-args 'org-property-changed-functions key nval)))
15486 (defun org-find-olp (path &optional this-buffer)
15487 "Return a marker pointing to the entry at outline path OLP.
15488 If anything goes wrong, throw an error.
15489 You can wrap this call to catch the error like this:
15491 (condition-case msg
15492 (org-mobile-locate-entry (match-string 4))
15493 (error (nth 1 msg)))
15495 The return value will then be either a string with the error message,
15496 or a marker if everything is OK.
15498 If THIS-BUFFER is set, the outline path does not contain a file,
15500 (let* ((file (if this-buffer buffer-file-name (pop path)))
15501 (buffer (if this-buffer (current-buffer) (find-file-noselect file)))
15505 limit re end found pos heading cnt flevel)
15506 (unless buffer (error "File not found :%s" file))
15507 (with-current-buffer buffer
15511 (setq limit (point-max))
15512 (goto-char (point-min))
15513 (while (setq heading (pop path))
15514 (setq re (format org-complex-heading-regexp-format
15515 (regexp-quote heading)))
15516 (setq cnt 0 pos (point))
15517 (while (re-search-forward re end t)
15518 (setq level (- (match-end 1) (match-beginning 1)))
15519 (if (and (>= level lmin) (<= level lmax))
15520 (setq found (match-beginning 0) flevel level cnt (1+ cnt))))
15521 (when (= cnt 0) (error "Heading not found on level %d: %s"
15523 (when (> cnt 1) (error "Heading not unique on level %d: %s"
15526 (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
15527 (setq end (save-excursion (org-end-of-subtree t t))))
15528 (when (org-at-heading-p)
15529 (point-marker)))))))
15531 (defun org-find-exact-headline-in-buffer (heading &optional buffer pos-only)
15532 "Find node HEADING in BUFFER.
15533 Return a marker to the heading if it was found, or nil if not.
15534 If POS-ONLY is set, return just the position instead of a marker.
15536 The heading text must match exact, but it may have a TODO keyword,
15537 a priority cookie and tags in the standard locations."
15538 (with-current-buffer (or buffer (current-buffer))
15542 (goto-char (point-min))
15543 (let (case-fold-search)
15544 (if (re-search-forward
15545 (format org-complex-heading-regexp-format
15546 (regexp-quote heading)) nil t)
15548 (match-beginning 0)
15549 (move-marker (make-marker) (match-beginning 0)))))))))
15551 (defun org-find-exact-heading-in-directory (heading &optional dir)
15552 "Find Org node headline HEADING in all .org files in directory DIR.
15553 When the target headline is found, return a marker to this location."
15554 (let ((files (directory-files (or dir default-directory)
15555 nil "\\`[^.#].*\\.org\\'"))
15556 file visiting m buffer)
15558 (while (setq file (pop files))
15559 (message "trying %s" file)
15560 (setq visiting (org-find-base-buffer-visiting file))
15561 (setq buffer (or visiting (find-file-noselect file)))
15562 (setq m (org-find-exact-headline-in-buffer
15564 (when (and (not m) (not visiting)) (kill-buffer buffer))
15565 (and m (throw 'found m))))))
15567 (defun org-find-entry-with-id (ident)
15568 "Locate the entry that contains the ID property with exact value IDENT.
15569 IDENT can be a string, a symbol or a number, this function will search for
15570 the string representation of it.
15571 Return the position where this entry starts, or nil if there is no such entry."
15572 (interactive "sID: ")
15574 ((stringp ident) ident)
15575 ((symbol-name ident) (symbol-name ident))
15576 ((numberp ident) (number-to-string ident))
15577 (t (error "IDENT %s must be a string, symbol or number" ident))))
15578 (case-fold-search nil))
15582 (goto-char (point-min))
15583 (when (re-search-forward
15584 (concat "^[ \t]*:ID:[ \t]+" (regexp-quote id) "[ \t]*$")
15586 (org-back-to-heading t)
15591 (defvar org-last-changed-timestamp nil)
15592 (defvar org-last-inserted-timestamp nil
15593 "The last time stamp inserted with `org-insert-time-stamp'.")
15594 (defvar org-time-was-given) ; dynamically scoped parameter
15595 (defvar org-end-time-was-given) ; dynamically scoped parameter
15596 (defvar org-ts-what) ; dynamically scoped parameter
15598 (defun org-time-stamp (arg &optional inactive)
15599 "Prompt for a date/time and insert a time stamp.
15600 If the user specifies a time like HH:MM or if this command is
15601 called with at least one prefix argument, the time stamp contains
15602 the date and the time. Otherwise, only the date is be included.
15604 All parts of a date not specified by the user is filled in from
15605 the current date/time. So if you just press return without
15606 typing anything, the time stamp will represent the current
15609 If there is already a timestamp at the cursor, it will be
15612 With two universal prefix arguments, insert an active timestamp
15613 with the current time without prompting the user."
15617 ;; Default time is either today, or, when entering a range,
15618 ;; the range start.
15619 (if (or (and (org-at-timestamp-p t) (setq ts (match-string 0)))
15621 (re-search-backward
15622 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
15623 (- (point) 20) t)))
15624 (apply 'encode-time (org-parse-time-string (match-string 1)))
15626 (default-input (and ts (org-get-compact-tod ts)))
15627 (repeater (save-excursion
15629 (beginning-of-line)
15630 (when (re-search-forward
15631 "\\([.+-]+[0-9]+[hdwmy] ?\\)+" ;;\\(?:[/ ][-+]?[0-9]+[hdwmy]\\)?\\) ?"
15632 (save-excursion (progn (end-of-line) (point))) t)
15633 (match-string 0)))))
15634 org-time-was-given org-end-time-was-given time)
15636 ((and (org-at-timestamp-p t)
15637 (memq last-command '(org-time-stamp org-time-stamp-inactive))
15638 (memq this-command '(org-time-stamp org-time-stamp-inactive)))
15640 (setq time (let ((this-command this-command))
15641 (org-read-date arg 'totime nil nil
15642 default-time default-input inactive)))
15643 (org-insert-time-stamp time (or org-time-was-given arg) inactive))
15644 ((org-at-timestamp-p t)
15645 (setq time (let ((this-command this-command))
15646 (org-read-date arg 'totime nil nil default-time default-input inactive)))
15647 (when (org-at-timestamp-p t) ; just to get the match data
15648 ; (setq inactive (eq (char-after (match-beginning 0)) ?\[))
15650 (setq org-last-changed-timestamp
15651 (org-insert-time-stamp
15652 time (or org-time-was-given arg)
15653 inactive nil nil (list org-end-time-was-given)))
15654 (when repeater (goto-char (1- (point))) (insert " " repeater)
15655 (setq org-last-changed-timestamp
15656 (concat (substring org-last-inserted-timestamp 0 -1)
15657 " " repeater ">"))))
15658 (message "Timestamp updated"))
15660 (org-insert-time-stamp (current-time) t))
15662 (setq time (let ((this-command this-command))
15663 (org-read-date arg 'totime nil nil default-time default-input inactive)))
15664 (org-insert-time-stamp time (or org-time-was-given arg) inactive
15665 nil nil (list org-end-time-was-given))))))
15667 ;; FIXME: can we use this for something else, like computing time differences?
15668 (defun org-get-compact-tod (s)
15669 (when (string-match "\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\(-\\(\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)\\)?" s)
15670 (let* ((t1 (match-string 1 s))
15671 (h1 (string-to-number (match-string 2 s)))
15672 (m1 (string-to-number (match-string 3 s)))
15673 (t2 (and (match-end 4) (match-string 5 s)))
15674 (h2 (and t2 (string-to-number (match-string 6 s))))
15675 (m2 (and t2 (string-to-number (match-string 7 s))))
15679 (setq dh (- h2 h1) dm (- m2 m1))
15680 (if (< dm 0) (setq dm (+ dm 60) dh (1- dh)))
15681 (concat t1 "+" (number-to-string dh)
15682 (if (/= 0 dm) (concat ":" (number-to-string dm))))))))
15684 (defun org-time-stamp-inactive (&optional arg)
15685 "Insert an inactive time stamp.
15686 An inactive time stamp is enclosed in square brackets instead of angle
15687 brackets. It is inactive in the sense that it does not trigger agenda entries,
15688 does not link to the calendar and cannot be changed with the S-cursor keys.
15689 So these are more for recording a certain time/date."
15691 (org-time-stamp arg 'inactive))
15693 (defvar org-date-ovl (make-overlay 1 1))
15694 (overlay-put org-date-ovl 'face 'org-date-selected)
15695 (org-detach-overlay org-date-ovl)
15697 (defvar org-ans1) ; dynamically scoped parameter
15698 (defvar org-ans2) ; dynamically scoped parameter
15700 (defvar org-plain-time-of-day-regexp) ; defined below
15702 (defvar org-overriding-default-time nil) ; dynamically scoped
15703 (defvar org-read-date-overlay nil)
15704 (defvar org-dcst nil) ; dynamically scoped
15705 (defvar org-read-date-history nil)
15706 (defvar org-read-date-final-answer nil)
15707 (defvar org-read-date-analyze-futurep nil)
15708 (defvar org-read-date-analyze-forced-year nil)
15709 (defvar org-read-date-inactive)
15711 (defvar org-read-date-minibuffer-local-map
15712 (let ((map (make-sparse-keymap)))
15713 (set-keymap-parent map minibuffer-local-map)
15714 (org-defkey map (kbd ".")
15715 (lambda () (interactive)
15716 (org-eval-in-calendar '(calendar-goto-today))))
15717 (org-defkey map [(meta shift left)]
15718 (lambda () (interactive)
15719 (org-eval-in-calendar '(calendar-backward-month 1))))
15720 (org-defkey map [(meta shift right)]
15721 (lambda () (interactive)
15722 (org-eval-in-calendar '(calendar-forward-month 1))))
15723 (org-defkey map [(meta shift up)]
15724 (lambda () (interactive)
15725 (org-eval-in-calendar '(calendar-backward-year 1))))
15726 (org-defkey map [(meta shift down)]
15727 (lambda () (interactive)
15728 (org-eval-in-calendar '(calendar-forward-year 1))))
15729 (org-defkey map [?\e (shift left)]
15730 (lambda () (interactive)
15731 (org-eval-in-calendar '(calendar-backward-month 1))))
15732 (org-defkey map [?\e (shift right)]
15733 (lambda () (interactive)
15734 (org-eval-in-calendar '(calendar-forward-month 1))))
15735 (org-defkey map [?\e (shift up)]
15736 (lambda () (interactive)
15737 (org-eval-in-calendar '(calendar-backward-year 1))))
15738 (org-defkey map [?\e (shift down)]
15739 (lambda () (interactive)
15740 (org-eval-in-calendar '(calendar-forward-year 1))))
15741 (org-defkey map [(shift up)]
15742 (lambda () (interactive)
15743 (org-eval-in-calendar '(calendar-backward-week 1))))
15744 (org-defkey map [(shift down)]
15745 (lambda () (interactive)
15746 (org-eval-in-calendar '(calendar-forward-week 1))))
15747 (org-defkey map [(shift left)]
15748 (lambda () (interactive)
15749 (org-eval-in-calendar '(calendar-backward-day 1))))
15750 (org-defkey map [(shift right)]
15751 (lambda () (interactive)
15752 (org-eval-in-calendar '(calendar-forward-day 1))))
15753 (org-defkey map "!"
15754 (lambda () (interactive)
15755 (org-eval-in-calendar '(diary-view-entries))
15757 (org-defkey map ">"
15758 (lambda () (interactive)
15759 (org-eval-in-calendar '(scroll-calendar-left 1))))
15760 (org-defkey map "<"
15761 (lambda () (interactive)
15762 (org-eval-in-calendar '(scroll-calendar-right 1))))
15763 (org-defkey map "\C-v"
15764 (lambda () (interactive)
15765 (org-eval-in-calendar
15766 '(calendar-scroll-left-three-months 1))))
15767 (org-defkey map "\M-v"
15768 (lambda () (interactive)
15769 (org-eval-in-calendar
15770 '(calendar-scroll-right-three-months 1))))
15772 "Keymap for minibuffer commands when using `org-read-date'.")
15774 (defun org-read-date (&optional org-with-time to-time from-string prompt
15775 default-time default-input inactive)
15776 "Read a date, possibly a time, and make things smooth for the user.
15777 The prompt will suggest to enter an ISO date, but you can also enter anything
15778 which will at least partially be understood by `parse-time-string'.
15779 Unrecognized parts of the date will default to the current day, month, year,
15780 hour and minute. If this command is called to replace a timestamp at point,
15781 or to enter the second timestamp of a range, the default time is taken
15782 from the existing stamp. Furthermore, the command prefers the future,
15783 so if you are giving a date where the year is not given, and the day-month
15784 combination is already past in the current year, it will assume you
15785 mean next year. For details, see the manual. A few examples:
15787 3-2-5 --> 2003-02-05
15788 feb 15 --> currentyear-02-15
15789 2/15 --> currentyear-02-15
15790 sep 12 9 --> 2009-09-12
15791 12:45 --> today 12:45
15792 22 sept 0:34 --> currentyear-09-22 0:34
15793 12 --> currentyear-currentmonth-12
15794 Fri --> nearest Friday (today or later)
15797 Furthermore you can specify a relative date by giving, as the *first* thing
15798 in the input: a plus/minus sign, a number and a letter [hdwmy] to indicate
15799 change in days weeks, months, years.
15800 With a single plus or minus, the date is relative to today. With a double
15801 plus or minus, it is relative to the date in DEFAULT-TIME. E.g.
15802 +4d --> four days from today
15803 +4 --> same as above
15804 +2w --> two weeks from today
15805 ++5 --> five days from default date
15807 The function understands only English month and weekday abbreviations.
15809 While prompting, a calendar is popped up - you can also select the
15810 date with the mouse (button 1). The calendar shows a period of three
15811 months. To scroll it to other months, use the keys `>' and `<'.
15812 If you don't like the calendar, turn it off with
15813 \(setq org-read-date-popup-calendar nil)
15815 With optional argument TO-TIME, the date will immediately be converted
15816 to an internal time.
15817 With an optional argument ORG-WITH-TIME, the prompt will suggest to
15818 also insert a time. Note that when ORG-WITH-TIME is not set, you can
15819 still enter a time, and this function will inform the calling routine
15820 about this change. The calling routine may then choose to change the
15821 format used to insert the time stamp into the buffer to include the time.
15822 With optional argument FROM-STRING, read from this string instead from
15823 the user. PROMPT can overwrite the default prompt. DEFAULT-TIME is
15824 the time/date that is used for everything that is not specified by the
15826 (require 'parse-time)
15827 (let* ((org-time-stamp-rounding-minutes
15828 (if (equal org-with-time '(16)) '(0 0) org-time-stamp-rounding-minutes))
15829 (org-dcst org-display-custom-times)
15830 (ct (org-current-time))
15831 (org-def (or org-overriding-default-time default-time ct))
15832 (org-defdecode (decode-time org-def))
15834 (when (< (nth 2 org-defdecode) org-extend-today-until)
15835 (setcar (nthcdr 2 org-defdecode) -1)
15836 (setcar (nthcdr 1 org-defdecode) 59)
15837 (setq org-def (apply 'encode-time org-defdecode)
15838 org-defdecode (decode-time org-def)))))
15839 (mouse-autoselect-window nil) ; Don't let the mouse jump
15840 (calendar-frame-setup nil)
15841 (calendar-setup nil)
15842 (calendar-move-hook nil)
15843 (calendar-view-diary-initially-flag nil)
15844 (calendar-view-holidays-initially-flag nil)
15845 (timestr (format-time-string
15846 (if org-with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") org-def))
15847 (prompt (concat (if prompt (concat prompt " ") "")
15848 (format "Date+time [%s]: " timestr)))
15849 ans (org-ans0 "") org-ans1 org-ans2 final)
15852 (from-string (setq ans from-string))
15853 (org-read-date-popup-calendar
15855 (save-window-excursion
15857 (org-eval-in-calendar '(setq cursor-type nil) t)
15860 (calendar-forward-day (- (time-to-days org-def)
15861 (calendar-absolute-from-gregorian
15862 (calendar-current-date))))
15863 (org-eval-in-calendar nil t)
15864 (let* ((old-map (current-local-map))
15865 (map (copy-keymap calendar-mode-map))
15866 (minibuffer-local-map
15867 (copy-keymap org-read-date-minibuffer-local-map)))
15868 (org-defkey map (kbd "RET") 'org-calendar-select)
15869 (org-defkey map [mouse-1] 'org-calendar-select-mouse)
15870 (org-defkey map [mouse-2] 'org-calendar-select-mouse)
15873 (use-local-map map)
15874 (setq org-read-date-inactive inactive)
15875 (add-hook 'post-command-hook 'org-read-date-display)
15876 (setq org-ans0 (read-string prompt default-input
15877 'org-read-date-history nil))
15878 ;; org-ans0: from prompt
15879 ;; org-ans1: from mouse click
15880 ;; org-ans2: from calendar motion
15881 (setq ans (concat org-ans0 " " (or org-ans1 org-ans2))))
15882 (remove-hook 'post-command-hook 'org-read-date-display)
15883 (use-local-map old-map)
15884 (when org-read-date-overlay
15885 (delete-overlay org-read-date-overlay)
15886 (setq org-read-date-overlay nil)))))
15887 (bury-buffer "*Calendar*")))))
15889 (t ; Naked prompt only
15891 (setq ans (read-string prompt default-input
15892 'org-read-date-history timestr))
15893 (when org-read-date-overlay
15894 (delete-overlay org-read-date-overlay)
15895 (setq org-read-date-overlay nil)))))
15897 (setq final (org-read-date-analyze ans org-def org-defdecode))
15899 (when org-read-date-analyze-forced-year
15900 (message "Year was forced into %s"
15901 (if org-read-date-force-compatible-dates
15902 "compatible range (1970-2037)"
15903 "range representable on this machine"))
15906 ;; One round trip to get rid of 34th of August and stuff like that....
15907 (setq final (decode-time (apply 'encode-time final)))
15909 (setq org-read-date-final-answer ans)
15912 (apply 'encode-time final)
15913 (if (and (boundp 'org-time-was-given) org-time-was-given)
15914 (format "%04d-%02d-%02d %02d:%02d"
15915 (nth 5 final) (nth 4 final) (nth 3 final)
15916 (nth 2 final) (nth 1 final))
15917 (format "%04d-%02d-%02d" (nth 5 final) (nth 4 final) (nth 3 final))))))
15920 (defvar org-defdecode)
15921 (defvar org-with-time)
15922 (defun org-read-date-display ()
15923 "Display the current date prompt interpretation in the minibuffer."
15924 (when org-read-date-display-live
15925 (when org-read-date-overlay
15926 (delete-overlay org-read-date-overlay))
15927 (when (minibufferp (current-buffer))
15930 (while (not (equal (buffer-substring
15931 (max (point-min) (- (point) 4)) (point))
15934 (let* ((ans (concat (buffer-substring (point-at-bol) (point-max))
15935 " " (or org-ans1 org-ans2)))
15936 (org-end-time-was-given nil)
15937 (f (org-read-date-analyze ans org-def org-defdecode))
15939 org-time-stamp-custom-formats
15940 org-time-stamp-formats))
15941 (fmt (if (or org-with-time
15942 (and (boundp 'org-time-was-given) org-time-was-given))
15945 (txt (format-time-string fmt (apply 'encode-time f)))
15946 (txt (if org-read-date-inactive (concat "[" (substring txt 1 -1) "]") txt))
15947 (txt (concat "=> " txt)))
15948 (when (and org-end-time-was-given
15949 (string-match org-plain-time-of-day-regexp txt))
15950 (setq txt (concat (substring txt 0 (match-end 0)) "-"
15951 org-end-time-was-given
15952 (substring txt (match-end 0)))))
15953 (when org-read-date-analyze-futurep
15954 (setq txt (concat txt " (=>F)")))
15955 (setq org-read-date-overlay
15956 (make-overlay (1- (point-at-eol)) (point-at-eol)))
15957 (org-overlay-display org-read-date-overlay txt 'secondary-selection)))))
15959 (defun org-read-date-analyze (ans org-def org-defdecode)
15960 "Analyze the combined answer of the date prompt."
15961 ;; FIXME: cleanup and comment
15962 (let ((nowdecode (decode-time (current-time)))
15963 delta deltan deltaw deltadef year month day
15964 hour minute second wday pm h2 m2 tl wday1
15965 iso-year iso-weekday iso-week iso-year iso-date futurep kill-year)
15966 (setq org-read-date-analyze-futurep nil
15967 org-read-date-analyze-forced-year nil)
15968 (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans)
15971 (when (setq delta (org-read-date-get-relative ans (current-time) org-def))
15972 (setq ans (replace-match "" t t ans)
15974 deltaw (nth 1 delta)
15975 deltadef (nth 2 delta)))
15977 ;; Check if there is an iso week date in there. If yes, store the
15978 ;; info and postpone interpreting it until the rest of the parsing
15980 (when (string-match "\\<\\(?:\\([0-9]+\\)-\\)?[wW]\\([0-9]\\{1,2\\}\\)\\(?:-\\([0-6]\\)\\)?\\([ \t]\\|$\\)" ans)
15981 (setq iso-year (if (match-end 1)
15982 (org-small-year-to-year
15983 (string-to-number (match-string 1 ans))))
15984 iso-weekday (if (match-end 3)
15985 (string-to-number (match-string 3 ans)))
15986 iso-week (string-to-number (match-string 2 ans)))
15987 (setq ans (replace-match "" t t ans)))
15989 ;; Help matching ISO dates with single digit month or day, like 2006-8-11.
15990 (when (string-match
15991 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans)
15992 (setq year (if (match-end 2)
15993 (string-to-number (match-string 2 ans))
15994 (progn (setq kill-year t)
15995 (string-to-number (format-time-string "%Y"))))
15996 month (string-to-number (match-string 3 ans))
15997 day (string-to-number (match-string 4 ans)))
15998 (if (< year 100) (setq year (+ 2000 year)))
15999 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
16002 ;; Help matching dotted european dates
16003 (when (string-match
16004 "^ *\\(3[01]\\|0?[1-9]\\|[12][0-9]\\)\\. ?\\(0?[1-9]\\|1[012]\\)\\.\\( ?[1-9][0-9]\\{3\\}\\)?" ans)
16005 (setq year (if (match-end 3) (string-to-number (match-string 3 ans))
16007 (string-to-number (format-time-string "%Y")))
16008 day (string-to-number (match-string 1 ans))
16009 month (string-to-number (match-string 2 ans))
16010 ans (replace-match (format "%04d-%02d-%02d" year month day)
16013 ;; Help matching american dates, like 5/30 or 5/30/7
16014 (when (string-match
16015 "^ *\\(0?[1-9]\\|1[012]\\)/\\(0?[1-9]\\|[12][0-9]\\|3[01]\\)\\(/\\([0-9]+\\)\\)?\\([^/0-9]\\|$\\)" ans)
16016 (setq year (if (match-end 4)
16017 (string-to-number (match-string 4 ans))
16018 (progn (setq kill-year t)
16019 (string-to-number (format-time-string "%Y"))))
16020 month (string-to-number (match-string 1 ans))
16021 day (string-to-number (match-string 2 ans)))
16022 (if (< year 100) (setq year (+ 2000 year)))
16023 (setq ans (replace-match (format "%04d-%02d-%02d\\5" year month day)
16025 ;; Help matching am/pm times, because `parse-time-string' does not do that.
16026 ;; If there is a time with am/pm, and *no* time without it, we convert
16027 ;; so that matching will be successful.
16028 (loop for i from 1 to 2 do ; twice, for end time as well
16029 (when (and (not (string-match "\\(\\`\\|[^+]\\)[012]?[0-9]:[0-9][0-9]\\([ \t\n]\\|$\\)" ans))
16030 (string-match "\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\(am\\|AM\\|pm\\|PM\\)\\>" ans))
16031 (setq hour (string-to-number (match-string 1 ans))
16032 minute (if (match-end 3)
16033 (string-to-number (match-string 3 ans))
16036 (string-to-char (downcase (match-string 4 ans)))))
16037 (if (and (= hour 12) (not pm))
16039 (if (and pm (< hour 12)) (setq hour (+ 12 hour))))
16040 (setq ans (replace-match (format "%02d:%02d" hour minute)
16043 ;; Check if a time range is given as a duration
16044 (when (string-match "\\([012]?[0-9]\\):\\([0-6][0-9]\\)\\+\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?" ans)
16045 (setq hour (string-to-number (match-string 1 ans))
16046 h2 (+ hour (string-to-number (match-string 3 ans)))
16047 minute (string-to-number (match-string 2 ans))
16048 m2 (+ minute (if (match-end 5) (string-to-number
16049 (match-string 5 ans))0)))
16050 (if (>= m2 60) (setq h2 (1+ h2) m2 (- m2 60)))
16051 (setq ans (replace-match (format "%02d:%02d-%02d:%02d" hour minute h2 m2)
16054 ;; Check if there is a time range
16055 (when (boundp 'org-end-time-was-given)
16056 (setq org-time-was-given nil)
16057 (when (and (string-match org-plain-time-of-day-regexp ans)
16059 (setq org-end-time-was-given (match-string 8 ans))
16060 (setq ans (concat (substring ans 0 (match-beginning 7))
16061 (substring ans (match-end 7))))))
16063 (setq tl (parse-time-string ans)
16064 day (or (nth 3 tl) (nth 3 org-defdecode))
16065 month (or (nth 4 tl)
16066 (if (and org-read-date-prefer-future
16067 (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode)))
16068 (prog1 (1+ (nth 4 nowdecode)) (setq futurep t))
16069 (nth 4 org-defdecode)))
16070 year (or (and (not kill-year) (nth 5 tl))
16071 (if (and org-read-date-prefer-future
16072 (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode)))
16073 (prog1 (1+ (nth 5 nowdecode)) (setq futurep t))
16074 (nth 5 org-defdecode)))
16075 hour (or (nth 2 tl) (nth 2 org-defdecode))
16076 minute (or (nth 1 tl) (nth 1 org-defdecode))
16077 second (or (nth 0 tl) 0)
16080 (when (and (eq org-read-date-prefer-future 'time)
16081 (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl))
16082 (equal day (nth 3 nowdecode))
16083 (equal month (nth 4 nowdecode))
16084 (equal year (nth 5 nowdecode))
16086 (or (< (nth 2 tl) (nth 2 nowdecode))
16087 (and (= (nth 2 tl) (nth 2 nowdecode))
16089 (< (nth 1 tl) (nth 1 nowdecode)))))
16093 ;; Special date definitions below
16096 ;; There was an iso week
16099 (setq year (or iso-year year)
16100 day (or iso-weekday wday 1)
16101 wday nil ; to make sure that the trigger below does not match
16102 iso-date (calendar-gregorian-from-absolute
16103 (calendar-absolute-from-iso
16104 (list iso-week day year))))
16105 ; FIXME: Should we also push ISO weeks into the future?
16106 ; (when (and org-read-date-prefer-future
16108 ; (< (calendar-absolute-from-gregorian iso-date)
16109 ; (time-to-days (current-time))))
16110 ; (setq year (1+ year)
16111 ; iso-date (calendar-gregorian-from-absolute
16112 ; (calendar-absolute-from-iso
16113 ; (list iso-week day year)))))
16114 (setq month (car iso-date)
16115 year (nth 2 iso-date)
16116 day (nth 1 iso-date)))
16120 (let ((now (decode-time (current-time))))
16121 (setq day (nth 3 now) month (nth 4 now) year (nth 5 now))))
16122 (cond ((member deltaw '("d" "")) (setq day (+ day deltan)))
16123 ((equal deltaw "w") (setq day (+ day (* 7 deltan))))
16124 ((equal deltaw "m") (setq month (+ month deltan)))
16125 ((equal deltaw "y") (setq year (+ year deltan)))))
16126 ((and wday (not (nth 3 tl)))
16127 ;; Weekday was given, but no day, so pick that day in the week
16128 ;; on or after the derived date.
16129 (setq wday1 (nth 6 (decode-time (encode-time 0 0 0 day month year))))
16130 (unless (equal wday wday1)
16131 (setq day (+ day (% (- wday wday1 -7) 7))))))
16132 (if (and (boundp 'org-time-was-given)
16134 (setq org-time-was-given t))
16135 (if (< year 100) (setq year (+ 2000 year)))
16136 ;; Check of the date is representable
16137 (if org-read-date-force-compatible-dates
16140 (setq year 1970 org-read-date-analyze-forced-year t))
16142 (setq year 2037 org-read-date-analyze-forced-year t)))
16143 (condition-case nil
16144 (ignore (encode-time second minute hour day month year))
16146 (setq year (nth 5 org-defdecode))
16147 (setq org-read-date-analyze-forced-year t))))
16148 (setq org-read-date-analyze-futurep futurep)
16149 (list second minute hour day month year)))
16151 (defvar parse-time-weekdays)
16152 (defun org-read-date-get-relative (s today default)
16153 "Check string S for special relative date string.
16154 TODAY and DEFAULT are internal times, for today and for a default.
16155 Return shift list (N what def-flag)
16156 WHAT is \"d\", \"w\", \"m\", or \"y\" for day, week, month, year.
16157 N is the number of WHATs to shift.
16158 DEF-FLAG is t when a double ++ or -- indicates shift relative to
16159 the DEFAULT date rather than TODAY."
16160 (require 'parse-time)
16164 "\\`[ \t]*\\([-+]\\{0,2\\}\\)"
16166 "\\([hdwmy]\\|\\(" (mapconcat 'car parse-time-weekdays "\\|") "\\)\\)?"
16167 "\\([ \t]\\|$\\)") s)
16168 (or (> (match-end 1) (match-beginning 1)) (match-end 4)))
16169 (let* ((dir (if (> (match-end 1) (match-beginning 1))
16170 (string-to-char (substring (match-string 1 s) -1))
16172 (rel (and (match-end 1) (= 2 (- (match-end 1) (match-beginning 1)))))
16173 (n (if (match-end 2) (string-to-number (match-string 2 s)) 1))
16174 (what (if (match-end 3) (match-string 3 s) "d"))
16175 (wday1 (cdr (assoc (downcase what) parse-time-weekdays)))
16176 (date (if rel default today))
16177 (wday (nth 6 (decode-time date)))
16181 (setq delta (mod (+ 7 (- wday1 wday)) 7))
16182 (if (= dir ?-) (setq delta (- delta 7)))
16183 (if (> n 1) (setq delta (+ delta (* (1- n) (if (= dir ?-) -7 7)))))
16184 (list delta "d" rel))
16185 (list (* n (if (= dir ?-) -1 1)) what rel)))))
16187 (defun org-order-calendar-date-args (arg1 arg2 arg3)
16188 "Turn a user-specified date into the internal representation.
16189 The internal representation needed by the calendar is (month day year).
16190 This is a wrapper to handle the brain-dead convention in calendar that
16191 user function argument order change dependent on argument order."
16192 (if (boundp 'calendar-date-style)
16194 ((eq calendar-date-style 'american)
16195 (list arg1 arg2 arg3))
16196 ((eq calendar-date-style 'european)
16197 (list arg2 arg1 arg3))
16198 ((eq calendar-date-style 'iso)
16199 (list arg2 arg3 arg1)))
16200 (org-no-warnings ;; european-calendar-style is obsolete as of version 23.1
16201 (if (org-bound-and-true-p european-calendar-style)
16202 (list arg2 arg1 arg3)
16203 (list arg1 arg2 arg3)))))
16205 (defun org-eval-in-calendar (form &optional keepdate)
16206 "Eval FORM in the calendar window and return to current window.
16207 When KEEPDATE is non-nil, update `org-ans2' from the cursor date,
16208 otherwise stick to the current value of `org-ans2'."
16209 (let ((sf (selected-frame))
16210 (sw (selected-window)))
16211 (select-window (get-buffer-window "*Calendar*" t))
16213 (when (and (not keepdate) (calendar-cursor-to-date))
16214 (let* ((date (calendar-cursor-to-date))
16215 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
16216 (setq org-ans2 (format-time-string "%Y-%m-%d" time))))
16217 (move-overlay org-date-ovl (1- (point)) (1+ (point)) (current-buffer))
16219 (org-select-frame-set-input-focus sf)))
16221 (defun org-calendar-select ()
16222 "Return to `org-read-date' with the date currently selected.
16223 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
16225 (when (calendar-cursor-to-date)
16226 (let* ((date (calendar-cursor-to-date))
16227 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
16228 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
16229 (if (active-minibuffer-window) (exit-minibuffer))))
16231 (defun org-insert-time-stamp (time &optional with-hm inactive pre post extra)
16232 "Insert a date stamp for the date given by the internal TIME.
16233 WITH-HM means use the stamp format that includes the time of the day.
16234 INACTIVE means use square brackets instead of angular ones, so that the
16235 stamp will not contribute to the agenda.
16236 PRE and POST are optional strings to be inserted before and after the
16238 The command returns the inserted time stamp."
16239 (let ((fmt (funcall (if with-hm 'cdr 'car) org-time-stamp-formats))
16241 (if inactive (setq fmt (concat "[" (substring fmt 1 -1) "]")))
16242 (insert-before-markers (or pre ""))
16243 (when (listp extra)
16244 (setq extra (car extra))
16245 (if (and (stringp extra)
16246 (string-match "\\([0-9]+\\):\\([0-9]+\\)" extra))
16247 (setq extra (format "-%02d:%02d"
16248 (string-to-number (match-string 1 extra))
16249 (string-to-number (match-string 2 extra))))
16252 (setq fmt (concat (substring fmt 0 -1) extra (substring fmt -1))))
16253 (insert-before-markers (setq stamp (format-time-string fmt time)))
16254 (insert-before-markers (or post ""))
16255 (setq org-last-inserted-timestamp stamp)))
16257 (defun org-toggle-time-stamp-overlays ()
16258 "Toggle the use of custom time stamp formats."
16260 (setq org-display-custom-times (not org-display-custom-times))
16261 (unless org-display-custom-times
16262 (let ((p (point-min)) (bmp (buffer-modified-p)))
16263 (while (setq p (next-single-property-change p 'display))
16264 (if (and (get-text-property p 'display)
16265 (eq (get-text-property p 'face) 'org-date))
16266 (remove-text-properties
16267 p (setq p (next-single-property-change p 'display))
16269 (set-buffer-modified-p bmp)))
16270 (if (featurep 'xemacs)
16271 (remove-text-properties (point-min) (point-max) '(end-glyph t)))
16272 (org-restart-font-lock)
16273 (setq org-table-may-need-update t)
16274 (if org-display-custom-times
16275 (message "Time stamps are overlaid with custom format")
16276 (message "Time stamp overlays removed")))
16278 (defun org-display-custom-time (beg end)
16279 "Overlay modified time stamp format over timestamp between BEG and END."
16280 (let* ((ts (buffer-substring beg end))
16281 t1 w1 with-hm tf time str w2 (off 0))
16283 (setq t1 (org-parse-time-string ts t))
16284 (if (string-match "\\(-[0-9]+:[0-9]+\\)?\\( [.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)?\\'" ts)
16285 (setq off (- (match-end 0) (match-beginning 0)))))
16286 (setq end (- end off))
16287 (setq w1 (- end beg)
16288 with-hm (and (nth 1 t1) (nth 2 t1))
16289 tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
16290 time (org-fix-decoded-time t1)
16292 (format-time-string
16293 (substring tf 1 -1) (apply 'encode-time time))
16294 nil 'mouse-face 'highlight)
16296 (if (not (= w2 w1))
16297 (add-text-properties (1+ beg) (+ 2 beg)
16298 (list 'org-dwidth t 'org-dwidth-n (- w1 w2))))
16299 (if (featurep 'xemacs)
16301 (put-text-property beg end 'invisible t)
16302 (put-text-property beg end 'end-glyph (make-glyph str)))
16303 (put-text-property beg end 'display str))))
16305 (defun org-translate-time (string)
16306 "Translate all timestamps in STRING to custom format.
16307 But do this only if the variable `org-display-custom-times' is set."
16308 (when org-display-custom-times
16311 (re org-ts-regexp-both)
16312 t1 with-hm inactive tf time str beg end)
16313 (while (setq start (string-match re string start))
16314 (setq beg (match-beginning 0)
16316 t1 (save-match-data
16317 (org-parse-time-string (substring string beg end) t))
16318 with-hm (and (nth 1 t1) (nth 2 t1))
16319 inactive (equal (substring string beg (1+ beg)) "[")
16320 tf (funcall (if with-hm 'cdr 'car)
16321 org-time-stamp-custom-formats)
16322 time (org-fix-decoded-time t1)
16323 str (format-time-string
16325 (if inactive "[" "<") (substring tf 1 -1)
16326 (if inactive "]" ">"))
16327 (apply 'encode-time time))
16328 string (replace-match str t t string)
16329 start (+ start (length str)))))))
16332 (defun org-fix-decoded-time (time)
16333 "Set 0 instead of nil for the first 6 elements of time.
16334 Don't touch the rest."
16336 (mapcar (lambda (x) (if (< (setq n (1+ n)) 7) (or x 0) x)) time)))
16338 (define-obsolete-function-alias 'org-days-to-time 'org-time-stamp-to-now "24.3")
16340 (defun org-time-stamp-to-now (timestamp-string &optional seconds)
16341 "Difference between TIMESTAMP-STRING and now in days.
16342 If SECONDS is non-nil, return the difference in seconds."
16343 (let ((fdiff (if seconds 'org-float-time 'time-to-days)))
16344 (- (funcall fdiff (org-time-string-to-time timestamp-string))
16345 (funcall fdiff (current-time)))))
16347 (defun org-deadline-close (timestamp-string &optional ndays)
16348 "Is the time in TIMESTAMP-STRING close to the current date?"
16349 (setq ndays (or ndays (org-get-wdays timestamp-string)))
16350 (and (< (org-time-stamp-to-now timestamp-string) ndays)
16351 (not (org-entry-is-done-p))))
16353 (defun org-get-wdays (ts &optional delay zero-delay)
16354 "Get the deadline lead time appropriate for timestring TS.
16355 When DELAY is non-nil, get the delay time for scheduled items
16356 instead of the deadline lead time. When ZERO-DELAY is non-nil
16357 and `org-scheduled-delay-days' is 0, enforce 0 as the delay,
16358 don't try to find the delay cookie in the scheduled timestamp."
16359 (let ((tv (if delay org-scheduled-delay-days
16360 org-deadline-warning-days)))
16362 ((or (and delay (< tv 0))
16363 (and delay zero-delay (<= tv 0))
16364 (and (not delay) (<= tv 0)))
16365 ;; Enforce this value no matter what
16367 ((string-match "-\\([0-9]+\\)\\([hdwmy]\\)\\(\\'\\|>\\| \\)" ts)
16368 ;; lead time is specified.
16369 (floor (* (string-to-number (match-string 1 ts))
16370 (cdr (assoc (match-string 2 ts)
16371 '(("d" . 1) ("w" . 7)
16372 ("m" . 30.4) ("y" . 365.25)
16373 ("h" . 0.041667)))))))
16374 ;; go for the default.
16377 (defun org-calendar-select-mouse (ev)
16378 "Return to `org-read-date' with the date currently selected.
16379 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
16381 (mouse-set-point ev)
16382 (when (calendar-cursor-to-date)
16383 (let* ((date (calendar-cursor-to-date))
16384 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
16385 (setq org-ans1 (format-time-string "%Y-%m-%d" time)))
16386 (if (active-minibuffer-window) (exit-minibuffer))))
16388 (defun org-check-deadlines (ndays)
16389 "Check if there are any deadlines due or past due.
16390 A deadline is considered due if it happens within `org-deadline-warning-days'
16391 days from today's date. If the deadline appears in an entry marked DONE,
16392 it is not shown. The prefix arg NDAYS can be used to test that many
16393 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
16395 (let* ((org-warn-days
16397 ((equal ndays '(4)) 100000)
16398 (ndays (prefix-numeric-value ndays))
16399 (t (abs org-deadline-warning-days))))
16400 (case-fold-search nil)
16401 (regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
16403 (lambda () (org-deadline-close (match-string 1) org-warn-days))))
16405 (message "%d deadlines past-due or due within %d days"
16406 (org-occur regexp nil callback)
16409 (defsubst org-re-timestamp (type)
16410 "Return a regexp for timestamp TYPE.
16411 Allowed values for TYPE are:
16413 all: all timestamps
16414 active: only active timestamps (<...>)
16415 inactive: only inactive timestamps ([...])
16416 scheduled: only scheduled timestamps
16417 deadline: only deadline timestamps
16419 When TYPE is nil, fall back on returning a regexp that matches
16420 both scheduled and deadline timestamps."
16421 (cond ((eq type 'all) "\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\(?: +[^]+0-9>
\n -]+\\)?\\(?: +[0-9]\\{1,2\\}:[0-9]\\{2\\}\\)?\\)")
16422 ((eq type 'active) org-ts-regexp)
16423 ((eq type 'inactive) "\\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^
\n>]*?\\)\\]")
16424 ((eq type 'scheduled) (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>"))
16425 ((eq type 'deadline) (concat "\\<" org-deadline-string " *<\\([^>]+\\)>"))
16426 ((eq type 'scheduled-or-deadline)
16427 (concat "\\<\\(?:" org-deadline-string "\\|" org-scheduled-string "\\) *<\\([^>]+\\)>"))))
16429 (defun org-check-before-date (date)
16430 "Check if there are deadlines or scheduled entries before DATE."
16431 (interactive (list (org-read-date)))
16432 (let ((case-fold-search nil)
16433 (regexp (org-re-timestamp org-ts-type))
16435 (lambda () (time-less-p
16436 (org-time-string-to-time (match-string 1))
16437 (org-time-string-to-time date)))))
16438 (message "%d entries before %s"
16439 (org-occur regexp nil callback) date)))
16441 (defun org-check-after-date (date)
16442 "Check if there are deadlines or scheduled entries after DATE."
16443 (interactive (list (org-read-date)))
16444 (let ((case-fold-search nil)
16445 (regexp (org-re-timestamp org-ts-type))
16449 (org-time-string-to-time (match-string 1))
16450 (org-time-string-to-time date))))))
16451 (message "%d entries after %s"
16452 (org-occur regexp nil callback) date)))
16454 (defun org-check-dates-range (start-date end-date)
16455 "Check for deadlines/scheduled entries between START-DATE and END-DATE."
16456 (interactive (list (org-read-date nil nil nil "Range starts")
16457 (org-read-date nil nil nil "Range end")))
16458 (let ((case-fold-search nil)
16459 (regexp (org-re-timestamp org-ts-type))
16462 (let ((match (match-string 1)))
16465 (org-time-string-to-time match)
16466 (org-time-string-to-time start-date)))
16468 (org-time-string-to-time match)
16469 (org-time-string-to-time end-date)))))))
16470 (message "%d entries between %s and %s"
16471 (org-occur regexp nil callback) start-date end-date)))
16473 (defun org-evaluate-time-range (&optional to-buffer)
16474 "Evaluate a time range by computing the difference between start and end.
16475 Normally the result is just printed in the echo area, but with prefix arg
16476 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
16477 If the time range is actually in a table, the result is inserted into the
16479 For time difference computation, a year is assumed to be exactly 365
16480 days in order to avoid rounding problems."
16483 (org-clock-update-time-maybe)
16485 (unless (org-at-date-range-p t)
16486 (goto-char (point-at-bol))
16487 (re-search-forward org-tr-regexp-both (point-at-eol) t))
16488 (if (not (org-at-date-range-p t))
16489 (error "Not at a time-stamp range, and none found in current line")))
16490 (let* ((ts1 (match-string 1))
16491 (ts2 (match-string 2))
16492 (havetime (or (> (length ts1) 15) (> (length ts2) 15)))
16493 (match-end (match-end 0))
16494 (time1 (org-time-string-to-time ts1))
16495 (time2 (org-time-string-to-time ts2))
16496 (t1 (org-float-time time1))
16497 (t2 (org-float-time time2))
16498 (diff (abs (- t2 t1)))
16499 (negative (< (- t2 t1) 0))
16500 ;; (ys (floor (* 365 24 60 60)))
16503 (fy "%dy %dd %02d:%02d")
16505 (fd "%dd %02d:%02d")
16510 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
16512 d (floor (/ diff ds)) diff (mod diff ds)
16513 h (floor (/ diff hs)) diff (mod diff hs)
16514 m (floor (/ diff 60)))
16515 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
16517 d (floor (+ (/ diff ds) 0.5))
16519 (if (not to-buffer)
16520 (message "%s" (org-make-tdiff-string y d h m))
16521 (if (org-at-table-p)
16523 (goto-char match-end)
16525 (and (looking-at " *|") (goto-char (match-end 0))))
16526 (goto-char match-end))
16528 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
16529 (replace-match ""))
16530 (if negative (insert " -"))
16531 (if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
16532 (if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
16533 (insert " " (format fh h m))))
16534 (if align (org-table-align))
16535 (message "Time difference inserted")))))
16537 (defun org-make-tdiff-string (y d h m)
16540 (if (> y 0) (setq fmt (concat fmt "%d year" (if (> y 1) "s" "") " ")
16542 (if (> d 0) (setq fmt (concat fmt "%d day" (if (> d 1) "s" "") " ")
16544 (if (> h 0) (setq fmt (concat fmt "%d hour" (if (> h 1) "s" "") " ")
16546 (if (> m 0) (setq fmt (concat fmt "%d minute" (if (> m 1) "s" "") " ")
16548 (apply 'format fmt (nreverse l))))
16550 (defun org-time-string-to-time (s &optional buffer pos)
16551 "Convert a timestamp string into internal time."
16552 (condition-case errdata
16553 (apply 'encode-time (org-parse-time-string s))
16554 (error (error "Bad timestamp `%s'%s\nError was: %s"
16555 s (if (not (and buffer pos))
16557 (format " at %d in buffer `%s'" pos buffer))
16560 (defun org-time-string-to-seconds (s)
16561 "Convert a timestamp string to a number of seconds."
16562 (org-float-time (org-time-string-to-time s)))
16564 (defun org-time-string-to-absolute (s &optional daynr prefer show-all buffer pos)
16565 "Convert a time stamp to an absolute day number.
16566 If there is a specifier for a cyclic time stamp, get the closest
16568 PREFER and SHOW-ALL are passed through to `org-closest-date'.
16569 The variable date is bound by the calendar when this is called."
16571 ((and daynr (string-match "\\`%%\\((.*)\\)" s))
16572 (if (org-diary-sexp-entry (match-string 1 s) "" date)
16575 ((and daynr (string-match "\\+[0-9]+[hdwmy]" s))
16576 (org-closest-date s (if (and (boundp 'daynr) (integerp daynr)) daynr
16577 (time-to-days (current-time))) (match-string 0 s)
16580 (condition-case errdata
16581 (apply 'encode-time (org-parse-time-string s))
16582 (error (error "Bad timestamp `%s'%s\nError was: %s"
16583 s (if (not (and buffer pos))
16585 (format " at %d in buffer `%s'" pos buffer))
16586 (cdr errdata))))))))
16588 (defun org-days-to-iso-week (days)
16589 "Return the iso week number."
16591 (car (calendar-iso-from-absolute days)))
16593 (defun org-small-year-to-year (year)
16594 "Convert 2-digit years into 4-digit years.
16595 38-99 are mapped into 1938-1999. 1-37 are mapped into 2001-2007.
16596 The year 2000 cannot be abbreviated. Any year larger than 99
16597 is returned unchanged."
16599 (setq year (+ 2000 year))
16601 (setq year (+ 1900 year))))
16604 (defun org-time-from-absolute (d)
16605 "Return the time corresponding to date D.
16606 D may be an absolute day number, or a calendar-type list (month day year)."
16607 (if (numberp d) (setq d (calendar-gregorian-from-absolute d)))
16608 (encode-time 0 0 0 (nth 1 d) (car d) (nth 2 d)))
16610 (defun org-calendar-holiday ()
16611 "List of holidays, for Diary display in Org-mode."
16612 (require 'holidays)
16614 (if (fboundp 'calendar-check-holidays)
16615 'calendar-check-holidays 'check-calendar-holidays) date)))
16616 (if hl (mapconcat 'identity hl "; "))))
16618 (defun org-diary-sexp-entry (sexp entry date)
16619 "Process a SEXP diary ENTRY for DATE."
16620 (require 'diary-lib)
16621 (let ((result (if calendar-debug-sexp
16622 (let ((stack-trace-on-error t))
16623 (eval (car (read-from-string sexp))))
16624 (condition-case nil
16625 (eval (car (read-from-string sexp)))
16628 (message "Bad sexp at line %d in %s: %s"
16630 (buffer-file-name) sexp)
16632 (cond ((stringp result) (split-string result "; "))
16633 ((and (consp result)
16634 (not (consp (cdr result)))
16635 (stringp (cdr result))) (cdr result))
16636 ((and (consp result)
16637 (stringp (car result))) result)
16640 (defun org-diary-to-ical-string (frombuf)
16641 "Get iCalendar entries from diary entries in buffer FROMBUF.
16642 This uses the icalendar.el library."
16643 (let* ((tmpdir (if (featurep 'xemacs)
16645 temporary-file-directory))
16646 (tmpfile (make-temp-name
16647 (expand-file-name "orgics" tmpdir)))
16649 (with-current-buffer frombuf
16650 (icalendar-export-region (point-min) (point-max) tmpfile)
16651 (setq buf (find-buffer-visiting tmpfile))
16653 (goto-char (point-min))
16654 (if (re-search-forward "^BEGIN:VEVENT" nil t)
16655 (setq b (match-beginning 0)))
16656 (goto-char (point-max))
16657 (if (re-search-backward "^END:VEVENT" nil t)
16658 (setq e (match-end 0)))
16659 (setq rtn (if (and b e) (concat (buffer-substring b e) "\n") "")))
16661 (delete-file tmpfile)
16664 (defun org-closest-date (start current change prefer show-all)
16665 "Find the date closest to CURRENT that is consistent with START and CHANGE.
16666 When PREFER is `past', return a date that is either CURRENT or past.
16667 When PREFER is `future', return a date that is either CURRENT or future.
16668 When SHOW-ALL is nil, only return the current occurrence of a time stamp."
16669 ;; Make the proper lists from the dates
16671 (let ((a1 '(("h" . hour)
16676 (shour (nth 2 (org-parse-time-string start)))
16677 dn dw sday cday n1 n2 n0
16678 d m y y1 y2 date1 date2 nmonths nm ny m2)
16680 (setq start (org-date-to-gregorian start)
16681 current (org-date-to-gregorian
16684 (time-to-days (current-time))))
16685 sday (calendar-absolute-from-gregorian start)
16686 cday (calendar-absolute-from-gregorian current))
16688 (if (<= cday sday) (throw 'exit sday))
16690 (if (string-match "\\(\\+[0-9]+\\)\\([hdwmy]\\)" change)
16691 (setq dn (string-to-number (match-string 1 change))
16692 dw (cdr (assoc (match-string 2 change) a1)))
16693 (error "Invalid change specifier: %s" change))
16694 (if (eq dw 'week) (setq dw 'day dn (* 7 dn)))
16697 (let ((missing-hours
16698 (mod (+ (- (* 24 (- cday sday)) shour) org-extend-today-until)
16700 (setq n1 (if (zerop missing-hours) cday
16701 (- cday (1+ (floor (/ missing-hours 24)))))
16702 n2 (+ cday (floor (/ (- dn missing-hours) 24))))))
16704 (setq n1 (+ sday (* dn (floor (/ (- cday sday) dn))))
16707 (setq d (nth 1 start) m (car start) y1 (nth 2 start) y2 (nth 2 current))
16708 (setq y1 (+ (* (floor (/ (- y2 y1) dn)) dn) y1))
16709 (setq date1 (list m d y1)
16710 n1 (calendar-absolute-from-gregorian date1)
16711 date2 (list m d (+ y1 (* (if (< n1 cday) 1 -1) dn)))
16712 n2 (calendar-absolute-from-gregorian date2)))
16714 ;; approx number of month between the two dates
16715 (setq nmonths (floor (/ (- cday sday) 30.436875)))
16716 ;; How often does dn fit in there?
16717 (setq d (nth 1 start) m (car start) y (nth 2 start)
16718 nm (* dn (max 0 (1- (floor (/ nmonths dn)))))
16720 ny (floor (/ m 12))
16723 (while (> m 12) (setq m (- m 12) y (1+ y)))
16724 (setq n1 (calendar-absolute-from-gregorian (list m d y)))
16725 (setq m2 (+ m dn) y2 y)
16726 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
16727 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2)))
16728 (while (<= n2 cday)
16729 (setq n1 n2 m m2 y y2)
16730 (setq m2 (+ m dn) y2 y)
16731 (if (> m2 12) (setq y2 (1+ y2) m2 (- m2 12)))
16732 (setq n2 (calendar-absolute-from-gregorian (list m2 d y2))))))
16733 ;; Make sure n1 is the earlier date
16734 (setq n0 n1 n1 (min n1 n2) n2 (max n0 n2))
16737 ((eq prefer 'past) (if (= cday n2) n2 n1))
16738 ((eq prefer 'future) (if (= cday n1) n1 n2))
16739 (t (if (> (abs (- cday n1)) (abs (- cday n2))) n2 n1)))
16741 ((eq prefer 'past) (if (= cday n2) n2 n1))
16742 ((eq prefer 'future) (if (= cday n1) n1 n2))
16743 (t (if (= cday n1) n1 n2)))))))
16745 (defun org-date-to-gregorian (date)
16746 "Turn any specification of DATE into a Gregorian date for the calendar."
16747 (cond ((integerp date) (calendar-gregorian-from-absolute date))
16748 ((and (listp date) (= (length date) 3)) date)
16750 (setq date (org-parse-time-string date))
16751 (list (nth 4 date) (nth 3 date) (nth 5 date)))
16753 (list (nth 4 date) (nth 3 date) (nth 5 date)))))
16755 (defun org-parse-time-string (s &optional nodefault)
16756 "Parse the standard Org-mode time string.
16757 This should be a lot faster than the normal `parse-time-string'.
16758 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
16759 hour and minute fields will be nil if not given."
16760 (cond ((string-match org-ts-regexp0 s)
16762 (if (or (match-beginning 8) (not nodefault))
16763 (string-to-number (or (match-string 8 s) "0")))
16764 (if (or (match-beginning 7) (not nodefault))
16765 (string-to-number (or (match-string 7 s) "0")))
16766 (string-to-number (match-string 4 s))
16767 (string-to-number (match-string 3 s))
16768 (string-to-number (match-string 2 s))
16770 ((string-match "^<[^>]+>$" s)
16771 (decode-time (seconds-to-time (org-matcher-time s))))
16772 (t (error "Not a standard Org-mode time string: %s" s))))
16774 (defun org-timestamp-up (&optional arg)
16775 "Increase the date item at the cursor by one.
16776 If the cursor is on the year, change the year. If it is on the month,
16777 the day or the time, change that.
16778 With prefix ARG, change by that many units."
16780 (org-timestamp-change (prefix-numeric-value arg) nil 'updown))
16782 (defun org-timestamp-down (&optional arg)
16783 "Decrease the date item at the cursor by one.
16784 If the cursor is on the year, change the year. If it is on the month,
16785 the day or the time, change that.
16786 With prefix ARG, change by that many units."
16788 (org-timestamp-change (- (prefix-numeric-value arg)) nil 'updown))
16790 (defun org-timestamp-up-day (&optional arg)
16791 "Increase the date in the time stamp by one day.
16792 With prefix ARG, change that many days."
16794 (if (and (not (org-at-timestamp-p t))
16795 (org-at-heading-p))
16797 (org-timestamp-change (prefix-numeric-value arg) 'day 'updown)))
16799 (defun org-timestamp-down-day (&optional arg)
16800 "Decrease the date in the time stamp by one day.
16801 With prefix ARG, change that many days."
16803 (if (and (not (org-at-timestamp-p t))
16804 (org-at-heading-p))
16806 (org-timestamp-change (- (prefix-numeric-value arg)) 'day) 'updown))
16808 (defun org-at-timestamp-p (&optional inactive-ok)
16809 "Determine if the cursor is in or at a timestamp."
16811 (let* ((tsr (if inactive-ok org-ts-regexp3 org-ts-regexp2))
16813 (ans (or (looking-at tsr)
16815 (skip-chars-backward "^[<\n\r\t")
16816 (if (> (point) (point-min)) (backward-char 1))
16817 (and (looking-at tsr)
16818 (> (- (match-end 0) pos) -1))))))
16820 (boundp 'org-ts-what)
16823 ((= pos (match-beginning 0)) 'bracket)
16824 ;; Point is considered to be "on the bracket" whether
16825 ;; it's really on it or right after it.
16826 ((= pos (1- (match-end 0))) 'bracket)
16827 ((= pos (match-end 0)) 'after)
16828 ((org-pos-in-match-range pos 2) 'year)
16829 ((org-pos-in-match-range pos 3) 'month)
16830 ((org-pos-in-match-range pos 7) 'hour)
16831 ((org-pos-in-match-range pos 8) 'minute)
16832 ((or (org-pos-in-match-range pos 4)
16833 (org-pos-in-match-range pos 5)) 'day)
16834 ((and (> pos (or (match-end 8) (match-end 5)))
16835 (< pos (match-end 0)))
16836 (- pos (or (match-end 8) (match-end 5))))
16840 (defun org-toggle-timestamp-type ()
16841 "Toggle the type (<active> or [inactive]) of a time stamp."
16843 (when (org-at-timestamp-p t)
16844 (let ((beg (match-beginning 0)) (end (match-end 0))
16845 (map '((?\[ . "<") (?\] . ">") (?< . "[") (?> . "]"))))
16848 (while (re-search-forward "[][<>]" end t)
16849 (replace-match (cdr (assoc (char-after (match-beginning 0)) map))
16851 (message "Timestamp is now %sactive"
16852 (if (equal (char-after beg) ?<) "" "in")))))
16854 (defvar org-clock-history) ; defined in org-clock.el
16855 (defvar org-clock-adjust-closest nil) ; defined in org-clock.el
16856 (defun org-timestamp-change (n &optional what updown suppress-tmp-delay)
16857 "Change the date in the time stamp at point.
16858 The date will be changed by N times WHAT. WHAT can be `day', `month',
16859 `year', `minute', `second'. If WHAT is not given, the cursor position
16860 in the timestamp determines what will be changed.
16861 When SUPPRESS-TMP-DELAY is non-nil, suppress delays like \"--2d\"."
16862 (let ((origin (point)) origin-cat
16864 (dm (max (nth 1 org-time-stamp-rounding-minutes) 1))
16867 ts time time0 fixnext clrgx)
16868 (if (not (org-at-timestamp-p t))
16869 (error "Not at a timestamp"))
16870 (if (and (not what) (eq org-ts-what 'bracket))
16871 (org-toggle-timestamp-type)
16872 ;; Point isn't on brackets. Remember the part of the time-stamp
16873 ;; the point was in. Indeed, size of time-stamps may change,
16874 ;; but point must be kept in the same category nonetheless.
16875 (setq origin-cat org-ts-what)
16876 (if (and (not what) (not (eq org-ts-what 'day))
16877 org-display-custom-times
16878 (get-text-property (point) 'display)
16879 (not (get-text-property (1- (point)) 'display)))
16880 (setq org-ts-what 'day))
16881 (setq org-ts-what (or what org-ts-what)
16882 inactive (= (char-after (match-beginning 0)) ?\[)
16883 ts (match-string 0))
16885 (when (string-match
16886 "\\(\\(-[012][0-9]:[0-5][0-9]\\)?\\( +[.+]?-?[-+][0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)*\\)[]>]"
16888 (setq extra (match-string 1 ts))
16889 (if suppress-tmp-delay
16890 (setq extra (replace-regexp-in-string " --[0-9]+[hdwmy]" "" extra))))
16891 (if (string-match "^.\\{10\\}.*?[0-9]+:[0-9][0-9]" ts)
16893 (setq time0 (org-parse-time-string ts))
16895 (eq org-ts-what 'minute)
16896 (not current-prefix-arg))
16897 ;; This looks like s-up and s-down. Change by one rounding step.
16898 (setq n (* dm (cond ((> n 0) 1) ((< n 0) -1) (t 0))))
16899 (when (not (= 0 (setq rem (% (nth 1 time0) dm))))
16900 (setcar (cdr time0) (+ (nth 1 time0)
16901 (if (> n 0) (- rem) (- dm rem))))))
16903 (encode-time (or (car time0) 0)
16904 (+ (if (eq org-ts-what 'minute) n 0) (nth 1 time0))
16905 (+ (if (eq org-ts-what 'hour) n 0) (nth 2 time0))
16906 (+ (if (eq org-ts-what 'day) n 0) (nth 3 time0))
16907 (+ (if (eq org-ts-what 'month) n 0) (nth 4 time0))
16908 (+ (if (eq org-ts-what 'year) n 0) (nth 5 time0))
16910 (when (and (member org-ts-what '(hour minute))
16912 (string-match "-\\([012][0-9]\\):\\([0-5][0-9]\\)" extra))
16913 (setq extra (org-modify-ts-extra
16915 (if (eq org-ts-what 'hour) 2 5)
16917 (when (integerp org-ts-what)
16918 (setq extra (org-modify-ts-extra extra org-ts-what n dm)))
16919 (if (eq what 'calendar)
16920 (let ((cal-date (org-get-date-from-calendar)))
16921 (setcar (nthcdr 4 time0) (nth 0 cal-date)) ; month
16922 (setcar (nthcdr 3 time0) (nth 1 cal-date)) ; day
16923 (setcar (nthcdr 5 time0) (nth 2 cal-date)) ; year
16924 (setcar time0 (or (car time0) 0))
16925 (setcar (nthcdr 1 time0) (or (nth 1 time0) 0))
16926 (setcar (nthcdr 2 time0) (or (nth 2 time0) 0))
16927 (setq time (apply 'encode-time time0))))
16928 ;; Insert the new time-stamp, and ensure point stays in the same
16929 ;; category as before (i.e. not after the last position in that
16931 (let ((pos (point)))
16932 ;; Stay before inserted string. `save-excursion' is of no use.
16933 (setq org-last-changed-timestamp
16934 (org-insert-time-stamp time with-hm inactive nil nil extra))
16937 (looking-at org-ts-regexp3)
16939 ;; `day' category ends before `hour' if any, or at
16940 ;; the end of the day name.
16941 ((eq origin-cat 'day)
16942 (min (or (match-beginning 7) (1- (match-end 5))) origin))
16943 ((eq origin-cat 'hour) (min (match-end 7) origin))
16944 ((eq origin-cat 'minute) (min (1- (match-end 8)) origin))
16945 ((integerp origin-cat) (min (1- (match-end 0)) origin))
16946 ;; `year' and `month' have both fixed size: point
16947 ;; couldn't have moved into another part.
16949 ;; Update clock if on a CLOCK line.
16950 (org-clock-update-time-maybe)
16951 ;; Maybe adjust the closest clock in `org-clock-history'
16952 (when org-clock-adjust-closest
16953 (if (not (and (org-at-clock-log-p)
16954 (< 1 (length (delq nil (mapcar (lambda(m) (marker-position m))
16955 org-clock-history))))))
16956 (message "No clock to adjust")
16957 (cond ((save-excursion ; fix previous clock?
16958 (re-search-backward org-ts-regexp0 nil t)
16959 (org-looking-back (concat org-clock-string " \\[")))
16960 (setq fixnext 1 clrgx (concat org-ts-regexp0 "\\] =>.*$")))
16961 ((save-excursion ; fix next clock?
16962 (re-search-backward org-ts-regexp0 nil t)
16963 (looking-at (concat org-ts-regexp0 "\\] =>")))
16964 (setq fixnext -1 clrgx (concat org-clock-string " \\[" org-ts-regexp0))))
16965 (save-window-excursion
16966 ;; Find closest clock to point, adjust the previous/next one in history
16967 (let* ((p (save-excursion (org-back-to-heading t)))
16968 (cl (mapcar (lambda(c) (abs (- (marker-position c) p))) org-clock-history))
16970 (+ fixnext (- (length cl) (or (length (member (apply #'min cl) cl)) 100))))
16971 (clfixpos (if (> 0 clfixnth) nil (nth clfixnth org-clock-history))))
16973 (message "No clock to adjust")
16975 (org-goto-marker-or-bmk clfixpos)
16977 (when (re-search-forward clrgx nil t)
16978 (goto-char (match-beginning 1))
16979 (let (org-clock-adjust-closest)
16980 (org-timestamp-change n org-ts-what updown))
16981 (message "Clock adjusted in %s for heading: %s"
16982 (file-name-nondirectory (buffer-file-name))
16983 (org-get-heading t t)))))))))
16984 ;; Try to recenter the calendar window, if any.
16985 (if (and org-calendar-follow-timestamp-change
16986 (get-buffer-window "*Calendar*" t)
16987 (memq org-ts-what '(day month year)))
16988 (org-recenter-calendar (time-to-days time))))))
16990 (defun org-modify-ts-extra (s pos n dm)
16991 "Change the different parts of the lead-time and repeat fields in timestamp."
16992 (let ((idx '(("d" . 0) ("w" . 1) ("m" . 2) ("y" . 3) ("d" . -1) ("y" . 4)))
16994 (when (string-match "\\(-\\([012][0-9]\\):\\([0-5][0-9]\\)\\)?\\( +\\+\\([0-9]+\\)\\([dmwy]\\)\\)?\\( +-\\([0-9]+\\)\\([dmwy]\\)\\)?" s)
16996 ((or (org-pos-in-match-range pos 2)
16997 (org-pos-in-match-range pos 3))
16998 (setq m (string-to-number (match-string 3 s))
16999 h (string-to-number (match-string 2 s)))
17000 (if (org-pos-in-match-range pos 2)
17002 (setq n (* dm (org-no-warnings (signum n))))
17003 (when (not (= 0 (setq rem (% m dm))))
17004 (setq m (+ m (if (> n 0) (- rem) (- dm rem)))))
17006 (if (< m 0) (setq m (+ m 60) h (1- h)))
17007 (if (> m 59) (setq m (- m 60) h (1+ h)))
17008 (setq h (min 24 (max 0 h)))
17009 (setq ng 1 new (format "-%02d:%02d" h m)))
17010 ((org-pos-in-match-range pos 6)
17011 (setq ng 6 new (car (rassoc (+ n (cdr (assoc (match-string 6 s) idx))) idx))))
17012 ((org-pos-in-match-range pos 5)
17013 (setq ng 5 new (format "%d" (max 1 (+ n (string-to-number (match-string 5 s)))))))
17015 ((org-pos-in-match-range pos 9)
17016 (setq ng 9 new (car (rassoc (+ n (cdr (assoc (match-string 9 s) idx))) idx))))
17017 ((org-pos-in-match-range pos 8)
17018 (setq ng 8 new (format "%d" (max 0 (+ n (string-to-number (match-string 8 s))))))))
17022 (substring s 0 (match-beginning ng))
17024 (substring s (match-end ng))))))
17027 (defun org-recenter-calendar (date)
17028 "If the calendar is visible, recenter it to DATE."
17029 (let ((cwin (get-buffer-window "*Calendar*" t)))
17031 (let ((calendar-move-hook nil))
17032 (with-selected-window cwin
17033 (calendar-goto-date (if (listp date) date
17034 (calendar-gregorian-from-absolute date))))))))
17036 (defun org-goto-calendar (&optional arg)
17037 "Go to the Emacs calendar at the current date.
17038 If there is a time stamp in the current line, go to that date.
17039 A prefix ARG can be used to force the current date."
17041 (let ((tsr org-ts-regexp) diff
17042 (calendar-move-hook nil)
17043 (calendar-view-holidays-initially-flag nil)
17044 (calendar-view-diary-initially-flag nil))
17045 (if (or (org-at-timestamp-p)
17047 (beginning-of-line 1)
17048 (looking-at (concat ".*" tsr))))
17049 (let ((d1 (time-to-days (current-time)))
17051 (org-time-string-to-time (match-string 1)))))
17052 (setq diff (- d2 d1))))
17054 (calendar-goto-today)
17055 (if (and diff (not arg)) (calendar-forward-day diff))))
17057 (defun org-get-date-from-calendar ()
17058 "Return a list (month day year) of date at point in calendar."
17059 (with-current-buffer "*Calendar*"
17061 (calendar-cursor-to-date))))
17063 (defun org-date-from-calendar ()
17064 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
17065 If there is already a time stamp at the cursor position, update it."
17067 (if (org-at-timestamp-p t)
17068 (org-timestamp-change 0 'calendar)
17069 (let ((cal-date (org-get-date-from-calendar)))
17070 (org-insert-time-stamp
17071 (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
17073 (defcustom org-effort-durations
17076 ("w" . ,(* 60 8 5))
17077 ("m" . ,(* 60 8 5 4))
17078 ("y" . ,(* 60 8 5 40)))
17079 "Conversion factor to minutes for an effort modifier.
17081 Each entry has the form (MODIFIER . MINUTES).
17083 In an effort string, a number followed by MODIFIER is multiplied
17084 by the specified number of MINUTES to obtain an effort in
17087 For example, if the value of this variable is ((\"hours\" . 60)), then an
17088 effort string \"2hours\" is equivalent to 120 minutes."
17091 :type '(alist :key-type (string :tag "Modifier")
17092 :value-type (number :tag "Minutes")))
17094 (defun org-minutes-to-clocksum-string (m)
17095 "Format number of minutes as a clocksum string.
17096 The format is determined by `org-time-clocksum-format',
17097 `org-time-clocksum-use-fractional' and
17098 `org-time-clocksum-fractional-format' and
17099 `org-time-clocksum-use-effort-durations'."
17100 (let ((clocksum "") h d w mo y fmt n)
17101 (setq h (if org-time-clocksum-use-effort-durations
17102 (cdr (assoc "h" org-effort-durations)) 60)
17103 d (if org-time-clocksum-use-effort-durations
17104 (/ (cdr (assoc "d" org-effort-durations)) h) 24)
17105 w (if org-time-clocksum-use-effort-durations
17106 (/ (cdr (assoc "w" org-effort-durations)) (* d h)) 7)
17107 mo (if org-time-clocksum-use-effort-durations
17108 (/ (cdr (assoc "m" org-effort-durations)) (* d h)) 30)
17109 y (if org-time-clocksum-use-effort-durations
17110 (/ (cdr (assoc "y" org-effort-durations)) (* d h)) 365))
17111 ;; fractional format
17112 (if org-time-clocksum-use-fractional
17114 ;; single format string
17115 ((stringp org-time-clocksum-fractional-format)
17116 (format org-time-clocksum-fractional-format (/ m (float h))))
17117 ;; choice of fractional formats for different time units
17118 ((and (setq fmt (plist-get org-time-clocksum-fractional-format :years))
17119 (> (/ (truncate m) (* y d h)) 0))
17120 (format fmt (/ m (* y d (float h)))))
17121 ((and (setq fmt (plist-get org-time-clocksum-fractional-format :months))
17122 (> (/ (truncate m) (* mo d h)) 0))
17123 (format fmt (/ m (* mo d (float h)))))
17124 ((and (setq fmt (plist-get org-time-clocksum-fractional-format :weeks))
17125 (> (/ (truncate m) (* w d h)) 0))
17126 (format fmt (/ m (* w d (float h)))))
17127 ((and (setq fmt (plist-get org-time-clocksum-fractional-format :days))
17128 (> (/ (truncate m) (* d h)) 0))
17129 (format fmt (/ m (* d (float h)))))
17130 ((and (setq fmt (plist-get org-time-clocksum-fractional-format :hours))
17131 (> (/ (truncate m) h) 0))
17132 (format fmt (/ m (float h))))
17133 ((setq fmt (plist-get org-time-clocksum-fractional-format :minutes))
17135 ;; fall back to smallest time unit with a format
17136 ((setq fmt (plist-get org-time-clocksum-fractional-format :hours))
17137 (format fmt (/ m (float h))))
17138 ((setq fmt (plist-get org-time-clocksum-fractional-format :days))
17139 (format fmt (/ m (* d (float h)))))
17140 ((setq fmt (plist-get org-time-clocksum-fractional-format :weeks))
17141 (format fmt (/ m (* w d (float h)))))
17142 ((setq fmt (plist-get org-time-clocksum-fractional-format :months))
17143 (format fmt (/ m (* mo d (float h)))))
17144 ((setq fmt (plist-get org-time-clocksum-fractional-format :years))
17145 (format fmt (/ m (* y d (float h))))))
17146 ;; standard (non-fractional) format, with single format string
17147 (if (stringp org-time-clocksum-format)
17148 (format org-time-clocksum-format (setq n (/ m h)) (- m (* h n)))
17149 ;; separate formats components
17150 (and (setq fmt (plist-get org-time-clocksum-format :years))
17151 (or (> (setq n (/ (truncate m) (* y d h))) 0)
17152 (plist-get org-time-clocksum-format :require-years))
17153 (setq clocksum (concat clocksum (format fmt n))
17154 m (- m (* n y d h))))
17155 (and (setq fmt (plist-get org-time-clocksum-format :months))
17156 (or (> (setq n (/ (truncate m) (* mo d h))) 0)
17157 (plist-get org-time-clocksum-format :require-months))
17158 (setq clocksum (concat clocksum (format fmt n))
17159 m (- m (* n mo d h))))
17160 (and (setq fmt (plist-get org-time-clocksum-format :weeks))
17161 (or (> (setq n (/ (truncate m) (* w d h))) 0)
17162 (plist-get org-time-clocksum-format :require-weeks))
17163 (setq clocksum (concat clocksum (format fmt n))
17164 m (- m (* n w d h))))
17165 (and (setq fmt (plist-get org-time-clocksum-format :days))
17166 (or (> (setq n (/ (truncate m) (* d h))) 0)
17167 (plist-get org-time-clocksum-format :require-days))
17168 (setq clocksum (concat clocksum (format fmt n))
17169 m (- m (* n d h))))
17170 (and (setq fmt (plist-get org-time-clocksum-format :hours))
17171 (or (> (setq n (/ (truncate m) h)) 0)
17172 (plist-get org-time-clocksum-format :require-hours))
17173 (setq clocksum (concat clocksum (format fmt n))
17175 (and (setq fmt (plist-get org-time-clocksum-format :minutes))
17176 (or (> m 0) (plist-get org-time-clocksum-format :require-minutes))
17177 (setq clocksum (concat clocksum (format fmt m))))
17178 ;; return formatted time duration
17181 (defalias 'org-minutes-to-hh:mm-string 'org-minutes-to-clocksum-string)
17182 (make-obsolete 'org-minutes-to-hh:mm-string 'org-minutes-to-clocksum-string
17183 "Org mode version 8.0")
17185 (defun org-hours-to-clocksum-string (n)
17186 (org-minutes-to-clocksum-string (* n 60)))
17188 (defun org-hh:mm-string-to-minutes (s)
17189 "Convert a string H:MM to a number of minutes.
17190 If the string is just a number, interpret it as minutes.
17191 In fact, the first hh:mm or number in the string will be taken,
17192 there can be extra stuff in the string.
17193 If no number is found, the return value is 0."
17196 ((string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
17197 (+ (* (string-to-number (match-string 1 s)) 60)
17198 (string-to-number (match-string 2 s))))
17199 ((string-match "\\([0-9]+\\)" s)
17200 (string-to-number (match-string 1 s)))
17203 (defcustom org-image-actual-width t
17204 "Should we use the actual width of images when inlining them?
17206 When set to `t', always use the image width.
17208 When set to a number, use imagemagick (when available) to set
17209 the image's width to this value.
17211 When set to a number in a list, try to get the width from the
17212 #+ATTR.* keyword if it matches a width specification like
17213 width=\"[0-9]+\", and fall back on that number if none is found.
17215 When set to nil, try to get the width from an #+ATTR.* keyword
17216 and fall back on the original width if none is found.
17218 This requires Emacs >= 24.1, build with imagemagick support."
17219 :group 'org-appearance
17222 (const :tag "Use the image width" t)
17223 (integer :tag "Use a number of pixels")
17224 (list :tag "Use #+ATTR* or a number of pixels" (integer))
17225 (const :tag "Use #+ATTR* or don't resize" nil)))
17227 (defcustom org-agenda-inhibit-startup t
17228 "Inhibit startup when preparing agenda buffers.
17229 When this variable is `t' (the default), the initialization of
17230 the Org agenda buffers is inhibited: e.g. the visibility state
17231 is not set, the tables are not re-aligned, etc."
17234 :group 'org-agenda)
17236 (defun org-duration-string-to-minutes (s &optional output-to-string)
17237 "Convert a duration string S to minutes.
17239 A bare number is interpreted as minutes, modifiers can be set by
17240 customizing `org-effort-durations' (which see).
17242 Entries containing a colon are interpreted as H:MM by
17243 `org-hh:mm-string-to-minutes'."
17245 (re (concat "\\([0-9.]+\\) *\\("
17246 (regexp-opt (mapcar 'car org-effort-durations))
17248 (while (string-match re s)
17249 (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
17250 (string-to-number (match-string 1 s))))
17251 (setq s (replace-match "" nil t s)))
17252 (setq result (floor result))
17253 (incf result (org-hh:mm-string-to-minutes s))
17254 (if output-to-string (number-to-string result) result)))
17258 (defun org-save-all-org-buffers ()
17259 "Save all Org-mode buffers without user confirmation."
17261 (message "Saving all Org-mode buffers...")
17262 (save-some-buffers t (lambda () (derived-mode-p 'org-mode)))
17263 (when (featurep 'org-id) (org-id-locations-save))
17264 (message "Saving all Org-mode buffers... done"))
17266 (defun org-revert-all-org-buffers ()
17267 "Revert all Org-mode buffers.
17268 Prompt for confirmation when there are unsaved changes.
17269 Be sure you know what you are doing before letting this function
17270 overwrite your changes.
17272 This function is useful in a setup where one tracks org files
17273 with a version control system, to revert on one machine after pulling
17274 changes from another. I believe the procedure must be like this:
17276 1. M-x org-save-all-org-buffers
17277 2. Pull changes from the other machine, resolve conflicts
17278 3. M-x org-revert-all-org-buffers"
17280 (unless (yes-or-no-p "Revert all Org buffers from their files? ")
17283 (save-window-excursion
17286 (when (and (with-current-buffer b (derived-mode-p 'org-mode))
17287 (with-current-buffer b buffer-file-name))
17288 (org-pop-to-buffer-same-window b)
17289 (revert-buffer t 'no-confirm)))
17291 (when (and (featurep 'org-id) org-id-track-globally)
17292 (org-id-locations-load)))))
17297 (defun org-switchb (&optional arg)
17298 "Switch between Org buffers.
17299 With one prefix argument, restrict available buffers to files.
17300 With two prefix arguments, restrict available buffers to agenda files.
17302 Defaults to `iswitchb' for buffer name completion.
17303 Set `org-completion-use-ido' to make it use ido instead."
17305 (let ((blist (cond ((equal arg '(4)) (org-buffer-list 'files))
17306 ((equal arg '(16)) (org-buffer-list 'agenda))
17307 (t (org-buffer-list))))
17308 (org-completion-use-iswitchb org-completion-use-iswitchb)
17309 (org-completion-use-ido org-completion-use-ido))
17310 (unless (or org-completion-use-ido org-completion-use-iswitchb)
17311 (setq org-completion-use-iswitchb t))
17312 (org-pop-to-buffer-same-window
17313 (org-icompleting-read "Org buffer: "
17314 (mapcar 'list (mapcar 'buffer-name blist))
17317 ;;; Define some older names previously used for this functionality
17319 (defalias 'org-ido-switchb 'org-switchb)
17321 (defalias 'org-iswitchb 'org-switchb)
17323 (defun org-buffer-list (&optional predicate exclude-tmp)
17324 "Return a list of Org buffers.
17325 PREDICATE can be `export', `files' or `agenda'.
17327 export restrict the list to Export buffers.
17328 files restrict the list to buffers visiting Org files.
17329 agenda restrict the list to buffers visiting agenda files.
17331 If EXCLUDE-TMP is non-nil, ignore temporary buffers."
17333 (agenda-files (and (eq predicate 'agenda)
17334 (mapcar 'file-truename (org-agenda-files t))))
17337 ((eq predicate 'files)
17338 (lambda (b) (with-current-buffer b (derived-mode-p 'org-mode))))
17339 ((eq predicate 'export)
17340 (lambda (b) (string-match "\*Org .*Export" (buffer-name b))))
17341 ((eq predicate 'agenda)
17343 (with-current-buffer b
17344 (and (derived-mode-p 'org-mode)
17345 (setq bfn (buffer-file-name b))
17346 (member (file-truename bfn) agenda-files)))))
17347 (t (lambda (b) (with-current-buffer b
17348 (or (derived-mode-p 'org-mode)
17349 (string-match "\*Org .*Export"
17350 (buffer-name b)))))))))
17354 (if (and (funcall filter b)
17355 (or (not exclude-tmp)
17356 (not (string-match "tmp" (buffer-name b)))))
17361 (defun org-agenda-files (&optional unrestricted archives)
17362 "Get the list of agenda files.
17363 Optional UNRESTRICTED means return the full list even if a restriction
17364 is currently in place.
17365 When ARCHIVES is t, include all archive files that are really being
17366 used by the agenda files. If ARCHIVE is `ifmode', do this only if
17367 `org-agenda-archives-mode' is t."
17370 ((and (not unrestricted) (get 'org-agenda-files 'org-restrict)))
17371 ((stringp org-agenda-files) (org-read-agenda-file-list))
17372 ((listp org-agenda-files) org-agenda-files)
17373 (t (error "Invalid value of `org-agenda-files'")))))
17374 (setq files (apply 'append
17375 (mapcar (lambda (f)
17376 (if (file-directory-p f)
17378 f t org-agenda-file-regexp)
17381 (when org-agenda-skip-unavailable-files
17382 (setq files (delq nil
17385 (and (file-readable-p file) file)))
17387 (when (or (eq archives t)
17388 (and (eq archives 'ifmode) (eq org-agenda-archives-mode t)))
17389 (setq files (org-add-archive-files files)))
17392 (defun org-agenda-file-p (&optional file)
17393 "Return non-nil, if FILE is an agenda file.
17394 If FILE is omitted, use the file associated with the current
17396 (member (or file (buffer-file-name))
17397 (org-agenda-files t)))
17399 (defun org-edit-agenda-file-list ()
17400 "Edit the list of agenda files.
17401 Depending on setup, this either uses customize to edit the variable
17402 `org-agenda-files', or it visits the file that is holding the list. In the
17403 latter case, the buffer is set up in a way that saving it automatically kills
17404 the buffer and restores the previous window configuration."
17406 (if (stringp org-agenda-files)
17407 (let ((cw (current-window-configuration)))
17408 (find-file org-agenda-files)
17409 (org-set-local 'org-window-configuration cw)
17410 (org-add-hook 'after-save-hook
17412 (set-window-configuration
17413 (prog1 org-window-configuration
17414 (kill-buffer (current-buffer))))
17415 (org-install-agenda-files-menu)
17416 (message "New agenda file list installed"))
17418 (message "%s" (substitute-command-keys
17419 "Edit list and finish with \\[save-buffer]")))
17420 (customize-variable 'org-agenda-files)))
17422 (defun org-store-new-agenda-file-list (list)
17423 "Set new value for the agenda file list and save it correctly."
17424 (if (stringp org-agenda-files)
17425 (let ((fe (org-read-agenda-file-list t)) b u)
17426 (while (setq b (find-buffer-visiting org-agenda-files))
17428 (with-temp-file org-agenda-files
17431 (lambda (f) ;; Keep un-expanded entries.
17432 (if (setq u (assoc f fe))
17437 (let ((org-mode-hook nil) (org-inhibit-startup t)
17438 (org-insert-mode-line-in-empty-file nil))
17439 (setq org-agenda-files list)
17440 (customize-save-variable 'org-agenda-files org-agenda-files))))
17442 (defun org-read-agenda-file-list (&optional pair-with-expansion)
17443 "Read the list of agenda files from a file.
17444 If PAIR-WITH-EXPANSION is t return pairs with un-expanded
17445 filenames, used by `org-store-new-agenda-file-list' to write back
17446 un-expanded file names."
17447 (when (file-directory-p org-agenda-files)
17448 (error "`org-agenda-files' cannot be a single directory"))
17449 (when (stringp org-agenda-files)
17451 (insert-file-contents org-agenda-files)
17454 (let ((e (expand-file-name (substitute-in-file-name f)
17456 (if pair-with-expansion
17459 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*")))))
17462 (defun org-cycle-agenda-files ()
17463 "Cycle through the files in `org-agenda-files'.
17464 If the current buffer visits an agenda file, find the next one in the list.
17465 If the current buffer does not, find the first agenda file."
17467 (let* ((fs (org-agenda-files t))
17468 (files (append fs (list (car fs))))
17469 (tcf (if buffer-file-name (file-truename buffer-file-name)))
17471 (unless files (error "No agenda files"))
17473 (while (setq file (pop files))
17474 (if (equal (file-truename file) tcf)
17476 (find-file (car files))
17478 (find-file (car fs)))
17479 (if (buffer-base-buffer) (org-pop-to-buffer-same-window (buffer-base-buffer)))))
17481 (defun org-agenda-file-to-front (&optional to-end)
17482 "Move/add the current file to the top of the agenda file list.
17483 If the file is not present in the list, it is added to the front. If it is
17484 present, it is moved there. With optional argument TO-END, add/move to the
17487 (let ((org-agenda-skip-unavailable-files nil)
17488 (file-alist (mapcar (lambda (x)
17489 (cons (file-truename x) x))
17490 (org-agenda-files t)))
17491 (ctf (file-truename
17492 (or buffer-file-name
17493 (error "Please save the current buffer to a file"))))
17495 (setq x (assoc ctf file-alist) had x)
17497 (if (not x) (setq x (cons ctf (abbreviate-file-name buffer-file-name))))
17499 (setq file-alist (append (delq x file-alist) (list x)))
17500 (setq file-alist (cons x (delq x file-alist))))
17501 (org-store-new-agenda-file-list (mapcar 'cdr file-alist))
17502 (org-install-agenda-files-menu)
17503 (message "File %s to %s of agenda file list"
17504 (if had "moved" "added") (if to-end "end" "front"))))
17506 (defun org-remove-file (&optional file)
17507 "Remove current file from the list of files in variable `org-agenda-files'.
17508 These are the files which are being checked for agenda entries.
17509 Optional argument FILE means use this file instead of the current."
17511 (let* ((org-agenda-skip-unavailable-files nil)
17512 (file (or file buffer-file-name
17513 (error "Current buffer does not visit a file")))
17514 (true-file (file-truename file))
17515 (afile (abbreviate-file-name file))
17516 (files (delq nil (mapcar
17518 (if (equal true-file
17521 (org-agenda-files t)))))
17522 (if (not (= (length files) (length (org-agenda-files t))))
17524 (org-store-new-agenda-file-list files)
17525 (org-install-agenda-files-menu)
17526 (message "Removed file: %s" afile))
17527 (message "File was not in list: %s (not removed)" afile))))
17529 (defun org-file-menu-entry (file)
17530 (vector file (list 'find-file file) t))
17532 (defun org-check-agenda-file (file)
17533 "Make sure FILE exists. If not, ask user what to do."
17534 (when (not (file-exists-p file))
17535 (message "Non-existent agenda file %s. [R]emove from list or [A]bort?"
17536 (abbreviate-file-name file))
17537 (let ((r (downcase (read-char-exclusive))))
17540 (org-remove-file file)
17541 (throw 'nextfile t))
17542 (t (error "Abort"))))))
17544 (defun org-get-agenda-file-buffer (file)
17545 "Get a buffer visiting FILE. If the buffer needs to be created, add
17546 it to the list of buffers which might be released later."
17547 (let ((buf (org-find-base-buffer-visiting file)))
17549 buf ; just return it
17550 ;; Make a new buffer and remember it
17551 (setq buf (find-file-noselect file))
17552 (if buf (push buf org-agenda-new-buffers))
17555 (defun org-release-buffers (blist)
17556 "Release all buffers in list, asking the user for confirmation when needed.
17557 When a buffer is unmodified, it is just killed. When modified, it is saved
17558 \(if the user agrees) and then killed."
17560 (while (setq buf (pop blist))
17561 (setq file (buffer-file-name buf))
17562 (when (and (buffer-modified-p buf)
17564 (y-or-n-p (format "Save file %s? " file)))
17565 (with-current-buffer buf (save-buffer)))
17566 (kill-buffer buf))))
17568 (defun org-agenda-prepare-buffers (files)
17569 "Create buffers for all agenda files, protect archived trees and comments."
17571 (let ((pa '(:org-archived t))
17572 (pc '(:org-comment t))
17573 (pall '(:org-archived t :org-comment t))
17574 (inhibit-read-only t)
17575 (org-inhibit-startup org-agenda-inhibit-startup)
17576 (rea (concat ":" org-archive-tag ":"))
17580 (while (setq file (pop files))
17584 (org-check-agenda-file file)
17585 (set-buffer (org-get-agenda-file-buffer file)))
17588 (org-refresh-category-properties)
17589 (org-refresh-properties org-effort-property 'org-effort)
17590 (org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime)
17591 (setq org-todo-keywords-for-agenda
17592 (append org-todo-keywords-for-agenda org-todo-keywords-1))
17593 (setq org-done-keywords-for-agenda
17594 (append org-done-keywords-for-agenda org-done-keywords))
17595 (setq org-todo-keyword-alist-for-agenda
17596 (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
17597 (setq org-drawers-for-agenda
17598 (append org-drawers-for-agenda org-drawers))
17599 (setq org-tag-alist-for-agenda
17600 (append org-tag-alist-for-agenda org-tag-alist))
17603 (remove-text-properties (point-min) (point-max) pall)
17604 (when org-agenda-skip-archived-trees
17605 (goto-char (point-min))
17606 (while (re-search-forward rea nil t)
17607 (if (org-at-heading-p t)
17608 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
17609 (goto-char (point-min))
17610 (setq re (format org-heading-keyword-regexp-format
17611 org-comment-string))
17612 (while (re-search-forward re nil t)
17613 (add-text-properties
17614 (match-beginning 0) (org-end-of-subtree t) pc))))))))
17615 (setq org-todo-keywords-for-agenda
17616 (org-uniquify org-todo-keywords-for-agenda))
17617 (setq org-todo-keyword-alist-for-agenda
17618 (org-uniquify org-todo-keyword-alist-for-agenda)
17619 org-tag-alist-for-agenda (org-uniquify org-tag-alist-for-agenda))))
17623 ;;;; CDLaTeX minor mode
17625 (defvar org-cdlatex-mode-map (make-sparse-keymap)
17626 "Keymap for the minor `org-cdlatex-mode'.")
17628 (org-defkey org-cdlatex-mode-map "_" 'org-cdlatex-underscore-caret)
17629 (org-defkey org-cdlatex-mode-map "^" 'org-cdlatex-underscore-caret)
17630 (org-defkey org-cdlatex-mode-map "`" 'cdlatex-math-symbol)
17631 (org-defkey org-cdlatex-mode-map "'" 'org-cdlatex-math-modify)
17632 (org-defkey org-cdlatex-mode-map "\C-c{" 'cdlatex-environment)
17634 (defvar org-cdlatex-texmathp-advice-is-done nil
17635 "Flag remembering if we have applied the advice to texmathp already.")
17637 (define-minor-mode org-cdlatex-mode
17638 "Toggle the minor `org-cdlatex-mode'.
17639 This mode supports entering LaTeX environment and math in LaTeX fragments
17641 \\{org-cdlatex-mode-map}"
17643 (when org-cdlatex-mode
17645 (run-hooks 'cdlatex-mode-hook)
17646 (cdlatex-compute-tables))
17647 (unless org-cdlatex-texmathp-advice-is-done
17648 (setq org-cdlatex-texmathp-advice-is-done t)
17649 (defadvice texmathp (around org-math-always-on activate)
17650 "Always return t in org-mode buffers.
17651 This is because we want to insert math symbols without dollars even outside
17652 the LaTeX math segments. If Orgmode thinks that point is actually inside
17653 an embedded LaTeX fragment, let texmathp do its job.
17654 \\[org-cdlatex-mode-map]"
17658 ((not (derived-mode-p 'org-mode)) ad-do-it)
17659 ((eq this-command 'cdlatex-math-symbol)
17660 (setq ad-return-value t
17661 texmathp-why '("cdlatex-math-symbol in org-mode" . 0)))
17663 (let ((p (org-inside-LaTeX-fragment-p)))
17664 (if (and p (member (car p) (plist-get org-format-latex-options :matchers)))
17665 (setq ad-return-value t
17666 texmathp-why '("Org-mode embedded math" . 0))
17667 (if p ad-do-it)))))))))
17669 (defun turn-on-org-cdlatex ()
17670 "Unconditionally turn on `org-cdlatex-mode'."
17671 (org-cdlatex-mode 1))
17673 (defun org-try-cdlatex-tab ()
17674 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
17675 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
17676 - inside a LaTeX fragment, or
17677 - after the first word in a line, where an abbreviation expansion could
17678 insert a LaTeX environment."
17679 (when org-cdlatex-mode
17681 ;; Before any word on the line: No expansion possible.
17682 ((save-excursion (skip-chars-backward " \t") (bolp)) nil)
17683 ;; Just after first word on the line: Expand it. Make sure it
17684 ;; cannot happen on headlines, though.
17686 (skip-chars-backward "a-zA-Z0-9*")
17687 (skip-chars-backward " \t")
17688 (and (bolp) (not (org-at-heading-p))))
17690 ((org-inside-LaTeX-fragment-p) (cdlatex-tab) t))))
17692 (defun org-cdlatex-underscore-caret (&optional arg)
17693 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
17694 Revert to the normal definition outside of these fragments."
17696 (if (org-inside-LaTeX-fragment-p)
17697 (call-interactively 'cdlatex-sub-superscript)
17698 (let (org-cdlatex-mode)
17699 (call-interactively (key-binding (vector last-input-event))))))
17701 (defun org-cdlatex-math-modify (&optional arg)
17702 "Execute `cdlatex-math-modify' in LaTeX fragments.
17703 Revert to the normal definition outside of these fragments."
17705 (if (org-inside-LaTeX-fragment-p)
17706 (call-interactively 'cdlatex-math-modify)
17707 (let (org-cdlatex-mode)
17708 (call-interactively (key-binding (vector last-input-event))))))
17712 ;;;; LaTeX fragments
17714 (defvar org-latex-regexps
17715 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t)
17716 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
17717 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
17718 ("$1" "\\([^$]\\|^\\)\\(\\$[^ \r\n,;.$]\\$\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
17719 ("$" "\\([^$]\\|^\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([- .,?;:'\")\000]\\|$\\)" 2 nil)
17720 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
17721 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
17722 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
17723 "Regular expressions for matching embedded LaTeX.")
17725 (defun org-inside-LaTeX-fragment-p ()
17726 "Test if point is inside a LaTeX fragment.
17727 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
17728 sequence appearing also before point.
17729 Even though the matchers for math are configurable, this function assumes
17730 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
17731 delimiters are skipped when they have been removed by customization.
17732 The return value is nil, or a cons cell with the delimiter and the
17733 position of this delimiter.
17735 This function does a reasonably good job, but can locally be fooled by
17736 for example currency specifications. For example it will assume being in
17737 inline math after \"$22.34\". The LaTeX fragment formatter will only format
17738 fragments that are properly closed, but during editing, we have to live
17739 with the uncertainty caused by missing closing delimiters. This function
17740 looks only before point, not after."
17742 (let ((pos (point))
17743 (dodollar (member "$" (plist-get org-format-latex-options :matchers)))
17745 (re-search-backward (concat "^\\(" paragraph-start "\\)") nil t)
17747 dd-on str (start 0) m re)
17750 (setq str (concat (buffer-substring lim (point)) "\000 X$.")
17751 re (nth 1 (assoc "$" org-latex-regexps)))
17752 (while (string-match re str start)
17754 ((= (match-end 0) (length str))
17755 (throw 'exit (cons "$" (+ lim (match-beginning 0) 1))))
17756 ((= (match-end 0) (- (length str) 5))
17758 (t (setq start (match-end 0))))))
17759 (when (setq m (re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t))
17761 (and (match-beginning 1) (throw 'exit (cons (match-string 1) m)))
17762 (and (match-beginning 2) (throw 'exit nil))
17764 (while (re-search-backward "\\$\\$" lim t)
17765 (setq dd-on (not dd-on)))
17767 (if dd-on (cons "$$" m))))))
17769 (defun org-inside-latex-macro-p ()
17770 "Is point inside a LaTeX macro or its arguments?"
17773 "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")))
17775 (defvar org-latex-fragment-image-overlays nil
17776 "List of overlays carrying the images of latex fragments.")
17777 (make-variable-buffer-local 'org-latex-fragment-image-overlays)
17779 (defun org-remove-latex-fragment-image-overlays ()
17780 "Remove all overlays with LaTeX fragment images in current buffer."
17781 (mapc 'delete-overlay org-latex-fragment-image-overlays)
17782 (setq org-latex-fragment-image-overlays nil))
17784 (defun org-preview-latex-fragment (&optional subtree)
17785 "Preview the LaTeX fragment at point, or all locally or globally.
17786 If the cursor is in a LaTeX fragment, create the image and overlay
17787 it over the source code. If there is no fragment at point, display
17788 all fragments in the current text, from one headline to the next. With
17789 prefix SUBTREE, display all fragments in the current subtree. With a
17790 double prefix arg \\[universal-argument] \\[universal-argument], or when \
17791 the cursor is before the first headline,
17792 display all fragments in the buffer.
17793 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
17795 (unless buffer-file-name
17796 (error "Can't preview LaTeX fragment in a non-file buffer"))
17797 (org-remove-latex-fragment-image-overlays)
17800 (let (beg end at msg)
17802 ((or (equal subtree '(16))
17803 (not (save-excursion
17804 (re-search-backward org-outline-regexp-bol nil t))))
17805 (setq beg (point-min) end (point-max)
17806 msg "Creating images for buffer...%s"))
17807 ((equal subtree '(4))
17808 (org-back-to-heading)
17809 (setq beg (point) end (org-end-of-subtree t)
17810 msg "Creating images for subtree...%s"))
17812 (if (setq at (org-inside-LaTeX-fragment-p))
17813 (goto-char (max (point-min) (- (cdr at) 2)))
17814 (org-back-to-heading))
17815 (setq beg (point) end (progn (outline-next-heading) (point))
17816 msg (if at "Creating image...%s"
17817 "Creating images for entry...%s"))))
17819 (narrow-to-region beg end)
17822 (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
17823 (file-name-nondirectory
17824 buffer-file-name)))
17825 default-directory 'overlays msg at 'forbuffer
17826 org-latex-create-formula-image-program)
17827 (message msg "done. Use `C-c C-c' to remove images.")))))
17829 (defun org-format-latex (prefix &optional dir overlays msg at
17830 forbuffer processing-type)
17831 "Replace LaTeX fragments with links to an image, and produce images.
17832 Some of the options can be changed using the variable
17833 `org-format-latex-options'."
17834 (if (and overlays (fboundp 'clear-image-cache)) (clear-image-cache))
17835 (let* ((prefixnodir (file-name-nondirectory prefix))
17836 (absprefix (expand-file-name prefix dir))
17837 (todir (file-name-directory absprefix))
17838 (opt org-format-latex-options)
17839 (optnew org-format-latex-options)
17840 (matchers (plist-get opt :matchers))
17841 (re-list org-latex-regexps)
17842 (cnt 0) txt hash link beg end re e checkdir
17844 m n block-type block linkfile movefile ov)
17845 ;; Check the different regular expressions
17846 (while (setq e (pop re-list))
17847 (setq m (car e) re (nth 1 e) n (nth 2 e) block-type (nth 3 e)
17848 block (if block-type "\n\n" ""))
17849 (when (member m matchers)
17850 (goto-char (point-min))
17851 (while (re-search-forward re nil t)
17852 (when (and (or (not at) (equal (cdr at) (match-beginning n)))
17854 (not (eq (get-char-property (match-beginning n)
17856 'org-latex-overlay))))
17858 ((eq processing-type 'verbatim))
17859 ((eq processing-type 'mathjax)
17860 ;; Prepare for MathJax processing.
17861 (setq string (match-string n))
17862 (when (member m '("$" "$1"))
17864 (delete-region (match-beginning n) (match-end n))
17865 (goto-char (match-beginning n))
17866 (insert (concat "\\(" (substring string 1 -1) "\\)")))))
17867 ((or (eq processing-type 'dvipng)
17868 (eq processing-type 'imagemagick))
17869 ;; Process to an image.
17870 (setq txt (match-string n)
17871 beg (match-beginning n) end (match-end n)
17873 (let ((face (face-at-point))
17874 (fg (plist-get opt :foreground))
17875 (bg (plist-get opt :background))
17876 ;; Ensure full list is printed.
17877 print-length print-level)
17879 ;; Get the colors from the face at point.
17881 (when (eq fg 'auto)
17882 (setq fg (face-attribute face :foreground nil 'default)))
17883 (when (eq bg 'auto)
17884 (setq bg (face-attribute face :background nil 'default)))
17885 (setq optnew (copy-sequence opt))
17886 (plist-put optnew :foreground fg)
17887 (plist-put optnew :background bg))
17888 (setq hash (sha1 (prin1-to-string
17889 (list org-format-latex-header
17890 org-latex-default-packages-alist
17891 org-latex-packages-alist
17892 org-format-latex-options
17893 forbuffer txt fg bg)))
17894 linkfile (format "%s_%s.png" prefix hash)
17895 movefile (format "%s_%s.png" absprefix hash)))
17896 (setq link (concat block "[[file:" linkfile "]]" block))
17897 (if msg (message msg cnt))
17899 (unless checkdir ; Ensure the directory exists.
17901 (or (file-directory-p todir) (make-directory todir t)))
17902 (unless (file-exists-p movefile)
17903 (org-create-formula-image
17904 txt movefile optnew forbuffer processing-type))
17908 (if (eq (overlay-get o 'org-overlay-type)
17909 'org-latex-overlay)
17910 (delete-overlay o)))
17911 (overlays-in beg end))
17912 (setq ov (make-overlay beg end))
17913 (overlay-put ov 'org-overlay-type 'org-latex-overlay)
17914 (if (featurep 'xemacs)
17916 (overlay-put ov 'invisible t)
17919 (make-glyph (vector 'png :file movefile))))
17922 (list 'image :type 'png :file movefile :ascent 'center)))
17923 (push ov org-latex-fragment-image-overlays)
17925 (delete-region beg end)
17926 (insert (org-add-props link
17927 (list 'org-latex-src
17928 (replace-regexp-in-string
17930 'org-latex-src-embed-type
17931 (if block-type 'paragraph 'character))))))
17932 ((eq processing-type 'mathml)
17933 ;; Process to MathML
17934 (unless (save-match-data (org-format-latex-mathml-available-p))
17935 (error "LaTeX to MathML converter not configured"))
17936 (setq txt (match-string n)
17937 beg (match-beginning n) end (match-end n)
17939 (if msg (message msg cnt))
17941 (delete-region beg end)
17942 (insert (org-format-latex-as-mathml
17943 txt block-type prefix dir)))
17945 (error "Unknown conversion type %s for latex fragments"
17946 processing-type)))))))))
17948 (defun org-create-math-formula (latex-frag &optional mathml-file)
17949 "Convert LATEX-FRAG to MathML and store it in MATHML-FILE.
17950 Use `org-latex-to-mathml-convert-command'. If the conversion is
17951 sucessful, return the portion between \"<math...> </math>\"
17952 elements otherwise return nil. When MATHML-FILE is specified,
17953 write the results in to that file. When invoked as an
17954 interactive command, prompt for LATEX-FRAG, with initial value
17955 set to the current active region and echo the results for user
17957 (interactive (list (let ((frag (when (org-region-active-p)
17958 (buffer-substring-no-properties
17959 (region-beginning) (region-end)))))
17960 (read-string "LaTeX Fragment: " frag nil frag))))
17961 (unless latex-frag (error "Invalid latex-frag"))
17962 (let* ((tmp-in-file (file-relative-name
17963 (make-temp-name (expand-file-name "ltxmathml-in"))))
17964 (ignore (write-region latex-frag nil tmp-in-file))
17965 (tmp-out-file (file-relative-name
17966 (make-temp-name (expand-file-name "ltxmathml-out"))))
17968 org-latex-to-mathml-convert-command
17969 `((?j . ,(shell-quote-argument
17970 (expand-file-name org-latex-to-mathml-jar-file)))
17971 (?I . ,(shell-quote-argument tmp-in-file))
17972 (?o . ,(shell-quote-argument tmp-out-file)))))
17973 mathml shell-command-output)
17974 (when (org-called-interactively-p 'any)
17975 (unless (org-format-latex-mathml-available-p)
17976 (error "LaTeX to MathML converter not configured")))
17977 (message "Running %s" cmd)
17978 (setq shell-command-output (shell-command-to-string cmd))
17980 (when (file-readable-p tmp-out-file)
17981 (with-current-buffer (find-file-noselect tmp-out-file t)
17982 (goto-char (point-min))
17983 (when (re-search-forward
17986 "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">")
17988 (regexp-quote "</math>")) nil t)
17989 (prog1 (match-string 0) (kill-buffer))))))
17993 (concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" mathml))
17995 (write-region mathml nil mathml-file))
17996 (when (org-called-interactively-p 'any)
17998 ((message "LaTeX to MathML conversion failed")
17999 (message shell-command-output)))
18000 (delete-file tmp-in-file)
18001 (when (file-exists-p tmp-out-file)
18002 (delete-file tmp-out-file))
18005 (defun org-format-latex-as-mathml (latex-frag latex-frag-type
18006 prefix &optional dir)
18007 "Use `org-create-math-formula' but check local cache first."
18008 (let* ((absprefix (expand-file-name prefix dir))
18009 (print-length nil) (print-level nil)
18010 (formula-id (concat
18015 org-latex-to-mathml-convert-command)))))
18016 (formula-cache (format "%s-%s.mathml" absprefix formula-id))
18017 (formula-cache-dir (file-name-directory formula-cache)))
18019 (unless (file-directory-p formula-cache-dir)
18020 (make-directory formula-cache-dir t))
18022 (unless (file-exists-p formula-cache)
18023 (org-create-math-formula latex-frag formula-cache))
18025 (if (file-exists-p formula-cache)
18026 ;; Successful conversion. Return the link to MathML file.
18028 (format "[[file:%s]]" (file-relative-name formula-cache dir))
18029 (list 'org-latex-src (replace-regexp-in-string "\"" "" latex-frag)
18030 'org-latex-src-embed-type (if latex-frag-type
18031 'paragraph 'character)))
18032 ;; Failed conversion. Return the LaTeX fragment verbatim
18035 (defun org-create-formula-image (string tofile options buffer &optional type)
18036 "Create an image from LaTeX source using dvipng or convert.
18037 This function calls either `org-create-formula-image-with-dvipng'
18038 or `org-create-formula-image-with-imagemagick' depending on the
18039 value of `org-latex-create-formula-image-program' or on the value
18040 of the optional TYPE variable.
18042 Note: ultimately these two function should be combined as they
18043 share a good deal of logic."
18044 (org-check-external-command
18045 "latex" "needed to convert LaTeX fragments to images")
18047 (case (or type org-latex-create-formula-image-program)
18049 (org-check-external-command
18050 "dvipng" "needed to convert LaTeX fragments to images")
18051 #'org-create-formula-image-with-dvipng)
18053 (org-check-external-command
18054 "convert" "you need to install imagemagick")
18055 #'org-create-formula-image-with-imagemagick)
18057 "invalid value of `org-latex-create-formula-image-program'")))
18058 string tofile options buffer))
18060 ;; This function borrows from Ganesh Swami's latex2png.el
18061 (defun org-create-formula-image-with-dvipng (string tofile options buffer)
18062 "This calls dvipng."
18063 (let* ((tmpdir (if (featurep 'xemacs)
18065 temporary-file-directory))
18066 (texfilebase (make-temp-name
18067 (expand-file-name "orgtex" tmpdir)))
18068 (texfile (concat texfilebase ".tex"))
18069 (dvifile (concat texfilebase ".dvi"))
18070 (pngfile (concat texfilebase ".png"))
18071 (fnh (if (featurep 'xemacs)
18072 (font-height (face-font 'default))
18073 (face-attribute 'default :height nil)))
18074 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
18075 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
18076 (fg (or (plist-get options (if buffer :foreground :html-foreground))
18078 (bg (or (plist-get options (if buffer :background :html-background))
18080 (if (eq fg 'default) (setq fg (org-dvipng-color :foreground))
18081 (unless (string= fg "Transparent") (setq fg (org-dvipng-color-format fg))))
18082 (if (eq bg 'default) (setq bg (org-dvipng-color :background))
18083 (unless (string= bg "Transparent") (setq bg (org-dvipng-color-format bg))))
18084 (with-temp-file texfile
18085 (require 'ox-latex)
18086 (insert (org-latex-guess-inputenc
18087 (org-splice-latex-header
18088 org-format-latex-header
18089 org-latex-default-packages-alist
18090 org-latex-packages-alist t)))
18091 (insert "\n\\begin{document}\n" string "\n\\end{document}\n"))
18092 (let ((dir default-directory))
18093 (condition-case nil
18096 (call-process "latex" nil nil nil texfile))
18099 (if (not (file-exists-p dvifile))
18100 (progn (message "Failed to create dvi file from %s" texfile) nil)
18101 (condition-case nil
18102 (if (featurep 'xemacs)
18103 (call-process "dvipng" nil nil nil
18108 (call-process "dvipng" nil nil nil
18111 ;;"-x" scale "-y" scale
18116 (if (not (file-exists-p pngfile))
18117 (if org-format-latex-signal-error
18118 (error "Failed to create png file from %s" texfile)
18119 (message "Failed to create png file from %s" texfile)
18121 ;; Use the requested file name and clean up
18122 (copy-file pngfile tofile 'replace)
18123 (loop for e in '(".dvi" ".tex" ".aux" ".log" ".png" ".out") do
18124 (if (file-exists-p (concat texfilebase e))
18125 (delete-file (concat texfilebase e))))
18128 (defvar org-latex-pdf-process) ; From ox-latex.el
18129 (defun org-create-formula-image-with-imagemagick (string tofile options buffer)
18130 "This calls convert, which is included into imagemagick."
18131 (let* ((tmpdir (if (featurep 'xemacs)
18133 temporary-file-directory))
18134 (texfilebase (make-temp-name
18135 (expand-file-name "orgtex" tmpdir)))
18136 (texfile (concat texfilebase ".tex"))
18137 (pdffile (concat texfilebase ".pdf"))
18138 (pngfile (concat texfilebase ".png"))
18139 (fnh (if (featurep 'xemacs)
18140 (font-height (face-font 'default))
18141 (face-attribute 'default :height nil)))
18142 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
18143 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))))))
18144 (fg (or (plist-get options (if buffer :foreground :html-foreground))
18146 (bg (or (plist-get options (if buffer :background :html-background))
18148 (if (eq fg 'default) (setq fg (org-latex-color :foreground))
18149 (setq fg (org-latex-color-format fg)))
18150 (if (eq bg 'default) (setq bg (org-latex-color :background))
18151 (setq bg (org-latex-color-format
18152 (if (string= bg "Transparent") "white" bg))))
18153 (with-temp-file texfile
18154 (require 'ox-latex)
18155 (insert (org-latex-guess-inputenc
18156 (org-splice-latex-header
18157 org-format-latex-header
18158 org-latex-default-packages-alist
18159 org-latex-packages-alist t)))
18160 (insert "\n\\begin{document}\n"
18161 "\\definecolor{fg}{rgb}{" fg "}\n"
18162 "\\definecolor{bg}{rgb}{" bg "}\n"
18163 "\n\\pagecolor{bg}\n"
18167 "\n\\end{document}\n"))
18168 (let ((dir default-directory) cmd cmds latex-frags-cmds)
18169 (condition-case nil
18172 (setq cmds org-latex-pdf-process)
18174 (setq latex-frags-cmds (pop cmds))
18175 (if (listp latex-frags-cmds)
18177 (setq latex-frags-cmds (list (car org-latex-pdf-process)))))
18178 (while latex-frags-cmds
18179 (setq cmd (pop latex-frags-cmds))
18180 (while (string-match "%b" cmd)
18181 (setq cmd (replace-match
18183 (shell-quote-argument texfile))
18185 (while (string-match "%f" cmd)
18186 (setq cmd (replace-match
18188 (shell-quote-argument
18189 (file-name-nondirectory texfile)))
18191 (while (string-match "%o" cmd)
18192 (setq cmd (replace-match
18194 (shell-quote-argument
18195 (file-name-directory texfile)))
18197 (setq cmd (split-string cmd))
18198 (eval (append (list 'call-process (pop cmd) nil nil nil) cmd))))
18201 (if (not (file-exists-p pdffile))
18202 (progn (message "Failed to create pdf file from %s" texfile) nil)
18203 (condition-case nil
18204 (if (featurep 'xemacs)
18205 (call-process "convert" nil nil nil
18211 ;; "-sharpen" "0x1.0"
18213 (call-process "convert" nil nil nil
18219 ;; "-sharpen" "0x1.0"
18222 (if (not (file-exists-p pngfile))
18223 (if org-format-latex-signal-error
18224 (error "Failed to create png file from %s" texfile)
18225 (message "Failed to create png file from %s" texfile)
18227 ;; Use the requested file name and clean up
18228 (copy-file pngfile tofile 'replace)
18229 (loop for e in '(".pdf" ".tex" ".aux" ".log" ".png") do
18230 (if (file-exists-p (concat texfilebase e))
18231 (delete-file (concat texfilebase e))))
18234 (defun org-splice-latex-header (tpl def-pkg pkg snippets-p &optional extra)
18235 "Fill a LaTeX header template TPL.
18236 In the template, the following place holders will be recognized:
18238 [DEFAULT-PACKAGES] \\usepackage statements for DEF-PKG
18239 [NO-DEFAULT-PACKAGES] do not include DEF-PKG
18240 [PACKAGES] \\usepackage statements for PKG
18241 [NO-PACKAGES] do not include PKG
18242 [EXTRA] the string EXTRA
18243 [NO-EXTRA] do not include EXTRA
18245 For backward compatibility, if both the positive and the negative place
18246 holder is missing, the positive one (without the \"NO-\") will be
18247 assumed to be present at the end of the template.
18248 DEF-PKG and PKG are assumed to be alists of options/packagename lists.
18250 SNIPPETS-P indicates if this is run to create snippet images for HTML."
18251 (let (rpl (end ""))
18252 (if (string-match "^[ \t]*\\[\\(NO-\\)?DEFAULT-PACKAGES\\][ \t]*\n?" tpl)
18253 (setq rpl (if (or (match-end 1) (not def-pkg))
18254 "" (org-latex-packages-to-string def-pkg snippets-p t))
18255 tpl (replace-match rpl t t tpl))
18256 (if def-pkg (setq end (org-latex-packages-to-string def-pkg snippets-p))))
18258 (if (string-match "\\[\\(NO-\\)?PACKAGES\\][ \t]*\n?" tpl)
18259 (setq rpl (if (or (match-end 1) (not pkg))
18260 "" (org-latex-packages-to-string pkg snippets-p t))
18261 tpl (replace-match rpl t t tpl))
18264 (org-latex-packages-to-string pkg snippets-p)))))
18266 (if (string-match "\\[\\(NO-\\)?EXTRA\\][ \t]*\n?" tpl)
18267 (setq rpl (if (or (match-end 1) (not extra))
18268 "" (concat extra "\n"))
18269 tpl (replace-match rpl t t tpl))
18270 (if (and extra (string-match "\\S-" extra))
18271 (setq end (concat end "\n" extra))))
18273 (if (string-match "\\S-" end)
18274 (concat tpl "\n" end)
18277 (defun org-latex-packages-to-string (pkg &optional snippets-p newline)
18278 "Turn an alist of packages into a string with the \\usepackage macros."
18279 (setq pkg (mapconcat (lambda(p)
18282 ((and snippets-p (>= (length p) 3) (not (nth 2 p)))
18283 (format "%% Package %s omitted" (cadr p)))
18284 ((equal "" (car p))
18285 (format "\\usepackage{%s}" (cadr p)))
18287 (format "\\usepackage[%s]{%s}"
18288 (car p) (cadr p)))))
18291 (if newline (concat pkg "\n") pkg))
18293 (defun org-dvipng-color (attr)
18294 "Return a RGB color specification for dvipng."
18295 (apply 'format "rgb %s %s %s"
18296 (mapcar 'org-normalize-color
18297 (if (featurep 'xemacs)
18298 (color-rgb-components
18299 (face-property 'default
18300 (cond ((eq attr :foreground) 'foreground)
18301 ((eq attr :background) 'background))))
18302 (color-values (face-attribute 'default attr nil))))))
18304 (defun org-dvipng-color-format (color-name)
18305 "Convert COLOR-NAME to a RGB color value for dvipng."
18306 (apply 'format "rgb %s %s %s"
18307 (mapcar 'org-normalize-color
18308 (color-values color-name))))
18310 (defun org-latex-color (attr)
18311 "Return a RGB color for the LaTeX color package."
18312 (apply 'format "%s,%s,%s"
18313 (mapcar 'org-normalize-color
18314 (if (featurep 'xemacs)
18315 (color-rgb-components
18316 (face-property 'default
18317 (cond ((eq attr :foreground) 'foreground)
18318 ((eq attr :background) 'background))))
18319 (color-values (face-attribute 'default attr nil))))))
18321 (defun org-latex-color-format (color-name)
18322 "Convert COLOR-NAME to a RGB color value."
18323 (apply 'format "%s,%s,%s"
18324 (mapcar 'org-normalize-color
18325 (color-values color-name))))
18327 (defun org-normalize-color (value)
18328 "Return string to be used as color value for an RGB component."
18329 (format "%g" (/ value 65535.0)))
18335 (defvar org-inline-image-overlays nil)
18336 (make-variable-buffer-local 'org-inline-image-overlays)
18338 (defun org-toggle-inline-images (&optional include-linked)
18339 "Toggle the display of inline images.
18340 INCLUDE-LINKED is passed to `org-display-inline-images'."
18342 (if org-inline-image-overlays
18344 (org-remove-inline-images)
18345 (message "Inline image display turned off"))
18346 (org-display-inline-images include-linked)
18347 (if (and (org-called-interactively-p)
18348 org-inline-image-overlays)
18349 (message "%d images displayed inline"
18350 (length org-inline-image-overlays))
18351 (message "No images to display inline"))))
18353 (defun org-redisplay-inline-images ()
18354 "Refresh the display of inline images."
18356 (if (not org-inline-image-overlays)
18357 (org-toggle-inline-images)
18358 (org-toggle-inline-images)
18359 (org-toggle-inline-images)))
18361 (defun org-display-inline-images (&optional include-linked refresh beg end)
18362 "Display inline images.
18363 Normally only links without a description part are inlined, because this
18364 is how it will work for export. When INCLUDE-LINKED is set, also links
18365 with a description part will be inlined. This can be nice for a quick
18366 look at those images, but it does not reflect what exported files will look
18368 When REFRESH is set, refresh existing images between BEG and END.
18369 This will create new image displays only if necessary.
18370 BEG and END default to the buffer boundaries."
18373 (org-remove-inline-images)
18374 (if (fboundp 'clear-image-cache) (clear-image-cache)))
18378 (setq beg (or beg (point-min)) end (or end (point-max)))
18380 (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
18381 (substring (org-image-file-name-regexp) 0 -2)
18382 "\\)\\]" (if include-linked "" "\\]")))
18383 old file ov img type attrwidth width)
18384 (while (re-search-forward re end t)
18385 (setq old (get-char-property-and-overlay (match-beginning 1)
18386 'org-image-overlay)
18387 file (expand-file-name
18388 (concat (or (match-string 3) "") (match-string 4))))
18389 (when (image-type-available-p 'imagemagick)
18390 (setq attrwidth (if (or (listp org-image-actual-width)
18391 (null org-image-actual-width))
18394 (when (re-search-backward
18395 "#\\+ATTR.*width=\"\\([^\"]+\\)\""
18397 (re-search-backward "^[ \t]*$\\|\\`" nil t)) t)
18398 (string-to-number (match-string 1))))))
18399 width (cond ((eq org-image-actual-width t) nil)
18400 ((null org-image-actual-width) attrwidth)
18401 ((numberp org-image-actual-width)
18402 org-image-actual-width)
18403 ((listp org-image-actual-width)
18404 (or attrwidth (car org-image-actual-width))))
18405 type (if width 'imagemagick)))
18406 (when (file-exists-p file)
18407 (if (and (car-safe old) refresh)
18408 (image-refresh (overlay-get (cdr old) 'display))
18409 (setq img (save-match-data (create-image file type nil :width width)))
18411 (setq ov (make-overlay (match-beginning 0) (match-end 0)))
18412 (overlay-put ov 'display img)
18413 (overlay-put ov 'face 'default)
18414 (overlay-put ov 'org-image-overlay t)
18415 (overlay-put ov 'modification-hooks
18416 (list 'org-display-inline-remove-overlay))
18417 (push ov org-inline-image-overlays)))))))))
18419 (define-obsolete-function-alias
18420 'org-display-inline-modification-hook 'org-display-inline-remove-overlay "24.3")
18422 (defun org-display-inline-remove-overlay (ov after beg end &optional len)
18423 "Remove inline-display overlay if a corresponding region is modified."
18424 (let ((inhibit-modification-hooks t))
18425 (when (and ov after)
18426 (delete ov org-inline-image-overlays)
18427 (delete-overlay ov))))
18429 (defun org-remove-inline-images ()
18430 "Remove inline display of images."
18432 (mapc 'delete-overlay org-inline-image-overlays)
18433 (setq org-inline-image-overlays nil))
18437 ;; Outline functions from `outline-mode-prefix-map'
18438 ;; that can be remapped in Org:
18439 (define-key org-mode-map [remap outline-mark-subtree] 'org-mark-subtree)
18440 (define-key org-mode-map [remap show-subtree] 'org-show-subtree)
18441 (define-key org-mode-map [remap outline-forward-same-level]
18442 'org-forward-heading-same-level)
18443 (define-key org-mode-map [remap outline-backward-same-level]
18444 'org-backward-heading-same-level)
18445 (define-key org-mode-map [remap show-branches]
18446 'org-kill-note-or-show-branches)
18447 (define-key org-mode-map [remap outline-promote] 'org-promote-subtree)
18448 (define-key org-mode-map [remap outline-demote] 'org-demote-subtree)
18449 (define-key org-mode-map [remap outline-insert-heading] 'org-ctrl-c-ret)
18451 ;; Outline functions from `outline-mode-prefix-map' that can not
18452 ;; be remapped in Org:
18454 ;; - the column "key binding" shows whether the Outline function is still
18455 ;; available in Org mode on the same key that it has been bound to in
18457 ;; - "overridden": key used for a different functionality in Org mode
18458 ;; - else: key still bound to the same Outline function in Org mode
18460 ;; | Outline function | key binding | Org replacement |
18461 ;; |------------------------------------+-------------+-----------------------|
18462 ;; | `outline-next-visible-heading' | `C-c C-n' | still same function |
18463 ;; | `outline-previous-visible-heading' | `C-c C-p' | still same function |
18464 ;; | `outline-up-heading' | `C-c C-u' | still same function |
18465 ;; | `outline-move-subtree-up' | overridden | better: org-shiftup |
18466 ;; | `outline-move-subtree-down' | overridden | better: org-shiftdown |
18467 ;; | `show-entry' | overridden | no replacement |
18468 ;; | `show-children' | `C-c C-i' | visibility cycling |
18469 ;; | `show-branches' | `C-c C-k' | still same function |
18470 ;; | `show-subtree' | overridden | visibility cycling |
18471 ;; | `show-all' | overridden | no replacement |
18472 ;; | `hide-subtree' | overridden | visibility cycling |
18473 ;; | `hide-body' | overridden | no replacement |
18474 ;; | `hide-entry' | overridden | visibility cycling |
18475 ;; | `hide-leaves' | overridden | no replacement |
18476 ;; | `hide-sublevels' | overridden | no replacement |
18477 ;; | `hide-other' | overridden | no replacement |
18479 ;; Make `C-c C-x' a prefix key
18480 (org-defkey org-mode-map "\C-c\C-x" (make-sparse-keymap))
18482 ;; TAB key with modifiers
18483 (org-defkey org-mode-map "\C-i" 'org-cycle)
18484 (org-defkey org-mode-map [(tab)] 'org-cycle)
18485 (org-defkey org-mode-map [(control tab)] 'org-force-cycle-archived)
18486 (org-defkey org-mode-map "\M-\t" 'pcomplete)
18487 ;; The following line is necessary under Suse GNU/Linux
18488 (unless (featurep 'xemacs)
18489 (org-defkey org-mode-map [S-iso-lefttab] 'org-shifttab))
18490 (org-defkey org-mode-map [(shift tab)] 'org-shifttab)
18491 (define-key org-mode-map [backtab] 'org-shifttab)
18493 (org-defkey org-mode-map [(shift return)] 'org-table-copy-down)
18494 (org-defkey org-mode-map [(meta shift return)] 'org-insert-todo-heading)
18495 (org-defkey org-mode-map [(meta return)] 'org-meta-return)
18497 ;; Cursor keys with modifiers
18498 (org-defkey org-mode-map [(meta left)] 'org-metaleft)
18499 (org-defkey org-mode-map [(meta right)] 'org-metaright)
18500 (org-defkey org-mode-map [(meta up)] 'org-metaup)
18501 (org-defkey org-mode-map [(meta down)] 'org-metadown)
18503 (org-defkey org-mode-map [(meta shift left)] 'org-shiftmetaleft)
18504 (org-defkey org-mode-map [(meta shift right)] 'org-shiftmetaright)
18505 (org-defkey org-mode-map [(meta shift up)] 'org-shiftmetaup)
18506 (org-defkey org-mode-map [(meta shift down)] 'org-shiftmetadown)
18508 (org-defkey org-mode-map [(shift up)] 'org-shiftup)
18509 (org-defkey org-mode-map [(shift down)] 'org-shiftdown)
18510 (org-defkey org-mode-map [(shift left)] 'org-shiftleft)
18511 (org-defkey org-mode-map [(shift right)] 'org-shiftright)
18513 (org-defkey org-mode-map [(control shift right)] 'org-shiftcontrolright)
18514 (org-defkey org-mode-map [(control shift left)] 'org-shiftcontrolleft)
18515 (org-defkey org-mode-map [(control shift up)] 'org-shiftcontrolup)
18516 (org-defkey org-mode-map [(control shift down)] 'org-shiftcontroldown)
18519 (define-key org-mode-map org-babel-key-prefix org-babel-map)
18520 (mapc (lambda (pair)
18521 (define-key org-babel-map (car pair) (cdr pair)))
18522 org-babel-key-bindings)
18524 ;;; Extra keys for tty access.
18525 ;; We only set them when really needed because otherwise the
18526 ;; menus don't show the simple keys
18528 (when (or org-use-extra-keys
18529 (featurep 'xemacs) ;; because XEmacs supports multi-device stuff
18530 (not window-system))
18531 (org-defkey org-mode-map "\C-c\C-xc" 'org-table-copy-down)
18532 (org-defkey org-mode-map "\C-c\C-xM" 'org-insert-todo-heading)
18533 (org-defkey org-mode-map "\C-c\C-xm" 'org-meta-return)
18534 (org-defkey org-mode-map [?\e (return)] 'org-meta-return)
18535 (org-defkey org-mode-map [?\e (left)] 'org-metaleft)
18536 (org-defkey org-mode-map "\C-c\C-xl" 'org-metaleft)
18537 (org-defkey org-mode-map [?\e (right)] 'org-metaright)
18538 (org-defkey org-mode-map "\C-c\C-xr" 'org-metaright)
18539 (org-defkey org-mode-map [?\e (up)] 'org-metaup)
18540 (org-defkey org-mode-map "\C-c\C-xu" 'org-metaup)
18541 (org-defkey org-mode-map [?\e (down)] 'org-metadown)
18542 (org-defkey org-mode-map "\C-c\C-xd" 'org-metadown)
18543 (org-defkey org-mode-map "\C-c\C-xL" 'org-shiftmetaleft)
18544 (org-defkey org-mode-map "\C-c\C-xR" 'org-shiftmetaright)
18545 (org-defkey org-mode-map "\C-c\C-xU" 'org-shiftmetaup)
18546 (org-defkey org-mode-map "\C-c\C-xD" 'org-shiftmetadown)
18547 (org-defkey org-mode-map [?\C-c (up)] 'org-shiftup)
18548 (org-defkey org-mode-map [?\C-c (down)] 'org-shiftdown)
18549 (org-defkey org-mode-map [?\C-c (left)] 'org-shiftleft)
18550 (org-defkey org-mode-map [?\C-c (right)] 'org-shiftright)
18551 (org-defkey org-mode-map [?\C-c ?\C-x (right)] 'org-shiftcontrolright)
18552 (org-defkey org-mode-map [?\C-c ?\C-x (left)] 'org-shiftcontrolleft)
18553 (org-defkey org-mode-map [?\e (tab)] 'pcomplete)
18554 (org-defkey org-mode-map [?\e (shift return)] 'org-insert-todo-heading)
18555 (org-defkey org-mode-map [?\e (shift left)] 'org-shiftmetaleft)
18556 (org-defkey org-mode-map [?\e (shift right)] 'org-shiftmetaright)
18557 (org-defkey org-mode-map [?\e (shift up)] 'org-shiftmetaup)
18558 (org-defkey org-mode-map [?\e (shift down)] 'org-shiftmetadown))
18560 ;; All the other keys
18562 (org-defkey org-mode-map "\C-c\C-a" 'show-all) ; in case allout messed up.
18563 (org-defkey org-mode-map "\C-c\C-r" 'org-reveal)
18564 (if (boundp 'narrow-map)
18565 (org-defkey narrow-map "s" 'org-narrow-to-subtree)
18566 (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
18567 (if (boundp 'narrow-map)
18568 (org-defkey narrow-map "b" 'org-narrow-to-block)
18569 (org-defkey org-mode-map "\C-xnb" 'org-narrow-to-block))
18570 (if (boundp 'narrow-map)
18571 (org-defkey narrow-map "e" 'org-narrow-to-element)
18572 (org-defkey org-mode-map "\C-xne" 'org-narrow-to-element))
18573 (org-defkey org-mode-map "\C-\M-t" 'org-transpose-element)
18574 (org-defkey org-mode-map "\M-}" 'org-forward-element)
18575 (org-defkey org-mode-map "\M-{" 'org-backward-element)
18576 (org-defkey org-mode-map "\C-c\C-^" 'org-up-element)
18577 (org-defkey org-mode-map "\C-c\C-_" 'org-down-element)
18578 (org-defkey org-mode-map "\C-c\C-f" 'org-forward-heading-same-level)
18579 (org-defkey org-mode-map "\C-c\C-b" 'org-backward-heading-same-level)
18580 (org-defkey org-mode-map "\C-c\M-f" 'org-next-block)
18581 (org-defkey org-mode-map "\C-c\M-b" 'org-previous-block)
18582 (org-defkey org-mode-map "\C-c$" 'org-archive-subtree)
18583 (org-defkey org-mode-map "\C-c\C-x\C-s" 'org-advertized-archive-subtree)
18584 (org-defkey org-mode-map "\C-c\C-x\C-a" 'org-archive-subtree-default)
18585 (org-defkey org-mode-map "\C-c\C-xd" 'org-insert-drawer)
18586 (org-defkey org-mode-map "\C-c\C-xa" 'org-toggle-archive-tag)
18587 (org-defkey org-mode-map "\C-c\C-xA" 'org-archive-to-archive-sibling)
18588 (org-defkey org-mode-map "\C-c\C-xb" 'org-tree-to-indirect-buffer)
18589 (org-defkey org-mode-map "\C-c\C-j" 'org-goto)
18590 (org-defkey org-mode-map "\C-c\C-t" 'org-todo)
18591 (org-defkey org-mode-map "\C-c\C-q" 'org-set-tags-command)
18592 (org-defkey org-mode-map "\C-c\C-s" 'org-schedule)
18593 (org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
18594 (org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
18595 (org-defkey org-mode-map "\C-c\C-w" 'org-refile)
18596 (org-defkey org-mode-map "\C-c\M-w" 'org-copy)
18597 (org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
18598 (org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
18599 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
18600 (org-defkey org-mode-map "\M-\C-m" 'org-insert-heading)
18601 (org-defkey org-mode-map "\C-c\C-xc" 'org-clone-subtree-with-time-shift)
18602 (org-defkey org-mode-map "\C-c\C-xv" 'org-copy-visible)
18603 (org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
18604 (org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
18605 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
18606 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
18607 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
18608 (org-defkey org-mode-map "\C-c\C-\M-l" 'org-insert-all-links)
18609 (org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
18610 (org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)
18611 (org-defkey org-mode-map "\C-c&" 'org-mark-ring-goto)
18612 (org-defkey org-mode-map "\C-c\C-z" 'org-add-note) ; Alternative binding
18613 (org-defkey org-mode-map "\C-c." 'org-time-stamp) ; Minor-mode reserved
18614 (org-defkey org-mode-map "\C-c!" 'org-time-stamp-inactive) ; Minor-mode r.
18615 (org-defkey org-mode-map "\C-c," 'org-priority) ; Minor-mode reserved
18616 (org-defkey org-mode-map "\C-c\C-y" 'org-evaluate-time-range)
18617 (org-defkey org-mode-map "\C-c>" 'org-goto-calendar)
18618 (org-defkey org-mode-map "\C-c<" 'org-date-from-calendar)
18619 (org-defkey org-mode-map [(control ?,)] 'org-cycle-agenda-files)
18620 (org-defkey org-mode-map [(control ?\')] 'org-cycle-agenda-files)
18621 (org-defkey org-mode-map "\C-c[" 'org-agenda-file-to-front)
18622 (org-defkey org-mode-map "\C-c]" 'org-remove-file)
18623 (org-defkey org-mode-map "\C-c\C-x<" 'org-agenda-set-restriction-lock)
18624 (org-defkey org-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
18625 (org-defkey org-mode-map "\C-c-" 'org-ctrl-c-minus)
18626 (org-defkey org-mode-map "\C-c*" 'org-ctrl-c-star)
18627 (org-defkey org-mode-map "\C-c^" 'org-sort)
18628 (org-defkey org-mode-map "\C-c\C-c" 'org-ctrl-c-ctrl-c)
18629 (org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
18630 (org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
18631 (org-defkey org-mode-map "\C-m" 'org-return)
18632 (org-defkey org-mode-map "\C-j" 'org-return-indent)
18633 (org-defkey org-mode-map "\C-c?" 'org-table-field-info)
18634 (org-defkey org-mode-map "\C-c " 'org-table-blank-field)
18635 (org-defkey org-mode-map "\C-c+" 'org-table-sum)
18636 (org-defkey org-mode-map "\C-c=" 'org-table-eval-formula)
18637 (org-defkey org-mode-map "\C-c'" 'org-edit-special)
18638 (org-defkey org-mode-map "\C-c`" 'org-table-edit-field)
18639 (org-defkey org-mode-map "\C-c|" 'org-table-create-or-convert-from-region)
18640 (org-defkey org-mode-map [(control ?#)] 'org-table-rotate-recalc-marks)
18641 (org-defkey org-mode-map "\C-c~" 'org-table-create-with-table.el)
18642 (org-defkey org-mode-map "\C-c\C-a" 'org-attach)
18643 (org-defkey org-mode-map "\C-c}" 'org-table-toggle-coordinate-overlays)
18644 (org-defkey org-mode-map "\C-c{" 'org-table-toggle-formula-debugger)
18645 (org-defkey org-mode-map "\C-c\C-e" 'org-export-dispatch)
18646 (org-defkey org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
18647 (org-defkey org-mode-map "\C-c\C-x\C-f" 'org-emphasize)
18648 (org-defkey org-mode-map "\C-c\C-xf" 'org-footnote-action)
18649 (org-defkey org-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
18650 (org-defkey org-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
18651 (org-defkey org-mode-map "\C-c@" 'org-mark-subtree)
18652 (org-defkey org-mode-map "\M-h" 'org-mark-element)
18653 (org-defkey org-mode-map [?\C-c (control ?*)] 'org-list-make-subtree)
18654 ;;(org-defkey org-mode-map [?\C-c (control ?-)] 'org-list-make-list-from-subtree)
18656 (org-defkey org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
18657 (org-defkey org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
18658 (org-defkey org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
18660 (org-defkey org-mode-map "\C-c\C-x\C-t" 'org-toggle-time-stamp-overlays)
18661 (org-defkey org-mode-map "\C-c\C-x\C-i" 'org-clock-in)
18662 (org-defkey org-mode-map "\C-c\C-x\C-x" 'org-clock-in-last)
18663 (org-defkey org-mode-map "\C-c\C-x\C-z" 'org-resolve-clocks)
18664 (org-defkey org-mode-map "\C-c\C-x\C-o" 'org-clock-out)
18665 (org-defkey org-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
18666 (org-defkey org-mode-map "\C-c\C-x\C-q" 'org-clock-cancel)
18667 (org-defkey org-mode-map "\C-c\C-x\C-d" 'org-clock-display)
18668 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
18669 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
18670 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
18671 (org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
18672 (org-defkey org-mode-map "\C-c\C-x\C-\M-v" 'org-redisplay-inline-images)
18673 (org-defkey org-mode-map "\C-c\C-x\\" 'org-toggle-pretty-entities)
18674 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
18675 (org-defkey org-mode-map "\C-c\C-xp" 'org-set-property)
18676 (org-defkey org-mode-map "\C-c\C-xP" 'org-set-property-and-value)
18677 (org-defkey org-mode-map "\C-c\C-xe" 'org-set-effort)
18678 (org-defkey org-mode-map "\C-c\C-xE" 'org-inc-effort)
18679 (org-defkey org-mode-map "\C-c\C-xo" 'org-toggle-ordered-property)
18680 (org-defkey org-mode-map "\C-c\C-xi" 'org-insert-columns-dblock)
18681 (org-defkey org-mode-map [(control ?c) (control ?x) ?\;] 'org-timer-set-timer)
18682 (org-defkey org-mode-map [(control ?c) (control ?x) ?\:] 'org-timer-cancel-timer)
18684 (org-defkey org-mode-map "\C-c\C-x." 'org-timer)
18685 (org-defkey org-mode-map "\C-c\C-x-" 'org-timer-item)
18686 (org-defkey org-mode-map "\C-c\C-x0" 'org-timer-start)
18687 (org-defkey org-mode-map "\C-c\C-x_" 'org-timer-stop)
18688 (org-defkey org-mode-map "\C-c\C-x," 'org-timer-pause-or-continue)
18690 (define-key org-mode-map "\C-c\C-x\C-c" 'org-columns)
18692 (define-key org-mode-map "\C-c\C-x!" 'org-reload)
18694 (define-key org-mode-map "\C-c\C-xg" 'org-feed-update-all)
18695 (define-key org-mode-map "\C-c\C-xG" 'org-feed-goto-inbox)
18697 (define-key org-mode-map "\C-c\C-x[" 'org-reftex-citation)
18700 (when (featurep 'xemacs)
18701 (org-defkey org-mode-map 'button3 'popup-mode-menu))
18704 (defconst org-speed-commands-default
18706 ("Outline Navigation")
18707 ("n" . (org-speed-move-safe 'outline-next-visible-heading))
18708 ("p" . (org-speed-move-safe 'outline-previous-visible-heading))
18709 ("f" . (org-speed-move-safe 'org-forward-heading-same-level))
18710 ("b" . (org-speed-move-safe 'org-backward-heading-same-level))
18711 ("F" . org-next-block)
18712 ("B" . org-previous-block)
18713 ("u" . (org-speed-move-safe 'outline-up-heading))
18715 ("g" . (org-refile t))
18716 ("Outline Visibility")
18718 ("C" . org-shifttab)
18719 (" " . org-display-outline-path)
18720 ("=" . org-columns)
18721 ("Outline Structure Editing")
18722 ("U" . org-shiftmetaup)
18723 ("D" . org-shiftmetadown)
18724 ("r" . org-metaright)
18725 ("l" . org-metaleft)
18726 ("R" . org-shiftmetaright)
18727 ("L" . org-shiftmetaleft)
18728 ("i" . (progn (forward-char 1) (call-interactively
18729 'org-insert-heading-respect-content)))
18732 ("a" . org-archive-subtree-default-with-confirmation)
18733 ("." . org-mark-subtree) ;; FIXME Better use @ (see C-c @) here?
18734 ("#" . org-toggle-comment)
18736 ("I" . org-clock-in)
18737 ("O" . org-clock-out)
18738 ("Meta Data Editing")
18740 ("," . (org-priority))
18741 ("0" . (org-priority ?\ ))
18742 ("1" . (org-priority ?A))
18743 ("2" . (org-priority ?B))
18744 ("3" . (org-priority ?C))
18745 (":" . org-set-tags-command)
18746 ("e" . org-set-effort)
18747 ("E" . org-inc-effort)
18748 ("W" . (lambda(m) (interactive "sMinutes before warning: ")
18749 (org-entry-put (point) "APPT_WARNTIME" m)))
18750 ("Agenda Views etc")
18752 ("/" . org-sparse-tree)
18754 ("o" . org-open-at-point)
18755 ("?" . org-speed-command-help)
18756 ("<" . (org-agenda-set-restriction-lock 'subtree))
18757 (">" . (org-agenda-remove-restriction-lock))
18759 "The default speed commands.")
18761 (defun org-print-speed-command (e)
18762 (if (> (length (car e)) 1)
18767 (princ (make-string (length (car e)) ?-))
18771 (if (symbolp (cdr e))
18772 (princ (symbol-name (cdr e)))
18776 (defun org-speed-command-help ()
18777 "Show the available speed commands."
18779 (if (not org-use-speed-commands)
18780 (error "Speed commands are not activated, customize `org-use-speed-commands'")
18781 (with-output-to-temp-buffer "*Help*"
18782 (princ "User-defined Speed commands\n===========================\n")
18783 (mapc 'org-print-speed-command org-speed-commands-user)
18785 (princ "Built-in Speed commands\n=======================\n")
18786 (mapc 'org-print-speed-command org-speed-commands-default))
18787 (with-current-buffer "*Help*"
18788 (setq truncate-lines t))))
18790 (defun org-speed-move-safe (cmd)
18791 "Execute CMD, but make sure that the cursor always ends up in a headline.
18792 If not, return to the original position and throw an error."
18794 (let ((pos (point)))
18795 (call-interactively cmd)
18796 (unless (and (bolp) (org-at-heading-p))
18798 (error "Boundary reached while executing %s" cmd))))
18800 (defvar org-self-insert-command-undo-counter 0)
18802 (defvar org-table-auto-blank-field) ; defined in org-table.el
18803 (defvar org-speed-command nil)
18805 (define-obsolete-function-alias
18806 'org-speed-command-default-hook 'org-speed-command-activate "24.3")
18808 (defun org-speed-command-activate (keys)
18809 "Hook for activating single-letter speed commands.
18810 `org-speed-commands-default' specifies a minimal command set.
18811 Use `org-speed-commands-user' for further customization."
18812 (when (or (and (bolp) (looking-at org-outline-regexp))
18813 (and (functionp org-use-speed-commands)
18814 (funcall org-use-speed-commands)))
18815 (cdr (assoc keys (append org-speed-commands-user
18816 org-speed-commands-default)))))
18818 (define-obsolete-function-alias
18819 'org-babel-speed-command-hook 'org-babel-speed-command-activate "24.3")
18821 (defun org-babel-speed-command-activate (keys)
18822 "Hook for activating single-letter code block commands."
18823 (when (and (bolp) (looking-at org-babel-src-block-regexp))
18824 (cdr (assoc keys org-babel-key-bindings))))
18826 (defcustom org-speed-command-hook
18827 '(org-speed-command-default-hook org-babel-speed-command-hook)
18828 "Hook for activating speed commands at strategic locations.
18829 Hook functions are called in sequence until a valid handler is
18832 Each hook takes a single argument, a user-pressed command key
18833 which is also a `self-insert-command' from the global map.
18835 Within the hook, examine the cursor position and the command key
18836 and return nil or a valid handler as appropriate. Handler could
18837 be one of an interactive command, a function, or a form.
18839 Set `org-use-speed-commands' to non-nil value to enable this
18840 hook. The default setting is `org-speed-command-activate'."
18841 :group 'org-structure
18845 (defun org-self-insert-command (N)
18846 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
18847 If the cursor is in a table looking at whitespace, the whitespace is
18848 overwritten, and the table is not marked as requiring realignment."
18850 (org-check-before-invisible-edit 'insert)
18852 ((and org-use-speed-commands
18853 (setq org-speed-command
18854 (run-hook-with-args-until-success
18855 'org-speed-command-hook (this-command-keys))))
18857 ((commandp org-speed-command)
18858 (setq this-command org-speed-command)
18859 (call-interactively org-speed-command))
18860 ((functionp org-speed-command)
18861 (funcall org-speed-command))
18862 ((and org-speed-command (listp org-speed-command))
18863 (eval org-speed-command))
18864 (t (let (org-use-speed-commands)
18865 (call-interactively 'org-self-insert-command)))))
18869 ;; check if we blank the field, and if that triggers align
18870 (and (featurep 'org-table) org-table-auto-blank-field
18871 (member last-command
18872 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c yas/expand))
18873 (if (or (equal (char-after) ?\ ) (looking-at "[^|\n]* |"))
18874 ;; got extra space, this field does not determine column width
18875 (let (org-table-may-need-update) (org-table-blank-field))
18876 ;; no extra space, this field may determine column width
18877 (org-table-blank-field)))
18880 (looking-at "[^|\n]* |"))
18881 (let (org-table-may-need-update)
18882 (goto-char (1- (match-end 0)))
18883 (backward-delete-char 1)
18884 (goto-char (match-beginning 0))
18885 (self-insert-command N)))
18887 (setq org-table-may-need-update t)
18888 (self-insert-command N)
18889 (org-fix-tags-on-the-fly)
18890 (if org-self-insert-cluster-for-undo
18891 (if (not (eq last-command 'org-self-insert-command))
18892 (setq org-self-insert-command-undo-counter 1)
18893 (if (>= org-self-insert-command-undo-counter 20)
18894 (setq org-self-insert-command-undo-counter 1)
18895 (and (> org-self-insert-command-undo-counter 0)
18896 buffer-undo-list (listp buffer-undo-list)
18897 (not (cadr buffer-undo-list)) ; remove nil entry
18898 (setcdr buffer-undo-list (cddr buffer-undo-list)))
18899 (setq org-self-insert-command-undo-counter
18900 (1+ org-self-insert-command-undo-counter))))))))
18902 (defun org-check-before-invisible-edit (kind)
18903 "Check is editing if kind KIND would be dangerous with invisible text around.
18904 The detailed reaction depends on the user option `org-catch-invisible-edits'."
18905 ;; First, try to get out of here as quickly as possible, to reduce overhead
18906 (if (and org-catch-invisible-edits
18907 (or (not (boundp 'visible-mode)) (not visible-mode))
18908 (or (get-char-property (point) 'invisible)
18909 (get-char-property (max (point-min) (1- (point))) 'invisible)))
18910 ;; OK, we need to take a closer look
18911 (let* ((invisible-at-point (get-char-property (point) 'invisible))
18912 (invisible-before-point (if (bobp) nil (get-char-property
18913 (1- (point)) 'invisible)))
18914 (border-and-ok-direction
18916 ;; Check if we are acting predictably before invisible text
18917 (and invisible-at-point (not invisible-before-point)
18918 (memq kind '(insert delete-backward)))
18919 ;; Check if we are acting predictably after invisible text
18920 ;; This works not well, and I have turned it off. It seems
18921 ;; better to always show and stop after invisible text.
18922 ;; (and (not invisible-at-point) invisible-before-point
18923 ;; (memq kind '(insert delete)))
18925 (when (or (memq invisible-at-point '(outline org-hide-block t))
18926 (memq invisible-before-point '(outline org-hide-block t)))
18927 (if (eq org-catch-invisible-edits 'error)
18928 (error "Editing in invisible areas is prohibited - make visible first"))
18929 (if (and org-custom-properties-overlays
18930 (y-or-n-p "Display invisible properties in this buffer? "))
18931 (org-toggle-custom-properties-visibility)
18932 ;; Make the area visible
18934 (if invisible-before-point
18935 (goto-char (previous-single-char-property-change
18936 (point) 'invisible)))
18939 ((eq org-catch-invisible-edits 'show)
18940 ;; That's it, we do the edit after showing
18942 "Unfolding invisible region around point before editing")
18944 ((and (eq org-catch-invisible-edits 'smart)
18945 border-and-ok-direction)
18946 (message "Unfolding invisible region around point before editing"))
18948 ;; Don't do the edit, make the user repeat it in full visibility
18949 (error "Edit in invisible region aborted, repeat to confirm with text visible"))))))))
18951 (defun org-fix-tags-on-the-fly ()
18952 (when (and (equal (char-after (point-at-bol)) ?*)
18953 (org-at-heading-p))
18954 (org-align-tags-here org-tags-column)))
18956 (defun org-delete-backward-char (N)
18957 "Like `delete-backward-char', insert whitespace at field end in tables.
18958 When deleting backwards, in tables this function will insert whitespace in
18959 front of the next \"|\" separator, to keep the table aligned. The table will
18960 still be marked for re-alignment if the field did fill the entire column,
18961 because, in this case the deletion might narrow the column."
18964 (org-check-before-invisible-edit 'delete-backward)
18965 (if (and (org-table-p)
18967 (string-match "|" (buffer-substring (point-at-bol) (point)))
18968 (looking-at ".*?|"))
18969 (let ((pos (point))
18970 (noalign (looking-at "[^|\n\r]* |"))
18971 (c org-table-may-need-update))
18972 (backward-delete-char N)
18973 (if (not overwrite-mode)
18975 (skip-chars-forward "^|")
18977 (goto-char (1- pos))))
18978 ;; noalign: if there were two spaces at the end, this field
18979 ;; does not determine the width of the column.
18980 (if noalign (setq org-table-may-need-update c)))
18981 (backward-delete-char N)
18982 (org-fix-tags-on-the-fly))))
18984 (defun org-delete-char (N)
18985 "Like `delete-char', but insert whitespace at field end in tables.
18986 When deleting characters, in tables this function will insert whitespace in
18987 front of the next \"|\" separator, to keep the table aligned. The table will
18988 still be marked for re-alignment if the field did fill the entire column,
18989 because, in this case the deletion might narrow the column."
18992 (org-check-before-invisible-edit 'delete)
18993 (if (and (org-table-p)
18995 (not (= (char-after) ?|))
18997 (if (looking-at ".*?|")
18998 (let ((pos (point))
18999 (noalign (looking-at "[^|\n\r]* |"))
19000 (c org-table-may-need-update))
19001 (replace-match (concat
19002 (substring (match-string 0) 1 -1)
19005 ;; noalign: if there were two spaces at the end, this field
19006 ;; does not determine the width of the column.
19007 (if noalign (setq org-table-may-need-update c)))
19010 (org-fix-tags-on-the-fly))))
19012 ;; Make `delete-selection-mode' work with org-mode and orgtbl-mode
19013 (put 'org-self-insert-command 'delete-selection t)
19014 (put 'orgtbl-self-insert-command 'delete-selection t)
19015 (put 'org-delete-char 'delete-selection 'supersede)
19016 (put 'org-delete-backward-char 'delete-selection 'supersede)
19017 (put 'org-yank 'delete-selection 'yank)
19019 ;; Make `flyspell-mode' delay after some commands
19020 (put 'org-self-insert-command 'flyspell-delayed t)
19021 (put 'orgtbl-self-insert-command 'flyspell-delayed t)
19022 (put 'org-delete-char 'flyspell-delayed t)
19023 (put 'org-delete-backward-char 'flyspell-delayed t)
19025 ;; Make pabbrev-mode expand after org-mode commands
19026 (put 'org-self-insert-command 'pabbrev-expand-after-command t)
19027 (put 'orgtbl-self-insert-command 'pabbrev-expand-after-command t)
19029 ;; How to do this: Measure non-white length of current string
19030 ;; If equal to column width, we should realign.
19032 (defun org-remap (map &rest commands)
19033 "In MAP, remap the functions given in COMMANDS.
19034 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
19037 (setq old (pop commands) new (pop commands))
19038 (if (fboundp 'command-remapping)
19039 (org-defkey map (vector 'remap old) new)
19040 (substitute-key-definition old new map global-map)))))
19042 (defun org-transpose-words ()
19043 "Transpose words for Org.
19044 This uses the `org-mode-transpose-word-syntax-table' syntax
19045 table, which interprets characters in `org-emphasis-alist' as
19046 word constituants."
19048 (with-syntax-table org-mode-transpose-word-syntax-table
19049 (call-interactively 'transpose-words)))
19050 (org-remap org-mode-map 'transpose-words 'org-transpose-words)
19052 (when (eq org-enable-table-editor 'optimized)
19053 ;; If the user wants maximum table support, we need to hijack
19054 ;; some standard editing functions
19055 (org-remap org-mode-map
19056 'self-insert-command 'org-self-insert-command
19057 'delete-char 'org-delete-char
19058 'delete-backward-char 'org-delete-backward-char)
19059 (org-defkey org-mode-map "|" 'org-force-self-insert))
19061 (defvar org-ctrl-c-ctrl-c-hook nil
19062 "Hook for functions attaching themselves to `C-c C-c'.
19064 This can be used to add additional functionality to the C-c C-c
19065 key which executes context-dependent commands. This hook is run
19066 before any other test, while `org-ctrl-c-ctrl-c-final-hook' is
19067 run after the last test.
19069 Each function will be called with no arguments. The function
19070 must check if the context is appropriate for it to act. If yes,
19071 it should do its thing and then return a non-nil value. If the
19072 context is wrong, just do nothing and return nil.")
19074 (defvar org-ctrl-c-ctrl-c-final-hook nil
19075 "Hook for functions attaching themselves to `C-c C-c'.
19077 This can be used to add additional functionality to the C-c C-c
19078 key which executes context-dependent commands. This hook is run
19079 after any other test, while `org-ctrl-c-ctrl-c-hook' is run
19080 before the first test.
19082 Each function will be called with no arguments. The function
19083 must check if the context is appropriate for it to act. If yes,
19084 it should do its thing and then return a non-nil value. If the
19085 context is wrong, just do nothing and return nil.")
19087 (defvar org-tab-first-hook nil
19088 "Hook for functions to attach themselves to TAB.
19089 See `org-ctrl-c-ctrl-c-hook' for more information.
19090 This hook runs as the first action when TAB is pressed, even before
19091 `org-cycle' messes around with the `outline-regexp' to cater for
19092 inline tasks and plain list item folding.
19093 If any function in this hook returns t, any other actions that
19094 would have been caused by TAB (such as table field motion or visibility
19095 cycling) will not occur.")
19097 (defvar org-tab-after-check-for-table-hook nil
19098 "Hook for functions to attach themselves to TAB.
19099 See `org-ctrl-c-ctrl-c-hook' for more information.
19100 This hook runs after it has been established that the cursor is not in a
19101 table, but before checking if the cursor is in a headline or if global cycling
19103 If any function in this hook returns t, not other actions like visibility
19104 cycling will be done.")
19106 (defvar org-tab-after-check-for-cycling-hook nil
19107 "Hook for functions to attach themselves to TAB.
19108 See `org-ctrl-c-ctrl-c-hook' for more information.
19109 This hook runs after it has been established that not table field motion and
19110 not visibility should be done because of current context. This is probably
19111 the place where a package like yasnippets can hook in.")
19113 (defvar org-tab-before-tab-emulation-hook nil
19114 "Hook for functions to attach themselves to TAB.
19115 See `org-ctrl-c-ctrl-c-hook' for more information.
19116 This hook runs after every other options for TAB have been exhausted, but
19117 before indentation and \t insertion takes place.")
19119 (defvar org-metaleft-hook nil
19120 "Hook for functions attaching themselves to `M-left'.
19121 See `org-ctrl-c-ctrl-c-hook' for more information.")
19122 (defvar org-metaright-hook nil
19123 "Hook for functions attaching themselves to `M-right'.
19124 See `org-ctrl-c-ctrl-c-hook' for more information.")
19125 (defvar org-metaup-hook nil
19126 "Hook for functions attaching themselves to `M-up'.
19127 See `org-ctrl-c-ctrl-c-hook' for more information.")
19128 (defvar org-metadown-hook nil
19129 "Hook for functions attaching themselves to `M-down'.
19130 See `org-ctrl-c-ctrl-c-hook' for more information.")
19131 (defvar org-shiftmetaleft-hook nil
19132 "Hook for functions attaching themselves to `M-S-left'.
19133 See `org-ctrl-c-ctrl-c-hook' for more information.")
19134 (defvar org-shiftmetaright-hook nil
19135 "Hook for functions attaching themselves to `M-S-right'.
19136 See `org-ctrl-c-ctrl-c-hook' for more information.")
19137 (defvar org-shiftmetaup-hook nil
19138 "Hook for functions attaching themselves to `M-S-up'.
19139 See `org-ctrl-c-ctrl-c-hook' for more information.")
19140 (defvar org-shiftmetadown-hook nil
19141 "Hook for functions attaching themselves to `M-S-down'.
19142 See `org-ctrl-c-ctrl-c-hook' for more information.")
19143 (defvar org-metareturn-hook nil
19144 "Hook for functions attaching themselves to `M-RET'.
19145 See `org-ctrl-c-ctrl-c-hook' for more information.")
19146 (defvar org-shiftup-hook nil
19147 "Hook for functions attaching themselves to `S-up'.
19148 See `org-ctrl-c-ctrl-c-hook' for more information.")
19149 (defvar org-shiftup-final-hook nil
19150 "Hook for functions attaching themselves to `S-up'.
19151 This one runs after all other options except shift-select have been excluded.
19152 See `org-ctrl-c-ctrl-c-hook' for more information.")
19153 (defvar org-shiftdown-hook nil
19154 "Hook for functions attaching themselves to `S-down'.
19155 See `org-ctrl-c-ctrl-c-hook' for more information.")
19156 (defvar org-shiftdown-final-hook nil
19157 "Hook for functions attaching themselves to `S-down'.
19158 This one runs after all other options except shift-select have been excluded.
19159 See `org-ctrl-c-ctrl-c-hook' for more information.")
19160 (defvar org-shiftleft-hook nil
19161 "Hook for functions attaching themselves to `S-left'.
19162 See `org-ctrl-c-ctrl-c-hook' for more information.")
19163 (defvar org-shiftleft-final-hook nil
19164 "Hook for functions attaching themselves to `S-left'.
19165 This one runs after all other options except shift-select have been excluded.
19166 See `org-ctrl-c-ctrl-c-hook' for more information.")
19167 (defvar org-shiftright-hook nil
19168 "Hook for functions attaching themselves to `S-right'.
19169 See `org-ctrl-c-ctrl-c-hook' for more information.")
19170 (defvar org-shiftright-final-hook nil
19171 "Hook for functions attaching themselves to `S-right'.
19172 This one runs after all other options except shift-select have been excluded.
19173 See `org-ctrl-c-ctrl-c-hook' for more information.")
19175 (defun org-modifier-cursor-error ()
19176 "Throw an error, a modified cursor command was applied in wrong context."
19177 (error "This command is active in special context like tables, headlines or items"))
19179 (defun org-shiftselect-error ()
19180 "Throw an error because Shift-Cursor command was applied in wrong context."
19181 (if (and (boundp 'shift-select-mode) shift-select-mode)
19182 (error "To use shift-selection with Org-mode, customize `org-support-shift-select'")
19183 (error "This command works only in special context like headlines or timestamps")))
19185 (defun org-call-for-shift-select (cmd)
19186 (let ((this-command-keys-shift-translated t))
19187 (call-interactively cmd)))
19189 (defun org-shifttab (&optional arg)
19190 "Global visibility cycling or move to previous table field.
19191 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
19193 See the individual commands for more information."
19196 ((org-at-table-p) (call-interactively 'org-table-previous-field))
19198 (let ((arg2 (if org-odd-levels-only (1- (* 2 arg)) arg)))
19199 (message "Content view to level: %d" arg)
19200 (org-content (prefix-numeric-value arg2))
19201 (setq org-cycle-global-status 'overview)))
19202 (t (call-interactively 'org-global-cycle))))
19204 (defun org-shiftmetaleft ()
19205 "Promote subtree or delete table column.
19206 Calls `org-promote-subtree', `org-outdent-item-tree', or
19207 `org-table-delete-column', depending on context. See the
19208 individual commands for more information."
19211 ((run-hook-with-args-until-success 'org-shiftmetaleft-hook))
19212 ((org-at-table-p) (call-interactively 'org-table-delete-column))
19213 ((org-at-heading-p) (call-interactively 'org-promote-subtree))
19214 ((if (not (org-region-active-p)) (org-at-item-p)
19215 (save-excursion (goto-char (region-beginning))
19217 (call-interactively 'org-outdent-item-tree))
19218 (t (org-modifier-cursor-error))))
19220 (defun org-shiftmetaright ()
19221 "Demote subtree or insert table column.
19222 Calls `org-demote-subtree', `org-indent-item-tree', or
19223 `org-table-insert-column', depending on context. See the
19224 individual commands for more information."
19227 ((run-hook-with-args-until-success 'org-shiftmetaright-hook))
19228 ((org-at-table-p) (call-interactively 'org-table-insert-column))
19229 ((org-at-heading-p) (call-interactively 'org-demote-subtree))
19230 ((if (not (org-region-active-p)) (org-at-item-p)
19231 (save-excursion (goto-char (region-beginning))
19233 (call-interactively 'org-indent-item-tree))
19234 (t (org-modifier-cursor-error))))
19236 (defun org-shiftmetaup (&optional arg)
19237 "Move subtree up or kill table row.
19238 Calls `org-move-subtree-up' or `org-table-kill-row' or
19239 `org-move-item-up' or `org-timestamp-up', depending on context.
19240 See the individual commands for more information."
19243 ((run-hook-with-args-until-success 'org-shiftmetaup-hook))
19244 ((org-at-table-p) (call-interactively 'org-table-kill-row))
19245 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
19246 ((org-at-item-p) (call-interactively 'org-move-item-up))
19247 ((org-at-clock-log-p) (let ((org-clock-adjust-closest t))
19248 (call-interactively 'org-timestamp-up)))
19249 (t (call-interactively 'org-drag-line-backward))))
19251 (defun org-shiftmetadown (&optional arg)
19252 "Move subtree down or insert table row.
19253 Calls `org-move-subtree-down' or `org-table-insert-row' or
19254 `org-move-item-down' or `org-timestamp-up', depending on context.
19255 See the individual commands for more information."
19258 ((run-hook-with-args-until-success 'org-shiftmetadown-hook))
19259 ((org-at-table-p) (call-interactively 'org-table-insert-row))
19260 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
19261 ((org-at-item-p) (call-interactively 'org-move-item-down))
19262 ((org-at-clock-log-p) (let ((org-clock-adjust-closest t))
19263 (call-interactively 'org-timestamp-down)))
19264 (t (call-interactively 'org-drag-line-forward))))
19266 (defsubst org-hidden-tree-error ()
19268 "Hidden subtree, open with TAB or use subtree command M-S-<left>/<right>"))
19270 (defun org-metaleft (&optional arg)
19271 "Promote heading or move table column to left.
19272 Calls `org-do-promote' or `org-table-move-column', depending on context.
19273 With no specific context, calls the Emacs default `backward-word'.
19274 See the individual commands for more information."
19277 ((run-hook-with-args-until-success 'org-metaleft-hook))
19278 ((org-at-table-p) (org-call-with-arg 'org-table-move-column 'left))
19279 ((org-with-limited-levels
19280 (or (org-at-heading-p)
19281 (and (org-region-active-p)
19283 (goto-char (region-beginning))
19284 (org-at-heading-p)))))
19285 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
19286 (call-interactively 'org-do-promote))
19287 ;; At an inline task.
19288 ((org-at-heading-p)
19289 (call-interactively 'org-inlinetask-promote))
19290 ((or (org-at-item-p)
19291 (and (org-region-active-p)
19293 (goto-char (region-beginning))
19295 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
19296 (call-interactively 'org-outdent-item))
19297 (t (call-interactively 'backward-word))))
19299 (defun org-metaright (&optional arg)
19300 "Demote a subtree, a list item or move table column to right.
19301 In front of a drawer or a block keyword, indent it correctly.
19302 With no specific context, calls the Emacs default `forward-word'.
19303 See the individual commands for more information."
19306 ((run-hook-with-args-until-success 'org-metaright-hook))
19307 ((org-at-table-p) (call-interactively 'org-table-move-column))
19308 ((org-at-drawer-p) (call-interactively 'org-indent-drawer))
19309 ((org-at-block-p) (call-interactively 'org-indent-block))
19310 ((org-with-limited-levels
19311 (or (org-at-heading-p)
19312 (and (org-region-active-p)
19314 (goto-char (region-beginning))
19315 (org-at-heading-p)))))
19316 (when (org-check-for-hidden 'headlines) (org-hidden-tree-error))
19317 (call-interactively 'org-do-demote))
19318 ;; At an inline task.
19319 ((org-at-heading-p)
19320 (call-interactively 'org-inlinetask-demote))
19321 ((or (org-at-item-p)
19322 (and (org-region-active-p)
19324 (goto-char (region-beginning))
19326 (when (org-check-for-hidden 'items) (org-hidden-tree-error))
19327 (call-interactively 'org-indent-item))
19328 (t (call-interactively 'forward-word))))
19330 (defun org-check-for-hidden (what)
19331 "Check if there are hidden headlines/items in the current visual line.
19332 WHAT can be either `headlines' or `items'. If the current line is
19333 an outline or item heading and it has a folded subtree below it,
19334 this function returns t, nil otherwise."
19336 ((eq what 'headlines) org-outline-regexp-bol)
19337 ((eq what 'items) (org-item-beginning-re))
19338 (t (error "This should not happen"))))
19342 (unless (org-region-active-p)
19343 (setq beg (point-at-bol))
19344 (beginning-of-line 2)
19345 (while (and (not (eobp)) ;; this is like `next-line'
19346 (get-char-property (1- (point)) 'invisible))
19347 (beginning-of-line 2))
19350 (goto-char (point-at-eol))
19351 (setq end (max end (point)))
19352 (while (re-search-forward re end t)
19353 (if (get-char-property (match-beginning 0) 'invisible)
19357 (defun org-metaup (&optional arg)
19358 "Move subtree up or move table row up.
19359 Calls `org-move-subtree-up' or `org-table-move-row' or
19360 `org-move-item-up', depending on context. See the individual commands
19361 for more information."
19364 ((run-hook-with-args-until-success 'org-metaup-hook))
19365 ((org-region-active-p)
19366 (let* ((a (min (region-beginning) (region-end)))
19367 (b (1- (max (region-beginning) (region-end))))
19368 (c (save-excursion (goto-char a)
19369 (move-beginning-of-line 0)))
19370 (d (save-excursion (goto-char a)
19371 (move-end-of-line 0) (point))))
19372 (transpose-regions a b c d)
19374 ((org-at-table-p) (org-call-with-arg 'org-table-move-row 'up))
19375 ((org-at-heading-p) (call-interactively 'org-move-subtree-up))
19376 ((org-at-item-p) (call-interactively 'org-move-item-up))
19377 (t (org-drag-element-backward))))
19379 (defun org-metadown (&optional arg)
19380 "Move subtree down or move table row down.
19381 Calls `org-move-subtree-down' or `org-table-move-row' or
19382 `org-move-item-down', depending on context. See the individual
19383 commands for more information."
19386 ((run-hook-with-args-until-success 'org-metadown-hook))
19387 ((org-region-active-p)
19388 (let* ((a (min (region-beginning) (region-end)))
19389 (b (max (region-beginning) (region-end)))
19390 (c (save-excursion (goto-char b)
19391 (move-beginning-of-line 1)))
19392 (d (save-excursion (goto-char b)
19393 (move-end-of-line 1) (1+ (point)))))
19394 (transpose-regions a b c d)
19396 ((org-at-table-p) (call-interactively 'org-table-move-row))
19397 ((org-at-heading-p) (call-interactively 'org-move-subtree-down))
19398 ((org-at-item-p) (call-interactively 'org-move-item-down))
19399 (t (org-drag-element-forward))))
19401 (defun org-shiftup (&optional arg)
19402 "Increase item in timestamp or increase priority of current headline.
19403 Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
19404 depending on context. See the individual commands for more information."
19407 ((run-hook-with-args-until-success 'org-shiftup-hook))
19408 ((and org-support-shift-select (org-region-active-p))
19409 (org-call-for-shift-select 'previous-line))
19410 ((org-at-timestamp-p t)
19411 (call-interactively (if org-edit-timestamp-down-means-later
19412 'org-timestamp-down 'org-timestamp-up)))
19413 ((and (not (eq org-support-shift-select 'always))
19414 org-enable-priority-commands
19415 (org-at-heading-p))
19416 (call-interactively 'org-priority-up))
19417 ((and (not org-support-shift-select) (org-at-item-p))
19418 (call-interactively 'org-previous-item))
19419 ((org-clocktable-try-shift 'up arg))
19420 ((run-hook-with-args-until-success 'org-shiftup-final-hook))
19421 (org-support-shift-select
19422 (org-call-for-shift-select 'previous-line))
19423 (t (org-shiftselect-error))))
19425 (defun org-shiftdown (&optional arg)
19426 "Decrease item in timestamp or decrease priority of current headline.
19427 Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
19428 depending on context. See the individual commands for more information."
19431 ((run-hook-with-args-until-success 'org-shiftdown-hook))
19432 ((and org-support-shift-select (org-region-active-p))
19433 (org-call-for-shift-select 'next-line))
19434 ((org-at-timestamp-p t)
19435 (call-interactively (if org-edit-timestamp-down-means-later
19436 'org-timestamp-up 'org-timestamp-down)))
19437 ((and (not (eq org-support-shift-select 'always))
19438 org-enable-priority-commands
19439 (org-at-heading-p))
19440 (call-interactively 'org-priority-down))
19441 ((and (not org-support-shift-select) (org-at-item-p))
19442 (call-interactively 'org-next-item))
19443 ((org-clocktable-try-shift 'down arg))
19444 ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
19445 (org-support-shift-select
19446 (org-call-for-shift-select 'next-line))
19447 (t (org-shiftselect-error))))
19449 (defun org-shiftright (&optional arg)
19450 "Cycle the thing at point or in the current line, depending on context.
19451 Depending on context, this does one of the following:
19453 - switch a timestamp at point one day into the future
19454 - on a headline, switch to the next TODO keyword.
19455 - on an item, switch entire list to the next bullet type
19456 - on a property line, switch to the next allowed value
19457 - on a clocktable definition line, move time block into the future"
19460 ((run-hook-with-args-until-success 'org-shiftright-hook))
19461 ((and org-support-shift-select (org-region-active-p))
19462 (org-call-for-shift-select 'forward-char))
19463 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-up-day))
19464 ((and (not (eq org-support-shift-select 'always))
19465 (org-at-heading-p))
19466 (let ((org-inhibit-logging
19467 (not org-treat-S-cursor-todo-selection-as-state-change))
19468 (org-inhibit-blocking
19469 (not org-treat-S-cursor-todo-selection-as-state-change)))
19470 (org-call-with-arg 'org-todo 'right)))
19471 ((or (and org-support-shift-select
19472 (not (eq org-support-shift-select 'always))
19473 (org-at-item-bullet-p))
19474 (and (not org-support-shift-select) (org-at-item-p)))
19475 (org-call-with-arg 'org-cycle-list-bullet nil))
19476 ((and (not (eq org-support-shift-select 'always))
19477 (org-at-property-p))
19478 (call-interactively 'org-property-next-allowed-value))
19479 ((org-clocktable-try-shift 'right arg))
19480 ((run-hook-with-args-until-success 'org-shiftright-final-hook))
19481 (org-support-shift-select
19482 (org-call-for-shift-select 'forward-char))
19483 (t (org-shiftselect-error))))
19485 (defun org-shiftleft (&optional arg)
19486 "Cycle the thing at point or in the current line, depending on context.
19487 Depending on context, this does one of the following:
19489 - switch a timestamp at point one day into the past
19490 - on a headline, switch to the previous TODO keyword.
19491 - on an item, switch entire list to the previous bullet type
19492 - on a property line, switch to the previous allowed value
19493 - on a clocktable definition line, move time block into the past"
19496 ((run-hook-with-args-until-success 'org-shiftleft-hook))
19497 ((and org-support-shift-select (org-region-active-p))
19498 (org-call-for-shift-select 'backward-char))
19499 ((org-at-timestamp-p t) (call-interactively 'org-timestamp-down-day))
19500 ((and (not (eq org-support-shift-select 'always))
19501 (org-at-heading-p))
19502 (let ((org-inhibit-logging
19503 (not org-treat-S-cursor-todo-selection-as-state-change))
19504 (org-inhibit-blocking
19505 (not org-treat-S-cursor-todo-selection-as-state-change)))
19506 (org-call-with-arg 'org-todo 'left)))
19507 ((or (and org-support-shift-select
19508 (not (eq org-support-shift-select 'always))
19509 (org-at-item-bullet-p))
19510 (and (not org-support-shift-select) (org-at-item-p)))
19511 (org-call-with-arg 'org-cycle-list-bullet 'previous))
19512 ((and (not (eq org-support-shift-select 'always))
19513 (org-at-property-p))
19514 (call-interactively 'org-property-previous-allowed-value))
19515 ((org-clocktable-try-shift 'left arg))
19516 ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
19517 (org-support-shift-select
19518 (org-call-for-shift-select 'backward-char))
19519 (t (org-shiftselect-error))))
19521 (defun org-shiftcontrolright ()
19522 "Switch to next TODO set."
19525 ((and org-support-shift-select (org-region-active-p))
19526 (org-call-for-shift-select 'forward-word))
19527 ((and (not (eq org-support-shift-select 'always))
19528 (org-at-heading-p))
19529 (org-call-with-arg 'org-todo 'nextset))
19530 (org-support-shift-select
19531 (org-call-for-shift-select 'forward-word))
19532 (t (org-shiftselect-error))))
19534 (defun org-shiftcontrolleft ()
19535 "Switch to previous TODO set."
19538 ((and org-support-shift-select (org-region-active-p))
19539 (org-call-for-shift-select 'backward-word))
19540 ((and (not (eq org-support-shift-select 'always))
19541 (org-at-heading-p))
19542 (org-call-with-arg 'org-todo 'previousset))
19543 (org-support-shift-select
19544 (org-call-for-shift-select 'backward-word))
19545 (t (org-shiftselect-error))))
19547 (defun org-shiftcontrolup (&optional n)
19548 "Change timestamps synchronously up in CLOCK log lines.
19549 Optional argument N tells to change by that many units."
19551 (cond ((and (not org-support-shift-select)
19552 (org-at-clock-log-p)
19553 (org-at-timestamp-p t))
19554 (org-clock-timestamps-up n))
19555 (t (org-shiftselect-error))))
19557 (defun org-shiftcontroldown (&optional n)
19558 "Change timestamps synchronously down in CLOCK log lines.
19559 Optional argument N tells to change by that many units."
19561 (cond ((and (not org-support-shift-select)
19562 (org-at-clock-log-p)
19563 (org-at-timestamp-p t))
19564 (org-clock-timestamps-down n))
19565 (t (org-shiftselect-error))))
19567 (defun org-ctrl-c-ret ()
19568 "Call `org-table-hline-and-move' or `org-insert-heading' dep. on context."
19571 ((org-at-table-p) (call-interactively 'org-table-hline-and-move))
19572 (t (call-interactively 'org-insert-heading))))
19574 (defun org-find-visible ()
19576 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
19577 (get-char-property s 'invisible)))
19579 (defun org-find-invisible ()
19581 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
19582 (not (get-char-property s 'invisible))))
19585 (defun org-copy-visible (beg end)
19586 "Copy the visible parts of the region."
19591 (narrow-to-region beg end)
19592 (setq s (goto-char (point-min)))
19593 (while (not (= (point) (point-max)))
19594 (goto-char (org-find-invisible))
19595 (push (buffer-substring s (point)) snippets)
19596 (setq s (goto-char (org-find-visible))))))
19597 (kill-new (apply 'concat (nreverse snippets)))))
19599 (defun org-copy-special ()
19600 "Copy region in table or copy current subtree.
19601 Calls `org-table-copy' or `org-copy-subtree', depending on context.
19602 See the individual commands for more information."
19604 (call-interactively
19605 (if (org-at-table-p) 'org-table-copy-region 'org-copy-subtree)))
19607 (defun org-cut-special ()
19608 "Cut region in table or cut current subtree.
19609 Calls `org-table-copy' or `org-cut-subtree', depending on context.
19610 See the individual commands for more information."
19612 (call-interactively
19613 (if (org-at-table-p) 'org-table-cut-region 'org-cut-subtree)))
19615 (defun org-paste-special (arg)
19616 "Paste rectangular region into table, or past subtree relative to level.
19617 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
19618 See the individual commands for more information."
19620 (if (org-at-table-p)
19621 (org-table-paste-rectangle)
19622 (org-paste-subtree arg)))
19624 (defsubst org-in-fixed-width-region-p ()
19625 "Is point in a fixed-width region?"
19627 (eq 'fixed-width (org-element-type (org-element-at-point)))))
19629 (defun org-edit-special (&optional arg)
19630 "Call a special editor for the element at point.
19631 When at a table, call the formula editor with `org-table-edit-formulas'.
19632 When in a source code block, call `org-edit-src-code'.
19633 When in a fixed-width region, call `org-edit-fixed-width-region'.
19634 When at an #+INCLUDE keyword, visit the included file.
19635 On a link, call `ffap' to visit the link at point.
19636 Otherwise, return a user error."
19638 (let ((element (org-element-at-point)))
19639 (assert (not buffer-read-only) nil
19640 "Buffer is read-only: %s" (buffer-name))
19641 (case (org-element-type element)
19643 (if (not arg) (org-edit-src-code)
19644 (let* ((info (org-babel-get-src-block-info))
19645 (lang (nth 0 info))
19646 (params (nth 2 info))
19647 (session (cdr (assq :session params))))
19648 (if (not session) (org-edit-src-code)
19649 ;; At a src-block with a session and function called with
19650 ;; an ARG: switch to the buffer related to the inferior
19652 (funcall (intern (concat "org-babel-prep-session:" lang))
19653 session params)))))
19655 (if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE"))
19657 (org-remove-double-quotes
19658 (car (org-split-string (org-element-property :value element)))))
19659 (user-error "No special environment to edit here")))
19661 (if (eq (org-element-property :type element) 'table.el)
19662 (org-edit-src-code)
19663 (call-interactively 'org-table-edit-formulas)))
19664 ;; Only Org tables contain `table-row' type elements.
19665 (table-row (call-interactively 'org-table-edit-formulas))
19666 ((example-block export-block) (org-edit-src-code))
19667 (fixed-width (org-edit-fixed-width-region))
19669 ;; No notable element at point. Though, we may be at a link,
19670 ;; which is an object. Thus, scan deeper.
19671 (if (eq (org-element-type (org-element-context element)) 'link)
19672 (call-interactively 'ffap)
19673 (user-error "No special environment to edit here"))))))
19675 (defvar org-table-coordinate-overlays) ; defined in org-table.el
19676 (defun org-ctrl-c-ctrl-c (&optional arg)
19677 "Set tags in headline, or update according to changed information at point.
19679 This command does many different things, depending on context:
19681 - If a function in `org-ctrl-c-ctrl-c-hook' recognizes this location,
19682 this is what we do.
19684 - If the cursor is on a statistics cookie, update it.
19686 - If the cursor is in a headline, prompt for tags and insert them
19687 into the current line, aligned to `org-tags-column'. When called
19688 with prefix arg, realign all tags in the current buffer.
19690 - If the cursor is in one of the special #+KEYWORD lines, this
19691 triggers scanning the buffer for these lines and updating the
19694 - If the cursor is inside a table, realign the table. This command
19695 works even if the automatic table editor has been turned off.
19697 - If the cursor is on a #+TBLFM line, re-apply the formulas to
19700 - If the cursor is at a footnote reference or definition, jump to
19701 the corresponding definition or references, respectively.
19703 - If the cursor is a the beginning of a dynamic block, update it.
19705 - If the current buffer is a capture buffer, close note and file it.
19707 - If the cursor is on a <<<target>>>, update radio targets and
19708 corresponding links in this buffer.
19710 - If the cursor is on a numbered item in a plain list, renumber the
19713 - If the cursor is on a checkbox, toggle it.
19715 - If the cursor is on a code block, evaluate it. The variable
19716 `org-confirm-babel-evaluate' can be used to control prompting
19717 before code block evaluation, by default every code block
19718 evaluation requires confirmation. Code block evaluation can be
19719 inhibited by setting `org-babel-no-eval-on-ctrl-c-ctrl-c'."
19722 ((or (and (boundp 'org-clock-overlays) org-clock-overlays)
19723 org-occur-highlights
19724 org-latex-fragment-image-overlays)
19725 (and (boundp 'org-clock-overlays) (org-clock-remove-overlays))
19726 (org-remove-occur-highlights)
19727 (org-remove-latex-fragment-image-overlays)
19728 (message "Temporary highlights/overlays removed from current buffer"))
19729 ((and (local-variable-p 'org-finish-function (current-buffer))
19730 (fboundp org-finish-function))
19731 (funcall org-finish-function))
19732 ((run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-hook))
19734 (let* ((context (org-element-context)) (type (org-element-type context)))
19735 ;; Test if point is within a blank line.
19736 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*$"))
19737 (or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
19738 (user-error "C-c C-c can do nothing useful at this location"))
19739 ;; For convenience: at the first line of a paragraph on the
19740 ;; same line as an item, apply function on that item instead.
19741 (when (eq type 'paragraph)
19742 (let ((parent (org-element-property :parent context)))
19743 (when (and (eq (org-element-type parent) 'item)
19744 (= (point-at-bol) (org-element-property :begin parent)))
19745 (setq context parent type 'item))))
19746 ;; Act according to type of element or object at point.
19748 (clock (org-clock-update-time-maybe))
19751 (goto-char (org-element-property :post-affiliated context))
19752 (org-update-dblock)))
19753 (footnote-definition
19754 (goto-char (org-element-property :post-affiliated context))
19755 (call-interactively 'org-footnote-action))
19756 (footnote-reference (call-interactively 'org-footnote-action))
19757 ((headline inlinetask)
19758 (save-excursion (goto-char (org-element-property :begin context))
19759 (call-interactively 'org-set-tags)))
19761 ;; At an item: a double C-u set checkbox to "[-]"
19762 ;; unconditionally, whereas a single one will toggle its
19763 ;; presence. Without an universal argument, if the item
19764 ;; has a checkbox, toggle it. Otherwise repair the list.
19765 (let* ((box (org-element-property :checkbox context))
19766 (struct (org-element-property :structure context))
19767 (old-struct (copy-tree struct))
19768 (parents (org-list-parents-alist struct))
19769 (prevs (org-list-prevs-alist struct))
19770 (orderedp (org-not-nil (org-entry-get nil "ORDERED"))))
19771 (org-list-set-checkbox
19772 (org-element-property :begin context) struct
19773 (cond ((equal arg '(16)) "[-]")
19774 ((and (not box) (equal arg '(4))) "[ ]")
19775 ((or (not box) (equal arg '(4))) nil)
19776 ((eq box 'on) "[ ]")
19778 ;; Mimic `org-list-write-struct' but with grabbing
19779 ;; a return value from `org-list-struct-fix-box'.
19780 (org-list-struct-fix-ind struct parents 2)
19781 (org-list-struct-fix-item-end struct)
19782 (org-list-struct-fix-bul struct prevs)
19783 (org-list-struct-fix-ind struct parents)
19785 (org-list-struct-fix-box struct parents prevs orderedp)))
19786 (if (and box (equal struct old-struct))
19787 (if (equal arg '(16))
19788 (message "Checkboxes already reset")
19789 (user-error "Cannot toggle this checkbox: %s"
19791 "all subitems checked"
19792 "unchecked subitems")))
19793 (org-list-struct-apply-struct struct old-struct)
19794 (org-update-checkbox-count-maybe))
19796 (message "Checkboxes were removed due to empty box at line %d"
19797 (org-current-line block-item))))))
19799 (let ((org-inhibit-startup-visibility-stuff t)
19800 (org-startup-align-all-tables nil))
19801 (when (boundp 'org-table-coordinate-overlays)
19802 (mapc 'delete-overlay org-table-coordinate-overlays)
19803 (setq org-table-coordinate-overlays nil))
19804 (org-save-outline-visibility 'use-markers (org-mode-restart)))
19805 (message "Local setup has been refreshed"))
19807 ;; At a plain list, with a double C-u argument, set
19808 ;; checkboxes of each item to "[-]", whereas a single one
19809 ;; will toggle their presence according to the state of the
19810 ;; first item in the list. Without an argument, repair the
19812 (let* ((begin (org-element-property :contents-begin context))
19813 (struct (org-element-property :structure context))
19814 (old-struct (copy-tree struct))
19815 (first-box (save-excursion
19817 (looking-at org-list-full-item-re)
19818 (match-string-no-properties 3)))
19819 (new-box (cond ((equal arg '(16)) "[-]")
19820 ((equal arg '(4)) (unless first-box "[ ]"))
19821 ((equal first-box "[X]") "[ ]")
19825 (mapc (lambda (pos) (org-list-set-checkbox pos struct new-box))
19826 (org-list-get-all-items
19827 begin struct (org-list-prevs-alist struct))))
19828 ((and first-box (eq (point) begin))
19829 ;; For convenience, when point is at bol on the first
19830 ;; item of the list and no argument is provided, simply
19831 ;; toggle checkbox of that item, if any.
19832 (org-list-set-checkbox begin struct new-box)))
19833 (org-list-write-struct
19834 struct (org-list-parents-alist struct) old-struct)
19835 (org-update-checkbox-count-maybe)
19836 (save-excursion (goto-char begin) (org-list-send-list 'maybe))))
19837 ((property-drawer node-property)
19838 (call-interactively 'org-property-action))
19839 ((radio-target target)
19840 (call-interactively 'org-update-radio-target-regexp))
19842 (call-interactively 'org-update-statistics-cookies))
19843 ((table table-cell table-row)
19844 ;; At a table, recalculate every field and align it. Also
19845 ;; send the table if necessary. If the table has
19846 ;; a `table.el' type, just give up. At a table row or
19847 ;; cell, maybe recalculate line but always align table.
19848 (if (eq (org-element-property :type context) 'table.el)
19849 (message "Use C-c ' to edit table.el tables")
19850 (let ((org-enable-table-editor t))
19851 (if (or (eq type 'table)
19852 ;; Check if point is at a TBLFM line.
19853 (and (eq type 'table-row)
19854 (= (point) (org-element-property :end context))))
19856 (goto-char (org-element-property :contents-begin context))
19857 (org-call-with-arg 'org-table-recalculate (or arg t))
19858 (orgtbl-send-table 'maybe))
19859 (org-table-maybe-eval-formula)
19860 (cond (arg (call-interactively 'org-table-recalculate))
19861 ((org-table-maybe-recalculate-line))
19862 (t (org-table-align)))))))
19863 (timestamp (org-timestamp-change 0 'day))
19865 (or (run-hook-with-args-until-success 'org-ctrl-c-ctrl-c-final-hook)
19867 "C-c C-c can do nothing useful at this location")))))))))
19869 (defun org-mode-restart ()
19870 "Restart Org-mode, to scan again for special lines.
19871 Also updates the keyword regular expressions."
19874 (message "Org-mode restarted"))
19876 (defun org-kill-note-or-show-branches ()
19877 "If this is a Note buffer, abort storing the note. Else call `show-branches'."
19879 (if (not org-finish-function)
19882 (call-interactively 'show-branches))
19883 (let ((org-note-abort t))
19884 (funcall org-finish-function))))
19886 (defun org-return (&optional indent)
19887 "Goto next table row or insert a newline.
19888 Calls `org-table-next-row' or `newline', depending on context.
19889 See the individual commands for more information."
19893 ((or (bobp) (org-in-src-block-p))
19894 (if indent (newline-and-indent) (newline)))
19896 (org-table-justify-field-maybe)
19897 (call-interactively 'org-table-next-row))
19898 ;; when `newline-and-indent' is called within a list, make sure
19899 ;; text moved stays inside the item.
19900 ((and (org-in-item-p) indent)
19901 (if (and (org-at-item-p) (>= (point) (match-end 0)))
19903 (save-match-data (newline))
19904 (org-indent-line-to (length (match-string 0))))
19905 (let ((ind (org-get-indentation)))
19907 (if (org-looking-back org-list-end-re)
19909 (org-indent-line-to ind)))))
19910 ((and org-return-follows-link
19911 (org-at-timestamp-p t)
19912 (not (eq org-ts-what 'after)))
19913 (org-follow-timestamp-link))
19914 ((and org-return-follows-link
19915 (let ((tprop (get-text-property (point) 'face)))
19916 (or (eq tprop 'org-link)
19917 (and (listp tprop) (memq 'org-link tprop)))))
19918 (call-interactively 'org-open-at-point))
19919 ((and (org-at-heading-p)
19921 (org-re "\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$")))
19925 (t (if indent (newline-and-indent) (newline))))))
19927 (defun org-return-indent ()
19928 "Goto next table row or insert a newline and indent.
19929 Calls `org-table-next-row' or `newline-and-indent', depending on
19930 context. See the individual commands for more information."
19934 (defun org-ctrl-c-star ()
19935 "Compute table, or change heading status of lines.
19936 Calls `org-table-recalculate' or `org-toggle-heading',
19937 depending on context."
19941 (call-interactively 'org-table-recalculate))
19943 ;; Convert all lines in region to list items
19944 (call-interactively 'org-toggle-heading))))
19946 (defun org-ctrl-c-minus ()
19947 "Insert separator line in table or modify bullet status of line.
19948 Also turns a plain line or a region of lines into list items.
19949 Calls `org-table-insert-hline', `org-toggle-item', or
19950 `org-cycle-list-bullet', depending on context."
19954 (call-interactively 'org-table-insert-hline))
19955 ((org-region-active-p)
19956 (call-interactively 'org-toggle-item))
19958 (call-interactively 'org-cycle-list-bullet))
19960 (call-interactively 'org-toggle-item))))
19962 (defun org-toggle-item (arg)
19963 "Convert headings or normal lines to items, items to normal lines.
19964 If there is no active region, only the current line is considered.
19966 If the first non blank line in the region is an headline, convert
19967 all headlines to items, shifting text accordingly.
19969 If it is an item, convert all items to normal lines.
19971 If it is normal text, change region into an item. With a prefix
19972 argument ARG, change each line in region into an item."
19976 ;; Shift text in current section to IND, from point to END.
19977 ;; The function leaves point to END line.
19979 (let ((min-i 1000) (end (copy-marker end)))
19980 ;; First determine the minimum indentation (MIN-I) of
19984 (while (< (point) end)
19985 (let ((i (org-get-indentation)))
19987 ;; Skip blank lines and inline tasks.
19988 ((looking-at "^[ \t]*$"))
19989 ((looking-at org-outline-regexp-bol))
19990 ;; We can't find less than 0 indentation.
19991 ((zerop i) (throw 'exit (setq min-i 0)))
19992 ((< i min-i) (setq min-i i))))
19994 ;; Then indent each line so that a line indented to
19995 ;; MIN-I becomes indented to IND. Ignore blank lines
19996 ;; and inline tasks in the process.
19997 (let ((delta (- ind min-i)))
19998 (while (< (point) end)
19999 (unless (or (looking-at "^[ \t]*$")
20000 (looking-at org-outline-regexp-bol))
20001 (org-indent-line-to (+ (org-get-indentation) delta)))
20002 (forward-line)))))))
20005 ;; Return beginning of first non-blank line, starting from
20010 (skip-chars-forward " \r\t\n")
20013 ;; Determine boundaries of changes.
20014 (if (org-region-active-p)
20015 (setq beg (funcall skip-blanks (region-beginning))
20016 end (copy-marker (region-end)))
20017 (setq beg (funcall skip-blanks (point-at-bol))
20018 end (copy-marker (point-at-eol))))
20019 ;; Depending on the starting line, choose an action on the text
20020 ;; between BEG and END.
20021 (org-with-limited-levels
20025 ;; Case 1. Start at an item: de-itemize. Note that it only
20026 ;; happens when a region is active: `org-ctrl-c-minus'
20027 ;; would call `org-cycle-list-bullet' otherwise.
20029 (while (< (point) end)
20030 (when (org-at-item-p)
20031 (skip-chars-forward " \t")
20032 (delete-region (point) (match-end 0)))
20034 ;; Case 2. Start at an heading: convert to items.
20035 ((org-at-heading-p)
20036 (let* ((bul (org-list-bullet-string "-"))
20037 (bul-len (length bul))
20038 ;; Indentation of the first heading. It should be
20039 ;; relative to the indentation of its parent, if any.
20040 (start-ind (save-excursion
20042 ((not org-adapt-indentation) 0)
20043 ((not (outline-previous-heading)) 0)
20044 (t (length (match-string 0))))))
20045 ;; Level of first heading. Further headings will be
20046 ;; compared to it to determine hierarchy in the list.
20047 (ref-level (org-reduced-level (org-outline-level))))
20048 (while (< (point) end)
20049 (let* ((level (org-reduced-level (org-outline-level)))
20050 (delta (max 0 (- level ref-level))))
20051 ;; If current headline is less indented than the first
20052 ;; one, set it as reference, in order to preserve
20054 (when (< level ref-level) (setq ref-level level))
20055 (replace-match bul t t)
20056 (org-indent-line-to (+ start-ind (* delta bul-len)))
20057 ;; Ensure all text down to END (or SECTION-END) belongs
20058 ;; to the newly created item.
20059 (let ((section-end (save-excursion
20060 (or (outline-next-heading) (point)))))
20062 (funcall shift-text
20063 (+ start-ind (* (1+ delta) bul-len))
20064 (min end section-end)))))))
20065 ;; Case 3. Normal line with ARG: turn each non-item line into
20068 (while (< (point) end)
20069 (unless (or (org-at-heading-p) (org-at-item-p))
20070 (if (looking-at "\\([ \t]*\\)\\(\\S-\\)")
20072 (concat "\\1" (org-list-bullet-string "-") "\\2"))))
20074 ;; Case 4. Normal line without ARG: make the first line of
20075 ;; region an item, and shift indentation of others
20076 ;; lines to set them as item's body.
20077 (t (let* ((bul (org-list-bullet-string "-"))
20078 (bul-len (length bul))
20079 (ref-ind (org-get-indentation)))
20080 (skip-chars-forward " \t")
20083 (while (< (point) end)
20084 ;; Ensure that lines less indented than first one
20085 ;; still get included in item body.
20086 (funcall shift-text
20087 (+ ref-ind bul-len)
20088 (min end (save-excursion (or (outline-next-heading)
20090 (forward-line)))))))))
20092 (defun org-toggle-heading (&optional nstars)
20093 "Convert headings to normal text, or items or text to headings.
20094 If there is no active region, only the current line is considered.
20096 With a \\[universal-argument] prefix, convert the whole list at
20097 point into heading.
20101 - If the first non blank line is an headline, remove the stars
20102 from all headlines in the region.
20104 - If it is a normal line turn each and every normal line (i.e. not an
20105 heading or an item) in the region into a heading.
20107 - If it is a plain list item, turn all plain list items into headings.
20109 When converting a line into a heading, the number of stars is chosen
20110 such that the lines become children of the current entry. However,
20111 when a prefix argument is given, its value determines the number of
20116 ;; Return beginning of first non-blank line, starting from
20121 (while (org-at-comment-p) (forward-line))
20122 (skip-chars-forward " \r\t\n")
20125 ;; Determine boundaries of changes. If a universal prefix has
20126 ;; been given, put the list in a region. If region ends at a bol,
20127 ;; do not consider the last line to be in the region.
20129 (when (and current-prefix-arg (org-at-item-p))
20130 (if (equal current-prefix-arg '(4)) (setq current-prefix-arg 1))
20131 (org-mark-element))
20133 (if (org-region-active-p)
20134 (setq beg (funcall skip-blanks (region-beginning))
20135 end (copy-marker (save-excursion
20136 (goto-char (region-end))
20137 (if (bolp) (point) (point-at-eol)))))
20138 (setq beg (funcall skip-blanks (point-at-bol))
20139 end (copy-marker (point-at-eol))))
20140 ;; Ensure inline tasks don't count as headings.
20141 (org-with-limited-levels
20145 ;; Case 1. Started at an heading: de-star headings.
20146 ((org-at-heading-p)
20147 (while (< (point) end)
20148 (when (org-at-heading-p t)
20149 (looking-at org-outline-regexp) (replace-match "")
20152 ;; Case 2. Started at an item: change items into headlines.
20153 ;; One star will be added by `org-list-to-subtree'.
20155 (let* ((stars (make-string
20157 ;; subtract the star that will be added again by
20158 ;; `org-list-to-subtree'
20159 (1- (prefix-numeric-value current-prefix-arg))
20160 (or (org-current-level) 0))
20163 (cond (nstars "") ; stars from prefix only
20164 ((equal stars "") "") ; before first heading
20165 (org-odd-levels-only "*") ; inside heading, odd
20166 (t "")))) ; inside heading, oddeven
20167 (while (< (point) end)
20168 (when (org-at-item-p)
20169 ;; Pay attention to cases when region ends before list.
20170 (let* ((struct (org-list-struct))
20171 (list-end (min (org-list-get-bottom-point struct) (1+ end))))
20173 (narrow-to-region (point) list-end)
20175 (org-list-to-subtree
20176 (org-list-parse-list t)
20177 '(:istart (concat stars add-stars (funcall get-stars depth))
20178 :icount (concat stars add-stars (funcall get-stars depth)))))))
20181 ;; Case 3. Started at normal text: make every line an heading,
20182 ;; skipping headlines and items.
20183 (t (let* ((stars (make-string
20185 (prefix-numeric-value current-prefix-arg)
20186 (or (org-current-level) 0))
20189 (cond (nstars "") ; stars from prefix only
20190 ((equal stars "") "*") ; before first heading
20191 (org-odd-levels-only "**") ; inside heading, odd
20192 (t "*"))) ; inside heading, oddeven
20193 (rpl (concat stars add-stars " ")))
20194 (while (< (point) end)
20195 (when (and (not (or (org-at-heading-p) (org-at-item-p) (org-at-comment-p)))
20196 (looking-at "\\([ \t]*\\)\\(\\S-\\)"))
20197 (replace-match (concat rpl (match-string 2))) (setq toggled t))
20198 (forward-line)))))))
20199 (unless toggled (message "Cannot toggle heading from here"))))
20201 (defun org-meta-return (&optional arg)
20202 "Insert a new heading or wrap a region in a table.
20203 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
20204 See the individual commands for more information."
20207 ((run-hook-with-args-until-success 'org-metareturn-hook))
20208 ((or (org-at-drawer-p) (org-at-property-p))
20209 (newline-and-indent))
20211 (call-interactively 'org-table-wrap-region))
20212 (t (call-interactively 'org-insert-heading))))
20216 (defsubst org-in-subtree-not-table-p ()
20217 "Are we in a subtree and not in a table?"
20218 (and (not (org-before-first-heading-p))
20219 (not (org-at-table-p))))
20221 ;; Define the Org-mode menus
20222 (easy-menu-define org-tbl-menu org-mode-map "Tbl menu"
20224 ["Align" org-ctrl-c-ctrl-c :active (org-at-table-p)]
20225 ["Next Field" org-cycle (org-at-table-p)]
20226 ["Previous Field" org-shifttab (org-at-table-p)]
20227 ["Next Row" org-return (org-at-table-p)]
20229 ["Blank Field" org-table-blank-field (org-at-table-p)]
20230 ["Edit Field" org-table-edit-field (org-at-table-p)]
20231 ["Copy Field from Above" org-table-copy-down (org-at-table-p)]
20234 ["Move Column Left" org-metaleft (org-at-table-p)]
20235 ["Move Column Right" org-metaright (org-at-table-p)]
20236 ["Delete Column" org-shiftmetaleft (org-at-table-p)]
20237 ["Insert Column" org-shiftmetaright (org-at-table-p)])
20239 ["Move Row Up" org-metaup (org-at-table-p)]
20240 ["Move Row Down" org-metadown (org-at-table-p)]
20241 ["Delete Row" org-shiftmetaup (org-at-table-p)]
20242 ["Insert Row" org-shiftmetadown (org-at-table-p)]
20243 ["Sort lines in region" org-table-sort-lines (org-at-table-p)]
20245 ["Insert Hline" org-ctrl-c-minus (org-at-table-p)])
20247 ["Copy Rectangle" org-copy-special (org-at-table-p)]
20248 ["Cut Rectangle" org-cut-special (org-at-table-p)]
20249 ["Paste Rectangle" org-paste-special (org-at-table-p)]
20250 ["Fill Rectangle" org-table-wrap-region (org-at-table-p)])
20253 ["Set Column Formula" org-table-eval-formula (org-at-table-p)]
20254 ["Set Field Formula" (org-table-eval-formula '(4)) :active (org-at-table-p) :keys "C-u C-c ="]
20255 ["Edit Formulas" org-edit-special (org-at-table-p)]
20257 ["Recalculate line" org-table-recalculate (org-at-table-p)]
20258 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active (org-at-table-p) :keys "C-u C-c *"]
20259 ["Iterate all" (lambda () (interactive) (org-table-recalculate '(16))) :active (org-at-table-p) :keys "C-u C-u C-c *"]
20261 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks (org-at-table-p)]
20263 ["Sum Column/Rectangle" org-table-sum
20264 (or (org-at-table-p) (org-region-active-p))]
20265 ["Which Column?" org-table-current-column (org-at-table-p)])
20267 org-table-toggle-formula-debugger
20268 :style toggle :selected (org-bound-and-true-p org-table-formula-debug)]
20269 ["Show Col/Row Numbers"
20270 org-table-toggle-coordinate-overlays
20272 :selected (org-bound-and-true-p org-table-overlay-coordinates)]
20274 ["Create" org-table-create (and (not (org-at-table-p))
20275 org-enable-table-editor)]
20276 ["Convert Region" org-table-convert-region (not (org-at-table-p 'any))]
20277 ["Import from File" org-table-import (not (org-at-table-p))]
20278 ["Export to File" org-table-export (org-at-table-p)]
20280 ["Create/Convert from/to table.el" org-table-create-with-table.el t]))
20282 (easy-menu-define org-org-menu org-mode-map "Org menu"
20285 ["Cycle Visibility" org-cycle :active (or (bobp) (outline-on-heading-p))]
20286 ["Cycle Global Visibility" org-shifttab :active (not (org-at-table-p))]
20287 ["Sparse Tree..." org-sparse-tree t]
20288 ["Reveal Context" org-reveal t]
20289 ["Show All" show-all t]
20291 ["Subtree to indirect buffer" org-tree-to-indirect-buffer t])
20293 ["New Heading" org-insert-heading t]
20294 ("Navigate Headings"
20295 ["Up" outline-up-heading t]
20296 ["Next" outline-next-visible-heading t]
20297 ["Previous" outline-previous-visible-heading t]
20298 ["Next Same Level" outline-forward-same-level t]
20299 ["Previous Same Level" outline-backward-same-level t]
20301 ["Jump" org-goto t])
20303 ["Refile Subtree" org-refile (org-in-subtree-not-table-p)]
20305 ["Move Subtree Up" org-shiftmetaup (org-in-subtree-not-table-p)]
20306 ["Move Subtree Down" org-shiftmetadown (org-in-subtree-not-table-p)]
20308 ["Copy Subtree" org-copy-special (org-in-subtree-not-table-p)]
20309 ["Cut Subtree" org-cut-special (org-in-subtree-not-table-p)]
20310 ["Paste Subtree" org-paste-special (not (org-at-table-p))]
20312 ["Clone subtree, shift time" org-clone-subtree-with-time-shift t]
20314 ["Copy visible text" org-copy-visible t]
20316 ["Promote Heading" org-metaleft (org-in-subtree-not-table-p)]
20317 ["Promote Subtree" org-shiftmetaleft (org-in-subtree-not-table-p)]
20318 ["Demote Heading" org-metaright (org-in-subtree-not-table-p)]
20319 ["Demote Subtree" org-shiftmetaright (org-in-subtree-not-table-p)]
20321 ["Sort Region/Children" org-sort t]
20323 ["Convert to odd levels" org-convert-to-odd-levels t]
20324 ["Convert to odd/even levels" org-convert-to-oddeven-levels t])
20326 ["Emphasis..." org-emphasize t]
20327 ["Edit Source Example" org-edit-special t]
20329 ["Footnote new/jump" org-footnote-action t]
20330 ["Footnote extra" (org-footnote-action t) :active t :keys "C-u C-c C-x f"])
20332 ["Archive (default method)" org-archive-subtree-default (org-in-subtree-not-table-p)]
20334 ["Move Subtree to Archive file" org-advertized-archive-subtree (org-in-subtree-not-table-p)]
20335 ["Toggle ARCHIVE tag" org-toggle-archive-tag (org-in-subtree-not-table-p)]
20336 ["Move subtree to Archive sibling" org-archive-to-archive-sibling (org-in-subtree-not-table-p)]
20340 ["Store Link (Global)" org-store-link t]
20341 ["Find existing link to here" org-occur-link-in-agenda-files t]
20342 ["Insert Link" org-insert-link t]
20343 ["Follow Link" org-open-at-point t]
20345 ["Next link" org-next-link t]
20346 ["Previous link" org-previous-link t]
20348 ["Descriptive Links"
20349 org-toggle-link-display
20351 :selected org-descriptive-links
20354 org-toggle-link-display
20356 :selected (not org-descriptive-links)])
20359 ["TODO/DONE/-" org-todo t]
20361 ["Next keyword" org-shiftright (org-at-heading-p)]
20362 ["Previous keyword" org-shiftleft (org-at-heading-p)]
20363 ["Complete Keyword" pcomplete (assq :todo-keyword (org-context))]
20364 ["Next keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))]
20365 ["Previous keyword set" org-shiftcontrolright (and (> (length org-todo-sets) 1) (org-at-heading-p))])
20366 ["Show TODO Tree" org-show-todo-tree :active t :keys "C-c / t"]
20367 ["Global TODO list" org-todo-list :active t :keys "C-c a t"]
20369 ["Enforce dependencies" (customize-variable 'org-enforce-todo-dependencies)
20370 :selected org-enforce-todo-dependencies :style toggle :active t]
20371 "Settings for tree at point"
20372 ["Do Children sequentially" org-toggle-ordered-property :style radio
20373 :selected (org-entry-get nil "ORDERED")
20374 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
20375 ["Do Children parallel" org-toggle-ordered-property :style radio
20376 :selected (not (org-entry-get nil "ORDERED"))
20377 :active org-enforce-todo-dependencies :keys "C-c C-x o"]
20379 ["Set Priority" org-priority t]
20380 ["Priority Up" org-shiftup t]
20381 ["Priority Down" org-shiftdown t]
20383 ["Get news from all feeds" org-feed-update-all t]
20384 ["Go to the inbox of a feed..." org-feed-goto-inbox t]
20385 ["Customize feeds" (customize-variable 'org-feed-alist) t])
20386 ("TAGS and Properties"
20387 ["Set Tags" org-set-tags-command (not (org-before-first-heading-p))]
20388 ["Change tag in region" org-change-tag-in-region (org-region-active-p)]
20390 ["Set property" org-set-property (not (org-before-first-heading-p))]
20391 ["Column view of properties" org-columns t]
20392 ["Insert Column View DBlock" org-insert-columns-dblock t])
20393 ("Dates and Scheduling"
20394 ["Timestamp" org-time-stamp (not (org-before-first-heading-p))]
20395 ["Timestamp (inactive)" org-time-stamp-inactive (not (org-before-first-heading-p))]
20397 ["1 Day Later" org-shiftright (org-at-timestamp-p)]
20398 ["1 Day Earlier" org-shiftleft (org-at-timestamp-p)]
20399 ["1 ... Later" org-shiftup (org-at-timestamp-p)]
20400 ["1 ... Earlier" org-shiftdown (org-at-timestamp-p)])
20401 ["Compute Time Range" org-evaluate-time-range t]
20402 ["Schedule Item" org-schedule (not (org-before-first-heading-p))]
20403 ["Deadline" org-deadline (not (org-before-first-heading-p))]
20405 ["Custom time format" org-toggle-time-stamp-overlays
20406 :style radio :selected org-display-custom-times]
20408 ["Goto Calendar" org-goto-calendar t]
20409 ["Date from Calendar" org-date-from-calendar t]
20411 ["Start/Restart Timer" org-timer-start t]
20412 ["Pause/Continue Timer" org-timer-pause-or-continue t]
20413 ["Stop Timer" org-timer-pause-or-continue :active t :keys "C-u C-c C-x ,"]
20414 ["Insert Timer String" org-timer t]
20415 ["Insert Timer Item" org-timer-item t])
20417 ["Clock in" org-clock-in :active t :keys "C-c C-x C-i"]
20418 ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"]
20419 ["Clock out" org-clock-out t]
20420 ["Clock cancel" org-clock-cancel t]
20422 ["Mark as default task" org-clock-mark-default-task t]
20423 ["Clock in, mark as default" (lambda () (interactive) (org-clock-in '(16))) :active t :keys "C-u C-u C-c C-x C-i"]
20424 ["Goto running clock" org-clock-goto t]
20426 ["Display times" org-clock-display t]
20427 ["Create clock table" org-clock-report t]
20429 ["Record DONE time"
20430 (progn (setq org-log-done (not org-log-done))
20431 (message "Switching to %s will %s record a timestamp"
20432 (car org-done-keywords)
20433 (if org-log-done "automatically" "not")))
20434 :style toggle :selected org-log-done])
20436 ["Agenda Command..." org-agenda t]
20437 ["Set Restriction Lock" org-agenda-set-restriction-lock t]
20438 ("File List for Agenda")
20439 ("Special views current file"
20440 ["TODO Tree" org-show-todo-tree t]
20441 ["Check Deadlines" org-check-deadlines t]
20442 ["Timeline" org-timeline t]
20443 ["Tags/Property tree" org-match-sparse-tree t])
20445 ["Export/Publish..." org-export-dispatch t]
20447 ["Org CDLaTeX mode" org-cdlatex-mode :style toggle
20448 :selected org-cdlatex-mode]
20449 ["Insert Environment" cdlatex-environment (fboundp 'cdlatex-environment)]
20450 ["Insert math symbol" cdlatex-math-symbol (fboundp 'cdlatex-math-symbol)]
20451 ["Modify math symbol" org-cdlatex-math-modify
20452 (org-inside-LaTeX-fragment-p)]
20453 ["Insert citation" org-reftex-citation t]
20455 ["Template for BEAMER" (org-beamer-insert-options-template) t])
20458 ["Push Files and Views" org-mobile-push t]
20459 ["Get Captured and Flagged" org-mobile-pull t]
20460 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
20462 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
20465 ["Show Version" org-version t]
20466 ["Info Documentation" org-info t])
20468 ["Browse Org Group" org-customize t]
20470 ["Expand This Menu" org-create-customize-menu
20471 (fboundp 'customize-menu-create)])
20472 ["Send bug report" org-submit-bug-report t]
20475 ["Refresh setup current buffer" org-mode-restart t]
20476 ["Reload Org (after update)" org-reload t]
20477 ["Reload Org uncompiled" (org-reload t) :active t :keys "C-u C-c C-x !"])
20480 (defun org-info (&optional node)
20481 "Read documentation for Org-mode in the info system.
20482 With optional NODE, go directly to that node."
20484 (info (format "(org)%s" (or node ""))))
20487 (defun org-submit-bug-report ()
20488 "Submit a bug report on Org-mode via mail.
20490 Don't hesitate to report any problems or inaccurate documentation.
20492 If you don't have setup sending mail from (X)Emacs, please copy the
20493 output buffer into your mail program, as it gives us important
20494 information about your Org-mode version and configuration."
20496 (require 'reporter)
20497 (org-load-modules-maybe)
20498 (org-require-autoloaded-modules)
20499 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
20500 (reporter-submit-bug-report
20501 "emacs-orgmode@gnu.org"
20502 (org-version nil 'full)
20504 (save-window-excursion
20505 (org-pop-to-buffer-same-window (get-buffer-create "*Warn about privacy*"))
20506 (delete-other-windows)
20508 (insert "You are about to submit a bug report to the Org-mode mailing list.
20510 We would like to add your full Org-mode and Outline configuration to the
20511 bug report. This greatly simplifies the work of the maintainer and
20512 other experts on the mailing list.
20514 HOWEVER, some variables you have customized may contain private
20515 information. The names of customers, colleagues, or friends, might
20516 appear in the form of file names, tags, todo states, or search strings.
20517 If you answer yes to the prompt, you might want to check and remove
20518 such private information before sending the email.")
20519 (add-text-properties (point-min) (point-max) '(face org-warning))
20520 (when (yes-or-no-p "Include your Org-mode configuration ")
20524 (string-match "\\`\\(org-\\|outline-\\)" (symbol-name v))
20525 (or (and (symbol-value v)
20526 (string-match "\\(-hook\\|-function\\)\\'" (symbol-name v)))
20528 (get v 'custom-type) (get v 'standard-value)
20529 (not (equal (symbol-value v) (eval (car (get v 'standard-value)))))))
20531 (kill-buffer (get-buffer "*Warn about privacy*"))
20534 "Remember to cover the basics, that is, what you expected to happen and
20535 what in fact did happen. You don't know how to make a good report? See
20537 http://orgmode.org/manual/Feedback.html#Feedback
20539 Your bug report will be posted to the Org-mode mailing list.
20540 ------------------------------------------------------------------------")
20542 (if (re-search-backward "^\\(Subject: \\)Org-mode version \\(.*?\\);[ \t]*\\(.*\\)" nil t)
20543 (replace-match "\\1Bug: \\3 [\\2]")))))
20546 (defun org-install-agenda-files-menu ()
20547 (let ((bl (buffer-list)))
20550 (set-buffer (pop bl))
20551 (if (derived-mode-p 'org-mode) (setq bl nil)))
20552 (when (derived-mode-p 'org-mode)
20554 '("Org") "File List for Agenda"
20557 ["Edit File List" (org-edit-agenda-file-list) t]
20558 ["Add/Move Current File to Front of List" org-agenda-file-to-front t]
20559 ["Remove Current File from List" org-remove-file t]
20560 ["Cycle through agenda files" org-cycle-agenda-files t]
20561 ["Occur in all agenda files" org-occur-in-agenda-files t]
20563 (mapcar 'org-file-menu-entry (org-agenda-files t))))))))
20567 (defun org-require-autoloaded-modules ()
20570 '(org-agenda org-archive org-attach org-clock org-colview org-id
20571 org-remember org-table org-timer)))
20574 (defun org-reload (&optional uncompiled)
20575 "Reload all org lisp files.
20576 With prefix arg UNCOMPILED, load the uncompiled versions."
20578 (require 'loadhist)
20579 (let* ((org-dir (org-find-library-dir "org"))
20580 (contrib-dir (or (org-find-library-dir "org-contribdir") org-dir))
20581 (feature-re "^\\(org\\|ob\\|ox\\)\\(-.*\\)?")
20582 (remove-re (mapconcat 'identity
20583 (mapcar (lambda (f) (concat "^" f "$"))
20584 (list (if (featurep 'xemacs)
20586 "org-colview-xemacs")
20587 "org" "org-loaddefs" "org-version"))
20589 (feats (delete-dups
20590 (mapcar 'file-name-sans-extension
20591 (mapcar 'file-name-nondirectory
20593 (mapcar 'feature-file
20600 (if (and (string-match feature-re f)
20601 (not (string-match remove-re f)))
20605 (list "org-version" "org")))
20606 (load-suffixes (when (boundp 'load-suffixes) load-suffixes))
20607 (load-suffixes (if uncompiled (reverse load-suffixes) load-suffixes))
20608 load-uncore load-misses)
20611 (mapcar (lambda (f)
20612 (or (org-load-noerror-mustsuffix (concat org-dir f))
20613 (and (string= org-dir contrib-dir)
20614 (org-load-noerror-mustsuffix (concat contrib-dir f)))
20615 (and (org-load-noerror-mustsuffix (concat (org-find-library-dir f) f))
20616 (add-to-list 'load-uncore f 'append)
20621 (message "The following feature%s found in load-path, please check if that's correct:\n%s"
20622 (if (> (length load-uncore) 1) "s were" " was") load-uncore))
20624 (message "Some error occured while reloading Org feature%s\n%s\nPlease check *Messages*!\n%s"
20625 (if (> (length load-misses) 1) "s" "") load-misses (org-version nil 'full))
20626 (message "Successfully reloaded Org\n%s" (org-version nil 'full)))))
20629 (defun org-customize ()
20630 "Call the customize function with org as argument."
20632 (org-load-modules-maybe)
20633 (org-require-autoloaded-modules)
20634 (customize-browse 'org))
20636 (defun org-create-customize-menu ()
20637 "Create a full customization menu for Org-mode, insert it into the menu."
20639 (org-load-modules-maybe)
20640 (org-require-autoloaded-modules)
20641 (if (fboundp 'customize-menu-create)
20644 '("Org") "Customize"
20645 `(["Browse Org group" org-customize t]
20647 ,(customize-menu-create 'org)
20648 ["Set" Custom-set t]
20649 ["Save" Custom-save t]
20650 ["Reset to Current" Custom-reset-current t]
20651 ["Reset to Saved" Custom-reset-saved t]
20652 ["Reset to Standard Settings" Custom-reset-standard t]))
20653 (message "\"Org\"-menu now contains full customization menu"))
20654 (error "Cannot expand menu (outdated version of cus-edit.el)")))
20656 ;;;; Miscellaneous stuff
20658 ;;; Generally useful functions
20660 (defun org-get-at-bol (property)
20661 "Get text property PROPERTY at beginning of line."
20662 (get-text-property (point-at-bol) property))
20664 (defun org-find-text-property-in-string (prop s)
20665 "Return the first non-nil value of property PROP in string S."
20666 (or (get-text-property 0 prop s)
20667 (get-text-property (or (next-single-property-change 0 prop s) 0)
20670 (defun org-display-warning (message) ;; Copied from Emacs-Muse
20671 "Display the given MESSAGE as a warning."
20672 (if (fboundp 'display-warning)
20673 (display-warning 'org message
20674 (if (featurep 'xemacs) 'warning :warning))
20675 (let ((buf (get-buffer-create "*Org warnings*")))
20676 (with-current-buffer buf
20677 (goto-char (point-max))
20678 (insert "Warning (Org): " message)
20681 (display-buffer buf)
20684 (defun org-eval (form)
20685 "Eval FORM and return result."
20686 (condition-case error
20688 (error (format "%%![Error: %s]" error))))
20690 (defun org-in-clocktable-p ()
20691 "Check if the cursor is in a clocktable."
20692 (let ((pos (point)) start)
20695 (and (re-search-backward "^[ \t]*#\\+BEGIN:[ \t]+clocktable" nil t)
20696 (setq start (match-beginning 0))
20697 (re-search-forward "^[ \t]*#\\+END:.*" nil t)
20698 (>= (match-end 0) pos)
20701 (defun org-in-commented-line ()
20702 "Is point in a line starting with `#'?"
20703 (equal (char-after (point-at-bol)) ?#))
20705 (defun org-in-indented-comment-line ()
20706 "Is point in a line starting with `#' after some white space?"
20709 (goto-char (point-at-bol))
20710 (looking-at "[ \t]*#"))))
20712 (defun org-in-verbatim-emphasis ()
20714 (and (org-in-regexp org-emph-re 2) (member (match-string 3) '("=" "~")))))
20716 (defun org-goto-marker-or-bmk (marker &optional bookmark)
20717 "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK."
20718 (if (and marker (marker-buffer marker)
20719 (buffer-live-p (marker-buffer marker)))
20721 (org-pop-to-buffer-same-window (marker-buffer marker))
20722 (if (or (> marker (point-max)) (< marker (point-min)))
20725 (org-show-context 'org-goto))
20727 (bookmark-jump bookmark)
20728 (error "Cannot find location"))))
20730 (defun org-quote-csv-field (s)
20731 "Quote field for inclusion in CSV material."
20732 (if (string-match "[\",]" s)
20733 (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
20736 (defun org-force-self-insert (N)
20737 "Needed to enforce self-insert under remapping."
20739 (self-insert-command N))
20741 (defun org-string-width (s)
20742 "Compute width of string, ignoring invisible characters.
20743 This ignores character with invisibility property `org-link', and also
20744 characters with property `org-cwidth', because these will become invisible
20745 upon the next fontification round."
20747 (when (or (eq t buffer-invisibility-spec)
20748 (assq 'org-link buffer-invisibility-spec))
20749 (while (setq b (text-property-any 0 (length s)
20750 'invisible 'org-link s))
20751 (setq s (concat (substring s 0 b)
20752 (substring s (or (next-single-property-change
20753 b 'invisible s) (length s)))))))
20754 (while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
20755 (setq s (concat (substring s 0 b)
20756 (substring s (or (next-single-property-change
20757 b 'org-cwidth s) (length s))))))
20758 (setq l (string-width s) b -1)
20759 (while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
20760 (setq l (- l (get-text-property b 'org-dwidth-n s))))
20763 (defun org-shorten-string (s maxlength)
20764 "Shorten string S so tht it is no longer than MAXLENGTH characters.
20765 If the string is shorter or has length MAXLENGTH, just return the
20766 original string. If it is longer, the functions finds a space in the
20767 string, breaks this string off at that locations and adds three dots
20768 as ellipsis. Including the ellipsis, the string will not be longer
20769 than MAXLENGTH. If finding a good breaking point in the string does
20770 not work, the string is just chopped off in the middle of a word
20772 (if (<= (length s) maxlength)
20774 (let* ((n (max (- maxlength 4) 1))
20775 (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
20776 (if (string-match re s)
20777 (concat (match-string 1 s) "...")
20778 (concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
20780 (defun org-get-indentation (&optional line)
20781 "Get the indentation of the current line, interpreting tabs.
20782 When LINE is given, assume it represents a line and compute its indentation."
20784 (if (string-match "^ *" (org-remove-tabs line))
20787 (beginning-of-line 1)
20788 (skip-chars-forward " \t")
20789 (current-column))))
20791 (defun org-get-string-indentation (s)
20792 "What indentation has S due to SPACE and TAB at the beginning of the string?"
20793 (let ((n -1) (i 0) (w tab-width) c)
20795 (while (< (setq n (1+ n)) (length s))
20796 (setq c (aref s n))
20797 (cond ((= c ?\ ) (setq i (1+ i)))
20798 ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
20799 (t (throw 'exit t)))))
20802 (defun org-remove-tabs (s &optional width)
20803 "Replace tabulators in S with spaces.
20804 Assumes that s is a single line, starting in column 0."
20805 (setq width (or width tab-width))
20806 (while (string-match "\t" s)
20807 (setq s (replace-match
20809 (- (* width (/ (+ (match-beginning 0) width) width))
20810 (match-beginning 0)) ?\ )
20814 (defun org-fix-indentation (line ind)
20815 "Fix indentation in LINE.
20816 IND is a cons cell with target and minimum indentation.
20817 If the current indentation in LINE is smaller than the minimum,
20818 leave it alone. If it is larger than ind, set it to the target."
20819 (let* ((l (org-remove-tabs line))
20820 (i (org-get-indentation l))
20821 (i1 (car ind)) (i2 (cdr ind)))
20822 (if (>= i i2) (setq l (substring line i2)))
20824 (concat (make-string i1 ?\ ) l)
20827 (defun org-remove-indentation (code &optional n)
20828 "Remove the maximum common indentation from the lines in CODE.
20829 N may optionally be the number of spaces to remove."
20832 (org-do-remove-indentation n)
20835 (defun org-do-remove-indentation (&optional n)
20836 "Remove the maximum common indentation from the buffer."
20837 (untabify (point-min) (point-max))
20838 (let ((min 10000) re)
20841 (goto-char (point-min))
20842 (while (re-search-forward "^ *[^ \n]" nil t)
20843 (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
20844 (unless (or (= min 0) (= min 10000))
20845 (setq re (format "^ \\{%d\\}" min))
20846 (goto-char (point-min))
20847 (while (re-search-forward re nil t)
20852 (defun org-fill-template (template alist)
20853 "Find each %key of ALIST in TEMPLATE and replace it."
20854 (let ((case-fold-search nil)
20856 (setq alist (sort (copy-sequence alist)
20857 (lambda (a b) (< (length (car a)) (length (car b))))))
20858 (while (setq entry (pop alist))
20860 (replace-regexp-in-string
20861 (concat "%" (regexp-quote (car entry)))
20862 (or (cdr entry) "") template t t)))
20865 (defun org-base-buffer (buffer)
20866 "Return the base buffer of BUFFER, if it has one. Else return the buffer."
20869 (or (buffer-base-buffer buffer)
20872 (defun org-trim (s)
20873 "Remove whitespace at beginning and end of string."
20874 (if (string-match "\\`[ \t\n\r]+" s) (setq s (replace-match "" t t s)))
20875 (if (string-match "[ \t\n\r]+\\'" s) (setq s (replace-match "" t t s)))
20878 (defun org-wrap (string &optional width lines)
20879 "Wrap string to either a number of lines, or a width in characters.
20880 If WIDTH is non-nil, the string is wrapped to that width, however many lines
20881 that costs. If there is a word longer than WIDTH, the text is actually
20882 wrapped to the length of that word.
20883 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
20884 many lines, whatever width that takes.
20885 The return value is a list of lines, without newlines at the end."
20886 (let* ((words (org-split-string string "[ \t\n]+"))
20887 (maxword (apply 'max (mapcar 'org-string-width words)))
20890 (org-do-wrap words (max maxword width)))
20893 (setq ll (org-do-wrap words maxword))
20894 (if (<= (length ll) lines)
20897 (while (> (length ll) lines)
20899 (setq ll (org-do-wrap words w)))
20901 (t (error "Cannot wrap this")))))
20903 (defun org-do-wrap (words width)
20904 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
20907 (setq line (pop words))
20908 (while (and words (< (+ (length line) (length (car words))) width))
20909 (setq line (concat line " " (pop words))))
20910 (setq lines (push line lines)))
20913 (defun org-split-string (string &optional separators)
20914 "Splits STRING into substrings at SEPARATORS.
20915 No empty strings are returned if there are matches at the beginning
20916 and end of string."
20917 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
20921 (while (and (string-match rexp string
20923 (= start (match-beginning 0))
20924 (< start (length string)))
20926 (< (match-beginning 0) (length string)))
20928 (or (eq (match-beginning 0) 0)
20929 (and (eq (match-beginning 0) (match-end 0))
20930 (eq (match-beginning 0) start))
20932 (cons (substring string start (match-beginning 0))
20934 (setq start (match-end 0)))
20935 (or (eq start (length string))
20937 (cons (substring string start)
20941 (defun org-quote-vert (s)
20942 "Replace \"|\" with \"\\vert\"."
20943 (while (string-match "|" s)
20944 (setq s (replace-match "\\vert" t t s)))
20947 (defun org-uuidgen-p (s)
20948 "Is S an ID created by UUIDGEN?"
20949 (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s)))
20951 (defun org-in-src-block-p (&optional inside)
20952 "Whether point is in a code source block.
20953 When INSIDE is non-nil, don't consider we are within a src block
20954 when point is at #+BEGIN_SRC or #+END_SRC."
20955 (let ((case-fold-search t) ov)
20956 (or (and (setq ov (overlays-at (point)))
20957 (memq 'org-block-background
20958 (overlay-properties (car ov))))
20962 (beginning-of-line)
20963 (looking-at ".*#\\+\\(begin\\|end\\)_src")))))))
20965 (defun org-context ()
20966 "Return a list of contexts of the current cursor position.
20967 If several contexts apply, all are returned.
20968 Each context entry is a list with a symbol naming the context, and
20969 two positions indicating start and end of the context. Possible
20972 :headline anywhere in a headline
20973 :headline-stars on the leading stars in a headline
20974 :todo-keyword on a TODO keyword (including DONE) in a headline
20975 :tags on the TAGS in a headline
20976 :priority on the priority cookie in a headline
20977 :item on the first line of a plain list item
20978 :item-bullet on the bullet/number of a plain list item
20979 :checkbox on the checkbox in a plain list item
20980 :table in an org-mode table
20981 :table-special on a special filed in a table
20982 :table-table in a table.el table
20983 :clocktable in a clocktable
20984 :src-block in a source block
20985 :link on a hyperlink
20986 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE, COMMENT, QUOTE.
20987 :target on a <<target>>
20988 :radio-target on a <<<radio-target>>>
20989 :latex-fragment on a LaTeX fragment
20990 :latex-preview on a LaTeX fragment with overlaid preview image
20992 This function expects the position to be visible because it uses font-lock
20993 faces as a help to recognize the following contexts: :table-special, :link,
20995 (let* ((f (get-text-property (point) 'face))
20996 (faces (if (listp f) f (list f)))
20997 (case-fold-search t)
20998 (p (point)) clist o)
20999 ;; First the large context
21001 ((org-at-heading-p t)
21002 (push (list :headline (point-at-bol) (point-at-eol)) clist)
21004 (beginning-of-line 1)
21005 (looking-at org-todo-line-tags-regexp))
21006 (push (org-point-in-group p 1 :headline-stars) clist)
21007 (push (org-point-in-group p 2 :todo-keyword) clist)
21008 (push (org-point-in-group p 4 :tags) clist))
21010 (skip-chars-backward "^[\n\r \t") (or (bobp) (backward-char 1))
21011 (if (looking-at "\\[#[A-Z0-9]\\]")
21012 (push (org-point-in-group p 0 :priority) clist)))
21015 (push (org-point-in-group p 2 :item-bullet) clist)
21016 (push (list :item (point-at-bol)
21017 (save-excursion (org-end-of-item) (point)))
21019 (and (org-at-item-checkbox-p)
21020 (push (org-point-in-group p 0 :checkbox) clist)))
21023 (push (list :table (org-table-begin) (org-table-end)) clist)
21024 (if (memq 'org-formula faces)
21025 (push (list :table-special
21026 (previous-single-property-change p 'face)
21027 (next-single-property-change p 'face)) clist)))
21028 ((org-at-table-p 'any)
21029 (push (list :table-table) clist)))
21032 (let ((case-fold-search t))
21033 ;; New the "medium" contexts: clocktables, source blocks
21034 (cond ((org-in-clocktable-p)
21035 (push (list :clocktable
21036 (and (or (looking-at "#\\+BEGIN: clocktable")
21037 (search-backward "#+BEGIN: clocktable" nil t))
21038 (match-beginning 0))
21039 (and (re-search-forward "#\\+END:?" nil t)
21040 (match-end 0))) clist))
21041 ((org-in-src-block-p)
21042 (push (list :src-block
21043 (and (or (looking-at "#\\+BEGIN_SRC")
21044 (search-backward "#+BEGIN_SRC" nil t))
21045 (match-beginning 0))
21046 (and (search-forward "#+END_SRC" nil t)
21047 (match-beginning 0))) clist))))
21050 ;; Now the small context
21052 ((org-at-timestamp-p)
21053 (push (org-point-in-group p 0 :timestamp) clist))
21054 ((memq 'org-link faces)
21056 (previous-single-property-change p 'face)
21057 (next-single-property-change p 'face)) clist))
21058 ((memq 'org-special-keyword faces)
21059 (push (list :keyword
21060 (previous-single-property-change p 'face)
21061 (next-single-property-change p 'face)) clist))
21063 (push (org-point-in-group p 0 :target) clist)
21064 (goto-char (1- (match-beginning 0)))
21065 (if (looking-at org-radio-target-regexp)
21066 (push (org-point-in-group p 0 :radio-target) clist))
21068 ((setq o (car (delq nil
21071 (if (memq x org-latex-fragment-image-overlays) x))
21072 (overlays-at (point))))))
21073 (push (list :latex-fragment
21074 (overlay-start o) (overlay-end o)) clist)
21075 (push (list :latex-preview
21076 (overlay-start o) (overlay-end o)) clist))
21077 ((org-inside-LaTeX-fragment-p)
21078 ;; FIXME: positions wrong.
21079 (push (list :latex-fragment (point) (point)) clist)))
21081 (setq clist (nreverse (delq nil clist)))
21084 ;; FIXME: Compare with at-regexp-p Do we need both?
21085 (defun org-in-regexp (re &optional nlines visually)
21086 "Check if point is inside a match of regexp.
21087 Normally only the current line is checked, but you can include NLINES extra
21088 lines both before and after point into the search.
21089 If VISUALLY is set, require that the cursor is not after the match but
21090 really on, so that the block visually is on the match."
21092 (let ((pos (point))
21093 (eol (point-at-eol (+ 1 (or nlines 0))))
21094 (inc (if visually 1 0)))
21096 (beginning-of-line (- 1 (or nlines 0)))
21097 (while (re-search-forward re eol t)
21098 (if (and (<= (match-beginning 0) pos)
21099 (>= (+ inc (match-end 0)) pos))
21100 (throw 'exit (cons (match-beginning 0) (match-end 0)))))))))
21102 (defun org-at-regexp-p (regexp)
21103 "Is point inside a match of REGEXP in the current line?"
21106 (let ((pos (point)) (end (point-at-eol)))
21107 (beginning-of-line 1)
21108 (while (re-search-forward regexp end t)
21109 (if (and (<= (match-beginning 0) pos)
21110 (>= (match-end 0) pos))
21114 (defun org-between-regexps-p (start-re end-re &optional lim-up lim-down)
21115 "Non-nil when point is between matches of START-RE and END-RE.
21117 Also return a non-nil value when point is on one of the matches.
21119 Optional arguments LIM-UP and LIM-DOWN bound the search; they are
21120 buffer positions. Default values are the positions of headlines
21121 surrounding the point.
21123 The functions returns a cons cell whose car (resp. cdr) is the
21124 position before START-RE (resp. after END-RE)."
21126 (let ((pos (point))
21127 (limit-up (or lim-up (save-excursion (outline-previous-heading))))
21128 (limit-down (or lim-down (save-excursion (outline-next-heading))))
21131 ;; Point is on a block when on START-RE or if START-RE can be
21132 ;; found before it...
21133 (and (or (org-at-regexp-p start-re)
21134 (re-search-backward start-re limit-up t))
21135 (setq beg (match-beginning 0))
21136 ;; ... and END-RE after it...
21137 (goto-char (match-end 0))
21138 (re-search-forward end-re limit-down t)
21139 (> (setq end (match-end 0)) pos)
21140 ;; ... without another START-RE in-between.
21141 (goto-char (match-beginning 0))
21142 (not (re-search-backward start-re (1+ beg) t))
21144 (cons beg end))))))
21146 (defun org-in-block-p (names)
21147 "Non-nil when point belongs to a block whose name belongs to NAMES.
21149 NAMES is a list of strings containing names of blocks.
21151 Return first block name matched, or nil. Beware that in case of
21152 nested blocks, the returned name may not belong to the closest
21156 (let ((case-fold-search t)
21157 (lim-up (save-excursion (outline-previous-heading)))
21158 (lim-down (save-excursion (outline-next-heading))))
21159 (mapc (lambda (name)
21160 (let ((n (regexp-quote name)))
21161 (when (org-between-regexps-p
21162 (concat "^[ \t]*#\\+begin_" n)
21163 (concat "^[ \t]*#\\+end_" n)
21169 (defun org-occur-in-agenda-files (regexp &optional nlines)
21170 "Call `multi-occur' with buffers for all agenda files."
21171 (interactive "sOrg-files matching: \np")
21172 (let* ((files (org-agenda-files))
21173 (tnames (mapcar 'file-truename files))
21174 (extra org-agenda-text-search-extra-files)
21176 (when (eq (car extra) 'agenda-archives)
21177 (setq extra (cdr extra))
21178 (setq files (org-add-archive-files files)))
21179 (while (setq f (pop extra))
21180 (unless (member (file-truename f) tnames)
21181 (add-to-list 'files f 'append)
21182 (add-to-list 'tnames (file-truename f) 'append)))
21184 (mapcar (lambda (x)
21185 (with-current-buffer
21186 (or (get-file-buffer x) (find-file-noselect x))
21192 (if (boundp 'occur-mode-find-occurrence-hook)
21194 (add-hook 'occur-mode-find-occurrence-hook
21196 (when (derived-mode-p 'org-mode)
21199 (defadvice occur-mode-goto-occurrence
21200 (after org-occur-reveal activate)
21201 (and (derived-mode-p 'org-mode) (org-reveal)))
21202 (defadvice occur-mode-goto-occurrence-other-window
21203 (after org-occur-reveal activate)
21204 (and (derived-mode-p 'org-mode) (org-reveal)))
21205 (defadvice occur-mode-display-occurrence
21206 (after org-occur-reveal activate)
21207 (when (derived-mode-p 'org-mode)
21208 (let ((pos (occur-mode-find-occurrence)))
21209 (with-current-buffer (marker-buffer pos)
21214 (defun org-occur-link-in-agenda-files ()
21215 "Create a link and search for it in the agendas.
21216 The link is not stored in `org-stored-links', it is just created
21217 for the search purpose."
21219 (let ((link (condition-case nil
21220 (org-store-link nil)
21221 (error "Unable to create a link to here"))))
21222 (org-occur-in-agenda-files (regexp-quote link))))
21224 (defun org-reverse-string (string)
21225 "Return the reverse of STRING."
21226 (apply 'string (reverse (string-to-list string))))
21228 (defun org-uniquify (list)
21229 "Remove duplicate elements from LIST."
21231 (mapc (lambda (x) (add-to-list 'res x 'append)) list)
21234 (defun org-delete-all (elts list)
21235 "Remove all elements in ELTS from LIST."
21237 (setq list (delete (pop elts) list)))
21240 (defun org-count (cl-item cl-seq)
21241 "Count the number of occurrences of ITEM in SEQ.
21242 Taken from `count' in cl-seq.el with all keyword arguments removed."
21243 (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0) cl-x)
21244 (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
21245 (while (< cl-start cl-end)
21246 (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
21247 (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
21248 (setq cl-start (1+ cl-start)))
21251 (defun org-remove-if (predicate seq)
21252 "Remove everything from SEQ that fulfills PREDICATE."
21256 (if (not (funcall predicate e)) (push e res)))
21259 (defun org-remove-if-not (predicate seq)
21260 "Remove everything from SEQ that does not fulfill PREDICATE."
21264 (if (funcall predicate e) (push e res)))
21267 (defun org-reduce (cl-func cl-seq &rest cl-keys)
21268 "Reduce two-argument FUNCTION across SEQ.
21269 Taken from `reduce' in cl-seq.el with all keyword arguments but
21270 \":initial-value\" removed."
21271 (let ((cl-accum (cond ((memq :initial-value cl-keys)
21272 (cadr (memq :initial-value cl-keys)))
21273 (cl-seq (pop cl-seq))
21274 (t (funcall cl-func)))))
21276 (setq cl-accum (funcall cl-func cl-accum (pop cl-seq))))
21279 (defun org-back-over-empty-lines ()
21280 "Move backwards over whitespace, to the beginning of the first empty line.
21281 Returns the number of empty lines passed."
21282 (let ((pos (point)))
21283 (if (cdr (assoc 'heading org-blank-before-new-entry))
21284 (skip-chars-backward " \t\n\r")
21286 (forward-line -1)))
21287 (beginning-of-line 2)
21288 (goto-char (min (point) pos))
21289 (count-lines (point) pos)))
21291 (defun org-skip-whitespace ()
21292 (skip-chars-forward " \t\n\r"))
21294 (defun org-point-in-group (point group &optional context)
21295 "Check if POINT is in match-group GROUP.
21296 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
21297 match. If the match group does not exist or point is not inside it,
21299 (and (match-beginning group)
21300 (>= point (match-beginning group))
21301 (<= point (match-end group))
21303 (list context (match-beginning group) (match-end group))
21306 (defun org-switch-to-buffer-other-window (&rest args)
21307 "Switch to buffer in a second window on the current frame.
21308 In particular, do not allow pop-up frames.
21309 Returns the newly created buffer."
21311 (apply 'switch-to-buffer-other-window args)))
21313 (defun org-combine-plists (&rest plists)
21314 "Create a single property list from all plists in PLISTS.
21315 The process starts by copying the first list, and then setting properties
21316 from the other lists. Settings in the last list are the most significant
21317 ones and overrule settings in the other lists."
21318 (let ((rtn (copy-sequence (pop plists)))
21321 (setq ls (pop plists))
21323 (setq p (pop ls) v (pop ls))
21324 (setq rtn (plist-put rtn p v))))
21327 (defun org-replace-escapes (string table)
21328 "Replace %-escapes in STRING with values in TABLE.
21329 TABLE is an association list with keys like \"%a\" and string values.
21330 The sequences in STRING may contain normal field width and padding information,
21331 for example \"%-5s\". Replacements happen in the sequence given by TABLE,
21332 so values can contain further %-escapes if they are define later in TABLE."
21333 (let ((tbl (copy-alist table))
21334 (case-fold-search nil)
21337 (while (setq e (pop tbl))
21338 (setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
21339 (when (and (cdr e) (string-match re (cdr e)))
21340 (let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
21342 (add-text-properties 0 3 (list 'sref sref) safe)
21343 (setcdr e (replace-match safe t t (cdr e)))))
21344 (while (string-match re string)
21345 (setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
21347 (setq string (replace-match rpl t t string))))
21348 (while (setq pchg (next-property-change pchg string))
21349 (let ((sref (get-text-property pchg 'sref string)))
21350 (when (and sref (string-match "SREF" string pchg))
21351 (setq string (replace-match sref t t string)))))
21354 (defun org-sublist (list start end)
21355 "Return a section of LIST, from START to END.
21356 Counting starts at 1."
21357 (let (rtn (c start))
21358 (setq list (nthcdr (1- start) list))
21359 (while (and list (<= c end))
21360 (push (pop list) rtn)
21364 (defun org-find-base-buffer-visiting (file)
21365 "Like `find-buffer-visiting' but always return the base buffer and
21366 not an indirect buffer."
21367 (let ((buf (or (get-file-buffer file)
21368 (find-buffer-visiting file))))
21370 (or (buffer-base-buffer buf) buf)
21373 (defun org-image-file-name-regexp (&optional extensions)
21374 "Return regexp matching the file names of images.
21375 If EXTENSIONS is given, only match these."
21376 (if (and (not extensions) (fboundp 'image-file-name-regexp))
21377 (image-file-name-regexp)
21378 (let ((image-file-name-extensions
21380 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
21381 "xbm" "xpm" "pbm" "pgm" "ppm"))))
21383 (regexp-opt (nconc (mapcar 'upcase
21384 image-file-name-extensions)
21385 image-file-name-extensions)
21389 (defun org-file-image-p (file &optional extensions)
21390 "Return non-nil if FILE is an image."
21392 (string-match (org-image-file-name-regexp extensions) file)))
21394 (defun org-get-cursor-date (&optional with-time)
21395 "Return the date at cursor in as a time.
21396 This works in the calendar and in the agenda, anywhere else it just
21397 returns the current time.
21398 If WITH-TIME is non-nil, returns the time of the event at point (in
21399 the agenda) or the current time of the day."
21400 (let (date day defd tp tm hod mod)
21402 (setq tp (get-text-property (point) 'time))
21403 (when (and tp (string-match "\\([0-9][0-9]\\):\\([0-9][0-9]\\)" tp))
21404 (setq hod (string-to-number (match-string 1 tp))
21405 mod (string-to-number (match-string 2 tp))))
21406 (or tp (setq hod (nth 2 (decode-time (current-time)))
21407 mod (nth 1 (decode-time (current-time))))))
21409 ((eq major-mode 'calendar-mode)
21410 (setq date (calendar-cursor-to-date)
21411 defd (encode-time 0 (or mod 0) (or hod 0)
21412 (nth 1 date) (nth 0 date) (nth 2 date))))
21413 ((eq major-mode 'org-agenda-mode)
21414 (setq day (get-text-property (point) 'day))
21416 (setq date (calendar-gregorian-from-absolute day)
21417 defd (encode-time 0 (or mod 0) (or hod 0)
21418 (nth 1 date) (nth 0 date) (nth 2 date))))))
21419 (or defd (current-time))))
21421 (defun org-mark-subtree (&optional up)
21422 "Mark the current subtree.
21423 This puts point at the start of the current subtree, and mark at
21424 the end. If a numeric prefix UP is given, move up into the
21425 hierarchy of headlines by UP levels before marking the subtree."
21427 (org-with-limited-levels
21428 (cond ((org-at-heading-p) (beginning-of-line))
21429 ((org-before-first-heading-p) (error "Not in a subtree"))
21430 (t (outline-previous-visible-heading 1))))
21431 (when up (while (and (> up 0) (org-up-heading-safe)) (decf up)))
21432 (if (org-called-interactively-p 'any)
21433 (call-interactively 'org-mark-element)
21434 (org-mark-element)))
21439 (defun org-indent-line ()
21440 "Indent line depending on context."
21442 (let* ((pos (point))
21443 (itemp (org-at-item-p))
21444 (case-fold-search t)
21445 (org-drawer-regexp (or org-drawer-regexp "\000"))
21446 (inline-task-p (and (featurep 'org-inlinetask)
21447 (org-inlinetask-in-task-p)))
21448 (inline-re (and inline-task-p
21449 (org-inlinetask-outline-regexp)))
21451 (if (and orgstruct-is-++ (eq pos (point)))
21452 (let ((indent-line-function (cadadr (assoc 'indent-line-function org-fb-vars))))
21453 (indent-according-to-mode))
21454 (beginning-of-line 1)
21457 ((looking-at org-outline-regexp) (setq column 0))
21458 ;; Footnote definition
21459 ((looking-at org-footnote-definition-re) (setq column 0))
21460 ;; Literal examples
21461 ((looking-at "[ \t]*:\\( \\|$\\)")
21462 (setq column (org-get-indentation))) ; do nothing
21464 ((ignore-errors (goto-char (org-in-item-p)))
21465 (setq column (if itemp
21466 (org-get-indentation)
21467 (org-list-item-body-column (point))))
21470 ((and (looking-at "[ \t]*:END:")
21471 (save-excursion (re-search-backward org-drawer-regexp nil t)))
21473 (goto-char (1- (match-beginning 1)))
21474 (setq column (current-column))))
21476 ((and (looking-at "[ \t]*#\\+end_\\([a-z]+\\)")
21478 (re-search-backward
21479 (concat "^[ \t]*#\\+begin_" (downcase (match-string 1))) nil t)))
21480 (setq column (org-get-indentation (match-string 0))))
21481 ((and (not (looking-at "[ \t]*#\\+begin_"))
21482 (org-between-regexps-p "^[ \t]*#\\+begin_" "[ \t]*#\\+end_"))
21484 (re-search-backward "^[ \t]*#\\+begin_\\([a-z]+\\)" nil t))
21486 (cond ((equal (downcase (match-string 1)) "src")
21487 ;; src blocks: let `org-edit-src-exit' handle them
21488 (org-get-indentation))
21489 ((equal (downcase (match-string 1)) "example")
21490 (max (org-get-indentation)
21491 (org-get-indentation (match-string 0))))
21493 (org-get-indentation (match-string 0))))))
21494 ;; This line has nothing special, look at the previous relevant
21495 ;; line to compute indentation
21497 (beginning-of-line 0)
21498 (while (and (not (bobp))
21499 (not (looking-at org-table-line-regexp))
21500 (not (looking-at org-drawer-regexp))
21501 ;; When point started in an inline task, do not move
21502 ;; above task starting line.
21503 (not (and inline-task-p (looking-at inline-re)))
21504 ;; Skip drawers, blocks, empty lines, verbatim,
21505 ;; comments, tables, footnotes definitions, lists,
21507 (or (and (looking-at "[ \t]*:END:")
21508 (re-search-backward org-drawer-regexp nil t))
21509 (and (looking-at "[ \t]*#\\+end_")
21510 (re-search-backward "[ \t]*#\\+begin_"nil t))
21511 (looking-at "[ \t]*[\n:#|]")
21512 (looking-at org-footnote-definition-re)
21513 (and (ignore-errors (goto-char (org-in-item-p)))
21515 (org-list-get-top-point (org-list-struct))))
21516 (and (not inline-task-p)
21517 (featurep 'org-inlinetask)
21518 (org-inlinetask-in-task-p)
21519 (or (org-inlinetask-goto-beginning) t))))
21520 (beginning-of-line 0))
21522 ;; There was an heading above.
21523 ((looking-at "\\*+[ \t]+")
21524 (if (not org-adapt-indentation)
21526 (goto-char (match-end 0))
21527 (setq column (current-column))))
21528 ;; A drawer had started and is unfinished
21529 ((looking-at org-drawer-regexp)
21530 (goto-char (1- (match-beginning 1)))
21531 (setq column (current-column)))
21532 ;; Else, nothing noticeable found: get indentation and go on.
21533 (t (setq column (org-get-indentation))))))
21534 ;; Now apply indentation and move cursor accordingly
21536 (if (<= (current-column) (current-indentation))
21537 (org-indent-line-to column)
21538 (save-excursion (org-indent-line-to column)))
21539 ;; Special polishing for properties, see `org-property-format'
21540 (setq column (current-column))
21541 (beginning-of-line 1)
21543 "\\([ \t]*\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
21544 (replace-match (concat (match-string 1)
21545 (format org-property-format
21546 (match-string 2) (match-string 3)))
21548 (org-move-to-column column))))
21550 (defun org-indent-drawer ()
21551 "Indent the drawer at point."
21554 (e (and (save-excursion (re-search-forward ":END:" nil t))
21559 (when (overlays-at (point))
21560 (member 'invisible (overlay-properties
21561 (car (overlays-at (point)))))))))
21562 (when folded (org-cycle))
21563 (indent-for-tab-command)
21564 (while (and (move-beginning-of-line 2) (< (point) e))
21565 (indent-for-tab-command))
21567 (when folded (org-cycle)))
21568 (message "Drawer at point indented"))
21570 (defun org-indent-block ()
21571 "Indent the block at point."
21574 (case-fold-search t)
21575 (e (and (save-excursion (re-search-forward "#\\+end_?\\(?:[a-z]+\\)?" nil t))
21580 (when (overlays-at (point))
21581 (member 'invisible (overlay-properties
21582 (car (overlays-at (point)))))))))
21583 (when folded (org-cycle))
21584 (indent-for-tab-command)
21585 (while (and (move-beginning-of-line 2) (< (point) e))
21586 (indent-for-tab-command))
21588 (when folded (org-cycle)))
21589 (message "Block at point indented"))
21591 (defun org-indent-region (start end)
21595 (let ((line-end (org-current-line end)))
21597 (while (< (org-current-line) line-end)
21598 (cond ((org-in-src-block-p) (org-src-native-tab-command-maybe))
21599 (t (call-interactively 'org-indent-line)))
21600 (move-beginning-of-line 2)))))
21605 ;; We use our own fill-paragraph and auto-fill functions.
21607 ;; `org-fill-paragraph' relies on adaptive filling and context
21608 ;; checking. Appropriate `fill-prefix' is computed with
21609 ;; `org-adaptive-fill-function'.
21611 ;; `org-auto-fill-function' takes care of auto-filling. It calls
21612 ;; `do-auto-fill' only on valid areas with `fill-prefix' shadowed with
21613 ;; `org-adaptive-fill-function' value. Internally,
21614 ;; `org-comment-line-break-function' breaks the line.
21616 ;; `org-setup-filling' installs filling and auto-filling related
21617 ;; variables during `org-mode' initialization.
21619 (defun org-setup-filling ()
21621 ;; Prevent auto-fill from inserting unwanted new items.
21622 (when (boundp 'fill-nobreak-predicate)
21624 'fill-nobreak-predicate
21626 (append fill-nobreak-predicate
21627 '(org-fill-paragraph-separate-nobreak-p
21628 org-fill-line-break-nobreak-p
21629 org-fill-paragraph-with-timestamp-nobreak-p)))))
21630 (org-set-local 'fill-paragraph-function 'org-fill-paragraph)
21631 (org-set-local 'auto-fill-inhibit-regexp nil)
21632 (org-set-local 'adaptive-fill-function 'org-adaptive-fill-function)
21633 (org-set-local 'normal-auto-fill-function 'org-auto-fill-function)
21634 (org-set-local 'comment-line-break-function 'org-comment-line-break-function))
21636 (defvar org-element-paragraph-separate) ; org-element.el
21637 (defun org-fill-paragraph-separate-nobreak-p ()
21638 "Non-nil when a line break at point would insert a new item."
21639 (looking-at (substring org-element-paragraph-separate 1)))
21641 (defun org-fill-line-break-nobreak-p ()
21642 "Non-nil when a line break at point would create an Org line break."
21644 (skip-chars-backward "[ \t]")
21645 (skip-chars-backward "\\\\")
21646 (looking-at "\\\\\\\\\\($\\|[^\\\\]\\)")))
21648 (defun org-fill-paragraph-with-timestamp-nobreak-p ()
21649 "Non-nil when a line break at point would insert a new item."
21650 (and (org-at-timestamp-p t)
21651 (not (looking-at org-ts-regexp-both))))
21653 (declare-function message-in-body-p "message" ())
21654 (defvar orgtbl-line-start-regexp) ; From org-table.el
21655 (defun org-adaptive-fill-function ()
21656 "Compute a fill prefix for the current line.
21657 Return fill prefix, as a string, or nil if current line isn't
21658 meant to be filled."
21661 (when (derived-mode-p 'message-mode)
21663 (beginning-of-line)
21664 (cond ((or (not (message-in-body-p))
21665 (looking-at orgtbl-line-start-regexp))
21667 ((looking-at message-cite-prefix-regexp)
21668 (throw 'exit (match-string-no-properties 0)))
21669 ((looking-at org-outline-regexp)
21670 (throw 'exit (make-string (length (match-string 0)) ? ))))))
21671 (org-with-wide-buffer
21672 (let* ((p (line-beginning-position))
21673 (element (save-excursion (beginning-of-line)
21674 (org-element-at-point)))
21675 (type (org-element-type element))
21676 (post-affiliated (org-element-property :post-affiliated element)))
21677 (unless (and post-affiliated (< p post-affiliated))
21679 (comment (looking-at "[ \t]*# ?") (match-string 0))
21680 (footnote-definition "")
21682 (make-string (org-list-item-body-column
21683 (or post-affiliated
21684 (org-element-property :begin element)))
21687 ;; Fill prefix is usually the same as the current line,
21688 ;; except if the paragraph is at the beginning of an item.
21689 (let ((parent (org-element-property :parent element)))
21690 (cond ((eq (org-element-type parent) 'item)
21691 (make-string (org-list-item-body-column
21692 (org-element-property :begin parent))
21694 ((save-excursion (beginning-of-line) (looking-at "[ \t]+"))
21698 ;; Only fill contents if P is within block boundaries.
21699 (let* ((cbeg (save-excursion (goto-char post-affiliated)
21702 (cend (save-excursion
21703 (goto-char (org-element-property :end element))
21704 (skip-chars-backward " \r\t\n")
21705 (line-beginning-position))))
21706 (when (and (>= p cbeg) (< p cend))
21707 (if (save-excursion (beginning-of-line) (looking-at "[ \t]+"))
21711 (declare-function message-goto-body "message" ())
21712 (defvar message-cite-prefix-regexp) ; From message.el
21713 (defvar org-element-all-objects) ; From org-element.el
21714 (defun org-fill-paragraph (&optional justify)
21715 "Fill element at point, when applicable.
21717 This function only applies to comment blocks, comments, example
21718 blocks and paragraphs. Also, as a special case, re-align table
21719 when point is at one.
21721 If JUSTIFY is non-nil (interactively, with prefix argument),
21722 justify as well. If `sentence-end-double-space' is non-nil, then
21723 period followed by one space does not end a sentence, so don't
21724 break a line there. The variable `fill-column' controls the
21727 For convenience, when point is at a plain list, an item or
21728 a footnote definition, try to fill the first paragraph within."
21730 (if (and (derived-mode-p 'message-mode)
21731 (or (not (message-in-body-p))
21732 (save-excursion (move-beginning-of-line 1)
21733 (looking-at message-cite-prefix-regexp))))
21734 ;; First ensure filling is correct in message-mode.
21735 (let ((fill-paragraph-function
21736 (cadadr (assoc 'fill-paragraph-function org-fb-vars)))
21737 (fill-prefix (cadadr (assoc 'fill-prefix org-fb-vars)))
21738 (paragraph-start (cadadr (assoc 'paragraph-start org-fb-vars)))
21739 (paragraph-separate
21740 (cadadr (assoc 'paragraph-separate org-fb-vars))))
21741 (fill-paragraph nil))
21743 ;; Move to end of line in order to get the first paragraph
21744 ;; within a plain list or a footnote definition.
21746 (let ((element (org-element-at-point)))
21747 ;; First check if point is in a blank line at the beginning of
21748 ;; the buffer. In that case, ignore filling.
21749 (if (< (point) (org-element-property :begin element)) t
21750 (case (org-element-type element)
21751 ;; Use major mode filling function is src blocks.
21752 (src-block (org-babel-do-key-sequence-in-edit-buffer (kbd "M-q")))
21753 ;; Align Org tables, leave table.el tables as-is.
21754 (table-row (org-table-align) t)
21756 (when (eq (org-element-property :type element) 'org)
21760 ;; Paragraphs may contain `line-break' type objects.
21761 (let ((beg (max (point-min)
21762 (org-element-property :contents-begin element)))
21763 (end (min (point-max)
21764 (org-element-property :contents-end element))))
21765 ;; Do nothing if point is at an affiliated keyword.
21766 (if (< (point) beg) t
21767 (when (derived-mode-p 'message-mode)
21768 ;; In `message-mode', do not fill following
21769 ;; citation in current paragraph nor text before
21771 (let ((body-start (save-excursion (message-goto-body))))
21772 (when body-start (setq beg (max body-start beg))))
21773 (when (save-excursion
21775 (concat "^" message-cite-prefix-regexp) end t))
21776 (setq end (match-beginning 0))))
21777 ;; Fill paragraph, taking line breaks into
21778 ;; consideration. For that, slice the paragraph
21779 ;; using line breaks as separators, and fill the
21780 ;; parts in reverse order to avoid messing with
21786 (fill-region-as-paragraph pos (point) justify)
21788 ;; Find the list of ending positions for line
21789 ;; breaks in the current paragraph. Add paragraph
21790 ;; beginning to include first slice.
21795 (org-element--parse-objects
21796 beg end nil org-element-all-objects)
21798 (lambda (lb) (org-element-property :end lb)))))))
21800 ;; Contents of `comment-block' type elements should be
21801 ;; filled as plain text, but only if point is within block
21804 (let* ((case-fold-search t)
21805 (beg (save-excursion
21806 (goto-char (org-element-property :begin element))
21807 (re-search-forward "^[ \t]*#\\+begin_comment" nil t)
21810 (end (save-excursion
21811 (goto-char (org-element-property :end element))
21812 (re-search-backward "^[ \t]*#\\+end_comment" nil t)
21813 (line-beginning-position))))
21814 (when (and (>= (point) beg) (< (point) end))
21815 (fill-region-as-paragraph
21818 (re-search-backward "^[ \t]*$" beg 'move)
21819 (line-beginning-position))
21821 (beginning-of-line)
21822 (re-search-forward "^[ \t]*$" end 'move)
21823 (line-beginning-position))
21827 (comment (fill-comment-paragraph justify))
21828 ;; Ignore every other element.
21829 (otherwise t)))))))
21831 (defun org-auto-fill-function ()
21832 "Auto-fill function."
21833 ;; Check if auto-filling is meaningful.
21834 (let ((fc (current-fill-column)))
21835 (when (and fc (> (current-column) fc))
21836 (let* ((fill-prefix (org-adaptive-fill-function))
21837 ;; Enforce empty fill prefix, if required. Otherwise, it
21838 ;; will be computed again.
21839 (adaptive-fill-mode (not (equal fill-prefix ""))))
21840 (when fill-prefix (do-auto-fill))))))
21842 (defun org-comment-line-break-function (&optional soft)
21843 "Break line at point and indent, continuing comment if within one.
21844 The inserted newline is marked hard if variable
21845 `use-hard-newlines' is true, unless optional argument SOFT is
21847 (if soft (insert-and-inherit ?\n) (newline 1))
21848 (save-excursion (forward-char -1) (delete-horizontal-space))
21849 (delete-horizontal-space)
21850 (indent-to-left-margin)
21851 (insert-before-markers-and-inherit fill-prefix))
21856 ;; Org comments syntax is quite complex. It requires the entire line
21857 ;; to be just a comment. Also, even with the right syntax at the
21858 ;; beginning of line, some some elements (i.e. verse-block or
21859 ;; example-block) don't accept comments. Usual Emacs comment commands
21860 ;; cannot cope with those requirements. Therefore, Org replaces them.
21862 ;; Org still relies on `comment-dwim', but cannot trust
21863 ;; `comment-only-p'. So, `comment-region-function' and
21864 ;; `uncomment-region-function' both point
21865 ;; to`org-comment-or-uncomment-region'. Eventually,
21866 ;; `org-insert-comment' takes care of insertion of comments at the
21867 ;; beginning of line.
21869 ;; `org-setup-comments-handling' install comments related variables
21870 ;; during `org-mode' initialization.
21872 (defun org-setup-comments-handling ()
21874 (org-set-local 'comment-use-syntax nil)
21875 (org-set-local 'comment-start "# ")
21876 (org-set-local 'comment-start-skip "^\\s-*#\\(?: \\|$\\)")
21877 (org-set-local 'comment-insert-comment-function 'org-insert-comment)
21878 (org-set-local 'comment-region-function 'org-comment-or-uncomment-region)
21879 (org-set-local 'uncomment-region-function 'org-comment-or-uncomment-region))
21881 (defun org-insert-comment ()
21882 "Insert an empty comment above current line.
21883 If the line is empty, insert comment at its beginning."
21884 (beginning-of-line)
21885 (if (looking-at "\\s-*$") (replace-match "") (open-line 1))
21889 (defvar comment-empty-lines) ; From newcomment.el.
21890 (defun org-comment-or-uncomment-region (beg end &rest ignore)
21891 "Comment or uncomment each non-blank line in the region.
21892 Uncomment each non-blank line between BEG and END if it only
21893 contains commented lines. Otherwise, comment them."
21896 (narrow-to-region (save-excursion (goto-char beg)
21897 (skip-chars-forward " \r\t\n" end)
21898 (line-beginning-position))
21899 (save-excursion (goto-char end)
21900 (skip-chars-backward " \r\t\n" beg)
21901 (line-end-position)))
21903 ;; UNCOMMENTP is non-nil when every non blank line between
21904 ;; BEG and END is a comment.
21906 (goto-char (point-min))
21907 (while (and (not (eobp))
21908 (let ((element (org-element-at-point)))
21909 (and (eq (org-element-type element) 'comment)
21910 (goto-char (min (point-max)
21911 (org-element-property
21912 :end element)))))))
21915 ;; Only blank lines and comments in region: uncomment it.
21917 (goto-char (point-min))
21918 (while (not (eobp))
21919 (when (looking-at "[ \t]*\\(#\\(?: \\|$\\)\\)")
21920 (replace-match "" nil nil nil 1))
21922 ;; Comment each line in region.
21923 (let ((min-indent (point-max)))
21924 ;; First find the minimum indentation across all lines.
21926 (goto-char (point-min))
21927 (while (and (not (eobp)) (not (zerop min-indent)))
21928 (unless (looking-at "[ \t]*$")
21929 (setq min-indent (min min-indent (current-indentation))))
21931 ;; Then loop over all lines.
21933 (goto-char (point-min))
21934 (while (not (eobp))
21935 (unless (and (not comment-empty-lines) (looking-at "[ \t]*$"))
21936 (org-move-to-column min-indent t)
21937 (insert comment-start))
21938 (forward-line))))))))
21943 ;; This section contains tools to operate on timestamp objects, as
21944 ;; returned by, e.g. `org-element-context'.
21946 (defun org-timestamp-has-time-p (timestamp)
21947 "Non-nil when TIMESTAMP has a time specified."
21948 (org-element-property :hour-start timestamp))
21950 (defun org-timestamp-format (timestamp format &optional end utc)
21951 "Format a TIMESTAMP element into a string.
21953 FORMAT is a format specifier to be passed to
21954 `format-time-string'.
21956 When optional argument END is non-nil, use end of date-range or
21957 time-range, if possible.
21959 When optional argument UTC is non-nil, time will be expressed as
21961 (format-time-string
21963 (apply 'encode-time
21966 (lambda (prop) (or (org-element-property prop timestamp) 0))
21967 (if end '(:minute-end :hour-end :day-end :month-end :year-end)
21968 '(:minute-start :hour-start :day-start :month-start
21972 (defun org-timestamp-split-range (timestamp &optional end)
21973 "Extract a timestamp object from a date or time range.
21975 TIMESTAMP is a timestamp object. END, when non-nil, means extract
21976 the end of the range. Otherwise, extract its start.
21978 Return a new timestamp object sharing the same parent as
21980 (let ((type (org-element-property :type timestamp)))
21981 (if (memq type '(active inactive diary)) timestamp
21982 (let ((split-ts (list 'timestamp (copy-sequence (nth 1 timestamp)))))
21984 (org-element-put-property
21985 split-ts :type (if (eq type 'active-range) 'active 'inactive))
21986 ;; Copy start properties over end properties if END is
21987 ;; non-nil. Otherwise, copy end properties over `start' ones.
21988 (let ((p-alist '((:minute-start . :minute-end)
21989 (:hour-start . :hour-end)
21990 (:day-start . :day-end)
21991 (:month-start . :month-end)
21992 (:year-start . :year-end))))
21993 (dolist (p-cell p-alist)
21994 (org-element-put-property
21996 (funcall (if end 'car 'cdr) p-cell)
21997 (org-element-property
21998 (funcall (if end 'cdr 'car) p-cell) split-ts)))
21999 ;; Eventually refresh `:raw-value'.
22000 (org-element-put-property split-ts :raw-value nil)
22001 (org-element-put-property
22002 split-ts :raw-value (org-element-interpret-data split-ts)))))))
22004 (defun org-timestamp-translate (timestamp &optional boundary)
22005 "Apply `org-translate-time' on a TIMESTAMP object.
22006 When optional argument BOUNDARY is non-nil, it is either the
22007 symbol `start' or `end'. In this case, only translate the
22008 starting or ending part of TIMESTAMP if it is a date or time
22009 range. Otherwise, translate both parts."
22010 (if (and (not boundary)
22011 (memq (org-element-property :type timestamp)
22012 '(active-range inactive-range)))
22014 (org-translate-time
22015 (org-element-property :raw-value
22016 (org-timestamp-split-range timestamp)))
22018 (org-translate-time
22019 (org-element-property :raw-value
22020 (org-timestamp-split-range timestamp t))))
22021 (org-translate-time
22022 (org-element-property
22024 (if (not boundary) timestamp
22025 (org-timestamp-split-range timestamp (eq boundary 'end)))))))
22031 (defun org-toggle-fixed-width-section (arg)
22032 "Toggle the fixed-width export.
22033 If there is no active region, the QUOTE keyword at the current headline is
22034 inserted or removed. When present, it causes the text between this headline
22035 and the next to be exported as fixed-width text, and unmodified.
22036 If there is an active region, this command adds or removes a colon as the
22037 first character of this line. If the first character of a line is a colon,
22038 this line is also exported in fixed-width font."
22041 (regionp (org-region-active-p))
22042 (beg (if regionp (region-beginning) (point)))
22043 (end (if regionp (region-end)))
22044 (nlines (or arg (if (and beg end) (count-lines beg end) 1)))
22045 (case-fold-search nil)
22046 (re "[ \t]*\\(:\\(?: \\|$\\)\\)")
22051 (setq cc (current-column))
22052 (beginning-of-line 1)
22053 (setq off (looking-at re))
22054 (while (> nlines 0)
22055 (setq nlines (1- nlines))
22056 (beginning-of-line 1)
22059 (org-move-to-column cc t)
22062 ((and off (looking-at re))
22063 (replace-match "" t t nil 1))
22064 ((not off) (org-move-to-column cc t) (insert ": ")))
22067 (org-back-to-heading)
22069 ((looking-at (format org-heading-keyword-regexp-format
22071 (goto-char (match-end 1))
22072 (looking-at (concat " +" org-quote-string))
22073 (replace-match "" t t)
22074 (when (eolp) (insert " ")))
22075 ((looking-at org-outline-regexp)
22076 (goto-char (match-end 0))
22077 (insert org-quote-string " ")))))))
22079 (defun org-reftex-citation ()
22080 "Use reftex-citation to insert a citation into the buffer.
22081 This looks for a line like
22083 #+BIBLIOGRAPHY: foo plain option:-d
22085 and derives from it that foo.bib is the bibliography file relevant
22086 for this document. It then installs the necessary environment for RefTeX
22087 to work in this buffer and calls `reftex-citation' to insert a citation
22090 Export of such citations to both LaTeX and HTML is handled by the contributed
22091 package org-exp-bibtex by Taru Karttunen."
22093 (let ((reftex-docstruct-symbol 'rds)
22094 (reftex-cite-format "\\cite{%l}")
22099 (let ((case-fold-search t)
22100 (re "^#\\+bibliography:[ \t]+\\([^ \t\n]+\\)"))
22101 (if (not (save-excursion
22102 (or (re-search-forward re nil t)
22103 (re-search-backward re nil t))))
22104 (error "No bibliography defined in file")
22105 (setq bib (concat (match-string 1) ".bib")
22106 rds (list (list 'bib bib)))))))
22107 (call-interactively 'reftex-citation)))
22109 ;;;; Functions extending outline functionality
22111 (defun org-beginning-of-line (&optional arg)
22112 "Go to the beginning of the current line. If that is invisible, continue
22113 to a visible line beginning. This makes the function of C-a more intuitive.
22114 If this is a headline, and `org-special-ctrl-a/e' is set, ignore tags on the
22115 first attempt, and only move to after the tags when the cursor is already
22116 beyond the end of the headline."
22118 (let ((pos (point))
22119 (special (if (consp org-special-ctrl-a/e)
22120 (car org-special-ctrl-a/e)
22121 org-special-ctrl-a/e))
22123 (if (org-bound-and-true-p visual-line-mode)
22124 (beginning-of-visual-line 1)
22125 (beginning-of-line 1))
22126 (if (and arg (fboundp 'move-beginning-of-line))
22127 (call-interactively 'move-beginning-of-line)
22131 (if (org-truely-invisible-p)
22132 (while (and (not (bobp)) (org-truely-invisible-p))
22134 (beginning-of-line 1))
22135 (forward-char 1))))
22138 ((and (looking-at org-complex-heading-regexp)
22139 (= (char-after (match-end 1)) ?\ ))
22140 (setq refpos (min (1+ (or (match-end 3) (match-end 2) (match-end 1)))
22144 (cond ((> pos refpos) refpos)
22145 ((= pos (point)) refpos)
22147 (cond ((> pos (point)) (point))
22148 ((not (eq last-command this-command)) (point))
22151 ;; Being at an item and not looking at an the item means point
22152 ;; was previously moved to beginning of a visual line, which
22153 ;; doesn't contain the item. Therefore, do nothing special,
22155 (when (looking-at org-list-full-item-re)
22156 ;; Set special position at first white space character after
22157 ;; bullet, and check-box, if any.
22158 (let ((after-bullet
22159 (let ((box (match-end 3)))
22160 (if (not box) (match-end 1)
22161 (let ((after (char-after box)))
22162 (if (and after (= after ? )) (1+ box) box))))))
22163 ;; Special case: Move point to special position when
22164 ;; currently after it or at beginning of line.
22166 (when (or (> pos after-bullet) (= (point) pos))
22167 (goto-char after-bullet))
22168 ;; Reversed case: Move point to special position when
22169 ;; point was already at beginning of line and command is
22171 (when (and (= (point) pos) (eq last-command this-command))
22172 (goto-char after-bullet))))))))
22174 (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
22176 (defun org-end-of-line (&optional arg)
22177 "Go to the end of the line.
22178 If this is a headline, and `org-special-ctrl-a/e' is set, ignore
22179 tags on the first attempt, and only move to after the tags when
22180 the cursor is already beyond the end of the headline."
22182 (let ((special (if (consp org-special-ctrl-a/e) (cdr org-special-ctrl-a/e)
22183 org-special-ctrl-a/e))
22184 (move-fun (cond ((org-bound-and-true-p visual-line-mode)
22185 'end-of-visual-line)
22186 ((fboundp 'move-end-of-line) 'move-end-of-line)
22187 (t 'end-of-line))))
22188 (if (or (not special) arg) (call-interactively move-fun)
22189 (let* ((element (save-excursion (beginning-of-line)
22190 (org-element-at-point)))
22191 (type (org-element-type element)))
22193 ((memq type '(headline inlinetask))
22194 (let ((pos (point)))
22195 (beginning-of-line 1)
22196 (if (looking-at (org-re ".*?\\(?:\\([ \t]*\\)\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\)?$"))
22198 (if (or (< pos (match-beginning 1)) (= pos (match-end 0)))
22199 (goto-char (match-beginning 1))
22200 (goto-char (match-end 0)))
22201 (if (or (< pos (match-end 0))
22202 (not (eq this-command last-command)))
22203 (goto-char (match-end 0))
22204 (goto-char (match-beginning 1))))
22205 (call-interactively move-fun))))
22206 ((org-element-property :hiddenp element)
22207 ;; If element is hidden, `move-end-of-line' would put point
22208 ;; after it. Use `end-of-line' to stay on current line.
22209 (call-interactively 'end-of-line))
22210 (t (call-interactively move-fun)))))
22211 (org-no-warnings (and (featurep 'xemacs) (setq zmacs-region-stays t)))))
22213 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
22214 (define-key org-mode-map "\C-e" 'org-end-of-line)
22216 (defun org-backward-sentence (&optional arg)
22217 "Go to beginning of sentence, or beginning of table field.
22218 This will call `backward-sentence' or `org-table-beginning-of-field',
22219 depending on context."
22222 ((org-at-table-p) (call-interactively 'org-table-beginning-of-field))
22223 (t (call-interactively 'backward-sentence))))
22225 (defun org-forward-sentence (&optional arg)
22226 "Go to end of sentence, or end of table field.
22227 This will call `forward-sentence' or `org-table-end-of-field',
22228 depending on context."
22231 ((org-at-table-p) (call-interactively 'org-table-end-of-field))
22232 (t (call-interactively 'forward-sentence))))
22234 (define-key org-mode-map "\M-a" 'org-backward-sentence)
22235 (define-key org-mode-map "\M-e" 'org-forward-sentence)
22237 (defun org-kill-line (&optional arg)
22238 "Kill line, to tags or end of line."
22241 ((or (not org-special-ctrl-k)
22243 (not (org-at-heading-p)))
22244 (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible)
22245 org-ctrl-k-protect-subtree)
22246 (if (or (eq org-ctrl-k-protect-subtree 'error)
22247 (not (y-or-n-p "Kill hidden subtree along with headline? ")))
22248 (error "C-k aborted - would kill hidden subtree")))
22249 (call-interactively
22250 (if (org-bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line)))
22251 ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@#%:]+:\\)\\)[ \t]*$"))
22252 (kill-region (point) (match-beginning 1))
22253 (org-set-tags nil t))
22254 (t (kill-region (point) (point-at-eol)))))
22256 (define-key org-mode-map "\C-k" 'org-kill-line)
22258 (defun org-yank (&optional arg)
22259 "Yank. If the kill is a subtree, treat it specially.
22260 This command will look at the current kill and check if is a single
22261 subtree, or a series of subtrees[1]. If it passes the test, and if the
22262 cursor is at the beginning of a line or after the stars of a currently
22263 empty headline, then the yank is handled specially. How exactly depends
22264 on the value of the following variables, both set by default.
22266 org-yank-folded-subtrees
22267 When set, the subtree(s) will be folded after insertion, but only
22268 if doing so would now swallow text after the yanked text.
22270 org-yank-adjusted-subtrees
22271 When set, the subtree will be promoted or demoted in order to
22272 fit into the local outline tree structure, which means that the level
22273 will be adjusted so that it becomes the smaller one of the two
22274 *visible* surrounding headings.
22276 Any prefix to this command will cause `yank' to be called directly with
22277 no special treatment. In particular, a simple \\[universal-argument] prefix \
22279 plainly yank the text as it is.
22281 \[1] The test checks if the first non-white line is a heading
22282 and if there are no other headings with fewer stars."
22284 (org-yank-generic 'yank arg))
22286 (defun org-yank-generic (command arg)
22287 "Perform some yank-like command.
22289 This function implements the behavior described in the `org-yank'
22290 documentation. However, it has been generalized to work for any
22291 interactive command with similar behavior."
22293 ;; pretend to be command COMMAND
22294 (setq this-command command)
22297 (call-interactively command)
22299 (let ((subtreep ; is kill a subtree, and the yank position appropriate?
22300 (and (org-kill-is-subtree-p)
22302 (and (looking-at "[ \t]*$")
22305 (buffer-substring (point-at-bol) (point)))))))
22308 ((and subtreep org-yank-folded-subtrees)
22309 (let ((beg (point))
22311 (if (and subtreep org-yank-adjusted-subtrees)
22312 (org-paste-subtree nil nil 'for-yank)
22313 (call-interactively command))
22317 (when (and (bolp) subtreep
22318 (not (setq swallowp
22319 (org-yank-folding-would-swallow-text beg end))))
22320 (org-with-limited-levels
22321 (or (looking-at org-outline-regexp)
22322 (re-search-forward org-outline-regexp-bol end t))
22323 (while (and (< (point) end) (looking-at org-outline-regexp))
22325 (org-cycle-show-empty-lines 'folded)
22326 (condition-case nil
22327 (outline-forward-same-level 1)
22328 (error (goto-char end))))))
22331 "Inserted text not folded because that would swallow text"))
22334 (skip-chars-forward " \t\n\r")
22335 (beginning-of-line 1)
22336 (push-mark beg 'nomsg)))
22337 ((and subtreep org-yank-adjusted-subtrees)
22338 (let ((beg (point-at-bol)))
22339 (org-paste-subtree nil nil 'for-yank)
22340 (push-mark beg 'nomsg)))
22342 (call-interactively command))))))
22344 (defun org-yank-folding-would-swallow-text (beg end)
22345 "Would hide-subtree at BEG swallow any text after END?"
22347 (org-with-limited-levels
22350 (when (or (looking-at org-outline-regexp)
22351 (re-search-forward org-outline-regexp-bol end t))
22352 (setq level (org-outline-level)))
22354 (skip-chars-forward " \t\r\n\v\f")
22356 (and (bolp) (looking-at org-outline-regexp)
22357 (<= (org-outline-level) level)))
22358 nil ; Nothing would be swallowed
22359 t))))) ; something would swallow
22361 (define-key org-mode-map "\C-y" 'org-yank)
22363 (defun org-truely-invisible-p ()
22364 "Check if point is at a character currently not visible.
22365 This version does not only check the character property, but also
22367 ;; Early versions of noutline don't have `outline-invisible-p'.
22368 (if (org-bound-and-true-p visible-mode)
22370 (outline-invisible-p)))
22372 (defun org-invisible-p2 ()
22373 "Check if point is at a character currently not visible."
22375 (if (and (eolp) (not (bobp))) (backward-char 1))
22376 ;; Early versions of noutline don't have `outline-invisible-p'.
22377 (outline-invisible-p)))
22379 (defun org-back-to-heading (&optional invisible-ok)
22380 "Call `outline-back-to-heading', but provide a better error message."
22381 (condition-case nil
22382 (outline-back-to-heading invisible-ok)
22383 (error (error "Before first headline at position %d in buffer %s"
22384 (point) (current-buffer)))))
22386 (defun org-before-first-heading-p ()
22387 "Before first heading?"
22390 (null (re-search-backward org-outline-regexp-bol nil t))))
22392 (defun org-at-heading-p (&optional ignored)
22393 (outline-on-heading-p t))
22394 ;; Compatibility alias with Org versions < 7.8.03
22395 (defalias 'org-on-heading-p 'org-at-heading-p)
22397 (defun org-at-comment-p nil
22398 "Is cursor in a line starting with a # character?"
22400 (beginning-of-line)
22401 (looking-at "^#")))
22403 (defun org-at-drawer-p nil
22404 "Is cursor at a drawer keyword?"
22406 (move-beginning-of-line 1)
22407 (looking-at org-drawer-regexp)))
22409 (defun org-at-block-p nil
22410 "Is cursor at a block keyword?"
22412 (move-beginning-of-line 1)
22413 (looking-at org-block-regexp)))
22415 (defun org-point-at-end-of-empty-headline ()
22416 "If point is at the end of an empty headline, return t, else nil.
22417 If the heading only contains a TODO keyword, it is still still considered
22419 (and (looking-at "[ \t]*$")
22420 (when org-todo-line-regexp
22422 (beginning-of-line 1)
22423 (let ((case-fold-search nil))
22424 (looking-at org-todo-line-regexp)
22425 (string= (match-string 3) ""))))))
22427 (defun org-at-heading-or-item-p ()
22428 (or (org-at-heading-p) (org-at-item-p)))
22430 (defun org-at-target-p ()
22431 (or (org-in-regexp org-radio-target-regexp)
22432 (org-in-regexp org-target-regexp)))
22433 ;; Compatibility alias with Org versions < 7.8.03
22434 (defalias 'org-on-target-p 'org-at-target-p)
22436 (defun org-up-heading-all (arg)
22437 "Move to the heading line of which the present line is a subheading.
22438 This function considers both visible and invisible heading lines.
22439 With argument, move up ARG levels."
22440 (if (fboundp 'outline-up-heading-all)
22441 (outline-up-heading-all arg) ; emacs 21 version of outline.el
22442 (outline-up-heading arg t))) ; emacs 22 version of outline.el
22444 (defun org-up-heading-safe ()
22445 "Move to the heading line of which the present line is a subheading.
22446 This version will not throw an error. It will return the level of the
22447 headline found, or nil if no higher level is found.
22449 Also, this function will be a lot faster than `outline-up-heading',
22450 because it relies on stars being the outline starters. This can really
22451 make a significant difference in outlines with very many siblings."
22452 (let (start-level re)
22453 (org-back-to-heading t)
22454 (setq start-level (funcall outline-level))
22455 (if (equal start-level 1)
22457 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
22458 (if (re-search-backward re nil t)
22459 (funcall outline-level)))))
22461 (defun org-first-sibling-p ()
22462 "Is this heading the first child of its parents?"
22464 (let ((re org-outline-regexp-bol)
22466 (unless (org-at-heading-p t)
22467 (error "Not at a heading"))
22468 (setq level (funcall outline-level))
22470 (if (not (re-search-backward re nil t))
22472 (setq l (funcall outline-level))
22475 (defun org-goto-sibling (&optional previous)
22476 "Goto the next sibling, even if it is invisible.
22477 When PREVIOUS is set, go to the previous sibling instead. Returns t
22478 when a sibling was found. When none is found, return nil and don't
22480 (let ((fun (if previous 're-search-backward 're-search-forward))
22482 (re org-outline-regexp-bol)
22484 (when (condition-case nil (org-back-to-heading t) (error nil))
22485 (setq level (funcall outline-level))
22487 (or previous (forward-char 1))
22488 (while (funcall fun re nil t)
22489 (setq l (funcall outline-level))
22490 (when (< l level) (goto-char pos) (throw 'exit nil))
22491 (when (= l level) (goto-char (match-beginning 0)) (throw 'exit t)))
22495 (defun org-show-siblings ()
22496 "Show all siblings of the current headline."
22498 (while (org-goto-sibling) (org-flag-heading nil)))
22500 (while (org-goto-sibling 'previous)
22501 (org-flag-heading nil))))
22503 (defun org-goto-first-child ()
22504 "Goto the first child, even if it is invisible.
22505 Return t when a child was found. Otherwise don't move point and
22507 (let (level (pos (point)) (re org-outline-regexp-bol))
22508 (when (condition-case nil (org-back-to-heading t) (error nil))
22509 (setq level (outline-level))
22511 (if (and (re-search-forward re nil t) (> (outline-level) level))
22512 (progn (goto-char (match-beginning 0)) t)
22513 (goto-char pos) nil))))
22515 (defun org-show-hidden-entry ()
22516 "Show an entry where even the heading is hidden."
22520 (defun org-flag-heading (flag &optional entry)
22521 "Flag the current heading. FLAG non-nil means make invisible.
22522 When ENTRY is non-nil, show the entire entry."
22524 (org-back-to-heading t)
22525 ;; Check if we should show the entire entry
22530 (and (outline-next-heading)
22531 (org-flag-heading nil))))
22532 (outline-flag-region (max (point-min) (1- (point)))
22533 (save-excursion (outline-end-of-heading) (point))
22536 (defun org-get-next-sibling ()
22537 "Move to next heading of the same level, and return point.
22538 If there is no such heading, return nil.
22539 This is like outline-next-sibling, but invisible headings are ok."
22540 (let ((level (funcall outline-level)))
22541 (outline-next-heading)
22542 (while (and (not (eobp)) (> (funcall outline-level) level))
22543 (outline-next-heading))
22544 (if (or (eobp) (< (funcall outline-level) level))
22548 (defun org-get-last-sibling ()
22549 "Move to previous heading of the same level, and return point.
22550 If there is no such heading, return nil."
22551 (let ((opoint (point))
22552 (level (funcall outline-level)))
22553 (outline-previous-heading)
22554 (when (and (/= (point) opoint) (outline-on-heading-p t))
22555 (while (and (> (funcall outline-level) level)
22557 (outline-previous-heading))
22558 (if (< (funcall outline-level) level)
22562 (defun org-end-of-subtree (&optional invisible-ok to-heading)
22563 "Goto to the end of a subtree."
22564 ;; This contains an exact copy of the original function, but it uses
22565 ;; `org-back-to-heading', to make it work also in invisible
22566 ;; trees. And is uses an invisible-ok argument.
22567 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
22568 ;; Furthermore, when used inside Org, finding the end of a large subtree
22569 ;; with many children and grandchildren etc, this can be much faster
22570 ;; than the outline version.
22571 (org-back-to-heading invisible-ok)
22573 (level (funcall outline-level)))
22574 (if (and (derived-mode-p 'org-mode) (< level 1000))
22575 ;; A true heading (not a plain list item), in Org-mode
22576 ;; This means we can easily find the end by looking
22577 ;; only for the right number of stars. Using a regexp to do
22578 ;; this is so much faster than using a Lisp loop.
22579 (let ((re (concat "^\\*\\{1," (int-to-string level) "\\} ")))
22581 (and (re-search-forward re nil 'move) (beginning-of-line 1)))
22582 ;; something else, do it the slow way
22583 (while (and (not (eobp))
22584 (or first (> (funcall outline-level) level)))
22586 (outline-next-heading)))
22588 (if (memq (preceding-char) '(?\n ?\^M))
22590 ;; Go to end of line before heading
22592 (if (memq (preceding-char) '(?\n ?\^M))
22593 ;; leave blank line before heading
22594 (forward-char -1))))))
22597 (defadvice outline-end-of-subtree (around prefer-org-version activate compile)
22598 "Use Org version in org-mode, for dramatic speed-up."
22599 (if (derived-mode-p 'org-mode)
22601 (org-end-of-subtree nil t)
22602 (unless (eobp) (backward-char 1)))
22605 (defun org-end-of-meta-data-and-drawers ()
22606 "Jump to the first text after meta data and drawers in the current entry.
22607 This will move over empty lines, lines with planning time stamps,
22608 clocking lines, and drawers."
22609 (org-back-to-heading t)
22610 (let ((end (save-excursion (outline-next-heading) (point)))
22611 (re (concat "\\(" org-drawer-regexp "\\)"
22612 "\\|" "[ \t]*" org-keyword-time-regexp)))
22614 (while (re-search-forward re end t)
22615 (if (not (match-end 1))
22616 ;; empty or planning line
22618 ;; a drawer, find the end
22619 (re-search-forward "^[ \t]*:END:" end 'move)
22621 (and (re-search-forward "[^\n]" nil t) (backward-char 1))
22624 (defun org-forward-heading-same-level (arg &optional invisible-ok)
22625 "Move forward to the ARG'th subheading at same level as this one.
22626 Stop at the first and last subheadings of a superior heading.
22627 Normally this only looks at visible headings, but when INVISIBLE-OK is
22628 non-nil it will also look at invisible ones."
22630 (if (not (ignore-errors (org-back-to-heading invisible-ok)))
22631 (if (and arg (< arg 0))
22632 (goto-char (point-min))
22633 (outline-next-heading))
22635 (let ((level (- (match-end 0) (match-beginning 0) 1))
22636 (f (if (and arg (< arg 0))
22637 're-search-backward
22638 're-search-forward))
22639 (count (if arg (abs arg) 1))
22641 (forward-char (if (and arg (< arg 0)) -1 1))
22642 (while (and (> count 0)
22643 (funcall f org-outline-regexp-bol nil 'move))
22644 (let ((l (- (match-end 0) (match-beginning 0) 1)))
22645 (cond ((< l level) (setq count 0))
22649 (goto-char (line-beginning-position))
22650 (not (outline-invisible-p)))))
22651 (setq count (1- count))
22653 (setq result (point)))))))
22654 (goto-char result))
22655 (beginning-of-line 1)))
22657 (defun org-backward-heading-same-level (arg &optional invisible-ok)
22658 "Move backward to the ARG'th subheading at same level as this one.
22659 Stop at the first and last subheadings of a superior heading."
22661 (org-forward-heading-same-level (if arg (- arg) -1) invisible-ok))
22663 (defun org-next-block (arg &optional backward block-regexp)
22664 "Jump to the next block.
22665 With a prefix argument ARG, jump forward ARG many source blocks.
22666 When BACKWARD is non-nil, jump to the previous block.
22667 When BLOCK-REGEXP is non-nil, use this regexp to find blocks."
22669 (let ((re (or block-regexp org-block-regexp))
22670 (re-search-fn (or (and backward 're-search-backward)
22671 're-search-forward)))
22672 (if (looking-at re) (forward-char 1))
22673 (condition-case nil
22674 (funcall re-search-fn re nil nil arg)
22675 (error (error "No %s code blocks" (if backward "previous" "further" ))))
22676 (goto-char (match-beginning 0)) (org-show-context)))
22678 (defun org-previous-block (arg &optional block-regexp)
22679 "Jump to the previous block.
22680 With a prefix argument ARG, jump backward ARG many source blocks.
22681 When BLOCK-REGEXP is non-nil, use this regexp to find blocks."
22683 (org-next-block arg t block-regexp))
22685 (defun org-forward-element ()
22686 "Move forward by one element.
22687 Move to the next element at the same level, when possible."
22689 (cond ((eobp) (error "Cannot move further down"))
22690 ((org-with-limited-levels (org-at-heading-p))
22691 (let ((origin (point)))
22692 (goto-char (org-end-of-subtree nil t))
22693 (unless (org-with-limited-levels (org-at-heading-p))
22695 (error "Cannot move further down"))))
22697 (let* ((elem (org-element-at-point))
22698 (end (org-element-property :end elem))
22699 (parent (org-element-property :parent elem)))
22700 (if (and parent (= (org-element-property :contents-end parent) end))
22701 (goto-char (org-element-property :end parent))
22702 (goto-char end))))))
22704 (defun org-backward-element ()
22705 "Move backward by one element.
22706 Move to the previous element at the same level, when possible."
22708 (cond ((bobp) (error "Cannot move further up"))
22709 ((org-with-limited-levels (org-at-heading-p))
22710 ;; At an headline, move to the previous one, if any, or stay
22712 (let ((origin (point)))
22713 (org-with-limited-levels (org-backward-heading-same-level 1))
22714 ;; When current headline has no sibling above, move to its
22716 (when (= (point) origin)
22717 (or (org-with-limited-levels (org-up-heading-safe))
22718 (progn (goto-char origin)
22719 (error "Cannot move further up"))))))
22721 (let* ((trail (org-element-at-point 'keep-trail))
22723 (prev-elem (nth 1 trail))
22724 (beg (org-element-property :begin elem)))
22726 ;; Move to beginning of current element if point isn't
22728 ((/= (point) beg) (goto-char beg))
22729 (prev-elem (goto-char (org-element-property :begin prev-elem)))
22730 ((org-before-first-heading-p) (goto-char (point-min)))
22731 (t (org-back-to-heading)))))))
22733 (defun org-up-element ()
22734 "Move to upper element."
22736 (if (org-with-limited-levels (org-at-heading-p))
22737 (unless (org-up-heading-safe) (error "No surrounding element"))
22738 (let* ((elem (org-element-at-point))
22739 (parent (org-element-property :parent elem)))
22740 (if parent (goto-char (org-element-property :begin parent))
22741 (if (org-with-limited-levels (org-before-first-heading-p))
22742 (error "No surrounding element")
22743 (org-with-limited-levels (org-back-to-heading)))))))
22745 (defvar org-element-greater-elements)
22746 (defun org-down-element ()
22747 "Move to inner element."
22749 (let ((element (org-element-at-point)))
22751 ((memq (org-element-type element) '(plain-list table))
22752 (goto-char (org-element-property :contents-begin element))
22754 ((memq (org-element-type element) org-element-greater-elements)
22755 ;; If contents are hidden, first disclose them.
22756 (when (org-element-property :hiddenp element) (org-cycle))
22757 (goto-char (or (org-element-property :contents-begin element)
22758 (error "No content for this element"))))
22759 (t (error "No inner element")))))
22761 (defun org-drag-element-backward ()
22762 "Move backward element at point."
22764 (if (org-with-limited-levels (org-at-heading-p)) (org-move-subtree-up)
22765 (let* ((trail (org-element-at-point 'keep-trail))
22767 (prev-elem (nth 1 trail)))
22768 ;; Error out if no previous element or previous element is
22769 ;; a parent of the current one.
22770 (if (or (not prev-elem) (org-element-nested-p elem prev-elem))
22771 (error "Cannot drag element backward")
22772 (let ((pos (point)))
22773 (org-element-swap-A-B prev-elem elem)
22774 (goto-char (+ (org-element-property :begin prev-elem)
22775 (- pos (org-element-property :begin elem)))))))))
22777 (defun org-drag-element-forward ()
22778 "Move forward element at point."
22780 (let* ((pos (point))
22781 (elem (org-element-at-point)))
22782 (when (= (point-max) (org-element-property :end elem))
22783 (error "Cannot drag element forward"))
22784 (goto-char (org-element-property :end elem))
22785 (let ((next-elem (org-element-at-point)))
22786 (when (or (org-element-nested-p elem next-elem)
22787 (and (eq (org-element-type next-elem) 'headline)
22788 (not (eq (org-element-type elem) 'headline))))
22790 (error "Cannot drag element forward"))
22791 ;; Compute new position of point: it's shifted by NEXT-ELEM
22792 ;; body's length (without final blanks) and by the length of
22793 ;; blanks between ELEM and NEXT-ELEM.
22794 (let ((size-next (- (save-excursion
22795 (goto-char (org-element-property :end next-elem))
22796 (skip-chars-backward " \r\t\n")
22798 ;; Small correction if buffer doesn't end
22799 ;; with a newline character.
22800 (if (and (eolp) (not (bolp))) (1+ (point)) (point)))
22801 (org-element-property :begin next-elem)))
22802 (size-blank (- (org-element-property :end elem)
22804 (goto-char (org-element-property :end elem))
22805 (skip-chars-backward " \r\t\n")
22808 (org-element-swap-A-B elem next-elem)
22809 (goto-char (+ pos size-next size-blank))))))
22811 (defun org-drag-line-forward (arg)
22812 "Drag the line at point ARG lines forward."
22814 (dotimes (n (abs arg))
22815 (let ((c (current-column)))
22818 (beginning-of-line 2)
22819 (transpose-lines 1)
22820 (beginning-of-line 0))
22821 (transpose-lines 1)
22822 (beginning-of-line -1))
22823 (org-move-to-column c))))
22825 (defun org-drag-line-backward (arg)
22826 "Drag the line at point ARG lines backward."
22828 (org-drag-line-forward (- arg)))
22830 (defun org-mark-element ()
22831 "Put point at beginning of this element, mark at end.
22833 Interactively, if this command is repeated or (in Transient Mark
22834 mode) if the mark is active, it marks the next element after the
22835 ones already marked."
22837 (let (deactivate-mark)
22838 (if (and (org-called-interactively-p 'any)
22839 (or (and (eq last-command this-command) (mark t))
22840 (and transient-mark-mode mark-active)))
22844 (goto-char (org-element-property :end (org-element-at-point)))))
22845 (let ((element (org-element-at-point)))
22847 (push-mark (org-element-property :end element) t t)
22848 (goto-char (org-element-property :begin element))))))
22850 (defun org-narrow-to-element ()
22851 "Narrow buffer to current element."
22853 (let ((elem (org-element-at-point)))
22855 ((eq (car elem) 'headline)
22857 (org-element-property :begin elem)
22858 (org-element-property :end elem)))
22859 ((memq (car elem) org-element-greater-elements)
22861 (org-element-property :contents-begin elem)
22862 (org-element-property :contents-end elem)))
22865 (org-element-property :begin elem)
22866 (org-element-property :end elem))))))
22868 (defun org-transpose-element ()
22869 "Transpose current and previous elements, keeping blank lines between.
22870 Point is moved after both elements."
22872 (org-skip-whitespace)
22873 (let ((end (org-element-property :end (org-element-at-point))))
22874 (org-drag-element-backward)
22877 (defun org-unindent-buffer ()
22878 "Un-indent the visible part of the buffer.
22879 Relative indentation (between items, inside blocks, etc.) isn't
22882 (unless (eq major-mode 'org-mode)
22883 (error "Cannot un-indent a buffer not in Org mode"))
22884 (let* ((parse-tree (org-element-parse-buffer 'greater-element))
22885 unindent-tree ; For byte-compiler.
22891 (if (memq (org-element-type element) '(headline section))
22892 (funcall unindent-tree (org-element-contents element))
22896 (org-element-property :begin element)
22897 (org-element-property :end element))
22898 (org-do-remove-indentation)))))
22899 (reverse contents))))))
22900 (funcall unindent-tree (org-element-contents parse-tree))))
22902 (defun org-show-subtree ()
22903 "Show everything after this heading at deeper levels."
22905 (outline-flag-region
22908 (org-end-of-subtree t t))
22911 (defun org-show-entry ()
22912 "Show the body directly following this heading.
22913 Show the heading too, if it is currently invisible."
22916 (condition-case nil
22918 (org-back-to-heading t)
22919 (outline-flag-region
22920 (max (point-min) (1- (point)))
22922 (if (re-search-forward
22923 (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
22924 (match-beginning 1)
22927 (org-cycle-hide-drawers 'children))
22930 (defun org-make-options-regexp (kwds &optional extra)
22931 "Make a regular expression for keyword lines."
22934 (mapconcat 'regexp-quote kwds "\\|")
22935 (if extra (concat "\\|" extra))
22936 "\\):[ \t]*\\(.*\\)"))
22938 ;; Make isearch reveal the necessary context
22939 (defun org-isearch-end ()
22940 "Reveal context after isearch exits."
22941 (when isearch-success ; only if search was successful
22942 (if (featurep 'xemacs)
22943 ;; Under XEmacs, the hook is run in the correct place,
22944 ;; we directly show the context.
22945 (org-show-context 'isearch)
22946 ;; In Emacs the hook runs *before* restoring the overlays.
22947 ;; So we have to use a one-time post-command-hook to do this.
22948 ;; (Emacs 22 has a special variable, see function `org-mode')
22949 (unless (and (boundp 'isearch-mode-end-hook-quit)
22950 isearch-mode-end-hook-quit)
22951 ;; Only when the isearch was not quitted.
22952 (org-add-hook 'post-command-hook 'org-isearch-post-command
22953 'append 'local)))))
22955 (defun org-isearch-post-command ()
22956 "Remove self from hook, and show context."
22957 (remove-hook 'post-command-hook 'org-isearch-post-command 'local)
22958 (org-show-context 'isearch))
22961 ;;;; Integration with and fixes for other packages
22965 (defvar org-imenu-markers nil
22966 "All markers currently used by Imenu.")
22967 (make-variable-buffer-local 'org-imenu-markers)
22969 (defun org-imenu-new-marker (&optional pos)
22970 "Return a new marker for use by Imenu, and remember the marker."
22971 (let ((m (make-marker)))
22972 (move-marker m (or pos (point)))
22973 (push m org-imenu-markers)
22976 (defun org-imenu-get-tree ()
22977 "Produce the index for Imenu."
22978 (mapc (lambda (x) (move-marker x nil)) org-imenu-markers)
22979 (setq org-imenu-markers nil)
22980 (let* ((n org-imenu-depth)
22981 (re (concat "^" (org-get-limited-outline-regexp)))
22982 (subs (make-vector (1+ n) nil))
22988 (goto-char (point-max))
22989 (while (re-search-backward re nil t)
22990 (setq level (org-reduced-level (funcall outline-level)))
22991 (when (and (<= level n)
22992 (looking-at org-complex-heading-regexp))
22993 (setq head (org-link-display-format
22994 (org-match-string-no-properties 4))
22995 m (org-imenu-new-marker))
22996 (org-add-props head nil 'org-imenu-marker m 'org-imenu t)
22997 (if (>= level last-level)
22998 (push (cons head m) (aref subs level))
22999 (push (cons head (aref subs (1+ level))) (aref subs level))
23000 (loop for i from (1+ level) to n do (aset subs i nil)))
23001 (setq last-level level)))))
23004 (eval-after-load "imenu"
23006 (add-hook 'imenu-after-jump-hook
23008 (if (derived-mode-p 'org-mode)
23009 (org-show-context 'org-goto))))))
23011 (defun org-link-display-format (link)
23012 "Replace a link with either the description, or the link target
23013 if no description is present"
23015 (if (string-match org-bracket-link-analytic-regexp link)
23016 (replace-match (if (match-end 5)
23017 (match-string 5 link)
23018 (concat (match-string 1 link)
23019 (match-string 3 link)))
23023 (defun org-toggle-link-display ()
23024 "Toggle the literal or descriptive display of links."
23026 (if org-descriptive-links
23027 (progn (org-remove-from-invisibility-spec '(org-link))
23028 (org-restart-font-lock)
23029 (setq org-descriptive-links nil))
23030 (progn (add-to-invisibility-spec '(org-link))
23031 (org-restart-font-lock)
23032 (setq org-descriptive-links t))))
23034 ;; Speedbar support
23036 (defvar org-speedbar-restriction-lock-overlay (make-overlay 1 1)
23037 "Overlay marking the agenda restriction line in speedbar.")
23038 (overlay-put org-speedbar-restriction-lock-overlay
23039 'face 'org-agenda-restriction-lock)
23040 (overlay-put org-speedbar-restriction-lock-overlay
23041 'help-echo "Agendas are currently limited to this item.")
23042 (org-detach-overlay org-speedbar-restriction-lock-overlay)
23044 (defun org-speedbar-set-agenda-restriction ()
23045 "Restrict future agenda commands to the location at point in speedbar.
23046 To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
23048 (require 'org-agenda)
23049 (let (p m tp np dir txt)
23051 ((setq p (text-property-any (point-at-bol) (point-at-eol)
23053 (setq m (get-text-property p 'org-imenu-marker))
23054 (with-current-buffer (marker-buffer m)
23056 (org-agenda-set-restriction-lock 'subtree)))
23057 ((setq p (text-property-any (point-at-bol) (point-at-eol)
23058 'speedbar-function 'speedbar-find-file))
23059 (setq tp (previous-single-property-change
23060 (1+ p) 'speedbar-function)
23061 np (next-single-property-change
23062 tp 'speedbar-function)
23063 dir (speedbar-line-directory)
23064 txt (buffer-substring-no-properties (or tp (point-min))
23065 (or np (point-max))))
23066 (with-current-buffer (find-file-noselect
23067 (let ((default-directory dir))
23068 (expand-file-name txt)))
23069 (unless (derived-mode-p 'org-mode)
23070 (error "Cannot restrict to non-Org-mode file"))
23071 (org-agenda-set-restriction-lock 'file)))
23072 (t (error "Don't know how to restrict Org-mode's agenda")))
23073 (move-overlay org-speedbar-restriction-lock-overlay
23074 (point-at-bol) (point-at-eol))
23075 (setq current-prefix-arg nil)
23076 (org-agenda-maybe-redo)))
23078 (eval-after-load "speedbar"
23080 (speedbar-add-supported-extension ".org")
23081 (define-key speedbar-file-key-map "<" 'org-speedbar-set-agenda-restriction)
23082 (define-key speedbar-file-key-map "\C-c\C-x<" 'org-speedbar-set-agenda-restriction)
23083 (define-key speedbar-file-key-map ">" 'org-agenda-remove-restriction-lock)
23084 (define-key speedbar-file-key-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
23085 (add-hook 'speedbar-visiting-tag-hook
23086 (lambda () (and (derived-mode-p 'org-mode) (org-show-context 'org-goto))))))
23088 ;;; Fixes and Hacks for problems with other packages
23090 ;; Make flyspell not check words in links, to not mess up our keymap
23091 (defvar org-element-affiliated-keywords) ; From org-element.el
23092 (defvar org-element-block-name-alist) ; From org-element.el
23093 (defun org-mode-flyspell-verify ()
23094 "Don't let flyspell put overlays at active buttons, or on
23095 {todo,all-time,additional-option-like}-keywords."
23096 (let ((pos (max (1- (point)) (point-min)))
23097 (word (thing-at-point 'word)))
23098 (and (not (get-text-property pos 'keymap))
23099 (not (get-text-property pos 'org-no-flyspell))
23100 (not (member word org-todo-keywords-1))
23101 (not (member word org-all-time-keywords))
23102 (not (member word org-options-keywords))
23103 (not (member word (mapcar 'car org-startup-options)))
23104 (not (member-ignore-case word org-element-affiliated-keywords))
23105 (not (member-ignore-case word (org-get-export-keywords)))
23106 (not (member-ignore-case
23107 word (mapcar 'car org-element-block-name-alist)))
23108 (not (member-ignore-case word '("BEGIN" "END" "ATTR"))))))
23110 (defun org-remove-flyspell-overlays-in (beg end)
23111 "Remove flyspell overlays in region."
23112 (and (org-bound-and-true-p flyspell-mode)
23113 (fboundp 'flyspell-delete-region-overlays)
23114 (flyspell-delete-region-overlays beg end))
23115 (add-text-properties beg end '(org-no-flyspell t)))
23117 ;; Make `bookmark-jump' shows the jump location if it was hidden.
23118 (eval-after-load "bookmark"
23119 '(if (boundp 'bookmark-after-jump-hook)
23120 ;; We can use the hook
23121 (add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)
23122 ;; Hook not available, use advice
23123 (defadvice bookmark-jump (after org-make-visible activate)
23124 "Make the position visible."
23125 (org-bookmark-jump-unhide))))
23127 ;; Make sure saveplace shows the location if it was hidden
23128 (eval-after-load "saveplace"
23129 '(defadvice save-place-find-file-hook (after org-make-visible activate)
23130 "Make the position visible."
23131 (org-bookmark-jump-unhide)))
23133 ;; Make sure ecb shows the location if it was hidden
23134 (eval-after-load "ecb"
23135 '(defadvice ecb-method-clicked (after esf/org-show-context activate)
23136 "Make hierarchy visible when jumping into location from ECB tree buffer."
23137 (if (derived-mode-p 'org-mode)
23138 (org-show-context))))
23140 (defun org-bookmark-jump-unhide ()
23141 "Unhide the current position, to show the bookmark location."
23142 (and (derived-mode-p 'org-mode)
23143 (or (outline-invisible-p)
23144 (save-excursion (goto-char (max (point-min) (1- (point))))
23145 (outline-invisible-p)))
23146 (org-show-context 'bookmark-jump)))
23148 ;; Make session.el ignore our circular variable
23149 (eval-after-load "session"
23150 '(add-to-list 'session-globals-exclude 'org-mark-ring))
23152 ;;;; Experimental code
23154 (defun org-closed-in-range ()
23155 "Sparse tree of items closed in a certain time range.
23156 Still experimental, may disappear in the future."
23158 ;; Get the time interval from the user.
23159 (let* ((time1 (org-float-time
23160 (org-read-date nil 'to-time nil "Starting date: ")))
23161 (time2 (org-float-time
23162 (org-read-date nil 'to-time nil "End date:")))
23163 ;; callback function
23164 (callback (lambda ()
23167 (apply 'encode-time
23168 (org-parse-time-string
23169 (match-string 1))))))
23170 ;; check if time in interval
23171 (and (>= time time1) (<= time time2))))))
23172 ;; make tree, check each match with the callback
23173 (org-occur "CLOSED: +\\[\\(.*?\\)\\]" nil callback)))
23179 (run-hooks 'org-load-hook)
23181 ;;; org.el ends here