emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <dominik@uva.nl>
To: org-mode list <emacs-orgmode@gnu.org>
Subject: Allowing multiple date trees in a single file
Date: Sun, 15 Jan 2017 17:46:50 +0100	[thread overview]
Message-ID: <CADn3Z2JH5VJ-4c5kxfgKE8DmQA9PeFpqBch1FOV0Xfq7PXtDTQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 425 bytes --]

Hi everyone,

here is a patch that allows to have multiple date trees or iso-week trees
in a single file by allowing to specify the property name that will be used
to place the tree.  The property name can be set in org-capture-templates,
individually for every template if so desired.  I use that to have three
different kind of journals in a single file.

Any objections gains me to merge this change into Master?

Carsten

[-- Attachment #1.2: Type: text/html, Size: 555 bytes --]

[-- Attachment #2: patch-datetree --]
[-- Type: application/octet-stream, Size: 4333 bytes --]

Changes in master
	Modified doc/org.texi
diff --git a/doc/org.texi b/doc/org.texi
index f68ef6e..d59976d 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -7253,6 +7253,11 @@ separator line.
 @item :kill-buffer
 If the target file was not yet visited when capture was invoked, kill the
 buffer again after capture is completed.
+
+@item :tree-property
+If the target is in a date or week tree, this property will be used instead
+of DATE_TREE or WEEK_TREE to identify the org entry under which the tree
+should be built.
 @end table
 @end table
 
	Modified lisp/org-capture.el
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index a8b9879..1202664 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -227,6 +227,10 @@ properties are:
                      capture was invoked, kill the buffer again after capture
                      is finalized.
 
+ :tree-property      The property that identifies the entry where the date or
+                     iso-week tree should be placed.  When given, overrules
+                     the default DATE_TREE or WEEK_TREE properties.
+
 The template defines the text to be inserted.  Often this is an
 Org mode entry (so the first line should start with a star) that
 will be filed as a child of the target headline.  It can also be
@@ -379,7 +383,8 @@ you can escape ambiguous cases with a backward slash, e.g., \\%i."
 				   ((const :format "%v " :clock-resume) (const t))
 				   ((const :format "%v " :unnarrowed) (const t))
 				   ((const :format "%v " :table-line-pos) (const t))
-				   ((const :format "%v " :kill-buffer) (const t)))))))))
+				   ((const :format "%v " :kill-buffer) (const t))
+				   ((const :format "%v " :tree-property) (string "")))))))))
 
 (defcustom org-capture-before-finalize-hook nil
   "Hook that is run right before a capture process is finalized.
@@ -974,7 +979,8 @@ Store them in the capture property list."
 	    (t
 	     ;; Current date, possibly corrected for late night
 	     ;; workers.
-	     (org-today))))))
+	     (org-today))))
+	  nil (org-capture-get :tree-property)))
 	(`(file+function ,path ,function)
 	 (set-buffer (org-capture-target-buffer path))
 	 (org-capture-put-target-region-and-position)
	Modified lisp/org-datetree.el
diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el
index 540753d..d9aa665 100644
--- a/lisp/org-datetree.el
+++ b/lisp/org-datetree.el
@@ -50,15 +50,18 @@ Added time stamp is active unless value is `inactive'."
 	  (const :tag "Add an active time stamp" active)))
 
 ;;;###autoload
-(defun org-datetree-find-date-create (d &optional keep-restriction)
+(defun org-datetree-find-date-create (d &optional keep-restriction
+					tree-property)
   "Find or create an entry for date D.
 If KEEP-RESTRICTION is non-nil, do not widen the buffer.
 When it is nil, the buffer will be widened to make sure an existing date
-tree can be found."
+tree can be found.
+If TREE-PROPERTY is given, place the tree under an entry that has this
+property, instead of the default DATE_TREE property."
   (setq-local org-datetree-base-level 1)
   (or keep-restriction (widen))
   (save-restriction
-    (let ((prop (org-find-property "DATE_TREE")))
+    (let ((prop (org-find-property (or tree-property "DATE_TREE"))))
       (when prop
 	(goto-char prop)
 	(setq-local org-datetree-base-level
@@ -80,17 +83,20 @@ tree can be found."
        year month day))))
 
 ;;;###autoload
-(defun org-datetree-find-iso-week-create (d &optional keep-restriction)
+(defun org-datetree-find-iso-week-create (d &optional keep-restriction
+					    tree-property)
   "Find or create an ISO week entry for date D.
 Compared to `org-datetree-find-date-create' this function creates
 entries ordered by week instead of months.
 If KEEP-RESTRICTION is non-nil, do not widen the buffer.  When it
 is nil, the buffer will be widened to make sure an existing date
-tree can be found."
+tree can be found.
+If TREE-PROPERTY is given, place the tree under an entry that has this
+property, instead of the default DATE_TREE property."
   (setq-local org-datetree-base-level 1)
   (or keep-restriction (widen))
   (save-restriction
-    (let ((prop (org-find-property "WEEK_TREE")))
+    (let ((prop (org-find-property (or tree-property "WEEK_TREE"))))
       (when prop
 	(goto-char prop)
 	(setq-local org-datetree-base-level


             reply	other threads:[~2017-01-15 16:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-15 16:46 Carsten Dominik [this message]
2017-01-16  7:45 ` Allowing multiple date trees in a single file Nicolas Goaziou
2017-01-17 12:19   ` Carsten Dominik
2017-01-17 17:50     ` Nicolas Goaziou
2017-01-18  5:53       ` Carsten Dominik
2017-01-18 11:23         ` Nicolas Goaziou
2017-02-03 14:08           ` Carsten Dominik
2017-02-04 12:48             ` Nicolas Goaziou
2017-02-05 10:40               ` Carsten Dominik
2017-02-06 13:06                 ` Nicolas Goaziou
2017-01-18 20:19 ` Samuel Wales
2017-01-19 12:57   ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADn3Z2JH5VJ-4c5kxfgKE8DmQA9PeFpqBch1FOV0Xfq7PXtDTQ@mail.gmail.com \
    --to=dominik@uva.nl \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).