emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Insert datetree entry


From: Bruce V Chiarelli
Subject: Re: [O] Insert datetree entry
Date: Wed, 05 Apr 2017 14:40:45 -0700
User-agent: mu4e 0.9.19; emacs 26.0.50

Daniele Nicolodi writes:

> On 4/4/17 1:25 PM, Bruce V Chiarelli wrote:
>>
>> Daniele Nicolodi <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]