;;; org-inlinetask.el --- Tasks independent of outline hierarchy
-;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
-;; Version: 7.7
;; This file is part of GNU Emacs.
;;; Commentary:
;;
;; This module implements inline tasks in Org-mode. Inline tasks are
-;; tasks that have all the properties of normal outline nodes, including
-;; the ability to store meta data like scheduling dates, TODO state, tags
-;; and properties. However, these nodes are treated specially by the
-;; visibility cycling and export commands.
+;; tasks that have all the properties of normal outline nodes,
+;; including the ability to store meta data like scheduling dates,
+;; TODO state, tags and properties. However, these nodes are treated
+;; specially by the visibility cycling.
;;
-;; Visibility cycling exempts these nodes from cycling. So whenever their
-;; parent is opened, so are these tasks. This will only work with
-;; `org-cycle', so if you are also using other commands to show/hide
-;; entries, you will occasionally find these tasks to behave like
-;; all other outline nodes, seemingly splitting the text of the parent
-;; into children.
+;; Visibility cycling exempts these nodes from cycling. So whenever
+;; their parent is opened, so are these tasks. This will only work
+;; with `org-cycle', so if you are also using other commands to
+;; show/hide entries, you will occasionally find these tasks to behave
+;; like all other outline nodes, seemingly splitting the text of the
+;; parent into children.
;;
-;; Export commands do not treat these nodes as part of the sectioning
-;; structure, but as a special inline text that is either removed, or
-;; formatted in some special way. This in handled by
-;; `org-inlinetask-export' and `org-inlinetask-export-templates'
-;; variables.
+;; Special fontification of inline tasks, so that they can be
+;; immediately recognized. From the stars of the headline, only the
+;; first and the last two will be visible, the others will be hidden
+;; using the `org-hide' face.
;;
-;; Special fontification of inline tasks, so that they can be immediately
-;; recognized. From the stars of the headline, only the first and the
-;; last two will be visible, the others will be hidden using the
-;; `org-hide' face.
-;;
-;; An inline task is identified solely by a minimum outline level, given
-;; by the variable `org-inlinetask-min-level', default 15.
+;; An inline task is identified solely by a minimum outline level,
+;; given by the variable `org-inlinetask-min-level', default 15.
;;
;; If you need to have a time planning line (DEADLINE etc), drawers,
;; for example LOGBOOK of PROPERTIES, or even normal text as part of
;; Also, if you want to use refiling and archiving for inline tasks,
;; The END line must be present to make things work properly.
;;
+;; Note that you should not try to use inline tasks within plain list,
+;; visibility cycling is known to be problematic when doing so.
+;;
;; This package installs one new command:
;;
;; C-c C-x t Insert a new inline task with END line
(defcustom org-inlinetask-min-level 15
"Minimum level a headline must have before it is treated as an inline task.
+Don't set it to something higher than `29' or clocking will break since this
+is the hardcoded maximum number of stars `org-clock-sum' will work with.
+
It is strongly recommended that you set `org-cycle-max-level' not at all,
or to a number smaller than this one. In fact, when `org-cycle-max-level' is
not set, it will be assumed to be one less than the value of smaller than
(const :tag "Off" nil)
(integer)))
-(defcustom org-inlinetask-export t
- "Non-nil means export inline tasks.
-When nil, they will not be exported."
- :group 'org-inlinetask
+(defcustom org-inlinetask-show-first-star nil
+ "Non-nil means display the first star of an inline task as additional marker.
+When nil, the first star is not shown."
+ :tag "Org Inline Tasks"
+ :group 'org-structure
:type 'boolean)
-(defvar org-inlinetask-export-templates
- '((html "<pre class=\"inlinetask\"><b>%s%s</b><br />%s</pre>"
- '((unless (eq todo "")
- (format "<span class=\"%s %s\">%s%s</span> "
- class todo todo priority))
- heading content))
- (latex "\\begin\{description\}\n\\item[%s%s]~%s\\end\{description\}"
- '((unless (eq todo "") (format "\\textsc\{%s%s\} " todo priority))
- heading content))
- (ascii " -- %s%s%s"
- '((unless (eq todo "") (format "%s%s " todo priority))
- heading
- (unless (eq content "")
- (format "\n ¦ %s"
- (mapconcat 'identity (org-split-string content "\n")
- "\n ¦ ")))))
- (docbook "<variablelist>
-<varlistentry>
-<term>%s%s</term>
-<listitem><para>%s</para></listitem>
-</varlistentry>
-</variablelist>"
- '((unless (eq todo "") (format "%s%s " todo priority))
- heading content)))
- "Templates for inline tasks in various exporters.
-
-This variable is an alist in the shape of (BACKEND STRING OBJECTS).
-
-BACKEND is the name of the backend for the template (ascii, html...).
-
-STRING is a format control string.
-
-OBJECTS is a list of elements to be substituted into the format
-string. They can be of any type, from a string to a form
-returning a value (thus allowing conditional insertion). A nil
-object will be substituted as the empty string. Obviously, there
-must be at least as many objects as %-sequences in the format
-string.
-
-Moreover, the following special keywords are provided: `todo',
-`priority', `heading', `content', `tags'. If some of them are not
-defined in an inline task, their value is the empty string.
-
-As an example, valid associations are:
-
-(html \"<ul><li>%s <p>%s</p></li></ul>\" (heading content))
-
-or, with the additional package \"todonotes\" for LaTeX,
-
-(latex \"\\todo[inline]{\\textbf{\\textsf{%s %s}}\\linebreak{} %s}\"
- '((unless (eq todo \"\")
- (format \"\\textsc{%s%s}\" todo priority))
- heading content)))")
-
(defvar org-odd-levels-only)
(defvar org-keyword-time-regexp)
(defvar org-drawer-regexp)
This should be the state `org-inlinetask-insert-task' should use by
default, or nil of no state should be assigned."
:group 'org-inlinetask
+ :version "24.1"
:type '(choice
(const :tag "No state" nil)
(string :tag "Specific state")))
"Insert an inline task.
If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'."
(interactive "P")
+ ;; Error when inside an inline task, except if point was at its very
+ ;; beginning, in which case the new inline task will be inserted
+ ;; before this one.
+ (when (and (org-inlinetask-in-task-p)
+ (not (and (org-inlinetask-at-task-p) (bolp))))
+ (error "Cannot nest inline tasks"))
(or (bolp) (newline))
- (let ((indent org-inlinetask-min-level))
- (if org-odd-levels-only
- (setq indent (- (* 2 indent) 1)))
- (insert (make-string indent ?*)
- (if (or no-state (not org-inlinetask-default-state))
- " \n"
- (concat " " org-inlinetask-default-state " \n"))
- (make-string indent ?*) " END\n"))
+ (let* ((indent (if org-odd-levels-only
+ (1- (* 2 org-inlinetask-min-level))
+ org-inlinetask-min-level))
+ (indent-string (concat (make-string indent ?*) " ")))
+ (insert indent-string
+ (if (or no-state (not org-inlinetask-default-state))
+ "\n"
+ (concat org-inlinetask-default-state " \n"))
+ indent-string "END\n"))
(end-of-line -1))
(define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
(re-search-backward inlinetask-re nil t))))
(defun org-inlinetask-goto-end ()
- "Go to the end of the inline task at point."
- (beginning-of-line)
- (let ((case-fold-search t)
- (inlinetask-re (org-inlinetask-outline-regexp)))
- (cond
- ((org-looking-at-p (concat inlinetask-re "END[ \t]*$"))
- (forward-line 1))
- ((org-looking-at-p inlinetask-re)
- (forward-line 1)
- (when (org-inlinetask-in-task-p)
- (re-search-forward inlinetask-re nil t)
- (forward-line 1)))
- (t
- (re-search-forward inlinetask-re nil t)
- (forward-line 1)))))
+ "Go to the end of the inline task at point.
+Return point."
+ (save-match-data
+ (beginning-of-line)
+ (let* ((case-fold-search t)
+ (inlinetask-re (org-inlinetask-outline-regexp))
+ (task-end-re (concat inlinetask-re "END[ \t]*$")))
+ (cond
+ ((looking-at task-end-re) (forward-line))
+ ((looking-at inlinetask-re)
+ (forward-line)
+ (cond
+ ((looking-at task-end-re) (forward-line))
+ ((looking-at inlinetask-re))
+ ((org-inlinetask-in-task-p)
+ (re-search-forward inlinetask-re nil t)
+ (forward-line))))
+ (t (re-search-forward inlinetask-re nil t)
+ (forward-line)))
+ (point))))
(defun org-inlinetask-get-task-level ()
"Get the level of the inline task around.
(goto-char beg)
(org-fixup-indentation diff)))))))
-(defvar org-export-current-backend) ; dynamically bound in org-exp.el
-(defun org-inlinetask-export-handler ()
- "Handle headlines with level larger or equal to `org-inlinetask-min-level'.
-Either remove headline and meta data, or do special formatting."
- (goto-char (point-min))
- (let* ((keywords-re (concat "^[ \t]*" org-keyword-time-regexp))
- (inline-re (concat (org-inlinetask-outline-regexp) ".*")))
- (while (re-search-forward inline-re nil t)
- (let ((headline (match-string 0))
- (beg (point-at-bol))
- (end (copy-marker (save-excursion
- (org-inlinetask-goto-end) (point))))
- content)
- ;; Delete SCHEDULED, DEADLINE...
- (while (re-search-forward keywords-re end t)
- (delete-region (point-at-bol) (1+ (point-at-eol))))
- (goto-char beg)
- ;; Delete drawers
- (while (re-search-forward org-drawer-regexp end t)
- (when (save-excursion (re-search-forward org-property-end-re nil t))
- (delete-region beg (1+ (match-end 0)))))
- ;; Get CONTENT, if any.
- (goto-char beg)
- (forward-line 1)
- (unless (= (point) end)
- (setq content (buffer-substring (point)
- (save-excursion (goto-char end)
- (forward-line -1)
- (point)))))
- ;; Remove the task.
- (goto-char beg)
- (delete-region beg end)
- (when org-inlinetask-export
- ;; Format CONTENT, if appropriate.
- (setq content
- (if (not (and content (string-match "\\S-" content)))
- ""
- ;; Ensure CONTENT has minimal indentation, a single
- ;; newline character at its boundaries, and isn't
- ;; protected.
- (when (string-match "`\\([ \t]*\n\\)+" content)
- (setq content (substring content (match-end 0))))
- (when (string-match "[ \t\n]+\\'" content)
- (setq content (substring content 0 (match-beginning 0))))
- (org-add-props (concat "\n" (org-remove-indentation content) "\n")
- '(org-protected nil))))
- (when (string-match org-complex-heading-regexp headline)
- (let* ((nil-to-str
- (function
- ;; Change nil arguments into empty strings.
- (lambda (el) (or (eval el) ""))))
- ;; Set up keywords provided to templates.
- (todo (or (match-string 2 headline) ""))
- (class (or (and (eq "" todo) "")
- (if (member todo org-done-keywords) "done" "todo")))
- (priority (or (match-string 3 headline) ""))
- (heading (or (match-string 4 headline) ""))
- (tags (or (match-string 5 headline) ""))
- ;; Read `org-inlinetask-export-templates'.
- (backend-spec (assq org-export-current-backend
- org-inlinetask-export-templates))
- (format-str (org-add-props (nth 1 backend-spec)
- '(org-protected t)))
- (tokens (cadr (nth 2 backend-spec)))
- ;; Build export string. Ensure it won't break
- ;; surrounding lists by giving it arbitrary high
- ;; indentation.
- (export-str (org-add-props
- (eval (append '(format format-str)
- (mapcar nil-to-str tokens)))
- '(original-indentation 1000))))
- (insert export-str)
- (unless (bolp) (insert "\n")))))))))
-
(defun org-inlinetask-get-current-indentation ()
"Get the indentation of the last non-while line above this one."
(save-excursion
(goto-char (match-end 0))
(current-column)))
+(defvar org-indent-indentation-per-level) ; defined in org-indent.el
+
+(defface org-inlinetask
+ (org-compatible-face 'shadow '((t (:bold t))))
+ "Face for inlinetask headlines."
+ :group 'org-faces)
+
(defun org-inlinetask-fontify (limit)
- "Fontify the inline tasks."
+ "Fontify the inline tasks down to LIMIT."
(let* ((nstars (if org-odd-levels-only
(1- (* 2 (or org-inlinetask-min-level 200)))
(or org-inlinetask-min-level 200)))
(re (concat "^\\(\\*\\)\\(\\*\\{"
- (format "%d" (- nstars 3))
- ",\\}\\)\\(\\*\\* .*\\)")))
+ (format "%d" (- nstars 3))
+ ",\\}\\)\\(\\*\\* .*\\)"))
+ ;; Virtual indentation will add the warning face on the first
+ ;; star. Thus, in that case, only hide it.
+ (start-face (if (and (org-bound-and-true-p org-indent-mode)
+ (> org-indent-indentation-per-level 1))
+ 'org-hide
+ 'org-warning)))
(while (re-search-forward re limit t)
- (add-text-properties (match-beginning 1) (match-end 1)
- '(face org-warning font-lock-fontified t))
- (add-text-properties (match-beginning 2) (match-end 2)
+ (if org-inlinetask-show-first-star
+ (add-text-properties (match-beginning 1) (match-end 1)
+ `(face ,start-face font-lock-fontified t)))
+ (add-text-properties (match-beginning
+ (if org-inlinetask-show-first-star 2 1))
+ (match-end 2)
'(face org-hide font-lock-fontified t))
(add-text-properties (match-beginning 3) (match-end 3)
- '(face shadow font-lock-fontified t)))))
+ '(face org-inlinetask font-lock-fontified t)))))
(defun org-inlinetask-toggle-visibility ()
"Toggle visibility of inline task at point."
((= end start))
;; Inlinetask was folded: expand it.
((get-char-property (1+ start) 'invisible)
- (outline-flag-region start end nil))
+ (outline-flag-region start end nil)
+ (org-cycle-hide-drawers 'children))
(t (outline-flag-region start end t)))))
(defun org-inlinetask-remove-END-maybe ()
org-inlinetask-min-level))
(replace-match "")))
-(eval-after-load "org-exp"
- '(add-hook 'org-export-preprocess-before-backend-specifics-hook
- 'org-inlinetask-export-handler))
(eval-after-load "org"
'(add-hook 'org-font-lock-hook 'org-inlinetask-fontify))