command does.
Note that, when the buffer text includes very long lines, these two
-hooks are called as if they were in a @code{with-narrowing} form
+hooks are called as if they were in a @code{with-restriction} form
(@pxref{Narrowing}), with a
@code{long-line-optimizations-in-command-hooks} label and with the
buffer narrowed to a portion around point.
usually assign faces to around 400 to 600 characters at each call.
Note that, when the buffer text includes very long lines, these
-functions are called as if they were in a @code{with-narrowing} form
+functions are called as if they were in a @code{with-restriction} form
(@pxref{Narrowing}), with a
@code{long-line-optimizations-in-fontification-functions} label and
with the buffer narrowed to a portion around @var{pos}.
In an interactive call, @var{start} and @var{end} are set to the bounds
of the current region (point and the mark, with the smallest first).
-However, when the narrowing has been set by @code{with-narrowing} with
+However, when the narrowing has been set by @code{with-restriction} with
a label argument (see below), @code{narrow-to-region} can be used only
within the limits of that narrowing. If @var{start} or @var{end} are
outside these limits, the corresponding limit set by
-@code{with-narrowing} is used instead. To gain access to other
-portions of the buffer, use @code{without-narrowing} with the same
+@code{with-restriction} is used instead. To gain access to other
+portions of the buffer, use @code{without-restriction} with the same
label.
@end deffn
(narrow-to-region 1 (1+ (buffer-size)))
@end example
-However, when a narrowing has been set by @code{with-narrowing} with a
-label argument (see below), the limits set by @code{with-narrowing}
+However, when a narrowing has been set by @code{with-restriction} with a
+label argument (see below), the limits set by @code{with-restriction}
are restored, instead of canceling the narrowing. To gain access to
-other portions of the buffer, use @code{without-narrowing} with the
+other portions of the buffer, use @code{without-restriction} with the
same label.
@end deffn
Therefore, this construct is a clean way to narrow a buffer temporarily.
This construct also saves and restores the narrowings that were set by
-@code{with-narrowing} with a label argument (see below).
+@code{with-restriction} with a label argument (see below).
The value returned by @code{save-restriction} is that returned by the
last form in @var{body}, or @code{nil} if no body forms were given.
@end example
@end defspec
-@defspec with-narrowing start end [:label label] body
+@defspec with-restriction start end [:label label] body
This special form saves the current bounds of the accessible portion
of the buffer, sets the accessible portion to start at @var{start} and
end at @var{end}, evaluates the @var{body} forms, and restores the
limits.
@item
-To lift the restriction introduced by @code{with-narrowing} and gain
-access to other portions of the buffer, use @code{without-narrowing}
+To lift the restriction introduced by @code{with-restriction} and gain
+access to other portions of the buffer, use @code{without-restriction}
with the same @var{label} argument. (Another way to gain access to
other portions of the buffer is to use an indirect buffer
(@pxref{Indirect Buffers}).)
@end itemize
@end defspec
-@defspec without-narrowing [:label label] body
+@defspec without-restriction [:label label] body
This special form saves the current bounds of the accessible portion
of the buffer, widens the buffer, evaluates the @var{body} forms, and
restores the saved bounds. In that case it is equivalent to
@end example
When the optional @var{label} argument is present however, the
-narrowing set by @code{with-narrowing} with the same @var{label}
+narrowing set by @code{with-restriction} with the same @var{label}
argument is lifted.
@end defspec
hooks are executed on a narrowed portion of the buffer, whose size is
controlled by the variables 'long-line-optimizations-region-size' and
'long-line-optimizations-bol-search-limit', as if they were in a
-'with-narrowing' form. This may, in particular, cause occasional
+'with-restriction form. This may, in particular, cause occasional
mis-fontifications in these buffers.
The new function 'long-line-optimizations-p' returns non-nil when
'set-transient-map-timeout'.
+++
-** New forms 'with-narrowing' and 'without-narrowing'.
+** New forms 'with-restriction' and 'without-restriction'.
These forms can be used as enhanced alternatives to the
'save-restriction' form combined with, respectively,
'narrow-to-region' and 'widen'. They also accept an optional label
"Return non-nil if the current buffer is narrowed."
(/= (- (point-max) (point-min)) (buffer-size)))
-(defmacro with-narrowing (start end &rest rest)
+(defmacro with-restriction (start end &rest rest)
"Execute BODY with restrictions set to START and END.
The current restrictions, if any, are restored upon return.
When the optional :label LABEL argument is present, in which
LABEL is a symbol, inside BODY, `narrow-to-region' and `widen'
can be used only within the START and END limits. To gain access
-to other portions of the buffer, use `without-narrowing' with the
+to other portions of the buffer, use `without-restriction' with the
same LABEL argument.
\(fn START END [:label LABEL] BODY)"
(if (eq (car rest) :label)
- `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest))
+ `(internal--with-restriction ,start ,end (lambda () ,@(cddr rest))
,(cadr rest))
- `(internal--with-narrowing ,start ,end (lambda () ,@rest))))
+ `(internal--with-restriction ,start ,end (lambda () ,@rest))))
-(defun internal--with-narrowing (start end body &optional label)
- "Helper function for `with-narrowing', which see."
+(defun internal--with-restriction (start end body &optional label)
+ "Helper function for `with-restriction', which see."
(save-restriction
(narrow-to-region start end)
(if label (internal--lock-narrowing label))
(funcall body)))
-(defmacro without-narrowing (&rest rest)
+(defmacro without-restriction (&rest rest)
"Execute BODY without restrictions.
The current restrictions, if any, are restored upon return.
When the optional :label LABEL argument is present, the
-restrictions set by `with-narrowing' with the same LABEL argument
+restrictions set by `with-restriction' with the same LABEL argument
are lifted.
\(fn [:label LABEL] BODY)"
(if (eq (car rest) :label)
- `(internal--without-narrowing (lambda () ,@(cddr rest))
+ `(internal--without-restriction (lambda () ,@(cddr rest))
,(cadr rest))
- `(internal--without-narrowing (lambda () ,@rest))))
+ `(internal--without-restriction (lambda () ,@rest))))
-(defun internal--without-narrowing (body &optional label)
- "Helper function for `without-narrowing', which see."
+(defun internal--without-restriction (body &optional label)
+ "Helper function for `without-restriction', which see."
(save-restriction
(if label (internal--unlock-narrowing label))
(widen)
`long-line-optimizations-p' is non-nil. For performance reasons, in
such buffers, the `fontification-functions', `pre-command-hook' and
`post-command-hook' hooks are executed on a narrowed buffer around
-point, as if they were called in a `with-narrowing' form with a label.
+point, as if they were called in a `with-restriction' form with a label.
This variable specifies the size of the narrowed region around point.
To disable that narrowing, set this variable to 0.
`long-line-optimizations-p' is non-nil. For performance reasons, in
such buffers, the `fontification-functions', `pre-command-hook' and
`post-command-hook' hooks are executed on a narrowed buffer around
-point, as if they were called in a `with-narrowing' form with a label.
+point, as if they were called in a `with-restriction' form with a label.
The variable `long-line-optimizations-region-size' specifies the
size of the narrowed region around point. This variable, which should
be a small integer, specifies the number of characters by which that
This allows the buffer's full text to be seen and edited.
-However, when restrictions have been set by `with-narrowing' with a
-label, `widen' restores the narrowing limits set by `with-narrowing'.
+However, when restrictions have been set by `with-restriction' with a
+label, `widen' restores the narrowing limits set by `with-restriction'.
To gain access to other portions of the buffer, use
-`without-narrowing' with the same label. */)
+`without-restriction' with the same label. */)
(void)
{
Fset (Qoutermost_narrowing, Qnil);
positions (integers or markers) bounding the text that should
remain visible.
-However, when restrictions have been set by `with-narrowing' with a
+However, when restrictions have been set by `with-restriction' with a
label, `narrow-to-region' can be used only within the limits of these
restrictions. If the START or END arguments are outside these limits,
-the corresponding limit set by `with-narrowing' is used instead of the
+the corresponding limit set by `with-restriction' is used instead of the
argument. To gain access to other portions of the buffer, use
-`without-narrowing' with the same label. */)
+`without-restriction' with the same label. */)
(Lisp_Object start, Lisp_Object end)
{
EMACS_INT s = fix_position (start), e = fix_position (end);
Sinternal__lock_narrowing, 1, 1, 0,
doc: /* Lock the current narrowing with LABEL.
-This is an internal function used by `with-narrowing'. */)
+This is an internal function used by `with-restriction'. */)
(Lisp_Object tag)
{
Lisp_Object buf = Fcurrent_buffer ();
Sinternal__unlock_narrowing, 1, 1, 0,
doc: /* Unlock a narrowing locked with LABEL.
-This is an internal function used by `without-narrowing'. */)
+This is an internal function used by `without-restriction'. */)
(Lisp_Object tag)
{
Lisp_Object buf = Fcurrent_buffer ();
The buffer's restrictions make parts of the beginning and end invisible.
\(They are set up with `narrow-to-region' and eliminated with `widen'.)
This special form, `save-restriction', saves the current buffer's
-restrictions, including those that were set by `with-narrowing' with a
+restrictions, including those that were set by `with-restriction' with a
label argument, when it is entered, and restores them when it is exited.
So any `narrow-to-region' within BODY lasts only until the end of the form.
The old restrictions settings are restored even in case of abnormal exit
the error might happen repeatedly and make Emacs nonfunctional.
Note that, when `long-line-optimizations-p' is non-nil in the buffer,
-these functions are called as if they were in a `with-narrowing' form,
+these functions are called as if they were in a `with-restriction' form,
with a `long-line-optimizations-in-command-hooks' label and with the
buffer narrowed to a portion around point whose size is specified by
`long-line-optimizations-region-size'.
avoid making Emacs unresponsive while the user types.
Note that, when `long-line-optimizations-p' is non-nil in the buffer,
-these functions are called as if they were in a `with-narrowing' form,
+these functions are called as if they were in a `with-restriction' form,
with a `long-line-optimizations-in-command-hooks' label and with the
buffer narrowed to a portion around point whose size is specified by
`long-line-optimizations-region-size'.
fontified regions the property `fontified' with a non-nil value.
Note that, when `long-line-optimizations-p' is non-nil in the buffer,
-these functions are called as if they were in a `with-narrowing' form,
+these functions are called as if they were in a `with-restriction' form,
with a `long-line-optimizations-in-fontification-functions' label and
with the buffer narrowed to a portion around POS whose size is
specified by `long-line-optimizations-region-size'. */);
)))
(ert-deftest test-labeled-narrowing ()
- "Test `with-narrowing' and `without-narrowing'."
+ "Test `with-restriction' and `without-restriction'."
(with-current-buffer (generate-new-buffer " foo" t)
(insert (make-string 5000 ?a))
(should (= (point-min) 1))
(should (= (point-max) 5001))
- (with-narrowing
+ (with-restriction
100 500 :label 'foo
(should (= (point-min) 100))
(should (= (point-max) 500))
(narrow-to-region 400 1000)
(should (= (point-min) 400))
(should (= (point-max) 500))
- (without-narrowing
+ (without-restriction
:label 'bar
(should (= (point-min) 100))
(should (= (point-max) 500)))
- (without-narrowing
+ (without-restriction
:label 'foo
(should (= (point-min) 1))
(should (= (point-max) 5001)))
(widen)
(should (= (point-min) 100))
(should (= (point-max) 500))
- (with-narrowing
+ (with-restriction
50 250 :label 'bar
(should (= (point-min) 100))
(should (= (point-max) 250))
(widen)
(should (= (point-min) 100))
(should (= (point-max) 250))
- (without-narrowing
+ (without-restriction
:label 'bar
(should (= (point-min) 100))
(should (= (point-max) 500))
- (without-narrowing
+ (without-restriction
:label 'foo
(should (= (point-min) 1))
(should (= (point-max) 5001)))
(should (= (point-max) 250)))
(should (= (point-min) 100))
(should (= (point-max) 500))
- (with-narrowing
+ (with-restriction
50 250 :label 'bar
(should (= (point-min) 100))
(should (= (point-max) 250))
- (with-narrowing
+ (with-restriction
150 500 :label 'baz
(should (= (point-min) 150))
(should (= (point-max) 250))
- (without-narrowing
+ (without-restriction
:label 'bar
(should (= (point-min) 150))
(should (= (point-max) 250)))
- (without-narrowing
+ (without-restriction
:label 'foo
(should (= (point-min) 150))
(should (= (point-max) 250)))
- (without-narrowing
+ (without-restriction
:label 'baz
(should (= (point-min) 100))
(should (= (point-max) 250))
- (without-narrowing
+ (without-restriction
:label 'foo
(should (= (point-min) 100))
(should (= (point-max) 250)))
- (without-narrowing
+ (without-restriction
:label 'bar
(should (= (point-min) 100))
(should (= (point-max) 500))
- (without-narrowing
+ (without-restriction
:label 'foobar
(should (= (point-min) 100))
(should (= (point-max) 500)))
- (without-narrowing
+ (without-restriction
:label 'foo
(should (= (point-min) 1))
(should (= (point-max) 5001)))