Browse Source

Allow diary entry insertion at top-level

Matt Lundin writes:

> The new org-agenda-diary-entry looks quite convenient.
>
> Would it be possible to add an option to bypass the date tree so as to
> add each new appointment as a simple first level heading? I prefer to
> keep my appointments organized by project and/or category and have no
> real use for the date tree. Ideally, new appointments would appear as
> first level headlines in the org-agenda-diary-file (i.e., my inbox),
> ready to be refiled.
Carsten Dominik 16 years ago
parent
commit
1bb0df0511
2 changed files with 36 additions and 6 deletions
  1. 5 0
      lisp/ChangeLog
  2. 31 6
      lisp/org-agenda.el

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2009-11-19  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-11-19  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-agenda.el (org-agenda-insert-diary-strategy): New variable.
+	(org-agenda-insert-diary-as-top-level): New function.
+	(org-agenda-add-entry-to-org-agenda-diary-file): Call
+	`org-agenda-insert-diary-as-top-level'.
+
 	* org.el (org-occur-in-agenda-files): Make sure none of the
 	* org.el (org-occur-in-agenda-files): Make sure none of the
 	buffers is narrowed.
 	buffers is narrowed.
 	(org-activate-plain-links): Add the face property here.
 	(org-activate-plain-links): Add the face property here.

+ 31 - 6
lisp/org-agenda.el

@@ -6694,6 +6694,17 @@ The cursor may be at a date in the calendar, or in the Org agenda."
       (org-reveal t))
       (org-reveal t))
      (t (error "Invalid selection character `%c'" char)))))
      (t (error "Invalid selection character `%c'" char)))))
 
 
+(defcustom org-agenda-insert-diary-strategy 'date-tree
+  "Where in `org-agenda-diary-file' should new entries be added?
+Valid values:
+
+date-tree    in the date tree, as child of the date
+top-level    as top-level entries at the end of the file."
+  :group 'org-agenda
+  :type '(choice
+	  (const :tag "in a date tree" date-tree)
+	  (const :tag "as top level at end of file" top-level)))
+
 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
   "Add a diary entry with TYPE to `org-agenda-diary-file'.
   "Add a diary entry with TYPE to `org-agenda-diary-file'.
 If TEXT is not empty, it will become the headline of the new entry, and
 If TEXT is not empty, it will become the headline of the new entry, and
@@ -6728,9 +6739,11 @@ the resulting entry will not be shown.  When TEXT is empty, switch to
 	(insert (format "%%%%(diary-anniversary %s) %s"
 	(insert (format "%%%%(diary-anniversary %s) %s"
 			(calendar-date-string d1 nil t) text))))
 			(calendar-date-string d1 nil t) text))))
      ((eq type 'day)
      ((eq type 'day)
-      (require 'org-datetree)
-      (org-datetree-find-date-create d1)
-      (org-agenda-insert-diary-make-new-entry text)
+      (if (eq org-agenda-insert-diary-strategy 'top-level)
+	  (org-agenda-insert-diary-as-top-level text)
+	(require 'org-datetree)
+	(org-datetree-find-date-create d1)
+	(org-agenda-insert-diary-make-new-entry text))
       (org-insert-time-stamp (org-time-from-absolute
       (org-insert-time-stamp (org-time-from-absolute
 			      (calendar-absolute-from-gregorian d1)))
 			      (calendar-absolute-from-gregorian d1)))
       (end-of-line 0))
       (end-of-line 0))
@@ -6738,9 +6751,11 @@ the resulting entry will not be shown.  When TEXT is empty, switch to
       (if (> (calendar-absolute-from-gregorian d1)
       (if (> (calendar-absolute-from-gregorian d1)
 	     (calendar-absolute-from-gregorian d2))
 	     (calendar-absolute-from-gregorian d2))
 	  (setq d1 (prog1 d2 (setq d2 d1))))
 	  (setq d1 (prog1 d2 (setq d2 d1))))
-      (require 'org-datetree)
-      (org-datetree-find-date-create d1)
-      (org-agenda-insert-diary-make-new-entry text)
+      (if (eq org-agenda-insert-diary-strategy 'top-level)
+	  (org-agenda-insert-diary-as-top-level text)
+	(require 'org-datetree)
+	(org-datetree-find-date-create d1)
+	(org-agenda-insert-diary-make-new-entry text))
       (org-insert-time-stamp (org-time-from-absolute
       (org-insert-time-stamp (org-time-from-absolute
 			      (calendar-absolute-from-gregorian d1)))
 			      (calendar-absolute-from-gregorian d1)))
       (insert "--")
       (insert "--")
@@ -6756,6 +6771,16 @@ the resulting entry will not be shown.  When TEXT is empty, switch to
       (org-reveal t)
       (org-reveal t)
       (message "Please finish entry here"))))
       (message "Please finish entry here"))))
 
 
+(defun org-agenda-insert-diary-as-top-level (text)
+  "Make new entry as a top-level entry at the end of the file.
+Add TEXT as headline, and position the cursor in the second line so that
+a timestamp can be added there."
+  (widen)
+  (goto-char (point-max))
+  (or (bolp) (insert "\n"))
+  (insert "* " text "\n")
+  (if org-adapt-indentation (org-indent-to-column 2)))
+
 (defun org-agenda-insert-diary-make-new-entry (text)
 (defun org-agenda-insert-diary-make-new-entry (text)
   "Make new entry as last child of current entry.
   "Make new entry as last child of current entry.
 Add TEXT as headline, and position the cursor in the second line so that
 Add TEXT as headline, and position the cursor in the second line so that