1 ;;; org-inlinetask.el --- Tasks independent of outline hierarchy
3 ;; Copyright (C) 2009 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This module implements inline tasks in Org-mode. Inline tasks are
31 ;; tasks that have all the properties of normal outline nodes, including
32 ;; the ability to store meta data like scheduling dates, TODO state, tags
33 ;; and properties. However, these nodes are treated specially by the
34 ;; visibility cycling and export commands.
36 ;; Visibility cycling exempts these nodes from cycling. So whenever their
37 ;; parent is opened, so are these tasks. This will only work with
38 ;; `org-cycle', so if you are also using orther commands to show/hide
39 ;; entries, you will occasionally find these tasks to behave like
40 ;; all other outline nodes, seemingly splitting the text of the parent
43 ;; Export commands do not treat these nodes as part of the sectioning
44 ;; structure, but as a special inline text that is either removed, or
45 ;; formatted in some special way.
47 ;; Special fontification of inline tasks, so that they can be immediately
48 ;; recognized. From the stars of the headline, only the first and the
49 ;; last two will be visible, the others will be hidden using the
52 ;; An inline task is identified solely by a minimum outline level, given
53 ;; by the variable `org-inlinetask-min-level', default 15.
55 ;; Inline tasks are normally assumed to contain at most a time planning
56 ;; line (DEADLINE etc) after it, and then any number of drawers, for
57 ;; example LOGBOOK of PROPERTIES. No empty lines are allowed.
58 ;; If you need to have normal text as part of an inline task, you
59 ;; can do so by adding an "END" headline with the same number of stars,
62 ;; **************** TODO some small task
63 ;; DEADLINE: <2009-03-30 Mon>
65 ;; :SOMETHING: or other
67 ;; And here is some extra text
68 ;; **************** END
70 ;; Also, if you want to use refiling and archiving for inline tasks,
71 ;; The END line must be present to make things work properly.
73 ;; This package installs one new comand:
75 ;; C-c C-x t Insert a new inline task with END line
82 (defgroup org-inlinetask nil
83 "Options concerning inline tasks in Org mode."
84 :tag
"Org Inline Tasks"
85 :group
'org-structure
)
87 (defcustom org-inlinetask-min-level
15
88 "Minimum level a headline must have before it is treated as an inline task.
89 It is strongly recommended that you set `org-cycle-max-level' not at all,
90 or to a number smaller than this one. In fact, when `org-cycle-max-level' is
91 not set, it will be assumed to be one less than the value of smaller than
92 the value of this variable."
93 :group
'org-inlinetask
96 (defcustom org-inlinetask-export
'arrow
+content
97 "What should be done with inlinetasks upon export?
100 nil Remove entirely, headline and \"content\"
101 arrow Insert heading in bold, preceeded by an arrow
102 arrow+content Insert arrow and headline, add content below in an
103 #+begin_example box (ugly, but works for now)
105 The \"content\" of an inline task is the material below the planning
106 line and any drawers, up to a lines wit the same number of stars,
107 but containing only the word END."
108 :group
'org-inlinetask
109 :group
'org-export-general
111 (const :tag
"Remove entirely" nil
)
112 (const :tag
"Headline preceeded by arrow" arrow
)
113 (const :tag
"Arrow, headline, + content" arrow
+content
)))
115 (defvar org-odd-levels-only
)
116 (defvar org-keyword-time-regexp
)
117 (defvar org-drawer-regexp
)
118 (defvar org-complex-heading-regexp
)
119 (defvar org-property-end-re
)
121 (defun org-inlinetask-insert-task ()
122 "Insert an inline task."
124 (or (bolp) (newline))
125 (insert (make-string org-inlinetask-min-level ?
*) " \n"
126 (make-string org-inlinetask-min-level ?
*) " END\n")
128 (define-key org-mode-map
"\C-c\C-xt" 'org-inlinetask-insert-task
)
130 (defun org-inlinetask-export-handler ()
131 "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
132 Either remove headline and meta data, or do special formatting."
133 (goto-char (point-min))
134 (let* ((nstars (if org-odd-levels-only
135 (1- (* 2 (or org-inlinetask-min-level
200)))
136 (or org-inlinetask-min-level
200)))
137 (re1 (format "^\\(\\*\\{%d,\\}\\) .*\n" nstars
))
138 (re2 (concat "^[ \t]*" org-keyword-time-regexp
))
139 headline beg end stars content
)
140 (while (re-search-forward re1 nil t
)
141 (setq headline
(match-string 0)
142 stars
(match-string 1)
145 (while (looking-at re2
)
146 (delete-region (point) (1+ (point-at-eol))))
147 (while (looking-at org-drawer-regexp
)
149 (if (re-search-forward org-property-end-re nil t
)
150 (delete-region beg
(1+ (match-end 0)))))
152 (when (and (re-search-forward "^\\(\\*+\\) " nil t
)
153 (= (length (match-string 1)) (length stars
))
154 (progn (goto-char (match-end 0))
155 (looking-at "END[ \t]*$")))
156 (setq content
(buffer-substring beg
(1- (point-at-bol))))
157 (delete-region beg
(1+ (match-end 0))))
159 (when (and org-inlinetask-export
160 (string-match org-complex-heading-regexp headline
))
161 (when (memq org-inlinetask-export
'(arrow+content arrow
))
162 (insert "\n\n\\Rightarrow\\Rightarrow\\Rightarrow *"
163 (if (match-end 2) (concat (match-string 2 headline
) " ") "")
164 (match-string 4 headline
) "*\n"))
165 (when (and content
(eq org-inlinetask-export
'arrow
+content
))
166 (insert "#+BEGIN_EXAMPLE\n" content
"\n#+END_EXAMPLE\n"))
169 (defun org-inlinetask-fontify (limit)
170 "Fontify the inline tasks."
171 (let* ((nstars (if org-odd-levels-only
172 (1- (* 2 (or org-inlinetask-min-level
200)))
173 (or org-inlinetask-min-level
200)))
174 (re (concat "^\\(\\*\\)\\(\\*\\{"
175 (format "%d" (- nstars
3))
176 ",\\}\\)\\(\\*\\* .*\\)")))
177 (while (re-search-forward re limit t
)
178 (add-text-properties (match-beginning 1) (match-end 1)
179 '(face org-warning font-lock-fontified t
))
180 (add-text-properties (match-beginning 2) (match-end 2)
181 '(face org-hide font-lock-fontified t
))
182 (add-text-properties (match-beginning 3) (match-end 3)
183 '(face shadow font-lock-fontified t
)))))
185 (defun org-inlinetask-remove-END-maybe ()
186 "Remove an END line when present."
187 (when (looking-at (format "\\([ \t]*\n\\)*\\*\\{%d,\\}[ \t]+END[ \t]*$"
188 org-inlinetask-min-level
))
191 (eval-after-load "org-exp"
192 '(add-hook 'org-export-preprocess-after-tree-selection-hook
193 'org-inlinetask-export-handler
))
194 (eval-after-load "org"
195 '(add-hook 'org-font-lock-hook
'org-inlinetask-fontify
))
197 (provide 'org-inlinetask
)
199 ;;; org-inlinetask.el ends here