Carsten Dominik 16 年 前
コミット
e341a34297
2 ファイル変更142 行追加4 行削除
  1. 118 0
      contrib/lisp/org-inlinetasks.el
  2. 24 4
      lisp/org.el

+ 118 - 0
contrib/lisp/org-inlinetasks.el

@@ -0,0 +1,118 @@
+;;; org-inlinetask.el --- Tasks outside the outline hierarchy
+;; Copyright (C) 2008 Free Software Foundation, Inc.
+;;
+;; Author: Carsten Dominik <carsten at orgmode dot org>
+;; Keywords: outlines, hypermedia, calendar, wp
+;; Homepage: http://orgmode.org
+;; Version: 0.01
+;;
+;; This file is not yet part of GNU Emacs.
+;;
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; 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
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; 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 commands and by the export commands.
+
+Visibility cycling exempts these nodes from cycling, so whenever their
+parent is opened, so are these tasks.
+
+Export commands do not treat the tasks as part of the sectioning
+structure, but as a spe
+
+;;; Code
+
+(defcustom org-inlinetask-export 'arrow+content
+  "What should be done with inlinetasks upon export?
+Possible values:
+
+nil            Remove entirely
+arrow          Insert arrow and headline
+arrow+content  Insert arrow and headline, add content like example
+example        Turn headline and content into example"
+  :group 'org-export-general
+  :type 'boolean)
+
+(defun org-inlinetask-export-handler ()
+  "Handle headlines with level larger than `org-cycle-max-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-cycle-max-level 1000)))
+		   (or org-cycle-max-level 1000)))
+	 (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))))
+      (when (and org-inlinetask-export
+		 (string-match org-complex-heading-regexp headline))
+	(when (memq org-inlinetask-export '(arrow+content arrow))
+	  (insert "\n\n\\Rightarrow *"
+		  (if (match-end 2) (concat (match-string 2 headline) " ") "")
+		  (match-string 4 headline) "*\n"))
+	(when (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-cycle-max-level 1000)))
+		   (or org-cycle-max-level 1000)))
+	 (re (concat "^\\(\\*\\)\\(\\*\\{"
+		    (format "%d" (- nstars 2))
+		    ",\\}\\)\\(\\*\\* .*\\)")))
+    (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)))))
+
+(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)
+
+;;; org-inlinetask.el ends here
+

+ 24 - 4
lisp/org.el

@@ -548,6 +548,17 @@ new-frame        Make a new frame each time.  Note that in this case
   :tag "Org Cycle"
   :group 'org-structure)
 
+(defcustom org-cycle-max-level nil
+  "Maximum level which should still be subject to visibility cycling.
+Levels higher than this will, for cycling, be treated as text, not a headline.
+When `org-odd-levels-only' is set, a value of N in this variable actually
+means 2N-1 stars as the limiting headline.
+When nil, cycle all levels."
+  :group 'org-cycle
+  :type '(choice
+	  (const :tag "No limit" nil)
+	  (integer :tag "Maximum level")))
+
 (defcustom org-drawers '("PROPERTIES" "CLOCK" "LOGBOOK")
   "Names of drawers.  Drawers are not opened by cycling on the headline above.
 Drawers only open with a TAB on the drawer line itself.  A drawer looks like
@@ -562,6 +573,7 @@ Drawers can be defined on the per-file basis with a line like:
 
 #+DRAWERS: HIDDEN STATE PROPERTIES"
   :group 'org-structure
+  :group 'org-cycle
   :type '(repeat (string :tag "Drawer Name")))
 
 (defcustom org-cycle-global-at-bob nil
@@ -4469,6 +4481,7 @@ If KWD is a number, get the corresponding match group."
 (make-variable-buffer-local 'org-cycle-subtree-status)
 
 ;;;###autoload
+
 (defun org-cycle (&optional arg)
   "Visibility cycling for Org-mode.
 
@@ -4504,10 +4517,17 @@ If KWD is a number, get the corresponding match group."
   But only if also the variable `org-cycle-global-at-bob' is t."
   (interactive "P")
   (org-load-modules-maybe)
-  (let* ((outline-regexp
-	  (if (and (org-mode-p) org-cycle-include-plain-lists)
-	      "\\(?:\\*+ \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"
-	    outline-regexp))
+  (let* ((nstars (if org-odd-levels-only
+		     (and org-cycle-max-level (1- (* org-cycle-max-level 2)))
+		   org-cycle-max-level))
+	 (outline-regexp
+	  (cond
+	   ((not (org-mode-p)) outline-regexp)
+	   (org-cycle-include-plain-lists
+	    (concat "\\(?:\\*"
+		    (if nstars (format "\\{1,%d\\} " nstars) "+")
+		    " \\|\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) \\)"))
+	   (t (concat "\\*" (if nstars (format "\\{1,%d\\} " nstars) "+ ")))))
 	 (bob-special (and org-cycle-global-at-bob (bobp)
 			   (not (looking-at outline-regexp))))
 	 (org-cycle-hook