emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9d8a6c8283: Fix the bytecode incompatibility due to the change to


From: Gregory Heytings
Subject: master 9d8a6c8283: Fix the bytecode incompatibility due to the change to 'narrow-to-region'.
Date: Mon, 1 Aug 2022 15:12:44 -0400 (EDT)

branch: master
commit 9d8a6c82838f2f24e76a67379b02956aa668d7cf
Author: Gregory Heytings <gregory@heytings.org>
Commit: Gregory Heytings <gregory@heytings.org>

    Fix the bytecode incompatibility due to the change to 'narrow-to-region'.
    
    * src/editfns.c (narrow_to_region_internal): New function, which
    contains the body previously in 'Fnarrow_to_region' but accepts
    a third argument.
    (Fnarrow_to_region): Use the new function. Update the docstring.
    (Fwiden): Update the docstring.
    
    * src/lisp.h: Prototype of the new function.
    
    * src/xdisp.c (handle_fontified_prop): Use the new function instead
    of 'Fnarrow_to_region'.
    
    * src/process.c (Finternal_default_process_filter):
    * src/lread.c (readevalloop): Remove the third argument to
    'Fnarrow_to_region'.
    
    * src/bytecode.c (exec_byte_code):
    * lisp/emacs-lisp/comp.el (comp-limplify-lap-inst):
    * lisp/emacs-lisp/bytecomp.el: Restore the statu quo ante.
    
    * etc/NEWS: Remove the entry about the new optional argument.
    
    * doc/lispref/positions.texi (Narrowing): Update the documentation.
---
 doc/lispref/positions.texi  | 15 ++++++-------
 etc/NEWS                    |  7 ------
 lisp/emacs-lisp/bytecomp.el |  4 ++--
 lisp/emacs-lisp/comp.el     |  5 ++++-
 src/bytecode.c              |  4 ++--
 src/editfns.c               | 52 ++++++++++++++++++++++++++-------------------
 src/lisp.h                  |  1 +
 src/lread.c                 |  2 +-
 src/process.c               |  2 +-
 src/xdisp.c                 |  3 ++-
 10 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi
index 3a9a152f8d..e08ee76ed9 100644
--- a/doc/lispref/positions.texi
+++ b/doc/lispref/positions.texi
@@ -995,7 +995,7 @@ the entire buffer regardless of any narrowing.
 types of text, consider using an alternative facility described in
 @ref{Swapping Text}.
 
-@deffn Command narrow-to-region start end &optional lock
+@deffn Command narrow-to-region start end
 This function sets the accessible portion of the current buffer to start
 at @var{start} and end at @var{end}.  Both arguments should be character
 positions.
@@ -1003,10 +1003,9 @@ positions.
 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).
 
-When @var{lock} is non-@code{nil}, calls to @code{widen}, or to
-@code{narrow-to-region} with an optional argument @var{lock}
-@code{nil}, do not produce any effect until the end of the current
-body form.
+Note that, in rare circumstances, Emacs may decide to leave, for
+performance reasons, the accessible portion of the buffer unchanged
+after a call to @code{narrow-to-region}.
 @end deffn
 
 @deffn Command narrow-to-page &optional move-count
@@ -1032,9 +1031,9 @@ It is equivalent to the following expression:
 @end example
 @end deffn
 
-However, when @code{widen} is called inside a body form in which
-@code{narrow-to-region} was called with an optional argument
-@code{lock} non-@code{nil}, it does not produce any effect.
+Note that, in rare circumstances, Emacs may decide to leave, for
+performance reasons, the accessible portion of the buffer unchanged
+after a call to @code{widen}.
 
 @defun buffer-narrowed-p
 This function returns non-@code{nil} if the buffer is narrowed, and
diff --git a/etc/NEWS b/etc/NEWS
index 963aa22c68..b011413cbc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2560,13 +2560,6 @@ things to be saved.
 ** New function 'string-equal-ignore-case'.
 This compares strings ignoring case differences.
 
-+++
-** New argument LOCK of 'narrow-to-region'.
-If 'narrow-to-region' is called from Lisp with the new optional
-argument LOCK non-nil, then calls to 'widen' and calls to
-'narrow-to-region' with the optional argument LOCK nil or omitted do
-not produce any effect until the end of the current body form.
-
 ** Themes
 
 ---
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 1ecd77f751..b4954eee9f 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -767,7 +767,7 @@ Each element is (INDEX . VALUE)")
 (byte-defop 122  0 byte-char-syntax)
 (byte-defop 123 -1 byte-buffer-substring)
 (byte-defop 124 -1 byte-delete-region)
-(byte-defop 125 -2 byte-narrow-to-region)
+(byte-defop 125 -1 byte-narrow-to-region)
 (byte-defop 126  1 byte-widen)
 (byte-defop 127  0 byte-end-of-line)
 
@@ -3833,7 +3833,7 @@ If it is nil, then the handler is 
\"byte-compile-SYMBOL.\""
 (byte-defop-compiler setcdr            2)
 (byte-defop-compiler buffer-substring  2)
 (byte-defop-compiler delete-region     2)
-(byte-defop-compiler narrow-to-region  2-3)
+(byte-defop-compiler narrow-to-region  2)
 (byte-defop-compiler (% byte-rem)      2)
 (byte-defop-compiler aset              3)
 
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 4354ea03a4..5ee10fcbca 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -1915,7 +1915,10 @@ and the annotation emission."
       (byte-char-syntax auto)
       (byte-buffer-substring auto)
       (byte-delete-region auto)
-      (byte-narrow-to-region auto)
+      (byte-narrow-to-region
+       (comp-emit-set-call (comp-call 'narrow-to-region
+                                      (comp-slot)
+                                      (comp-slot+1))))
       (byte-widen
        (comp-emit-set-call (comp-call 'widen)))
       (byte-end-of-line auto)
diff --git a/src/bytecode.c b/src/bytecode.c
index 2b1eccdc51..d75767bb0c 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1480,8 +1480,8 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
 
        CASE (Bnarrow_to_region):
          {
-           Lisp_Object v2 = POP, v1 = POP;
-           TOP = Fnarrow_to_region (TOP, v1, v2);
+           Lisp_Object v1 = POP;
+           TOP = Fnarrow_to_region (TOP, v1);
            NEXT;
          }
 
diff --git a/src/editfns.c b/src/editfns.c
index 79af27d24d..35b2415e8b 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2660,9 +2660,10 @@ DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
        doc: /* Remove restrictions (narrowing) from current buffer.
 This allows the buffer's full text to be seen and edited.
 
-When called from Lisp inside a body form in which `narrow-to-region'
-was called with an optional argument LOCK non-nil, this function does
-not produce any effect.  */)
+Note that, when the current buffer contains one or more lines whose
+length is above `long-line-threshold', Emacs may decide to leave, for
+performance reasons, the accessible portion of the buffer unchanged
+after this function is called.  */)
   (void)
 {
   if (! NILP (Vrestrictions_locked))
@@ -2689,22 +2690,11 @@ unwind_locked_zv (Lisp_Object point_max)
   SET_BUF_ZV (current_buffer, XFIXNUM (point_max));
 }
 
-DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 3, "r",
-       doc: /* Restrict editing in this buffer to the current region.
-The rest of the text becomes temporarily invisible and untouchable
-but is not deleted; if you save the buffer in a file, the invisible
-text is included in the file.  \\[widen] makes all visible again.
-See also `save-restriction'.
-
-When calling from Lisp, pass two arguments START and END:
-positions (integers or markers) bounding the text that should
-remain visible.
-
-When called from Lisp with the optional argument LOCK non-nil,
-calls to `widen', or to `narrow-to-region' with an optional
-argument LOCK nil, do not produce any effect until the end of
-the current body form.  */)
-  (Lisp_Object start, Lisp_Object end, Lisp_Object lock)
+/* Internal function for Fnarrow_to_region, meant to be used with a
+   third argument 'true', in which case it should be followed by "specbind
+   (Qrestrictions_locked, Qt)".  */
+Lisp_Object
+narrow_to_region_internal (Lisp_Object start, Lisp_Object end, bool lock)
 {
   EMACS_INT s = fix_position (start), e = fix_position (end);
 
@@ -2713,7 +2703,7 @@ the current body form.  */)
       EMACS_INT tem = s; s = e; e = tem;
     }
 
-  if (! NILP (lock))
+  if (lock)
     {
       if (!(BEGV <= s && s <= e && e <= ZV))
        args_out_of_range (start, end);
@@ -2727,8 +2717,6 @@ the current body form.  */)
 
       SET_BUF_BEGV (current_buffer, s);
       SET_BUF_ZV (current_buffer, e);
-
-      specbind (Qrestrictions_locked, Qt);
     }
   else
     {
@@ -2754,6 +2742,26 @@ the current body form.  */)
   return Qnil;
 }
 
+DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
+       doc: /* Restrict editing in this buffer to the current region.
+The rest of the text becomes temporarily invisible and untouchable
+but is not deleted; if you save the buffer in a file, the invisible
+text is included in the file.  \\[widen] makes all visible again.
+See also `save-restriction'.
+
+When calling from Lisp, pass two arguments START and END:
+positions (integers or markers) bounding the text that should
+remain visible.
+
+Note that, when the current buffer contains one or more lines whose
+length is above `long-line-threshold', Emacs may decide to leave, for
+performance reasons, the accessible portion of the buffer unchanged
+after this function is called.  */)
+  (Lisp_Object start, Lisp_Object end)
+{
+  return narrow_to_region_internal (start, end, false);
+}
+
 Lisp_Object
 save_restriction_save (void)
 {
diff --git a/src/lisp.h b/src/lisp.h
index 807fcb0e5b..c8ad0bc56f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4679,6 +4679,7 @@ extern void save_restriction_restore (Lisp_Object);
 extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool);
 extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t,
                                            ptrdiff_t, bool);
+extern Lisp_Object narrow_to_region_internal (Lisp_Object, Lisp_Object, bool);
 extern void init_editfns (void);
 extern void syms_of_editfns (void);
 
diff --git a/src/lread.c b/src/lread.c
index 0720774db2..0b46a2e4ee 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2261,7 +2261,7 @@ readevalloop (Lisp_Object readcharfun,
          /* Set point and ZV around stuff to be read.  */
          Fgoto_char (start);
          if (!NILP (end))
-           Fnarrow_to_region (make_fixnum (BEGV), end, Qnil);
+           Fnarrow_to_region (make_fixnum (BEGV), end);
 
          /* Just for cleanliness, convert END to a marker
             if it is an integer.  */
diff --git a/src/process.c b/src/process.c
index a15efa39bd..1ac5a509e5 100644
--- a/src/process.c
+++ b/src/process.c
@@ -6339,7 +6339,7 @@ Otherwise it discards the output.  */)
 
       /* If the restriction isn't what it should be, set it.  */
       if (old_begv != BEGV || old_zv != ZV)
-       Fnarrow_to_region (make_fixnum (old_begv), make_fixnum (old_zv), Qnil);
+       Fnarrow_to_region (make_fixnum (old_begv), make_fixnum (old_zv));
 
       bset_read_only (current_buffer, old_read_only);
       SET_PT_BOTH (opoint, opoint_byte);
diff --git a/src/xdisp.c b/src/xdisp.c
index 88a489e290..65d9221a15 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -4406,7 +4406,8 @@ handle_fontified_prop (struct it *it)
              if (!begv) begv = BEGV;
              zv = get_narrowed_zv (it->w, charpos);
            }
-         Fnarrow_to_region (make_fixnum (begv), make_fixnum (zv), Qt);
+         narrow_to_region_internal (make_fixnum (begv), make_fixnum (zv), 
true);
+         specbind (Qrestrictions_locked, Qt);
        }
 
       /* Don't allow Lisp that runs from 'fontification-functions'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]