* [PATCH] org-capture: Add a custom to control save target file or not.
@ 2018-04-12 1:20 tumashu
2018-04-12 13:22 ` Nicolas Goaziou
0 siblings, 1 reply; 24+ messages in thread
From: tumashu @ 2018-04-12 1:20 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 317 bytes --]
I use org-capture to capture text to a file of my mobile phone
with the help of tramp and termux's sshd, the save buffer is very
slow, so I want to org-capture-finalize just update buffer, and
I save buffer manually when need.
By the way, can we contribute org-mode with the help of PR feature in code.orgmode.org?
[-- Attachment #1.2: Type: text/html, Size: 427 bytes --]
[-- Attachment #2: 0001-org-capture-Add-a-custom-to-control-save-target-file.patch --]
[-- Type: application/octet-stream, Size: 1701 bytes --]
From ff25c3327914069f1dc3be6337c8ceb2d0e4f791 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Thu, 12 Apr 2018 09:04:13 +0800
Subject: [PATCH] org-capture: Add a custom to control save target file or not.
* lisp/org-capture.el (org-capture-finalize-save-buffer): New variable.
(org-capture-finalize): Use org-capture-finalize-save-buffer.
I use org-capture to capture text to a file of my mobile phone
with the help of tramp and termux's sshd, the save buffer is very
slow, so I want to org-capture-finalize just update buffer, and
I save buffer manually when need.
---
lisp/org-capture.el | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index f59e2ce6a..e2234e816 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -438,6 +438,12 @@ The capture buffer is current and still narrowed."
:version "24.1"
:type 'hook)
+(defcustom org-capture-finalize-save-buffer t
+ "When nil, org-capture-finalize will not save target file's buffer."
+ :group 'org-capture
+ :version "24.1"
+ :type 'boolean)
+
(defcustom org-capture-bookmark t
"When non-nil, add a bookmark pointing at the last stored
position when capturing."
@@ -791,7 +797,10 @@ captured item after finalizing."
(org-encrypt-entry)))
;; Kill the indirect buffer
- (save-buffer)
+ (if org-capture-finalize-save-buffer
+ (save-buffer)
+ (message "The capture target file is not auto saved, please save it manually."))
+
(let ((return-wconf (org-capture-get :return-to-wconf 'local))
(new-buffer (org-capture-get :new-buffer 'local))
(kill-buffer (org-capture-get :kill-buffer 'local))
--
2.16.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-12 1:20 [PATCH] org-capture: Add a custom to control save target file or not tumashu
@ 2018-04-12 13:22 ` Nicolas Goaziou
2018-04-13 2:10 ` tumashu
2018-04-26 23:34 ` Bastien
0 siblings, 2 replies; 24+ messages in thread
From: Nicolas Goaziou @ 2018-04-12 13:22 UTC (permalink / raw)
To: tumashu; +Cc: emacs-orgmode
Hello,
tumashu <tumashu@163.com> writes:
> I use org-capture to capture text to a file of my mobile phone
> with the help of tramp and termux's sshd, the save buffer is very
> slow, so I want to org-capture-finalize just update buffer, and
> I save buffer manually when need.
Thank you. Comments follow.
> By the way, can we contribute org-mode with the help of PR feature in
> code.orgmode.org?
AFAIC, I'd rather deal with email than with a web interface. However,
Bastien accepted PR from code.orgmode.org in the past.
The problem with PR in code.orgmode.org is that the discussion around
the patch happens somewhere else than on the ML.
> +(defcustom org-capture-finalize-save-buffer t
> + "When nil, org-capture-finalize will not save target file's buffer."
> + :group 'org-capture
> + :version "24.1"
> + :type 'boolean)
The :version value is incorrect. Also, it is missing ":safe #'booleanp".
> (defcustom org-capture-bookmark t
> "When non-nil, add a bookmark pointing at the last stored
> position when capturing."
> @@ -791,7 +797,10 @@ captured item after finalizing."
> (org-encrypt-entry)))
>
> ;; Kill the indirect buffer
> - (save-buffer)
> + (if org-capture-finalize-save-buffer
> + (save-buffer)
> + (message "The capture target file is not auto saved, please save it manually."))
Would it make sense to simply not call `save-buffer' in all cases?
Saving buffer after a capture is rather opinionated.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-12 13:22 ` Nicolas Goaziou
@ 2018-04-13 2:10 ` tumashu
2018-04-14 7:44 ` Nicolas Goaziou
2018-04-26 23:34 ` Bastien
1 sibling, 1 reply; 24+ messages in thread
From: tumashu @ 2018-04-13 2:10 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
At 2018-04-12 21:22:21, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
>Hello,
>
>tumashu <tumashu@163.com> writes:
>
>> I use org-capture to capture text to a file of my mobile phone
>> with the help of tramp and termux's sshd, the save buffer is very
>> slow, so I want to org-capture-finalize just update buffer, and
>> I save buffer manually when need.
>
>Thank you. Comments follow.
>
>> By the way, can we contribute org-mode with the help of PR feature in
>> code.orgmode.org?
>
>AFAIC, I'd rather deal with email than with a web interface. However,
>Bastien accepted PR from code.orgmode.org in the past.
>
>The problem with PR in code.orgmode.org is that the discussion around
>the patch happens somewhere else than on the ML.
>
>> +(defcustom org-capture-finalize-save-buffer t
>> + "When nil, org-capture-finalize will not save target file's buffer."
>> + :group 'org-capture
>> + :version "24.1"
>> + :type 'boolean)
>
>The :version value is incorrect. Also, it is missing ":safe #'booleanp".
>
:version 26.1 ? or 27.0 ?
>> (defcustom org-capture-bookmark t
>> "When non-nil, add a bookmark pointing at the last stored
>> position when capturing."
>> @@ -791,7 +797,10 @@ captured item after finalizing."
>> (org-encrypt-entry)))
>>
>> ;; Kill the indirect buffer
>> - (save-buffer)
>> + (if org-capture-finalize-save-buffer
>> + (save-buffer)
>> + (message "The capture target file is not auto saved, please save it manually."))
>
>Would it make sense to simply not call `save-buffer' in all cases?
>Saving buffer after a capture is rather opinionated.
I do not know why must save-buffer, may be for information safe :-)
>
>
>Regards,
>
>--
>Nicolas Goaziou
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-13 2:10 ` tumashu
@ 2018-04-14 7:44 ` Nicolas Goaziou
2018-04-14 9:42 ` tumashu
0 siblings, 1 reply; 24+ messages in thread
From: Nicolas Goaziou @ 2018-04-14 7:44 UTC (permalink / raw)
To: tumashu; +Cc: emacs-orgmode
Hello,
tumashu <tumashu@163.com> writes:
> I do not know why must save-buffer, may be for information safe :-)
If there is no objection, I suggest to simply remove this call to
`save-buffer' instead of introducing a new variable.
Regards,
--
Nicolas Goaziou 0x80A93738
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-14 7:44 ` Nicolas Goaziou
@ 2018-04-14 9:42 ` tumashu
2018-04-16 1:06 ` tumashu
2018-09-26 17:11 ` Kaushal Modi
0 siblings, 2 replies; 24+ messages in thread
From: tumashu @ 2018-04-14 9:42 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
At 2018-04-14 15:44:00, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
>Hello,
>
>tumashu <tumashu@163.com> writes:
>
>> I do not know why must save-buffer, may be for information safe :-)
>
>If there is no objection, I suggest to simply remove this call to
>`save-buffer' instead of introducing a new variable.
>
Agree this idea, If user want to save-buffer when capture finish, they can
add save-buffer to org-capture-after-finalize-hook or just type C-x C-s
>Regards,
>
>--
>Nicolas Goaziou 0x80A93738
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-14 9:42 ` tumashu
@ 2018-04-16 1:06 ` tumashu
2018-04-16 10:11 ` Nicolas Goaziou
2018-09-26 17:11 ` Kaushal Modi
1 sibling, 1 reply; 24+ messages in thread
From: tumashu @ 2018-04-16 1:06 UTC (permalink / raw)
To: 我; +Cc: emacs-orgmode, Nicolas Goaziou
[-- Attachment #1.1: Type: text/plain, Size: 668 bytes --]
At 2018-04-14 17:42:27, "tumashu" <tumashu@163.com> wrote:
>
>
>
>
>
>
>
>
>
>
>At 2018-04-14 15:44:00, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
>>Hello,
>>
>>tumashu <tumashu@163.com> writes:
>>
>>> I do not know why must save-buffer, may be for information safe :-)
>>
>>If there is no objection, I suggest to simply remove this call to
>>`save-buffer' instead of introducing a new variable.
>>
>
>Agree this idea, If user want to save-buffer when capture finish, they can
>add save-buffer to org-capture-after-finalize-hook or just type C-x C-s
>
>>Regards,
>>
>>--
>>Nicolas Goaziou 0x80A93738
[-- Attachment #1.2: Type: text/html, Size: 1003 bytes --]
[-- Attachment #2: 0001-org-capture-Do-not-save-buffer-when-run-org-capture-.patch --]
[-- Type: application/octet-stream, Size: 819 bytes --]
From 3e18b38f5e48f87addb386dec680cabc089f44d0 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@163.com>
Date: Mon, 16 Apr 2018 09:02:13 +0800
Subject: [PATCH] org-capture: Do not save buffer when run
org-capture-finalize.
* lisp/org-capture.el (org-capture-finalize): Do not run save-buffer.
---
lisp/org-capture.el | 1 -
1 file changed, 1 deletion(-)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index f59e2ce6a..02f9e3df3 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -791,7 +791,6 @@ captured item after finalizing."
(org-encrypt-entry)))
;; Kill the indirect buffer
- (save-buffer)
(let ((return-wconf (org-capture-get :return-to-wconf 'local))
(new-buffer (org-capture-get :new-buffer 'local))
(kill-buffer (org-capture-get :kill-buffer 'local))
--
2.16.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-16 1:06 ` tumashu
@ 2018-04-16 10:11 ` Nicolas Goaziou
0 siblings, 0 replies; 24+ messages in thread
From: Nicolas Goaziou @ 2018-04-16 10:11 UTC (permalink / raw)
To: tumashu; +Cc: emacs-orgmode
Hello,
tumashu <tumashu@163.com> writes:
> From: Feng Shu <tumashu@163.com>
> Date: Mon, 16 Apr 2018 09:02:13 +0800
> Subject: [PATCH] org-capture: Do not save buffer when run org-capture-finalize.
Applied. Thank you.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-12 13:22 ` Nicolas Goaziou
2018-04-13 2:10 ` tumashu
@ 2018-04-26 23:34 ` Bastien
1 sibling, 0 replies; 24+ messages in thread
From: Bastien @ 2018-04-26 23:34 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: tumashu, emacs-orgmode
Hi Tumashu,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> AFAIC, I'd rather deal with email than with a web interface. However,
> Bastien accepted PR from code.orgmode.org in the past.
PS: Just to be clear, we don't accept PR from code.orgmode.org, this
was just a left-over from the default configuration of gogs.
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-04-14 9:42 ` tumashu
2018-04-16 1:06 ` tumashu
@ 2018-09-26 17:11 ` Kaushal Modi
2018-09-26 17:29 ` Kaushal Modi
2018-09-27 5:47 ` Eric S Fraga
1 sibling, 2 replies; 24+ messages in thread
From: Kaushal Modi @ 2018-09-26 17:11 UTC (permalink / raw)
To: tumashu; +Cc: emacs-org list, Nicolas Goaziou
On Sat, Apr 14, 2018 at 5:43 AM tumashu <tumashu@163.com> wrote:
>
> At 2018-04-14 15:44:00, "Nicolas Goaziou" <mail@nicolasgoaziou.fr> wrote:
> >Hello,
> >
> >tumashu <tumashu@163.com> writes:
> >
> >> I do not know why must save-buffer, may be for information safe :-)
> >
> >If there is no objection, I suggest to simply remove this call to
> >`save-buffer' instead of introducing a new variable.
> >
>
> Agree this idea, If user want to save-buffer when capture finish, they can
> add save-buffer to org-capture-after-finalize-hook or just type C-x C-s
I just stumbled across this today; the relevant commit
https://code.orgmode.org/bzg/org-mode/commit/b4422add3745c26ec3b2e11b8da425844b2e9d3d
I had been wondering for quite some time (about since 5 months :P) why
my Org captures have stopped auto-saving.
Today I started looking into it, and found that commit.
I believe this 1-liner commit is a pretty serious change. Users used
to have they captures safely auto-saved might be in for a surprise. So
just wanted to write this email about it. This commit does not affect
the stable releases of Org so far (9.1). This change is present only
on master as of today.
I'll add a note about this to NEWS on master branch.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-26 17:11 ` Kaushal Modi
@ 2018-09-26 17:29 ` Kaushal Modi
2018-09-26 18:11 ` Kaushal Modi
2018-09-27 5:47 ` Eric S Fraga
1 sibling, 1 reply; 24+ messages in thread
From: Kaushal Modi @ 2018-09-26 17:29 UTC (permalink / raw)
To: tumashu; +Cc: emacs-org list, Nicolas Goaziou
> On Sat, Apr 14, 2018 at 5:43 AM tumashu <tumashu@163.com> wrote:
> >
> > Agree this idea, If user want to save-buffer when capture finish, they can
> > add save-buffer to org-capture-after-finalize-hook or just type C-x C-s
Also that suggestion to use org-capture-after-finalize-hook does not
work.. I am investigating to find the right way.
The reason is that the (current-buffer) when that hook is run is the
buffer from where the capture is initiated (which usually is not the
capture target buffer).
So running save-buffer in that hook simply saves a buffer unrelated to
the capture (which is not good).
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-26 17:29 ` Kaushal Modi
@ 2018-09-26 18:11 ` Kaushal Modi
0 siblings, 0 replies; 24+ messages in thread
From: Kaushal Modi @ 2018-09-26 18:11 UTC (permalink / raw)
To: tumashu; +Cc: emacs-org list, Nicolas Goaziou
> Also that suggestion to use org-capture-after-finalize-hook does not
> work.. I am investigating to find the right way.
I got the captures to auto-save with the below work-around:
(with-eval-after-load 'org-capture
(defvar modi/org-capture-base-buffer nil)
(defun modi/org-capture-before-finalize ()
(let ((base-buffer (buffer-base-buffer (current-buffer))))
(setq modi/org-capture-base-buffer base-buffer)))
(add-hook 'org-capture-before-finalize-hook
#'modi/org-capture-before-finalize)
(defun modi/org-capture-save-buffer ()
(when modi/org-capture-base-buffer
(let ((base-buffer-already-open (bufferp modi/org-capture-base-buffer)))
(with-current-buffer modi/org-capture-base-buffer
(save-buffer))))
(setq modi/org-capture-base-buffer nil)) ;Reset the buffer name cache
(add-hook 'org-capture-after-finalize-hook #'modi/org-capture-save-buffer))
tumashu: I am wondering if it's possible to undo this commit and we
can figure out how to prevent file saving during org-capture.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-26 17:11 ` Kaushal Modi
2018-09-26 17:29 ` Kaushal Modi
@ 2018-09-27 5:47 ` Eric S Fraga
2018-09-27 13:33 ` Kaushal Modi
1 sibling, 1 reply; 24+ messages in thread
From: Eric S Fraga @ 2018-09-27 5:47 UTC (permalink / raw)
To: Kaushal Modi; +Cc: tumashu, emacs-org list, Nicolas Goaziou
On Wednesday, 26 Sep 2018 at 13:11, Kaushal Modi wrote:
> I had been wondering for quite some time (about since 5 months :P) why
> my Org captures have stopped auto-saving.
This has been really annoying me for some time. Thanks for the code you've posted which I will try out. I use at least 2 instances of Emacs, 1 for gnus which often leads to capturing notes and tasks and the others for writing etc. Not having an automatic save can lead to problems.
--
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-27 5:47 ` Eric S Fraga
@ 2018-09-27 13:33 ` Kaushal Modi
2018-09-28 12:28 ` Kaushal Modi
0 siblings, 1 reply; 24+ messages in thread
From: Kaushal Modi @ 2018-09-27 13:33 UTC (permalink / raw)
To: tumashu, emacs-org list, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 1839 bytes --]
On Thu, Sep 27, 2018 at 1:47 AM Eric S Fraga <esflists@gmail.com> wrote:
> On Wednesday, 26 Sep 2018 at 13:11, Kaushal Modi wrote:
> > I had been wondering for quite some time (about since 5 months :P) why
> > my Org captures have stopped auto-saving.
>
> This has been really annoying me for some time. Thanks for the code
> you've posted which I will try out. I use at least 2 instances of Emacs, 1
> for gnus which often leads to capturing notes and tasks and the others for
> writing etc. Not having an automatic save can lead to problems.
>
I'd suggest reverting that commit.
Removing save-buffer from org-capture-finalize, makes the whole concept of
Org Capture very unsafe (i.e. no guarantee that the captured date will be
saved - unless the finalize hooks workaround is used). It feels like a bit
more extra work is needed to make org capture do the "right thing". If the
hooks are not configured, then there's a mental overhead of having to save
all the capture target buffers manually.
@tumashu <tumashu@163.com> You can easily avoid saving of the capture
target buffers on your phone by adding this to the emacs config just on
your phone:
(defun advice/dont-save-during-org-capture (orig-fun &rest args)
"Make `save-buffer' do nothing during `org-capture-finalize'."
(cl-letf (((symbol-function #'save-buffer)
(lambda ()
(message "Skipping `save-buffer' in `org-capture-finalize'")
nil)))
(apply orig-fun args)))
(advice-add 'org-capture-finalize :around
#'advice/dont-save-during-org-capture)
Above just makes save-buffer to do nothing, but *only* in
org-capture-finalize.
Summary:
- Proposal to revert
https://code.orgmode.org/bzg/org-mode/commit/b4422add3745c26ec3b2e11b8da425844b2e9d3d
- Use the above advice if you don't want to save buffer during org-capture.
[-- Attachment #2: Type: text/html, Size: 2667 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-27 13:33 ` Kaushal Modi
@ 2018-09-28 12:28 ` Kaushal Modi
2018-09-28 20:50 ` Nicolas Goaziou
0 siblings, 1 reply; 24+ messages in thread
From: Kaushal Modi @ 2018-09-28 12:28 UTC (permalink / raw)
To: tumashu, emacs-org list, Nicolas Goaziou
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
On Thu, Sep 27, 2018, 9:33 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:
>
> Summary:
>
> - Proposal to revert
> https://code.orgmode.org/bzg/org-mode/commit/b4422add3745c26ec3b2e11b8da425844b2e9d3d
> - Use the above advice if you don't want to save buffer during org-capture.
>
@Nicolas, tumashu: Would love to get your comments.
>
[-- Attachment #2: Type: text/html, Size: 1212 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-28 12:28 ` Kaushal Modi
@ 2018-09-28 20:50 ` Nicolas Goaziou
2018-09-28 21:17 ` Kaushal Modi
0 siblings, 1 reply; 24+ messages in thread
From: Nicolas Goaziou @ 2018-09-28 20:50 UTC (permalink / raw)
To: Kaushal Modi; +Cc: tumashu, emacs-org list
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> @Nicolas, tumashu: Would love to get your comments.
I don't remember the initial report.
However, saving the capture buffer may be problematic if there was
unsaved modifications before the capture process. Saving silently the
file would also save unrelated changes.
Also, isn't it easy enough to add a `save-buffer' call in a hook?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-28 20:50 ` Nicolas Goaziou
@ 2018-09-28 21:17 ` Kaushal Modi
2018-09-29 6:31 ` Nicolas Goaziou
0 siblings, 1 reply; 24+ messages in thread
From: Kaushal Modi @ 2018-09-28 21:17 UTC (permalink / raw)
To: tumashu, emacs-org list
[-- Attachment #1: Type: text/plain, Size: 2519 bytes --]
On Fri, Sep 28, 2018 at 4:50 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> Hello,
>
> Kaushal Modi <kaushal.modi@gmail.com> writes:
>
> > @Nicolas, tumashu: Would love to get your comments.
>
> I don't remember the initial report.
>
Sorry. Here's the original thread:
https://lists.gnu.org/r/emacs-orgmode/2018-04/msg00204.html
My email client shows the whole thread from then to now, so I forgot
pasting that.
> However, saving the capture buffer may be problematic if there was
> unsaved modifications before the capture process. Saving silently the
> file would also save unrelated changes.
>
That's a valid concern, though I see the risk of losing unsaved data as
higher than that.
Also, isn't it easy enough to add a `save-buffer' call in a hook?
>
The problem is that when org-capture-after-finalize-hook is run, the
indirect capture buffer is already killed, and the "context" is back to the
buffer where the M-x org-capture was initiated. So trying to do save-buffer
in that hook simply saves the unrelated buffer.
So another possible solution is:
- Save the capture base buffer to a new key in the org-capture-plist. And
have a org-capture-save-buffer function that save the buffer retrieved from
that key. That fn can then be run in org-capture-after-finalize-hook.
Since I last posted my workaround, I have updated that workaround to this:
(defun modi/org-capture-get-base-buffer ()
"Stores base buffer of the Org Capture indirect buffer.
The base buffer is stored in `:base-buffer' entry in
`org-capture-plist'."
(let ((base-buffer (buffer-base-buffer (current-buffer))))
(org-capture-put :base-buffer base-buffer)))
(add-hook 'org-capture-before-finalize-hook
#'modi/org-capture-get-base-buffer)
(defun modi/org-capture-save-base-buffer ()
"Saves the base buffer of the Org Capture indirect buffer.
The base buffer is retrieved from the `:base-buffer' entry in
`org-capture-plist'."
(when-let ((base-buffer (org-capture-get :base-buffer)))
(with-current-buffer base-buffer
(save-buffer))))
(add-hook 'org-capture-after-finalize-hook
#'modi/org-capture-save-base-buffer)
So the proposal is to do modify org-capture-finalize to set that
:base-buffer key so that one doesn't need to customize the
org-capture-before-finalize-hook hook.
And then modi/org-capture-save-base-buffer is basically
org-capture-save-buffer that I mentioned above.
With these changes, a user would need to just do:
(add-hook 'org-capture-after-finalize-hook #'org-capture-save-buffer)
[-- Attachment #2: Type: text/html, Size: 4099 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-28 21:17 ` Kaushal Modi
@ 2018-09-29 6:31 ` Nicolas Goaziou
2018-09-29 10:27 ` Eric S Fraga
0 siblings, 1 reply; 24+ messages in thread
From: Nicolas Goaziou @ 2018-09-29 6:31 UTC (permalink / raw)
To: Kaushal Modi; +Cc: tumashu, emacs-org list
Kaushal Modi <kaushal.modi@gmail.com> writes:
> Sorry. Here's the original thread:
> https://lists.gnu.org/r/emacs-orgmode/2018-04/msg00204.html
Thank you.
> My email client shows the whole thread from then to now, so I forgot
> pasting that.
Mine (Gnus) also used to, but, for some reason, it doesn't anymore.
> That's a valid concern, though I see the risk of losing unsaved data as
> higher than that.
Then saving should be the default again, and not saving optional.
What about introducing a :no-save keyword in capture templates? It could
be useful when the capture target is a remote file, as the OP noted, or
when you simply want to handle buffer saving manually.
Regards,
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-29 6:31 ` Nicolas Goaziou
@ 2018-09-29 10:27 ` Eric S Fraga
2018-09-29 10:35 ` Van L
0 siblings, 1 reply; 24+ messages in thread
From: Eric S Fraga @ 2018-09-29 10:27 UTC (permalink / raw)
To: Kaushal Modi; +Cc: tumashu, emacs-org list
On Saturday, 29 Sep 2018 at 08:31, Nicolas Goaziou wrote:
> Then saving should be the default again, and not saving optional.
I believe this would be the best option.
--
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-29 10:27 ` Eric S Fraga
@ 2018-09-29 10:35 ` Van L
2018-12-13 15:08 ` Kaushal Modi
0 siblings, 1 reply; 24+ messages in thread
From: Van L @ 2018-09-29 10:35 UTC (permalink / raw)
To: emacs-org list
>> Then saving should be the default again, and not saving optional.
>
> I believe this would be the best option.
Very, very strongly concur with this belief.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-09-29 10:35 ` Van L
@ 2018-12-13 15:08 ` Kaushal Modi
2018-12-13 15:24 ` Kaushal Modi
0 siblings, 1 reply; 24+ messages in thread
From: Kaushal Modi @ 2018-12-13 15:08 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: van, Eric Abrahamsen, emacs-org list, Bastien Guerry
[-- Attachment #1: Type: text/plain, Size: 932 bytes --]
Hello Nicolas,
While we are planning to cut Org 9.2 release this week, this one regression
in the Org Capture and auto-saving behavior comes to my mind, that I think
should be fixed.
Summary:
In Org 9.1.x, org-capture target files got auto-saved after C-c C-c when
ending the capture. In Org master branch, that stopped happening.
As per your last proposal, we should revert
https://code.orgmode.org/bzg/org-mode/commit/b4422add3745c26ec3b2e11b8da425844b2e9d3d
and then add a :no-save option that skips that save-buffer call.
Past references:
- https://lists.gnu.org/r/emacs-orgmode/2018-04/msg00204.html
- https://lists.gnu.org/r/emacs-orgmode/2018-09/msg00325.html
--
Kaushal Modi
On Sat, Sep 29, 2018 at 6:36 AM Van L <van@scratch.space> wrote:
>
> >> Then saving should be the default again, and not saving optional.
> >
> > I believe this would be the best option.
>
> Very, very strongly concur with this belief.
>
>
[-- Attachment #2: Type: text/html, Size: 1756 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-12-13 15:08 ` Kaushal Modi
@ 2018-12-13 15:24 ` Kaushal Modi
2018-12-13 15:33 ` Kaushal Modi
2018-12-13 16:25 ` Nicolas Goaziou
0 siblings, 2 replies; 24+ messages in thread
From: Kaushal Modi @ 2018-12-13 15:24 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: van, Eric Abrahamsen, emacs-org list, Bastien Guerry
[-- Attachment #1.1: Type: text/plain, Size: 739 bytes --]
On Thu, Dec 13, 2018 at 10:08 AM Kaushal Modi <kaushal.modi@gmail.com>
wrote:
> Hello Nicolas,
>
> While we are planning to cut Org 9.2 release this week, this one
> regression in the Org Capture and auto-saving behavior comes to my mind,
> that I think should be fixed.
>
> Summary:
>
> In Org 9.1.x, org-capture target files got auto-saved after C-c C-c when
> ending the capture. In Org master branch, that stopped happening.
>
> As per your last proposal, we should revert
> https://code.orgmode.org/bzg/org-mode/commit/b4422add3745c26ec3b2e11b8da425844b2e9d3d
> and then add a :no-save option that skips that save-buffer call.
>
I have formatted 2 patches to address this (attached). If they look fine, I
can commit them to master.
[-- Attachment #1.2: Type: text/html, Size: 1313 bytes --]
[-- Attachment #2: 0001-Revert-org-capture-Do-not-save-buffer-when-running-o.patch --]
[-- Type: application/octet-stream, Size: 984 bytes --]
From 54123cd7f20227d9679130bee907ede9e42e73fd Mon Sep 17 00:00:00 2001
From: Kaushal Modi <kaushal.modi@gmail.com>
Date: Thu, 13 Dec 2018 10:11:25 -0500
Subject: [PATCH 1/2] Revert "org-capture: Do not save buffer when running
`org-capture-finalize'"
This reverts commit b4422add3745c26ec3b2e11b8da425844b2e9d3d.
Revert the regression in Org capture + auto-saving behavior.
Ref: https://lists.gnu.org/r/emacs-orgmode/2018-09/msg00325.html
---
lisp/org-capture.el | 1 +
1 file changed, 1 insertion(+)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 2946b6fc5..a463e29fa 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -796,6 +796,7 @@ captured item after finalizing."
(org-encrypt-entry)))
;; Kill the indirect buffer
+ (save-buffer)
(let ((return-wconf (org-capture-get :return-to-wconf 'local))
(new-buffer (org-capture-get :new-buffer 'local))
(kill-buffer (org-capture-get :kill-buffer 'local))
--
2.18.0.547.g1d89318c4
[-- Attachment #3: 0002-Add-no-save-keyword-for-Org-capture-templates.patch --]
[-- Type: application/octet-stream, Size: 2100 bytes --]
From cbe7d03b427b31f30af04761eab04dd70191b64b Mon Sep 17 00:00:00 2001
From: Kaushal Modi <kaushal.modi@gmail.com>
Date: Thu, 13 Dec 2018 10:18:18 -0500
Subject: [PATCH 2/2] Add :no-save keyword for Org capture templates
Setting this will prevent capture target file saving upon finishing a
capture.
Ref: https://lists.gnu.org/r/emacs-orgmode/2018-09/msg00325.html
---
doc/org-manual.org | 4 ++++
lisp/org-capture.el | 8 ++++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index 051ffaa4d..b301d0a6a 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -7352,6 +7352,10 @@ Now lets look at the elements of a template definition. Each entry in
If the target file was not yet visited when capture was invoked, kill
the buffer again after capture is completed.
+ - ~:no-save~ ::
+
+ Do not save the target file after finishing the capture.
+
**** Template expansion
:PROPERTIES:
:DESCRIPTION: Filling in information about time and context.
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index a463e29fa..1d83741fc 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -266,6 +266,8 @@ properties are:
capture was invoked, kill the buffer again after capture
is finalized.
+ :no-save Do not save the target file after finishing the capture.
+
The template defines the text to be inserted. Often this is an
Org mode entry (so the first line should start with a star) that
will be filed as a child of the target headline. It can also be
@@ -795,8 +797,10 @@ captured item after finalizing."
(goto-char (org-capture-get :decrypted))
(org-encrypt-entry)))
- ;; Kill the indirect buffer
- (save-buffer)
+ (unless (org-capture-get :no-save)
+ ;; Save the target file.
+ (save-buffer))
+
(let ((return-wconf (org-capture-get :return-to-wconf 'local))
(new-buffer (org-capture-get :new-buffer 'local))
(kill-buffer (org-capture-get :kill-buffer 'local))
--
2.18.0.547.g1d89318c4
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-12-13 15:24 ` Kaushal Modi
@ 2018-12-13 15:33 ` Kaushal Modi
2018-12-13 16:25 ` Nicolas Goaziou
1 sibling, 0 replies; 24+ messages in thread
From: Kaushal Modi @ 2018-12-13 15:33 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: van, Eric Abrahamsen, emacs-org list, Bastien Guerry
[-- Attachment #1: Type: text/plain, Size: 685 bytes --]
On Thu, Dec 13, 2018 at 10:24 AM Kaushal Modi <kaushal.modi@gmail.com>
wrote:
>
> I have formatted 2 patches to address this (attached). If they look fine,
> I can commit them to master.
>
I forgot to properly format the commit messages.. locally, I have fixed the
commit message of 0002 patch to the below:
=====
Add :no-save keyword for Org capture templates
* lisp/org-capture.el (org-capture-finalize): Do not save the target
capture file if :no-save keyword is non-nil in the capture template.
* doc/org-manual.org (Template elements),
lisp/org-capture.el (org-capture-templates): Document :no-save.
Ref: https://lists.gnu.org/r/emacs-orgmode/2018-09/msg00325.html
=====
[-- Attachment #2: Type: text/html, Size: 1232 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-12-13 15:24 ` Kaushal Modi
2018-12-13 15:33 ` Kaushal Modi
@ 2018-12-13 16:25 ` Nicolas Goaziou
2018-12-13 19:12 ` Kaushal Modi
1 sibling, 1 reply; 24+ messages in thread
From: Nicolas Goaziou @ 2018-12-13 16:25 UTC (permalink / raw)
To: Kaushal Modi; +Cc: van, Eric Abrahamsen, emacs-org list, Bastien Guerry
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> I have formatted 2 patches to address this (attached). If they look fine, I
> can commit them to master.
Thank you.
> + (unless (org-capture-get :no-save)
> + ;; Save the target file.
> + (save-buffer))
The comment does not look terribly useful. I would put the whole
`unless' in a single line.
Barring that nitpicking of mine, LGTM!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH] org-capture: Add a custom to control save target file or not.
2018-12-13 16:25 ` Nicolas Goaziou
@ 2018-12-13 19:12 ` Kaushal Modi
0 siblings, 0 replies; 24+ messages in thread
From: Kaushal Modi @ 2018-12-13 19:12 UTC (permalink / raw)
To: van, Eric Abrahamsen, emacs-org list, Bastien Guerry
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
On Thu, Dec 13, 2018 at 11:25 AM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
>
> > + (unless (org-capture-get :no-save)
> > + ;; Save the target file.
> > + (save-buffer))
>
> The comment does not look terribly useful. I would put the whole
> `unless' in a single line.
>
> Barring that nitpicking of mine, LGTM!
>
Thanks. I have made the suggested change, and pushed to master, merged into
next.
[-- Attachment #2: Type: text/html, Size: 753 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2018-12-13 19:12 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-12 1:20 [PATCH] org-capture: Add a custom to control save target file or not tumashu
2018-04-12 13:22 ` Nicolas Goaziou
2018-04-13 2:10 ` tumashu
2018-04-14 7:44 ` Nicolas Goaziou
2018-04-14 9:42 ` tumashu
2018-04-16 1:06 ` tumashu
2018-04-16 10:11 ` Nicolas Goaziou
2018-09-26 17:11 ` Kaushal Modi
2018-09-26 17:29 ` Kaushal Modi
2018-09-26 18:11 ` Kaushal Modi
2018-09-27 5:47 ` Eric S Fraga
2018-09-27 13:33 ` Kaushal Modi
2018-09-28 12:28 ` Kaushal Modi
2018-09-28 20:50 ` Nicolas Goaziou
2018-09-28 21:17 ` Kaushal Modi
2018-09-29 6:31 ` Nicolas Goaziou
2018-09-29 10:27 ` Eric S Fraga
2018-09-29 10:35 ` Van L
2018-12-13 15:08 ` Kaushal Modi
2018-12-13 15:24 ` Kaushal Modi
2018-12-13 15:33 ` Kaushal Modi
2018-12-13 16:25 ` Nicolas Goaziou
2018-12-13 19:12 ` Kaushal Modi
2018-04-26 23:34 ` Bastien
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.