emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: tumashu <tumashu@163.com>, emacs-org list <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-capture: Add a custom to control save target file or not.
Date: Fri, 28 Sep 2018 17:17:39 -0400	[thread overview]
Message-ID: <CAFyQvY1b8-VqkUH6uTnCyKC63E1UUaaePp5sDwmu+_dyz1uWgg@mail.gmail.com> (raw)
In-Reply-To: <87sh1t5ots.fsf@nicolasgoaziou.fr>

[-- 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 --]

  reply	other threads:[~2018-09-28 21:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFyQvY1b8-VqkUH6uTnCyKC63E1UUaaePp5sDwmu+_dyz1uWgg@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tumashu@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).