emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* buffer-file-name in [* Org src *] buffers
@ 2018-03-11 22:56 Clément Pit-Claudel
  2018-03-12  3:47 ` numbchild
  2018-03-12 14:38 ` Nicolas Goaziou
  0 siblings, 2 replies; 7+ messages in thread
From: Clément Pit-Claudel @ 2018-03-11 22:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

TL;DR: why does org-src-mode-configure-edit-buffer set buffer-file-name to a non-nil value?  https://code.orgmode.org/bzg/org-mode/commit/4b6988bf36cb458c9d113ee4332e016990c1eb04#diff-ea848b037ba2c0bf95915700bb6f4e539d80d8cR486

Background information: I'm reviewing a patch (https://github.com/flycheck/flycheck/pull/1426) to enable Flycheck in temporary buffers created by org-mode while editing a code snippet with org-edit-src-code (among others).  The patch teaches Flycheck to append an checker-appropriate extension to the temporary files that it creates: for example, when editing a Python snippet from an Org file, Flycheck would now create a file named /tmp/<random string>.py instead of /tmp/<random string> (which would make Python happy).

We're thinking of enabling this automatic suffix addition behavior only for buffers that do not have a buffer-file-name currently set (in the ones that do, Flycheck already derives file names for its temporary files from the buffer's  file name), but we were surprised to find that [* Org src *] actually have a buffer-file-name.

Why is that?

Thanks,
Clément.

 

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-03-11 22:56 buffer-file-name in [* Org src *] buffers Clément Pit-Claudel
@ 2018-03-12  3:47 ` numbchild
  2018-03-12 14:38 ` Nicolas Goaziou
  1 sibling, 0 replies; 7+ messages in thread
From: numbchild @ 2018-03-12  3:47 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: Org-mode

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

I agree, should compatible with situations like `flycheck` need to use
buffer-file-name.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Mon, Mar 12, 2018 at 6:56 AM, Clément Pit-Claudel <cpitclaudel@gmail.com>
wrote:

> Hi all,
>
> TL;DR: why does org-src-mode-configure-edit-buffer set buffer-file-name
> to a non-nil value?  https://code.orgmode.org/bzg/org-mode/commit/
> 4b6988bf36cb458c9d113ee4332e016990c1eb04#diff-
> ea848b037ba2c0bf95915700bb6f4e539d80d8cR486
>
> Background information: I'm reviewing a patch (
> https://github.com/flycheck/flycheck/pull/1426) to enable Flycheck in
> temporary buffers created by org-mode while editing a code snippet with
> org-edit-src-code (among others).  The patch teaches Flycheck to append an
> checker-appropriate extension to the temporary files that it creates: for
> example, when editing a Python snippet from an Org file, Flycheck would now
> create a file named /tmp/<random string>.py instead of /tmp/<random string>
> (which would make Python happy).
>
> We're thinking of enabling this automatic suffix addition behavior only
> for buffers that do not have a buffer-file-name currently set (in the ones
> that do, Flycheck already derives file names for its temporary files from
> the buffer's  file name), but we were surprised to find that [* Org src *]
> actually have a buffer-file-name.
>
> Why is that?
>
> Thanks,
> Clément.
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2605 bytes --]

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-03-11 22:56 buffer-file-name in [* Org src *] buffers Clément Pit-Claudel
  2018-03-12  3:47 ` numbchild
@ 2018-03-12 14:38 ` Nicolas Goaziou
  2018-03-14 14:18   ` Clément Pit-Claudel
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2018-03-12 14:38 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: emacs-orgmode

Hello,

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

> TL;DR: why does org-src-mode-configure-edit-buffer set
> buffer-file-name to a non-nil value?
> https://code.orgmode.org/bzg/org-mode/commit/4b6988bf36cb458c9d113ee4332e016990c1eb04#diff-ea848b037ba2c0bf95915700bb6f4e539d80d8cR486

[...]

> Why is that?

The explanation is here:

<http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00335.html>

AFAIU, this was needed so that Emacs would warn when closing a remote
editing buffer with C-x k. This feature doesn't appear to be functional
at the moment, tho.

Regards,

-- 
Nicolas Goaziou

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-03-12 14:38 ` Nicolas Goaziou
@ 2018-03-14 14:18   ` Clément Pit-Claudel
  2018-03-14 19:57     ` Nicolas Goaziou
  2018-04-26 23:34     ` Bastien
  0 siblings, 2 replies; 7+ messages in thread
From: Clément Pit-Claudel @ 2018-03-14 14:18 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Nicolas Goaziou

Hi Nicolas,

> The explanation is here:
> 
> <http://lists.gnu.org/archive/html/emacs-orgmode/2009-08/msg00335.html>
> 
> AFAIU, this was needed so that Emacs would warn when closing a remote
> editing buffer with C-x k. This feature doesn't appear to be functional
> at the moment, tho.

Sorry for the delayed answer; I didn't receive your message.

Thanks for the link to the discussion.  It'd be great to find a different way to do it, though, as the current implementation sends a confusing signal to other packages.

The original implementation listed three problems:

> * Proposed bug I
>       C-x k kills the edit buffer without questions; the overlay
>       remains, but now links to a deleted buffer.
> * Proposed bug II
>       C-x C-c kills a modified edit buffer silently, without offering to
>       save your work. I have lost work like that a number of times
>       recently.
> * Proposed bug III
>       C-x s does not offer to save a modified edit buffer

It also mentioned this:

> This patch gives the desired behaviour, at the cost of being forced
> to assign a buffer-file-name to the edit buffer. The consequence is
> that the edit buffer is considered to always be modified

I think there's an alternative fix for these issues that doesn't require setting buffer-file-name:

1. Set buffer-offer-save to 'always; this guarantees that C-x s will ask about the edit buffer.
2. Add an entry to kill-buffer-query-functions.  For example, with-editor (used by magit) does this:
   (add-hook 'kill-buffer-query-functions
             'with-editor-kill-buffer-noop nil t)

With these, we could leave buffer-file-name to nil.

WDYT?
Clément.

PS: point (1) shares an issue with the original implementation (it always prompts during save-some-buffers).  One fix to this could be to add a buffer-modification-hook that marks the source buffer as modified when the edit buffer is modified, and to make change the source buffer's write-contents-functions to offer to save edit buffers too.

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-03-14 14:18   ` Clément Pit-Claudel
@ 2018-03-14 19:57     ` Nicolas Goaziou
  2018-04-26 23:34     ` Bastien
  1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2018-03-14 19:57 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: emacs-orgmode

Hello,

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

> 1. Set buffer-offer-save to 'always; this guarantees that C-x s will ask about the edit buffer.
> 2. Add an entry to kill-buffer-query-functions.  For example, with-editor (used by magit) does this:
>    (add-hook 'kill-buffer-query-functions
>              'with-editor-kill-buffer-noop nil t)
>
> With these, we could leave buffer-file-name to nil.
>
> WDYT?

`buffer-offer-save' is already set to a non-nil value. See
`org-src-mode-configure-edit-buffer'.

> PS: point (1) shares an issue with the original implementation (it
> always prompts during save-some-buffers). One fix to this could be to
> add a buffer-modification-hook that marks the source buffer as modified
> when the edit buffer is modified, and to make change the source buffer's
> write-contents-functions to offer to save edit buffers too.

Right. Then we might as well use the second solution instead, and leave
out both `buffer-file-name' and `buffer-offer-save'.

So, would you want to implement it?


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-03-14 14:18   ` Clément Pit-Claudel
  2018-03-14 19:57     ` Nicolas Goaziou
@ 2018-04-26 23:34     ` Bastien
  2018-04-27  5:06       ` Clément Pit-Claudel
  1 sibling, 1 reply; 7+ messages in thread
From: Bastien @ 2018-04-26 23:34 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: emacs-orgmode, Nicolas Goaziou

Hi Clément and Nicolas,

Clément Pit-Claudel <cpitclaudel@gmail.com> writes:

>> * Proposed bug I
>>       C-x k kills the edit buffer without questions; the overlay
>>       remains, but now links to a deleted buffer.
>> * Proposed bug II
>>       C-x C-c kills a modified edit buffer silently, without offering to
>>       save your work. I have lost work like that a number of times
>>       recently.
>> * Proposed bug III
>>       C-x s does not offer to save a modified edit buffer

I've removed the setting of `buffer-file-name' in Org Src buffers.

buffer-offer-save being non-nil, but I and II are solved, and I don't
see a situation where bug III is still relevant when bugs I and II are
fixed.

Let me know if you think otherwise.

Thanks,

-- 
 Bastien

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

* Re: buffer-file-name in [* Org src *] buffers
  2018-04-26 23:34     ` Bastien
@ 2018-04-27  5:06       ` Clément Pit-Claudel
  0 siblings, 0 replies; 7+ messages in thread
From: Clément Pit-Claudel @ 2018-04-27  5:06 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Nicolas Goaziou

On 2018-04-26 19:34, Bastien wrote:
> Hi Clément and Nicolas,
> […]
> I've removed the setting of `buffer-file-name' in Org Src buffers.

Wonderful news, thanks Bastien !

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

end of thread, other threads:[~2018-04-27  5:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-11 22:56 buffer-file-name in [* Org src *] buffers Clément Pit-Claudel
2018-03-12  3:47 ` numbchild
2018-03-12 14:38 ` Nicolas Goaziou
2018-03-14 14:18   ` Clément Pit-Claudel
2018-03-14 19:57     ` Nicolas Goaziou
2018-04-26 23:34     ` Bastien
2018-04-27  5:06       ` Clément Pit-Claudel

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).