2016-06-21 20:42:09 +00:00
|
|
|
;;; org-inlinetask.el --- Tasks Independent of Outline Hierarchy -*- lexical-binding: t; -*-
|
2009-08-08 04:34:24 +00:00
|
|
|
|
2017-01-06 01:19:23 +00:00
|
|
|
;; Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
2009-03-29 15:31:20 +00:00
|
|
|
;;
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
2009-08-08 04:34:24 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
2009-03-29 15:31:20 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2009-08-08 04:34:24 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2009-03-29 15:31:20 +00: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
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-08-08 04:34:24 +00:00
|
|
|
|
2009-03-29 15:31:20 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
2016-10-11 16:00:08 +00:00
|
|
|
;; This module implements inline tasks in Org mode. Inline tasks are
|
2013-01-27 23:02:51 +00:00
|
|
|
;; 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.
|
2009-03-30 11:15:36 +00:00
|
|
|
;;
|
2013-01-27 23:02:51 +00:00
|
|
|
;; 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.
|
2009-03-30 11:15:36 +00:00
|
|
|
;;
|
2013-01-27 23:02:51 +00: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.
|
2009-03-30 11:15:36 +00:00
|
|
|
;;
|
2013-01-27 23:02:51 +00:00
|
|
|
;; An inline task is identified solely by a minimum outline level,
|
|
|
|
;; given by the variable `org-inlinetask-min-level', default 15.
|
2009-03-30 11:15:36 +00:00
|
|
|
;;
|
2010-12-21 10:06:58 +00: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 11:15:36 +00:00
|
|
|
;;
|
2010-12-21 10:06:58 +00:00
|
|
|
;; As an example, here are two valid inline tasks:
|
|
|
|
;;
|
|
|
|
;; **************** TODO a small task
|
|
|
|
;;
|
|
|
|
;; and
|
|
|
|
;;
|
|
|
|
;; **************** TODO another small task
|
2009-03-30 11:15:36 +00:00
|
|
|
;; DEADLINE: <2009-03-30 Mon>
|
|
|
|
;; :PROPERTIES:
|
|
|
|
;; :SOMETHING: or other
|
|
|
|
;; :END:
|
|
|
|
;; And here is some extra text
|
|
|
|
;; **************** END
|
2009-07-19 07:42:22 +00:00
|
|
|
;;
|
|
|
|
;; Also, if you want to use refiling and archiving for inline tasks,
|
|
|
|
;; The END line must be present to make things work properly.
|
|
|
|
;;
|
2012-12-29 10:04:33 +00:00
|
|
|
;; Note that you should not try to use inline tasks within plain list,
|
|
|
|
;; visibility cycling is known to be problematic when doing so.
|
|
|
|
;;
|
2009-11-12 12:39:29 +00:00
|
|
|
;; This package installs one new command:
|
2009-07-19 07:42:22 +00:00
|
|
|
;;
|
|
|
|
;; C-c C-x t Insert a new inline task with END line
|
|
|
|
|
2010-07-16 21:22:01 +00:00
|
|
|
;;; Code:
|
2009-03-29 15:31:20 +00:00
|
|
|
|
2009-07-20 07:16:28 +00:00
|
|
|
(require 'org)
|
|
|
|
|
2009-03-30 11:15:36 +00:00
|
|
|
(defgroup org-inlinetask nil
|
|
|
|
"Options concerning inline tasks in Org mode."
|
|
|
|
:tag "Org Inline Tasks"
|
|
|
|
:group 'org-structure)
|
2009-03-29 15:31:20 +00:00
|
|
|
|
2009-03-30 11:15:36 +00:00
|
|
|
(defcustom org-inlinetask-min-level 15
|
|
|
|
"Minimum level a headline must have before it is treated as an inline task.
|
2012-08-11 17:10:44 +00:00
|
|
|
Don't set it to something higher than `29' or clocking will break since this
|
2012-03-19 20:38:12 +00:00
|
|
|
is the hardcoded maximum number of stars `org-clock-sum' will work with.
|
|
|
|
|
2009-03-30 11:15:36 +00:00
|
|
|
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 08:29:56 +00:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Off" nil)
|
|
|
|
(integer)))
|
2009-03-29 15:31:20 +00:00
|
|
|
|
2012-03-19 20:38:12 +00:00
|
|
|
(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"
|
2013-12-30 09:13:57 +00:00
|
|
|
:group 'org-structure
|
|
|
|
:type 'boolean)
|
2012-03-19 20:38:12 +00:00
|
|
|
|
2009-03-31 18:12:37 +00:00
|
|
|
(defvar org-odd-levels-only)
|
|
|
|
(defvar org-keyword-time-regexp)
|
|
|
|
(defvar org-complex-heading-regexp)
|
|
|
|
(defvar org-property-end-re)
|
2009-07-19 07:42:22 +00:00
|
|
|
|
2010-10-19 17:08:28 +00:00
|
|
|
(defcustom org-inlinetask-default-state nil
|
2010-04-20 16:31:03 +00:00
|
|
|
"Non-nil means make inline tasks have a TODO keyword initially.
|
|
|
|
This should be the state `org-inlinetask-insert-task' should use by
|
2017-10-10 00:15:42 +00:00
|
|
|
default, or nil if no state should be assigned."
|
2010-04-20 16:31:03 +00:00
|
|
|
:group 'org-inlinetask
|
2012-03-19 20:38:12 +00:00
|
|
|
:version "24.1"
|
2010-04-21 07:10:57 +00:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "No state" nil)
|
|
|
|
(string :tag "Specific state")))
|
2010-04-20 16:31:03 +00:00
|
|
|
|
|
|
|
(defun org-inlinetask-insert-task (&optional no-state)
|
|
|
|
"Insert an inline task.
|
2017-10-07 13:44:25 +00:00
|
|
|
If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'.
|
|
|
|
If there is a region wrap it inside the inline task."
|
2010-04-20 16:31:03 +00:00
|
|
|
(interactive "P")
|
2011-08-11 12:09:55 +00: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 07:42:22 +00:00
|
|
|
(or (bolp) (newline))
|
2011-07-21 17:02:35 +00:00
|
|
|
(let* ((indent (if org-odd-levels-only
|
|
|
|
(1- (* 2 org-inlinetask-min-level))
|
|
|
|
org-inlinetask-min-level))
|
2017-10-07 13:44:25 +00:00
|
|
|
(indent-string (concat (make-string indent ?*) " "))
|
|
|
|
(rbeg (if (org-region-active-p) (region-beginning) (point)))
|
|
|
|
(rend (if (org-region-active-p) (region-end) (point))))
|
|
|
|
(goto-char rend)
|
|
|
|
(insert "\n" indent-string "END\n")
|
|
|
|
(goto-char rbeg)
|
|
|
|
(unless (bolp) (insert "\n"))
|
2011-07-21 17:02:35 +00:00
|
|
|
(insert indent-string
|
|
|
|
(if (or no-state (not org-inlinetask-default-state))
|
2017-10-07 13:44:25 +00:00
|
|
|
""
|
|
|
|
(concat org-inlinetask-default-state " "))
|
|
|
|
(if (= rend rbeg) "" "\n"))
|
|
|
|
(unless (= rend rbeg) (end-of-line 0))))
|
2009-07-19 07:42:22 +00:00
|
|
|
(define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
|
|
|
|
|
2010-11-06 09:10:22 +00: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 16:42:38 +00: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 08:16:06 +00:00
|
|
|
(defun org-inlinetask-in-task-p ()
|
|
|
|
"Return true if point is inside an inline task."
|
|
|
|
(save-excursion
|
2010-12-21 10:06:58 +00:00
|
|
|
(beginning-of-line)
|
|
|
|
(let* ((case-fold-search t)
|
|
|
|
(stars-re (org-inlinetask-outline-regexp))
|
2010-10-14 08:16:06 +00:00
|
|
|
(task-beg-re (concat stars-re "\\(?:.*\\)"))
|
2010-12-21 10:06:58 +00:00
|
|
|
(task-end-re (concat stars-re "END[ \t]*$")))
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(or (looking-at-p task-beg-re)
|
2010-10-14 08:16:06 +00:00
|
|
|
(and (re-search-forward "^\\*+[ \t]+" nil t)
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(progn (beginning-of-line) (looking-at-p task-end-re)))))))
|
2010-10-14 08:16:06 +00:00
|
|
|
|
2010-11-06 09:10:22 +00:00
|
|
|
(defun org-inlinetask-goto-beginning ()
|
|
|
|
"Go to the beginning of the inline task at point."
|
|
|
|
(end-of-line)
|
2010-12-21 10:06:58 +00:00
|
|
|
(let ((case-fold-search t)
|
|
|
|
(inlinetask-re (org-inlinetask-outline-regexp)))
|
|
|
|
(re-search-backward inlinetask-re nil t)
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(when (looking-at-p (concat inlinetask-re "END[ \t]*$"))
|
2010-12-21 10:06:58 +00:00
|
|
|
(re-search-backward inlinetask-re nil t))))
|
2010-11-06 09:10:22 +00:00
|
|
|
|
|
|
|
(defun org-inlinetask-goto-end ()
|
2011-08-30 12:28:36 +00:00
|
|
|
"Go to the end of the inline task at point.
|
|
|
|
Return point."
|
2011-09-01 06:49:28 +00: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 12:28:36 +00:00
|
|
|
(cond
|
2015-12-04 18:25:36 +00:00
|
|
|
((looking-at task-end-re))
|
2011-09-01 06:49:28 +00:00
|
|
|
((looking-at inlinetask-re)
|
2011-08-30 12:28:36 +00:00
|
|
|
(forward-line)
|
2011-09-01 06:49:28 +00:00
|
|
|
(cond
|
2015-12-04 18:25:36 +00:00
|
|
|
((looking-at task-end-re))
|
2011-09-01 06:49:28 +00:00
|
|
|
((looking-at inlinetask-re))
|
|
|
|
((org-inlinetask-in-task-p)
|
2015-12-04 18:25:36 +00:00
|
|
|
(re-search-forward inlinetask-re nil t))))
|
|
|
|
(t (re-search-forward inlinetask-re nil t)))
|
|
|
|
(end-of-line)
|
2011-09-01 06:49:28 +00:00
|
|
|
(point))))
|
2010-11-06 09:10:22 +00: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 21:56:04 +00: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)))))))
|
|
|
|
|
2009-10-02 11:00:22 +00: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 15:31:20 +00:00
|
|
|
|
2011-07-21 17:02:35 +00:00
|
|
|
(defvar org-indent-indentation-per-level) ; defined in org-indent.el
|
2011-08-01 22:24:50 +00:00
|
|
|
|
2016-06-30 15:45:04 +00:00
|
|
|
(defface org-inlinetask '((t :inherit shadow))
|
2011-08-01 22:24:50 +00:00
|
|
|
"Face for inlinetask headlines."
|
|
|
|
:group 'org-faces)
|
|
|
|
|
2009-03-29 15:31:20 +00:00
|
|
|
(defun org-inlinetask-fontify (limit)
|
2011-08-23 19:26:51 +00:00
|
|
|
"Fontify the inline tasks down to LIMIT."
|
2009-03-29 15:31:20 +00:00
|
|
|
(let* ((nstars (if org-odd-levels-only
|
2009-03-30 11:15:36 +00:00
|
|
|
(1- (* 2 (or org-inlinetask-min-level 200)))
|
|
|
|
(or org-inlinetask-min-level 200)))
|
2009-03-29 15:31:20 +00:00
|
|
|
(re (concat "^\\(\\*\\)\\(\\*\\{"
|
2012-08-11 17:10:44 +00:00
|
|
|
(format "%d" (- nstars 3))
|
|
|
|
",\\}\\)\\(\\*\\* .*\\)"))
|
2011-07-21 17:02:35 +00:00
|
|
|
;; Virtual indentation will add the warning face on the first
|
2012-08-11 17:10:44 +00:00
|
|
|
;; star. Thus, in that case, only hide it.
|
2016-06-23 12:18:38 +00:00
|
|
|
(start-face (if (and (bound-and-true-p org-indent-mode)
|
2011-07-21 17:02:35 +00:00
|
|
|
(> org-indent-indentation-per-level 1))
|
|
|
|
'org-hide
|
|
|
|
'org-warning)))
|
2009-03-29 15:31:20 +00:00
|
|
|
(while (re-search-forward re limit t)
|
2012-03-19 20:38:12 +00:00
|
|
|
(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)
|
2009-03-29 15:31:20 +00:00
|
|
|
'(face org-hide font-lock-fontified t))
|
|
|
|
(add-text-properties (match-beginning 3) (match-end 3)
|
2011-08-01 22:24:50 +00:00
|
|
|
'(face org-inlinetask font-lock-fontified t)))))
|
2009-03-29 15:31:20 +00:00
|
|
|
|
2011-01-30 16:42:38 +00: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.
|
2015-05-17 17:22:12 +00:00
|
|
|
((eq (get-char-property (1+ start) 'invisible) 'outline)
|
2013-10-29 16:07:49 +00:00
|
|
|
(outline-flag-region start end nil)
|
|
|
|
(org-cycle-hide-drawers 'children))
|
2011-01-30 16:42:38 +00:00
|
|
|
(t (outline-flag-region start end t)))))
|
|
|
|
|
2015-04-01 22:06:49 +00:00
|
|
|
(defun org-inlinetask-hide-tasks (state)
|
|
|
|
"Hide inline tasks in buffer when STATE is `contents' or `children'.
|
|
|
|
This function is meant to be used in `org-cycle-hook'."
|
2016-07-25 14:34:48 +00:00
|
|
|
(pcase state
|
|
|
|
(`contents
|
2015-04-01 22:06:49 +00:00
|
|
|
(let ((regexp (org-inlinetask-outline-regexp)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward regexp nil t)
|
|
|
|
(org-inlinetask-toggle-visibility)
|
|
|
|
(org-inlinetask-goto-end)))))
|
2016-07-25 14:34:48 +00:00
|
|
|
(`children
|
2015-04-01 22:06:49 +00:00
|
|
|
(save-excursion
|
|
|
|
(while (and (outline-next-heading) (org-inlinetask-at-task-p))
|
|
|
|
(org-inlinetask-toggle-visibility)
|
|
|
|
(org-inlinetask-goto-end))))))
|
|
|
|
|
2009-07-19 07:42:22 +00: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 "")))
|
|
|
|
|
2015-04-01 22:06:49 +00:00
|
|
|
(add-hook 'org-font-lock-hook 'org-inlinetask-fontify)
|
|
|
|
(add-hook 'org-cycle-hook 'org-inlinetask-hide-tasks)
|
2009-03-29 15:31:20 +00:00
|
|
|
|
|
|
|
(provide 'org-inlinetask)
|
|
|
|
|
|
|
|
;;; org-inlinetask.el ends here
|