Browse Source

Inline tasks: Play along with archiving, refiling, and footnotes, store link.

Carsten Dominik 15 years ago
parent
commit
8530298b45
6 changed files with 64 additions and 2 deletions
  1. 19 0
      lisp/ChangeLog
  2. 2 0
      lisp/org-archive.el
  3. 1 1
      lisp/org-footnote.el
  4. 24 0
      lisp/org-inlinetask.el
  5. 14 0
      lisp/org-macs.el
  6. 4 1
      lisp/org.el

+ 19 - 0
lisp/ChangeLog

@@ -1,5 +1,24 @@
 2009-07-19  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-store-link): Never store a link to an inline task.
+
+	* org-inlinetask.el (org-inlinetask-insert-task): New command.
+
+	* org-footnote.el (org-footnote-goto-local-insertion-point): Skip
+	inline tasks when positioning footnotes.
+
+	* org-inlinetask.el (org-inlinetask-remove-END-maybe): New
+	function.
+
+	* org.el (org-refile): Remove the END line when archiving an
+	inline task that does have an END line.
+
+	* org-archive.el (org-archive-subtree): Remove the END line when
+	archiving an inline task that does have an END line.
+
+	* org-macs.el (org-with-limited-levels): New macro.
+	(org-get-limited-outline-regexp): New function.
+
 	* org-exp.el (org-export-format-source-code-or-example): Fix bug
 	that did not enumerate first line.
 	(org-export-mark-radio-links): Skip matches in links.

+ 2 - 0
lisp/org-archive.el

@@ -303,6 +303,8 @@ this heading."
       ;; Here we are back in the original buffer.  Everything seems to have
       ;; worked.  So now cut the tree and finish up.
       (let (this-command) (org-cut-subtree))
+      (when (featurep 'org-inlinetask)
+	(org-inlinetask-remove-END-maybe))
       (setq org-markers-to-move nil)
       (message "Subtree archived %s"
 	       (if (eq this-buffer buffer)

+ 1 - 1
lisp/org-footnote.el

@@ -487,7 +487,7 @@ ENTRY is (fn-label num-mark definition)."
 
 (defun org-footnote-goto-local-insertion-point ()
   "Find insertion point for footnote, just before next outline heading."
-  (outline-next-heading)
+  (org-with-limited-levels (outline-next-heading))
   (or (bolp) (newline))
   (beginning-of-line 0)
   (while (and (not (bobp)) (= (char-after) ?#))

+ 24 - 0
lisp/org-inlinetask.el

@@ -65,6 +65,14 @@
 ;;                     :END:
 ;;                     And here is some extra text
 ;;    **************** END
+;;
+;; 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:
+;;
+;; C-c C-x t      Insert a new inline task with END line
+
 
 ;;; Code
 
@@ -106,6 +114,16 @@ but containing only the word END."
 (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."
@@ -161,6 +179,12 @@ Either remove headline and meta data, or do special formatting."
       (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))

+ 14 - 0
lisp/org-macs.el

@@ -257,7 +257,21 @@ This is in contrast to merely setting it to 0."
 					(match-beginning 0) string)))
   (replace-match newtext fixedcase literal string))
 
+(defmacro org-with-limited-levels (&rest body)
+  "Execute BODY with limited number of outline levels."
+  `(let* ((outline-regexp (org-get-limited-outline-regexp)))
+     ,@body))
+
+(defun org-get-limited-outline-regexp ()
+  "Return outline-regexp with limited number of levels.
+The number of levels is controlled by "
+  (if (or (not (org-mode-p)) (not (featurep 'org-inlinetask)))
 
+      outline-regexp
+    (let* ((limit-level (1- org-inlinetask-min-level))
+	   (nstars (if org-odd-levels-only (1- (* limit-level 2)) limit-level)))
+      (format "\\*\\{1,%d\\} " nstars))))
+		     
 (provide 'org-macs)
 
 ;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668

+ 4 - 1
lisp/org.el

@@ -6936,7 +6936,8 @@ For file links, arg negates `org-context-in-file-links'."
   (interactive "P")
   (org-load-modules-maybe)
   (setq org-store-link-plist nil)  ; reset
-  (let (link cpltxt desc description search txt custom-id)
+  (let ((outline-regexp org-get-limited-outline-regexp)
+	link cpltxt desc description search txt custom-id)
     (cond
 
      ((run-hook-with-args-until-success 'org-store-link-functions)
@@ -8497,6 +8498,8 @@ See also `org-refile-use-outline-path' and `org-completion-use-ido'"
 	  (if regionp
 	      (delete-region (point) (+ (point) region-length))
 	    (org-cut-subtree))
+	  (when (featurep 'org-inlinetask)
+	    (org-inlinetask-remove-END-maybe))
 	  (setq org-markers-to-move nil)
 	  (message "Refiled to \"%s\"" (car it))))))
   (org-reveal))