1 ;;; org.el --- Outline-based notes management and organize
2 ;; Carstens outline-mode for keeping track of everything.
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing
31 ;; project planning with a fast and effective plain-text system.
33 ;; Org-mode develops organizational tasks around NOTES files that contain
34 ;; information about projects as plain text. Org-mode is implemented on
35 ;; top of outline-mode, which makes it possible to keep the content of
36 ;; large files well structured. Visibility cycling and structure editing
37 ;; help to work with the tree. Tables are easily created with a built-in
38 ;; table editor. Org-mode supports ToDo items, deadlines, time stamps,
39 ;; and scheduling. It dynamically compiles entries into an agenda that
40 ;; utilizes and smoothly integrates much of the Emacs calendar and diary.
41 ;; Plain text URL-like links connect to websites, emails, Usenet
42 ;; messages, BBDB entries, and any files related to the projects. For
43 ;; printing and sharing of notes, an Org-mode file can be exported as a
44 ;; structured ASCII file, as HTML, or (todo and agenda items only) as an
45 ;; iCalendar file. It can also serve as a publishing tool for a set of
51 ;; If Org-mode is part of the Emacs distribution or an XEmacs package, you
52 ;; only need to copy the following lines to your .emacs file. The last two
53 ;; lines define *global* keys for the commands `org-store-link' and
54 ;; `org-agenda' - please choose suitable keys yourself.
56 ;; (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
57 ;; (define-key global-map "\C-cl" 'org-store-link)
58 ;; (define-key global-map "\C-ca" 'org-agenda)
60 ;; Furthermore you need to activate font-lock-mode in org-mode buffers.
61 ;; either of the following two lins will do the trick:
63 ;; (global-font-lock-mode 1) ; for all buffers
64 ;; (add-hook 'org-mode-hook 'turn-on-font-lock) ; org-mode buffers only
66 ;; If you have downloaded Org-mode from the Web, you have to take additional
67 ;; action: Byte-compile org.el and org-publish.el and put them together with
68 ;; org-install.el on your load path. Then also add to your .emacs file:
70 ;; (require 'org-install)
75 ;; The setup above will put all files with extension ".org" into Org-mode.
76 ;; As an alternative, make the first line of a file look like this:
78 ;; MY PROJECTS -*- mode: org; -*-
80 ;; which will select Org-mode for this buffer no matter what the file's
85 ;; The documentation of Org-mode can be found in the TeXInfo file. The
86 ;; distribution also contains a PDF version of it. At the homepage of
87 ;; Org-mode, you can read the same text online as HTML. There is also an
88 ;; excellent reference card made by Philip Rooke. This card can be found
89 ;; in the etc/ directory of Emacs 22.
98 ;; - `s' key in the agenda saves all org-mode buffers.
101 ;; - Shift-curser keys can modify inactive time stamps (inactive time
102 ;; stamps are the ones in [...] brackets.
103 ;; - Toggle all checkboxes in a region/below a headline.
110 ;; - Special tag ARCHIVE keeps a subtree closed and away from agenda lists.
111 ;; - LaTeX code in Org-mode files can be converted to images for HTML.
113 ;; - CDLaTeX-mode features can be used in Org-mode to help inserting
114 ;; LaTeX environment and math.
117 ;; - noutline.el is now required (important for XEmacs users only).
119 ;; - Archiving of all level 1 trees without open TODO items.
120 ;; - Clock reports can be inserted into the file in a special section.
121 ;; - FAQ removed from the manual, now only on the web.
125 ;; - Clock-feature for measuring time spent on specific items.
126 ;; - Improved emphasizing allows configuration and stacking.
129 ;; - Improved indentation of ASCII export, when headlines become items.
130 ;; - Handling of 12am and 12pm fixed. Times beyond 24:00 can be used
131 ;; and will not lead to conflicts.
132 ;; - Support for mutually exclusive TAGS with the fast tags interface.
136 ;; - HTML export is now valid XHTML.
137 ;; - Timeline can also show dates without entries. See new option
138 ;; `org-timeline-show-empty-dates'.
139 ;; - The bullets created by the ASCII exporter can now be configured.
140 ;; See the new option `org-export-ascii-bullets'.
141 ;; - New face `org-upcoming-deadline' (was `org-scheduled-previously').
142 ;; - New function `org-context' to allow testing for local context.
148 ;; - New commands to move through plain lists: S-up and S-down.
149 ;; - Bug fixes and documentation update.
152 ;; - Fast (single-key-per-tag) interface for setting TAGS.
153 ;; - The list of legal tags can be configured globally and locally.
154 ;; - Elisp and Info links (thanks to Todd Neal).
155 ;; - `org-export-publishing-directory' can be an alist, with different
156 ;; directories for different export types.
157 ;; - All context-sensitive commands use `call-interactively' to dispatch.
158 ;; - `org-confirm-shell-links' renamed to `org-confirm-shell-link-function'.
165 ;; - Modified installation: Autoloads have been collected in org-install.el.
166 ;; - Logging (org-log-done) is now a #+STARTUP option.
167 ;; - Checkboxes in plain list items, following up on Frank Ruell's idea.
168 ;; - File links inserted with C-c C-l will use relative paths if the linked
169 ;; file is in the current directory or a subdirectory of it.
170 ;; - New variable `org-link-file-path-type' to specify preference for
171 ;; relative and absolute paths.
172 ;; - New CSS classes for tags, timestamps, timestamp keywords.
173 ;; - Bug and typo fixes.
176 ;; - Inlining images in HTML export now depends on wheather the link
177 ;; contains a description or not.
178 ;; - TODO items can be scheduled from the global TODO list using C-c C-s.
179 ;; - TODO items already scheduled can be made to disappear from the global
180 ;; todo list, see `org-agenda-todo-ignore-scheduled'.
181 ;; - In Tables, formulas may also be Lisp forms.
182 ;; - Exporting the visible part of an outline with `C-c C-x v' works now
183 ;; for all available exporters.
184 ;; - Bug fixes, lots of them :-(
190 ;; - HTML exporter generalized to receive external options.
191 ;; As part of the process, author, email and date have been moved to the
192 ;; end of the HTML file.
193 ;; - Support for customizable file search in file links.
194 ;; - BibTeX database links as first application of the above.
195 ;; - New option `org-agenda-todo-list-sublevels' to turn off listing TODO
196 ;; entries that are sublevels of another TODO entry.
204 ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for
205 ;; the file noutline.el being loaded.
206 (if (featurep 'xemacs
) (condition-case nil
(require 'noutline
)))
207 ;; We require noutline, which might be provided in outline.el
208 (require 'outline
) (require 'noutline
)
209 ;; Other stuff we need.
213 ;;; Customization variables
215 (defvar org-version
"4.43"
216 "The version number of the file org.el.")
217 (defun org-version ()
219 (message "Org-mode version %s" org-version
))
221 ;; The following constant is for compatibility with different versions
223 (defconst org-noutline-p
(featurep 'noutline
)
224 "Are we using the new outline mode?")
225 (defconst org-xemacs-p
(featurep 'xemacs
)) ; not used by org.el itself
226 (defconst org-format-transports-properties-p
228 (add-text-properties 0 1 '(test t
) x
)
229 (get-text-property 0 'test
(format "%s" x
)))
230 "Does format transport text properties?")
233 "Outline-based notes management and organizer."
239 (defgroup org-startup nil
240 "Options concerning startup of Org-mode."
244 (defcustom org-startup-folded t
245 "Non-nil means, entering Org-mode will switch to OVERVIEW.
246 This can also be configured on a per-file basis by adding one of
247 the following lines anywhere in the buffer:
254 (const :tag
"nofold: show all" nil
)
255 (const :tag
"fold: overview" t
)
256 (const :tag
"content: all headlines" content
)))
258 (defcustom org-startup-truncated t
259 "Non-nil means, entering Org-mode will set `truncate-lines'.
260 This is useful since some lines containing links can be very long and
261 uninteresting. Also tables look terrible when wrapped."
265 (defcustom org-startup-align-all-tables nil
266 "Non-nil means, align all tables when visiting a file.
267 This is useful when the column width in tables is forced with <N> cookies
268 in table fields. Such tables will look correct only after the first re-align.
269 This can also be configured on a per-file basis by adding one of
270 the following lines anywhere in the buffer:
276 (defcustom org-startup-with-deadline-check nil
277 "Non-nil means, entering Org-mode will run the deadline check.
278 This means, if you start editing an org file, you will get an
279 immediate reminder of any due deadlines.
280 This can also be configured on a per-file basis by adding one of
281 the following lines anywhere in the buffer:
283 #+STARTUP: nodlcheck"
287 (defcustom org-insert-mode-line-in-empty-file nil
288 "Non-nil means insert the first line setting Org-mode in empty files.
289 When the function `org-mode' is called interactively in an empty file, this
290 normally means that the file name does not automatically trigger Org-mode.
291 To ensure that the file will always be in Org-mode in the future, a
292 line enforcing Org-mode will be inserted into the buffer, if this option
297 (defcustom org-CUA-compatible nil
298 "Non-nil means use alternative key bindings for S-<cursor movement>.
299 Org-mode used S-<cursor movement> for changing timestamps and priorities.
300 S-<cursor movement> is also used for example by `CUA-mode' to select text.
301 If you want to use Org-mode together with `CUA-mode', Org-mode needs to use
302 alternative bindings. Setting this variable to t will replace the following
303 keys both in Org-mode and in the Org-agenda buffer.
311 If you do not like the alternative keys, take a look at the variable
314 This option is only relevant at load-time of Org-mode. Changing it requires
315 a restart of Emacs to become effective."
319 (defvar org-disputed-keys
320 '((S-up [(shift up
)] [(meta ?p
)])
321 (S-down [(shift down
)] [(meta ?n
)])
322 (S-left [(shift left
)] [(meta ?-
)])
323 (S-right [(shift right
)] [(meta ?
+)])
324 (S-return [(shift return
)] [(control shift return
)]))
325 "Keys for which Org-mode and other modes compete.
326 This is an alist, cars are symbols for lookup, 1st element is the default key,
327 second element will be used when `org-CUA-compatible' is t.")
330 "Select a key according to `org-CUA-compatible'."
331 (nth (if org-CUA-compatible
2 1)
332 (or (assq key org-disputed-keys
)
333 (error "Invalid Key %s in `org-key'" key
))))
335 (defcustom org-ellipsis nil
336 "The ellipsis to use in the Org-mode outline.
337 When nil, just use the standard three dots. When a string, use that instead,
338 and just in Org-mode (which will then use its own display table).
339 Changing this requires executing `M-x org-mode' in a buffer to become
342 :type
'(choice (const :tag
"Default" nil
)
343 (string :tag
"String" :value
"...#")))
345 (defvar org-display-table nil
346 "The display table for org-mode, in case `org-ellipsis' is non-nil.")
348 (defgroup org-keywords nil
349 "Keywords in Org-mode."
353 (defcustom org-deadline-string
"DEADLINE:"
354 "String to mark deadline entries.
355 A deadline is this string, followed by a time stamp. Should be a word,
356 terminated by a colon. You can insert a schedule keyword and
357 a timestamp with \\[org-deadline].
358 Changes become only effective after restarting Emacs."
362 (defcustom org-scheduled-string
"SCHEDULED:"
363 "String to mark scheduled TODO entries.
364 A schedule is this string, followed by a time stamp. Should be a word,
365 terminated by a colon. You can insert a schedule keyword and
366 a timestamp with \\[org-schedule].
367 Changes become only effective after restarting Emacs."
371 (defcustom org-closed-string
"CLOSED:"
372 "String used as the prefix for timestamps logging closing a TODO entry."
376 (defcustom org-clock-string
"CLOCK:"
377 "String used as prefix for timestamps clocking work hours on an item."
381 (defcustom org-comment-string
"COMMENT"
382 "Entries starting with this keyword will never be exported.
383 An entry can be toggled between COMMENT and normal with
384 \\[org-toggle-comment].
385 Changes become only effective after restarting Emacs."
389 (defcustom org-quote-string
"QUOTE"
390 "Entries starting with this keyword will be exported in fixed-width font.
391 Quoting applies only to the text in the entry following the headline, and does
392 not extend beyond the next headline, even if that is lower level.
393 An entry can be toggled between QUOTE and normal with
394 \\[org-toggle-fixed-width-section]."
398 (defgroup org-structure nil
399 "Options concerning the general structure of Org-mode files."
403 (defgroup org-cycle nil
404 "Options concerning visibility cycling in Org-mode."
406 :group
'org-structure
)
408 (defcustom org-cycle-global-at-bob t
409 "Cycle globally if cursor is at beginning of buffer and not at a headline.
410 This makes it possible to do global cycling without having to use S-TAB or
411 C-u TAB. For this special case to work, the first line of the buffer
412 must not be a headline - it may be empty ot some other text. When used in
413 this way, `org-cycle-hook' is disables temporarily, to make sure the
414 cursor stays at the beginning of the buffer.
415 When this option is nil, don't do anything special at the beginning
420 (defcustom org-cycle-emulate-tab t
421 "Where should `org-cycle' emulate TAB.
423 white Only in completely white lines
424 whitestart Only at the beginning of lines, before the first non-white char.
425 t Everywhere except in headlines
426 If TAB is used in a place where it does not emulate TAB, the current subtree
427 visibility is cycled."
429 :type
'(choice (const :tag
"Never" nil
)
430 (const :tag
"Only in completely white lines" white
)
431 (const :tag
"Before first char in a line" whitestart
)
432 (const :tag
"Everywhere except in headlines" t
)
435 (defcustom org-cycle-hook
'(org-cycle-hide-archived-subtrees
436 org-optimize-window-after-visibility-change
)
437 "Hook that is run after `org-cycle' has changed the buffer visibility.
438 The function(s) in this hook must accept a single argument which indicates
439 the new state that was set by the most recent `org-cycle' command. The
440 argument is a symbol. After a global state change, it can have the values
441 `overview', `content', or `all'. After a local state change, it can have
442 the values `folded', `children', or `subtree'."
446 (defgroup org-edit-structure nil
447 "Options concerning structure editing in Org-mode."
448 :tag
"Org Edit Structure"
449 :group
'org-structure
)
451 (defcustom org-odd-levels-only nil
452 "Non-nil means, skip even levels and only use odd levels for the outline.
453 This has the effect that two stars are being added/taken away in
454 promotion/demotion commands. It also influences how levels are
455 handled by the exporters.
456 Changing it requires restart of `font-lock-mode' to become effective
457 for fontification also in regions already fontified.
458 You may also set this on a per-file basis by adding one of the following
463 :group
'org-edit-structure
464 :group
'org-font-lock
467 (defcustom org-adapt-indentation t
468 "Non-nil means, adapt indentation when promoting and demoting.
469 When this is set and the *entire* text in an entry is indented, the
470 indentation is increased by one space in a demotion command, and
471 decreased by one in a promotion command. If any line in the entry
472 body starts at column 0, indentation is not changed at all."
473 :group
'org-edit-structure
476 (defcustom org-insert-heading-hook nil
477 "Hook being run after inserting a new heading."
478 :group
'org-edit-structure
481 (defcustom org-enable-fixed-width-editor t
482 "Non-nil means, lines starting with \":\" are treated as fixed-width.
483 This currently only means, they are never auto-wrapped.
484 When nil, such lines will be treated like ordinary lines.
485 See also the QUOTE keyword."
486 :group
'org-edit-structure
489 (defgroup org-sparse-trees nil
490 "Options concerning sparse trees in Org-mode."
491 :tag
"Org Sparse Trees"
492 :group
'org-structure
)
494 (defcustom org-highlight-sparse-tree-matches t
495 "Non-nil means, highlight all matches that define a sparse tree.
496 The highlights will automatically disappear the next time the buffer is
497 changed by an edit command."
498 :group
'org-sparse-trees
501 (defcustom org-show-hierarchy-above t
502 "Non-nil means, show full hierarchy when showing a spot in the tree.
503 Turning this off makes sparse trees more compact, but also less clear."
504 :group
'org-sparse-trees
507 (defcustom org-show-following-heading t
508 "Non-nil means, show heading following match in `org-occur'.
509 When doing an `org-occur' it is useful to show the headline which
510 follows the match, even if they do not match the regexp. This makes it
511 easier to edit directly inside the sparse tree. However, if you use
512 `org-occur' mainly as an overview, the following headlines are
513 unnecessary clutter."
514 :group
'org-sparse-trees
517 (defcustom org-occur-hook
'(org-first-headline-recenter)
518 "Hook that is run after `org-occur' has constructed a sparse tree.
519 This can be used to recenter the window to show as much of the structure
521 :group
'org-sparse-trees
524 (defgroup org-plain-lists nil
525 "Options concerning plain lists in Org-mode."
526 :tag
"Org Plain lists"
527 :group
'org-structure
)
529 (defcustom org-cycle-include-plain-lists nil
530 "Non-nil means, include plain lists into visibility cycling.
531 This means that during cycling, plain list items will *temporarily* be
532 interpreted as outline headlines with a level given by 1000+i where i is the
533 indentation of the bullet. In all other operations, plain list items are
534 not seen as headlines. For example, you cannot assign a TODO keyword to
536 :group
'org-plain-lists
540 (defcustom org-plain-list-ordered-item-terminator t
541 "The character that makes a line with leading number an ordered list item.
542 Valid values are ?. and ?\). To get both terminators, use t. While
543 ?. may look nicer, it creates the danger that a line with leading
544 number may be incorrectly interpreted as an item. ?\) therefore is
546 :group
'org-plain-lists
547 :type
'(choice (const :tag
"dot like in \"2.\"" ?.
)
548 (const :tag
"paren like in \"2)\"" ?\
))
549 (const :tab
"both" t
)))
551 (defcustom org-auto-renumber-ordered-lists t
552 "Non-nil means, automatically renumber ordered plain lists.
553 Renumbering happens when the sequence have been changed with
554 \\[org-shiftmetaup] or \\[org-shiftmetadown]. After other editing commands,
555 use \\[org-ctrl-c-ctrl-c] to trigger renumbering."
556 :group
'org-plain-lists
559 (defgroup org-archive nil
560 "Options concerning archiving in Org-mode."
562 :group
'org-structure
)
564 (defcustom org-archive-tag
"ARCHIVE"
565 "The tag that marks a subtree as archived.
566 An archived subtree does not open during visibility cycling, and does
567 not contribute to the agenda listings."
572 (defcustom org-agenda-skip-archived-trees t
573 "Non-nil means, the agenda will skip any items located in archived trees.
574 An archived tree is a tree marked with the tag ARCHIVE."
576 :group
'org-agenda-display
579 (defcustom org-cycle-open-archived-trees nil
580 "Non-nil means, `org-cycle' will open archived trees.
581 An archived tree is a tree marked with the tag ARCHIVE.
582 When nil, archived trees will stay folded. You can still open them with
583 normal outline commands like `show-all', but not with the cycling commands."
588 (defcustom org-sparse-tree-open-archived-trees nil
589 "Non-nil means sparse tree construction shows matches in archived trees.
590 When nil, matches in these trees are highlighted, but the trees are kept in
593 :group
'org-sparse-trees
596 (defcustom org-archive-location
"%s_archive::"
597 "The location where subtrees should be archived.
598 This string consists of two parts, separated by a double-colon.
600 The first part is a file name - when omitted, archiving happens in the same
601 file. %s will be replaced by the current file name (without directory part).
602 Archiving to a different file is useful to keep archived entries from
603 contributing to the Org-mode Agenda.
605 The part after the double colon is a headline. The archived entries will be
606 filed under that headline. When omitted, the subtrees are simply filed away
607 at the end of the file, as top-level entries.
609 Here are a few examples:
611 If the current file is Projects.org, archive in file
612 Projects.org_archive, as top-level trees. This is the default.
614 \"::* Archived Tasks\"
615 Archive in the current file, under the top-level headline
616 \"* Archived Tasks\".
618 \"~/org/archive.org::\"
619 Archive in file ~/org/archive.org (absolute path), as top-level trees.
621 \"basement::** Finished Tasks\"
622 Archive in file ./basement (relative path), as level 3 trees
623 below the level 2 heading \"** Finished Tasks\".
625 You may set this option on a per-file basis by adding to the buffer a
628 #+ARCHIVE: basement::** Finished Tasks"
632 (defcustom org-archive-mark-done t
633 "Non-nil means, mark entries as DONE when they are moved to the archive file."
637 (defcustom org-archive-stamp-time t
638 "Non-nil means, add a time stamp to entries moved to an archive file.
639 The time stamp will be added directly after the TODO state keyword in the
640 first line, so it is probably best to use this in combinations with
641 `org-archive-mark-done'."
645 (defgroup org-table nil
646 "Options concerning tables in Org-mode."
650 (defcustom org-enable-table-editor
'optimized
651 "Non-nil means, lines starting with \"|\" are handled by the table editor.
652 When nil, such lines will be treated like ordinary lines.
654 When equal to the symbol `optimized', the table editor will be optimized to
656 - Use automatic overwrite mode in front of whitespace in table fields.
657 This make the structure of the table stay in tact as long as the edited
658 field does not exceed the column width.
659 - Minimize the number of realigns. Normally, the table is aligned each time
660 TAB or RET are pressed to move to another field. With optimization this
661 happens only if changes to a field might have changed the column width.
662 Optimization requires replacing the functions `self-insert-command',
663 `delete-char', and `backward-delete-char' in Org-mode buffers, with a
664 slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is
665 very good at guessing when a re-align will be necessary, but you can always
666 force one with \\[org-ctrl-c-ctrl-c].
668 If you would like to use the optimized version in Org-mode, but the
669 un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'.
671 This variable can be used to turn on and off the table editor during a session,
672 but in order to toggle optimization, a restart is required.
674 See also the variable `org-table-auto-blank-field'."
677 (const :tag
"off" nil
)
679 (const :tag
"on, optimized" optimized
)))
681 (defcustom orgtbl-optimized
(eq org-enable-table-editor
'optimized
)
682 "Non-nil means, use the optimized table editor version for `orgtbl-mode'.
683 In the optimized version, the table editor takes over all simple keys that
684 normally just insert a character. In tables, the characters are inserted
685 in a way to minimize disturbing the table structure (i.e. in overwrite mode
686 for empty fields). Outside tables, the correct binding of the keys is
689 The default for this option is t if the optimized version is also used in
690 Org-mode. See the variable `org-enable-table-editor' for details. Changing
691 this variable requires a restart of Emacs to become effective."
695 (defgroup org-table-settings nil
696 "Settings for tables in Org-mode."
697 :tag
"Org Table Settings"
700 (defcustom org-table-default-size
"5x2"
701 "The default size for newly created tables, Columns x Rows."
702 :group
'org-table-settings
705 (defcustom org-table-number-regexp
"^[<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%]*$"
706 "Regular expression for recognizing numbers in table columns.
707 If a table column contains mostly numbers, it will be aligned to the
708 right. If not, it will be aligned to the left.
710 The default value of this option is a regular expression which allows
711 anything which looks remotely like a number as used in scientific
712 context. For example, all of the following will be considered a
714 12 12.2 2.4e-08 2x10^12 4.034+-0.02 2.7(10) >3.5
716 Other options offered by the customize interface are more restrictive."
717 :group
'org-table-settings
719 (const :tag
"Positive Integers"
721 (const :tag
"Integers"
723 (const :tag
"Floating Point Numbers"
724 "^[-+]?\\([0-9]*\\.[0-9]+\\|[0-9]+\\.[0-9]*\\)$")
725 (const :tag
"Floating Point Number or Integer"
726 "^[-+]?\\([0-9]*\\.[0-9]+\\|[0-9]+\\.?[0-9]*\\)$")
727 (const :tag
"Exponential, Floating point, Integer"
728 "^[-+]?[0-9.]+\\([eEdD][-+0-9]+\\)?$")
729 (const :tag
"Very General Number-Like"
730 "^[<>]?[-+^.0-9]*[0-9][-+^.0-9eEdDx()%]*$")
731 (string :tag
"Regexp:")))
733 (defcustom org-table-number-fraction
0.5
734 "Fraction of numbers in a column required to make the column align right.
735 In a column all non-white fields are considered. If at least this
736 fraction of fields is matched by `org-table-number-fraction',
737 alignment to the right border applies."
738 :group
'org-table-settings
741 (defgroup org-table-editing nil
742 "Bahavior of tables during editing in Org-mode."
743 :tag
"Org Table Editing"
746 (defcustom org-table-automatic-realign t
747 "Non-nil means, automatically re-align table when pressing TAB or RETURN.
748 When nil, aligning is only done with \\[org-table-align], or after column
750 :group
'org-table-editing
753 (defcustom org-table-limit-column-width t
;kw
754 "Non-nil means, allow to limit the width of table columns with <N> fields."
755 :group
'org-table-editing
758 (defcustom org-table-auto-blank-field t
759 "Non-nil means, automatically blank table field when starting to type into it.
760 This only happens when typing immediately after a field motion
761 command (TAB, S-TAB or RET).
762 Only relevant when `org-enable-table-editor' is equal to `optimized'."
763 :group
'org-table-editing
766 (defcustom org-table-tab-jumps-over-hlines t
767 "Non-nil means, tab in the last column of a table with jump over a hline.
768 If a horizontal separator line is following the current line,
769 `org-table-next-field' can either create a new row before that line, or jump
770 over the line. When this option is nil, a new line will be created before
772 :group
'org-table-editing
775 (defcustom org-table-tab-recognizes-table.el t
776 "Non-nil means, TAB will automatically notice a table.el table.
777 When it sees such a table, it moves point into it and - if necessary -
778 calls `table-recognize-table'."
779 :group
'org-table-editing
782 (defgroup org-table-calculation nil
783 "Options concerning tables in Org-mode."
784 :tag
"Org Table Calculation"
787 (defcustom org-table-copy-increment t
788 "Non-nil means, increment when copying current field with \\[org-table-copy-down]."
789 :group
'org-table-calculation
792 (defcustom org-calc-default-modes
793 '(calc-internal-prec 12
794 calc-float-format
(float 5)
797 calc-symbolic-mode nil
798 calc-date-format
(YYYY "-" MM
"-" DD
" " Www
(" " HH
":" mm
))
799 calc-display-working-message t
801 "List with Calc mode settings for use in calc-eval for table formulas.
802 The list must contain alternating symbols (Calc modes variables and values).
803 Don't remove any of the default settings, just change the values. Org-mode
804 relies on the variables to be present in the list."
805 :group
'org-table-calculation
808 (defcustom org-table-formula-evaluate-inline t
809 "Non-nil means, TAB and RET evaluate a formula in current table field.
810 If the current field starts with an equal sign, it is assumed to be a formula
811 which should be evaluated as described in the manual and in the documentation
812 string of the command `org-table-eval-formula'. This feature requires the
814 When this variable is nil, formula calculation is only available through
815 the command \\[org-table-eval-formula]."
816 :group
'org-table-calculation
820 (defcustom org-table-formula-use-constants t
821 "Non-nil means, interpret constants in formulas in tables.
822 A constant looks like `$c' or `$Grav' and will be replaced before evaluation
823 by the value given in `org-table-formula-constants', or by a value obtained
824 from the `constants.el' package."
825 :group
'org-table-calculation
828 (defcustom org-table-formula-constants nil
829 "Alist with constant names and values, for use in table formulas.
830 The car of each element is a name of a constant, without the `$' before it.
831 The cdr is the value as a string. For example, if you'd like to use the
832 speed of light in a formula, you would configure
834 (setq org-table-formula-constants '((\"c\" . \"299792458.\")))
836 and then use it in an equation like `$1*$c'."
837 :group
'org-table-calculation
839 (cons (string :tag
"name")
840 (string :tag
"value"))))
842 (defcustom org-table-formula-numbers-only nil
843 "Non-nil means, calculate only with numbers in table formulas.
844 Then all input fields will be converted to a number, and the result
845 must also be a number. When nil, calc's full potential is available
846 in table calculations, including symbolics etc."
847 :group
'org-table-calculation
850 (defcustom org-table-allow-automatic-line-recalculation t
851 "Non-nil means, lines marked with |#| or |*| will be recomputed automatically.
852 Automatically means, when TAB or RET or C-c C-c are pressed in the line."
853 :group
'org-table-calculation
856 (defgroup org-link nil
857 "Options concerning links in Org-mode."
861 (defcustom org-descriptive-links t
862 "Non-nil means, hide link part and only show description of bracket links.
863 Bracket links are like [[link][descritpion]]. This variable sets the initial
864 state in new org-mode buffers. The setting can then be toggled on a
865 per-buffer basis from the Org->Hyperlinks menu."
869 (defcustom org-link-style
'bracket
870 "The style of links to be inserted with \\[org-insert-link].
872 bracket [[link][description]]. This is recommended
873 plain Description \\n link. The old way, no longer recommended."
876 (const :tag
"Bracket (recommended)" bracket
)
877 (const :tag
"Plain (no longer recommended)" plain
)))
879 (defcustom org-link-format
"%s"
880 "Default format for external, URL-like linkes in the buffer.
881 This is a format string for printf, %s will be replaced by the link text.
882 The recommended value is just \"%s\", since links will be protected by
883 enclosing them in double brackets. If you prefer plain links (see variable
884 `org-link-style'), \"<%s>\" is useful. Some people also recommend an
885 additional URL: prefix, so the format would be \"<URL:%s>\"."
888 (const :tag
"\"%s\" (e.g. http://www.there.com)" "%s")
889 (const :tag
"\"<%s>\" (e.g. <http://www.there.com>)" "<%s>")
890 (const :tag
"\"<URL:%s>\" (e.g. <URL:http://www.there.com>)" "<URL:%s>")
891 (string :tag
"Other" :value
"<%s>")))
893 (defcustom org-link-file-path-type
'adaptive
894 "How the path name in file links should be stored.
897 relative relative to the current directory, i.e. the directory of the file
898 into which the link is being inserted.
899 absolute absolute path, if possible with ~ for home directory.
900 noabbrev absolute path, no abbreviation of home directory.
901 adaptive Use relative path for files in the current directory and sub-
902 directories of it. For other files, use an absolute path."
910 (defcustom org-activate-links
'(bracket angle plain radio tag date
)
911 "Types of links that should be activated in Org-mode files.
912 This is a list of symbols, each leading to the activation of a certain link
913 type. In principle, it does not hurt to turn on most link types - there may
914 be a small gain when turning off unused link types. The types are:
916 bracket The recommended [[link][description]] or [[link]] links with hiding.
917 angular Links in angular brackes that may contain whitespace like
918 <bbdb:Carsten Dominik>.
919 plain Plain links in normal text, no whitespace, like http://google.com.
920 radio Text that is matched by a radio target, see manual for details.
921 tag Tag settings in a headline (link to tag search).
922 date Time stamps (link to calendar).
923 camel CamelCase words defining text searches.
925 Changing this variable requires a restart of Emacs to become effective."
927 :type
'(set (const :tag
"Double bracket links (new style)" bracket
)
928 (const :tag
"Angular bracket links (old style)" angular
)
929 (const :tag
"plain text links" plain
)
930 (const :tag
"Radio target matches" radio
)
931 (const :tag
"Tags" tag
)
932 (const :tag
"Timestamps" date
)
933 (const :tag
"CamelCase words" camel
)))
935 (defgroup org-link-store nil
936 "Options concerning storing links in Org-mode"
937 :tag
"Org Store Link"
940 (defcustom org-context-in-file-links t
941 "Non-nil means, file links from `org-store-link' contain context.
942 A search string will be added to the file name with :: as separator and
943 used to find the context when the link is activated by the command
945 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
946 negates this setting for the duration of the command."
947 :group
'org-link-store
950 (defcustom org-file-link-context-use-camel-case nil
951 "Non-nil means, use CamelCase to store a search context in a file link.
952 When nil, the search string simply consists of the words of the string.
953 CamelCase is deprecated, and support for it may be dropped in the future."
954 :group
'org-link-store
957 (defcustom org-keep-stored-link-after-insertion nil
958 "Non-nil means, keep link in list for entire session.
960 The command `org-store-link' adds a link pointing to the current
961 location to an internal list. These links accumulate during a session.
962 The command `org-insert-link' can be used to insert links into any
963 Org-mode file (offering completion for all stored links). When this
964 option is nil, every link which has been inserted once using \\[org-insert-link]
965 will be removed from the list, to make completing the unused links
967 :group
'org-link-store
970 (defcustom org-usenet-links-prefer-google nil
971 "Non-nil means, `org-store-link' will create web links to Google groups.
972 When nil, Gnus will be used for such links.
973 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
974 negates this setting for the duration of the command."
975 :group
'org-link-store
978 (defgroup org-link-follow nil
979 "Options concerning following links in Org-mode"
980 :tag
"Org Follow Link"
983 (defcustom org-tab-follows-link nil
984 "Non-nil means, on links TAB will follow the link.
985 Needs to be set before org.el is loaded."
986 :group
'org-link-follow
989 (defcustom org-return-follows-link nil
990 "Non-nil means, on links RET will follow the link.
991 Needs to be set before org.el is loaded."
992 :group
'org-link-follow
995 (defcustom org-mouse-1-follows-link t
996 "Non-nil means, mouse-1 on a link will follow the link.
997 A longer mouse click will still set point. Does not wortk on XEmacs.
998 Needs to be set before org.el is loaded."
999 :group
'org-link-follow
1002 (defcustom org-mark-ring-length
4
1003 "Number of different positions to be recorded in the ring
1004 Changing this requires a restart of Emacs to work correctly."
1005 :group
'org-link-follow
1008 (defcustom org-link-frame-setup
1009 '((vm . vm-visit-folder-other-frame
)
1010 (gnus . gnus-other-frame
)
1011 (file . find-file-other-window
))
1012 "Setup the frame configuration for following links.
1013 When following a link with Emacs, it may often be useful to display
1014 this link in another window or frame. This variable can be used to
1015 set this up for the different types of links.
1018 `vm-visit-folder-other-frame'
1019 For Gnus, use any of
1022 For FILE, use any of
1024 `find-file-other-window'
1025 `find-file-other-frame'
1026 For the calendar, use the variable `calendar-setup'.
1027 For BBDB, it is currently only possible to display the matches in
1029 :group
'org-link-follow
1033 (const vm-visit-folder
)
1034 (const vm-visit-folder-other-window
)
1035 (const vm-visit-folder-other-frame
)))
1039 (const gnus-other-frame
)))
1043 (const find-file-other-window
)
1044 (const find-file-other-frame
)))))
1046 (defcustom org-open-non-existing-files nil
1047 "Non-nil means, `org-open-file' will open non-existing file.
1048 When nil, an error will be generated."
1049 :group
'org-link-follow
1052 (defcustom org-confirm-shell-link-function
'yes-or-no-p
1053 "Non-nil means, ask for confirmation before executing shell links.
1054 Shell links can be dangerous, just thing about a link
1056 [[shell:rm -rf ~/*][Google Search]]
1058 This link would show up in your Org-mode document as \"Google Search\"
1059 but really it would remove your entire home directory.
1060 Therefore I *definitely* advise against setting this variable to nil.
1061 Just change it to `y-or-n-p' of you want to confirm with a single key press
1062 rather than having to type \"yes\"."
1063 :group
'org-link-follow
1065 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1066 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1067 (const :tag
"no confirmation (dangerous)" nil
)))
1069 (defcustom org-confirm-elisp-link-function
'yes-or-no-p
1070 "Non-nil means, ask for confirmation before executing elisp links.
1071 Elisp links can be dangerous, just thing about a link
1073 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
1075 This link would show up in your Org-mode document as \"Google Search\"
1076 but really it would remove your entire home directory.
1077 Therefore I *definitely* advise against setting this variable to nil.
1078 Just change it to `y-or-n-p' of you want to confirm with a single key press
1079 rather than having to type \"yes\"."
1080 :group
'org-link-follow
1082 (const :tag
"with yes-or-no (safer)" yes-or-no-p
)
1083 (const :tag
"with y-or-n (faster)" y-or-n-p
)
1084 (const :tag
"no confirmation (dangerous)" nil
)))
1086 (defconst org-file-apps-defaults-gnu
1089 "Default file applications on a UNIX or GNU/Linux system.
1090 See `org-file-apps'.")
1092 (defconst org-file-apps-defaults-macosx
1098 ("eps.gz" .
"gv %s")
1100 ("fig" .
"xfig %s"))
1101 "Default file applications on a MacOS X system.
1102 The system \"open\" is known as a default, but we use X11 applications
1103 for some files for which the OS does not have a good default.
1104 See `org-file-apps'.")
1106 (defconst org-file-apps-defaults-windowsnt
1110 (list (if (featurep 'xemacs
)
1111 'mswindows-shell-execute
1114 "Default file applications on a Windows NT system.
1115 The system \"open\" is used for most files.
1116 See `org-file-apps'.")
1118 (defcustom org-file-apps
1127 "External applications for opening `file:path' items in a document.
1128 Org-mode uses system defaults for different file types, but
1129 you can use this variable to set the application for a given file
1130 extension. The entries in this list are cons cells where the car identifies
1131 files and the cdr the corresponding command. Possible values for the
1133 \"ext\" A string identifying an extension
1134 `directory' Matches a directory
1135 `remote' Matches a remove file, accessible through tramp or efs.
1136 Remote files most likely should be visited through emacs
1137 because external applications cannot handle such paths.
1138 t Default for all remaining files
1140 Possible values for the command are:
1141 `emacs' The file will be visited by the current Emacs process.
1142 `default' Use the default application for this file type.
1143 string A command to be executed by a shell; %s will be replaced
1144 by the path to the file.
1145 sexp A Lisp form which will be evaluated. The file path will
1146 be available in the Lisp variable `file'.
1147 For more examples, see the system specific constants
1148 `org-file-apps-defaults-macosx'
1149 `org-file-apps-defaults-windowsnt'
1150 `org-file-apps-defaults-gnu'."
1151 :group
'org-link-follow
1153 (cons (choice :value
""
1154 (string :tag
"Extension")
1155 (const :tag
"Default for unrecognized files" t
)
1156 (const :tag
"Remote file" remote
)
1157 (const :tag
"Links to a directory" directory
))
1159 (const :tag
"Visit with Emacs" emacs
)
1160 (const :tag
"Use system default" default
)
1161 (string :tag
"Command")
1162 (sexp :tag
"Lisp form")))))
1164 (defcustom org-mhe-search-all-folders nil
1165 "Non-nil means, that the search for the mh-message will be extended to
1166 all folders if the message cannot be found in the folder given in the link.
1167 Searching all folders is very effective with one of the search engines
1168 supported by MH-E, but will be slow with pick."
1169 :group
'org-link-follow
1172 (defgroup org-remember nil
1173 "Options concerning interaction with remember.el."
1177 (defcustom org-directory
"~/org"
1178 "Directory with org files.
1179 This directory will be used as default to prompt for org files.
1180 Used by the hooks for remember.el."
1181 :group
'org-remember
1184 (defcustom org-default-notes-file
"~/.notes"
1185 "Default target for storing notes.
1186 Used by the hooks for remember.el. This can be a string, or nil to mean
1187 the value of `remember-data-file'."
1188 :group
'org-remember
1190 (const :tag
"Default from remember-data-file" nil
)
1193 (defcustom org-remember-templates nil
1194 "Templates for the creation of remember buffers.
1195 When nil, just let remember make the buffer.
1196 When not nil, this is a list of 3-element lists. In each entry, the first
1197 element is a character, a unique key to select this template.
1198 The second element is the template. The third element is optional and can
1199 specify a destination file for remember items created with this template.
1200 The default file is given by `org-default-notes-file'.
1202 The template specifies the structure of the remember buffer. It should have
1203 a first line starting with a star, to act as the org-mode headline.
1204 Furthermore, the following %-escapes will be replaced with content:
1205 %t time stamp, date only
1206 %T time stamp with date and time
1207 %u inactive time stamp, date only
1208 %U inactive time stamp with date and time
1210 %a annotation, normally the link created with org-store-link
1211 %i initial content, the region when remember is called with C-u.
1212 If %i is indented, the entire inserted text will be indented as well.
1213 %? This will be removed, and the cursor placed at this position."
1214 :group
'org-remember
1215 :type
'(repeat :tag
"enabled"
1216 (list :value
(?a
"\n" nil
)
1217 (character :tag
"Selection Key")
1218 (string :tag
"Template")
1219 (file :tag
"Destination file (optional)"))))
1221 (defcustom org-reverse-note-order nil
1222 "Non-nil means, store new notes at the beginning of a file or entry.
1223 When nil, new notes will be filed to the end of a file or entry."
1224 :group
'org-remember
1226 (const :tag
"Reverse always" t
)
1227 (const :tag
"Reverse never" nil
)
1228 (repeat :tag
"By file name regexp"
1229 (cons regexp boolean
))))
1231 (defgroup org-todo nil
1232 "Options concerning TODO items in Org-mode."
1236 (defcustom org-todo-keywords
'("TODO" "DONE")
1237 "List of TODO entry keywords.
1238 \\<org-mode-map>By default, this is '(\"TODO\" \"DONE\"). The last entry in the list is
1239 considered to mean that the entry is \"done\". All the other mean that
1240 action is required, and will make the entry show up in todo lists, diaries
1242 The command \\[org-todo] cycles an entry through these states, and an
1243 additional state where no keyword is present. For details about this
1244 cycling, see also the variable `org-todo-interpretation'
1245 Changes become only effective after restarting Emacs."
1247 :group
'org-keywords
1248 :type
'(repeat (string :tag
"Keyword")))
1250 (defcustom org-todo-interpretation
'sequence
1251 "Controls how TODO keywords are interpreted.
1252 This variable is only relevant if `org-todo-keywords' contains more than two
1253 states. \\<org-mode-map>Possible values are `sequence' and `type'.
1255 When `sequence', \\[org-todo] will always switch to the next state in the
1256 `org-todo-keywords' list. When `type', \\[org-todo] only cycles from state
1257 to state when executed several times in direct succession. Otherwise, it
1258 switches directly to DONE from any state.
1259 See the manual for more information."
1261 :group
'org-keywords
1262 :type
'(choice (const sequence
)
1265 (defcustom org-after-todo-state-change-hook nil
1266 "Hook which is run after the state of a TODO item was changed.
1267 The new state (a string with a TODO keyword, or nil) is available in the
1268 Lisp variable `state'."
1272 (defcustom org-log-done nil
1273 "When set, insert a (non-active) time stamp when TODO entry is marked DONE.
1274 When the state of an entry is changed from nothing to TODO, remove a previous
1276 This can also be configured on a per-file basis by adding one of
1277 the following lines anywhere in the buffer:
1280 #+STARTUP: nologging"
1284 (defgroup org-priorities nil
1285 "Priorities in Org-mode."
1286 :tag
"Org Priorities"
1289 (defcustom org-default-priority ?B
1290 "The default priority of TODO items.
1291 This is the priority an item get if no explicit priority is given."
1292 :group
'org-priorities
1295 (defcustom org-lowest-priority ?C
1296 "The lowest priority of TODO items. A character like ?A, ?B etc."
1297 :group
'org-priorities
1300 (defgroup org-time nil
1301 "Options concerning time stamps and deadlines in Org-mode."
1305 (defcustom org-insert-labeled-timestamps-at-point nil
1306 "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point.
1307 When nil, these labeled time stamps are forces into the second line of an
1308 entry, just after the headline. When scheduling from the global TODO list,
1309 the time stamp will always be forced into the second line."
1313 (defconst org-time-stamp-formats
'("<%Y-%m-%d %a>" .
"<%Y-%m-%d %a %H:%M>")
1314 "Formats for `format-time-string' which are used for time stamps.
1315 It is not recommended to change this constant.")
1317 (defcustom org-time-stamp-rounding-minutes
0
1318 "Number of minutes to round time stamps to upon insertion.
1319 When zero, insert the time unmodified. Useful rounding numbers
1320 should be factors of 60, so for example 5, 10, 15.
1321 When this is not zero, you can still force an exact time-stamp by using
1322 a double prefix argument to a time-stamp command like `C-c .' or `C-c !'."
1326 (defcustom org-deadline-warning-days
30
1327 "No. of days before expiration during which a deadline becomes active.
1328 This variable governs the display in the org file."
1332 (defcustom org-popup-calendar-for-date-prompt t
1333 "Non-nil means, pop up a calendar when prompting for a date.
1334 In the calendar, the date can be selected with mouse-1. However, the
1335 minibuffer will also be active, and you can simply enter the date as well.
1336 When nil, only the minibuffer will be available."
1340 (defcustom org-calendar-follow-timestamp-change t
1341 "Non-nil means, make the calendar window follow timestamp changes.
1342 When a timestamp is modified and the calendar window is visible, it will be
1343 moved to the new date."
1347 (defgroup org-tags nil
1348 "Options concerning tags in Org-mode."
1352 (defcustom org-tag-alist nil
1353 "List of tags allowed in Org-mode files.
1354 When this list is nil, Org-mode will base TAG input on what is already in the
1356 The value of this variable is an alist, the car may be (and should) be a
1357 character that is used to select that tag through the fast-tag-selection
1358 interface. See the manual for details."
1362 (cons (string :tag
"Tag name")
1363 (character :tag
"Access char"))
1364 (const :tag
"Start radio group" (:startgroup
))
1365 (const :tag
"End radio group" (:endgroup
)))))
1367 (defcustom org-use-fast-tag-selection
'auto
1368 "Non-nil means, use fast tag selection scheme.
1369 This is a special interface to select and deselect tags with single keys.
1370 When nil, fast selection is never used.
1371 When the symbol `auto', fast selection is used if and only if selection
1372 characters for tags have been configured, either through the variable
1373 `org-tag-alist' or through a #+TAGS line in the buffer.
1374 When t, fast selection is always used and selection keys are assigned
1375 automatically if necessary."
1378 (const :tag
"Always" t
)
1379 (const :tag
"Never" nil
)
1380 (const :tag
"When selection characters are configured" 'auto
)))
1382 (defcustom org-tags-column
48
1383 "The column to which tags should be indented in a headline.
1384 If this number is positive, it specifies the column. If it is negative,
1385 it means that the tags should be flushright to that column. For example,
1386 -79 works well for a normal 80 character screen."
1390 (defcustom org-auto-align-tags t
1391 "Non-nil means, realign tags after pro/demotion of TODO state change.
1392 These operations change the length of a headline and therefore shift
1393 the tags around. With this options turned on, after each such operation
1394 the tags are again aligned to `org-tags-column'."
1398 (defcustom org-use-tag-inheritance t
1399 "Non-nil means, tags in levels apply also for sublevels.
1400 When nil, only the tags directly given in a specific line apply there.
1401 If you turn off this option, you very likely want to turn on the
1402 companion option `org-tags-match-list-sublevels'."
1406 (defcustom org-tags-match-list-sublevels nil
1407 "Non-nil means list also sublevels of headlines matching tag search.
1408 Because of tag inheritance (see variable `org-use-tag-inheritance'),
1409 the sublevels of a headline matching a tag search often also match
1410 the same search. Listing all of them can create very long lists.
1411 Setting this variable to nil causes subtrees of a match to be skipped.
1412 This option is off by default, because inheritance in on. If you turn
1413 inheritance off, you very likely want to turn this option on.
1415 As a special case, if the tag search is restricted to TODO items, the
1416 value of this variable is ignored and sublevels are always checked, to
1417 make sure all corresponding TODO items find their way into the list."
1421 (defvar org-tags-history nil
1422 "History of minibuffer reads for tags.")
1423 (defvar org-last-tags-completion-table nil
1424 "The last used completion table for tags.")
1426 (defgroup org-agenda nil
1427 "Options concerning agenda display Org-mode."
1431 (defvar org-category nil
1432 "Variable used by org files to set a category for agenda display.
1433 Such files should use a file variable to set it, for example
1435 -*- mode: org; org-category: \"ELisp\"
1437 or contain a special line
1441 If the file does not specify a category, then file's base name
1443 (make-variable-buffer-local 'org-category
)
1445 (defcustom org-agenda-files nil
1446 "The files to be used for agenda display.
1447 Entries may be added to this list with \\[org-agenda-file-to-front] and removed with
1448 \\[org-remove-file]. You can also use customize to edit the list.
1450 If the value of the variable is not a list but a single file name, then
1451 the list of agenda files is actually stored and maintained in that file, one
1452 agenda file per line."
1455 (repeat :tag
"List of files" file
)
1456 (file :tag
"Store list in a file\n" :value
"~/.agenda_files")))
1458 (defcustom org-agenda-custom-commands
'(("w" todo
"WAITING"))
1459 "Custom commands for the agenda.
1460 These commands will be offered on the splash screen displayed by the
1461 agenda dispatcher \\[org-agenda]. Each entry is a list of 3 items:
1463 key The key (a single char as a string) to be associated with the command.
1464 type The command type, any of the following symbols:
1465 todo Entries with a specific TODO keyword, in all agenda files.
1466 tags Tags match in all agenda files.
1467 tags-todo Tags match in all agenda files, TODO entries only.
1468 todo-tree Sparse tree of specific TODO keyword in *current* file.
1469 tags-tree Sparse tree with all tags matches in *current* file.
1470 occur-tree Occur sparse tree for current file.
1471 match What to search for:
1472 - a single keyword for TODO keyword searches
1473 - a tags match expression for tags searches
1474 - a regular expression for occur searches"
1477 (list (string :tag
"Key")
1479 (const :tag
"Tags search in all agenda files" tags
)
1480 (const :tag
"Tags search of TODO entries, all agenda files" tags-todo
)
1481 (const :tag
"TODO keyword search in all agenda files" todo
)
1482 (const :tag
"Tags sparse tree in current buffer" tags-tree
)
1483 (const :tag
"TODO keyword tree in current buffer" todo-tree
)
1484 (const :tag
"Occur tree in current buffer" occur-tree
))
1485 (string :tag
"Match"))))
1487 (defcustom org-agenda-todo-list-sublevels t
1488 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
1489 When nil, the sublevels of a TODO entry are not checked, resulting in
1490 potentially much shorter TODO lists."
1495 (defcustom org-agenda-todo-ignore-scheduled nil
1496 "Non-nil means, don't show scheduled entries in the global todo list.
1497 The idea behind this is that by scheduling it, you have already taken care
1503 (defcustom org-agenda-include-all-todo nil
1504 "Non-nil means, the agenda will always contain all TODO entries.
1505 When nil, date-less entries will only be shown if `org-agenda' is called
1506 with a prefix argument.
1507 When non-nil, the TODO entries will be listed at the top of the agenda, before
1508 the entries for specific days."
1512 (defcustom org-agenda-include-diary nil
1513 "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
1517 (defcustom org-calendar-to-agenda-key
[?c
]
1518 "The key to be installed in `calendar-mode-map' for switching to the agenda.
1519 The command `org-calendar-goto-agenda' will be bound to this key. The
1520 default is the character `c' because then `c' can be used to switch back and
1521 forth between agenda and calendar."
1525 (defgroup org-agenda-setup nil
1526 "Options concerning setting up the Agenda window in Org Mode."
1527 :tag
"Org Agenda Window Setup"
1530 (defcustom org-agenda-mouse-1-follows-link nil
1531 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
1532 A longer mouse click will still set point. Does not wortk on XEmacs.
1533 Needs to be set before org.el is loaded."
1534 :group
'org-agenda-setup
1537 (defcustom org-agenda-start-with-follow-mode nil
1538 "The initial value of follwo-mode in a newly created agenda window."
1539 :group
'org-agenda-setup
1542 (defcustom org-select-agenda-window t
1543 "Non-nil means, after creating an agenda, move cursor into Agenda window.
1544 When nil, cursor will remain in the current window."
1545 :group
'org-agenda-setup
1548 (defcustom org-fit-agenda-window t
1549 "Non-nil means, change window size of agenda to fit content."
1550 :group
'org-agenda-setup
1553 (defgroup org-agenda-display nil
1554 "Options concerning what to display initially in Agenda."
1555 :tag
"Org Agenda Display"
1558 (defcustom org-agenda-show-all-dates t
1559 "Non-nil means, `org-agenda' shows every day in the selected range.
1560 When nil, only the days which actually have entries are shown."
1561 :group
'org-agenda-display
1564 (defcustom org-agenda-start-on-weekday
1
1565 "Non-nil means, start the overview always on the specified weekday.
1566 0 denotes Sunday, 1 denotes Monday etc.
1567 When nil, always start on the current day."
1568 :group
'org-agenda-display
1569 :type
'(choice (const :tag
"Today" nil
)
1570 (number :tag
"Weekday No.")))
1572 (defcustom org-agenda-ndays
7
1573 "Number of days to include in overview display.
1575 :group
'org-agenda-display
1578 (defcustom org-agenda-use-time-grid t
1579 "Non-nil means, show a time grid in the agenda schedule.
1580 A time grid is a set of lines for specific times (like every two hours between
1581 8:00 and 20:00). The items scheduled for a day at specific times are
1582 sorted in between these lines.
1583 For details about when the grid will be shown, and what it will look like, see
1584 the variable `org-agenda-time-grid'."
1585 :group
'org-agenda-display
1588 (defcustom org-agenda-time-grid
1589 '((daily today require-timed
)
1591 (800 1000 1200 1400 1600 1800 2000))
1593 "The settings for time grid for agenda display.
1594 This is a list of three items. The first item is again a list. It contains
1595 symbols specifying conditions when the grid should be displayed:
1597 daily if the agenda shows a single day
1598 weekly if the agenda shows an entire week
1599 today show grid on current date, independent of daily/weekly display
1600 require-timed show grid only if at least on item has a time specification
1602 The second item is a string which will be places behing the grid time.
1604 The third item is a list of integers, indicating the times that should have
1606 :group
'org-agenda-display
1609 (set :greedy t
:tag
"Grid Display Options"
1610 (const :tag
"Show grid in single day agenda display" daily
)
1611 (const :tag
"Show grid in weekly agenda display" weekly
)
1612 (const :tag
"Always show grid for today" today
)
1613 (const :tag
"Show grid only if any timed entries are present"
1615 (const :tag
"Skip grid times already present in an entry"
1617 (string :tag
"Grid String")
1618 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
1620 (defcustom org-agenda-sorting-strategy
'(time-up category-keep priority-down
)
1621 "Sorting structure for the agenda items of a single day.
1622 This is a list of symbols which will be used in sequence to determine
1623 if an entry should be listed before another entry. The following
1624 symbols are recognized:
1626 time-up Put entries with time-of-day indications first, early first
1627 time-down Put entries with time-of-day indications first, late first
1628 category-keep Keep the default order of categories, corresponding to the
1629 sequence in `org-agenda-files'.
1630 category-up Sort alphabetically by category, A-Z.
1631 category-down Sort alphabetically by category, Z-A.
1632 priority-up Sort numerically by priority, high priority last.
1633 priority-down Sort numerically by priority, high priority first.
1635 The different possibilities will be tried in sequence, and testing stops
1636 if one comparison returns a \"not-equal\". For example, the default
1637 '(time-up category-keep priority-down)
1638 means: Pull out all entries having a specified time of day and sort them,
1639 in order to make a time schedule for the current day the first thing in the
1640 agenda listing for the day. Of the entries without a time indication, keep
1641 the grouped in categories, don't sort the categories, but keep them in
1642 the sequence given in `org-agenda-files'. Within each category sort by
1645 Leaving out `category-keep' would mean that items will be sorted across
1646 categories by priority."
1647 :group
'org-agenda-display
1652 (const category-keep
)
1654 (const category-down
)
1656 (const priority-down
))))
1658 (defcustom org-sort-agenda-notime-is-late t
1659 "Non-nil means, items without time are considered late.
1660 This is only relevant for sorting. When t, items which have no explicit
1661 time like 15:30 will be considered as 99:01, i.e. later than any items which
1662 do have a time. When nil, the default time is before 0:00. You can use this
1663 option to decide if the schedule for today should come before or after timeless
1665 :group
'org-agenda-display
1669 (defgroup org-agenda-prefix nil
1670 "Options concerning the entry prefix in the Org-mode agenda display."
1671 :tag
"Org Agenda Prefix"
1674 (defcustom org-agenda-prefix-format
" %-12:c%?-12t% s"
1675 "Format specification for the prefix of items in the agenda buffer.
1676 This format works similar to a printf format, with the following meaning:
1678 %c the category of the item, \"Diary\" for entries from the diary, or
1679 as given by the CATEGORY keyword or derived from the file name.
1680 %T the first tag of the item.
1681 %t the time-of-day specification if one applies to the entry, in the
1683 %s Scheduling/Deadline information, a short string
1685 All specifiers work basically like the standard `%s' of printf, but may
1686 contain two additional characters: A question mark just after the `%' and
1687 a whitespace/punctuation character just before the final letter.
1689 If the first character after `%' is a question mark, the entire field
1690 will only be included if the corresponding value applies to the
1691 current entry. This is useful for fields which should have fixed
1692 width when present, but zero width when absent. For example,
1693 \"%?-12t\" will result in a 12 character time field if a time of the
1694 day is specified, but will completely disappear in entries which do
1697 If there is punctuation or whitespace character just before the final
1698 format letter, this character will be appended to the field value if
1699 the value is not empty. For example, the format \"%-12:c\" leads to
1700 \"Diary: \" if the category is \"Diary\". If the category were be
1701 empty, no additional colon would be interted.
1703 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1704 - Indent the line with two space characters
1705 - Give the category in a 12 chars wide field, padded with whitespace on
1706 the right (because of `-'). Append a colon if there is a category
1708 - If there is a time-of-day, put it into a 12 chars wide field. If no
1709 time, don't put in an empty field, just skip it (because of '?').
1710 - Finally, put the scheduling information and append a whitespace.
1712 As another example, if you don't want the time-of-day of entries in
1713 the prefix, you could use:
1715 (setq org-agenda-prefix-format \" %-11:c% s\")
1717 See also the variables `org-agenda-remove-times-when-in-prefix' and
1718 `org-agenda-remove-tags-when-in-prefix'."
1720 :group
'org-agenda-prefix
)
1722 (defvar org-prefix-format-compiled nil
1723 "The compiled version of the most recently used prefix format.
1724 Depending on which command was used last, this may be the compiled version
1725 of `org-agenda-prefix-format' or `org-timeline-prefix-format'.")
1727 (defcustom org-agenda-remove-times-when-in-prefix t
1728 "Non-nil means, remove duplicate time specifications in agenda items.
1729 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1730 time-of-day specification in a headline or diary entry is extracted and
1731 placed into the prefix. If this option is non-nil, the original specification
1732 \(a timestamp or -range, or just a plain time(range) specification like
1733 11:30-4pm) will be removed for agenda display. This makes the agenda less
1735 The option can be t or nil. It may also be the symbol `beg', indicating
1736 that the time should only be removed what it is located at the beginning of
1737 the headline/diary entry."
1738 :group
'org-agenda-prefix
1740 (const :tag
"Always" t
)
1741 (const :tag
"Never" nil
)
1742 (const :tag
"When at beginning of entry" beg
)))
1744 (defcustom org-agenda-remove-tags-when-in-prefix nil
1745 "Non-nil means, remove the tags from the headline copy in the agenda.
1746 When this is the symbol `prefix', only remove tags when
1747 `org-agenda-prefix-format' contains a `%T' specifier."
1748 :group
'org-agenda-prefix
1750 (const :tag
"Always" t
)
1751 (const :tag
"Never" nil
)
1752 (const :tag
"When prefix format contains %T" prefix
)))
1754 (defgroup org-agenda-timeline nil
1755 "Options concerning the timeline buffer in Org Mode."
1756 :tag
"Org Agenda Timeline"
1759 (defcustom org-timeline-prefix-format
" % s"
1760 "Like `org-agenda-prefix-format', but for the timeline of a single file."
1762 :group
'org-agenda-timeline
)
1764 (defcustom org-select-timeline-window t
1765 "Non-nil means, after creating a timeline, move cursor into Timeline window.
1766 When nil, cursor will remain in the current window."
1767 :group
'org-agenda-timeline
1770 (defcustom org-timeline-show-empty-dates
3
1771 "Non-nil means, `org-timeline' also shows dates without an entry.
1772 When nil, only the days which actually have entries are shown.
1773 When t, all days between the first and the last date are shown.
1774 When an integer, show also empty dates, but if there is a gap of more than
1775 N days, just insert a special line indicating the size of the gap."
1776 :group
'org-agenda-timeline
1778 (const :tag
"None" nil
)
1779 (const :tag
"All" t
)
1780 (number :tag
"at most")))
1782 (defgroup org-latex nil
1783 "Options for embedding LaTeX code into Org-mode"
1787 (defcustom org-format-latex-options
1788 '(:foreground
"Black" :background
"Transparent" :scale
1.0
1789 :matchers
("begin" "$" "$$" "\\(" "\\["))
1790 "Options for creating images from LaTeX fragments.
1791 This is a property list with the following properties:
1792 :foreground the foreground color, for example \"Black\".
1793 :background the background color, or \"Transparent\".
1794 :scale a scaling factor for the size of the images
1795 :matchers a list indicating which matchers should be used to
1796 find LaTeX fragments. Valid members of this list are:
1797 \"begin\" find environments
1798 \"$\" find math expressions surrounded by $...$
1799 \"$$\" find math expressions surrounded by $$....$$
1800 \"\\(\" find math expressions surrounded by \\(...\\)
1801 \"\\ [\" find math expressions surrounded by \\ [...\\]"
1805 (defgroup org-export nil
1806 "Options for exporting org-listings."
1810 (defgroup org-export-general nil
1811 "General options for exporting Org-mode files."
1812 :tag
"Org Export General"
1815 (defcustom org-export-publishing-directory
"."
1816 "Path to the location where exported files should be located.
1817 This path may be relative to the directory where the Org-mode file lives.
1818 The default is to put them into the same directory as the Org-mode file.
1819 The variable may also be an alist with export types `:html', `:ascii',
1820 `:ical', or `:xoxo' and the corresponding directories. If a direcoty path
1821 is relative, it is interpreted relative to the directory where the exported
1822 Org-mode files lives."
1823 :group
'org-export-general
1829 (const :html
) (const :ascii
) (const :ical
) (const :xoxo
))
1832 (defcustom org-export-language-setup
1833 '(("en" "Author" "Date" "Table of Contents")
1834 ("da" "Ophavsmand" "Dato" "Indhold")
1835 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
1836 ("es" "Autor" "Fecha" "\xccndice")
1837 ("fr" "Auteur" "Date" "Table des Mati\xe8res")
1838 ("it" "Autore" "Data" "Indice")
1839 ("nl" "Auteur" "Datum" "Inhoudsopgave")
1840 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
1841 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
1842 "Terms used in export text, translated to different languages.
1843 Use the variable `org-export-default-language' to set the language,
1844 or use the +OPTION lines for a per-file setting."
1845 :group
'org-export-general
1848 (string :tag
"HTML language tag")
1849 (string :tag
"Author")
1850 (string :tag
"Date")
1851 (string :tag
"Table of Contents"))))
1853 (defcustom org-export-default-language
"en"
1854 "The default language of HTML export, as a string.
1855 This should have an association in `org-export-language-setup'."
1856 :group
'org-export-general
1859 (defcustom org-export-headline-levels
3
1860 "The last level which is still exported as a headline.
1861 Inferior levels will produce itemize lists when exported.
1862 Note that a numeric prefix argument to an exporter function overrides
1865 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
1866 :group
'org-export-general
1869 (defcustom org-export-with-section-numbers t
1870 "Non-nil means, add section numbers to headlines when exporting.
1872 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
1873 :group
'org-export-general
1876 (defcustom org-export-with-toc t
1877 "Non-nil means, create a table of contents in exported files.
1878 The TOC contains headlines with levels up to`org-export-headline-levels'.
1880 Headlines which contain any TODO items will be marked with \"(*)\" in
1881 ASCII export, and with red color in HTML output.
1883 In HTML output, the TOC will be clickable.
1885 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"."
1886 :group
'org-export-general
1889 (defcustom org-export-mark-todo-in-toc nil
1890 "Non-nil means, mark TOC lines that contain any open TODO items."
1891 :group
'org-export-general
1894 (defcustom org-export-preserve-breaks nil
1895 "Non-nil means, preserve all line breaks when exporting.
1896 Normally, in HTML output paragraphs will be reformatted. In ASCII
1897 export, line breaks will always be preserved, regardless of this variable.
1899 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
1900 :group
'org-export-general
1903 (defcustom org-export-with-archived-trees
'headline
1904 "Whether subtrees with the ARCHIVE tag should be exported.
1905 This can have three different values
1906 nil Do not export, pretend this tree is not present
1907 t Do export the entire tree
1908 headline Only export the headline, but skip the tree below it."
1909 :group
'org-export-general
1912 (const :tag
"not at all" nil
)
1913 (const :tag
"headline only" 'headline
)
1914 (const :tag
"entirely" t
)))
1916 (defcustom org-export-with-timestamps t
1917 "Nil means, do not export time stamps and associated keywords."
1921 (defcustom org-export-remove-timestamps-from-toc t
1922 "Nil means, remove timestamps from the table of contents entries."
1926 (defcustom org-export-with-tags t
1927 "Nil means, do not export tags, just remove them from headlines."
1928 :group
'org-export-general
1931 (defcustom org-export-with-timestamps t
1932 "Nil means, do not export timestamps and associated keywords."
1933 :group
'org-export-general
1936 (defgroup org-export-translation nil
1937 "Options for translating special ascii sequences for the export backends."
1938 :tag
"Org Export Translation"
1941 (defcustom org-export-with-emphasize t
1942 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
1943 If the export target supports emphasizing text, the word will be
1944 typeset in bold, italic, or underlined, respectively. Works only for
1945 single words, but you can say: I *really* *mean* *this*.
1946 Not all export backends support this.
1948 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
1949 :group
'org-export-translation
1952 (defcustom org-export-with-sub-superscripts t
1953 "Non-nil means, interpret \"_\" and \"^\" for export.
1954 When this option is turned on, you can use TeX-like syntax for sub- and
1955 superscripts. Several characters after \"_\" or \"^\" will be
1956 considered as a single item - so grouping with {} is normally not
1957 needed. For example, the following things will be parsed as single
1958 sub- or superscripts.
1960 10^24 or 10^tau several digits will be considered 1 item.
1961 10^-12 or 10^-tau a leading sign with digits or a word
1962 x^2-y^3 will be read as x^2 - y^3, because items are
1963 terminated by almost any nonword/nondigit char.
1964 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
1966 Still, ambiguity is possible - so when in doubt use {} to enclose the
1968 Not all export backends support this, but HTML does.
1970 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
1971 :group
'org-export-translation
1974 (defcustom org-export-with-TeX-macros t
1975 "Non-nil means, interpret simple TeX-like macros when exporting.
1976 For example, HTML export converts \\alpha to α and \\AA to Å.
1977 No only real TeX macros will work here, but the standard HTML entities
1978 for math can be used as macro names as well. For a list of supported
1979 names in HTML export, see the constant `org-html-entities'.
1980 Not all export backends support this.
1982 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
1983 :group
'org-export-translation
1987 (defcustom org-export-with-LaTeX-fragments nil
1988 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
1989 When set, the exporter will find LaTeX environments if the \\begin line is
1990 the first non-white thing on a line. It will also find the math delimiters
1991 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
1994 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
1995 :group
'org-export-translation
1999 (defcustom org-export-with-fixed-width t
2000 "Non-nil means, lines starting with \":\" will be in fixed width font.
2001 This can be used to have pre-formatted text, fragments of code etc. For
2003 : ;; Some Lisp examples
2006 will be looking just like this in also HTML. See also the QUOTE keyword.
2007 Not all export backends support this.
2009 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
2010 :group
'org-export-translation
2013 (defcustom org-match-sexp-depth
3
2014 "Number of stacked braces for sub/superscript matching.
2015 This has to be set before loading org.el to be effective."
2016 :group
'org-export-translation
2019 (defgroup org-export-tables nil
2020 "Options for exporting tables in Org-mode."
2021 :tag
"Org Export Tables"
2024 (defcustom org-export-with-tables t
2025 "If non-nil, lines starting with \"|\" define a table.
2028 | Name | Address | Birthday |
2029 |-------------+----------+-----------|
2030 | Arthur Dent | England | 29.2.2100 |
2032 Not all export backends support this.
2034 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
2035 :group
'org-export-tables
2038 (defcustom org-export-highlight-first-table-line t
2039 "Non-nil means, highlight the first table line.
2040 In HTML export, this means use <th> instead of <td>.
2041 In tables created with table.el, this applies to the first table line.
2042 In Org-mode tables, all lines before the first horizontal separator
2043 line will be formatted with <th> tags."
2044 :group
'org-export-tables
2047 (defcustom org-export-table-remove-special-lines t
2048 "Remove special lines and marking characters in calculating tables.
2049 This removes the special marking character column from tables that are set
2050 up for spreadsheet calculations. It also removes the entire lines
2051 marked with `!', `_', or `^'. The lines with `$' are kept, because
2052 the values of constants may be useful to have."
2053 :group
'org-export-tables
2056 (defcustom org-export-prefer-native-exporter-for-tables nil
2057 "Non-nil means, always export tables created with table.el natively.
2058 Natively means, use the HTML code generator in table.el.
2059 When nil, Org-mode's own HTML generator is used when possible (i.e. if
2060 the table does not use row- or column-spanning). This has the
2061 advantage, that the automatic HTML conversions for math symbols and
2062 sub/superscripts can be applied. Org-mode's HTML generator is also
2064 :group
'org-export-tables
2067 (defgroup org-export-ascii nil
2068 "Options specific for ASCII export of Org-mode files."
2069 :tag
"Org Export ASCII"
2072 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
2073 "Characters for underlining headings in ASCII export.
2074 In the given sequence, these characters will be used for level 1, 2, ..."
2075 :group
'org-export-ascii
2076 :type
'(repeat character
))
2078 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
2079 "Bullet characters for headlines converted to lists in ASCII export.
2080 The first character is is used for the first lest level generated in this
2081 way, and so on. If there are more levels than characters given here,
2082 the list will be repeated.
2083 Note that plain lists will keep the same bullets as the have in the
2085 :group
'org-export-ascii
2086 :type
'(repeat character
))
2088 (defcustom org-export-ascii-show-new-buffer t
2089 "Non-nil means, popup buffer containing the exported ASCII text.
2090 Otherwise the buffer will just be saved to a file and stay hidden."
2091 :group
'org-export-ascii
2094 (defgroup org-export-xml nil
2095 "Options specific for XML export of Org-mode files."
2096 :tag
"Org Export XML"
2099 (defgroup org-export-html nil
2100 "Options specific for HTML export of Org-mode files."
2101 :tag
"Org Export HTML"
2104 (defcustom org-export-html-style
2105 "<style type=\"text/css\">
2107 font-family: Times, serif;
2110 .title { text-align: center; }
2111 .todo { color: red; }
2112 .done { color: green; }
2113 .timestamp { color: grey }
2114 .timestamp-kwd { color: CadetBlue }
2115 .tag { background-color:lightblue; font-weight:normal }
2116 .target { background-color: lavender; }
2118 border: 1pt solid #AEBDCC;
2119 background-color: #F3F5F7;
2121 font-family: courier, monospace;
2123 table { border-collapse: collapse; }
2125 vertical-align: top;
2126 border: 1pt solid #ADB9CC;
2129 "The default style specification for exported HTML files.
2130 Since there are different ways of setting style information, this variable
2131 needs to contain the full HTML structure to provide a style, including the
2132 surrounding HTML tags. The style specifications should include definitions
2133 for new classes todo, done, title, and deadline. For example, legal values
2136 <style type=\"text/css\">
2137 p { font-weight: normal; color: gray; }
2138 h1 { color: black; }
2139 .title { text-align: center; }
2140 .todo, .deadline { color: red; }
2141 .done { color: green; }
2144 or, if you want to keep the style in a file,
2146 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
2148 As the value of this option simply gets inserted into the HTML <head> header,
2149 you can \"misuse\" it to add arbitrary text to the header."
2150 :group
'org-export-html
2153 (defcustom org-export-html-link-org-files-as-html t
2154 "Non-nil means, make file links to `file.org' point to `file.html'.
2155 When org-mode is exporting an org-mode file to HTML, links to
2156 non-html files are directly put into a href tag in HTML.
2157 However, links to other Org-mode files (recognized by the
2158 extension `.org.) should become links to the corresponding html
2159 file, assuming that the linked org-mode file will also be
2161 When nil, the links still point to the plain `.org' file."
2162 :group
'org-export-html
2165 (defcustom org-export-html-inline-images
'maybe
2166 "Non-nil means, inline images into exported HTML pages.
2167 This is done using an <img> tag. When nil, an anchor with href is used to
2168 link to the image. If this option is `maybe', then images in links with
2169 an empty description will be inlined, while images with a description will
2171 :group
'org-export-html
2172 :type
'(choice (const :tag
"Never" nil
)
2173 (const :tag
"Always" t
)
2174 (const :tag
"When there is no description" maybe
)))
2176 (defcustom org-export-html-expand t
2177 "Non-nil means, for HTML export, treat @<...> as HTML tag.
2178 When nil, these tags will be exported as plain text and therefore
2179 not be interpreted by a browser.
2181 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
2182 :group
'org-export-html
2185 (defcustom org-export-html-table-tag
2186 "<table border=\"1\" cellspacing=\"0\" cellpadding=\"6\">"
2187 "The HTML tag used to start a table.
2188 This must be a <table> tag, but you may change the options like
2189 borders and spacing."
2190 :group
'org-export-html
2193 (defcustom org-export-html-with-timestamp nil
2194 "If non-nil, write `org-export-html-html-helper-timestamp'
2195 into the exported HTML text. Otherwise, the buffer will just be saved
2197 :group
'org-export-html
2200 (defcustom org-export-html-html-helper-timestamp
2201 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
2202 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
2203 :group
'org-export-html
2206 (defcustom org-export-html-show-new-buffer nil
2207 "Non-nil means, popup buffer containing the exported html text.
2208 Otherwise, the buffer will just be saved to a file and stay hidden."
2209 :group
'org-export-html
2212 (defgroup org-export-icalendar nil
2213 "Options specific for iCalendar export of Org-mode files."
2214 :tag
"Org Export iCalendar"
2217 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
2218 "The file name for the iCalendar file covering all agenda files.
2219 This file is created with the command \\[org-export-icalendar-all-agenda-files].
2220 The file name should be absolute."
2221 :group
'org-export-icalendar
2224 (defcustom org-icalendar-include-todo nil
2225 "Non-nil means, export to iCalendar files should also cover TODO items."
2226 :group
'org-export-icalendar
2229 (defcustom org-icalendar-combined-name
"OrgMode"
2230 "Calendar name for the combined iCalendar representing all agenda files."
2231 :group
'org-export-icalendar
2234 (defgroup org-font-lock nil
2235 "Font-lock settings for highlighting in Org-mode."
2236 :tag
"Org Font Lock"
2239 (defcustom org-level-color-stars-only nil
2240 "Non-nil means fontify only the stars in each headline.
2241 When nil, the entire headline is fontified.
2242 Changing it requires restart of `font-lock-mode' to become effective
2243 also in regions already fontified."
2244 :group
'org-font-lock
2247 (defcustom org-hide-leading-stars nil
2248 "Non-nil means, hide the first N-1 stars in a headline.
2249 This works by using the face `org-hide' for these stars. This
2250 face is white for a light background, and black for a dark
2251 background. You may have to customize the face `org-hide' to
2253 Changing it requires restart of `font-lock-mode' to become effective
2254 also in regions already fontified.
2255 You may also set this on a per-file basis by adding one of the following
2256 lines to the buffer:
2258 #+STARTUP: hidestars
2259 #+STARTUP: showstars"
2260 :group
'org-font-lock
2263 (defcustom org-fontify-done-headline nil
2264 "Non-nil means, change the face of a headline if it is marked DONE.
2265 Normally, only the TODO/DONE keyword indicates the state of a headline.
2266 When this is non-nil, the headline after the keyword is set to the
2267 `org-headline-done' as an additional indication."
2268 :group
'org-font-lock
2271 (defcustom org-fontify-emphasized-text t
2272 "Non-nil means fontify *bold*, /italic/ and _underlined_ text.
2273 Changing this variable requires a restart of Emacs to take effect."
2274 :group
'org-font-lock
2277 (defvar org-emph-re nil
2278 "Regular expression for matching emphasis.")
2279 (defvar org-emphasis-regexp-components
) ; defined just below
2280 (defvar org-emphasis-alist
) ; defined just below
2281 (defun org-set-emph-re (var val
)
2282 "Set variable and compute the emphasis regular expression."
2284 (when (and (boundp 'org-emphasis-alist
)
2285 (boundp 'org-emphasis-regexp-components
)
2286 org-emphasis-alist org-emphasis-regexp-components
)
2287 (let* ((e org-emphasis-regexp-components
)
2294 (body1 (concat body
"*?"))
2295 (markers (mapconcat 'car org-emphasis-alist
"")))
2296 ;; make sure special characters appear at the right position in the class
2297 (if (string-match "\\^" markers
)
2298 (setq markers
(concat (replace-match "" t t markers
) "^")))
2299 (if (string-match "-" markers
)
2300 (setq markers
(concat (replace-match "" t t markers
) "-")))
2301 (while (>= (setq nl
(1- nl
)) 0) (setq body1
(concat body1
"\n?" body
"*?")))
2304 (concat "\\([" pre
(if stacked markers
) "]\\|^\\)"
2306 "\\([" markers
"]\\)"
2308 "[^" border markers
"]"
2310 "[^" border markers
"]"
2313 "\\([" post
(if stacked markers
) "]\\|$\\)")))))
2315 (defcustom org-emphasis-regexp-components
2316 '(" \t(" " \t.,?;:'\")" " \t\r\n,." "." 1 nil
)
2317 "Components used to build the reqular expression for emphasis.
2318 This is a list with 6 entries. Terminology: In an emphasis string
2319 like \" *strong word* \", we call the initial space PREMATCH, the final
2320 space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters
2321 and \"trong wor\" is the body. The different components in this variable
2322 specify what is allowed/forbidden in each part:
2324 pre Chars allowed as prematch. Beginning of line will be allowed too.
2325 post Chars allowed as postmatch. End of line will be allowed too.
2326 border The chars *forbidden* as border characters. In addition to the
2327 characters given here, all marker characters are forbidden too.
2328 body-regexp A regexp like \".\" to match a body character. Don't use
2329 non-shy groups here, and don't allow newline here.
2330 newline The maximum number of newlines allowed in an emphasis exp.
2331 stacked Non-nil means, allow stacked styles. This works only in HTML
2332 export. When this is set, all marker characters (as given in
2333 `org-emphasis-alist') will be allowed as pre/post, aiding
2334 inside-out matching.
2335 Use customize to modify this, or restart emacs after changing it."
2336 :group
'org-font-lock
2337 :set
'org-set-emph-re
2339 (sexp :tag
"Allowed chars in pre ")
2340 (sexp :tag
"Allowed chars in post ")
2341 (sexp :tag
"Forbidden chars in border ")
2342 (sexp :tag
"Regexp for body ")
2343 (integer :tag
"number of newlines allowed")
2344 (boolean :tag
"Stacking allowed ")))
2346 (defcustom org-emphasis-alist
2347 '(("*" bold
"<b>" "</b>")
2348 ("/" italic
"<i>" "</i>")
2349 ("_" underline
"<u>" "</u>")
2350 ("=" shadow
"<code>" "</code>")
2351 ("+" (:strike-through t
) "<del>" "</del>")
2353 "Special syntax for emphasised text.
2354 Text starting and ending with a special character will be emphasized, for
2355 example *bold*, _underlined_ and /italic/. This variable sets the marker
2356 characters, the face to bbe used by font-lock for highlighting in Org-mode
2357 emacs buffers, and the HTML tags to be used for this.
2358 Use customize to modify this, or restart emacs after changing it."
2359 :group
'org-font-lock
2360 :set
'org-set-emph-re
2363 (string :tag
"Marker character")
2365 (face :tag
"Font-lock-face")
2366 (plist :tag
"Face property list"))
2367 (string :tag
"HTML start tag")
2368 (string :tag
"HTML end tag"))))
2370 (defgroup org-faces nil
2371 "Faces in Org-mode."
2373 :group
'org-font-lock
)
2375 (defun org-compatible-face (specs)
2376 "Make a compatible face specification.
2377 XEmacs and Emacs 21 do not know about the `min-colors' attribute.
2378 For them we convert a (min-colors 8) entry to a `tty' entry and move it
2379 to the top of the list. The `min-colors' attribute will be removed from
2380 any other entries, and any resulting duplicates will be removed entirely."
2381 (if (or (featurep 'xemacs
) (< emacs-major-version
22))
2383 (while (setq e
(pop specs
))
2385 ((memq (car e
) '(t default
)) (push e r
))
2386 ((setq a
(member '(min-colors 8) (car e
)))
2387 (nconc r
(list (cons (cons '(type tty
) (delq (car a
) (car e
)))
2389 ((setq a
(assq 'min-colors
(car e
)))
2390 (setq e
(cons (delq a
(car e
)) (cdr e
)))
2391 (or (assoc (car e
) r
) (push e r
)))
2392 (t (or (assoc (car e
) r
) (push e r
)))))
2397 '((((background light
)) (:foreground
"white"))
2398 (((background dark
)) (:foreground
"black")))
2399 "Face used to hide leading stars in headlines.
2400 The forground color of this face should be equal to the background
2401 color of the frame."
2404 (defface org-level-1
;; font-lock-function-name-face
2405 (org-compatible-face
2406 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Blue1"))
2407 (((class color
) (min-colors 88) (background dark
)) (:foreground
"LightSkyBlue"))
2408 (((class color
) (min-colors 16) (background light
)) (:foreground
"Blue"))
2409 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSkyBlue"))
2410 (((class color
) (min-colors 8)) (:foreground
"blue" :bold t
))
2412 "Face used for level 1 headlines."
2415 (defface org-level-2
;; font-lock-variable-name-face
2416 (org-compatible-face
2417 '((((class color
) (min-colors 16) (background light
)) (:foreground
"DarkGoldenrod"))
2418 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightGoldenrod"))
2419 (((class color
) (min-colors 8) (background light
)) (:foreground
"yellow"))
2420 (((class color
) (min-colors 8) (background dark
)) (:foreground
"yellow" :bold t
))
2422 "Face used for level 2 headlines."
2425 (defface org-level-3
;; font-lock-keyword-face
2426 (org-compatible-face
2427 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Purple"))
2428 (((class color
) (min-colors 88) (background dark
)) (:foreground
"Cyan1"))
2429 (((class color
) (min-colors 16) (background light
)) (:foreground
"Purple"))
2430 (((class color
) (min-colors 16) (background dark
)) (:foreground
"Cyan"))
2431 (((class color
) (min-colors 8) (background light
)) (:foreground
"purple" :bold t
))
2432 (((class color
) (min-colors 8) (background dark
)) (:foreground
"cyan" :bold t
))
2434 "Face used for level 3 headlines."
2437 (defface org-level-4
;; font-lock-comment-face
2438 (org-compatible-face
2439 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Firebrick"))
2440 (((class color
) (min-colors 88) (background dark
)) (:foreground
"chocolate1"))
2441 (((class color
) (min-colors 16) (background light
)) (:foreground
"red"))
2442 (((class color
) (min-colors 16) (background dark
)) (:foreground
"red1"))
2443 (((class color
) (min-colors 8) (background light
)) (:foreground
"red" :bold t
))
2444 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red" :bold t
))
2446 "Face used for level 4 headlines."
2449 (defface org-level-5
;; font-lock-type-face
2450 (org-compatible-face
2451 '((((class color
) (min-colors 16) (background light
)) (:foreground
"ForestGreen"))
2452 (((class color
) (min-colors 16) (background dark
)) (:foreground
"PaleGreen"))
2453 (((class color
) (min-colors 8)) (:foreground
"green"))))
2454 "Face used for level 5 headlines."
2457 (defface org-level-6
;; font-lock-constant-face
2458 (org-compatible-face
2459 '((((class color
) (min-colors 16) (background light
)) (:foreground
"CadetBlue"))
2460 (((class color
) (min-colors 16) (background dark
)) (:foreground
"Aquamarine"))
2461 (((class color
) (min-colors 8)) (:foreground
"magenta"))))
2462 "Face used for level 6 headlines."
2465 (defface org-level-7
;; font-lock-builtin-face
2466 (org-compatible-face
2467 '((((class color
) (min-colors 16) (background light
)) (:foreground
"Orchid"))
2468 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSteelBlue"))
2469 (((class color
) (min-colors 8)) (:foreground
"blue"))))
2470 "Face used for level 7 headlines."
2473 (defface org-level-8
;; font-lock-string-face
2474 (org-compatible-face
2475 '((((class color
) (min-colors 16) (background light
)) (:foreground
"RosyBrown"))
2476 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSalmon"))
2477 (((class color
) (min-colors 8)) (:foreground
"green"))))
2478 "Face used for level 8 headlines."
2481 (defface org-special-keyword
;; font-lock-string-face
2482 (org-compatible-face
2483 '((((class color
) (min-colors 16) (background light
)) (:foreground
"RosyBrown"))
2484 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSalmon"))
2486 "Face used for special keywords."
2489 (defface org-warning
;; font-lock-warning-face
2490 (org-compatible-face
2491 '((((class color
) (min-colors 16) (background light
)) (:foreground
"Red1" :bold t
))
2492 (((class color
) (min-colors 16) (background dark
)) (:foreground
"Pink" :bold t
))
2493 (((class color
) (min-colors 8) (background light
)) (:foreground
"red" :bold t
))
2494 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red" :bold t
))
2496 "Face for deadlines and TODO keywords."
2499 (defface org-headline-done
;; font-lock-string-face
2500 (org-compatible-face
2501 '((((class color
) (min-colors 16) (background light
)) (:foreground
"RosyBrown"))
2502 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSalmon"))
2503 (((class color
) (min-colors 8) (background light
)) (:bold nil
))))
2504 "Face used to indicate that a headline is DONE.
2505 This face is only used if `org-fontify-done-headline' is set."
2508 (defface org-archived
; similar to shadow
2509 (org-compatible-face
2510 '((((class color grayscale
) (min-colors 88) (background light
))
2511 (:foreground
"grey50"))
2512 (((class color grayscale
) (min-colors 88) (background dark
))
2513 (:foreground
"grey70"))
2514 (((class color
) (min-colors 8) (background light
))
2515 (:foreground
"green"))
2516 (((class color
) (min-colors 8) (background dark
))
2517 (:foreground
"yellow"))))
2518 "Face for headline with the ARCHIVE tag."
2522 '((((class color
) (background light
)) (:foreground
"Purple" :underline t
))
2523 (((class color
) (background dark
)) (:foreground
"Cyan" :underline t
))
2529 '((((class color
) (background light
)) (:foreground
"Purple" :underline t
))
2530 (((class color
) (background dark
)) (:foreground
"Cyan" :underline t
))
2540 (defface org-todo
;; font-lock-warning-face
2541 (org-compatible-face
2542 '((((class color
) (min-colors 16) (background light
)) (:foreground
"Red1" :bold t
))
2543 (((class color
) (min-colors 16) (background dark
)) (:foreground
"Pink" :bold t
))
2544 (((class color
) (min-colors 8) (background light
)) (:foreground
"red" :bold t
))
2545 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red" :bold t
))
2546 (t (:inverse-video t
:bold t
))))
2547 "Face for TODO keywords."
2550 (defface org-done
;; font-lock-type-face
2551 (org-compatible-face
2552 '((((class color
) (min-colors 16) (background light
)) (:foreground
"ForestGreen"))
2553 (((class color
) (min-colors 16) (background dark
)) (:foreground
"PaleGreen"))
2554 (((class color
) (min-colors 8)) (:foreground
"green"))
2556 "Face used for DONE."
2559 (defface org-table
;; font-lock-function-name-face
2560 (org-compatible-face
2561 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Blue1"))
2562 (((class color
) (min-colors 88) (background dark
)) (:foreground
"LightSkyBlue"))
2563 (((class color
) (min-colors 16) (background light
)) (:foreground
"Blue"))
2564 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightSkyBlue"))
2565 (((class color
) (min-colors 8) (background light
)) (:foreground
"blue"))
2566 (((class color
) (min-colors 8) (background dark
)))))
2567 "Face used for tables."
2570 (defface org-formula
2571 (org-compatible-face
2572 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Firebrick"))
2573 (((class color
) (min-colors 88) (background dark
)) (:foreground
"chocolate1"))
2574 (((class color
) (min-colors 8) (background light
)) (:foreground
"red"))
2575 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red"))
2576 (t (:bold t
:italic t
))))
2577 "Face for formulas."
2580 (defface org-scheduled-today
2581 (org-compatible-face
2582 '((((class color
) (min-colors 88) (background light
)) (:foreground
"DarkGreen"))
2583 (((class color
) (min-colors 88) (background dark
)) (:foreground
"PaleGreen"))
2584 (((class color
) (min-colors 8)) (:foreground
"green"))
2585 (t (:bold t
:italic t
))))
2586 "Face for items scheduled for a certain day."
2589 (defface org-scheduled-previously
2590 (org-compatible-face
2591 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Firebrick"))
2592 (((class color
) (min-colors 88) (background dark
)) (:foreground
"chocolate1"))
2593 (((class color
) (min-colors 8) (background light
)) (:foreground
"red"))
2594 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red" :bold t
))
2596 "Face for items scheduled previously, and not yet done."
2599 (defface org-upcoming-deadline
2600 (org-compatible-face
2601 '((((class color
) (min-colors 88) (background light
)) (:foreground
"Firebrick"))
2602 (((class color
) (min-colors 88) (background dark
)) (:foreground
"chocolate1"))
2603 (((class color
) (min-colors 8) (background light
)) (:foreground
"red"))
2604 (((class color
) (min-colors 8) (background dark
)) (:foreground
"red" :bold t
))
2606 "Face for items scheduled previously, and not yet done."
2609 (defface org-time-grid
;; font-lock-variable-name-face
2610 (org-compatible-face
2611 '((((class color
) (min-colors 16) (background light
)) (:foreground
"DarkGoldenrod"))
2612 (((class color
) (min-colors 16) (background dark
)) (:foreground
"LightGoldenrod"))
2613 (((class color
) (min-colors 8)) (:foreground
"yellow" :weight light
))))
2614 "Face used for time grids."
2617 (defconst org-level-faces
2618 '(org-level-1 org-level-2 org-level-3 org-level-4
2619 org-level-5 org-level-6 org-level-7 org-level-8
2621 (defconst org-n-levels
(length org-level-faces
))
2624 ;; Variables for pre-computed regular expressions, all buffer local
2625 (defvar org-done-string nil
2626 "The last string in `org-todo-keywords', indicating an item is DONE.")
2627 (make-variable-buffer-local 'org-done-string
)
2628 (defvar org-todo-regexp nil
2629 "Matches any of the TODO state keywords.")
2630 (make-variable-buffer-local 'org-todo-regexp
)
2631 (defvar org-not-done-regexp nil
2632 "Matches any of the TODO state keywords except the last one.")
2633 (make-variable-buffer-local 'org-not-done-regexp
)
2634 (defvar org-todo-line-regexp nil
2635 "Matches a headline and puts TODO state into group 2 if present.")
2636 (make-variable-buffer-local 'org-todo-line-regexp
)
2637 (defvar org-todo-line-tags-regexp nil
2638 "Matches a headline and puts TODO state into group 2 if present.
2639 Also put tags into group 4 if tags are present.")
2640 (make-variable-buffer-local 'org-todo-line-tags-regexp
)
2641 (defvar org-nl-done-regexp nil
2642 "Matches newline followed by a headline with the DONE keyword.")
2643 (make-variable-buffer-local 'org-nl-done-regexp
)
2644 (defvar org-looking-at-done-regexp nil
2645 "Matches the DONE keyword a point.")
2646 (make-variable-buffer-local 'org-looking-at-done-regexp
)
2647 (defvar org-todo-kwd-priority-p nil
2648 "Do TODO items have priorities?")
2649 (make-variable-buffer-local 'org-todo-kwd-priority-p
)
2650 (defvar org-todo-kwd-max-priority nil
2651 "Maximum priority of TODO items.")
2652 (make-variable-buffer-local 'org-todo-kwd-max-priority
)
2653 (defvar org-ds-keyword-length
12
2654 "Maximum length of the Deadline and SCHEDULED keywords.")
2655 (make-variable-buffer-local 'org-ds-keyword-length
)
2656 (defvar org-deadline-regexp nil
2657 "Matches the DEADLINE keyword.")
2658 (make-variable-buffer-local 'org-deadline-regexp
)
2659 (defvar org-deadline-time-regexp nil
2660 "Matches the DEADLINE keyword together with a time stamp.")
2661 (make-variable-buffer-local 'org-deadline-time-regexp
)
2662 (defvar org-deadline-line-regexp nil
2663 "Matches the DEADLINE keyword and the rest of the line.")
2664 (make-variable-buffer-local 'org-deadline-line-regexp
)
2665 (defvar org-scheduled-regexp nil
2666 "Matches the SCHEDULED keyword.")
2667 (make-variable-buffer-local 'org-scheduled-regexp
)
2668 (defvar org-scheduled-time-regexp nil
2669 "Matches the SCHEDULED keyword together with a time stamp.")
2670 (make-variable-buffer-local 'org-scheduled-time-regexp
)
2671 (defvar org-closed-time-regexp nil
2672 "Matches the CLOSED keyword together with a time stamp.")
2673 (make-variable-buffer-local 'org-closed-time-regexp
)
2675 (defvar org-keyword-time-regexp nil
2676 "Matches any of the 3 keywords, together with the time stamp.")
2677 (make-variable-buffer-local 'org-keyword-time-regexp
)
2678 (defvar org-maybe-keyword-time-regexp nil
2679 "Matches a timestamp, possibly preceeded by a keyword.")
2680 (make-variable-buffer-local 'org-keyword-time-regexp
)
2682 (defconst org-rm-props
'(invisible t face t keymap t intangible t mouse-face t
2684 "Properties to remove when a string without properties is wanted.")
2686 (defsubst org-match-string-no-properties
(num &optional string
)
2687 (if (featurep 'xemacs
)
2688 (let ((s (match-string num string
)))
2689 (remove-text-properties 0 (length s
) org-rm-props s
)
2691 (match-string-no-properties num string
)))
2693 (defsubst org-no-properties
(s)
2694 (remove-text-properties 0 (length s
) org-rm-props s
)
2697 (defsubst org-mode-p
()
2698 "Check if the current buffer is in Org-mode."
2699 (eq major-mode
'org-mode
))
2701 (defun org-set-regexps-and-options ()
2702 "Precompute regular expressions for current buffer."
2704 (let ((re (org-make-options-regexp
2705 '("CATEGORY" "SEQ_TODO" "PRI_TODO" "TYP_TODO"
2706 "STARTUP" "ARCHIVE" "TAGS")))
2708 kwds int key value cat arch tags
)
2712 (goto-char (point-min))
2713 (while (re-search-forward re nil t
)
2714 (setq key
(match-string 1) value
(org-match-string-no-properties 2))
2716 ((equal key
"CATEGORY")
2717 (if (string-match "[ \t]+$" value
)
2718 (setq value
(replace-match "" t t value
)))
2719 (setq cat
(intern value
)))
2720 ((equal key
"SEQ_TODO")
2722 kwds
(append kwds
(org-split-string value splitre
))))
2723 ((equal key
"PRI_TODO")
2725 kwds
(append kwds
(org-split-string value splitre
))))
2726 ((equal key
"TYP_TODO")
2728 kwds
(append kwds
(org-split-string value splitre
))))
2730 (setq tags
(append tags
(org-split-string value splitre
))))
2731 ((equal key
"STARTUP")
2732 (let ((opts (org-split-string value splitre
))
2733 (set '(("fold" org-startup-folded t
)
2734 ("overview" org-startup-folded t
)
2735 ("nofold" org-startup-folded nil
)
2736 ("showall" org-startup-folded nil
)
2737 ("content" org-startup-folded content
)
2738 ("hidestars" org-hide-leading-stars t
)
2739 ("showstars" org-hide-leading-stars nil
)
2740 ("odd" org-odd-levels-only t
)
2741 ("oddeven" org-odd-levels-only nil
)
2742 ("align" org-startup-align-all-tables t
)
2743 ("noalign" org-startup-align-all-tables nil
)
2744 ("logging" org-log-done t
)
2745 ("nologging" org-log-done nil
)
2746 ("dlcheck" org-startup-with-deadline-check t
)
2747 ("nodlcheck" org-startup-with-deadline-check nil
)))
2749 (while (setq l
(assoc (pop opts
) set
))
2750 (setq var
(nth 1 l
) val
(nth 2 l
))
2751 (set (make-local-variable var
) val
))))
2752 ((equal key
"ARCHIVE")
2753 (string-match " *$" value
)
2754 (setq arch
(replace-match "" t t value
))
2755 (remove-text-properties 0 (length arch
)
2756 '(face t fontified t
) arch
)))
2758 (and cat
(set (make-local-variable 'org-category
) cat
))
2759 (and kwds
(set (make-local-variable 'org-todo-keywords
) kwds
))
2760 (and arch
(set (make-local-variable 'org-archive-location
) arch
))
2761 (and int
(set (make-local-variable 'org-todo-interpretation
) int
))
2764 (while (setq e
(pop tags
))
2766 ((equal e
"{") (push '(:startgroup
) tgs
))
2767 ((equal e
"}") (push '(:endgroup
) tgs
))
2768 ((string-match "^\\([0-9a-zA-Z_@]+\\)(\\(.\\))$" e
)
2769 (push (cons (match-string 1 e
)
2770 (string-to-char (match-string 2 e
)))
2772 (t (push (list e
) tgs
))))
2773 (set (make-local-variable 'org-tag-alist
) nil
)
2774 (while (setq e
(pop tgs
))
2775 (or (and (stringp (car e
))
2776 (assoc (car e
) org-tag-alist
))
2777 (push e org-tag-alist
))))))
2779 ;; Compute the regular expressions and other local variables
2780 (setq org-todo-kwd-priority-p
(equal org-todo-interpretation
'priority
)
2781 org-todo-kwd-max-priority
(1- (length org-todo-keywords
))
2782 org-ds-keyword-length
(+ 2 (max (length org-deadline-string
)
2783 (length org-scheduled-string
)))
2785 (nth (1- (length org-todo-keywords
)) org-todo-keywords
)
2787 (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords
2791 (mapconcat 'regexp-quote
2792 (nreverse (cdr (reverse org-todo-keywords
)))
2795 org-todo-line-regexp
2796 (concat "^\\(\\*+\\)[ \t]*\\("
2797 (mapconcat 'regexp-quote org-todo-keywords
"\\|")
2800 (concat "[\r\n]\\*+[ \t]+" org-done-string
"\\>")
2801 org-todo-line-tags-regexp
2802 (concat "^\\(\\*+\\)[ \t]*\\("
2803 (mapconcat 'regexp-quote org-todo-keywords
"\\|")
2804 "\\)? *\\(.*?\\([ \t]:[a-zA-Z0-9:_@]+:[ \t]*\\)?$\\)")
2805 org-looking-at-done-regexp
(concat "^" org-done-string
"\\>")
2806 org-deadline-regexp
(concat "\\<" org-deadline-string
)
2807 org-deadline-time-regexp
2808 (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>")
2809 org-deadline-line-regexp
2810 (concat "\\<\\(" org-deadline-string
"\\).*")
2811 org-scheduled-regexp
2812 (concat "\\<" org-scheduled-string
)
2813 org-scheduled-time-regexp
2814 (concat "\\<" org-scheduled-string
" *<\\([^>]+\\)>")
2815 org-closed-time-regexp
2816 (concat "\\<" org-closed-string
" *\\[\\([^]]+\\)\\]")
2817 org-keyword-time-regexp
2818 (concat "\\<\\(" org-scheduled-string
2819 "\\|" org-deadline-string
2820 "\\|" org-closed-string
2821 "\\|" org-clock-string
"\\)"
2822 " *[[<]\\([^]>]+\\)[]>]")
2823 org-maybe-keyword-time-regexp
2824 (concat "\\(\\<\\(" org-scheduled-string
2825 "\\|" org-deadline-string
2826 "\\|" org-closed-string
2827 "\\|" org-clock-string
"\\)\\)?"
2828 " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}[^]\r\n>]*?[]>]\\)"))
2830 (org-set-font-lock-defaults)))
2832 ;; Tell the compiler about dynamically scoped variables,
2833 ;; and variables from other packages
2834 (defvar calc-embedded-close-formula
) ; defined by the calc package
2835 (defvar calc-embedded-open-formula
) ; defined by the calc package
2836 (defvar font-lock-unfontify-region-function
) ; defined by font-lock.el
2837 (defvar zmacs-regions
) ; XEmacs regions
2838 (defvar original-date
) ; dynamically scoped in calendar
2839 (defvar org-old-auto-fill-inhibit-regexp
) ; local variable used by `orgtbl-mode'
2840 (defvar orgtbl-mode-menu
) ; defined when orgtbl mode get initialized
2841 (defvar org-html-entities
) ; defined later in this file
2842 (defvar org-goto-start-pos
) ; dynamically scoped parameter
2843 (defvar org-time-was-given
) ; dynamically scoped parameter
2844 (defvar org-ts-what
) ; dynamically scoped parameter
2845 (defvar org-current-export-file
) ; dynamically scoped parameter
2846 (defvar org-current-export-dir
) ; dynamically scoped parameter
2847 (defvar mark-active
) ; Emacs only, not available in XEmacs.
2848 (defvar timecnt
) ; dynamically scoped parameter
2849 (defvar levels-open
) ; dynamically scoped parameter
2850 (defvar entry
) ; dynamically scoped parameter
2851 (defvar state
) ; dynamically scoped into `org-after-todo-state-change-hook'
2852 (defvar date
) ; dynamically scoped parameter
2853 (defvar description
) ; dynamically scoped parameter
2854 (defvar ans1
) ; dynamically scoped parameter
2855 (defvar ans2
) ; dynamically scoped parameter
2856 (defvar starting-day
) ; local variable
2857 (defvar include-all-loc
) ; local variable
2858 (defvar vm-message-pointer
) ; from vm
2859 (defvar vm-folder-directory
) ; from vm
2860 (defvar wl-summary-buffer-elmo-folder
) ; from wanderlust
2861 (defvar wl-summary-buffer-folder-name
) ; from wanderlust
2862 (defvar gnus-group-name
) ; from gnus
2863 (defvar gnus-article-current
) ; from gnus
2864 (defvar w3m-current-url
) ; from w3m
2865 (defvar w3m-current-title
) ; from w3m
2866 (defvar mh-progs
) ; from MH-E
2867 (defvar mh-current-folder
) ; from MH-E
2868 (defvar mh-show-folder-buffer
) ; from MH-E
2869 (defvar mh-index-folder
) ; from MH-E
2870 (defvar mh-searcher
) ; from MH-E
2871 (defvar org-selected-point
) ; dynamically scoped parameter
2872 (defvar calendar-mode-map
) ; from calendar.el
2873 (defvar last-arg
) ; local variable
2874 (defvar remember-save-after-remembering
) ; from remember.el
2875 (defvar remember-data-file
) ; from remember.el
2876 (defvar annotation
) ; from remember.el, dynamically scoped in `remember-mode'
2877 (defvar initial
) ; from remember.el, dynamically scoped in `remember-mode'
2878 (defvar orgtbl-mode
) ; defined later in this file
2879 (defvar Info-current-file
) ; from info.el
2880 (defvar Info-current-node
) ; from info.el
2881 (defvar texmathp-why
) ; from texmathp.el
2882 (defvar org-latex-regexps
)
2886 (defvar org-mode-map
2887 (if (and (not (keymapp outline-mode-map
)) (featurep 'allout
))
2888 (error "Conflict with outdated version of allout.el. Load org.el before allout.el, or ugrade to newer allout, for example by switching to Emacs 22.")
2889 (copy-keymap outline-mode-map
))
2890 "Keymap for Org-mode.")
2892 (defvar org-struct-menu
) ; defined later in this file
2893 (defvar org-org-menu
) ; defined later in this file
2894 (defvar org-tbl-menu
) ; defined later in this file
2896 ;; We use a before-change function to check if a table might need
2898 (defvar org-table-may-need-update t
2899 "Indicates that a table might need an update.
2900 This variable is set by `org-before-change-function'.
2901 `org-table-align' sets it back to nil.")
2902 (defvar org-mode-hook nil
)
2903 (defvar org-inhibit-startup nil
) ; Dynamically-scoped param.
2904 (defvar org-agenda-keep-modes nil
) ; Dynamically-scoped param.
2908 (define-derived-mode org-mode outline-mode
"Org"
2909 "Outline-based notes management and organizer, alias
2910 \"Carsten's outline-mode for keeping track of everything.\"
2912 Org-mode develops organizational tasks around a NOTES file which
2913 contains information about projects as plain text. Org-mode is
2914 implemented on top of outline-mode, which is ideal to keep the content
2915 of large files well structured. It supports ToDo items, deadlines and
2916 time stamps, which magically appear in the diary listing of the Emacs
2917 calendar. Tables are easily created with a built-in table editor.
2918 Plain text URL-like links connect to websites, emails (VM), Usenet
2919 messages (Gnus), BBDB entries, and any files related to the project.
2920 For printing and sharing of notes, an Org-mode file (or a part of it)
2921 can be exported as a structured ASCII or HTML file.
2923 The following commands are available:
2927 ;; Get rid of Outline menus, they are not needed
2928 ;; Need to do this here because define-derived-mode sets up
2929 ;; the keymap so late.
2930 (if (featurep 'xemacs
)
2933 (easy-menu-remove outline-mode-menu-heading
)
2934 (easy-menu-remove outline-mode-menu-show
)
2935 (easy-menu-remove outline-mode-menu-hide
))
2936 (delete-menu-item '("Headings"))
2937 (delete-menu-item '("Show"))
2938 (delete-menu-item '("Hide"))
2939 (set-menubar-dirty-flag))
2940 (define-key org-mode-map
[menu-bar headings
] 'undefined
)
2941 (define-key org-mode-map
[menu-bar hide
] 'undefined
)
2942 (define-key org-mode-map
[menu-bar show
] 'undefined
))
2944 (easy-menu-add org-org-menu
)
2945 (easy-menu-add org-tbl-menu
)
2946 (org-install-agenda-files-menu)
2947 (if org-descriptive-links
(org-add-to-invisibility-spec '(org-link)))
2948 (org-add-to-invisibility-spec '(org-cwidth))
2949 (when (featurep 'xemacs
)
2950 (set (make-local-variable 'line-move-ignore-invisible
) t
))
2951 (setq outline-regexp
"\\*+")
2952 ;;(setq outline-regexp "\\(?:\\*+\\|[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\) \\)")
2953 (setq outline-level
'org-outline-level
)
2954 (when (and org-ellipsis
(stringp org-ellipsis
))
2955 (unless org-display-table
2956 (setq org-display-table
(make-display-table)))
2957 (set-display-table-slot org-display-table
2958 4 (string-to-vector org-ellipsis
))
2959 (setq buffer-display-table org-display-table
))
2960 (org-set-regexps-and-options)
2961 (modify-syntax-entry ?
# "<")
2962 (if org-startup-truncated
(setq truncate-lines t
))
2963 (set (make-local-variable 'font-lock-unfontify-region-function
)
2964 'org-unfontify-region
)
2965 ;; Activate before-change-function
2966 (set (make-local-variable 'org-table-may-need-update
) t
)
2967 (org-add-hook 'before-change-functions
'org-before-change-function nil
2969 ;; Check for running clock before killing a buffer
2970 (org-add-hook 'kill-buffer-hook
'org-check-running-clock nil
'local
)
2971 ;; Paragraphs and auto-filling
2972 (org-set-autofill-regexps)
2973 (org-update-radio-target-regexp)
2975 (if (and org-insert-mode-line-in-empty-file
2977 (= (point-min) (point-max)))
2978 (insert " -*- mode: org -*-\n\n"))
2980 (unless org-inhibit-startup
2981 (when org-startup-align-all-tables
2982 (let ((bmp (buffer-modified-p)))
2983 (org-table-map-tables 'org-table-align
)
2984 (set-buffer-modified-p bmp
)))
2985 (if org-startup-with-deadline-check
2986 (call-interactively 'org-check-deadlines
)
2988 ((eq org-startup-folded t
)
2990 ((eq org-startup-folded
'content
)
2991 (let ((this-command 'org-cycle
) (last-command 'org-cycle
))
2992 (org-cycle '(4)) (org-cycle '(4))))))))
2994 (defsubst org-call-with-arg
(command arg
)
2995 "Call COMMAND interactively, but pretend prefix are was ARG."
2996 (let ((current-prefix-arg arg
)) (call-interactively command
)))
2998 (defsubst org-current-line
(&optional pos
)
2999 (+ (if (bolp) 1 0) (count-lines (point-min) (or pos
(point)))))
3001 (defun org-current-time ()
3002 "Current time, possibly rounded to `org-time-stamp-rounding-minutes'."
3003 (if (> org-time-stamp-rounding-minutes
0)
3004 (let ((r org-time-stamp-rounding-minutes
)
3005 (time (decode-time)))
3007 (append (list 0 (* r
(floor (+ .5 (/ (float (nth 1 time
)) r
)))))
3011 (defun org-add-props (string plist
&rest props
)
3012 "Add text properties to entire string, from beginning to end.
3013 PLIST may be a list of properties, PROPS are individual properties and values
3014 that will be added to PLIST. Returns the string that was modified."
3015 (add-text-properties
3016 0 (length string
) (if props
(append plist props
) plist
) string
)
3018 (put 'org-add-props
'lisp-indent-function
2)
3023 (defvar org-mouse-map
(make-sparse-keymap))
3024 (define-key org-mouse-map
3025 (if (featurep 'xemacs
) [button2] [mouse-2]) 'org-open-at-mouse)
3026 (define-key org-mouse-map
3027 (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse)
3028 (when org-mouse-1-follows-link
3029 (define-key org-mouse-map [follow-link] 'mouse-face))
3030 (when org-tab-follows-link
3031 (define-key org-mouse-map [(tab)] 'org-open-at-point)
3032 (define-key org-mouse-map "\C-i" 'org-open-at-point))
3033 (when org-return-follows-link
3034 (define-key org-mouse-map [(return)] 'org-open-at-point)
3035 (define-key org-mouse-map "\C-m" 'org-open-at-point))
3037 (require 'font-lock)
3039 (defconst org-non-link-chars "]\t\n\r<>")
3040 (defconst org-link-types '("https?" "ftp" "mailto" "file" "news" "bbdb" "vm"
3041 "wl" "mhe" "rmail" "gnus" "shell" "info" "elisp"))
3042 (defconst org-link-re-with-space
3044 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3045 "\\([^" org-non-link-chars " ]"
3046 "[^" org-non-link-chars "]*"
3047 "[^" org-non-link-chars " ]\\)>?")
3048 "Matches a link with spaces, optional angular brackets around it.")
3050 (defconst org-link-re-with-space2
3052 "<?\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3053 "\\([^" org-non-link-chars " ]"
3055 "[^" org-non-link-chars " ]\\)>?")
3056 "Matches a link with spaces, optional angular brackets around it.")
3058 (defconst org-angle-link-re
3060 "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3061 "\\([^" org-non-link-chars " ]"
3062 "[^" org-non-link-chars "]*"
3064 "Matches link with angular brackets, spaces are allowed.")
3065 (defconst org-plain-link-re
3067 "\\(" (mapconcat 'identity org-link-types "\\|") "\\):"
3068 "\\([^]\t\n\r<>,;() ]+\\)")
3069 "Matches plain link, without spaces.")
3071 (defconst org-bracket-link-regexp
3072 "\\[\\[\\([^]]+\\)\\]\\(\\[\\([^]]+\\)\\]\\)?\\]"
3073 "Matches a link in double brackets.")
3075 (defconst org-bracket-link-analytic-regexp
3078 "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?"
3081 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
3090 (defconst org-ts-lengths
3091 (cons (length (format-time-string (car org-time-stamp-formats)))
3092 (length (format-time-string (cdr org-time-stamp-formats))))
3093 "This holds the lengths of the two different time formats.")
3094 (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}[^\r\n>]*?\\)>"
3095 "Regular expression for fast time stamp matching.")
3096 (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}[^\r\n>]*?\\)[]>]"
3097 "Regular expression for fast time stamp matching.")
3098 (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\([^]0-9>\r\n]*\\)\\(\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
3099 "Regular expression matching time strings for analysis.")
3100 (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 ">")
3101 "Regular expression matching time stamps, with groups.")
3102 (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[]>]")
3103 "Regular expression matching time stamps (also [..]), with groups.")
3104 (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
3105 "Regular expression matching a time stamp range.")
3106 (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
3107 org-ts-regexp "\\)?")
3108 "Regular expression matching a time stamp or time stamp range.")
3110 (defvar org-§emph-face nil)
3112 (defun org-do-emphasis-faces (limit)
3113 "Run through the buffer and add overlays to links."
3114 (if (re-search-forward org-emph-re limit t)
3116 (font-lock-prepend-text-property (match-beginning 2) (match-end 2)
3118 (nth 1 (assoc (match-string 3)
3119 org-emphasis-alist)))
3120 (add-text-properties (match-beginning 2) (match-end 2)
3121 '(font-lock-multiline t))
3125 (defun org-activate-plain-links (limit)
3126 "Run through the buffer and add overlays to links."
3127 (if (re-search-forward org-plain-link-re limit t)
3129 (add-text-properties (match-beginning 0) (match-end 0)
3130 (list 'mouse-face 'highlight
3131 'keymap org-mouse-map
3135 (defun org-activate-angle-links (limit)
3136 "Run through the buffer and add overlays to links."
3137 (if (re-search-forward org-angle-link-re limit t)
3139 (add-text-properties (match-beginning 0) (match-end 0)
3140 (list 'mouse-face 'highlight
3141 'keymap org-mouse-map
3145 (defun org-activate-bracket-links (limit)
3146 "Run through the buffer and add overlays to bracketed links."
3147 (if (re-search-forward org-bracket-link-regexp limit t)
3148 (let* ((help (concat "LINK: "
3149 (org-match-string-no-properties 1)))
3150 ;; FIXME: above we should remove the escapes.
3151 ;; but that requires another match, protecting match data,
3152 ;; a lot of overhead for font-lock.
3153 (ip (list 'invisible 'org-link 'intangible t 'rear-nonsticky t
3154 'keymap org-mouse-map 'mouse-face 'highlight
3156 (vp (list 'rear-nonsticky t
3157 'keymap org-mouse-map 'mouse-face 'highlight
3159 ;; We need to remove the invisible property here. Table narrowing
3160 ;; may have made some of this invisible.
3161 (remove-text-properties (match-beginning 0) (match-end 0)
3165 (add-text-properties (match-beginning 0) (match-beginning 3) ip)
3166 (add-text-properties (match-beginning 3) (match-end 3) vp)
3167 (add-text-properties (match-end 3) (match-end 0) ip))
3168 (add-text-properties (match-beginning 0) (match-beginning 1) ip)
3169 (add-text-properties (match-beginning 1) (match-end 1) vp)
3170 (add-text-properties (match-end 1) (match-end 0) ip))
3173 (defun org-activate-dates (limit)
3174 "Run through the buffer and add overlays to dates."
3175 (if (re-search-forward org-tsr-regexp limit t)
3177 (add-text-properties (match-beginning 0) (match-end 0)
3178 (list 'mouse-face 'highlight
3179 'keymap org-mouse-map))
3182 (defvar org-target-link-regexp nil
3183 "Regular expression matching radio targets in plain text.")
3184 (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>"
3185 "Regular expression matching a link target.")
3186 (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>"
3187 "Regular expression matching a link target.")
3189 (defun org-activate-target-links (limit)
3190 "Run through the buffer and add overlays to target matches."
3191 (when org-target-link-regexp
3192 (let ((case-fold-search t))
3193 (if (re-search-forward org-target-link-regexp limit t)
3195 (add-text-properties (match-beginning 0) (match-end 0)
3196 (list 'mouse-face 'highlight
3197 'keymap org-mouse-map
3198 'help-echo "Radio target link"
3199 'org-linked-text t))
3202 (defun org-update-radio-target-regexp ()
3203 "Find all radio targets in this file and update the regular expression."
3205 (when (memq 'radio org-activate-links)
3206 (setq org-target-link-regexp
3207 (org-make-target-link-regexp (org-all-targets 'radio)))
3208 (org-restart-font-lock)))
3210 (defun org-hide-wide-columns (limit)
3212 (setq s (text-property-any (point) (or limit (point-max))
3215 (setq e (next-single-property-change s 'org-cwidth))
3216 (add-text-properties s e '(invisible org-cwidth intangible t))
3220 (defun org-restart-font-lock ()
3221 "Restart font-lock-mode, to force refontification."
3222 (when (and (boundp 'font-lock-mode) font-lock-mode)
3224 (font-lock-mode 1)))
3226 (defun org-all-targets (&optional radio)
3227 "Return a list of all targets in this file.
3228 With optional argument RADIO, only find radio targets."
3229 (let ((re (if radio org-radio-target-regexp org-target-regexp))
3232 (goto-char (point-min))
3233 (while (re-search-forward re nil t)
3234 (add-to-list 'rtn (downcase (org-match-string-no-properties 1))))
3237 (defun org-make-target-link-regexp (targets)
3238 "Make regular expression matching all strings in TARGETS.
3239 The regular expression finds the targets also if there is a line break
3246 (while (string-match " +" x)
3247 (setq x (replace-match "\\s-+" t t x)))
3253 (defvar org-camel-regexp "\\*?\\<[A-Z]+[a-z]+[A-Z][a-zA-Z]*\\>"
3254 "Matches CamelCase words, possibly with a star before it.")
3256 (defun org-activate-camels (limit)
3257 "Run through the buffer and add overlays to dates."
3258 (if (re-search-forward org-camel-regexp limit t)
3260 (add-text-properties (match-beginning 0) (match-end 0)
3261 (list 'mouse-face 'highlight
3262 'keymap org-mouse-map))
3265 (defun org-activate-tags (limit)
3266 (if (re-search-forward "[ \t]\\(:[A-Za-z_@0-9:]+:\\)[ \r\n]" limit t)
3268 (add-text-properties (match-beginning 1) (match-end 1)
3269 (list 'mouse-face 'highlight
3270 'keymap org-mouse-map))
3273 (defun org-font-lock-level ()
3275 (org-back-to-heading t)
3276 (- (match-end 0) (match-beginning 0))))
3278 (defun org-outline-level ()
3280 (looking-at outline-regexp)
3281 (if (match-beginning 1)
3282 (+ (org-get-string-indentation (match-string 1)) 1000)
3283 (- (match-end 0) (match-beginning 0)))))
3285 (defvar org-font-lock-keywords nil)
3287 (defun org-set-font-lock-defaults ()
3288 (let* ((em org-fontify-emphasized-text)
3289 (lk org-activate-links)
3290 (org-font-lock-extra-keywords
3293 '("^\\(\\**\\)\\(\\*\\)\\(.*\\)" (1 (org-get-level-face 1))
3294 (2 (org-get-level-face 2)) (3 (org-get-level-face 3)))
3295 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
3298 (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
3299 (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
3300 (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
3301 (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
3302 (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
3303 (if (memq 'camel lk) '(org-activate-camels (0 'org-link t)))
3304 (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
3305 (if org-table-limit-column-width
3306 '(org-hide-wide-columns (0 nil append)))
3308 (list (concat "^\\*+[ \t]*" org-not-done-regexp)
3311 (list (concat "\\[#[A-Z]\\]") '(0 'org-special-keyword t))
3313 (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
3314 (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
3315 (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
3316 (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
3318 (if em '(org-do-emphasis-faces))
3319 ;; Checkboxes, similar to Frank Ruell's org-checklet.el
3320 '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[ X]\\]\\)"
3323 (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string
3324 "\\|" org-quote-string "\\)\\>")
3325 '(1 'org-special-keyword t))
3326 '("^#.*" (0 'font-lock-comment-face t))
3328 (if org-fontify-done-headline
3329 (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\(.*\\)\\>")
3330 '(1 'org-done t) '(2 'org-headline-done t))
3331 (list (concat "^[*]+ +\\<\\(" org-done-string "\\)\\>")
3334 '("^[ \t]*\\(:.*\\)" (1 'org-table t))
3335 '("| *\\(:?=[^|\n]*\\)" (1 'org-formula t))
3336 '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t))
3337 (if org-format-transports-properties-p
3338 '("| *\\(<[0-9]+>\\) *" (1 'org-formula t)))
3339 '("^\\*+ \\(.*:ARCHIVE:.*\\)" (1 'org-archived prepend))
3341 (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
3342 ;; Now set the full font-lock-keywords
3343 (set (make-local-variable 'org-font-lock-keywords)
3344 org-font-lock-extra-keywords)
3345 (set (make-local-variable 'font-lock-defaults)
3346 '(org-font-lock-keywords t nil nil backward-paragraph))
3347 (kill-local-variable 'font-lock-keywords) nil))
3352 (defun org-get-level-face (n)
3353 "Get the right face for match N in font-lock matching of healdines."
3354 (setq org-l (- (match-end 2) (match-beginning 1)))
3355 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
3356 ; (setq org-f (nth (1- (% org-l org-n-levels)) org-level-faces))
3357 (setq org-f (nth (% (1- org-l) org-n-levels) org-level-faces))
3359 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
3361 (t (if org-level-color-stars-only nil org-f))))
3363 (defun org-unfontify-region (beg end &optional maybe_loudly)
3364 "Remove fontification and activation overlays from links."
3365 (font-lock-default-unfontify-region beg end)
3366 (let* ((buffer-undo-list t)
3367 (inhibit-read-only t) (inhibit-point-motion-hooks t)
3368 (inhibit-modification-hooks t)
3369 deactivate-mark buffer-file-name buffer-file-truename)
3370 (remove-text-properties beg end
3371 '(mouse-face nil keymap nil org-linked-text nil
3372 invisible nil intangible nil))))
3373 ;;; Visibility cycling
3375 (defvar org-cycle-global-status nil)
3376 (make-variable-buffer-local 'org-cycle-global-status)
3377 (defvar org-cycle-subtree-status nil)
3378 (make-variable-buffer-local 'org-cycle-subtree-status)
3381 (defun org-cycle (&optional arg)
3382 "Visibility cycling for Org-mode.
3384 - When this function is called with a prefix argument, rotate the entire
3385 buffer through 3 states (global cycling)
3386 1. OVERVIEW: Show only top-level headlines.
3387 2. CONTENTS: Show all headlines of all levels, but no body text.
3388 3. SHOW ALL: Show everything.
3390 - When point is at the beginning of a headline, rotate the subtree started
3391 by this line through 3 different states (local cycling)
3392 1. FOLDED: Only the main headline is shown.
3393 2. CHILDREN: The main headline and the direct children are shown.
3394 From this state, you can move to one of the children
3395 and zoom in further.
3396 3. SUBTREE: Show the entire subtree, including body text.
3398 - When there is a numeric prefix, go up to a heading with level ARG, do
3399 a `show-subtree' and return to the previous cursor position. If ARG
3400 is negative, go up that many levels.
3402 - When point is not at the beginning of a headline, execute
3403 `indent-relative', like TAB normally does. See the option
3404 `org-cycle-emulate-tab' for details.
3406 - Special case: if point is the the beginning of the buffer and there is
3407 no headline in line 1, this function will act as if called with prefix arg."
3410 (let* ((outline-regexp
3411 (if org-cycle-include-plain-lists
3412 "\\*+\\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) "
3414 (bob-special (and org-cycle-global-at-bob (bobp)
3415 (not (looking-at outline-regexp))))
3418 (delq 'org-optimize-window-after-visibility-change
3419 (copy-sequence org-cycle-hook))
3423 (if (or bob-special (equal arg '(4)))
3424 ;; special case: use global cycling
3429 ((org-at-table-p 'any)
3430 ;; Enter the table or move to the next field in the table
3431 (or (org-table-recognize-table.el)
3433 (if arg (org-table-edit-field t)
3434 (org-table-justify-field-maybe)
3435 (call-interactively 'org-table-next-field)))))
3437 ((eq arg t) ;; Global cycling
3440 ((and (eq last-command this-command)
3441 (eq org-cycle-global-status 'overview))
3442 ;; We just created the overview - now do table of contents
3443 ;; This can be slow in very large buffers, so indicate action
3444 (message "CONTENTS...")
3446 (message "CONTENTS...done")
3447 (setq org-cycle-global-status 'contents)
3448 (run-hook-with-args 'org-cycle-hook 'contents))
3450 ((and (eq last-command this-command)
3451 (eq org-cycle-global-status 'contents))
3452 ;; We just showed the table of contents - now show everything
3454 (message "SHOW ALL")
3455 (setq org-cycle-global-status 'all)
3456 (run-hook-with-args 'org-cycle-hook 'all))
3459 ;; Default action: go to overview
3461 (message "OVERVIEW")
3462 (setq org-cycle-global-status 'overview)
3463 (run-hook-with-args 'org-cycle-hook 'overview))))
3466 ;; Show-subtree, ARG levels up from here.
3468 (org-back-to-heading)
3469 (outline-up-heading (if (< arg 0) (- arg)
3470 (- (funcall outline-level) arg)))
3471 (org-show-subtree)))
3473 ((save-excursion (beginning-of-line 1) (looking-at outline-regexp))
3474 ;; At a heading: rotate between three different views
3475 (org-back-to-heading)
3476 (let ((goal-column 0) eoh eol eos)
3477 ;; First, some boundaries
3479 (org-back-to-heading)
3481 (beginning-of-line 2)
3482 (while (and (not (eobp)) ;; this is like `next-line'
3483 (get-char-property (1- (point)) 'invisible))
3484 (beginning-of-line 2)) (setq eol (point)))
3485 (outline-end-of-heading) (setq eoh (point))
3486 (org-end-of-subtree t) (setq eos (point))
3487 (outline-next-heading))
3488 ;; Find out what to do next and set `this-command'
3491 ;; Nothing is hidden behind this heading
3492 (message "EMPTY ENTRY")
3493 (setq org-cycle-subtree-status nil)))
3495 ;; Entire subtree is hidden in one line: open it
3498 (message "CHILDREN")
3499 (setq org-cycle-subtree-status 'children)
3500 (run-hook-with-args 'org-cycle-hook 'children))
3501 ((and (eq last-command this-command)
3502 (eq org-cycle-subtree-status 'children))
3503 ;; We just showed the children, now show everything.
3506 (setq org-cycle-subtree-status 'subtree)
3507 (run-hook-with-args 'org-cycle-hook 'subtree))
3509 ;; Default action: hide the subtree.
3512 (setq org-cycle-subtree-status 'folded)
3513 (run-hook-with-args 'org-cycle-hook 'folded)))))
3516 (buffer-read-only (org-back-to-heading))
3518 ((org-try-cdlatex-tab))
3520 ((if (and (memq org-cycle-emulate-tab '(white whitestart))
3521 (save-excursion (beginning-of-line 1) (looking-at "[ \t]*"))
3522 (or (and (eq org-cycle-emulate-tab 'white)
3523 (= (match-end 0) (point-at-eol)))
3524 (and (eq org-cycle-emulate-tab 'whitestart)
3525 (>= (match-end 0) pos))))
3527 (eq org-cycle-emulate-tab t))
3528 (if (and (looking-at "[ \n\r\t]")
3529 (string-match "^[ \t]*$" (buffer-substring
3530 (point-at-bol) (point))))
3532 (beginning-of-line 1)
3533 (and (looking-at "[ \t]+") (replace-match ""))))
3537 (org-back-to-heading)
3541 (defun org-global-cycle (&optional arg)
3542 "Cycle the global visibility. For details see `org-cycle'."
3547 (hide-sublevels arg)
3548 (setq org-cycle-global-status 'contents))
3551 (defun org-overview ()
3552 "Switch to overview mode, shoing only top-level headlines.
3553 Really, this shows all headlines with level equal or greater than the level
3554 of the first headline in the buffer. This is important, because if the
3555 first headline is not level one, then (hide-sublevels 1) gives confusing
3558 (hide-sublevels (save-excursion
3559 (goto-char (point-min))
3560 (if (re-search-forward (concat "^" outline-regexp) nil t)
3562 (goto-char (match-beginning 0))
3563 (funcall outline-level))
3566 ;; FIXME: allow an argument to give a limiting level for this.
3567 (defun org-content ()
3568 "Show all headlines in the buffer, like a table of contents"
3571 ;; Visit all headings and show their offspring
3572 (goto-char (point-max))
3574 (while (and (progn (condition-case nil
3575 (outline-previous-visible-heading 1)
3576 (error (goto-char (point-min))))
3578 (looking-at outline-regexp))
3580 (if (bobp) (throw 'exit nil))))))
3583 (defun org-optimize-window-after-visibility-change (state)
3584 "Adjust the window after a change in outline visibility.
3585 This function is the default value of the hook `org-cycle-hook'."
3586 (when (get-buffer-window (current-buffer))
3588 ((eq state 'overview) (org-first-headline-recenter 1))
3589 ((eq state 'content) nil)
3590 ((eq state 'all) nil)
3591 ((eq state 'folded) nil)
3592 ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1)))
3593 ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1))))))
3595 (defun org-subtree-end-visible-p ()
3596 "Is the end of the current subtree visible?"
3597 (pos-visible-in-window-p
3598 (save-excursion (org-end-of-subtree t) (point))))
3600 (defun org-first-headline-recenter (&optional N)
3601 "Move cursor to the first headline and recenter the headline.
3602 Optional argument N means, put the headline into the Nth line of the window."
3603 (goto-char (point-min))
3604 (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t)
3606 (recenter (prefix-numeric-value N))))
3608 (defvar org-goto-window-configuration nil)
3609 (defvar org-goto-marker nil)
3610 (defvar org-goto-map (make-sparse-keymap))
3611 (let ((cmds '(isearch-forward isearch-backward)) cmd)
3612 (while (setq cmd (pop cmds))
3613 (substitute-key-definition cmd cmd org-goto-map global-map)))
3614 (define-key org-goto-map "\C-m" 'org-goto-ret)
3615 (define-key org-goto-map [(left)] 'org-goto-left)
3616 (define-key org-goto-map [(right)] 'org-goto-right)
3617 (define-key org-goto-map [(?q)] 'org-goto-quit)
3618 (define-key org-goto-map [(control ?g)] 'org-goto-quit)
3619 (define-key org-goto-map "\C-i" 'org-cycle)
3620 (define-key org-goto-map [(tab)] 'org-cycle)
3621 (define-key org-goto-map [(down)] 'outline-next-visible-heading)
3622 (define-key org-goto-map [(up)] 'outline-previous-visible-heading)
3623 (define-key org-goto-map "n" 'outline-next-visible-heading)
3624 (define-key org-goto-map "p" 'outline-previous-visible-heading)
3625 (define-key org-goto-map "f" 'outline-forward-same-level)
3626 (define-key org-goto-map "b" 'outline-backward-same-level)
3627 (define-key org-goto-map "u" 'outline-up-heading)
3628 (define-key org-goto-map "\C-c\C-n" 'outline-next-visible-heading)
3629 (define-key org-goto-map "\C-c\C-p" 'outline-previous-visible-heading)
3630 (define-key org-goto-map "\C-c\C-f" 'outline-forward-same-level)
3631 (define-key org-goto-map "\C-c\C-b" 'outline-backward-same-level)
3632 (define-key org-goto-map "\C-c\C-u" 'outline-up-heading)
3633 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
3634 (while l (define-key org-goto-map (int-to-string (pop l)) 'digit-argument)))
3636 (defconst org-goto-help
3637 "Select a location to jump to, press RET
3638 \[Up]/[Down]=next/prev headline TAB=cycle visibility RET=select [Q]uit")
3641 "Go to a different location of the document, keeping current visibility.
3643 When you want to go to a different location in a document, the fastest way
3644 is often to fold the entire buffer and then dive into the tree. This
3645 method has the disadvantage, that the previous location will be folded,
3646 which may not be what you want.
3648 This command works around this by showing a copy of the current buffer in
3649 overview mode. You can dive into the tree in that copy, to find the
3650 location you want to reach. When pressing RET, the command returns to the
3651 original buffer in which the visibility is still unchanged. It then jumps
3652 to the new location, making it and the headline hierarchy above it visible."
3654 (let* ((org-goto-start-pos (point))
3656 (org-get-location (current-buffer) org-goto-help)))
3659 (org-mark-ring-push org-goto-start-pos)
3660 (goto-char selected-point)
3661 (if (or (org-invisible-p) (org-invisible-p2))
3662 (org-show-hierarchy-above)))
3665 (defun org-get-location (buf help)
3666 "Let the user select a location in the Org-mode buffer BUF.
3667 This function uses a recursive edit. It returns the selected position
3669 (let (org-selected-point)
3671 (save-window-excursion
3672 (delete-other-windows)
3673 (switch-to-buffer (get-buffer-create "*org-goto*"))
3674 (with-output-to-temp-buffer "*Help*"
3676 (shrink-window-if-larger-than-buffer (get-buffer-window "*Help*"))
3677 (setq buffer-read-only nil)
3679 (insert-buffer-substring buf)
3680 (let ((org-startup-truncated t)
3681 (org-startup-folded t)
3682 (org-startup-align-all-tables nil)
3683 (org-startup-with-deadline-check nil))
3685 (setq buffer-read-only t)
3686 (if (boundp 'org-goto-start-pos)
3687 (goto-char org-goto-start-pos)
3688 (goto-char (point-min)))
3689 (org-beginning-of-line)
3690 (message "Select location and press RET")
3691 ;; now we make sure that during selection, ony very few keys work
3692 ;; and that it is impossible to switch to another window.
3693 (let ((gm (current-global-map))
3694 (overriding-local-map org-goto-map))
3697 (use-global-map org-goto-map)
3699 (use-global-map gm)))))
3700 (kill-buffer "*org-goto*")
3701 org-selected-point))
3703 (defun org-goto-ret (&optional arg)
3704 "Finish `org-goto' by going to the new location."
3706 (setq org-selected-point (point)
3707 current-prefix-arg arg)
3710 (defun org-goto-left ()
3711 "Finish `org-goto' by going to the new location."
3713 (if (org-on-heading-p)
3715 (beginning-of-line 1)
3716 (setq org-selected-point (point)
3717 current-prefix-arg (- (match-end 0) (match-beginning 0)))
3719 (error "Not on a heading")))
3721 (defun org-goto-right ()
3722 "Finish `org-goto' by going to the new location."
3724 (if (org-on-heading-p)
3726 (outline-end-of-subtree)
3727 (or (eobp) (forward-char 1))
3728 (setq org-selected-point (point)
3729 current-prefix-arg (- (match-end 0) (match-beginning 0)))
3731 (error "Not on a heading")))
3733 (defun org-goto-quit ()
3734 "Finish `org-goto' without cursor motion."
3736 (setq org-selected-point nil)
3739 ;;; Promotion, Demotion, Inserting new headlines
3741 (defvar org-ignore-region nil
3742 "To temporarily disable the active region.")
3744 (defun org-insert-heading (&optional force-heading)
3745 "Insert a new heading or item with same depth at point.
3746 If point is in a plain list and FORCE-HEADING is nil, create a new list item.
3747 If point is at the beginning of a headline, insert a sibling before the
3748 current headline. If point is in the middle of a headline, split the headline
3749 at that position and make the rest of the headline part of the sibling below
3750 the current headline."
3752 (if (= (buffer-size) 0)
3754 (when (or force-heading (not (org-insert-item)))
3755 (let* ((head (save-excursion
3758 (org-back-to-heading)
3763 ((and (org-on-heading-p) (bolp)
3764 (save-excursion (backward-char 1) (not (org-invisible-p))))
3766 ((and (bolp) (save-excursion
3767 (backward-char 1) (not (org-invisible-p))))
3770 (insert head) (just-one-space)
3773 (unless (= (point) pos) (just-one-space) (backward-delete-char 1))
3774 (run-hooks 'org-insert-heading-hook)))))
3776 (defun org-insert-item (&optional checkbox)
3777 "Insert a new item at the current level.
3778 Return t when things worked, nil when we are not in an item."
3779 (when (save-excursion
3782 (org-beginning-of-item)
3786 (let* ((bul (match-string 0))
3787 (eow (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")
3791 ((and (org-at-item-p) (<= (point) eow))
3792 ;; before the bullet
3793 (beginning-of-line 1)
3796 (beginning-of-line 1))
3798 (insert bul (if checkbox "[ ]" ""))
3802 (unless (= (point) pos) (just-one-space) (backward-delete-char 1)))
3803 (org-maybe-renumber-ordered-list)
3806 (defun org-insert-todo-heading (arg)
3807 "Insert a new heading with the same level and TODO state as current heading.
3808 If the heading has no TODO state, or if the state is DONE, use the first
3809 state (TODO by default). Also with prefix arg, force first state."
3811 (when (not (org-insert-item 'checkbox))
3812 (org-insert-heading)
3814 (org-back-to-heading)
3816 (outline-previous-heading)
3817 (outline-previous-visible-heading t))
3818 (looking-at org-todo-line-regexp))
3820 (not (match-beginning 2))
3821 (equal (match-string 2) org-done-string))
3822 (insert (car org-todo-keywords) " ")
3823 (insert (match-string 2) " "))))
3825 (defun org-promote-subtree ()
3826 "Promote the entire subtree.
3827 See also `org-promote'."
3830 (org-map-tree 'org-promote)))
3832 (defun org-demote-subtree ()
3833 "Demote the entire subtree. See `org-demote'.
3834 See also `org-promote'."
3837 (org-map-tree 'org-demote)))
3839 (defun org-do-promote ()
3840 "Promote the current heading higher up the tree.
3841 If the region is active in `transient-mark-mode', promote all headings
3845 (if (org-region-active-p)
3846 (org-map-region 'org-promote (region-beginning) (region-end))
3848 (org-fix-position-after-promote))
3850 (defun org-do-demote ()
3851 "Demote the current heading lower down the tree.
3852 If the region is active in `transient-mark-mode', demote all headings
3856 (if (org-region-active-p)
3857 (org-map-region 'org-demote (region-beginning) (region-end))
3859 (org-fix-position-after-promote))
3861 (defun org-fix-position-after-promote ()
3862 "Make sure that after pro/demotion cursor position is right."
3863 (and (equal (char-after) ?\ )
3864 (equal (char-before) ?*)
3867 (defun org-get-legal-level (level change)
3868 "Rectify a level change under the influence of `org-odd-levels-only'
3869 LEVEL is a current level, CHANGE is by how much the level should be
3870 modified. Even if CHANGE is nil, LEVEL may be returned modified because
3871 even level numbers will become the next higher odd number."
3872 (if org-odd-levels-only
3873 (cond ((not change) (1+ (* 2 (/ level 2))))
3874 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
3875 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
3876 (max 1 (+ level change))))
3878 (defun org-promote ()
3879 "Promote the current heading higher up the tree.
3880 If the region is active in `transient-mark-mode', promote all headings
3882 (org-back-to-heading t)
3883 (let* ((level (save-match-data (funcall outline-level)))
3884 (up-head (make-string (org-get-legal-level level -1) ?*))
3885 (diff (abs (- level (length up-head)))))
3886 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover"))
3887 (replace-match up-head nil t)
3888 ;; Fixup tag positioning
3889 (and org-auto-align-tags (org-set-tags nil t))
3890 (if org-adapt-indentation (org-fixup-indentation (- diff)))))
3892 (defun org-demote ()
3893 "Demote the current heading lower down the tree.
3894 If the region is active in `transient-mark-mode', demote all headings
3896 (org-back-to-heading t)
3897 (let* ((level (save-match-data (funcall outline-level)))
3898 (down-head (make-string (org-get-legal-level level 1) ?*))
3899 (diff (abs (- level (length down-head)))))
3900 (replace-match down-head nil t)
3901 ;; Fixup tag positioning
3902 (and org-auto-align-tags (org-set-tags nil t))
3903 (if org-adapt-indentation (org-fixup-indentation diff))))
3905 (defun org-map-tree (fun)
3906 "Call FUN for every heading underneath the current one."
3907 (org-back-to-heading)
3908 (let ((level (funcall outline-level)))
3912 (outline-next-heading)
3913 (> (funcall outline-level) level))
3917 (defun org-map-region (fun beg end)
3918 "Call FUN for every heading between BEG and END."
3919 (let ((org-ignore-region t))
3921 (setq end (copy-marker end))
3923 (if (and (re-search-forward (concat "^" outline-regexp) nil t)
3927 (outline-next-heading)
3932 (defun org-fixup-indentation (diff)
3933 "Change the indentation in the current entry by DIFF
3934 However, if any line in the current entry has no indentation, or if it
3935 would end up with no indentation after the change, nothing at all is done."
3937 (let ((end (save-excursion (outline-next-heading)
3939 (prohibit (if (> diff 0)
3941 (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-")))
3943 (unless (save-excursion (re-search-forward prohibit end t))
3944 (while (re-search-forward "^[ \t]+" end t)
3945 (goto-char (match-end 0))
3946 (setq col (current-column))
3947 (if (< diff 0) (replace-match ""))
3948 (indent-to (+ diff col))))
3949 (move-marker end nil))))
3951 ;;; Vertical tree motion, cutting and pasting of subtrees
3953 (defun org-move-subtree-up (&optional arg)
3954 "Move the current subtree up past ARG headlines of the same level."
3956 (org-move-subtree-down (- (prefix-numeric-value arg))))
3958 (defun org-move-subtree-down (&optional arg)
3959 "Move the current subtree down past ARG headlines of the same level."
3961 (setq arg (prefix-numeric-value arg))
3962 (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
3963 'outline-get-last-sibling))
3964 (ins-point (make-marker))
3968 (org-back-to-heading)
3971 (save-excursion (outline-end-of-heading)
3972 (setq folded (org-invisible-p)))
3973 (outline-end-of-subtree))
3974 (outline-next-heading)
3976 ;; Find insertion point, with error handling
3979 (or (and (funcall movfunc) (looking-at outline-regexp))
3980 (progn (goto-char beg)
3981 (error "Cannot move past superior level or buffer limit")))
3982 (setq cnt (1- cnt)))
3984 ;; Moving forward - still need to move over subtree
3985 (progn (outline-end-of-subtree)
3986 (outline-next-heading)
3987 (if (not (or (looking-at (concat "^" outline-regexp))
3990 (move-marker ins-point (point))
3991 (setq txt (buffer-substring beg end))
3992 (delete-region beg end)
3994 (goto-char ins-point)
3995 (if folded (hide-subtree))
3996 (move-marker ins-point nil)))
3998 (defvar org-subtree-clip ""
3999 "Clipboard for cut and paste of subtrees.
4000 This is actually only a copy of the kill, because we use the normal kill
4001 ring. We need it to check if the kill was created by `org-copy-subtree'.")
4003 (defvar org-subtree-clip-folded nil
4004 "Was the last copied subtree folded?
4005 This is used to fold the tree back after pasting.")
4007 (defun org-cut-subtree ()
4008 "Cut the current subtree into the clipboard.
4009 This is a short-hand for marking the subtree and then cutting it."
4011 (org-copy-subtree 'cut))
4013 (defun org-copy-subtree (&optional cut)
4014 "Cut the current subtree into the clipboard.
4015 This is a short-hand for marking the subtree and then copying it.
4016 If CUT is non nil, actually cut the subtree."
4018 (let (beg end folded)
4019 (org-back-to-heading)
4022 (save-excursion (outline-end-of-heading)
4023 (setq folded (org-invisible-p)))
4024 (outline-end-of-subtree))
4025 (if (equal (char-after) ?\n) (forward-char 1))
4029 (setq org-subtree-clip-folded folded)
4030 (if cut (kill-region beg end) (copy-region-as-kill beg end))
4031 (setq org-subtree-clip (current-kill 0))
4032 (message "%s: Subtree with %d characters"
4033 (if cut "Cut" "Copied")
4034 (length org-subtree-clip)))))
4036 (defun org-paste-subtree (&optional level tree)
4037 "Paste the clipboard as a subtree, with modification of headline level.
4038 The entire subtree is promoted or demoted in order to match a new headline
4039 level. By default, the new level is derived from the visible headings
4040 before and after the insertion point, and taken to be the inferior headline
4041 level of the two. So if the previous visible heading is level 3 and the
4042 next is level 4 (or vice versa), level 4 will be used for insertion.
4043 This makes sure that the subtree remains an independent subtree and does
4044 not swallow low level entries.
4046 You can also force a different level, either by using a numeric prefix
4047 argument, or by inserting the heading marker by hand. For example, if the
4048 cursor is after \"*****\", then the tree will be shifted to level 5.
4050 If you want to insert the tree as is, just use \\[yank].
4052 If optional TREE is given, use this text instead of the kill ring."
4054 (unless (org-kill-is-subtree-p tree)
4056 (substitute-command-keys
4057 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
4058 (let* ((txt (or tree (and kill-ring (current-kill 0))))
4059 (^re (concat "^\\(" outline-regexp "\\)"))
4060 (re (concat "\\(" outline-regexp "\\)"))
4061 (^re_ (concat "\\(" outline-regexp "\\)[ \t]*"))
4063 (old-level (if (string-match ^re txt)
4064 (- (match-end 0) (match-beginning 0))
4066 (force-level (cond (level (prefix-numeric-value level))
4068 ^re_ (buffer-substring (point-at-bol) (point)))
4069 (- (match-end 0) (match-beginning 0)))
4071 (previous-level (save-excursion
4074 (outline-previous-visible-heading 1)
4076 (- (match-end 0) (match-beginning 0))
4079 (next-level (save-excursion
4082 (outline-next-visible-heading 1)
4084 (- (match-end 0) (match-beginning 0))
4087 (new-level (or force-level (max previous-level next-level)))
4088 (shift (if (or (= old-level -1)
4090 (= old-level new-level))
4092 (- new-level old-level)))
4094 (delta (if (> shift 0) -1 1))
4095 (func (if (> shift 0) 'org-demote 'org-promote))
4096 (org-odd-levels-only nil)
4098 ;; Remove the forces level indicator
4100 (delete-region (point-at-bol) (point)))
4101 ;; Make sure we start at the beginning of an empty line
4102 (if (not (bolp)) (insert "\n"))
4103 (if (not (looking-at "[ \t]*$"))
4104 (progn (insert "\n") (backward-char 1)))
4107 (if (string-match "[ \t\r\n]+\\'" txt)
4108 (setq txt (replace-match "\n" t t txt)))
4111 (if (looking-at "[ \t\r\n]+")
4112 (replace-match "\n"))
4114 ;; Shift if necessary
4116 (message "Pasted at level %d, without shift" new-level)
4118 (narrow-to-region beg end)
4119 (while (not (= shift 0))
4120 (org-map-region func (point-min) (point-max))
4121 (setq shift (+ delta shift)))
4122 (goto-char (point-min))
4123 (message "Pasted at level %d, with shift by %d levels"
4126 (eq org-subtree-clip (current-kill 0))
4127 org-subtree-clip-folded)
4128 ;; The tree was folded before it was killed/copied
4131 (defun org-kill-is-subtree-p (&optional txt)
4132 "Check if the current kill is an outline subtree, or a set of trees.
4133 Returns nil if kill does not start with a headline, or if the first
4134 headline level is not the largest headline level in the tree.
4135 So this will actually accept several entries of equal levels as well,
4136 which is OK for `org-paste-subtree'.
4137 If optional TXT is given, check this string instead of the current kill."
4138 (let* ((kill (or txt (and kill-ring (current-kill 0)) ""))
4139 (start-level (and kill
4140 (string-match (concat "\\`" outline-regexp) kill)
4141 (- (match-end 0) (match-beginning 0))))
4142 (re (concat "^" outline-regexp))
4144 (if (not start-level)
4145 nil ;; does not even start with a heading
4147 (while (setq start (string-match re kill (1+ start)))
4148 (if (< (- (match-end 0) (match-beginning 0)) start-level)
4152 (defun org-narrow-to-subtree ()
4153 "Narrow buffer to the current subtree."
4157 (progn (org-back-to-heading) (point))
4158 (progn (org-end-of-subtree t) (point)))))
4160 ;;; Plain list items
4162 (defun org-at-item-p ()
4163 "Is point in a line starting a hand-formatted item?"
4164 (let ((llt org-plain-list-ordered-item-terminator))
4166 (goto-char (point-at-bol))
4169 ((eq llt t) "\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
4170 ((= llt ?.) "\\([ \t]*\\([-+]\\|\\([0-9]+\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
4171 ((= llt ?\)) "\\([ \t]*\\([-+]\\|\\([0-9]+)\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
4172 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))))))
4174 (defun org-at-item-checkbox-p ()
4175 "Is point at a line starting a plain-list item with a checklet?"
4176 (and (org-at-item-p)
4178 (goto-char (match-end 0))
4179 (skip-chars-forward " \t")
4180 (looking-at "\\[[ X]\\]"))))
4182 (defun org-toggle-checkbox (&optional arg)
4183 "Toggle the checkbox in the current line."
4186 (let (beg end status (firstnew 'unknown))
4188 ((org-region-active-p)
4189 (setq beg (region-beginning) end (region-end)))
4191 (setq beg (point) end (save-excursion (outline-next-heading) (point))))
4192 ((org-at-item-checkbox-p)
4194 (replace-match (if (equal (match-string 0) "[ ]") "[X]" "[ ]") t t))
4196 (t (error "Not at a checkbox or heading, and no active region")))
4199 (while (< (point) end)
4200 (when (org-at-item-checkbox-p)
4201 (setq status (equal (match-string 0) "[X]"))
4202 (when (eq firstnew 'unknown)
4203 (setq firstnew (not status)))
4205 (if (if arg (not status) firstnew) "[X]" "[ ]") t t))
4206 (beginning-of-line 2))))))
4208 (defun org-get-indentation (&optional line)
4209 "Get the indentation of the current line, interpreting tabs.
4210 When LINE is given, assume it represents a line and compute its indentation."
4212 (if (string-match "^ *" (org-remove-tabs line))
4215 (beginning-of-line 1)
4216 (skip-chars-forward " \t")
4219 (defun org-remove-tabs (s &optional width)
4220 "Replace tabulators in S with spaces.
4221 Assumes that s is a single line, starting in column 0."
4222 (setq width (or width tab-width))
4223 (while (string-match "\t" s)
4224 (setq s (replace-match
4226 (- (* width (/ (+ (match-beginning 0) width) width))
4227 (match-beginning 0)) ?\ )
4231 ;; FIXME: document properly.
4232 (defun org-fix-indentation (line ind)
4233 "If the current indenation is smaller than ind1, leave it alone.
4234 If it is larger than ind, reduce it by ind."
4235 (let* ((l (org-remove-tabs line))
4236 (i (org-get-indentation l))
4237 (i1 (car ind)) (i2 (cdr ind)))
4238 (if (>= i i2) (setq l (substring line i2)))
4240 (concat (make-string i1 ?\ ) l)
4243 (defun org-beginning-of-item ()
4244 "Go to the beginning of the current hand-formatted item.
4245 If the cursor is not in an item, throw an error."
4248 (limit (save-excursion (org-back-to-heading)
4249 (beginning-of-line 2) (point)))
4252 (beginning-of-line 1)
4253 (beginning-of-line 1)
4254 (skip-chars-forward " \t")
4255 (setq ind (current-column))
4258 (beginning-of-line 0)
4259 (if (< (point) limit) (throw 'exit nil))
4260 (unless (looking-at "[ \t]*$")
4261 (skip-chars-forward " \t")
4262 (setq ind1 (current-column))
4264 (throw 'exit (org-at-item-p))))))
4267 (error "Not in an item")))))
4269 (defun org-end-of-item ()
4270 "Go to the end of the current hand-formatted item.
4271 If the cursor is not in an item, throw an error."
4274 (limit (save-excursion (outline-next-heading) (point)))
4275 (ind (save-excursion
4276 (org-beginning-of-item)
4277 (skip-chars-forward " \t")
4282 (beginning-of-line 2)
4283 (if (>= (point) limit) (throw 'exit t))
4284 (unless (looking-at "[ \t]*$")
4285 (skip-chars-forward " \t")
4286 (setq ind1 (current-column))
4287 (if (<= ind1 ind) (throw 'exit t)))))
4288 (beginning-of-line 1)
4290 (error "Not in an item"))))
4292 (defun org-next-item ()
4293 "Move to the beginning of the next item in the current plain list.
4294 Error if not at a plain list, or if this is the last item in the list."
4296 (let (ind ind1 (pos (point)))
4297 (org-beginning-of-item)
4298 (setq ind (org-get-indentation))
4300 (setq ind1 (org-get-indentation))
4301 (unless (and (org-at-item-p) (= ind ind1))
4303 (error "On last item"))))
4305 (defun org-previous-item ()
4306 "Move to the beginning of the previous item in the current plain list.
4307 Error if not at a plain list, or if this is the last item in the list."
4309 (let (beg ind (pos (point)))
4310 (org-beginning-of-item)
4312 (setq ind (org-get-indentation))
4316 (beginning-of-line 0)
4317 (if (looking-at "[ \t]*$")
4319 (if (<= (org-get-indentation) ind)
4322 (org-beginning-of-item)
4323 (error (goto-char pos)
4324 (error "On first item")))))
4326 (defun org-move-item-down ()
4327 "Move the plain list item at point down, i.e. swap with following item.
4328 Subitems (items with larger indentation) are considered part of the item,
4329 so this really moves item trees."
4331 (let (beg end ind ind1 (pos (point)) txt)
4332 (org-beginning-of-item)
4334 (setq ind (org-get-indentation))
4337 (setq ind1 (org-get-indentation))
4338 (if (and (org-at-item-p) (= ind ind1))
4341 (setq txt (buffer-substring beg end))
4343 (delete-region beg end))
4347 (org-maybe-renumber-ordered-list))
4349 (error "Cannot move this item further down"))))
4351 (defun org-move-item-up (arg)
4352 "Move the plain list item at point up, i.e. swap with previous item.
4353 Subitems (items with larger indentation) are considered part of the item,
4354 so this really moves item trees."
4356 (let (beg end ind ind1 (pos (point)) txt)
4357 (org-beginning-of-item)
4359 (setq ind (org-get-indentation))
4365 (beginning-of-line 0)
4366 (if (looking-at "[ \t]*$")
4368 (if (<= (setq ind1 (org-get-indentation)) ind)
4371 (org-beginning-of-item)
4372 (error (goto-char beg)
4373 (error "Cannot move this item further up")))
4374 (setq ind1 (org-get-indentation))
4375 (if (and (org-at-item-p) (= ind ind1))
4377 (setq txt (buffer-substring beg end))
4379 (delete-region beg end))
4383 (org-maybe-renumber-ordered-list))
4385 (error "Cannot move this item further up"))))
4387 (defun org-maybe-renumber-ordered-list ()
4388 "Renumber the ordered list at point if setup allows it.
4389 This tests the user option `org-auto-renumber-ordered-lists' before
4390 doing the renumbering."
4391 (and org-auto-renumber-ordered-lists
4394 (org-renumber-ordered-list 1)))
4396 (defun org-get-string-indentation (s)
4397 "What indentation has S due to SPACE and TAB at the beginning of the string?"
4398 (let ((n -1) (i 0) (w tab-width) c)
4400 (while (< (setq n (1+ n)) (length s))
4402 (cond ((= c ?\ ) (setq i (1+ i)))
4403 ((= c ?\t) (setq i (* (/ (+ w i) w) w)))
4404 (t (throw 'exit t)))))
4407 (defun org-renumber-ordered-list (arg)
4408 "Renumber an ordered plain list.
4409 Cursor needs to be in the first line of an item, the line that starts
4410 with something like \"1.\" or \"2)\"."
4412 (unless (and (org-at-item-p)
4413 (match-beginning 3))
4414 (error "This is not an ordered list"))
4415 (let ((line (org-current-line))
4416 (col (current-column))
4417 (ind (org-get-string-indentation
4418 (buffer-substring (point-at-bol) (match-beginning 3))))
4419 ;; (term (substring (match-string 3) -1))
4421 ;; find where this list begins
4425 (beginning-of-line 0)
4426 (if (looking-at "[ \t]*$") (throw 'next t))
4427 (skip-chars-forward " \t") (setq ind1 (current-column))
4428 (if (or (< ind1 ind)
4430 (not (org-at-item-p))))
4432 ;; Walk forward and replace these numbers
4436 (beginning-of-line 2)
4437 (if (eobp) (throw 'exit nil))
4438 (if (looking-at "[ \t]*$") (throw 'next nil))
4439 (skip-chars-forward " \t") (setq ind1 (current-column))
4440 (if (> ind1 ind) (throw 'next t))
4441 (if (< ind1 ind) (throw 'exit t))
4442 (if (not (org-at-item-p)) (throw 'exit nil))
4443 (if (not (match-beginning 3))
4444 (error "unordered bullet in ordered list. Press \\[undo] to recover"))
4445 (delete-region (match-beginning 3) (1- (match-end 3)))
4446 (goto-char (match-beginning 3))
4447 (insert (format "%d" (setq n (1+ n)))))))
4449 (move-to-column col)))
4451 (defvar org-last-indent-begin-marker (make-marker))
4452 (defvar org-last-indent-end-marker (make-marker))
4454 (defun org-outdent-item (arg)
4455 "Outdent a local list item."
4457 (org-indent-item (- arg)))
4459 (defun org-indent-item (arg)
4460 "Indent a local list item."
4462 (unless (org-at-item-p)
4463 (error "Not on an item"))
4465 (let (beg end ind ind1)
4466 (if (memq last-command '(org-shiftmetaright org-shiftmetaleft))
4467 (setq beg org-last-indent-begin-marker
4468 end org-last-indent-end-marker)
4469 (org-beginning-of-item)
4470 (setq beg (move-marker org-last-indent-begin-marker (point)))
4472 (setq end (move-marker org-last-indent-end-marker (point))))
4474 (skip-chars-forward " \t") (setq ind (current-column))
4475 (if (< (+ arg ind) 0) (error "Cannot outdent beyond margin"))
4476 (while (< (point) end)
4477 (beginning-of-line 1)
4478 (skip-chars-forward " \t") (setq ind1 (current-column))
4479 (delete-region (point-at-bol) (point))
4480 (indent-to-column (+ ind1 arg))
4481 (beginning-of-line 2)))))
4485 (defun org-archive-subtree (&optional find-done)
4486 "Move the current subtree to the archive.
4487 The archive can be a certain top-level heading in the current file, or in
4488 a different file. The tree will be moved to that location, the subtree
4489 heading be marked DONE, and the current time will be added.
4491 When called with prefix argument FIND-DONE, find whole trees without any
4492 open TODO items and archive them (after getting confirmation from the user).
4493 If the cursor is not at a headline when this comand is called, try all level
4494 1 trees. If the cursor is on a headline, only try the direct children of
4498 (org-archive-all-done)
4499 ;; Save all relevant TODO keyword-relatex variables
4501 (let ((tr-org-todo-line-regexp org-todo-line-regexp) ; keep despite compiler
4502 (tr-org-todo-keywords org-todo-keywords)
4503 (tr-org-todo-interpretation org-todo-interpretation)
4504 (tr-org-done-string org-done-string)
4505 (tr-org-todo-regexp org-todo-regexp)
4506 (tr-org-todo-line-regexp org-todo-line-regexp)
4507 (this-buffer (current-buffer))
4508 file heading buffer level newfile-p)
4509 (if (string-match "\\(.*\\)::\\(.*\\)" org-archive-location)
4511 (setq file (format (match-string 1 org-archive-location)
4512 (file-name-nondirectory buffer-file-name))
4513 heading (match-string 2 org-archive-location)))
4514 (error "Invalid `org-archive-location'"))
4515 (if (> (length file) 0)
4516 (setq newfile-p (not (file-exists-p file))
4517 buffer (find-file-noselect file))
4518 (setq buffer (current-buffer)))
4520 (error "Cannot access file \"%s\"" file))
4521 (if (and (> (length heading) 0)
4522 (string-match "^\\*+" heading))
4523 (setq level (match-end 0))
4524 (setq heading nil level 0))
4526 ;; We first only copy, in case something goes wrong
4527 ;; we need to protect this-command, to avoid kill-region sets it,
4528 ;; which would lead to duplication of subtrees
4529 (let (this-command) (org-copy-subtree))
4531 ;; Enforce org-mode for the archive buffer
4532 (if (not (org-mode-p))
4533 ;; Force the mode for future visits.
4534 (let ((org-insert-mode-line-in-empty-file t))
4535 (call-interactively 'org-mode)))
4537 (goto-char (point-max))
4538 (insert (format "\nArchived entries from file %s\n\n"
4539 (buffer-file-name this-buffer))))
4540 ;; Force the TODO keywords of the original buffer
4541 (let ((org-todo-line-regexp tr-org-todo-line-regexp)
4542 (org-todo-keywords tr-org-todo-keywords)
4543 (org-todo-interpretation tr-org-todo-interpretation)
4544 (org-done-string tr-org-done-string)
4545 (org-todo-regexp tr-org-todo-regexp)
4546 (org-todo-line-regexp tr-org-todo-line-regexp))
4547 (goto-char (point-min))
4550 (if (re-search-forward
4551 (concat "\\(^\\|\r\\)"
4552 (regexp-quote heading) "[ \t]*\\($\\|\r\\)")
4554 (goto-char (match-end 0))
4555 ;; Heading not found, just insert it at the end
4556 (goto-char (point-max))
4557 (or (bolp) (insert "\n"))
4558 (insert "\n" heading "\n")
4560 ;; Make the subtree visible
4562 (org-end-of-subtree t)
4563 (skip-chars-backward " \t\r\n]")
4564 (and (looking-at "[ \t\r\n]*")
4565 (replace-match "\n\n")))
4566 ;; No specific heading, just go to end of file.
4567 (goto-char (point-max)) (insert "\n"))
4569 (org-paste-subtree (1+ level))
4570 ;; Mark the entry as done, i.e. set to last work in org-todo-keywords
4571 (if org-archive-mark-done
4572 (org-todo (length org-todo-keywords)))
4573 ;; Move cursor to right after the TODO keyword
4574 (when org-archive-stamp-time
4575 (beginning-of-line 1)
4576 (looking-at org-todo-line-regexp)
4577 (goto-char (or (match-end 2) (match-beginning 3)))
4578 (insert "(" (format-time-string (cdr org-time-stamp-formats)
4581 ;; Save the buffer, if it is not the same buffer.
4582 (if (not (eq this-buffer buffer)) (save-buffer))))
4583 ;; Here we are back in the original buffer. Everything seems to have
4584 ;; worked. So now cut the tree and finish up.
4585 (let (this-command) (org-cut-subtree))
4586 (if (and (not (eobp)) (looking-at "[ \t]*$")) (kill-line))
4587 (message "Subtree archived %s"
4588 (if (eq this-buffer buffer)
4589 (concat "under heading: " heading)
4590 (concat "in file: " (abbreviate-file-name file)))))))
4592 (defun org-archive-all-done (&optional tag)
4593 "Archive sublevels of the current tree without open TODO items.
4594 If the cursor is not on a headline, try all level 1 trees. If
4595 it is on a headline, try all direct children.
4596 When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
4597 (let ((re (concat "^\\*+ +" org-not-done-regexp)) re1
4598 (rea (concat ".*:" org-archive-tag ":"))
4599 (begm (make-marker))
4600 (endm (make-marker))
4601 (question (if tag "Set ARCHIVE tag (no open TODO items)? "
4602 "Move subtree to archive (no open TODO items)? "))
4603 beg end (cntarch 0))
4604 (if (org-on-heading-p)
4606 (setq re1 (concat "^" (regexp-quote
4608 (1+ (- (match-end 0) (match-beginning 0)))
4611 (move-marker begm (point))
4612 (move-marker endm (org-end-of-subtree)))
4614 (move-marker begm (point-min))
4615 (move-marker endm (point-max)))
4618 (while (re-search-forward re1 endm t)
4619 (setq beg (match-beginning 0)
4620 end (save-excursion (org-end-of-subtree t) (point)))
4622 (if (re-search-forward re end t)
4625 (if (and (or (not tag) (not (looking-at rea)))
4626 (y-or-n-p question))
4629 (org-toggle-tag org-archive-tag 'on)
4630 (org-archive-subtree))
4631 (setq cntarch (1+ cntarch)))
4633 (message "%d trees archived" cntarch)))
4635 (defun org-cycle-hide-archived-subtrees (state)
4636 "Re-hide all archived subtrees after a visibility state change."
4637 (when (and (not org-cycle-open-archived-trees)
4638 (not (memq state '(overview folded))))
4640 (let* ((globalp (memq state '(contents all)))
4641 (beg (if globalp (point-min) (point)))
4642 (end (if globalp (point-max) (org-end-of-subtree))))
4643 (org-hide-archived-subtrees beg end)))))
4645 (defun org-hide-archived-subtrees (beg end)
4646 "Re-hide all archived subtrees after a visibility state change."
4648 (let* ((re (concat ":" org-archive-tag ":")))
4650 (while (re-search-forward re end t)
4651 (and (org-on-heading-p) (hide-subtree))
4652 (org-end-of-subtree)))))
4654 (defun org-toggle-tag (tag &optional onoff)
4655 "Toggle the tag TAG for the current line.
4656 If ONOFF is `on' or `off', don't toggle but set to this state."
4657 (unless (org-on-heading-p) (error "Not on headling"))
4661 (if (re-search-forward "[ \t]:\\([a-zA-Z0-9_@:]+\\):[ \t]*$"
4664 (setq current (match-string 1))
4667 (setq current (nreverse (org-split-string current ":")))
4671 (or (member tag current) (push tag current)))
4673 (or (not (member tag current)) (setq current (delete tag current))))
4674 (t (if (member tag current)
4675 (setq current (delete tag current))
4677 (push tag current))))
4680 (insert " :" (mapconcat 'identity (nreverse current) ":") ":"))
4681 (org-set-tags nil t))
4684 (defun org-toggle-archive-tag (&optional arg)
4685 "Toggle the archive tag for the current headline.
4686 With prefix ARG, check all children of current headline and offer tagging
4687 the children that do not contain any open TODO items."
4690 (org-archive-all-done 'tag)
4693 (org-back-to-heading t)
4694 (setq set (org-toggle-tag org-archive-tag))
4695 (when set (hide-subtree)))
4696 (and set (beginning-of-line 1))
4697 (message "Subtree %s" (if set "archived" "unarchived")))))
4699 (defun org-prepare-agenda-buffers (files)
4700 "Create buffers for all agenda files, protect archived trees and comments."
4702 (let ((pa '(:org-archived t))
4703 (pc '(:org-comment t))
4704 (pall '(:org-archived t :org-comment t))
4705 (rea (concat ":" org-archive-tag ":"))
4708 (while (setq file (pop files))
4709 (org-check-agenda-file file)
4710 (set-buffer (org-get-agenda-file-buffer file))
4712 (setq bmp (buffer-modified-p))
4714 (remove-text-properties (point-min) (point-max) pall)
4715 (when org-agenda-skip-archived-trees
4716 (goto-char (point-min))
4717 (while (re-search-forward rea nil t)
4718 (if (org-on-heading-p)
4719 (add-text-properties (point-at-bol) (org-end-of-subtree t) pa))))
4720 (goto-char (point-min))
4721 (setq re (concat "^\\*+ +" org-comment-string "\\>"))
4722 (while (re-search-forward re nil t)
4723 (add-text-properties
4724 (match-beginning 0) (org-end-of-subtree t) pc)))
4725 (set-buffer-modified-p bmp)))))
4727 (defun org-agenda-skip ()
4728 "Throw to `:skip' in places that should be skipped."
4729 (let ((p (point-at-bol)))
4730 (and org-agenda-skip-archived-trees
4731 (get-text-property p :org-archived)
4732 (org-end-of-subtree)
4734 (and (get-text-property p :org-comment)
4735 (org-end-of-subtree)
4737 (if (equal (char-after p) ?#) (throw :skip t))))
4739 (defun org-agenda-toggle-archive-tag ()
4740 "Toggle the archive tag for the current entry."
4742 (org-agenda-check-no-diary)
4743 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4744 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
4745 (org-agenda-error)))
4746 (buffer (marker-buffer hdmarker))
4747 (pos (marker-position hdmarker))
4748 (buffer-read-only nil)
4750 (with-current-buffer buffer
4753 (org-show-hidden-entry)
4755 (and (outline-next-heading)
4756 (org-flag-heading nil))) ; show the next heading
4757 (call-interactively 'org-toggle-archive-tag)
4759 (setq newhead (org-get-heading)))
4760 (org-agenda-change-all-lines newhead hdmarker)
4761 (beginning-of-line 1)))
4765 (defun org-find-dblock (name)
4766 "Find the first dynamic block with name NAME in the buffer.
4767 If not found, stay at current position and return nil."
4770 (goto-char (point-min))
4771 (setq pos (and (re-search-forward (concat "^#\\+BEGIN:[ \t]+" name "\\>")
4773 (match-beginning 0))))
4774 (if pos (goto-char pos))
4777 (defconst org-dblock-start-re
4778 "^#\\+BEGIN:[ \t]+\\(\\S-+\\)[ \t]+\\(.*\\)"
4779 "Matches the startline of a dynamic block, with parameters.")
4781 (defconst org-dblock-end-re "^#\\+END\\([: \t\r\n]\\|$\\)"
4782 "Matches the end of a dyhamic block.")
4784 (defun org-create-dblock (plist)
4785 "Create a dynamic block section, with parameters taken from PLIST.
4786 PLIST must containe a :name entry which is used as name of the block."
4787 (unless (bolp) (newline))
4788 (let ((name (plist-get plist :name)))
4789 (insert "#+BEGIN: " name)
4791 (if (eq (car plist) :name)
4792 (setq plist (cddr plist))
4793 (insert " " (prin1-to-string (pop plist)))))
4794 (insert "\n\n#+END:\n")
4795 (beginning-of-line -2)))
4797 (defun org-prepare-dblock ()
4798 "Prepare dynamic block for refresh.
4799 This empties the block, puts the cursor at the insert position and returns
4800 the property list including an extra property :name with the block name."
4801 (unless (looking-at org-dblock-start-re)
4802 (error "Not at a dynamic block"))
4803 (let* ((begdel (1+ (match-end 0)))
4804 (name (match-string 1))
4805 (params (append (list :name name)
4806 (read (concat "(" (match-string 2) ")")))))
4807 (unless (re-search-forward org-dblock-end-re nil t)
4808 (error "Dynamic block not terminated"))
4809 (delete-region begdel (match-beginning 0))
4814 (defun org-map-dblocks (&optional command)
4815 "Apply COMMAND to all dynamic blocks in the current buffer.
4816 If COMMAND is not given, use `org-update-dblock'."
4817 (let ((cmd (or command 'org-update-dblock))
4820 (goto-char (point-min))
4821 (while (re-search-forward org-dblock-start-re nil t)
4822 (goto-char (setq pos (match-beginning 0)))
4825 (error (message "Error during update of dynamic block")))
4827 (unless (re-search-forward org-dblock-end-re nil t)
4828 (error "Dynamic block not terminated"))))))
4830 (defun org-dblock-update (&optional arg)
4831 "User command for updating dynamic blocks.
4832 Update the dynamic block at point. With prefix ARG, update all dynamic
4833 blocks in the buffer."
4836 (org-update-all-dblocks)
4837 (or (looking-at org-dblock-start-re)
4838 (org-beginning-of-dblock))
4839 (org-update-dblock)))
4841 (defun org-update-dblock ()
4842 "Update the dynamic block at point
4843 This means to empty the block, parse for parameters and then call
4844 the correct writing function."
4845 (let* ((pos (point))
4846 (params (org-prepare-dblock))
4847 (name (plist-get params :name))
4848 (cmd (intern (concat "org-dblock-write:" name))))
4849 (funcall cmd params)
4852 (defun org-beginning-of-dblock ()
4853 "Find the beginning of the dynamic block at point.
4854 Error if there is no scuh block at point."
4858 (if (and (re-search-backward org-dblock-start-re nil t)
4859 (setq beg (match-beginning 0))
4860 (re-search-forward org-dblock-end-re nil t)
4861 (> (match-end 0) pos))
4864 (error "Not in a dynamic block"))))
4866 (defun org-update-all-dblocks ()
4867 "Update all dynamic blocks in the buffer.
4868 This function can be used in a hook."
4870 (org-map-dblocks 'org-update-dblock)))
4875 (defun org-complete (&optional arg)
4876 "Perform completion on word at point.
4877 At the beginning of a headline, this completes TODO keywords as given in
4878 `org-todo-keywords'.
4879 If the current word is preceded by a backslash, completes the TeX symbols
4880 that are supported for HTML support.
4881 If the current word is preceded by \"#+\", completes special words for
4882 setting file options.
4883 At all other locations, this simply calls `ispell-complete-word'."
4886 (let* ((end (point))
4887 (beg1 (save-excursion
4888 (if (equal (char-before (point)) ?\ ) (backward-char 1))
4889 (skip-chars-backward "a-zA-Z_@0-9")
4891 (beg (save-excursion
4892 (if (equal (char-before (point)) ?\ ) (backward-char 1))
4893 (skip-chars-backward "a-zA-Z0-9_:$")
4895 (confirm (lambda (x) (stringp (car x))))
4896 (camel (equal (char-before beg) ?*))
4897 (tag (equal (char-before beg1) ?:))
4898 (texp (equal (char-before beg) ?\\))
4899 (opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
4902 (completion-ignore-case opt)
4909 (string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
4910 (cons (match-string 2 x) (match-string 1 x)))
4911 (org-split-string (org-get-current-options) "\n")))
4915 ((string-match "\\`\\*+[ \t]*\\'"
4916 (buffer-substring (point-at-bol) beg))
4918 (mapcar 'list org-todo-keywords))
4922 (goto-char (point-min))
4923 (while (re-search-forward org-todo-line-regexp nil t)
4925 (if org-file-link-context-use-camel-case
4926 (org-make-org-heading-camel (match-string 3) t)
4927 (org-make-org-heading-search-string
4928 (match-string 3) t)))
4931 (tag (setq type :tag beg beg1)
4932 (or org-tag-alist (org-get-buffer-tags)))
4933 (t (progn (ispell-complete-word arg) (throw 'exit nil)))))
4934 (pattern (buffer-substring-no-properties beg end))
4935 (completion (try-completion pattern table confirm)))
4936 (cond ((eq completion t)
4937 (if (equal type :opt)
4938 (insert (substring (cdr (assoc (upcase pattern) table))
4939 (length pattern)))))
4941 (message "Can't find completion for \"%s\"" pattern)
4943 ((not (string= pattern completion))
4944 (delete-region beg end)
4945 (if (string-match " +$" completion)
4946 (setq completion (replace-match "" t t completion)))
4948 (if (get-buffer-window "*Completions*")
4949 (delete-window (get-buffer-window "*Completions*")))
4950 (if (assoc completion table)
4951 (if (eq type :todo) (insert " ")
4952 (if (eq type :tag) (insert ":"))))
4953 (if (and (equal type :opt) (assoc completion table))
4954 (message "%s" (substitute-command-keys
4955 "Press \\[org-complete] again to insert example settings"))))
4957 (message "Making completion list...")
4958 (let ((list (sort (all-completions pattern table confirm)
4960 (with-output-to-temp-buffer "*Completions*"
4962 ;; Protection needed for XEmacs and emacs 21
4963 (display-completion-list list pattern)
4964 (error (display-completion-list list)))))
4965 (message "Making completion list...%s" "done"))))))
4967 ;;; Comments, TODO and DEADLINE
4969 (defun org-toggle-comment ()
4970 "Change the COMMENT state of an entry."
4973 (org-back-to-heading)
4974 (if (looking-at (concat outline-regexp
4975 "\\( +\\<" org-comment-string "\\>\\)"))
4976 (replace-match "" t t nil 1)
4977 (if (looking-at outline-regexp)
4979 (goto-char (match-end 0))
4980 (insert " " org-comment-string))))))
4982 (defvar org-last-todo-state-is-todo nil
4983 "This is non-nil when the last TODO state change led to a TODO state.
4984 If the last change removed the TODO tag or switched to DONE, then
4987 (defun org-todo (&optional arg)
4988 "Change the TODO state of an item.
4989 The state of an item is given by a keyword at the start of the heading,
4991 *** TODO Write paper
4994 The different keywords are specified in the variable `org-todo-keywords'.
4995 By default the available states are \"TODO\" and \"DONE\".
4996 So for this example: when the item starts with TODO, it is changed to DONE.
4997 When it starts with DONE, the DONE is removed. And when neither TODO nor
4998 DONE are present, add TODO at the beginning of the heading.
5000 With prefix arg, use completion to determine the new state. With numeric
5001 prefix arg, switch to that state."
5004 (org-back-to-heading)
5005 (if (looking-at outline-regexp) (goto-char (match-end 0)))
5006 (or (looking-at (concat " +" org-todo-regexp " *"))
5008 (let* ((this (match-string 1))
5009 (completion-ignore-case t)
5010 (member (member this org-todo-keywords))
5014 ;; Read a state with completion
5015 (completing-read "State: " (mapcar (lambda(x) (list x))
5020 (if tail (car tail) nil)
5021 (car org-todo-keywords)))
5023 (if (equal member org-todo-keywords)
5026 (nth (- (length org-todo-keywords) (length tail) 2)
5030 ;; user requests a specific state
5031 (nth (1- (prefix-numeric-value arg))
5033 ((null member) (car org-todo-keywords))
5034 ((null tail) nil) ;; -> first entry
5035 ((eq org-todo-interpretation 'sequence)
5037 ((memq org-todo-interpretation '(type priority))
5038 (if (eq this-command last-command)
5040 (if (> (length tail) 0) org-done-string nil)))
5042 (next (if state (concat " " state " ") " ")))
5043 (replace-match next t t)
5044 (setq org-last-todo-state-is-todo
5045 (not (equal state org-done-string)))
5047 (if (equal state org-done-string)
5048 (org-add-planning-info 'closed (current-time) 'scheduled)
5050 (org-add-planning-info nil nil 'closed))))
5051 ;; Fixup tag positioning
5052 (and org-auto-align-tags (org-set-tags nil t))
5053 (run-hooks 'org-after-todo-state-change-hook)))
5054 ;; Fixup cursor location if close to the keyword
5055 (if (and (outline-on-heading-p)
5057 (save-excursion (beginning-of-line 1)
5058 (looking-at org-todo-line-regexp))
5059 (< (point) (+ 2 (or (match-end 2) (match-end 1)))))
5061 (goto-char (or (match-end 2) (match-end 1)))
5064 (defun org-log-done (&optional undone)
5065 "Add a time stamp logging that a TODO entry has been closed.
5066 When UNDONE is non-nil, remove such a time stamp again."
5070 (org-back-to-heading t)
5072 (looking-at (concat outline-regexp " *"))
5073 (goto-char (match-end 0))
5074 (setq col (current-column))
5075 (outline-next-heading)
5078 (when (re-search-forward (concat
5080 (regexp-quote org-closed-string)
5081 " *\\[.*?\\][^\n\r]*[\n\r]?\\)") end t)
5082 (delete-region (match-beginning 1) (match-end 1)))
5084 (org-back-to-heading t)
5085 (skip-chars-forward "^\n\r")
5086 (goto-char (min (1+ (point)) (point-max)))
5087 (when (not (member (char-before) '(?\r ?\n)))
5090 (insert org-closed-string " "
5092 (concat "[" (substring (cdr org-time-stamp-formats) 1 -1) "]")
5096 (defun org-show-todo-tree (arg)
5097 "Make a compact tree which shows all headlines marked with TODO.
5098 The tree will show the lines where the regexp matches, and all higher
5099 headlines above the match.
5100 With \\[universal-argument] prefix, also show the DONE entries.
5101 With a numeric prefix N, construct a sparse tree for the Nth element
5102 of `org-todo-keywords'."
5104 (let ((case-fold-search nil)
5106 (cond ((null arg) org-not-done-regexp)
5107 ((equal arg '(4)) org-todo-regexp)
5108 ((<= (prefix-numeric-value arg) (length org-todo-keywords))
5109 (regexp-quote (nth (1- (prefix-numeric-value arg))
5110 org-todo-keywords)))
5111 (t (error "Invalid prefix argument: %s" arg)))))
5112 (message "%d TODO entries found"
5113 (org-occur (concat "^" outline-regexp " +" kwd-re )))))
5115 (defun org-deadline ()
5116 "Insert the DEADLINE: string to make a deadline.
5117 A timestamp is also inserted - use \\[org-timestamp-up] and \\[org-timestamp-down]
5118 to modify it to the correct date."
5120 (org-add-planning-info 'deadline nil 'closed))
5122 (defun org-schedule ()
5123 "Insert the SCHEDULED: string to schedule a TODO item.
5124 A timestamp is also inserted - use \\[org-timestamp-up] and \\[org-timestamp-down]
5125 to modify it to the correct date."
5127 (org-add-planning-info 'scheduled nil 'closed))
5129 (defun org-add-planning-info (what &optional time &rest remove)
5130 "Insert new timestamp with keyword in the line directly after the headline.
5131 WHAT indicates what kind of time stamp to add. TIME indicated the time to use.
5132 If non is given, the user is prompted for a date.
5133 REMOVE indicates what kind of entries to remove. An old WHAT entry will also
5136 (when what (setq time (or time (org-read-date nil 'to-time))))
5137 (when (and org-insert-labeled-timestamps-at-point
5138 (member what '(scheduled deadline)))
5140 (if (eq what 'scheduled) org-scheduled-string org-deadline-string)
5142 (format-time-string (car org-time-stamp-formats) time))
5145 (let (col list elt (buffer-invisibility-spec nil) ts)
5146 (org-back-to-heading t)
5147 (looking-at (concat outline-regexp "\\( *\\)[^\r\n]*"))
5148 (goto-char (match-end 1))
5149 (setq col (current-column))
5150 (goto-char (1+ (match-end 0)))
5151 (if (and (not (looking-at outline-regexp))
5152 (looking-at (concat "[^\r\n]*?" org-keyword-time-regexp
5154 (not (equal (match-string 1) org-clock-string)))
5155 (narrow-to-region (match-beginning 0) (match-end 0))
5158 (narrow-to-region (point) (point))
5159 (indent-to-column col))
5160 ;; Check if we have to remove something.
5161 (setq list (cons what remove))
5163 (setq elt (pop list))
5164 (goto-char (point-min))
5165 (when (or (and (eq elt 'scheduled)
5166 (re-search-forward org-scheduled-time-regexp nil t))
5167 (and (eq elt 'deadline)
5168 (re-search-forward org-deadline-time-regexp nil t))
5169 (and (eq elt 'closed)
5170 (re-search-forward org-closed-time-regexp nil t)))
5172 (if (looking-at " +") (replace-match ""))))
5173 (goto-char (point-max))
5176 (if (not (equal (char-before) ?\ )) " " "")
5177 (cond ((eq what 'scheduled) org-scheduled-string)
5178 ((eq what 'deadline) org-deadline-string)
5179 ((eq what 'closed) org-closed-string))
5184 (if (eq what 'closed)
5185 (concat "[" (substring (cdr org-time-stamp-formats) 1 -1) "]")
5186 (car org-time-stamp-formats))
5188 (goto-char (point-min))
5190 (if (looking-at "[ \t]+\r?\n")
5194 (defun org-occur (regexp &optional callback)
5195 "Make a compact tree which shows all matches of REGEXP.
5196 The tree will show the lines where the regexp matches, and all higher
5197 headlines above the match. It will also show the heading after the match,
5198 to make sure editing the matching entry is easy.
5199 If CALLBACK is non-nil, it is a function which is called to confirm
5200 that the match should indeed be shown."
5201 (interactive "sRegexp: ")
5202 (org-remove-occur-highlights nil nil t)
5203 (setq regexp (org-check-occur-regexp regexp))
5206 (goto-char (point-min))
5208 (while (re-search-forward regexp nil t)
5209 (when (or (not callback)
5210 (save-match-data (funcall callback)))
5212 (org-highlight-new-match (match-beginning 0) (match-end 0))
5213 (org-show-hierarchy-above))))
5214 (org-add-hook 'before-change-functions 'org-remove-occur-highlights
5216 (unless org-sparse-tree-open-archived-trees
5217 (org-hide-archived-subtrees (point-min) (point-max)))
5218 (run-hooks 'org-occur-hook)
5220 (message "%d match(es) for regexp %s" cnt regexp))
5223 (defun org-show-hierarchy-above ()
5224 "Make sure point and the headings hierarchy above is visible."
5226 (if (org-on-heading-p t)
5227 (org-flag-heading nil) ; only show the heading
5228 (and (or (org-invisible-p) (org-invisible-p2))
5229 (org-show-hidden-entry))) ; show entire entry
5231 (and org-show-following-heading
5232 (outline-next-heading)
5233 (org-flag-heading nil))) ; show the next heading
5234 (when org-show-hierarchy-above
5235 (save-excursion ; show all higher headings
5236 (while (and (condition-case nil
5237 (progn (org-up-heading-all 1) t)
5240 (org-flag-heading nil))))))
5242 ;; Overlay compatibility functions
5243 (defun org-make-overlay (beg end &optional buffer)
5244 (if (featurep 'xemacs)
5245 (make-extent beg end buffer)
5246 (make-overlay beg end buffer)))
5247 (defun org-delete-overlay (ovl)
5248 (if (featurep 'xemacs) (delete-extent ovl) (delete-overlay ovl)))
5249 (defun org-detatch-overlay (ovl)
5250 (if (featurep 'xemacs) (detach-extent ovl) (delete-overlay ovl)))
5251 (defun org-move-overlay (ovl beg end &optional buffer)
5252 (if (featurep 'xemacs)
5253 (set-extent-endpoints ovl beg end buffer)
5254 (move-overlay ovl beg end buffer)))
5255 (defun org-overlay-put (ovl prop value)
5256 (if (featurep 'xemacs)
5257 (set-extent-property ovl prop value)
5258 (overlay-put ovl prop value)))
5259 (defun org-overlays-at (pos)
5260 (if (featurep 'xemacs) (extents-at pos) (overlays-at pos)))
5261 (defun org-overlay-start (o)
5262 (if (featurep 'xemacs) (extent-start-position o) (overlay-start o)))
5263 (defun org-overlay-end (o)
5264 (if (featurep 'xemacs) (extent-end-position o) (overlay-end o)))
5266 (defvar org-occur-highlights nil)
5267 (make-variable-buffer-local 'org-occur-highlights)
5268 (defun org-highlight-new-match (beg end)
5269 "Highlight from BEG to END and mark the highlight is an occur headline."
5270 (let ((ov (org-make-overlay beg end)))
5271 (org-overlay-put ov 'face 'secondary-selection)
5272 (push ov org-occur-highlights)))
5274 (defvar org-inhibit-highlight-removal nil)
5275 (defun org-remove-occur-highlights (&optional beg end noremove)
5276 "Remove the occur highlights from the buffer.
5277 BEG and END are ignored. If NOREMOVE is nil, remove this function
5278 from the `before-change-functions' in the current buffer."
5280 (unless org-inhibit-highlight-removal
5281 (mapc 'org-delete-overlay org-occur-highlights)
5282 (setq org-occur-highlights nil)
5284 (remove-hook 'before-change-functions
5285 'org-remove-occur-highlights 'local))))
5289 (defvar org-priority-regexp ".*?\\(\\[#\\([A-Z]\\)\\] ?\\)"
5290 "Regular expression matching the priority indicator.")
5292 (defvar org-remove-priority-next-time nil)
5294 (defun org-priority-up ()
5295 "Increase the priority of the current item."
5299 (defun org-priority-down ()
5300 "Decrease the priority of the current item."
5302 (org-priority 'down))
5304 (defun org-priority (&optional action)
5305 "Change the priority of an item by ARG.
5306 ACTION can be set, up, or down."
5308 (setq action (or action 'set))
5309 (let (current new news have remove)
5311 (org-back-to-heading)
5312 (if (looking-at org-priority-regexp)
5313 (setq current (string-to-char (match-string 2))
5315 (setq current org-default-priority))
5318 (message "Priority A-%c, SPC to remove: " org-lowest-priority)
5319 (setq new (read-char-exclusive))
5320 (cond ((equal new ?\ ) (setq remove t))
5321 ((or (< (upcase new) ?A) (> (upcase new) org-lowest-priority))
5322 (error "Priority must be between `%c' and `%c'"
5323 ?A org-lowest-priority))))
5325 (setq new (1- current)))
5327 (setq new (1+ current)))
5328 (t (error "Invalid action")))
5329 (setq new (min (max ?A (upcase new)) org-lowest-priority))
5330 (setq news (format "%c" new))
5333 (replace-match "" t t nil 1)
5334 (replace-match news t t nil 2))
5336 (error "No priority cookie found in line")
5337 (looking-at org-todo-line-regexp)
5340 (goto-char (match-end 2))
5341 (insert " [#" news "]"))
5342 (goto-char (match-beginning 3))
5343 (insert "[#" news "] ")))))
5345 (message "Priority removed")
5346 (message "Priority of current item set to %s" news))))
5349 (defun org-get-priority (s)
5350 "Find priority cookie and return priority."
5352 (if (not (string-match org-priority-regexp s))
5353 (* 1000 (- org-lowest-priority org-default-priority))
5354 (* 1000 (- org-lowest-priority
5355 (string-to-char (match-string 2 s)))))))
5359 (defvar org-last-changed-timestamp nil)
5361 (defun org-time-stamp (arg)
5362 "Prompt for a date/time and insert a time stamp.
5363 If the user specifies a time like HH:MM, or if this command is called
5364 with a prefix argument, the time stamp will contain date and time.
5365 Otherwise, only the date will be included. All parts of a date not
5366 specified by the user will be filled in from the current date/time.
5367 So if you press just return without typing anything, the time stamp
5368 will represent the current date/time. If there is already a timestamp
5369 at the cursor, it will be modified."
5371 (let ((fmt (if arg (cdr org-time-stamp-formats)
5372 (car org-time-stamp-formats)))
5373 (org-time-was-given nil)
5376 ((and (org-at-timestamp-p)
5377 (eq last-command 'org-time-stamp)
5378 (eq this-command 'org-time-stamp))
5380 (setq time (let ((this-command this-command))
5381 (org-read-date arg 'totime)))
5382 (if org-time-was-given (setq fmt (cdr org-time-stamp-formats)))
5383 (insert (format-time-string fmt time)))
5384 ((org-at-timestamp-p)
5385 (setq time (let ((this-command this-command))
5386 (org-read-date arg 'totime)))
5387 (and (org-at-timestamp-p) (replace-match
5388 (setq org-last-changed-timestamp
5389 (format-time-string fmt time))
5391 (message "Timestamp updated"))
5393 (setq time (let ((this-command this-command))
5394 (org-read-date arg 'totime)))
5395 (if org-time-was-given (setq fmt (cdr org-time-stamp-formats)))
5396 (insert (format-time-string fmt time))))))
5398 (defun org-time-stamp-inactive (&optional arg)
5399 "Insert an inactive time stamp.
5400 An inactive time stamp is enclosed in square brackets instead of angle
5401 brackets. It is inactive in the sense that it does not trigger agenda entries,
5402 does not link to the calendar and cannot be changed with the S-cursor keys.
5403 So these are more for recording a certain time/date."
5405 (let ((fmt (if arg (cdr org-time-stamp-formats)
5406 (car org-time-stamp-formats)))
5407 (org-time-was-given nil)
5409 (setq time (org-read-date arg 'totime))
5410 (if org-time-was-given (setq fmt (cdr org-time-stamp-formats)))
5411 (setq fmt (concat "[" (substring fmt 1 -1) "]"))
5412 (insert (format-time-string fmt time))))
5414 (defvar org-date-ovl (org-make-overlay 1 1))
5415 (org-overlay-put org-date-ovl 'face 'org-warning)
5416 (org-detatch-overlay org-date-ovl)
5418 (defun org-read-date (&optional with-time to-time)
5419 "Read a date and make things smooth for the user.
5420 The prompt will suggest to enter an ISO date, but you can also enter anything
5421 which will at least partially be understood by `parse-time-string'.
5422 Unrecognized parts of the date will default to the current day, month, year,
5423 hour and minute. For example,
5424 3-2-5 --> 2003-02-05
5425 feb 15 --> currentyear-02-15
5426 sep 12 9 --> 2009-09-12
5427 12:45 --> today 12:45
5428 22 sept 0:34 --> currentyear-09-22 0:34
5429 12 --> currentyear-currentmonth-12
5430 Fri --> nearest Friday (today or later)
5432 The function understands only English month and weekday abbreviations,
5433 but this can be configured with the variables `parse-time-months' and
5434 `parse-time-weekdays'.
5436 While prompting, a calendar is popped up - you can also select the
5437 date with the mouse (button 1). The calendar shows a period of three
5438 months. To scroll it to other months, use the keys `>' and `<'.
5439 If you don't like the calendar, turn it off with
5440 \(setq org-popup-calendar-for-date-prompt nil)
5442 With optional argument TO-TIME, the date will immediately be converted
5443 to an internal time.
5444 With an optional argument WITH-TIME, the prompt will suggest to also
5445 insert a time. Note that when WITH-TIME is not set, you can still
5446 enter a time, and this function will inform the calling routine about
5447 this change. The calling routine may then choose to change the format
5448 used to insert the time stamp into the buffer to include the time."
5449 (require 'parse-time)
5450 (let* ((org-time-stamp-rounding-minutes
5451 (if (equal with-time '(16)) 0 org-time-stamp-rounding-minutes))
5452 (ct (org-current-time))
5454 ;; Default time is either today, or, when entering a range,
5458 (concat org-ts-regexp "--?-?\\=") ; 1-3 minuses
5462 (mapcar (lambda(x) (or x 0))
5463 (parse-time-string (match-string 1))))
5465 (calendar-move-hook nil)
5466 (view-diary-entries-initially nil)
5467 (view-calendar-holidays-initially nil)
5468 (timestr (format-time-string
5469 (if with-time "%Y-%m-%d %H:%M" "%Y-%m-%d") default-time))
5470 (prompt (format "YYYY-MM-DD [%s]: " timestr))
5472 second minute hour day month year tl wday wday1)
5474 (if org-popup-calendar-for-date-prompt
5476 (save-window-excursion
5478 (calendar-forward-day (- (time-to-days default-time)
5479 (calendar-absolute-from-gregorian
5480 (calendar-current-date))))
5481 (org-eval-in-calendar nil)
5482 (let* ((old-map (current-local-map))
5483 (map (copy-keymap calendar-mode-map))
5484 (minibuffer-local-map (copy-keymap minibuffer-local-map)))
5485 (define-key map (kbd "RET") 'org-calendar-select)
5486 (define-key map (if (featurep 'xemacs) [button1] [mouse-1])
5487 'org-calendar-select-mouse)
5488 (define-key map (if (featurep 'xemacs) [button2] [mouse-2
])
5489 'org-calendar-select-mouse
)
5490 (define-key minibuffer-local-map
[(meta shift left
)]
5491 (lambda () (interactive)
5492 (org-eval-in-calendar '(calendar-backward-month 1))))
5493 (define-key minibuffer-local-map
[(meta shift right
)]
5494 (lambda () (interactive)
5495 (org-eval-in-calendar '(calendar-forward-month 1))))
5496 (define-key minibuffer-local-map
[(shift up
)]
5497 (lambda () (interactive)
5498 (org-eval-in-calendar '(calendar-backward-week 1))))
5499 (define-key minibuffer-local-map
[(shift down
)]
5500 (lambda () (interactive)
5501 (org-eval-in-calendar '(calendar-forward-week 1))))
5502 (define-key minibuffer-local-map
[(shift left
)]
5503 (lambda () (interactive)
5504 (org-eval-in-calendar '(calendar-backward-day 1))))
5505 (define-key minibuffer-local-map
[(shift right
)]
5506 (lambda () (interactive)
5507 (org-eval-in-calendar '(calendar-forward-day 1))))
5508 (define-key minibuffer-local-map
">"
5509 (lambda () (interactive)
5510 (org-eval-in-calendar '(scroll-calendar-left 1))))
5511 (define-key minibuffer-local-map
"<"
5512 (lambda () (interactive)
5513 (org-eval-in-calendar '(scroll-calendar-right 1))))
5517 (setq ans
(read-string prompt
"" nil nil
))
5518 (if (not (string-match "\\S-" ans
)) (setq ans nil
))
5519 (setq ans
(or ans1 ans ans2
)))
5520 (use-local-map old-map
)))))
5521 ;; Naked prompt only
5522 (setq ans
(read-string prompt
"" nil timestr
)))
5523 (org-detatch-overlay org-date-ovl
)
5526 "^ *\\(\\([0-9]+\\)-\\)?\\([0-1]?[0-9]\\)-\\([0-3]?[0-9]\\)\\([^-0-9]\\|$\\)" ans
)
5528 (setq year
(if (match-end 2)
5529 (string-to-number (match-string 2 ans
))
5530 (string-to-number (format-time-string "%Y")))
5531 month
(string-to-number (match-string 3 ans
))
5532 day
(string-to-number (match-string 4 ans
)))
5533 (if (< year
100) (setq year
(+ 2000 year
)))
5534 (setq ans
(replace-match (format "%04d-%02d-%02d\\5" year month day
)
5536 (setq tl
(parse-time-string ans
)
5537 year
(or (nth 5 tl
) (string-to-number (format-time-string "%Y" ct
)))
5538 month
(or (nth 4 tl
) (string-to-number (format-time-string "%m" ct
)))
5539 day
(or (nth 3 tl
) (string-to-number (format-time-string "%d" ct
)))
5540 hour
(or (nth 2 tl
) (string-to-number (format-time-string "%H" ct
)))
5541 minute
(or (nth 1 tl
) (string-to-number (format-time-string "%M" ct
)))
5542 second
(or (nth 0 tl
) 0)
5544 (when (and wday
(not (nth 3 tl
)))
5545 ;; Weekday was given, but no day, so pick that day in the week
5546 ;; on or after the derived date.
5547 (setq wday1
(nth 6 (decode-time (encode-time 0 0 0 day month year
))))
5548 (unless (equal wday wday1
)
5549 (setq day
(+ day
(%
(- wday wday1 -
7) 7)))))
5550 (if (and (boundp 'org-time-was-given
)
5552 (setq org-time-was-given t
))
5553 (if (< year
100) (setq year
(+ 2000 year
)))
5555 (encode-time second minute hour day month year
)
5556 (if (or (nth 1 tl
) (nth 2 tl
))
5557 (format "%04d-%02d-%02d %02d:%02d" year month day hour minute
)
5558 (format "%04d-%02d-%02d" year month day
)))))
5560 (defun org-eval-in-calendar (form)
5561 "Eval FORM in the calendar window and return to current window.
5562 Also, store the cursor date in variable ans2."
5563 (let ((sw (selected-window)))
5564 (select-window (get-buffer-window "*Calendar*"))
5566 (when (calendar-cursor-to-date)
5567 (let* ((date (calendar-cursor-to-date))
5568 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
5569 (setq ans2
(format-time-string "%Y-%m-%d" time
))))
5570 (org-move-overlay org-date-ovl
(1- (point)) (1+ (point)) (current-buffer))
5571 (select-window sw
)))
5573 (defun org-calendar-select ()
5574 "Return to `org-read-date' with the date currently selected.
5575 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
5577 (when (calendar-cursor-to-date)
5578 (let* ((date (calendar-cursor-to-date))
5579 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
5580 (setq ans1
(format-time-string "%Y-%m-%d" time
)))
5581 (if (active-minibuffer-window) (exit-minibuffer))))
5583 (defun org-calendar-select-mouse (ev)
5584 "Return to `org-read-date' with the date currently selected.
5585 This is used by `org-read-date' in a temporary keymap for the calendar buffer."
5587 (mouse-set-point ev
)
5588 (when (calendar-cursor-to-date)
5589 (let* ((date (calendar-cursor-to-date))
5590 (time (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
5591 (setq ans1
(format-time-string "%Y-%m-%d" time
)))
5592 (if (active-minibuffer-window) (exit-minibuffer))))
5594 (defun org-check-deadlines (ndays)
5595 "Check if there are any deadlines due or past due.
5596 A deadline is considered due if it happens within `org-deadline-warning-days'
5597 days from today's date. If the deadline appears in an entry marked DONE,
5598 it is not shown. The prefix arg NDAYS can be used to test that many
5599 days. If the prefix is a raw \\[universal-argument] prefix, all deadlines are shown."
5601 (let* ((org-warn-days
5603 ((equal ndays
'(4)) 100000)
5604 (ndays (prefix-numeric-value ndays
))
5605 (t org-deadline-warning-days
)))
5606 (case-fold-search nil
)
5607 (regexp (concat "\\<" org-deadline-string
" *<\\([^>]+\\)>"))
5610 (and (let ((d1 (time-to-days (current-time)))
5612 (org-time-string-to-time (match-string 1)))))
5613 (< (- d2 d1
) org-warn-days
))
5614 (not (org-entry-is-done-p))))))
5615 (message "%d deadlines past-due or due within %d days"
5616 (org-occur regexp callback
)
5619 (defun org-evaluate-time-range (&optional to-buffer
)
5620 "Evaluate a time range by computing the difference between start and end.
5621 Normally the result is just printed in the echo area, but with prefix arg
5622 TO-BUFFER, the result is inserted just after the date stamp into the buffer.
5623 If the time range is actually in a table, the result is inserted into the
5625 For time difference computation, a year is assumed to be exactly 365
5626 days in order to avoid rounding problems."
5629 (unless (org-at-date-range-p)
5630 (goto-char (point-at-bol))
5631 (re-search-forward org-tr-regexp
(point-at-eol) t
))
5632 (if (not (org-at-date-range-p))
5633 (error "Not at a time-stamp range, and none found in current line")))
5634 (let* ((ts1 (match-string 1))
5635 (ts2 (match-string 2))
5636 (havetime (or (> (length ts1
) 15) (> (length ts2
) 15)))
5637 (match-end (match-end 0))
5638 (time1 (org-time-string-to-time ts1
))
5639 (time2 (org-time-string-to-time ts2
))
5640 (t1 (time-to-seconds time1
))
5641 (t2 (time-to-seconds time2
))
5642 (diff (abs (- t2 t1
)))
5643 (negative (< (- t2 t1
) 0))
5644 ;; (ys (floor (* 365 24 60 60)))
5647 (fy "%dy %dd %02d:%02d")
5649 (fd "%dd %02d:%02d")
5654 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
5656 d
(floor (/ diff ds
)) diff
(mod diff ds
)
5657 h
(floor (/ diff hs
)) diff
(mod diff hs
)
5658 m
(floor (/ diff
60)))
5659 (setq ; y (floor (/ diff ys)) diff (mod diff ys)
5661 d
(floor (+ (/ diff ds
) 0.5))
5664 (message (org-make-tdiff-string y d h m
))
5665 (when (org-at-table-p)
5666 (goto-char match-end
)
5668 (and (looking-at " *|") (goto-char (match-end 0))))
5670 "\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
5672 (if negative
(insert " -"))
5673 (if (> y
0) (insert " " (format (if havetime fy fy1
) y d h m
))
5674 (if (> d
0) (insert " " (format (if havetime fd fd1
) d h m
))
5675 (insert " " (format fh h m
))))
5676 (if align
(org-table-align))
5677 (message "Time difference inserted"))))
5679 (defun org-make-tdiff-string (y d h m
)
5682 (if (> y
0) (setq fmt
(concat fmt
"%d year" (if (> y
1) "s" "") " ")
5684 (if (> d
0) (setq fmt
(concat fmt
"%d day" (if (> d
1) "s" "") " ")
5686 (if (> h
0) (setq fmt
(concat fmt
"%d hour" (if (> h
1) "s" "") " ")
5688 (if (> m
0) (setq fmt
(concat fmt
"%d minute" (if (> m
1) "s" "") " ")
5690 (apply 'format fmt
(nreverse l
))))
5692 (defun org-time-string-to-time (s)
5693 (apply 'encode-time
(org-parse-time-string s
)))
5695 (defun org-parse-time-string (s &optional nodefault
)
5696 "Parse the standard Org-mode time string.
5697 This should be a lot faster than the normal `parse-time-string'.
5698 If time is not given, defaults to 0:00. However, with optional NODEFAULT,
5699 hour and minute fields will be nil if not given."
5700 (if (string-match org-ts-regexp1 s
)
5702 (if (or (match-beginning 8) (not nodefault
))
5703 (string-to-number (or (match-string 8 s
) "0")))
5704 (if (or (match-beginning 7) (not nodefault
))
5705 (string-to-number (or (match-string 7 s
) "0")))
5706 (string-to-number (match-string 4 s
))
5707 (string-to-number (match-string 3 s
))
5708 (string-to-number (match-string 2 s
))
5712 (defun org-timestamp-up (&optional arg
)
5713 "Increase the date item at the cursor by one.
5714 If the cursor is on the year, change the year. If it is on the month or
5715 the day, change that.
5716 With prefix ARG, change by that many units."
5718 (org-timestamp-change (prefix-numeric-value arg
)))
5720 (defun org-timestamp-down (&optional arg
)
5721 "Decrease the date item at the cursor by one.
5722 If the cursor is on the year, change the year. If it is on the month or
5723 the day, change that.
5724 With prefix ARG, change by that many units."
5726 (org-timestamp-change (- (prefix-numeric-value arg
))))
5728 (defun org-timestamp-up-day (&optional arg
)
5729 "Increase the date in the time stamp by one day.
5730 With prefix ARG, change that many days."
5732 (if (and (not (org-at-timestamp-p t
))
5735 (org-timestamp-change (prefix-numeric-value arg
) 'day
)))
5737 (defun org-timestamp-down-day (&optional arg
)
5738 "Decrease the date in the time stamp by one day.
5739 With prefix ARG, change that many days."
5741 (if (and (not (org-at-timestamp-p t
))
5744 (org-timestamp-change (- (prefix-numeric-value arg
)) 'day
)))
5746 (defsubst org-pos-in-match-range
(pos n
)
5747 (and (match-beginning n
)
5748 (<= (match-beginning n
) pos
)
5749 (>= (match-end n
) pos
)))
5751 (defun org-at-timestamp-p (&optional also-inactive
)
5752 "Determine if the cursor is in or at a timestamp."
5754 (let* ((tsr (if also-inactive org-ts-regexp3 org-ts-regexp2
))
5756 (ans (or (looking-at tsr
)
5758 (skip-chars-backward "^[<\n\r\t")
5759 (if (> (point) 1) (backward-char 1))
5760 (and (looking-at tsr
)
5761 (> (- (match-end 0) pos
) -
1))))))
5762 (and (boundp 'org-ts-what
)
5765 ((org-pos-in-match-range pos
2) 'year
)
5766 ((org-pos-in-match-range pos
3) 'month
)
5767 ((org-pos-in-match-range pos
7) 'hour
)
5768 ((org-pos-in-match-range pos
8) 'minute
)
5769 ((or (org-pos-in-match-range pos
4)
5770 (org-pos-in-match-range pos
5)) 'day
)
5774 (defun org-timestamp-change (n &optional what
)
5775 "Change the date in the time stamp at point.
5776 The date will be changed by N times WHAT. WHAT can be `day', `month',
5777 `year', `minute', `second'. If WHAT is not given, the cursor position
5778 in the timestamp determines what will be changed."
5779 (let ((fmt (car org-time-stamp-formats
))
5783 (if (not (org-at-timestamp-p t
))
5784 (error "Not at a timestamp"))
5785 (setq org-ts-what
(or what org-ts-what
))
5786 (setq fmt
(if (<= (abs (- (cdr org-ts-lengths
)
5787 (- (match-end 0) (match-beginning 0))))
5789 (cdr org-time-stamp-formats
)
5790 (car org-time-stamp-formats
)))
5791 (if (= (char-after (match-beginning 0)) ?\
[)
5792 (setq fmt
(concat "[" (substring fmt
1 -
1) "]")))
5793 (setq ts
(match-string 0))
5795 (setq time0
(org-parse-time-string ts
))
5799 (list (or (car time0
) 0))
5800 (list (+ (if (eq org-ts-what
'minute
) n
0) (nth 1 time0
)))
5801 (list (+ (if (eq org-ts-what
'hour
) n
0) (nth 2 time0
)))
5802 (list (+ (if (eq org-ts-what
'day
) n
0) (nth 3 time0
)))
5803 (list (+ (if (eq org-ts-what
'month
) n
0) (nth 4 time0
)))
5804 (list (+ (if (eq org-ts-what
'year
) n
0) (nth 5 time0
)))
5806 (if (eq what
'calendar
)
5810 (set-buffer "*Calendar*")
5811 (calendar-cursor-to-date)))))
5812 (setcar (nthcdr 4 time0
) (nth 0 cal-date
)) ; month
5813 (setcar (nthcdr 3 time0
) (nth 1 cal-date
)) ; day
5814 (setcar (nthcdr 5 time0
) (nth 2 cal-date
)) ; year
5815 (setcar time0
(or (car time0
) 0))
5816 (setcar (nthcdr 1 time0
) (or (nth 1 time0
) 0))
5817 (setcar (nthcdr 2 time0
) (or (nth 1 time0
) 0))
5818 (setq time
(apply 'encode-time time0
))))
5819 (insert (setq org-last-changed-timestamp
(format-time-string fmt time
)))
5821 ;; Try to recenter the calendar window, if any
5822 (if (and org-calendar-follow-timestamp-change
5823 (get-buffer-window "*Calendar*" t
)
5824 (memq org-ts-what
'(day month year
)))
5825 (org-recenter-calendar (time-to-days time
)))))
5827 (defun org-recenter-calendar (date)
5828 "If the calendar is visible, recenter it to DATE."
5829 (let* ((win (selected-window))
5830 (cwin (get-buffer-window "*Calendar*" t
))
5831 (calendar-move-hook nil
))
5833 (select-window cwin
)
5834 (calendar-goto-date (if (listp date
) date
5835 (calendar-gregorian-from-absolute date
)))
5836 (select-window win
))))
5838 (defun org-goto-calendar (&optional arg
)
5839 "Go to the Emacs calendar at the current date.
5840 If there is a time stamp in the current line, go to that date.
5841 A prefix ARG can be used to force the current date."
5843 (let ((tsr org-ts-regexp
) diff
5844 (calendar-move-hook nil
)
5845 (view-calendar-holidays-initially nil
)
5846 (view-diary-entries-initially nil
))
5847 (if (or (org-at-timestamp-p)
5849 (beginning-of-line 1)
5850 (looking-at (concat ".*" tsr
))))
5851 (let ((d1 (time-to-days (current-time)))
5853 (org-time-string-to-time (match-string 1)))))
5854 (setq diff
(- d2 d1
))))
5856 (calendar-goto-today)
5857 (if (and diff
(not arg
)) (calendar-forward-day diff
))))
5859 (defun org-date-from-calendar ()
5860 "Insert time stamp corresponding to cursor date in *Calendar* buffer.
5861 If there is already a time stamp at the cursor position, update it."
5863 (org-timestamp-change 0 'calendar
))
5865 ;;; The clock for measuring work time.
5867 (defvar org-clock-marker
(make-marker)
5868 "Marker recording the last clock-in.")
5870 (defun org-clock-in ()
5871 "Start the clock on the current item.
5872 If necessary, clock-out of the currently active clock."
5877 (org-back-to-heading t
)
5878 (beginning-of-line 2)
5879 (if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp
))
5880 (not (equal (match-string 1) org-clock-string
)))
5881 (beginning-of-line 1))
5882 (insert "\n") (backward-char 1)
5884 (insert org-clock-string
" "
5885 (setq ts
(concat "[" (format-time-string
5887 (cdr org-time-stamp-formats
) 1 -
1)
5890 (move-marker org-clock-marker
(point))
5891 (message "Clock started at %s" ts
))))
5893 (defun org-clock-out (&optional fail-quietly
)
5894 "Stop the currently running clock.
5895 If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
5898 (if (not (marker-buffer org-clock-marker
))
5899 (if fail-quietly
(throw 'exit t
) (error "No active clock")))
5902 (set-buffer (marker-buffer org-clock-marker
))
5903 (goto-char org-clock-marker
)
5904 (beginning-of-line 1)
5905 (if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp
))
5906 (equal (match-string 1) org-clock-string
))
5907 (setq ts
(match-string 2))
5908 (if fail-quietly
(throw 'exit nil
) (error "Clock start time is gone")))
5909 (goto-char org-clock-marker
)
5910 (setq te
(concat "[" (format-time-string
5912 (cdr org-time-stamp-formats
) 1 -
1)
5915 (setq s
(- (time-to-seconds (apply 'encode-time
(org-parse-time-string te
)))
5916 (time-to-seconds (apply 'encode-time
(org-parse-time-string ts
))))
5917 h
(floor (/ s
3600))
5921 (insert "--" te
" => " (format "%2d:%02d" h m
))
5922 (move-marker org-clock-marker nil
)
5923 (message "Clock stopped at %s after HH:MM = %d:%02d" te h m
)))))
5925 (defun org-clock-cancel ()
5926 "Cancel the running clock be removing the start timestamp."
5928 (if (not (marker-buffer org-clock-marker
))
5929 (error "No active clock"))
5931 (set-buffer (marker-buffer org-clock-marker
))
5932 (goto-char org-clock-marker
)
5933 (delete-region (1- (point-at-bol)) (point-at-eol)))
5934 (message "Clock canceled"))
5936 (defvar org-clock-file-total-minutes nil
5937 "Holds the file total time in minutes, after a call to `org-clock-sum'.")
5938 (make-variable-buffer-local 'org-clock-file-total-minutes
)
5940 (defun org-clock-sum ()
5941 "Sum the times for each subtree.
5942 Puts the resulting times in minutes as a text property on each headline."
5944 (let* ((bmp (buffer-modified-p))
5945 (re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
5947 ".*=>[ \t]*\\([0-9]+\\):\\([0-9]+\\)[ \t]*$"))
5949 (ltimes (make-vector lmax
0))
5953 (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t
))
5955 (goto-char (point-max))
5956 (while (re-search-backward re nil t
)
5959 (setq t1
(+ t1
(* 60 (string-to-number (match-string 2)))
5960 (string-to-number (match-string 3))))
5962 (setq level
(- (match-end 1) (match-beginning 1)))
5963 (when (or (> t1
0) (> (aref ltimes level
) 0))
5964 (loop for l from
0 to level do
5965 (aset ltimes l
(+ (aref ltimes l
) t1
)))
5966 (setq t1
0 time
(aref ltimes level
))
5967 (loop for l from level to
(1- lmax
) do
5969 (goto-char (match-beginning 0))
5970 (put-text-property (point) (point-at-eol) :org-clock-minutes time
))))
5971 (setq org-clock-file-total-minutes
(aref ltimes
0)))
5972 (set-buffer-modified-p bmp
)))
5974 (defun org-clock-display (&optional total-only
)
5975 "Show subtree times in the entire buffer.
5976 If TOTAL-ONLY is non-nil, only show the total time for the entire file
5979 (org-remove-clock-overlays)
5984 (goto-char (point-min))
5985 (while (setq p
(next-single-property-change (point) :org-clock-minutes
))
5987 (when (setq time
(get-text-property p
:org-clock-minutes
))
5988 (org-put-clock-overlay time
(funcall outline-level
))))
5989 (setq h
(/ org-clock-file-total-minutes
60)
5990 m
(- org-clock-file-total-minutes
(* 60 h
)))
5991 ;; Arrange to remove the overlays upon next change.
5992 (org-add-hook 'before-change-functions
'org-remove-clock-overlays
5994 (message "Total file time: %d:%02d (%d hours and %d minutes)" h m h m
)))
5996 (defvar org-clock-overlays nil
)
5997 (make-variable-buffer-local 'org-clock-overlays
)
5999 (defun org-put-clock-overlay (time &optional level
)
6000 "Put an overlays on the current line, displaying TIME.
6001 If LEVEL is given, prefix time with a corresponding number of stars.
6002 This creates a new overlay and stores it in `org-clock-overlays', so that it
6003 will be easy to remove."
6004 (let* ((c 60) (h (floor (/ time
60))) (m (- time
(* 60 h
)))
6005 (l (if level
(org-get-legal-level level
0) 0))
6009 (unless (eolp) (skip-chars-backward "^ \t"))
6010 (skip-chars-backward " \t")
6011 (setq ov
(org-make-overlay (1- (point)) (point-at-eol))
6012 tx
(concat (buffer-substring (1- (point)) (point))
6013 (make-string (+ off
(max 0 (- c
(current-column)))) ?.
)
6014 (org-add-props (format "%s %2d:%02d%s"
6015 (make-string l ?
*) h m
6016 (make-string (- 10 l
) ?\
))
6017 '(face secondary-selection
))
6019 (org-overlay-put ov
'display tx
)
6020 (push ov org-clock-overlays
)))
6022 (defun org-remove-clock-overlays (&optional beg end noremove
)
6023 "Remove the occur highlights from the buffer.
6024 BEG and END are ignored. If NOREMOVE is nil, remove this function
6025 from the `before-change-functions' in the current buffer."
6027 (unless org-inhibit-highlight-removal
6028 (mapc 'org-delete-overlay org-clock-overlays
)
6029 (setq org-clock-overlays nil
)
6031 (remove-hook 'before-change-functions
6032 'org-remove-clock-overlays
'local
))))
6034 (defun org-clock-out-if-current ()
6035 "Clock out if the current entry contains the running clock.
6036 This is used to stop the clock after a TODO entry is marked DONE."
6037 (when (and (equal state org-done-string
)
6038 (equal (marker-buffer org-clock-marker
) (current-buffer))
6039 (< (point) org-clock-marker
)
6040 (> (save-excursion (outline-next-heading) (point))
6044 (add-hook 'org-after-todo-state-change-hook
6045 'org-clock-out-if-current
)
6047 (defun org-check-running-clock ()
6048 "Check if the current buffer contains the running clock.
6049 If yes, offer to stop it and to save the buffer with the changes."
6050 (when (and (equal (marker-buffer org-clock-marker
) (current-buffer))
6051 (y-or-n-p (format "Clock-out in buffer %s before killing it? "
6054 (when (y-or-n-p "Save changed buffer?")
6057 (defun org-clock-report ()
6058 "Create a table containing a report about clocked time.
6059 If the buffer contains lines
6060 #+BEGIN: clocktable :maxlevel 3 :emphasize nil
6063 then the table will be inserted between these lines, replacing whatever
6064 is was there before. If these lines are not in the buffer, the table
6065 is inserted at point, surrounded by the special lines.
6066 The BEGIN line can contain parameters. Allowed are:
6067 :maxlevel The maximum level to be included in the table. Default is 3.
6068 :emphasize t/nil, if levell 1 and level 2 should be bold/italic in the table."
6070 (org-remove-clock-overlays)
6071 (unless (org-find-dblock "clocktable")
6072 (org-create-dblock (list :name
"clocktable"
6073 :maxlevel
2 :emphasize nil
)))
6074 (org-update-dblock))
6076 (defun org-dblock-write:clocktable
(params)
6077 "Write the standard clocktable."
6078 (let ((hlchars '((1 .
"*") (2 . ?
/)))
6081 ipos time h m p level hlc hdl maxlevel
)
6082 (setq maxlevel
(or (plist-get params
:maxlevel
) 3)
6083 emph
(plist-get params
:emphasize
))
6084 (move-marker ins
(point))
6086 (insert-before-markers "Clock summary at ["
6088 (format-time-string (cdr org-time-stamp-formats
))
6090 "]\n|L|Headline|Time|\n")
6092 (setq h
(/ org-clock-file-total-minutes
60)
6093 m
(- org-clock-file-total-minutes
(* 60 h
)))
6094 (insert-before-markers "|-\n|0|" "*Total file time*| "
6095 (format "*%d:%02d*" h m
)
6097 (goto-char (point-min))
6098 (while (setq p
(next-single-property-change (point) :org-clock-minutes
))
6100 (when (setq time
(get-text-property p
:org-clock-minutes
))
6101 (beginning-of-line 1)
6102 (when (and (looking-at "\\(\\*+\\)[ \t]+\\(.*?\\)\\([ \t]+:[0-9a-zA-Z_@:]+:\\)?[ \t]*$")
6103 (setq level
(- (match-end 1) (match-beginning 1)))
6104 (<= level maxlevel
))
6105 (setq hlc
(if emph
(or (cdr (assoc level hlchars
)) "") "")
6106 hdl
(match-string 2)
6108 m
(- time
(* 60 h
)))
6111 (if (= level
1) (insert-before-markers "|-\n"))
6112 (insert-before-markers
6113 "| " (int-to-string level
) "|" hlc hdl hlc
" |"
6114 (make-string (1- level
) ?|
)
6116 (format "%d:%02d" h m
)
6120 (backward-delete-char 1)
6122 (skip-chars-forward "^|")
6125 (defun org-collect-clock-time-entries ()
6126 "Return an internal list with clocking information.
6127 This list has one entry for each CLOCK interval.
6128 FIXME: describe the elements."
6130 (let ((re (concat "^[ \t]*" org-clock-string
6131 " *\\[\\(.*?\\)\\]--\\[\\(.*?\\)\\]"))
6132 rtn beg end next cont level title total closedp leafp
6133 clockpos titlepos h m donep
)
6136 (goto-char (point-min))
6137 (while (re-search-forward re nil t
)
6138 (setq clockpos
(match-beginning 0)
6139 beg
(match-string 1) end
(match-string 2)
6141 (setq beg
(apply 'encode-time
(org-parse-time-string beg
))
6142 end
(apply 'encode-time
(org-parse-time-string end
)))
6143 (org-back-to-heading t
)
6144 (setq donep
(org-entry-is-done-p))
6145 (setq titlepos
(point)
6146 total
(or (get-text-property (1+ (point)) :org-clock-minutes
) 0)
6147 h
(/ total
60) m
(- total
(* 60 h
))
6149 (looking-at "\\(\\*+\\) +\\(.*\\)")
6150 (setq level
(- (match-end 1) (match-beginning 1))
6151 title
(org-match-string-no-properties 2))
6152 (save-excursion (outline-next-heading) (setq next
(point)))
6153 (setq closedp
(re-search-forward org-closed-time-regexp next t
))
6155 (setq leafp
(and (looking-at "^\\*+ ")
6156 (<= (- (match-end 0) (point)) level
)))
6157 (push (list beg end clockpos closedp donep
6158 total title titlepos level leafp
)
6163 ;;; Agenda, and Diary Integration
6167 (defvar org-agenda-mode-map
(make-sparse-keymap)
6168 "Keymap for `org-agenda-mode'.")
6170 (defvar org-agenda-menu
) ; defined later in this file.
6171 (defvar org-agenda-follow-mode nil
)
6172 (defvar org-agenda-show-log nil
)
6173 (defvar org-agenda-buffer-name
"*Org Agenda*")
6174 (defvar org-agenda-redo-command nil
)
6175 (defvar org-agenda-mode-hook nil
)
6176 (defvar org-agenda-type nil
)
6177 (defvar org-agenda-force-single-file nil
)
6179 (defun org-agenda-mode ()
6180 "Mode for time-sorted view on action items in Org-mode files.
6182 The following commands are available:
6184 \\{org-agenda-mode-map}"
6186 (kill-all-local-variables)
6187 (setq major-mode
'org-agenda-mode
)
6188 (setq mode-name
"Org-Agenda")
6189 (use-local-map org-agenda-mode-map
)
6190 (easy-menu-add org-agenda-menu
)
6191 (if org-startup-truncated
(setq truncate-lines t
))
6192 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
6193 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
6194 (unless org-agenda-keep-modes
6195 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
6196 org-agenda-show-log nil
))
6198 '("Agenda") "Agenda Files"
6202 (if (get 'org-agenda-files
'org-restrict
)
6203 "Restricted to single file"
6205 '(org-edit-agenda-file-list)
6206 (not (get 'org-agenda-files
'org-restrict
)))
6208 (mapcar 'org-file-menu-entry
(org-agenda-files))))
6209 (org-agenda-set-mode-name)
6211 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
6212 (list 'org-agenda-mode-hook
)))
6214 (define-key org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
6215 (define-key org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
6216 (define-key org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
6217 (define-key org-agenda-mode-map
" " 'org-agenda-show
)
6218 (define-key org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
6219 (define-key org-agenda-mode-map
"o" 'delete-other-windows
)
6220 (define-key org-agenda-mode-map
"L" 'org-agenda-recenter
)
6221 (define-key org-agenda-mode-map
"t" 'org-agenda-todo
)
6222 (define-key org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
6223 (define-key org-agenda-mode-map
":" 'org-agenda-set-tags
)
6224 (define-key org-agenda-mode-map
"." 'org-agenda-goto-today
)
6225 (define-key org-agenda-mode-map
"d" 'org-agenda-day-view
)
6226 (define-key org-agenda-mode-map
"w" 'org-agenda-week-view
)
6227 (define-key org-agenda-mode-map
(org-key 'S-right
) 'org-agenda-date-later
)
6228 (define-key org-agenda-mode-map
(org-key 'S-left
) 'org-agenda-date-earlier
)
6229 (define-key org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-date-later
)
6230 (define-key org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-date-earlier
)
6232 (define-key org-agenda-mode-map
">" 'org-agenda-date-prompt
)
6233 (define-key org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
6234 (define-key org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
6235 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
6236 (while l
(define-key org-agenda-mode-map
6237 (int-to-string (pop l
)) 'digit-argument
)))
6239 (define-key org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
6240 (define-key org-agenda-mode-map
"l" 'org-agenda-log-mode
)
6241 (define-key org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
6242 (define-key org-agenda-mode-map
"g" 'org-agenda-toggle-time-grid
)
6243 (define-key org-agenda-mode-map
"r" 'org-agenda-redo
)
6244 (define-key org-agenda-mode-map
"q" 'org-agenda-quit
)
6245 (define-key org-agenda-mode-map
"x" 'org-agenda-exit
)
6246 (define-key org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
6247 (define-key org-agenda-mode-map
"P" 'org-agenda-show-priority
)
6248 (define-key org-agenda-mode-map
"T" 'org-agenda-show-tags
)
6249 (define-key org-agenda-mode-map
"n" 'next-line
)
6250 (define-key org-agenda-mode-map
"p" 'previous-line
)
6251 (define-key org-agenda-mode-map
"\C-n" 'org-agenda-next-date-line
)
6252 (define-key org-agenda-mode-map
"\C-p" 'org-agenda-previous-date-line
)
6253 (define-key org-agenda-mode-map
"," 'org-agenda-priority
)
6254 (define-key org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
6255 (define-key org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
6256 (define-key org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
6257 (eval-after-load "calendar"
6258 '(define-key calendar-mode-map org-calendar-to-agenda-key
6259 'org-calendar-goto-agenda
))
6260 (define-key org-agenda-mode-map
"C" 'org-agenda-convert-date
)
6261 (define-key org-agenda-mode-map
"m" 'org-agenda-phases-of-moon
)
6262 (define-key org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
6263 (define-key org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
6264 (define-key org-agenda-mode-map
"h" 'org-agenda-holidays
)
6265 (define-key org-agenda-mode-map
"H" 'org-agenda-holidays
)
6266 (define-key org-agenda-mode-map
"+" 'org-agenda-priority-up
)
6267 (define-key org-agenda-mode-map
"I" 'org-agenda-clock-in
)
6268 (define-key org-agenda-mode-map
"O" 'org-clock-out
)
6269 (define-key org-agenda-mode-map
"X" 'org-clock-cancel
)
6270 (define-key org-agenda-mode-map
"-" 'org-agenda-priority-down
)
6271 (define-key org-agenda-mode-map
(org-key 'S-up
) 'org-agenda-priority-up
)
6272 (define-key org-agenda-mode-map
(org-key 'S-down
) 'org-agenda-priority-down
)
6273 (define-key org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
6274 (define-key org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
6275 (define-key org-agenda-mode-map
[(right)] 'org-agenda-later
)
6276 (define-key org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
6277 (define-key org-agenda-mode-map
"\C-c\C-x\C-c" 'org-export-icalendar-combine-agenda-files
)
6278 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
6279 "Local keymap for agenda entries from Org-mode.")
6281 (define-key org-agenda-keymap
6282 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
6283 (define-key org-agenda-keymap
6284 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
6285 (when org-agenda-mouse-1-follows-link
6286 (define-key org-agenda-keymap
[follow-link
] 'mouse-face
))
6287 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
6291 ["Show" org-agenda-show t
]
6292 ["Go To (other window)" org-agenda-goto t
]
6293 ["Go To (one window)" org-agenda-switch-to t
]
6294 ["Follow Mode" org-agenda-follow-mode
6295 :style toggle
:selected org-agenda-follow-mode
:active t
]
6297 ["Cycle TODO" org-agenda-todo t
]
6299 ["Show all Tags" org-agenda-show-tags t
]
6300 ["Set Tags" org-agenda-set-tags t
])
6302 ["Schedule" org-agenda-schedule t
]
6303 ["Set Deadline" org-agenda-deadline t
]
6305 ["Reschedule +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
6306 ["Reschedule -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
6307 ["Reschedule to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
6309 ["Set Priority" org-agenda-priority t
]
6310 ["Increase Priority" org-agenda-priority-up t
]
6311 ["Decrease Priority" org-agenda-priority-down t
]
6312 ["Show Priority" org-agenda-show-priority t
])
6314 ;; ["New agenda command" org-agenda t]
6315 ["Rebuild buffer" org-agenda-redo t
]
6316 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
6318 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
6319 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
6320 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
6322 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
6323 :style radio
:selected
(equal org-agenda-ndays
1)]
6324 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
6325 :style radio
:selected
(equal org-agenda-ndays
7)]
6327 ["Show Logbook entries" org-agenda-log-mode
6328 :style toggle
:selected org-agenda-show-log
:active
(org-agenda-check-type nil
'agenda
'timeline
)]
6329 ["Include Diary" org-agenda-toggle-diary
6330 :style toggle
:selected org-agenda-include-diary
:active
(org-agenda-check-type nil
'agenda
)]
6331 ["Use Time Grid" org-agenda-toggle-time-grid
6332 :style toggle
:selected org-agenda-use-time-grid
:active
(org-agenda-check-type nil
'agenda
)]
6334 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
6335 ("Calendar Commands"
6336 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
6337 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
6338 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
6339 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
6340 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)])
6341 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
]
6343 ["Quit" org-agenda-quit t
]
6344 ["Exit and Release Buffers" org-agenda-exit t
]
6348 (defun org-agenda (arg)
6349 "Dispatch agenda commands to collect entries to the agenda buffer.
6350 Prompts for a character to select a command. Any prefix arg will be passed
6351 on to the selected command. The default selections are:
6353 a Call `org-agenda' to display the agenda for the current day or week.
6354 t Call `org-todo-list' to display the global todo list.
6355 T Call `org-todo-list' to display the global todo list, select only
6356 entries with a specific TODO keyword (the user gets a prompt).
6357 m Call `org-tags-view' to display headlines with tags matching
6358 a condition (the user is prompted for the condition).
6359 M Like `m', but select only TODO entries, no ordinary headlines.
6361 More commands can be added by configuring the variable
6362 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
6363 searches can be pre-defined in this way.
6365 If the current buffer is in Org-mode and visiting a file, you can also
6366 first press `1' to indicate that the agenda should be temporarily (until the
6367 next use of \\[org-agenda]) restricted to the current file."
6370 (let ((restrict-ok (and buffer-file-name
(org-mode-p)))
6371 (bfn buffer-file-name
)
6372 (custom org-agenda-custom-commands
)
6373 c entry key type string
)
6374 (put 'org-agenda-files
'org-restrict nil
)
6375 (save-window-excursion
6376 (delete-other-windows)
6377 (switch-to-buffer-other-window " *Agenda Commands*")
6380 "Press key for an agenda command:
6381 --------------------------------
6382 a Agenda for current week or day
6383 t List of all TODO entries T Entries with special TODO kwd
6384 m Match a TAGS query M Like m, but only TODO entries
6385 C Configure your own agenda commands")
6386 (while (setq entry
(pop custom
))
6387 (setq key
(car entry
) type
(nth 1 entry
) string
(nth 2 entry
))
6388 (insert (format "\n%-4s%-14s: %s"
6391 ((eq type
'tags
) "Tags query")
6392 ((eq type
'todo
) "TODO keyword")
6393 ((eq type
'tags-tree
) "Tags tree")
6394 ((eq type
'todo-tree
) "TODO kwd tree")
6395 ((eq type
'occur-tree
) "Occur tree")
6397 (org-add-props string nil
'face
'org-warning
))))
6398 (goto-char (point-min))
6399 (if (fboundp 'fit-window-to-buffer
) (fit-window-to-buffer))
6400 (message "Press key for agenda command%s"
6401 (if restrict-ok
", or [1] to restrict to current file" ""))
6402 (setq c
(read-char-exclusive))
6406 (put 'org-agenda-files
'org-restrict
(list bfn
))
6407 (error "Cannot restrict agenda to current buffer"))
6408 (message "Press key for agenda command%s"
6409 (if restrict-ok
" (restricted to current file)" ""))
6410 (setq c
(read-char-exclusive))
6412 (require 'calendar
) ; FIXME: can we avoid this for some commands?
6413 ;; For example the todo list should not need it (but does...)
6415 ((equal c ?C
) (customize-variable 'org-agenda-custom-commands
))
6416 ((equal c ?a
) (call-interactively 'org-agenda-list
))
6417 ((equal c ?t
) (call-interactively 'org-todo-list
))
6418 ((equal c ?T
) (org-call-with-arg 'org-todo-list
(or arg
'(4))))
6419 ((equal c ?m
) (call-interactively 'org-tags-view
))
6420 ((equal c ?M
) (org-call-with-arg 'org-tags-view
(or arg
'(4))))
6421 ((setq entry
(assoc (char-to-string c
) org-agenda-custom-commands
))
6422 (setq type
(nth 1 entry
) string
(nth 2 entry
))
6425 (org-tags-view current-prefix-arg string
))
6426 ((eq type
'tags-todo
)
6427 (org-tags-view '(4) string
))
6429 (org-todo-list string
))
6430 ((eq type
'tags-tree
)
6431 (org-check-for-org-mode)
6432 (org-tags-sparse-tree current-prefix-arg string
))
6433 ((eq type
'todo-tree
)
6434 (org-check-for-org-mode)
6435 (org-occur (concat "^" outline-regexp
"[ \t]*"
6436 (regexp-quote string
) "\\>")))
6437 ((eq type
'occur-tree
)
6438 (org-check-for-org-mode)
6440 (t (error "Invalid custom agenda command type %s" type
))))
6441 (t (error "Invalid key"))))))
6443 (defun org-check-for-org-mode ()
6444 "Make sure current buffer is in org-mode. Error if not."
6446 (error "Cannot execute org-mode agenda command on buffer in %s."
6449 (defun org-fit-agenda-window ()
6450 "Fit the window to the buffer size."
6451 (and org-fit-agenda-window
6452 (fboundp 'fit-window-to-buffer
)
6453 (fit-window-to-buffer nil
(/ (* (frame-height) 3) 4)
6454 (/ (frame-height) 2))))
6456 (defun org-agenda-files (&optional unrestricted
)
6457 "Get the list of agenda files.
6458 Optional UNRESTRICTED means return the full list even if a restriction
6459 is currently in place."
6461 ((and (not unrestricted
) (get 'org-agenda-files
'org-restrict
)))
6462 ((stringp org-agenda-files
) (org-read-agenda-file-list))
6463 ((listp org-agenda-files
) org-agenda-files
)
6464 (t (error "Invalid value of `org-agenda-files'"))))
6466 (defvar org-window-configuration
)
6468 (defun org-edit-agenda-file-list ()
6469 "Edit the list of agenda files.
6470 Depending on setup, this either uses customize to edit the variable
6471 `org-agenda-files', or it visits the file that is holding the list. In the
6472 latter case, the buffer is set up in a way that saving it automatically kills
6473 the buffer and restores the previous window configuration."
6475 (if (stringp org-agenda-files
)
6476 (let ((cw (current-window-configuration)))
6477 (find-file org-agenda-files
)
6478 (set (make-local-variable 'org-window-configuration
) cw
)
6479 (org-add-hook 'after-save-hook
6481 (set-window-configuration
6482 (prog1 org-window-configuration
6483 (kill-buffer (current-buffer))))
6484 (org-install-agenda-files-menu)
6485 (message "New agenda file list installed"))
6487 (message (substitute-command-keys
6488 "Edit list and finish with \\[save-buffer]")))
6489 (customize-variable 'org-agenda-files
)))
6491 (defun org-store-new-agenda-file-list (list)
6492 "Set new value for the agenda file list and save it correcly."
6493 (if (stringp org-agenda-files
)
6494 (let ((f org-agenda-files
) b
)
6495 (while (setq b
(find-buffer-visiting f
)) (kill-buffer b
))
6497 (insert (mapconcat 'identity list
"\n") "\n")))
6498 (let ((org-mode-hook nil
) (default-major-mode 'fundamental-mode
))
6499 (setq org-agenda-files list
)
6500 (customize-save-variable 'org-agenda-files org-agenda-files
))))
6502 (defun org-read-agenda-file-list ()
6503 "Read the list of agenda files from a file."
6504 (when (stringp org-agenda-files
)
6506 (insert-file-contents org-agenda-files
)
6507 (org-split-string (buffer-string) "[ \t\r\n]*?[\r\n][ \t\r\n]*"))))
6509 (defvar org-agenda-markers nil
6510 "List of all currently active markers created by `org-agenda'.")
6511 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
6512 "Creation time of the last agenda marker.")
6514 (defun org-agenda-new-marker (&optional pos
)
6515 "Return a new agenda marker.
6516 Org-mode keeps a list of these markers and resets them when they are
6518 (let ((m (copy-marker (or pos
(point)))))
6519 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
6520 (push m org-agenda-markers
)
6523 (defun org-agenda-maybe-reset-markers (&optional force
)
6524 "Reset markers created by `org-agenda'. But only if they are old enough."
6526 (> (- (time-to-seconds (current-time))
6527 org-agenda-last-marker-time
)
6529 (while org-agenda-markers
6530 (move-marker (pop org-agenda-markers
) nil
))))
6532 (defvar org-agenda-new-buffers nil
6533 "Buffers created to visit agenda files.")
6535 (defun org-get-agenda-file-buffer (file)
6536 "Get a buffer visiting FILE. If the buffer needs to be created, add
6537 it to the list of buffers which might be released later."
6538 (let ((buf (find-buffer-visiting file
)))
6540 buf
; just return it
6541 ;; Make a new buffer and remember it
6542 (setq buf
(find-file-noselect file
))
6543 (if buf
(push buf org-agenda-new-buffers
))
6546 (defun org-release-buffers (blist)
6547 "Release all buffers in list, asking the user for confirmation when needed.
6548 When a buffer is unmodified, it is just killed. When modified, it is saved
6549 \(if the user agrees) and then killed."
6551 (while (setq buf
(pop blist
))
6552 (setq file
(buffer-file-name buf
))
6553 (when (and (buffer-modified-p buf
)
6555 (y-or-n-p (format "Save file %s? " file
)))
6556 (with-current-buffer buf
(save-buffer)))
6557 (kill-buffer buf
))))
6559 (defvar org-respect-restriction nil
) ; Dynamically-scoped param.
6561 (defun org-timeline (&optional include-all keep-modes
)
6562 "Show a time-sorted view of the entries in the current org file.
6563 Only entries with a time stamp of today or later will be listed. With
6564 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
6565 under the current date.
6566 If the buffer contains an active region, only check the region for
6570 (org-agenda-maybe-reset-markers 'force
)
6571 (org-compile-prefix-format org-timeline-prefix-format
)
6573 (dotodo include-all
)
6574 (doclosed org-agenda-show-log
)
6575 (org-agenda-keep-modes keep-modes
)
6576 (entry buffer-file-name
)
6577 (org-agenda-files (list buffer-file-name
))
6578 (date (calendar-current-date))
6579 (win (selected-window))
6581 (beg (if (org-region-active-p) (region-beginning) (point-min)))
6582 (end (if (org-region-active-p) (region-end) (point-max)))
6583 (day-numbers (org-get-all-dates beg end
'no-ranges
6584 t doclosed
; always include today
6585 org-timeline-show-empty-dates
))
6586 (today (time-to-days (current-time)))
6587 (org-respect-restriction t
)
6591 (org-prepare-agenda-buffers org-agenda-files
)
6592 (setq org-agenda-redo-command
6594 (list 'switch-to-buffer-other-window
(current-buffer))
6595 (list 'org-timeline
(list 'quote include-all
) t
)))
6597 ;; Remove past dates from the list of dates.
6598 (setq day-numbers
(delq nil
(mapcar (lambda(x)
6599 (if (>= x today
) x nil
))
6601 (switch-to-buffer-other-window
6602 (get-buffer-create org-agenda-buffer-name
))
6603 (setq buffer-read-only nil
)
6605 (org-agenda-mode) (setq buffer-read-only nil
)
6606 (set (make-local-variable 'org-agenda-type
) 'timeline
)
6607 (if doclosed
(push :closed args
))
6608 (push :timestamp args
)
6609 (if dotodo
(push :todo args
))
6610 (while (setq d
(pop day-numbers
))
6611 (if (and (listp d
) (eq (car d
) :omitted
))
6614 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
6615 (put-text-property s
(1- (point)) 'face
'org-level-3
))
6616 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
6617 (if (and (>= d today
)
6622 (insert (make-string 79 ?-
) "\n")))
6623 (setq date
(calendar-gregorian-from-absolute d
))
6625 (setq rtn
(and (not emptyp
)
6626 (apply 'org-agenda-get-day-entries
6628 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
6630 (insert (calendar-day-name date
) " "
6631 (number-to-string (extract-calendar-day date
)) " "
6632 (calendar-month-name (extract-calendar-month date
)) " "
6633 (number-to-string (extract-calendar-year date
)) "\n")
6634 (put-text-property s
(1- (point)) 'face
6637 (put-text-property s
(1- (point)) 'org-today t
))
6638 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
6639 (put-text-property s
(1- (point)) 'day d
)))))
6640 (goto-char (point-min))
6641 (setq buffer-read-only t
)
6642 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
6644 (when (not org-select-timeline-window
)
6649 (defun org-agenda-list (&optional include-all start-day ndays keep-modes
)
6650 "Produce a weekly view from all files in variable `org-agenda-files'.
6651 The view will be for the current week, but from the overview buffer you
6652 will be able to go to other weeks.
6653 With one \\[universal-argument] prefix argument INCLUDE-ALL, all unfinished TODO items will
6654 also be shown, under the current date.
6655 With two \\[universal-argument] prefix argument INCLUDE-ALL, all TODO entries marked DONE
6656 on the days are also shown. See the variable `org-log-done' for how
6658 START-DAY defaults to TODAY, or to the most recent match for the weekday
6659 given in `org-agenda-start-on-weekday'.
6660 NDAYS defaults to `org-agenda-ndays'."
6662 (org-agenda-maybe-reset-markers 'force
)
6663 (org-compile-prefix-format org-agenda-prefix-format
)
6665 (let* ((org-agenda-start-on-weekday
6666 (if (or (equal ndays
1)
6667 (and (null ndays
) (equal 1 org-agenda-ndays
)))
6668 nil org-agenda-start-on-weekday
))
6669 (org-agenda-keep-modes keep-modes
)
6670 (thefiles (org-agenda-files))
6672 (win (selected-window))
6673 (today (time-to-days (current-time)))
6674 (sd (or start-day today
))
6675 (start (if (or (null org-agenda-start-on-weekday
)
6676 (< org-agenda-ndays
7))
6678 (let* ((nt (calendar-day-of-week
6679 (calendar-gregorian-from-absolute sd
)))
6680 (n1 org-agenda-start-on-weekday
)
6682 (- sd
(+ (if (< d
0) 7 0) d
)))))
6683 (day-numbers (list start
))
6684 (inhibit-redisplay t
)
6685 s e rtn rtnall file date d start-pos end-pos todayp nd
)
6686 (org-prepare-agenda-buffers files
)
6687 (setq org-agenda-redo-command
6688 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays t
))
6689 ;; Make the list of days
6690 (setq ndays
(or ndays org-agenda-ndays
)
6693 (push (1+ (car day-numbers
)) day-numbers
)
6694 (setq ndays
(1- ndays
)))
6695 (setq day-numbers
(nreverse day-numbers
))
6696 (if (not (equal (current-buffer) (get-buffer org-agenda-buffer-name
)))
6698 (delete-other-windows)
6699 (switch-to-buffer-other-window
6700 (get-buffer-create org-agenda-buffer-name
))))
6701 (setq buffer-read-only nil
)
6703 (org-agenda-mode) (setq buffer-read-only nil
)
6704 (set (make-local-variable 'org-agenda-type
) 'agenda
)
6705 (set (make-local-variable 'starting-day
) (car day-numbers
))
6706 (set (make-local-variable 'include-all-loc
) include-all
)
6707 (when (and (or include-all org-agenda-include-all-todo
)
6708 (member today day-numbers
))
6709 (setq files thefiles
6711 (while (setq file
(pop files
))
6713 (org-check-agenda-file file
)
6714 (setq date
(calendar-gregorian-from-absolute today
)
6715 rtn
(org-agenda-get-day-entries
6717 (setq rtnall
(append rtnall rtn
))))
6719 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
6720 (add-text-properties (point-min) (1- (point))
6721 (list 'face
'org-level-3
))
6722 (insert (org-finalize-agenda-entries rtnall
) "\n")))
6723 (while (setq d
(pop day-numbers
))
6724 (setq date
(calendar-gregorian-from-absolute d
)
6726 (if (or (setq todayp
(= d today
))
6727 (and (not start-pos
) (= d sd
)))
6728 (setq start-pos
(point))
6729 (if (and start-pos
(not end-pos
))
6730 (setq end-pos
(point))))
6731 (setq files thefiles
6733 (while (setq file
(pop files
))
6735 (org-check-agenda-file file
)
6736 (if org-agenda-show-log
6737 (setq rtn
(org-agenda-get-day-entries
6739 :deadline
:scheduled
:timestamp
:closed
))
6740 (setq rtn
(org-agenda-get-day-entries
6742 :deadline
:scheduled
:timestamp
)))
6743 (setq rtnall
(append rtnall rtn
))))
6744 (if org-agenda-include-diary
6746 (require 'diary-lib
)
6747 (setq rtn
(org-get-entries-from-diary date
))
6748 (setq rtnall
(append rtnall rtn
))))
6749 (if (or rtnall org-agenda-show-all-dates
)
6751 (insert (format "%-9s %2d %s %4d\n"
6752 (calendar-day-name date
)
6753 (extract-calendar-day date
)
6754 (calendar-month-name (extract-calendar-month date
))
6755 (extract-calendar-year date
)))
6756 (put-text-property s
(1- (point)) 'face
6759 (org-finalize-agenda-entries
6760 (org-agenda-add-time-grid-maybe
6763 (put-text-property s
(1- (point)) 'day d
))))
6764 (goto-char (point-min))
6765 (setq buffer-read-only t
)
6766 (org-fit-agenda-window)
6767 (unless (and (pos-visible-in-window-p (point-min))
6768 (pos-visible-in-window-p (point-max)))
6769 (goto-char (1- (point-max)))
6771 (if (not (pos-visible-in-window-p (or start-pos
1)))
6773 (goto-char (or start-pos
1))
6775 (goto-char (or start-pos
1))
6776 (if (not org-select-agenda-window
) (select-window win
))
6779 (defvar org-select-this-todo-keyword nil
)
6782 (defun org-todo-list (arg &optional keep-modes
)
6783 "Show all TODO entries from all agenda file in a single list.
6784 The prefix arg can be used to select a specific TODO keyword and limit
6785 the list to these. When using \\[universal-argument], you will be prompted
6786 for a keyword. A numeric prefix directly selects the Nth keyword in
6787 `org-todo-keywords'."
6789 (org-agenda-maybe-reset-markers 'force
)
6790 (org-compile-prefix-format org-agenda-prefix-format
)
6791 (let* ((org-agenda-keep-modes keep-modes
)
6792 (today (time-to-days (current-time)))
6793 (date (calendar-gregorian-from-absolute today
))
6794 (win (selected-window))
6795 (kwds org-todo-keywords
)
6796 (completion-ignore-case t
)
6797 (org-select-this-todo-keyword
6798 (if (stringp arg
) arg
6799 (and arg
(integerp arg
) (> arg
0)
6800 (nth (1- arg
) org-todo-keywords
))))
6801 rtn rtnall files file pos
)
6802 (when (equal arg
'(4))
6803 (setq org-select-this-todo-keyword
6804 (completing-read "Keyword: " (mapcar 'list org-todo-keywords
)
6806 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
6807 (if (not (equal (current-buffer) (get-buffer org-agenda-buffer-name
)))
6809 (delete-other-windows)
6810 (switch-to-buffer-other-window
6811 (get-buffer-create org-agenda-buffer-name
))))
6812 (setq buffer-read-only nil
)
6814 (org-agenda-mode) (setq buffer-read-only nil
)
6815 (set (make-local-variable 'org-agenda-type
) 'todo
)
6816 (set (make-local-variable 'last-arg
) arg
)
6817 (set (make-local-variable 'org-todo-keywords
) kwds
)
6818 (set (make-local-variable 'org-agenda-redo-command
)
6819 '(org-todo-list (or current-prefix-arg last-arg
) t
))
6820 (setq files
(org-agenda-files)
6822 (org-prepare-agenda-buffers files
)
6823 (while (setq file
(pop files
))
6825 (org-check-agenda-file file
)
6826 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
6827 (setq rtnall
(append rtnall rtn
))))
6828 (insert "Global list of TODO items of type: ")
6829 (add-text-properties (point-min) (1- (point))
6830 (list 'face
'org-level-3
))
6832 (insert (or org-select-this-todo-keyword
"ALL") "\n")
6833 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
6836 "Available with `N r': (0)ALL "
6838 (mapconcat (lambda (x)
6839 (format "(%d)%s" (setq n
(1+ n
)) x
))
6840 org-todo-keywords
" "))
6842 (add-text-properties pos
(1- (point)) (list 'face
'org-level-3
))
6844 (insert (org-finalize-agenda-entries rtnall
) "\n"))
6845 (goto-char (point-min))
6846 (setq buffer-read-only t
)
6847 (org-fit-agenda-window)
6848 (if (not org-select-agenda-window
) (select-window win
))))
6850 (defun org-check-agenda-file (file)
6851 "Make sure FILE exists. If not, ask user what to do."
6852 (when (not (file-exists-p file
))
6853 (message "non-existent file %s. [R]emove from list or [A]bort?"
6854 (abbreviate-file-name file
))
6855 (let ((r (downcase (read-char-exclusive))))
6858 (org-remove-file file
)
6859 (throw 'nextfile t
))
6860 (t (error "Abort"))))))
6862 (defun org-agenda-check-type (error &rest types
)
6863 "Check if agenda buffer is of allowed type.
6864 If ERROR is non-nil, throw an error, otherwise just return nil."
6865 (if (memq org-agenda-type types
)
6868 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
6871 (defun org-agenda-quit ()
6872 "Exit agenda by removing the window or the buffer."
6874 (let ((buf (current-buffer)))
6875 (if (not (one-window-p)) (delete-window))
6877 (org-agenda-maybe-reset-markers 'force
)))
6879 (defun org-agenda-exit ()
6880 "Exit agenda by removing the window or the buffer.
6881 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6882 Org-mode buffers visited directly by the user will not be touched."
6884 (org-release-buffers org-agenda-new-buffers
)
6885 (setq org-agenda-new-buffers nil
)
6888 ;; FIXME: move this function.
6889 (defun org-save-all-org-buffers ()
6890 "Save all Org-mode buffers without user confirmation."
6892 (message "Saving all Org-mode buffers...")
6893 (save-some-buffers t
'org-mode-p
)
6894 (message "Saving all Org-mode buffers... done"))
6896 (defun org-agenda-redo ()
6898 When this is the global TODO list, a prefix argument will be interpreted."
6900 (message "Rebuilding agenda buffer...")
6901 (eval org-agenda-redo-command
)
6902 (message "Rebuilding agenda buffer...done"))
6904 (defun org-agenda-goto-today ()
6907 (org-agenda-check-type t
'timeline
'agenda
)
6908 (if (boundp 'starting-day
)
6909 (let ((cmd (car org-agenda-redo-command
))
6910 (iall (nth 1 org-agenda-redo-command
))
6911 (nday (nth 3 org-agenda-redo-command
))
6912 (keep (nth 4 org-agenda-redo-command
)))
6913 (eval (list cmd iall nil nday keep
)))
6914 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
6917 (defun org-agenda-later (arg)
6918 "Go forward in time by `org-agenda-ndays' days.
6919 With prefix ARG, go forward that many times `org-agenda-ndays'."
6921 (org-agenda-check-type t
'agenda
)
6922 (org-agenda-list (if (boundp 'include-all-loc
) include-all-loc nil
)
6923 (+ starting-day
(* arg org-agenda-ndays
)) nil t
))
6925 (defun org-agenda-earlier (arg)
6926 "Go back in time by `org-agenda-ndays' days.
6927 With prefix ARG, go back that many times `org-agenda-ndays'."
6929 (org-agenda-check-type t
'agenda
)
6930 (org-agenda-list (if (boundp 'include-all-loc
) include-all-loc nil
)
6931 (- starting-day
(* arg org-agenda-ndays
)) nil t
))
6933 (defun org-agenda-week-view ()
6934 "Switch to weekly view for agenda."
6936 (org-agenda-check-type t
'agenda
)
6937 (setq org-agenda-ndays
7)
6938 (org-agenda-list include-all-loc
6939 (or (get-text-property (point) 'day
)
6942 (org-agenda-set-mode-name)
6943 (message "Switched to week view"))
6945 (defun org-agenda-day-view ()
6946 "Switch to daily view for agenda."
6948 (org-agenda-check-type t
'agenda
)
6949 (setq org-agenda-ndays
1)
6950 (org-agenda-list include-all-loc
6951 (or (get-text-property (point) 'day
)
6954 (org-agenda-set-mode-name)
6955 (message "Switched to day view"))
6957 (defun org-agenda-next-date-line (&optional arg
)
6958 "Jump to the next line indicating a date in agenda buffer."
6960 (org-agenda-check-type t
'agenda
'timeline
)
6961 (beginning-of-line 1)
6962 (if (looking-at "^\\S-") (forward-char 1))
6963 (if (not (re-search-forward "^\\S-" nil t arg
))
6966 (error "No next date after this line in this buffer")))
6967 (goto-char (match-beginning 0)))
6969 (defun org-agenda-previous-date-line (&optional arg
)
6970 "Jump to the previous line indicating a date in agenda buffer."
6972 (org-agenda-check-type t
'agenda
'timeline
)
6973 (beginning-of-line 1)
6974 (if (not (re-search-backward "^\\S-" nil t arg
))
6975 (error "No previous date before this line in this buffer")))
6977 ;; Initialize the highlight
6978 (defvar org-hl
(org-make-overlay 1 1))
6979 (org-overlay-put org-hl
'face
'highlight
)
6981 (defun org-highlight (begin end
&optional buffer
)
6982 "Highlight a region with overlay."
6983 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
6984 org-hl begin end
(or buffer
(current-buffer))))
6986 (defun org-unhighlight ()
6987 "Detach overlay INDEX."
6988 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
6991 (defun org-agenda-follow-mode ()
6992 "Toggle follow mode in an agenda buffer."
6994 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
6995 (org-agenda-set-mode-name)
6996 (message "Follow mode is %s"
6997 (if org-agenda-follow-mode
"on" "off")))
6999 (defun org-agenda-log-mode ()
7000 "Toggle log mode in an agenda buffer."
7002 (org-agenda-check-type t
'agenda
'timeline
)
7003 (setq org-agenda-show-log
(not org-agenda-show-log
))
7004 (org-agenda-set-mode-name)
7006 (message "Log mode is %s"
7007 (if org-agenda-show-log
"on" "off")))
7009 (defun org-agenda-toggle-diary ()
7010 "Toggle diary inclusion in an agenda buffer."
7012 (org-agenda-check-type t
'agenda
)
7013 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
7015 (org-agenda-set-mode-name)
7016 (message "Diary inclusion turned %s"
7017 (if org-agenda-include-diary
"on" "off")))
7019 (defun org-agenda-toggle-time-grid ()
7020 "Toggle time grid in an agenda buffer."
7022 (org-agenda-check-type t
'agenda
)
7023 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
7025 (org-agenda-set-mode-name)
7026 (message "Time-grid turned %s"
7027 (if org-agenda-use-time-grid
"on" "off")))
7029 (defun org-agenda-set-mode-name ()
7030 "Set the mode name to indicate all the small mode settings."
7032 (concat "Org-Agenda"
7033 (if (equal org-agenda-ndays
1) " Day" "")
7034 (if (equal org-agenda-ndays
7) " Week" "")
7035 (if org-agenda-follow-mode
" Follow" "")
7036 (if org-agenda-include-diary
" Diary" "")
7037 (if org-agenda-use-time-grid
" Grid" "")
7038 (if org-agenda-show-log
" Log" "")))
7039 (force-mode-line-update))
7041 (defun org-agenda-post-command-hook ()
7042 (and (eolp) (not (bolp)) (backward-char 1))
7043 (if (and org-agenda-follow-mode
7044 (get-text-property (point) 'org-marker
))
7047 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
7049 (defun org-get-entries-from-diary (date)
7050 "Get the (Emacs Calendar) diary entries for DATE."
7051 (let* ((fancy-diary-buffer "*temporary-fancy-diary-buffer*")
7052 (diary-display-hook '(fancy-diary-display))
7053 (list-diary-entries-hook
7054 (cons 'org-diary-default-entry list-diary-entries-hook
))
7055 (diary-file-name-prefix-function nil
) ; turn this feature off
7056 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
7058 (org-disable-agenda-to-diary t
))
7060 (save-window-excursion
7061 (list-diary-entries date
1))) ;; Keep this name for now, compatibility
7062 (if (not (get-buffer fancy-diary-buffer
))
7064 (with-current-buffer fancy-diary-buffer
7065 (setq buffer-read-only nil
)
7066 (if (= (point-max) 1)
7069 ;; Omit the date and other unnecessary stuff
7070 (org-agenda-cleanup-fancy-diary)
7071 ;; Add prefix to each line and extend the text properties
7072 (if (= (point-max) 1)
7074 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
7075 (set-buffer-modified-p nil
)
7076 (kill-buffer fancy-diary-buffer
)))
7078 (setq entries
(org-split-string entries
"\n"))
7082 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
7083 ;; Extend the text properties to the beginning of the line
7084 (org-add-props x
(text-properties-at (1- (length x
)) x
)))
7087 (defun org-agenda-cleanup-fancy-diary ()
7088 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
7089 This gets rid of the date, the underline under the date, and
7090 the dummy entry installed by `org-mode' to ensure non-empty diary for each
7091 date. It also removes lines that contain only whitespace."
7092 (goto-char (point-min))
7093 (if (looking-at ".*?:[ \t]*")
7096 (re-search-forward "\n=+$" nil t
)
7098 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
7099 (re-search-forward "\n=+$" nil t
)
7100 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
7101 (goto-char (point-min))
7102 (while (re-search-forward "^ +\n" nil t
)
7104 (goto-char (point-min))
7105 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
7106 (replace-match "")))
7108 ;; Make sure entries from the diary have the right text properties.
7109 (eval-after-load "diary-lib"
7110 '(if (boundp 'diary-modify-entry-list-string-function
)
7111 ;; We can rely on the hook, nothing to do
7113 ;; Hook not avaiable, must use advice to make this work
7114 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
7115 "Make the position visible."
7116 (if (and org-disable-agenda-to-diary
;; called from org-agenda
7119 (setq string
(org-modify-diary-entry-string string
))))))
7121 (defun org-modify-diary-entry-string (string)
7122 "Add text properties to string, allowing org-mode to act on it."
7123 (org-add-props string nil
7124 'mouse-face
'highlight
7125 'keymap org-agenda-keymap
7126 'help-echo
(format "mouse-2 or RET jump to diary file %s"
7127 (abbreviate-file-name buffer-file-name
))
7128 'org-agenda-diary-link t
7129 'org-marker
(org-agenda-new-marker (point-at-bol))))
7131 (defun org-diary-default-entry ()
7132 "Add a dummy entry to the diary.
7133 Needed to avoid empty dates which mess up holiday display."
7134 ;; Catch the error if dealing with the new add-to-diary-alist
7135 (when org-disable-agenda-to-diary
7137 (add-to-diary-list original-date
"Org-mode dummy" "")
7139 (add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
7141 (defun org-cycle-agenda-files ()
7142 "Cycle through the files in `org-agenda-files'.
7143 If the current buffer visits an agenda file, find the next one in the list.
7144 If the current buffer does not, find the first agenda file."
7146 (let* ((fs (org-agenda-files t
))
7147 (files (append fs
(list (car fs
))))
7148 (tcf (if buffer-file-name
(file-truename buffer-file-name
)))
7150 (unless files
(error "No agenda files"))
7152 (while (setq file
(pop files
))
7153 (if (equal (file-truename file
) tcf
)
7155 (find-file (car files
))
7157 (find-file (car fs
)))))
7159 (defun org-agenda-file-to-end ()
7160 "Move/add the current file to the end of the agenda file list.
7161 If the file is not present in the list, it is appended to the list. If it is
7162 present, it is moved there."
7164 (org-agenda-file-to-front 'to-end
))
7166 (defun org-agenda-file-to-front (&optional to-end
)
7167 "Move/add the current file to the top of the agenda file list.
7168 If the file is not present in the list, it is added to the front. If it is
7169 present, it is moved there. With optional argument TO-END, add/move to the
7172 (let ((file-alist (mapcar (lambda (x)
7173 (cons (file-truename x
) x
))
7174 (org-agenda-files t
)))
7175 (ctf (file-truename buffer-file-name
))
7177 (setq x
(assoc ctf file-alist
) had x
)
7179 (if (not x
) (setq x
(cons ctf
(abbreviate-file-name buffer-file-name
))))
7181 (setq file-alist
(append (delq x file-alist
) (list x
)))
7182 (setq file-alist
(cons x
(delq x file-alist
))))
7183 (org-store-new-agenda-file-list (mapcar 'cdr file-alist
))
7184 (org-install-agenda-files-menu)
7185 (message "File %s to %s of agenda file list"
7186 (if had
"moved" "added") (if to-end
"end" "front"))))
7188 (defun org-remove-file (&optional file
)
7189 "Remove current file from the list of files in variable `org-agenda-files'.
7190 These are the files which are being checked for agenda entries.
7191 Optional argument FILE means, use this file instead of the current."
7193 (let* ((file (or file buffer-file-name
))
7194 (true-file (file-truename file
))
7195 (afile (abbreviate-file-name file
))
7196 (files (delq nil
(mapcar
7198 (if (equal true-file
7201 (org-agenda-files t
)))))
7202 (if (not (= (length files
) (length (org-agenda-files t
))))
7204 (org-store-new-agenda-file-list files
)
7205 (org-install-agenda-files-menu)
7206 (message "Removed file: %s" afile
))
7207 (message "File was not in list: %s" afile
))))
7209 (defun org-file-menu-entry (file)
7210 (vector file
(list 'find-file file
) t
))
7212 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty
)
7213 "Return a list of all relevant day numbers from BEG to END buffer positions.
7214 If NO-RANGES is non-nil, include only the start and end dates of a range,
7215 not every single day in the range. If FORCE-TODAY is non-nil, make
7216 sure that TODAY is included in the list. If INACTIVE is non-nil, also
7217 inactive time stamps (those in square brackets) are included.
7218 When EMPTY is non-nil, also include days without any entries."
7219 (let ((re (if inactive org-ts-regexp-both org-ts-regexp
))
7220 dates dates1 date day day1 day2 ts1 ts2
)
7222 (setq dates
(list (time-to-days (current-time)))))
7225 (while (re-search-forward re end t
)
7226 (setq day
(time-to-days (org-time-string-to-time
7227 (substring (match-string 1) 0 10))))
7228 (or (memq day dates
) (push day dates
)))
7231 (while (re-search-forward org-tr-regexp end t
)
7232 (setq ts1
(substring (match-string 1) 0 10)
7233 ts2
(substring (match-string 2) 0 10)
7234 day1
(time-to-days (org-time-string-to-time ts1
))
7235 day2
(time-to-days (org-time-string-to-time ts2
)))
7236 (while (< (setq day1
(1+ day1
)) day2
)
7237 (or (memq day1 dates
) (push day1 dates
)))))
7238 (setq dates
(sort dates
'<))
7240 (while (setq day
(pop dates
))
7241 (setq day2
(car dates
))
7243 (when (and day2 empty
)
7244 (if (or (eq empty t
)
7245 (and (numberp empty
) (<= (- day2 day
) empty
)))
7246 (while (< (setq day
(1+ day
)) day2
)
7247 (push (list day
) dates1
))
7248 (push (cons :omitted
(- day2 day
)) dates1
))))
7249 (setq dates
(nreverse dates1
)))
7253 (defun org-diary (&rest args
)
7254 "Return diary information from org-files.
7255 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
7256 It accesses org files and extracts information from those files to be
7257 listed in the diary. The function accepts arguments specifying what
7258 items should be listed. The following arguments are allowed:
7260 :timestamp List the headlines of items containing a date stamp or
7261 date range matching the selected date. Deadlines will
7262 also be listed, on the expiration day.
7264 :deadline List any deadlines past due, or due within
7265 `org-deadline-warning-days'. The listing occurs only
7266 in the diary for *today*, not at any other date. If
7267 an entry is marked DONE, it is no longer listed.
7269 :scheduled List all items which are scheduled for the given date.
7270 The diary for *today* also contains items which were
7271 scheduled earlier and are not yet marked DONE.
7273 :todo List all TODO items from the org-file. This may be a
7274 long list - so this is not turned on by default.
7275 Like deadlines, these entries only show up in the
7276 diary for *today*, not at any other date.
7278 The call in the diary file should look like this:
7280 &%%(org-diary) ~/path/to/some/orgfile.org
7282 Use a separate line for each org file to check. Or, if you omit the file name,
7283 all files listed in `org-agenda-files' will be checked automatically:
7287 If you don't give any arguments (as in the example above), the default
7288 arguments (:deadline :scheduled :timestamp) are used. So the example above may
7291 &%%(org-diary :deadline :timestamp :scheduled)
7293 The function expects the lisp variables `entry' and `date' to be provided
7294 by the caller, because this is how the calendar works. Don't use this
7295 function from a program - use `org-agenda-get-day-entries' instead."
7296 (org-agenda-maybe-reset-markers)
7297 (org-compile-prefix-format org-agenda-prefix-format
)
7298 (setq args
(or args
'(:deadline
:scheduled
:timestamp
)))
7299 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
7301 (org-agenda-files t
)))
7303 ;; If this is called during org-agenda, don't return any entries to
7304 ;; the calendar. Org Agenda will list these entries itself.
7305 (if org-disable-agenda-to-diary
(setq files nil
))
7306 (while (setq file
(pop files
))
7307 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
7308 (setq results
(append results rtn
)))
7310 (concat (org-finalize-agenda-entries results
) "\n"))))
7311 (defvar org-category-table nil
)
7312 (defun org-get-category-table ()
7313 "Get the table of categories and positions in current buffer."
7316 (goto-char (point-min))
7317 (while (re-search-forward "\\(^\\|\r\\)#\\+CATEGORY:[ \t]*\\(.*\\)" nil t
)
7318 (push (cons (point) (org-trim (match-string 2))) tbl
)))
7320 (defun org-get-category (&optional pos
)
7321 "Get the category applying to position POS."
7322 (if (not org-category-table
)
7324 ((null org-category
)
7326 (if buffer-file-name
7327 (file-name-sans-extension
7328 (file-name-nondirectory buffer-file-name
))
7330 ((symbolp org-category
) (symbol-name org-category
))
7332 (let ((tbl org-category-table
)
7333 (pos (or pos
(point))))
7334 (while (and tbl
(> (caar tbl
) pos
))
7336 (or (cdar tbl
) (cdr (nth (1- (length org-category-table
))
7337 org-category-table
))))))
7339 (defun org-agenda-get-day-entries (file date
&rest args
)
7340 "Does the work for `org-diary' and `org-agenda'.
7341 FILE is the path to a file to be checked for entries. DATE is date like
7342 the one returned by `calendar-current-date'. ARGS are symbols indicating
7343 which kind of entries should be extracted. For details about these, see
7344 the documentation of `org-diary'."
7345 (setq args
(or args
'(:deadline
:scheduled
:timestamp
)))
7346 (let* ((org-startup-with-deadline-check nil
)
7347 (org-startup-folded nil
)
7348 (org-startup-align-all-tables nil
)
7349 (buffer (if (file-exists-p file
)
7350 (org-get-agenda-file-buffer file
)
7351 (error "No such file %s" file
)))
7354 ;; If file does not exist, make sure an error message ends up in diary
7355 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
7356 (with-current-buffer buffer
7357 (unless (org-mode-p)
7358 (error "Agenda file %s is not in `org-mode'" file
))
7359 (setq org-category-table
(org-get-category-table))
7360 (let ((case-fold-search nil
))
7363 (if org-respect-restriction
7364 (if (org-region-active-p)
7365 ;; Respect a region to restrict search
7366 (narrow-to-region (region-beginning) (region-end)))
7367 ;; If we work for the calendar or many files,
7368 ;; get rid of any restriction
7370 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
7371 (while (setq arg
(pop args
))
7373 ((and (eq arg
:todo
)
7374 (equal date
(calendar-current-date)))
7375 (setq rtn
(org-agenda-get-todos))
7376 (setq results
(append results rtn
)))
7377 ((eq arg
:timestamp
)
7378 (setq rtn
(org-agenda-get-blocks))
7379 (setq results
(append results rtn
))
7380 (setq rtn
(org-agenda-get-timestamps))
7381 (setq results
(append results rtn
)))
7382 ((eq arg
:scheduled
)
7383 (setq rtn
(org-agenda-get-scheduled))
7384 (setq results
(append results rtn
)))
7386 (setq rtn
(org-agenda-get-closed))
7387 (setq results
(append results rtn
)))
7388 ((and (eq arg
:deadline
)
7389 (equal date
(calendar-current-date)))
7390 (setq rtn
(org-agenda-get-deadlines))
7391 (setq results
(append results rtn
))))))))
7394 (defun org-entry-is-done-p ()
7395 "Is the current entry marked DONE?"
7397 (and (re-search-backward "[\r\n]\\*" nil t
)
7398 (looking-at org-nl-done-regexp
))))
7400 (defun org-at-date-range-p ()
7401 "Is the cursor inside a date range?"
7405 (let ((pos (point)))
7406 (skip-chars-backward "^<\r\n")
7407 (skip-chars-backward "<")
7408 (and (looking-at org-tr-regexp
)
7409 (>= (match-end 0) pos
)
7411 (skip-chars-backward "^<\r\n")
7412 (skip-chars-backward "<")
7413 (and (looking-at org-tr-regexp
)
7414 (>= (match-end 0) pos
)
7418 (defun org-agenda-get-todos ()
7419 "Return the TODO information for agenda display."
7420 (let* ((props (list 'face nil
7421 'done-face
'org-done
7422 'org-not-done-regexp org-not-done-regexp
7423 'mouse-face
'highlight
7424 'keymap org-agenda-keymap
7426 (format "mouse-2 or RET jump to org file %s"
7427 (abbreviate-file-name buffer-file-name
))))
7428 (regexp (concat "[\n\r]\\*+ *\\("
7429 (if org-select-this-todo-keyword
7430 (concat "\\<\\(" org-select-this-todo-keyword
7432 org-not-done-regexp
)
7434 (sched-re (concat ".*\n?.*?" org-scheduled-time-regexp
))
7435 marker priority category tags
7437 (goto-char (point-min))
7438 (while (re-search-forward regexp nil t
)
7440 (when (and org-agenda-todo-ignore-scheduled
7441 (looking-at sched-re
))
7442 ;; FIXME: the following test also happens below, but we need it here
7443 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
7446 (goto-char (match-beginning 1))
7447 (setq marker
(org-agenda-new-marker (1+ (match-beginning 0)))
7448 category
(org-get-category)
7449 tags
(org-get-tags-at (point))
7450 txt
(org-format-agenda-item "" (match-string 1) category tags
)
7452 (+ (org-get-priority txt
)
7453 (if org-todo-kwd-priority-p
7454 (- org-todo-kwd-max-priority -
2
7456 (member (match-string 2) org-todo-keywords
)))
7458 (org-add-props txt props
7459 'org-marker marker
'org-hd-marker marker
7460 'priority priority
'category category
)
7462 (if org-agenda-todo-list-sublevels
7463 (goto-char (match-end 1))
7464 (org-end-of-subtree 'invisible
))))
7467 (defconst org-agenda-no-heading-message
7468 "No heading for this item in buffer or region.")
7470 (defun org-agenda-get-timestamps ()
7471 "Return the date stamp information for agenda display."
7472 (let* ((props (list 'face nil
7473 'org-not-done-regexp org-not-done-regexp
7474 'mouse-face
'highlight
7475 'keymap org-agenda-keymap
7477 (format "mouse-2 or RET jump to org file %s"
7478 (abbreviate-file-name buffer-file-name
))))
7479 (regexp (regexp-quote
7482 (car org-time-stamp-formats
)
7483 (apply 'encode-time
; DATE bound by calendar
7484 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
7486 marker hdmarker deadlinep scheduledp donep tmp priority category
7487 ee txt timestr tags
)
7488 (goto-char (point-min))
7489 (while (re-search-forward regexp nil t
)
7491 (and (save-match-data (org-at-date-range-p)) (throw :skip nil
))
7493 (setq marker
(org-agenda-new-marker (match-beginning 0))
7494 category
(org-get-category (match-beginning 0))
7495 tmp
(buffer-substring (max (point-min)
7496 (- (match-beginning 0)
7497 org-ds-keyword-length
))
7498 (match-beginning 0))
7499 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
7500 deadlinep
(string-match org-deadline-regexp tmp
)
7501 scheduledp
(string-match org-scheduled-regexp tmp
)
7502 donep
(org-entry-is-done-p))
7503 (if (string-match ">" timestr
)
7504 ;; substring should only run to end of time stamp
7505 (setq timestr
(substring timestr
0 (match-end 0))))
7507 (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t
)
7509 (goto-char (match-end 1))
7510 (setq hdmarker
(org-agenda-new-marker)
7511 tags
(org-get-tags-at))
7512 (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
7513 (setq txt
(org-format-agenda-item
7515 (if deadlinep
"Deadline: " "")
7516 (if scheduledp
"Scheduled: " ""))
7517 (match-string 1) category tags timestr
)))
7518 (setq txt org-agenda-no-heading-message
))
7519 (setq priority
(org-get-priority txt
))
7520 (org-add-props txt props
7521 'org-marker marker
'org-hd-marker hdmarker
)
7523 (org-add-props txt nil
7524 'face
(if donep
'org-done
'org-warning
)
7525 'undone-face
'org-warning
'done-face
'org-done
7526 'category category
'priority
(+ 100 priority
))
7528 (org-add-props txt nil
7529 'face
'org-scheduled-today
7530 'undone-face
'org-scheduled-today
'done-face
'org-done
7531 'category category
'priority
(+ 99 priority
))
7532 (org-add-props txt nil
'priority priority
'category category
)))
7534 (outline-next-heading)))
7537 (defun org-agenda-get-closed ()
7538 "Return the logged TODO entries for agenda display."
7539 (let* ((props (list 'mouse-face
'highlight
7540 'org-not-done-regexp org-not-done-regexp
7541 'keymap org-agenda-keymap
7543 (format "mouse-2 or RET jump to org file %s"
7544 (abbreviate-file-name buffer-file-name
))))
7546 "\\<\\(" org-closed-string
"\\|" org-clock-string
"\\) *\\["
7550 (car org-time-stamp-formats
)
7551 (apply 'encode-time
; DATE bound by calendar
7552 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
7554 marker hdmarker priority category tags closedp
7556 (goto-char (point-min))
7557 (while (re-search-forward regexp nil t
)
7560 (setq marker
(org-agenda-new-marker (match-beginning 0))
7561 closedp
(equal (match-string 1) org-closed-string
)
7562 category
(org-get-category (match-beginning 0))
7563 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
7564 ;; donep (org-entry-is-done-p)
7566 (if (string-match "\\]" timestr
)
7567 ;; substring should only run to end of time stamp
7568 (setq timestr
(substring timestr
0 (match-end 0))))
7570 (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t
)
7572 (goto-char (match-end 1))
7573 (setq hdmarker
(org-agenda-new-marker)
7574 tags
(org-get-tags-at))
7575 (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
7576 (setq txt
(org-format-agenda-item
7577 (if closedp
"Closed: " "Clocked: ")
7578 (match-string 1) category tags timestr
)))
7579 (setq txt org-agenda-no-heading-message
))
7580 (setq priority
100000)
7581 (org-add-props txt props
7582 'org-marker marker
'org-hd-marker hdmarker
'face
'org-done
7583 'priority priority
'category category
7584 'undone-face
'org-warning
'done-face
'org-done
)
7586 (outline-next-heading)))
7589 (defun org-agenda-get-deadlines ()
7590 "Return the deadline information for agenda display."
7591 (let* ((wdays org-deadline-warning-days
)
7592 (props (list 'mouse-face
'highlight
7593 'org-not-done-regexp org-not-done-regexp
7594 'keymap org-agenda-keymap
7596 (format "mouse-2 or RET jump to org file %s"
7597 (abbreviate-file-name buffer-file-name
))))
7598 (regexp org-deadline-time-regexp
)
7599 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
7600 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
7601 d2 diff pos pos1 category tags
7603 (goto-char (point-min))
7604 (while (re-search-forward regexp nil t
)
7607 (setq pos
(1- (match-beginning 1))
7609 (org-time-string-to-time (match-string 1)))
7611 ;; When to show a deadline in the calendar:
7612 ;; If the expiration is within wdays warning time.
7613 ;; Past-due deadlines are only shown on the current date
7614 (if (and (< diff wdays
) todayp
(not (= diff
0)))
7616 (setq category
(org-get-category))
7617 (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t
)
7619 (goto-char (match-end 0))
7620 (setq pos1
(match-end 1))
7621 (setq tags
(org-get-tags-at pos1
))
7622 (setq head
(buffer-substring-no-properties
7624 (progn (skip-chars-forward "^\r\n")
7626 (if (string-match org-looking-at-done-regexp head
)
7628 (setq txt
(org-format-agenda-item
7629 (format "In %3d d.: " diff
) head category tags
))))
7630 (setq txt org-agenda-no-heading-message
))
7632 (setq face
(cond ((<= diff
0) 'org-warning
)
7633 ((<= diff
5) 'org-upcoming-deadline
)
7635 (org-add-props txt props
7636 'org-marker
(org-agenda-new-marker pos
)
7637 'org-hd-marker
(org-agenda-new-marker pos1
)
7638 'priority
(+ (- 10 diff
) (org-get-priority txt
))
7640 'face face
'undone-face face
'done-face
'org-done
)
7644 (defun org-agenda-get-scheduled ()
7645 "Return the scheduled information for agenda display."
7646 (let* ((props (list 'face
'org-scheduled-previously
7647 'org-not-done-regexp org-not-done-regexp
7648 'undone-face
'org-scheduled-previously
7649 'done-face
'org-done
7650 'mouse-face
'highlight
7651 'keymap org-agenda-keymap
7653 (format "mouse-2 or RET jump to org file %s"
7654 (abbreviate-file-name buffer-file-name
))))
7655 (regexp org-scheduled-time-regexp
)
7656 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
7657 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
7658 d2 diff pos pos1 category tags
7660 (goto-char (point-min))
7661 (while (re-search-forward regexp nil t
)
7664 (setq pos
(1- (match-beginning 1))
7666 (org-time-string-to-time (match-string 1)))
7668 ;; When to show a scheduled item in the calendar:
7669 ;; If it is on or past the date.
7670 (if (and (< diff
0) todayp
)
7672 (setq category
(org-get-category))
7673 (if (re-search-backward "\\(^\\|\r\\)\\*+[ \t]*" nil t
)
7675 (goto-char (match-end 0))
7676 (setq pos1
(match-end 1))
7677 (setq tags
(org-get-tags-at))
7678 (setq head
(buffer-substring-no-properties
7680 (progn (skip-chars-forward "^\r\n") (point))))
7681 (if (string-match org-looking-at-done-regexp head
)
7683 (setq txt
(org-format-agenda-item
7684 (format "Sched.%2dx: " (- 1 diff
)) head
7686 (setq txt org-agenda-no-heading-message
))
7688 (org-add-props txt props
7689 'org-marker
(org-agenda-new-marker pos
)
7690 'org-hd-marker
(org-agenda-new-marker pos1
)
7691 'priority
(+ (- 5 diff
) (org-get-priority txt
))
7696 (defun org-agenda-get-blocks ()
7697 "Return the date-range information for agenda display."
7698 (let* ((props (list 'face nil
7699 'org-not-done-regexp org-not-done-regexp
7700 'mouse-face
'highlight
7701 'keymap org-agenda-keymap
7703 (format "mouse-2 or RET jump to org file %s"
7704 (abbreviate-file-name buffer-file-name
))))
7705 (regexp org-tr-regexp
)
7706 (d0 (calendar-absolute-from-gregorian date
))
7707 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags
)
7708 (goto-char (point-min))
7709 (while (re-search-forward regexp nil t
)
7712 (setq timestr
(match-string 0)
7715 d1
(time-to-days (org-time-string-to-time s1
))
7716 d2
(time-to-days (org-time-string-to-time s2
)))
7717 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
7718 ;; Only allow days between the limits, because the normal
7719 ;; date stamps will catch the limits.
7721 (setq marker
(org-agenda-new-marker (point)))
7722 (setq category
(org-get-category))
7723 (if (re-search-backward "\\(^\\|\r\\)\\*+" nil t
)
7725 (setq hdmarker
(org-agenda-new-marker (match-end 1)))
7726 (goto-char (match-end 1))
7727 (setq tags
(org-get-tags-at))
7728 (looking-at "\\*+[ \t]*\\([^\r\n]+\\)")
7729 (setq txt
(org-format-agenda-item
7730 (format (if (= d1 d2
) "" "(%d/%d): ")
7731 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
7732 (match-string 1) category tags
7733 (if (= d0 d1
) timestr
))))
7734 (setq txt org-agenda-no-heading-message
))
7735 (org-add-props txt props
7736 'org-marker marker
'org-hd-marker hdmarker
7737 'priority
(org-get-priority txt
) 'category category
)
7739 (outline-next-heading)))
7740 ;; Sort the entries by expiration date.
7743 (defconst org-plain-time-of-day-regexp
7746 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
7749 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
7751 "Regular expression to match a plain time or time range.
7752 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
7753 groups carry important information:
7755 1 the first time, range or not
7756 8 the second time, if it is a range.")
7758 (defconst org-stamp-time-of-day-regexp
7760 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +[a-zA-Z]+ +\\)"
7761 "\\([012][0-9]:[0-5][0-9]\\)>"
7763 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
7764 "Regular expression to match a timestamp time or time range.
7765 After a match, the following groups carry important information:
7767 1 date plus weekday, for backreferencing to make sure both times on same day
7768 2 the first time, range or not
7769 4 the second time, if it is a range.")
7771 (defvar org-prefix-has-time nil
7772 "A flag, set by `org-compile-prefix-format'.
7773 The flag is set if the currently compiled format contains a `%t'.")
7774 (defvar org-prefix-has-tag nil
7775 "A flag, set by `org-compile-prefix-format'.
7776 The flag is set if the currently compiled format contains a `%T'.")
7778 (defun org-format-agenda-item (extra txt
&optional category tags dotime noprefix
)
7779 "Format TXT to be inserted into the agenda buffer.
7780 In particular, it adds the prefix and corresponding text properties. EXTRA
7781 must be a string and replaces the `%s' specifier in the prefix format.
7782 CATEGORY (string, symbol or nil) may be used to overrule the default
7783 category taken from local variable or file name. It will replace the `%c'
7784 specifier in the format. DOTIME, when non-nil, indicates that a
7785 time-of-day should be extracted from TXT for sorting of this entry, and for
7786 the `%t' specifier in the format. When DOTIME is a string, this string is
7787 searched for a time before TXT is. NOPREFIX is a flag and indicates that
7788 only the correctly processes TXT should be returned - this is used by
7789 `org-agenda-change-all-lines'. TAG can be the tag of the headline."
7791 ;; Diary entries sometimes have extra whitespace at the beginning
7792 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
7793 (let* ((category (or category
7795 (if buffer-file-name
7796 (file-name-sans-extension
7797 (file-name-nondirectory buffer-file-name
))
7799 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
7800 time
;; needed for the eval of the prefix format
7801 (ts (if dotime
(concat (if (stringp dotime
) dotime
"") txt
)))
7802 (time-of-day (and dotime
(org-get-time-of-day ts
)))
7803 stamp plain s0 s1 s2 rtn
)
7804 (when (and dotime time-of-day org-prefix-has-time
)
7805 ;; Extract starting and ending time and move them to prefix
7806 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
7807 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
7808 (setq s0
(match-string 0 ts
)
7809 s1
(match-string (if plain
1 2) ts
)
7810 s2
(match-string (if plain
8 4) ts
))
7812 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
7813 ;; them, we might want to remove them there to avoid duplication.
7814 ;; The user can turn this off with a variable.
7815 (if (and org-agenda-remove-times-when-in-prefix
(or stamp plain
)
7816 (string-match (concat (regexp-quote s0
) " *") txt
)
7817 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
7818 (= (match-beginning 0) 0)
7820 (setq txt
(replace-match "" nil nil txt
))))
7821 ;; Normalize the time(s) to 24 hour
7822 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
7823 (if s2
(setq s2
(org-get-time-of-day s2
'string t
))))
7825 (when (string-match "\\([ \t]+\\)\\(:[a-zA-Z_@0-9:]+:\\)[ \t]*$" txt
)
7826 ;; Tags are in the string
7827 (if (or (eq org-agenda-remove-tags-when-in-prefix t
)
7828 (and org-agenda-remove-tags-when-in-prefix
7829 org-prefix-has-tag
))
7830 (setq txt
(replace-match "" t t txt
))
7831 (setq txt
(replace-match
7832 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
7833 (match-string 2 txt
))
7836 ;; Create the final string
7839 ;; Prepare the variables needed in the eval of the compiled format
7840 (setq time
(cond (s2 (concat s1
"-" s2
))
7841 (s1 (concat s1
"......"))
7844 category
(if (symbolp category
) (symbol-name category
) category
))
7845 ;; Evaluate the compiled format
7846 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
7848 ;; And finally add the text properties
7849 (org-add-props rtn nil
7850 'category
(downcase category
) 'tags tags
7851 'prefix-length
(- (length rtn
) (length txt
))
7852 'time-of-day time-of-day
7855 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
7857 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
7858 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
7859 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
7860 ((member 'weekly
(car org-agenda-time-grid
)))
7861 (t (throw 'exit list
)))
7862 (let* ((have (delq nil
(mapcar
7863 (lambda (x) (get-text-property 1 'time-of-day x
))
7865 (string (nth 1 org-agenda-time-grid
))
7866 (gridtimes (nth 2 org-agenda-time-grid
))
7867 (req (car org-agenda-time-grid
))
7868 (remove (member 'remove-match req
))
7870 (if (and (member 'require-timed req
) (not have
))
7871 ;; don't show empty grid
7873 (while (setq time
(pop gridtimes
))
7874 (unless (and remove
(member time have
))
7875 (setq time
(int-to-string time
))
7876 (push (org-format-agenda-item
7878 (concat (substring time
0 -
2) ":" (substring time -
2)))
7881 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
7882 (if (member 'time-up org-agenda-sorting-strategy
)
7884 (append list new
)))))
7886 (defun org-compile-prefix-format (format)
7887 "Compile the prefix format into a Lisp form that can be evaluated.
7888 The resulting form is returned and stored in the variable
7889 `org-prefix-format-compiled'."
7890 (setq org-prefix-has-time nil org-prefix-has-tag nil
)
7891 (let ((start 0) varform vars var
(s format
)e c f opt
)
7892 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
7894 (setq var
(cdr (assoc (match-string 4 s
)
7895 '(("c" . category
) ("t" . time
) ("s" . extra
)
7897 c
(or (match-string 3 s
) "")
7898 opt
(match-beginning 1)
7899 start
(1+ (match-beginning 0)))
7900 (if (equal var
'time
) (setq org-prefix-has-time t
))
7901 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
7902 (setq f
(concat "%" (match-string 2 s
) "s"))
7905 `(if (equal "" ,var
)
7907 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
7908 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
7909 (setq s
(replace-match "%s" t nil s
))
7910 (push varform vars
))
7911 (setq vars
(nreverse vars
))
7912 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
7914 (defun org-get-time-of-day (s &optional string mod24
)
7915 "Check string S for a time of day.
7916 If found, return it as a military time number between 0 and 2400.
7917 If not found, return nil.
7918 The optional STRING argument forces conversion into a 5 character wide string
7924 "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
7926 "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
7927 (let* ((h (string-to-number (match-string 1 s
)))
7928 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
7929 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
7930 (am-p (equal ampm
"am"))
7931 (h1 (cond ((not ampm
) h
)
7932 ((= h
12) (if am-p
0 12))
7933 (t (+ h
(if am-p
0 12)))))
7934 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
7936 (t0 (+ (* 100 h2
) m
))
7937 (t1 (concat (if (>= h1
24) "+" " ")
7938 (if (< t0
100) "0" "")
7939 (if (< t0
10) "0" "")
7940 (int-to-string t0
))))
7941 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
7943 (defun org-finalize-agenda-entries (list)
7944 "Sort and concatenate the agenda items."
7945 (setq list
(mapcar 'org-agenda-highlight-todo list
))
7946 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n"))
7948 (defun org-agenda-highlight-todo (x)
7952 (beginning-of-line 1)
7953 (setq re
(get-text-property (point) 'org-not-done-regexp
))
7954 (goto-char (+ (point) (get-text-property (point) 'prefix-length
)))
7955 (and (looking-at (concat "[ \t]*" re
))
7956 (add-text-properties (match-beginning 0) (match-end 0)
7958 (setq re
(get-text-property 0 'org-not-done-regexp x
)
7959 pl
(get-text-property 0 'prefix-length x
))
7960 (and re
(equal (string-match re x pl
) pl
)
7961 (add-text-properties (match-beginning 0) (match-end 0)
7962 '(face org-todo
) x
))
7965 (defsubst org-cmp-priority
(a b
)
7966 "Compare the priorities of string A and B."
7967 (let ((pa (or (get-text-property 1 'priority a
) 0))
7968 (pb (or (get-text-property 1 'priority b
) 0)))
7969 (cond ((> pa pb
) +1)
7973 (defsubst org-cmp-category
(a b
)
7974 "Compare the string values of categories of strings A and B."
7975 (let ((ca (or (get-text-property 1 'category a
) ""))
7976 (cb (or (get-text-property 1 'category b
) "")))
7977 (cond ((string-lessp ca cb
) -
1)
7978 ((string-lessp cb ca
) +1)
7981 (defsubst org-cmp-time
(a b
)
7982 "Compare the time-of-day values of strings A and B."
7983 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
7984 (ta (or (get-text-property 1 'time-of-day a
) def
))
7985 (tb (or (get-text-property 1 'time-of-day b
) def
)))
7986 (cond ((< ta tb
) -
1)
7990 (defun org-entries-lessp (a b
)
7991 "Predicate for sorting agenda entries."
7992 ;; The following variables will be used when the form is evaluated.
7993 (let* ((time-up (org-cmp-time a b
))
7994 (time-down (if time-up
(- time-up
) nil
))
7995 (priority-up (org-cmp-priority a b
))
7996 (priority-down (if priority-up
(- priority-up
) nil
))
7997 (category-up (org-cmp-category a b
))
7998 (category-down (if category-up
(- category-up
) nil
))
7999 (category-keep (if category-up
+1 nil
)))
8001 (eval (cons 'or org-agenda-sorting-strategy
))
8002 '((-1 . t
) (1 . nil
) (nil . nil
))))))
8004 (defun org-agenda-show-priority ()
8005 "Show the priority of the current item.
8006 This priority is composed of the main priority given with the [#A] cookies,
8007 and by additional input from the age of a schedules or deadline entry."
8009 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
8010 (message "Priority is %d" (if pri pri -
1000))))
8012 (defun org-agenda-show-tags ()
8013 "Show the tags applicable to the current item."
8015 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
8017 (message "Tags are :%s:"
8018 (org-no-properties (mapconcat 'identity tags
":")))
8019 (message "No tags associated with this line"))))
8021 (defun org-agenda-goto (&optional highlight
)
8022 "Go to the Org-mode file which contains the item at point."
8024 (let* ((marker (or (get-text-property (point) 'org-marker
)
8025 (org-agenda-error)))
8026 (buffer (marker-buffer marker
))
8027 (pos (marker-position marker
)))
8028 (switch-to-buffer-other-window buffer
)
8032 (org-show-hidden-entry)
8034 (and (outline-next-heading)
8035 (org-flag-heading nil
)))) ; show the next heading
8036 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
8038 (defun org-agenda-switch-to ()
8039 "Go to the Org-mode file which contains the item at point."
8041 (let* ((marker (or (get-text-property (point) 'org-marker
)
8042 (org-agenda-error)))
8043 (buffer (marker-buffer marker
))
8044 (pos (marker-position marker
)))
8045 (switch-to-buffer buffer
)
8046 (delete-other-windows)
8050 (org-show-hidden-entry)
8052 (and (outline-next-heading)
8053 (org-flag-heading nil
)))))) ; show the next heading
8055 (defun org-agenda-goto-mouse (ev)
8056 "Go to the Org-mode file which contains the item at the mouse click."
8058 (mouse-set-point ev
)
8061 (defun org-agenda-show ()
8062 "Display the Org-mode file which contains the item at point."
8064 (let ((win (selected-window)))
8066 (select-window win
)))
8068 (defun org-agenda-recenter (arg)
8069 "Display the Org-mode file which contains the item at point and recenter."
8071 (let ((win (selected-window)))
8074 (select-window win
)))
8076 (defun org-agenda-show-mouse (ev)
8077 "Display the Org-mode file which contains the item at the mouse click."
8079 (mouse-set-point ev
)
8082 (defun org-agenda-check-no-diary ()
8083 "Check if the entry is a diary link and abort if yes."
8084 (if (get-text-property (point) 'org-agenda-diary-link
)
8085 (org-agenda-error)))
8087 (defun org-agenda-error ()
8088 (error "Command not allowed in this line"))
8090 (defvar org-last-heading-marker
(make-marker)
8091 "Marker pointing to the headline that last changed its TODO state
8092 by a remote command from the agenda.")
8094 (defun org-agenda-todo (&optional arg
)
8095 "Cycle TODO state of line at point, also in Org-mode file.
8096 This changes the line at point, all other lines in the agenda referring to
8097 the same tree node, and the headline of the tree node in the Org-mode file."
8099 (org-agenda-check-no-diary)
8100 (let* ((col (current-column))
8101 (marker (or (get-text-property (point) 'org-marker
)
8102 (org-agenda-error)))
8103 (buffer (marker-buffer marker
))
8104 (pos (marker-position marker
))
8105 (hdmarker (get-text-property (point) 'org-hd-marker
))
8106 (buffer-read-only nil
)
8108 (with-current-buffer buffer
8111 (org-show-hidden-entry)
8113 (and (outline-next-heading)
8114 (org-flag-heading nil
))) ; show the next heading
8116 (and (bolp) (forward-char 1))
8117 (setq newhead
(org-get-heading))
8119 (org-back-to-heading)
8120 (move-marker org-last-heading-marker
(point))))
8121 (beginning-of-line 1)
8123 (org-agenda-change-all-lines newhead hdmarker
'fixface
))
8124 (move-to-column col
)))
8126 (defun org-agenda-change-all-lines (newhead hdmarker
&optional fixface
)
8127 "Change all lines in the agenda buffer which match HDMARKER.
8128 The new content of the line will be NEWHEAD (as modified by
8129 `org-format-agenda-item'). HDMARKER is checked with
8130 `equal' against all `org-hd-marker' text properties in the file.
8131 If FIXFACE is non-nil, the face of each item is modified acording to
8132 the new TODO state."
8133 (let* (props m pl undone-face done-face finish new dotime cat tags
)
8134 ; (setq newhead (org-format-agenda-item "x" newhead "x" nil 'noprefix))
8136 (goto-char (point-max))
8137 (beginning-of-line 1)
8139 (setq finish
(bobp))
8140 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
8142 (setq props
(text-properties-at (point))
8143 dotime
(get-text-property (point) 'dotime
)
8144 cat
(get-text-property (point) 'category
)
8145 tags
(get-text-property (point) 'tags
)
8146 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
8147 pl
(get-text-property (point) 'prefix-length
)
8148 undone-face
(get-text-property (point) 'undone-face
)
8149 done-face
(get-text-property (point) 'done-face
))
8151 (if (looking-at ".*")
8153 (replace-match new t t
)
8154 (beginning-of-line 1)
8155 (add-text-properties (point-at-bol) (point-at-eol) props
)
8157 (add-text-properties
8158 (point-at-bol) (point-at-eol)
8160 (if org-last-todo-state-is-todo
8161 undone-face done-face
)))
8162 (org-agenda-highlight-todo 'line
))
8163 (beginning-of-line 1))
8164 (error "Line update did not work")))
8165 (beginning-of-line 0)))))
8167 (defun org-agenda-priority-up ()
8168 "Increase the priority of line at point, also in Org-mode file."
8170 (org-agenda-priority 'up
))
8172 (defun org-agenda-priority-down ()
8173 "Decrease the priority of line at point, also in Org-mode file."
8175 (org-agenda-priority 'down
))
8177 (defun org-agenda-priority (&optional force-direction
)
8178 "Set the priority of line at point, also in Org-mode file.
8179 This changes the line at point, all other lines in the agenda referring to
8180 the same tree node, and the headline of the tree node in the Org-mode file."
8182 (org-agenda-check-no-diary)
8183 (let* ((marker (or (get-text-property (point) 'org-marker
)
8184 (org-agenda-error)))
8185 (buffer (marker-buffer marker
))
8186 (pos (marker-position marker
))
8187 (hdmarker (get-text-property (point) 'org-hd-marker
))
8188 (buffer-read-only nil
)
8190 (with-current-buffer buffer
8193 (org-show-hidden-entry)
8195 (and (outline-next-heading)
8196 (org-flag-heading nil
))) ; show the next heading
8197 (funcall 'org-priority force-direction
)
8199 (setq newhead
(org-get-heading)))
8200 (org-agenda-change-all-lines newhead hdmarker
)
8201 (beginning-of-line 1)))
8203 (defun org-get-tags-at (&optional pos
)
8204 "Get a list of all headline tags applicable at POS.
8205 POS defaults to point. If tags are inherited, the list contains
8206 the targets in the same sequence as the headlines appear, i.e.
8207 the tags of the current headline come last."
8211 (goto-char (or pos
(point)))
8213 (org-back-to-heading t
)
8216 (if (looking-at "[^\r\n]+?:\\([a-zA-Z_@0-9:]+\\):[ \t]*\\([\n\r]\\|\\'\\)")
8217 (setq tags
(append (org-split-string
8218 (org-match-string-no-properties 1) ":")
8220 (or org-use-tag-inheritance
(error ""))
8221 (org-up-heading-all 1))
8226 (defun org-agenda-set-tags ()
8227 "Set tags for the current headline."
8229 (org-agenda-check-no-diary)
8230 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
8231 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
8232 (org-agenda-error)))
8233 (buffer (marker-buffer hdmarker
))
8234 (pos (marker-position hdmarker
))
8235 (buffer-read-only nil
)
8237 (with-current-buffer buffer
8240 (org-show-hidden-entry)
8242 (and (outline-next-heading)
8243 (org-flag-heading nil
))) ; show the next heading
8244 (call-interactively 'org-set-tags
)
8246 (setq newhead
(org-get-heading)))
8247 (org-agenda-change-all-lines newhead hdmarker
)
8248 (beginning-of-line 1)))
8250 (defun org-agenda-date-later (arg &optional what
)
8251 "Change the date of this item to one day later."
8253 (org-agenda-check-type t
'agenda
'timeline
)
8254 (org-agenda-check-no-diary)
8255 (let* ((marker (or (get-text-property (point) 'org-marker
)
8256 (org-agenda-error)))
8257 (buffer (marker-buffer marker
))
8258 (pos (marker-position marker
)))
8259 (with-current-buffer buffer
8262 (if (not (org-at-timestamp-p))
8263 (error "Cannot find time stamp"))
8264 (org-timestamp-change arg
(or what
'day
))
8265 (message "Time stamp changed to %s" org-last-changed-timestamp
))))
8267 (defun org-agenda-date-earlier (arg &optional what
)
8268 "Change the date of this item to one day earlier."
8270 (org-agenda-date-later (- arg
) what
))
8272 (defun org-agenda-date-prompt (arg)
8273 "Change the date of this item. Date is prompted for, with default today.
8274 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8275 be used to request time specification in the time stamp."
8277 (org-agenda-check-type t
'agenda
'timeline
)
8278 (org-agenda-check-no-diary)
8279 (let* ((marker (or (get-text-property (point) 'org-marker
)
8280 (org-agenda-error)))
8281 (buffer (marker-buffer marker
))
8282 (pos (marker-position marker
)))
8283 (with-current-buffer buffer
8286 (if (not (org-at-timestamp-p))
8287 (error "Cannot find time stamp"))
8288 (org-time-stamp arg
)
8289 (message "Time stamp changed to %s" org-last-changed-timestamp
))))
8291 (defun org-agenda-schedule (arg)
8292 "Schedule the item at point."
8294 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
)
8295 (org-agenda-check-no-diary)
8296 (let* ((marker (or (get-text-property (point) 'org-marker
)
8297 (org-agenda-error)))
8298 (buffer (marker-buffer marker
))
8299 (pos (marker-position marker
))
8300 (org-insert-labeled-timestamps-at-point nil
)
8302 (with-current-buffer buffer
8305 (setq ts
(org-schedule))
8306 (message "Item scheduled for %s" ts
))))
8308 (defun org-agenda-deadline (arg)
8309 "Schedule the item at point."
8311 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
)
8312 (org-agenda-check-no-diary)
8313 (let* ((marker (or (get-text-property (point) 'org-marker
)
8314 (org-agenda-error)))
8315 (buffer (marker-buffer marker
))
8316 (pos (marker-position marker
))
8317 (org-insert-labeled-timestamps-at-point nil
)
8319 (with-current-buffer buffer
8322 (setq ts
(org-deadline))
8323 (message "Deadline for this item set to %s" ts
))))
8325 (defun org-get-heading ()
8326 "Return the heading of the current entry, without the stars."
8328 (and (memq (char-before) '(?
\n ?
\r)) (skip-chars-forward "^\n\r"))
8329 (if (and (re-search-backward "[\r\n]\\*" nil t
)
8330 (looking-at "[\r\n]\\*+[ \t]+\\([^\r\n]*\\)"))
8334 (defun org-agenda-clock-in (&optional arg
)
8335 "Start the clock on the currently selected item."
8337 (org-agenda-check-no-diary)
8338 (let* ((marker (or (get-text-property (point) 'org-marker
)
8339 (org-agenda-error)))
8340 (pos (marker-position marker
)))
8341 (with-current-buffer (marker-buffer marker
)
8346 (defun org-agenda-diary-entry ()
8347 "Make a diary entry, like the `i' command from the calendar.
8348 All the standard commands work: block, weekly etc."
8350 (org-agenda-check-type t
'agenda
'timeline
)
8351 (require 'diary-lib
)
8353 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8354 (read-char-exclusive)))
8355 (cmd (cdr (assoc char
8356 '((?d . insert-diary-entry
)
8357 (?w . insert-weekly-diary-entry
)
8358 (?m . insert-monthly-diary-entry
)
8359 (?y . insert-yearly-diary-entry
)
8360 (?a . insert-anniversary-diary-entry
)
8361 (?b . insert-block-diary-entry
)
8362 (?c . insert-cyclic-diary-entry
)))))
8363 (oldf (symbol-function 'calendar-cursor-to-date
))
8365 (mark (or (mark t
) (point))))
8367 (error "No command associated with <%c>" char
))
8368 (unless (and (get-text-property point
'day
)
8369 (or (not (equal ?b char
))
8370 (get-text-property mark
'day
)))
8371 (error "Don't know which date to use for diary entry"))
8372 ;; We implement this by hacking the `calendar-cursor-to-date' function
8373 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8374 (let ((calendar-mark-ring
8375 (list (calendar-gregorian-from-absolute
8376 (or (get-text-property mark
'day
)
8377 (get-text-property point
'day
))))))
8380 (fset 'calendar-cursor-to-date
8381 (lambda (&optional error
)
8382 (calendar-gregorian-from-absolute
8383 (get-text-property point
'day
))))
8384 (call-interactively cmd
))
8385 (fset 'calendar-cursor-to-date oldf
)))))
8388 (defun org-agenda-execute-calendar-command (cmd)
8389 "Execute a calendar command from the agenda, with the date associated to
8390 the cursor position."
8391 (org-agenda-check-type t
'agenda
'timeline
)
8392 (require 'diary-lib
)
8393 (unless (get-text-property (point) 'day
)
8394 (error "Don't know which date to use for calendar command"))
8395 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
8397 (date (calendar-gregorian-from-absolute
8398 (get-text-property point
'day
)))
8399 (displayed-day (extract-calendar-day date
))
8400 (displayed-month (extract-calendar-month date
))
8401 (displayed-year (extract-calendar-year date
)))
8404 (fset 'calendar-cursor-to-date
8405 (lambda (&optional error
)
8406 (calendar-gregorian-from-absolute
8407 (get-text-property point
'day
))))
8408 (call-interactively cmd
))
8409 (fset 'calendar-cursor-to-date oldf
))))
8411 (defun org-agenda-phases-of-moon ()
8412 "Display the phases of the moon for the 3 months around the cursor date."
8414 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
8416 (defun org-agenda-holidays ()
8417 "Display the holidays for the 3 months around the cursor date."
8419 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
8421 (defun org-agenda-sunrise-sunset (arg)
8422 "Display sunrise and sunset for the cursor date.
8423 Latitude and longitude can be specified with the variables
8424 `calendar-latitude' and `calendar-longitude'. When called with prefix
8425 argument, latitude and longitude will be prompted for."
8427 (let ((calendar-longitude (if arg nil calendar-longitude
))
8428 (calendar-latitude (if arg nil calendar-latitude
))
8429 (calendar-location-name
8430 (if arg
"the given coordinates" calendar-location-name
)))
8431 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
8433 (defun org-agenda-goto-calendar ()
8434 "Open the Emacs calendar with the date at the cursor."
8436 (org-agenda-check-type t
'agenda
'timeline
)
8437 (let* ((day (or (get-text-property (point) 'day
)
8438 (error "Don't know which date to open in calendar")))
8439 (date (calendar-gregorian-from-absolute day
))
8440 (calendar-move-hook nil
)
8441 (view-calendar-holidays-initially nil
)
8442 (view-diary-entries-initially nil
))
8444 (calendar-goto-date date
)))
8446 (defun org-calendar-goto-agenda ()
8447 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8448 This is a command that has to be installed in `calendar-mode-map'."
8450 (org-agenda-list nil
(calendar-absolute-from-gregorian
8451 (calendar-cursor-to-date))
8454 (defun org-agenda-convert-date ()
8456 (org-agenda-check-type t
'agenda
'timeline
)
8457 (let ((day (get-text-property (point) 'day
))
8460 (error "Don't know which date to convert"))
8461 (setq date
(calendar-gregorian-from-absolute day
))
8463 "Gregorian: " (calendar-date-string date
) "\n"
8464 "ISO: " (calendar-iso-date-string date
) "\n"
8465 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
8466 "Julian: " (calendar-julian-date-string date
) "\n"
8467 "Astron. JD: " (calendar-astro-date-string date
)
8468 " (Julian date number at noon UTC)\n"
8469 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
8470 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
8471 "French: " (calendar-french-date-string date
) "\n"
8472 "Mayan: " (calendar-mayan-date-string date
) "\n"
8473 "Coptic: " (calendar-coptic-date-string date
) "\n"
8474 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
8475 "Persian: " (calendar-persian-date-string date
) "\n"
8476 "Chinese: " (calendar-chinese-date-string date
) "\n"))
8477 (with-output-to-temp-buffer "*Dates*"
8479 (if (fboundp 'fit-window-to-buffer
)
8480 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
8484 (defun org-scan-tags (action matcher
&optional todo-only
)
8485 "Scan headline tags with inheritance and produce output ACTION.
8486 ACTION can be `sparse-tree' or `agenda'. MATCHER is a Lisp form to be
8487 evaluated, testing if a given set of tags qualifies a headline for
8488 inclusion. When TODO-ONLY is non-nil, only lines with a TODO keyword
8489 are included in the output."
8490 (let* ((re (concat "[\n\r]" outline-regexp
" *\\(\\<\\("
8491 (mapconcat 'regexp-quote
8492 (nreverse (cdr (reverse org-todo-keywords
)))
8494 "\\>\\)\\)? *\\(.*?\\)\\(:[A-Za-z_@0-9:]+:\\)?[ \t]*[\n\r]"))
8495 (props (list 'face nil
8496 'done-face
'org-done
8498 'mouse-face
'highlight
8499 'keymap org-agenda-keymap
8501 (format "mouse-2 or RET jump to org file %s"
8502 (abbreviate-file-name buffer-file-name
))))
8504 tags tags-list tags-alist
(llast 0) rtn level category i txt
8507 (goto-char (point-min))
8508 (when (eq action
'sparse-tree
) (org-overview))
8509 (while (re-search-forward re nil t
)
8511 (and (eq action
'agenda
) (org-agenda-skip))
8512 (setq todo
(if (match-end 1) (match-string 2))
8513 tags
(if (match-end 4) (match-string 4)))
8514 (goto-char (setq lspos
(1+ (match-beginning 0))))
8515 (setq level
(funcall outline-level
)
8516 category
(org-get-category))
8517 (setq i llast llast level
)
8518 ;; remove tag lists from same and sublevels
8520 (when (setq entry
(assoc i tags-alist
))
8521 (setq tags-alist
(delete entry tags-alist
)))
8525 (setq tags
(mapcar 'downcase
(org-split-string tags
":"))
8527 (cons (cons level tags
) tags-alist
)))
8528 ;; compile tags for current headline
8530 (if org-use-tag-inheritance
8531 (apply 'append
(mapcar 'cdr tags-alist
))
8533 (when (and (or (not todo-only
) todo
)
8535 (or (not org-agenda-skip-archived-trees
)
8536 (not (member org-archive-tag tags-list
))))
8537 ;; list this headline
8538 (if (eq action
'sparse-tree
)
8540 (org-show-hierarchy-above))
8541 (setq txt
(org-format-agenda-item
8544 (if org-tags-match-list-sublevels
8545 (make-string (1- level
) ?.
) "")
8547 category tags-list
))
8549 (setq marker
(org-agenda-new-marker))
8550 (org-add-props txt props
8551 'org-marker marker
'org-hd-marker marker
'category category
)
8553 ;; if we are to skip sublevels, jump to end of subtree
8555 (or org-tags-match-list-sublevels
(org-end-of-subtree))))))
8556 (when (and (eq action
'sparse-tree
)
8557 (not org-sparse-tree-open-archived-trees
))
8558 (org-hide-archived-subtrees (point-min) (point-max)))
8561 (defun org-tags-sparse-tree (&optional arg match
)
8562 "Create a sparse tree according to tags search string MATCH.
8563 MATCH can contain positive and negative selection of tags, like
8564 \"+WORK+URGENT-WITHBOSS\"."
8566 (let ((org-show-following-heading nil
)
8567 (org-show-hierarchy-above nil
))
8568 (org-scan-tags 'sparse-tree
(cdr (org-make-tags-matcher match
)))))
8570 (defun org-make-tags-matcher (match)
8571 "Create the TAGS matcher form for the tags-selecting string MATCH."
8573 ;; Get a new match request, with completion
8574 (setq org-last-tags-completion-table
8575 (or (org-get-buffer-tags)
8576 org-last-tags-completion-table
))
8577 (setq match
(completing-read
8578 "Tags: " 'org-tags-completion-function nil nil nil
8579 'org-tags-history
)))
8580 ;; parse the string and create a lisp form
8581 (let ((match0 match
) minus tag mm matcher orterms term orlist
)
8582 (setq orterms
(org-split-string match
"|"))
8583 (while (setq term
(pop orterms
))
8584 (while (string-match "^&?\\([-+:]\\)?\\([A-Za-z_@0-9]+\\)" term
)
8585 (setq minus
(and (match-end 1)
8586 (equal (match-string 1 term
) "-"))
8587 tag
(match-string 2 term
)
8588 term
(substring term
(match-end 0))
8589 mm
(list 'member
(downcase tag
) 'tags-list
)
8590 mm
(if minus
(list 'not mm
) mm
))
8592 (push (if (> (length matcher
) 1) (cons 'and matcher
) (car matcher
))
8595 (setq matcher
(if (> (length orlist
) 1) (cons 'or orlist
) (car orlist
)))
8596 ;; Return the string and lisp forms of the matcher
8597 (cons match0 matcher
)))
8600 (defun org-tags-view (&optional todo-only match keep-modes
)
8601 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
8602 The prefix arg TODO-ONLY limits the search to TODO entries."
8604 (org-agenda-maybe-reset-markers 'force
)
8605 (org-compile-prefix-format org-agenda-prefix-format
)
8606 (let* ((org-agenda-keep-modes keep-modes
)
8607 (org-tags-match-list-sublevels
8608 (if todo-only t org-tags-match-list-sublevels
))
8609 (win (selected-window))
8610 (completion-ignore-case t
)
8611 rtn rtnall files file pos matcher
8613 (setq matcher
(org-make-tags-matcher match
)
8614 match
(car matcher
) matcher
(cdr matcher
))
8615 (if (not (equal (current-buffer) (get-buffer org-agenda-buffer-name
)))
8617 (delete-other-windows)
8618 (switch-to-buffer-other-window
8619 (get-buffer-create org-agenda-buffer-name
))))
8620 (setq buffer-read-only nil
)
8622 (org-agenda-mode) (setq buffer-read-only nil
)
8623 (set (make-local-variable 'org-agenda-type
) 'tags
)
8624 (set (make-local-variable 'org-agenda-redo-command
)
8625 (list 'org-tags-view
(list 'quote todo-only
)
8626 (list 'if
'current-prefix-arg nil match
) t
))
8627 (setq files
(org-agenda-files)
8629 (org-prepare-agenda-buffers files
)
8630 (while (setq file
(pop files
))
8632 (org-check-agenda-file file
)
8633 (setq buffer
(if (file-exists-p file
)
8634 (org-get-agenda-file-buffer file
)
8635 (error "No such file %s" file
)))
8637 ;; If file does not exist, merror message to agenda
8639 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
8640 rtnall
(append rtnall rtn
))
8641 (with-current-buffer buffer
8642 (unless (org-mode-p)
8643 (error "Agenda file %s is not in `org-mode'" file
))
8644 (setq org-category-table
(org-get-category-table))
8647 (if org-respect-restriction
8648 (if (org-region-active-p)
8649 ;; Respect a region to restrict search
8650 (narrow-to-region (region-beginning) (region-end)))
8651 ;; If we work for the calendar or many files,
8652 ;; get rid of any restriction
8654 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
8655 (setq rtnall
(append rtnall rtn
))))))))
8656 (insert "Headlines with TAGS match: ")
8657 (add-text-properties (point-min) (1- (point))
8658 (list 'face
'org-level-3
))
8661 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
8663 (insert "Press `C-u r' to search again with new search string\n")
8664 (add-text-properties pos
(1- (point)) (list 'face
'org-level-3
))
8666 (insert (mapconcat 'identity rtnall
"\n")))
8667 (goto-char (point-min))
8668 (setq buffer-read-only t
)
8669 (org-fit-agenda-window)
8670 (if (not org-select-agenda-window
) (select-window win
))))
8672 (defvar org-add-colon-after-tag-completion nil
) ;; dynamically skoped param
8673 (defun org-set-tags (&optional arg just-align
)
8674 "Set the tags for the current headline.
8675 With prefix ARG, realign all tags in headings in the current buffer."
8677 (let* ((re (concat "^" outline-regexp
))
8678 (col (current-column))
8679 (current (org-get-tags))
8680 table current-tags inherited-tags
; computed below when needed
8681 tags hd empty invis
)
8684 (goto-char (point-min))
8685 (while (re-search-forward re nil t
)
8686 (org-set-tags nil t
))
8687 (message "All tags realigned to column %d" org-tags-column
))
8690 (setq table
(or org-tag-alist
(org-get-buffer-tags))
8691 org-last-tags-completion-table table
8692 current-tags
(org-split-string current
":")
8693 inherited-tags
(nreverse
8694 (nthcdr (length current-tags
)
8695 (nreverse (org-get-tags-at))))
8697 (if (or (eq t org-use-fast-tag-selection
)
8698 (and org-use-fast-tag-selection
8699 (delq nil
(mapcar 'cdr table
))))
8700 (org-fast-tag-selection current-tags inherited-tags table
)
8701 (let ((org-add-colon-after-tag-completion t
))
8702 (completing-read "Tags: " 'org-tags-completion-function
8703 nil nil current
'org-tags-history
))))
8704 (while (string-match "[-+&]+" tags
)
8705 (setq tags
(replace-match ":" t t tags
))))
8707 (unless (setq empty
(string-match "\\`[\t ]*\\'" tags
))
8708 (unless (string-match ":$" tags
) (setq tags
(concat tags
":")))
8709 (unless (string-match "^:" tags
) (setq tags
(concat ":" tags
))))
8710 (if (equal current
"")
8713 (or empty
(insert-before-markers " ")))
8714 (beginning-of-line 1)
8715 (setq invis
(org-invisible-p))
8716 (looking-at (concat "\\(.*\\)\\(" (regexp-quote current
) "\\)[ \t]*"))
8717 (setq hd
(match-string 1))
8718 (delete-region (match-beginning 0) (match-end 0))
8719 (insert-before-markers (org-trim hd
) (if empty
"" " ")))
8722 (beginning-of-line 1)
8723 (skip-chars-forward "*")
8724 (if (= (char-after) ?\
) (forward-char 1))
8725 (and (re-search-forward "[ \t]+$" (point-at-eol) t
)
8726 (replace-match "")))
8727 (move-to-column (max (current-column)
8728 (if (> org-tags-column
0)
8730 (- (- org-tags-column
) (length tags
))))
8732 (insert-before-markers tags
)
8733 (if (and (not invis
) (org-invisible-p))
8734 (outline-flag-region (point-at-bol) (point) nil
)))
8735 (move-to-column col
))))
8737 (defun org-tags-completion-function (string predicate
&optional flag
)
8738 (let (s1 s2 rtn
(ctable org-last-tags-completion-table
)
8739 (confirm (lambda (x) (stringp (car x
)))))
8740 (if (string-match "^\\(.*[-+:&|]\\)\\([^-+:&|]*\\)$" string
)
8741 (setq s1
(match-string 1 string
)
8742 s2
(match-string 2 string
))
8743 (setq s1
"" s2 string
))
8747 (setq rtn
(try-completion s2 ctable confirm
))
8749 (concat s1 s2
(substring rtn
(length s2
))
8750 (if (and org-add-colon-after-tag-completion
8756 (all-completions s2 ctable confirm
)
8763 (defun org-fast-tag-insert (kwd tags face
&optional end
)
8764 "Insert KDW, and the TAGS, the latter with face FACE. Also inser END."
8765 (insert (format "%-12s" (concat kwd
":"))
8766 (org-add-props (mapconcat 'identity tags
" ") nil
'face face
)
8769 (defun org-fast-tag-selection (current inherited table
)
8770 "Fast tag selection with single keys.
8771 CURRENT is the current list of tags in the headline, INHERITED is the
8772 list of inherited tags, and TABLE is an alist of tags and corresponding keys,
8773 possibly with grouping information.
8774 If the keys are nil, a-z are automatically assigned.
8775 Returns the new tags string, or nil to not change the current settings."
8776 (let* ((maxlen (apply 'max
(mapcar
8778 (if (stringp (car x
)) (string-width (car x
)) 0))
8780 (fwidth (+ maxlen
3 1 3))
8781 (ncol (/ (- (window-width) 4) fwidth
))
8784 tg cnt e c char c1 c2 ntable tbl rtn
8786 (save-window-excursion
8787 (delete-other-windows)
8788 (split-window-vertically)
8789 (switch-to-buffer-other-window (get-buffer-create " *Org tags*"))
8791 (org-fast-tag-insert "Inherited" inherited i-face
"\n")
8792 (org-fast-tag-insert "Current" current c-face
"\n\n")
8793 (setq tbl table char ?a cnt
0)
8794 (while (setq e
(pop tbl
))
8796 ((equal e
'(:startgroup
))
8797 (push '() groups
) (setq ingroup t
)
8798 (when (not (= cnt
0))
8802 ((equal e
'(:endgroup
))
8803 (setq ingroup nil cnt
0)
8806 (setq tg
(car e
) c2 nil
)
8809 ;; automatically assign a character.
8810 (setq c1
(string-to-char
8811 (downcase (substring
8812 tg
(if (= (string-to-char tg
) ?
@) 1 0)))))
8813 (if (or (rassoc c1 ntable
) (rassoc c1 table
))
8814 (while (or (rassoc char ntable
) (rassoc char table
))
8815 (setq char
(1+ char
)))
8817 (setq c
(or c2 char
)))
8818 (if ingroup
(push tg
(car groups
)))
8819 (setq tg
(org-add-props tg nil
'face
8821 ((member tg current
) c-face
)
8822 ((member tg inherited
) i-face
)
8824 (if (and (= cnt
0) (not ingroup
)) (insert " "))
8825 (insert "[" c
"] " tg
(make-string
8826 (- fwidth
4 (length tg
)) ?\
))
8827 (push (cons tg c
) ntable
)
8828 (when (= (setq cnt
(1+ cnt
)) ncol
)
8830 (if ingroup
(insert " "))
8832 (setq ntable
(nreverse ntable
))
8834 (goto-char (point-min))
8835 (if (fboundp 'fit-window-to-buffer
) (fit-window-to-buffer))
8839 (message "[key]:Toggle SPC: clear current RET accept%s"
8840 (if groups
" [!] ignore goups" ""))
8841 (setq c
(read-char-exclusive))
8843 ((= c ?
\r) (throw 'exit t
))
8846 (goto-char (point-min))
8847 (while (re-search-forward "[{}]" nil t
) (replace-match " ")))
8849 (and (= c ?q
) (not (rassoc c ntable
))))
8851 ((= c ?\
) (setq current nil
))
8852 ((setq e
(rassoc c ntable
) tg
(car e
))
8853 (if (member tg current
)
8854 (setq current
(delete tg current
))
8855 (loop for g in groups do
8858 (setq current
(delete x current
)))
8860 (setq current
(cons tg current
)))))
8861 ;; Create a sorted list
8865 (assoc b
(cdr (memq (assoc a ntable
) ntable
))))))
8866 (goto-char (point-min))
8867 (beginning-of-line 2)
8868 (delete-region (point) (point-at-eol))
8869 (org-fast-tag-insert "Current" current c-face
)
8870 (while (re-search-forward "\\[.\\] \\([a-zA-Z0-9_@]+\\)" nil t
)
8871 (setq tg
(match-string 1))
8872 (add-text-properties (match-beginning 1) (match-end 1)
8875 ((member tg current
) c-face
)
8876 ((member tg inherited
) i-face
)
8878 (goto-char (point-min)))))
8880 (mapconcat 'identity current
":")
8883 (defun org-get-tags ()
8884 "Get the TAGS string in the current headline."
8885 (unless (org-on-heading-p)
8886 (error "Not on a heading"))
8888 (beginning-of-line 1)
8889 (if (looking-at ".*[ \t]\\(:[A-Za-z_@0-9:]+:\\)[ \t]*\\(\r\\|$\\)")
8890 (org-match-string-no-properties 1)
8893 (defun org-get-buffer-tags ()
8894 "Get a table of all tags used in the buffer, for completion."
8897 (goto-char (point-min))
8898 (while (re-search-forward "[ \t]:\\([A-Za-z_@0-9:]+\\):[ \t\r\n]" nil t
)
8899 (mapc (lambda (x) (add-to-list 'tags x
))
8900 (org-split-string (org-match-string-no-properties 1) ":"))))
8901 (mapcar 'list tags
)))
8905 (defvar org-create-file-search-functions nil
8906 "List of functions to construct the right search string for a file link.
8907 These functions are called in turn with point at the location to
8908 which the link should point.
8910 A function in the hook should first test if it would like to
8911 handle this file type, for example by checking the major-mode or
8912 the file extension. If it decides not to handle this file, it
8913 should just return nil to give other functions a chance. If it
8914 does handle the file, it must return the search string to be used
8915 when following the link. The search string will be part of the
8916 file link, given after a double colon, and `org-open-at-point'
8917 will automatically search for it. If special measures must be
8918 taken to make the search successful, another function should be
8919 added to the companion hook `org-execute-file-search-functions',
8922 A function in this hook may also use `setq' to set the variable
8923 `description' to provide a suggestion for the descriptive text to
8924 be used for this link when it gets inserted into an Org-mode
8925 buffer with \\[org-insert-link].")
8927 (defvar org-execute-file-search-functions nil
8928 "List of functions to execute a file search triggered by a link.
8930 Functions added to this hook must accept a single argument, the
8931 search string that was part of the file link, the part after the
8932 double colon. The function must first check if it would like to
8933 handle this search, for example by checking the major-mode or the
8934 file extension. If it decides not to handle this search, it
8935 should just return nil to give other functions a chance. If it
8936 does handle the search, it must return a non-nil value to keep
8937 other functions from trying.
8939 Each function can access the current prefix argument through the
8940 variable `current-prefix-argument'. Note that a single prefix is
8941 used to force opening a link in Emacs, so it may be good to only
8942 use a numeric or double prefix to guide the search function.
8944 In case this is needed, a function in this hook can also restore
8945 the window configuration before `org-open-at-point' was called using:
8947 (set-window-configuration org-window-config-before-follow-link)")
8949 (defun org-find-file-at-mouse (ev)
8950 "Open file link or URL at mouse."
8952 (mouse-set-point ev
)
8953 (org-open-at-point 'in-emacs
))
8955 (defun org-open-at-mouse (ev)
8956 "Open file link or URL at mouse."
8958 (mouse-set-point ev
)
8959 (org-open-at-point))
8961 (defvar org-window-config-before-follow-link nil
8962 "The window configuration before following a link.
8963 This is saved in case the need arises to restore it.")
8965 (defun org-open-at-point (&optional in-emacs
)
8966 "Open link at or after point.
8967 If there is no link at point, this function will search forward up to
8968 the end of the current subtree.
8969 Normally, files will be opened by an appropriate application. If the
8970 optional argument IN-EMACS is non-nil, Emacs will visit the file."
8972 (setq org-window-config-before-follow-link
(current-window-configuration))
8973 (org-remove-occur-highlights nil nil t
)
8974 (if (org-at-timestamp-p)
8975 (org-agenda-list nil
(time-to-days (org-time-string-to-time
8976 (substring (match-string 1) 0 10)))
8978 (let (type path link line search
(pos (point)))
8981 (skip-chars-forward "^]\n\r")
8982 (when (and (re-search-backward "\\[\\[" nil t
)
8983 (looking-at org-bracket-link-regexp
)
8984 (<= (match-beginning 0) pos
)
8985 (>= (match-end 0) pos
))
8986 (setq link
(org-link-unescape (org-match-string-no-properties 1)))
8987 (while (string-match " *\n *" link
)
8988 (setq link
(replace-match " " t t link
)))
8989 (if (string-match org-link-re-with-space2 link
)
8990 (setq type
(match-string 1 link
)
8991 path
(match-string 2 link
))
8992 (setq type
"thisfile"
8996 (when (get-text-property (point) 'org-linked-text
)
8997 (setq type
"thisfile"
8998 pos
(if (get-text-property (1+ (point)) 'org-linked-text
)
8999 (1+ (point)) (point))
9000 path
(buffer-substring
9001 (previous-single-property-change pos
'org-linked-text
)
9002 (next-single-property-change pos
'org-linked-text
)))
9006 (skip-chars-backward (concat "^[]" org-non-link-chars
" "))
9007 (if (equal (char-before) ?
<) (backward-char 1))
9008 (when (or (looking-at org-angle-link-re
)
9009 (looking-at org-plain-link-re
)
9010 (and (or (re-search-forward org-angle-link-re
(point-at-eol) t
)
9011 (re-search-forward org-plain-link-re
(point-at-eol) t
))
9012 (<= (match-beginning 0) pos
)
9013 (>= (match-end 0) pos
)))
9014 (setq type
(match-string 1)
9015 path
(match-string 2))
9018 (skip-chars-backward "^ \t\n\r")
9019 (when (looking-at "\\(:[A-Za-z_@0-9:]+\\):[ \t\r\n]")
9021 path
(match-string 1))
9022 (while (string-match ":" path
)
9023 (setq path
(replace-match "+" t t path
)))
9026 (skip-chars-backward "a-zA-Z_")
9027 (when (and (memq 'camel org-activate-links
)
9028 (looking-at org-camel-regexp
))
9029 (setq type
"camel" path
(match-string 0))
9030 (if (equal (char-before) ?
*)
9031 (setq path
(concat "*" path
))))
9034 (error "No link found"))
9035 ;; Remove any trailing spaces in path
9036 (if (string-match " +\\'" path
)
9037 (setq path
(replace-match "" t t path
)))
9041 ((member type
'("http" "https" "ftp" "mailto" "news"))
9042 (browse-url (concat type
":" path
)))
9044 ((string= type
"tags")
9045 (org-tags-view in-emacs path
))
9046 ((or (string= type
"camel")
9047 (string= type
"thisfile"))
9048 (org-mark-ring-push)
9051 (cond ((equal in-emacs
'(4)) 'occur
)
9052 ((equal in-emacs
'(16)) 'org-occur
)
9055 ((string= type
"file")
9056 (if (string-match "::\\([0-9]+\\)\\'" path
)
9057 (setq line
(string-to-number (match-string 1 path
))
9058 path
(substring path
0 (match-beginning 0)))
9059 (if (string-match "::\\(.+\\)\\'" path
)
9060 (setq search
(match-string 1 path
)
9061 path
(substring path
0 (match-beginning 0)))))
9062 (org-open-file path in-emacs line search
))
9064 ((string= type
"news")
9065 (org-follow-gnus-link path
))
9067 ((string= type
"bbdb")
9068 (org-follow-bbdb-link path
))
9070 ((string= type
"info")
9071 (org-follow-info-link path
))
9073 ((string= type
"gnus")
9074 (let (group article
)
9075 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
9076 (error "Error in Gnus link"))
9077 (setq group
(match-string 1 path
)
9078 article
(match-string 3 path
))
9079 (org-follow-gnus-link group article
)))
9081 ((string= type
"vm")
9082 (let (folder article
)
9083 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
9084 (error "Error in VM link"))
9085 (setq folder
(match-string 1 path
)
9086 article
(match-string 3 path
))
9087 ;; in-emacs is the prefix arg, will be interpreted as read-only
9088 (org-follow-vm-link folder article in-emacs
)))
9090 ((string= type
"wl")
9091 (let (folder article
)
9092 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
9093 (error "Error in Wanderlust link"))
9094 (setq folder
(match-string 1 path
)
9095 article
(match-string 3 path
))
9096 (org-follow-wl-link folder article
)))
9098 ((string= type
"mhe")
9099 (let (folder article
)
9100 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
9101 (error "Error in MHE link"))
9102 (setq folder
(match-string 1 path
)
9103 article
(match-string 3 path
))
9104 (org-follow-mhe-link folder article
)))
9106 ((string= type
"rmail")
9107 (let (folder article
)
9108 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
9109 (error "Error in RMAIL link"))
9110 (setq folder
(match-string 1 path
)
9111 article
(match-string 3 path
))
9112 (org-follow-rmail-link folder article
)))
9114 ((string= type
"shell")
9116 (while (string-match "@{" cmd
)
9117 (setq cmd
(replace-match "<" t t cmd
)))
9118 (while (string-match "@}" cmd
)
9119 (setq cmd
(replace-match ">" t t cmd
)))
9120 (if (or (not org-confirm-shell-link-function
)
9121 (funcall org-confirm-shell-link-function
9122 (format "Execute \"%s\" in shell? "
9123 (org-add-props cmd nil
9124 'face
'org-warning
))))
9126 (message "Executing %s" cmd
)
9127 (shell-command cmd
))
9130 ((string= type
"elisp")
9132 (if (or (not org-confirm-elisp-link-function
)
9133 (funcall org-confirm-elisp-link-function
9134 (format "Execute \"%s\" as elisp? "
9135 (org-add-props cmd nil
9136 'face
'org-warning
))))
9137 (message "%s => %s" cmd
(eval (read cmd
)))
9141 (browse-url-at-point))))))
9143 (defun org-link-search (s &optional type
)
9144 "Search for a link search option.
9145 When S is a CamelCaseWord, search for a target, or for a sentence containing
9146 the words. If S is surrounded by forward slashes, it is interpreted as a
9147 regular expression. In org-mode files, this will create an `org-occur'
9148 sparse tree. In ordinary files, `occur' will be used to list matches.
9149 If the current buffer is in `dired-mode', grep will be used to search
9151 (let ((case-fold-search t
)
9152 (s0 (mapconcat 'identity
(org-split-string s
"[ \t\r\n]+") " "))
9155 words re0 re1 re2 re3 re4 re5 re2a reall camel
)
9157 ;; First check if there are any special
9158 ((run-hook-with-args-until-success 'org-execute-file-search-functions s
))
9159 ;; Now try the builtin stuff
9161 (goto-char (point-min))
9164 (concat "<<" (regexp-quote s0
) ">>") nil t
)
9165 (setq pos
(match-beginning 0))))
9166 ;; There is an exact target for this
9168 ((string-match "^/\\(.*\\)/$" s
)
9169 ;; A regular expression
9172 (org-occur (match-string 1 s
)))
9173 ;;((eq major-mode 'dired-mode)
9174 ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
9175 (t (org-do-occur (match-string 1 s
)))))
9176 ((or (setq camel
(string-match (concat "^" org-camel-regexp
"$") s
))
9178 ;; A camel or a normal search string
9179 (when (equal (string-to-char s
) ?
*)
9180 ;; Anchor on headlines, post may include tags.
9181 (setq pre
"^\\*+[ \t]*\\(?:\\sw+\\)?[ \t]*"
9182 post
"[ \t]*\\(?:[ \t]+:[a-zA-Z_@0-9:+]:[ \t]*\\)?$"
9184 (remove-text-properties
9186 '(face nil mouse-face nil keymap nil fontified nil
) s
)
9187 ;; Make a series of regular expressions to find a match
9190 (org-camel-to-words s
)
9191 (org-split-string s
"[ \n\r\t]+"))
9192 re0
(concat "\\(<<" (regexp-quote s0
) ">>\\)")
9193 re2
(concat "[ \t\r\n]\\(" (mapconcat 'downcase words
"[ \t]+") "\\)[ \t\r\n]")
9194 re2a
(concat "[ \t\r\n]\\(" (mapconcat 'downcase words
"[ \t\r\n]+") "\\)[ \t\r\n]")
9195 re4
(concat "[^a-zA-Z_]\\(" (mapconcat 'downcase words
"[^a-zA-Z_\r\n]+") "\\)[^a-zA-Z_]")
9196 re1
(concat pre re2 post
)
9197 re3
(concat pre re4 post
)
9198 re5
(concat pre
".*" re4
)
9199 re2
(concat pre re2
)
9200 re2a
(concat pre re2a
)
9201 re4
(concat pre re4
)
9202 reall
(concat "\\(" re0
"\\)\\|\\(" re1
"\\)\\|\\(" re2
9203 "\\)\\|\\(" re3
"\\)\\|\\(" re4
"\\)\\|\\("
9207 ((eq type
'org-occur
) (org-occur reall
))
9208 ((eq type
'occur
) (org-do-occur (downcase reall
) 'cleanup
))
9209 (t (goto-char (point-min))
9210 (if (or (org-search-not-link re0 nil t
)
9211 (org-search-not-link re1 nil t
)
9212 (org-search-not-link re2 nil t
)
9213 (org-search-not-link re2a nil t
)
9214 (org-search-not-link re3 nil t
)
9215 (org-search-not-link re4 nil t
)
9216 (org-search-not-link re5 nil t
)
9218 (goto-char (match-beginning 1))
9220 (error "No match")))))
9222 ;; Normal string-search
9223 (goto-char (point-min))
9224 (if (search-forward s nil t
)
9225 (goto-char (match-beginning 0))
9226 (error "No match"))))
9227 (and (org-mode-p) (org-show-hierarchy-above))))
9229 (defun org-search-not-link (&rest args
)
9230 "Execute `re-search-forward', but only accept matches that are not a link."
9233 (while (apply 're-search-forward args
)
9235 (if (not (save-match-data
9236 (and (re-search-backward "\\[\\[" nil t
)
9237 (looking-at org-bracket-link-regexp
)
9238 (<= (match-beginning 0) p1
)
9239 (>= (match-end 0) p1
))))
9240 (progn (goto-char (match-end 0))
9241 (throw 'exit
(point)))
9242 (goto-char (match-end 0)))))))
9244 (defun org-do-occur (regexp &optional cleanup
)
9245 "Call the Emacs command `occur'.
9246 If CLEANUP is non-nil, remove the printout of the regular expression
9247 in the *Occur* buffer. This is useful if the regex is long and not useful
9251 (let ((cwin (selected-window)) win beg end
)
9252 (when (setq win
(get-buffer-window "*Occur*"))
9253 (select-window win
))
9254 (goto-char (point-min))
9255 (when (re-search-forward "match[a-z]+" nil t
)
9256 (setq beg
(match-end 0))
9257 (if (re-search-forward "^[ \t]*[0-9]+" nil t
)
9258 (setq end
(1- (match-beginning 0)))))
9259 (and beg end
(let ((buffer-read-only)) (delete-region beg end
)))
9260 (goto-char (point-min))
9261 (select-window cwin
))))
9263 (defvar org-mark-ring nil
9264 "Mark ring for positions before jumps in Org-mode.")
9265 (defvar org-mark-ring-last-goto nil
9266 "Last position in the mark ring used to go back.")
9267 ;; Fill and close the ring
9268 (setq org-mark-ring nil org-mark-ring-last-goto nil
) ;; in case file is reloaded
9269 (loop for i from
1 to org-mark-ring-length do
9270 (push (make-marker) org-mark-ring
))
9271 (setcdr (nthcdr (1- org-mark-ring-length
) org-mark-ring
)
9274 (defun org-mark-ring-push (&optional pos buffer
)
9275 "Put the current position or POS into the mark ring and rotate it."
9277 (setq pos
(or pos
(point)))
9278 (setq org-mark-ring
(nthcdr (1- org-mark-ring-length
) org-mark-ring
))
9279 (move-marker (car org-mark-ring
)
9281 (or buffer
(current-buffer)))
9283 (substitute-command-keys
9284 "Position saved to mark ring, go back with \\[org-mark-ring-goto].")))
9286 (defun org-mark-ring-goto (&optional n
)
9287 "Jump to the previous position in the mark ring.
9288 With prefix arg N, jump back that many stored positions. When
9289 called several times in succession, walk through the entire ring.
9290 Org-mode commands jumping to a different position in the current file,
9291 or to another Org-mode file, automatically push the old position
9295 (if (eq last-command this-command
)
9296 (setq p
(nthcdr n
(or org-mark-ring-last-goto org-mark-ring
)))
9297 (setq p org-mark-ring
))
9298 (setq org-mark-ring-last-goto p
)
9300 (switch-to-buffer (marker-buffer m
))
9302 (if (or (org-invisible-p) (org-invisible-p2)) (org-show-hierarchy-above))))
9304 (defun org-camel-to-words (s)
9305 "Split \"CamelCaseWords\" to (\"Camel\" \"Case\" \"Words\")."
9306 (let ((case-fold-search nil
)
9308 (while (string-match "[a-z][A-Z]" s
)
9309 (push (substring s
0 (1+ (match-beginning 0))) words
)
9310 (setq s
(substring s
(1+ (match-beginning 0)))))
9311 (nreverse (cons s words
))))
9313 (defun org-remove-angle-brackets (s)
9314 (if (equal (substring s
0 1) "<") (setq s
(substring s
1)))
9315 (if (equal (substring s -
1) ">") (setq s
(substring s
0 -
1)))
9317 (defun org-add-angle-brackets (s)
9318 (if (equal (substring s
0 1) "<") nil
(setq s
(concat "<" s
)))
9319 (if (equal (substring s -
1) ">") nil
(setq s
(concat s
">")))
9322 (defun org-follow-bbdb-link (name)
9323 "Follow a BBDB link to NAME."
9325 (let ((inhibit-redisplay t
)
9326 (bbdb-electric-p nil
))
9328 ;; Exact match on name
9329 (bbdb-name (concat "\\`" name
"\\'") nil
)
9330 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil
))
9331 ;; Exact match on name
9332 (bbdb-company (concat "\\`" name
"\\'") nil
)
9333 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil
))
9334 ;; Partial match on name
9335 (bbdb-name name nil
)
9336 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil
))
9337 ;; Partial match on company
9338 (bbdb-company name nil
)
9339 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil
))
9340 ;; General match including network address and notes
9342 (when (= 0 (buffer-size (get-buffer "*BBDB*")))
9343 (delete-window (get-buffer-window "*BBDB*"))
9344 (error "No matching BBDB record")))))
9347 (defun org-follow-info-link (name)
9348 "Follow an info file & node link to NAME."
9349 (if (or (string-match "\\(.*\\)::?\\(.*\\)" name
)
9350 (string-match "\\(.*\\)" name
))
9353 (if (match-string 2 name
) ; If there isn't a node, choose "Top"
9354 (Info-find-node (match-string 1 name
) (match-string 2 name
))
9355 (Info-find-node (match-string 1 name
) "Top")))
9356 (message (concat "Could not open: " name
))))
9358 (defun org-follow-gnus-link (&optional group article
)
9359 "Follow a Gnus link to GROUP and ARTICLE."
9361 (funcall (cdr (assq 'gnus org-link-frame-setup
)))
9362 (if group
(gnus-fetch-group group
))
9364 (or (gnus-summary-goto-article article nil
'force
)
9365 (if (fboundp 'gnus-summary-insert-cached-articles
)
9367 (gnus-summary-insert-cached-articles)
9368 (gnus-summary-goto-article article nil
'force
))
9369 (message "Message could not be found.")))))
9371 (defun org-follow-vm-link (&optional folder article readonly
)
9372 "Follow a VM link to FOLDER and ARTICLE."
9374 (setq article
(org-add-angle-brackets article
))
9375 (if (string-match "^//\\([a-zA-Z]+@\\)?\\([^:]+\\):\\(.*\\)" folder
)
9376 ;; ange-ftp or efs or tramp access
9377 (let ((user (or (match-string 1 folder
) (user-login-name)))
9378 (host (match-string 2 folder
))
9379 (file (match-string 3 folder
)))
9382 ;; use tramp to access the file
9383 (if (featurep 'xemacs
)
9384 (setq folder
(format "[%s@%s]%s" user host file
))
9385 (setq folder
(format "/%s@%s:%s" user host file
))))
9387 ;; use ange-ftp or efs
9388 (require (if (featurep 'xemacs
) 'efs
'ange-ftp
))
9389 (setq folder
(format "/%s@%s:%s" user host file
))))))
9391 (funcall (cdr (assq 'vm org-link-frame-setup
)) folder readonly
)
9394 (vm-select-folder-buffer)
9396 (let ((case-fold-search t
))
9397 (goto-char (point-min))
9398 (if (not (re-search-forward
9399 (concat "^" "message-id: *" (regexp-quote article
))))
9400 (error "Could not find the specified message in this folder"))
9403 (vm-beginning-of-message)
9406 (defun org-follow-wl-link (folder article
)
9407 "Follow a Wanderlust link to FOLDER and ARTICLE."
9408 (setq article
(org-add-angle-brackets article
))
9409 (wl-summary-goto-folder-subr folder
'no-sync t nil t
)
9410 (if article
(wl-summary-jump-to-msg-by-message-id article
">"))
9411 (wl-summary-redisplay))
9413 (defun org-follow-rmail-link (folder article
)
9414 "Follow an RMAIL link to FOLDER and ARTICLE."
9415 (setq article
(org-add-angle-brackets article
))
9416 (let (message-number)
9418 (save-window-excursion
9419 (rmail (if (string= folder
"RMAIL") rmail-file-name folder
))
9420 (setq message-number
9423 (goto-char (point-max))
9424 (if (re-search-backward
9425 (concat "^Message-ID:\\s-+" (regexp-quote
9428 (rmail-what-message))))))
9431 (rmail (if (string= folder
"RMAIL") rmail-file-name folder
))
9432 (rmail-show-message message-number
)
9434 (error "Message not found"))))
9436 ;; mh-e integration based on planner-mode
9437 (defun org-mhe-get-message-real-folder ()
9438 "Return the name of the current message real folder, so if you use
9439 sequences, it will now work."
9442 (if (equal major-mode
'mh-folder-mode
)
9444 ;; Refer to the show buffer
9445 mh-show-folder-buffer
))
9447 (if (boundp 'mh-index-folder
)
9448 (min (length mh-index-folder
) (length folder
))))
9450 ;; a simple test on mh-index-data does not work, because
9451 ;; mh-index-data is always nil in a show buffer.
9452 (if (and (boundp 'mh-index-folder
)
9453 (string= mh-index-folder
(substring folder
0 end-index
)))
9454 (if (equal major-mode
'mh-show-mode
)
9455 (save-window-excursion
9456 (when (buffer-live-p (get-buffer folder
))
9458 (pop-to-buffer folder
)
9459 (org-mhe-get-message-folder-from-index)
9462 (org-mhe-get-message-folder-from-index)
9468 (defun org-mhe-get-message-folder-from-index ()
9469 "Returns the name of the message folder in a index folder buffer."
9471 (mh-index-previous-folder)
9472 (re-search-forward "^\\(+.*\\)$" nil t
)
9473 (message (match-string 1))))
9475 (defun org-mhe-get-message-folder ()
9476 "Return the name of the current message folder. Be careful if you
9479 (if (equal major-mode
'mh-folder-mode
)
9481 ;; Refer to the show buffer
9482 mh-show-folder-buffer
)))
9484 (defun org-mhe-get-message-num ()
9485 "Return the number of the current message. Be careful if you
9488 (if (equal major-mode
'mh-folder-mode
)
9489 (mh-get-msg-num nil
)
9490 ;; Refer to the show buffer
9491 (mh-show-buffer-message-number))))
9493 (defun org-mhe-get-header (header)
9494 "Return a header of the message in folder mode. This will create a
9495 show buffer for the corresponding message. If you have a more clever
9497 (let* ((folder (org-mhe-get-message-folder))
9498 (num (org-mhe-get-message-num))
9499 (buffer (get-buffer-create (concat "show-" folder
)))
9501 (with-current-buffer buffer
9502 (mh-display-msg num folder
)
9503 (if (equal major-mode
'mh-folder-mode
)
9505 (mh-show-header-display))
9507 (setq header-field
(mh-get-header-field header
))
9508 (if (equal major-mode
'mh-folder-mode
)
9513 (defun org-follow-mhe-link (folder article
)
9514 "Follow an MHE link to FOLDER and ARTICLE.
9515 If ARTICLE is nil FOLDER is shown. If the configuration variable
9516 `org-mhe-search-all-folders' is t and `mh-searcher' is pick,
9517 ARTICLE is searched in all folders. Indexed searches (swish++,
9518 namazu, and others supported by MH-E) will always search in all
9521 (require 'mh-search
)
9525 (mh-visit-folder (mh-normalize-folder-name folder
))
9526 (setq article
(org-add-angle-brackets article
))
9528 (if (equal mh-searcher
'pick
)
9530 (mh-search folder
(list "--message-id" article
))
9531 (when (and org-mhe-search-all-folders
9532 (not (org-mhe-get-message-real-folder)))
9534 (mh-search "+" (list "--message-id" article
))))
9535 (mh-search "+" article
))
9536 (if (org-mhe-get-message-real-folder)
9539 (error "Message not found"))))
9543 ;; Use the custom search meachnism to construct and use search strings for
9544 ;; file links to BibTeX database entries.
9546 (defun org-create-file-search-in-bibtex ()
9547 "Create the search string and description for a BibTeX database entry."
9548 (when (eq major-mode
'bibtex-mode
)
9549 ;; yes, we want to construct this search string.
9550 ;; Make a good description for this entry, using names, year and the title
9551 ;; Put it into the `description' variable which is dynamically scoped.
9552 (let ((bibtex-autokey-names 1)
9553 (bibtex-autokey-names-stretch 1)
9554 (bibtex-autokey-name-case-convert-function 'identity
)
9555 (bibtex-autokey-name-separator " & ")
9556 (bibtex-autokey-additional-names " et al.")
9557 (bibtex-autokey-year-length 4)
9558 (bibtex-autokey-name-year-separator " ")
9559 (bibtex-autokey-titlewords 3)
9560 (bibtex-autokey-titleword-separator " ")
9561 (bibtex-autokey-titleword-case-convert-function 'identity
)
9562 (bibtex-autokey-titleword-length 'infty
)
9563 (bibtex-autokey-year-title-separator ": "))
9564 (setq description
(bibtex-generate-autokey)))
9565 ;; Now parse the entry, get the key and return it.
9567 (bibtex-beginning-of-entry)
9568 (cdr (assoc "=key=" (bibtex-parse-entry))))))
9570 (defun org-execute-file-search-in-bibtex (s)
9571 "Find the link search string S as a key for a database entry."
9572 (when (eq major-mode
'bibtex-mode
)
9573 ;; Yes, we want to do the search in this file.
9574 ;; We construct a regexp that searches for "@entrytype{" followed by the key
9575 (goto-char (point-min))
9576 (and (re-search-forward (concat "@[a-zA-Z]+[ \t\n]*{[ \t\n]*"
9577 (regexp-quote s
) "[ \t\n]*,") nil t
)
9578 (goto-char (match-beginning 0)))
9579 (if (and (match-beginning 0) (equal current-prefix-arg
'(16)))
9580 ;; Use double prefix to indicate that any web link should be browsed
9581 (let ((b (current-buffer)) (p (point)))
9582 ;; Restore the window configuration because we just use the web link
9583 (set-window-configuration org-window-config-before-follow-link
)
9584 (save-excursion (set-buffer b
) (goto-char p
)
9586 (recenter 0)) ; Move entry start to beginning of window
9587 ;; return t to indicate that the search is done.
9590 ;; Finally add the functions to the right hooks.
9591 (add-hook 'org-create-file-search-functions
'org-create-file-search-in-bibtex
)
9592 (add-hook 'org-execute-file-search-functions
'org-execute-file-search-in-bibtex
)
9594 ;; end of Bibtex link setup
9596 (defun org-upgrade-old-links (&optional query-description
)
9597 "Transfer old <...> style links to new [[...]] style links.
9598 With arg query-description, ask at each match for a description text to use
9600 (interactive (list (y-or-n-p "Would you like to be queried for a description at each link?")))
9602 (goto-char (point-min))
9603 (let ((re (concat "\\([^[]\\)<\\("
9604 "\\(" (mapconcat 'identity org-link-types
"\\|")
9606 "[^" org-non-link-chars
"]+\\)>"))
9608 (while (re-search-forward re nil t
)
9610 l1
(org-match-string-no-properties 2)
9611 l2
(save-match-data (org-link-escape l1
)))
9612 (when query-description
(setq l1
(read-string "Desc: " l1
)))
9614 (replace-match (concat (match-string 1) "[[" l1
"]]") t t
)
9615 (replace-match (concat (match-string 1) "[[" l2
"][" l1
"]]") t t
)))
9616 (message "%d matches have beed treated" cnt
))))
9618 (defun org-open-file (path &optional in-emacs line search
)
9619 "Open the file at PATH.
9620 First, this expands any special file name abbreviations. Then the
9621 configuration variable `org-file-apps' is checked if it contains an
9622 entry for this file type, and if yes, the corresponding command is launched.
9623 If no application is found, Emacs simply visits the file.
9624 With optional argument IN-EMACS, Emacs will visit the file.
9625 Optional LINE specifies a line to go to, optional SEARCH a string to
9626 search for. If LINE or SEARCH is given, the file will always be
9628 If the file does not exist, an error is thrown."
9629 (setq in-emacs
(or in-emacs line search
))
9630 (let* ((file (if (equal path
"")
9633 (apps (append org-file-apps
(org-default-apps)))
9634 (remp (and (assq 'remote apps
) (org-file-remote-p file
)))
9635 (dirp (if remp nil
(file-directory-p file
)))
9636 (dfile (downcase file
))
9637 (old-buffer (current-buffer))
9639 (old-mode major-mode
)
9641 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\.gz\\)$" dfile
)
9642 (setq ext
(match-string 1 dfile
))
9643 (if (string-match "^.*\\.\\([a-zA-Z0-9]+\\)$" dfile
)
9644 (setq ext
(match-string 1 dfile
))))
9647 (setq cmd
(or (and remp
(cdr (assoc 'remote apps
)))
9648 (and dirp
(cdr (assoc 'directory apps
)))
9649 (cdr (assoc ext apps
))
9650 (cdr (assoc t apps
)))))
9651 (when (eq cmd
'mailcap
)
9653 (mailcap-parse-mailcaps)
9654 (let* ((mime-type (mailcap-extension-to-mime (or ext
"")))
9655 (command (mailcap-mime-info mime-type
)))
9656 (if (stringp command
)
9658 (setq cmd
'emacs
))))
9659 (if (and (not (eq cmd
'emacs
)) ; Emacs has not problems with non-ex files
9660 (not (file-exists-p file
))
9661 (not org-open-non-existing-files
))
9662 (error "No such file: %s" file
))
9664 ((and (stringp cmd
) (not (string-match "^\\s-*$" cmd
)))
9665 ;; Normalize use of quote, this can vary.
9666 (if (string-match "['\"]%s['\"]" cmd
)
9667 (setq cmd
(replace-match "'%s'" t t cmd
)))
9668 (setq cmd
(format cmd file
))
9669 (save-window-excursion
9670 (shell-command (concat cmd
" &"))))
9673 ; (unless (equal (file-truename file) (file-truename (or buffer-file-name "")))
9674 ; (funcall (cdr (assq 'file org-link-frame-setup)) file))
9675 (funcall (cdr (assq 'file org-link-frame-setup
)) file
)
9676 (if line
(goto-line line
)
9677 (if search
(org-link-search search
))))
9680 (t (funcall (cdr (assq 'file org-link-frame-setup
)) file
)))
9681 (and (org-mode-p) (eq old-mode
'org-mode
)
9682 (or (not (equal old-buffer
(current-buffer)))
9683 (not (equal old-pos
(point))))
9684 (org-mark-ring-push old-pos old-buffer
))))
9686 (defun org-default-apps ()
9687 "Return the default applications for this operating system."
9689 ((eq system-type
'darwin
)
9690 org-file-apps-defaults-macosx
)
9691 ((eq system-type
'windows-nt
)
9692 org-file-apps-defaults-windowsnt
)
9693 (t org-file-apps-defaults-gnu
)))
9695 (defun org-expand-file-name (path)
9696 "Replace special path abbreviations and expand the file name."
9697 (expand-file-name path
))
9699 (defun org-file-remote-p (file)
9700 "Test whether FILE specifies a location on a remote system.
9701 Return non-nil if the location is indeed remote.
9703 For example, the filename \"/user@host:/foo\" specifies a location
9704 on the system \"/user@host:\"."
9705 (cond ((fboundp 'file-remote-p
)
9706 (file-remote-p file
))
9707 ((fboundp 'tramp-handle-file-remote-p
)
9708 (tramp-handle-file-remote-p file
))
9709 ((and (boundp 'ange-ftp-name-format
)
9710 (string-match ange-ftp-name-format file
))
9714 (defvar org-insert-link-history nil
9715 "Minibuffer history for links inserted with `org-insert-link'.")
9717 (defvar org-stored-links nil
9718 "Contains the links stored with `org-store-link'.")
9721 (defun org-store-link (arg)
9722 "\\<org-mode-map>Store an org-link to the current location.
9723 This link can later be inserted into an org-buffer with
9724 \\[org-insert-link].
9725 For some link types, a prefix arg is interpreted:
9726 For links to usenet articles, arg negates `org-usenet-links-prefer-google'.
9727 For file links, arg negates `org-context-in-file-links'."
9729 (let (link cpltxt desc description search txt
(pos (point)))
9732 ((eq major-mode
'bbdb-mode
)
9733 (setq cpltxt
(concat
9735 (or (bbdb-record-name (bbdb-current-record))
9736 (bbdb-record-company (bbdb-current-record))))
9737 link
(org-make-link cpltxt
)))
9739 ((eq major-mode
'Info-mode
)
9740 (setq link
(org-make-link "info:"
9741 (file-name-nondirectory Info-current-file
)
9742 ":" Info-current-node
))
9743 (setq cpltxt
(concat (file-name-nondirectory Info-current-file
)
9744 ":" Info-current-node
)))
9746 ((eq major-mode
'calendar-mode
)
9747 (let ((cd (calendar-cursor-to-date)))
9750 (car org-time-stamp-formats
)
9752 (list 0 0 0 (nth 1 cd
) (nth 0 cd
) (nth 2 cd
)
9755 ((or (eq major-mode
'vm-summary-mode
)
9756 (eq major-mode
'vm-presentation-mode
))
9757 (and (eq major-mode
'vm-presentation-mode
) (vm-summarize))
9758 (vm-follow-summary-cursor)
9760 (vm-select-folder-buffer)
9761 (let* ((message (car vm-message-pointer
))
9762 (folder buffer-file-name
)
9763 (subject (vm-su-subject message
))
9764 (author (vm-su-full-name message
))
9765 (message-id (vm-su-message-id message
)))
9766 (setq message-id
(org-remove-angle-brackets message-id
))
9767 (setq folder
(abbreviate-file-name folder
))
9768 (if (string-match (concat "^" (regexp-quote vm-folder-directory
))
9770 (setq folder
(replace-match "" t t folder
)))
9771 (setq cpltxt
(concat author
" on: " subject
))
9772 (setq link
(org-make-link "vm:" folder
"#" message-id
)))))
9774 ((eq major-mode
'wl-summary-mode
)
9775 (let* ((msgnum (wl-summary-message-number))
9776 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
9777 msgnum
'message-id
))
9778 (wl-message-entity (elmo-msgdb-overview-get-entity
9779 msgnum
(wl-summary-buffer-msgdb)))
9780 (author (wl-summary-line-from)) ; FIXME: correct?
9781 (subject "???")) ; FIXME:
9782 (setq message-id
(org-remove-angle-brackets message-id
))
9783 (setq cpltxt
(concat author
" on: " subject
))
9784 (setq link
(org-make-link "wl:" wl-summary-buffer-folder-name
9787 ((or (equal major-mode
'mh-folder-mode
)
9788 (equal major-mode
'mh-show-mode
))
9789 (let ((from-header (org-mhe-get-header "From:"))
9790 (to-header (org-mhe-get-header "To:"))
9791 (subject (org-mhe-get-header "Subject:")))
9792 (setq cpltxt
(concat from-header
" on: " subject
))
9793 (setq link
(org-make-link "mhe:" (org-mhe-get-message-real-folder) "#"
9794 (org-remove-angle-brackets
9795 (org-mhe-get-header "Message-Id:"))))))
9797 ((eq major-mode
'rmail-mode
)
9800 (rmail-narrow-to-non-pruned-header)
9801 (let ((folder buffer-file-name
)
9802 (message-id (mail-fetch-field "message-id"))
9803 (author (mail-fetch-field "from"))
9804 (subject (mail-fetch-field "subject")))
9805 (setq message-id
(org-remove-angle-brackets message-id
))
9806 (setq cpltxt
(concat author
" on: " subject
))
9807 (setq link
(org-make-link "rmail:" folder
"#" message-id
))))))
9809 ((eq major-mode
'gnus-group-mode
)
9810 (let ((group (cond ((fboundp 'gnus-group-group-name
) ; depending on Gnus
9811 (gnus-group-group-name)) ; version
9812 ((fboundp 'gnus-group-name
)
9815 (setq cpltxt
(concat
9816 (if (org-xor arg org-usenet-links-prefer-google
)
9817 "http://groups.google.com/groups?group="
9820 link
(org-make-link cpltxt
))))
9822 ((memq major-mode
'(gnus-summary-mode gnus-article-mode
))
9823 (and (eq major-mode
'gnus-article-mode
) (gnus-article-show-summary))
9824 (gnus-summary-beginning-of-article)
9825 (let* ((group (car gnus-article-current
))
9826 (article (cdr gnus-article-current
))
9827 (header (gnus-summary-article-header article
))
9828 (author (mail-header-from header
))
9829 (message-id (mail-header-id header
))
9830 (date (mail-header-date header
))
9831 (subject (gnus-summary-subject-string)))
9832 (setq cpltxt
(concat author
" on: " subject
))
9833 (if (org-xor arg org-usenet-links-prefer-google
)
9837 (format "http://groups.google.com/groups?as_umsgid=%s"
9838 (org-fixup-message-id-for-http message-id
))))
9839 (setq link
(org-make-link "gnus:" group
9840 "#" (number-to-string article
))))))
9842 ((eq major-mode
'w3-mode
)
9843 (setq cpltxt
(url-view-url t
)
9844 link
(org-make-link cpltxt
)))
9845 ((eq major-mode
'w3m-mode
)
9846 (setq cpltxt
(or w3m-current-title w3m-current-url
)
9847 link
(org-make-link w3m-current-url
)))
9849 ((setq search
(run-hook-with-args-until-success
9850 'org-create-file-search-functions
))
9851 (setq link
(concat "file:" (abbreviate-file-name buffer-file-name
)
9853 (setq cpltxt
(or description link
)))
9855 ((eq major-mode
'image-mode
)
9856 (setq cpltxt
(concat "file:"
9857 (abbreviate-file-name buffer-file-name
))
9858 link
(org-make-link cpltxt
)))
9861 ;; Just link to current headline
9862 (setq cpltxt
(concat "file:"
9863 (abbreviate-file-name buffer-file-name
)))
9864 ;; Add a context search string
9865 (when (org-xor org-context-in-file-links arg
)
9866 ;; Check if we are on a target
9868 (skip-chars-forward "^>\n\r")
9869 (and (re-search-backward "<<" nil t
)
9870 (looking-at "<<\\(.*?\\)>>")
9871 (<= (match-beginning 0) pos
)
9872 (>= (match-end 0) pos
)))
9873 (setq cpltxt
(concat cpltxt
"::" (match-string 1)))
9875 ((org-on-heading-p) nil
)
9876 ((org-region-active-p)
9877 (buffer-substring (region-beginning) (region-end)))
9878 (t (buffer-substring (point-at-bol) (point-at-eol)))))
9879 (when (or (null txt
) (string-match "\\S-" txt
))
9882 (if org-file-link-context-use-camel-case
9883 (org-make-org-heading-camel txt
)
9884 (org-make-org-heading-search-string txt
)))
9886 (if (string-match "::\\'" cpltxt
)
9887 (setq cpltxt
(substring cpltxt
0 -
2)))
9888 (setq link
(org-make-link cpltxt
)))
9891 ;; Just link to this file here.
9892 (setq cpltxt
(concat "file:"
9893 (abbreviate-file-name buffer-file-name
)))
9894 ;; Add a context string
9895 (when (org-xor org-context-in-file-links arg
)
9896 (setq txt
(if (org-region-active-p)
9897 (buffer-substring (region-beginning) (region-end))
9898 (buffer-substring (point-at-bol) (point-at-eol))))
9899 ;; Only use search option if there is some text.
9900 (when (string-match "\\S-" txt
)
9903 (if org-file-link-context-use-camel-case
9904 (org-make-org-heading-camel txt
)
9905 (org-make-org-heading-search-string txt
)))
9907 (setq link
(org-make-link cpltxt
)))
9910 (error "Cannot link to a buffer which is not visiting a file"))
9912 (t (setq link nil
)))
9914 (if (consp link
) (setq cpltxt
(car link
) link
(cdr link
)))
9915 (setq link
(or link cpltxt
)
9916 desc
(or desc cpltxt
))
9917 (if (equal desc
"NONE") (setq desc nil
))
9919 (if (and (interactive-p) link
)
9921 (setq org-stored-links
9922 (cons (list cpltxt link desc
) org-stored-links
))
9923 (message "Stored: %s" (or cpltxt link
)))
9924 (org-make-link-string link desc
))))
9926 (defun org-make-org-heading-search-string (&optional string heading
)
9927 "Make search string for STRING or current headline."
9929 (let ((s (or string
(org-get-heading))))
9930 (unless (and string
(not heading
))
9931 ;; We are using a headline, clean up garbage in there.
9932 (if (string-match org-todo-regexp s
)
9933 (setq s
(replace-match "" t t s
)))
9934 (if (string-match ":[a-zA-Z_@0-9:]+:[ \t]*$" s
)
9935 (setq s
(replace-match "" t t s
)))
9936 (setq s
(org-trim s
))
9937 (if (string-match (concat "^\\(" org-quote-string
"\\|"
9938 org-comment-string
"\\)") s
)
9939 (setq s
(replace-match "" t t s
)))
9940 (while (string-match org-ts-regexp s
)
9941 (setq s
(replace-match "" t t s
))))
9942 (while (string-match "[^a-zA-Z_0-9 \t]+" s
)
9943 (setq s
(replace-match " " t t s
)))
9944 (or string
(setq s
(concat "*" s
))) ; Add * for headlines
9945 (mapconcat 'identity
(org-split-string s
"[ \t]+") " ")))
9947 (defun org-make-org-heading-camel (&optional string heading
)
9948 "Make a CamelCase string for STRING or the current headline."
9950 (let ((s (or string
(org-get-heading))))
9951 (unless (and string
(not heading
))
9952 ;; We are using a headline, clean up garbage in there.
9953 (if (string-match org-todo-regexp s
)
9954 (setq s
(replace-match "" t t s
)))
9955 (if (string-match ":[a-zA-Z_@0-9:]+:[ \t]*$" s
)
9956 (setq s
(replace-match "" t t s
)))
9957 (setq s
(org-trim s
))
9958 (if (string-match (concat "^\\(" org-quote-string
"\\|"
9959 org-comment-string
"\\)") s
)
9960 (setq s
(replace-match "" t t s
)))
9961 (while (string-match org-ts-regexp s
)
9962 (setq s
(replace-match "" t t s
))))
9963 (while (string-match "[^a-zA-Z_ \t]+" s
)
9964 (setq s
(replace-match " " t t s
)))
9965 (or string
(setq s
(concat "*" s
))) ; Add * for headlines
9966 (mapconcat 'capitalize
(org-split-string s
"[ \t]+") "")))
9968 (defun org-make-link (&rest strings
)
9969 "Concatenate STRINGS, format resulting string with `org-link-format'."
9970 (format org-link-format
(apply 'concat strings
)))
9972 (defun org-make-link-string (link &optional description
)
9973 "Make a link with brackets, consisting of LINK and DESCRIPTION."
9974 (if (eq org-link-style
'plain
)
9975 (if (equal description link
)
9977 (concat description
"\n" link
))
9978 (when (stringp description
)
9979 ;; Remove brackets from the description, they are fatal.
9980 (while (string-match "\\[\\|\\]" description
)
9981 (setq description
(replace-match "" t t description
))))
9982 (when (equal (org-link-escape link
) description
)
9983 ;; No description needed, it is identical
9984 (setq description nil
))
9985 (when (and (not description
)
9986 (not (equal link
(org-link-escape link
))))
9987 (setq description link
))
9988 (concat "[[" (org-link-escape link
) "]"
9989 (if description
(concat "[" description
"]") "")
9992 (defconst org-link-escape-chars
'(("[" .
"%5B") ("]" .
"%5D") (" " .
"%20"))
9993 "Association list of escapes for some characters problematic in links.")
9995 (defun org-link-escape (text)
9996 "Escape charaters in TEXT that are problematic for links."
9998 (let ((re (mapconcat (lambda (x) (regexp-quote (car x
)))
9999 org-link-escape-chars
"\\|")))
10000 (while (string-match re text
)
10003 (cdr (assoc (match-string 0 text
) org-link-escape-chars
))
10007 (defun org-link-unescape (text)
10008 "Reverse the action of `org-link-escape'."
10010 (let ((re (mapconcat (lambda (x) (regexp-quote (cdr x
)))
10011 org-link-escape-chars
"\\|")))
10012 (while (string-match re text
)
10015 (car (rassoc (match-string 0 text
) org-link-escape-chars
))
10019 (defun org-xor (a b
)
10023 (defun org-get-header (header)
10024 "Find a header field in the current buffer."
10026 (goto-char (point-min))
10027 (let ((case-fold-search t
) s
)
10030 (if (re-search-forward "^From:\\s-+\\(.*\\)" nil t
)
10031 (setq s
(match-string 1)))
10032 (while (string-match "\"" s
)
10033 (setq s
(replace-match "" t t s
)))
10034 (if (string-match "[<(].*" s
)
10035 (setq s
(replace-match "" t t s
))))
10036 ((eq header
'message-id
)
10037 (if (re-search-forward "^message-id:\\s-+\\(.*\\)" nil t
)
10038 (setq s
(match-string 1))))
10039 ((eq header
'subject
)
10040 (if (re-search-forward "^subject:\\s-+\\(.*\\)" nil t
)
10041 (setq s
(match-string 1)))))
10042 (if (string-match "\\`[ \t\]+" s
) (setq s
(replace-match "" t t s
)))
10043 (if (string-match "[ \t\]+\\'" s
) (setq s
(replace-match "" t t s
)))
10047 (defun org-fixup-message-id-for-http (s)
10048 "Replace special characters in a message id, so it can be used in an http query."
10049 (while (string-match "<" s
)
10050 (setq s
(replace-match "%3C" t t s
)))
10051 (while (string-match ">" s
)
10052 (setq s
(replace-match "%3E" t t s
)))
10053 (while (string-match "@" s
)
10054 (setq s
(replace-match "%40" t t s
)))
10057 (defun org-insert-link (&optional complete-file
)
10058 "Insert a link. At the prompt, enter the link.
10060 Completion can be used to select a link previously stored with
10061 `org-store-link'. When the empty string is entered (i.e. if you just
10062 press RET at the prompt), the link defaults to the most recently
10063 stored link. As SPC triggers completion in the minibuffer, you need to
10064 use M-SPC or C-q SPC to force the insertion of a space character.
10066 You will also be prompted for a description, and if one is given, it will
10067 be displayed in the buffer instead of the link.
10069 If there is already a link at point, this command will allow you to edit link
10070 and description parts.
10072 With a \\[universal-argument] prefix, prompts for a file to link to. The file name can be
10073 selected using completion. The path to the file will be relative to
10074 the current directory if the file is in the current directory or a
10075 subdirectory. Otherwise, the link will be the absolute path as
10076 completed in the minibuffer (i.e. normally ~/path/to/file).
10078 With two \\[universal-argument] prefixes, enforce an absolute path even if the file
10079 is in the current directory or below.
10080 With three \\[universal-argument] prefixes, negate the meaning of
10081 `org-keep-stored-link-after-insertion'."
10083 (let (link desc entry remove file
(pos (point)))
10086 (skip-chars-forward "^]\n\r")
10087 (and (re-search-backward "\\[\\[" nil t
)
10088 (looking-at org-bracket-link-regexp
)
10089 (<= (match-beginning 0) pos
)
10090 (>= (match-end 0) pos
)))
10091 ;; We do have a link at point, and we are going to edit it.
10092 (setq remove
(list (match-beginning 0) (match-end 0)))
10093 (setq desc
(if (match-end 3) (org-match-string-no-properties 3)))
10094 (setq link
(read-string "Link: "
10096 (org-match-string-no-properties 1)))))
10097 ((equal complete-file
'(4))
10098 ;; Completing read for file names.
10099 (setq file
(read-file-name "File: "))
10100 (let ((pwd (file-name-as-directory (expand-file-name ".")))
10101 (pwd1 (file-name-as-directory (abbreviate-file-name
10102 (expand-file-name ".")))))
10104 ((equal complete-file
'(16))
10105 (setq link
(org-make-link
10107 (abbreviate-file-name (expand-file-name file
)))))
10108 ((string-match (concat "^" (regexp-quote pwd1
) "\\(.+\\)") file
)
10109 (setq link
(org-make-link "file:" (match-string 1 file
))))
10110 ((string-match (concat "^" (regexp-quote pwd
) "\\(.+\\)")
10111 (expand-file-name file
))
10112 (setq link
(org-make-link
10113 "file:" (match-string 1 (expand-file-name file
)))))
10114 (t (setq link
(org-make-link "file:" file
))))))
10116 ;; Read link, with completion for stored links.
10117 (setq link
(org-completing-read
10118 "Link: " org-stored-links nil nil nil
10119 org-insert-link-history
10120 (or (car (car org-stored-links
)))))
10121 (setq entry
(assoc link org-stored-links
))
10122 (if (funcall (if (equal complete-file
'(64)) 'not
'identity
)
10123 (not org-keep-stored-link-after-insertion
))
10124 (setq org-stored-links
(delq (assoc link org-stored-links
)
10125 org-stored-links
)))
10126 (setq link
(if entry
(nth 1 entry
) link
)
10127 desc
(or desc
(nth 2 entry
)))))
10129 (if (string-match org-plain-link-re link
)
10130 ;; URL-like link, normalize the use of angular brackets.
10131 (setq link
(org-make-link (org-remove-angle-brackets link
))))
10133 ;; Check if we are linking to the current file with a search option
10134 ;; If yes, simplify the link by using only the search option.
10135 (when (string-match "\\<file:\\(.+?\\)::\\([^>]+\\)" link
)
10136 (let* ((path (match-string 1 link
))
10137 (case-fold-search nil
)
10138 (search (match-string 2 link
)))
10140 (if (equal (file-truename buffer-file-name
) (file-truename path
))
10141 ;; We are linking to this same file, with a search option
10142 (setq link search
)))))
10144 ;; Check if we can/should use a relative path. If yes, simplify the link
10145 (when (string-match "\\<file:\\(.*\\)" link
)
10146 (let* ((path (match-string 1 link
))
10147 (case-fold-search nil
))
10149 ((eq org-link-file-path-type
'absolute
)
10150 (setq path
(abbreviate-file-name (expand-file-name path
))))
10151 ((eq org-link-file-path-type
'noabbrev
)
10152 (setq path
(expand-file-name path
)))
10153 ((eq org-link-file-path-type
'relative
)
10154 (setq path
(file-relative-name path
)))
10157 (if (string-match (concat "^" (regexp-quote
10158 (file-name-as-directory
10159 (expand-file-name "."))))
10160 (expand-file-name path
))
10161 ;; We are linking a file with relative path name.
10162 (setq path
(substring (expand-file-name path
)
10163 (match-end 0)))))))
10164 (setq link
(concat "file:" path
))))
10166 (setq desc
(read-string "Description: " desc
))
10167 (unless (string-match "\\S-" desc
) (setq desc nil
))
10168 (if remove
(apply 'delete-region remove
))
10169 (insert (org-make-link-string link desc
))))
10171 (defun org-completing-read (&rest args
)
10172 (let ((minibuffer-local-completion-map
10173 (copy-keymap minibuffer-local-completion-map
)))
10174 (define-key minibuffer-local-completion-map
" " 'self-insert-command
)
10175 (apply 'completing-read args
)))
10177 ;;; Hooks for remember.el
10179 (defvar org-finish-function nil
)
10182 (defun org-remember-annotation ()
10183 "Return a link to the current location as an annotation for remember.el.
10184 If you are using Org-mode files as target for data storage with
10185 remember.el, then the annotations should include a link compatible with the
10186 conventions in Org-mode. This function returns such a link."
10187 (org-store-link nil
))
10189 (defconst org-remember-help
10190 "Select a destination location for the note.
10191 UP/DOWN=headline TAB=cycle visibility [Q]uit RET/<left>/<right>=Store
10192 RET at beg-of-buf -> Append to file as level 2 headline
10193 RET on headline -> Store as sublevel entry to current headline
10194 <left>/<right> -> before/after current headline, same headings level")
10197 (defun org-remember-apply-template ()
10198 "Initialize *remember* buffer with template, invoke `org-mode'.
10199 This function should be placed into `remember-mode-hook' and in fact requires
10200 to be run from that hook to fucntion properly."
10201 (if org-remember-templates
10203 (let* ((entry (if (= (length org-remember-templates
) 1)
10204 (cdar org-remember-templates
)
10205 (message "Select template: %s"
10207 (lambda (x) (char-to-string (car x
)))
10208 org-remember-templates
" "))
10209 (cdr (assoc (read-char-exclusive) org-remember-templates
))))
10211 (file (if (consp (cdr entry
)) (nth 1 entry
)))
10212 (v-t (format-time-string (car org-time-stamp-formats
) (org-current-time)))
10213 (v-T (format-time-string (cdr org-time-stamp-formats
) (org-current-time)))
10214 (v-u (concat "[" (substring v-t
1 -
1) "]"))
10215 (v-U (concat "[" (substring v-T
1 -
1) "]"))
10216 (v-a annotation
) ; defined in `remember-mode'
10217 (v-i initial
) ; defined in `remember-mode'
10218 (v-n user-full-name
)
10220 (unless tpl
(setq tpl
"") (message "No template") (ding))
10221 (insert tpl
) (goto-char (point-min))
10222 (while (re-search-forward "%\\([tTuTai]\\)" nil t
)
10223 (when (and initial
(equal (match-string 0) "%i"))
10225 (let* ((lead (buffer-substring
10226 (point-at-bol) (match-beginning 0))))
10227 (setq v-i
(mapconcat 'identity
10228 (org-split-string initial
"\n")
10229 (concat "\n" lead
))))))
10231 (or (eval (intern (concat "v-" (match-string 1)))) "")
10233 (let ((org-startup-folded nil
)
10234 (org-startup-with-deadline-check nil
))
10236 (if (and file
(string-match "\\S-" file
) (not (file-directory-p file
)))
10237 (set (make-local-variable 'org-default-notes-file
) file
))
10238 (goto-char (point-min))
10239 (if (re-search-forward "%\\?" nil t
) (replace-match "")))
10240 (let ((org-startup-folded nil
)
10241 (org-startup-with-deadline-check nil
))
10243 (set (make-local-variable 'org-finish-function
) 'remember-buffer
))
10246 (defun org-remember-handler ()
10247 "Store stuff from remember.el into an org file.
10248 First prompts for an org file. If the user just presses return, the value
10249 of `org-default-notes-file' is used.
10250 Then the command offers the headings tree of the selected file in order to
10251 file the text at a specific location.
10252 You can either immediately press RET to get the note appended to the
10253 file, or you can use vertical cursor motion and visibility cycling (TAB) to
10254 find a better place. Then press RET or <left> or <right> in insert the note.
10256 Key Cursor position Note gets inserted
10257 -----------------------------------------------------------------------------
10258 RET buffer-start as level 2 heading at end of file
10259 RET on headline as sublevel of the heading at cursor
10260 RET no heading at cursor position, level taken from context.
10261 Or use prefix arg to specify level manually.
10262 <left> on headline as same level, before current heading
10263 <right> on headline as same level, after current heading
10265 So the fastest way to store the note is to press RET RET to append it to
10266 the default file. This way your current train of thought is not
10267 interrupted, in accordance with the principles of remember.el. But with
10268 little extra effort, you can push it directly to the correct location.
10270 Before being stored away, the function ensures that the text has a
10271 headline, i.e. a first line that starts with a \"*\". If not, a headline
10272 is constructed from the current date and some additional data.
10274 If the variable `org-adapt-indentation' is non-nil, the entire text is
10275 also indented so that it starts in the same column as the headline
10276 \(i.e. after the stars).
10278 See also the variable `org-reverse-note-order'."
10280 (let* ((txt (buffer-substring (point-min) (point-max)))
10281 (fastp current-prefix-arg
)
10282 (file (if fastp org-default-notes-file
(org-get-org-file)))
10283 (visiting (find-buffer-visiting file
))
10284 (org-startup-with-deadline-check nil
)
10285 (org-startup-folded nil
)
10286 (org-startup-align-all-tables nil
)
10287 spos level indent reversed
)
10288 ;; Modify text so that it becomes a nice subtree which can be inserted
10289 ;; into an org tree.
10290 (let* ((lines (split-string txt
"\n"))
10292 ;; remove empty lines at the beginning
10293 (while (and lines
(string-match "^[ \t]*\n" (car lines
)))
10294 (setq lines
(cdr lines
)))
10295 (setq first
(car lines
) lines
(cdr lines
))
10296 (if (string-match "^\\*+" first
)
10297 ;; Is already a headline
10299 ;; We need to add a headline: Use time and first buffer line
10300 (setq lines
(cons first lines
)
10301 first
(concat "* " (current-time-string)
10302 " (" (remember-buffer-desc) ")")
10304 (if (and org-adapt-indentation indent
)
10305 (setq lines
(mapcar (lambda (x) (concat indent x
)) lines
)))
10306 (setq txt
(concat first
"\n"
10307 (mapconcat 'identity lines
"\n"))))
10310 (find-file-noselect file
))
10311 (with-current-buffer (get-file-buffer file
)
10312 (save-excursion (and (goto-char (point-min))
10313 (not (re-search-forward "^\\* " nil t
))
10314 (insert "\n* Notes\n")))
10315 (setq reversed
(org-notes-order-reversed-p))
10319 ;; Ask the User for a location
10320 (setq spos
(if fastp
1 (org-get-location
10322 org-remember-help
)))
10323 (if (not spos
) (throw 'quit nil
)) ; return nil to show we did
10324 ; not handle this note
10327 ;; Put it at the start or end, as level 2
10330 (goto-char (if reversed
(point-min) (point-max)))
10331 (if (not (bolp)) (newline))
10332 (org-paste-subtree 2 txt
)))
10333 ((and (org-on-heading-p nil
) (not current-prefix-arg
))
10334 ;; Put it below this entry, at the beg/end of the subtree
10335 (org-back-to-heading)
10336 (setq level
(funcall outline-level
))
10338 (outline-end-of-heading)
10339 (outline-end-of-subtree))
10340 (if (not (bolp)) (newline))
10341 (beginning-of-line 1)
10342 (org-paste-subtree (1+ level
) txt
))
10344 ;; Put it right there, with automatic level determined by
10345 ;; org-paste-subtree or from prefix arg
10346 (org-paste-subtree current-prefix-arg txt
)))
10347 (when remember-save-after-remembering
10349 (if (not visiting
) (kill-buffer (current-buffer)))))))))
10350 t
) ;; return t to indicate that we took care of this note.
10352 (defun org-get-org-file ()
10353 "Read a filename, with default directory `org-directory'."
10354 (let ((default (or org-default-notes-file remember-data-file
)))
10355 (read-file-name (format "File name [%s]: " default
)
10356 (file-name-as-directory org-directory
)
10359 (defun org-notes-order-reversed-p ()
10360 "Check if the current file should receive notes in reversed order."
10362 ((not org-reverse-note-order
) nil
)
10363 ((eq t org-reverse-note-order
) t
)
10364 ((not (listp org-reverse-note-order
)) nil
)
10366 (let ((all org-reverse-note-order
)
10368 (while (setq entry
(pop all
))
10369 (if (string-match (car entry
) buffer-file-name
)
10370 (throw 'exit
(cdr entry
))))
10375 ;; Watch out: Here we are talking about two different kind of tables.
10376 ;; Most of the code is for the tables created with the Org-mode table editor.
10377 ;; Sometimes, we talk about tables created and edited with the table.el
10378 ;; Emacs package. We call the former org-type tables, and the latter
10379 ;; table.el-type tables.
10382 (defun org-before-change-function (beg end
)
10383 "Every change indicates that a table might need an update."
10384 (setq org-table-may-need-update t
))
10386 (defconst org-table-line-regexp
"^[ \t]*|"
10387 "Detects an org-type table line.")
10388 (defconst org-table-dataline-regexp
"^[ \t]*|[^-]"
10389 "Detects an org-type table line.")
10390 (defconst org-table-auto-recalculate-regexp
"^[ \t]*| *# *\\(|\\|$\\)"
10391 "Detects a table line marked for automatic recalculation.")
10392 (defconst org-table-recalculate-regexp
"^[ \t]*| *[#*] *\\(|\\|$\\)"
10393 "Detects a table line marked for automatic recalculation.")
10394 (defconst org-table-calculate-mark-regexp
"^[ \t]*| *[!$^_#*] *\\(|\\|$\\)"
10395 "Detects a table line marked for automatic recalculation.")
10396 (defconst org-table-hline-regexp
"^[ \t]*|-"
10397 "Detects an org-type table hline.")
10398 (defconst org-table1-hline-regexp
"^[ \t]*\\+-[-+]"
10399 "Detects a table-type table hline.")
10400 (defconst org-table-any-line-regexp
"^[ \t]*\\(|\\|\\+-[-+]\\)"
10401 "Detects an org-type or table-type table.")
10402 (defconst org-table-border-regexp
"^[ \t]*[^| \t]"
10403 "Searching from within a table (any type) this finds the first line
10404 outside the table.")
10405 (defconst org-table-any-border-regexp
"^[ \t]*[^|+ \t]"
10406 "Searching from within a table (any type) this finds the first line
10407 outside the table.")
10409 (defun org-table-create-with-table.el
()
10410 "Use the table.el package to insert a new table.
10411 If there is already a table at point, convert between Org-mode tables
10412 and table.el tables."
10416 ((org-at-table.el-p
)
10417 (if (y-or-n-p "Convert table to Org-mode table? ")
10418 (org-table-convert)))
10420 (if (y-or-n-p "Convert table to table.el table? ")
10421 (org-table-convert)))
10422 (t (call-interactively 'table-insert
))))
10424 (defun org-table-create-or-convert-from-region (arg)
10425 "Convert region to table, or create an empty table.
10426 If there is an active region, convert it to a table. If there is no such
10427 region, create an empty table."
10429 (if (org-region-active-p)
10430 (org-table-convert-region (region-beginning) (region-end) arg
)
10431 (org-table-create arg
)))
10433 (defun org-table-create (&optional size
)
10434 "Query for a size and insert a table skeleton.
10435 SIZE is a string Columns x Rows like for example \"3x2\"."
10438 (setq size
(read-string
10439 (concat "Table size Columns x Rows [e.g. "
10440 org-table-default-size
"]: ")
10441 "" nil org-table-default-size
)))
10443 (let* ((pos (point))
10444 (indent (make-string (current-column) ?\
))
10445 (split (org-split-string size
" *x *"))
10446 (rows (string-to-number (nth 1 split
)))
10447 (columns (string-to-number (car split
)))
10448 (line (concat (apply 'concat indent
"|" (make-list columns
" |"))
10450 (if (string-match "^[ \t]*$" (buffer-substring-no-properties
10451 (point-at-bol) (point)))
10452 (beginning-of-line 1)
10454 ;; (mapcar (lambda (x) (insert line)) (make-list rows t))
10455 (dotimes (i rows
) (insert line
))
10458 ;; Insert a hline after the first row.
10463 (org-table-align)))
10465 (defun org-table-convert-region (beg0 end0
&optional nspace
)
10466 "Convert region to a table.
10467 The region goes from BEG0 to END0, but these borders will be moved
10468 slightly, to make sure a beginning of line in the first line is included.
10469 When NSPACE is non-nil, it indicates the minimum number of spaces that
10470 separate columns (default: just one space)."
10472 (let* ((beg (min beg0 end0
))
10473 (end (max beg0 end0
))
10477 (beginning-of-line 1)
10478 (setq beg
(move-marker (make-marker) (point)))
10480 (if (bolp) (backward-char 1) (end-of-line 1))
10481 (setq end
(move-marker (make-marker) (point)))
10482 ;; Lets see if this is tab-separated material. If every nonempty line
10483 ;; contains a tab, we will assume that it is tab-separated material
10487 (and (re-search-forward "^[^\n\t]+$" end t
) (setq tabsep nil
)))
10488 (if nspace
(setq tabsep nil
))
10491 (setq re
(format "^ *\\| *\t *\\| \\{%d,\\}"
10492 (max 1 (prefix-numeric-value nspace
)))))
10494 (while (re-search-forward re end t
)
10495 (replace-match "|" t t
))
10498 (org-table-align)))
10500 (defun org-table-import (file arg
)
10501 "Import FILE as a table.
10502 The file is assumed to be tab-separated. Such files can be produced by most
10503 spreadsheet and database applications. If no tabs (at least one per line)
10504 are found, lines will be split on whitespace into fields."
10505 (interactive "f\nP")
10506 (or (bolp) (newline))
10507 (let ((beg (point))
10509 (insert-file-contents file
)
10510 (org-table-convert-region beg
(+ (point) (- (point-max) pm
)) arg
)))
10512 (defun org-table-export ()
10513 "Export table as a tab-separated file.
10514 Such a file can be imported into a spreadsheet program like Excel."
10516 (let* ((beg (org-table-begin))
10517 (end (org-table-end))
10518 (table (buffer-substring beg end
))
10519 (file (read-file-name "Export table to: "))
10521 (unless (or (not (file-exists-p file
))
10522 (y-or-n-p (format "Overwrite file %s? " file
)))
10524 (with-current-buffer (find-file-noselect file
)
10525 (setq buf
(current-buffer))
10529 (goto-char (point-min))
10530 (while (re-search-forward "^[ \t]*|[ \t]*" nil t
)
10531 (replace-match "" t t
)
10533 (goto-char (point-min))
10534 (while (re-search-forward "[ \t]*|[ \t]*$" nil t
)
10535 (replace-match "" t t
)
10536 (goto-char (min (1+ (point)) (point-max))))
10537 (goto-char (point-min))
10538 (while (re-search-forward "^-[-+]*$" nil t
)
10540 (if (looking-at "\n")
10542 (goto-char (point-min))
10543 (while (re-search-forward "[ \t]*|[ \t]*" nil t
)
10544 (replace-match "\t" t t
))
10546 (kill-buffer buf
)))
10548 (defvar org-table-aligned-begin-marker
(make-marker)
10549 "Marker at the beginning of the table last aligned.
10550 Used to check if cursor still is in that table, to minimize realignment.")
10551 (defvar org-table-aligned-end-marker
(make-marker)
10552 "Marker at the end of the table last aligned.
10553 Used to check if cursor still is in that table, to minimize realignment.")
10554 (defvar org-table-last-alignment nil
10555 "List of flags for flushright alignment, from the last re-alignment.
10556 This is being used to correctly align a single field after TAB or RET.")
10557 (defvar org-table-last-column-widths nil
10558 "List of max width of fields in each column.
10559 This is being used to correctly align a single field after TAB or RET.")
10561 (defvar org-last-recalc-line nil
)
10562 (defconst org-narrow-column-arrow
"=>"
10563 "Used as display property in narrowed table columns.")
10565 (defun org-table-align ()
10566 "Align the table at point by aligning all vertical bars."
10570 (beg (org-table-begin))
10571 (end (org-table-end))
10572 ;; Current cursor position
10573 (linepos (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
10574 (colpos (org-table-current-column))
10575 (winstart (window-start))
10576 lines
(new "") lengths l typenums ty fields maxfields i
10578 (indent "") cnt frac
10584 (make-string sp2 ?\
) "%%%s%ds" (make-string sp1 ?\
) "|"))
10586 (make-string sp2 ?-
) "%s" (make-string sp1 ?-
) "+"))
10587 emptystrings links narrow fmax f1 len c e
)
10589 (remove-text-properties beg end
'(org-cwidth t display t
))
10590 ;; Check if we have links
10592 (setq links
(re-search-forward org-bracket-link-regexp end t
))
10593 ;; Make sure the link properties are right
10594 (when links
(goto-char beg
) (while (org-activate-bracket-links end
)))
10595 ;; Check if we are narrowing any columns
10597 (setq narrow
(and org-format-transports-properties-p
10598 (re-search-forward "<[0-9]+>" end t
)))
10600 (setq lines
(org-split-string
10601 (buffer-substring beg end
) "\n"))
10602 ;; Store the indentation of the first line
10603 (if (string-match "^ *" (car lines
))
10604 (setq indent
(make-string (- (match-end 0) (match-beginning 0)) ?\
)))
10605 ;; Mark the hlines by setting the corresponding element to nil
10606 ;; At the same time, we remove trailing space.
10607 (setq lines
(mapcar (lambda (l)
10608 (if (string-match "^ *|-" l
)
10610 (if (string-match "[ \t]+$" l
)
10611 (substring l
0 (match-beginning 0))
10614 ;; Get the data fields by splitting the lines.
10615 (setq fields
(mapcar
10617 (org-split-string l
" *| *"))
10618 (delq nil
(copy-sequence lines
))))
10619 ;; How many fields in the longest line?
10620 (condition-case nil
10621 (setq maxfields
(apply 'max
(mapcar 'length fields
)))
10623 (kill-region beg end
)
10624 (org-table-create org-table-default-size
)
10625 (error "Empty table - created default table")))
10626 ;; A list of empty string to fill any short rows on output
10627 (setq emptystrings
(make-list maxfields
""))
10628 ;; Check for special formatting.
10630 (while (< (setq i
(1+ i
)) maxfields
) ;; Loop over all columns
10631 (setq column
(mapcar (lambda (x) (or (nth i x
) "")) fields
))
10632 ;; Check if there is an explicit width specified
10633 (when (and org-table-limit-column-width narrow
)
10634 (setq c column fmax nil
)
10637 (if (and (stringp e
) (string-match "^<\\([0-9]+\\)>$" e
))
10638 (setq fmax
(string-to-number (match-string 1 e
)) c nil
)))
10639 ;; Find fields that are wider than fmax, and shorten them
10641 (loop for xx in column do
10642 (when (and (stringp xx
)
10643 (> (org-string-width xx
) fmax
))
10644 (org-add-props xx nil
10646 (concat "Clipped table field, use C-c ` to edit. Full value is:\n" (org-no-properties (copy-sequence xx
))))
10647 (setq f1
(min fmax
(or (string-match org-bracket-link-regexp xx
) fmax
)))
10649 (error "Cannot narrow field starting with wide link \"%s\""
10650 (match-string 0 xx
)))
10651 (add-text-properties f1
(length xx
) (list 'org-cwidth t
) xx
)
10652 (add-text-properties (- f1
2) f1
10653 (list 'display org-narrow-column-arrow
)
10655 ;; Get the maximum width for each column
10656 (push (apply 'max
1 (mapcar 'org-string-width column
)) lengths
)
10657 ;; Get the fraction of numbers, to decide about alignment of the column
10658 (setq cnt
0 frac
0.0)
10659 (loop for x in column do
10662 (setq frac
( / (+ (* frac cnt
)
10663 (if (string-match org-table-number-regexp x
) 1 0))
10664 (setq cnt
(1+ cnt
))))))
10665 (push (>= frac org-table-number-fraction
) typenums
))
10666 (setq lengths
(nreverse lengths
) typenums
(nreverse typenums
))
10668 ;; Store the alignment of this table, for later editing of single fields
10669 (setq org-table-last-alignment typenums
10670 org-table-last-column-widths lengths
)
10672 ;; With invisible characters, `format' does not get the field width right
10673 ;; So we need to make these fields wide by hand.
10675 (loop for i from
0 upto
(1- maxfields
) do
10676 (setq len
(nth i lengths
))
10677 (loop for j from
0 upto
(1- (length fields
)) do
10678 (setq c
(nthcdr i
(car (nthcdr j fields
))))
10679 (if (and (stringp (car c
))
10680 (string-match org-bracket-link-regexp
(car c
))
10681 (< (org-string-width (car c
)) len
))
10682 (setcar c
(concat (car c
) (make-string (- len
(org-string-width (car c
))) ?\
)))))))
10684 ;; Compute the formats needed for output of the table
10685 (setq rfmt
(concat indent
"|") hfmt
(concat indent
"|"))
10686 (while (setq l
(pop lengths
))
10687 (setq ty
(if (pop typenums
) "" "-")) ; number types flushright
10688 (setq rfmt
(concat rfmt
(format rfmt1 ty l
))
10689 hfmt
(concat hfmt
(format hfmt1
(make-string l ?-
)))))
10690 (setq rfmt
(concat rfmt
"\n")
10691 hfmt
(concat (substring hfmt
0 -
1) "|\n"))
10693 (setq new
(mapconcat
10695 (if l
(apply 'format rfmt
10696 (append (pop fields
) emptystrings
))
10699 ;; Replace the old one
10700 (delete-region beg end
)
10701 (move-marker end nil
)
10702 (move-marker org-table-aligned-begin-marker
(point))
10704 (move-marker org-table-aligned-end-marker
(point))
10705 (when (and orgtbl-mode
(not (org-mode-p)))
10706 (goto-char org-table-aligned-begin-marker
)
10707 (while (org-hide-wide-columns org-table-aligned-end-marker
)))
10708 ;; Try to move to the old location (approximately)
10709 (goto-line linepos
)
10710 (set-window-start (selected-window) winstart
'noforce
)
10711 (org-table-goto-column colpos
)
10712 (setq org-table-may-need-update nil
)
10715 (defun org-string-width (s)
10716 "Compute width of string, ignoring invisible characters.
10717 This ignores character with invisibility property `org-link', and also
10718 characters with property `org-cwidth', because these will become invisible
10719 upon the next fontification round."
10721 (when (or (eq t buffer-invisibility-spec
)
10722 (assq 'org-link buffer-invisibility-spec
))
10723 (while (setq b
(text-property-any 0 (length s
)
10724 'invisible
'org-link s
))
10725 (setq s
(concat (substring s
0 b
)
10726 (substring s
(or (next-single-property-change
10727 b
'invisible s
) (length s
)))))))
10728 (while (setq b
(text-property-any 0 (length s
) 'org-cwidth t s
))
10729 (setq s
(concat (substring s
0 b
)
10730 (substring s
(or (next-single-property-change
10731 b
'org-cwidth s
) (length s
))))))
10734 (defun org-table-begin (&optional table-type
)
10735 "Find the beginning of the table and return its position.
10736 With argument TABLE-TYPE, go to the beginning of a table.el-type table."
10738 (if (not (re-search-backward
10739 (if table-type org-table-any-border-regexp
10740 org-table-border-regexp
)
10742 (progn (goto-char (point-min)) (point))
10743 (goto-char (match-beginning 0))
10744 (beginning-of-line 2)
10747 (defun org-table-end (&optional table-type
)
10748 "Find the end of the table and return its position.
10749 With argument TABLE-TYPE, go to the end of a table.el-type table."
10751 (if (not (re-search-forward
10752 (if table-type org-table-any-border-regexp
10753 org-table-border-regexp
)
10755 (goto-char (point-max))
10756 (goto-char (match-beginning 0)))
10759 (defun org-table-justify-field-maybe (&optional new
)
10760 "Justify the current field, text to left, number to right.
10761 Optional argument NEW may specify text to replace the current field content."
10763 ((and (not new
) org-table-may-need-update
)) ; Realignment will happen anyway
10764 ((org-at-table-hline-p))
10766 (or (not (equal (marker-buffer org-table-aligned-begin-marker
)
10768 (< (point) org-table-aligned-begin-marker
)
10769 (>= (point) org-table-aligned-end-marker
)))
10770 ;; This is not the same table, force a full re-align
10771 (setq org-table-may-need-update t
))
10772 (t ;; realign the current field, based on previous full realign
10773 (let* ((pos (point)) s
10774 (col (org-table-current-column))
10775 (num (if (> col
0) (nth (1- col
) org-table-last-alignment
)))
10778 (skip-chars-backward "^|\n")
10779 (if (looking-at " *\\([^|\n]*?\\) *\\(|\\|$\\)")
10781 (setq s
(match-string 1)
10783 l
(max 1 (- (match-end 0) (match-beginning 0) 3))
10784 e
(not (= (match-beginning 2) (match-end 2))))
10785 (setq f
(format (if num
" %%%ds %s" " %%-%ds %s")
10786 l
(if e
"|" (setq org-table-may-need-update t
) ""))
10789 (if (<= (length new
) l
) ;; FIXME: length -> str-width?
10790 (setq n
(format f new
))
10791 (setq n
(concat new
"|") org-table-may-need-update t
)))
10793 (let (org-table-may-need-update)
10794 (replace-match n
))))
10795 (setq org-table-may-need-update t
))
10796 (goto-char pos
))))))
10798 (defun org-table-next-field ()
10799 "Go to the next field in the current table, creating new lines as needed.
10800 Before doing so, re-align the table if necessary."
10802 (org-table-maybe-eval-formula)
10803 (org-table-maybe-recalculate-line)
10804 (if (and org-table-automatic-realign
10805 org-table-may-need-update
)
10807 (let ((end (org-table-end)))
10808 (if (org-at-table-hline-p)
10810 (condition-case nil
10812 (re-search-forward "|" end
)
10813 (if (looking-at "[ \t]*$")
10814 (re-search-forward "|" end
))
10815 (if (and (looking-at "-")
10816 org-table-tab-jumps-over-hlines
10817 (re-search-forward "^[ \t]*|\\([^-]\\)" end t
))
10818 (goto-char (match-beginning 1)))
10819 (if (looking-at "-")
10821 (beginning-of-line 0)
10822 (org-table-insert-row 'below
))
10823 (if (looking-at " ") (forward-char 1))))
10825 (org-table-insert-row 'below
)))))
10827 (defun org-table-previous-field ()
10828 "Go to the previous field in the table.
10829 Before doing so, re-align the table if necessary."
10831 (org-table-justify-field-maybe)
10832 (org-table-maybe-recalculate-line)
10833 (if (and org-table-automatic-realign
10834 org-table-may-need-update
)
10836 (if (org-at-table-hline-p)
10838 (re-search-backward "|" (org-table-begin))
10839 (re-search-backward "|" (org-table-begin))
10840 (while (looking-at "|\\(-\\|[ \t]*$\\)")
10841 (re-search-backward "|" (org-table-begin)))
10842 (if (looking-at "| ?")
10843 (goto-char (match-end 0))))
10845 (defun org-table-next-row ()
10846 "Go to the next row (same column) in the current table.
10847 Before doing so, re-align the table if necessary."
10849 (org-table-maybe-eval-formula)
10850 (org-table-maybe-recalculate-line)
10851 (if (or (looking-at "[ \t]*$")
10852 (save-excursion (skip-chars-backward " \t") (bolp)))
10854 (if (and org-table-automatic-realign
10855 org-table-may-need-update
)
10857 (let ((col (org-table-current-column)))
10858 (beginning-of-line 2)
10859 (if (or (not (org-at-table-p))
10860 (org-at-table-hline-p))
10862 (beginning-of-line 0)
10863 (org-table-insert-row 'below
)))
10864 (org-table-goto-column col
)
10865 (skip-chars-backward "^|\n\r")
10866 (if (looking-at " ") (forward-char 1)))))
10868 (defun org-table-copy-down (n)
10869 "Copy a field down in the current column.
10870 If the field at the cursor is empty, copy into it the content of the nearest
10871 non-empty field above. With argument N, use the Nth non-empty field.
10872 If the current field is not empty, it is copied down to the next row, and
10873 the cursor is moved with it. Therefore, repeating this command causes the
10874 column to be filled row-by-row.
10875 If the variable `org-table-copy-increment' is non-nil and the field is an
10876 integer, it will be incremented while copying."
10878 (let* ((colpos (org-table-current-column))
10879 (field (org-table-get-field))
10880 (non-empty (string-match "[^ \t]" field
))
10881 (beg (org-table-begin))
10883 (org-table-check-inside-data-field)
10886 (setq txt
(org-trim field
))
10887 (org-table-next-row)
10888 (org-table-blank-field))
10892 (while (progn (beginning-of-line 1)
10893 (re-search-backward org-table-dataline-regexp
10895 (org-table-goto-column colpos t
)
10896 (if (and (looking-at
10897 "|[ \t]*\\([^| \t][^|]*?\\)[ \t]*|")
10898 (= (setq n
(1- n
)) 0))
10899 (throw 'exit
(match-string 1))))))))
10902 (if (and org-table-copy-increment
10903 (string-match "^[0-9]+$" txt
))
10904 (setq txt
(format "%d" (+ (string-to-number txt
) 1))))
10906 (org-table-maybe-recalculate-line)
10908 (error "No non-empty field found"))))
10910 (defun org-table-check-inside-data-field ()
10911 "Is point inside a table data field?
10912 I.e. not on a hline or before the first or after the last column?
10913 This actually throws an error, so it aborts the current command."
10914 (if (or (not (org-at-table-p))
10915 (= (org-table-current-column) 0)
10916 (org-at-table-hline-p)
10917 (looking-at "[ \t]*$"))
10918 (error "Not in table data field")))
10920 (defvar org-table-clip nil
10921 "Clipboard for table regions.")
10923 (defun org-table-blank-field ()
10924 "Blank the current table field or active region."
10926 (org-table-check-inside-data-field)
10927 (if (and (interactive-p) (org-region-active-p))
10928 (let (org-table-clip)
10929 (org-table-cut-region (region-beginning) (region-end)))
10930 (skip-chars-backward "^|")
10932 (if (looking-at "|[^|\n]+")
10933 (let* ((pos (match-beginning 0))
10934 (match (match-string 0))
10935 (len (org-string-width match
)))
10936 (replace-match (concat "|" (make-string (1- len
) ?\
)))
10937 (goto-char (+ 2 pos
))
10938 (substring match
1)))))
10940 (defun org-table-get-field (&optional n replace
)
10941 "Return the value of the field in column N of current row.
10942 N defaults to current field.
10943 If REPLACE is a string, replace field with this value. The return value
10944 is always the old value."
10945 (and n
(org-table-goto-column n
))
10946 (skip-chars-backward "^|\n")
10948 (if (looking-at "|[^|\r\n]*")
10949 (let* ((pos (match-beginning 0))
10950 (val (buffer-substring (1+ pos
) (match-end 0))))
10952 (replace-match (concat "|" replace
)))
10953 (goto-char (min (point-at-eol) (+ 2 pos
)))
10955 (forward-char 1) ""))
10957 (defun org-table-current-column ()
10958 "Find out which column we are in.
10959 When called interactively, column is also displayed in echo area."
10961 (if (interactive-p) (org-table-check-inside-data-field))
10963 (let ((cnt 0) (pos (point)))
10964 (beginning-of-line 1)
10965 (while (search-forward "|" pos t
)
10966 (setq cnt
(1+ cnt
)))
10967 (if (interactive-p) (message "This is table column %d" cnt
))
10970 (defun org-table-goto-column (n &optional on-delim force
)
10971 "Move the cursor to the Nth column in the current table line.
10972 With optional argument ON-DELIM, stop with point before the left delimiter
10974 If there are less than N fields, just go to after the last delimiter.
10975 However, when FORCE is non-nil, create new columns if necessary."
10977 (let ((pos (point-at-eol)))
10978 (beginning-of-line 1)
10980 (while (and (> (setq n
(1- n
)) -
1)
10981 (or (search-forward "|" pos t
)
10983 (progn (end-of-line 1)
10984 (skip-chars-backward "^|")
10985 (insert " | "))))))
10986 ; (backward-char 2) t)))))
10987 (when (and force
(not (looking-at ".*|")))
10988 (save-excursion (end-of-line 1) (insert " | ")))
10991 (if (looking-at " ") (forward-char 1))))))
10993 (defun org-at-table-p (&optional table-type
)
10994 "Return t if the cursor is inside an org-type table.
10995 If TABLE-TYPE is non-nil, also check for table.el-type tables."
10996 (if org-enable-table-editor
10998 (beginning-of-line 1)
10999 (looking-at (if table-type org-table-any-line-regexp
11000 org-table-line-regexp
)))
11003 (defun org-at-table.el-p
()
11004 "Return t if and only if we are at a table.el table."
11005 (and (org-at-table-p 'any
)
11007 (goto-char (org-table-begin 'any
))
11008 (looking-at org-table1-hline-regexp
))))
11010 (defun org-table-recognize-table.el
()
11011 "If there is a table.el table nearby, recognize it and move into it."
11012 (if org-table-tab-recognizes-table.el
11013 (if (org-at-table.el-p
)
11015 (beginning-of-line 1)
11016 (if (looking-at org-table-dataline-regexp
)
11018 (if (looking-at org-table1-hline-regexp
)
11020 (beginning-of-line 2)
11021 (if (looking-at org-table-any-border-regexp
)
11022 (beginning-of-line -
1)))))
11023 (if (re-search-forward "|" (org-table-end t
) t
)
11026 (if (table--at-cell-p (point))
11028 (message "recognizing table.el table...")
11029 (table-recognize-table)
11030 (message "recognizing table.el table...done")))
11031 (error "This should not happen..."))
11036 (defun org-at-table-hline-p ()
11037 "Return t if the cursor is inside a hline in a table."
11038 (if org-enable-table-editor
11040 (beginning-of-line 1)
11041 (looking-at org-table-hline-regexp
))
11044 (defun org-table-insert-column ()
11045 "Insert a new column into the table."
11047 (if (not (org-at-table-p))
11048 (error "Not at a table"))
11049 (org-table-find-dataline)
11050 (let* ((col (max 1 (org-table-current-column)))
11051 (beg (org-table-begin))
11052 (end (org-table-end))
11053 ;; Current cursor position
11054 (linepos (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
11057 (while (< (point) end
)
11058 (if (org-at-table-hline-p)
11060 (org-table-goto-column col t
)
11062 (beginning-of-line 2))
11063 (move-marker end nil
)
11064 (goto-line linepos
)
11065 (org-table-goto-column colpos
)
11067 (org-table-modify-formulas 'insert col
)))
11069 (defun org-table-find-dataline ()
11070 "Find a dataline in the current table, which is needed for column commands."
11071 (if (and (org-at-table-p)
11072 (not (org-at-table-hline-p)))
11074 (let ((col (current-column))
11075 (end (org-table-end)))
11076 (move-to-column col
)
11077 (while (and (< (point) end
)
11078 (or (not (= (current-column) col
))
11079 (org-at-table-hline-p)))
11080 (beginning-of-line 2)
11081 (move-to-column col
))
11082 (if (and (org-at-table-p)
11083 (not (org-at-table-hline-p)))
11086 "Please position cursor in a data line for column operations")))))
11088 (defun org-table-delete-column ()
11089 "Delete a column from the table."
11091 (if (not (org-at-table-p))
11092 (error "Not at a table"))
11093 (org-table-find-dataline)
11094 (org-table-check-inside-data-field)
11095 (let* ((col (org-table-current-column))
11096 (beg (org-table-begin))
11097 (end (org-table-end))
11098 ;; Current cursor position
11099 (linepos (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
11102 (while (< (point) end
)
11103 (if (org-at-table-hline-p)
11105 (org-table-goto-column col t
)
11106 (and (looking-at "|[^|\n]+|")
11107 (replace-match "|")))
11108 (beginning-of-line 2))
11109 (move-marker end nil
)
11110 (goto-line linepos
)
11111 (org-table-goto-column colpos
)
11113 (org-table-modify-formulas 'remove col
)))
11115 (defun org-table-move-column-right ()
11116 "Move column to the right."
11118 (org-table-move-column nil
))
11119 (defun org-table-move-column-left ()
11120 "Move column to the left."
11122 (org-table-move-column 'left
))
11124 (defun org-table-move-column (&optional left
)
11125 "Move the current column to the right. With arg LEFT, move to the left."
11127 (if (not (org-at-table-p))
11128 (error "Not at a table"))
11129 (org-table-find-dataline)
11130 (org-table-check-inside-data-field)
11131 (let* ((col (org-table-current-column))
11132 (col1 (if left
(1- col
) col
))
11133 (beg (org-table-begin))
11134 (end (org-table-end))
11135 ;; Current cursor position
11136 (linepos (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
11137 (colpos (if left
(1- col
) (1+ col
))))
11138 (if (and left
(= col
1))
11139 (error "Cannot move column further left"))
11140 (if (and (not left
) (looking-at "[^|\n]*|[^|\n]*$"))
11141 (error "Cannot move column further right"))
11143 (while (< (point) end
)
11144 (if (org-at-table-hline-p)
11146 (org-table-goto-column col1 t
)
11147 (and (looking-at "|\\([^|\n]+\\)|\\([^|\n]+\\)|")
11148 (replace-match "|\\2|\\1|")))
11149 (beginning-of-line 2))
11150 (move-marker end nil
)
11151 (goto-line linepos
)
11152 (org-table-goto-column colpos
)
11154 (org-table-modify-formulas 'swap col
(if left
(1- col
) (1+ col
)))))
11156 (defun org-table-move-row-down ()
11157 "Move table row down."
11159 (org-table-move-row nil
))
11160 (defun org-table-move-row-up ()
11161 "Move table row up."
11163 (org-table-move-row 'up
))
11165 (defun org-table-move-row (&optional up
)
11166 "Move the current table line down. With arg UP, move it up."
11168 (let ((col (current-column))
11170 (tonew (if up
0 2))
11172 (beginning-of-line tonew
)
11173 (if (not (org-at-table-p))
11176 (error "Cannot move row further")))
11178 (beginning-of-line 1)
11180 (setq txt
(buffer-substring (point) (1+ (point-at-eol))))
11181 (delete-region (point) (1+ (point-at-eol)))
11182 (beginning-of-line tonew
)
11184 (beginning-of-line 0)
11185 (move-to-column col
)))
11187 (defun org-table-insert-row (&optional arg
)
11188 "Insert a new row above the current line into the table.
11189 With prefix ARG, insert below the current line."
11191 (if (not (org-at-table-p))
11192 (error "Not at a table"))
11193 (let* ((line (buffer-substring (point-at-bol) (point-at-eol)))
11194 (new (org-table-clean-line line
)))
11195 ;; Fix the first field if necessary
11196 (if (string-match "^[ \t]*| *[#$] *|" line
)
11197 (setq new
(replace-match (match-string 0 line
) t t new
)))
11198 (beginning-of-line (if arg
2 1))
11199 (let (org-table-may-need-update) (insert-before-markers new
"\n"))
11200 (beginning-of-line 0)
11201 (re-search-forward "| ?" (point-at-eol) t
)
11202 (and org-table-may-need-update
(org-table-align))))
11204 (defun org-table-insert-hline (&optional arg
)
11205 "Insert a horizontal-line below the current line into the table.
11206 With prefix ARG, insert above the current line."
11208 (if (not (org-at-table-p))
11209 (error "Not at a table"))
11210 (let ((line (org-table-clean-line
11211 (buffer-substring (point-at-bol) (point-at-eol))))
11212 (col (current-column)))
11213 (while (string-match "|\\( +\\)|" line
)
11214 (setq line
(replace-match
11215 (concat "+" (make-string (- (match-end 1) (match-beginning 1))
11216 ?-
) "|") t t line
)))
11217 (and (string-match "\\+" line
) (setq line
(replace-match "|" t t line
)))
11218 (beginning-of-line (if arg
1 2))
11220 (beginning-of-line (if arg
1 -
1))
11221 (move-to-column col
)))
11223 (defun org-table-clean-line (s)
11224 "Convert a table line S into a string with only \"|\" and space.
11225 In particular, this does handle wide and invisible characters."
11226 (if (string-match "^[ \t]*|-" s
)
11227 ;; It's a hline, just map the characters
11228 (setq s
(mapconcat (lambda (x) (if (member x
'(?| ?
+)) "|" " ")) s
""))
11229 (while (string-match "|\\([ \t]*?[^ \t\r\n|][^\r\n|]*\\)|" s
)
11230 (setq s
(replace-match
11231 (concat "|" (make-string (org-string-width (match-string 1 s
))
11236 (defun org-table-kill-row ()
11237 "Delete the current row or horizontal line from the table."
11239 (if (not (org-at-table-p))
11240 (error "Not at a table"))
11241 (let ((col (current-column)))
11242 (kill-region (point-at-bol) (min (1+ (point-at-eol)) (point-max)))
11243 (if (not (org-at-table-p)) (beginning-of-line 0))
11244 (move-to-column col
)))
11246 (defun org-table-sort-lines (beg end numericp
)
11247 "Sort table lines in region.
11248 Point and mark define the first and last line to include. Both point and
11249 mark should be in the column that is used for sorting. For example, to
11250 sort according to column 3, put the mark in the first line to sort, in
11251 table column 3. Put point into the last line to be included in the sorting,
11252 also in table column 3. The command will prompt for the sorting method
11253 \(n for numerical, a for alphanumeric)."
11254 (interactive "r\nsSorting method: [n]=numeric [a]=alpha: ")
11255 (setq numericp
(string-match "[nN]" numericp
))
11256 (org-table-align) ;; Just to be safe
11257 (let* (bcol ecol cmp column lns
)
11259 (org-table-check-inside-data-field)
11260 (setq column
(org-table-current-column)
11261 beg
(move-marker (make-marker) (point-at-bol)))
11263 (org-table-check-inside-data-field)
11264 (setq end
(move-marker (make-marker) (1+ (point-at-eol))))
11267 (org-table-goto-column column
)
11268 (skip-chars-backward "^|")
11269 (setq bcol
(current-column))
11270 (org-table-goto-column (1+ column
))
11271 (skip-chars-backward "^|")
11272 (setq ecol
(1- (current-column)))
11273 (setq cmp
(if numericp
11274 (lambda (a b
) (< (car a
) (car b
)))
11275 (lambda (a b
) (string< (car a
) (car b
)))))
11276 (setq lns
(mapcar (lambda(x) (cons (org-trim (substring x bcol ecol
)) x
))
11277 (org-split-string (buffer-substring beg end
) "\n")))
11279 (setq lns
(mapcar (lambda(x)
11280 (cons (string-to-number (car x
)) (cdr x
)))
11282 (delete-region beg end
)
11283 (move-marker beg nil
)
11284 (move-marker end nil
)
11285 (insert (mapconcat 'cdr
(setq lns
(sort lns cmp
)) "\n") "\n")
11286 (message "%d lines sorted %s based on column %d"
11288 (if numericp
"numerically" "alphabetically") column
)))
11290 (defun org-table-cut-region (beg end
)
11291 "Copy region in table to the clipboard and blank all relevant fields."
11293 (org-table-copy-region beg end
'cut
))
11295 (defun org-table-copy-region (beg end
&optional cut
)
11296 "Copy rectangular region in table to clipboard.
11297 A special clipboard is used which can only be accessed
11298 with `org-table-paste-rectangle'."
11300 (let* (l01 c01 l02 c02 l1 c1 l2 c2 ic1 ic2
11302 (rpl (if cut
" " nil
)))
11304 (org-table-check-inside-data-field)
11305 (setq l01
(count-lines (point-min) (point))
11306 c01
(org-table-current-column))
11308 (org-table-check-inside-data-field)
11309 (setq l02
(count-lines (point-min) (point))
11310 c02
(org-table-current-column))
11311 (setq l1
(min l01 l02
) l2
(max l01 l02
)
11312 c1
(min c01 c02
) c2
(max c01 c02
))
11316 (if (> l1 l2
) (throw 'exit t
))
11318 (if (org-at-table-hline-p) (throw 'nextline
(setq l1
(1+ l1
))))
11319 (setq cols nil ic1 c1 ic2 c2
)
11320 (while (< ic1
(1+ ic2
))
11321 (push (org-table-get-field ic1 rpl
) cols
)
11322 (setq ic1
(1+ ic1
)))
11323 (push (nreverse cols
) region
)
11324 (setq l1
(1+ l1
)))))
11325 (setq org-table-clip
(nreverse region
))
11326 (if cut
(org-table-align))
11329 (defun org-table-paste-rectangle ()
11330 "Paste a rectangular region into a table.
11331 The upper right corner ends up in the current field. All involved fields
11332 will be overwritten. If the rectangle does not fit into the present table,
11333 the table is enlarged as needed. The process ignores horizontal separator
11336 (unless (and org-table-clip
(listp org-table-clip
))
11337 (error "First cut/copy a region to paste!"))
11338 (org-table-check-inside-data-field)
11339 (let* ((clip org-table-clip
)
11340 (line (count-lines (point-min) (point)))
11341 (col (org-table-current-column))
11342 (org-enable-table-editor t
)
11343 (org-table-automatic-realign nil
)
11345 (while (setq cols
(pop clip
))
11346 (while (org-at-table-hline-p) (beginning-of-line 2))
11347 (if (not (org-at-table-p))
11348 (progn (end-of-line 0) (org-table-next-field)))
11350 (while (setq field
(pop cols
))
11351 (org-table-goto-column c nil
'force
)
11352 (org-table-get-field nil field
)
11354 (beginning-of-line 2))
11356 (org-table-goto-column col
)
11357 (org-table-align)))
11359 (defun org-table-convert ()
11360 "Convert from `org-mode' table to table.el and back.
11361 Obviously, this only works within limits. When an Org-mode table is
11362 converted to table.el, all horizontal separator lines get lost, because
11363 table.el uses these as cell boundaries and has no notion of horizontal lines.
11364 A table.el table can be converted to an Org-mode table only if it does not
11365 do row or column spanning. Multiline cells will become multiple cells.
11366 Beware, Org-mode does not test if the table can be successfully converted - it
11367 blindly applies a recipe that works for simple tables."
11370 (if (org-at-table.el-p
)
11371 ;; convert to Org-mode table
11372 (let ((beg (move-marker (make-marker) (org-table-begin t
)))
11373 (end (move-marker (make-marker) (org-table-end t
))))
11374 (table-unrecognize-region beg end
)
11376 (while (re-search-forward "^\\([ \t]*\\)\\+-.*\n" end t
)
11377 (replace-match ""))
11379 (if (org-at-table-p)
11380 ;; convert to table.el table
11381 (let ((beg (move-marker (make-marker) (org-table-begin)))
11382 (end (move-marker (make-marker) (org-table-end))))
11383 ;; first, get rid of all horizontal lines
11385 (while (re-search-forward "^\\([ \t]*\\)|-.*\n" end t
)
11386 (replace-match ""))
11387 ;; insert a hline before first
11389 (org-table-insert-hline 'above
)
11390 (beginning-of-line -
1)
11391 ;; insert a hline after each line
11392 (while (progn (beginning-of-line 3) (< (point) end
))
11393 (org-table-insert-hline))
11395 (setq end
(move-marker end
(org-table-end)))
11396 ;; replace "+" at beginning and ending of hlines
11397 (while (re-search-forward "^\\([ \t]*\\)|-" end t
)
11398 (replace-match "\\1+-"))
11400 (while (re-search-forward "-|[ \t]*$" end t
)
11401 (replace-match "-+"))
11402 (goto-char beg
)))))
11404 (defun org-table-wrap-region (arg)
11405 "Wrap several fields in a column like a paragraph.
11406 This is useful if you'd like to spread the contents of a field over several
11407 lines, in order to keep the table compact.
11409 If there is an active region, and both point and mark are in the same column,
11410 the text in the column is wrapped to minimum width for the given number of
11411 lines. Generally, this makes the table more compact. A prefix ARG may be
11412 used to change the number of desired lines. For example, `C-2 \\[org-table-wrap]'
11413 formats the selected text to two lines. If the region was longer than two
11414 lines, the remaining lines remain empty. A negative prefix argument reduces
11415 the current number of lines by that amount. The wrapped text is pasted back
11416 into the table. If you formatted it to more lines than it was before, fields
11417 further down in the table get overwritten - so you might need to make space in
11420 If there is no region, the current field is split at the cursor position and
11421 the text fragment to the right of the cursor is prepended to the field one
11424 If there is no region, but you specify a prefix ARG, the current field gets
11425 blank, and the content is appended to the field above."
11427 (org-table-check-inside-data-field)
11428 (if (org-region-active-p)
11429 ;; There is a region: fill as a paragraph
11430 (let ((beg (region-beginning))
11432 (org-table-cut-region (region-beginning) (region-end))
11433 (if (> (length (car org-table-clip
)) 1)
11434 (error "Region must be limited to single column"))
11435 (setq nlines
(if arg
11437 (+ (length org-table-clip
) arg
)
11439 (length org-table-clip
)))
11440 (setq org-table-clip
11441 (mapcar 'list
(org-wrap (mapconcat 'car org-table-clip
" ")
11444 (org-table-paste-rectangle))
11445 ;; No region, split the current field at point
11447 ;; combine with field above
11448 (let ((s (org-table-blank-field))
11449 (col (org-table-current-column)))
11450 (beginning-of-line 0)
11451 (while (org-at-table-hline-p) (beginning-of-line 0))
11452 (org-table-goto-column col
)
11453 (skip-chars-forward "^|")
11454 (skip-chars-backward " ")
11455 (insert " " (org-trim s
))
11458 (when (looking-at "\\([^|]+\\)+|")
11459 (let ((s (match-string 1)))
11460 (replace-match " |")
11461 (goto-char (match-beginning 0))
11462 (org-table-next-row)
11463 (insert (org-trim s
) " ")
11464 (org-table-align))))))
11466 (defvar org-field-marker nil
)
11468 (defun org-table-edit-field (arg)
11469 "Edit table field in a different window.
11470 This is mainly useful for fields that contain hidden parts.
11471 When called with a \\[universal-argument] prefix, just make the full field visible so that
11472 it can be edited in place."
11475 (let ((b (save-excursion (skip-chars-backward "^|") (point)))
11476 (e (save-excursion (skip-chars-forward "^|\r\n") (point))))
11477 (remove-text-properties b e
'(org-cwidth t invisible t
11478 display t intangible t
))
11479 (if (and (boundp 'font-lock-mode
) font-lock-mode
)
11480 (font-lock-fontify-block)))
11481 (let ((pos (move-marker (make-marker) (point)))
11482 (field (org-table-get-field))
11483 (cw (current-window-configuration))
11485 (switch-to-buffer-other-window "*Org tmp*")
11487 (insert "#\n# Edit field and finish with C-c C-c\n#\n")
11489 (goto-char (setq p
(point-max)))
11490 (insert (org-trim field
))
11491 (remove-text-properties p
(point-max)
11492 '(invisible t org-cwidth t display t
11495 (set (make-local-variable 'org-finish-function
)
11496 'org-table-finish-edit-field
)
11497 (set (make-local-variable 'org-window-configuration
) cw
)
11498 (set (make-local-variable 'org-field-marker
) pos
)
11499 (message "Edit and finish with C-c C-c"))))
11501 (defun org-table-finish-edit-field ()
11502 "Finish editing a table data field.
11503 Remove all newline characters, insert the result into the table, realign
11504 the table and kill the editing buffer."
11505 (let ((pos org-field-marker
)
11506 (cw org-window-configuration
)
11507 (cb (current-buffer))
11509 (goto-char (point-min))
11510 (while (re-search-forward "^#.*\n?" nil t
) (replace-match ""))
11511 (while (re-search-forward "\\([ \t]*\n[ \t]*\\)+" nil t
)
11512 (replace-match " "))
11513 (setq text
(org-trim (buffer-string)))
11514 (set-window-configuration cw
)
11516 (select-window (get-buffer-window (marker-buffer pos
)))
11518 (move-marker pos nil
)
11519 (org-table-check-inside-data-field)
11520 (org-table-get-field nil text
)
11522 (message "New field value inserted")))
11524 (defun org-trim (s)
11525 "Remove whitespace at beginning and end of string."
11526 (if (string-match "^[ \t]+" s
) (setq s
(replace-match "" t t s
)))
11527 (if (string-match "[ \t]+$" s
) (setq s
(replace-match "" t t s
)))
11530 (defun org-wrap (string &optional width lines
)
11531 "Wrap string to either a number of lines, or a width in characters.
11532 If WIDTH is non-nil, the string is wrapped to that width, however many lines
11533 that costs. If there is a word longer than WIDTH, the text is actually
11534 wrapped to the length of that word.
11535 IF WIDTH is nil and LINES is non-nil, the string is forced into at most that
11536 many lines, whatever width that takes.
11537 The return value is a list of lines, without newlines at the end."
11538 (let* ((words (org-split-string string
"[ \t\n]+"))
11539 (maxword (apply 'max
(mapcar 'org-string-width words
)))
11542 (org-do-wrap words
(max maxword width
)))
11545 (setq ll
(org-do-wrap words maxword
))
11546 (if (<= (length ll
) lines
)
11549 (while (> (length ll
) lines
)
11551 (setq ll
(org-do-wrap words w
)))
11553 (t (error "Cannot wrap this")))))
11556 (defun org-do-wrap (words width
)
11557 "Create lines of maximum width WIDTH (in characters) from word list WORDS."
11560 (setq line
(pop words
))
11561 (while (and words
(< (+ (length line
) (length (car words
))) width
))
11562 (setq line
(concat line
" " (pop words
))))
11563 (setq lines
(push line lines
)))
11566 (defun org-split-string (string &optional separators
)
11567 "Splits STRING into substrings at SEPARATORS.
11568 No empty strings are returned if there are matches at the beginning
11569 and end of string."
11570 (let ((rexp (or separators
"[ \f\t\n\r\v]+"))
11574 (while (and (string-match rexp string
11576 (= start
(match-beginning 0))
11577 (< start
(length string
)))
11579 (< (match-beginning 0) (length string
)))
11581 (or (eq (match-beginning 0) 0)
11582 (and (eq (match-beginning 0) (match-end 0))
11583 (eq (match-beginning 0) start
))
11585 (cons (substring string start
(match-beginning 0))
11587 (setq start
(match-end 0)))
11588 (or (eq start
(length string
))
11590 (cons (substring string start
)
11594 (defun org-table-map-tables (function)
11595 "Apply FUNCTION to the start of all tables in the buffer."
11599 (goto-char (point-min))
11600 (while (re-search-forward org-table-any-line-regexp nil t
)
11601 (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size)))
11602 (beginning-of-line 1)
11603 (if (looking-at org-table-line-regexp
)
11604 (save-excursion (funcall function
)))
11605 (re-search-forward org-table-any-border-regexp nil
1))))
11606 (message "Mapping tables: done"))
11608 (defun org-table-sum (&optional beg end nlast
)
11609 "Sum numbers in region of current table column.
11610 The result will be displayed in the echo area, and will be available
11611 as kill to be inserted with \\[yank].
11613 If there is an active region, it is interpreted as a rectangle and all
11614 numbers in that rectangle will be summed. If there is no active
11615 region and point is located in a table column, sum all numbers in that
11618 If at least one number looks like a time HH:MM or HH:MM:SS, all other
11619 numbers are assumed to be times as well (in decimal hours) and the
11620 numbers are added as such.
11622 If NLAST is a number, only the NLAST fields will actually be summed."
11625 (let (col (timecnt 0) diff h m s org-table-clip
)
11627 ((and beg end
)) ; beg and end given explicitly
11628 ((org-region-active-p)
11629 (setq beg
(region-beginning) end
(region-end)))
11631 (setq col
(org-table-current-column))
11632 (goto-char (org-table-begin))
11633 (unless (re-search-forward "^[ \t]*|[^-]" nil t
)
11634 (error "No table data"))
11635 (org-table-goto-column col
)
11636 ;not needed? (skip-chars-backward "^|")
11638 (goto-char (org-table-end))
11639 (unless (re-search-backward "^[ \t]*|[^-]" nil t
)
11640 (error "No table data"))
11641 (org-table-goto-column col
)
11642 ;not needed? (skip-chars-forward "^|")
11643 (setq end
(point))))
11644 (let* ((items (apply 'append
(org-table-copy-region beg end
)))
11645 (items1 (cond ((not nlast
) items
)
11646 ((>= nlast
(length items
)) items
)
11647 (t (setq items
(reverse items
))
11648 (setcdr (nthcdr (1- nlast
) items
) nil
)
11649 (nreverse items
))))
11650 (numbers (delq nil
(mapcar 'org-table-get-number-for-summing
11652 (res (apply '+ numbers
))
11653 (sres (if (= timecnt
0)
11655 (setq diff
(* 3600 res
)
11656 h
(floor (/ diff
3600)) diff
(mod diff
3600)
11657 m
(floor (/ diff
60)) diff
(mod diff
60)
11659 (format "%d:%02d:%02d" h m s
))))
11661 (if (interactive-p)
11663 (substitute-command-keys
11664 (format "Sum of %d items: %-20s (\\[yank] will insert result into buffer)"
11665 (length numbers
) sres
))))
11668 (defun org-table-get-number-for-summing (s)
11670 (if (string-match "^ *|? *" s
)
11671 (setq s
(replace-match "" nil nil s
)))
11672 (if (string-match " *|? *$" s
)
11673 (setq s
(replace-match "" nil nil s
)))
11674 (setq n
(string-to-number s
))
11676 ((and (string-match "0" s
)
11677 (string-match "\\`[-+ \t0.edED]+\\'" s
)) 0)
11678 ((string-match "\\`[ \t]+\\'" s
) nil
)
11679 ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?\\'" s
)
11680 (let ((h (string-to-number (or (match-string 1 s
) "0")))
11681 (m (string-to-number (or (match-string 2 s
) "0")))
11682 (s (string-to-number (or (match-string 4 s
) "0"))))
11683 (if (boundp 'timecnt
) (setq timecnt
(1+ timecnt
)))
11684 (* 1.0 (+ h
(/ m
60.0) (/ s
3600.0)))))
11688 (defun org-table-get-vertical-vector (desc &optional tbeg col
)
11689 "Get a calc vector from a column, accorting to descriptor DESC.
11690 Optional arguments TBEG and COL can give the beginning of the table and
11691 the current column, to avoid unnecessary parsing."
11693 (or tbeg
(setq tbeg
(org-table-begin)))
11694 (or col
(setq col
(org-table-current-column)))
11695 (let (beg end nn n n1 n2 l
(thisline (org-current-line)) hline-list
)
11697 ((string-match "\\(I+\\)\\(-\\(I+\\)\\)?" desc
)
11698 (setq n1
(- (match-end 1) (match-beginning 1)))
11699 (if (match-beginning 3)
11700 (setq n2
(- (match-end 2) (match-beginning 3))))
11701 (setq n
(if n2
(max n1 n2
) n1
))
11702 (setq n1
(if n2
(min n1 n2
)))
11704 (while (and (> nn
0)
11705 (re-search-backward org-table-hline-regexp tbeg t
))
11706 (push (org-current-line) hline-list
)
11708 (setq hline-list
(nreverse hline-list
))
11709 (goto-line (nth (1- n
) hline-list
))
11710 (when (re-search-forward org-table-dataline-regexp
)
11711 (org-table-goto-column col
)
11712 (setq beg
(point)))
11713 (goto-line (if n1
(nth (1- n1
) hline-list
) thisline
))
11714 (when (re-search-backward org-table-dataline-regexp
)
11715 (org-table-goto-column col
)
11716 (setq end
(point)))
11717 (setq l
(apply 'append
(org-table-copy-region beg end
)))
11718 (concat "[" (mapconcat (lambda (x) (setq x
(org-trim x
))
11719 (if (equal x
"") "0" x
))
11721 ((string-match "\\([0-9]+\\)-\\([0-9]+\\)" desc
)
11722 (setq n1
(string-to-number (match-string 1 desc
))
11723 n2
(string-to-number (match-string 2 desc
)))
11724 (beginning-of-line 1)
11726 (when (re-search-backward org-table-dataline-regexp tbeg t n1
)
11727 (org-table-goto-column col
)
11728 (setq beg
(point))))
11729 (when (re-search-backward org-table-dataline-regexp tbeg t n2
)
11730 (org-table-goto-column col
)
11731 (setq end
(point)))
11732 (setq l
(apply 'append
(org-table-copy-region beg end
)))
11733 (concat "[" (mapconcat
11734 (lambda (x) (setq x
(org-trim x
))
11735 (if (equal x
"") "0" x
))
11737 ((string-match "\\([0-9]+\\)" desc
)
11738 (beginning-of-line 1)
11739 (when (re-search-backward org-table-dataline-regexp tbeg t
11740 (string-to-number (match-string 0 desc
)))
11741 (org-table-goto-column col
)
11742 (org-trim (org-table-get-field))))))))
11744 (defvar org-table-formula-history nil
)
11746 (defvar org-table-column-names nil
11747 "Alist with column names, derived from the `!' line.")
11748 (defvar org-table-column-name-regexp nil
11749 "Regular expression matching the current column names.")
11750 (defvar org-table-local-parameters nil
11751 "Alist with parameter names, derived from the `$' line.")
11752 (defvar org-table-named-field-locations nil
11753 "Alist with locations of named fields.")
11755 (defun org-table-get-formula (&optional equation named
)
11756 "Read a formula from the minibuffer, offer stored formula as default."
11757 (let* ((name (car (rassoc (list (org-current-line)
11758 (org-table-current-column))
11759 org-table-named-field-locations
)))
11762 (error "Not in a named field"))
11763 (int-to-string (org-table-current-column))))
11764 (dummy (and name
(not named
)
11765 (not (y-or-n-p "Replace named-field formula with column equation? " ))
11767 (org-table-may-need-update nil
)
11768 (stored-list (org-table-get-stored-formulas))
11769 (stored (cdr (assoc scol stored-list
)))
11771 ((and stored equation
(string-match "^ *=? *$" equation
))
11773 ((stringp equation
)
11776 (format "%s formula $%s=" (if named
"Field" "Column") scol
)
11777 (or stored
"") 'org-table-formula-history
11781 (when (not (string-match "\\S-" eq
))
11783 (setq stored-list
(delq (assoc scol stored-list
) stored-list
))
11784 (org-table-store-formulas stored-list
)
11785 (error "Formula removed"))
11786 (if (string-match "^ *=?" eq
) (setq eq
(replace-match "" t t eq
)))
11787 (if (string-match " *$" eq
) (setq eq
(replace-match "" t t eq
)))
11788 (if (and name
(not named
))
11789 ;; We set the column equation, delete the named one.
11790 (setq stored-list
(delq (assoc name stored-list
) stored-list
)
11793 (setcdr (assoc scol stored-list
) eq
)
11794 (setq stored-list
(cons (cons scol eq
) stored-list
)))
11795 (if (or mustsave
(not (equal stored eq
)))
11796 (org-table-store-formulas stored-list
))
11799 (defun org-table-store-formulas (alist)
11800 "Store the list of formulas below the current table."
11801 (setq alist
(sort alist
(lambda (a b
) (string< (car a
) (car b
)))))
11803 (goto-char (org-table-end))
11804 (if (looking-at "\\([ \t]*\n\\)*#\\+TBLFM:.*\n?")
11805 (delete-region (point) (match-end 0)))
11806 (insert "#+TBLFM: "
11807 (mapconcat (lambda (x)
11808 (concat "$" (car x
) "=" (cdr x
)))
11812 (defun org-table-get-stored-formulas ()
11813 "Return an alist with the stored formulas directly after current table."
11815 (let (scol eq eq-alist strings string seen
)
11817 (goto-char (org-table-end))
11818 (when (looking-at "\\([ \t]*\n\\)*#\\+TBLFM: *\\(.*\\)")
11819 (setq strings
(org-split-string (match-string 2) " *:: *"))
11820 (while (setq string
(pop strings
))
11821 (when (string-match "\\$\\([a-zA-Z0-9]+\\) *= *\\(.*[^ \t]\\)" string
)
11822 (setq scol
(match-string 1 string
)
11823 eq
(match-string 2 string
)
11824 eq-alist
(cons (cons scol eq
) eq-alist
))
11825 (if (member scol seen
)
11826 (error "Double definition `$%s=' in TBLFM line, please fix by hand" scol
)
11827 (push scol seen
))))))
11828 (nreverse eq-alist
)))
11830 (defun org-table-modify-formulas (action &rest columns
)
11831 "Modify the formulas stored below the current table.
11832 ACTION can be `remove', `insert', `swap'. For `swap', two column numbers are
11833 expected, for the other actions only a single column number is needed."
11834 (let ((list (org-table-get-stored-formulas))
11835 (nmax (length (org-split-string
11836 (buffer-substring (point-at-bol) (point-at-eol))
11838 col col1 col2 scol si sc1 sc2
)
11840 ((null list
)) ; No action needed if there are no stored formulas
11841 ((eq action
'remove
)
11842 (setq col
(car columns
)
11843 scol
(int-to-string col
))
11844 (org-table-replace-in-formulas list scol
"INVALID")
11845 (if (assoc scol list
) (setq list
(delq (assoc scol list
) list
)))
11846 (loop for i from
(1+ col
) upto nmax by
1 do
11847 (setq si
(int-to-string i
))
11848 (org-table-replace-in-formulas list si
(int-to-string (1- i
)))
11849 (if (assoc si list
) (setcar (assoc si list
)
11850 (int-to-string (1- i
))))))
11851 ((eq action
'insert
)
11852 (setq col
(car columns
))
11853 (loop for i from nmax downto col by
1 do
11854 (setq si
(int-to-string i
))
11855 (org-table-replace-in-formulas list si
(int-to-string (1+ i
)))
11856 (if (assoc si list
) (setcar (assoc si list
)
11857 (int-to-string (1+ i
))))))
11859 (setq col1
(car columns
) col2
(nth 1 columns
)
11860 sc1
(int-to-string col1
) sc2
(int-to-string col2
))
11861 ;; Hopefully, ZqZtZ will never be a name in a table
11862 (org-table-replace-in-formulas list sc1
"ZqZtZ")
11863 (org-table-replace-in-formulas list sc2 sc1
)
11864 (org-table-replace-in-formulas list
"ZqZtZ" sc2
)
11865 (if (assoc sc1 list
) (setcar (assoc sc1 list
) "ZqZtZ"))
11866 (if (assoc sc2 list
) (setcar (assoc sc2 list
) sc1
))
11867 (if (assoc "ZqZtZ" list
) (setcar (assoc "ZqZtZ" list
) sc2
)))
11868 (t (error "Invalid action in `org-table-modify-formulas'")))
11869 (if list
(org-table-store-formulas list
))))
11871 (defun org-table-replace-in-formulas (list s1 s2
)
11873 (setq s1
(concat "$" (if (integerp s1
) (int-to-string s1
) s1
))
11874 s2
(concat "$" (if (integerp s2
) (int-to-string s2
) s2
))
11875 re
(concat (regexp-quote s1
) "\\>"))
11876 (while (setq elt
(pop list
))
11878 (while (string-match re s
)
11879 (setq s
(replace-match s2 t t s
)))
11882 (defun org-table-get-specials ()
11883 "Get the column names and local parameters for this table."
11885 (let ((beg (org-table-begin)) (end (org-table-end))
11886 names name fields fields1 field cnt c v line col
)
11887 (setq org-table-column-names nil
11888 org-table-local-parameters nil
11889 org-table-named-field-locations nil
)
11891 (when (re-search-forward "^[ \t]*| *! *\\(|.*\\)" end t
)
11892 (setq names
(org-split-string (match-string 1) " *| *")
11894 (while (setq name
(pop names
))
11895 (setq cnt
(1+ cnt
))
11896 (if (string-match "^[a-zA-Z][a-zA-Z0-9]*$" name
)
11897 (push (cons name
(int-to-string cnt
)) org-table-column-names
))))
11898 (setq org-table-column-names
(nreverse org-table-column-names
))
11899 (setq org-table-column-name-regexp
11900 (concat "\\$\\(" (mapconcat 'car org-table-column-names
"\\|") "\\)\\>"))
11902 (while (re-search-forward "^[ \t]*| *\\$ *\\(|.*\\)" end t
)
11903 (setq fields
(org-split-string (match-string 1) " *| *"))
11904 (while (setq field
(pop fields
))
11905 (if (string-match "^\\([a-zA-Z][a-zA-Z0-9]*\\|%\\) *= *\\(.*\\)" field
)
11906 (push (cons (match-string 1 field
) (match-string 2 field
))
11907 org-table-local-parameters
))))
11909 (while (re-search-forward "^[ \t]*| *\\([_^]\\) *\\(|.*\\)" end t
)
11910 (setq c
(match-string 1)
11911 fields
(org-split-string (match-string 2) " *| *"))
11913 (beginning-of-line (if (equal c
"_") 2 0))
11914 (setq line
(org-current-line) col
1)
11915 (and (looking-at "^[ \t]*|[^|]*\\(|.*\\)")
11916 (setq fields1
(org-split-string (match-string 1) " *| *"))))
11917 (while (and fields1
(setq field
(pop fields
)))
11918 (setq v
(pop fields1
) col
(1+ col
))
11919 (when (and (stringp field
) (stringp v
)
11920 (string-match "^[a-zA-Z][a-zA-Z0-9]*$" field
))
11921 (push (cons field v
) org-table-local-parameters
)
11922 (push (list field line col
) org-table-named-field-locations
)))))))
11924 (defun org-this-word ()
11925 ;; Get the current word
11927 (let ((beg (progn (skip-chars-backward "^ \t\n") (point)))
11928 (end (progn (skip-chars-forward "^ \t\n") (point))))
11929 (buffer-substring-no-properties beg end
))))
11931 (defun org-table-maybe-eval-formula ()
11932 "Check if the current field starts with \"=\" or \":=\".
11933 If yes, store the formula and apply it."
11934 ;; We already know we are in a table. Get field will only return a formula
11935 ;; when appropriate. It might return a separator line, but no problem.
11936 (when org-table-formula-evaluate-inline
11937 (let* ((field (org-trim (or (org-table-get-field) "")))
11939 (when (string-match "^:?=\\(.*\\)" field
)
11940 (setq named
(equal (string-to-char field
) ?
:)
11941 eq
(match-string 1 field
))
11942 (if (fboundp 'calc-eval
)
11943 (org-table-eval-formula (if named
'(4) nil
) eq
))))))
11945 (defvar org-recalc-commands nil
11946 "List of commands triggering the recalculation of a line.
11947 Will be filled automatically during use.")
11949 (defvar org-recalc-marks
11950 '((" " .
"Unmarked: no special line, no automatic recalculation")
11951 ("#" .
"Automatically recalculate this line upon TAB, RET, and C-c C-c in the line")
11952 ("*" .
"Recalculate only when entire table is recalculated with `C-u C-c *'")
11953 ("!" .
"Column name definition line. Reference in formula as $name.")
11954 ("$" .
"Parameter definition line name=value. Reference in formula as $name.")
11955 ("_" .
"Names for values in row below this one.")
11956 ("^" .
"Names for values in row above this one.")))
11958 (defun org-table-rotate-recalc-marks (&optional newchar
)
11959 "Rotate the recalculation mark in the first column.
11960 If in any row, the first field is not consistent with a mark,
11961 insert a new column for the markers.
11962 When there is an active region, change all the lines in the region,
11963 after prompting for the marking character.
11964 After each change, a message will be displayed indicating the meaning
11967 (unless (org-at-table-p) (error "Not at a table"))
11968 (let* ((marks (append (mapcar 'car org-recalc-marks
) '(" ")))
11969 (beg (org-table-begin))
11970 (end (org-table-end))
11971 (l (org-current-line))
11972 (l1 (if (org-region-active-p) (org-current-line (region-beginning))))
11973 (l2 (if (org-region-active-p) (org-current-line (region-end))))
11977 (not (re-search-forward "^[ \t]*|[^-|][^|]*[^#!$*_^| \t][^|]*|" end t
))))
11978 (col (org-table-current-column))
11979 (forcenew (car (assoc newchar org-recalc-marks
)))
11982 (message "Change region to what mark? Type # * ! $ or SPC: ")
11983 (setq newchar
(char-to-string (read-char-exclusive))
11984 forcenew
(car (assoc newchar org-recalc-marks
))))
11985 (if (and newchar
(not forcenew
))
11986 (error "Invalid NEWCHAR `%s' in `org-table-rotate-recalc-marks'"
11988 (if l1
(goto-line l1
))
11990 (beginning-of-line 1)
11991 (unless (looking-at org-table-dataline-regexp
)
11992 (error "Not at a table data line")))
11994 (org-table-goto-column 1)
11995 (org-table-insert-column)
11996 (org-table-goto-column (1+ col
)))
11997 (setq epos
(point-at-eol))
11999 (beginning-of-line 1)
12000 (org-table-get-field
12001 1 (if (looking-at "^[ \t]*| *\\([#!$*^_ ]\\) *|")
12003 (setq new
(or forcenew
12004 (cadr (member (match-string 1) marks
))))
12010 (while (progn (beginning-of-line 2) (not (= (org-current-line) l2
)))
12011 (and (looking-at org-table-dataline-regexp
)
12012 (org-table-get-field 1 (concat " " new
" "))))
12014 (if (not (= epos
(point-at-eol))) (org-table-align))
12016 (and (interactive-p) (message (cdr (assoc new org-recalc-marks
))))))
12018 (defun org-table-maybe-recalculate-line ()
12019 "Recompute the current line if marked for it, and if we haven't just done it."
12021 (and org-table-allow-automatic-line-recalculation
12022 (not (and (memq last-command org-recalc-commands
)
12023 (equal org-last-recalc-line
(org-current-line))))
12024 (save-excursion (beginning-of-line 1)
12025 (looking-at org-table-auto-recalculate-regexp
))
12026 (fboundp 'calc-eval
)
12027 (org-table-recalculate) t
))
12029 (defvar org-table-formula-debug nil
12030 "Non-nil means, debug table formulas.
12031 When nil, simply write \"#ERROR\" in corrupted fields.")
12034 (defsubst org-set-calc-mode
(var &optional value
)
12036 (setq var
(assoc var
'(("D" calc-angle-mode deg
)
12037 ("R" calc-angle-mode rad
)
12038 ("F" calc-prefer-frac t
)
12039 ("S" calc-symbolic-mode t
)))
12040 value
(nth 2 var
) var
(nth 1 var
)))
12041 (if (memq var modes
)
12042 (setcar (cdr (memq var modes
)) value
)
12043 (cons var
(cons value modes
)))
12046 (defun org-table-eval-formula (&optional arg equation
12047 suppress-align suppress-const
12049 "Replace the table field value at the cursor by the result of a calculation.
12051 This function makes use of Dave Gillespie's Calc package, in my view the
12052 most exciting program ever written for GNU Emacs. So you need to have Calc
12053 installed in order to use this function.
12055 In a table, this command replaces the value in the current field with the
12056 result of a formula. It also installs the formula as the \"current\" column
12057 formula, by storing it in a special line below the table. When called
12058 with a `C-u' prefix, the current field must ba a named field, and the
12059 formula is installed as valid in only this specific field.
12061 When called, the command first prompts for a formula, which is read in
12062 the minibuffer. Previously entered formulas are available through the
12063 history list, and the last used formula is offered as a default.
12064 These stored formulas are adapted correctly when moving, inserting, or
12065 deleting columns with the corresponding commands.
12067 The formula can be any algebraic expression understood by the Calc package.
12068 For details, see the Org-mode manual.
12070 This function can also be called from Lisp programs and offers
12071 additional arguments: EQUATION can be the formula to apply. If this
12072 argument is given, the user will not be prompted. SUPPRESS-ALIGN is
12073 used to speed-up recursive calls by by-passing unnecessary aligns.
12074 SUPPRESS-CONST suppresses the interpretation of constants in the
12075 formula, assuming that this has been done already outside the function.
12076 SUPPRESS-STORE means the formula should not be stored, either because
12077 it is already stored, or because it is a modified equation that should
12078 not overwrite the stored one."
12081 (org-table-check-inside-data-field)
12082 (org-table-get-specials)
12084 (ndown (if (integerp arg
) arg
1))
12085 (org-table-automatic-realign nil
)
12086 (case-fold-search nil
)
12088 (formula (if (and equation suppress-store
)
12090 (org-table-get-formula equation
(equal arg
'(4)))))
12091 (n0 (org-table-current-column))
12092 (modes (copy-sequence org-calc-default-modes
))
12093 n form fmt x ev orig c lispp
)
12094 ;; Parse the format string. Since we have a lot of modes, this is
12095 ;; a lot of work. However, I think calc still uses most of the time.
12096 (if (string-match ";" formula
)
12097 (let ((tmp (org-split-string formula
";")))
12098 (setq formula
(car tmp
)
12099 fmt
(concat (cdr (assoc "%" org-table-local-parameters
))
12101 (while (string-match "[pnfse]\\(-?[0-9]+\\)" fmt
)
12102 (setq c
(string-to-char (match-string 1 fmt
))
12103 n
(string-to-number (or (match-string 1 fmt
) "")))
12104 (if (= c ?p
) (setq modes
(org-set-calc-mode 'calc-internal-prec n
))
12105 (setq modes
(org-set-calc-mode
12107 (list (cdr (assoc c
'((?n . float
) (?f . fix
)
12108 (?s . sci
) (?e . eng
))))
12110 (setq fmt
(replace-match "" t t fmt
)))
12111 (while (string-match "[DRFS]" fmt
)
12112 (setq modes
(org-set-calc-mode (match-string 0 fmt
)))
12113 (setq fmt
(replace-match "" t t fmt
)))
12114 (unless (string-match "\\S-" fmt
)
12116 (if (and (not suppress-const
) org-table-formula-use-constants
)
12117 (setq formula
(org-table-formula-substitute-names formula
)))
12118 (setq orig
(or (get-text-property 1 :orig-formula formula
) "?"))
12120 (setq fields
(org-split-string
12122 (point-at-bol) (point-at-eol)) " *| *"))
12123 (if org-table-formula-numbers-only
12124 (setq fields
(mapcar
12125 (lambda (x) (number-to-string (string-to-number x
)))
12127 (setq ndown
(1- ndown
))
12128 (setq form
(copy-sequence formula
)
12129 lispp
(equal (substring form
0 2) "'("))
12130 ;; Insert the references to fields in same row
12131 (while (string-match "\\$\\([0-9]+\\)?" form
)
12132 (setq n
(if (match-beginning 1)
12133 (string-to-number (match-string 1 form
))
12135 x
(nth (1- n
) fields
))
12136 (unless x
(error "Invalid field specifier \"%s\""
12137 (match-string 0 form
)))
12138 (if (equal x
"") (setq x
"0"))
12139 (setq form
(replace-match
12140 (if lispp x
(concat "(" x
")"))
12142 ;; Insert ranges in current column
12143 (while (string-match "\\&[-I0-9]+" form
)
12144 (setq form
(replace-match
12146 (org-table-get-vertical-vector (match-string 0 form
)
12150 (setq ev
(eval (eval (read form
)))
12151 ev
(if (numberp ev
) (number-to-string ev
) ev
))
12152 (setq ev
(calc-eval (cons form modes
)
12153 (if org-table-formula-numbers-only
'num
))))
12155 (when org-table-formula-debug
12156 (with-output-to-temp-buffer "*Help*"
12157 (princ (format "Substitution history of formula
12160 $1-> %s\n" orig formula form
))
12162 (princ (format " %s^\nError: %s"
12163 (make-string (car ev
) ?\-
) (nth 1 ev
)))
12164 (princ (format "Result: %s\nFormat: %s\nFinal: %s"
12166 (if fmt
(format fmt
(string-to-number ev
)) ev
)))))
12167 (shrink-window-if-larger-than-buffer (get-buffer-window "*Help*"))
12168 (unless (and (interactive-p) (not ndown
))
12169 (unless (let (inhibit-redisplay)
12170 (y-or-n-p "Debugging Formula. Continue to next? "))
12173 (delete-window (get-buffer-window "*Help*"))
12175 (if (listp ev
) (setq fmt nil ev
"#ERROR"))
12176 (org-table-justify-field-maybe
12177 (if fmt
(format fmt
(string-to-number ev
)) ev
))
12178 (if (and down
(> ndown
0) (looking-at ".*\n[ \t]*|[^-]"))
12179 (call-interactively 'org-return
)
12181 (and down
(org-table-maybe-recalculate-line))
12182 (or suppress-align
(and org-table-may-need-update
12183 (org-table-align)))))
12185 (defun org-table-recalculate (&optional all noalign
)
12186 "Recalculate the current table line by applying all stored formulas.
12187 With prefix arg ALL, do this for all lines in the table."
12189 (or (memq this-command org-recalc-commands
)
12190 (setq org-recalc-commands
(cons this-command org-recalc-commands
)))
12191 (unless (org-at-table-p) (error "Not at a table"))
12192 (org-table-get-specials)
12193 (let* ((eqlist (sort (org-table-get-stored-formulas)
12194 (lambda (a b
) (string< (car a
) (car b
)))))
12195 (inhibit-redisplay t
)
12196 (line-re org-table-dataline-regexp
)
12197 (thisline (+ (if (bolp) 1 0) (count-lines (point-min) (point))))
12198 (thiscol (org-table-current-column))
12199 beg end entry eqlnum eqlname eql
(cnt 0) eq a name
)
12200 ;; Insert constants in all formulas
12202 (mapcar (lambda (x)
12203 (setcdr x
(org-table-formula-substitute-names (cdr x
)))
12206 ;; Split the equation list
12207 (while (setq eq
(pop eqlist
))
12208 (if (<= (string-to-char (car eq
)) ?
9)
12210 (push eq eqlname
)))
12211 (setq eqlnum
(nreverse eqlnum
) eqlname
(nreverse eqlname
))
12214 (setq end
(move-marker (make-marker) (1+ (org-table-end))))
12215 (goto-char (setq beg
(org-table-begin)))
12216 (if (re-search-forward org-table-calculate-mark-regexp end t
)
12217 ;; This is a table with marked lines, only compute selected lines
12218 (setq line-re org-table-recalculate-regexp
)
12219 ;; Move forward to the first non-header line
12220 (if (and (re-search-forward org-table-dataline-regexp end t
)
12221 (re-search-forward org-table-hline-regexp end t
)
12222 (re-search-forward org-table-dataline-regexp end t
))
12223 (setq beg
(match-beginning 0))
12224 nil
))) ;; just leave beg where it is
12225 (setq beg
(point-at-bol)
12226 end
(move-marker (make-marker) (1+ (point-at-eol)))))
12228 (and all
(message "Re-applying formulas to full table..."))
12229 (while (re-search-forward line-re end t
)
12230 (unless (string-match "^ *[_^!$] *$" (org-table-get-field 1))
12231 ;; Unprotected line, recalculate
12232 (and all
(message "Re-applying formulas to full table...(line %d)"
12233 (setq cnt
(1+ cnt
))))
12234 (setq org-last-recalc-line
(org-current-line))
12236 (while (setq entry
(pop eql
))
12237 (goto-line org-last-recalc-line
)
12238 (org-table-goto-column (string-to-number (car entry
)) nil
'force
)
12239 (org-table-eval-formula nil
(cdr entry
) 'noalign
'nocst
'nostore
))))
12240 (goto-line thisline
)
12241 (org-table-goto-column thiscol
)
12242 (or noalign
(and org-table-may-need-update
(org-table-align))
12243 (and all
(message "Re-applying formulas to %d lines...done" cnt
)))
12244 ;; Now do the names fields
12245 (while (setq eq
(pop eqlname
))
12246 (setq name
(car eq
)
12247 a
(assoc name org-table-named-field-locations
))
12249 (message "Re-applying formula to named field: %s" name
)
12250 (goto-line (nth 1 a
))
12251 (org-table-goto-column (nth 2 a
))
12252 (org-table-eval-formula nil
(cdr eq
) 'noalign
'nocst
'nostore
)))
12253 ;; back to initial position
12254 (goto-line thisline
)
12255 (org-table-goto-column thiscol
)
12256 (or noalign
(and org-table-may-need-update
(org-table-align))
12257 (and all
(message "Re-applying formulas...done")))))
12259 (defun org-table-formula-substitute-names (f)
12260 "Replace $const with values in string F."
12261 (let ((start 0) a n1 n2 nn1 nn2 s
(f1 f
))
12262 ;; First, check for column names
12263 (while (setq start
(string-match org-table-column-name-regexp f start
))
12264 (setq start
(1+ start
))
12265 (setq a
(assoc (match-string 1 f
) org-table-column-names
))
12266 (setq f
(replace-match (concat "$" (cdr a
)) t t f
)))
12267 ;; Expand ranges to vectors
12268 (while (string-match "\\$\\([0-9]+\\)\\.\\.\\.?\\$\\([0-9]+\\)" f
)
12269 (setq n1
(string-to-number (match-string 1 f
))
12270 n2
(string-to-number (match-string 2 f
))
12271 nn1
(1+ (min n1 n2
)) nn2
(max n1 n2
)
12272 s
(concat "[($" (number-to-string (1- nn1
)) ")"))
12273 (loop for i from nn1 upto nn2 do
12274 (setq s
(concat s
",($" (int-to-string i
) ")")))
12275 (setq s
(concat s
"]"))
12276 (if (< n2 n1
) (setq s
(concat "rev(" s
")")))
12277 (setq f
(replace-match s t t f
)))
12278 ;; Parameters and constants
12280 (while (setq start
(string-match "\\$\\([a-zA-Z][a-zA-Z0-9]*\\)" f start
))
12281 (setq start
(1+ start
))
12282 (if (setq a
(save-match-data
12283 (org-table-get-constant (match-string 1 f
))))
12284 (setq f
(replace-match (concat "(" a
")") t t f
))))
12285 (if org-table-formula-debug
12286 (put-text-property 0 (length f
) :orig-formula f1 f
))
12289 (defun org-table-get-constant (const)
12290 "Find the value for a parameter or constant in a formula.
12291 Parameters get priority."
12292 (or (cdr (assoc const org-table-local-parameters
))
12293 (cdr (assoc const org-table-formula-constants
))
12294 (and (fboundp 'constants-get
) (constants-get const
))
12295 "#UNDEFINED_NAME"))
12297 (defvar org-edit-formulas-map
(make-sparse-keymap))
12298 (define-key org-edit-formulas-map
"\C-c\C-c" 'org-finish-edit-formulas
)
12299 (define-key org-edit-formulas-map
"\C-c\C-q" 'org-abort-edit-formulas
)
12300 (define-key org-edit-formulas-map
"\C-c?" 'org-show-variable
)
12304 (defun org-table-edit-formulas ()
12305 "Edit the formulas of the current table in a separate buffer."
12307 (unless (org-at-table-p)
12308 (error "Not at a table"))
12309 (org-table-get-specials)
12310 (let ((eql (org-table-get-stored-formulas))
12311 (pos (move-marker (make-marker) (point)))
12312 (wc (current-window-configuration))
12314 (switch-to-buffer-other-window "*Edit Formulas*")
12317 (set (make-local-variable 'org-pos
) pos
)
12318 (set (make-local-variable 'org-window-configuration
) wc
)
12319 (use-local-map org-edit-formulas-map
)
12320 (setq s
"# Edit formulas and finish with `C-c C-c'.
12321 # Use `C-u C-c C-c' to also appy them immediately to the entire table.
12322 # Use `C-c ?' to get information about $name at point.
12323 # To cancel editing, press `C-c C-q'.\n")
12324 (put-text-property 0 (length s
) 'face
'font-lock-comment-face s
)
12326 (while (setq entry
(pop eql
))
12327 (when (setq loc
(assoc (car entry
) org-table-named-field-locations
))
12328 (setq s
(format "# Named formula, referring to column %d in line %d\n"
12329 (nth 2 loc
) (nth 1 loc
)))
12330 (put-text-property 0 (length s
) 'face
'font-lock-comment-face s
)
12332 (setq s
(concat "$" (car entry
) "=" (cdr entry
) "\n"))
12333 (remove-text-properties 0 (length s
) '(face nil
) s
)
12335 (goto-char (point-min))
12336 (message "Edit formulas and finish with `C-c C-c'.")))
12338 (defun org-show-variable ()
12339 "Show the location/value of the $ expression at point."
12341 (let (var (pos org-pos
) (win (selected-window)) e
)
12343 (or (looking-at "\\$") (skip-chars-backward "$a-zA-Z0-9"))
12344 (if (looking-at "\\$\\([a-zA-Z0-9]+\\)")
12345 (setq var
(match-string 1))
12346 (error "No variable at point")))
12348 ((setq e
(assoc var org-table-named-field-locations
))
12349 (switch-to-buffer-other-window (marker-buffer pos
))
12350 (goto-line (nth 1 e
))
12351 (org-table-goto-column (nth 2 e
))
12352 (select-window win
)
12353 (message "Named field, column %d of line %d" (nth 2 e
) (nth 1 e
)))
12354 ((setq e
(assoc var org-table-column-names
))
12355 (switch-to-buffer-other-window (marker-buffer pos
))
12357 (goto-char (org-table-begin))
12358 (if (re-search-forward (concat "^[ \t]*| *! *.*?| *\\(" var
"\\) *|")
12361 (goto-char (match-beginning 1))
12362 (message "Named column (column %s)" (cdr e
)))
12363 (error "Column name not found"))
12364 (select-window win
))
12365 ((string-match "^[0-9]$" var
)
12367 (switch-to-buffer-other-window (marker-buffer pos
))
12369 (goto-char (org-table-begin))
12371 (if (re-search-forward org-table-dataline-regexp
12374 (goto-char (match-beginning 0))
12375 (org-table-goto-column (string-to-number var
))
12376 (message "Column %s" var
))
12377 (error "Column name not found"))
12378 (select-window win
))
12379 ((setq e
(assoc var org-table-local-parameters
))
12380 (switch-to-buffer-other-window (marker-buffer pos
))
12382 (goto-char (org-table-begin))
12383 (if (re-search-forward (concat "^[ \t]*| *\\$ *.*?| *\\(" var
"=\\)") nil t
)
12385 (goto-char (match-beginning 1))
12386 (message "Local parameter."))
12387 (error "Parameter not found"))
12388 (select-window win
))
12391 ((setq e
(assoc var org-table-formula-constants
))
12392 (message "Constant: $%s=%s in `org-table-formula-constants'." var
(cdr e
)))
12393 ((setq e
(and (fboundp 'constants-get
) (constants-get var
)))
12394 (message "Constant: $%s=%s, retrieved from `constants.el'." var e
))
12395 (t (error "Undefined name $%s" var
)))))))
12397 (defun org-finish-edit-formulas (&optional arg
)
12398 "Parse the buffer for formula definitions and install them.
12399 With prefix ARG, apply the new formulas to the table."
12401 (let ((pos org-pos
) eql
)
12402 (goto-char (point-min))
12403 (while (re-search-forward "^\\$\\([a-zA-Z0-9]+\\) *= *\\(.*?\\) *$" nil t
)
12404 (push (cons (match-string 1) (match-string 2)) eql
))
12405 (set-window-configuration org-window-configuration
)
12406 (select-window (get-buffer-window (marker-buffer pos
)))
12408 (unless (org-at-table-p)
12409 (error "Lost table position - cannot install formulae"))
12410 (org-table-store-formulas eql
)
12411 (move-marker pos nil
)
12412 (kill-buffer "*Edit Formulas*")
12414 (org-table-recalculate 'all
)
12415 (message "New formulas installed - press C-u C-c C-c to apply."))))
12417 (defun org-abort-edit-formulas ()
12418 "Abort editing formulas, without installing the changes."
12420 (let ((pos org-pos
))
12421 (set-window-configuration org-window-configuration
)
12422 (select-window (get-buffer-window (marker-buffer pos
)))
12424 (message "Formula editing aborted without installing changes")))
12426 ;;; The orgtbl minor mode
12428 ;; Define a minor mode which can be used in other modes in order to
12429 ;; integrate the org-mode table editor.
12431 ;; This is really a hack, because the org-mode table editor uses several
12432 ;; keys which normally belong to the major mode, for example the TAB and
12433 ;; RET keys. Here is how it works: The minor mode defines all the keys
12434 ;; necessary to operate the table editor, but wraps the commands into a
12435 ;; function which tests if the cursor is currently inside a table. If that
12436 ;; is the case, the table editor command is executed. However, when any of
12437 ;; those keys is used outside a table, the function uses `key-binding' to
12438 ;; look up if the key has an associated command in another currently active
12439 ;; keymap (minor modes, major mode, global), and executes that command.
12440 ;; There might be problems if any of the keys used by the table editor is
12441 ;; otherwise used as a prefix key.
12443 ;; Another challenge is that the key binding for TAB can be tab or \C-i,
12444 ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode
12445 ;; addresses this by checking explicitly for both bindings.
12447 ;; The optimized version (see variable `orgtbl-optimized') takes over
12448 ;; all keys which are bound to `self-insert-command' in the *global map*.
12449 ;; Some modes bind other commands to simple characters, for example
12450 ;; AUCTeX binds the double quote to `Tex-insert-quote'. With orgtbl-mode
12451 ;; active, this binding is ignored inside tables and replaced with a
12452 ;; modified self-insert.
12454 (defvar orgtbl-mode nil
12455 "Variable controlling `orgtbl-mode', a minor mode enabling the `org-mode'
12456 table editor in arbitrary modes.")
12457 (make-variable-buffer-local 'orgtbl-mode
)
12459 (defvar orgtbl-mode-map
(make-keymap)
12460 "Keymap for `orgtbl-mode'.")
12463 (defun turn-on-orgtbl ()
12464 "Unconditionally turn on `orgtbl-mode'."
12468 (defun orgtbl-mode (&optional arg
)
12469 "The `org-mode' table editor as a minor mode for use in other modes."
12472 ;; Exit without error, in case some hook functions calls this
12473 ;; by accident in org-mode.
12474 (message "Orgtbl-mode is not useful in org-mode, command ignored")
12476 (if arg
(> (prefix-numeric-value arg
) 0) (not orgtbl-mode
)))
12479 (and (orgtbl-setup) (defun orgtbl-setup () nil
))
12480 ;; Make sure we are first in minor-mode-map-alist
12481 (let ((c (assq 'orgtbl-mode minor-mode-map-alist
)))
12482 (and c
(setq minor-mode-map-alist
12483 (cons c
(delq c minor-mode-map-alist
)))))
12484 (set (make-local-variable (quote org-table-may-need-update
)) t
)
12485 (org-add-hook 'before-change-functions
'org-before-change-function
12487 (set (make-local-variable 'org-old-auto-fill-inhibit-regexp
)
12488 auto-fill-inhibit-regexp
)
12489 (set (make-local-variable 'auto-fill-inhibit-regexp
)
12490 (if auto-fill-inhibit-regexp
12491 (concat "\\([ \t]*|\\|" auto-fill-inhibit-regexp
)
12493 (org-add-to-invisibility-spec '(org-cwidth))
12494 (easy-menu-add orgtbl-mode-menu
)
12495 (run-hooks 'orgtbl-mode-hook
))
12496 (setq auto-fill-inhibit-regexp org-old-auto-fill-inhibit-regexp
)
12497 (org-cleanup-narrow-column-properties)
12498 (org-remove-from-invisibility-spec '(org-cwidth))
12499 (remove-hook 'before-change-functions
'org-before-change-function t
)
12500 (easy-menu-remove orgtbl-mode-menu
)
12501 (force-mode-line-update 'all
))))
12503 (defun org-cleanup-narrow-column-properties ()
12504 "Remove all properties related to narrow-column invisibility."
12506 (while (setq s
(text-property-any s
(point-max)
12507 'display org-narrow-column-arrow
))
12508 (remove-text-properties s
(1+ s
) '(display t
)))
12510 (while (setq s
(text-property-any s
(point-max) 'org-cwidth
1))
12511 (remove-text-properties s
(1+ s
) '(org-cwidth t
)))
12513 (while (setq s
(text-property-any s
(point-max) 'invisible
'org-cwidth
))
12514 (remove-text-properties s
(1+ s
) '(invisible t
)))))
12516 ;; Install it as a minor mode.
12517 (put 'orgtbl-mode
:included t
)
12518 (put 'orgtbl-mode
:menu-tag
"Org Table Mode")
12519 (add-minor-mode 'orgtbl-mode
" OrgTbl" orgtbl-mode-map
)
12521 (defun orgtbl-make-binding (fun n
&rest keys
)
12522 "Create a function for binding in the table minor mode.
12523 FUN is the command to call inside a table. N is used to create a unique
12524 command name. KEYS are keys that should be checked in for a command
12525 to execute outside of tables."
12528 (intern (concat "orgtbl-hijacker-command-" (int-to-string n
)))
12530 (concat "In tables, run `" (symbol-name fun
) "'.\n"
12531 "Outside of tables, run the binding of `"
12532 (mapconcat (lambda (x) (format "%s" x
)) keys
"' or `")
12537 (list 'call-interactively
(list 'quote fun
))
12538 (list 'let
'(orgtbl-mode)
12539 (list 'call-interactively
12541 (mapcar (lambda (k)
12542 (list 'key-binding k
))
12544 '('orgtbl-error
))))))))
12546 (defun orgtbl-error ()
12547 "Error when there is no default binding for a table key."
12549 (error "This key is has no function outside tables"))
12551 (defun orgtbl-setup ()
12552 "Setup orgtbl keymaps."
12556 '([(meta shift left
)] org-table-delete-column
)
12557 '([(meta left
)] org-table-move-column-left
)
12558 '([(meta right
)] org-table-move-column-right
)
12559 '([(meta shift right
)] org-table-insert-column
)
12560 '([(meta shift up
)] org-table-kill-row
)
12561 '([(meta shift down
)] org-table-insert-row
)
12562 '([(meta up
)] org-table-move-row-up
)
12563 '([(meta down
)] org-table-move-row-down
)
12564 '("\C-c\C-w" org-table-cut-region
)
12565 '("\C-c\M-w" org-table-copy-region
)
12566 '("\C-c\C-y" org-table-paste-rectangle
)
12567 '("\C-c-" org-table-insert-hline
)
12568 ; '([(shift tab)] org-table-previous-field)
12569 '("\C-m" org-table-next-row
)
12570 (list (org-key 'S-return
) 'org-table-copy-down
)
12571 '([(meta return
)] org-table-wrap-region
)
12572 '("\C-c\C-q" org-table-wrap-region
)
12573 '("\C-c?" org-table-current-column
)
12574 '("\C-c " org-table-blank-field
)
12575 '("\C-c+" org-table-sum
)
12576 '("\C-c=" org-table-eval-formula
)
12577 '("\C-c'" org-table-edit-formulas
)
12578 '("\C-c`" org-table-edit-field
)
12579 '("\C-c*" org-table-recalculate
)
12580 '("\C-c|" org-table-create-or-convert-from-region
)
12581 '("\C-c^" org-table-sort-lines
)
12582 '([(control ?
#)] org-table-rotate-recalc-marks
)))
12584 (while (setq elt
(pop bindings
))
12585 (setq nfunc
(1+ nfunc
))
12586 (setq key
(car elt
)
12588 cmd
(orgtbl-make-binding fun nfunc key
))
12589 (define-key orgtbl-mode-map key cmd
))
12590 ;; Special treatment needed for TAB and RET
12591 (define-key orgtbl-mode-map
[(return)]
12592 (orgtbl-make-binding 'orgtbl-ret
100 [(return)] "\C-m"))
12593 (define-key orgtbl-mode-map
"\C-m"
12594 (orgtbl-make-binding 'orgtbl-ret
101 "\C-m" [(return)]))
12595 (define-key orgtbl-mode-map
[(tab)]
12596 (orgtbl-make-binding 'orgtbl-tab
102 [(tab)] "\C-i"))
12597 (define-key orgtbl-mode-map
"\C-i"
12598 (orgtbl-make-binding 'orgtbl-tab
103 "\C-i" [(tab)])))
12599 (define-key orgtbl-mode-map
"\C-i"
12600 (orgtbl-make-binding 'orgtbl-tab
104 [(shift tab
)]))
12601 (define-key orgtbl-mode-map
"\C-c\C-c"
12602 (orgtbl-make-binding 'org-ctrl-c-ctrl-c
105 "\C-c\C-c"))
12603 (when orgtbl-optimized
12604 ;; If the user wants maximum table support, we need to hijack
12605 ;; some standard editing functions
12606 (org-remap orgtbl-mode-map
12607 'self-insert-command
'orgtbl-self-insert-command
12608 'delete-char
'org-delete-char
12609 'delete-backward-char
'org-delete-backward-char
)
12610 (define-key orgtbl-mode-map
"|" 'org-force-self-insert
))
12611 (easy-menu-define orgtbl-mode-menu orgtbl-mode-map
"OrgTbl menu"
12613 ["Align" org-ctrl-c-ctrl-c
:active
(org-at-table-p) :keys
"C-c C-c"]
12614 ["Next Field" org-cycle
:active
(org-at-table-p) :keys
"TAB"]
12615 ["Previous Field" org-shifttab
:active
(org-at-table-p) :keys
"S-TAB"]
12616 ["Next Row" org-return
:active
(org-at-table-p) :keys
"RET"]
12618 ["Blank Field" org-table-blank-field
:active
(org-at-table-p) :keys
"C-c SPC"]
12619 ["Edit Field" org-table-edit-field
:active
(org-at-table-p) :keys
"C-c ` "]
12620 ["Copy Field from Above"
12621 org-table-copy-down
:active
(org-at-table-p) :keys
"S-RET"]
12624 ["Move Column Left" org-metaleft
:active
(org-at-table-p) :keys
"M-<left>"]
12625 ["Move Column Right" org-metaright
:active
(org-at-table-p) :keys
"M-<right>"]
12626 ["Delete Column" org-shiftmetaleft
:active
(org-at-table-p) :keys
"M-S-<left>"]
12627 ["Insert Column" org-shiftmetaright
:active
(org-at-table-p) :keys
"M-S-<right>"]
12629 ["Enable Narrowing" (setq org-table-limit-column-width
(not org-table-limit-column-width
)) :active
(org-at-table-p) :selected org-table-limit-column-width
:style toggle
])
12631 ["Move Row Up" org-metaup
:active
(org-at-table-p) :keys
"M-<up>"]
12632 ["Move Row Down" org-metadown
:active
(org-at-table-p) :keys
"M-<down>"]
12633 ["Delete Row" org-shiftmetaup
:active
(org-at-table-p) :keys
"M-S-<up>"]
12634 ["Insert Row" org-shiftmetadown
:active
(org-at-table-p) :keys
"M-S-<down>"]
12635 ["Sort lines in region" org-table-sort-lines
(org-at-table-p) :keys
"C-c ^"]
12637 ["Insert Hline" org-table-insert-hline
:active
(org-at-table-p) :keys
"C-c -"])
12639 ["Copy Rectangle" org-copy-special
:active
(org-at-table-p)]
12640 ["Cut Rectangle" org-cut-special
:active
(org-at-table-p)]
12641 ["Paste Rectangle" org-paste-special
:active
(org-at-table-p)]
12642 ["Fill Rectangle" org-table-wrap-region
:active
(org-at-table-p)])
12644 ["Set Column Formula" org-table-eval-formula
:active
(org-at-table-p) :keys
"C-c ="]
12645 ["Set Named Field Formula" (org-table-eval-formula '(4)) :active
(org-at-table-p) :keys
"C-u C-c ="]
12646 ["Edit Formulas" org-table-edit-formulas
:active
(org-at-table-p) :keys
"C-c '"]
12647 ["Recalculate line" org-table-recalculate
:active
(org-at-table-p) :keys
"C-c *"]
12648 ["Recalculate all" (org-table-recalculate '(4)) :active
(org-at-table-p) :keys
"C-u C-c *"]
12649 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks
:active
(org-at-table-p) :keys
"C-c #"]
12650 ["Sum Column/Rectangle" org-table-sum
12651 :active
(or (org-at-table-p) (org-region-active-p)) :keys
"C-c +"]
12652 ["Which Column?" org-table-current-column
:active
(org-at-table-p) :keys
"C-c ?"]
12654 (setq org-table-formula-debug
(not org-table-formula-debug
))
12655 :style toggle
:selected org-table-formula-debug
]
12659 (defun orgtbl-tab (arg)
12660 "Justification and field motion for `orgtbl-mode'."
12662 (if arg
(org-table-edit-field t
)
12663 (org-table-justify-field-maybe)
12664 (org-table-next-field)))
12666 (defun orgtbl-ret ()
12667 "Justification and field motion for `orgtbl-mode'."
12669 (org-table-justify-field-maybe)
12670 (org-table-next-row))
12672 (defun orgtbl-self-insert-command (N)
12673 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
12674 If the cursor is in a table looking at whitespace, the whitespace is
12675 overwritten, and the table is not marked as requiring realignment."
12677 (if (and (org-at-table-p)
12679 (and org-table-auto-blank-field
12680 (member last-command
12681 '(orgtbl-hijacker-command-100
12682 orgtbl-hijacker-command-101
12683 orgtbl-hijacker-command-102
12684 orgtbl-hijacker-command-103
12685 orgtbl-hijacker-command-104
12686 orgtbl-hijacker-command-105
))
12687 (org-table-blank-field))
12690 (looking-at "[^|\n]* +|"))
12691 (let (org-table-may-need-update)
12692 (goto-char (1- (match-end 0)))
12693 (delete-backward-char 1)
12694 (goto-char (match-beginning 0))
12695 (self-insert-command N
))
12696 (setq org-table-may-need-update t
)
12698 (call-interactively (key-binding (vector last-input-event
))))))
12700 (defun org-force-self-insert (N)
12701 "Needed to enforce self-insert under remapping."
12703 (self-insert-command N
))
12707 (defconst org-level-max
20)
12709 (defvar org-export-html-preamble nil
12710 "Preamble, to be inserted just after <body>. Set by publishing functions.")
12711 (defvar org-export-html-postamble nil
12712 "Preamble, to be inserted just before </body>. Set by publishing functions.")
12713 (defvar org-export-html-auto-preamble t
12714 "Should default preamble be inserted? Set by publishing functions.")
12715 (defvar org-export-html-auto-postamble t
12716 "Should default postamble be inserted? Set by publishing functions.")
12718 (defconst org-export-plist-vars
12719 '((:language . org-export-default-language
)
12720 (:headline-levels . org-export-headline-levels
)
12721 (:section-numbers . org-export-with-section-numbers
)
12722 (:table-of-contents . org-export-with-toc
)
12723 (:archived-trees . org-export-with-archived-trees
)
12724 (:emphasize . org-export-with-emphasize
)
12725 (:sub-superscript . org-export-with-sub-superscripts
)
12726 (:TeX-macros . org-export-with-TeX-macros
)
12727 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
12728 (:fixed-width . org-export-with-fixed-width
)
12729 (:timestamps . org-export-with-timestamps
)
12730 (:tables . org-export-with-tables
)
12731 (:table-auto-headline . org-export-highlight-first-table-line
)
12732 (:style . org-export-html-style
)
12733 (:convert-org-links . org-export-html-link-org-files-as-html
)
12734 (:inline-images . org-export-html-inline-images
)
12735 (:expand-quoted-html . org-export-html-expand
)
12736 (:timestamp . org-export-html-with-timestamp
)
12737 (:publishing-directory . org-export-publishing-directory
)
12738 (:preamble . org-export-html-preamble
)
12739 (:postamble . org-export-html-postamble
)
12740 (:auto-preamble . org-export-html-auto-preamble
)
12741 (:auto-postamble . org-export-html-auto-postamble
)
12742 (:author . user-full-name
)
12743 (:email . user-mail-address
)))
12745 (defun org-default-export-plist ()
12746 "Return the property list with default settings for the export variables."
12747 (let ((l org-export-plist-vars
) rtn e
)
12748 (while (setq e
(pop l
))
12749 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
12752 (defun org-infile-export-plist ()
12753 "Return the property list with file-local settings for export."
12756 (let ((re (org-make-options-regexp
12757 '("TITLE" "AUTHOR" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE")))
12758 p key val text options
)
12759 (while (re-search-forward re nil t
)
12760 (setq key
(org-match-string-no-properties 1)
12761 val
(org-match-string-no-properties 2))
12763 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
12764 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
12765 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
12766 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
12767 ((string-equal key
"TEXT")
12768 (setq text
(if text
(concat text
"\n" val
) val
)))
12769 ((string-equal key
"OPTIONS") (setq options val
))))
12770 (setq p
(plist-put p
:text text
))
12772 (let ((op '(("H" .
:headline-levels
)
12773 ("num" .
:section-numbers
)
12774 ("toc" .
:table-of-contents
)
12775 ("\\n" .
:preserve-breaks
)
12776 ("@" .
:expand-quoted-html
)
12777 (":" .
:fixed-width
)
12779 ("^" .
:sub-superscript
)
12781 ("TeX" .
:TeX-macros
)
12782 ("LaTeX" .
:LaTeX-fragments
)))
12784 (while (setq o
(pop op
))
12785 (if (string-match (concat (regexp-quote (car o
))
12786 ":\\([^ \t\n\r;,.]*\\)")
12788 (setq p
(plist-put p
(cdr o
)
12789 (car (read-from-string
12790 (match-string 1 options
)))))))))
12793 (defun org-combine-plists (&rest plists
)
12794 "Create a single property list from all plists in PLISTS.
12795 The process starts by copying the last list, and then setting properties
12796 from the other lists. Settings in the first list are the most significant
12797 ones and overrule settings in the other lists."
12798 (let ((rtn (copy-sequence (pop plists
)))
12801 (setq ls
(pop plists
))
12803 (setq p
(pop ls
) v
(pop ls
))
12804 (setq rtn
(plist-put rtn p v
))))
12807 (defun org-export-directory (type plist
)
12808 (let* ((val (plist-get plist
:publishing-directory
))
12809 (dir (if (listp val
)
12810 (or (cdr (assoc type val
)) ".")
12814 (defun org-export-find-first-heading-line (list)
12815 "Remove all lines from LIST which are before the first headline."
12816 (let ((orig-list list
)
12817 (re (concat "^" outline-regexp
)))
12819 (not (string-match re
(car list
))))
12821 (or list orig-list
)))
12823 (defun org-skip-comments (lines)
12824 "Skip lines starting with \"#\" and subtrees starting with COMMENT."
12825 (let ((re1 (concat "^\\(\\*+\\)[ \t]+" org-comment-string
))
12826 (re2 "^\\(\\*+\\)[ \t\n\r]")
12828 (while (setq line
(pop lines
))
12830 ((and (string-match re1 line
)
12831 (setq level
(- (match-end 1) (match-beginning 1))))
12832 ;; Beginning of a COMMENT subtree. Skip it.
12833 (while (and (setq line
(pop lines
))
12834 (or (not (string-match re2 line
))
12835 (> (- (match-end 1) (match-beginning 1)) level
))))
12836 (setq lines
(cons line lines
)))
12837 ((string-match "^#" line
)
12838 ;; an ordinary comment line
12840 ((and org-export-table-remove-special-lines
12841 (string-match "^[ \t]*|" line
)
12842 (or (string-match "^[ \t]*| *[!_^] *|" line
)
12843 (and (string-match "| *<[0-9]+> *|" line
)
12844 (not (string-match "| *[^ <|]" line
)))))
12845 ;; a special table line that should be removed
12847 (t (setq rtn
(cons line rtn
)))))
12850 (defun org-export (&optional arg
)
12852 (let ((help "[t] insert the export option template
12853 \[v] limit export to visible part of outline tree
12855 \[a] export as ASCII
12856 \[h] export as HTML
12857 \[b] export as HTML and browse immediately
12858 \[x] export as XOXO
12860 \[i] export current file as iCalendar file
12861 \[I] export all agenda files as iCalendar files
12862 \[c] export agenda files into combined iCalendar file
12864 \[F] publish current file
12865 \[P] publish current project
12866 \[X] publish... (project will be prompted for)
12867 \[A] publish all projects")
12869 '((?t . org-insert-export-options-template
)
12870 (?v . org-export-visible
)
12871 (?a . org-export-as-ascii
)
12872 (?h . org-export-as-html
)
12873 (?b . org-export-as-html-and-open
)
12874 (?x . org-export-as-xoxo
)
12875 (?i . org-export-icalendar-this-file
)
12876 (?I . org-export-icalendar-all-agenda-files
)
12877 (?c . org-export-icalendar-combine-agenda-files
)
12878 (?F . org-publish-current-file
)
12879 (?P . org-publish-current-project
)
12881 (?A . org-publish-all
)))
12883 (save-window-excursion
12884 (delete-other-windows)
12885 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
12887 (message "Select command: ")
12888 (setq r1
(read-char-exclusive)))
12889 (setq r2
(if (< r1
27) (+ r1
96) r1
))
12890 (if (setq ass
(assq r2 cmds
))
12891 (call-interactively (cdr ass
))
12892 (error "No command associated with key %c" r1
))))
12896 (defconst org-html-entities
12936 ("Aring") ("AA".
"Å")
13025 ("varepsilon".
"ε")
13038 ("sigmaf") ("varsigma".
"ς")
13046 ("thetasym") ("vartheta".
"ϑ")
13049 ("bull") ("bullet".
"•")
13050 ("hellip") ("dots".
"…")
13060 ("larr") ("leftarrow".
"←") ("gets".
"←")
13061 ("uarr") ("uparrow".
"↑")
13062 ("rarr") ("to".
"→") ("rightarrow".
"→")
13063 ("darr")("downarrow".
"↓")
13064 ("harr") ("leftrightarrow".
"↔")
13065 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
13066 ("lArr") ("Leftarrow".
"⇐")
13067 ("uArr") ("Uparrow".
"⇑")
13068 ("rArr") ("Rightarrow".
"⇒")
13069 ("dArr") ("Downarrow".
"⇓")
13070 ("hArr") ("Leftrightarrow".
"⇔")
13072 ("part") ("partial".
"∂")
13073 ("exist") ("exists".
"∃")
13074 ("empty") ("emptyset".
"∅")
13076 ("isin") ("in".
"∈")
13082 ("lowast") ("ast".
"∗")
13084 ("prop") ("proptp".
"∝")
13085 ("infin") ("infty".
"∞")
13086 ("ang") ("angle".
"∠")
13087 ("and") ("vee".
"∧")
13088 ("or") ("wedge".
"∨")
13094 ("cong") ("simeq".
"≅")
13095 ("asymp")("approx".
"≈")
13096 ("ne") ("neq".
"≠")
13100 ("sub") ("subset".
"⊂")
13101 ("sup") ("supset".
"⊃")
13108 ("sdot") ("cdot".
"⋅")
13115 ("loz") ("Diamond".
"◊")
13116 ("spades") ("spadesuit".
"♠")
13117 ("clubs") ("clubsuit".
"♣")
13118 ("hearts") ("diamondsuit".
"♥")
13119 ("diams") ("diamondsuit".
"♦")
13153 ("arccos".
"arccos")
13154 ("arcsin".
"arcsin")
13155 ("arctan".
"arctan")
13172 ("liminf".
"liminf")
13173 ("limsup".
"limsup")
13186 "Entities for TeX->HTML translation.
13187 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
13188 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
13189 In that case, \"\\ent\" will be translated to \"&other;\".
13190 The list contains HTML entities for Latin-1, Greek and other symbols.
13191 It is supplemented by a number of commonly used TeX macros with appropriate
13192 translations. There is currently no way for users to extend this.")
13194 (defun org-cleaned-string-for-export (string &rest parameters
)
13195 "Cleanup a buffer substring so that links can be created safely."
13197 (let* ((re-radio (and org-target-link-regexp
13198 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
13199 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
13200 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
13201 (re-archive (concat ":" org-archive-tag
":"))
13204 (set-buffer (get-buffer-create " org-mode-tmp"))
13207 (let ((org-inhibit-startup t
)) (org-mode))
13209 ;; Get rid of archived trees
13210 (when (not (eq org-export-with-archived-trees t
))
13211 (goto-char (point-min))
13212 (while (re-search-forward re-archive nil t
)
13213 (if (not (org-on-heading-p))
13214 (org-end-of-subtree t
)
13215 (beginning-of-line 1)
13217 (if org-export-with-archived-trees
(1+ (point-at-eol)) (point))
13218 (org-end-of-subtree)))))
13220 ;; Find targets in comments and move them out of comments,
13221 ;; but mark them as targets that should be invisible
13222 (goto-char (point-min))
13223 (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t
)
13224 (replace-match "\\1(INVISIBLE)"))
13226 ;; Find matches for radio targets and turn them into internal links
13227 (goto-char (point-min))
13229 (while (re-search-forward re-radio nil t
)
13230 (replace-match "\\1[[\\2]]")))
13232 ;; Find all links that contain a newline and put them into a single line
13233 (goto-char (point-min))
13234 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
13235 (replace-match "\\1 \\3")
13236 (goto-char (match-beginning 0)))
13238 ;; Convert LaTeX fragments to images
13239 (when (memq :LaTeX-fragments parameters
)
13241 (concat "ltxpng/" (file-name-sans-extension
13242 (file-name-nondirectory
13243 org-current-export-file
)))
13244 org-current-export-dir nil
"Creating LaTeX image %s"))
13245 (message "Exporting...")
13247 ;; Normalize links: Convert angle and plain links into bracket links
13248 (goto-char (point-min))
13249 (while (re-search-forward re-plain-link nil t
)
13252 (match-string 1) "[[" (match-string 2) ":" (match-string 3) "]]")
13254 (goto-char (point-min))
13255 (while (re-search-forward re-angle-link nil t
)
13258 (match-string 1) "[[" (match-string 2) ":" (match-string 3) "]]")
13261 ;; Find multiline emphasis and put them into single line
13262 (when (memq :emph-multiline parameters
)
13263 (goto-char (point-min))
13264 (while (re-search-forward org-emph-re nil t
)
13265 (subst-char-in-region (match-beginning 0) (match-end 0) ?
\n ?\ t
)
13266 (goto-char (1- (match-end 0)))))
13269 (goto-char (point-min))
13270 (while (re-search-forward "^#.*\n?" nil t
)
13271 (replace-match ""))
13272 (setq rtn
(buffer-string)))
13273 (kill-buffer " org-mode-tmp")
13276 (defun org-solidify-link-text (s &optional alist
)
13277 "Take link text and make a safe target out of it."
13282 (org-split-string s
"[ \t\r\n]+") "--"))
13283 (a (assoc rtn alist
)))
13284 (or (cdr a
) rtn
))))
13286 (defun org-convert-to-odd-levels ()
13287 "Convert an org-mode file with all levels allowed to one with odd levels.
13288 This will leave level 1 alone, convert level 2 to level 3, level 3 to
13291 (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ")
13292 (let ((org-odd-levels-only nil
) n
)
13294 (goto-char (point-min))
13295 (while (re-search-forward "^\\*\\*+" nil t
)
13296 (setq n
(1- (length (match-string 0))))
13297 (while (>= (setq n
(1- n
)) 0)
13299 (end-of-line 1))))))
13302 (defun org-convert-to-oddeven-levels ()
13303 "Convert an org-mode file with only odd levels to one with odd and even levels.
13304 This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a
13305 section with an even level, conversion would destroy the structure of the file. An error
13306 is signaled in this case."
13308 (goto-char (point-min))
13309 ;; First check if there are no even levels
13310 (when (re-search-forward "^\\(\\*\\*\\)+[^*]" nil t
)
13311 (org-show-hierarchy-above)
13312 (error "Not all levels are odd in this file. Conversion not possible."))
13313 (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ")
13314 (let ((org-odd-levels-only nil
) n
)
13316 (goto-char (point-min))
13317 (while (re-search-forward "^\\*\\*+" nil t
)
13318 (setq n
(/ (length (match-string 0)) 2))
13319 (while (>= (setq n
(1- n
)) 0)
13321 (end-of-line 1))))))
13323 (defun org-tr-level (n)
13324 "Make N odd if required."
13325 (if org-odd-levels-only
(1+ (/ n
2)) n
))
13327 (defvar org-last-level nil
) ; dynamically scoped variable
13328 (defvar org-ascii-current-indentation nil
) ; For communication
13330 (defun org-export-as-ascii (arg)
13331 "Export the outline as a pretty ASCII file.
13332 If there is an active region, export only the region.
13333 The prefix ARG specifies how many levels of the outline should become
13334 underlined headlines. The default is 3."
13336 (setq-default org-todo-line-regexp org-todo-line-regexp
)
13337 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
13338 (org-infile-export-plist)))
13341 (if (org-region-active-p) (region-beginning) (point-min))
13342 (if (org-region-active-p) (region-end) (point-max))))
13343 (lines (org-export-find-first-heading-line
13346 (org-cleaned-string-for-export region
)
13348 (org-ascii-current-indentation '(0 .
0))
13349 (org-startup-with-deadline-check nil
)
13352 (case-fold-search nil
)
13353 (filename (concat (file-name-as-directory
13354 (org-export-directory :ascii opt-plist
))
13355 (file-name-sans-extension
13356 (file-name-nondirectory buffer-file-name
))
13358 (buffer (find-file-noselect filename
))
13359 (levels-open (make-vector org-level-max nil
))
13360 (odd org-odd-levels-only
)
13361 (date (format-time-string "%Y/%m/%d" (current-time)))
13362 (time (format-time-string "%X" (org-current-time)))
13363 (author (plist-get opt-plist
:author
))
13364 (title (or (plist-get opt-plist
:title
)
13365 (file-name-sans-extension
13366 (file-name-nondirectory buffer-file-name
))))
13367 (email (plist-get opt-plist
:email
))
13368 (language (plist-get opt-plist
:language
))
13373 (setq org-last-level
1)
13374 (org-init-section-numbers)
13376 (find-file-noselect filename
)
13378 (setq lang-words
(or (assoc language org-export-language-setup
)
13379 (assoc "en" org-export-language-setup
)))
13380 (if org-export-ascii-show-new-buffer
13381 (switch-to-buffer-other-window buffer
)
13382 (set-buffer buffer
))
13385 ;; create local variables for all options, to make sure all called
13386 ;; functions get the correct information
13387 (mapcar (lambda (x)
13388 (set (make-local-variable (cdr x
))
13389 (plist-get opt-plist
(car x
))))
13390 org-export-plist-vars
)
13391 (set (make-local-variable 'org-odd-levels-only
) odd
)
13392 (setq umax
(if arg
(prefix-numeric-value arg
)
13393 org-export-headline-levels
))
13396 (if title
(org-insert-centered title ?
=))
13398 (if (or author email
)
13399 (insert (concat (nth 1 lang-words
) ": " (or author
"")
13400 (if email
(concat " <" email
">") "")
13402 (if (and date time
)
13403 (insert (concat (nth 2 lang-words
) ": " date
" " time
"\n")))
13404 (if text
(insert (concat (org-html-expand-for-ascii text
) "\n\n")))
13408 (if org-export-with-toc
13410 (insert (nth 3 lang-words
) "\n"
13411 (make-string (length (nth 3 lang-words
)) ?
=) "\n")
13412 (mapcar '(lambda (line)
13413 (if (string-match org-todo-line-regexp
13415 ;; This is a headline
13417 (setq level
(- (match-end 1) (match-beginning 1))
13418 level
(org-tr-level level
)
13419 txt
(match-string 3 line
)
13421 (or (and org-export-mark-todo-in-toc
13422 (match-beginning 2)
13423 (not (equal (match-string 2 line
)
13426 (and org-export-mark-todo-in-toc
13428 (org-search-todo-below
13429 line lines level
))))
13430 (setq txt
(org-html-expand-for-ascii txt
))
13432 (if org-export-with-section-numbers
13433 (setq txt
(concat (org-section-number level
)
13435 (if (<= level umax
)
13438 (make-string (* (1- level
) 4) ?\
)
13439 (format (if todo
"%s (*)\n" "%s\n") txt
))
13440 (setq org-last-level level
))
13444 (org-init-section-numbers)
13445 (while (setq line
(pop lines
))
13446 ;; Remove the quoted HTML tags.
13447 (setq line
(org-html-expand-for-ascii line
))
13449 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
13450 (setq line
(replace-match "" t t line
)))
13451 ;; Replace internal links
13452 (while (string-match org-bracket-link-regexp line
)
13453 (setq line
(replace-match
13454 (if (match-end 3) "[\\3]" "[\\1]")
13457 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line
)
13459 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
13460 txt
(match-string 2 line
))
13461 (org-ascii-level-start level txt umax lines
))
13463 (insert (org-fix-indentation line org-ascii-current-indentation
) "\n"))))
13466 ;; remove display and invisible chars
13468 (goto-char (point-min))
13469 (while (setq beg
(next-single-property-change (point) 'display
))
13470 (setq end
(next-single-property-change beg
'display
))
13471 (delete-region beg end
)
13474 (goto-char (point-min))
13475 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
13476 (setq end
(next-single-property-change beg
'org-cwidth
))
13477 (delete-region beg end
)
13479 (goto-char (point-min))))
13481 (defun org-search-todo-below (line lines level
)
13482 "Search the subtree below LINE for any TODO entries."
13483 (let ((rest (cdr (memq line lines
)))
13484 (re org-todo-line-regexp
)
13487 (while (setq line
(pop rest
))
13488 (if (string-match re line
)
13490 (setq lv
(- (match-end 1) (match-beginning 1))
13491 todo
(and (match-beginning 2)
13492 (not (equal (match-string 2 line
)
13493 org-done-string
))))
13495 (if (<= lv level
) (throw 'exit nil
))
13496 (if todo
(throw 'exit t
))))))))
13498 (defun org-html-expand-for-ascii (line)
13499 "Handle quoted HTML for ASCII export."
13500 (if org-export-html-expand
13501 (while (string-match "@<[^<>\n]*>" line
)
13502 ;; We just remove the tags for now.
13503 (setq line
(replace-match "" nil nil line
))))
13506 (defun org-insert-centered (s &optional underline
)
13507 "Insert the string S centered and underline it with character UNDERLINE."
13508 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
13509 (insert (make-string ind ?\
) s
"\n")
13511 (insert (make-string ind ?\
)
13512 (make-string (string-width s
) underline
)
13515 (defun org-ascii-level-start (level title umax
&optional lines
)
13516 "Insert a new level in ASCII export."
13517 (let (char (n (- level umax
1)) (ind 0))
13520 (insert (make-string (* 2 n
) ?\
)
13521 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
13522 org-export-ascii-bullets
))
13524 ;; find the indentation of the next non-empty line
13527 (if (string-match "^\\*" (car lines
)) (throw 'stop nil
))
13528 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
13529 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
13531 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
13532 (if (or (not (equal (char-before) ?
\n))
13533 (not (equal (char-before (1- (point))) ?
\n)))
13535 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
13536 (if org-export-with-section-numbers
13537 (setq title
(concat (org-section-number level
) " " title
)))
13538 (insert title
"\n" (make-string (string-width title
) char
) "\n")
13539 (setq org-ascii-current-indentation
'(0 .
0)))))
13541 (defun org-export-visible (type arg
)
13542 "Create a copy of the visible part of the current buffer, and export it.
13543 The copy is created in a temporary buffer and removed after use.
13544 TYPE is the final key (as a string) that also select the export command in
13545 the `C-c C-e' export dispatcher.
13546 As a special case, if the you type SPC at the prompt, the temporary
13547 org-mode file will not be removed but presented to you so that you can
13548 continue to use it. The prefix arg ARG is passed through to the exporting
13552 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [x]OXO [ ]keep buffer")
13553 (read-char-exclusive))
13554 current-prefix-arg
))
13555 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
13556 (error "Invalid export key"))
13557 (let* ((binding (cdr (assoc type
13558 '((?a . org-export-as-ascii
)
13559 (?\C-a . org-export-as-ascii
)
13560 (?b . org-export-as-html-and-open
)
13561 (?\C-b . org-export-as-html-and-open
)
13562 (?h . org-export-as-html
)
13563 (?x . org-export-as-xoxo
)))))
13564 (keepp (equal type ?\
))
13565 (file buffer-file-name
)
13566 (buffer (get-buffer-create "*Org Export Visible*"))
13568 (with-current-buffer buffer
(erase-buffer))
13570 (setq s
(goto-char (point-min)))
13571 (while (not (= (point) (point-max)))
13572 (goto-char (org-find-invisible))
13573 (append-to-buffer buffer s
(point))
13574 (setq s
(goto-char (org-find-visible))))
13575 (goto-char (point-min))
13577 ;; Copy all comment lines to the end, to make sure #+ settings are
13578 ;; still available for the second export step. Kind of a hack, but
13579 ;; does do the trick.
13580 (if (looking-at "#[^\r\n]*")
13581 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
13582 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
13583 (append-to-buffer buffer
(1+ (match-beginning 0))
13584 (min (point-max) (1+ (match-end 0))))))
13585 (set-buffer buffer
)
13586 (let ((buffer-file-name file
)
13587 (org-inhibit-startup t
))
13590 (unless keepp
(funcall binding arg
))))
13592 (kill-buffer buffer
)
13593 (switch-to-buffer-other-window buffer
)
13594 (goto-char (point-min)))))
13596 (defun org-find-visible ()
13597 (if (featurep 'noutline
)
13599 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
13600 (get-char-property s
'invisible
)))
13602 (skip-chars-forward "^\n")
13604 (defun org-find-invisible ()
13605 (if (featurep 'noutline
)
13607 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
13608 (not (get-char-property s
'invisible
))))
13610 (skip-chars-forward "^\r")
13616 (defun org-get-current-options ()
13617 "Return a string with current options as keyword options.
13618 Does include HTML export options as well as TODO and CATEGORY stuff."
13624 #+TEXT: Some descriptive text to be emitted. Several lines OK.
13625 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s *:%s TeX:%s LaTeX:%s
13629 #+STARTUP: %s %s %s %s %s %s
13633 (buffer-name) (user-full-name) user-mail-address org-export-default-language
13634 org-export-headline-levels
13635 org-export-with-section-numbers
13636 org-export-with-toc
13637 org-export-preserve-breaks
13638 org-export-html-expand
13639 org-export-with-fixed-width
13640 org-export-with-tables
13641 org-export-with-sub-superscripts
13642 org-export-with-emphasize
13643 org-export-with-TeX-macros
13644 org-export-with-LaTeX-fragments
13645 (file-name-nondirectory buffer-file-name
)
13646 (if (equal org-todo-interpretation
'sequence
)
13647 (mapconcat 'identity org-todo-keywords
" ")
13648 "TODO FEEDBACK VERIFY DONE")
13649 (if (equal org-todo-interpretation
'type
)
13650 (mapconcat 'identity org-todo-keywords
" ")
13651 "Me Jason Marie DONE")
13652 (cdr (assoc org-startup-folded
13653 '((nil .
"showall") (t .
"overview") (content .
"content"))))
13654 (if org-startup-with-deadline-check
"dlcheck" "nodlcheck")
13655 (if org-odd-levels-only
"odd" "oddeven")
13656 (if org-hide-leading-stars
"hidestars" "showstars")
13657 (if org-startup-align-all-tables
"align" "noalign")
13658 (if org-log-done
"logging" "nologging")
13659 (if org-tag-alist
(mapconcat 'car org-tag-alist
" ") "")
13660 org-archive-location
13663 (defun org-insert-export-options-template ()
13664 "Insert into the buffer a template with information for exporting."
13666 (if (not (bolp)) (newline))
13667 (let ((s (org-get-current-options)))
13668 (and (string-match "#\\+CATEGORY" s
)
13669 (setq s
(substring s
0 (match-beginning 0))))
13672 (defun org-toggle-fixed-width-section (arg)
13673 "Toggle the fixed-width export.
13674 If there is no active region, the QUOTE keyword at the current headline is
13675 inserted or removed. When present, it causes the text between this headline
13676 and the next to be exported as fixed-width text, and unmodified.
13677 If there is an active region, this command adds or removes a colon as the
13678 first character of this line. If the first character of a line is a colon,
13679 this line is also exported in fixed-width font."
13682 (regionp (org-region-active-p))
13683 (beg (if regionp
(region-beginning) (point)))
13684 (end (if regionp
(region-end)))
13685 (nlines (or arg
(if (and beg end
) (count-lines beg end
) 1)))
13686 (re "[ \t]*\\(:\\)")
13691 (setq cc
(current-column))
13692 (beginning-of-line 1)
13693 (setq off
(looking-at re
))
13694 (while (> nlines
0)
13695 (setq nlines
(1- nlines
))
13696 (beginning-of-line 1)
13699 (move-to-column cc t
)
13702 ((and off
(looking-at re
))
13703 (replace-match "" t t nil
1))
13704 ((not off
) (move-to-column cc t
) (insert ":")))
13707 (org-back-to-heading)
13708 (if (looking-at (concat outline-regexp
13709 "\\( +\\<" org-quote-string
"\\>\\)"))
13710 (replace-match "" t t nil
1)
13711 (if (looking-at outline-regexp
)
13713 (goto-char (match-end 0))
13714 (insert " " org-quote-string
))))))))
13716 (defun org-export-as-html-and-open (arg)
13717 "Export the outline as HTML and immediately open it with a browser.
13718 If there is an active region, export only the region.
13719 The prefix ARG specifies how many levels of the outline should become
13720 headlines. The default is 3. Lower levels will become bulleted lists."
13722 (org-export-as-html arg
'hidden
)
13723 (org-open-file buffer-file-name
))
13725 (defun org-export-as-html-batch ()
13726 "Call `org-export-as-html', may be used in batch processing as
13728 --load=$HOME/lib/emacs/org.el
13729 --eval \"(setq org-export-headline-levels 2)\"
13730 --visit=MyFile --funcall org-export-as-html-batch"
13731 (org-export-as-html org-export-headline-levels
'hidden
))
13733 (defun org-export-as-html (arg &optional hidden ext-plist
)
13734 "Export the outline as a pretty HTML file.
13735 If there is an active region, export only the region.
13736 The prefix ARG specifies how many levels of the outline should become
13737 headlines. The default is 3. Lower levels will become bulleted lists.
13738 When HIDDEN is non-nil, don't display the HTML buffer.
13739 EXT-PLIST is a property list with external parameters overriding
13740 org-mode's default settings, but still inferior to file-local settings."
13742 (message "Exporting...")
13743 (setq-default org-todo-line-regexp org-todo-line-regexp
)
13744 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
13745 (setq-default org-done-string org-done-string
)
13746 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
13748 (org-infile-export-plist)))
13750 (style (plist-get opt-plist
:style
))
13751 (link-validate (plist-get opt-plist
:link-validation-function
))
13753 (odd org-odd-levels-only
)
13754 (region-p (org-region-active-p))
13757 (if region-p
(region-beginning) (point-min))
13758 (if region-p
(region-end) (point-max))))
13759 ;; The following two are dynamically scoped into other
13761 (org-current-export-dir (org-export-directory :html opt-plist
))
13762 (org-current-export-file buffer-file-name
)
13764 (org-skip-comments (org-split-string
13765 (org-cleaned-string-for-export
13766 region
:emph-multiline
13767 (if (plist-get opt-plist
:LaTeX-fragments
)
13770 (lines (org-export-find-first-heading-line all_lines
))
13771 (level 0) (line "") (origline "") txt todo
13773 (filename (concat (file-name-as-directory
13774 (org-export-directory :html opt-plist
))
13775 (file-name-sans-extension
13776 (file-name-nondirectory buffer-file-name
))
13778 (current-dir (file-name-directory buffer-file-name
))
13779 (buffer (find-file-noselect filename
))
13780 (levels-open (make-vector org-level-max nil
))
13781 (date (format-time-string "%Y/%m/%d" (current-time)))
13782 (time (format-time-string "%X" (org-current-time)))
13783 (author (plist-get opt-plist
:author
))
13784 (title (or (plist-get opt-plist
:title
)
13785 (file-name-sans-extension
13786 (file-name-nondirectory buffer-file-name
))))
13787 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
13788 (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string
"\\>\\)"))
13791 (in-local-list nil
)
13792 (local-list-num nil
)
13793 (local-list-indent nil
)
13794 (llt org-plain-list-ordered-item-terminator
)
13795 (email (plist-get opt-plist
:email
))
13796 (language (plist-get opt-plist
:language
))
13797 (text (plist-get opt-plist
:text
))
13799 (target-alist nil
) tg
13802 (coding-system (and (fboundp 'coding-system-get
)
13803 (boundp 'buffer-file-coding-system
)
13804 buffer-file-coding-system
))
13805 (coding-system-for-write (or coding-system coding-system-for-write
))
13806 (save-buffer-coding-system (or coding-system save-buffer-coding-system
))
13807 (charset (and coding-system
13808 (coding-system-get coding-system
'mime-charset
)))
13810 table-buffer table-orig-buffer
13811 ind start-is-num starter
13812 rpl path desc descp desc1 desc2 link
13814 (message "Exporting...")
13816 (setq org-last-level
1)
13817 (org-init-section-numbers)
13819 ;; Get the language-dependent settings
13820 (setq lang-words
(or (assoc language org-export-language-setup
)
13821 (assoc "en" org-export-language-setup
)))
13823 ;; Switch to the output buffer
13824 (if (or hidden
(not org-export-html-show-new-buffer
))
13825 (set-buffer buffer
)
13826 (switch-to-buffer-other-window buffer
))
13829 (let ((case-fold-search nil
)
13830 (org-odd-levels-only odd
))
13831 ;; create local variables for all options, to make sure all called
13832 ;; functions get the correct information
13833 (mapcar (lambda (x)
13834 (set (make-local-variable (cdr x
))
13835 (plist-get opt-plist
(car x
))))
13836 org-export-plist-vars
)
13837 (setq umax
(if arg
(prefix-numeric-value arg
)
13838 org-export-headline-levels
))
13842 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
13843 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
13844 <html xmlns=\"http://www.w3.org/1999/xhtml\"
13845 lang=\"%s\" xml:lang=\"%s\">
13848 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
13849 <meta name=\"generator\" content=\"Org-mode\"/>
13850 <meta name=\"generated\" content=\"%s %s\"/>
13851 <meta name=\"author\" content=\"%s\"/>
13855 language language
(org-html-expand title
) (or charset
"iso-8859-1")
13856 date time author style
))
13859 (insert (or (plist-get opt-plist
:preamble
) ""))
13861 (when (plist-get opt-plist
:auto-preamble
)
13862 (if title
(insert (concat "<h1 class=\"title\">"
13863 (org-html-expand title
) "</h1>\n")))
13865 (if text
(insert "<p>\n" (org-html-expand text
) "</p>")))
13867 (if org-export-with-toc
13869 (insert (format "<h2>%s</h2>\n" (nth 3 lang-words
)))
13870 (insert "<ul>\n<li>")
13872 (mapcar '(lambda (line)
13873 (if (string-match org-todo-line-regexp line
)
13874 ;; This is a headline
13876 (setq level
(- (match-end 1) (match-beginning 1))
13877 level
(org-tr-level level
)
13878 txt
(save-match-data
13880 (org-export-cleanup-toc-line
13881 (match-string 3 line
))))
13883 (or (and org-export-mark-todo-in-toc
13884 (match-beginning 2)
13885 (not (equal (match-string 2 line
)
13888 (and org-export-mark-todo-in-toc
13890 (org-search-todo-below
13891 line lines level
))))
13892 (if org-export-with-section-numbers
13893 (setq txt
(concat (org-section-number level
)
13895 (if (<= level umax
)
13897 (setq head-count
(+ head-count
1))
13898 (if (> level org-last-level
)
13900 (setq cnt
(- level org-last-level
))
13901 (while (>= (setq cnt
(1- cnt
)) 0)
13902 (insert "\n<ul>\n<li>"))
13904 (if (< level org-last-level
)
13906 (setq cnt
(- org-last-level level
))
13907 (while (>= (setq cnt
(1- cnt
)) 0)
13908 (insert "</li>\n</ul>"))
13910 ;; Check for targets
13911 (while (string-match org-target-regexp line
)
13912 (setq tg
(match-string 1 line
)
13913 line
(replace-match
13914 (concat "@<span class=\"target\">" tg
"@</span> ")
13916 (push (cons (org-solidify-link-text tg
)
13917 (format "sec-%d" head-count
))
13919 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
13920 (setq txt
(replace-match "" t t txt
)))
13924 "</li>\n<li><a href=\"#sec-%d\"><span class=\"todo\">%s</span></a>"
13925 "</li>\n<li><a href=\"#sec-%d\">%s</a>")
13928 (setq org-last-level level
))
13932 (while (> org-last-level
0)
13933 (setq org-last-level
(1- org-last-level
))
13934 (insert "</li>\n</ul>\n"))
13936 (setq head-count
0)
13937 (org-init-section-numbers)
13939 (while (setq line
(pop lines
) origline line
)
13942 ;; end of quote section?
13943 (when (and inquote
(string-match "^\\*+" line
))
13944 (insert "</pre>\n")
13945 (setq inquote nil
))
13946 ;; inside a quote section?
13948 (insert (org-html-protect line
) "\n")
13949 (throw 'nextline nil
))
13952 (when (and org-export-with-fixed-width
13953 (string-match "^[ \t]*:\\(.*\\)" line
))
13954 (when (not infixed
)
13956 (insert "<pre>\n"))
13957 (insert (org-html-protect (match-string 1 line
)) "\n")
13959 (not (string-match "^[ \t]*\\(:.*\\)"
13962 (insert "</pre>\n"))
13963 (throw 'nextline nil
))
13966 ;; make targets to anchors
13967 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
13970 (setq line
(replace-match
13971 (concat "@<a name=\""
13972 (org-solidify-link-text (match-string 1 line
))
13975 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
13976 (setq line
(replace-match
13977 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
13978 ; (concat "@<i>" (match-string 1 line) "@</i> ")
13981 (setq line
(replace-match
13982 (concat "@<a name=\""
13983 (org-solidify-link-text (match-string 1 line
))
13984 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
13987 (setq line
(org-html-handle-time-stamps line
))
13989 ;; replace "&" by "&", "<" and ">" by "<" and ">"
13990 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
13991 ;; Also handle sub_superscripts and checkboxes
13992 (setq line
(org-html-expand line
))
13994 ;; Format the links
13996 (while (string-match org-bracket-link-analytic-regexp line start
)
13997 (setq start
(match-beginning 0))
13998 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
13999 (setq path
(match-string 3 line
))
14000 (setq desc1
(if (match-end 5) (match-string 5 line
))
14001 desc2
(if (match-end 2) (concat type
":" path
) path
)
14002 descp
(and desc1
(not (equal desc1 desc2
)))
14003 desc
(or desc1 desc2
))
14004 ;; FIXME: do we need to unescape here somewhere?
14006 ((equal type
"internal")
14010 (org-solidify-link-text path target-alist
)
14011 "\">" desc
"</a>")))
14012 ((member type
'("http" "https" "ftp" "mailto" "news"))
14014 (setq link
(concat type
":" path
))
14015 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
14016 ((string= type
"file")
14018 (let* ((filename path
)
14019 (abs-p (file-name-absolute-p filename
))
14020 thefile file-is-image-p search
)
14022 (if (string-match "::\\(.*\\)" filename
)
14023 (setq search
(match-string 1 filename
)
14024 filename
(replace-match "" t nil filename
)))
14026 (if (functionp link-validate
)
14027 (funcall link-validate filename current-dir
)
14029 (setq file-is-image-p
14030 (string-match (org-image-file-name-regexp) filename
))
14031 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
14032 (when (and org-export-html-link-org-files-as-html
14033 (string-match "\\.org$" thefile
))
14034 (setq thefile
(concat (substring thefile
0
14035 (match-beginning 0))
14038 ;; make sure this is can be used as target search
14039 (not (string-match "^[0-9]*$" search
))
14040 (not (string-match "^\\*" search
))
14041 (not (string-match "^/.*/$" search
)))
14042 (setq thefile
(concat thefile
"#"
14043 (org-solidify-link-text
14044 (org-link-unescape search
)))))
14045 (when (string-match "^file:" desc
)
14046 (setq desc
(replace-match "" t t desc
))
14047 (if (string-match "\\.org$" desc
)
14048 (setq desc
(replace-match "" t t desc
))))))
14049 (setq rpl
(if (and file-is-image-p
14050 (or (eq t org-export-html-inline-images
)
14051 (and org-export-html-inline-images
14053 (concat "<img src=\"" thefile
"\"/>")
14054 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
14055 (if (not valid
) (setq rpl desc
))))
14056 ((member type
'("bbdb" "vm" "wl" "mhe" "rmail" "gnus" "shell" "info" "elisp"))
14057 (setq rpl
(concat "<i><" type
":"
14058 (save-match-data (org-link-unescape path
))
14060 (setq line
(replace-match rpl t t line
)
14061 start
(+ start
(length rpl
))))
14063 (if (and (string-match org-todo-line-regexp line
)
14064 (match-beginning 2))
14065 (if (equal (match-string 2 line
) org-done-string
)
14066 (setq line
(replace-match
14067 "<span class=\"done\">\\2</span>"
14069 (setq line
(replace-match "<span class=\"todo\">\\2</span>"
14073 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line
)
14074 ;; This is a headline
14075 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
14076 txt
(match-string 2 line
))
14077 (if (string-match quote-re0 txt
)
14078 (setq txt
(replace-match "" t t txt
)))
14079 (if (<= level umax
) (setq head-count
(+ head-count
1)))
14080 (when in-local-list
14081 ;; Close any local lists before inserting a new header line
14082 (while local-list-num
14084 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
14085 (pop local-list-num
))
14086 (setq local-list-indent nil
14087 in-local-list nil
))
14088 (org-html-level-start level txt umax
14089 (and org-export-with-toc
(<= level umax
))
14092 (when (string-match quote-re line
)
14096 ((and org-export-with-tables
14097 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
14098 (if (not table-open
)
14099 ;; New table starts
14100 (setq table-open t table-buffer nil table-orig-buffer nil
))
14101 ;; Accumulate lines
14102 (setq table-buffer
(cons line table-buffer
)
14103 table-orig-buffer
(cons origline table-orig-buffer
))
14104 (when (or (not lines
)
14105 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
14107 (setq table-open nil
14108 table-buffer
(nreverse table-buffer
)
14109 table-orig-buffer
(nreverse table-orig-buffer
))
14110 (org-close-par-maybe)
14111 (insert (org-format-table-html table-buffer table-orig-buffer
))))
14114 (when (string-match
14116 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
14117 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
14118 ((= llt ?\
)) "^\\( \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
14119 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
14121 (setq ind
(org-get-string-indentation line
)
14122 start-is-num
(match-beginning 4)
14123 starter
(if (match-beginning 2)
14124 (substring (match-string 2 line
) 0 -
1))
14125 line
(substring line
(match-beginning 5)))
14126 (unless (string-match "[^ \t]" line
)
14127 ;; empty line. Pretend indentation is large.
14128 (setq ind
(1+ (or (car local-list-indent
) 1))))
14129 (while (and in-local-list
14130 (or (and (= ind
(car local-list-indent
))
14132 (< ind
(car local-list-indent
))))
14134 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
14135 (pop local-list-num
) (pop local-list-indent
)
14136 (setq in-local-list local-list-indent
))
14139 (or (not in-local-list
)
14140 (> ind
(car local-list-indent
))))
14141 ;; Start new (level of ) list
14142 (org-close-par-maybe)
14143 (insert (if start-is-num
"<ol>\n<li>\n" "<ul>\n<li>\n"))
14144 (push start-is-num local-list-num
)
14145 (push ind local-list-indent
)
14146 (setq in-local-list t
))
14148 ;; continue current list
14150 (insert "<li>\n")))
14151 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
14154 (if (equal (match-string 1 line
) "X")
14156 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
14159 ;; Empty lines start a new paragraph. If hand-formatted lists
14160 ;; are not fully interpreted, lines starting with "-", "+", "*"
14161 ;; also start a new paragraph.
14162 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
14164 ;; Check if the line break needs to be conserved
14166 ((string-match "\\\\\\\\[ \t]*$" line
)
14167 (setq line
(replace-match "<br/>" t t line
)))
14168 (org-export-preserve-breaks
14169 (setq line
(concat line
"<br/>"))))
14171 (insert line
"\n")))))
14173 ;; Properly close all local lists and other lists
14174 (when inquote
(insert "</pre>\n"))
14175 (when in-local-list
14176 ;; Close any local lists before inserting a new header line
14177 (while local-list-num
14179 (insert (if (car local-list-num
) "</ol>\n" "</ul>\n"))
14180 (pop local-list-num
))
14181 (setq local-list-indent nil
14182 in-local-list nil
))
14183 (org-html-level-start 1 nil umax
14184 (and org-export-with-toc
(<= level umax
))
14187 (when (plist-get opt-plist
:auto-postamble
)
14189 (insert "<p class=\"author\"> "
14190 (nth 1 lang-words
) ": " author
"\n")
14192 (insert "<a href=\"mailto:" email
"\"><"
14193 email
"></a>\n"))
14195 (when (and date time
)
14196 (insert "<p class=\"date\"> "
14197 (nth 2 lang-words
) ": "
14198 date
" " time
"</p>\n")))
14200 (if org-export-html-with-timestamp
14201 (insert org-export-html-html-helper-timestamp
))
14202 (insert (or (plist-get opt-plist
:postamble
) ""))
14203 (insert "</body>\n</html>\n")
14205 ;; remove empty paragraphs and lists
14206 (goto-char (point-min))
14207 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
14208 (replace-match ""))
14209 (goto-char (point-min))
14210 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
14211 (replace-match ""))
14213 (goto-char (point-min))
14214 (message "Exporting... done"))))
14217 (defun org-format-table-html (lines olines
)
14218 "Find out which HTML converter to use and return the HTML code."
14219 (if (string-match "^[ \t]*|" (car lines
))
14220 ;; A normal org table
14221 (org-format-org-table-html lines
)
14222 ;; Table made by table.el - test for spanning
14223 (let* ((hlines (delq nil
(mapcar
14225 (if (string-match "^[ \t]*\\+-" x
) x
14228 (first (car hlines
))
14229 (ll (and (string-match "\\S-+" first
)
14230 (match-string 0 first
)))
14231 (re (concat "^[ \t]*" (regexp-quote ll
)))
14232 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
14234 (if (and (not spanning
)
14235 (not org-export-prefer-native-exporter-for-tables
))
14236 ;; We can use my own converter with HTML conversions
14237 (org-format-table-table-html lines
)
14238 ;; Need to use the code generator in table.el, with the original text.
14239 (org-format-table-table-html-using-table-generate-source olines
)))))
14241 (defun org-format-org-table-html (lines)
14242 "Format a table into HTML."
14243 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
14244 (setq lines
(nreverse lines
))
14245 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
14246 (setq lines
(nreverse lines
))
14247 (when org-export-table-remove-special-lines
14248 ;; Check if the table has a marking column. If yes remove the
14249 ;; column and the special lines
14255 (or (string-match "^[ \t]*|-" x
)
14256 (string-match "^[ \t]*| *\\([#!$*_^ ]\\) *|" x
)))
14263 (if (string-match "^[ \t]*| *[!_^] *|" x
)
14264 nil
; ignore this line
14265 (and (or (string-match "^[ \t]*|-+\\+" x
)
14266 (string-match "^[ \t]*|[^|]*|" x
))
14267 (replace-match "|" t t x
))))
14270 (let ((head (and org-export-highlight-first-table-line
14272 (lambda (x) (string-match "^[ \t]*|-" x
))
14275 (setq html
(concat org-export-html-table-tag
"\n"))
14276 (while (setq line
(pop lines
))
14278 (if (string-match "^[ \t]*|-" line
)
14280 (setq head nil
) ;; head ends here, first time around
14281 ;; ignore this line
14282 (throw 'next-line t
)))
14283 ;; Break the line into fields
14284 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
14288 (mapconcat (lambda (x)
14290 (concat "<th>" x
"</th>")
14291 (concat "<td>" x
"</td>")))
14294 (setq html
(concat html
"</table>\n"))
14297 (defun org-fake-empty-table-line (line)
14298 "Replace everything except \"|\" with spaces."
14299 (let ((i (length line
))
14300 (newstr (copy-sequence line
)))
14303 (if (not (eq (aref newstr i
) ?|
))
14304 (aset newstr i ?\
)))
14307 (defun org-format-table-table-html (lines)
14308 "Format a table generated by table.el into HTML.
14309 This conversion does *not* use `table-generate-source' from table.el.
14310 This has the advantage that Org-mode's HTML conversions can be used.
14311 But it has the disadvantage, that no cell- or row-spanning is allowed."
14312 (let (line field-buffer
14313 (head org-export-highlight-first-table-line
)
14315 (setq html
(concat org-export-html-table-tag
"\n"))
14316 (while (setq line
(pop lines
))
14317 (setq empty
" ")
14319 (if (string-match "^[ \t]*\\+-" line
)
14328 (if (equal x
"") (setq x empty
))
14330 (concat "<th>" x
"</th>\n")
14331 (concat "<td>" x
"</td>\n")))
14335 (setq field-buffer nil
)))
14336 ;; Ignore this line
14337 (throw 'next-line t
)))
14338 ;; Break the line into fields and store the fields
14339 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
14341 (setq field-buffer
(mapcar
14343 (concat x
"<br/>" (pop fields
)))
14345 (setq field-buffer fields
))))
14346 (setq html
(concat html
"</table>\n"))
14349 (defun org-format-table-table-html-using-table-generate-source (lines)
14350 "Format a table into html, using `table-generate-source' from table.el.
14351 This has the advantage that cell- or row-spanning is allowed.
14352 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
14354 (with-current-buffer (get-buffer-create " org-tmp1 ")
14356 (insert (mapconcat 'identity lines
"\n"))
14357 (goto-char (point-min))
14358 (if (not (re-search-forward "|[^+]" nil t
))
14359 (error "Error processing table"))
14360 (table-recognize-table)
14361 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
14362 (table-generate-source 'html
" org-tmp2 ")
14363 (set-buffer " org-tmp2 ")
14364 (buffer-substring (point-min) (point-max))))
14366 (defun org-html-handle-time-stamps (s)
14367 "Format time stamps in string S, or remove them."
14370 (while (string-match org-maybe-keyword-time-regexp s
)
14371 ;; FIXME: is it good to never export CLOCK, or do we need control?
14372 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
14374 (or b
(setq b
(substring s
0 (match-beginning 0))))
14375 (if (not org-export-with-timestamps
)
14376 (setq r
(concat r
(substring s
0 (match-beginning 0)))
14377 s
(substring s
(match-end 0)))
14379 r
(substring s
0 (match-beginning 0))
14381 (format "@<span class=\"timestamp-kwd\">%s @</span>"
14382 (match-string 1 s
)))
14383 (format " @<span class=\"timestamp\">%s@</span>"
14384 (substring (match-string 3 s
) 1 -
1)))
14385 s
(substring s
(match-end 0)))))
14386 ;; Line break if line started and ended with time stamp stuff
14389 (setq r
(concat r s
))
14390 (unless (string-match "\\S-" (concat b s
))
14391 (setq r
(concat r
"@<br/>")))
14394 (defun org-html-protect (s)
14395 ;; convert & to &, < to < and > to >
14397 (while (string-match "&" s start
)
14398 (setq s
(replace-match "&" t t s
)
14399 start
(1+ (match-beginning 0))))
14400 (while (string-match "<" s
)
14401 (setq s
(replace-match "<" t t s
)))
14402 (while (string-match ">" s
)
14403 (setq s
(replace-match ">" t t s
))))
14406 (defun org-export-cleanup-toc-line (s)
14407 "Remove tags and time staps from lines going into the toc."
14408 (if (string-match " +:[a-zA-Z0-9_@:]+: *$" s
)
14409 (setq s
(replace-match "" t t s
)))
14410 (when org-export-remove-timestamps-from-toc
14411 (while (string-match org-maybe-keyword-time-regexp s
)
14412 (setq s
(replace-match "" t t s
))))
14415 (defun org-html-expand (string)
14416 "Prepare STRING for HTML export. Applies all active conversions.
14417 If there are links in the string, don't modify these."
14419 (while (setq m
(string-match org-bracket-link-regexp string
))
14420 (setq s
(substring string
0 m
)
14421 l
(match-string 0 string
)
14422 string
(substring string
(match-end 0)))
14423 (push (org-html-do-expand s
) res
)
14425 (push (org-html-do-expand string
) res
)
14426 (apply 'concat
(nreverse res
))))
14428 (defun org-html-do-expand (s)
14429 "Apply all active conversions to translate special ASCII to HTML."
14430 (setq s
(org-html-protect s
))
14431 (if org-export-html-expand
14432 (while (string-match "@<\\([^&]*\\)>" s
)
14433 (setq s
(replace-match "<\\1>" t nil s
))))
14434 (if org-export-with-emphasize
14435 (setq s
(org-export-html-convert-emphasize s
)))
14436 (if org-export-with-sub-superscripts
14437 (setq s
(org-export-html-convert-sub-super s
)))
14438 (if org-export-with-TeX-macros
14439 (let ((start 0) wd ass
)
14440 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
14441 (setq wd
(match-string 1 s
))
14442 (if (setq ass
(assoc wd org-html-entities
))
14443 (setq s
(replace-match (or (cdr ass
)
14444 (concat "&" (car ass
) ";"))
14446 (setq start
(+ start
(length wd
)))))))
14449 (defun org-create-multibrace-regexp (left right n
)
14450 "Create a regular expression which will match a balanced sexp.
14451 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
14452 as single character strings.
14453 The regexp returned will match the entire expression including the
14454 delimiters. It will also define a single group which contains the
14455 match except for the outermost delimiters. The maximum depth of
14456 stacked delimiters is N. Escaping delimiters is not possible."
14457 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
14460 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
14463 re
(concat re or next
)
14464 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
14465 (concat left
"\\(" re
"\\)" right
)))
14467 (defvar org-match-substring-regexp
14469 "\\([^\\]\\)\\([_^]\\)\\("
14470 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
14472 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
14474 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
14475 "The regular expression matching a sub- or superscript.")
14477 (defun org-export-html-convert-sub-super (string)
14478 "Convert sub- and superscripts in STRING to HTML."
14480 (while (string-match org-match-substring-regexp string
)
14481 (setq key
(if (string= (match-string 2 string
) "_") "sub" "sup"))
14482 (setq c
(or (match-string 8 string
)
14483 (match-string 6 string
)
14484 (match-string 5 string
)))
14485 (setq string
(replace-match
14486 (concat (match-string 1 string
)
14487 "<" key
">" c
"</" key
">")
14489 (while (string-match "\\\\\\([_^]\\)" string
)
14490 (setq string
(replace-match (match-string 1 string
) t t string
))))
14493 (defun org-export-html-convert-emphasize (string)
14495 (while (string-match org-emph-re string
)
14496 (setq string
(replace-match (concat "\\1" (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
)) "\\4" (nth 3 (assoc (match-string 3 string
) org-emphasis-alist
)) "\\5") t nil string
)))
14499 (defvar org-par-open nil
)
14500 (defun org-open-par ()
14501 "Insert <p>, but first close previous paragraph if any."
14502 (org-close-par-maybe)
14504 (setq org-par-open t
))
14505 (defun org-close-par-maybe ()
14506 "Close paragraph if there is one open."
14509 (setq org-par-open nil
)))
14510 (defun org-close-li ()
14511 "Close <li> if necessary."
14512 (org-close-par-maybe)
14513 (insert "</li>\n"))
14514 ; (when (save-excursion
14515 ; (re-search-backward "</?\\(ul\\|ol\\|li\\|[hH][0-9]\\)>" nil t))
14516 ; (if (member (match-string 0) '("</ul>" "</ol>" "<li>"))
14517 ; (insert "</li>"))))
14519 (defun org-html-level-start (level title umax with-toc head-count
)
14520 "Insert a new level in HTML export.
14521 When TITLE is nil, just close all open levels."
14522 (org-close-par-maybe)
14523 (let ((l (1+ (max level umax
))))
14524 (while (<= l org-level-max
)
14525 (if (aref levels-open
(1- l
))
14527 (org-html-level-close l
)
14528 (aset levels-open
(1- l
) nil
)))
14531 ;; If title is nil, this means this function is called to close
14532 ;; all levels, so the rest is done only if title is given
14533 (when (string-match "\\(:[a-zA-Z0-9_@:]+:\\)[ \t]*$" title
)
14534 (setq title
(replace-match
14535 (if org-export-with-tags
14538 " <span class=\"tag\">"
14539 (mapconcat 'identity
(org-split-string
14540 (match-string 1 title
) ":")
14547 (if (aref levels-open
(1- level
))
14550 (insert "<li>" title
"<br/>\n"))
14551 (aset levels-open
(1- level
) t
)
14552 (org-close-par-maybe)
14553 (insert "<ul>\n<li>" title
"<br/>\n")))
14554 (if org-export-with-section-numbers
14555 (setq title
(concat (org-section-number level
) " " title
)))
14556 (setq level
(+ level
1))
14558 (insert (format "\n<h%d><a name=\"sec-%d\">%s</a></h%d>\n"
14559 level head-count title level
))
14560 (insert (format "\n<h%d>%s</h%d>\n" level title level
)))
14563 (defun org-html-level-close (&rest args
)
14564 "Terminate one level in HTML export."
14568 ;; Variable holding the vector with section numbers
14569 (defvar org-section-numbers
(make-vector org-level-max
0))
14571 (defun org-init-section-numbers ()
14572 "Initialize the vector for the section numbers."
14574 (numbers (nreverse (org-split-string "" "\\.")))
14575 (depth (1- (length org-section-numbers
)))
14576 (i depth
) number-string
)
14579 (aset org-section-numbers i
0)
14580 (setq number-string
(or (car numbers
) "0"))
14581 (if (string-match "\\`[A-Z]\\'" number-string
)
14582 (aset org-section-numbers i
14583 (- (string-to-char number-string
) ?A -
1))
14584 (aset org-section-numbers i
(string-to-number number-string
)))
14588 (defun org-section-number (&optional level
)
14589 "Return a string with the current section number.
14590 When LEVEL is non-nil, increase section numbers on that level."
14591 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
14594 (aset org-section-numbers
14595 level
(1+ (aref org-section-numbers level
))))
14596 (setq idx
(1+ level
))
14597 (while (<= idx depth
)
14598 (if (not (= idx
1))
14599 (aset org-section-numbers idx
0))
14600 (setq idx
(1+ idx
))))
14602 (while (<= idx depth
)
14603 (setq n
(aref org-section-numbers idx
))
14604 (setq string
(concat string
(if (not (string= string
"")) "." "")
14605 (int-to-string n
)))
14606 (setq idx
(1+ idx
)))
14608 (if (string-match "\\`\\([@0]\\.\\)+" string
)
14609 (setq string
(replace-match "" t nil string
)))
14610 (if (string-match "\\(\\.0\\)+\\'" string
)
14611 (setq string
(replace-match "" t nil string
))))
14616 (defun org-export-icalendar-this-file ()
14617 "Export current file as an iCalendar file.
14618 The iCalendar file will be located in the same directory as the Org-mode
14619 file, but with extension `.ics'."
14621 (org-export-icalendar nil buffer-file-name
))
14623 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
14624 (with-current-buffer buffer
14625 (apply 'insert output
)))
14627 (defun org-export-as-xoxo (&optional buffer
)
14628 "Export the org buffer as XOXO.
14629 The XOXO buffer is named *xoxo-<source buffer name>*"
14630 (interactive (list (current-buffer)))
14631 ;; A quickie abstraction
14633 ;; Output everything as XOXO
14634 (with-current-buffer (get-buffer buffer
)
14635 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
14636 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
14637 (org-infile-export-plist)))
14638 (filename (concat (file-name-as-directory
14639 (org-export-directory :xoxo opt-plist
))
14640 (file-name-sans-extension
14641 (file-name-nondirectory buffer-file-name
))
14643 (out (find-file-noselect filename
))
14646 ;; Check the output buffer is empty.
14647 (with-current-buffer out
(erase-buffer))
14648 ;; Kick off the output
14649 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
14650 (while (re-search-forward "^\\(\\*+\\) \\(.+\\)" (point-max) 't
)
14651 (let* ((hd (match-string-no-properties 1))
14652 (level (length hd
))
14654 (match-string-no-properties 2)
14656 (goto-char (match-end 0))
14661 (if (looking-at "^[ \t]\\(.*\\)")
14662 (setq str
(concat str
(match-string-no-properties 1)))
14663 (throw 'loop str
)))))))))
14665 ;; Handle level rendering
14667 ((> level last-level
)
14668 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
14670 ((< level last-level
)
14671 (dotimes (- (- last-level level
) 1)
14673 (org-export-as-xoxo-insert-into out
"</li>\n"))
14674 (org-export-as-xoxo-insert-into out
"</ol>\n"))
14676 (org-export-as-xoxo-insert-into out
"</li>\n")
14677 (setq hanging-li nil
)))
14679 ((equal level last-level
)
14681 (org-export-as-xoxo-insert-into out
"</li>\n")))
14684 (setq last-level level
)
14686 ;; And output the new li
14687 (setq hanging-li
't
)
14688 (if (equal ?
+ (elt text
0))
14689 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
14690 (org-export-as-xoxo-insert-into out
"<li>" text
))))
14692 ;; Finally finish off the ol
14693 (dotimes (- last-level
1)
14695 (org-export-as-xoxo-insert-into out
"</li>\n"))
14696 (org-export-as-xoxo-insert-into out
"</ol>\n"))
14698 ;; Finish the buffer off and clean it up.
14699 (switch-to-buffer-other-window out
)
14700 (indent-region (point-min) (point-max) nil
)
14702 (goto-char (point-min))
14706 (defun org-export-icalendar-all-agenda-files ()
14707 "Export all files in `org-agenda-files' to iCalendar .ics files.
14708 Each iCalendar file will be located in the same directory as the Org-mode
14709 file, but with extension `.ics'."
14711 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
14714 (defun org-export-icalendar-combine-agenda-files ()
14715 "Export all files in `org-agenda-files' to a single combined iCalendar file.
14716 The file is stored under the name `org-combined-agenda-icalendar-file'."
14718 (apply 'org-export-icalendar t
(org-agenda-files t
)))
14720 (defun org-export-icalendar (combine &rest files
)
14721 "Create iCalendar files for all elements of FILES.
14722 If COMBINE is non-nil, combine all calendar entries into a single large
14723 file and store it under the name `org-combined-agenda-icalendar-file'."
14725 (let* ((dir (org-export-directory
14726 :ical
(list :publishing-directory
14727 org-export-publishing-directory
)))
14728 file ical-file ical-buffer category started org-agenda-new-buffers
)
14732 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
14733 org-combined-agenda-icalendar-file
14734 (expand-file-name org-combined-agenda-icalendar-file dir
))
14735 ical-buffer
(org-get-agenda-file-buffer ical-file
))
14736 (set-buffer ical-buffer
) (erase-buffer))
14737 (while (setq file
(pop files
))
14739 (org-check-agenda-file file
)
14740 (set-buffer (org-get-agenda-file-buffer file
))
14742 (setq ical-file
(concat (file-name-as-directory dir
)
14743 (file-name-sans-extension
14744 (file-name-nondirectory buffer-file-name
))
14746 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
14747 (with-current-buffer ical-buffer
(erase-buffer)))
14748 (setq category
(or org-category
14749 (file-name-sans-extension
14750 (file-name-nondirectory buffer-file-name
))))
14751 (if (symbolp category
) (setq category
(symbol-name category
)))
14752 (let ((standard-output ical-buffer
))
14754 (and (not started
) (setq started t
)
14755 (org-start-icalendar-file org-icalendar-combined-name
))
14756 (org-start-icalendar-file category
))
14757 (org-print-icalendar-entries combine category
)
14758 (when (or (and combine
(not files
)) (not combine
))
14759 (org-finish-icalendar-file)
14760 (set-buffer ical-buffer
)
14762 (run-hooks 'org-after-save-iCalendar-file-hook
)))))
14763 (org-release-buffers org-agenda-new-buffers
))))
14765 (defvar org-after-save-iCalendar-file-hook nil
14766 "Hook run after an iCalendar file has been saved.
14767 The iCalendar buffer is still current when this hook is run.
14768 A good way to use this is to tell a desktop calenndar application to re-read
14769 the iCalendar file.")
14771 (defun org-print-icalendar-entries (&optional combine category
)
14772 "Print iCalendar entries for the current Org-mode file to `standard-output'.
14773 When COMBINE is non nil, add the category to each line."
14774 (let ((re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
14775 (dts (org-ical-ts-to-string
14776 (format-time-string (cdr org-time-stamp-formats
) (current-time))
14778 hd ts ts2 state
(inc t
) pos scheduledp deadlinep tmp pri
)
14780 (goto-char (point-min))
14781 (while (re-search-forward org-ts-regexp nil t
)
14782 (setq pos
(match-beginning 0)
14783 ts
(match-string 0)
14785 hd
(org-get-heading))
14786 (if (looking-at re2
)
14788 (goto-char (match-end 0))
14789 (setq ts2
(match-string 1) inc nil
))
14791 tmp
(buffer-substring (max (point-min)
14792 (- pos org-ds-keyword-length
))
14794 deadlinep
(string-match org-deadline-regexp tmp
)
14795 scheduledp
(string-match org-scheduled-regexp tmp
)
14796 ;; donep (org-entry-is-done-p)
14798 (if (or (string-match org-tr-regexp hd
)
14799 (string-match org-ts-regexp hd
))
14800 (setq hd
(replace-match "" t t hd
)))
14802 (setq hd
(concat hd
" (category " category
")")))
14803 (if deadlinep
(setq hd
(concat "DL: " hd
" This is a deadline")))
14804 (if scheduledp
(setq hd
(concat "S: " hd
" Scheduled for this date")))
14805 (princ (format "BEGIN:VEVENT
14810 (org-ical-ts-to-string ts
"DTSTART")
14811 (org-ical-ts-to-string ts2
"DTEND" inc
)
14813 (when org-icalendar-include-todo
14814 (goto-char (point-min))
14815 (while (re-search-forward org-todo-line-regexp nil t
)
14816 (setq state
(match-string 1))
14817 (unless (equal state org-done-string
)
14818 (setq hd
(match-string 3))
14819 (if (string-match org-priority-regexp hd
)
14820 (setq pri
(string-to-char (match-string 2 hd
))
14821 hd
(concat (substring hd
0 (match-beginning 1))
14822 (substring hd
(- (match-end 1)))))
14823 (setq pri org-default-priority
))
14824 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
14825 (- org-lowest-priority ?A
))))))
14827 (princ (format "BEGIN:VTODO
14835 (defun org-start-icalendar-file (name)
14836 "Start an iCalendar file by inserting the header."
14837 (let ((user user-full-name
)
14838 (name (or name
"unknown"))
14839 (timezone (cadr (current-time-zone))))
14841 (format "BEGIN:VCALENDAR
14844 PRODID:-//%s//Emacs with Org-mode//EN
14846 CALSCALE:GREGORIAN\n" name user timezone
))))
14848 (defun org-finish-icalendar-file ()
14849 "Finish an iCalendar file by inserting the END statement."
14850 (princ "END:VCALENDAR\n"))
14852 (defun org-ical-ts-to-string (s keyword
&optional inc
)
14853 "Take a time string S and convert it to iCalendar format.
14854 KEYWORD is added in front, to make a complete line like DTSTART....
14855 When INC is non-nil, increase the hour by two (if time string contains
14856 a time), or the day by one (if it does not contain a time)."
14857 (let ((t1 (org-parse-time-string s
'nodefault
))
14858 t2 fmt have-time time
)
14859 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
14860 (setq t2 t1 have-time t
)
14861 (setq t2
(org-parse-time-string s
)))
14862 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
14863 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
14865 (if have-time
(setq h
(+ 2 h
)) (setq d
(1+ d
))))
14866 (setq time
(encode-time s mi h d m y
)))
14867 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
14868 (concat keyword
(format-time-string fmt time
))))
14872 (defvar org-cdlatex-mode-map
(make-sparse-keymap)
14873 "Keymap for the minor `org-cdlatex-mode'.")
14875 (define-key org-cdlatex-mode-map
"_" 'org-cdlatex-underscore-caret
)
14876 (define-key org-cdlatex-mode-map
"^" 'org-cdlatex-underscore-caret
)
14877 (define-key org-cdlatex-mode-map
"`" 'cdlatex-math-symbol
)
14878 (define-key org-cdlatex-mode-map
"'" 'org-cdlatex-math-modify
)
14879 (define-key org-cdlatex-mode-map
"\C-c{" 'cdlatex-environment
)
14881 (defvar org-cdlatex-texmathp-advice-is-done nil
14882 "Flag remembering if we have applied the advice to texmathp already.")
14884 (define-minor-mode org-cdlatex-mode
14885 "Toggle the minor `org-cdlatex-mode'.
14886 This mode supports entering LaTeX environment and math in LaTeX fragments
14888 \\{org-cdlatex-mode-map}"
14890 (when org-cdlatex-mode
(require 'cdlatex
))
14891 (unless org-cdlatex-texmathp-advice-is-done
14892 (setq org-cdlatex-texmathp-advice-is-done t
)
14893 (defadvice texmathp
(around org-math-always-on activate
)
14894 "Always return t in org-mode buffers.
14895 This is because we want to insert math symbols without dollars even outside
14896 the LaTeX math segments. If Orgmode thinks that point is actually inside
14897 en embedded LaTeX fragement, let texmathp do its job.
14898 \\[org-cdlatex-mode-map]"
14902 ((not (org-mode-p)) ad-do-it
)
14903 ((eq this-command
'cdlatex-math-symbol
)
14904 (setq ad-return-value t
14905 texmathp-why
'("cdlatex-math-symbol in org-mode" .
0)))
14907 (let ((p (org-inside-LaTeX-fragment-p)))
14908 (if (and p
(member (car p
) (plist-get org-format-latex-options
:matchers
)))
14909 (setq ad-return-value t
14910 texmathp-why
'("Org-mode embedded math" .
0))
14911 (if p ad-do-it
)))))))))
14913 (defun turn-on-org-cdlatex ()
14914 "Unconditionally turn on `org-cdlatex-mode'."
14915 (org-cdlatex-mode 1))
14917 (defun org-inside-LaTeX-fragment-p ()
14918 "Test if point is inside a LaTeX fragment.
14919 I.e. after a \\begin, \\(, \\[, $, or $$, without the corresponding closing
14920 sequence appearing also before point.
14921 Even though the matchers for math are configurable, this function assumes
14922 that \\begin, \\(, \\[, and $$ are always used. Only the single dollar
14923 delimiters are skipped when they have been removed by customization.
14924 The return value is nil, or a cons cell with the delimiter and
14925 and the position of this delimiter.
14927 This function does a reasonably good job, but can locally be fooled by
14928 for example currency specifications. For example it will assume being in
14929 inline math after \"$22.34\". The LaTeX fragment formatter will only format
14930 fragments that are properly closed, but during editing, we have to live
14931 with the uncertainty caused by missing closing delimiters. This function
14932 looks only before point, not after."
14934 (let ((pos (point))
14935 (dodollar (member "$" (plist-get org-format-latex-options
:matchers
)))
14937 (re-search-backward (concat "^\\(" paragraph-start
"\\)") nil t
)
14939 dd-on str
(start 0) m re
)
14942 (setq str
(concat (buffer-substring lim
(point)) "\000 X$.")
14943 re
(nth 1 (assoc "$" org-latex-regexps
)))
14944 (while (string-match re str start
)
14946 ((= (match-end 0) (length str
))
14947 (throw 'exit
(cons "$" (+ lim
(match-beginning 0)))))
14948 ((= (match-end 0) (- (length str
) 5))
14950 (t (setq start
(match-end 0))))))
14951 (when (setq m
(re-search-backward "\\(\\\\begin{[^}]*}\\|\\\\(\\|\\\\\\[\\)\\|\\(\\\\end{[^}]*}\\|\\\\)\\|\\\\\\]\\)\\|\\(\\$\\$\\)" lim t
))
14953 (and (match-beginning 1) (throw 'exit
(cons (match-string 1) m
)))
14954 (and (match-beginning 2) (throw 'exit nil
))
14956 (while (re-search-backward "\\$\\$" lim t
)
14957 (setq dd-on
(not dd-on
)))
14959 (if dd-on
(cons "$$" m
))))))
14962 (defun org-try-cdlatex-tab ()
14963 "Check if it makes sense to execute `cdlatex-tab', and do it if yes.
14964 It makes sense to do so if `org-cdlatex-mode' is active and if the cursor is
14965 - inside a LaTeX fragment, or
14966 - after the first word in a line, where an abbreviation expansion could
14967 insert a LaTeX environment."
14968 ;; FIXME: This may still need refinement.
14969 (when org-cdlatex-mode
14972 (skip-chars-backward "a-zA-Z0-9*")
14973 (skip-chars-backward " \t")
14976 ((org-inside-LaTeX-fragment-p)
14980 (defun org-cdlatex-underscore-caret (&optional arg
)
14981 "Execute `cdlatex-sub-superscript' in LaTeX fragments.
14982 Revert to the normal definition outside of these fragments."
14984 (if (org-inside-LaTeX-fragment-p)
14985 (call-interactively 'cdlatex-sub-superscript
)
14986 (let (org-cdlatex-mode)
14987 (call-interactively (key-binding (vector last-input-event
))))))
14989 (defun org-cdlatex-math-modify (&optional arg
)
14990 "Execute `cdlatex-math-modify' in LaTeX fragments.
14991 Revert to the normal definition outside of these fragments."
14993 (if (org-inside-LaTeX-fragment-p)
14994 (call-interactively 'cdlatex-math-modify
)
14995 (let (org-cdlatex-mode)
14996 (call-interactively (key-binding (vector last-input-event
))))))
14998 (defvar org-latex-fragment-image-overlays nil
14999 "List of overlays carrying the images of latex fragments.")
15000 (make-variable-buffer-local 'org-latex-fragment-image-overlays
)
15002 (defun org-remove-latex-fragment-image-overlays ()
15003 "Remove all overlays with LaTeX fragment images in current buffer."
15004 (mapc 'org-delete-overlay org-latex-fragment-image-overlays
)
15005 (setq org-latex-fragment-image-overlays nil
))
15007 (defun org-preview-latex-fragment (&optional subtree
)
15008 "Preview the LaTeX fragment at point, or all locally or globally.
15009 If the cursor is in a LaTeX fragment, create the image and overlay
15010 it over the source code. If there is no fragment at point, display
15011 all fragments in the current text, from one headline to the next. With
15012 prefix SUBTREE, display all fragments in the current subtree. With a
15013 double prefix `C-u C-u', or when the cursor is before the first headline,
15014 display all fragments in the buffer.
15015 The images can be removed again with \\[org-ctrl-c-ctrl-c]."
15017 (org-remove-latex-fragment-image-overlays)
15020 (let (beg end at msg
)
15022 ((or (equal subtree
'(16))
15023 (not (save-excursion
15024 (re-search-backward (concat "^" outline-regexp
) nil t
))))
15025 (setq beg
(point-min) end
(point-max)
15026 msg
"Creating images for buffer...%s"))
15027 ((equal subtree
'(4))
15028 (org-back-to-heading)
15029 (setq beg
(point) end
(org-end-of-subtree)
15030 msg
"Creating images for subtree...%s"))
15032 (if (setq at
(org-inside-LaTeX-fragment-p))
15033 (goto-char (max (point-min) (- (cdr at
) 2)))
15034 (org-back-to-heading))
15035 (setq beg
(point) end
(progn (outline-next-heading) (point))
15036 msg
(if at
"Creating image...%s"
15037 "Creating images for entry...%s"))))
15039 (narrow-to-region beg end
)
15041 (concat "ltxpng/" (file-name-sans-extension
15042 (file-name-nondirectory
15043 buffer-file-name
)))
15044 default-directory
'overlays msg at
)
15045 (message msg
"done. Use `C-c C-c' to remove images.")))))
15047 (defvar org-latex-regexps
15048 '(("begin" "^[ \t]*\\(\\\\begin{\\([a-zA-Z0-9\\*]+\\)[^\000]+?\\\\end{\\2}\\)" 1 t
)
15049 ;; ("$" "\\([ (]\\|^\\)\\(\\(\\([$]\\)\\([^ \r\n,.$].*?\\(\n.*?\\)\\{0,5\\}[^ \r\n,.$]\\)\\4\\)\\)\\([ .,?;:'\")]\\|$\\)" 2 nil)
15050 ;; \000 in the following regex is needed for org-inside-LaTeX-fragment-p
15051 ("$" "\\([^$]\\)\\(\\(\\$\\([^ \r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ \r\n,.$]\\)\\$\\)\\)\\([ .,?;:'\")\000]\\|$\\)" 2 nil
)
15052 ("\\(" "\\\\([^\000]*?\\\\)" 0 nil
)
15053 ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 t
)
15054 ("$$" "\\$\\$[^\000]*?\\$\\$" 0 t
))
15055 "Regular expressions for matching embedded LaTeX.")
15057 (defun org-format-latex (prefix &optional dir overlays msg at
)
15058 "Replace LaTeX fragments with links to an image, and produce images."
15059 (if (and overlays
(fboundp 'clear-image-cache
)) (clear-image-cache))
15060 (let* ((prefixnodir (file-name-nondirectory prefix
))
15061 (absprefix (expand-file-name prefix dir
))
15062 (todir (file-name-directory absprefix
))
15063 (opt org-format-latex-options
)
15064 (matchers (plist-get opt
:matchers
))
15065 (re-list org-latex-regexps
)
15066 (cnt 0) txt link beg end re e oldfiles
15067 m n block linkfile movefile ov
)
15068 ;; Make sure the directory exists
15069 (or (file-directory-p todir
) (make-directory todir
))
15070 ;; Check if there are old images files with this prefix, and remove them
15071 (setq oldfiles
(directory-files
15073 (concat (regexp-quote prefixnodir
) "_[0-9]+\\.png$")))
15074 (while oldfiles
(delete-file (pop oldfiles
)))
15075 ;; Check the different regular expressions
15076 (while (setq e
(pop re-list
))
15077 (setq m
(car e
) re
(nth 1 e
) n
(nth 2 e
)
15078 block
(if (nth 3 e
) "\n\n" ""))
15079 (when (member m matchers
)
15080 (goto-char (point-min))
15081 (while (re-search-forward re nil t
)
15082 (when (or (not at
) (equal (cdr at
) (match-beginning n
)))
15083 (setq txt
(match-string n
)
15084 beg
(match-beginning n
) end
(match-end n
)
15086 linkfile
(format "%s_%04d.png" prefix cnt
)
15087 movefile
(format "%s_%04d.png" absprefix cnt
)
15088 link
(concat block
"[[file:" linkfile
"]]" block
))
15089 (if msg
(message msg cnt
))
15091 (org-create-formula-image
15095 (setq ov
(org-make-overlay beg end
))
15096 (if (featurep 'xemacs
)
15098 (org-overlay-put ov
'invisible t
)
15101 (make-glyph (vector 'png
:file movefile
))))
15104 (list 'image
:type
'png
:file movefile
:ascent
'center
)))
15105 (push ov org-latex-fragment-image-overlays
)
15107 (delete-region beg end
)
15108 (insert link
))))))))
15110 ;; This function borrows from Ganesh Swami's latex2png.el
15111 (defun org-create-formula-image (string tofile options
)
15112 (let* ((tmpdir (if (featurep 'xemacs
)
15114 temporary-file-directory
))
15115 (texfilebase (make-temp-name
15116 (expand-file-name "orgtex" tmpdir
)))
15118 ;(texfilebase (make-temp-file "orgtex"))
15119 ; (dummy (delete-file texfilebase))
15120 (texfile (concat texfilebase
".tex"))
15121 (dvifile (concat texfilebase
".dvi"))
15122 (pngfile (concat texfilebase
".png"))
15123 (scale (number-to-string (* 1000 (or (plist-get options
:scale
) 1.0))))
15124 (fg (or (plist-get options
:foreground
) "Black"))
15125 (bg (or (plist-get options
:background
) "Transparent")))
15126 (with-temp-file texfile
15127 (insert "\\documentclass{article}
15128 \\usepackage{fullpage}
15129 \\usepackage{amssymb}
15130 \\usepackage[usenames]{color}
15131 \\usepackage{amsmath}
15132 \\usepackage{latexsym}
15133 \\usepackage[mathscr]{eucal}
15135 \\begin{document}\n" string
"\n\\end{document}\n"))
15136 (let ((dir default-directory
))
15137 (condition-case nil
15140 (call-process "latex" nil nil nil texfile
))
15143 (if (not (file-exists-p dvifile
))
15144 (progn (message "Failed to create dvi file from %s" texfile
) nil
)
15145 (call-process "dvipng" nil nil nil
15146 "-E" "-fg" fg
"-bg" bg
15147 "-x" scale
"-y" scale
"-T" "tight"
15150 (if (not (file-exists-p pngfile
))
15151 (progn (message "Failed to create png file from %s" texfile
) nil
)
15152 ;; Use the requested file name and clean up
15153 (copy-file pngfile tofile
'replace
)
15154 (loop for e in
'(".dvi" ".tex" ".aux" ".log" ".png") do
15155 (delete-file (concat texfilebase e
)))
15160 ;; - Bindings in Org-mode map are currently
15161 ;; 0123456789abcdefghijklmnopqrstuvwxyz!?@#$%^&-+*/=()_{}[]:;"|,.<>~`'\t the alphabet
15162 ;; abcd fgh j lmnopqrstuvwxyz!? #$ ^ -+*/= [] ; |,.<>~ '\t necessary bindings
15163 ;; e (?) useful from outline-mode
15164 ;; i k @ expendable from outline-mode
15165 ;; 0123456789 % & ()_{} " ` free
15167 ;; Make `C-c C-x' a prefix key
15168 (define-key org-mode-map
"\C-c\C-x" (make-sparse-keymap))
15170 ;; TAB key with modifiers
15171 (define-key org-mode-map
"\C-i" 'org-cycle
)
15172 (define-key org-mode-map
[(tab)] 'org-cycle
)
15173 (define-key org-mode-map
[(meta tab
)] 'org-complete
)
15174 (define-key org-mode-map
"\M-\C-i" 'org-complete
) ; for tty emacs
15175 ;; The following line is necessary under Suse GNU/Linux
15176 (unless (featurep 'xemacs
)
15177 (define-key org-mode-map
[S-iso-lefttab
] 'org-shifttab
))
15178 (define-key org-mode-map
[(shift tab
)] 'org-shifttab
)
15180 (define-key org-mode-map
(org-key 'S-return
) 'org-table-copy-down
)
15181 (define-key org-mode-map
"\C-c\C-xc" 'org-table-copy-down
) ; tty
15182 (define-key org-mode-map
[(meta shift return
)] 'org-insert-todo-heading
)
15183 (define-key org-mode-map
"\C-c\C-xM" 'org-insert-todo-heading
) ; tty
15184 (define-key org-mode-map
[(meta return
)] 'org-meta-return
)
15185 (define-key org-mode-map
"\C-c\C-xm" 'org-meta-return
) ; tty emacs
15186 (define-key org-mode-map
[?\e
(return)] 'org-meta-return
) ; tty emacs
15188 ;; Cursor keys with modifiers
15189 (define-key org-mode-map
[(meta left
)] 'org-metaleft
)
15190 (define-key org-mode-map
[?\e
(left)] 'org-metaleft
) ; for tty emacs
15191 (define-key org-mode-map
"\C-c\C-xl" 'org-metaleft
) ; for tty emacs
15192 (define-key org-mode-map
[(meta right
)] 'org-metaright
)
15193 (define-key org-mode-map
[?\e
(right)] 'org-metaright
) ; for tty emacs
15194 (define-key org-mode-map
"\C-c\C-xr" 'org-metaright
) ; for tty emacs
15195 (define-key org-mode-map
[(meta up
)] 'org-metaup
)
15196 (define-key org-mode-map
[?\e
(up)] 'org-metaup
) ; for tty emacs
15197 (define-key org-mode-map
"\C-c\C-xu" 'org-metaup
) ; for tty emacs
15198 (define-key org-mode-map
[(meta down
)] 'org-metadown
)
15199 (define-key org-mode-map
[?\e
(down)] 'org-metadown
) ; for tty emacs
15200 (define-key org-mode-map
"\C-c\C-xd" 'org-metadown
) ; for tty emacs
15202 (define-key org-mode-map
[(meta shift left
)] 'org-shiftmetaleft
)
15203 (define-key org-mode-map
"\C-c\C-xL" 'org-shiftmetaleft
) ; tty
15204 (define-key org-mode-map
[(meta shift right
)] 'org-shiftmetaright
)
15205 (define-key org-mode-map
"\C-c\C-xR" 'org-shiftmetaright
) ; tty
15206 (define-key org-mode-map
[(meta shift up
)] 'org-shiftmetaup
)
15207 (define-key org-mode-map
"\C-c\C-xU" 'org-shiftmetaup
) ; tty
15208 (define-key org-mode-map
[(meta shift down
)] 'org-shiftmetadown
)
15209 (define-key org-mode-map
"\C-c\C-xD" 'org-shiftmetadown
) ; tty
15210 (define-key org-mode-map
(org-key 'S-up
) 'org-shiftup
)
15211 (define-key org-mode-map
[?\C-c ?\C-x
(up)] 'org-shiftup
)
15212 (define-key org-mode-map
(org-key 'S-down
) 'org-shiftdown
)
15213 (define-key org-mode-map
[?\C-c ?\C-x
(down)] 'org-shiftdown
)
15214 (define-key org-mode-map
(org-key 'S-left
) 'org-shiftleft
)
15215 (define-key org-mode-map
[?\C-c ?\C-x
(left)] 'org-shiftleft
)
15216 (define-key org-mode-map
(org-key 'S-right
) 'org-shiftright
)
15217 (define-key org-mode-map
[?\C-c ?\C-x
(right)] 'org-shiftright
)
15219 ;; All the other keys
15221 (define-key org-mode-map
"\C-c\C-a" 'show-all
) ; in case allout messed up.
15222 (define-key org-mode-map
"\C-xns" 'org-narrow-to-subtree
)
15223 (define-key org-mode-map
"\C-c$" 'org-archive-subtree
)
15224 (define-key org-mode-map
"\C-c\C-x\C-a" 'org-toggle-archive-tag
)
15225 (define-key org-mode-map
"\C-c\C-j" 'org-goto
)
15226 (define-key org-mode-map
"\C-c\C-t" 'org-todo
)
15227 (define-key org-mode-map
"\C-c\C-s" 'org-schedule
)
15228 (define-key org-mode-map
"\C-c\C-d" 'org-deadline
)
15229 (define-key org-mode-map
"\C-c;" 'org-toggle-comment
)
15230 (define-key org-mode-map
"\C-c\C-v" 'org-show-todo-tree
)
15231 (define-key org-mode-map
"\C-c\C-w" 'org-check-deadlines
)
15232 (define-key org-mode-map
"\C-c/" 'org-occur
) ; Minor-mode reserved
15233 (define-key org-mode-map
"\C-c\\" 'org-tags-sparse-tree
) ; Minor-mode res.
15234 (define-key org-mode-map
"\C-c\C-m" 'org-insert-heading
)
15235 (define-key org-mode-map
"\M-\C-m" 'org-insert-heading
)
15236 (define-key org-mode-map
"\C-c\C-l" 'org-insert-link
)
15237 (define-key org-mode-map
"\C-c\C-o" 'org-open-at-point
)
15238 (define-key org-mode-map
"\C-c%" 'org-mark-ring-push
)
15239 (define-key org-mode-map
"\C-c&" 'org-mark-ring-goto
)
15240 (define-key org-mode-map
"\C-c\C-z" 'org-time-stamp
) ; Alternative binding
15241 (define-key org-mode-map
"\C-c." 'org-time-stamp
) ; Minor-mode reserved
15242 (define-key org-mode-map
"\C-c!" 'org-time-stamp-inactive
) ; Minor-mode r.
15243 (define-key org-mode-map
"\C-c," 'org-priority
) ; Minor-mode reserved
15244 (define-key org-mode-map
"\C-c\C-y" 'org-evaluate-time-range
)
15245 (define-key org-mode-map
"\C-c>" 'org-goto-calendar
)
15246 (define-key org-mode-map
"\C-c<" 'org-date-from-calendar
)
15247 (define-key org-mode-map
[(control ?
,)] 'org-cycle-agenda-files
)
15248 (define-key org-mode-map
"\C-c[" 'org-agenda-file-to-front
)
15249 (define-key org-mode-map
"\C-c]" 'org-remove-file
)
15250 (define-key org-mode-map
"\C-c\C-r" 'org-timeline
)
15251 (define-key org-mode-map
"\C-c-" 'org-table-insert-hline
)
15252 (define-key org-mode-map
"\C-c^" 'org-table-sort-lines
)
15253 (define-key org-mode-map
"\C-c\C-c" 'org-ctrl-c-ctrl-c
)
15254 (define-key org-mode-map
"\C-m" 'org-return
)
15255 (define-key org-mode-map
"\C-c?" 'org-table-current-column
)
15256 (define-key org-mode-map
"\C-c " 'org-table-blank-field
)
15257 (define-key org-mode-map
"\C-c+" 'org-table-sum
)
15258 (define-key org-mode-map
"\C-c=" 'org-table-eval-formula
)
15259 (define-key org-mode-map
"\C-c'" 'org-table-edit-formulas
)
15260 (define-key org-mode-map
"\C-c`" 'org-table-edit-field
)
15261 (define-key org-mode-map
"\C-c|" 'org-table-create-or-convert-from-region
)
15262 (define-key org-mode-map
"\C-c*" 'org-table-recalculate
)
15263 (define-key org-mode-map
[(control ?
#)] 'org-table-rotate-recalc-marks
)
15264 (define-key org-mode-map
"\C-c~" 'org-table-create-with-table.el
)
15265 (define-key org-mode-map
"\C-c\C-q" 'org-table-wrap-region
)
15266 (define-key org-mode-map
"\C-c\C-e" 'org-export
)
15267 (define-key org-mode-map
"\C-c:" 'org-toggle-fixed-width-section
)
15269 (define-key org-mode-map
"\C-c\C-x\C-k" 'org-cut-special
)
15270 (define-key org-mode-map
"\C-c\C-x\C-w" 'org-cut-special
)
15271 (define-key org-mode-map
"\C-c\C-x\M-w" 'org-copy-special
)
15272 (define-key org-mode-map
"\C-c\C-x\C-y" 'org-paste-special
)
15274 (define-key org-mode-map
"\C-c\C-x\C-i" 'org-clock-in
)
15275 (define-key org-mode-map
"\C-c\C-x\C-o" 'org-clock-out
)
15276 (define-key org-mode-map
"\C-c\C-x\C-x" 'org-clock-cancel
)
15277 (define-key org-mode-map
"\C-c\C-x\C-d" 'org-clock-display
)
15278 (define-key org-mode-map
"\C-c\C-x\C-r" 'org-clock-report
)
15279 (define-key org-mode-map
"\C-c\C-x\C-u" 'org-dblock-update
)
15280 (define-key org-mode-map
"\C-c\C-x\C-l" 'org-preview-latex-fragment
)
15281 (define-key org-mode-map
"\C-c\C-x\C-b" 'org-toggle-checkbox
)
15283 (when (featurep 'xemacs
)
15284 (define-key org-mode-map
'button3
'popup-mode-menu
))
15286 (defsubst org-table-p
() (org-at-table-p))
15288 (defun org-self-insert-command (N)
15289 "Like `self-insert-command', use overwrite-mode for whitespace in tables.
15290 If the cursor is in a table looking at whitespace, the whitespace is
15291 overwritten, and the table is not marked as requiring realignment."
15293 (if (and (org-table-p)
15295 ;; check if we blank the field, and if that triggers align
15296 (and org-table-auto-blank-field
15297 (member last-command
15298 '(org-cycle org-return org-shifttab org-ctrl-c-ctrl-c
))
15299 (if (or (equal (char-after) ?\
) (looking-at "[^|\n]* |"))
15300 ;; got extra space, this field does not determine column width
15301 (let (org-table-may-need-update) (org-table-blank-field))
15302 ;; no extra space, this field may determine column width
15303 (org-table-blank-field)))
15306 (looking-at "[^|\n]* |"))
15307 (let (org-table-may-need-update)
15308 (goto-char (1- (match-end 0)))
15309 (delete-backward-char 1)
15310 (goto-char (match-beginning 0))
15311 (self-insert-command N
))
15312 (setq org-table-may-need-update t
)
15313 (self-insert-command N
)))
15315 (defun org-delete-backward-char (N)
15316 "Like `delete-backward-char', insert whitespace at field end in tables.
15317 When deleting backwards, in tables this function will insert whitespace in
15318 front of the next \"|\" separator, to keep the table aligned. The table will
15319 still be marked for re-alignment if the field did fill the entire column,
15320 because, in this case the deletion might narrow the column."
15322 (if (and (org-table-p)
15324 (string-match "|" (buffer-substring (point-at-bol) (point)))
15325 (looking-at ".*?|"))
15326 (let ((pos (point))
15327 (noalign (looking-at "[^|\n\r]* |"))
15328 (c org-table-may-need-update
))
15329 (backward-delete-char N
)
15330 (skip-chars-forward "^|")
15332 (goto-char (1- pos
))
15333 ;; noalign: if there were two spaces at the end, this field
15334 ;; does not determine the width of the column.
15335 (if noalign
(setq org-table-may-need-update c
)))
15336 (backward-delete-char N
)))
15338 (defun org-delete-char (N)
15339 "Like `delete-char', but insert whitespace at field end in tables.
15340 When deleting characters, in tables this function will insert whitespace in
15341 front of the next \"|\" separator, to keep the table aligned. The table will
15342 still be marked for re-alignment if the field did fill the entire column,
15343 because, in this case the deletion might narrow the column."
15345 (if (and (org-table-p)
15347 (not (= (char-after) ?|
))
15349 (if (looking-at ".*?|")
15350 (let ((pos (point))
15351 (noalign (looking-at "[^|\n\r]* |"))
15352 (c org-table-may-need-update
))
15353 (replace-match (concat
15354 (substring (match-string 0) 1 -
1)
15357 ;; noalign: if there were two spaces at the end, this field
15358 ;; does not determine the width of the column.
15359 (if noalign
(setq org-table-may-need-update c
)))
15363 ;; How to do this: Measure non-white length of current string
15364 ;; If equal to column width, we should realign.
15366 (defun org-remap (map &rest commands
)
15367 "In MAP, remap the functions given in COMMANDS.
15368 COMMANDS is a list of alternating OLDDEF NEWDEF command names."
15371 (setq old
(pop commands
) new
(pop commands
))
15372 (if (fboundp 'command-remapping
)
15373 (define-key map
(vector 'remap old
) new
)
15374 (substitute-key-definition old new map global-map
)))))
15376 (when (eq org-enable-table-editor
'optimized
)
15377 ;; If the user wants maximum table support, we need to hijack
15378 ;; some standard editing functions
15379 (org-remap org-mode-map
15380 'self-insert-command
'org-self-insert-command
15381 'delete-char
'org-delete-char
15382 'delete-backward-char
'org-delete-backward-char
)
15383 (define-key org-mode-map
"|" 'org-force-self-insert
))
15385 (defun org-shiftcursor-error ()
15386 "Throw an error because Shift-Cursor command was applied in wrong context."
15387 (error "This command is active in special context like tables, headlines or timestamps"))
15389 (defun org-shifttab (&optional arg
)
15390 "Global visibility cycling or move to previous table field.
15391 Calls `org-cycle' with argument t, or `org-table-previous-field', depending
15393 See the individual commands for more information."
15396 ((org-at-table-p) (call-interactively 'org-table-previous-field
))
15397 (t (call-interactively 'org-global-cycle
))))
15399 (defun org-shiftmetaleft ()
15400 "Promote subtree or delete table column.
15401 Calls `org-promote-subtree' or `org-table-delete-column', depending on context.
15402 See the individual commands for more information."
15405 ((org-at-table-p) (call-interactively 'org-table-delete-column
))
15406 ((org-on-heading-p) (call-interactively 'org-promote-subtree
))
15407 ((org-at-item-p) (call-interactively 'org-outdent-item
))
15408 (t (org-shiftcursor-error))))
15410 (defun org-shiftmetaright ()
15411 "Demote subtree or insert table column.
15412 Calls `org-demote-subtree' or `org-table-insert-column', depending on context.
15413 See the individual commands for more information."
15416 ((org-at-table-p) (call-interactively 'org-table-insert-column
))
15417 ((org-on-heading-p) (call-interactively 'org-demote-subtree
))
15418 ((org-at-item-p) (call-interactively 'org-indent-item
))
15419 (t (org-shiftcursor-error))))
15421 (defun org-shiftmetaup (&optional arg
)
15422 "Move subtree up or kill table row.
15423 Calls `org-move-subtree-up' or `org-table-kill-row' or
15424 `org-move-item-up' depending on context. See the individual commands
15425 for more information."
15428 ((org-at-table-p) (call-interactively 'org-table-kill-row
))
15429 ((org-on-heading-p) (call-interactively 'org-move-subtree-up
))
15430 ((org-at-item-p) (call-interactively 'org-move-item-up
))
15431 (t (org-shiftcursor-error))))
15432 (defun org-shiftmetadown (&optional arg
)
15433 "Move subtree down or insert table row.
15434 Calls `org-move-subtree-down' or `org-table-insert-row' or
15435 `org-move-item-down', depending on context. See the individual
15436 commands for more information."
15439 ((org-at-table-p) (call-interactively 'org-table-insert-row
))
15440 ((org-on-heading-p) (call-interactively 'org-move-subtree-down
))
15441 ((org-at-item-p) (call-interactively 'org-move-item-down
))
15442 (t (org-shiftcursor-error))))
15444 (defun org-metaleft (&optional arg
)
15445 "Promote heading or move table column to left.
15446 Calls `org-do-promote' or `org-table-move-column', depending on context.
15447 With no specific context, calls the Emacs default `backward-word'.
15448 See the individual commands for more information."
15451 ((org-at-table-p) (org-call-with-arg 'org-table-move-column
'left
))
15452 ((or (org-on-heading-p) (org-region-active-p))
15453 (call-interactively 'org-do-promote
))
15454 (t (call-interactively 'backward-word
))))
15456 (defun org-metaright (&optional arg
)
15457 "Demote subtree or move table column to right.
15458 Calls `org-do-demote' or `org-table-move-column', depending on context.
15459 With no specific context, calls the Emacs default `forward-word'.
15460 See the individual commands for more information."
15463 ((org-at-table-p) (call-interactively 'org-table-move-column
))
15464 ((or (org-on-heading-p) (org-region-active-p))
15465 (call-interactively 'org-do-demote
))
15466 (t (call-interactively 'forward-word
))))
15468 (defun org-metaup (&optional arg
)
15469 "Move subtree up or move table row up.
15470 Calls `org-move-subtree-up' or `org-table-move-row' or
15471 `org-move-item-up', depending on context. See the individual commands
15472 for more information."
15475 ((org-at-table-p) (org-call-with-arg 'org-table-move-row
'up
))
15476 ((org-on-heading-p) (call-interactively 'org-move-subtree-up
))
15477 ((org-at-item-p) (call-interactively 'org-move-item-up
))
15478 (t (org-shiftcursor-error))))
15480 (defun org-metadown (&optional arg
)
15481 "Move subtree down or move table row down.
15482 Calls `org-move-subtree-down' or `org-table-move-row' or
15483 `org-move-item-down', depending on context. See the individual
15484 commands for more information."
15487 ((org-at-table-p) (call-interactively 'org-table-move-row
))
15488 ((org-on-heading-p) (call-interactively 'org-move-subtree-down
))
15489 ((org-at-item-p) (call-interactively 'org-move-item-down
))
15490 (t (org-shiftcursor-error))))
15492 (defun org-shiftup (&optional arg
)
15493 "Increase item in timestamp or increase priority of current headline.
15494 Calls `org-timestamp-up' or `org-priority-up', depending on context.
15495 See the individual commands for more information."
15498 ((org-at-timestamp-p t
) (call-interactively 'org-timestamp-up
))
15499 ((org-on-heading-p) (call-interactively 'org-priority-up
))
15500 ((org-at-item-p) (call-interactively 'org-previous-item
))
15501 (t (call-interactively 'org-beginning-of-item
) (beginning-of-line 1))))
15503 (defun org-shiftdown (&optional arg
)
15504 "Decrease item in timestamp or decrease priority of current headline.
15505 Calls `org-timestamp-down' or `org-priority-down', depending on context.
15506 See the individual commands for more information."
15509 ((org-at-timestamp-p t
) (call-interactively 'org-timestamp-down
))
15510 ((org-on-heading-p) (call-interactively 'org-priority-down
))
15511 (t (call-interactively 'org-next-item
))))
15513 (defun org-shiftright ()
15514 "Next TODO keyword or timestamp one day later, depending on context."
15517 ((org-at-timestamp-p t
) (call-interactively 'org-timestamp-up-day
))
15518 ((org-on-heading-p) (org-call-with-arg 'org-todo
'right
))
15519 (t (org-shiftcursor-error))))
15521 (defun org-shiftleft ()
15522 "Previous TODO keyword or timestamp one day earlier, depending on context."
15525 ((org-at-timestamp-p t
) (call-interactively 'org-timestamp-down-day
))
15526 ((org-on-heading-p) (org-call-with-arg 'org-todo
'left
))
15527 (t (org-shiftcursor-error))))
15529 (defun org-copy-special ()
15530 "Copy region in table or copy current subtree.
15531 Calls `org-table-copy' or `org-copy-subtree', depending on context.
15532 See the individual commands for more information."
15534 (call-interactively
15535 (if (org-at-table-p) 'org-table-copy-region
'org-copy-subtree
)))
15537 (defun org-cut-special ()
15538 "Cut region in table or cut current subtree.
15539 Calls `org-table-copy' or `org-cut-subtree', depending on context.
15540 See the individual commands for more information."
15542 (call-interactively
15543 (if (org-at-table-p) 'org-table-cut-region
'org-cut-subtree
)))
15545 (defun org-paste-special (arg)
15546 "Paste rectangular region into table, or past subtree relative to level.
15547 Calls `org-table-paste-rectangle' or `org-paste-subtree', depending on context.
15548 See the individual commands for more information."
15550 (if (org-at-table-p)
15551 (org-table-paste-rectangle)
15552 (org-paste-subtree arg
)))
15554 (defun org-ctrl-c-ctrl-c (&optional arg
)
15555 "Set tags in headline, or update according to changed information at point.
15557 This command does many different things, depending on context:
15559 - If the cursor is in a headline, prompt for tags and insert them
15560 into the current line, aligned to `org-tags-column'. When called
15561 with prefix arg, realign all tags in the current buffer.
15563 - If the cursor is in one of the special #+KEYWORD lines, this
15564 triggers scanning the buffer for these lines and updating the
15567 - If the cursor is inside a table, realign the table. This command
15568 works even if the automatic table editor has been turned off.
15570 - If the cursor is on a #+TBLFM line, re-apply the formulas to
15573 - If the cursor is inside a table created by the table.el package,
15574 activate that table.
15576 - If the current buffer is a remember buffer, close note and file it.
15577 with a prefix argument, file it without further interaction to the default
15580 - If the cursor is on a <<<target>>>, update radio targets and corresponding
15581 links in this buffer.
15583 - If the cursor is on a numbered item in a plain list, renumber the
15586 (let ((org-enable-table-editor t
))
15588 ((or org-clock-overlays org-occur-highlights
15589 org-latex-fragment-image-overlays
)
15590 (org-remove-clock-overlays)
15591 (org-remove-occur-highlights)
15592 (org-remove-latex-fragment-image-overlays)
15593 (message "Temporary highlights/overlays removed from current buffer"))
15594 ((and (local-variable-p 'org-finish-function
(current-buffer))
15595 (fboundp org-finish-function
))
15596 (funcall org-finish-function
))
15597 ((org-on-target-p) (call-interactively 'org-update-radio-target-regexp
))
15598 ((org-on-heading-p) (call-interactively 'org-set-tags
))
15599 ((org-at-table.el-p
)
15601 (beginning-of-line 1)
15602 (re-search-forward "|" (save-excursion (end-of-line 2) (point)))
15603 (call-interactively 'table-recognize-table
))
15605 (org-table-maybe-eval-formula)
15607 (call-interactively 'org-table-recalculate
)
15608 (org-table-maybe-recalculate-line))
15609 (call-interactively 'org-table-align
))
15610 ((org-at-item-checkbox-p)
15611 (call-interactively 'org-toggle-checkbox
))
15613 (call-interactively 'org-renumber-ordered-list
))
15614 ((save-excursion (beginning-of-line 1) (looking-at "#\\+\\([A-Z]+\\)"))
15616 ((equal (match-string 1) "TBLFM")
15617 ;; Recalculate the table before this line
15619 (beginning-of-line 1)
15620 (skip-chars-backward " \r\n\t")
15621 (if (org-at-table-p)
15622 (org-call-with-arg 'org-table-recalculate t
))))
15624 (call-interactively 'org-mode-restart
))))
15625 (t (error "C-c C-c can do nothing useful at this location.")))))
15627 (defun org-mode-restart ()
15628 "Restart Org-mode, to scan again for special lines.
15629 Also updates the keyword regular expressions."
15631 (let ((org-inhibit-startup t
)) (org-mode))
15632 (message "Org-mode restarted to refresh keyword and special line setup"))
15634 (defun org-return ()
15635 "Goto next table row or insert a newline.
15636 Calls `org-table-next-row' or `newline', depending on context.
15637 See the individual commands for more information."
15641 (org-table-justify-field-maybe)
15642 (call-interactively 'org-table-next-row
))
15645 (defun org-meta-return (&optional arg
)
15646 "Insert a new heading or wrap a region in a table.
15647 Calls `org-insert-heading' or `org-table-wrap-region', depending on context.
15648 See the individual commands for more information."
15652 (call-interactively 'org-table-wrap-region
))
15653 (t (call-interactively 'org-insert-heading
))))
15657 ;; Define the Org-mode menus
15658 (easy-menu-define org-tbl-menu org-mode-map
"Tbl menu"
15660 ["Align" org-ctrl-c-ctrl-c
(org-at-table-p)]
15661 ["Next Field" org-cycle
(org-at-table-p)]
15662 ["Previous Field" org-shifttab
(org-at-table-p)]
15663 ["Next Row" org-return
(org-at-table-p)]
15665 ["Blank Field" org-table-blank-field
(org-at-table-p)]
15666 ["Edit Field" org-table-edit-field
(org-at-table-p)]
15667 ["Copy Field from Above" org-table-copy-down
(org-at-table-p)]
15670 ["Move Column Left" org-metaleft
(org-at-table-p)]
15671 ["Move Column Right" org-metaright
(org-at-table-p)]
15672 ["Delete Column" org-shiftmetaleft
(org-at-table-p)]
15673 ["Insert Column" org-shiftmetaright
(org-at-table-p)]
15675 ["Enable Narrowing" (setq org-table-limit-column-width
(not org-table-limit-column-width
)) :active
(org-at-table-p) :selected org-table-limit-column-width
:style toggle
])
15677 ["Move Row Up" org-metaup
(org-at-table-p)]
15678 ["Move Row Down" org-metadown
(org-at-table-p)]
15679 ["Delete Row" org-shiftmetaup
(org-at-table-p)]
15680 ["Insert Row" org-shiftmetadown
(org-at-table-p)]
15681 ["Sort lines in region" org-table-sort-lines
(org-at-table-p)]
15683 ["Insert Hline" org-table-insert-hline
(org-at-table-p)])
15685 ["Copy Rectangle" org-copy-special
(org-at-table-p)]
15686 ["Cut Rectangle" org-cut-special
(org-at-table-p)]
15687 ["Paste Rectangle" org-paste-special
(org-at-table-p)]
15688 ["Fill Rectangle" org-table-wrap-region
(org-at-table-p)])
15691 ["Set Column Formula" org-table-eval-formula
(org-at-table-p)]
15692 ["Set Named Field Formula" (org-table-eval-formula '(4)) :active
(org-at-table-p) :keys
"C-u C-c ="]
15693 ["Edit Formulas" org-table-edit-formulas
(org-at-table-p)]
15695 ["Recalculate line" org-table-recalculate
(org-at-table-p)]
15696 ["Recalculate all" (lambda () (interactive) (org-table-recalculate '(4))) :active
(org-at-table-p) :keys
"C-u C-c *"]
15697 ["Toggle Recalculate Mark" org-table-rotate-recalc-marks
(org-at-table-p)]
15699 ["Sum Column/Rectangle" org-table-sum
15700 (or (org-at-table-p) (org-region-active-p))]
15701 ["Which Column?" org-table-current-column
(org-at-table-p)])
15703 (setq org-table-formula-debug
(not org-table-formula-debug
))
15704 :style toggle
:selected org-table-formula-debug
]
15706 ["Create" org-table-create
(and (not (org-at-table-p))
15707 org-enable-table-editor
)]
15708 ["Convert Region" org-table-convert-region
(not (org-at-table-p 'any
))]
15709 ["Import from File" org-table-import
(not (org-at-table-p))]
15710 ["Export to File" org-table-export
(org-at-table-p)]
15712 ["Create/Convert from/to table.el" org-table-create-with-table.el t
]))
15714 (easy-menu-define org-org-menu org-mode-map
"Org menu"
15716 ["Cycle Visibility" org-cycle
(or (bobp) (outline-on-heading-p))]
15717 ["Cycle Global Visibility" org-shifttab
(not (org-at-table-p))]
15718 ["Sparse Tree" org-occur t
]
15719 ["Show All" show-all t
]
15721 ["New Heading" org-insert-heading t
]
15722 ("Navigate Headings"
15723 ["Up" outline-up-heading t
]
15724 ["Next" outline-next-visible-heading t
]
15725 ["Previous" outline-previous-visible-heading t
]
15726 ["Next Same Level" outline-forward-same-level t
]
15727 ["Previous Same Level" outline-backward-same-level t
]
15729 ["Jump" org-goto t
])
15731 ["Move Subtree Up" org-shiftmetaup
(not (org-at-table-p))]
15732 ["Move Subtree Down" org-shiftmetadown
(not (org-at-table-p))]
15734 ["Copy Subtree" org-copy-special
(not (org-at-table-p))]
15735 ["Cut Subtree" org-cut-special
(not (org-at-table-p))]
15736 ["Paste Subtree" org-paste-special
(not (org-at-table-p))]
15738 ["Promote Heading" org-metaleft
(not (org-at-table-p))]
15739 ["Promote Subtree" org-shiftmetaleft
(not (org-at-table-p))]
15740 ["Demote Heading" org-metaright
(not (org-at-table-p))]
15741 ["Demote Subtree" org-shiftmetaright
(not (org-at-table-p))]
15743 ["Convert to odd levels" org-convert-to-odd-levels t
]
15744 ["Convert to odd/even levels" org-convert-to-oddeven-levels t
])
15746 ["Toggle ARCHIVE tag" org-toggle-archive-tag t
]
15747 ["Check and Tag Children" (org-toggle-archive-tag (4))
15748 :active t
:keys
"C-u C-c C-x C-a"]
15749 ["Sparse trees open ARCHIVE trees"
15750 (setq org-sparse-tree-open-archived-trees
15751 (not org-sparse-tree-open-archived-trees
))
15752 :style toggle
:selected org-sparse-tree-open-archived-trees
]
15753 ["Cycling opens ARCHIVE trees"
15754 (setq org-cycle-open-archived-trees
(not org-cycle-open-archived-trees
))
15755 :style toggle
:selected org-cycle-open-archived-trees
]
15756 ["Agenda includes ARCHIVE trees"
15757 (setq org-agenda-skip-archived-trees
(not org-agenda-skip-archived-trees
))
15758 :style toggle
:selected
(not org-agenda-skip-archived-trees
)]
15760 ["Move Subtree to Archive" org-archive-subtree t
]
15761 ["Check and Move Children" (org-archive-subtree '(4))
15762 :active t
:keys
"C-u C-c $"])
15765 ["TODO/DONE/-" org-todo t
]
15766 ["Show TODO Tree" org-show-todo-tree t
]
15767 ["Global TODO list" org-todo-list t
]
15769 ["Set Priority" org-priority t
]
15770 ["Priority Up" org-shiftup t
]
15771 ["Priority Down" org-shiftdown t
])
15772 ("Dates and Scheduling"
15773 ["Timestamp" org-time-stamp t
]
15774 ["Timestamp (inactive)" org-time-stamp-inactive t
]
15776 ["1 Day Later" org-timestamp-up-day t
]
15777 ["1 Day Earlier" org-timestamp-down-day t
]
15778 ["1 ... Later" org-shiftup t
]
15779 ["1 ... Earlier" org-shiftdown t
])
15780 ["Compute Time Range" org-evaluate-time-range t
]
15781 ["Schedule Item" org-schedule t
]
15782 ["Deadline" org-deadline t
]
15784 ["Goto Calendar" org-goto-calendar t
]
15785 ["Date from Calendar" org-date-from-calendar t
])
15787 ["Clock in" org-clock-in t
]
15788 ["Clock out" org-clock-out t
]
15789 ["Clock cancel" org-clock-cancel t
]
15790 ["Display times" org-clock-display t
]
15791 ["Create clock table" org-clock-report t
]
15793 ["Record DONE time"
15794 (progn (setq org-log-done
(not org-log-done
))
15795 (message "Switching to %s will %s record a timestamp"
15797 (if org-log-done
"automatically" "not")))
15798 :style toggle
:selected org-log-done
])
15800 ["Agenda Command" org-agenda t
]
15801 ("File List for Agenda")
15802 ("Special views current file"
15803 ["TODO Tree" org-show-todo-tree t
]
15804 ["Check Deadlines" org-check-deadlines t
]
15805 ["Timeline" org-timeline t
]
15806 ["Tags Tree" org-tags-sparse-tree t
])
15809 ["Store Link (Global)" org-store-link t
]
15810 ["Insert Link" org-insert-link t
]
15811 ["Follow Link" org-open-at-point t
]
15813 ["Descriptive Links"
15814 (progn (org-add-to-invisibility-spec '(org-link)) (org-restart-font-lock))
15815 :style radio
:selected
(member '(org-link) buffer-invisibility-spec
)]
15818 (org-remove-from-invisibility-spec '(org-link)) (org-restart-font-lock))
15819 :style radio
:selected
(not (member '(org-link) buffer-invisibility-spec
))]
15821 ["Upgrade all <link> to [[link][desc]]" org-upgrade-old-links
15822 (save-excursion (goto-char (point-min))
15823 (re-search-forward "<[a-z]+:" nil t
))])
15825 ["Export/Publish" org-export t
]
15827 ["Org CDLaTeX mode" org-cdlatex-mode
:style toggle
15828 :selected org-cdlatex-mode
]
15829 ["Insert Environment" cdlatex-environment
(fboundp 'cdlatex-environment
)]
15830 ["Insert math symbol" cdlatex-math-symbol
(fboundp 'cdlatex-math-symbol
)]
15831 ["Modify math symbol" org-cdlatex-math-modify
15832 (org-inside-LaTeX-fragment-p)]
15833 ["Export LaTeX fragments as images"
15834 (setq org-export-with-LaTeX-fragments
(not org-export-with-LaTeX-fragments
))
15835 :style toggle
:selected org-export-with-LaTeX-fragments
])
15838 ["Show Version" org-version t
]
15839 ["Info Documentation" org-info t
])
15841 ["Browse Org Group" org-customize t
]
15843 ["Expand This Menu" org-create-customize-menu
15844 (fboundp 'customize-menu-create
)])
15846 ["Refresh setup" org-mode-restart t
]
15849 (defun org-info (&optional node
)
15850 "Read documentation for Org-mode in the info system.
15851 With optional NODE, go directly to that node."
15854 (Info-goto-node (format "(org)%s" (or node
""))))
15856 (defun org-install-agenda-files-menu ()
15857 (let ((bl (buffer-list)))
15860 (set-buffer (pop bl
))
15861 (if (org-mode-p) (setq bl nil
)))
15864 '("Org") "File List for Agenda"
15867 ["Edit File List" (org-edit-agenda-file-list) t
]
15868 ["Add/Move Current File to Front of List" org-agenda-file-to-front t
]
15869 ["Remove Current File from List" org-remove-file t
]
15870 ["Cycle through agenda files" org-cycle-agenda-files t
]
15872 (mapcar 'org-file-menu-entry
(org-agenda-files t
))))))))
15876 (defun org-customize ()
15877 "Call the customize function with org as argument."
15879 (customize-browse 'org
))
15881 (defun org-create-customize-menu ()
15882 "Create a full customization menu for Org-mode, insert it into the menu."
15884 (if (fboundp 'customize-menu-create
)
15887 '("Org") "Customize"
15888 `(["Browse Org group" org-customize t
]
15890 ,(customize-menu-create 'org
)
15891 ["Set" Custom-set t
]
15892 ["Save" Custom-save t
]
15893 ["Reset to Current" Custom-reset-current t
]
15894 ["Reset to Saved" Custom-reset-saved t
]
15895 ["Reset to Standard Settings" Custom-reset-standard t
]))
15896 (message "\"Org\"-menu now contains full customization menu"))
15897 (error "Cannot expand menu (outdated version of cus-edit.el)")))
15899 ;;; Miscellaneous stuff
15901 (defun org-context ()
15902 "Return a list of contexts of the current cursor position.
15903 If several contexts apply, all are returned.
15904 Each context entry is a list with a symbol naming the context, and
15905 two positions indicating start and end of the context. Possible
15908 :headline anywhere in a headline
15909 :headline-stars on the leading stars in a headline
15910 :todo-keyword on a TODO keyword (including DONE) in a headline
15911 :tags on the TAGS in a headline
15912 :priority on the priority cookie in a headline
15913 :item on the first line of a plain list item
15914 :item-bullet on the bullet/number of a plain list item
15915 :checkbox on the checkbox in a plain list item
15916 :table in an org-mode table
15917 :table-special on a special filed in a table
15918 :table-table in a table.el table
15919 :link on a hyperline
15920 :keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE.
15921 :target on a <<target>>
15922 :radio-target on a <<<radio-target>>>
15923 :latex-fragment on a LaTeX fragment
15924 :latex-preview on a LaTeX fragment with overlayed preview image
15926 This function expects the position to be visible because it uses font-lock
15927 faces as a help to recognize the following contexts: :table-special, :link,
15929 (let* ((f (get-text-property (point) 'face
))
15930 (faces (if (listp f
) f
(list f
)))
15931 (p (point)) clist o
)
15932 ;; First the large context
15934 ((org-on-heading-p)
15935 (push (list :headline
(point-at-bol) (point-at-eol)) clist
)
15937 (beginning-of-line 1)
15938 (looking-at org-todo-line-tags-regexp
))
15939 (push (org-point-in-group p
1 :headline-stars
) clist
)
15940 (push (org-point-in-group p
2 :todo-keyword
) clist
)
15941 (push (org-point-in-group p
4 :tags
) clist
))
15943 (skip-chars-backward "^[\n\r \t") (or (eobp) (backward-char 1))
15944 (if (looking-at "\\[#[A-Z]\\]")
15945 (push (org-point-in-group p
0 :priority
) clist
)))
15948 (push (org-point-in-group p
2 :item-bullet
) clist
)
15949 (push (list :item
(point-at-bol)
15950 (save-excursion (org-end-of-item) (point)))
15952 (and (org-at-item-checkbox-p)
15953 (push (org-point-in-group p
0 :checkbox
) clist
)))
15956 (push (list :table
(org-table-begin) (org-table-end)) clist
)
15957 (if (memq 'org-formula faces
)
15958 (push (list :table-special
15959 (previous-single-property-change p
'face
)
15960 (next-single-property-change p
'face
)) clist
)))
15961 ((org-at-table-p 'any
)
15962 (push (list :table-table
) clist
)))
15965 ;; Now the small context
15967 ((org-at-timestamp-p)
15968 (push (org-point-in-group p
0 :timestamp
) clist
))
15969 ((memq 'org-link faces
)
15971 (previous-single-property-change p
'face
)
15972 (next-single-property-change p
'face
)) clist
))
15973 ((memq 'org-special-keyword faces
)
15974 (push (list :keyword
15975 (previous-single-property-change p
'face
)
15976 (next-single-property-change p
'face
)) clist
))
15978 (push (org-point-in-group p
0 :target
) clist
)
15979 (goto-char (1- (match-beginning 0)))
15980 (if (looking-at org-radio-target-regexp
)
15981 (push (org-point-in-group p
0 :radio-target
) clist
))
15983 ((setq o
(car (delq nil
15986 (if (memq x org-latex-fragment-image-overlays
) x
))
15987 (org-overlays-at (point))))))
15988 (push (list :latex-fragment
15989 (org-overlay-start o
) (org-overlay-end o
)) clist
)
15990 (push (list :latex-preview
15991 (org-overlay-start o
) (org-overlay-end o
)) clist
))
15992 ((org-inside-LaTeX-fragment-p)
15993 ;; FIXME: positions wring.
15994 (push (list :latex-fragment
(point) (point)) clist
)))
15996 (setq clist
(nreverse (delq nil clist
)))
15999 (defun org-point-in-group (point group
&optional context
)
16000 "Check if POINT is in match-group GROUP.
16001 If CONTEXT is non-nil, return a list with CONTEXT and the boundaries of the
16002 match. If the match group does ot exist or point is not inside it,
16004 (and (match-beginning group
)
16005 (>= point
(match-beginning group
))
16006 (<= point
(match-end group
))
16008 (list context
(match-beginning group
) (match-end group
))
16011 (defun org-move-line-down (arg)
16012 "Move the current line down. With prefix argument, move it past ARG lines."
16014 (let ((col (current-column))
16016 (beginning-of-line 1) (setq beg
(point))
16017 (beginning-of-line 2) (setq end
(point))
16018 (beginning-of-line (+ 1 arg
))
16019 (setq pos
(move-marker (make-marker) (point)))
16020 (insert (delete-and-extract-region beg end
))
16022 (move-to-column col
)))
16024 (defun org-move-line-up (arg)
16025 "Move the current line up. With prefix argument, move it past ARG lines."
16027 (let ((col (current-column))
16029 (beginning-of-line 1) (setq beg
(point))
16030 (beginning-of-line 2) (setq end
(point))
16031 (beginning-of-line (- arg
))
16032 (setq pos
(move-marker (make-marker) (point)))
16033 (insert (delete-and-extract-region beg end
))
16035 (move-to-column col
)))
16037 ;; Paragraph filling stuff.
16038 ;; We want this to be just right, so use the full arsenal.
16040 (defun org-set-autofill-regexps ()
16042 ;; In the paragraph separator we include headlines, because filling
16043 ;; text in a line directly attached to a headline would otherwise
16044 ;; fill the headline as well.
16045 (set (make-local-variable 'comment-start-skip
) "^#+[ \t]*")
16046 (set (make-local-variable 'paragraph-separate
) "\f\\|\\*\\|[ ]*$\\|[ \t]*[:|]")
16047 ;; The paragraph starter includes hand-formatted lists.
16048 (set (make-local-variable 'paragraph-start
)
16049 "\f\\|[ ]*$\\|\\([*\f]+\\)\\|[ \t]*\\([-+*][ \t]+\\|[0-9]+[.)][ \t]+\\)\\|[ \t]*[:|]")
16050 ;; Inhibit auto-fill for headers, tables and fixed-width lines.
16051 ;; But only if the user has not turned off tables or fixed-width regions
16052 (set (make-local-variable 'auto-fill-inhibit-regexp
)
16054 "\\|[ \t]*" org-keyword-time-regexp
16055 (if (or org-enable-table-editor org-enable-fixed-width-editor
)
16058 (if org-enable-table-editor
"|" "")
16059 (if org-enable-fixed-width-editor
":" "")
16061 ;; We use our own fill-paragraph function, to make sure that tables
16062 ;; and fixed-width regions are not wrapped. That function will pass
16063 ;; through to `fill-paragraph' when appropriate.
16064 (set (make-local-variable 'fill-paragraph-function
) 'org-fill-paragraph
)
16065 ;; Adaptive filling: To get full control, first make sure that
16066 ;; `adaptive-fill-regexp' never matches. Then install our own matcher.
16067 (set (make-local-variable 'adaptive-fill-regexp
) "\000")
16068 (set (make-local-variable 'adaptive-fill-function
)
16069 'org-adaptive-fill-function
))
16071 (defun org-fill-paragraph (&optional justify
)
16072 "Re-align a table, pass through to fill-paragraph if no table."
16073 (let ((table-p (org-at-table-p))
16074 (table.el-p
(org-at-table.el-p
)))
16075 (cond ((equal (char-after (point-at-bol)) ?
*) t
) ; skip headlines
16076 (table.el-p t
) ; skip table.el tables
16077 (table-p (org-table-align) t
) ; align org-mode tables
16078 (t nil
)))) ; call paragraph-fill
16080 ;; For reference, this is the default value of adaptive-fill-regexp
16081 ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*"
16083 (defun org-adaptive-fill-function ()
16084 "Return a fill prefix for org-mode files.
16085 In particular, this makes sure hanging paragraphs for hand-formatted lists
16087 (if (looking-at " *\\([-*+] \\|[0-9]+[.)] \\)?")
16088 (make-string (- (match-end 0) (match-beginning 0)) ?\
)))
16090 ;; Functions needed for Emacs/XEmacs region compatibility
16092 (defun org-add-hook (hook function
&optional append local
)
16093 "Add-hook, compatible with both Emacsen."
16094 (if (and local
(featurep 'xemacs
))
16095 (add-local-hook hook function append
)
16096 (add-hook hook function append local
)))
16098 (defun org-region-active-p ()
16099 "Is `transient-mark-mode' on and the region active?
16100 Works on both Emacs and XEmacs."
16101 (if org-ignore-region
16103 (if (featurep 'xemacs
)
16104 (and zmacs-regions
(region-active-p))
16105 (and transient-mark-mode mark-active
))))
16107 (defun org-add-to-invisibility-spec (arg)
16108 "Add elements to `buffer-invisibility-spec'.
16109 See documentation for `buffer-invisibility-spec' for the kind of elements
16110 that can be added."
16112 ((fboundp 'add-to-invisibility-spec
)
16113 (add-to-invisibility-spec arg
))
16114 ((or (null buffer-invisibility-spec
) (eq buffer-invisibility-spec t
))
16115 (setq buffer-invisibility-spec
(list arg
)))
16117 (setq buffer-invisibility-spec
16118 (cons arg buffer-invisibility-spec
)))))
16120 (defun org-remove-from-invisibility-spec (arg)
16121 "Remove elements from `buffer-invisibility-spec'."
16122 (if (fboundp 'remove-from-invisibility-spec
)
16123 (remove-from-invisibility-spec arg
)
16124 (if (consp buffer-invisibility-spec
)
16125 (setq buffer-invisibility-spec
16126 (delete arg buffer-invisibility-spec
)))))
16128 (defun org-in-invisibility-spec-p (arg)
16129 "Is ARG a member of `buffer-invisibility-spec'?"
16130 (if (consp buffer-invisibility-spec
)
16131 (member arg buffer-invisibility-spec
)
16134 (defun org-image-file-name-regexp ()
16135 "Return regexp matching the file names of images."
16136 (if (fboundp 'image-file-name-regexp
)
16137 (image-file-name-regexp)
16138 (let ((image-file-name-extensions
16139 '("png" "jpeg" "jpg" "gif" "tiff" "tif"
16140 "xbm" "xpm" "pbm" "pgm" "ppm")))
16142 (regexp-opt (nconc (mapcar 'upcase
16143 image-file-name-extensions
)
16144 image-file-name-extensions
)
16148 ;; Functions needed for compatibility with old outline.el.
16150 ;; Programming for the old outline.el (that uses selective display
16151 ;; instead of `invisible' text properties) is a nightmare, mostly
16152 ;; because regular expressions can no longer be anchored at
16153 ;; beginning/end of line. Therefore a number of function need special
16154 ;; treatment when the old outline.el is being used.
16156 ;; The following functions capture almost the entire compatibility code
16157 ;; between the different versions of outline-mode. The only other
16158 ;; places where this is important are the font-lock-keywords, and in
16159 ;; `org-export-visible'. Search for `org-noutline-p' to find them.
16161 ;; C-a should go to the beginning of a *visible* line, also in the
16162 ;; new outline.el. I guess this should be patched into Emacs?
16163 (defun org-beginning-of-line ()
16164 "Go to the beginning of the current line. If that is invisible, continue
16165 to a visible line beginning. This makes the function of C-a more intuitive."
16167 (beginning-of-line 1)
16171 (if (org-invisible-p)
16172 (while (and (not (bobp)) (org-invisible-p))
16174 (beginning-of-line 1))
16175 (forward-char 1))))
16177 (when org-noutline-p
16178 (define-key org-mode-map
"\C-a" 'org-beginning-of-line
))
16180 (defun org-invisible-p ()
16181 "Check if point is at a character currently not visible."
16183 ;; Early versions of noutline don't have `outline-invisible-p'.
16184 (if (fboundp 'outline-invisible-p
)
16185 (outline-invisible-p)
16186 (get-char-property (point) 'invisible
))
16188 (skip-chars-backward "^\r\n")
16189 (equal (char-before) ?
\r))))
16191 (defun org-invisible-p2 ()
16192 "Check if point is at a character currently not visible."
16196 (if (and (eolp) (not (bobp))) (backward-char 1))
16197 ;; Early versions of noutline don't have `outline-invisible-p'.
16198 (if (fboundp 'outline-invisible-p
)
16199 (outline-invisible-p)
16200 (get-char-property (point) 'invisible
)))
16201 (skip-chars-backward "^\r\n")
16202 (equal (char-before) ?
\r))))
16204 (defun org-back-to-heading (&optional invisible-ok
)
16205 "Move to previous heading line, or beg of this line if it's a heading.
16206 Only visible heading lines are considered, unless INVISIBLE-OK is non-nil."
16208 (outline-back-to-heading invisible-ok
)
16209 (if (and (or (bobp) (memq (char-before) '(?
\n ?
\r)))
16210 (looking-at outline-regexp
))
16212 (if (re-search-backward (concat (if invisible-ok
"\\([\r\n]\\|^\\)" "^")
16216 (progn (goto-char (or (match-end 1) (match-beginning 0)))
16217 (looking-at outline-regexp
)))
16218 (error "Before first heading")))))
16220 (defun org-on-heading-p (&optional invisible-ok
)
16221 "Return t if point is on a (visible) heading line.
16222 If INVISIBLE-OK is non-nil, an invisible heading line is ok too."
16224 (outline-on-heading-p 'invisible-ok
)
16226 (skip-chars-backward "^\n\r")
16227 (and (looking-at outline-regexp
)
16230 (equal (char-before) ?
\n))))))
16232 (defun org-on-target-p ()
16233 (let ((pos (point)))
16235 (skip-chars-forward "<")
16236 (and (re-search-backward "<<" nil t
)
16237 (or (looking-at org-radio-target-regexp
)
16238 (looking-at org-target-regexp
))
16239 (<= (match-beginning 0) pos
)
16240 (>= (1+ (match-end 0)) pos
)))))
16242 (defun org-up-heading-all (arg)
16243 "Move to the heading line of which the present line is a subheading.
16244 This function considers both visible and invisible heading lines.
16245 With argument, move up ARG levels."
16247 (if (fboundp 'outline-up-heading-all
)
16248 (outline-up-heading-all arg
) ; emacs 21 version of outline.el
16249 (outline-up-heading arg t
)) ; emacs 22 version of outline.el
16250 (org-back-to-heading t
)
16251 (looking-at outline-regexp
)
16252 (if (<= (- (match-end 0) (match-beginning 0)) arg
)
16253 (error "Cannot move up %d levels" arg
)
16254 (re-search-backward
16255 (concat "[\n\r]" (regexp-quote
16256 (make-string (- (match-end 0) (match-beginning 0) arg
)
16259 (forward-char 1))))
16261 (defun org-show-hidden-entry ()
16262 "Show an entry where even the heading is hidden."
16264 (if (not org-noutline-p
)
16266 (org-back-to-heading t
)
16267 (org-flag-heading nil
)))
16270 (defun org-check-occur-regexp (regexp)
16271 "If REGEXP starts with \"^\", modify it to check for \\r as well.
16272 Of course, only for the old outline mode."
16275 (if (string-match "^\\^" regexp
)
16276 (concat "[\n\r]" (substring regexp
1))
16279 (defun org-flag-heading (flag &optional entry
)
16280 "Flag the current heading. FLAG non-nil means make invisible.
16281 When ENTRY is non-nil, show the entire entry."
16283 (org-back-to-heading t
)
16284 (if (not org-noutline-p
)
16285 ;; Make the current headline visible
16286 (outline-flag-region (max 1 (1- (point))) (point) (if flag ?
\r ?
\n)))
16287 ;; Check if we should show the entire entry
16292 (and (outline-next-heading)
16293 (org-flag-heading nil
))))
16294 (outline-flag-region (max 1 (1- (point)))
16295 (save-excursion (outline-end-of-heading) (point))
16298 (if flag ?
\r ?
\n))))))
16300 (defun org-end-of-subtree (&optional invisible-OK
)
16301 ;; This is an exact copy of the original function, but it uses
16302 ;; `org-back-to-heading', to make it work also in invisible
16303 ;; trees. And is uses an invisible-OK argument.
16304 ;; Under Emacs this is not needed, but the old outline.el needs this fix.
16305 (org-back-to-heading invisible-OK
)
16307 (level (funcall outline-level
)))
16308 (while (and (not (eobp))
16309 (or first
(> (funcall outline-level
) level
)))
16311 (outline-next-heading))
16312 (if (memq (preceding-char) '(?
\n ?\^M
))
16314 ;; Go to end of line before heading
16316 (if (memq (preceding-char) '(?
\n ?\^M
))
16317 ;; leave blank line before heading
16318 (forward-char -
1)))))
16321 (defun org-show-subtree ()
16322 "Show everything after this heading at deeper levels."
16323 (outline-flag-region
16326 (outline-end-of-subtree) (outline-next-heading) (point))
16327 (if org-noutline-p nil ?
\n)))
16329 (defun org-show-entry ()
16330 "Show the body directly following this heading.
16331 Show the heading too, if it is currently invisible."
16334 (org-back-to-heading t
)
16335 (outline-flag-region
16336 (max 1 (1- (point)))
16338 (re-search-forward (concat "[\r\n]\\(" outline-regexp
"\\)") nil
'move
)
16339 (or (match-beginning 1) (point-max)))
16340 (if org-noutline-p nil ?
\n))))
16342 (defun org-make-options-regexp (kwds)
16343 "Make a regular expression for keyword lines."
16345 (if org-noutline-p
"^" "[\n\r]")
16347 (mapconcat 'regexp-quote kwds
"\\|")
16349 (if org-noutline-p
"\\(.+\\)" "\\([^\n\r]+\\)")))
16351 ;; Make `bookmark-jump' show the jump location if it was hidden.
16352 (eval-after-load "bookmark"
16353 '(if (boundp 'bookmark-after-jump-hook
)
16354 ;; We can use the hook
16355 (add-hook 'bookmark-after-jump-hook
'org-bookmark-jump-unhide
)
16356 ;; Hook not available, use advice
16357 (defadvice bookmark-jump
(after org-make-visible activate
)
16358 "Make the position visible."
16359 (org-bookmark-jump-unhide))))
16361 (defun org-bookmark-jump-unhide ()
16362 "Unhide the current position, to show the bookmark location."
16364 (or (org-invisible-p)
16365 (save-excursion (goto-char (max (point-min) (1- (point))))
16366 (org-invisible-p)))
16367 (org-show-hierarchy-above)))
16369 ;;; Experimental code
16376 (run-hooks 'org-load-hook
)
16378 ;; arch-tag: e77da1a7-acc7-4336-b19e-efa25af3f9fd
16379 ;;; org.el ends here