瀏覽代碼

Date tree ca be filed under entry. And reveal after jump.

Carsten Dominik 15 年之前
父節點
當前提交
cba8527897
共有 3 個文件被更改,包括 35 次插入15 次删除
  1. 17 13
      doc/org.texi
  2. 2 1
      lisp/org-agenda.el
  3. 16 1
      lisp/org-datetree.el

+ 17 - 13
doc/org.texi

@@ -5813,10 +5813,12 @@ to @code{org-remember-default-headline}.  If the file name is not an absolute
 path, it will be interpreted relative to @code{org-directory}.
 path, it will be interpreted relative to @code{org-directory}.
 
 
 The heading can also be the symbols @code{top} or @code{bottom} to send notes
 The heading can also be the symbols @code{top} or @code{bottom} to send notes
-as level 1 entries to the beginning or end of the file, respectively.  I may
-also be the symbol @code{date-tree}.  Then, a tree with year on level 1, month
-on level 2 and day on level three will be build in the file, and the entry
-will be filed into the tree under the current date.
+as level 1 entries to the beginning or end of the file, respectively.  It may
+also be the symbol @code{date-tree}.  Then, a tree with year on level 1,
+month on level 2 and day on level three will be build in the file, and the
+entry will be filed into the tree under the current date@footnote{If the file
+contains an entry with a @code{DATE_TREE} property, the entire date tree will
+be build under that entry.}
 
 
 An optional sixth element specifies the contexts in which the user can select
 An optional sixth element specifies the contexts in which the user can select
 the template.  This element can be a list of major modes or a function.
 the template.  This element can be a list of major modes or a function.
@@ -7635,20 +7637,22 @@ date at the cursor.
 @item i
 @item i
 @vindex org-agenda-diary-file
 @vindex org-agenda-diary-file
 Insert a new entry into the diary, using the date at the cursor and (for
 Insert a new entry into the diary, using the date at the cursor and (for
-clock entries) the date at the mark.  This will add to the Emacs diary
+block entries) the date at the mark.  This will add to the Emacs diary
 file@footnote{This file is parsed for the agenda when
 file@footnote{This file is parsed for the agenda when
 @code{org-agenda-include-diary} is set.}, in a way similar to the @kbd{i}
 @code{org-agenda-include-diary} is set.}, in a way similar to the @kbd{i}
 command in the calendar.  The diary file will pop up in another window, where
 command in the calendar.  The diary file will pop up in another window, where
 you can add the entry.
 you can add the entry.
 
 
-If you configure @code{org-agenda-diary-file} to point to an Org-mode file
-instead, Org will create entries in that file.  Most entries will be stored
-in a date-based outline tree that will later make it easy to archive
-appointments from previous months/years.  Emacs will prompt you for the entry
-text - if you specify it, the entry will be created in
-@code{org-agenda-diary-file} without further interaction.  If you directly
-press @key{RET} at the prompt without typing text, the target file will be
-shown in another window for you to finish the entry there.
+If you configure @code{org-agenda-diary-file} to point to an Org-mode file,
+Org will create entries (in org-mode syntax) in that file instead.  Most
+entries will be stored in a date-based outline tree that will later make it
+easy to archive appointments from previous months/years.  The tree will be
+build under an entry with a @code{DATE_TREE} property, or else with years as
+top-level entries.  Emacs will prompt you for the entry text - if you specify
+it, the entry will be created in @code{org-agenda-diary-file} without further
+interaction.  If you directly press @key{RET} at the prompt without typing
+text, the target file will be shown in another window for you to finish the
+entry there.  See also the @kbd{k r} command.
 @c
 @c
 @kindex M
 @kindex M
 @item M
 @item M

+ 2 - 1
lisp/org-agenda.el

@@ -6675,7 +6675,8 @@ The cursor may be at a date in the calendar, or in the Org agenda."
      ((equal char ?j)
      ((equal char ?j)
       (org-switch-to-buffer-other-window
       (org-switch-to-buffer-other-window
        (find-file-noselect org-agenda-diary-file))
        (find-file-noselect org-agenda-diary-file))
-      (org-datetree-find-date-create d1))
+      (org-datetree-find-date-create d1)
+      (org-reveal t))
      (t (error "Invalid selection character `%c'" char)))))
      (t (error "Invalid selection character `%c'" char)))))
 
 
 (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)

+ 16 - 1
lisp/org-datetree.el

@@ -33,11 +33,26 @@
 
 
 (require 'org)
 (require 'org)
 
 
+(defvar org-datetree-base-level 1
+  "The level at which years should be placed in the date tree.
+This is normally one, but if the buffer has an entry with a DATE_TREE
+property, the date tree will become a subtree under that entry, so the
+base level will be properly adjusted.")
+
 (defun org-datetree-find-date-create (date)
 (defun org-datetree-find-date-create (date)
   "Find or create an entry for DATE."
   "Find or create an entry for DATE."
   (let ((year (nth 2 date))
   (let ((year (nth 2 date))
 	(month (car date))
 	(month (car date))
 	(day (nth 1 date)))
 	(day (nth 1 date)))
+    (org-set-local 'org-datetree-base-level 1)
+    (widen)
+    (goto-char (point-min))
+    (when (re-search-forward "^[ \t]*:DATE_TREE:[ \t]+\\S-" nil t)
+      (org-back-to-heading t)
+      (org-set-local 'org-datetree-base-level
+		     (org-get-valid-level (funcall outline-level) 1))
+      (org-narrow-to-subtree))
+    (goto-char (point-min))
     (org-datetree-find-year-create year)
     (org-datetree-find-year-create year)
     (org-datetree-find-month-create year month)
     (org-datetree-find-month-create year month)
     (org-datetree-find-day-create year month day)
     (org-datetree-find-day-create year month day)
@@ -103,7 +118,7 @@
   (let ((pos (point)))
   (let ((pos (point)))
     (skip-chars-backward " \t\n")
     (skip-chars-backward " \t\n")
     (delete-region (point) pos)
     (delete-region (point) pos)
-    (insert "\n* \n")
+    (insert "\n" (make-string org-datetree-base-level ?*) " \n")
     (backward-char 1)
     (backward-char 1)
     (if month (org-do-demote))
     (if month (org-do-demote))
     (if day (org-do-demote))
     (if day (org-do-demote))