all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* buffer-swap-text
@ 2008-10-21 10:42 Eli Zaretskii
  2008-10-21 13:56 ` buffer-swap-text Stefan Monnier
  2008-10-21 19:40 ` buffer-swap-text Richard M. Stallman
  0 siblings, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2008-10-21 10:42 UTC (permalink / raw)
  To: emacs-devel

Should this function swap the value of buffer-file-coding-system as
well?  Otherwise, we could confuse the user if the swapped text cannot
be saved with the current buffer's encoding, and we will then pop up
questions when the user tries to save.





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

* Re: buffer-swap-text
  2008-10-21 10:42 buffer-swap-text Eli Zaretskii
@ 2008-10-21 13:56 ` Stefan Monnier
  2008-10-21 15:30   ` buffer-swap-text Eli Zaretskii
  2008-10-21 19:40 ` buffer-swap-text Richard M. Stallman
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-10-21 13:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

> Should this function swap the value of buffer-file-coding-system as
> well?  Otherwise, we could confuse the user if the swapped text cannot
> be saved with the current buffer's encoding, and we will then pop up
> questions when the user tries to save.

I see buffer-swap-text as a (very) low-level function.  So, I'd rather
let the code that uses it deal with things like
buffer-file-coding-system.  I don't think we have enough experience with
it to decide whether that variable (or any other for that matter) needs
to be swap alongside the buffer's text.


        Stefan




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

* Re: buffer-swap-text
  2008-10-21 13:56 ` buffer-swap-text Stefan Monnier
@ 2008-10-21 15:30   ` Eli Zaretskii
  2008-10-21 22:04     ` buffer-swap-text Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2008-10-21 15:30 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: emacs-devel@gnu.org
> Date: Tue, 21 Oct 2008 09:56:15 -0400
> 
> > Should this function swap the value of buffer-file-coding-system as
> > well?  Otherwise, we could confuse the user if the swapped text cannot
> > be saved with the current buffer's encoding, and we will then pop up
> > questions when the user tries to save.
> 
> I see buffer-swap-text as a (very) low-level function.  So, I'd
> rather let the code that uses it deal with things like
> buffer-file-coding-system.

I cannot imagine a situation where code that uses this function would
not want to copy buffer-file-coding-system.

> I don't think we have enough experience with it to decide whether
> that variable (or any other for that matter) needs to be swap
> alongside the buffer's text.

I'm okay with trying and erring like that, but I think that the only
reason this didn't come up yet is because the 2 sole users of this
function (tar-mode and pmail) swap text between a unibyte buffer and a
multibyte buffer, and saving is allowed only from the unibyte one (and
pmail is not yet used widely anyway).




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

* Re: buffer-swap-text
  2008-10-21 10:42 buffer-swap-text Eli Zaretskii
  2008-10-21 13:56 ` buffer-swap-text Stefan Monnier
@ 2008-10-21 19:40 ` Richard M. Stallman
  2008-10-21 22:06   ` buffer-swap-text Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Richard M. Stallman @ 2008-10-21 19:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

    Should this function swap the value of buffer-file-coding-system as
    well?

We need to address the general question of what C-x C-s should do in a
buffer where you have done the swap.  I think your question is part of
that question.




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

* Re: buffer-swap-text
  2008-10-21 15:30   ` buffer-swap-text Eli Zaretskii
@ 2008-10-21 22:04     ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2008-10-21 22:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>> > Should this function swap the value of buffer-file-coding-system as
>> > well?  Otherwise, we could confuse the user if the swapped text cannot
>> > be saved with the current buffer's encoding, and we will then pop up
>> > questions when the user tries to save.
>> I see buffer-swap-text as a (very) low-level function.  So, I'd
>> rather let the code that uses it deal with things like
>> buffer-file-coding-system.
> I cannot imagine a situation where code that uses this function would
> not want to copy buffer-file-coding-system.

>> I don't think we have enough experience with it to decide whether
>> that variable (or any other for that matter) needs to be swap
>> alongside the buffer's text.

> I'm okay with trying and erring like that, but I think that the only
> reason this didn't come up yet is because the 2 sole users of this
> function (tar-mode and pmail) swap text between a unibyte buffer and a
> multibyte buffer, and saving is allowed only from the unibyte one (and
> pmail is not yet used widely anyway).

Could be.  But I expect that 99.99% of the uses of buffer-swap-text will
follow this model.  Note also that the need to swap
buffer-file-coding-system depends on how the file is saved.

If the coding system to use is non-trivial, then writing the buffer-save
functionality might become far from obvious (since the save might query
the user about which coding-system to use, displaying the problematic
chars, but these are in the "other" buffer rather than the one normally
displayed), so I don't expect this use case to be common, and if it
comes up, we'll probably have much larger problems to deal with than
merely swapping buffer-file-coding-system.

Furthermore, I'd expect that swapping might not always be right: most
likely one of the two buffers will be a fresh new buffer, so swapping
would mean that the old buffer gets a buffer-file-coding-system set to
nil, which will be reflected in the modeline.


        Stefan




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

* Re: buffer-swap-text
  2008-10-21 19:40 ` buffer-swap-text Richard M. Stallman
@ 2008-10-21 22:06   ` Stefan Monnier
  2008-10-23  3:06     ` buffer-swap-text Richard M. Stallman
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-10-21 22:06 UTC (permalink / raw)
  To: rms; +Cc: Eli Zaretskii, emacs-devel

>     Should this function swap the value of buffer-file-coding-system as
>     well?

> We need to address the general question of what C-x C-s should do in a
> buffer where you have done the swap.  I think your question is part of
> that question.

This depends on the use case.  It might be worthwhile to point to
write-region-annotate-functions as a good way to do the save (at least
it's the method used in tar-mode and seems to provide a sane behavior,
even in cases where the user uses write-region or C-x C-w).


        Stefan




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

* Re: buffer-swap-text
  2008-10-21 22:06   ` buffer-swap-text Stefan Monnier
@ 2008-10-23  3:06     ` Richard M. Stallman
  2008-10-23  3:24       ` buffer-swap-text Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Richard M. Stallman @ 2008-10-23  3:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: eliz, emacs-devel

    > We need to address the general question of what C-x C-s should do in a
    > buffer where you have done the swap.  I think your question is part of
    > that question.

    This depends on the use case.

We have seen two use cases, which are somewhat similar.
What do they do?  Is there one approach that would work for both?

I think we need a feature that lets one buffer point to the other
and say "save that one instead".  And swapping should turn this
on and off.  So when Rmail or Arc mode swaps the buffers, it should
make the visible buffer point to the other one saying "save that instead".
And when it unswaps them, it should reverse that, making the hidden buffer
point to the visible one saying "save that instead".

So here's the proposed feature.

1. A buffer-local variable buffer-save-other-buffer.

2. If that is non-nil, it should be a buffer, and `basic-save-buffer'
saves that buffer instead.

3. When `buffer-swap-text' sees that buffer A's
buffer-save-other-buffer points to buffer B, it "swaps" that, making
buffer B's buffer-save-other-buffer point to buffer A instead.

If the mode doesn't use the buffer-save-other-buffer feature, that
variable will be nil in both buffers, so `buffer-swap-text' won't
change it.




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

* Re: buffer-swap-text
  2008-10-23  3:06     ` buffer-swap-text Richard M. Stallman
@ 2008-10-23  3:24       ` Stefan Monnier
  2008-10-23 21:09         ` buffer-swap-text Richard M. Stallman
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2008-10-23  3:24 UTC (permalink / raw)
  To: rms; +Cc: eliz, emacs-devel

>> We need to address the general question of what C-x C-s should do in a
>> buffer where you have done the swap.  I think your question is part of
>> that question.

>     This depends on the use case.

> We have seen two use cases, which are somewhat similar.
> What do they do?  Is there one approach that would work for both?

> I think we need a feature that lets one buffer point to the other
> and say "save that one instead".  And swapping should turn this
> on and off.  So when Rmail or Arc mode swaps the buffers, it should
> make the visible buffer point to the other one saying "save that instead".
> And when it unswaps them, it should reverse that, making the hidden buffer
> point to the visible one saying "save that instead".

> So here's the proposed feature.

> 1. A buffer-local variable buffer-save-other-buffer.

> 2. If that is non-nil, it should be a buffer, and `basic-save-buffer'
> saves that buffer instead.

> 3. When `buffer-swap-text' sees that buffer A's
> buffer-save-other-buffer points to buffer B, it "swaps" that, making
> buffer B's buffer-save-other-buffer point to buffer A instead.

> If the mode doesn't use the buffer-save-other-buffer feature, that
> variable will be nil in both buffers, so `buffer-swap-text' won't
> change it.

I don't see any benefit to hardcode this in buffer-swap-text.
We may very well rename buffer-swap-text to buffer-swap-text-internal
and introduce a new buffer-swap-text which can perform such things
(probably using write-region-annotation-function), as well as swap
variables like buffer-file-coding-system.

I'd rather we first get more experience with it to see how it's used
in practice.


        Stefan




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

* Re: buffer-swap-text
  2008-10-23  3:24       ` buffer-swap-text Stefan Monnier
@ 2008-10-23 21:09         ` Richard M. Stallman
  2008-10-24  4:05           ` buffer-swap-text Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Richard M. Stallman @ 2008-10-23 21:09 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: eliz, emacs-devel

    I don't see any benefit to hardcode this in buffer-swap-text.
    We may very well rename buffer-swap-text to buffer-swap-text-internal
    and introduce a new buffer-swap-text which can perform such things
    (probably using write-region-annotation-function), as well as swap
    variables like buffer-file-coding-system.

That would be ok, I suppose, but one advantage of doing it in C
is that there is no chance anything can cause it to swap
the text without swapping the rest.




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

* Re: buffer-swap-text
  2008-10-23 21:09         ` buffer-swap-text Richard M. Stallman
@ 2008-10-24  4:05           ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2008-10-24  4:05 UTC (permalink / raw)
  To: rms; +Cc: eliz, emacs-devel

>     I don't see any benefit to hardcode this in buffer-swap-text.
>     We may very well rename buffer-swap-text to buffer-swap-text-internal
>     and introduce a new buffer-swap-text which can perform such things
>     (probably using write-region-annotation-function), as well as swap
>     variables like buffer-file-coding-system.

> That would be ok, I suppose, but one advantage of doing it in C
> is that there is no chance anything can cause it to swap
> the text without swapping the rest.

It is not necessary to swap the rest at the same time.
More specifically, it will not cause any inconsistency or crash.

Now, maybe in all practical cases swapping those other things will be
necessary to provide the desired behavior, but there may just as well be
uses of buffer-swap-text where swapping those other variables is not
needed or undesirable.


        Stefan




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

end of thread, other threads:[~2008-10-24  4:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21 10:42 buffer-swap-text Eli Zaretskii
2008-10-21 13:56 ` buffer-swap-text Stefan Monnier
2008-10-21 15:30   ` buffer-swap-text Eli Zaretskii
2008-10-21 22:04     ` buffer-swap-text Stefan Monnier
2008-10-21 19:40 ` buffer-swap-text Richard M. Stallman
2008-10-21 22:06   ` buffer-swap-text Stefan Monnier
2008-10-23  3:06     ` buffer-swap-text Richard M. Stallman
2008-10-23  3:24       ` buffer-swap-text Stefan Monnier
2008-10-23 21:09         ` buffer-swap-text Richard M. Stallman
2008-10-24  4:05           ` buffer-swap-text Stefan Monnier

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.