From 97314447e609e673be060bcdf0f244f396a70a3a Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 9 Feb 2023 01:09:10 +0000 Subject: Make 'narrowing-lock' and 'narrowing-unlock' internal * src/editfns.c (Finternal__lock_narrowing): Renamed from 'narrowing-lock'. (Finternal__unlock_narrowing): Renamed from 'narrowing-unlock'. (unwind_narrow_to_region_locked): (narrow_to_region_locked): (syms_of_editfns): Use the new names. * lisp/subr.el (internal--with-narrowing): Use the new name. --- lisp/subr.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index 32c997425cf..5cc0c94ba48 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3963,7 +3963,7 @@ detailed description. (save-restriction (progn (narrow-to-region start end) - (if tag (narrowing-lock tag)) + (if tag (internal--lock-narrowing tag)) (funcall body)))) (defun find-tag-default-bounds () -- cgit v1.2.1 From d8438e2bb44f448d1a0653321a8f262a1b6a3f2b Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 9 Feb 2023 01:09:10 +0000 Subject: Add 'without-narrowing' macro * lisp/subr.el (without-narrowing): New macro, companion (and almost identical) to 'with-narrowing'. --- lisp/subr.el | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index 5cc0c94ba48..af3f1f1abd5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3952,18 +3952,37 @@ and END limits, unless the restrictions are unlocked by calling `narrowing-unlock' with TAG. See `narrowing-lock' for a more detailed description. -\(fn START END [:locked TAG] BODY)" - (if (eq (car rest) :locked) +\(fn START END [:label LABEL] BODY)" + (if (eq (car rest) :label) `(internal--with-narrowing ,start ,end (lambda () ,@(cddr rest)) ,(cadr rest)) `(internal--with-narrowing ,start ,end (lambda () ,@rest)))) -(defun internal--with-narrowing (start end body &optional tag) +(defun internal--with-narrowing (start end body &optional label) "Helper function for `with-narrowing', which see." (save-restriction (progn (narrow-to-region start end) - (if tag (internal--lock-narrowing tag)) + (if label (internal--lock-narrowing label)) + (funcall body)))) + +(defmacro without-narrowing (&rest rest) + "Execute BODY without restrictions. + +The current restrictions, if any, are restored upon return. + +\(fn [:label LABEL] BODY)" + (if (eq (car rest) :label) + `(internal--without-narrowing (lambda () ,@(cddr rest)) + ,(cadr rest)) + `(internal--without-narrowing (lambda () ,@rest)))) + +(defun internal--without-narrowing (body &optional label) + "Helper function for `without-narrowing', which see." + (save-restriction + (progn + (if label (internal--unlock-narrowing label)) + (widen) (funcall body)))) (defun find-tag-default-bounds () -- cgit v1.2.1 From 79ce185ad1373845781646812638d4872b8aee69 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 9 Feb 2023 01:09:10 +0000 Subject: Update the documentation about labeled (locked) narrowing * src/xdisp.c (syms_of_xdisp) : Update docstring. * src/keyboard.c (syms_of_keyboard) : (syms_of_keyboard) : Update docstring. * src/editfns.c: (narrowing_locks): Explain why an alist is used instead of a buffer-local variable. (reset_outermost_narrowings): Point to recipes that demonstrate why it is necessary to restore the user narrowing bounds when redisplay starts. (Fwiden): Update docstring. (Fnarrow_to_region): Update docstring. (Finternal__lock_narrowing): Update docstring. (Finternal__unlock_narrowing): Update docstring. (Fsave_restriction): Update docstring. * src/buffer.c (syms_of_buffer) : Update docstring. (syms_of_buffer) : Update docstring. * lisp/subr.el (with-narrowing): Update docstring. (without-narrowing): Update docstring. * etc/NEWS: Mention the 'long-line-optimizations-region-size' and 'long-line-optimizations-bol-search-limit' options. Announce the 'with-narrowing' and 'without-narrowing' forms. * doc/lispref/positions.texi (Narrowing): Update the documentation of 'narrow-to-region', 'widen' and 'save-restriction'. Document the 'with-narrowing' and 'without-narrowing' special forms. * doc/lispref/display.texi (Auto Faces): Update the documentation. * doc/lispref/commands.texi (Command Overview): Document the fact that the buffer is narrowed around 'pre-command-hook' and 'post-command-hook' when the buffer text includes very long lines. --- lisp/subr.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index af3f1f1abd5..7ed0cb02a70 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3946,11 +3946,11 @@ See also `locate-user-emacs-file'.") The current restrictions, if any, are restored upon return. -With the optional :locked TAG argument, inside BODY, -`narrow-to-region' and `widen' can be used only within the START -and END limits, unless the restrictions are unlocked by calling -`narrowing-unlock' with TAG. See `narrowing-lock' for a more -detailed description. +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 +same LABEL argument. \(fn START END [:label LABEL] BODY)" (if (eq (car rest) :label) @@ -3971,6 +3971,10 @@ detailed description. 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 +are lifted. + \(fn [:label LABEL] BODY)" (if (eq (car rest) :label) `(internal--without-narrowing (lambda () ,@(cddr rest)) -- cgit v1.2.1 From dcb2379a463678bdadd05ee39d61e7da84c71c5e Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Mon, 13 Feb 2023 10:23:39 +0000 Subject: Minor improvements to labeled narrowing * lisp/subr.el (internal--with-narrowing): (internal--without-narrowing): Remove unnecessary 'progn'. * etc/NEWS: Mention 'with-narrowing' in the entry about long lines. * doc/lispref/positions.texi (Narrowing): Fix typo. * doc/lispref/display.texi (Auto Faces): Use @pxref. * doc/lispref/commands.texi (Command Overview): Use @pxref. --- lisp/subr.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index 7ed0cb02a70..d280c7fef13 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3961,10 +3961,9 @@ same LABEL argument. (defun internal--with-narrowing (start end body &optional label) "Helper function for `with-narrowing', which see." (save-restriction - (progn - (narrow-to-region start end) - (if label (internal--lock-narrowing label)) - (funcall body)))) + (narrow-to-region start end) + (if label (internal--lock-narrowing label)) + (funcall body))) (defmacro without-narrowing (&rest rest) "Execute BODY without restrictions. @@ -3984,10 +3983,9 @@ are lifted. (defun internal--without-narrowing (body &optional label) "Helper function for `without-narrowing', which see." (save-restriction - (progn - (if label (internal--unlock-narrowing label)) - (widen) - (funcall body)))) + (if label (internal--unlock-narrowing label)) + (widen) + (funcall body))) (defun find-tag-default-bounds () "Determine the boundaries of the default tag, based on text at point. -- cgit v1.2.1