* What should I use to unrestrict a buffer?
@ 2024-01-24 20:12 hw
2024-01-25 7:14 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: hw @ 2024-01-24 20:12 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
in a function, I would like to remove all restrictions from a buffer
because I want to perform an operation with it that doesn't work well
on it when the buffer is restricted (i. e. narrowed). Essentially,
the buffer contents are piped through an external program and then get
replaced by its output, using
(shell-command-on-region (point-min) (point-max) ...).
I found that only the part of the buffer is piped and replaced which
the buffer is narrowed to, and that is very undesirable because
everything outside the narrowing gets lost that way.
At first I thought I can just use (widen) to remove the narrowing, but
the documentation of that indicates that there can be more
restrictions, possibly using labels, that can apparently narrow a
buffer.
Can there be other restrictions on a buffer that might interfere?
Also, I don't want possible restrictions to be restored, like
(without-restriction) would do.
So what should I use to unrestrict a buffer?
Is there a way to find out if there are any restrictions that might
interfere? It might suffice to give a warning message that
restrictions need to be removed before the operation can be performed;
then they could be removed manually.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What should I use to unrestrict a buffer?
2024-01-24 20:12 What should I use to unrestrict a buffer? hw
@ 2024-01-25 7:14 ` Eli Zaretskii
2024-01-25 18:30 ` hw
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-01-25 7:14 UTC (permalink / raw)
To: help-gnu-emacs
> From: hw <hw@adminart.net>
> Date: Wed, 24 Jan 2024 21:12:56 +0100
>
> Also, I don't want possible restrictions to be restored, like
> (without-restriction) would do.
Why not? After you do whatever you need to do with the widened
buffer, you are supposed to return the restrictions to their previous
state, and that includes restoring the restrictions present before the
widening. Why would you need to avoid restoring them, and thus change
the restrictions behind some other Lisp program which doesn't expect
its restrictions to be lifted?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What should I use to unrestrict a buffer?
2024-01-25 7:14 ` Eli Zaretskii
@ 2024-01-25 18:30 ` hw
2024-01-25 19:03 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: hw @ 2024-01-25 18:30 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 2024-01-25 at 09:14 +0200, Eli Zaretskii wrote:
> > From: hw <hw@adminart.net>
> > Date: Wed, 24 Jan 2024 21:12:56 +0100
> >
> > Also, I don't want possible restrictions to be restored, like
> > (without-restriction) would do.
>
> Why not? After you do whatever you need to do with the widened
> buffer, you are supposed to return the restrictions to their previous
> state, and that includes restoring the restrictions present before the
> widening. Why would you need to avoid restoring them, and thus change
> the restrictions behind some other Lisp program which doesn't expect
> its restrictions to be lifted?
I want to behold the whole buffer after the operation was performed to
see if the outcome looks ok. And if the external program has found an
error, it puts a message into the first line of its output (the
buffer) which I'm unlikely to be able to see when the buffer is
restricted.
Keeping or restoring restrictions wouldn't be useful.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What should I use to unrestrict a buffer?
2024-01-25 18:30 ` hw
@ 2024-01-25 19:03 ` Eli Zaretskii
2024-02-08 5:38 ` hw
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-01-25 19:03 UTC (permalink / raw)
To: help-gnu-emacs
> From: hw <hw@adminart.net>
> Date: Thu, 25 Jan 2024 19:30:17 +0100
>
> On Thu, 2024-01-25 at 09:14 +0200, Eli Zaretskii wrote:
> > > From: hw <hw@adminart.net>
> > > Date: Wed, 24 Jan 2024 21:12:56 +0100
> > >
> > > Also, I don't want possible restrictions to be restored, like
> > > (without-restriction) would do.
> >
> > Why not? After you do whatever you need to do with the widened
> > buffer, you are supposed to return the restrictions to their previous
> > state, and that includes restoring the restrictions present before the
> > widening. Why would you need to avoid restoring them, and thus change
> > the restrictions behind some other Lisp program which doesn't expect
> > its restrictions to be lifted?
>
> I want to behold the whole buffer after the operation was performed to
> see if the outcome looks ok. And if the external program has found an
> error, it puts a message into the first line of its output (the
> buffer) which I'm unlikely to be able to see when the buffer is
> restricted.
>
> Keeping or restoring restrictions wouldn't be useful.
The restrictions that cannot be lifted via a call to 'widen' aren't
supposed to be lifted. IOW, a Lisp program that calls 'widen' is not
allowed to look beyond those restrictions that 'widen' cannot remove.
So what you want to do is not supposed to be done, and this is a
protocol of using restrictions in Emacs.
The problem is not serious, btw, since it is a very rare situation to
see such restrictions in practice. So you can simply disregard that
possibility.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What should I use to unrestrict a buffer?
2024-01-25 19:03 ` Eli Zaretskii
@ 2024-02-08 5:38 ` hw
0 siblings, 0 replies; 5+ messages in thread
From: hw @ 2024-02-08 5:38 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 2024-01-25 at 21:03 +0200, Eli Zaretskii wrote:
> > From: hw <hw@adminart.net>
> > Date: Thu, 25 Jan 2024 19:30:17 +0100
> >
> > On Thu, 2024-01-25 at 09:14 +0200, Eli Zaretskii wrote:
> > > > From: hw <hw@adminart.net>
> > > > Date: Wed, 24 Jan 2024 21:12:56 +0100
> > > >
> > > > Also, I don't want possible restrictions to be restored, like
> > > > (without-restriction) would do.
> > >
> > > Why not? After you do whatever you need to do with the widened
> > > buffer, you are supposed to return the restrictions to their previous
> > > state, and that includes restoring the restrictions present before the
> > > widening. Why would you need to avoid restoring them, and thus change
> > > the restrictions behind some other Lisp program which doesn't expect
> > > its restrictions to be lifted?
> >
> > I want to behold the whole buffer after the operation was performed to
> > see if the outcome looks ok. And if the external program has found an
> > error, it puts a message into the first line of its output (the
> > buffer) which I'm unlikely to be able to see when the buffer is
> > restricted.
> >
> > Keeping or restoring restrictions wouldn't be useful.
>
> The restrictions that cannot be lifted via a call to 'widen' aren't
> supposed to be lifted. IOW, a Lisp program that calls 'widen' is not
> allowed to look beyond those restrictions that 'widen' cannot remove.
> So what you want to do is not supposed to be done, and this is a
> protocol of using restrictions in Emacs.
>
> The problem is not serious, btw, since it is a very rare situation to
> see such restrictions in practice. So you can simply disregard that
> possibility.
I can't just disregard the problem because disregarding it means that
many hours of work which may have been done over many years could get
lost in an instance just because some buffer restriction has been
overlooked.
Is there a way to find out if any restrictions are in effect so that
the function may refuse to replace the buffer contents when
restrictions could lead to loosing those contents, or parts of them?
Otherwise it's an accident waiting to happen, and it basically makes
all functionality to pipe buffer contents through external programs
and updating the buffer with the result, if not useless, at least a
bad security risk.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-08 5:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-24 20:12 What should I use to unrestrict a buffer? hw
2024-01-25 7:14 ` Eli Zaretskii
2024-01-25 18:30 ` hw
2024-01-25 19:03 ` Eli Zaretskii
2024-02-08 5:38 ` hw
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.