* Insert datetree entry
@ 2017-04-03 22:40 Daniele Nicolodi
2017-04-03 23:37 ` Bruce V Chiarelli
0 siblings, 1 reply; 8+ messages in thread
From: Daniele Nicolodi @ 2017-04-03 22:40 UTC (permalink / raw
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-03 22:40 Insert datetree entry Daniele Nicolodi
@ 2017-04-03 23:37 ` Bruce V Chiarelli
2017-04-04 18:42 ` Daniele Nicolodi
0 siblings, 1 reply; 8+ messages in thread
From: Bruce V Chiarelli @ 2017-04-03 23:37 UTC (permalink / raw
To: Daniele Nicolodi; +Cc: emacs-orgmode
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-03 23:37 ` Bruce V Chiarelli
@ 2017-04-04 18:42 ` Daniele Nicolodi
2017-04-04 19:25 ` Bruce V Chiarelli
0 siblings, 1 reply; 8+ messages in thread
From: Daniele Nicolodi @ 2017-04-04 18:42 UTC (permalink / raw
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-04 18:42 ` Daniele Nicolodi
@ 2017-04-04 19:25 ` Bruce V Chiarelli
2017-04-04 19:50 ` Daniele Nicolodi
2017-04-04 21:18 ` Daniele Nicolodi
0 siblings, 2 replies; 8+ messages in thread
From: Bruce V Chiarelli @ 2017-04-04 19:25 UTC (permalink / raw
To: Daniele Nicolodi; +Cc: emacs-orgmode
Daniele Nicolodi <daniele@grinta.net> 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.
>
> Cheers,
> Daniele
--
Bruce V. Chiarelli
http://github.com/bccomm
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-04 19:25 ` Bruce V Chiarelli
@ 2017-04-04 19:50 ` Daniele Nicolodi
2017-04-04 21:18 ` Daniele Nicolodi
1 sibling, 0 replies; 8+ messages in thread
From: Daniele Nicolodi @ 2017-04-04 19:50 UTC (permalink / raw
To: emacs-orgmode
On 4/4/17 1:25 PM, Bruce V Chiarelli wrote:
>
> Daniele Nicolodi <daniele@grinta.net> 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.
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-04 19:25 ` Bruce V Chiarelli
2017-04-04 19:50 ` Daniele Nicolodi
@ 2017-04-04 21:18 ` Daniele Nicolodi
2017-04-05 21:40 ` Bruce V Chiarelli
1 sibling, 1 reply; 8+ messages in thread
From: Daniele Nicolodi @ 2017-04-04 21:18 UTC (permalink / raw
To: emacs-orgmode
On 4/4/17 1:25 PM, Bruce V Chiarelli wrote:
>
> Daniele Nicolodi <daniele@grinta.net> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-04 21:18 ` Daniele Nicolodi
@ 2017-04-05 21:40 ` Bruce V Chiarelli
2017-04-05 23:19 ` Daniele Nicolodi
0 siblings, 1 reply; 8+ messages in thread
From: Bruce V Chiarelli @ 2017-04-05 21:40 UTC (permalink / raw
To: Daniele Nicolodi; +Cc: emacs-orgmode
Daniele Nicolodi writes:
> On 4/4/17 1:25 PM, Bruce V Chiarelli wrote:
>>
>> Daniele Nicolodi <daniele@grinta.net> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Insert datetree entry
2017-04-05 21:40 ` Bruce V Chiarelli
@ 2017-04-05 23:19 ` Daniele Nicolodi
0 siblings, 0 replies; 8+ messages in thread
From: Daniele Nicolodi @ 2017-04-05 23:19 UTC (permalink / raw
To: emacs-orgmode
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 Nicolodi <daniele@grinta.net> 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.
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-04-05 23:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-03 22:40 Insert datetree entry Daniele Nicolodi
2017-04-03 23:37 ` Bruce V Chiarelli
2017-04-04 18:42 ` Daniele Nicolodi
2017-04-04 19:25 ` Bruce V Chiarelli
2017-04-04 19:50 ` Daniele Nicolodi
2017-04-04 21:18 ` Daniele Nicolodi
2017-04-05 21:40 ` Bruce V Chiarelli
2017-04-05 23:19 ` Daniele Nicolodi
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.