From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce V Chiarelli Subject: Re: Insert datetree entry Date: Wed, 05 Apr 2017 14:40:45 -0700 Message-ID: <87y3ve7ctk.fsf@topd0g> References: <87fuhp83ls.fsf@topd0g> <92332b50-c4a8-73a3-f506-c058fb54b9de@grinta.net> <87efx87z71.fsf@topd0g> <0f31392a-463f-5c16-6ae0-2ddd8cab20d2@grinta.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvsfi-0002Km-F9 for emacs-orgmode@gnu.org; Wed, 05 Apr 2017 17:40:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvsff-0001WJ-Cj for emacs-orgmode@gnu.org; Wed, 05 Apr 2017 17:40:58 -0400 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:34428) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvsff-0001WA-6M for emacs-orgmode@gnu.org; Wed, 05 Apr 2017 17:40:55 -0400 Received: by mail-pg0-x235.google.com with SMTP id 21so16323153pgg.1 for ; Wed, 05 Apr 2017 14:40:54 -0700 (PDT) In-reply-to: <0f31392a-463f-5c16-6ae0-2ddd8cab20d2@grinta.net> 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: Daniele Nicolodi Cc: emacs-orgmode@gnu.org Daniele Nicolodi writes: > On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: >> >> Daniele Nicolodi writes: > 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))) Nice! I'm afraid I'm unqualified to give any comments/criticism on your code, since I'm fairly new to elisp myself. Looks better than what I had though, at least to work around the missing 'subtree-at-point feature. Maybe someone else can chime in. I did notice that with my function, org-up-heading-safe didn't always behave the way I wanted it to (like if it was already *on* the root headline). But I only needed the function a few times, so I didn't bother with improving it. > Cheers, > Daniele Best, Bruce