1 ;;; org-inlinetask.el --- Tasks independent of outline hierarchy
2 ;; Copyright (C) 2009 Free Software Foundation, Inc.
4 ;; Author: Carsten Dominik <carsten at orgmode dot org>
5 ;; Keywords: outlines, hypermedia, calendar, wp
6 ;; Homepage: http://orgmode.org
9 ;; This file is not yet part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This module implements inline tasks in Org-mode. Inline tasks are
30 ;; tasks that have all the properties of normal outline nodes, including
31 ;; the ability to store meta data like scheduling dates, TODO state, tags
32 ;; and properties. However, these nodes are treated specially by the
33 ;; visibility cycling and export commands.
35 ;; Visibility cycling exempts these nodes from cycling. So whenever their
36 ;; parent is opened, so are these tasks. This will only work with
37 ;; `org-cycle', so if you are also using orther commands to show/hide
38 ;; entries, you will occasionally find these tasks to behave like
39 ;; all other outline nodes, seemingly splitting the text of the parent
42 ;; Export commands do not treat these nodes as part of the sectioning
43 ;; structure, but as a special inline text that is either removed, or
44 ;; formatted in some special way.
46 ;; Special fontification of inline tasks, so that they can be immediately
47 ;; recognized. From the stars of the headline, only the first and the
48 ;; last two will be visible, the others will be hidden using the
51 ;; An inline task is identified solely by a minimum outline level, given
52 ;; by the variable `org-inlinetask-min-level', default 15.
54 ;; Inline tasks are normally assumed to contain at most a time planning
55 ;; line (DEADLINE etc) after it, and then any number of drawers, for
56 ;; example LOGBOOK of PROPERTIES. No empty lines are allowed.
57 ;; If you need to have normal text as part of an inline task, you
58 ;; can do so by adding an "END" headline with the same number of stars,
61 ;; **************** TODO some small task
62 ;; DEADLINE: <2009-03-30 Mon>
64 ;; :SOMETHING: or other
66 ;; And here is some extra text
67 ;; **************** END
71 (defgroup org-inlinetask nil
72 "Options concerning inline tasks in Org mode."
73 :tag
"Org Inline Tasks"
74 :group
'org-structure
)
76 (defcustom org-inlinetask-min-level
15
77 "Minimum level a headline must have before it is treated as an inline task.
78 It is strongly recommended that you set `org-cycle-max-level' not at all,
79 or to a number smaller than this one. In fact, when `org-cycle-max-level' is
80 not set, it will be assumed to be one less than the value of smaller than
81 the value of this variable."
82 :group
'org-inlinetask
85 (defcustom org-inlinetask-export
'arrow
+content
86 "What should be done with inlinetasks upon export?
89 nil Remove entirely, headline and \"content\"
90 arrow Insert heading in bold, preceeded by an arrow
91 arrow+content Insert arrow and headline, add content below in an
92 #+begin_example box (ugly, but works for now)
94 The \"content\" of an inline task is the material below the planning
95 line and any drawers, up to a lines wit the same number of stars,
96 but containing only the word END."
97 :group
'org-inlinetask
98 :group
'org-export-general
100 (const :tag
"Remove entirely" nil
)
101 (const :tag
"Headline preceeded by arrow" arrow
)
102 (const :tag
"Arrow, headline, + content" arrow
+content
)))
104 (defvar org-odd-levels-only
)
105 (defvar org-keyword-time-regexp
)
106 (defvar org-drawer-regexp
)
107 (defvar org-complex-heading-regexp
)
108 (defvar org-property-end-re
)
109 (defun org-inlinetask-export-handler ()
110 "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
111 Either remove headline and meta data, or do special formatting."
112 (goto-char (point-min))
113 (let* ((nstars (if org-odd-levels-only
114 (1- (* 2 (or org-inlinetask-min-level
200)))
115 (or org-inlinetask-min-level
200)))
116 (re1 (format "^\\(\\*\\{%d,\\}\\) .*\n" nstars
))
117 (re2 (concat "^[ \t]*" org-keyword-time-regexp
))
118 headline beg end stars content
)
119 (while (re-search-forward re1 nil t
)
120 (setq headline
(match-string 0)
121 stars
(match-string 1)
124 (while (looking-at re2
)
125 (delete-region (point) (1+ (point-at-eol))))
126 (while (looking-at org-drawer-regexp
)
128 (if (re-search-forward org-property-end-re nil t
)
129 (delete-region beg
(1+ (match-end 0)))))
131 (when (and (re-search-forward "^\\(\\*+\\) " nil t
)
132 (= (length (match-string 1)) (length stars
))
133 (progn (goto-char (match-end 0))
134 (looking-at "END[ \t]*$")))
135 (setq content
(buffer-substring beg
(1- (point-at-bol))))
136 (delete-region beg
(1+ (match-end 0))))
138 (when (and org-inlinetask-export
139 (string-match org-complex-heading-regexp headline
))
140 (when (memq org-inlinetask-export
'(arrow+content arrow
))
141 (insert "\n\n\\Rightarrow\\Rightarrow\\Rightarrow *"
142 (if (match-end 2) (concat (match-string 2 headline
) " ") "")
143 (match-string 4 headline
) "*\n"))
144 (when (and content
(eq org-inlinetask-export
'arrow
+content
))
145 (insert "#+BEGIN_EXAMPLE\n" content
"\n#+END_EXAMPLE\n"))
148 (defun org-inlinetask-fontify (limit)
149 "Fontify the inline tasks."
150 (let* ((nstars (if org-odd-levels-only
151 (1- (* 2 (or org-inlinetask-min-level
200)))
152 (or org-inlinetask-min-level
200)))
153 (re (concat "^\\(\\*\\)\\(\\*\\{"
154 (format "%d" (- nstars
3))
155 ",\\}\\)\\(\\*\\* .*\\)")))
156 (while (re-search-forward re limit t
)
157 (add-text-properties (match-beginning 1) (match-end 1)
158 '(face org-warning font-lock-fontified t
))
159 (add-text-properties (match-beginning 2) (match-end 2)
160 '(face org-hide font-lock-fontified t
))
161 (add-text-properties (match-beginning 3) (match-end 3)
162 '(face shadow font-lock-fontified t
)))))
164 (eval-after-load "org-exp"
165 '(add-hook 'org-export-preprocess-after-tree-selection-hook
166 'org-inlinetask-export-handler
))
167 (eval-after-load "org"
168 '(add-hook 'org-font-lock-hook
'org-inlinetask-fontify
))
170 (provide 'org-inlinetask
)
172 ;;; org-inlinetask.el ends here