emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [QUESTION] Add advice on command org-add-note not working
@ 2021-08-20  1:22 Christopher M. Miles
  2021-08-20  8:45 ` Samuel Loury
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher M. Miles @ 2021-08-20  1:22 UTC (permalink / raw)
  To: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 627 bytes --]

<#secure method=pgpmime mode=sign>

I have following advice code:

#+begin_src emacs-lisp
(defun my/org-add-note--auto-add-tag ()
  "Auto add tag 'LOG' when add note log."
  (org-back-to-heading)
  ;; DEBUG: the following code is not executed.
  (message "DEBUG")
  (require 'seq)
  (org-set-tags (seq-uniq (cons "LOG" (org-get-tags nil t)))))

(advice-add 'org-add-note :after #'my/org-add-note--auto-add-tag)
#+end_src

With Emacs Edebug, I found it only executed to ~(org-back-to-heading)~, then stopped. The following
"DEBUG" message is not printed and tag "LOG" is not added.

Does anybody have some clue for this issue?


[-- Attachment #1.2: Type: text/html, Size: 2713 bytes --]

[-- Attachment #2: Type: text/plain, Size: 246 bytes --]

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QUESTION] Add advice on command org-add-note not working
  2021-08-20  1:22 [QUESTION] Add advice on command org-add-note not working Christopher M. Miles
@ 2021-08-20  8:45 ` Samuel Loury
  2021-08-20 15:16   ` [SOLVED] " stardiviner
  0 siblings, 1 reply; 3+ messages in thread
From: Samuel Loury @ 2021-08-20  8:45 UTC (permalink / raw)
  To: numbchild, Org Mode

[-- Attachment #1: Type: text/plain, Size: 1431 bytes --]

"Christopher M. Miles" <numbchild@gmail.com> writes:

> <#secure method=pgpmime mode=sign>

Beware this did not actually sign your message.

> I have following advice code:
>
> #+begin_src emacs-lisp
> (defun my/org-add-note--auto-add-tag ()
>   "Auto add tag 'LOG' when add note log."
>   (org-back-to-heading)
>   ;; DEBUG: the following code is not executed.
>   (message "DEBUG")
>   (require 'seq)
>   (org-set-tags (seq-uniq (cons "LOG" (org-get-tags nil t)))))
>
> (advice-add 'org-add-note :after #'my/org-add-note--auto-add-tag)
> #+end_src
>
> With Emacs Edebug, I found it only executed to ~(org-back-to-heading)~, then stopped. The following
> "DEBUG" message is not printed and tag "LOG" is not added.
>
> Does anybody have some clue for this issue?

`org-add-note` only sets up a side buffer to write the content of the
note. The "go back to the heading to actually write the note" is done by
`org-store-log-note`, invoked using C-c C-c on your note.

So it is normal that `org-back-to-heading` fails in the org-note buffer
that indeed does not have a heading.

Hint: press p when in edebug session to find out in which buffer context
the code will apply.

I just tried applying the advice to `org-store-log-note` instead of
`org-add-note` and it worked fine :-).

My best,
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [SOLVED] Re: [QUESTION] Add advice on command org-add-note not working
  2021-08-20  8:45 ` Samuel Loury
@ 2021-08-20 15:16   ` stardiviner
  0 siblings, 0 replies; 3+ messages in thread
From: stardiviner @ 2021-08-20 15:16 UTC (permalink / raw)
  To: Samuel Loury; +Cc: Org-mode

Thanks Samuel, using `org-store-log-note’ indeed solved the problem. Great solution.


> On Aug 20, 2021, at 4:45 PM, Samuel Loury <konubinix@gmail.com> wrote:
> 
> "Christopher M. Miles" <numbchild@gmail.com> writes:
> 
>> <#secure method=pgpmime mode=sign>
> 
> Beware this did not actually sign your message.
> 
>> I have following advice code:
>> 
>> #+begin_src emacs-lisp
>> (defun my/org-add-note--auto-add-tag ()
>>  "Auto add tag 'LOG' when add note log."
>>  (org-back-to-heading)
>>  ;; DEBUG: the following code is not executed.
>>  (message "DEBUG")
>>  (require 'seq)
>>  (org-set-tags (seq-uniq (cons "LOG" (org-get-tags nil t)))))
>> 
>> (advice-add 'org-add-note :after #'my/org-add-note--auto-add-tag)
>> #+end_src
>> 
>> With Emacs Edebug, I found it only executed to ~(org-back-to-heading)~, then stopped. The following
>> "DEBUG" message is not printed and tag "LOG" is not added.
>> 
>> Does anybody have some clue for this issue?
> 
> `org-add-note` only sets up a side buffer to write the content of the
> note. The "go back to the heading to actually write the note" is done by
> `org-store-log-note`, invoked using C-c C-c on your note.
> 
> So it is normal that `org-back-to-heading` fails in the org-note buffer
> that indeed does not have a heading.
> 
> Hint: press p when in edebug session to find out in which buffer context
> the code will apply.
> 
> I just tried applying the advice to `org-store-log-note` instead of
> `org-add-note` and it worked fine :-).
> 
> My best,
> -- 
> Konubinix
> GPG Key    : 7439106A
> Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-20 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  1:22 [QUESTION] Add advice on command org-add-note not working Christopher M. Miles
2021-08-20  8:45 ` Samuel Loury
2021-08-20 15:16   ` [SOLVED] " stardiviner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).