comparison lisp/org/org.el @ 100448:cea079b68b76

2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-refile): Avoid refiling to within the region to be refiled. * org-export-latex.el (org-export-latex-special-chars): Replace special characters also in tables. * org-agenda.el (org-agenda-change-all-lines): New argument FORCE-TAGS. (org-agenda-set-tags): Cet the new tags and pas them to `org-format-agenda-item'. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-export-latex.el (org-export-latex-classes): Add longable as a default package to all classes. (org-export-latex-tables): Handle the longtable attribute and the align attribute. * org-table.el (orgtbl-to-generic): Handle tables that start with a hline. * org-export-latex.el (org-export-latex-emphasis-alist): Switch to \verb for colde-like snippets. (org-export-as-latex): Fix issues with region export. * org.el (org-up-heading-safe): Speed up function by using a direct regexp search. (org-olpa): New variable. (org-get-outline-path): Speed-up path constructions in cases where this is possible because the entire hierarchy is scanned anyway. (org-refile-get-location): Don't compare the truenames of files, this is too slow. (org-goto-max-level): New option. (org-goto): Use `org-goto-max-level'. 2008-12-16 Tassilo Horn <tassilo@member.fsf.org> * org-gnus.el (org-gnus-article-link, org-gnus-article-link): Strip angle brackets from message-ids in the former and don't do it in the latter. (org-gnus-follow-link): Open summary reliable, even if the last messages were deleted, and handle empty groups, too. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-export-latex.el (org-export-latex-emphasis-alist): Use \verb instead of \texttt for the =...= and ~===~ emphasis environments. (org-export-as-latex): Remove any old :org-license-to-kill text properties. (org-export-as-latex): Pass RBEG to `org-export-latex-first-lines'. (org-export-latex-make-header): Add some hard space after the table of contents. (org-export-latex-first-lines): Accept RBEG argument. Mark exported text so that it will be excuded in further steps. * org-table.el (org-table-get-specials): Make @0 reference the last line in a table. (org-table-recalculate): Improve docstring. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-log-done): Fix docstring. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-html-format-image): Fix bugs. * org-export-latex.el (org-export-latex-tables) (org-export-latex-links): Implement attribute, label, and caption handling. * org-exp.el (org-export-html-style-default): Add style definitions for the figure div. (org-export-preprocess-string, org-export-as-html): Implement attribute, label, and caption handling. (org-export-attach-captions-and-attributes): New function. (org-export-html-format-image): New function. (org-format-org-table-html): Implement attribute, label, and caption handling. * org.el (org-find-text-property-in-string): New function. (org-extract-attributes): Use the property org-attr instead of org-attrobutes, because this property is now set with the #+ATTR lines. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-compat.el (org-substring-no-properties): Fix for XEmacs, for the case that FROM is nil. * org.el (org-before-first-heading-p): New function. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-as-html): Do not add a space before enforces line breaks. (org-export-as-html): Close paragraph before blockquote and verse tags. 2008-12-16 Carsten Dominik <carsten.dominik@gmail.com> * org-id.el (org-id-locations-file): Wrap file name with `convert-standard-filename'. (org-id-files): New variable. (org-id-use-hash): New option. (org-id-update-id-locations): Also search in all files current listed in `org-id-files'. Convert the resulting alist to a hash if the user customation says so. (org-id-locations-save): Handle he case if `org-id-locations' is a hash. (org-id-locations-load): Convert the alist to a hash. (org-id-add-location): Handle the hast case. (kill-emacs-hook): Make sure id locations are saved when Emacs is exited. (org-id-hash-to-alist, org-id-alist-to-hash) (org-id-paste-tracker): New functions.
author Carsten Dominik <dominik@science.uva.nl>
date Tue, 16 Dec 2008 13:28:37 +0000
parents 032aa24b2125
children ba23e35d3eaf
comparison
equal deleted inserted replaced
100447:f84c0729a0e9 100448:cea079b68b76
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Carsten Dominik <carsten at orgmode dot org> 5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp 6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org 7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.14 8 ;; Version: 6.15a
9 ;; 9 ;;
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 ;; 11 ;;
12 ;; GNU Emacs is free software: you can redistribute it and/or modify 12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by 13 ;; it under the terms of the GNU General Public License as published by
90 90
91 ;;;; Customization variables 91 ;;;; Customization variables
92 92
93 ;;; Version 93 ;;; Version
94 94
95 (defconst org-version "6.14" 95 (defconst org-version "6.15a"
96 "The version number of the file org.el.") 96 "The version number of the file org.el.")
97 97
98 (defun org-version (&optional here) 98 (defun org-version (&optional here)
99 "Show the org-mode version in the echo area. 99 "Show the org-mode version in the echo area.
100 With prefix arg HERE, insert it at point." 100 With prefix arg HERE, insert it at point."
160 :type 160 :type
161 '(set :greedy t 161 '(set :greedy t
162 (const :tag " bbdb: Links to BBDB entries" org-bbdb) 162 (const :tag " bbdb: Links to BBDB entries" org-bbdb)
163 (const :tag " bibtex: Links to BibTeX entries" org-bibtex) 163 (const :tag " bibtex: Links to BibTeX entries" org-bibtex)
164 (const :tag " gnus: Links to GNUS folders/messages" org-gnus) 164 (const :tag " gnus: Links to GNUS folders/messages" org-gnus)
165 (const :tag " id: Global id's for identifying entries" org-id) 165 (const :tag " id: Global IDs for identifying entries" org-id)
166 (const :tag " info: Links to Info nodes" org-info) 166 (const :tag " info: Links to Info nodes" org-info)
167 (const :tag " jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo) 167 (const :tag " jsinfo: Set up Sebastian Rose's JavaScript org-info.js" org-jsinfo)
168 (const :tag " irc: Links to IRC/ERC chat sessions" org-irc) 168 (const :tag " irc: Links to IRC/ERC chat sessions" org-irc)
169 (const :tag " mac-message: Links to messages in Apple Mail" org-mac-message) 169 (const :tag " mac-message: Links to messages in Apple Mail" org-mac-message)
170 (const :tag " mew Links to Mew folders/messages" org-mew) 170 (const :tag " mew Links to Mew folders/messages" org-mew)
176 (const :tag " mouse: Additional mouse support" org-mouse) 176 (const :tag " mouse: Additional mouse support" org-mouse)
177 177
178 (const :tag "C annotate-file: Annotate a file with org syntax" org-annotate-file) 178 (const :tag "C annotate-file: Annotate a file with org syntax" org-annotate-file)
179 (const :tag "C annotation-helper: Call Remeber directly from Browser" org-annotation-helper) 179 (const :tag "C annotation-helper: Call Remeber directly from Browser" org-annotation-helper)
180 (const :tag "C bookmark: Org links to bookmarks" org-bookmark) 180 (const :tag "C bookmark: Org links to bookmarks" org-bookmark)
181 (const :tag "C browser-url: Store link, directly from Browser" org-browser-url)
181 (const :tag "C depend: TODO dependencies for Org-mode" org-depend) 182 (const :tag "C depend: TODO dependencies for Org-mode" org-depend)
182 (const :tag "C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol) 183 (const :tag "C elisp-symbol: Org links to emacs-lisp symbols" org-elisp-symbol)
183 (const :tag "C eval: Include command output as text" org-eval) 184 (const :tag "C eval: Include command output as text" org-eval)
184 (const :tag "C eval-light: Evaluate inbuffer-code on demand" org-eval-light) 185 (const :tag "C eval-light: Evaluate inbuffer-code on demand" org-eval-light)
185 (const :tag "C expiry: Expiry mechanism for Org entries" org-expiry) 186 (const :tag "C expiry: Expiry mechanism for Org entries" org-expiry)
186 (const :tag "C exp-blocks: Pre-process blocks for export" org-exp-blocks) 187 (const :tag "C exp-blocks: Pre-process blocks for export" org-exp-blocks)
187 (const :tag "C id: Global id's for identifying entries" org-id)
188 (const :tag "C interactive-query: Interactive modification of tags query" org-interactive-query) 188 (const :tag "C interactive-query: Interactive modification of tags query" org-interactive-query)
189 (const :tag "C mairix: Hook mairix search into Org for different MUAs" org-mairix) 189 (const :tag "C mairix: Hook mairix search into Org for different MUAs" org-mairix)
190 (const :tag "C man: Support for links to manpages in Org-mode" org-man) 190 (const :tag "C man: Support for links to manpages in Org-mode" org-man)
191 (const :tag "C mtags: Support for muse-like tags" org-mtags) 191 (const :tag "C mtags: Support for muse-like tags" org-mtags)
192 (const :tag "C panel: Simple routines for us with bad memory" org-panel) 192 (const :tag "C panel: Simple routines for us with bad memory" org-panel)
953 (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2))) 953 (if (and r1 r2) (concat r1 "\\|" r2) (or r1 r2)))
954 "Regexp mached against the \"From:\" header of an email or usenet message. 954 "Regexp mached against the \"From:\" header of an email or usenet message.
955 It should match if the message is from the user him/herself." 955 It should match if the message is from the user him/herself."
956 :group 'org-link-store 956 :group 'org-link-store
957 :type 'regexp) 957 :type 'regexp)
958
959 (defcustom org-link-to-org-use-id 'create-if-interactive
960 "Non-nil means, storing a link to an Org file will use entry IDs.
961
962 Note that before this variable is even considered, org-id must be loaded,
963 to please customize `org-modules' and turn it on.
964
965 The variable can have the following values:
966
967 t Create an ID if needed to make a link to the current entry.
968
969 create-if-interactive
970 If `org-store-link' is called directly (interactively, as a user
971 command), do create an ID to support the link. But when doing the
972 job for remember, only use the ID if it already exists. The
973 purpose of this setting is to avoid proliferation of unwanted
974 IDs, just because you happen to be in an Org file when you
975 call `org-remember' that automatically and preemptively
976 creates a link. If you do want to get an ID link in a remember
977 template to an entry not having an ID, create it first by
978 explicitly creating a link to it, using `C-c C-l' first.
979
980 use-existing
981 Use existing ID, do not create one.
982
983 nil Never use an ID to make a link, instead link using a text search for
984 the headline text."
985 :group 'org-link-store
986 :type '(choice
987 (const :tag "Create ID to make link" t)
988 (const :tag "Create if string link interactively"
989 'create-if-interactive)
990 (const :tag "Only use existing" 'use-existing)
991 (const :tag "Do not use ID to create link" nil)))
958 992
959 (defcustom org-context-in-file-links t 993 (defcustom org-context-in-file-links t
960 "Non-nil means, file links from `org-store-link' contain context. 994 "Non-nil means, file links from `org-store-link' contain context.
961 A search string will be added to the file name with :: as separator and 995 A search string will be added to the file name with :: as separator and
962 used to find the context when the link is activated by the command 996 used to find the context when the link is activated by the command
1281 :group 'org-refile 1315 :group 'org-refile
1282 :type '(choice 1316 :type '(choice
1283 (const :tag "Outline" outline) 1317 (const :tag "Outline" outline)
1284 (const :tag "Outline-path-completion" outline-path-completion))) 1318 (const :tag "Outline-path-completion" outline-path-completion)))
1285 1319
1320 (defcustom org-goto-max-level 5
1321 "Maximum level to be considered when running org-goto with refile interface."
1322 :group 'org-refile
1323 :type 'number)
1324
1286 (defcustom org-reverse-note-order nil 1325 (defcustom org-reverse-note-order nil
1287 "Non-nil means, store new notes at the beginning of a file or entry. 1326 "Non-nil means, store new notes at the beginning of a file or entry.
1288 When nil, new notes will be filed to the end of a file or entry. 1327 When nil, new notes will be filed to the end of a file or entry.
1289 This can also be a list with cons cells of regular expressions that 1328 This can also be a list with cons cells of regular expressions that
1290 are matched against file names, and values." 1329 are matched against file names, and values."
1513 (cons :tag "Tag action" 1552 (cons :tag "Tag action"
1514 (string :tag "Tag") 1553 (string :tag "Tag")
1515 (choice (const :tag "Add" t) (const :tag "Remove" nil))))))) 1554 (choice (const :tag "Add" t) (const :tag "Remove" nil)))))))
1516 1555
1517 (defcustom org-log-done nil 1556 (defcustom org-log-done nil
1518 "Non-nil means, record a CLOSED timestamp when moving an entry to DONE. 1557 "Information to record when a task moves to the DONE state.
1519 When equal to the list (done), also prompt for a closing note. 1558
1520 This can also be configured on a per-file basis by adding one of 1559 Possible values are:
1521 the following lines anywhere in the buffer: 1560
1522 1561 nil Don't add anything, just change the keyword
1562 time Add a time stamp to the task
1563 note Prompt a closing note and add it with template `org-log-note-headings'
1564
1565 This option can also be set with on a per-file-basis with
1566
1567 #+STARTUP: nologdone
1523 #+STARTUP: logdone 1568 #+STARTUP: logdone
1524 #+STARTUP: lognotedone 1569 #+STARTUP: lognotedone
1525 #+STARTUP: nologdone" 1570
1571 You can have local logging settings for a subtree by setting the LOGGING
1572 property to one or more of these keywords."
1526 :group 'org-todo 1573 :group 'org-todo
1527 :group 'org-progress 1574 :group 'org-progress
1528 :type '(choice 1575 :type '(choice
1529 (const :tag "No logging" nil) 1576 (const :tag "No logging" nil)
1530 (const :tag "Record CLOSED timestamp" time) 1577 (const :tag "Record CLOSED timestamp" time)
2804 org-columns-compute org-agenda-columns org-columns-remove-overlays 2851 org-columns-compute org-agenda-columns org-columns-remove-overlays
2805 org-columns org-insert-columns-dblock org-dblock-write:columnview)) 2852 org-columns org-insert-columns-dblock org-dblock-write:columnview))
2806 2853
2807 ;; Autoload ID code 2854 ;; Autoload ID code
2808 2855
2856 (declare-function org-id-store-link "org-id")
2809 (org-autoload "org-id" 2857 (org-autoload "org-id"
2810 '(org-id-get-create org-id-new org-id-copy org-id-get 2858 '(org-id-get-create org-id-new org-id-copy org-id-get
2811 org-id-get-with-outline-path-completion 2859 org-id-get-with-outline-path-completion
2812 org-id-get-with-outline-drilling 2860 org-id-get-with-outline-drilling
2813 org-id-goto org-id-find)) 2861 org-id-goto org-id-find org-id-store-link))
2814 2862
2815 ;;; Variables for pre-computed regular expressions, all buffer local 2863 ;;; Variables for pre-computed regular expressions, all buffer local
2816 2864
2817 (defvar org-drawer-regexp nil 2865 (defvar org-drawer-regexp nil
2818 "Matches first line of a hidden block.") 2866 "Matches first line of a hidden block.")
4502 When pressing RET or `Q', the command returns to the original buffer in 4550 When pressing RET or `Q', the command returns to the original buffer in
4503 which the visibility is still unchanged. After RET is will also jump to 4551 which the visibility is still unchanged. After RET is will also jump to
4504 the location selected in the indirect buffer and expose the 4552 the location selected in the indirect buffer and expose the
4505 the headline hierarchy above." 4553 the headline hierarchy above."
4506 (interactive "P") 4554 (interactive "P")
4507 (let* ((org-refile-targets '((nil . (:maxlevel . 10)))) 4555 (let* ((org-refile-targets `((nil . (:maxlevel . ,org-goto-max-level))))
4508 (org-refile-use-outline-path t) 4556 (org-refile-use-outline-path t)
4509 (interface 4557 (interface
4510 (if (not alternative-interface) 4558 (if (not alternative-interface)
4511 org-goto-interface 4559 org-goto-interface
4512 (if (eq org-goto-interface 'outline) 4560 (if (eq org-goto-interface 'outline)
5266 (delete-region (point-at-bol) (point))) 5314 (delete-region (point-at-bol) (point)))
5267 ;; Paste 5315 ;; Paste
5268 (beginning-of-line 1) 5316 (beginning-of-line 1)
5269 (unless for-yank (org-back-over-empty-lines)) 5317 (unless for-yank (org-back-over-empty-lines))
5270 (setq beg (point)) 5318 (setq beg (point))
5319 (and (fboundp 'org-id-paste-tracker) (org-id-paste-tracker txt))
5271 (insert-before-markers txt) 5320 (insert-before-markers txt)
5272 (unless (string-match "\n\\'" txt) (insert "\n")) 5321 (unless (string-match "\n\\'" txt) (insert "\n"))
5273 (setq newend (point)) 5322 (setq newend (point))
5274 (org-reinstall-markers-in-region beg) 5323 (org-reinstall-markers-in-region beg)
5275 (setq end (point)) 5324 (setq end (point))
6139 (org-make-link-regexps) 6188 (org-make-link-regexps)
6140 (if (assoc type org-link-protocols) 6189 (if (assoc type org-link-protocols)
6141 (setcdr (assoc type org-link-protocols) (list follow export)) 6190 (setcdr (assoc type org-link-protocols) (list follow export))
6142 (push (list type follow export) org-link-protocols))) 6191 (push (list type follow export) org-link-protocols)))
6143 6192
6144
6145 ;;;###autoload 6193 ;;;###autoload
6146 (defun org-store-link (arg) 6194 (defun org-store-link (arg)
6147 "\\<org-mode-map>Store an org-link to the current location. 6195 "\\<org-mode-map>Store an org-link to the current location.
6148 This link is added to `org-stored-links' and can later be inserted 6196 This link is added to `org-stored-links' and can later be inserted
6149 into an org-buffer with \\[org-insert-link]. 6197 into an org-buffer with \\[org-insert-link].
6200 (expand-file-name 6248 (expand-file-name
6201 (dired-get-filename nil t)))) 6249 (dired-get-filename nil t))))
6202 link (org-make-link cpltxt))) 6250 link (org-make-link cpltxt)))
6203 6251
6204 ((and buffer-file-name (org-mode-p)) 6252 ((and buffer-file-name (org-mode-p))
6205 ;; Just link to current headline 6253 (cond
6206 (setq cpltxt (concat "file:" 6254 ((org-in-regexp "<<\\(.*?\\)>>")
6207 (abbreviate-file-name buffer-file-name))) 6255 (setq cpltxt
6208 ;; Add a context search string 6256 (concat "file:"
6209 (when (org-xor org-context-in-file-links arg) 6257 (abbreviate-file-name buffer-file-name)
6210 ;; Check if we are on a target 6258 "::" (match-string 1))
6211 (if (org-in-regexp "<<\\(.*?\\)>>") 6259 link (org-make-link cpltxt)))
6212 (setq cpltxt (concat cpltxt "::" (match-string 1))) 6260 ((and (featurep 'org-id)
6261 (or (eq org-link-to-org-use-id t)
6262 (and (eq org-link-to-org-use-id 'create-if-interactive)
6263 (interactive-p))
6264 (and org-link-to-org-use-id
6265 (condition-case nil
6266 (org-entry-get nil "ID")
6267 (error nil)))))
6268 ;; We can make a link using the ID.
6269 (setq link (condition-case nil
6270 (org-id-store-link)
6271 (error
6272 ;; probably before first headling, link to file only
6273 (concat "file:"
6274 (abbreviate-file-name buffer-file-name))))))
6275 (t
6276 ;; Just link to current headline
6277 (setq cpltxt (concat "file:"
6278 (abbreviate-file-name buffer-file-name)))
6279 ;; Add a context search string
6280 (when (org-xor org-context-in-file-links arg)
6213 (setq txt (cond 6281 (setq txt (cond
6214 ((org-on-heading-p) nil) 6282 ((org-on-heading-p) nil)
6215 ((org-region-active-p) 6283 ((org-region-active-p)
6216 (buffer-substring (region-beginning) (region-end))) 6284 (buffer-substring (region-beginning) (region-end)))
6217 (t nil))) 6285 (t nil)))
6219 (setq cpltxt 6287 (setq cpltxt
6220 (concat cpltxt "::" 6288 (concat cpltxt "::"
6221 (condition-case nil 6289 (condition-case nil
6222 (org-make-org-heading-search-string txt) 6290 (org-make-org-heading-search-string txt)
6223 (error ""))) 6291 (error "")))
6224 desc "NONE")))) 6292 desc "NONE")))
6225 (if (string-match "::\\'" cpltxt) 6293 (if (string-match "::\\'" cpltxt)
6226 (setq cpltxt (substring cpltxt 0 -2))) 6294 (setq cpltxt (substring cpltxt 0 -2)))
6227 (setq link (org-make-link cpltxt))) 6295 (setq link (org-make-link cpltxt)))))
6228 6296
6229 ((buffer-file-name (buffer-base-buffer)) 6297 ((buffer-file-name (buffer-base-buffer))
6230 ;; Just link to this file here. 6298 ;; Just link to this file here.
6231 (setq cpltxt (concat "file:" 6299 (setq cpltxt (concat "file:"
6232 (abbreviate-file-name 6300 (abbreviate-file-name
6653 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0))) 6721 (setq a (match-string 1 s) s (substring s 0 (match-beginning 0)))
6654 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start) 6722 (while (string-match "\\([a-zA-Z]+\\)=\"\\([^\"]*\\)\"" a start)
6655 (setq key (match-string 1 a) value (match-string 2 a) 6723 (setq key (match-string 1 a) value (match-string 2 a)
6656 start (match-end 0) 6724 start (match-end 0)
6657 attr (plist-put attr (intern key) value)))) 6725 attr (plist-put attr (intern key) value))))
6658 (org-add-props s nil 'org-attributes attr)) 6726 (org-add-props s nil 'org-attr attr))
6659 s)) 6727 s))
6660 6728
6661 (defun org-attributes-to-string (plist) 6729 (defun org-attributes-to-string (plist)
6662 "Format a property list into an HTML attribute list." 6730 "Format a property list into an HTML attribute list."
6663 (let ((s "") key value) 6731 (let ((s "") key value)
6664 (while plist 6732 (while plist
6665 (setq key (pop plist) value (pop plist)) 6733 (setq key (pop plist) value (pop plist))
6666 (setq s (concat s " "(symbol-name key) "=\"" value "\""))) 6734 (and value
6735 (setq s (concat s " " (symbol-name key) "=\"" value "\""))))
6667 s)) 6736 s))
6668 6737
6669 ;;; Opening/following a link 6738 ;;; Opening/following a link
6670 6739
6671 (defvar org-link-search-failed nil) 6740 (defvar org-link-search-failed nil)
7390 "Buffers created to visit agenda files.") 7459 "Buffers created to visit agenda files.")
7391 7460
7392 (defun org-get-refile-targets (&optional default-buffer) 7461 (defun org-get-refile-targets (&optional default-buffer)
7393 "Produce a table with refile targets." 7462 "Produce a table with refile targets."
7394 (let ((entries (or org-refile-targets '((nil . (:level . 1))))) 7463 (let ((entries (or org-refile-targets '((nil . (:level . 1)))))
7395 targets txt re files f desc descre) 7464 targets txt re files f desc descre fast-path-p level)
7465 (message "Getting targets...")
7396 (with-current-buffer (or default-buffer (current-buffer)) 7466 (with-current-buffer (or default-buffer (current-buffer))
7397 (while (setq entry (pop entries)) 7467 (while (setq entry (pop entries))
7398 (setq files (car entry) desc (cdr entry)) 7468 (setq files (car entry) desc (cdr entry))
7469 (setq fast-path-p nil)
7399 (cond 7470 (cond
7400 ((null files) (setq files (list (current-buffer)))) 7471 ((null files) (setq files (list (current-buffer))))
7401 ((eq files 'org-agenda-files) 7472 ((eq files 'org-agenda-files)
7402 (setq files (org-agenda-files 'unrestricted))) 7473 (setq files (org-agenda-files 'unrestricted)))
7403 ((and (symbolp files) (fboundp files)) 7474 ((and (symbolp files) (fboundp files))
7417 (if org-odd-levels-only 7488 (if org-odd-levels-only
7418 (1- (* 2 (cdr desc))) 7489 (1- (* 2 (cdr desc)))
7419 (cdr desc))) 7490 (cdr desc)))
7420 "\\}[ \t]"))) 7491 "\\}[ \t]")))
7421 ((eq (car desc) :maxlevel) 7492 ((eq (car desc) :maxlevel)
7493 (setq fast-path-p t)
7422 (setq descre (concat "^\\*\\{1," (number-to-string 7494 (setq descre (concat "^\\*\\{1," (number-to-string
7423 (if org-odd-levels-only 7495 (if org-odd-levels-only
7424 (1- (* 2 (cdr desc))) 7496 (1- (* 2 (cdr desc)))
7425 (cdr desc))) 7497 (cdr desc)))
7426 "\\}[ \t]"))) 7498 "\\}[ \t]")))
7434 (widen) 7506 (widen)
7435 (goto-char (point-min)) 7507 (goto-char (point-min))
7436 (while (re-search-forward descre nil t) 7508 (while (re-search-forward descre nil t)
7437 (goto-char (point-at-bol)) 7509 (goto-char (point-at-bol))
7438 (when (looking-at org-complex-heading-regexp) 7510 (when (looking-at org-complex-heading-regexp)
7439 (setq txt (org-link-display-format (match-string 4)) 7511 (setq level (org-reduced-level (- (match-end 1) (match-beginning 1)))
7512 txt (org-link-display-format (match-string 4))
7440 re (concat "^" (regexp-quote 7513 re (concat "^" (regexp-quote
7441 (buffer-substring (match-beginning 1) 7514 (buffer-substring (match-beginning 1)
7442 (match-end 4))))) 7515 (match-end 4)))))
7443 (if (match-end 5) (setq re (concat re "[ \t]+" 7516 (if (match-end 5) (setq re (concat re "[ \t]+"
7444 (regexp-quote 7517 (regexp-quote
7450 (if (eq org-refile-use-outline-path 'file) 7523 (if (eq org-refile-use-outline-path 'file)
7451 (list (file-name-nondirectory 7524 (list (file-name-nondirectory
7452 (buffer-file-name (buffer-base-buffer)))) 7525 (buffer-file-name (buffer-base-buffer))))
7453 (if (eq org-refile-use-outline-path 'full-file-path) 7526 (if (eq org-refile-use-outline-path 'full-file-path)
7454 (list (buffer-file-name (buffer-base-buffer))))) 7527 (list (buffer-file-name (buffer-base-buffer)))))
7455 (org-get-outline-path) 7528 (org-get-outline-path fast-path-p level txt)
7456 (list txt)) 7529 (list txt))
7457 "/"))) 7530 "/")))
7458 (push (list txt f re (point)) targets)) 7531 (push (list txt f re (point)) targets))
7459 (goto-char (point-at-eol)))))))) 7532 (goto-char (point-at-eol))))))))
7460 (nreverse targets)))) 7533 (message "Getting targets...done")
7534 (nreverse targets))))
7461 7535
7462 (defun org-protect-slash (s) 7536 (defun org-protect-slash (s)
7463 (while (string-match "/" s) 7537 (while (string-match "/" s)
7464 (setq s (replace-match "\\" t t s))) 7538 (setq s (replace-match "\\" t t s)))
7465 s) 7539 s)
7466 7540
7467 (defun org-get-outline-path () 7541 (defvar org-olpa (make-vector 20 nil))
7542
7543 (defun org-get-outline-path (&optional fastp level heading)
7468 "Return the outline path to the current entry, as a list." 7544 "Return the outline path to the current entry, as a list."
7469 (let (rtn) 7545 (if (> level 19) (error "Outline path failure, more than 19 levels."))
7470 (save-excursion 7546 (if fastp
7471 (while (org-up-heading-safe) 7547 (progn
7472 (when (looking-at org-complex-heading-regexp) 7548 (loop for i from level upto 19 do
7473 (push (org-match-string-no-properties 4) rtn))) 7549 (aset org-olpa i nil))
7474 rtn))) 7550 (prog1
7551 (delq nil (append org-olpa nil))
7552 (aset org-olpa level heading)))
7553 (let (rtn)
7554 (save-excursion
7555 (while (org-up-heading-safe)
7556 (when (looking-at org-complex-heading-regexp)
7557 (push (org-match-string-no-properties 4) rtn)))
7558 rtn))))
7475 7559
7476 (defvar org-refile-history nil 7560 (defvar org-refile-history nil
7477 "History for refiling operations.") 7561 "History for refiling operations.")
7478 7562
7479 (defun org-refile (&optional goto default-buffer) 7563 (defun org-refile (&optional goto default-buffer)
7512 (when (setq it (org-refile-get-location 7596 (when (setq it (org-refile-get-location
7513 (if goto "Goto: " "Refile to: ") default-buffer)) 7597 (if goto "Goto: " "Refile to: ") default-buffer))
7514 (setq file (nth 1 it) 7598 (setq file (nth 1 it)
7515 re (nth 2 it) 7599 re (nth 2 it)
7516 pos (nth 3 it)) 7600 pos (nth 3 it))
7601 (if (and (equal (buffer-file-name) file)
7602 (if regionp
7603 (and (>= pos region-start)
7604 (<= pos region-end))
7605 (and (>= pos (point))
7606 (< pos (save-excursion
7607 (org-end-of-subtree t t))))))
7608 (error "Cannot refile to position inside the tree or region"))
7609
7517 (setq nbuf (or (find-buffer-visiting file) 7610 (setq nbuf (or (find-buffer-visiting file)
7518 (find-file-noselect file))) 7611 (find-file-noselect file)))
7519 (if goto 7612 (if goto
7520 (progn 7613 (progn
7521 (switch-to-buffer nbuf) 7614 (switch-to-buffer nbuf)
7569 org-outline-path-complete-in-steps) 7662 org-outline-path-complete-in-steps)
7570 'org-olpath-completing-read 7663 'org-olpath-completing-read
7571 'org-ido-completing-read)) 7664 'org-ido-completing-read))
7572 (extra (if org-refile-use-outline-path "/" "")) 7665 (extra (if org-refile-use-outline-path "/" ""))
7573 (filename (buffer-file-name (buffer-base-buffer cbuf))) 7666 (filename (buffer-file-name (buffer-base-buffer cbuf)))
7574 (fname (and filename (file-truename filename)))
7575 (tbl (mapcar 7667 (tbl (mapcar
7576 (lambda (x) 7668 (lambda (x)
7577 (if (not (equal fname (file-truename (nth 1 x)))) 7669 (if (not (equal filename (nth 1 x)))
7578 (cons (concat (car x) extra " (" 7670 (cons (concat (car x) extra " ("
7579 (file-name-nondirectory (nth 1 x)) ")") 7671 (file-name-nondirectory (nth 1 x)) ")")
7580 (cdr x)) 7672 (cdr x))
7581 (cons (concat (car x) extra) (cdr x)))) 7673 (cons (concat (car x) extra) (cdr x))))
7582 org-refile-target-table)) 7674 org-refile-target-table))
7738 '("BEGIN_HTML" "BEGIN_LaTeX" "END_HTML" "END_LaTeX" 7830 '("BEGIN_HTML" "BEGIN_LaTeX" "END_HTML" "END_LaTeX"
7739 "ORGTBL" "HTML:" "LaTeX:" "BEGIN:" "END:" "TBLFM" 7831 "ORGTBL" "HTML:" "LaTeX:" "BEGIN:" "END:" "TBLFM"
7740 "BEGIN_EXAMPLE" "END_EXAMPLE" 7832 "BEGIN_EXAMPLE" "END_EXAMPLE"
7741 "BEGIN_QUOTE" "END_QUOTE" 7833 "BEGIN_QUOTE" "END_QUOTE"
7742 "BEGIN_VERSE" "END_VERSE" 7834 "BEGIN_VERSE" "END_VERSE"
7743 "BEGIN_SRC" "END_SRC")) 7835 "BEGIN_SRC" "END_SRC"
7836 "CAPTION" "LABEL" "ATTR_HTML" "ATTR_LaTeX"))
7744 7837
7745 (defcustom org-structure-template-alist 7838 (defcustom org-structure-template-alist
7746 '( 7839 '(
7747 ("s" "#+begin_src ?\n\n#+end_src" 7840 ("s" "#+begin_src ?\n\n#+end_src"
7748 "<src lang=\"?\">\n\n</src>") 7841 "<src lang=\"?\">\n\n</src>")
9435 s) 9528 s)
9436 9529
9437 (defun org-toggle-tag (tag &optional onoff) 9530 (defun org-toggle-tag (tag &optional onoff)
9438 "Toggle the tag TAG for the current line. 9531 "Toggle the tag TAG for the current line.
9439 If ONOFF is `on' or `off', don't toggle but set to this state." 9532 If ONOFF is `on' or `off', don't toggle but set to this state."
9440 (unless (org-on-heading-p t) (error "Not on headling"))
9441 (let (res current) 9533 (let (res current)
9442 (save-excursion 9534 (save-excursion
9443 (beginning-of-line) 9535 (org-back-to-heading t)
9444 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$") 9536 (if (re-search-forward (org-re "[ \t]:\\([[:alnum:]_@:]+\\):[ \t]*$")
9445 (point-at-eol) t) 9537 (point-at-eol) t)
9446 (progn 9538 (progn
9447 (setq current (match-string 1)) 9539 (setq current (match-string 1))
9448 (replace-match "")) 9540 (replace-match ""))
10557 (defun org-find-entry-with-id (ident) 10649 (defun org-find-entry-with-id (ident)
10558 "Locate the entry that contains the ID property with exact value IDENT. 10650 "Locate the entry that contains the ID property with exact value IDENT.
10559 IDENT can be a string, a symbol or a number, this function will search for 10651 IDENT can be a string, a symbol or a number, this function will search for
10560 the string representation of it. 10652 the string representation of it.
10561 Return the position where this entry starts, or nil if there is no such entry." 10653 Return the position where this entry starts, or nil if there is no such entry."
10654 (interactive "sID: ")
10562 (let ((id (cond 10655 (let ((id (cond
10563 ((stringp ident) ident) 10656 ((stringp ident) ident)
10564 ((symbol-name ident) (symbol-name ident)) 10657 ((symbol-name ident) (symbol-name ident))
10565 ((numberp ident) (number-to-string ident)) 10658 ((numberp ident) (number-to-string ident))
10566 (t (error "IDENT %s must be a string, symbol or number" ident)))) 10659 (t (error "IDENT %s must be a string, symbol or number" ident))))
13410 13503
13411 ;;;; Miscellaneous stuff 13504 ;;;; Miscellaneous stuff
13412 13505
13413 ;;; Generally useful functions 13506 ;;; Generally useful functions
13414 13507
13508 (defun org-find-text-property-in-string (prop s)
13509 "Return the first non-nil value of property PROP in string S."
13510 (or (get-text-property 0 prop s)
13511 (get-text-property (or (next-single-property-change 0 prop s) 0)
13512 prop s)))
13513
13415 (defun org-display-warning (message) ;; Copied from Emacs-Muse 13514 (defun org-display-warning (message) ;; Copied from Emacs-Muse
13416 "Display the given MESSAGE as a warning." 13515 "Display the given MESSAGE as a warning."
13417 (if (fboundp 'display-warning) 13516 (if (fboundp 'display-warning)
13418 (display-warning 'org message 13517 (display-warning 'org message
13419 (if (featurep 'xemacs) 13518 (if (featurep 'xemacs)
14306 (condition-case nil 14405 (condition-case nil
14307 (outline-back-to-heading invisible-ok) 14406 (outline-back-to-heading invisible-ok)
14308 (error (error "Before first headline at position %d in buffer %s" 14407 (error (error "Before first headline at position %d in buffer %s"
14309 (point) (current-buffer))))) 14408 (point) (current-buffer)))))
14310 14409
14410 (defun org-before-first-heading-p ()
14411 "Before first heading?"
14412 (save-excursion
14413 (null (re-search-backward "^\\*+ " nil t))))
14414
14311 (defalias 'org-on-heading-p 'outline-on-heading-p) 14415 (defalias 'org-on-heading-p 'outline-on-heading-p)
14312 (defalias 'org-at-heading-p 'outline-on-heading-p) 14416 (defalias 'org-at-heading-p 'outline-on-heading-p)
14313 (defun org-at-heading-or-item-p () 14417 (defun org-at-heading-or-item-p ()
14314 (or (org-on-heading-p) (org-at-item-p))) 14418 (or (org-on-heading-p) (org-at-item-p)))
14315 14419
14327 14431
14328 (defun org-up-heading-safe () 14432 (defun org-up-heading-safe ()
14329 "Move to the heading line of which the present line is a subheading. 14433 "Move to the heading line of which the present line is a subheading.
14330 This version will not throw an error. It will return the level of the 14434 This version will not throw an error. It will return the level of the
14331 headline found, or nil if no higher level is found." 14435 headline found, or nil if no higher level is found."
14332 (let ((pos (point)) start-level level 14436 (let (start-level re)
14333 (re (concat "^" outline-regexp))) 14437 (org-back-to-heading t)
14334 (catch 'exit 14438 (setq start-level (funcall outline-level))
14335 (org-back-to-heading t) 14439 (if (equal start-level 1)
14336 (setq start-level (funcall outline-level)) 14440 nil
14337 (if (equal start-level 1) (throw 'exit nil)) 14441 (setq re (concat "^\\*\\{1," (number-to-string (1- start-level)) "\\} "))
14338 (while (re-search-backward re nil t) 14442 (if (re-search-backward re nil t)
14339 (setq level (funcall outline-level)) 14443 (funcall outline-level)))))
14340 (if (< level start-level) (throw 'exit level)))
14341 nil)))
14342 14444
14343 (defun org-first-sibling-p () 14445 (defun org-first-sibling-p ()
14344 "Is this heading the first child of its parents?" 14446 "Is this heading the first child of its parents?"
14345 (interactive) 14447 (interactive)
14346 (let ((re (concat "^" outline-regexp)) 14448 (let ((re (concat "^" outline-regexp))