;;; org.el --- Outline-based notes management and organizer ;; Carstens outline-mode for keeping track of everything. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; ;; Author: Carsten Dominik ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org ;; Version: 6.10c ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;; Commentary: ;; ;; Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing ;; project planning with a fast and effective plain-text system. ;; ;; Org-mode develops organizational tasks around NOTES files that contain ;; information about projects as plain text. Org-mode is implemented on ;; top of outline-mode, which makes it possible to keep the content of ;; large files well structured. Visibility cycling and structure editing ;; help to work with the tree. Tables are easily created with a built-in ;; table editor. Org-mode supports ToDo items, deadlines, time stamps, ;; and scheduling. It dynamically compiles entries into an agenda that ;; utilizes and smoothly integrates much of the Emacs calendar and diary. ;; Plain text URL-like links connect to websites, emails, Usenet ;; messages, BBDB entries, and any files related to the projects. For ;; printing and sharing of notes, an Org-mode file can be exported as a ;; structured ASCII file, as HTML, or (todo and agenda items only) as an ;; iCalendar file. It can also serve as a publishing tool for a set of ;; linked webpages. ;; ;; Installation and Activation ;; --------------------------- ;; See the corresponding sections in the manual at ;; ;; http://orgmode.org/org.html#Installation ;; ;; Documentation ;; ------------- ;; The documentation of Org-mode can be found in the TeXInfo file. The ;; distribution also contains a PDF version of it. At the homepage of ;; Org-mode, you can read the same text online as HTML. There is also an ;; excellent reference card made by Philip Rooke. This card can be found ;; in the etc/ directory of Emacs 22. ;; ;; A list of recent changes can be found at ;; http://orgmode.org/Changes.html ;; ;;; Code: (defvar org-inhibit-highlight-removal nil) ; dynamically scoped param (defvar org-table-formula-constants-local nil "Local version of `org-table-formula-constants'.") (make-variable-buffer-local 'org-table-formula-constants-local) ;;;; Require other packages (eval-when-compile (require 'cl) (require 'gnus-sum) (require 'calendar)) ;; For XEmacs, noutline is not yet provided by outline.el, so arrange for ;; the file noutline.el being loaded. (if (featurep 'xemacs) (condition-case nil (require 'noutline))) ;; We require noutline, which might be provided in outline.el (require 'outline) (require 'noutline) ;; Other stuff we need. (require 'time-date) (unless (fboundp 'time-subtract) (defalias 'time-subtract 'subtract-time)) (require 'easymenu) (require 'org-macs) (require 'org-compat) (require 'org-faces) (require 'org-list) ;;;; Customization variables ;;; Version (defconst org-version "6.10c" "The version number of the file org.el.") (defun org-version (&optional here) "Show the org-mode version in the echo area. With prefix arg HERE, insert it at point." (interactive "P") (let ((version (format "Org-mode version %s" org-version))) (message version) (if here (insert version)))) ;;; Compatibility constants ;;; The custom variables (defgroup org nil "Outline-based notes management and organizer." :tag "Org" :group 'outlines :group 'hypermedia :group 'calendar) (defcustom org-load-hook nil "Hook that is run after org.el has been loaded." :group 'org :type 'hook) (defvar org-modules) ; defined below (defvar org-modules-loaded nil "Have the modules been loaded already?") (defun org-load-modules-maybe (&optional force) "Load all extensions listed in `org-default-extensions'." (when (or force (not org-modules-loaded)) (mapc (lambda (ext) (condition-case nil (require ext) (error (message "Problems while trying to load feature `%s'" ext)))) org-modules) (setq org-modules-loaded t))) (defun org-set-modules (var value) "Set VAR to VALUE and call `org-load-modules-maybe' with the force flag." (set var value) (when (featurep 'org) (org-load-modules-maybe 'force))) (when (org-bound-and-true-p org-modules) (let ((a (member 'org-infojs org-modules))) (and a (setcar a 'org-jsinfo)))) (defcustom org-modules '(org-bbdb org-bibtex org-gnus org-info org-jsinfo org-irc org-mew org-mhe org-rmail org-vm org-wl) "Modules that should always be loaded together with org.el. If a description starts with , the file is not part of Emacs and loading it will require that you have downloaded and properly installed the org-mode distribution. You can also use this system to load external packages (i.e. neither Org core modules, not modules from the CONTRIB directory). Just add symbols to the end of the list. If the package is called org-xyz.el, then you need to add the symbol `xyz', and the package must have a call to (provide 'org-xyz)" :group 'org :set 'org-set-modules :type '(set :greedy t (const :tag " bbdb: Links to BBDB entries" org-bbdb) (const :tag " bibtex: Links to BibTeX entries" org-bibtex) (const :tag " gnus: Links to GNUS folders/messages" org-gnus) (const :tag " id: Global id's for identifying entries" org-id) (const :tag " info: Links to Info nodes" org-info) (const :tag " jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo) (const :tag " irc: Links to IRC/ERC chat sessions" org-irc) (const :tag " mac-message: Links to messages in Apple Mail" org-mac-message) (const :tag " mew Links to Mew folders/messages" org-mew) (const :tag " mhe: Links to MHE folders/messages" org-mhe) (const :tag " rmail: Links to RMAIL folders/messages" org-rmail) (const :tag " vm: Links to VM folders/messages" org-vm) (const :tag " wl: Links to Wanderlust folders/messages" org-wl) (const :tag " mouse: Additional mouse support" org-mouse) (const :tag "C annotate-file: Annotate a file with org syntax" org-annotate-file) (const :tag "C annotation-helper: Call Remeber directly from Browser" org-annotation-helper) (const :tag "C bookmark: Org links to bookmarks" org-bookmark) (const :tag "C depend: TODO dependencies for Org-mode" org-depend) (const :tag "C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol) (const :tag "C eval: Include command output as text" org-eval) (const :tag "C expiry: Expiry mechanism for Org entries" org-expiry) (const :tag "C id: Global id's for identifying entries" org-id) (const :tag "C interactive-query: Interactive modification of tags query" org-interactive-query) (const :tag "C mairix: Hook mairix search into Org for different MUAs" org-mairix) (const :tag "C man: Support for links to manpages in Org-mode" org-man) (const :tag "C mtags: Support for muse-like tags" org-mtags) (const :tag "C panel: Simple routines for us with bad memory" org-panel) (const :tag "C registry: A registry for Org links" org-registry) (const :tag "C org2rem: Convert org appointments into reminders" org2rem) (const :tag "C screen: Visit screen sessions through Org-mode links" org-screen) (const :tag "C toc: Table of contents for Org-mode buffer" org-toc) (const :tag "C sqlinsert: Convert Org-mode tables to SQL insertions" orgtbl-sqlinsert) (repeat :tag "External packages" :inline t (symbol :tag "Package")))) (defgroup org-startup nil "Options concerning startup of Org-mode." :tag "Org Startup" :group 'org) (defcustom org-startup-folded t "Non-nil means, entering Org-mode will switch to OVERVIEW. This can also be configured on a per-file basis by adding one of the following lines anywhere in the buffer: #+STARTUP: fold #+STARTUP: nofold #+STARTUP: content" :group 'org-startup :type '(choice (const :tag "nofold: show all" nil) (const :tag "fold: overview" t) (const :tag "content: all headlines" content))) (defcustom org-startup-truncated t "Non-nil means, entering Org-mode will set `truncate-lines'. This is useful since some lines containing links can be very long and uninteresting. Also tables look terrible when wrapped." :group 'org-startup :type 'boolean) (defcustom org-startup-align-all-tables nil "Non-nil means, align all tables when visiting a file. This is useful when the column width in tables is forced with cookies in table fields. Such tables will look correct only after the first re-align. This can also be configured on a per-file basis by adding one of the following lines anywhere in the buffer: #+STARTUP: align #+STARTUP: noalign" :group 'org-startup :type 'boolean) (defcustom org-insert-mode-line-in-empty-file nil "Non-nil means insert the first line setting Org-mode in empty files. When the function `org-mode' is called interactively in an empty file, this normally means that the file name does not automatically trigger Org-mode. To ensure that the file will always be in Org-mode in the future, a line enforcing Org-mode will be inserted into the buffer, if this option has been set." :group 'org-startup :type 'boolean) (defcustom org-replace-disputed-keys nil "Non-nil means use alternative key bindings for some keys. Org-mode uses S- keys for changing timestamps and priorities. These keys are also used by other packages like `CUA-mode' or `windmove.el'. If you want to use Org-mode together with one of these other modes, or more generally if you would like to move some Org-mode commands to other keys, set this variable and configure the keys with the variable `org-disputed-keys'. This option is only relevant at load-time of Org-mode, and must be set *before* org.el is loaded. Changing it requires a restart of Emacs to become effective." :group 'org-startup :type 'boolean) (defcustom org-use-extra-keys nil "Non-nil means use extra key sequence definitions for certain commands. This happens automatically if you run XEmacs or if window-system is nil. This variable lets you do the same manually. You must set it before loading org. Example: on Carbon Emacs 22 running graphically, with an external keyboard on a Powerbook, the default way of setting M-left might not work for either Alt or ESC. Setting this variable will make it work for ESC." :group 'org-startup :type 'boolean) (if (fboundp 'defvaralias) (defvaralias 'org-CUA-compatible 'org-replace-disputed-keys)) (defcustom org-disputed-keys '(([(shift up)] . [(meta p)]) ([(shift down)] . [(meta n)]) ([(shift left)] . [(meta -)]) ([(shift right)] . [(meta +)]) ([(control shift right)] . [(meta shift +)]) ([(control shift left)] . [(meta shift -)])) "Keys for which Org-mode and other modes compete. This is an alist, cars are the default keys, second element specifies the alternative to use when `org-replace-disputed-keys' is t. Keys can be specified in any syntax supported by `define-key'. The value of this option takes effect only at Org-mode's startup, therefore you'll have to restart Emacs to apply it after changing." :group 'org-startup :type 'alist) (defun org-key (key) "Select key according to `org-replace-disputed-keys' and `org-disputed-keys'. Or return the original if not disputed." (if org-replace-disputed-keys (let* ((nkey (key-description key)) (x (org-find-if (lambda (x) (equal (key-description (car x)) nkey)) org-disputed-keys))) (if x (cdr x) key)) key)) (defun org-find-if (predicate seq) (catch 'exit (while seq (if (funcall predicate (car seq)) (throw 'exit (car seq)) (pop seq))))) (defun org-defkey (keymap key def) "Define a key, possibly translated, as returned by `org-key'." (define-key keymap (org-key key) def)) (defcustom org-ellipsis nil "The ellipsis to use in the Org-mode outline. When nil, just use the standard three dots. When a string, use that instead, When a face, use the standart 3 dots, but with the specified face. The change affects only Org-mode (which will then use its own display table). Changing this requires executing `M-x org-mode' in a buffer to become effective." :group 'org-startup :type '(choice (const :tag "Default" nil) (face :tag "Face" :value org-warning) (string :tag "String" :value "...#"))) (defvar org-display-table nil "The display table for org-mode, in case `org-ellipsis' is non-nil.") (defgroup org-keywords nil "Keywords in Org-mode." :tag "Org Keywords" :group 'org) (defcustom org-deadline-string "DEADLINE:" "String to mark deadline entries. A deadline is this string, followed by a time stamp. Should be a word, terminated by a colon. You can insert a schedule keyword and a timestamp with \\[org-deadline]. Changes become only effective after restarting Emacs." :group 'org-keywords :type 'string) (defcustom org-scheduled-string "SCHEDULED:" "String to mark scheduled TODO entries. A schedule is this string, followed by a time stamp. Should be a word, terminated by a colon. You can insert a schedule keyword and a timestamp with \\[org-schedule]. Changes become only effective after restarting Emacs." :group 'org-keywords :type 'string) (defcustom org-closed-string "CLOSED:" "String used as the prefix for timestamps logging closing a TODO entry." :group 'org-keywords :type 'string) (defcustom org-clock-string "CLOCK:" "String used as prefix for timestamps clocking work hours on an item." :group 'org-keywords :type 'string) (defcustom org-comment-string "COMMENT" "Entries starting with this keyword will never be exported. An entry can be toggled between COMMENT and normal with \\[org-toggle-comment]. Changes become only effective after restarting Emacs." :group 'org-keywords :type 'string) (defcustom org-quote-string "QUOTE" "Entries starting with this keyword will be exported in fixed-width font. Quoting applies only to the text in the entry following the headline, and does not extend beyond the next headline, even if that is lower level. An entry can be toggled between QUOTE and normal with \\[org-toggle-fixed-width-section]." :group 'org-keywords :type 'string) (defconst org-repeat-re "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*\\([.+]?\\+[0-9]+[dwmy]\\)" "Regular expression for specifying repeated events. After a match, group 1 contains the repeat expression.") (defgroup org-structure nil "Options concerning the general structure of Org-mode files." :tag "Org Structure" :group 'org) (defgroup org-reveal-location nil "Options about how to make context of a location visible." :tag "Org Reveal Location" :group 'org-structure) (defconst org-context-choice '(choice (const :tag "Always" t) (const :tag "Never" nil) (repeat :greedy t :tag "Individual contexts" (cons (choice :tag "Context" (const agenda) (const org-goto) (const occur-tree) (const tags-tree) (const link-search) (const mark-goto) (const bookmark-jump) (const isearch) (const default)) (boolean)))) "Contexts for the reveal options.") (defcustom org-show-hierarchy-above '((default . t)) "Non-nil means, show full hierarchy when revealing a location. Org-mode often shows locations in an org-mode file which might have been invisible before. When this is set, the hierarchy of headings above the exposed location is shown. Turning this off for example for sparse trees makes them very compact. Instead of t, this can also be an alist specifying this option for different contexts. Valid contexts are agenda when exposing an entry from the agenda org-goto when using the command `org-goto' on key C-c C-j occur-tree when using the command `org-occur' on key C-c / tags-tree when constructing a sparse tree based on tags matches link-search when exposing search matches associated with a link mark-goto when exposing the jump goal of a mark bookmark-jump when exposing a bookmark location isearch when exiting from an incremental search default default for all contexts not set explicitly" :group 'org-reveal-location :type org-context-choice) (defcustom org-show-following-heading '((default . nil)) "Non-nil means, show following heading when revealing a location. Org-mode often shows locations in an org-mode file which might have been invisible before. When this is set, the heading following the match is shown. Turning this off for example for sparse trees makes them very compact, but makes it harder to edit the location of the match. In such a case, use the command \\[org-reveal] to show more context. Instead of t, this can also be an alist specifying this option for different contexts. See `org-show-hierarchy-above' for valid contexts." :group 'org-reveal-location :type org-context-choice) (defcustom org-show-siblings '((default . nil) (isearch t)) "Non-nil means, show all sibling heading when revealing a location. Org-mode often shows locations in an org-mode file which might have been invisible before. When this is set, the sibling of the current entry heading are all made visible. If `org-show-hierarchy-above' is t, the same happens on each level of the hierarchy above the current entry. By default this is on for the isearch context, off for all other contexts. Turning this off for example for sparse trees makes them very compact, but makes it harder to edit the location of the match. In such a case, use the command \\[org-reveal] to show more context. Instead of t, this can also be an alist specifying this option for different contexts. See `org-show-hierarchy-above' for valid contexts." :group 'org-reveal-location :type org-context-choice) (defcustom org-show-entry-below '((default . nil)) "Non-nil means, show the entry below a headline when revealing a location. Org-mode often shows locations in an org-mode file which might have been invisible before. When this is set, the text below the headline that is exposed is also shown. By default this is off for all contexts. Instead of t, this can also be an alist specifying this option for different contexts. See `org-show-hierarchy-above' for valid contexts." :group 'org-reveal-location :type org-context-choice) (defcustom org-indirect-buffer-display 'other-window "How should indirect tree buffers be displayed? This applies to indirect buffers created with the commands \\[org-tree-to-indirect-buffer] and \\[org-agenda-tree-to-indirect-buffer]. Valid values are: current-window Display in the current window other-window Just display in another window. dedicated-frame Create one new frame, and re-use it each time. new-frame Make a new frame each time. Note that in this case previously-made indirect buffers are kept, and you need to kill these buffers yourself." :group 'org-structure :group 'org-agenda-windows :type '(choice (const :tag "In current window" current-window) (const :tag "In current frame, other window" other-window) (const :tag "Each time a new frame" new-frame) (const :tag "One dedicated frame" dedicated-frame))) (defgroup org-cycle nil "Options concerning visibility cycling in Org-mode." :tag "Org Cycle" :group 'org-structure) (defcustom org-drawers '("PROPERTIES" "CLOCK") "Names of drawers. Drawers are not opened by cycling on the headline above. Drawers only open with a TAB on the drawer line itself. A drawer looks like this: :DRAWERNAME: ..... :END: The drawer \"PROPERTIES\" is special for capturing properties through the property API. Drawers can be defined on the per-file basis with a line like: #+DRAWERS: HIDDEN STATE PROPERTIES" :group 'org-structure :type '(repeat (string :tag "Drawer Name"))) (defcustom org-cycle-global-at-bob nil "Cycle globally if cursor is at beginning of buffer and not at a headline. This makes it possible to do global cycling without having to use S-TAB or C-u TAB. For this special case to work, the first line of the buffer must not be a headline - it may be empty ot some other text. When used in this way, `org-cycle-hook' is disables temporarily, to make sure the cursor stays at the beginning of the buffer. When this option is nil, don't do anything special at the beginning of the buffer." :group 'org-cycle :type 'boolean) (defcustom org-cycle-emulate-tab t "Where should `org-cycle' emulate TAB. nil Never white Only in completely white lines whitestart Only at the beginning of lines, before the first non-white char t Everywhere except in headlines exc-hl-bol Everywhere except at the start of a headline If TAB is used in a place where it does not emulate TAB, the current subtree visibility is cycled." :group 'org-cycle :type '(choice (const :tag "Never" nil) (const :tag "Only in completely white lines" white) (const :tag "Before first char in a line" whitestart) (const :tag "Everywhere except in headlines" t) (const :tag "Everywhere except at bol in headlines" exc-hl-bol) )) (defcustom org-cycle-separator-lines 2 "Number of empty lines needed to keep an empty line between collapsed trees. If you leave an empty line between the end of a subtree and the following headline, this empty line is hidden when the subtree is folded. Org-mode will leave (exactly) one empty line visible if the number of empty lines is equal or larger to the number given in this variable. So the default 2 means, at least 2 empty lines after the end of a subtree are needed to produce free space between a collapsed subtree and the following headline. Special case: when 0, never leave empty lines in collapsed view." :group 'org-cycle :type 'integer) (put 'org-cycle-separator-lines 'safe-local-variable 'integerp) (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-show-empty-lines org-optimize-window-after-visibility-change) "Hook that is run after `org-cycle' has changed the buffer visibility. The function(s) in this hook must accept a single argument which indicates the new state that was set by the most recent `org-cycle' command. The argument is a symbol. After a global state change, it can have the values `overview', `content', or `all'. After a local state change, it can have the values `folded', `children', or `subtree'." :group 'org-cycle :type 'hook) (defgroup org-edit-structure nil "Options concerning structure editing in Org-mode." :tag "Org Edit Structure" :group 'org-structure) (defcustom org-odd-levels-only nil "Non-nil means, skip even levels and only use odd levels for the outline. This has the effect that two stars are being added/taken away in promotion/demotion commands. It also influences how levels are handled by the exporters. Changing it requires restart of `font-lock-mode' to become effective for fontification also in regions already fontified. You may also set this on a per-file basis by adding one of the following lines to the buffer: #+STARTUP: odd #+STARTUP: oddeven" :group 'org-edit-structure :group 'org-font-lock :type 'boolean) (defcustom org-adapt-indentation t "Non-nil means, adapt indentation when promoting and demoting. When this is set and the *entire* text in an entry is indented, the indentation is increased by one space in a demotion command, and decreased by one in a promotion command. If any line in the entry body starts at column 0, indentation is not changed at all." :group 'org-edit-structure :type 'boolean) (defcustom org-special-ctrl-a/e nil "Non-nil means `C-a' and `C-e' behave specially in headlines and items. When t, `C-a' will bring back the cursor to the beginning of the headline text, i.e. after the stars and after a possible TODO keyword. In an item, this will be the position after the bullet. When the cursor is already at that position, another `C-a' will bring it to the beginning of the line. `C-e' will jump to the end of the headline, ignoring the presence of tags in the headline. A second `C-e' will then jump to the true end of the line, after any tags. When set to the symbol `reversed', the first `C-a' or `C-e' works normally, and only a directly following, identical keypress will bring the cursor to the special positions." :group 'org-edit-structure :type '(choice (const :tag "off" nil) (const :tag "after bullet first" t) (const :tag "border first" reversed))) (if (fboundp 'defvaralias) (defvaralias 'org-special-ctrl-a 'org-special-ctrl-a/e)) (defcustom org-special-ctrl-k nil "Non-nil means `C-k' will behave specially in headlines. When nil, `C-k' will call the default `kill-line' command. When t, the following will happen while the cursor is in the headline: - When the cursor is at the beginning of a headline, kill the entire line and possible the folded subtree below the line. - When in the middle of the headline text, kill the headline up to the tags. - When after the headline text, kill the tags." :group 'org-edit-structure :type 'boolean) (defcustom org-yank-folded-subtrees t "Non-nil means, when yanking subtrees, fold them. If the kill is a single subtree, or a sequence of subtrees, i.e. if it starts with a heading and all other headings in it are either children or siblings, then fold all the subtrees." :group 'org-edit-structure :type 'boolean) (defcustom org-yank-adjusted-subtrees t "Non-nil means, when yanking subtrees, adjust the level. With this setting, `org-paste-subtree' is used to insert the subtree, see this function for details." :group 'org-edit-structure :type 'boolean) (defcustom org-M-RET-may-split-line '((default . t)) "Non-nil means, M-RET will split the line at the cursor position. When nil, it will go to the end of the line before making a new line. You may also set this option in a different way for different contexts. Valid contexts are: headline when creating a new headline item when creating a new item table in a table field default the value to be used for all contexts not explicitly customized" :group 'org-structure :group 'org-table :type '(choice (const :tag "Always" t) (const :tag "Never" nil) (repeat :greedy t :tag "Individual contexts" (cons (choice :tag "Context" (const headline) (const item) (const table) (const default)) (boolean))))) (defcustom org-insert-heading-respect-content nil "Non-nil means, insert new headings after the current subtree. When nil, the new heading is created directly after the current line. The commands \\[org-insert-heading-respect-content] and \\[org-insert-todo-heading-respect-content] turn this variable on for the duration of the command." :group 'org-structure :type 'boolean) (defcustom org-blank-before-new-entry '((heading . nil) (plain-list-item . nil)) "Should `org-insert-heading' leave a blank line before new heading/item? The value is an alist, with `heading' and `plain-list-item' as car, and a boolean flag as cdr." :group 'org-edit-structure :type '(list (cons (const heading) (boolean)) (cons (const plain-list-item) (boolean)))) (defcustom org-insert-heading-hook nil "Hook being run after inserting a new heading." :group 'org-edit-structure :type 'hook) (defcustom org-enable-fixed-width-editor t "Non-nil means, lines starting with \":\" are treated as fixed-width. This currently only means, they are never auto-wrapped. When nil, such lines will be treated like ordinary lines. See also the QUOTE keyword." :group 'org-edit-structure :type 'boolean) (defcustom org-edit-src-region-extra nil "Additional regexps to identify regions for editing with `org-edit-src-code'. For examples see the function `org-edit-src-find-region-and-lang'. The regular expression identifying the begin marker should end with a newline, and the regexp marking the end line should start with a newline, to make sure there are kept outside the narrowed region." :group 'org-edit-structure :type '(repeat (list (regexp :tag "begin regexp") (regexp :tag "end regexp") (choice :tag "language" (string :tag "specify") (integer :tag "from match group") (const :tag "from `lang' element") (const :tag "from `style' element"))))) (defcustom org-edit-fixed-width-region-mode 'artist-mode "The mode that should be used to edit fixed-width regions. These are the regions where each line starts with a colon." :group 'org-edit-structure :type '(choice (const artist-mode) (const picture-mode) (const fundamental-mode) (function :tag "Other (specify)"))) (defcustom org-goto-auto-isearch t "Non-nil means, typing characters in org-goto starts incremental search." :group 'org-edit-structure :type 'boolean) (defgroup org-sparse-trees nil "Options concerning sparse trees in Org-mode." :tag "Org Sparse Trees" :group 'org-structure) (defcustom org-highlight-sparse-tree-matches t "Non-nil means, highlight all matches that define a sparse tree. The highlights will automatically disappear the next time the buffer is changed by an edit command." :group 'org-sparse-trees :type 'boolean) (defcustom org-remove-highlights-with-change t "Non-nil means, any change to the buffer will remove temporary highlights. Such highlights are created by `org-occur' and `org-clock-display'. When nil, `C-c C-c needs to be used to get rid of the highlights. The highlights created by `org-preview-latex-fragment' always need `C-c C-c' to be removed." :group 'org-sparse-trees :group 'org-time :type 'boolean) (defcustom org-occur-hook '(org-first-headline-recenter) "Hook that is run after `org-occur' has constructed a sparse tree. This can be used to recenter the window to show as much of the structure as possible." :group 'org-sparse-trees :type 'hook) (defgroup org-imenu-and-speedbar nil "Options concerning imenu and speedbar in Org-mode." :tag "Org Imenu and Speedbar" :group 'org-structure) (defcustom org-imenu-depth 2 "The maximum level for Imenu access to Org-mode headlines. This also applied for speedbar access." :group 'org-imenu-and-speedbar :type 'number) (defgroup org-table nil "Options concerning tables in Org-mode." :tag "Org Table" :group 'org) (defcustom org-enable-table-editor 'optimized "Non-nil means, lines starting with \"|\" are handled by the table editor. When nil, such lines will be treated like ordinary lines. When equal to the symbol `optimized', the table editor will be optimized to do the following: - Automatic overwrite mode in front of whitespace in table fields. This makes the structure of the table stay in tact as long as the edited field does not exceed the column width. - Minimize the number of realigns. Normally, the table is aligned each time TAB or RET are pressed to move to another field. With optimization this happens only if changes to a field might have changed the column width. Optimization requires replacing the functions `self-insert-command', `delete-char', and `backward-delete-char' in Org-mode buffers, with a slight (in fact: unnoticeable) speed impact for normal typing. Org-mode is very good at guessing when a re-align will be necessary, but you can always force one with \\[org-ctrl-c-ctrl-c]. If you would like to use the optimized version in Org-mode, but the un-optimized version in OrgTbl-mode, see the variable `orgtbl-optimized'. This variable can be used to turn on and off the table editor during a session, but in order to toggle optimization, a restart is required. See also the variable `org-table-auto-blank-field'." :group 'org-table :type '(choice (const :tag "off" nil) (const :tag "on" t) (const :tag "on, optimized" optimized))) (defcustom org-table-tab-recognizes-table.el t "Non-nil means, TAB will automatically notice a table.el table. When it sees such a table, it moves point into it and - if necessary - calls `table-recognize-table'." :group 'org-table-editing :type 'boolean) (defgroup org-link nil "Options concerning links in Org-mode." :tag "Org Link" :group 'org) (defvar org-link-abbrev-alist-local nil "Buffer-local version of `org-link-abbrev-alist', which see. The value of this is taken from the #+LINK lines.") (make-variable-buffer-local 'org-link-abbrev-alist-local) (defcustom org-link-abbrev-alist nil "Alist of link abbreviations. The car of each element is a string, to be replaced at the start of a link. The cdrs are replacement values, like (\"linkkey\" . REPLACE). Abbreviated links in Org-mode buffers can have an optional tag after a double colon, e.g. [[linkkey:tag][description]] If REPLACE is a string, the tag will simply be appended to create the link. If the string contains \"%s\", the tag will be inserted there. REPLACE may also be a function that will be called with the tag as the only argument to create the link, which should be returned as a string. See the manual for examples." :group 'org-link :type 'alist) (defcustom org-descriptive-links t "Non-nil means, hide link part and only show description of bracket links. Bracket links are like [[link][descritpion]]. This variable sets the initial state in new org-mode buffers. The setting can then be toggled on a per-buffer basis from the Org->Hyperlinks menu." :group 'org-link :type 'boolean) (defcustom org-link-file-path-type 'adaptive "How the path name in file links should be stored. Valid values are: relative Relative to the current directory, i.e. the directory of the file into which the link is being inserted. absolute Absolute path, if possible with ~ for home directory. noabbrev Absolute path, no abbreviation of home directory. adaptive Use relative path for files in the current directory and sub- directories of it. For other files, use an absolute path." :group 'org-link :type '(choice (const relative) (const absolute) (const noabbrev) (const adaptive))) (defcustom org-activate-links '(bracket angle plain radio tag date) "Types of links that should be activated in Org-mode files. This is a list of symbols, each leading to the activation of a certain link type. In principle, it does not hurt to turn on most link types - there may be a small gain when turning off unused link types. The types are: bracket The recommended [[link][description]] or [[link]] links with hiding. angular Links in angular brackes that may contain whitespace like . plain Plain links in normal text, no whitespace, like http://google.com. radio Text that is matched by a radio target, see manual for details. tag Tag settings in a headline (link to tag search). date Time stamps (link to calendar). Changing this variable requires a restart of Emacs to become effective." :group 'org-link :type '(set (const :tag "Double bracket links (new style)" bracket) (const :tag "Angular bracket links (old style)" angular) (const :tag "Plain text links" plain) (const :tag "Radio target matches" radio) (const :tag "Tags" tag) (const :tag "Timestamps" date))) (defcustom org-make-link-description-function nil "Function to use to generate link descriptions from links. If nil the link location will be used. This function must take two parameters; the first is the link and the second the description org-insert-link has generated, and should return the description to use." :group 'org-link :type 'function) (defgroup org-link-store nil "Options concerning storing links in Org-mode." :tag "Org Store Link" :group 'org-link) (defcustom org-email-link-description-format "Email %c: %.30s" "Format of the description part of a link to an email or usenet message. The following %-excapes will be replaced by corresponding information: %F full \"From\" field %f name, taken from \"From\" field, address if no name %T full \"To\" field %t first name in \"To\" field, address if no name %c correspondent. Unually \"from NAME\", but if you sent it yourself, it will be \"to NAME\". See also the variable `org-from-is-user-regexp'. %s subject %m message-id. You may use normal field width specification between the % and the letter. This is for example useful to limit the length of the subject. Examples: \"%f on: %.30s\", \"Email from %f\", \"Email %c\"" :group 'org-link-store :type 'string) (defcustom org-from-is-user-regexp (let (r1 r2) (when (and user-mail-address (not (string= user-mail-address ""))) (setq r1 (concat "\\<" (regexp-quote user-mail-address) "\\>"))) (when (and user-full-name (not (string= user-full-name ""))) (setq r2 (concat "\\<" (regexp-quote user-full-name) "\\>"))) (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2))) "Regexp mached against the \"From:\" header of an email or usenet message. It should match if the message is from the user him/herself." :group 'org-link-store :type 'regexp) (defcustom org-context-in-file-links t "Non-nil means, file links from `org-store-link' contain context. A search string will be added to the file name with :: as separator and used to find the context when the link is activated by the command `org-open-at-point'. Using a prefix arg to the command \\[org-store-link] (`org-store-link') negates this setting for the duration of the command." :group 'org-link-store :type 'boolean) (defcustom org-keep-stored-link-after-insertion nil "Non-nil means, keep link in list for entire session. The command `org-store-link' adds a link pointing to the current location to an internal list. These links accumulate during a session. The command `org-insert-link' can be used to insert links into any Org-mode file (offering completion for all stored links). When this option is nil, every link which has been inserted once using \\[org-insert-link] will be removed from the list, to make completing the unused links more efficient." :group 'org-link-store :type 'boolean) (defgroup org-link-follow nil "Options concerning following links in Org-mode." :tag "Org Follow Link" :group 'org-link) (defcustom org-follow-link-hook nil "Hook that is run after a link has been followed." :group 'org-link-follow :type 'hook) (defcustom org-tab-follows-link nil "Non-nil means, on links TAB will follow the link. Needs to be set before org.el is loaded." :group 'org-link-follow :type 'boolean) (defcustom org-return-follows-link nil "Non-nil means, on links RET will follow the link. Needs to be set before org.el is loaded." :group 'org-link-follow :type 'boolean) (defcustom org-mouse-1-follows-link (if (boundp 'mouse-1-click-follows-link) mouse-1-click-follows-link t) "Non-nil means, mouse-1 on a link will follow the link. A longer mouse click will still set point. Does not work on XEmacs. Needs to be set before org.el is loaded." :group 'org-link-follow :type 'boolean) (defcustom org-mark-ring-length 4 "Number of different positions to be recorded in the ring Changing this requires a restart of Emacs to work correctly." :group 'org-link-follow :type 'interger) (defcustom org-link-frame-setup '((vm . vm-visit-folder-other-frame) (gnus . gnus-other-frame) (file . find-file-other-window)) "Setup the frame configuration for following links. When following a link with Emacs, it may often be useful to display this link in another window or frame. This variable can be used to set this up for the different types of links. For VM, use any of `vm-visit-folder' `vm-visit-folder-other-frame' For Gnus, use any of `gnus' `gnus-other-frame' `org-gnus-no-new-news' For FILE, use any of `find-file' `find-file-other-window' `find-file-other-frame' For the calendar, use the variable `calendar-setup'. For BBDB, it is currently only possible to display the matches in another window." :group 'org-link-follow :type '(list (cons (const vm) (choice (const vm-visit-folder) (const vm-visit-folder-other-window) (const vm-visit-folder-other-frame))) (cons (const gnus) (choice (const gnus) (const gnus-other-frame) (const org-gnus-no-new-news))) (cons (const file) (choice (const find-file) (const find-file-other-window) (const find-file-other-frame))))) (defcustom org-display-internal-link-with-indirect-buffer nil "Non-nil means, use indirect buffer to display infile links. Activating internal links (from one location in a file to another location in the same file) normally just jumps to the location. When the link is activated with a C-u prefix (or with mouse-3), the link is displayed in another window. When this option is set, the other window actually displays an indirect buffer clone of the current buffer, to avoid any visibility changes to the current buffer." :group 'org-link-follow :type 'boolean) (defcustom org-open-non-existing-files nil "Non-nil means, `org-open-file' will open non-existing files. When nil, an error will be generated." :group 'org-link-follow :type 'boolean) (defcustom org-open-directory-means-index-dot-org nil "Non-nil means, a link to a directory really means to index.org. When nil, following a directory link will run dired or open a finder/explorer window on that directory." :group 'org-link-follow :type 'boolean) (defcustom org-link-mailto-program '(browse-url "mailto:%a?subject=%s") "Function and arguments to call for following mailto links. This is a list with the first element being a lisp function, and the remaining elements being arguments to the function. In string arguments, %a will be replaced by the address, and %s will be replaced by the subject if one was given like in ." :group 'org-link-follow :type '(choice (const :tag "browse-url" (browse-url-mail "mailto:%a?subject=%s")) (const :tag "compose-mail" (compose-mail "%a" "%s")) (const :tag "message-mail" (message-mail "%a" "%s")) (cons :tag "other" (function) (repeat :tag "argument" sexp)))) (defcustom org-confirm-shell-link-function 'yes-or-no-p "Non-nil means, ask for confirmation before executing shell links. Shell links can be dangerous: just think about a link [[shell:rm -rf ~/*][Google Search]] This link would show up in your Org-mode document as \"Google Search\", but really it would remove your entire home directory. Therefore we advise against setting this variable to nil. Just change it to `y-or-n-p' of you want to confirm with a single keystroke rather than having to type \"yes\"." :group 'org-link-follow :type '(choice (const :tag "with yes-or-no (safer)" yes-or-no-p) (const :tag "with y-or-n (faster)" y-or-n-p) (const :tag "no confirmation (dangerous)" nil))) (defcustom org-confirm-elisp-link-function 'yes-or-no-p "Non-nil means, ask for confirmation before executing Emacs Lisp links. Elisp links can be dangerous: just think about a link [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]] This link would show up in your Org-mode document as \"Google Search\", but really it would remove your entire home directory. Therefore we advise against setting this variable to nil. Just change it to `y-or-n-p' of you want to confirm with a single keystroke rather than having to type \"yes\"." :group 'org-link-follow :type '(choice (const :tag "with yes-or-no (safer)" yes-or-no-p) (const :tag "with y-or-n (faster)" y-or-n-p) (const :tag "no confirmation (dangerous)" nil))) (defconst org-file-apps-defaults-gnu '((remote . emacs) (t . mailcap)) "Default file applications on a UNIX or GNU/Linux system. See `org-file-apps'.") (defconst org-file-apps-defaults-macosx '((remote . emacs) (t . "open %s") ("ps.gz" . "gv %s") ("eps.gz" . "gv %s") ("dvi" . "xdvi %s") ("fig" . "xfig %s")) "Default file applications on a MacOS X system. The system \"open\" is known as a default, but we use X11 applications for some files for which the OS does not have a good default. See `org-file-apps'.") (defconst org-file-apps-defaults-windowsnt (list '(remote . emacs) (cons t (list (if (featurep 'xemacs) 'mswindows-shell-execute 'w32-shell-execute) "open" 'file))) "Default file applications on a Windows NT system. The system \"open\" is used for most files. See `org-file-apps'.") (defcustom org-file-apps '( (auto-mode . emacs) ("\\.x?html?\\'" . default) ("\\.pdf\\'" . default) ) "External applications for opening `file:path' items in a document. Org-mode uses system defaults for different file types, but you can use this variable to set the application for a given file extension. The entries in this list are cons cells where the car identifies files and the cdr the corresponding command. Possible values for the file identifier are \"regex\" Regular expression matched against the file name. For backward compatibility, this can also be a string with only alphanumeric characters, which is then interpreted as an extension. `directory' Matches a directory `remote' Matches a remote file, accessible through tramp or efs. Remote files most likely should be visited through Emacs because external applications cannot handle such paths. `auto-mode' Matches files that are mached by any entry in `auto-mode-alist', so all files Emacs knows how to handle. Useing this with command `emacs' will open most files in Emacs. Beware that this will also open html files insite Emacs, unless you add (\"html\" . default) to the list as well. t Default for files not matched by any of the other options. Possible values for the command are: `emacs' The file will be visited by the current Emacs process. `default' Use the default application for this file type, which is the association for t in the list, most likely in the system-specific part. This can be used to overrule an unwanted seting in the system-specific variable. string A command to be executed by a shell; %s will be replaced by the path to the file. sexp A Lisp form which will be evaluated. The file path will be available in the Lisp variable `file'. For more examples, see the system specific constants `org-file-apps-defaults-macosx' `org-file-apps-defaults-windowsnt' `org-file-apps-defaults-gnu'." :group 'org-link-follow :type '(repeat (cons (choice :value "" (string :tag "Extension") (const :tag "Default for unrecognized files" t) (const :tag "Remote file" remote) (const :tag "Links to a directory" directory) (const :tag "Any files that have Emacs modes" auto-mode)) (choice :value "" (const :tag "Visit with Emacs" emacs) (const :tag "Use system default" default) (string :tag "Command") (sexp :tag "Lisp form"))))) (defgroup org-refile nil "Options concerning refiling entries in Org-mode." :tag "Org Remember" :group 'org) (defcustom org-directory "~/org" "Directory with org files. This directory will be used as default to prompt for org files. Used by the hooks for remember.el." :group 'org-refile :group 'org-remember :type 'directory) (defcustom org-default-notes-file (convert-standard-filename "~/.notes") "Default target for storing notes. Used by the hooks for remember.el. This can be a string, or nil to mean the value of `remember-data-file'. You can set this on a per-template basis with the variable `org-remember-templates'." :group 'org-refile :group 'org-remember :type '(choice (const :tag "Default from remember-data-file" nil) file)) (defcustom org-goto-interface 'outline "The default interface to be used for `org-goto'. Allowed vaues are: outline The interface shows an outline of the relevant file and the correct heading is found by moving through the outline or by searching with incremental search. outline-path-completion Headlines in the current buffer are offered via completion." :group 'org-refile :type '(choice (const :tag "Outline" outline) (const :tag "Outline-path-completion" outline-path-completion))) (defcustom org-reverse-note-order nil "Non-nil means, store new notes at the beginning of a file or entry. When nil, new notes will be filed to the end of a file or entry. This can also be a list with cons cells of regular expressions that are matched against file names, and values." :group 'org-remember :type '(choice (const :tag "Reverse always" t) (const :tag "Reverse never" nil) (repeat :tag "By file name regexp" (cons regexp boolean)))) (defcustom org-refile-targets nil "Targets for refiling entries with \\[org-refile]. This is list of cons cells. Each cell contains: - a specification of the files to be considered, either a list of files, or a symbol whose function or variable value will be used to retrieve a file name or a list of file names. Nil means, refile to a different heading in the current buffer. - A specification of how to find candidate refile targets. This may be any of - a cons cell (:tag . \"TAG\") to identify refile targets by a tag. This tag has to be present in all target headlines, inheritance will not be considered. - a cons cell (:todo . \"KEYWORD\") to identify refile targets by todo keyword. - a cons cell (:regexp . \"REGEXP\") with a regular expression matching headlines that are refiling targets. - a cons cell (:level . N). Any headline of level N is considered a target. - a cons cell (:maxlevel . N). Any headline with level <= N is a target. When this variable is nil, all top-level headlines in the current buffer are used, equivalent to the vlaue `((nil . (:level . 1))'." :group 'org-remember :type '(repeat (cons (choice :value org-agenda-files (const :tag "All agenda files" org-agenda-files) (const :tag "Current buffer" nil) (function) (variable) (file)) (choice :tag "Identify target headline by" (cons :tag "Specific tag" (const :tag) (string)) (cons :tag "TODO keyword" (const :todo) (string)) (cons :tag "Regular expression" (const :regexp) (regexp)) (cons :tag "Level number" (const :level) (integer)) (cons :tag "Max Level number" (const :maxlevel) (integer)))))) (defcustom org-refile-use-outline-path nil "Non-nil means, provide refile targets as paths. So a level 3 headline will be available as level1/level2/level3. When the value is `file', also include the file name (without directory) into the path. When `full-file-path', include the full file path." :group 'org-remember :type '(choice (const :tag "Not" nil) (const :tag "Yes" t) (const :tag "Start with file name" file) (const :tag "Start with full file path" full-file-path))) (defgroup org-todo nil "Options concerning TODO items in Org-mode." :tag "Org TODO" :group 'org) (defgroup org-progress nil "Options concerning Progress logging in Org-mode." :tag "Org Progress" :group 'org-time) (defcustom org-todo-keywords '((sequence "TODO" "DONE")) "List of TODO entry keyword sequences and their interpretation. \\This is a list of sequences. Each sequence starts with a symbol, either `sequence' or `type', indicating if the keywords should be interpreted as a sequence of action steps, or as different types of TODO items. The first keywords are states requiring action - these states will select a headline for inclusion into the global TODO list Org-mode produces. If one of the \"keywords\" is the vertical bat \"|\" the remaining keywords signify that no further action is necessary. If \"|\" is not found, the last keyword is treated as the only DONE state of the sequence. The command \\[org-todo] cycles an entry through these states, and one additional state where no keyword is present. For details about this cycling, see the manual. TODO keywords and interpretation can also be set on a per-file basis with the special #+SEQ_TODO and #+TYP_TODO lines. Each keyword can optionally specify a character for fast state selection \(in combination with the variable `org-use-fast-todo-selection') and specifiers for state change logging, using the same syntax that is used in the \"#+TODO:\" lines. For example, \"WAIT(w)\" says that the WAIT state can be selected with the \"w\" key. \"WAIT(w!)\" indicates to record a time stamp each time this state is selected. Each keyword may also specify if a timestamp or a note should be recorded when entering or leaving the state, by adding additional characters in the parenthesis after the keyword. This looks like this: \"WAIT(w@/!)\". \"@\" means to add a note (with time), \"!\" means to record only the time of the state change. With X and Y being either \"@\" or \"!\", \"X/Y\" means use X when entering the state, and use Y when leaving the state if and only if the *target* state does not define X. You may omit any of the fast-selection key or X or /Y, so WAIT(w@), WAIT(w/@) and WAIT(@/@) are all valid. For backward compatibility, this variable may also be just a list of keywords - in this case the interptetation (sequence or type) will be taken from the (otherwise obsolete) variable `org-todo-interpretation'." :group 'org-todo :group 'org-keywords :type '(choice (repeat :tag "Old syntax, just keywords" (string :tag "Keyword")) (repeat :tag "New syntax" (cons (choice :tag "Interpretation" (const :tag "Sequence (cycling hits every state)" sequence) (const :tag "Type (cycling directly to DONE)" type)) (repeat (string :tag "Keyword")))))) (defvar org-todo-keywords-1 nil "All TODO and DONE keywords active in a buffer.") (make-variable-buffer-local 'org-todo-keywords-1) (defvar org-todo-keywords-for-agenda nil) (defvar org-done-keywords-for-agenda nil) (defvar org-todo-keyword-alist-for-agenda nil) (defvar org-tag-alist-for-agenda nil) (defvar org-agenda-contributing-files nil) (defvar org-not-done-keywords nil) (make-variable-buffer-local 'org-not-done-keywords) (defvar org-done-keywords nil) (make-variable-buffer-local 'org-done-keywords) (defvar org-todo-heads nil) (make-variable-buffer-local 'org-todo-heads) (defvar org-todo-sets nil) (make-variable-buffer-local 'org-todo-sets) (defvar org-todo-log-states nil) (make-variable-buffer-local 'org-todo-log-states) (defvar org-todo-kwd-alist nil) (make-variable-buffer-local 'org-todo-kwd-alist) (defvar org-todo-key-alist nil) (make-variable-buffer-local 'org-todo-key-alist) (defvar org-todo-key-trigger nil) (make-variable-buffer-local 'org-todo-key-trigger) (defcustom org-todo-interpretation 'sequence "Controls how TODO keywords are interpreted. This variable is in principle obsolete and is only used for backward compatibility, if the interpretation of todo keywords is not given already in `org-todo-keywords'. See that variable for more information." :group 'org-todo :group 'org-keywords :type '(choice (const sequence) (const type))) (defcustom org-use-fast-todo-selection 'prefix "Non-nil means, use the fast todo selection scheme with C-c C-t. This variable describes if and under what circumstances the cycling mechanism for TODO keywords will be replaced by a single-key, direct selection scheme. When nil, fast selection is never used. When the symbol `prefix', it will be used when `org-todo' is called with a prefix argument, i.e. `C-u C-c C-t' in an Org-mode buffer, and `C-u t' in an agenda buffer. When t, fast selection is used by default. In this case, the prefix argument forces cycling instead. In all cases, the special interface is only used if access keys have actually been assigned by the user, i.e. if keywords in the configuration are followed by a letter in parenthesis, like TODO(t)." :group 'org-todo :type '(choice (const :tag "Never" nil) (const :tag "By default" t) (const :tag "Only with C-u C-c C-t" prefix))) (defcustom org-provide-todo-statistics t "Non-nil means, update todo statistics after insert and toggle. When this is set, todo statistics is updated in the parent of the current entry each time a todo state is changed." :group 'org-todo :type 'boolean) (defcustom org-after-todo-state-change-hook nil "Hook which is run after the state of a TODO item was changed. The new state (a string with a TODO keyword, or nil) is available in the Lisp variable `state'." :group 'org-todo :type 'hook) (defcustom org-todo-state-tags-triggers nil "Tag changes that should be triggered by TODO state changes. This is a list. Each entry is (state-change (tag . flag) .......) State-change can be a string with a state, and empty string to indicate the state that has no TODO keyword, or it can be one of the symbols `todo' or `done', meaning any not-done or done state, respectively." :group 'org-todo :group 'org-tags :type '(repeat (cons (choice :tag "When changing to" (const :tag "Not-done state" todo) (const :tag "Done state" done) (string :tag "State")) (repeat (cons :tag "Tag action" (string :tag "Tag") (choice (const :tag "Add" t) (const :tag "Remove" nil))))))) (defcustom org-log-done nil "Non-nil means, record a CLOSED timestamp when moving an entry to DONE. When equal to the list (done), also prompt for a closing note. This can also be configured on a per-file basis by adding one of the following lines anywhere in the buffer: #+STARTUP: logdone #+STARTUP: lognotedone #+STARTUP: nologdone" :group 'org-todo :group 'org-progress :type '(choice (const :tag "No logging" nil) (const :tag "Record CLOSED timestamp" time) (const :tag "Record CLOSED timestamp with closing note." note))) ;; Normalize old uses of org-log-done. (cond ((eq org-log-done t) (setq org-log-done 'time)) ((and (listp org-log-done) (memq 'done org-log-done)) (setq org-log-done 'note))) (defcustom org-log-note-clock-out nil "Non-nil means, record a note when clocking out of an item. This can also be configured on a per-file basis by adding one of the following lines anywhere in the buffer: #+STARTUP: lognoteclock-out #+STARTUP: nolognoteclock-out" :group 'org-todo :group 'org-progress :type 'boolean) (defcustom org-log-done-with-time t "Non-nil means, the CLOSED time stamp will contain date and time. When nil, only the date will be recorded." :group 'org-progress :type 'boolean) (defcustom org-log-note-headings '((done . "CLOSING NOTE %t") (state . "State %-12s %t") (note . "Note taken on %t") (clock-out . "")) "Headings for notes added to entries. The value is an alist, with the car being a symbol indicating the note context, and the cdr is the heading to be used. The heading may also be the empty string. %t in the heading will be replaced by a time stamp. %s will be replaced by the new TODO state, in double quotes. %u will be replaced by the user name. %U will be replaced by the full user name." :group 'org-todo :group 'org-progress :type '(list :greedy t (cons (const :tag "Heading when closing an item" done) string) (cons (const :tag "Heading when changing todo state (todo sequence only)" state) string) (cons (const :tag "Heading when just taking a note" note) string) (cons (const :tag "Heading when clocking out" clock-out) string))) (unless (assq 'note org-log-note-headings) (push '(note . "%t") org-log-note-headings)) (defcustom org-log-state-notes-insert-after-drawers nil "Non-nil means, insert state change notes after any drawers in entry. Only the drawers that *immediately* follow the headline and the deadline/scheduled line are skipped. When nil, insert notes right after the heading and perhaps the line with deadline/scheduling if present." :group 'org-todo :group 'org-progress :type 'boolean) (defcustom org-log-states-order-reversed t "Non-nil means, the latest state change note will be directly after heading. When nil, the notes will be orderer according to time." :group 'org-todo :group 'org-progress :type 'boolean) (defcustom org-log-repeat 'time "Non-nil means, record moving through the DONE state when triggering repeat. An auto-repeating tasks is immediately switched back to TODO when marked done. If you are not logging state changes (by adding \"@\" or \"!\" to the TODO keyword definition, or recording a closing note by setting `org-log-done', there will be no record of the task moving through DONE. This variable forces taking a note anyway. Possible values are: nil Don't force a record time Record a time stamp note Record a note This option can also be set with on a per-file-basis with #+STARTUP: logrepeat #+STARTUP: lognoterepeat #+STARTUP: nologrepeat You can have local logging settings for a subtree by setting the LOGGING property to one or more of these keywords." :group 'org-todo :group 'org-progress :type '(choice (const :tag "Don't force a record" nil) (const :tag "Force recording the DONE state" time) (const :tag "Force recording a note with the DONE state" note))) (defgroup org-priorities nil "Priorities in Org-mode." :tag "Org Priorities" :group 'org-todo) (defcustom org-highest-priority ?A "The highest priority of TODO items. A character like ?A, ?B etc. Must have a smaller ASCII number than `org-lowest-priority'." :group 'org-priorities :type 'character) (defcustom org-lowest-priority ?C "The lowest priority of TODO items. A character like ?A, ?B etc. Must have a larger ASCII number than `org-highest-priority'." :group 'org-priorities :type 'character) (defcustom org-default-priority ?B "The default priority of TODO items. This is the priority an item get if no explicit priority is given." :group 'org-priorities :type 'character) (defcustom org-priority-start-cycle-with-default t "Non-nil means, start with default priority when starting to cycle. When this is nil, the first step in the cycle will be (depending on the command used) one higher or lower that the default priority." :group 'org-priorities :type 'boolean) (defgroup org-time nil "Options concerning time stamps and deadlines in Org-mode." :tag "Org Time" :group 'org) (defcustom org-insert-labeled-timestamps-at-point nil "Non-nil means, SCHEDULED and DEADLINE timestamps are inserted at point. When nil, these labeled time stamps are forces into the second line of an entry, just after the headline. When scheduling from the global TODO list, the time stamp will always be forced into the second line." :group 'org-time :type 'boolean) (defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>") "Formats for `format-time-string' which are used for time stamps. It is not recommended to change this constant.") (defcustom org-time-stamp-rounding-minutes '(0 5) "Number of minutes to round time stamps to. These are two values, the first applies when first creating a time stamp. The second applies when changing it with the commands `S-up' and `S-down'. When changing the time stamp, this means that it will change in steps of N minutes, as given by the second value. When a setting is 0 or 1, insert the time unmodified. Useful rounding numbers should be factors of 60, so for example 5, 10, 15. When this is larger than 1, you can still force an exact time-stamp by using a double prefix argument to a time-stamp command like `C-c .' or `C-c !', and by using a prefix arg to `S-up/down' to specify the exact number of minutes to shift." :group 'org-time :get '(lambda (var) ; Make sure all entries have 5 elements (if (integerp (default-value var)) (list (default-value var) 5) (default-value var))) :type '(list (integer :tag "when inserting times") (integer :tag "when modifying times"))) ;; Normalize old customizations of this variable. (when (integerp org-time-stamp-rounding-minutes) (setq org-time-stamp-rounding-minutes (list org-time-stamp-rounding-minutes org-time-stamp-rounding-minutes))) (defcustom org-display-custom-times nil "Non-nil means, overlay custom formats over all time stamps. The formats are defined through the variable `org-time-stamp-custom-formats'. To turn this on on a per-file basis, insert anywhere in the file: #+STARTUP: customtime" :group 'org-time :set 'set-default :type 'sexp) (make-variable-buffer-local 'org-display-custom-times) (defcustom org-time-stamp-custom-formats '("<%m/%d/%y %a>" . "<%m/%d/%y %a %H:%M>") ; american "Custom formats for time stamps. See `format-time-string' for the syntax. These are overlayed over the default ISO format if the variable `org-display-custom-times' is set. Time like %H:%M should be at the end of the second format." :group 'org-time :type 'sexp) (defun org-time-stamp-format (&optional long inactive) "Get the right format for a time string." (let ((f (if long (cdr org-time-stamp-formats) (car org-time-stamp-formats)))) (if inactive (concat "[" (substring f 1 -1) "]") f))) (defcustom org-time-clocksum-format "%d:%02d" "The format string used when creating CLOCKSUM lines, or when org-mode generates a time duration." :group 'org-time :type 'string) (defcustom org-deadline-warning-days 14 "No. of days before expiration during which a deadline becomes active. This variable governs the display in sparse trees and in the agenda. When 0 or negative, it means use this number (the absolute value of it) even if a deadline has a different individual lead time specified." :group 'org-time :group 'org-agenda-daily/weekly :type 'number) (defcustom org-read-date-prefer-future t "Non-nil means, assume future for incomplete date input from user. This affects the following situations: 1. The user gives a day, but no month. For example, if today is the 15th, and you enter \"3\", Org-mode will read this as the third of *next* month. However, if you enter \"17\", it will be considered as *this* month. 2. The user gives a month but not a year. For example, if it is april and you enter \"feb 2\", this will be read as feb 2, *next* year. \"May 5\", however, will be this year. Currently this does not work for ISO week specifications. When this option is nil, the current month and year will always be used as defaults." :group 'org-time :type 'boolean) (defcustom org-read-date-display-live t "Non-nil means, display current interpretation of date prompt live. This display will be in an overlay, in the minibuffer." :group 'org-time :type 'boolean) (defcustom org-read-date-popup-calendar t "Non-nil means, pop up a calendar when prompting for a date. In the calendar, the date can be selected with mouse-1. However, the minibuffer will also be active, and you can simply enter the date as well. When nil, only the minibuffer will be available." :group 'org-time :type 'boolean) (if (fboundp 'defvaralias) (defvaralias 'org-popup-calendar-for-date-prompt 'org-read-date-popup-calendar)) (defcustom org-extend-today-until 0 "The hour when your day really ends. Must be an integer. This has influence for the following applications: - When switching the agenda to \"today\". It it is still earlier than the time given here, the day recognized as TODAY is actually yesterday. - When a date is read from the user and it is still before the time given here, the current date and time will be assumed to be yesterday, 23:59. Also, timestamps inserted in remember templates follow this rule. IMPORTANT: This is a feature whose implementation is and likely will remain incomplete. Really, it is only here because past midnight seems to be the favorite working time of John Wiegley :-)" :group 'org-time :type 'number) (defcustom org-edit-timestamp-down-means-later nil "Non-nil means, S-down will increase the time in a time stamp. When nil, S-up will increase." :group 'org-time :type 'boolean) (defcustom org-calendar-follow-timestamp-change t "Non-nil means, make the calendar window follow timestamp changes. When a timestamp is modified and the calendar window is visible, it will be moved to the new date." :group 'org-time :type 'boolean) (defgroup org-tags nil "Options concerning tags in Org-mode." :tag "Org Tags" :group 'org) (defcustom org-tag-alist nil "List of tags allowed in Org-mode files. When this list is nil, Org-mode will base TAG input on what is already in the buffer. The value of this variable is an alist, the car of each entry must be a keyword as a string, the cdr may be a character that is used to select that tag through the fast-tag-selection interface. See the manual for details." :group 'org-tags :type '(repeat (choice (cons (string :tag "Tag name") (character :tag "Access char")) (const :tag "Start radio group" (:startgroup)) (const :tag "End radio group" (:endgroup))))) (defvar org-file-tags nil "List of tags that can be inherited by all entries in the file. The tags will be inherited if the variable `org-use-tag-inheritance' says they should be. This variable is populated from #+TAG lines.") (defcustom org-use-fast-tag-selection 'auto "Non-nil means, use fast tag selection scheme. This is a special interface to select and deselect tags with single keys. When nil, fast selection is never used. When the symbol `auto', fast selection is used if and only if selection characters for tags have been configured, either through the variable `org-tag-alist' or through a #+TAGS line in the buffer. When t, fast selection is always used and selection keys are assigned automatically if necessary." :group 'org-tags :type '(choice (const :tag "Always" t) (const :tag "Never" nil) (const :tag "When selection characters are configured" 'auto))) (defcustom org-fast-tag-selection-single-key nil "Non-nil means, fast tag selection exits after first change. When nil, you have to press RET to exit it. During fast tag selection, you can toggle this flag with `C-c'. This variable can also have the value `expert'. In this case, the window displaying the tags menu is not even shown, until you press C-c again." :group 'org-tags :type '(choice (const :tag "No" nil) (const :tag "Yes" t) (const :tag "Expert" expert))) (defvar org-fast-tag-selection-include-todo nil "Non-nil means, fast tags selection interface will also offer TODO states. This is an undocumented feature, you should not rely on it.") (defcustom org-tags-column (if (featurep 'xemacs) -79 -80) "The column to which tags should be indented in a headline. If this number is positive, it specifies the column. If it is negative, it means that the tags should be flushright to that column. For example, -80 works well for a normal 80 character screen." :group 'org-tags :type 'integer) (defcustom org-auto-align-tags t "Non-nil means, realign tags after pro/demotion of TODO state change. These operations change the length of a headline and therefore shift the tags around. With this options turned on, after each such operation the tags are again aligned to `org-tags-column'." :group 'org-tags :type 'boolean) (defcustom org-use-tag-inheritance t "Non-nil means, tags in levels apply also for sublevels. When nil, only the tags directly given in a specific line apply there. If this option is t, a match early-on in a tree can lead to a large number of matches in the subtree. If you only want to see the first match in a tree during a search, check out the variable `org-tags-match-list-sublevels'. This may also be a list of tags that should be inherited, or a regexp that matches tags that should be inherited." :group 'org-tags :type '(choice (const :tag "Not" nil) (const :tag "Always" t) (repeat :tag "Specific tags" (string :tag "Tag")) (regexp :tag "Tags matched by regexp"))) (defun org-tag-inherit-p (tag) "Check if TAG is one that should be inherited." (cond ((eq org-use-tag-inheritance t) t) ((not org-use-tag-inheritance) nil) ((stringp org-use-tag-inheritance) (string-match org-use-tag-inheritance tag)) ((listp org-use-tag-inheritance) (member tag org-use-tag-inheritance)) (t (error "Invalid setting of `org-use-tag-inheritance'")))) (defcustom org-tags-match-list-sublevels t "Non-nil means list also sublevels of headlines matching tag search. Because of tag inheritance (see variable `org-use-tag-inheritance'), the sublevels of a headline matching a tag search often also match the same search. Listing all of them can create very long lists. Setting this variable to nil causes subtrees of a match to be skipped. This option is off by default, because inheritance in on. If you turn inheritance off, you very likely want to turn this option on. As a special case, if the tag search is restricted to TODO items, the value of this variable is ignored and sublevels are always checked, to make sure all corresponding TODO items find their way into the list." :group 'org-tags :type 'boolean) (defvar org-tags-history nil "History of minibuffer reads for tags.") (defvar org-last-tags-completion-table nil "The last used completion table for tags.") (defvar org-after-tags-change-hook nil "Hook that is run after the tags in a line have changed.") (defgroup org-properties nil "Options concerning properties in Org-mode." :tag "Org Properties" :group 'org) (defcustom org-property-format "%-10s %s" "How property key/value pairs should be formatted by `indent-line'. When `indent-line' hits a property definition, it will format the line according to this format, mainly to make sure that the values are lined-up with respect to each other." :group 'org-properties :type 'string) (defcustom org-use-property-inheritance nil "Non-nil means, properties apply also for sublevels. This setting is chiefly used during property searches. Turning it on can cause significant overhead when doing a search, which is why it is not on by default. When nil, only the properties directly given in the current entry count. When t, every property is inherited. The value may also be a list of properties that should have inheritance, or a regular expression matching properties that should be inherited. However, note that some special properties use inheritance under special circumstances (not in searches). Examples are CATEGORY, ARCHIVE, COLUMNS, and the properties ending in \"_ALL\" when they are used as descriptor for valid values of a property. Note for programmers: When querying an entry with `org-entry-get', you can control if inheritance should be used. By default, `org-entry-get' looks only at the local properties. You can request inheritance by setting the inherit argument to t (to force inheritance) or to `selective' (to respect the setting in this variable)." :group 'org-properties :type '(choice (const :tag "Not" nil) (const :tag "Always" t) (repeat :tag "Specific properties" (string :tag "Property")) (regexp :tag "Properties matched by regexp"))) (defun org-property-inherit-p (property) "Check if PROPERTY is one that should be inherited." (cond ((eq org-use-property-inheritance t) t) ((not org-use-property-inheritance) nil) ((stringp org-use-property-inheritance) (string-match org-use-property-inheritance property)) ((listp org-use-property-inheritance) (member property org-use-property-inheritance)) (t (error "Invalid setting of `org-use-property-inheritance'")))) (defcustom org-columns-default-format "%25ITEM %TODO %3PRIORITY %TAGS" "The default column format, if no other format has been defined. This variable can be set on the per-file basis by inserting a line #+COLUMNS: %25ITEM ....." :group 'org-properties :type 'string) (defcustom org-columns-ellipses ".." "The ellipses to be used when a field in column view is truncated. When this is the empty string, as many characters as possible are shown, but then there will be no visual indication that the field has been truncated. When this is a string of length N, the last N characters of a truncated field are replaced by this string. If the column is narrower than the ellipses string, only part of the ellipses string will be shown." :group 'org-properties :type 'string) (defcustom org-columns-modify-value-for-display-function nil "Function that modifies values for display in column view. For example, it can be used to cut out a certain part from a time stamp. The function must take 2 argments: column-title The tite of the column (*not* the property name) value The value that should be modified. The function should return the value that should be displayed, or nil if the normal value should be used." :group 'org-properties :type 'function) (defcustom org-effort-property "Effort" "The property that is being used to keep track of effort estimates. Effort estimates given in this property need to have the format H:MM." :group 'org-properties :group 'org-progress :type '(string :tag "Property")) (defconst org-global-properties-fixed '(("VISIBILITY_ALL" . "folded children content all")) "List of property/value pairs that can be inherited by any entry. These are fixed values, for the preset properties.") (defcustom org-global-properties nil "List of property/value pairs that can be inherited by any entry. You can set buffer-local values for this by adding lines like #+PROPERTY: NAME VALUE" :group 'org-properties :type '(repeat (cons (string :tag "Property") (string :tag "Value")))) (defvar org-file-properties nil "List of property/value pairs that can be inherited by any entry. Valid for the current buffer. This variable is populated from #+PROPERTY lines.") (make-variable-buffer-local 'org-file-properties) (defgroup org-agenda nil "Options concerning agenda views in Org-mode." :tag "Org Agenda" :group 'org) (defvar org-category nil "Variable used by org files to set a category for agenda display. Such files should use a file variable to set it, for example # -*- mode: org; org-category: \"ELisp\" or contain a special line #+CATEGORY: ELisp If the file does not specify a category, then file's base name is used instead.") (make-variable-buffer-local 'org-category) (put 'org-category 'safe-local-variable '(lambda (x) (or (symbolp x) (stringp x)))) (defcustom org-agenda-files nil "The files to be used for agenda display. Entries may be added to this list with \\[org-agenda-file-to-front] and removed with \\[org-remove-file]. You can also use customize to edit the list. If an entry is a directory, all files in that directory that are matched by `org-agenda-file-regexp' will be part of the file list. If the value of the variable is not a list but a single file name, then the list of agenda files is actually stored and maintained in that file, one agenda file per line." :group 'org-agenda :type '(choice (repeat :tag "List of files and directories" file) (file :tag "Store list in a file\n" :value "~/.agenda_files"))) (defcustom org-agenda-file-regexp "\\`[^.].*\\.org\\'" "Regular expression to match files for `org-agenda-files'. If any element in the list in that variable contains a directory instead of a normal file, all files in that directory that are matched by this regular expression will be included." :group 'org-agenda :type 'regexp) (defcustom org-agenda-text-search-extra-files nil "List of extra files to be searched by text search commands. These files will be search in addition to the agenda files by the commands `org-search-view' (`C-c a s') and `org-occur-in-agenda-files'. Note that these files will only be searched for text search commands, not for the other agenda views like todo lists, tag searches or the weekly agenda. This variable is intended to list notes and possibly archive files that should also be searched by these two commands. In fact, if the first element in the list is the symbol `agenda-archives', than all archive files of all agenda files will be added to the search scope." :group 'org-agenda :type '(set :greedy t (const :tag "Agenda Archives" agenda-archives) (repeat :inline t (file)))) (if (fboundp 'defvaralias) (defvaralias 'org-agenda-multi-occur-extra-files 'org-agenda-text-search-extra-files)) (defcustom org-agenda-skip-unavailable-files nil "Non-nil means to just skip non-reachable files in `org-agenda-files'. A nil value means to remove them, after a query, from the list." :group 'org-agenda :type 'boolean) (defcustom org-calendar-to-agenda-key [?c] "The key to be installed in `calendar-mode-map' for switching to the agenda. The command `org-calendar-goto-agenda' will be bound to this key. The default is the character `c' because then `c' can be used to switch back and forth between agenda and calendar." :group 'org-agenda :type 'sexp) (defcustom org-calendar-agenda-action-key [?k] "The key to be installed in `calendar-mode-map' for agenda-action. The command `org-agenda-action' will be bound to this key. The default is the character `k' because we use the same key in the agenda." :group 'org-agenda :type 'sexp) (eval-after-load "calendar" '(progn (org-defkey calendar-mode-map org-calendar-to-agenda-key 'org-calendar-goto-agenda) (org-defkey calendar-mode-map org-calendar-agenda-action-key 'org-agenda-action))) (defgroup org-latex nil "Options for embedding LaTeX code into Org-mode." :tag "Org LaTeX" :group 'org) (defcustom org-format-latex-options '(:foreground default :background default :scale 1.0 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers ("begin" "$" "$$" "\\(" "\\[")) "Options for creating images from LaTeX fragments. This is a property list with the following properties: :foreground the foreground color for images embedded in Emacs, e.g. \"Black\". `default' means use the foreground of the default face. :background the background color, or \"Transparent\". `default' means use the background of the default face. :scale a scaling factor for the size of the images. :html-foreground, :html-background, :html-scale the same numbers for HTML export. :matchers a list indicating which matchers should be used to find LaTeX fragments. Valid members of this list are: \"begin\" find environments \"$\" find math expressions surrounded by $...$ \"$$\" find math expressions surrounded by $$....$$ \"\\(\" find math expressions surrounded by \\(...\\) \"\\ [\" find math expressions surrounded by \\ [...\\]" :group 'org-latex :type 'plist) (defcustom org-format-latex-header "\\documentclass{article} \\usepackage{fullpage} % do not remove \\usepackage{amssymb} \\usepackage[usenames]{color} \\usepackage{amsmath} \\usepackage{latexsym} \\usepackage[mathscr]{eucal} \\pagestyle{empty} % do not remove" "The document header used for processing LaTeX fragments." :group 'org-latex :type 'string) (defgroup org-font-lock nil "Font-lock settings for highlighting in Org-mode." :tag "Org Font Lock" :group 'org) (defcustom org-level-color-stars-only nil "Non-nil means fontify only the stars in each headline. When nil, the entire headline is fontified. Changing it requires restart of `font-lock-mode' to become effective also in regions already fontified." :group 'org-font-lock :type 'boolean) (defcustom org-hide-leading-stars nil "Non-nil means, hide the first N-1 stars in a headline. This works by using the face `org-hide' for these stars. This face is white for a light background, and black for a dark background. You may have to customize the face `org-hide' to make this work. Changing it requires restart of `font-lock-mode' to become effective also in regions already fontified. You may also set this on a per-file basis by adding one of the following lines to the buffer: #+STARTUP: hidestars #+STARTUP: showstars" :group 'org-font-lock :type 'boolean) (defcustom org-fontify-done-headline nil "Non-nil means, change the face of a headline if it is marked DONE. Normally, only the TODO/DONE keyword indicates the state of a headline. When this is non-nil, the headline after the keyword is set to the `org-headline-done' as an additional indication." :group 'org-font-lock :type 'boolean) (defcustom org-fontify-emphasized-text t "Non-nil means fontify *bold*, /italic/ and _underlined_ text. Changing this variable requires a restart of Emacs to take effect." :group 'org-font-lock :type 'boolean) (defcustom org-highlight-latex-fragments-and-specials nil "Non-nil means, fontify what is treated specially by the exporters." :group 'org-font-lock :type 'boolean) (defcustom org-hide-emphasis-markers nil "Non-nil mean font-lock should hide the emphasis marker characters." :group 'org-font-lock :type 'boolean) (defvar org-emph-re nil "Regular expression for matching emphasis.") (defvar org-verbatim-re nil "Regular expression for matching verbatim text.") (defvar org-emphasis-regexp-components) ; defined just below (defvar org-emphasis-alist) ; defined just below (defun org-set-emph-re (var val) "Set variable and compute the emphasis regular expression." (set var val) (when (and (boundp 'org-emphasis-alist) (boundp 'org-emphasis-regexp-components) org-emphasis-alist org-emphasis-regexp-components) (let* ((e org-emphasis-regexp-components) (pre (car e)) (post (nth 1 e)) (border (nth 2 e)) (body (nth 3 e)) (nl (nth 4 e)) (stacked (and nil (nth 5 e))) ; stacked is no longer allowed, forced to nil (body1 (concat body "*?")) (markers (mapconcat 'car org-emphasis-alist "")) (vmarkers (mapconcat (lambda (x) (if (eq (nth 4 x) 'verbatim) (car x) "")) org-emphasis-alist ""))) ;; make sure special characters appear at the right position in the class (if (string-match "\\^" markers) (setq markers (concat (replace-match "" t t markers) "^"))) (if (string-match "-" markers) (setq markers (concat (replace-match "" t t markers) "-"))) (if (string-match "\\^" vmarkers) (setq vmarkers (concat (replace-match "" t t vmarkers) "^"))) (if (string-match "-" vmarkers) (setq vmarkers (concat (replace-match "" t t vmarkers) "-"))) (if (> nl 0) (setq body1 (concat body1 "\\(?:\n" body "*?\\)\\{0," (int-to-string nl) "\\}"))) ;; Make the regexp (setq org-emph-re (concat "\\([" pre (if (and nil stacked) markers) "]\\|^\\)" "\\(" "\\([" markers "]\\)" "\\(" "[^" border "]\\|" "[^" border (if (and nil stacked) markers) "]" body1 "[^" border (if (and nil stacked) markers) "]" "\\)" "\\3\\)" "\\([" post (if (and nil stacked) markers) "]\\|$\\)")) (setq org-verbatim-re (concat "\\([" pre "]\\|^\\)" "\\(" "\\([" vmarkers "]\\)" "\\(" "[^" border "]\\|" "[^" border "]" body1 "[^" border "]" "\\)" "\\3\\)" "\\([" post "]\\|$\\)"))))) (defcustom org-emphasis-regexp-components '(" \t('\"" "- \t.,:?;'\")" " \t\r\n,\"'" "." 1) "Components used to build the regular expression for emphasis. This is a list with 6 entries. Terminology: In an emphasis string like \" *strong word* \", we call the initial space PREMATCH, the final space POSTMATCH, the stars MARKERS, \"s\" and \"d\" are BORDER characters and \"trong wor\" is the body. The different components in this variable specify what is allowed/forbidden in each part: pre Chars allowed as prematch. Beginning of line will be allowed too. post Chars allowed as postmatch. End of line will be allowed too. border The chars *forbidden* as border characters. body-regexp A regexp like \".\" to match a body character. Don't use non-shy groups here, and don't allow newline here. newline The maximum number of newlines allowed in an emphasis exp. Use customize to modify this, or restart Emacs after changing it." :group 'org-font-lock :set 'org-set-emph-re :type '(list (sexp :tag "Allowed chars in pre ") (sexp :tag "Allowed chars in post ") (sexp :tag "Forbidden chars in border ") (sexp :tag "Regexp for body ") (integer :tag "number of newlines allowed") (option (boolean :tag "Please ignore this button")))) (defcustom org-emphasis-alist `(("*" bold "" "") ("/" italic "" "") ("_" underline "" "") ("=" org-code "" "" verbatim) ("~" org-verbatim "" "" verbatim) ("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t)) "" "") ) "Special syntax for emphasized text. Text starting and ending with a special character will be emphasized, for example *bold*, _underlined_ and /italic/. This variable sets the marker characters, the face to be used by font-lock for highlighting in Org-mode Emacs buffers, and the HTML tags to be used for this. Use customize to modify this, or restart Emacs after changing it." :group 'org-font-lock :set 'org-set-emph-re :type '(repeat (list (string :tag "Marker character") (choice (face :tag "Font-lock-face") (plist :tag "Face property list")) (string :tag "HTML start tag") (string :tag "HTML end tag") (option (const verbatim))))) ;;; Miscellaneous options (defgroup org-completion nil "Completion in Org-mode." :tag "Org Completion" :group 'org) (defcustom org-completion-fallback-command 'hippie-expand "The expansion command called by \\[org-complete] in normal context. Normal means, no org-mode-specific context." :group 'org-completion :type 'function) ;;; Functions and variables from ther packages ;; Declared here to avoid compiler warnings ;; XEmacs only (defvar outline-mode-menu-heading) (defvar outline-mode-menu-show) (defvar outline-mode-menu-hide) (defvar zmacs-regions) ; XEmacs regions ;; Emacs only (defvar mark-active) ;; Various packages (declare-function calendar-absolute-from-iso "cal-iso" (date)) (declare-function calendar-forward-day "cal-move" (arg)) (declare-function calendar-goto-date "cal-move" (date)) (declare-function calendar-goto-today "cal-move" ()) (declare-function calendar-iso-from-absolute "cal-iso" (date)) (defvar calc-embedded-close-formula) (defvar calc-embedded-open-formula) (declare-function cdlatex-tab "ext:cdlatex" ()) (declare-function dired-get-filename "dired" (&optional localp no-error-if-not-filep)) (defvar font-lock-unfontify-region-function) (declare-function iswitchb-mode "iswitchb" (&optional arg)) (declare-function iswitchb-read-buffer (prompt &optional default require-match start matches-set)) (defvar iswitchb-temp-buflist) (declare-function org-gnus-follow-link "org-gnus" (&optional group article)) (declare-function org-agenda-skip "org-agenda" ()) (declare-function org-format-agenda-item "org-agenda" (extra txt &optional category tags dotime noprefix remove-re)) (declare-function org-agenda-new-marker "org-agenda" (&optional pos)) (declare-function org-agenda-change-all-lines "org-agenda" (newhead hdmarker &optional fixface)) (declare-function org-agenda-set-restriction-lock "org-agenda" (&optional type)) (declare-function org-agenda-maybe-redo "org-agenda" ()) (declare-function org-agenda-save-markers-for-cut-and-paste "org-agenda" (beg end)) (declare-function parse-time-string "parse-time" (string)) (declare-function remember "remember" (&optional initial)) (declare-function remember-buffer-desc "remember" ()) (declare-function remember-finalize "remember" ()) (defvar remember-save-after-remembering) (defvar remember-data-file) (defvar remember-register) (defvar remember-buffer) (defvar remember-handler-functions) (defvar remember-annotation-functions) (defvar texmathp-why) (declare-function speedbar-line-directory "speedbar" (&optional depth)) (declare-function table--at-cell-p "table" (position &optional object at-column)) (defvar w3m-current-url) (defvar w3m-current-title) (defvar org-latex-regexps) ;;; Autoload and prepare some org modules ;; Some table stuff that needs to be defined here, because it is used ;; by the functions setting up org-mode or checking for table context. (defconst org-table-any-line-regexp "^[ \t]*\\(|\\|\\+-[-+]\\)" "Detects an org-type or table-type table.") (defconst org-table-line-regexp "^[ \t]*|" "Detects an org-type table line.") (defconst org-table-dataline-regexp "^[ \t]*|[^-]" "Detects an org-type table line.") (defconst org-table-hline-regexp "^[ \t]*|-" "Detects an org-type table hline.") (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]" "Detects a table-type table hline.") (defconst org-table-any-border-regexp "^[ \t]*[^|+ \t]" "Searching from within a table (any type) this finds the first line outside the table.") ;; Autoload the functions in org-table.el that are needed by functions here. (eval-and-compile (org-autoload "org-table" '(org-table-align org-table-begin org-table-blank-field org-table-convert org-table-convert-region org-table-copy-down org-table-copy-region org-table-create org-table-create-or-convert-from-region org-table-create-with-table.el org-table-current-dline org-table-cut-region org-table-delete-column org-table-edit-field org-table-edit-formulas org-table-end org-table-eval-formula org-table-export org-table-field-info org-table-get-stored-formulas org-table-goto-column org-table-hline-and-move org-table-import org-table-insert-column org-table-insert-hline org-table-insert-row org-table-iterate org-table-justify-field-maybe org-table-kill-row org-table-maybe-eval-formula org-table-maybe-recalculate-line org-table-move-column org-table-move-column-left org-table-move-column-right org-table-move-row org-table-move-row-down org-table-move-row-up org-table-next-field org-table-next-row org-table-paste-rectangle org-table-previous-field org-table-recalculate org-table-rotate-recalc-marks org-table-sort-lines org-table-sum org-table-toggle-coordinate-overlays org-table-toggle-formula-debugger org-table-wrap-region orgtbl-mode turn-on-orgtbl org-table-to-lisp))) (defun org-at-table-p (&optional table-type) "Return t if the cursor is inside an org-type table. If TABLE-TYPE is non-nil, also check for table.el-type tables." (if org-enable-table-editor (save-excursion (beginning-of-line 1) (looking-at (if table-type org-table-any-line-regexp org-table-line-regexp))) nil)) (defsubst org-table-p () (org-at-table-p)) (defun org-at-table.el-p () "Return t if and only if we are at a table.el table." (and (org-at-table-p 'any) (save-excursion (goto-char (org-table-begin 'any)) (looking-at org-table1-hline-regexp)))) (defun org-table-recognize-table.el () "If there is a table.el table nearby, recognize it and move into it." (if org-table-tab-recognizes-table.el (if (org-at-table.el-p) (progn (beginning-of-line 1) (if (looking-at org-table-dataline-regexp) nil (if (looking-at org-table1-hline-regexp) (progn (beginning-of-line 2) (if (looking-at org-table-any-border-regexp) (beginning-of-line -1))))) (if (re-search-forward "|" (org-table-end t) t) (progn (require 'table) (if (table--at-cell-p (point)) t (message "recognizing table.el table...") (table-recognize-table) (message "recognizing table.el table...done"))) (error "This should not happen...")) t) nil) nil)) (defun org-at-table-hline-p () "Return t if the cursor is inside a hline in a table." (if org-enable-table-editor (save-excursion (beginning-of-line 1) (looking-at org-table-hline-regexp)) nil)) (defvar org-table-clean-did-remove-column nil) (defun org-table-map-tables (function) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward org-table-any-line-regexp nil t) (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))) (beginning-of-line 1) (if (looking-at org-table-line-regexp) (save-excursion (funcall function))) (re-search-forward org-table-any-border-regexp nil 1)))) (message "Mapping tables: done")) ;; Declare and autoload functions from org-exp.el (declare-function org-default-export-plist "org-exp") (declare-function org-infile-export-plist "org-exp") (declare-function org-get-current-options "org-exp") (eval-and-compile (org-autoload "org-exp" '(org-export org-export-as-ascii org-export-visible org-insert-export-options-template org-export-as-html-and-open org-export-as-html-batch org-export-as-html-to-buffer org-replace-region-by-html org-export-region-as-html org-export-as-html org-export-icalendar-this-file org-export-icalendar-all-agenda-files org-table-clean-before-export org-export-icalendar-combine-agenda-files org-export-as-xoxo))) ;; Declare and autoload functions from org-agenda.el (eval-and-compile (org-autoload "org-agenda" '(org-agenda org-agenda-list org-search-view org-todo-list org-tags-view org-agenda-list-stuck-projects org-diary org-agenda-to-appt))) ;; Autoload org-remember (eval-and-compile (org-autoload "org-remember" '(org-remember-insinuate org-remember-annotation org-remember-apply-template org-remember org-remember-handler))) ;; Autoload org-clock.el (declare-function org-clock-save-markers-for-cut-and-paste "org-clock" (beg end)) (declare-function org-update-mode-line "org-clock" ()) (defvar org-clock-start-time) (defvar org-clock-marker (make-marker) "Marker recording the last clock-in.") (eval-and-compile (org-autoload "org-clock" '(org-clock-in org-clock-out org-clock-cancel org-clock-goto org-clock-sum org-clock-display org-remove-clock-overlays org-clock-report org-clocktable-shift org-dblock-write:clocktable org-get-clocktable))) (defun org-clock-update-time-maybe () "If this is a CLOCK line, update it and return t. Otherwise, return nil." (interactive) (save-excursion (beginning-of-line 1) (skip-chars-forward " \t") (when (looking-at org-clock-string) (let ((re (concat "[ \t]*" org-clock-string " *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]" "\\([ \t]*=>.*\\)?\\)?")) ts te h m s neg) (cond ((not (looking-at re)) nil) ((not (match-end 2)) (when (and (equal (marker-buffer org-clock-marker) (current-buffer)) (> org-clock-marker (point)) (<= org-clock-marker (point-at-eol))) ;; The clock is running here (setq org-clock-start-time (apply 'encode-time (org-parse-time-string (match-string 1)))) (org-update-mode-line))) (t (and (match-end 4) (delete-region (match-beginning 4) (match-end 4))) (end-of-line 1) (setq ts (match-string 1) te (match-string 3)) (setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te))) (time-to-seconds (apply 'encode-time (org-parse-time-string ts)))) neg (< s 0) s (abs s) h (floor (/ s 3600)) s (- s (* 3600 h)) m (floor (/ s 60)) s (- s (* 60 s))) (insert " => " (format (if neg "-%d:%02d" "%2d:%02d") h m)) t)))))) (defun org-check-running-clock () "Check if the current buffer contains the running clock. If yes, offer to stop it and to save the buffer with the changes." (when (and (equal (marker-buffer org-clock-marker) (current-buffer)) (y-or-n-p (format "Clock-out in buffer %s before killing it? " (buffer-name)))) (org-clock-out) (when (y-or-n-p "Save changed buffer?") (save-buffer)))) (defun org-clocktable-try-shift (dir n) "Check if this line starts a clock table, if yes, shift the time block." (when (org-match-line "#\\+BEGIN: clocktable\\>") (org-clocktable-shift dir n))) ;; Autoload archiving code ;; The stuff that is needed for cycling and tags has to be defined here. (defgroup org-archive nil "Options concerning archiving in Org-mode." :tag "Org Archive" :group 'org-structure) (defcustom org-archive-location "%s_archive::" "The location where subtrees should be archived. Otherwise, the value of this variable is a string, consisting of two parts, separated by a double-colon. The first part is a file name - when omitted, archiving happens in the same file. %s will be replaced by the current file name (without directory part). Archiving to a different file is useful to keep archived entries from contributing to the Org-mode Agenda. The part after the double colon is a headline. The archived entries will be filed under that headline. When omitted, the subtrees are simply filed away at the end of the file, as top-level entries. Here are a few examples: \"%s_archive::\" If the current file is Projects.org, archive in file Projects.org_archive, as top-level trees. This is the default. \"::* Archived Tasks\" Archive in the current file, under the top-level headline \"* Archived Tasks\". \"~/org/archive.org::\" Archive in file ~/org/archive.org (absolute path), as top-level trees. \"basement::** Finished Tasks\" Archive in file ./basement (relative path), as level 3 trees below the level 2 heading \"** Finished Tasks\". You may set this option on a per-file basis by adding to the buffer a line like #+ARCHIVE: basement::** Finished Tasks You may also define it locally for a subtree by setting an ARCHIVE property in the entry. If such a property is found in an entry, or anywhere up the hierarchy, it will be used." :group 'org-archive :type 'string) (defcustom org-archive-tag "ARCHIVE" "The tag that marks a subtree as archived. An archived subtree does not open during visibility cycling, and does not contribute to the agenda listings. After changing this, font-lock must be restarted in the relevant buffers to get the proper fontification." :group 'org-archive :group 'org-keywords :type 'string) (defcustom org-agenda-skip-archived-trees t "Non-nil means, the agenda will skip any items located in archived trees. An archived tree is a tree marked with the tag ARCHIVE. The use of this variable is no longer recommended, you should leave it at the value t. Instead, use the key `v' to cycle the archives-mode in the agenda." :group 'org-archive :group 'org-agenda-skip :type 'boolean) (defcustom org-cycle-open-archived-trees nil "Non-nil means, `org-cycle' will open archived trees. An archived tree is a tree marked with the tag ARCHIVE. When nil, archived trees will stay folded. You can still open them with normal outline commands like `show-all', but not with the cycling commands." :group 'org-archive :group 'org-cycle :type 'boolean) (defcustom org-sparse-tree-open-archived-trees nil "Non-nil means sparse tree construction shows matches in archived trees. When nil, matches in these trees are highlighted, but the trees are kept in collapsed state." :group 'org-archive :group 'org-sparse-trees :type 'boolean) (defun org-cycle-hide-archived-subtrees (state) "Re-hide all archived subtrees after a visibility state change." (when (and (not org-cycle-open-archived-trees) (not (memq state '(overview folded)))) (save-excursion (let* ((globalp (memq state '(contents all))) (beg (if globalp (point-min) (point))) (end (if globalp (point-max) (org-end-of-subtree t)))) (org-hide-archived-subtrees beg end) (goto-char beg) (if (looking-at (concat ".*:" org-archive-tag ":")) (message "%s" (substitute-command-keys "Subtree is archived and stays closed. Use \\[org-force-cycle-archived] to cycle it anyway."))))))) (defun org-force-cycle-archived () "Cycle subtree even if it is archived." (interactive) (setq this-command 'org-cycle) (let ((org-cycle-open-archived-trees t)) (call-interactively 'org-cycle))) (defun org-hide-archived-subtrees (beg end) "Re-hide all archived subtrees after a visibility state change." (save-excursion (let* ((re (concat ":" org-archive-tag ":"))) (goto-char beg) (while (re-search-forward re end t) (and (org-on-heading-p) (hide-subtree)) (org-end-of-subtree t))))) (defalias 'org-advertized-archive-subtree 'org-archive-subtree) (eval-and-compile (org-autoload "org-archive" '(org-add-archive-files org-archive-subtree org-archive-to-archive-sibling org-toggle-archive-tag))) ;; Autoload Column View Code (declare-function org-columns-number-to-string "org-colview") (declare-function org-columns-get-format-and-top-level "org-colview") (declare-function org-columns-compute "org-colview") (org-autoload (if (featurep 'xemacs) "org-colview-xemacs" "org-colview") '(org-columns-number-to-string org-columns-get-format-and-top-level org-columns-compute org-agenda-columns org-columns-remove-overlays org-columns org-insert-columns-dblock org-dblock-write:columnview)) ;; Autoload ID code (org-autoload "org-id" '(org-id-get-create org-id-new org-id-copy org-id-get org-id-get-with-outline-path-completion org-id-get-with-outline-drilling org-id-goto org-id-find)) ;;; Variables for pre-computed regular expressions, all buffer local (defvar org-drawer-regexp nil "Matches first line of a hidden block.") (make-variable-buffer-local 'org-drawer-regexp) (defvar org-todo-regexp nil "Matches any of the TODO state keywords.") (make-variable-buffer-local 'org-todo-regexp) (defvar org-not-done-regexp nil "Matches any of the TODO state keywords except the last one.") (make-variable-buffer-local 'org-not-done-regexp) (defvar org-todo-line-regexp nil "Matches a headline and puts TODO state into group 2 if present.") (make-variable-buffer-local 'org-todo-line-regexp) (defvar org-complex-heading-regexp nil "Matches a headline and puts everything into groups: group 1: the stars group 2: The todo keyword, maybe group 3: Priority cookie group 4: True headline group 5: Tags") (make-variable-buffer-local 'org-complex-heading-regexp) (defvar org-todo-line-tags-regexp nil "Matches a headline and puts TODO state into group 2 if present. Also put tags into group 4 if tags are present.") (make-variable-buffer-local 'org-todo-line-tags-regexp) (defvar org-nl-done-regexp nil "Matches newline followed by a headline with the DONE keyword.") (make-variable-buffer-local 'org-nl-done-regexp) (defvar org-looking-at-done-regexp nil "Matches the DONE keyword a point.") (make-variable-buffer-local 'org-looking-at-done-regexp) (defvar org-ds-keyword-length 12 "Maximum length of the Deadline and SCHEDULED keywords.") (make-variable-buffer-local 'org-ds-keyword-length) (defvar org-deadline-regexp nil "Matches the DEADLINE keyword.") (make-variable-buffer-local 'org-deadline-regexp) (defvar org-deadline-time-regexp nil "Matches the DEADLINE keyword together with a time stamp.") (make-variable-buffer-local 'org-deadline-time-regexp) (defvar org-deadline-line-regexp nil "Matches the DEADLINE keyword and the rest of the line.") (make-variable-buffer-local 'org-deadline-line-regexp) (defvar org-scheduled-regexp nil "Matches the SCHEDULED keyword.") (make-variable-buffer-local 'org-scheduled-regexp) (defvar org-scheduled-time-regexp nil "Matches the SCHEDULED keyword together with a time stamp.") (make-variable-buffer-local 'org-scheduled-time-regexp) (defvar org-closed-time-regexp nil "Matches the CLOSED keyword together with a time stamp.") (make-variable-buffer-local 'org-closed-time-regexp) (defvar org-keyword-time-regexp nil "Matches any of the 4 keywords, together with the time stamp.") (make-variable-buffer-local 'org-keyword-time-regexp) (defvar org-keyword-time-not-clock-regexp nil "Matches any of the 3 keywords, together with the time stamp.") (make-variable-buffer-local 'org-keyword-time-not-clock-regexp) (defvar org-maybe-keyword-time-regexp nil "Matches a timestamp, possibly preceeded by a keyword.") (make-variable-buffer-local 'org-maybe-keyword-time-regexp) (defvar org-planning-or-clock-line-re nil "Matches a line with planning or clock info.") (make-variable-buffer-local 'org-planning-or-clock-line-re) (defconst org-plain-time-of-day-regexp (concat "\\(\\<[012]?[0-9]" "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)" "\\(--?" "\\(\\<[012]?[0-9]" "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)" "\\)?") "Regular expression to match a plain time or time range. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following groups carry important information: 0 the full match 1 the first time, range or not 8 the second time, if it is a range.") (defconst org-plain-time-extension-regexp (concat "\\(\\<[012]?[0-9]" "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)" "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?") "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40. Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following groups carry important information: 0 the full match 7 hours of duration 9 minutes of duration") (defconst org-stamp-time-of-day-regexp (concat "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)" "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>" "\\(--?" "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?") "Regular expression to match a timestamp time or time range. After a match, the following groups carry important information: 0 the full match 1 date plus weekday, for backreferencing to make sure both times on same day 2 the first time, range or not 4 the second time, if it is a range.") (defconst org-startup-options '(("fold" org-startup-folded t) ("overview" org-startup-folded t) ("nofold" org-startup-folded nil) ("showall" org-startup-folded nil) ("content" org-startup-folded content) ("hidestars" org-hide-leading-stars t) ("showstars" org-hide-leading-stars nil) ("odd" org-odd-levels-only t) ("oddeven" org-odd-levels-only nil) ("align" org-startup-align-all-tables t) ("noalign" org-startup-align-all-tables nil) ("customtime" org-display-custom-times t) ("logdone" org-log-done time) ("lognotedone" org-log-done note) ("nologdone" org-log-done nil) ("lognoteclock-out" org-log-note-clock-out t) ("nolognoteclock-out" org-log-note-clock-out nil) ("logrepeat" org-log-repeat state) ("lognoterepeat" org-log-repeat note) ("nologrepeat" org-log-repeat nil) ("constcgs" constants-unit-system cgs) ("constSI" constants-unit-system SI)) "Variable associated with STARTUP options for org-mode. Each element is a list of three items: The startup options as written in the #+STARTUP line, the corresponding variable, and the value to set this variable to if the option is found. An optional forth element PUSH means to push this value onto the list in the variable.") (defun org-set-regexps-and-options () "Precompute regular expressions for current buffer." (when (org-mode-p) (org-set-local 'org-todo-kwd-alist nil) (org-set-local 'org-todo-key-alist nil) (org-set-local 'org-todo-key-trigger nil) (org-set-local 'org-todo-keywords-1 nil) (org-set-local 'org-done-keywords nil) (org-set-local 'org-todo-heads nil) (org-set-local 'org-todo-sets nil) (org-set-local 'org-todo-log-states nil) (org-set-local 'org-file-properties nil) (org-set-local 'org-file-tags nil) (let ((re (org-make-options-regexp '("CATEGORY" "SEQ_TODO" "TYP_TODO" "TODO" "COLUMNS" "STARTUP" "ARCHIVE" "FILETAGS" "TAGS" "LINK" "PRIORITIES" "CONSTANTS" "PROPERTY" "DRAWERS" "SETUPFILE"))) (splitre "[ \t]+") kwds kws0 kwsa key log value cat arch tags const links hw dws tail sep kws1 prio props ftags drawers ext-setup-or-nil setup-contents (start 0)) (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (or (and ext-setup-or-nil (string-match re ext-setup-or-nil start) (setq start (match-end 0))) (and (setq ext-setup-or-nil nil start 0) (re-search-forward re nil t))) (setq key (upcase (match-string 1 ext-setup-or-nil)) value (org-match-string-no-properties 2 ext-setup-or-nil)) (cond ((equal key "CATEGORY") (if (string-match "[ \t]+$" value) (setq value (replace-match "" t t value))) (setq cat value)) ((member key '("SEQ_TODO" "TODO")) (push (cons 'sequence (org-split-string value splitre)) kwds)) ((equal key "TYP_TODO") (push (cons 'type (org-split-string value splitre)) kwds)) ((equal key "TAGS") (setq tags (append tags (org-split-string value splitre)))) ((equal key "COLUMNS") (org-set-local 'org-columns-default-format value)) ((equal key "LINK") (when (string-match "^\\(\\S-+\\)[ \t]+\\(.+\\)" value) (push (cons (match-string 1 value) (org-trim (match-string 2 value))) links))) ((equal key "PRIORITIES") (setq prio (org-split-string value " +"))) ((equal key "PROPERTY") (when (string-match "\\(\\S-+\\)\\s-+\\(.*\\)" value) (push (cons (match-string 1 value) (match-string 2 value)) props))) ((equal key "FILETAGS") (when (string-match "\\S-" value) (setq ftags (append ftags (apply 'append (mapcar (lambda (x) (org-split-string x ":")) (org-split-string value))))))) ((equal key "DRAWERS") (setq drawers (org-split-string value splitre))) ((equal key "CONSTANTS") (setq const (append const (org-split-string value splitre)))) ((equal key "STARTUP") (let ((opts (org-split-string value splitre)) l var val) (while (setq l (pop opts)) (when (setq l (assoc l org-startup-options)) (setq var (nth 1 l) val (nth 2 l)) (if (not (nth 3 l)) (set (make-local-variable var) val) (if (not (listp (symbol-value var))) (set (make-local-variable var) nil)) (set (make-local-variable var) (symbol-value var)) (add-to-list var val)))))) ((equal key "ARCHIVE") (string-match " *$" value) (setq arch (replace-match "" t t value)) (remove-text-properties 0 (length arch) '(face t fontified t) arch)) ((equal key "SETUPFILE") (setq setup-contents (org-file-contents (expand-file-name (org-remove-double-quotes value)) 'noerror)) (if (not ext-setup-or-nil) (setq ext-setup-or-nil setup-contents start 0) (setq ext-setup-or-nil (concat (substring ext-setup-or-nil 0 start) "\n" setup-contents "\n" (substring ext-setup-or-nil start))))) )))) (when cat (org-set-local 'org-category (intern cat)) (push (cons "CATEGORY" cat) props)) (when prio (if (< (length prio) 3) (setq prio '("A" "C" "B"))) (setq prio (mapcar 'string-to-char prio)) (org-set-local 'org-highest-priority (nth 0 prio)) (org-set-local 'org-lowest-priority (nth 1 prio)) (org-set-local 'org-default-priority (nth 2 prio))) (and props (org-set-local 'org-file-properties (nreverse props))) (and ftags (org-set-local 'org-file-tags ftags)) (and drawers (org-set-local 'org-drawers drawers)) (and arch (org-set-local 'org-archive-location arch)) (and links (setq org-link-abbrev-alist-local (nreverse links))) ;; Process the TODO keywords (unless kwds ;; Use the global values as if they had been given locally. (setq kwds (default-value 'org-todo-keywords)) (if (stringp (car kwds)) (setq kwds (list (cons org-todo-interpretation (default-value 'org-todo-keywords))))) (setq kwds (reverse kwds))) (setq kwds (nreverse kwds)) (let (inter kws kw) (while (setq kws (pop kwds)) (setq inter (pop kws) sep (member "|" kws) kws0 (delete "|" (copy-sequence kws)) kwsa nil kws1 (mapcar (lambda (x) ;; 1 2 (if (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?.*?)\\)?$" x) (progn (setq kw (match-string 1 x) key (and (match-end 2) (match-string 2 x)) log (org-extract-log-state-settings x)) (push (cons kw (and key (string-to-char key))) kwsa) (and log (push log org-todo-log-states)) kw) (error "Invalid TODO keyword %s" x))) kws0) kwsa (if kwsa (append '((:startgroup)) (nreverse kwsa) '((:endgroup)))) hw (car kws1) dws (if sep (org-remove-keyword-keys (cdr sep)) (last kws1)) tail (list inter hw (car dws) (org-last dws))) (add-to-list 'org-todo-heads hw 'append) (push kws1 org-todo-sets) (setq org-done-keywords (append org-done-keywords dws nil)) (setq org-todo-key-alist (append org-todo-key-alist kwsa)) (mapc (lambda (x) (push (cons x tail) org-todo-kwd-alist)) kws1) (setq org-todo-keywords-1 (append org-todo-keywords-1 kws1 nil))) (setq org-todo-sets (nreverse org-todo-sets) org-todo-kwd-alist (nreverse org-todo-kwd-alist) org-todo-key-trigger (delq nil (mapcar 'cdr org-todo-key-alist)) org-todo-key-alist (org-assign-fast-keys org-todo-key-alist))) ;; Process the constants (when const (let (e cst) (while (setq e (pop const)) (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) (push (cons (match-string 1 e) (match-string 2 e)) cst))) (setq org-table-formula-constants-local cst))) ;; Process the tags. (when tags (let (e tgs) (while (setq e (pop tags)) (cond ((equal e "{") (push '(:startgroup) tgs)) ((equal e "}") (push '(:endgroup) tgs)) ((string-match (org-re "^\\([[:alnum:]_@]+\\)(\\(.\\))$") e) (push (cons (match-string 1 e) (string-to-char (match-string 2 e))) tgs)) (t (push (list e) tgs)))) (org-set-local 'org-tag-alist nil) (while (setq e (pop tgs)) (or (and (stringp (car e)) (assoc (car e) org-tag-alist)) (push e org-tag-alist))))) ;; Compute the regular expressions and other local variables (if (not org-done-keywords) (setq org-done-keywords (list (org-last org-todo-keywords-1)))) (setq org-ds-keyword-length (+ 2 (max (length org-deadline-string) (length org-scheduled-string) (length org-clock-string) (length org-closed-string))) org-drawer-regexp (concat "^[ \t]*:\\(" (mapconcat 'regexp-quote org-drawers "\\|") "\\):[ \t]*$") org-not-done-keywords (org-delete-all org-done-keywords (copy-sequence org-todo-keywords-1)) org-todo-regexp (concat "\\<\\(" (mapconcat 'regexp-quote org-todo-keywords-1 "\\|") "\\)\\>") org-not-done-regexp (concat "\\<\\(" (mapconcat 'regexp-quote org-not-done-keywords "\\|") "\\)\\>") org-todo-line-regexp (concat "^\\(\\*+\\)[ \t]+\\(?:\\(" (mapconcat 'regexp-quote org-todo-keywords-1 "\\|") "\\)\\>\\)?[ \t]*\\(.*\\)") org-complex-heading-regexp (concat "^\\(\\*+\\)\\(?:[ \t]+\\(" (mapconcat 'regexp-quote org-todo-keywords-1 "\\|") "\\)\\>\\)?\\(?:[ \t]*\\(\\[#.\\]\\)\\)?[ \t]*\\(.*?\\)" "\\(?:[ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$") org-nl-done-regexp (concat "\n\\*+[ \t]+" "\\(?:" (mapconcat 'regexp-quote org-done-keywords "\\|") "\\)" "\\>") org-todo-line-tags-regexp (concat "^\\(\\*+\\)[ \t]+\\(?:\\(" (mapconcat 'regexp-quote org-todo-keywords-1 "\\|") (org-re "\\)\\>\\)? *\\(.*?\\([ \t]:[[:alnum:]:_@]+:[ \t]*\\)?$\\)")) org-looking-at-done-regexp (concat "^" "\\(?:" (mapconcat 'regexp-quote org-done-keywords "\\|") "\\)" "\\>") org-deadline-regexp (concat "\\<" org-deadline-string) org-deadline-time-regexp (concat "\\<" org-deadline-string " *<\\([^>]+\\)>") org-deadline-line-regexp (concat "\\<\\(" org-deadline-string "\\).*") org-scheduled-regexp (concat "\\<" org-scheduled-string) org-scheduled-time-regexp (concat "\\<" org-scheduled-string " *<\\([^>]+\\)>") org-closed-time-regexp (concat "\\<" org-closed-string " *\\[\\([^]]+\\)\\]") org-keyword-time-regexp (concat "\\<\\(" org-scheduled-string "\\|" org-deadline-string "\\|" org-closed-string "\\|" org-clock-string "\\)" " *[[<]\\([^]>]+\\)[]>]") org-keyword-time-not-clock-regexp (concat "\\<\\(" org-scheduled-string "\\|" org-deadline-string "\\|" org-closed-string "\\)" " *[[<]\\([^]>]+\\)[]>]") org-maybe-keyword-time-regexp (concat "\\(\\<\\(" org-scheduled-string "\\|" org-deadline-string "\\|" org-closed-string "\\|" org-clock-string "\\)\\)?" " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*?[]>]\\|<%%([^\r\n>]*>\\)") org-planning-or-clock-line-re (concat "\\(?:^[ \t]*\\(" org-scheduled-string "\\|" org-deadline-string "\\|" org-closed-string "\\|" org-clock-string "\\)\\>\\)") ) (org-compute-latex-and-specials-regexp) (org-set-font-lock-defaults)))) (defun org-file-contents (file &optional noerror) "Return the contents of FILE, as a string." (if (or (not file) (not (file-readable-p file))) (if noerror (progn (message "Cannot read file %s" file) (ding) (sit-for 2) "") (error "Cannot read file %s" file)) (with-temp-buffer (insert-file-contents file) (buffer-string)))) (defun org-extract-log-state-settings (x) "Extract the log state setting from a TODO keyword string. This will extract info from a string like \"WAIT(w@/!)\"." (let (kw key log1 log2) (when (string-match "^\\(.*?\\)\\(?:(\\([^!@/]\\)?\\([!@]\\)?\\(?:/\\([!@]\\)\\)?)\\)?$" x) (setq kw (match-string 1 x) key (and (match-end 2) (match-string 2 x)) log1 (and (match-end 3) (match-string 3 x)) log2 (and (match-end 4) (match-string 4 x))) (and (or log1 log2) (list kw (and log1 (if (equal log1 "!") 'time 'note)) (and log2 (if (equal log2 "!") 'time 'note))))))) (defun org-remove-keyword-keys (list) "Remove a pair of parenthesis at the end of each string in LIST." (mapcar (lambda (x) (if (string-match "(.*)$" x) (substring x 0 (match-beginning 0)) x)) list)) ;; FIXME: this could be done much better, using second characters etc. (defun org-assign-fast-keys (alist) "Assign fast keys to a keyword-key alist. Respect keys that are already there." (let (new e k c c1 c2 (char ?a)) (while (setq e (pop alist)) (cond ((equal e '(:startgroup)) (push e new)) ((equal e '(:endgroup)) (push e new)) (t (setq k (car e) c2 nil) (if (cdr e) (setq c (cdr e)) ;; automatically assign a character. (setq c1 (string-to-char (downcase (substring k (if (= (string-to-char k) ?@) 1 0))))) (if (or (rassoc c1 new) (rassoc c1 alist)) (while (or (rassoc char new) (rassoc char alist)) (setq char (1+ char))) (setq c2 c1)) (setq c (or c2 char))) (push (cons k c) new)))) (nreverse new))) ;;; Some variables used in various places (defvar org-window-configuration nil "Used in various places to store a window configuration.") (defvar org-finish-function nil "Function to be called when `C-c C-c' is used. This is for getting out of special buffers like remember.") ;; FIXME: Occasionally check by commenting these, to make sure ;; no other functions uses these, forgetting to let-bind them. (defvar entry) (defvar state) (defvar last-state) (defvar date) (defvar description) ;; Defined somewhere in this file, but used before definition. (defvar org-html-entities) (defvar org-struct-menu) (defvar org-org-menu) (defvar org-tbl-menu) (defvar org-agenda-keymap) ;;;; Define the Org-mode (if (and (not (keymapp outline-mode-map)) (featurep 'allout)) (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.")) ;; We use a before-change function to check if a table might need ;; an update. (defvar org-table-may-need-update t "Indicates that a table might need an update. This variable is set by `org-before-change-function'. `org-table-align' sets it back to nil.") (defun org-before-change-function (beg end) "Every change indicates that a table might need an update." (setq org-table-may-need-update t)) (defvar org-mode-map) (defvar org-mode-hook nil) (defvar org-inhibit-startup nil) ; Dynamically-scoped param. (defvar org-agenda-keep-modes nil) ; Dynamically-scoped param. (defvar org-table-buffer-is-an nil) (defconst org-outline-regexp "\\*+ ") ;;;###autoload (define-derived-mode org-mode outline-mode "Org" "Outline-based notes management and organizer, alias \"Carsten's outline-mode for keeping track of everything.\" Org-mode develops organizational tasks around a NOTES file which contains information about projects as plain text. Org-mode is implemented on top of outline-mode, which is ideal to keep the content of large files well structured. It supports ToDo items, deadlines and time stamps, which magically appear in the diary listing of the Emacs calendar. Tables are easily created with a built-in table editor. Plain text URL-like links connect to websites, emails (VM), Usenet messages (Gnus), BBDB entries, and any files related to the project. For printing and sharing of notes, an Org-mode file (or a part of it) can be exported as a structured ASCII or HTML file. The following commands are available: \\{org-mode-map}" ;; Get rid of Outline menus, they are not needed ;; Need to do this here because define-derived-mode sets up ;; the keymap so late. Still, it is a waste to call this each time ;; we switch another buffer into org-mode. (if (featurep 'xemacs) (when (boundp 'outline-mode-menu-heading) ;; Assume this is Greg's port, it used easymenu (easy-menu-remove outline-mode-menu-heading) (easy-menu-remove outline-mode-menu-show) (easy-menu-remove outline-mode-menu-hide)) (define-key org-mode-map [menu-bar headings] 'undefined) (define-key org-mode-map [menu-bar hide] 'undefined) (define-key org-mode-map [menu-bar show] 'undefined)) (org-load-modules-maybe) (easy-menu-add org-org-menu) (easy-menu-add org-tbl-menu) (org-install-agenda-files-menu) (if org-descriptive-links (org-add-to-invisibility-spec '(org-link))) (org-add-to-invisibility-spec '(org-cwidth)) (when (featurep 'xemacs) (org-set-local 'line-move-ignore-invisible t)) (org-set-local 'outline-regexp org-outline-regexp) (org-set-local 'outline-level 'org-outline-level) (when (and org-ellipsis (fboundp 'set-display-table-slot) (boundp 'buffer-display-table) (fboundp 'make-glyph-code)) (unless org-display-table (setq org-display-table (make-display-table))) (set-display-table-slot org-display-table 4 (vconcat (mapcar (lambda (c) (make-glyph-code c (and (not (stringp org-ellipsis)) org-ellipsis))) (if (stringp org-ellipsis) org-ellipsis "...")))) (setq buffer-display-table org-display-table)) (org-set-regexps-and-options) ;; Calc embedded (org-set-local 'calc-embedded-open-mode "# ") (modify-syntax-entry ?# "<") (modify-syntax-entry ?@ "w") (if org-startup-truncated (setq truncate-lines t)) (org-set-local 'font-lock-unfontify-region-function 'org-unfontify-region) ;; Activate before-change-function (org-set-local 'org-table-may-need-update t) (org-add-hook 'before-change-functions 'org-before-change-function nil 'local) ;; Check for running clock before killing a buffer (org-add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local) ;; Paragraphs and auto-filling (org-set-autofill-regexps) (setq indent-line-function 'org-indent-line-function) (org-update-radio-target-regexp) ;; Comment characters ; (org-set-local 'comment-start "#") ;; FIXME: this breaks wrapping (org-set-local 'comment-padding " ") ;; Align options lines (org-set-local 'align-mode-rules-list '((org-in-buffer-settings (regexp . "^#\\+[A-Z_]+:\\(\\s-*\\)\\S-+") (modes . '(org-mode))))) ;; Imenu (org-set-local 'imenu-create-index-function 'org-imenu-get-tree) ;; Make isearch reveal context (if (or (featurep 'xemacs) (not (boundp 'outline-isearch-open-invisible-function))) ;; Emacs 21 and XEmacs make use of the hook (org-add-hook 'isearch-mode-end-hook 'org-isearch-end 'append 'local) ;; Emacs 22 deals with this through a special variable (org-set-local 'outline-isearch-open-invisible-function (lambda (&rest ignore) (org-show-context 'isearch)))) ;; If empty file that did not turn on org-mode automatically, make it to. (if (and org-insert-mode-line-in-empty-file (interactive-p) (= (point-min) (point-max))) (insert "# -*- mode: org -*-\n\n")) (unless org-inhibit-startup (when org-startup-align-all-tables (let ((bmp (buffer-modified-p))) (org-table-map-tables 'org-table-align) (set-buffer-modified-p bmp))) (org-set-startup-visibility))) (put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify) (defun org-current-time () "Current time, possibly rounded to `org-time-stamp-rounding-minutes'." (if (> (car org-time-stamp-rounding-minutes) 1) (let ((r (car org-time-stamp-rounding-minutes)) (time (decode-time))) (apply 'encode-time (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r))))) (nthcdr 2 time)))) (current-time))) ;;;; Font-Lock stuff, including the activators (defvar org-mouse-map (make-sparse-keymap)) (org-defkey org-mouse-map (if (featurep 'xemacs) [button2] [mouse-2]) 'org-open-at-mouse) (org-defkey org-mouse-map (if (featurep 'xemacs) [button3] [mouse-3]) 'org-find-file-at-mouse) (when org-mouse-1-follows-link (org-defkey org-mouse-map [follow-link] 'mouse-face)) (when org-tab-follows-link (org-defkey org-mouse-map [(tab)] 'org-open-at-point) (org-defkey org-mouse-map "\C-i" 'org-open-at-point)) (when org-return-follows-link (org-defkey org-mouse-map [(return)] 'org-open-at-point) (org-defkey org-mouse-map "\C-m" 'org-open-at-point)) (require 'font-lock) (defconst org-non-link-chars "]\t\n\r<>") (defvar org-link-types '("http" "https" "ftp" "mailto" "file" "news" "shell" "elisp")) (defvar org-link-types-re nil "Matches a link that has a url-like prefix like \"http:\"") (defvar org-link-re-with-space nil "Matches a link with spaces, optional angular brackets around it.") (defvar org-link-re-with-space2 nil "Matches a link with spaces, optional angular brackets around it.") (defvar org-angle-link-re nil "Matches link with angular brackets, spaces are allowed.") (defvar org-plain-link-re nil "Matches plain link, without spaces.") (defvar org-bracket-link-regexp nil "Matches a link in double brackets.") (defvar org-bracket-link-analytic-regexp nil "Regular expression used to analyze links. Here is what the match groups contain after a match: 1: http: 2: http 3: path 4: [desc] 5: desc") (defvar org-any-link-re nil "Regular expression matching any link.") (defun org-make-link-regexps () "Update the link regular expressions. This should be called after the variable `org-link-types' has changed." (setq org-link-types-re (concat "\\`\\(" (mapconcat 'identity org-link-types "\\|") "\\):") org-link-re-with-space (concat "?") org-link-re-with-space2 (concat "?") org-angle-link-re (concat "<\\(" (mapconcat 'identity org-link-types "\\|") "\\):" "\\([^" org-non-link-chars " ]" "[^" org-non-link-chars "]*" "\\)>") org-plain-link-re (concat "\\<\\(" (mapconcat 'identity org-link-types "\\|") "\\):" "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)") org-bracket-link-regexp "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" org-bracket-link-analytic-regexp (concat "\\[\\[" "\\(\\(" (mapconcat 'identity org-link-types "\\|") "\\):\\)?" "\\([^]]+\\)" "\\]" "\\(\\[" "\\([^]]+\\)" "\\]\\)?" "\\]") org-any-link-re (concat "\\(" org-bracket-link-regexp "\\)\\|\\(" org-angle-link-re "\\)\\|\\(" org-plain-link-re "\\)"))) (org-make-link-regexps) (defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)>" "Regular expression for fast time stamp matching.") (defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^\r\n>]*?\\)[]>]" "Regular expression for fast time stamp matching.") (defconst org-ts-regexp0 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)" "Regular expression matching time strings for analysis. This one does not require the space after the date, so it can be used on a string that terminates immediately after the date.") (defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) +\\([^]-+0-9>\r\n ]*\\)\\( \\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)" "Regular expression matching time strings for analysis.") (defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>") "Regular expression matching time stamps, with groups.") (defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]") "Regular expression matching time stamps (also [..]), with groups.") (defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp) "Regular expression matching a time stamp range.") (defconst org-tr-regexp-both (concat org-ts-regexp-both "--?-?" org-ts-regexp-both) "Regular expression matching a time stamp range.") (defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?" org-ts-regexp "\\)?") "Regular expression matching a time stamp or time stamp range.") (defconst org-tsr-regexp-both (concat org-ts-regexp-both "\\(--?-?" org-ts-regexp-both "\\)?") "Regular expression matching a time stamp or time stamp range. The time stamps may be either active or inactive.") (defvar org-emph-face nil) (defun org-do-emphasis-faces (limit) "Run through the buffer and add overlays to links." (let (rtn) (while (and (not rtn) (re-search-forward org-emph-re limit t)) (if (not (= (char-after (match-beginning 3)) (char-after (match-beginning 4)))) (progn (setq rtn t) (font-lock-prepend-text-property (match-beginning 2) (match-end 2) 'face (nth 1 (assoc (match-string 3) org-emphasis-alist))) (add-text-properties (match-beginning 2) (match-end 2) '(font-lock-multiline t)) (when org-hide-emphasis-markers (add-text-properties (match-end 4) (match-beginning 5) '(invisible org-link)) (add-text-properties (match-beginning 3) (match-end 3) '(invisible org-link))))) (backward-char 1)) rtn)) (defun org-emphasize (&optional char) "Insert or change an emphasis, i.e. a font like bold or italic. If there is an active region, change that region to a new emphasis. If there is no region, just insert the marker characters and position the cursor between them. CHAR should be either the marker character, or the first character of the HTML tag associated with that emphasis. If CHAR is a space, the means to remove the emphasis of the selected region. If char is not given (for example in an interactive call) it will be prompted for." (interactive) (let ((eal org-emphasis-alist) e det (erc org-emphasis-regexp-components) (prompt "") (string "") beg end move tag c s) (if (org-region-active-p) (setq beg (region-beginning) end (region-end) string (buffer-substring beg end)) (setq move t)) (while (setq e (pop eal)) (setq tag (car (org-split-string (nth 2 e) "[ <>/]+")) c (aref tag 0)) (push (cons c (string-to-char (car e))) det) (setq prompt (concat prompt (format " [%s%c]%s" (car e) c (substring tag 1))))) (setq det (nreverse det)) (unless char (message "%s" (concat "Emphasis marker or tag:" prompt)) (setq char (read-char-exclusive))) (setq char (or (cdr (assoc char det)) char)) (if (equal char ?\ ) (setq s "" move nil) (unless (assoc (char-to-string char) org-emphasis-alist) (error "No such emphasis marker: \"%c\"" char)) (setq s (char-to-string char))) (while (and (> (length string) 1) (equal (substring string 0 1) (substring string -1)) (assoc (substring string 0 1) org-emphasis-alist)) (setq string (substring string 1 -1))) (setq string (concat s string s)) (if beg (delete-region beg end)) (unless (or (bolp) (string-match (concat "[" (nth 0 erc) "\n]") (char-to-string (char-before (point))))) (insert " ")) (unless (string-match (concat "[" (nth 1 erc) "\n]") (char-to-string (char-after (point)))) (insert " ") (backward-char 1)) (insert string) (and move (backward-char 1)))) (defconst org-nonsticky-props '(mouse-face highlight keymap invisible intangible help-echo org-linked-text)) (defun org-activate-plain-links (limit) "Run through the buffer and add overlays to links." (catch 'exit (let (f) (while (re-search-forward org-plain-link-re limit t) (setq f (get-text-property (match-beginning 0) 'face)) (if (or (eq f 'org-tag) (and (listp f) (memq 'org-tag f))) nil (add-text-properties (match-beginning 0) (match-end 0) (list 'mouse-face 'highlight 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map )) (throw 'exit t)))))) (defun org-activate-code (limit) (if (re-search-forward "^[ \t]*\\(: .*\n?\\)" limit t) (progn (remove-text-properties (match-beginning 0) (match-end 0) '(display t invisible t intangible t)) t))) (defun org-activate-angle-links (limit) "Run through the buffer and add overlays to links." (if (re-search-forward org-angle-link-re limit t) (progn (add-text-properties (match-beginning 0) (match-end 0) (list 'mouse-face 'highlight 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map )) t))) (defun org-activate-bracket-links (limit) "Run through the buffer and add overlays to bracketed links." (if (re-search-forward org-bracket-link-regexp limit t) (let* ((help (concat "LINK: " (org-match-string-no-properties 1))) ;; FIXME: above we should remove the escapes. ;; but that requires another match, protecting match data, ;; a lot of overhead for font-lock. (ip (org-maybe-intangible (list 'invisible 'org-link 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map 'mouse-face 'highlight 'font-lock-multiline t 'help-echo help))) (vp (list 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map 'mouse-face 'highlight ' font-lock-multiline t 'help-echo help))) ;; We need to remove the invisible property here. Table narrowing ;; may have made some of this invisible. (remove-text-properties (match-beginning 0) (match-end 0) '(invisible nil)) (if (match-end 3) (progn (add-text-properties (match-beginning 0) (match-beginning 3) ip) (add-text-properties (match-beginning 3) (match-end 3) vp) (add-text-properties (match-end 3) (match-end 0) ip)) (add-text-properties (match-beginning 0) (match-beginning 1) ip) (add-text-properties (match-beginning 1) (match-end 1) vp) (add-text-properties (match-end 1) (match-end 0) ip)) t))) (defun org-activate-dates (limit) "Run through the buffer and add overlays to dates." (if (re-search-forward org-tsr-regexp-both limit t) (progn (add-text-properties (match-beginning 0) (match-end 0) (list 'mouse-face 'highlight 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map)) (when org-display-custom-times (if (match-end 3) (org-display-custom-time (match-beginning 3) (match-end 3))) (org-display-custom-time (match-beginning 1) (match-end 1))) t))) (defvar org-target-link-regexp nil "Regular expression matching radio targets in plain text.") (defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>" "Regular expression matching a link target.") (defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>" "Regular expression matching a radio target.") (defvar org-any-target-regexp "<<\n\r]+\\)>>>?" ; FIXME, not exact, would match <<> as a radio target. "Regular expression matching any target.") (defun org-activate-target-links (limit) "Run through the buffer and add overlays to target matches." (when org-target-link-regexp (let ((case-fold-search t)) (if (re-search-forward org-target-link-regexp limit t) (progn (add-text-properties (match-beginning 0) (match-end 0) (list 'mouse-face 'highlight 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map 'help-echo "Radio target link" 'org-linked-text t)) t))))) (defun org-update-radio-target-regexp () "Find all radio targets in this file and update the regular expression." (interactive) (when (memq 'radio org-activate-links) (setq org-target-link-regexp (org-make-target-link-regexp (org-all-targets 'radio))) (org-restart-font-lock))) (defun org-hide-wide-columns (limit) (let (s e) (setq s (text-property-any (point) (or limit (point-max)) 'org-cwidth t)) (when s (setq e (next-single-property-change s 'org-cwidth)) (add-text-properties s e (org-maybe-intangible '(invisible org-cwidth))) (goto-char e) t))) (defvar org-latex-and-specials-regexp nil "Regular expression for highlighting export special stuff.") (defvar org-match-substring-regexp) (defvar org-match-substring-with-braces-regexp) (defvar org-export-html-special-string-regexps) (defun org-compute-latex-and-specials-regexp () "Compute regular expression for stuff treated specially by exporters." (if (not org-highlight-latex-fragments-and-specials) (org-set-local 'org-latex-and-specials-regexp nil) (require 'org-exp) (let* ((matchers (plist-get org-format-latex-options :matchers)) (latexs (delq nil (mapcar (lambda (x) (if (member (car x) matchers) x)) org-latex-regexps))) (options (org-combine-plists (org-default-export-plist) (org-infile-export-plist))) (org-export-with-sub-superscripts (plist-get options :sub-superscript)) (org-export-with-LaTeX-fragments (plist-get options :LaTeX-fragments)) (org-export-with-TeX-macros (plist-get options :TeX-macros)) (org-export-html-expand (plist-get options :expand-quoted-html)) (org-export-with-special-strings (plist-get options :special-strings)) (re-sub (cond ((equal org-export-with-sub-superscripts '{}) (list org-match-substring-with-braces-regexp)) (org-export-with-sub-superscripts (list org-match-substring-regexp)) (t nil))) (re-latex (if org-export-with-LaTeX-fragments (mapcar (lambda (x) (nth 1 x)) latexs))) (re-macros (if org-export-with-TeX-macros (list (concat "\\\\" (regexp-opt (append (mapcar 'car org-html-entities) (if (boundp 'org-latex-entities) org-latex-entities nil)) 'words))) ; FIXME )) ;; (list "\\\\\\(?:[a-zA-Z]+\\)"))) (re-special (if org-export-with-special-strings (mapcar (lambda (x) (car x)) org-export-html-special-string-regexps))) (re-rest (delq nil (list (if org-export-html-expand "@<[^>\n]+>") )))) (org-set-local 'org-latex-and-specials-regexp (mapconcat 'identity (append re-latex re-sub re-macros re-special re-rest) "\\|"))))) (defun org-do-latex-and-special-faces (limit) "Run through the buffer and add overlays to links." (when org-latex-and-specials-regexp (let (rtn d) (while (and (not rtn) (re-search-forward org-latex-and-specials-regexp limit t)) (if (not (memq (car-safe (get-text-property (1+ (match-beginning 0)) 'face)) '(org-code org-verbatim underline))) (progn (setq rtn t d (cond ((member (char-after (1+ (match-beginning 0))) '(?_ ?^)) 1) (t 0))) (font-lock-prepend-text-property (+ d (match-beginning 0)) (match-end 0) 'face 'org-latex-and-export-specials) (add-text-properties (+ d (match-beginning 0)) (match-end 0) '(font-lock-multiline t))))) rtn))) (defun org-restart-font-lock () "Restart font-lock-mode, to force refontification." (when (and (boundp 'font-lock-mode) font-lock-mode) (font-lock-mode -1) (font-lock-mode 1))) (defun org-all-targets (&optional radio) "Return a list of all targets in this file. With optional argument RADIO, only find radio targets." (let ((re (if radio org-radio-target-regexp org-target-regexp)) rtn) (save-excursion (goto-char (point-min)) (while (re-search-forward re nil t) (add-to-list 'rtn (downcase (org-match-string-no-properties 1)))) rtn))) (defun org-make-target-link-regexp (targets) "Make regular expression matching all strings in TARGETS. The regular expression finds the targets also if there is a line break between words." (and targets (concat "\\<\\(" (mapconcat (lambda (x) (while (string-match " +" x) (setq x (replace-match "\\s-+" t t x))) x) targets "\\|") "\\)\\>"))) (defun org-activate-tags (limit) (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@:]+:\\)[ \r\n]") limit t) (progn (add-text-properties (match-beginning 1) (match-end 1) (list 'mouse-face 'highlight 'rear-nonsticky org-nonsticky-props 'keymap org-mouse-map)) t))) (defun org-outline-level () (save-excursion (looking-at outline-regexp) (if (match-beginning 1) (+ (org-get-string-indentation (match-string 1)) 1000) (1- (- (match-end 0) (match-beginning 0)))))) (defvar org-font-lock-keywords nil) (defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\):\\)[ \t]*\\([^ \t\r\n].*\\)") "Regular expression matching a property line.") (defvar org-font-lock-hook nil "Functions to be called for special font lock stuff.") (defun org-font-lock-hook (limit) (run-hook-with-args 'org-font-lock-hook limit)) (defun org-set-font-lock-defaults () (let* ((em org-fontify-emphasized-text) (lk org-activate-links) (org-font-lock-extra-keywords (list ;; Call the hook '(org-font-lock-hook) ;; Headlines '("^\\(\\**\\)\\(\\* \\)\\(.*\\)" (1 (org-get-level-face 1)) (2 (org-get-level-face 2)) (3 (org-get-level-face 3))) ;; Table lines '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)" (1 'org-table t)) ;; Table internals '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t)) '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t)) '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t)) ;; Drawers (list org-drawer-regexp '(0 'org-special-keyword t)) (list "^[ \t]*:END:" '(0 'org-special-keyword t)) ;; Properties (list org-property-re '(1 'org-special-keyword t) '(3 'org-property-value t)) (if org-format-transports-properties-p '("| *\\(<[0-9]+>\\) *" (1 'org-formula t))) ;; Links (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend))) (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t))) (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t))) (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t))) (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t))) (if (memq 'date lk) '(org-activate-dates (0 'org-date t))) '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t)) '(org-hide-wide-columns (0 nil append)) ;; TODO lines (list (concat "^\\*+[ \t]+" org-todo-regexp) '(1 (org-get-todo-face 1) t)) ;; DONE (if org-fontify-done-headline (list (concat "^[*]+ +\\<\\(" (mapconcat 'regexp-quote org-done-keywords "\\|") "\\)\\(.*\\)") '(2 'org-headline-done t)) nil) ;; Priorities (list (concat "\\[#[A-Z0-9]\\]") '(0 'org-special-keyword t)) ;; Special keywords (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t)) (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t)) ;; Emphasis (if em (if (featurep 'xemacs) '(org-do-emphasis-faces (0 nil append)) '(org-do-emphasis-faces))) ;; Checkboxes '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[- X]\\]\\)" 2 'bold prepend) (if org-provide-checkbox-statistics '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" (0 (org-get-checkbox-statistics-face) t))) ;; Description list items '("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(.*? ::\\)" 2 'bold prepend) (list (concat "^\\*+ \\(.*:" org-archive-tag ":.*\\)") '(1 'org-archived prepend)) ;; Specials '(org-do-latex-and-special-faces) ;; Code '(org-activate-code (1 'org-code t)) ;; COMMENT (list (concat "^\\*+[ \t]+\\<\\(" org-comment-string "\\|" org-quote-string "\\)\\>") '(1 'org-special-keyword t)) '("^#.*" (0 'font-lock-comment-face t)) ))) (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords)) ;; Now set the full font-lock-keywords (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords) (org-set-local 'font-lock-defaults '(org-font-lock-keywords t nil nil backward-paragraph)) (kill-local-variable 'font-lock-keywords) nil)) (defvar org-m nil) (defvar org-l nil) (defvar org-f nil) (defun org-get-level-face (n) "Get the right face for match N in font-lock matching of healdines." (setq org-l (- (match-end 2) (match-beginning 1) 1)) (if org-odd-levels-only (setq org-l (1+ (/ org-l 2)))) (setq org-f (nth (% (1- org-l) org-n-level-faces) org-level-faces)) (cond ((eq n 1) (if org-hide-leading-stars 'org-hide org-f)) ((eq n 2) org-f) (t (if org-level-color-stars-only nil org-f)))) (defun org-get-todo-face (kwd) "Get the right face for a TODO keyword KWD. If KWD is a number, get the corresponding match group." (if (numberp kwd) (setq kwd (match-string kwd))) (or (cdr (assoc kwd org-todo-keyword-faces)) (and (member kwd org-done-keywords) 'org-done) 'org-todo)) (defun org-unfontify-region (beg end &optional maybe_loudly) "Remove fontification and activation overlays from links." (font-lock-default-unfontify-region beg end) (let* ((buffer-undo-list t) (inhibit-read-only t) (inhibit-point-motion-hooks t) (inhibit-modification-hooks t) deactivate-mark buffer-file-name buffer-file-truename) (remove-text-properties beg end '(mouse-face t keymap t org-linked-text t invisible t intangible t)))) ;;;; Visibility cycling, including org-goto and indirect buffer ;;; Cycling (defvar org-cycle-global-status nil) (make-variable-buffer-local 'org-cycle-global-status) (defvar org-cycle-subtree-status nil) (make-variable-buffer-local 'org-cycle-subtree-status) ;;;###autoload (defun org-cycle (&optional arg) "Visibility cycling for Org-mode. - When this function is called with a prefix argument, rotate the entire buffer through 3 states (global cycling) 1. OVERVIEW: Show only top-level headlines. 2. CONTENTS: Show all headlines of all levels, but no body text. 3. SHOW ALL: Show everything. When called with two C-u C-u prefixes, switch to the startup visibility, determined by the variable `org-startup-folded', and by any VISIBILITY properties in the buffer. When called with three C-u C-u C-u prefixed, show the entire buffer, including drawers. - When point is at the beginning of a headline, rotate the subtree started by this line through 3 different states (local cycling) 1. FOLDED: Only the main headline is shown. 2. CHILDREN: The main headline and the direct children are shown. From this state, you can move to one of the children and zoom in further. 3. SUBTREE: Show the entire subtree, including body text. - When there is a numeric prefix, go up to a heading with level ARG, do a `show-subtree' and return to the previous cursor position. If ARG is negative, go up that many levels. - When point is not at the beginning of a headline, execute the global binding for TAB, which is re-indenting the line. See the option `org-cycle-emulate-tab' for details. - Special case: if point is at the beginning of the buffer and there is no headline in line 1, this function will act as if called with prefix arg. But only if also the variable `org-cycle-global-at-bob' is t." (interactive "P") (org-load-modules-maybe) (let* ((outline-regexp (if (and (org-mode-p) org-cycle-include-plain-lists) "\\(?:\\*+ \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)" outline-regexp)) (bob-special (and org-cycle-global-at-bob (bobp) (not (looking-at outline-regexp)))) (org-cycle-hook (if bob-special (delq 'org-optimize-window-after-visibility-change (copy-sequence org-cycle-hook)) org-cycle-hook)) (pos (point))) (if (or bob-special (equal arg '(4))) ;; special case: use global cycling (setq arg t)) (cond ((equal arg '(16)) (org-set-startup-visibility) (message "Startup visibility, plus VISIBILITY properties")) ((equal arg '(64)) (show-all) (message "Entire buffer visible, including drawers")) ((org-at-table-p 'any) ;; Enter the table or move to the next field in the table (or (org-table-recognize-table.el) (progn (if arg (org-table-edit-field t) (org-table-justify-field-maybe) (call-interactively 'org-table-next-field))))) ((eq arg t) ;; Global cycling (cond ((and (eq last-command this-command) (eq org-cycle-global-status 'overview)) ;; We just created the overview - now do table of contents ;; This can be slow in very large buffers, so indicate action (message "CONTENTS...") (org-content) (message "CONTENTS...done") (setq org-cycle-global-status 'contents) (run-hook-with-args 'org-cycle-hook 'contents)) ((and (eq last-command this-command) (eq org-cycle-global-status 'contents)) ;; We just showed the table of contents - now show everything (show-all) (message "SHOW ALL") (setq org-cycle-global-status 'all) (run-hook-with-args 'org-cycle-hook 'all)) (t ;; Default action: go to overview (org-overview) (message "OVERVIEW") (setq org-cycle-global-status 'overview) (run-hook-with-args 'org-cycle-hook 'overview)))) ((and org-drawers org-drawer-regexp (save-excursion (beginning-of-line 1) (looking-at org-drawer-regexp))) ;; Toggle block visibility (org-flag-drawer (not (get-char-property (match-end 0) 'invisible)))) ((integerp arg) ;; Show-subtree, ARG levels up from here. (save-excursion (org-back-to-heading) (outline-up-heading (if (< arg 0) (- arg) (- (funcall outline-level) arg))) (org-show-subtree))) ((and (save-excursion (beginning-of-line 1) (looking-at outline-regexp)) (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol)))) ;; At a heading: rotate between three different views (org-back-to-heading) (let ((goal-column 0) eoh eol eos) ;; First, some boundaries (save-excursion (org-back-to-heading) (save-excursion (beginning-of-line 2) (while (and (not (eobp)) ;; this is like `next-line' (get-char-property (1- (point)) 'invisible)) (beginning-of-line 2)) (setq eol (point))) (outline-end-of-heading) (setq eoh (point)) (org-end-of-subtree t) (unless (eobp) (skip-chars-forward " \t\n") (beginning-of-line 1) ; in case this is an item ) (setq eos (1- (point)))) ;; Find out what to do next and set `this-command' (cond ((= eos eoh) ;; Nothing is hidden behind this heading (message "EMPTY ENTRY") (setq org-cycle-subtree-status nil) (save-excursion (goto-char eos) (outline-next-heading) (if (org-invisible-p) (org-flag-heading nil)))) ((or (>= eol eos) (not (string-match "\\S-" (buffer-substring eol eos)))) ;; Entire subtree is hidden in one line: open it (org-show-entry) (show-children) (message "CHILDREN") (save-excursion (goto-char eos) (outline-next-heading) (if (org-invisible-p) (org-flag-heading nil))) (setq org-cycle-subtree-status 'children) (run-hook-with-args 'org-cycle-hook 'children)) ((and (eq last-command this-command) (eq org-cycle-subtree-status 'children)) ;; We just showed the children, now show everything. (org-show-subtree) (message "SUBTREE") (setq org-cycle-subtree-status 'subtree) (run-hook-with-args 'org-cycle-hook 'subtree)) (t ;; Default action: hide the subtree. (hide-subtree) (message "FOLDED") (setq org-cycle-subtree-status 'folded) (run-hook-with-args 'org-cycle-hook 'folded))))) ;; TAB emulation and template completion (buffer-read-only (org-back-to-heading)) ((org-try-structure-completion)) ((org-try-cdlatex-tab)) ((and (eq org-cycle-emulate-tab 'exc-hl-bol) (or (not (bolp)) (not (looking-at outline-regexp)))) (call-interactively (global-key-binding "\t"))) ((if (and (memq org-cycle-emulate-tab '(white whitestart)) (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")) (or (and (eq org-cycle-emulate-tab 'white) (= (match-end 0) (point-at-eol))) (and (eq org-cycle-emulate-tab 'whitestart) (>= (match-end 0) pos)))) t (eq org-cycle-emulate-tab t)) (call-interactively (global-key-binding "\t"))) (t (save-excursion (org-back-to-heading) (org-cycle)))))) ;;;###autoload (defun org-global-cycle (&optional arg) "Cycle the global visibility. For details see `org-cycle'. With C-u prefix arg, switch to startup visibility. With a numeric prefix, show all headlines up to that level." (interactive "P") (let ((org-cycle-include-plain-lists (if (org-mode-p) org-cycle-include-plain-lists nil))) (cond ((integerp arg) (show-all) (hide-sublevels arg) (setq org-cycle-global-status 'contents)) ((equal arg '(4)) (org-set-startup-visibility) (message "Startup visibility, plus VISIBILITY properties.")) (t (org-cycle '(4)))))) (defun org-set-startup-visibility () "Set the visibility required by startup options and properties." (cond ((eq org-startup-folded t) (org-cycle '(4))) ((eq org-startup-folded 'content) (let ((this-command 'org-cycle) (last-command 'org-cycle)) (org-cycle '(4)) (org-cycle '(4))))) (org-set-visibility-according-to-property 'no-cleanup) (org-cycle-hide-archived-subtrees 'all) (org-cycle-hide-drawers 'all) (org-cycle-show-empty-lines 'all)) (defun org-set-visibility-according-to-property (&optional no-cleanup) "Switch subtree visibilities according to :VISIBILITY: property." (interactive) (let (state) (save-excursion (goto-char (point-min)) (while (re-search-forward "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)" nil t) (setq state (match-string 1)) (save-excursion (org-back-to-heading t) (hide-subtree) (org-reveal) (cond ((equal state '("fold" "folded")) (hide-subtree)) ((equal state "children") (org-show-hidden-entry) (show-children)) ((equal state "content") (save-excursion (save-restriction (org-narrow-to-subtree) (org-content)))) ((member state '("all" "showall")) (show-subtree))))) (unless no-cleanup (org-cycle-hide-archived-subtrees 'all) (org-cycle-hide-drawers 'all) (org-cycle-show-empty-lines 'all))))) (defun org-overview () "Switch to overview mode, shoing only top-level headlines. Really, this shows all headlines with level equal or greater than the level of the first headline in the buffer. This is important, because if the first headline is not level one, then (hide-sublevels 1) gives confusing results." (interactive) (let ((level (save-excursion (goto-char (point-min)) (if (re-search-forward (concat "^" outline-regexp) nil t) (progn (goto-char (match-beginning 0)) (funcall outline-level)))))) (and level (hide-sublevels level)))) (defun org-content (&optional arg) "Show all headlines in the buffer, like a table of contents. With numerical argument N, show content up to level N." (interactive "P") (save-excursion ;; Visit all headings and show their offspring (and (integerp arg) (org-overview)) (goto-char (point-max)) (catch 'exit (while (and (progn (condition-case nil (outline-previous-visible-heading 1) (error (goto-char (point-min)))) t) (looking-at outline-regexp)) (if (integerp arg) (show-children (1- arg)) (show-branches)) (if (bobp) (throw 'exit nil)))))) (defun org-optimize-window-after-visibility-change (state) "Adjust the window after a change in outline visibility. This function is the default value of the hook `org-cycle-hook'." (when (get-buffer-window (current-buffer)) (cond ; ((eq state 'overview) (org-first-headline-recenter 1)) ; ((eq state 'overview) (org-beginning-of-line)) ((eq state 'content) nil) ((eq state 'all) nil) ((eq state 'folded) nil) ((eq state 'children) (or (org-subtree-end-visible-p) (recenter 1))) ((eq state 'subtree) (or (org-subtree-end-visible-p) (recenter 1)))))) (defun org-compact-display-after-subtree-move () (let (beg end) (save-excursion (if (org-up-heading-safe) (progn (hide-subtree) (show-entry) (show-children) (org-cycle-show-empty-lines 'children) (org-cycle-hide-drawers 'children)) (org-overview))))) (defun org-cycle-show-empty-lines (state) "Show empty lines above all visible headlines. The region to be covered depends on STATE when called through `org-cycle-hook'. Lisp program can use t for STATE to get the entire buffer covered. Note that an empty line is only shown if there are at least `org-cycle-separator-lines' empty lines before the headeline." (when (> org-cycle-separator-lines 0) (save-excursion (let* ((n org-cycle-separator-lines) (re (cond ((= n 1) "\\(\n[ \t]*\n\\*+\\) ") ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ") (t (let ((ns (number-to-string (- n 2)))) (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}" "[ \t]*\\(\n[ \t]*\n\\*+\\) "))))) beg end) (cond ((memq state '(overview contents t)) (setq beg (point-min) end (point-max))) ((memq state '(children folded)) (setq beg (point) end (progn (org-end-of-subtree t t) (beginning-of-line 2) (point))))) (when beg (goto-char beg) (while (re-search-forward re end t) (if (not (get-char-property (match-end 1) 'invisible)) (outline-flag-region (match-beginning 1) (match-end 1) nil))))))) ;; Never hide empty lines at the end of the file. (save-excursion (goto-char (point-max)) (outline-previous-heading) (outline-end-of-heading) (if (and (looking-at "[ \t\n]+") (= (match-end 0) (point-max))) (outline-flag-region (point) (match-end 0) nil)))) (defun org-show-empty-lines-in-parent () "Move to the parent and re-show empty lines before visible headlines." (save-excursion (let ((context (if (org-up-heading-safe) 'children 'overview))) (org-cycle-show-empty-lines context)))) (defun org-cycle-hide-drawers (state) "Re-hide all drawers after a visibility state change." (when (and (org-mode-p) (not (memq state '(overview folded)))) (save-excursion (let* ((globalp (memq state '(contents all))) (beg (if globalp (point-min) (point))) (end (if globalp (point-max) (org-end-of-subtree t)))) (goto-char beg) (while (re-search-forward org-drawer-regexp end t) (org-flag-drawer t)))))) (defun org-flag-drawer (flag) (save-excursion (beginning-of-line 1) (when (looking-at "^[ \t]*:[a-zA-Z][a-zA-Z0-9]*:") (let ((b (match-end 0)) (outline-regexp org-outline-regexp)) (if (re-search-forward "^[ \t]*:END:" (save-excursion (outline-next-heading) (point)) t) (outline-flag-region b (point-at-eol) flag) (error ":END: line missing")))))) (defun org-subtree-end-visible-p () "Is the end of the current subtree visible?" (pos-visible-in-window-p (save-excursion (org-end-of-subtree t) (point)))) (defun org-first-headline-recenter (&optional N) "Move cursor to the first headline and recenter the headline. Optional argument N means, put the headline into the Nth line of the window." (goto-char (point-min)) (when (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t) (beginning-of-line) (recenter (prefix-numeric-value N)))) ;;; Org-goto (defvar org-goto-window-configuration nil) (defvar org-goto-marker nil) (defvar org-goto-map (let ((map (make-sparse-keymap))) (let ((cmds '(isearch-forward isearch-backward kill-ring-save set-mark-command mouse-drag-region universal-argument org-occur)) cmd) (while (setq cmd (pop cmds)) (substitute-key-definition cmd cmd map global-map))) (suppress-keymap map) (org-defkey map "\C-m" 'org-goto-ret) (org-defkey map [(return)] 'org-goto-ret) (org-defkey map [(left)] 'org-goto-left) (org-defkey map [(right)] 'org-goto-right) (org-defkey map [(control ?g)] 'org-goto-quit) (org-defkey map "\C-i" 'org-cycle) (org-defkey map [(tab)] 'org-cycle) (org-defkey map [(down)] 'outline-next-visible-heading) (org-defkey map [(up)] 'outline-previous-visible-heading) (if org-goto-auto-isearch (if (fboundp 'define-key-after) (define-key-after map [t] 'org-goto-local-auto-isearch) nil) (org-defkey map "q" 'org-goto-quit) (org-defkey map "n" 'outline-next-visible-heading) (org-defkey map "p" 'outline-previous-visible-heading) (org-defkey map "f" 'outline-forward-same-level) (org-defkey map "b" 'outline-backward-same-level) (org-defkey map "u" 'outline-up-heading)) (org-defkey map "/" 'org-occur) (org-defkey map "\C-c\C-n" 'outline-next-visible-heading) (org-defkey map "\C-c\C-p" 'outline-previous-visible-heading) (org-defkey map "\C-c\C-f" 'outline-forward-same-level) (org-defkey map "\C-c\C-b" 'outline-backward-same-level) (org-defkey map "\C-c\C-u" 'outline-up-heading) map)) (defconst org-goto-help "Browse buffer copy, to find location or copy text. Just type for auto-isearch. RET=jump to location [Q]uit and return to previous location \[Up]/[Down]=next/prev headline TAB=cycle visibility [/] org-occur") (defvar org-goto-start-pos) ; dynamically scoped parameter ;; FIXME: Docstring doe not mention both interfaces (defun org-goto (&optional alternative-interface) "Look up a different location in the current file, keeping current visibility. When you want look-up or go to a different location in a document, the fastest way is often to fold the entire buffer and then dive into the tree. This method has the disadvantage, that the previous location will be folded, which may not be what you want. This command works around this by showing a copy of the current buffer in an indirect buffer, in overview mode. You can dive into the tree in that copy, use org-occur and incremental search to find a location. When pressing RET or `Q', the command returns to the original buffer in which the visibility is still unchanged. After RET is will also jump to the location selected in the indirect buffer and expose the the headline hierarchy above." (interactive "P") (let* ((org-refile-targets '((nil . (:maxlevel . 10)))) (org-refile-use-outline-path t) (interface (if (not alternative-interface) org-goto-interface (if (eq org-goto-interface 'outline) 'outline-path-completion 'outline))) (org-goto-start-pos (point)) (selected-point (if (eq interface 'outline) (car (org-get-location (current-buffer) org-goto-help)) (nth 3 (org-refile-get-location "Goto: "))))) (if selected-point (progn (org-mark-ring-push org-goto-start-pos) (goto-char selected-point) (if (or (org-invisible-p) (org-invisible-p2)) (org-show-context 'org-goto))) (message "Quit")))) (defvar org-goto-selected-point nil) ; dynamically scoped parameter (defvar org-goto-exit-command nil) ; dynamically scoped parameter (defvar org-goto-local-auto-isearch-map) ; defined below (defun org-get-location (buf help) "Let the user select a location in the Org-mode buffer BUF. This function uses a recursive edit. It returns the selected position or nil." (let ((isearch-mode-map org-goto-local-auto-isearch-map) (isearch-hide-immediately nil) (isearch-search-fun-function (lambda () 'org-goto-local-search-headings)) (org-goto-selected-point org-goto-exit-command)) (save-excursion (save-window-excursion (delete-other-windows) (and (get-buffer "*org-goto*") (kill-buffer "*org-goto*")) (switch-to-buffer (condition-case nil (make-indirect-buffer (current-buffer) "*org-goto*") (error (make-indirect-buffer (current-buffer) "*org-goto*")))) (with-output-to-temp-buffer "*Help*" (princ help)) (org-fit-window-to-buffer (get-buffer-window "*Help*")) (setq buffer-read-only nil) (let ((org-startup-truncated t) (org-startup-folded nil) (org-startup-align-all-tables nil)) (org-mode) (org-overview)) (setq buffer-read-only t) (if (and (boundp 'org-goto-start-pos) (integer-or-marker-p org-goto-start-pos)) (let ((org-show-hierarchy-above t) (org-show-siblings t) (org-show-following-heading t)) (goto-char org-goto-start-pos) (and (org-invisible-p) (org-show-context))) (goto-char (point-min))) (org-beginning-of-line) (message "Select location and press RET") (use-local-map org-goto-map) (recursive-edit) )) (kill-buffer "*org-goto*") (cons org-goto-selected-point org-goto-exit-command))) (defvar org-goto-local-auto-isearch-map (make-sparse-keymap)) (set-keymap-parent org-goto-local-auto-isearch-map isearch-mode-map) (define-key org-goto-local-auto-isearch-map "\C-i" 'isearch-other-control-char) (define-key org-goto-local-auto-isearch-map "\C-m" 'isearch-other-control-char) (defun org-goto-local-search-headings (string bound noerror) "Search and make sure that any matches are in headlines." (catch 'return (while (if isearch-forward (search-forward string bound noerror) (search-backward string bound noerror)) (when (let ((context (mapcar 'car (save-match-data (org-context))))) (and (member :headline context) (not (member :tags context)))) (throw 'return (point)))))) (defun org-goto-local-auto-isearch () "Start isearch." (interactive) (goto-char (point-min)) (let ((keys (this-command-keys))) (when (eq (lookup-key isearch-mode-map keys) 'isearch-printing-char) (isearch-mode t) (isearch-process-search-char (string-to-char keys))))) (defun org-goto-ret (&optional arg) "Finish `org-goto' by going to the new location." (interactive "P") (setq org-goto-selected-point (point) org-goto-exit-command 'return) (throw 'exit nil)) (defun org-goto-left () "Finish `org-goto' by going to the new location." (interactive) (if (org-on-heading-p) (progn (beginning-of-line 1) (setq org-goto-selected-point (point) org-goto-exit-command 'left) (throw 'exit nil)) (error "Not on a heading"))) (defun org-goto-right () "Finish `org-goto' by going to the new location." (interactive) (if (org-on-heading-p) (progn (setq org-goto-selected-point (point) org-goto-exit-command 'right) (throw 'exit nil)) (error "Not on a heading"))) (defun org-goto-quit () "Finish `org-goto' without cursor motion." (interactive) (setq org-goto-selected-point nil) (setq org-goto-exit-command 'quit) (throw 'exit nil)) ;;; Indirect buffer display of subtrees (defvar org-indirect-dedicated-frame nil "This is the frame being used for indirect tree display.") (defvar org-last-indirect-buffer nil) (defun org-tree-to-indirect-buffer (&optional arg) "Create indirect buffer and narrow it to current subtree. With numerical prefix ARG, go up to this level and then take that tree. If ARG is negative, go up that many levels. If `org-indirect-buffer-display' is not `new-frame', the command removes the indirect buffer previously made with this command, to avoid proliferation of indirect buffers. However, when you call the command with a `C-u' prefix, or when `org-indirect-buffer-display' is `new-frame', the last buffer is kept so that you can work with several indirect buffers at the same time. If `org-indirect-buffer-display' is `dedicated-frame', the C-u prefix also requests that a new frame be made for the new buffer, so that the dedicated frame is not changed." (interactive "P") (let ((cbuf (current-buffer)) (cwin (selected-window)) (pos (point)) beg end level heading ibuf) (save-excursion (org-back-to-heading t) (when (numberp arg) (setq level (org-outline-level)) (if (< arg 0) (setq arg (+ level arg))) (while (> (setq level (org-outline-level)) arg) (outline-up-heading 1 t))) (setq beg (point) heading (org-get-heading)) (org-end-of-subtree t) (setq end (point))) (if (and (buffer-live-p org-last-indirect-buffer) (not (eq org-indirect-buffer-display 'new-frame)) (not arg)) (kill-buffer org-last-indirect-buffer)) (setq ibuf (org-get-indirect-buffer cbuf) org-last-indirect-buffer ibuf) (cond ((or (eq org-indirect-buffer-display 'new-frame) (and arg (eq org-indirect-buffer-display 'dedicated-frame))) (select-frame (make-frame)) (delete-other-windows) (switch-to-buffer ibuf) (org-set-frame-title heading)) ((eq org-indirect-buffer-display 'dedicated-frame) (raise-frame (select-frame (or (and org-indirect-dedicated-frame (frame-live-p org-indirect-dedicated-frame) org-indirect-dedicated-frame) (setq org-indirect-dedicated-frame (make-frame))))) (delete-other-windows) (switch-to-buffer ibuf) (org-set-frame-title (concat "Indirect: " heading))) ((eq org-indirect-buffer-display 'current-window) (switch-to-buffer ibuf)) ((eq org-indirect-buffer-display 'other-window) (pop-to-buffer ibuf)) (t (error "Invalid value."))) (if (featurep 'xemacs) (save-excursion (org-mode) (turn-on-font-lock))) (narrow-to-region beg end) (show-all) (goto-char pos) (and (window-live-p cwin) (select-window cwin)))) (defun org-get-indirect-buffer (&optional buffer) (setq buffer (or buffer (current-buffer))) (let ((n 1) (base (buffer-name buffer)) bname) (while (buffer-live-p (get-buffer (setq bname (concat base "-" (number-to-string n))))) (setq n (1+ n))) (condition-case nil (make-indirect-buffer buffer bname 'clone) (error (make-indirect-buffer buffer bname))))) (defun org-set-frame-title (title) "Set the title of the current frame to the string TITLE." ;; FIXME: how to name a single frame in XEmacs??? (unless (featurep 'xemacs) (modify-frame-parameters (selected-frame) (list (cons 'name title))))) ;;;; Structure editing ;;; Inserting headlines (defun org-insert-heading (&optional force-heading) "Insert a new heading or item with same depth at point. If point is in a plain list and FORCE-HEADING is nil, create a new list item. If point is at the beginning of a headline, insert a sibling before the current headline. If point is not at the beginning, do not split the line, but create the new headline after the current line." (interactive "P") (if (= (buffer-size) 0) (insert "\n* ") (when (or force-heading (not (org-insert-item))) (let* ((head (save-excursion (condition-case nil (progn (org-back-to-heading) (match-string 0)) (error "*")))) (blank (cdr (assq 'heading org-blank-before-new-entry))) pos hide-previous previous-pos) (cond ((and (org-on-heading-p) (bolp) (or (bobp) (save-excursion (backward-char 1) (not (org-invisible-p))))) ;; insert before the current line (open-line (if blank 2 1))) ((and (bolp) (or (bobp) (save-excursion (backward-char 1) (not (org-invisible-p))))) ;; insert right here nil) (t ;; somewhere in the line (save-excursion (setq previous-pos (point-at-bol)) (end-of-line) (setq hide-previous (org-invisible-p))) (and org-insert-heading-respect-content (org-show-subtree)) (let ((split (and (org-get-alist-option org-M-RET-may-split-line 'headline) (save-excursion (let ((p (point))) (goto-char (point-at-bol)) (and (looking-at org-complex-heading-regexp) (> p (match-beginning 4))))))) tags pos) (cond (org-insert-heading-respect-content (org-end-of-subtree nil t) (open-line 1)) ((org-on-heading-p) (when hide-previous (show-children) (org-show-entry)) (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$") (setq tags (and (match-end 2) (match-string 2))) (and (match-end 1) (delete-region (match-beginning 1) (match-end 1))) (setq pos (point-at-bol)) (or split (end-of-line 1)) (delete-horizontal-space) (newline (if blank 2 1)) (when tags (save-excursion (goto-char pos) (end-of-line 1) (insert " " tags) (org-set-tags nil 'align)))) (t (or split (end-of-line 1)) (newline (if blank 2 1))))))) (insert head) (just-one-space) (setq pos (point)) (end-of-line 1) (unless (= (point) pos) (just-one-space) (backward-delete-char 1)) (when (and org-insert-heading-respect-content hide-previous) (save-excursion (goto-char previous-pos) (hide-subtree))) (run-hooks 'org-insert-heading-hook))))) (defun org-get-heading (&optional no-tags) "Return the heading of the current entry, without the stars." (save-excursion (org-back-to-heading t) (if (looking-at (if no-tags (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@]+:[ \t]*\\)?$") "\\*+[ \t]+\\([^\r\n]*\\)")) (match-string 1) ""))) (defun org-insert-heading-after-current () "Insert a new heading with same level as current, after current subtree." (interactive) (org-back-to-heading) (org-insert-heading) (org-move-subtree-down) (end-of-line 1)) (defun org-insert-heading-respect-content () (interactive) (let ((org-insert-heading-respect-content t)) (org-insert-heading t))) (defun org-insert-todo-heading-respect-content (&optional force-state) (interactive "P") (let ((org-insert-heading-respect-content t)) (org-insert-todo-heading force-state t))) (defun org-insert-todo-heading (arg &optional force-heading) "Insert a new heading with the same level and TODO state as current heading. If the heading has no TODO state, or if the state is DONE, use the first state (TODO by default). Also with prefix arg, force first state." (interactive "P") (when (or force-heading (not (org-insert-item 'checkbox))) (org-insert-heading force-heading) (save-excursion (org-back-to-heading) (outline-previous-heading) (looking-at org-todo-line-regexp)) (if (or arg (not (match-beginning 2)) (member (match-string 2) org-done-keywords)) (insert (car org-todo-keywords-1) " ") (insert (match-string 2) " ")) (when org-provide-todo-statistics (org-update-parent-todo-statistics)))) (defun org-insert-subheading (arg) "Insert a new subheading and demote it. Works for outline headings and for plain lists alike." (interactive "P") (org-insert-heading arg) (cond ((org-on-heading-p) (org-do-demote)) ((org-at-item-p) (org-indent-item 1)))) (defun org-insert-todo-subheading (arg) "Insert a new subheading with TODO keyword or checkbox and demote it. Works for outline headings and for plain lists alike." (interactive "P") (org-insert-todo-heading arg) (cond ((org-on-heading-p) (org-do-demote)) ((org-at-item-p) (org-indent-item 1)))) ;;; Promotion and Demotion (defun org-promote-subtree () "Promote the entire subtree. See also `org-promote'." (interactive) (save-excursion (org-map-tree 'org-promote)) (org-fix-position-after-promote)) (defun org-demote-subtree () "Demote the entire subtree. See `org-demote'. See also `org-promote'." (interactive) (save-excursion (org-map-tree 'org-demote)) (org-fix-position-after-promote)) (defun org-do-promote () "Promote the current heading higher up the tree. If the region is active in `transient-mark-mode', promote all headings in the region." (interactive) (save-excursion (if (org-region-active-p) (org-map-region 'org-promote (region-beginning) (region-end)) (org-promote))) (org-fix-position-after-promote)) (defun org-do-demote () "Demote the current heading lower down the tree. If the region is active in `transient-mark-mode', demote all headings in the region." (interactive) (save-excursion (if (org-region-active-p) (org-map-region 'org-demote (region-beginning) (region-end)) (org-demote))) (org-fix-position-after-promote)) (defun org-fix-position-after-promote () "Make sure that after pro/demotion cursor position is right." (let ((pos (point))) (when (save-excursion (beginning-of-line 1) (looking-at org-todo-line-regexp) (or (equal pos (match-end 1)) (equal pos (match-end 2)))) (cond ((eobp) (insert " ")) ((eolp) (insert " ")) ((equal (char-after) ?\ ) (forward-char 1)))))) (defun org-reduced-level (l) (if org-odd-levels-only (1+ (floor (/ l 2))) l)) (defun org-get-valid-level (level &optional change) "Rectify a level change under the influence of `org-odd-levels-only' LEVEL is a current level, CHANGE is by how much the level should be modified. Even if CHANGE is nil, LEVEL may be returned modified because even level numbers will become the next higher odd number." (if org-odd-levels-only (cond ((or (not change) (= 0 change)) (1+ (* 2 (/ level 2)))) ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2)))) ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2)))))) (max 1 (+ level change)))) (if (boundp 'define-obsolete-function-alias) (if (or (featurep 'xemacs) (< emacs-major-version 23)) (define-obsolete-function-alias 'org-get-legal-level 'org-get-valid-level) (define-obsolete-function-alias 'org-get-legal-level 'org-get-valid-level "23.1"))) (defun org-promote () "Promote the current heading higher up the tree. If the region is active in `transient-mark-mode', promote all headings in the region." (org-back-to-heading t) (let* ((level (save-match-data (funcall outline-level))) (up-head (concat (make-string (org-get-valid-level level -1) ?*) " ")) (diff (abs (- level (length up-head) -1)))) (if (= level 1) (error "Cannot promote to level 0. UNDO to recover if necessary")) (replace-match up-head nil t) ;; Fixup tag positioning (and org-auto-align-tags (org-set-tags nil t)) (if org-adapt-indentation (org-fixup-indentation (- diff))))) (defun org-demote () "Demote the current heading lower down the tree. If the region is active in `transient-mark-mode', demote all headings in the region." (org-back-to-heading t) (let* ((level (save-match-data (funcall outline-level))) (down-head (concat (make-string (org-get-valid-level level 1) ?*) " ")) (diff (abs (- level (length down-head) -1)))) (replace-match down-head nil t) ;; Fixup tag positioning (and org-auto-align-tags (org-set-tags nil t)) (if org-adapt-indentation (org-fixup-indentation diff)))) (defun org-map-tree (fun) "Call FUN for every heading underneath the current one." (org-back-to-heading) (let ((level (funcall outline-level))) (save-excursion (funcall fun) (while (and (progn (outline-next-heading) (> (funcall outline-level) level)) (not (eobp))) (funcall fun))))) (defun org-map-region (fun beg end) "Call FUN for every heading between BEG and END." (let ((org-ignore-region t)) (save-excursion (setq end (copy-marker end)) (goto-char beg) (if (and (re-search-forward (concat "^" outline-regexp) nil t) (< (point) end)) (funcall fun)) (while (and (progn (outline-next-heading) (< (point) end)) (not (eobp))) (funcall fun))))) (defun org-fixup-indentation (diff) "Change the indentation in the current entry by DIFF However, if any line in the current entry has no indentation, or if it would end up with no indentation after the change, nothing at all is done." (save-excursion (let ((end (save-excursion (outline-next-heading) (point-marker))) (prohibit (if (> diff 0) "^\\S-" (concat "^ \\{0," (int-to-string (- diff)) "\\}\\S-"))) col) (unless (save-excursion (end-of-line 1) (re-search-forward prohibit end t)) (while (and (< (point) end) (re-search-forward "^[ \t]+" end t)) (goto-char (match-end 0)) (setq col (current-column)) (if (< diff 0) (replace-match "")) (indent-to (+ diff col)))) (move-marker end nil)))) (defun org-convert-to-odd-levels () "Convert an org-mode file with all levels allowed to one with odd levels. This will leave level 1 alone, convert level 2 to level 3, level 3 to level 5 etc." (interactive) (when (yes-or-no-p "Are you sure you want to globally change levels to odd? ") (let ((org-odd-levels-only nil) n) (save-excursion (goto-char (point-min)) (while (re-search-forward "^\\*\\*+ " nil t) (setq n (- (length (match-string 0)) 2)) (while (>= (setq n (1- n)) 0) (org-demote)) (end-of-line 1)))))) (defun org-convert-to-oddeven-levels () "Convert an org-mode file with only odd levels to one with odd and even levels. This promotes level 3 to level 2, level 5 to level 3 etc. If the file contains a section with an even level, conversion would destroy the structure of the file. An error is signaled in this case." (interactive) (goto-char (point-min)) ;; First check if there are no even levels (when (re-search-forward "^\\(\\*\\*\\)+ " nil t) (org-show-context t) (error "Not all levels are odd in this file. Conversion not possible.")) (when (yes-or-no-p "Are you sure you want to globally change levels to odd-even? ") (let ((org-odd-levels-only nil) n) (save-excursion (goto-char (point-min)) (while (re-search-forward "^\\*\\*+ " nil t) (setq n (/ (1- (length (match-string 0))) 2)) (while (>= (setq n (1- n)) 0) (org-promote)) (end-of-line 1)))))) (defun org-tr-level (n) "Make N odd if required." (if org-odd-levels-only (1+ (/ n 2)) n)) ;;; Vertical tree motion, cutting and pasting of subtrees (defun org-move-subtree-up (&optional arg) "Move the current subtree up past ARG headlines of the same level." (interactive "p") (org-move-subtree-down (- (prefix-numeric-value arg)))) (defun org-move-subtree-down (&optional arg) "Move the current subtree down past ARG headlines of the same level." (interactive "p") (setq arg (prefix-numeric-value arg)) (let ((movfunc (if (> arg 0) 'outline-get-next-sibling 'outline-get-last-sibling)) (ins-point (make-marker)) (cnt (abs arg)) beg beg0 end txt folded ne-beg ne-end ne-ins ins-end) ;; Select the tree (org-back-to-heading) (setq beg0 (point)) (save-excursion (setq ne-beg (org-back-over-empty-lines)) (setq beg (point))) (save-match-data (save-excursion (outline-end-of-heading) (setq folded (org-invisible-p))) (outline-end-of-subtree)) (outline-next-heading) (setq ne-end (org-back-over-empty-lines)) (setq end (point)) (goto-char beg0) (when (and (> arg 0) (org-first-sibling-p) (< ne-end ne-beg)) ;; include less whitespace (save-excursion (goto-char beg) (forward-line (- ne-beg ne-end)) (setq beg (point)))) ;; Find insertion point, with error handling (while (> cnt 0) (or (and (funcall movfunc) (looking-at outline-regexp)) (progn (goto-char beg0) (error "Cannot move past superior level or buffer limit"))) (setq cnt (1- cnt))) (if (> arg 0) ;; Moving forward - still need to move over subtree (progn (org-end-of-subtree t t) (save-excursion (org-back-over-empty-lines) (or (bolp) (newline))))) (setq ne-ins (org-back-over-empty-lines)) (move-marker ins-point (point)) (setq txt (buffer-substring beg end)) (org-save-markers-in-region beg end) (delete-region beg end) (outline-flag-region (1- beg) beg nil) (outline-flag-region (1- (point)) (point) nil) (let ((bbb (point))) (insert-before-markers txt) (org-reinstall-markers-in-region bbb) (move-marker ins-point bbb)) (or (bolp) (insert "\n")) (setq ins-end (point)) (goto-char ins-point) (org-skip-whitespace) (when (and (< arg 0) (org-first-sibling-p) (> ne-ins ne-beg)) ;; Move whitespace back to beginning (save-excursion (goto-char ins-end) (let ((kill-whole-line t)) (kill-line (- ne-ins ne-beg)) (point))) (insert (make-string (- ne-ins ne-beg) ?\n))) (move-marker ins-point nil) (org-compact-display-after-subtree-move) (org-show-empty-lines-in-parent) (unless folded (org-show-entry) (show-children) (org-cycle-hide-drawers 'children)))) (defvar org-subtree-clip "" "Clipboard for cut and paste of subtrees. This is actually only a copy of the kill, because we use the normal kill ring. We need it to check if the kill was created by `org-copy-subtree'.") (defvar org-subtree-clip-folded nil "Was the last copied subtree folded? This is used to fold the tree back after pasting.") (defun org-cut-subtree (&optional n) "Cut the current subtree into the clipboard. With prefix arg N, cut this many sequential subtrees. This is a short-hand for marking the subtree and then cutting it." (interactive "p") (org-copy-subtree n 'cut)) (defun org-copy-subtree (&optional n cut force-store-markers) "Cut the current subtree into the clipboard. With prefix arg N, cut this many sequential subtrees. This is a short-hand for marking the subtree and then copying it. If CUT is non-nil, actually cut the subtree. If FORCE-STORE-MARKERS is non-nil, store the relative locations of some markers in the region, even if CUT is non-nil. This is useful if the caller implements cut-and-paste as copy-then-paste-then-cut." (interactive "p") (let (beg end folded (beg0 (point))) (if (interactive-p) (org-back-to-heading nil) ; take what looks like a subtree (org-back-to-heading t)) ; take what is really there (org-back-over-empty-lines) (setq beg (point)) (skip-chars-forward " \t\r\n") (save-match-data (save-excursion (outline-end-of-heading) (setq folded (org-invisible-p))) (condition-case nil (outline-forward-same-level (1- n)) (error nil)) (org-end-of-subtree t t)) (org-back-over-empty-lines) (setq end (point)) (goto-char beg0) (when (> end beg) (setq org-subtree-clip-folded folded) (when (or cut force-store-markers) (org-save-markers-in-region beg end)) (if cut (kill-region beg end) (copy-region-as-kill beg end)) (setq org-subtree-clip (current-kill 0)) (message "%s: Subtree(s) with %d characters" (if cut "Cut" "Copied") (length org-subtree-clip))))) (defun org-paste-subtree (&optional level tree for-yank) "Paste the clipboard as a subtree, with modification of headline level. The entire subtree is promoted or demoted in order to match a new headline level. If the cursor is at the beginning of a headline, the same level as that headline is used to paste the tree If not, the new level is derived from the *visible* headings before and after the insertion point, and taken to be the inferior headline level of the two. So if the previous visible heading is level 3 and the next is level 4 (or vice versa), level 4 will be used for insertion. This makes sure that the subtree remains an independent subtree and does not swallow low level entries. You can also force a different level, either by using a numeric prefix argument, or by inserting the heading marker by hand. For example, if the cursor is after \"*****\", then the tree will be shifted to level 5. If optional TREE is given, use this text instead of the kill ring. When FOR-YANK is set, this is called by `org-yank'. In this case, do not move back over whitespace before inserting, and move point to the end of the inserted text when done." (interactive "P") (unless (org-kill-is-subtree-p tree) (error "%s" (substitute-command-keys "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway"))) (let* ((visp (not (org-invisible-p))) (txt (or tree (and kill-ring (current-kill 0)))) (^re (concat "^\\(" outline-regexp "\\)")) (re (concat "\\(" outline-regexp "\\)")) (^re_ (concat "\\(\\*+\\)[ \t]*")) (old-level (if (string-match ^re txt) (- (match-end 0) (match-beginning 0) 1) -1)) (force-level (cond (level (prefix-numeric-value level)) ((and (looking-at "[ \t]*$") (string-match ^re_ (buffer-substring (point-at-bol) (point)))) (- (match-end 1) (match-beginning 1))) ((and (bolp) (looking-at org-outline-regexp)) (- (match-end 0) (point) 1)) (t nil))) (previous-level (save-excursion (condition-case nil (progn (outline-previous-visible-heading 1) (if (looking-at re) (- (match-end 0) (match-beginning 0) 1) 1)) (error 1)))) (next-level (save-excursion (condition-case nil (progn (or (looking-at outline-regexp) (outline-next-visible-heading 1)) (if (looking-at re) (- (match-end 0) (match-beginning 0) 1) 1)) (error 1)))) (new-level (or force-level (max previous-level next-level))) (shift (if (or (= old-level -1) (= new-level -1) (= old-level new-level)) 0 (- new-level old-level))) (delta (if (> shift 0) -1 1)) (func (if (> shift 0) 'org-demote 'org-promote)) (org-odd-levels-only nil) beg end newend) ;; Remove the forced level indicator (if force-level (delete-region (point-at-bol) (point))) ;; Paste (beginning-of-line 1) (unless for-yank (org-back-over-empty-lines)) (setq beg (point)) (insert-before-markers txt) (unless (string-match "\n\\'" txt) (insert "\n")) (setq newend (point)) (org-reinstall-markers-in-region beg) (setq end (point)) (goto-char beg) (skip-chars-forward " \t\n\r") (setq beg (point)) (if (and (org-invisible-p) visp) (save-excursion (outline-show-heading))) ;; Shift if necessary (unless (= shift 0) (save-restriction (narrow-to-region beg end) (while (not (= shift 0)) (org-map-region func (point-min) (point-max)) (setq shift (+ delta shift))) (goto-char (point-min)) (setq newend (point-max)))) (when (or (interactive-p) for-yank) (message "Clipboard pasted as level %d subtree" new-level)) (if (and (not for-yank) ; in this case, org-yank will decide about folding kill-ring (eq org-subtree-clip (current-kill 0)) org-subtree-clip-folded) ;; The tree was folded before it was killed/copied (hide-subtree)) (and for-yank (goto-char newend)))) (defun org-kill-is-subtree-p (&optional txt) "Check if the current kill is an outline subtree, or a set of trees. Returns nil if kill does not start with a headline, or if the first headline level is not the largest headline level in the tree. So this will actually accept several entries of equal levels as well, which is OK for `org-paste-subtree'. If optional TXT is given, check this string instead of the current kill." (let* ((kill (or txt (and kill-ring (current-kill 0)) "")) (start-level (and kill (string-match (concat "\\`\\([ \t\n\r]*?\n\\)?\\(" org-outline-regexp "\\)") kill) (- (match-end 2) (match-beginning 2) 1))) (re (concat "^" org-outline-regexp)) (start (1+ (or (match-beginning 2) -1)))) (if (not start-level) (progn nil) ;; does not even start with a heading (catch 'exit (while (setq start (string-match re kill (1+ start))) (when (< (- (match-end 0) (match-beginning 0) 1) start-level) (throw 'exit nil))) t)))) (defvar org-markers-to-move nil "Markers that should be moved with a cut-and-paste operation. Those markers are stored together with their positions relative to the start of the region.") (defun org-save-markers-in-region (beg end) "Check markers in region. If these markers are between BEG and END, record their position relative to BEG, so that after moving the block of text, we can put the markers back into place. This function gets called just before an entry or tree gets cut from the buffer. After re-insertion, `org-reinstall-markers-in-region' must be called immediately, to move the markers with the entries." (setq org-markers-to-move nil) (when (featurep 'org-clock) (org-clock-save-markers-for-cut-and-paste beg end)) (when (featurep 'org-agenda) (org-agenda-save-markers-for-cut-and-paste beg end))) (defun org-check-and-save-marker (marker beg end) "Check if MARKER is between BEG and END. If yes, remember the marker and the distance to BEG." (when (and (marker-buffer marker) (equal (marker-buffer marker) (current-buffer))) (if (and (>= marker beg) (< marker end)) (push (cons marker (- marker beg)) org-markers-to-move)))) (defun org-reinstall-markers-in-region (beg) "Move all remembered markers to their position relative to BEG." (mapc (lambda (x) (move-marker (car x) (+ beg (cdr x)))) org-markers-to-move) (setq org-markers-to-move nil)) (defun org-narrow-to-subtree () "Narrow buffer to the current subtree." (interactive) (save-excursion (save-match-data (narrow-to-region (progn (org-back-to-heading) (point)) (progn (org-end-of-subtree t) (point)))))) ;;; Outline Sorting (defun org-sort (with-case) "Call `org-sort-entries-or-items' or `org-table-sort-lines'. Optional argument WITH-CASE means sort case-sensitively." (interactive "P") (if (org-at-table-p) (org-call-with-arg 'org-table-sort-lines with-case) (org-call-with-arg 'org-sort-entries-or-items with-case))) (defun org-sort-remove-invisible (s) (remove-text-properties 0 (length s) org-rm-props s) (while (string-match org-bracket-link-regexp s) (setq s (replace-match (if (match-end 2) (match-string 3 s) (match-string 1 s)) t t s))) s) (defvar org-priority-regexp) ; defined later in the file (defun org-sort-entries-or-items (&optional with-case sorting-type getkey-func property) "Sort entries on a certain level of an outline tree. If there is an active region, the entries in the region are sorted. Else, if the cursor is before the first entry, sort the top-level items. Else, the children of the entry at point are sorted. Sorting can be alphabetically, numerically, and by date/time as given by the first time stamp in the entry. The command prompts for the sorting type unless it has been given to the function through the SORTING-TYPE argument, which needs to a character, any of (?n ?N ?a ?A ?t ?T ?p ?P ?f ?F). If the SORTING-TYPE is ?f or ?F, then GETKEY-FUNC specifies a function to be called with point at the beginning of the record. It must return either a string or a number that should serve as the sorting key for that record. Comparing entries ignores case by default. However, with an optional argument WITH-CASE, the sorting considers case as well." (interactive "P") (let ((case-func (if with-case 'identity 'downcase)) start beg end stars re re2 txt what tmp plain-list-p) ;; Find beginning and end of region to sort (cond ((org-region-active-p) ;; we will sort the region (setq end (region-end) what "region") (goto-char (region-beginning)) (if (not (org-on-heading-p)) (outline-next-heading)) (setq start (point))) ((org-at-item-p) ;; we will sort this plain list (org-beginning-of-item-list) (setq start (point)) (org-end-of-item-list) (setq end (point)) (goto-char start) (setq plain-list-p t what "plain list")) ((or (org-on-heading-p) (condition-case nil (progn (org-back-to-heading) t) (error nil))) ;; we will sort the children of the current headline (org-back-to-heading) (setq start (point) end (progn (org-end-of-subtree t t) (org-back-over-empty-lines) (point)) what "children") (goto-char start) (show-subtree) (outline-next-heading)) (t ;; we will sort the top-level entries in this file (goto-char (point-min)) (or (org-on-heading-p) (outline-next-heading)) (setq start (point) end (point-max) what "top-level") (goto-char start) (show-all))) (setq beg (point)) (if (>= beg end) (error "Nothing to sort")) (unless plain-list-p (looking-at "\\(\\*+\\)") (setq stars (match-string 1) re (concat "^" (regexp-quote stars) " +") re2 (concat "^" (regexp-quote (substring stars 0 -1)) "[^*]") txt (buffer-substring beg end)) (if (not (equal (substring txt -1) "\n")) (setq txt (concat txt "\n"))) (if (and (not (equal stars "*")) (string-match re2 txt)) (error "Region to sort contains a level above the first entry"))) (unless sorting-type (message (if plain-list-p "Sort %s: [a]lpha [n]umeric [t]ime [f]unc A/N/T/F means reversed:" "Sort %s: [a]lpha [n]umeric [t]ime [p]riority p[r]operty todo[o]rder [f]unc A/N/T/P/O/F means reversed:") what) (setq sorting-type (read-char-exclusive)) (and (= (downcase sorting-type) ?f) (setq getkey-func (completing-read "Sort using function: " obarray 'fboundp t nil nil)) (setq getkey-func (intern getkey-func))) (and (= (downcase sorting-type) ?r) (setq property (completing-read "Property: " (mapcar 'list (org-buffer-property-keys t)) nil t)))) (message "Sorting entries...") (save-restriction (narrow-to-region start end) (let ((dcst (downcase sorting-type)) (now (current-time))) (sort-subr (/= dcst sorting-type) ;; This function moves to the beginning character of the "record" to ;; be sorted. (if plain-list-p (lambda nil (if (org-at-item-p) t (goto-char (point-max)))) (lambda nil (if (re-search-forward re nil t) (goto-char (match-beginning 0)) (goto-char (point-max))))) ;; This function moves to the last character of the "record" being ;; sorted. (if plain-list-p 'org-end-of-item (lambda nil (save-match-data (condition-case nil (outline-forward-same-level 1) (error (goto-char (point-max))))))) ;; This function returns the value that gets sorted against. (if plain-list-p (lambda nil (when (looking-at "[ \t]*[-+*0-9.)]+[ \t]+") (cond ((= dcst ?n) (string-to-number (buffer-substring (match-end 0) (point-at-eol)))) ((= dcst ?a) (buffer-substring (match-end 0) (point-at-eol))) ((= dcst ?t) (if (re-search-forward org-ts-regexp (point-at-eol) t) (org-time-string-to-time (match-string 0)) now)) ((= dcst ?f) (if getkey-func (progn (setq tmp (funcall getkey-func)) (if (stringp tmp) (setq tmp (funcall case-func tmp))) tmp) (error "Invalid key function `%s'" getkey-func))) (t (error "Invalid sorting type `%c'" sorting-type))))) (lambda nil (cond ((= dcst ?n) (if (looking-at org-complex-heading-regexp) (string-to-number (match-string 4)) nil)) ((= dcst ?a) (if (looking-at org-complex-heading-regexp) (funcall case-func (match-string 4)) nil)) ((= dcst ?t) (if (re-search-forward org-ts-regexp (save-excursion (forward-line 2) (point)) t) (org-time-string-to-time (match-string 0)) now)) ((= dcst ?p) (if (re-search-forward org-priority-regexp (point-at-eol) t) (string-to-char (match-string 2)) org-default-priority)) ((= dcst ?r) (or (org-entry-get nil property) "")) ((= dcst ?o) (if (looking-at org-complex-heading-regexp) (- 9999 (length (member (match-string 2) org-todo-keywords-1))))) ((= dcst ?f) (if getkey-func (progn (setq tmp (funcall getkey-func)) (if (stringp tmp) (setq tmp (funcall case-func tmp))) tmp) (error "Invalid key function `%s'" getkey-func))) (t (error "Invalid sorting type `%c'" sorting-type))))) nil (cond ((= dcst ?a) 'string<) ((= dcst ?t) 'time-less-p) (t nil))))) (message "Sorting entries...done"))) (defun org-do-sort (table what &optional with-case sorting-type) "Sort TABLE of WHAT according to SORTING-TYPE. The user will be prompted for the SORTING-TYPE if the call to this function does not specify it. WHAT is only for the prompt, to indicate what is being sorted. The sorting key will be extracted from the car of the elements of the table. If WITH-CASE is non-nil, the sorting will be case-sensitive." (unless sorting-type (message "Sort %s: [a]lphabetic. [n]umeric. [t]ime. A/N/T means reversed:" what) (setq sorting-type (read-char-exclusive))) (let ((dcst (downcase sorting-type)) extractfun comparefun) ;; Define the appropriate functions (cond ((= dcst ?n) (setq extractfun 'string-to-number comparefun (if (= dcst sorting-type) '< '>))) ((= dcst ?a) (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisible x)) (lambda(x) (downcase (org-sort-remove-invisible x)))) comparefun (if (= dcst sorting-type) 'string< (lambda (a b) (and (not (string< a b)) (not (string= a b))))))) ((= dcst ?t) (setq extractfun (lambda (x) (if (string-match org-ts-regexp x) (time-to-seconds (org-time-string-to-time (match-string 0 x))) 0)) comparefun (if (= dcst sorting-type) '< '>))) (t (error "Invalid sorting type `%c'" sorting-type))) (sort (mapcar (lambda (x) (cons (funcall extractfun (car x)) (cdr x))) table) (lambda (a b) (funcall comparefun (car a) (car b)))))) ;;; Editing source examples (defvar org-exit-edit-mode-map (make-sparse-keymap)) (define-key org-exit-edit-mode-map "\C-c'" 'org-edit-src-exit) (defvar org-edit-src-force-single-line nil) (defvar org-edit-src-from-org-mode nil) (defvar org-edit-src-picture nil) (define-minor-mode org-exit-edit-mode "Minor mode installing a single key binding, \"C-c '\" to exit special edit.") (defun org-edit-src-code () "Edit the source code example at point. An indirect buffer is created, and that buffer is then narrowed to the example at point and switched to the correct language mode. When done, exit by killing the buffer with \\[org-edit-src-exit]." (interactive) (let ((line (org-current-line)) (case-fold-search t) (msg (substitute-command-keys "Edit, then exit with C-c ' (C-c and single quote)")) (info (org-edit-src-find-region-and-lang)) (org-mode-p (eq major-mode 'org-mode)) beg end lang lang-f single) (if (not info) nil (setq beg (nth 0 info) end (nth 1 info) lang (nth 2 info) single (nth 3 info) lang-f (intern (concat lang "-mode"))) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) (goto-line line) (if (get-buffer "*Org Edit Src Example*") (kill-buffer "*Org Edit Src Example*")) (switch-to-buffer (make-indirect-buffer (current-buffer) "*Org Edit Src Example*")) (narrow-to-region beg end) (remove-text-properties beg end '(display nil invisible nil intangible nil)) (let ((org-inhibit-startup t)) (funcall lang-f)) (set (make-local-variable 'org-edit-src-force-single-line) single) (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p) (when org-mode-p (goto-char (point-min)) (while (re-search-forward "^," nil t) (replace-match ""))) (goto-line line) (org-exit-edit-mode) (org-set-local 'header-line-format msg) (message "%s" msg) t))) (defun org-edit-fixed-width-region () "Edit the fixed-width ascii drawing at point. This must be a region where each line starts with ca colon followed by a space character. An indirect buffer is created, and that buffer is then narrowed to the example at point and switched to artist-mode. When done, exit by killing the buffer with \\[org-edit-src-exit]." (interactive) (let ((line (org-current-line)) (case-fold-search t) (msg (substitute-command-keys "Edit, then exit with C-c ' (C-c and single quote)")) (org-mode-p (eq major-mode 'org-mode)) beg end lang lang-f) (beginning-of-line 1) (if (looking-at "[ \t]*[^:\n \t]") nil (if (looking-at "[ \t]*\\(\n\\|\\'\\)]") (setq beg (point) end (match-end 0)) (save-excursion (if (re-search-backward "^[ \t]*[^:]" nil 'move) (setq beg (point-at-bol 2)) (setq beg (point)))) (save-excursion (if (re-search-forward "^[ \t]*[^:]" nil 'move) (setq end (1- (match-beginning 0))) (setq end (point)))) (goto-line line) (if (get-buffer "*Org Edit Picture*") (kill-buffer "*Org Edit Picture*")) (switch-to-buffer (make-indirect-buffer (current-buffer) "*Org Edit Picture*")) (narrow-to-region beg end) (remove-text-properties beg end '(display nil invisible nil intangible nil)) (when (fboundp 'font-lock-unfontify-region) (font-lock-unfontify-region (point-min) (point-max))) (cond ((eq org-edit-fixed-width-region-mode 'artist-mode) (fundamental-mode) (artist-mode 1)) (t (funcall org-edit-fixed-width-region-mode))) (set (make-local-variable 'org-edit-src-force-single-line) nil) (set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p) (set (make-local-variable 'org-edit-src-picture) t) (goto-char (point-min)) (while (re-search-forward "^[ \t]*: " nil t) (replace-match "")) (goto-line line) (org-exit-edit-mode) (org-set-local 'header-line-format msg) (message "%s" msg) t)))) (defun org-edit-src-find-region-and-lang () "Find the region and language for a local edit. Return a list with beginning and end of the region, a string representing the language, a switch telling of the content should be in a single line." (let ((re-list (append org-edit-src-region-extra '( ("[^<]*>[ \t]*\n?" "\n?[ \t]*" lang) ("[^<]*>[ \t]*\n?" "\n?[ \t]*" style) ("[ \t]*\n?" "\n?[ \t]*" "fundamental") ("[ \t]*\n?" "\n?[ \t]*" "emacs-lisp") ("[ \t]*\n?" "\n?[ \t]*" "perl") ("[ \t]*\n?" "\n?[ \t]*" "python") ("[ \t]*\n?" "\n?[ \t]*" "ruby") ("^#\\+begin_src\\( \\([^ \t\n]+\\)\\)?.*\n" "\n#\\+end_src" 2) ("^#\\+begin_example.*\n" "\n#\\+end_example" "fundamental") ("^#\\+html:" "\n" "html" single-line) ("^#\\+begin_html.*\n" "\n#\\+end_html" "html") ("^#\\+begin_latex.*\n" "\n#\\+end_latex" "latex") ("^#\\+latex:" "\n" "latex" single-line) ("^#\\+begin_ascii.*\n" "\n#\\+end_ascii" "fundamental") ("^#\\+ascii:" "\n" "ascii" single-line) ))) (pos (point)) re re1 re2 single beg end lang) (catch 'exit (while (setq entry (pop re-list)) (setq re1 (car entry) re2 (nth 1 entry) lang (nth 2 entry) single (nth 3 entry)) (save-excursion (if (or (looking-at re1) (re-search-backward re1 nil t)) (progn (setq beg (match-end 0) lang (org-edit-src-get-lang lang)) (if (and (re-search-forward re2 nil t) (>= (match-end 0) pos)) (throw 'exit (list beg (match-beginning 0) lang single)))) (if (or (looking-at re2) (re-search-forward re2 nil t)) (progn (setq end (match-beginning 0)) (if (and (re-search-backward re1 nil t) (<= (match-beginning 0) pos)) (throw 'exit (list (match-end 0) end (org-edit-src-get-lang lang) single))))))))))) (defun org-edit-src-get-lang (lang) "Extract the src language." (let ((m (match-string 0))) (cond ((stringp lang) lang) ((integerp lang) (match-string lang)) ((and (eq lang 'lang) (string-match "\\ (point-min) 1) (error "This buffer is not narrowed, something is wrong...")) (goto-char (point-min)) (if (looking-at "[ \t\n]*\n") (replace-match "")) (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match "")) (when (org-bound-and-true-p org-edit-src-force-single-line) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match " ")) (goto-char (point-min)) (if (looking-at "\\s-*") (replace-match " ")) (if (re-search-forward "\\s-+\\'" nil t) (replace-match ""))) (when (org-bound-and-true-p org-edit-src-from-org-mode) (goto-char (point-min)) (while (re-search-forward (if (org-mode-p) "^\\(.\\)" "^\\([*#]\\)") nil t) (replace-match ",\\1")) (when font-lock-mode (font-lock-unfontify-region (point-min) (point-max))) (put-text-property (point-min) (point-max) 'font-lock-fontified t)) (when (org-bound-and-true-p org-edit-src-picture) (goto-char (point-min)) (while (re-search-forward "^" nil t) (replace-match ": ")) (when font-lock-mode (font-lock-unfontify-region (point-min) (point-max))) (put-text-property (point-min) (point-max) 'font-lock-fontified t)) (kill-buffer (current-buffer)) (and (org-mode-p) (org-restart-font-lock))) ;;; The orgstruct minor mode ;; Define a minor mode which can be used in other modes in order to ;; integrate the org-mode structure editing commands. ;; This is really a hack, because the org-mode structure commands use ;; keys which normally belong to the major mode. Here is how it ;; works: The minor mode defines all the keys necessary to operate the ;; structure commands, but wraps the commands into a function which ;; tests if the cursor is currently at a headline or a plain list ;; item. If that is the case, the structure command is used, ;; temporarily setting many Org-mode variables like regular ;; expressions for filling etc. However, when any of those keys is ;; used at a different location, function uses `key-binding' to look ;; up if the key has an associated command in another currently active ;; keymap (minor modes, major mode, global), and executes that ;; command. There might be problems if any of the keys is otherwise ;; used as a prefix key. ;; Another challenge is that the key binding for TAB can be tab or \C-i, ;; likewise the binding for RET can be return or \C-m. Orgtbl-mode ;; addresses this by checking explicitly for both bindings. (defvar orgstruct-mode-map (make-sparse-keymap) "Keymap for the minor `orgstruct-mode'.") (defvar org-local-vars nil "List of local variables, for use by `orgstruct-mode'") ;;;###autoload (define-minor-mode orgstruct-mode "Toggle the minor more `orgstruct-mode'. This mode is for using Org-mode structure commands in other modes. The following key behave as if Org-mode was active, if the cursor is on a headline, or on a plain list item (both in the definition of Org-mode). M-up Move entry/item up M-down Move entry/item down M-left Promote M-right Demote M-S-up Move entry/item up M-S-down Move entry/item down M-S-left Promote subtree M-S-right Demote subtree M-q Fill paragraph and items like in Org-mode C-c ^ Sort entries C-c - Cycle list bullet TAB Cycle item visibility M-RET Insert new heading/item S-M-RET Insert new TODO heading / Chekbox item C-c C-c Set tags / toggle checkbox" nil " OrgStruct" nil (org-load-modules-maybe) (and (orgstruct-setup) (defun orgstruct-setup () nil))) ;;;###autoload (defun turn-on-orgstruct () "Unconditionally turn on `orgstruct-mode'." (orgstruct-mode 1)) ;;;###autoload (defun turn-on-orgstruct++ () "Unconditionally turn on `orgstruct-mode', and force org-mode indentations. In addition to setting orgstruct-mode, this also exports all indentation and autofilling variables from org-mode into the buffer. Note that turning off orgstruct-mode will *not* remove these additional settings." (orgstruct-mode 1) (let (var val) (mapc (lambda (x) (when (string-match "^\\(paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)" (symbol-name (car x))) (setq var (car x) val (nth 1 x)) (org-set-local var (if (eq (car-safe val) 'quote) (nth 1 val) val)))) org-local-vars))) (defun orgstruct-error () "Error when there is no default binding for a structure key." (interactive) (error "This key has no function outside structure elements")) (defun orgstruct-setup () "Setup orgstruct keymaps." (let ((nfunc 0) (bindings (list '([(meta up)] org-metaup) '([(meta down)] org-metadown) '([(meta left)] org-metaleft) '([(meta right)] org-metaright) '([(meta shift up)] org-shiftmetaup) '([(meta shift down)] org-shiftmetadown) '([(meta shift left)] org-shiftmetaleft) '([(meta shift right)] org-shiftmetaright) '([(shift up)] org-shiftup) '([(shift down)] org-shiftdown) '("\C-c\C-c" org-ctrl-c-ctrl-c) '("\M-q" fill-paragraph) '("\C-c^" org-sort) '("\C-c-" org-cycle-list-bullet))) elt key fun cmd) (while (setq elt (pop bindings)) (setq nfunc (1+ nfunc)) (setq key (org-key (car elt)) fun (nth 1 elt) cmd (orgstruct-make-binding fun nfunc key)) (org-defkey orgstruct-mode-map key cmd)) ;; Special treatment needed for TAB and RET (org-defkey orgstruct-mode-map [(tab)] (orgstruct-make-binding 'org-cycle 102 [(tab)] "\C-i")) (org-defkey orgstruct-mode-map "\C-i" (orgstruct-make-binding 'org-cycle 103 "\C-i" [(tab)])) (org-defkey orgstruct-mode-map "\M-\C-m" (orgstruct-make-binding 'org-insert-heading 105 "\M-\C-m" [(meta return)])) (org-defkey orgstruct-mode-map [(meta return)] (orgstruct-make-binding 'org-insert-heading 106 [(meta return)] "\M-\C-m")) (org-defkey orgstruct-mode-map [(shift meta return)] (orgstruct-make-binding 'org-insert-todo-heading 107 [(meta return)] "\M-\C-m")) (unless org-local-vars (setq org-local-vars (org-get-local-variables))) t)) (defun orgstruct-make-binding (fun n &rest keys) "Create a function for binding in the structure minor mode. FUN is the command to call inside a table. N is used to create a unique command name. KEYS are keys that should be checked in for a command to execute outside of tables." (eval (list 'defun (intern (concat "orgstruct-hijacker-command-" (int-to-string n))) '(arg) (concat "In Structure, run `" (symbol-name fun) "'.\n" "Outside of structure, run the binding of `" (mapconcat (lambda (x) (format "%s" x)) keys "' or `") "'.") '(interactive "p") (list 'if '(org-context-p 'headline 'item) (list 'org-run-like-in-org-mode (list 'quote fun)) (list 'let '(orgstruct-mode) (list 'call-interactively (append '(or) (mapcar (lambda (k) (list 'key-binding k)) keys) '('orgstruct-error)))))))) (defun org-context-p (&rest contexts) "Check if local context is any of CONTEXTS. Possible values in the list of contexts are `table', `headline', and `item'." (let ((pos (point))) (goto-char (point-at-bol)) (prog1 (or (and (memq 'table contexts) (looking-at "[ \t]*|")) (and (memq 'headline contexts) ;;????????? (looking-at "\\*+")) (looking-at outline-regexp)) (and (memq 'item contexts) (looking-at "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)"))) (goto-char pos)))) (defun org-get-local-variables () "Return a list of all local variables in an org-mode buffer." (let (varlist) (with-current-buffer (get-buffer-create "*Org tmp*") (erase-buffer) (org-mode) (setq varlist (buffer-local-variables))) (kill-buffer "*Org tmp*") (delq nil (mapcar (lambda (x) (setq x (if (symbolp x) (list x) (list (car x) (list 'quote (cdr x))))) (if (string-match "^\\(org-\\|orgtbl-\\|outline-\\|comment-\\|paragraph-\\|auto-fill\\|fill-paragraph\\|adaptive-fill\\|indent-\\)" (symbol-name (car x))) x nil)) varlist)))) ;;;###autoload (defun org-run-like-in-org-mode (cmd) (org-load-modules-maybe) (unless org-local-vars (setq org-local-vars (org-get-local-variables))) (eval (list 'let org-local-vars (list 'call-interactively (list 'quote cmd))))) ;;;; Archiving (defun org-get-category (&optional pos) "Get the category applying to position POS." (get-text-property (or pos (point)) 'org-category)) (defun org-refresh-category-properties () "Refresh category text properties in the buffer." (let ((def-cat (cond ((null org-category) (if buffer-file-name (file-name-sans-extension (file-name-nondirectory buffer-file-name)) "???")) ((symbolp org-category) (symbol-name org-category)) (t org-category))) beg end cat pos optionp) (org-unmodified (save-excursion (save-restriction (widen) (goto-char (point-min)) (put-text-property (point) (point-max) 'org-category def-cat) (while (re-search-forward "^\\(#\\+CATEGORY:\\|[ \t]*:CATEGORY:\\)\\(.*\\)" nil t) (setq pos (match-end 0) optionp (equal (char-after (match-beginning 0)) ?#) cat (org-trim (match-string 2))) (if optionp (setq beg (point-at-bol) end (point-max)) (org-back-to-heading t) (setq beg (point) end (org-end-of-subtree t t))) (put-text-property beg end 'org-category cat) (goto-char pos))))))) ;;;; Link Stuff ;;; Link abbreviations (defun org-link-expand-abbrev (link) "Apply replacements as defined in `org-link-abbrev-alist." (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link) (let* ((key (match-string 1 link)) (as (or (assoc key org-link-abbrev-alist-local) (assoc key org-link-abbrev-alist))) (tag (and (match-end 2) (match-string 3 link))) rpl) (if (not as) link (setq rpl (cdr as)) (cond ((symbolp rpl) (funcall rpl tag)) ((string-match "%s" rpl) (replace-match (or tag "") t t rpl)) (t (concat rpl tag))))) link)) ;;; Storing and inserting links (defvar org-insert-link-history nil "Minibuffer history for links inserted with `org-insert-link'.") (defvar org-stored-links nil "Contains the links stored with `org-store-link'.") (defvar org-store-link-plist nil "Plist with info about the most recently link created with `org-store-link'.") (defvar org-link-protocols nil "Link protocols added to Org-mode using `org-add-link-type'.") (defvar org-store-link-functions nil "List of functions that are called to create and store a link. Each function will be called in turn until one returns a non-nil value. Each function should check if it is responsible for creating this link (for example by looking at the major mode). If not, it must exit and return nil. If yes, it should return a non-nil value after a calling `org-store-link-props' with a list of properties and values. Special properties are: :type The link prefix. like \"http\". This must be given. :link The link, like \"http://www.astro.uva.nl/~dominik\". This is obligatory as well. :description Optional default description for the second pair of brackets in an Org-mode link. The user can still change this when inserting this link into an Org-mode buffer. In addition to these, any additional properties can be specified and then used in remember templates.") (defun org-add-link-type (type &optional follow export) "Add TYPE to the list of `org-link-types'. Re-compute all regular expressions depending on `org-link-types' FOLLOW and EXPORT are two functions. FOLLOW should take the link path as the single argument and do whatever is necessary to follow the link, for example find a file or display a mail message. EXPORT should format the link path for export to one of the export formats. It should be a function accepting three arguments: path the path of the link, the text after the prefix (like \"http:\") desc the description of the link, if any, nil if there was no descripton format the export format, a symbol like `html' or `latex'. The function may use the FORMAT information to return different values depending on the format. The return value will be put literally into the exported file. Org-mode has a built-in default for exporting links. If you are happy with this default, there is no need to define an export function for the link type. For a simple example of an export function, see `org-bbdb.el'." (add-to-list 'org-link-types type t) (org-make-link-regexps) (if (assoc type org-link-protocols) (setcdr (assoc type org-link-protocols) (list follow export)) (push (list type follow export) org-link-protocols))) ;;;###autoload (defun org-store-link (arg) "\\Store an org-link to the current location. This link is added to `org-stored-links' and can later be inserted into an org-buffer with \\[org-insert-link]. For some link types, a prefix arg is interpreted: For links to usenet articles, arg negates `org-usenet-links-prefer-google'. For file links, arg negates `org-context-in-file-links'." (interactive "P") (org-load-modules-maybe) (setq org-store-link-plist nil) ; reset (let (link cpltxt desc description search txt) (cond ((run-hook-with-args-until-success 'org-store-link-functions) (setq link (plist-get org-store-link-plist :link) desc (or (plist-get org-store-link-plist :description) link))) ((eq major-mode 'calendar-mode) (let ((cd (calendar-cursor-to-date))) (setq link (format-time-string (car org-time-stamp-formats) (apply 'encode-time (list 0 0 0 (nth 1 cd) (nth 0 cd) (nth 2 cd) nil nil nil)))) (org-store-link-props :type "calendar" :date cd))) ((eq major-mode 'w3-mode) (setq cpltxt (url-view-url t) link (org-make-link cpltxt)) (org-store-link-props :type "w3" :url (url-view-url t))) ((eq major-mode 'w3m-mode) (setq cpltxt (or w3m-current-title w3m-current-url) link (org-make-link w3m-current-url)) (org-store-link-props :type "w3m" :url (url-view-url t))) ((setq search (run-hook-with-args-until-success 'org-create-file-search-functions)) (setq link (concat "file:" (abbreviate-file-name buffer-file-name) "::" search)) (setq cpltxt (or description link))) ((eq major-mode 'image-mode) (setq cpltxt (concat "file:" (abbreviate-file-name buffer-file-name)) link (org-make-link cpltxt)) (org-store-link-props :type "image" :file buffer-file-name)) ((eq major-mode 'dired-mode) ;; link to the file in the current line (setq cpltxt (concat "file:" (abbreviate-file-name (expand-file-name (dired-get-filename nil t)))) link (org-make-link cpltxt))) ((and buffer-file-name (org-mode-p)) ;; Just link to current headline (setq cpltxt (concat "file:" (abbreviate-file-name buffer-file-name))) ;; Add a context search string (when (org-xor org-context-in-file-links arg) ;; Check if we are on a target (if (org-in-regexp "<<\\(.*?\\)>>") (setq cpltxt (concat cpltxt "::" (match-string 1))) (setq txt (cond ((org-on-heading-p) nil) ((org-region-active-p) (buffer-substring (region-beginning) (region-end))) (t nil))) (when (or (null txt) (string-match "\\S-" txt)) (setq cpltxt (concat cpltxt "::" (condition-case nil (org-make-org-heading-search-string txt) (error ""))) desc "NONE")))) (if (string-match "::\\'" cpltxt) (setq cpltxt (substring cpltxt 0 -2))) (setq link (org-make-link cpltxt))) ((buffer-file-name (buffer-base-buffer)) ;; Just link to this file here. (setq cpltxt (concat "file:" (abbreviate-file-name (buffer-file-name (buffer-base-buffer))))) ;; Add a context string (when (org-xor org-context-in-file-links arg) (setq txt (if (org-region-active-p) (buffer-substring (region-beginning) (region-end)) (buffer-substring (point-at-bol) (point-at-eol)))) ;; Only use search option if there is some text. (when (string-match "\\S-" txt) (setq cpltxt (concat cpltxt "::" (org-make-org-heading-search-string txt)) desc "NONE"))) (setq link (org-make-link cpltxt))) ((interactive-p) (error "Cannot link to a buffer which is not visiting a file")) (t (setq link nil))) (if (consp link) (setq cpltxt (car link) link (cdr link))) (setq link (or link cpltxt) desc (or desc cpltxt)) (if (equal desc "NONE") (setq desc nil)) (if (and (interactive-p) link) (progn (setq org-stored-links (cons (list link desc) org-stored-links)) (message "Stored: %s" (or desc link))) (and link (org-make-link-string link desc))))) (defun org-store-link-props (&rest plist) "Store link properties, extract names and addresses." (let (x adr) (when (setq x (plist-get plist :from)) (setq adr (mail-extract-address-components x)) (setq plist (plist-put plist :fromname (car adr))) (setq plist (plist-put plist :fromaddress (nth 1 adr)))) (when (setq x (plist-get plist :to)) (setq adr (mail-extract-address-components x)) (setq plist (plist-put plist :toname (car adr))) (setq plist (plist-put plist :toaddress (nth 1 adr))))) (let ((from (plist-get plist :from)) (to (plist-get plist :to))) (when (and from to org-from-is-user-regexp) (setq plist (plist-put plist :fromto (if (string-match org-from-is-user-regexp from) (concat "to %t") (concat "from %f")))))) (setq org-store-link-plist plist)) (defun org-add-link-props (&rest plist) "Add these properties to the link property list." (let (key value) (while plist (setq key (pop plist) value (pop plist)) (setq org-store-link-plist (plist-put org-store-link-plist key value))))) (defun org-email-link-description (&optional fmt) "Return the description part of an email link. This takes information from `org-store-link-plist' and formats it according to FMT (default from `org-email-link-description-format')." (setq fmt (or fmt org-email-link-description-format)) (let* ((p org-store-link-plist) (to (plist-get p :toaddress)) (from (plist-get p :fromaddress)) (table (list (cons "%c" (plist-get p :fromto)) (cons "%F" (plist-get p :from)) (cons "%f" (or (plist-get p :fromname) (plist-get p :fromaddress) "?")) (cons "%T" (plist-get p :to)) (cons "%t" (or (plist-get p :toname) (plist-get p :toaddress) "?")) (cons "%s" (plist-get p :subject)) (cons "%m" (plist-get p :message-id))))) (when (string-match "%c" fmt) ;; Check if the user wrote this message (if (and org-from-is-user-regexp from to (save-match-data (string-match org-from-is-user-regexp from))) (setq fmt (replace-match "to %t" t t fmt)) (setq fmt (replace-match "from %f" t t fmt)))) (org-replace-escapes fmt table))) (defun org-make-org-heading-search-string (&optional string heading) "Make search string for STRING or current headline." (interactive) (let ((s (or string (org-get-heading)))) (unless (and string (not heading)) ;; We are using a headline, clean up garbage in there. (if (string-match org-todo-regexp s) (setq s (replace-match "" t t s))) (if (string-match (org-re ":[[:alnum:]_@:]+:[ \t]*$") s) (setq s (replace-match "" t t s))) (setq s (org-trim s)) (if (string-match (concat "^\\(" org-quote-string "\\|" org-comment-string "\\)") s) (setq s (replace-match "" t t s))) (while (string-match org-ts-regexp s) (setq s (replace-match "" t t s)))) (while (string-match "[^a-zA-Z_0-9 \t]+" s) (setq s (replace-match " " t t s))) (or string (setq s (concat "*" s))) ; Add * for headlines (mapconcat 'identity (org-split-string s "[ \t]+") " "))) (defun org-make-link (&rest strings) "Concatenate STRINGS." (apply 'concat strings)) (defun org-make-link-string (link &optional description) "Make a link with brackets, consisting of LINK and DESCRIPTION." (unless (string-match "\\S-" link) (error "Empty link")) (when (stringp description) ;; Remove brackets from the description, they are fatal. (while (string-match "\\[" description) (setq description (replace-match "{" t t description))) (while (string-match "\\]" description) (setq description (replace-match "}" t t description)))) (when (equal (org-link-escape link) description) ;; No description needed, it is identical (setq description nil)) (when (and (not description) (not (equal link (org-link-escape link)))) (setq description (org-extract-attributes link))) (concat "[[" (org-link-escape link) "]" (if description (concat "[" description "]") "") "]")) (defconst org-link-escape-chars '((?\ . "%20") (?\[ . "%5B") (?\] . "%5D") (?\340 . "%E0") ; `a (?\342 . "%E2") ; ^a (?\347 . "%E7") ; ,c (?\350 . "%E8") ; `e (?\351 . "%E9") ; 'e (?\352 . "%EA") ; ^e (?\356 . "%EE") ; ^i (?\364 . "%F4") ; ^o (?\371 . "%F9") ; `u (?\373 . "%FB") ; ^u (?\; . "%3B") (?? . "%3F") (?= . "%3D") (?+ . "%2B") ) "Association list of escapes for some characters problematic in links. This is the list that is used for internal purposes.") (defconst org-link-escape-chars-browser '((?\ . "%20")) ; 32 for the SPC char "Association list of escapes for some characters problematic in links. This is the list that is used before handing over to the browser.") (defun org-link-escape (text &optional table) "Escape charaters in TEXT that are problematic for links." (setq table (or table org-link-escape-chars)) (when text (let ((re (mapconcat (lambda (x) (regexp-quote (char-to-string (car x)))) table "\\|"))) (while (string-match re text) (setq text (replace-match (cdr (assoc (string-to-char (match-string 0 text)) table)) t t text))) text))) (defun org-link-unescape (text &optional table) "Reverse the action of `org-link-escape'." (setq table (or table org-link-escape-chars)) (when text (let ((re (mapconcat (lambda (x) (regexp-quote (cdr x))) table "\\|"))) (while (string-match re text) (setq text (replace-match (char-to-string (car (rassoc (match-string 0 text) table))) t t text))) text))) (defun org-xor (a b) "Exclusive or." (if a (not b) b)) (defun org-get-header (header) "Find a header field in the current buffer." (save-excursion (goto-char (point-min)) (let ((case-fold-search t) s) (cond ((eq header 'from) (if (re-search-forward "^From:\\s-+\\(.*\\)" nil t) (setq s (match-string 1))) (while (string-match "\"" s) (setq s (replace-match "" t t s))) (if (string-match "[<(].*" s) (setq s (replace-match "" t t s)))) ((eq header 'message-id) (if (re-search-forward "^message-id:\\s-+\\(.*\\)" nil t) (setq s (match-string 1)))) ((eq header 'subject) (if (re-search-forward "^subject:\\s-+\\(.*\\)" nil t) (setq s (match-string 1))))) (if (string-match "\\`[ \t\]+" s) (setq s (replace-match "" t t s))) (if (string-match "[ \t\]+\\'" s) (setq s (replace-match "" t t s))) s))) (defun org-fixup-message-id-for-http (s) "Replace special characters in a message id, so it can be used in an http query." (while (string-match "<" s) (setq s (replace-match "%3C" t t s))) (while (string-match ">" s) (setq s (replace-match "%3E" t t s))) (while (string-match "@" s) (setq s (replace-match "%40" t t s))) s) ;;;###autoload (defun org-insert-link-global () "Insert a link like Org-mode does. This command can be called in any mode to insert a link in Org-mode syntax." (interactive) (org-load-modules-maybe) (org-run-like-in-org-mode 'org-insert-link)) (defun org-insert-link (&optional complete-file link-location) "Insert a link. At the prompt, enter the link. Completion can be used to select a link previously stored with `org-store-link'. When the empty string is entered (i.e. if you just press RET at the prompt), the link defaults to the most recently stored link. As SPC triggers completion in the minibuffer, you need to use M-SPC or C-q SPC to force the insertion of a space character. You will also be prompted for a description, and if one is given, it will be displayed in the buffer instead of the link. If there is already a link at point, this command will allow you to edit link and description parts. With a \\[universal-argument] prefix, prompts for a file to link to. The file name can be selected using completion. The path to the file will be relative to the current directory if the file is in the current directory or a subdirectory. Otherwise, the link will be the absolute path as completed in the minibuffer \(i.e. normally ~/path/to/file). With two \\[universal-argument] prefixes, enforce an absolute path even if the file is in the current directory or below. With three \\[universal-argument] prefixes, negate the meaning of `org-keep-stored-link-after-insertion'. If `org-make-link-description-function' is non-nil, this function will be called with the link target, and the result will be the default link description. If the LINK-LOCATION parameter is non-nil, this value will be used as the link location instead of reading one interactively." (interactive "P") (let* ((wcf (current-window-configuration)) (region (if (org-region-active-p) (buffer-substring (region-beginning) (region-end)))) (remove (and region (list (region-beginning) (region-end)))) (desc region) tmphist ; byte-compile incorrectly complains about this (link link-location) entry file) (cond (link-location) ; specified by arg, just use it. ((org-in-regexp org-bracket-link-regexp 1) ;; We do have a link at point, and we are going to edit it. (setq remove (list (match-beginning 0) (match-end 0))) (setq desc (if (match-end 3) (org-match-string-no-properties 3))) (setq link (read-string "Link: " (org-link-unescape (org-match-string-no-properties 1))))) ((or (org-in-regexp org-angle-link-re) (org-in-regexp org-plain-link-re)) ;; Convert to bracket link (setq remove (list (match-beginning 0) (match-end 0)) link (read-string "Link: " (org-remove-angle-brackets (match-string 0))))) ((equal complete-file '(4)) ;; Completing read for file names. (setq file (read-file-name "File: ")) (let ((pwd (file-name-as-directory (expand-file-name "."))) (pwd1 (file-name-as-directory (abbreviate-file-name (expand-file-name "."))))) (cond ((equal complete-file '(16)) (setq link (org-make-link "file:" (abbreviate-file-name (expand-file-name file))))) ((string-match (concat "^" (regexp-quote pwd1) "\\(.+\\)") file) (setq link (org-make-link "file:" (match-string 1 file)))) ((string-match (concat "^" (regexp-quote pwd) "\\(.+\\)") (expand-file-name file)) (setq link (org-make-link "file:" (match-string 1 (expand-file-name file))))) (t (setq link (org-make-link "file:" file)))))) (t ;; Read link, with completion for stored links. (with-output-to-temp-buffer "*Org Links*" (princ "Insert a link. Use TAB to complete valid link prefixes.\n") (when org-stored-links (princ "\nStored links are available with / or M-p/n (most recent with RET):\n\n") (princ (mapconcat (lambda (x) (if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x))) (reverse org-stored-links) "\n")))) (let ((cw (selected-window))) (select-window (get-buffer-window "*Org Links*")) (org-fit-window-to-buffer) (setq truncate-lines t) (select-window cw)) ;; Fake a link history, containing the stored links. (setq tmphist (append (mapcar 'car org-stored-links) org-insert-link-history)) (unwind-protect (setq link (org-completing-read "Link: " (append (mapcar (lambda (x) (list (concat (car x) ":"))) (append org-link-abbrev-alist-local org-link-abbrev-alist)) (mapcar (lambda (x) (list (concat x ":"))) org-link-types)) nil nil nil 'tmphist (or (car (car org-stored-links))))) (set-window-configuration wcf) (kill-buffer "*Org Links*")) (setq entry (assoc link org-stored-links)) (or entry (push link org-insert-link-history)) (if (funcall (if (equal complete-file '(64)) 'not 'identity) (not org-keep-stored-link-after-insertion)) (setq org-stored-links (delq (assoc link org-stored-links) org-stored-links))) (setq desc (or desc (nth 1 entry))))) (if (string-match org-plain-link-re link) ;; URL-like link, normalize the use of angular brackets. (setq link (org-make-link (org-remove-angle-brackets link)))) ;; Check if we are linking to the current file with a search option ;; If yes, simplify the link by using only the search option. (when (and buffer-file-name (string-match "\\]+\\)" link)) (let* ((path (match-string 1 link)) (case-fold-search nil) (search (match-string 2 link))) (save-match-data (if (equal (file-truename buffer-file-name) (file-truename path)) ;; We are linking to this same file, with a search option (setq link search))))) ;; Check if we can/should use a relative path. If yes, simplify the link (when (string-match "\\