Browse Source

Agenda export: Allow entry text to be inlined for export.

A new hook is introduced, `org-agenda-before-write-hook'.
A function that ca be added to this hook is
`org-agenda-add-entry-text'.   When this is done, each of the entries
shown in the agenda is amended with text that in the original buffer
is part of the entry text below the headline.  Drawers are not copied,
and also the line with scheduling and deadline information is not
used.  Finally, the number of ines to be added is imited by
`org-agenda-add-entry-text-maxlines'.
Carsten Dominik 16 năm trước cách đây
mục cha
commit
aadcc50e00
2 tập tin đã thay đổi với 87 bổ sung0 xóa
  1. 5 0
      lisp/ChangeLog
  2. 82 0
      lisp/org-agenda.el

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2009-02-26  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-agenda.el (org-agenda-before-write-hook)
+	(org-agenda-add-entry-text-maxlines): New options.
+	(org-write-agenda): Run the new hook in the temporary buffer.
+	(org-agenda-add-entry-text): New function.
+
 	* org.el (org-global-properties-fixed, org-global-properties):
 	Improve documentation string.
 

+ 82 - 0
lisp/org-agenda.el

@@ -109,6 +109,20 @@ This is a good place to set options for ps-print and for htmlize."
 	   (variable)
 	   (sexp :tag "Value"))))
 
+(defcustom org-agenda-before-write-hook nil
+  "Hook run in temporary buffer before writing it to an export file.
+A useful function would be `org-agenda-add-entry-text'."
+  :group 'org-agenda-export
+  :type 'hook
+  :options '(org-agenda-add-entry-text))
+
+(defcustom org-agenda-add-entry-text-maxlines 10
+  "Maximum number of entry text lines to be added to agenda.
+This is only relevant when `org-agenda-add-entry-text'
+has beed added to `org-agenda-before-write-hook'."
+  :group 'org-agenda
+  :type 'integer)
+
 (defcustom org-agenda-export-html-style ""
   "The style specification for exported HTML Agenda files.
 If this variable contains a string, it will replace the default <style>
@@ -1995,6 +2009,7 @@ higher priority settings."
 	       (delete-region
 		beg (or (next-single-property-change beg 'org-filtered)
 			(point-max))))
+	     (run-hooks 'org-agenda-before-write-hook)
 	     (cond
 	      ((string-match "\\.html?\\'" file)
 	       (set-buffer (htmlize-buffer (current-buffer)))
@@ -2058,6 +2073,73 @@ VALUE defaults to t."
        beg (or (next-single-property-change beg 'org-filtered)
 	       (point-max))))))
 
+(defun org-agenda-add-entry-text ()
+  "Add entry text to agenda lines.
+This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
+entry text following headings shown in the agenda.
+Drawers will be excluded, also the line with scheduling/deadline info."
+  (let (m txt drawer-re kwd-time-re ind)
+    (goto-char (point-min))
+    (while (not (eobp))
+      (if (not (setq m (get-text-property (point) 'org-hd-marker)))
+	  (beginning-of-line 2)
+	(save-excursion
+	  (with-current-buffer (marker-buffer m)
+	    (if (not (org-mode-p))
+		(setq txt "")
+	      (save-excursion
+		(save-restriction
+		  (widen)
+		  (goto-char m)
+		  (beginning-of-line 2)
+		  (setq txt (buffer-substring (point)
+					      (progn
+						(outline-next-heading) (point)))
+			drawer-re org-drawer-regexp
+			kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
+					    ".*\n?"))
+		  (with-temp-buffer
+		    (insert txt)
+		    (goto-char (point-min))
+		    (while (re-search-forward drawer-re nil t)
+		      (delete-region
+		       (match-beginning 0)
+		       (progn (re-search-forward "^[ \t]*:END:.*\n?" nil 'move)
+			      (point))))
+		    (goto-char (point-min))
+		    (while (re-search-forward kwd-time-re nil t)
+		      (replace-match ""))
+		    (if (re-search-forward "[ \t\n]+\\'" nil t)
+			(replace-match ""))
+		    (goto-char (point-min))
+		    ;; find min indentation
+		    (goto-char (point-min))
+		    (untabify (point-min) (point-max))
+		    (setq ind (org-get-indentation))
+		    (while (not (eobp))
+		      (unless (looking-at "[ \t]*$")
+			(setq ind (min ind (org-get-indentation))))
+		      (beginning-of-line 2))
+		    (goto-char (point-min))
+		    (while (not (eobp))
+		      (unless (looking-at "[ \t]*$")
+			(move-to-column ind)
+			(delete-region (point-at-bol) (point)))
+		      (beginning-of-line 2))
+		    (goto-char (point-min))
+		    (while (and (not (eobp)) (re-search-forward "^" nil t))
+		      (replace-match "    > "))
+		    (goto-char (point-min))
+		    (while (looking-at "[ \t]*\n") (replace-match ""))
+		    (goto-char (point-max))
+		    (when (> (org-current-line)
+			     (1+ org-agenda-add-entry-text-maxlines))
+		      (goto-line (1+ org-agenda-add-entry-text-maxlines))
+		      (backward-char 1))
+		    (setq txt (buffer-substring (point-min) (point)))))))))
+	(end-of-line 1)
+	(if (string-match "\\S-" txt) (insert "\n" txt))))))
+
 (defun org-agenda-collect-markers ()
   "Collect the markers pointing to entries in the agenda buffer."
   (let (m markers)