123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- (require 'org)
- (defgroup org-inlinetask nil
- "Options concerning inline tasks in Org mode."
- :tag "Org Inline Tasks"
- :group 'org-structure)
- (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
- :type 'boolean)
- (defcustom org-inlinetask-export 'arrow+content
- "What should be done with inlinetasks upon export?
- Possible values:
- nil Remove entirely, headline and \"content\"
- arrow Insert heading in bold, preceeded by an arrow
- arrow+content Insert arrow and headline, add content below in an
- #+begin_example box (ugly, but works for now)
- The \"content\" of an inline task is the material below the planning
- line and any drawers, up to a lines wit the same number of stars,
- but containing only the word END."
- :group 'org-inlinetask
- :group 'org-export-general
- :type '(choice
- (const :tag "Remove entirely" nil)
- (const :tag "Headline preceeded by arrow" arrow)
- (const :tag "Arrow, headline, + content" arrow+content)))
- (defvar org-odd-levels-only)
- (defvar org-keyword-time-regexp)
- (defvar org-drawer-regexp)
- (defvar org-complex-heading-regexp)
- (defvar org-property-end-re)
- (defun org-inlinetask-insert-task ()
- "Insert an inline task."
- (interactive)
- (or (bolp) (newline))
- (insert (make-string org-inlinetask-min-level ?*) " \n"
- (make-string org-inlinetask-min-level ?*) " END\n")
- (end-of-line -1))
- (define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
- (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* ((nstars (if org-odd-levels-only
- (1- (* 2 (or org-inlinetask-min-level 200)))
- (or org-inlinetask-min-level 200)))
- (re1 (format "^\\(\\*\\{%d,\\}\\) .*\n" nstars))
- (re2 (concat "^[ \t]*" org-keyword-time-regexp))
- headline beg end stars content)
- (while (re-search-forward re1 nil t)
- (setq headline (match-string 0)
- stars (match-string 1)
- content nil)
- (replace-match "")
- (while (looking-at re2)
- (delete-region (point) (1+ (point-at-eol))))
- (while (looking-at org-drawer-regexp)
- (setq beg (point))
- (if (re-search-forward org-property-end-re nil t)
- (delete-region beg (1+ (match-end 0)))))
- (setq beg (point))
- (when (and (re-search-forward "^\\(\\*+\\) " nil t)
- (= (length (match-string 1)) (length stars))
- (progn (goto-char (match-end 0))
- (looking-at "END[ \t]*$")))
- (setq content (buffer-substring beg (1- (point-at-bol))))
- (delete-region beg (1+ (match-end 0))))
- (goto-char beg)
- (when (and org-inlinetask-export
- (string-match org-complex-heading-regexp headline))
- (when (memq org-inlinetask-export '(arrow+content arrow))
- (insert "\n\n\\Rightarrow\\Rightarrow\\Rightarrow *"
- (if (match-end 2) (concat (match-string 2 headline) " ") "")
- (match-string 4 headline) "*\n"))
- (when (and content (eq org-inlinetask-export 'arrow+content))
- (insert "#+BEGIN_EXAMPLE\n" content "\n#+END_EXAMPLE\n"))
- (insert "\n")))))
- (defun org-inlinetask-fontify (limit)
- "Fontify the inline tasks."
- (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))
- ",\\}\\)\\(\\*\\* .*\\)")))
- (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)
- '(face org-hide font-lock-fontified t))
- (add-text-properties (match-beginning 3) (match-end 3)
- '(face shadow font-lock-fontified t)))))
- (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 "")))
- (eval-after-load "org-exp"
- '(add-hook 'org-export-preprocess-after-tree-selection-hook
- 'org-inlinetask-export-handler))
- (eval-after-load "org"
- '(add-hook 'org-font-lock-hook 'org-inlinetask-fontify))
- (provide 'org-inlinetask)
|