2009-03-30 07:15:36 -04:00
|
|
|
;;; org-inlinetask.el --- Tasks independent of outline hierarchy
|
2009-08-08 00:34:24 -04:00
|
|
|
|
2012-03-17 09:36:25 -04:00
|
|
|
;; Copyright (C) 2009-2012 Free Software Foundation, Inc.
|
2009-03-29 11:31:20 -04:00
|
|
|
;;
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
2009-08-08 00:34:24 -04:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
2009-03-29 11:31:20 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2009-08-08 00:34:24 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2009-03-29 11:31:20 -04:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2009-08-08 00:34:24 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-03-29 11:31:20 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
2009-03-30 07:15:36 -04:00
|
|
|
;; 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.
|
|
|
|
;;
|
2010-07-16 17:22:01 -04:00
|
|
|
;; Visibility cycling exempts these nodes from cycling. So whenever their
|
2009-03-30 07:15:36 -04:00
|
|
|
;; parent is opened, so are these tasks. This will only work with
|
2009-11-12 07:39:29 -05:00
|
|
|
;; `org-cycle', so if you are also using other commands to show/hide
|
2009-03-30 07:15:36 -04:00
|
|
|
;; 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
|
2011-01-30 11:42:38 -05:00
|
|
|
;; formatted in some special way. This in handled by
|
|
|
|
;; `org-inlinetask-export' and `org-inlinetask-export-templates'
|
|
|
|
;; variables.
|
2009-03-30 07:15:36 -04:00
|
|
|
;;
|
|
|
|
;; 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.
|
|
|
|
;;
|
2010-12-21 05:06:58 -05:00
|
|
|
;; If you need to have a time planning line (DEADLINE etc), drawers,
|
|
|
|
;; for example LOGBOOK of PROPERTIES, or even normal text as part of
|
|
|
|
;; the inline task, you must add an "END" headline with the same
|
|
|
|
;; number of stars.
|
2009-03-30 07:15:36 -04:00
|
|
|
;;
|
2010-12-21 05:06:58 -05:00
|
|
|
;; As an example, here are two valid inline tasks:
|
|
|
|
;;
|
|
|
|
;; **************** TODO a small task
|
|
|
|
;;
|
|
|
|
;; and
|
|
|
|
;;
|
|
|
|
;; **************** TODO another small task
|
2009-03-30 07:15:36 -04:00
|
|
|
;; DEADLINE: <2009-03-30 Mon>
|
|
|
|
;; :PROPERTIES:
|
|
|
|
;; :SOMETHING: or other
|
|
|
|
;; :END:
|
|
|
|
;; And here is some extra text
|
|
|
|
;; **************** END
|
2009-07-19 03:42:22 -04:00
|
|
|
;;
|
|
|
|
;; Also, if you want to use refiling and archiving for inline tasks,
|
|
|
|
;; The END line must be present to make things work properly.
|
|
|
|
;;
|
2009-11-12 07:39:29 -05:00
|
|
|
;; This package installs one new command:
|
2009-07-19 03:42:22 -04:00
|
|
|
;;
|
|
|
|
;; C-c C-x t Insert a new inline task with END line
|
|
|
|
|
2010-07-16 17:22:01 -04:00
|
|
|
;;; Code:
|
2009-03-29 11:31:20 -04:00
|
|
|
|
2009-07-20 03:16:28 -04:00
|
|
|
(require 'org)
|
|
|
|
|
2009-03-30 07:15:36 -04:00
|
|
|
(defgroup org-inlinetask nil
|
|
|
|
"Options concerning inline tasks in Org mode."
|
|
|
|
:tag "Org Inline Tasks"
|
|
|
|
:group 'org-structure)
|
2009-03-29 11:31:20 -04:00
|
|
|
|
2009-03-30 07:15:36 -04:00
|
|
|
(defcustom org-inlinetask-min-level 15
|
|
|
|
"Minimum level a headline must have before it is treated as an inline task.
|
|
|
|
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
|
|
|
|
the value of this variable."
|
|
|
|
:group 'org-inlinetask
|
2010-10-14 04:29:56 -04:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Off" nil)
|
|
|
|
(integer)))
|
2009-03-29 11:31:20 -04:00
|
|
|
|
2009-10-12 18:00:19 -04:00
|
|
|
(defcustom org-inlinetask-export t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means export inline tasks.
|
2009-10-12 03:28:02 -04:00
|
|
|
When nil, they will not be exported."
|
|
|
|
:group 'org-inlinetask
|
|
|
|
:type 'boolean)
|
|
|
|
|
2010-11-07 06:32:28 -05:00
|
|
|
(defvar org-inlinetask-export-templates
|
2011-08-11 16:07:45 -04:00
|
|
|
'((html "<div class=\"inlinetask\"><b>%s%s</b><br />%s</div>"
|
2010-11-07 06:32:28 -05:00
|
|
|
'((unless (eq todo "")
|
|
|
|
(format "<span class=\"%s %s\">%s%s</span> "
|
|
|
|
class todo todo priority))
|
|
|
|
heading content))
|
2011-08-11 16:07:45 -04:00
|
|
|
(odt "%s" '((org-odt-format-inlinetask heading content
|
|
|
|
todo priority tags)))
|
|
|
|
|
2011-03-17 07:12:31 -04:00
|
|
|
(latex "\\begin\{description\}\n\\item[%s%s]~%s\\end\{description\}"
|
2010-11-07 06:32:28 -05:00
|
|
|
'((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.
|
|
|
|
|
2011-08-11 08:10:35 -04:00
|
|
|
This variable is an alist in the shape of \(BACKEND STRING OBJECTS\).
|
2010-11-07 06:32:28 -05:00
|
|
|
|
2011-08-11 08:10:35 -04:00
|
|
|
BACKEND is the name of the backend for the template \(ascii, html...\).
|
2010-11-07 06:32:28 -05:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2011-08-11 08:10:35 -04:00
|
|
|
\(html \"<ul><li>%s <p>%s</p></li></ul>\" \(heading content\)\)
|
2010-11-07 06:32:28 -05:00
|
|
|
|
2010-12-06 13:24:00 -05:00
|
|
|
or, with the additional package \"todonotes\" for LaTeX,
|
2010-11-07 06:32:28 -05:00
|
|
|
|
2011-08-11 08:10:35 -04:00
|
|
|
\(latex \"\\todo[inline]{\\textbf{\\textsf{%s %s}}\\linebreak{} %s}\"
|
|
|
|
'\(\(unless \(eq todo \"\"\)
|
|
|
|
\(format \"\\textsc{%s%s}\" todo priority\)\)
|
|
|
|
heading content\)\)\)")
|
2010-11-07 06:32:28 -05:00
|
|
|
|
2009-03-31 14:12:37 -04:00
|
|
|
(defvar org-odd-levels-only)
|
|
|
|
(defvar org-keyword-time-regexp)
|
|
|
|
(defvar org-drawer-regexp)
|
|
|
|
(defvar org-complex-heading-regexp)
|
|
|
|
(defvar org-property-end-re)
|
2009-07-19 03:42:22 -04:00
|
|
|
|
2010-10-19 13:08:28 -04:00
|
|
|
(defcustom org-inlinetask-default-state nil
|
2010-04-20 12:31:03 -04:00
|
|
|
"Non-nil means make inline tasks have a TODO keyword initially.
|
|
|
|
This should be the state `org-inlinetask-insert-task' should use by
|
|
|
|
default, or nil of no state should be assigned."
|
|
|
|
:group 'org-inlinetask
|
2010-04-21 03:10:57 -04:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "No state" nil)
|
|
|
|
(string :tag "Specific state")))
|
2010-04-20 12:31:03 -04:00
|
|
|
|
|
|
|
(defun org-inlinetask-insert-task (&optional no-state)
|
|
|
|
"Insert an inline task.
|
2010-10-19 13:08:28 -04:00
|
|
|
If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'."
|
2010-04-20 12:31:03 -04:00
|
|
|
(interactive "P")
|
2011-08-11 08:09:55 -04:00
|
|
|
;; 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"))
|
2009-07-19 03:42:22 -04:00
|
|
|
(or (bolp) (newline))
|
2011-07-21 13:02:35 -04:00
|
|
|
(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"))
|
2009-07-19 03:42:22 -04:00
|
|
|
(end-of-line -1))
|
|
|
|
(define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
|
|
|
|
|
2010-11-06 05:10:22 -04:00
|
|
|
(defun org-inlinetask-outline-regexp ()
|
|
|
|
"Return string matching an inline task heading.
|
|
|
|
The number of levels is controlled by `org-inlinetask-min-level'."
|
|
|
|
(let ((nstars (if org-odd-levels-only
|
|
|
|
(1- (* org-inlinetask-min-level 2))
|
|
|
|
org-inlinetask-min-level)))
|
|
|
|
(format "^\\(\\*\\{%d,\\}\\)[ \t]+" nstars)))
|
|
|
|
|
2011-01-30 11:42:38 -05:00
|
|
|
(defun org-inlinetask-at-task-p ()
|
|
|
|
"Return true if point is at beginning of an inline task."
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line)
|
|
|
|
(and (looking-at (concat (org-inlinetask-outline-regexp) "\\(.*\\)"))
|
|
|
|
(not (string-match "^end[ \t]*$" (downcase (match-string 2)))))))
|
|
|
|
|
2010-10-14 04:16:06 -04:00
|
|
|
(defun org-inlinetask-in-task-p ()
|
|
|
|
"Return true if point is inside an inline task."
|
|
|
|
(save-excursion
|
2010-12-21 05:06:58 -05:00
|
|
|
(beginning-of-line)
|
|
|
|
(let* ((case-fold-search t)
|
|
|
|
(stars-re (org-inlinetask-outline-regexp))
|
2010-10-14 04:16:06 -04:00
|
|
|
(task-beg-re (concat stars-re "\\(?:.*\\)"))
|
2010-12-21 05:06:58 -05:00
|
|
|
(task-end-re (concat stars-re "END[ \t]*$")))
|
|
|
|
(or (org-looking-at-p task-beg-re)
|
2010-10-14 04:16:06 -04:00
|
|
|
(and (re-search-forward "^\\*+[ \t]+" nil t)
|
2010-12-21 05:06:58 -05:00
|
|
|
(progn (beginning-of-line) (org-looking-at-p task-end-re)))))))
|
2010-10-14 04:16:06 -04:00
|
|
|
|
2010-11-06 05:10:22 -04:00
|
|
|
(defun org-inlinetask-goto-beginning ()
|
|
|
|
"Go to the beginning of the inline task at point."
|
|
|
|
(end-of-line)
|
2010-12-21 05:06:58 -05:00
|
|
|
(let ((case-fold-search t)
|
|
|
|
(inlinetask-re (org-inlinetask-outline-regexp)))
|
|
|
|
(re-search-backward inlinetask-re nil t)
|
|
|
|
(when (org-looking-at-p (concat inlinetask-re "END[ \t]*$"))
|
|
|
|
(re-search-backward inlinetask-re nil t))))
|
2010-11-06 05:10:22 -04:00
|
|
|
|
|
|
|
(defun org-inlinetask-goto-end ()
|
2011-08-30 08:28:36 -04:00
|
|
|
"Go to the end of the inline task at point.
|
|
|
|
Return point."
|
2011-09-01 02:49:28 -04:00
|
|
|
(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]*$")))
|
2011-08-30 08:28:36 -04:00
|
|
|
(cond
|
2011-09-01 02:49:28 -04:00
|
|
|
((looking-at task-end-re) (forward-line))
|
|
|
|
((looking-at inlinetask-re)
|
2011-08-30 08:28:36 -04:00
|
|
|
(forward-line)
|
2011-09-01 02:49:28 -04:00
|
|
|
(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))))
|
2010-11-06 05:10:22 -04:00
|
|
|
|
|
|
|
(defun org-inlinetask-get-task-level ()
|
|
|
|
"Get the level of the inline task around.
|
|
|
|
This assumes the point is inside an inline task."
|
|
|
|
(save-excursion
|
|
|
|
(end-of-line)
|
|
|
|
(re-search-backward (org-inlinetask-outline-regexp) nil t)
|
|
|
|
(- (match-end 1) (match-beginning 1))))
|
|
|
|
|
2011-03-02 16:56:04 -05:00
|
|
|
(defun org-inlinetask-promote ()
|
|
|
|
"Promote the inline task at point.
|
|
|
|
If the task has an end part, promote it. Also, prevents level from
|
|
|
|
going below `org-inlinetask-min-level'."
|
|
|
|
(interactive)
|
|
|
|
(if (not (org-inlinetask-in-task-p))
|
|
|
|
(error "Not in an inline task")
|
|
|
|
(save-excursion
|
|
|
|
(let* ((lvl (org-inlinetask-get-task-level))
|
|
|
|
(next-lvl (org-get-valid-level lvl -1))
|
|
|
|
(diff (- next-lvl lvl))
|
|
|
|
(down-task (concat (make-string next-lvl ?*)))
|
|
|
|
beg)
|
|
|
|
(if (< next-lvl org-inlinetask-min-level)
|
|
|
|
(error "Cannot promote an inline task at minimum level")
|
|
|
|
(org-inlinetask-goto-beginning)
|
|
|
|
(setq beg (point))
|
|
|
|
(replace-match down-task nil t nil 1)
|
|
|
|
(org-inlinetask-goto-end)
|
|
|
|
(if (eobp) (beginning-of-line) (forward-line -1))
|
|
|
|
(unless (= (point) beg)
|
|
|
|
(replace-match down-task nil t nil 1)
|
|
|
|
(when org-adapt-indentation
|
|
|
|
(goto-char beg)
|
|
|
|
(org-fixup-indentation diff))))))))
|
|
|
|
|
|
|
|
(defun org-inlinetask-demote ()
|
|
|
|
"Demote the inline task at point.
|
|
|
|
If the task has an end part, also demote it."
|
|
|
|
(interactive)
|
|
|
|
(if (not (org-inlinetask-in-task-p))
|
|
|
|
(error "Not in an inline task")
|
|
|
|
(save-excursion
|
|
|
|
(let* ((lvl (org-inlinetask-get-task-level))
|
|
|
|
(next-lvl (org-get-valid-level lvl 1))
|
|
|
|
(diff (- next-lvl lvl))
|
|
|
|
(down-task (concat (make-string next-lvl ?*)))
|
|
|
|
beg)
|
|
|
|
(org-inlinetask-goto-beginning)
|
|
|
|
(setq beg (point))
|
|
|
|
(replace-match down-task nil t nil 1)
|
|
|
|
(org-inlinetask-goto-end)
|
|
|
|
(if (eobp) (beginning-of-line) (forward-line -1))
|
|
|
|
(unless (= (point) beg)
|
|
|
|
(replace-match down-task nil t nil 1)
|
|
|
|
(when org-adapt-indentation
|
|
|
|
(goto-char beg)
|
|
|
|
(org-fixup-indentation diff)))))))
|
|
|
|
|
2011-03-01 14:01:42 -05:00
|
|
|
(defvar org-export-current-backend) ; dynamically bound in org-exp.el
|
2009-03-29 11:31:20 -04:00
|
|
|
(defun org-inlinetask-export-handler ()
|
2009-03-30 07:15:36 -04:00
|
|
|
"Handle headlines with level larger or equal to `org-inlinetask-min-level'.
|
2009-03-29 11:31:20 -04:00
|
|
|
Either remove headline and meta data, or do special formatting."
|
|
|
|
(goto-char (point-min))
|
2011-03-17 07:12:31 -04:00
|
|
|
(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.
|
2009-03-31 14:12:37 -04:00
|
|
|
(goto-char beg)
|
2011-03-17 07:12:31 -04:00
|
|
|
(delete-region beg end)
|
2011-08-06 10:34:35 -04:00
|
|
|
(when (and org-inlinetask-export
|
|
|
|
(assq org-export-current-backend
|
|
|
|
org-inlinetask-export-templates))
|
2011-03-17 07:12:31 -04:00
|
|
|
;; 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.
|
2011-08-11 16:07:45 -04:00
|
|
|
(when (string-match "\\`\\([ \t]*\n\\)+" content)
|
2011-03-17 07:12:31 -04:00
|
|
|
(setq content (substring content (match-end 0))))
|
|
|
|
(when (string-match "[ \t\n]+\\'" content)
|
2009-10-12 03:28:02 -04:00
|
|
|
(setq content (substring content 0 (match-beginning 0))))
|
2011-08-11 16:07:45 -04:00
|
|
|
(org-add-props
|
|
|
|
(concat "\n\n" (org-remove-indentation content) "\n\n")
|
|
|
|
'(org-protected nil org-native-text nil))))
|
|
|
|
|
2010-11-07 06:32:28 -05:00
|
|
|
(when (string-match org-complex-heading-regexp headline)
|
2011-03-17 07:12:31 -04:00
|
|
|
(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) ""))
|
2010-11-07 06:32:28 -05:00
|
|
|
(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) ""))
|
2011-03-17 07:12:31 -04:00
|
|
|
;; Read `org-inlinetask-export-templates'.
|
|
|
|
(backend-spec (assq org-export-current-backend
|
2011-03-01 14:01:42 -05:00
|
|
|
org-inlinetask-export-templates))
|
2011-01-10 12:39:06 -05:00
|
|
|
(format-str (org-add-props (nth 1 backend-spec)
|
2011-08-11 16:07:45 -04:00
|
|
|
'(org-protected t org-native-text t)))
|
2010-11-07 06:32:28 -05:00
|
|
|
(tokens (cadr (nth 2 backend-spec)))
|
2011-03-17 07:12:31 -04:00
|
|
|
;; Build export string. Ensure it won't break
|
|
|
|
;; surrounding lists by giving it arbitrary high
|
|
|
|
;; indentation.
|
2010-11-07 06:32:28 -05:00
|
|
|
(export-str (org-add-props
|
|
|
|
(eval (append '(format format-str)
|
|
|
|
(mapcar nil-to-str tokens)))
|
2011-01-10 12:39:06 -05:00
|
|
|
'(original-indentation 1000))))
|
2011-08-08 14:21:41 -04:00
|
|
|
;; Ensure task starts a new paragraph.
|
|
|
|
(unless (or (bobp)
|
|
|
|
(save-excursion (forward-line -1)
|
|
|
|
(looking-at "[ \t]*$")))
|
|
|
|
(insert "\n"))
|
2011-03-17 07:12:31 -04:00
|
|
|
(insert export-str)
|
|
|
|
(unless (bolp) (insert "\n")))))))))
|
2009-10-02 07:00:22 -04:00
|
|
|
|
|
|
|
(defun org-inlinetask-get-current-indentation ()
|
|
|
|
"Get the indentation of the last non-while line above this one."
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(skip-chars-backward " \t\n")
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(or (org-at-item-p)
|
|
|
|
(looking-at "[ \t]*"))
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(current-column)))
|
2009-03-29 11:31:20 -04:00
|
|
|
|
2011-07-21 13:02:35 -04:00
|
|
|
(defvar org-indent-indentation-per-level) ; defined in org-indent.el
|
2011-08-01 18:24:50 -04:00
|
|
|
|
|
|
|
(defface org-inlinetask
|
|
|
|
(org-compatible-face 'shadow '((t (:bold t))))
|
|
|
|
"Face for inlinetask headlines."
|
|
|
|
:group 'org-faces)
|
|
|
|
|
2009-03-29 11:31:20 -04:00
|
|
|
(defun org-inlinetask-fontify (limit)
|
2011-08-23 15:26:51 -04:00
|
|
|
"Fontify the inline tasks down to LIMIT."
|
2009-03-29 11:31:20 -04:00
|
|
|
(let* ((nstars (if org-odd-levels-only
|
2009-03-30 07:15:36 -04:00
|
|
|
(1- (* 2 (or org-inlinetask-min-level 200)))
|
|
|
|
(or org-inlinetask-min-level 200)))
|
2009-03-29 11:31:20 -04:00
|
|
|
(re (concat "^\\(\\*\\)\\(\\*\\{"
|
2009-03-30 07:15:36 -04:00
|
|
|
(format "%d" (- nstars 3))
|
2011-07-21 13:02:35 -04:00
|
|
|
",\\}\\)\\(\\*\\* .*\\)"))
|
|
|
|
;; 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)))
|
2009-03-29 11:31:20 -04:00
|
|
|
(while (re-search-forward re limit t)
|
2012-03-17 09:34:01 -04:00
|
|
|
(add-text-properties (match-beginning 1) (match-end 1)
|
|
|
|
`(face ,start-face font-lock-fontified t))
|
|
|
|
(add-text-properties (match-beginning 2) (match-end 2)
|
2009-03-29 11:31:20 -04:00
|
|
|
'(face org-hide font-lock-fontified t))
|
|
|
|
(add-text-properties (match-beginning 3) (match-end 3)
|
2011-08-01 18:24:50 -04:00
|
|
|
'(face org-inlinetask font-lock-fontified t)))))
|
2009-03-29 11:31:20 -04:00
|
|
|
|
2011-01-30 11:42:38 -05:00
|
|
|
(defun org-inlinetask-toggle-visibility ()
|
|
|
|
"Toggle visibility of inline task at point."
|
|
|
|
(let ((end (save-excursion
|
|
|
|
(org-inlinetask-goto-end)
|
|
|
|
(if (bolp) (1- (point)) (point))))
|
|
|
|
(start (save-excursion
|
|
|
|
(org-inlinetask-goto-beginning)
|
|
|
|
(point-at-eol))))
|
|
|
|
(cond
|
|
|
|
;; Nothing to show/hide.
|
|
|
|
((= end start))
|
|
|
|
;; Inlinetask was folded: expand it.
|
|
|
|
((get-char-property (1+ start) 'invisible)
|
2012-03-17 09:34:01 -04:00
|
|
|
(outline-flag-region start end nil))
|
2011-01-30 11:42:38 -05:00
|
|
|
(t (outline-flag-region start end t)))))
|
|
|
|
|
2009-07-19 03:42:22 -04:00
|
|
|
(defun org-inlinetask-remove-END-maybe ()
|
|
|
|
"Remove an END line when present."
|
|
|
|
(when (looking-at (format "\\([ \t]*\n\\)*\\*\\{%d,\\}[ \t]+END[ \t]*$"
|
|
|
|
org-inlinetask-min-level))
|
|
|
|
(replace-match "")))
|
|
|
|
|
2009-03-29 11:31:20 -04:00
|
|
|
(eval-after-load "org-exp"
|
2011-01-10 12:39:06 -05:00
|
|
|
'(add-hook 'org-export-preprocess-before-backend-specifics-hook
|
2009-03-29 11:31:20 -04:00
|
|
|
'org-inlinetask-export-handler))
|
|
|
|
(eval-after-load "org"
|
|
|
|
'(add-hook 'org-font-lock-hook 'org-inlinetask-fontify))
|
|
|
|
|
|
|
|
(provide 'org-inlinetask)
|
|
|
|
|
|
|
|
;;; org-inlinetask.el ends here
|