From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniele Nicolodi Subject: Re: Insert datetree entry Date: Tue, 4 Apr 2017 15:18:12 -0600 Message-ID: <0f31392a-463f-5c16-6ae0-2ddd8cab20d2@grinta.net> References: <87fuhp83ls.fsf@topd0g> <92332b50-c4a8-73a3-f506-c058fb54b9de@grinta.net> <87efx87z71.fsf@topd0g> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvVqG-0003X3-Cg for emacs-orgmode@gnu.org; Tue, 04 Apr 2017 17:18:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvVqC-00007u-Ey for emacs-orgmode@gnu.org; Tue, 04 Apr 2017 17:18:20 -0400 Received: from zed.grinta.net ([109.74.203.128]:54854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvVqC-00007T-3u for emacs-orgmode@gnu.org; Tue, 04 Apr 2017 17:18:16 -0400 Received: from 688dnmac.campus.nist.gov (unknown [132.163.81.39]) (Authenticated sender: daniele) by zed.grinta.net (Postfix) with ESMTPSA id 37852E2F98 for ; Tue, 4 Apr 2017 21:18:15 +0000 (UTC) In-Reply-To: <87efx87z71.fsf@topd0g> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: > > Daniele Nicolodi writes: > >> >> thanks for the hint, but I don't understand what `subtree-at-point` is >> in your code, it does not seem to be defined in my emacs and >> `org-datetree-find-date-create` has a third parameter that is >> interpreted as a boolean. I'm confused. > > Ah, yes I forgot that this is a fairly new feature. Sorry for the > confusion. In the latest Org, the optional keep-restriction parameter can be > > - t - make the datetree at the end of the current /view/ of the buffer, > - nil - make the datetree at the end of the file, even if it was narrowed > to a subtree before, or > - 'subtree-at-point - put the datetree as a subheading at the end of the > current heading. This one is new in Org 9.0.5. > > The first two options have been around for a long time, so if you get > rid of 'subtree-at-point it should be fine. It will default to nil. Hi Bruce, I modified your code as follow to be able to insert a datetree entry correctly being anywhere in an existing datetree. I also added the possibility of having a prefix argument to prompt for the date. It works for me, but I don't know if this is the most elegant way to obtain what I want. Comments are welcome. ;; look for datetree root (defun dnn-org-datetree-root () (let ((re "^\\([12][0-9]\\{3\\}\\)\\(-\\([01][0-9]\\)\\(-\\([0123][0-9]\\)\\)?\\)? \\w+$")) (while (string-match re (org-get-heading)) (org-up-heading-safe)) (org-up-heading-safe))) ;; add a datetree entry (defun dnn-org-datetree-find-create (arg) (interactive "P") (let ((d (calendar-gregorian-from-absolute (if arg (time-to-days (org-read-date nil t)) (org-today))))) (dnn-org-datetree-root) (org-datetree-find-date-create d 'subtree-at-point))) Cheers, Daniele