comparison lisp/textmodes/org.el @ 69224:e80276821f75

(org-export-as-html): Fixed bugs in HTML formatting: No nested anchors. (org-all-targets): Fixed bug with XEmacs compatibility. (org-read-date): Add (require 'parse-time). (org-set-tags): Fixed bug with extra inserted space. (org-export-html-style): Define a style class for targets. (org-agenda-keymap, org-mouse-map): Added a binding for `follow-link'. (org-hide-leading-stars): New option. (org-hide): New face. (org-set-font-lock-defaults): Allow to hide leading stars. (org-get-legal-level, org-tr-level): New functions. (org-odd-levels-only): New option. (org-level-faces, org-paste-subtree, org-convert-to-odd-levels, org-demote, org-promote): Deal with double-star levels. (org-convert-to-odd-levels): New command.
author Carsten Dominik <dominik@science.uva.nl>
date Wed, 01 Mar 2006 07:07:01 +0000
parents 39ec690b89d6
children cdd3f2bbf2f8
comparison
equal deleted inserted replaced
69223:2a28f118a743 69224:e80276821f75
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. 3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Carsten Dominik <dominik at science dot uva dot nl> 5 ;; Author: Carsten Dominik <dominik at science dot uva dot nl>
6 ;; Keywords: outlines, hypermedia, calendar, wp 6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/ 7 ;; Homepage: http://www.astro.uva.nl/~dominik/Tools/org/
8 ;; Version: 4.06 8 ;; Version: 4.07
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
79 ;; excellent reference card made by Philip Rooke. This card can be found 79 ;; excellent reference card made by Philip Rooke. This card can be found
80 ;; in the etc/ directory of Emacs 22. 80 ;; in the etc/ directory of Emacs 22.
81 ;; 81 ;;
82 ;; Changes since version 4.00: 82 ;; Changes since version 4.00:
83 ;; --------------------------- 83 ;; ---------------------------
84 ;; Version 4.07
85 ;; - Bug fixes.
86 ;; - Leading stars in headlines can be hidden, so make the outline look
87 ;; cleaner.
88 ;; - Mouse-1 can be used to follow links.
89 ;;
84 ;; Version 4.06 90 ;; Version 4.06
85 ;; - HTML exporter treats targeted internal links. 91 ;; - HTML exporter treats targeted internal links.
86 ;; - Bug fixes. 92 ;; - Bug fixes.
87 ;; 93 ;;
88 ;; Version 4.05 94 ;; Version 4.05
128 (defvar calc-embedded-open-formula) 134 (defvar calc-embedded-open-formula)
129 (defvar font-lock-unfontify-region-function) 135 (defvar font-lock-unfontify-region-function)
130 136
131 ;;; Customization variables 137 ;;; Customization variables
132 138
133 (defvar org-version "4.06" 139 (defvar org-version "4.07"
134 "The version number of the file org.el.") 140 "The version number of the file org.el.")
135 (defun org-version () 141 (defun org-version ()
136 (interactive) 142 (interactive)
137 (message "Org-mode version %s" org-version)) 143 (message "Org-mode version %s" org-version))
138 144
792 When nil, the entire headline is fontified. 798 When nil, the entire headline is fontified.
793 Changing it requires restart of Emacs to become effective." 799 Changing it requires restart of Emacs to become effective."
794 :group 'org-structure 800 :group 'org-structure
795 :type 'boolean) 801 :type 'boolean)
796 802
803 (defcustom org-hide-leading-stars nil
804 "Non-nil means, hide the first N-1 stars in a headline.
805 This works by using the face `org-hide' for these stars. This
806 face is white for a light background, and black for a dark
807 background. You may have to customize the face `org-hide' to
808 make this work.
809 Changing the variable requires restart of Emacs to become effective."
810 :group 'org-structure
811 :type 'boolean)
812
813 (defcustom org-odd-levels-only nil
814 "Non-nil means, skip even levels and only use odd levels for the outline.
815 This has the effect that two stars are being added/taken away in
816 promotion/demotion commands. It also influences how levels are
817 handled by the exporters."
818 :group 'org-structure
819 :type 'boolean)
820
797 (defcustom org-adapt-indentation t 821 (defcustom org-adapt-indentation t
798 "Non-nil means, adapt indentation when promoting and demoting. 822 "Non-nil means, adapt indentation when promoting and demoting.
799 When this is set and the *entire* text in an entry is indented, the 823 When this is set and the *entire* text in an entry is indented, the
800 indentation is increased by one space in a demotion command, and 824 indentation is increased by one space in a demotion command, and
801 decreased by one in a promotion command. If any line in the entry 825 decreased by one in a promotion command. If any line in the entry
1407 font-size: 12pt; 1431 font-size: 12pt;
1408 } 1432 }
1409 .title { text-align: center; } 1433 .title { text-align: center; }
1410 .todo, .deadline { color: red; } 1434 .todo, .deadline { color: red; }
1411 .done { color: green; } 1435 .done { color: green; }
1436 .target { background-color: lavender; }
1412 pre { 1437 pre {
1413 border: 1pt solid #AEBDCC; 1438 border: 1pt solid #AEBDCC;
1414 background-color: #F3F5F7; 1439 background-color: #F3F5F7;
1415 padding: 5pt; 1440 padding: 5pt;
1416 font-family: courier, monospace; 1441 font-family: courier, monospace;
1631 :group 'org-export 1656 :group 'org-export
1632 :type 'boolean) 1657 :type 'boolean)
1633 1658
1634 (defcustom org-export-html-with-timestamp nil 1659 (defcustom org-export-html-with-timestamp nil
1635 "If non-nil, write `org-export-html-html-helper-timestamp' 1660 "If non-nil, write `org-export-html-html-helper-timestamp'
1636 into the exported html text. Otherwise, the buffer will just be saved 1661 into the exported HTML text. Otherwise, the buffer will just be saved
1637 to a file." 1662 to a file."
1638 :group 'org-export 1663 :group 'org-export
1639 :type 'boolean) 1664 :type 'boolean)
1640 1665
1641 (defcustom org-export-html-html-helper-timestamp 1666 (defcustom org-export-html-html-helper-timestamp
1649 Otherwise the buffer will just be saved to a file and stay hidden." 1674 Otherwise the buffer will just be saved to a file and stay hidden."
1650 :group 'org-export 1675 :group 'org-export
1651 :type 'boolean) 1676 :type 'boolean)
1652 1677
1653 (defcustom org-export-html-show-new-buffer nil 1678 (defcustom org-export-html-show-new-buffer nil
1654 "Non-nil means, popup buffer containing the exported HTML text. 1679 "Non-nil means, popup buffer containing the exported html text.
1655 Otherwise, the buffer will just be saved to a file and stay hidden." 1680 Otherwise, the buffer will just be saved to a file and stay hidden."
1656 :group 'org-export 1681 :group 'org-export
1657 :type 'boolean) 1682 :type 'boolean)
1658 1683
1659 (defcustom org-combined-agenda-icalendar-file "~/org.ics" 1684 (defcustom org-combined-agenda-icalendar-file "~/org.ics"
1674 1699
1675 (defgroup org-faces nil 1700 (defgroup org-faces nil
1676 "Faces for highlighting in Org-mode." 1701 "Faces for highlighting in Org-mode."
1677 :tag "Org Faces" 1702 :tag "Org Faces"
1678 :group 'org) 1703 :group 'org)
1704
1705 (defface org-hide
1706 '((((type tty) (class color)) (:foreground "blue" :weight bold))
1707 (((class color) (background light)) (:foreground "white"))
1708 (((class color) (background dark)) (:foreground "black"))
1709 ; (((class color) (background light)) (:foreground "grey90"))
1710 ; (((class color) (background dark)) (:foreground "grey10"))
1711 (t (:inverse-video nil)))
1712 "Face used for level 1 headlines."
1713 :group 'org-faces)
1679 1714
1680 (defface org-level-1 ;; font-lock-function-name-face 1715 (defface org-level-1 ;; font-lock-function-name-face
1681 '((((type tty) (class color)) (:foreground "blue" :weight bold)) 1716 '((((type tty) (class color)) (:foreground "blue" :weight bold))
1682 (((class color) (background light)) (:foreground "Blue")) 1717 (((class color) (background light)) (:foreground "Blue"))
1683 (((class color) (background dark)) (:foreground "LightSkyBlue")) 1718 (((class color) (background dark)) (:foreground "LightSkyBlue"))
1842 (((class color) (background dark)) (:foreground "LightGoldenrod")) 1877 (((class color) (background dark)) (:foreground "LightGoldenrod"))
1843 (t (:bold t :italic t))) 1878 (t (:bold t :italic t)))
1844 "Face used for time grids." 1879 "Face used for time grids."
1845 :group 'org-faces) 1880 :group 'org-faces)
1846 1881
1847 (defvar org-level-faces 1882 (defvar org-level-faces nil)
1848 '( 1883
1849 org-level-1 1884 (when (not org-level-faces)
1850 org-level-2 1885 (setq org-level-faces
1851 org-level-3 1886 '(
1852 org-level-4 1887 org-level-1
1853 org-level-5 1888 org-level-2
1854 org-level-6 1889 org-level-3
1855 org-level-7 1890 org-level-4
1856 org-level-8 1891 org-level-5
1857 )) 1892 org-level-6
1893 org-level-7
1894 org-level-8
1895 ))
1896 (when org-odd-levels-only
1897 (setq org-level-faces (apply 'append (mapcar (lambda (x) (list x x))
1898 org-level-faces)))
1899 (setq org-level-faces (append (cdr org-level-faces) (list 'org-level-1)))))
1900
1858 (defvar org-n-levels (length org-level-faces)) 1901 (defvar org-n-levels (length org-level-faces))
1859 1902
1860 (defun org-set-regexps-and-options () 1903 (defun org-set-regexps-and-options ()
1861 "Precompute regular expressions for current buffer." 1904 "Precompute regular expressions for current buffer."
1862 (when (eq major-mode 'org-mode) 1905 (when (eq major-mode 'org-mode)
1983 (defvar calendar-mode-map) 2026 (defvar calendar-mode-map)
1984 (defvar remember-save-after-remembering) 2027 (defvar remember-save-after-remembering)
1985 (defvar remember-data-file) 2028 (defvar remember-data-file)
1986 (defvar last-arg)) 2029 (defvar last-arg))
1987 2030
1988
1989 ;;; Define the mode 2031 ;;; Define the mode
1990 2032
1991 (defvar org-mode-map (copy-keymap outline-mode-map) 2033 (defvar org-mode-map (copy-keymap outline-mode-map)
1992 "Keymap for Org-mode.") 2034 "Keymap for Org-mode.")
1993 2035
1998 ;; We use a before-change function to check if a table might need 2040 ;; We use a before-change function to check if a table might need
1999 ;; an update. 2041 ;; an update.
2000 (defvar org-table-may-need-update t 2042 (defvar org-table-may-need-update t
2001 "Indicates that a table might need an update. 2043 "Indicates that a table might need an update.
2002 This variable is set by `org-before-change-function'. 2044 This variable is set by `org-before-change-function'.
2003 `org-table-align'sets it back to nil.") 2045 `org-table-align' sets it back to nil.")
2004 (defvar org-mode-hook nil) 2046 (defvar org-mode-hook nil)
2005 (defvar org-inhibit-startup nil) ; Dynamically-scoped param. 2047 (defvar org-inhibit-startup nil) ; Dynamically-scoped param.
2006 (defvar org-agenda-keep-modes nil) ; Dynamically-scoped param. 2048 (defvar org-agenda-keep-modes nil) ; Dynamically-scoped param.
2007 2049
2008 2050
2088 (defvar org-mouse-map (make-sparse-keymap)) 2130 (defvar org-mouse-map (make-sparse-keymap))
2089 (define-key org-mouse-map 2131 (define-key org-mouse-map
2090 (if org-xemacs-p [button2] [mouse-2]) 'org-open-at-mouse) 2132 (if org-xemacs-p [button2] [mouse-2]) 'org-open-at-mouse)
2091 (define-key org-mouse-map 2133 (define-key org-mouse-map
2092 (if org-xemacs-p [button3] [mouse-3]) 'org-find-file-at-mouse) 2134 (if org-xemacs-p [button3] [mouse-3]) 'org-find-file-at-mouse)
2135 (define-key org-mouse-map [follow-link] 'mouse-face)
2093 (when org-tab-follows-link 2136 (when org-tab-follows-link
2094 (define-key org-mouse-map [(tab)] 'org-open-at-point) 2137 (define-key org-mouse-map [(tab)] 'org-open-at-point)
2095 (define-key org-mouse-map "\C-i" 'org-open-at-point)) 2138 (define-key org-mouse-map "\C-i" 'org-open-at-point))
2096 (when org-return-follows-link 2139 (when org-return-follows-link
2097 (define-key org-mouse-map [(return)] 'org-open-at-point) 2140 (define-key org-mouse-map [(return)] 'org-open-at-point)
2198 (let ((re (if radio org-radio-target-regexp org-target-regexp)) 2241 (let ((re (if radio org-radio-target-regexp org-target-regexp))
2199 rtn) 2242 rtn)
2200 (save-excursion 2243 (save-excursion
2201 (goto-char (point-min)) 2244 (goto-char (point-min))
2202 (while (re-search-forward re nil t) 2245 (while (re-search-forward re nil t)
2203 (add-to-list 'rtn (downcase (match-string-no-properties 1)))) 2246 (add-to-list 'rtn (downcase
2247 (if (fboundp 'match-string-no-properties)
2248 (match-string-no-properties 1)
2249 (match-string 1)))))
2204 rtn))) 2250 rtn)))
2205 2251
2206 (defun org-make-target-link-regexp (targets) 2252 (defun org-make-target-link-regexp (targets)
2207 "Make regular expression matching all strings in TARGETS. 2253 "Make regular expression matching all strings in TARGETS.
2208 The regular expression finds the targets also if there is a line break 2254 The regular expression finds the targets also if there is a line break
2272 ;; (3 'bold)) 2318 ;; (3 'bold))
2273 ;; '("\\(\\s-\\|^\\)\\(/\\([a-zA-Z]+\\)/\\)\\([^a-zA-Z*]\\|$\\)" 2319 ;; '("\\(\\s-\\|^\\)\\(/\\([a-zA-Z]+\\)/\\)\\([^a-zA-Z*]\\|$\\)"
2274 ;; (3 'italic)) 2320 ;; (3 'italic))
2275 ;; '("\\(\\s-\\|^\\)\\(_\\([a-zA-Z]+\\)_\\)\\([^a-zA-Z*]\\|$\\)" 2321 ;; '("\\(\\s-\\|^\\)\\(_\\([a-zA-Z]+\\)_\\)\\([^a-zA-Z*]\\|$\\)"
2276 ;; (3 'underline)) 2322 ;; (3 'underline))
2277 ; (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string "\\)\\>")
2278 ; '(1 'org-warning t))
2279 (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string 2323 (list (concat "^\\*+[ \t]*\\<\\(" org-comment-string
2280 "\\|" org-quote-string "\\)\\>") 2324 "\\|" org-quote-string "\\)\\>")
2281 '(1 'org-special-keyword t)) 2325 '(1 'org-special-keyword t))
2282 '("^#.*" (0 'font-lock-comment-face t)) 2326 '("^#.*" (0 'font-lock-comment-face t))
2283 (if org-fontify-done-headline 2327 (if org-fontify-done-headline
2288 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)" 2332 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
2289 (1 'org-table t)) 2333 (1 'org-table t))
2290 '("^[ \t]*\\(:.*\\)" (1 'org-table t)) 2334 '("^[ \t]*\\(:.*\\)" (1 'org-table t))
2291 '("| *\\(:?=[^|\n]*\\)" (1 'org-formula t)) 2335 '("| *\\(:?=[^|\n]*\\)" (1 'org-formula t))
2292 '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t)) 2336 '("^[ \t]*| *\\([#!$*_^]\\) *|" (1 'org-formula t))
2293 ))) 2337 ))
2338 (exp
2339 ;; The font-lock expression for headlines is complicated. It depends
2340 ;; on two user options, and it needs to determine the level in
2341 ;; order to compute the level.
2342 (cond
2343 ((and org-level-color-stars-only (not org-hide-leading-stars))
2344 '("^\\(\\*+\\).*" 1 (nth (% (- (match-end 1) (match-beginning 1) 1) org-n-levels) org-level-faces) nil t))
2345 ((and (not org-level-color-stars-only) org-hide-leading-stars)
2346 '("^\\(\\**\\)\\(\\*.*\\)" (1 'org-hide) (2 (nth (% (- (match-end 1) (match-beginning 1)) org-n-levels) org-level-faces) nil t)))
2347 ((and org-level-color-stars-only org-hide-leading-stars)
2348 '("^\\(\\**\\)\\(\\*\\).*" (1 'org-hide) (2 (nth (% (- (match-end 1) (match-beginning 1)) org-n-levels) org-level-faces) nil t)))
2349 (t
2350 '("^\\(\\*+\\).*" 0 (nth (% (- (match-end 1) (match-beginning 1) 1) org-n-levels) org-level-faces) nil t)))))
2351
2352 ;; Now set the full font-lock-keywords
2294 (set (make-local-variable 'org-font-lock-keywords) 2353 (set (make-local-variable 'org-font-lock-keywords)
2295 (append 2354 (append
2296 (if org-noutline-p ; FIXME: I am not sure if eval will work 2355 (if org-xemacs-p (list exp) (list (cons 'eval (list 'quote exp))))
2297 ; on XEmacs if noutline is ever ported
2298 `((eval . (list "^\\(\\*+\\).*"
2299 ,(if org-level-color-stars-only 1 0)
2300 '(nth
2301 (% (- (match-end 1) (match-beginning 1) 1)
2302 org-n-levels)
2303 org-level-faces)
2304 nil t)))
2305 `(("^\\(\\(\\*+\\)[^\r\n]*\\)[\n\r]"
2306 (,(if org-level-color-stars-only 2 0)
2307 (nth (% (- (match-end 2) (match-beginning 2) 1)
2308 org-n-levels)
2309 org-level-faces)
2310 nil t))))
2311 org-font-lock-extra-keywords)) 2356 org-font-lock-extra-keywords))
2312 (set (make-local-variable 'font-lock-defaults) 2357 (set (make-local-variable 'font-lock-defaults)
2313 '(org-font-lock-keywords t nil nil backward-paragraph)) 2358 '(org-font-lock-keywords t nil nil backward-paragraph))
2314 (kill-local-variable 'font-lock-keywords) nil)) 2359 (kill-local-variable 'font-lock-keywords) nil))
2315 2360
2729 "Make sure that after pro/demotion cursor position is right." 2774 "Make sure that after pro/demotion cursor position is right."
2730 (and (equal (char-after) ?\ ) 2775 (and (equal (char-after) ?\ )
2731 (equal (char-before) ?*) 2776 (equal (char-before) ?*)
2732 (forward-char 1))) 2777 (forward-char 1)))
2733 2778
2779 (defun org-get-legal-level (level change)
2780 "Rectify a level change under the influence of `org-odd-levels-only'
2781 LEVEL is a current level, CHANGE is by how much the level should be
2782 modified. Even if CHANGE is nil, LEVEL may be returned modified because
2783 even level numbers will become the next higher odd number."
2784 (if org-odd-levels-only
2785 (cond ((not change) (1+ (* 2 (/ level 2))))
2786 ((> change 0) (1+ (* 2 (/ (+ level (* 2 change)) 2))))
2787 ((< change 0) (max 1 (1+ (* 2 (/ (+ level (* 2 change)) 2))))))
2788 (max 1 (+ level change))))
2789
2734 (defun org-promote () 2790 (defun org-promote ()
2735 "Promote the current heading higher up the tree. 2791 "Promote the current heading higher up the tree.
2736 If the region is active in `transient-mark-mode', promote all headings 2792 If the region is active in `transient-mark-mode', promote all headings
2737 in the region." 2793 in the region."
2738 (org-back-to-heading t) 2794 (org-back-to-heading t)
2739 (let* ((level (save-match-data (funcall outline-level))) 2795 (let* ((level (save-match-data (funcall outline-level)))
2740 (up-head (make-string (1- level) ?*))) 2796 (up-head (make-string (org-get-legal-level level -1) ?*))
2797 (diff (abs (- level (length up-head)))))
2741 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover")) 2798 (if (= level 1) (error "Cannot promote to level 0. UNDO to recover"))
2742 (replace-match up-head nil t) 2799 (replace-match up-head nil t)
2743 ;; Fixup tag positioning 2800 ;; Fixup tag positioning
2744 (and org-auto-align-tags (org-set-tags nil t)) 2801 (and org-auto-align-tags (org-set-tags nil t))
2745 (if org-adapt-indentation 2802 (if org-adapt-indentation
2746 (org-fixup-indentation "^ " "" "^ ?\\S-")))) 2803 (org-fixup-indentation (if (> diff 1) "^ " "^ ") ""
2804 (if (> diff 1) "^ ? ?\\S-" "^ ?\\S-")))))
2747 2805
2748 (defun org-demote () 2806 (defun org-demote ()
2749 "Demote the current heading lower down the tree. 2807 "Demote the current heading lower down the tree.
2750 If the region is active in `transient-mark-mode', demote all headings 2808 If the region is active in `transient-mark-mode', demote all headings
2751 in the region." 2809 in the region."
2752 (org-back-to-heading t) 2810 (org-back-to-heading t)
2753 (let* ((level (save-match-data (funcall outline-level))) 2811 (let* ((level (save-match-data (funcall outline-level)))
2754 (down-head (make-string (1+ level) ?*))) 2812 (down-head (make-string (org-get-legal-level level 1) ?*))
2813 (diff (abs (- level (length down-head)))))
2755 (replace-match down-head nil t) 2814 (replace-match down-head nil t)
2756 ;; Fixup tag positioning 2815 ;; Fixup tag positioning
2757 (and org-auto-align-tags (org-set-tags nil t)) 2816 (and org-auto-align-tags (org-set-tags nil t))
2758 (if org-adapt-indentation 2817 (if org-adapt-indentation
2759 (org-fixup-indentation "^ " " " "^\\S-")))) 2818 (org-fixup-indentation "^ " (if (> diff 1) " " " ") "^\\S-"))))
2760 2819
2761 (defun org-map-tree (fun) 2820 (defun org-map-tree (fun)
2762 "Call FUN for every heading underneath the current one." 2821 "Call FUN for every heading underneath the current one."
2763 (org-back-to-heading) 2822 (org-back-to-heading)
2764 (let ((level (outline-level))) 2823 (let ((level (outline-level)))
2883 (setq org-subtree-clip (current-kill 0)) 2942 (setq org-subtree-clip (current-kill 0))
2884 (message "%s: Subtree with %d characters" 2943 (message "%s: Subtree with %d characters"
2885 (if cut "Cut" "Copied") 2944 (if cut "Cut" "Copied")
2886 (length org-subtree-clip))))) 2945 (length org-subtree-clip)))))
2887 2946
2947 ;; FIXME: this needs to be adapted for the odd-level-only stuff.
2888 (defun org-paste-subtree (&optional level tree) 2948 (defun org-paste-subtree (&optional level tree)
2889 "Paste the clipboard as a subtree, with modification of headline level. 2949 "Paste the clipboard as a subtree, with modification of headline level.
2890 The entire subtree is promoted or demoted in order to match a new headline 2950 The entire subtree is promoted or demoted in order to match a new headline
2891 level. By default, the new level is derived from the visible headings 2951 level. By default, the new level is derived from the visible headings
2892 before and after the insertion point, and taken to be the inferior headline 2952 before and after the insertion point, and taken to be the inferior headline
2901 2961
2902 If you want to insert the tree as is, just use \\[yank]. 2962 If you want to insert the tree as is, just use \\[yank].
2903 2963
2904 If optional TREE is given, use this text instead of the kill ring." 2964 If optional TREE is given, use this text instead of the kill ring."
2905 (interactive "P") 2965 (interactive "P")
2966 (debug)
2906 (unless (org-kill-is-subtree-p tree) 2967 (unless (org-kill-is-subtree-p tree)
2907 (error 2968 (error
2908 (substitute-command-keys 2969 (substitute-command-keys
2909 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway"))) 2970 "The kill is not a (set of) tree(s) - please use \\[yank] to yank anyway")))
2910 (let* ((txt (or tree (current-kill 0))) 2971 (let* ((txt (or tree (current-kill 0)))
2943 0 3004 0
2944 (- new-level old-level))) 3005 (- new-level old-level)))
2945 (shift1 shift) 3006 (shift1 shift)
2946 (delta (if (> shift 0) -1 1)) 3007 (delta (if (> shift 0) -1 1))
2947 (func (if (> shift 0) 'org-demote 'org-promote)) 3008 (func (if (> shift 0) 'org-demote 'org-promote))
3009 (org-odd-levels-only nil)
2948 beg end) 3010 beg end)
2949 ;; Remove the forces level indicator 3011 ;; Remove the forces level indicator
2950 (if force-level 3012 (if force-level
2951 (delete-region (point-at-bol) (point))) 3013 (delete-region (point-at-bol) (point)))
2952 ;; Make sure we start at the beginning of an empty line 3014 ;; Make sure we start at the beginning of an empty line
3825 With an optional argument WITH-TIME, the prompt will suggest to also 3887 With an optional argument WITH-TIME, the prompt will suggest to also
3826 insert a time. Note that when WITH-TIME is not set, you can still 3888 insert a time. Note that when WITH-TIME is not set, you can still
3827 enter a time, and this function will inform the calling routine about 3889 enter a time, and this function will inform the calling routine about
3828 this change. The calling routine may then choose to change the format 3890 this change. The calling routine may then choose to change the format
3829 used to insert the time stamp into the buffer to include the time." 3891 used to insert the time stamp into the buffer to include the time."
3892 (require 'parse-time)
3830 (let* ((default-time 3893 (let* ((default-time
3831 ;; Default time is either today, or, when entering a range, 3894 ;; Default time is either today, or, when entering a range,
3832 ;; the range start. 3895 ;; the range start.
3833 (if (save-excursion 3896 (if (save-excursion
3834 (re-search-backward 3897 (re-search-backward
4346 4409
4347 (define-key org-agenda-keymap 4410 (define-key org-agenda-keymap
4348 (if org-xemacs-p [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse) 4411 (if org-xemacs-p [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
4349 (define-key org-agenda-keymap 4412 (define-key org-agenda-keymap
4350 (if org-xemacs-p [(button3)] [(mouse-3)]) 'org-agenda-show-mouse) 4413 (if org-xemacs-p [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
4351 4414 (define-key org-agenda-keymap [follow-link] 'mouse-face)
4352 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu" 4415 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
4353 '("Agenda" 4416 '("Agenda"
4354 ("Agenda Files") 4417 ("Agenda Files")
4355 "--" 4418 "--"
4356 ["Show" org-agenda-show t] 4419 ["Show" org-agenda-show t]
6623 (setq tags 6686 (setq tags
6624 (let ((org-add-colon-after-tag-completion t)) 6687 (let ((org-add-colon-after-tag-completion t))
6625 (completing-read "Tags: " 'org-tags-completion-function 6688 (completing-read "Tags: " 'org-tags-completion-function
6626 nil nil current 'org-tags-history))) 6689 nil nil current 'org-tags-history)))
6627 (while (string-match "[-+&]+" tags) 6690 (while (string-match "[-+&]+" tags)
6628 (setq tags (replace-match ":" t t tags))) 6691 (setq tags (replace-match ":" t t tags))))
6629 (unless (setq empty (string-match "\\`[\t ]*\\'" tags)) 6692 ;; FIXME: still optimize this byt not checking when JUST-ALIGN?
6630 (unless (string-match ":$" tags) (setq tags (concat tags ":"))) 6693 (unless (setq empty (string-match "\\`[\t ]*\\'" tags))
6631 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))) 6694 (unless (string-match ":$" tags) (setq tags (concat tags ":")))
6695 (unless (string-match "^:" tags) (setq tags (concat ":" tags))))
6632 (if (equal current "") 6696 (if (equal current "")
6633 (progn 6697 (progn
6634 (end-of-line 1) 6698 (end-of-line 1)
6635 (or empty (insert-before-markers " "))) 6699 (or empty (insert-before-markers " ")))
6636 (beginning-of-line 1) 6700 (beginning-of-line 1)
7190 (mh-get-msg-num nil) 7254 (mh-get-msg-num nil)
7191 ;; Refer to the show buffer 7255 ;; Refer to the show buffer
7192 (mh-show-buffer-message-number)))) 7256 (mh-show-buffer-message-number))))
7193 7257
7194 (defun org-mhe-get-header (header) 7258 (defun org-mhe-get-header (header)
7195 "Return a header of the message in folder mode. This will create a 7259 "Return a header of the message in folder mode. This will create a
7196 show buffer for the corresponding message. If you have a more clever 7260 show buffer for the corresponding message. If you have a more clever
7197 idea..." 7261 idea..."
7198 (let* ((folder (org-mhe-get-message-folder)) 7262 (let* ((folder (org-mhe-get-message-folder))
7199 (num (org-mhe-get-message-num)) 7263 (num (org-mhe-get-message-num))
7200 (buffer (get-buffer-create (concat "show-" folder))) 7264 (buffer (get-buffer-create (concat "show-" folder)))
7201 (header-field)) 7265 (header-field))
10452 (save-excursion 10516 (save-excursion
10453 (set-buffer (get-buffer-create " org-mode-tmp")) 10517 (set-buffer (get-buffer-create " org-mode-tmp"))
10454 (erase-buffer) 10518 (erase-buffer)
10455 (insert string) 10519 (insert string)
10456 (org-mode) 10520 (org-mode)
10457 ;; Find targets in comments and move them out of comments 10521 ;; Find targets in comments and move them out of comments,
10522 ;; but mark them as targets that should be invisible
10458 (goto-char (point-min)) 10523 (goto-char (point-min))
10459 (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t) 10524 (while (re-search-forward "^#.*?\\(<<<?[^>\r\n]+>>>?\\).*" nil t)
10460 (replace-match "\\1")) 10525 (replace-match "\\1(INVISIBLE)"))
10461 ;; Find matches for radio targets and turn them into links 10526 ;; Find matches for radio targets and turn them into links
10462 (goto-char (point-min)) 10527 (goto-char (point-min))
10463 (while (re-search-forward re-radio nil t) 10528 (while (re-search-forward re-radio nil t)
10464 (replace-match "\\1[[\\2]]")) 10529 (replace-match "\\1[[\\2]]"))
10465 ;; Find all links that contain a newline and put them into a single line 10530 ;; Find all links that contain a newline and put them into a single line
10473 (replace-match "")) 10538 (replace-match ""))
10474 (setq rtn (buffer-string))) 10539 (setq rtn (buffer-string)))
10475 (kill-buffer " org-mode-tmp") 10540 (kill-buffer " org-mode-tmp")
10476 rtn)) 10541 rtn))
10477 10542
10478 (defun org-solidify-link-text (s) 10543 (defun org-solidify-link-text (s &optional alist)
10479 "Take link text and make a safe target out of it." 10544 "Take link text and make a safe target out of it."
10480 (save-match-data 10545 (save-match-data
10481 (mapconcat 10546 (let* ((rtn
10482 'identity 10547 (mapconcat
10483 (org-split-string s "[ \t\r\n]+") "--"))) 10548 'identity
10549 (org-split-string s "[ \t\r\n]+") "--"))
10550 (a (assoc rtn alist)))
10551 (or (cdr a) rtn))))
10552
10553 (defun org-convert-to-odd-levels ()
10554 "Convert an org-mode file with all levels allowed to one with odd levels.
10555 This will leave level 1 alone, convert level 2 to level 3, level 3 to
10556 level 5 etc."
10557 (interactive)
10558 (when (yes-or-no-p "Are you sure you want to globally change levels? ")
10559 (let ((org-odd-levels-only nil) n)
10560 (save-excursion
10561 (goto-char (point-min))
10562 (while (re-search-forward "^\\*\\*+" nil t)
10563 (setq n (1- (length (match-string 0))))
10564 (while (>= (setq n (1- n)) 0)
10565 (org-demote))
10566 (end-of-line 1))))))
10567
10568 (defun org-tr-level (n)
10569 "Make N odd if required."
10570 (if org-odd-levels-only (1+ (/ n 2)) n))
10484 10571
10485 (defvar org-last-level nil) ; dynamically scoped variable 10572 (defvar org-last-level nil) ; dynamically scoped variable
10486 10573
10487 (defun org-export-as-ascii (arg) 10574 (defun org-export-as-ascii (arg)
10488 "Export the outline as a pretty ASCII file. 10575 "Export the outline as a pretty ASCII file.
10559 (if (string-match org-todo-line-regexp 10646 (if (string-match org-todo-line-regexp
10560 line) 10647 line)
10561 ;; This is a headline 10648 ;; This is a headline
10562 (progn 10649 (progn
10563 (setq level (- (match-end 1) (match-beginning 1)) 10650 (setq level (- (match-end 1) (match-beginning 1))
10651 level (org-tr-level level)
10564 txt (match-string 3 line) 10652 txt (match-string 3 line)
10565 todo 10653 todo
10566 (or (and (match-beginning 2) 10654 (or (and (match-beginning 2)
10567 (not (equal (match-string 2 line) 10655 (not (equal (match-string 2 line)
10568 org-done-string))) 10656 org-done-string)))
10597 (if (match-end 3) "[\\3]" "[\\1]") 10685 (if (match-end 3) "[\\3]" "[\\1]")
10598 t nil line))) 10686 t nil line)))
10599 (cond 10687 (cond
10600 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line) 10688 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line)
10601 ;; a Headline 10689 ;; a Headline
10602 (setq level (- (match-end 1) (match-beginning 1)) 10690 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
10603 txt (match-string 2 line)) 10691 txt (match-string 2 line))
10604 (org-ascii-level-start level txt umax)) 10692 (org-ascii-level-start level txt umax))
10605 (t (insert line "\n")))) 10693 (t (insert line "\n"))))
10606 (normal-mode) 10694 (normal-mode)
10607 (save-buffer) 10695 (save-buffer)
10858 (llt org-plain-list-ordered-item-terminator) 10946 (llt org-plain-list-ordered-item-terminator)
10859 (email user-mail-address) 10947 (email user-mail-address)
10860 (language org-export-default-language) 10948 (language org-export-default-language)
10861 (text nil) 10949 (text nil)
10862 (lang-words nil) 10950 (lang-words nil)
10951 (target-alist nil) tg
10863 (head-count 0) cnt 10952 (head-count 0) cnt
10864 (start 0) 10953 (start 0)
10865 ;; FIXME: The following returns always nil under XEmacs 10954 ;; FIXME: The following returns always nil under XEmacs
10866 (coding-system (and (fboundp 'coding-system-get) 10955 (coding-system (and (fboundp 'coding-system-get)
10867 (boundp 'buffer-file-coding-system) 10956 (boundp 'buffer-file-coding-system)
10921 (if text (insert (concat "<p>\n" (org-html-expand text)))) 11010 (if text (insert (concat "<p>\n" (org-html-expand text))))
10922 (if org-export-with-toc 11011 (if org-export-with-toc
10923 (progn 11012 (progn
10924 (insert (format "<H2>%s</H2>\n" (nth 3 lang-words))) 11013 (insert (format "<H2>%s</H2>\n" (nth 3 lang-words)))
10925 (insert "<ul>\n") 11014 (insert "<ul>\n")
11015 (setq lines
10926 (mapcar '(lambda (line) 11016 (mapcar '(lambda (line)
10927 (if (string-match org-todo-line-regexp line) 11017 (if (string-match org-todo-line-regexp line)
10928 ;; This is a headline 11018 ;; This is a headline
10929 (progn 11019 (progn
10930 (setq level (- (match-end 1) (match-beginning 1)) 11020 (setq level (- (match-end 1) (match-beginning 1))
11021 level (org-tr-level level)
10931 txt (save-match-data 11022 txt (save-match-data
10932 (org-html-expand 11023 (org-html-expand
10933 (match-string 3 line))) 11024 (match-string 3 line)))
10934 todo 11025 todo
10935 (or (and (match-beginning 2) 11026 (or (and (match-beginning 2)
10955 (progn 11046 (progn
10956 (setq cnt (- org-last-level level)) 11047 (setq cnt (- org-last-level level))
10957 (while (>= (setq cnt (1- cnt)) 0) 11048 (while (>= (setq cnt (1- cnt)) 0)
10958 (insert "</ul>")) 11049 (insert "</ul>"))
10959 (insert "\n"))) 11050 (insert "\n")))
11051 ;; Check for targets
11052 (while (string-match org-target-regexp line)
11053 (setq tg (match-string 1 line)
11054 line (replace-match
11055 (concat "@<span class=\"target\">" tg "@</span> ")
11056 t t line))
11057 (push (cons (org-solidify-link-text tg)
11058 (format "sec-%d" head-count))
11059 target-alist))
11060 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
11061 (setq txt (replace-match "" t t txt)))
10960 (insert 11062 (insert
10961 (format 11063 (format
10962 (if todo 11064 (if todo
10963 "<li><a href=\"#sec-%d\"><span class=\"todo\">%s</span></a>\n" 11065 "<li><a href=\"#sec-%d\"><span class=\"todo\">%s</span></a>\n"
10964 "<li><a href=\"#sec-%d\">%s</a>\n") 11066 "<li><a href=\"#sec-%d\">%s</a>\n")
10965 head-count txt)) 11067 head-count txt))
11068
10966 (setq org-last-level level)) 11069 (setq org-last-level level))
10967 )))) 11070 )))
10968 lines) 11071 line)
11072 lines))
10969 (while (> org-last-level 0) 11073 (while (> org-last-level 0)
10970 (setq org-last-level (1- org-last-level)) 11074 (setq org-last-level (1- org-last-level))
10971 (insert "</ul>\n")) 11075 (insert "</ul>\n"))
10972 )) 11076 ))
10973 (setq head-count 0) 11077 (setq head-count 0)
10999 (insert "</pre>\n")) 11103 (insert "</pre>\n"))
11000 (throw 'nextline nil)) 11104 (throw 'nextline nil))
11001 11105
11002 11106
11003 ;; make targets to anchors 11107 ;; make targets to anchors
11004 (while (string-match "<<<?\\([^<>]*\\)>>>?[ \t]*\n?" line) 11108 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
11005 (setq line (replace-match 11109 (cond
11006 (concat "@<a name=\"" 11110 ((match-end 2)
11007 (org-solidify-link-text (match-string 1 line)) 11111 (setq line (replace-match
11008 "\">\\nbsp@</a>") 11112 (concat "@<a name=\""
11009 t t line))) 11113 (org-solidify-link-text (match-string 1 line))
11114 "\">\\nbsp@</a>")
11115 t t line)))
11116 ((and org-export-with-toc (equal (string-to-char line) ?*))
11117 (setq line (replace-match
11118 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
11119 ; (concat "@<i>" (match-string 1 line) "@</i> ")
11120 t t line)))
11121 (t
11122 (setq line (replace-match
11123 (concat "@<a name=\""
11124 (org-solidify-link-text (match-string 1 line))
11125 "\" class=\"target\">" (match-string 1 line) "@</a> ")
11126 t t line)))))
11010 ;; Replace internal links 11127 ;; Replace internal links
11011 (while (string-match org-bracket-link-regexp line) 11128 (while (string-match org-bracket-link-regexp line)
11012 (setq line (replace-match 11129 (setq line (replace-match
11013 (concat 11130 (concat
11014 "@<a href=\"#" 11131 "@<a href=\"#"
11015 (org-solidify-link-text (match-string 1 line)) 11132 (org-solidify-link-text (match-string 1 line) target-alist)
11016 "\">" 11133 "\">"
11017 (match-string (if (match-end 3) 3 1) line) 11134 (match-string (if (match-end 3) 3 1) line)
11018 "@</a>") 11135 "@</a>")
11019 t t line))) 11136 t t line)))
11020 11137
11085 (setq line (replace-match "<span class=\"deadline\">\\&</span>" 11202 (setq line (replace-match "<span class=\"deadline\">\\&</span>"
11086 nil nil line 1))))) 11203 nil nil line 1)))))
11087 (cond 11204 (cond
11088 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line) 11205 ((string-match "^\\(\\*+\\)[ \t]*\\(.*\\)" line)
11089 ;; This is a headline 11206 ;; This is a headline
11090 (setq level (- (match-end 1) (match-beginning 1)) 11207 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)))
11091 txt (match-string 2 line)) 11208 txt (match-string 2 line))
11092 (if (<= level umax) (setq head-count (+ head-count 1))) 11209 (if (<= level umax) (setq head-count (+ head-count 1)))
11093 (when in-local-list 11210 (when in-local-list
11094 ;; Close any local lists before inserting a new header line 11211 ;; Close any local lists before inserting a new header line
11095 (while local-list-num 11212 (while local-list-num
11820 (define-key org-mode-map "\C-c:" 'org-toggle-fixed-width-section) 11937 (define-key org-mode-map "\C-c:" 'org-toggle-fixed-width-section)
11821 (define-key org-mode-map "\C-c\C-xh" 'org-export-as-html) 11938 (define-key org-mode-map "\C-c\C-xh" 'org-export-as-html)
11822 (define-key org-mode-map "\C-c\C-xb" 'org-export-as-html-and-open) 11939 (define-key org-mode-map "\C-c\C-xb" 'org-export-as-html-and-open)
11823 (define-key org-mode-map "\C-c\C-x\C-b" 'org-export-as-html-and-open) 11940 (define-key org-mode-map "\C-c\C-x\C-b" 'org-export-as-html-and-open)
11824 11941
11942 (define-key org-mode-map "\C-c\C-x\C-k" 'org-cut-special)
11825 (define-key org-mode-map "\C-c\C-x\C-w" 'org-cut-special) 11943 (define-key org-mode-map "\C-c\C-x\C-w" 'org-cut-special)
11826 (define-key org-mode-map "\C-c\C-x\M-w" 'org-copy-special) 11944 (define-key org-mode-map "\C-c\C-x\M-w" 'org-copy-special)
11827 (define-key org-mode-map "\C-c\C-x\C-y" 'org-paste-special) 11945 (define-key org-mode-map "\C-c\C-x\C-y" 'org-paste-special)
11828 11946
11829 (defsubst org-table-p () (org-at-table-p)) 11947 (defsubst org-table-p () (org-at-table-p))
12242 ["Promote Heading" org-metaleft (not (org-at-table-p))] 12360 ["Promote Heading" org-metaleft (not (org-at-table-p))]
12243 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))] 12361 ["Promote Subtree" org-shiftmetaleft (not (org-at-table-p))]
12244 ["Demote Heading" org-metaright (not (org-at-table-p))] 12362 ["Demote Heading" org-metaright (not (org-at-table-p))]
12245 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))] 12363 ["Demote Subtree" org-shiftmetaright (not (org-at-table-p))]
12246 "--" 12364 "--"
12247 ["Archive Subtree" org-archive-subtree t]) 12365 ["Archive Subtree" org-archive-subtree t]
12366 "--"
12367 ["Convert file to odd levels" org-convert-to-odd-levels t])
12248 "--" 12368 "--"
12249 ("TODO Lists" 12369 ("TODO Lists"
12250 ["TODO/DONE/-" org-todo t] 12370 ["TODO/DONE/-" org-todo t]
12251 ["Show TODO Tree" org-show-todo-tree t] 12371 ["Show TODO Tree" org-show-todo-tree t]
12252 ["Global TODO list" org-todo-list t] 12372 ["Global TODO list" org-todo-list t]