]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-inlinetask.el
Install org-mode version 7.3
[gnu-emacs] / lisp / org / org-inlinetask.el
index e36922bee4b264cf1fad867e013ecf7b7dceb0d5..29d8c40eed266b565549ab4898a88f6334b83f77 100644 (file)
@@ -1,15 +1,16 @@
 ;;; org-inlinetask.el --- Tasks independent of outline hierarchy
 
-;; Copyright (C) 2009 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 6.29c
+;; Version: 7.3
 
 ;; This file is 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 of the License, or
 ;; (at your option) any later version.
@@ -32,9 +33,9 @@
 ;; and properties.  However, these nodes are treated specially by the
 ;; visibility cycling and export commands.
 ;;
-;; Visibility cycling exempts these nodes from cycling. So whenever their
+;; 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 orther commands to show/hide
+;; `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.
 ;; Also, if you want to use refiling and archiving for inline tasks,
 ;; The END line must be present to make things work properly.
 ;;
-;; This package installs one new comand:
+;; This package installs one new command:
 ;;
 ;; C-c C-x t      Insert a new inline task with END line
 
-
-;;; Code
+;;; Code:
 
 (require 'org)
 
@@ -90,26 +90,15 @@ 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)
+  :type '(choice
+         (const :tag "Off" nil)
+         (integer)))
 
-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."
+(defcustom org-inlinetask-export t
+  "Non-nil means export inline tasks.
+When nil, they will not be exported."
   :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)))
+  :type 'boolean)
 
 (defvar org-odd-levels-only)
 (defvar org-keyword-time-regexp)
@@ -117,15 +106,49 @@ but containing only the word END."
 (defvar org-complex-heading-regexp)
 (defvar org-property-end-re)
 
-(defun org-inlinetask-insert-task ()
-  "Insert an inline task."
-  (interactive)
+(defcustom org-inlinetask-default-state nil
+  "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
+  :type '(choice
+         (const :tag "No state" nil)
+         (string :tag "Specific state")))
+
+(defun org-inlinetask-insert-task (&optional no-state)
+  "Insert an inline task.
+If prefix arg NO-STATE is set, ignore `org-inlinetask-default-state'."
+  (interactive "P")
   (or (bolp) (newline))
-  (insert (make-string org-inlinetask-min-level ?*) " \n"
-         (make-string org-inlinetask-min-level ?*) " END\n")
+  (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"))
   (end-of-line -1))
 (define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
 
+(defun org-inlinetask-in-task-p ()
+  "Return true if point is inside an inline task."
+  (save-excursion
+    (let* ((nstars (if org-odd-levels-only
+                      (1- (* 2 (or org-inlinetask-min-level 200)))
+                    (or org-inlinetask-min-level 200)))
+          (stars-re (concat "^\\(?:\\*\\{"
+                            (format "%d" (- nstars 1))
+                            ",\\}\\)[ \t]+"))
+          (task-beg-re (concat stars-re "\\(?:.*\\)"))
+          (task-end-re (concat stars-re "\\(?:END\\|end\\)")))
+      (beginning-of-line)
+      (or (looking-at task-beg-re)
+         (and (re-search-forward "^\\*+[ \t]+" nil t)
+              (progn (beginning-of-line) (looking-at task-end-re)))))))
+
+(defvar htmlp)  ; dynamically scoped into the next function
+(defvar latexp) ; dynamically scoped into the next function
 (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."
@@ -135,7 +158,7 @@ Either remove headline and meta data, or do special formatting."
                   (or org-inlinetask-min-level 200)))
         (re1 (format "^\\(\\*\\{%d,\\}\\) .*\n" nstars))
         (re2 (concat "^[ \t]*" org-keyword-time-regexp))
-        headline beg end stars content)
+        headline beg end stars content indent)
     (while (re-search-forward re1 nil t)
       (setq headline (match-string 0)
            stars (match-string 1)
@@ -155,15 +178,52 @@ Either remove headline and meta data, or do special formatting."
        (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")))))
+      (when org-inlinetask-export
+       (when (string-match org-complex-heading-regexp headline)
+         (setq headline (concat
+                         (if (match-end 2)
+                             (concat
+                              (org-add-props
+                                  (format
+                                   "@<span class=\"%s %s\"> %s@</span>"
+                                   (if (member (match-string 2 headline)
+                                               org-done-keywords)
+                                       "done" "todo")
+                                   (match-string 2 headline)
+                                   (match-string 2 headline))
+                                  nil 'org-protected t)
+                              " ") "")
+                         (match-string 4 headline)))
+         (when content
+           (if (not (string-match "\\S-" content))
+               (setq content nil)
+             (if (string-match "[ \t\n]+\\'" content)
+                 (setq content (substring content 0 (match-beginning 0))))
+             (setq content (org-remove-indentation content))
+             (if latexp (setq content (concat "\\quad \\\\\n" content)))))
+         (insert (make-string (org-inlinetask-get-current-indentation) ?\ )
+                 "- ")
+         (setq indent (make-string (current-column) ?\ ))
+         (insert headline " ::")
+         (if content
+             (insert (if htmlp " " (concat "\n" indent))
+                     (mapconcat 'identity (org-split-string content "\n")
+                                (concat "\n" indent)) "\n")
+           (insert "\n"))
+         (insert indent)
+         (backward-delete-char 2)
+         (insert "THISISTHEINLINELISTTEMINATOR\n"))))))
+
+(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)))
 
 (defun org-inlinetask-fontify (limit)
   "Fontify the inline tasks."
@@ -187,11 +247,31 @@ Either remove headline and meta data, or do special formatting."
                            org-inlinetask-min-level))
     (replace-match "")))
 
+(defun org-inlinetask-remove-terminator ()
+  (let (beg end)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "THISISTHEINLINELISTTEMINATOR\n" nil t)
+       (setq beg (match-beginning 0) end (match-end 0))
+       (save-excursion
+         (beginning-of-line 1)
+         (and (looking-at "<p\\(ara\\)?>THISISTHEINLINELISTTEMINATOR[ \t\n]*</p\\(ara\\)?>")
+              (setq beg (point) end (match-end 0))))
+       (delete-region beg end)))))
+
 (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))
+(eval-after-load "org-html"
+  '(add-hook 'org-export-html-final-hook 'org-inlinetask-remove-terminator))
+(eval-after-load "org-latex"
+  '(add-hook 'org-export-latex-final-hook 'org-inlinetask-remove-terminator))
+(eval-after-load "org-ascii"
+  '(add-hook 'org-export-ascii-final-hook 'org-inlinetask-remove-terminator))
+(eval-after-load "org-docbook"
+  '(add-hook 'org-export-docbook-final-hook 'org-inlinetask-remove-terminator))
 
 (provide 'org-inlinetask)