* Re: [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument [not found] ` <20211019125725.EA9CF209AA@vcs0.savannah.gnu.org> @ 2021-10-19 13:14 ` Stefan Monnier 2021-10-19 13:50 ` Ihor Radchenko 0 siblings, 1 reply; 4+ messages in thread From: Stefan Monnier @ 2021-10-19 13:14 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-devel Hi Ihor, > org-persist.el: Fix `add-hook' priority argument > --- > lisp/org-persist.el | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lisp/org-persist.el b/lisp/org-persist.el > index 9885386..e518974 100644 > --- a/lisp/org-persist.el > +++ b/lisp/org-persist.el > @@ -278,7 +278,7 @@ When BUFFER is `all', unregister VAR in all buffers." > (setq org-persist--index (nreverse new-index)))) > > (add-hook 'kill-emacs-hook #'org-persist-gc) > -(add-hook 'kill-emacs-hook #'org-persist-write-all 1000) > +(add-hook 'kill-emacs-hook #'org-persist-write-all 100) The docstring also says: Since nothing is \"always\" true, don't use 100 nor -100. 100 means that nothing will *ever* want to come later. I.e. you claim to be the one and only function that will ever deserve to always be the last one on this hook, which is rather presumptuous, I think. AFAICT the only thing that actually matters is that it should come after `org-persist-gc`, so even just 0.01 would be good enough. No need to get anywhere near 100 (tho it would make sense to leave room for other hooks that might need to come between `org-persist-gc` and `org-persist-write-all`). Also, I'd recommend you add a comment explaining the constraints that were considered when choosing this depth (e.g "Make sure it comes after `org-persist-gc`"). Stefan ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument 2021-10-19 13:14 ` [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument Stefan Monnier @ 2021-10-19 13:50 ` Ihor Radchenko 2021-10-19 14:16 ` Stefan Monnier 0 siblings, 1 reply; 4+ messages in thread From: Ihor Radchenko @ 2021-10-19 13:50 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel Hi Stefan, Thanks for providing comments on this new feature! Stefan Monnier <monnier@iro.umontreal.ca> writes: >> (add-hook 'kill-emacs-hook #'org-persist-gc) >> -(add-hook 'kill-emacs-hook #'org-persist-write-all 1000) >> +(add-hook 'kill-emacs-hook #'org-persist-write-all 100) > > The docstring also says: > > Since nothing is \"always\" true, don't use 100 nor -100. > > 100 means that nothing will *ever* want to come later. I.e. you claim > to be the one and only function that will ever deserve to always be the > last one on this hook, which is rather presumptuous, I think. > AFAICT the only thing that actually matters is that it should come after > `org-persist-gc`, so even just 0.01 would be good enough. No need to > get anywhere near 100 (tho it would make sense to leave room for other > hooks that might need to come between `org-persist-gc` and > `org-persist-write-all`). Also, I'd recommend you add a comment > explaining the constraints that were considered when choosing this depth > (e.g "Make sure it comes after `org-persist-gc`"). The idea behind 100 is related to Org usage. We save buffer-local `org-element--cache' to files. It needs to be done _after_ all the possible changes in Org buffers are made. If any hook changes an Org buffer after `org-persist-write-all', the saved value will become invalid. I am not sure what can be a reasonable DEPTH value in such case. Can it be something like 1? Looking through Emacs code base, I can mostly see non-nil values as DEPTH argument. So, maybe 90? 91? Best, Ihor ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument 2021-10-19 13:50 ` Ihor Radchenko @ 2021-10-19 14:16 ` Stefan Monnier 2021-10-20 13:38 ` Ihor Radchenko 0 siblings, 1 reply; 4+ messages in thread From: Stefan Monnier @ 2021-10-19 14:16 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-devel > The idea behind 100 is related to Org usage. We save buffer-local > `org-element--cache' to files. It needs to be done _after_ all the > possible changes in Org buffers are made. If any hook changes an Org > buffer after `org-persist-write-all', the saved value will become > invalid. I am not sure what can be a reasonable DEPTH value in such > case. Can it be something like 1? Looking through Emacs code base, I > can mostly see non-nil values as DEPTH argument. So, maybe 90? 91? The value should be chosen in accordance with other possibly interfering functions. IOW you need for the functions to agree on a numbering-convention. Since there is no such convention yet for your functions, you get to define it. So you can chose, for example 42 and from then on all function that need to come before `org-persist-write-all` simply have to refrain from using a value higher than 42. Stefan ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument 2021-10-19 14:16 ` Stefan Monnier @ 2021-10-20 13:38 ` Ihor Radchenko 0 siblings, 0 replies; 4+ messages in thread From: Ihor Radchenko @ 2021-10-20 13:38 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: >> The idea behind 100 is related to Org usage. We save buffer-local >> `org-element--cache' to files. It needs to be done _after_ all the >> possible changes in Org buffers are made. If any hook changes an Org >> buffer after `org-persist-write-all', the saved value will become >> invalid. I am not sure what can be a reasonable DEPTH value in such >> case. Can it be something like 1? Looking through Emacs code base, I >> can mostly see non-nil values as DEPTH argument. So, maybe 90? 91? > > The value should be chosen in accordance with other possibly > interfering functions. > IOW you need for the functions to agree on a numbering-convention. > Since there is no such convention yet for your functions, you get to > define it. > > So you can chose, for example 42 and from then on all function that need > to come before `org-persist-write-all` simply have to refrain from > using a value higher than 42. Thanks for the clarification. After more thinking and reading the manual, I have found that kill-emacs-hook and kill-buffer-hook generally run after the buffer is saved. So, I do not need to worry about something outside Org changing the file contents. Depth 0 is good enough given that I put add-hook calls in correct order. Best, Ihor ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-20 13:38 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <20211019125722.17993.60001@vcs0.savannah.gnu.org> [not found] ` <20211019125725.EA9CF209AA@vcs0.savannah.gnu.org> 2021-10-19 13:14 ` [elpa] externals/org 46da64c 4/6: org-persist.el: Fix `add-hook' priority argument Stefan Monnier 2021-10-19 13:50 ` Ihor Radchenko 2021-10-19 14:16 ` Stefan Monnier 2021-10-20 13:38 ` Ihor Radchenko
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.