emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Insert datetree entry


From: Daniele Nicolodi
Subject: Re: [O] Insert datetree entry
Date: Tue, 4 Apr 2017 15:18:12 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

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



reply via email to

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