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)