Re: [O] Insert datetree entry
On 4/5/17 3:40 PM, Bruce V Chiarelli wrote: > > Daniele Nicolodi writes: > >> On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: >>> >>> Daniele Nicolodiwrites: >> 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. If that code works around the missiong 'subtree-at-point feature on older org-mode releases, it is absolutely by chance, I "back-ported" the feature into my system from current org-mode master branch :-) Cheers, Daniele
Re: [O] Insert datetree entry
Daniele Nicolodi writes: > On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: >> >> Daniele Nicolodiwrites: > 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
Re: [O] Insert datetree entry
On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: > > Daniele Nicolodiwrites: > >> >> 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
Re: [O] Insert datetree entry
On 4/4/17 1:25 PM, Bruce V Chiarelli wrote: > > Daniele Nicolodiwrites: > >> >> 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. I would like t he functionality provided specifying 'subtree-at-point, but it has been introduced after the 3.0.5 release currently available on melpa :( Cheers, Daniele
Re: [O] Insert datetree entry
Daniele Nicolodiwrites: > > 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. > > Cheers, > Daniele -- Bruce V. Chiarelli http://github.com/bccomm
Re: [O] Insert datetree entry
On 4/3/17 5:37 PM, Bruce V Chiarelli wrote: > > Daniele Nicolodi writes: > >> Hello, >> >> there is a way in org-mode to insert a datetree entry without going >> through the org-capture? Ideally the function would jump to the >> datetree and inser an headline for the current day if one is not >> present, or move to the end of it if one is present. >> >> I haven't found anything like this in the manual. I'm now digging in the >> code. Hopefully it is not something too hard to implement with my >> lacking elisp knowledge. > > I don't believe there really is one, but I've had to do it a couple of > times myself. This is my solution (I'm not a lisp expert either, but it > did the job): > > (defun bc/org-new-datetree-at-point >(interactive) >(org-up-heading-safe) >(org-datetree-find-date-create > (calendar-gregorian-from-absolute (org-today)) > 'subtree-at-point)) > > This will make the datetree as a subheading of the current heading (or > find it if it already exists). Getting rid of 'subtree-at-point will > make the year a level 1 heading at the end of the file, like with > org-capture. Hi Bruce, 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. Cheers, Daniele
Re: [O] Insert datetree entry
Daniele Nicolodi writes: > Hello, > > there is a way in org-mode to insert a datetree entry without going > through the org-capture? Ideally the function would jump to the > datetree and inser an headline for the current day if one is not > present, or move to the end of it if one is present. > > I haven't found anything like this in the manual. I'm now digging in the > code. Hopefully it is not something too hard to implement with my > lacking elisp knowledge. I don't believe there really is one, but I've had to do it a couple of times myself. This is my solution (I'm not a lisp expert either, but it did the job): (defun bc/org-new-datetree-at-point (interactive) (org-up-heading-safe) (org-datetree-find-date-create (calendar-gregorian-from-absolute (org-today)) 'subtree-at-point)) This will make the datetree as a subheading of the current heading (or find it if it already exists). Getting rid of 'subtree-at-point will make the year a level 1 heading at the end of the file, like with org-capture. Bruce -- Bruce V. Chiarelli http://github.com/bccomm
[O] Insert datetree entry
Hello, there is a way in org-mode to insert a datetree entry without going through the org-capture? Ideally the function would jump to the datetree and inser an headline for the current day if one is not present, or move to the end of it if one is present. I haven't found anything like this in the manual. I'm now digging in the code. Hopefully it is not something too hard to implement with my lacking elisp knowledge. Thanks. Cheers, Daniele