unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 56682@debbugs.gnu.org, monnier@iro.umontreal.ca
Subject: bug#56682: feature/improved-locked-narrowing 9dee6df39c: Reworked locked narrowing.
Date: Tue, 09 May 2023 21:48:42 +0000	[thread overview]
Message-ID: <24b4118b217952fab8dd@heytings.org> (raw)
In-Reply-To: <83mt2igelb.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]


>>>> +      struct Lisp_Marker *begv
>>>> +	= labeled_restrictions_get_bound (buf, true, true);
>>>> +      struct Lisp_Marker *zv
>>>> +	= labeled_restrictions_get_bound (buf, false, true);
>>>
>>> Why the strange design of having a function return a pointer to a 
>>> 'struct Lisp_Marker'? why not return the marker itself instead?  (I 
>>> realize that this was so in the code we already have, but I still 
>>> don't understand why you did it that way, and prefer that function to 
>>> return a marker instead.)
>>
>> Good question.  You mean that it would have been better to return a 
>> Lisp_Object, right?  I don't recall exactly, I think it was because in 
>> the calls to SET_BUF_BEGV_BOTH/SET_BUF_ZV_BOTH (which are the only 
>> places where the return value of labeled_restrictions_get_bound are 
>> used) one can use the pointer to a struct Lisp_Marker immediately, 
>> whereas a call to XMARKER would have been necessary if a Lisp_Object 
>> had been used.
>
> I'd prefer to use a marker there, but that can be a separate changeset.
>

Can you confirm that the attached patch is what you would prefer?  IMHO it 
is better/clearer to have a single call to XMARKER in 
'labeled_restrictions_get_bound', instead of having to repeat it 
everywhere its return value is used.  The price is indeed that the 
signature of that (internal) function is unusual.  (Note that we cannot 
wrap the calls to 'labeled_restrictions_get_bound' in a call to XMARKER, 
because it can return nil.)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: editfns.patch --]
[-- Type: text/x-diff; name=editfns.patch, Size: 6106 bytes --]

diff --git a/src/editfns.c b/src/editfns.c
index 4c5b691eb50..9d35491a6d8 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2687,20 +2687,19 @@ labeled_restrictions_remove (Lisp_Object buf)
 }
 
 /* Retrieve one of the labeled restriction bounds in BUF from the
-   labeled_restrictions alist, as a pointer to a struct Lisp_Marker,
-   or return NULL if BUF is not in labeled_restrictions or is a killed
-   buffer.  When OUTERMOST is true, the restriction bounds that were
-   current when the first labeled restriction was entered are
-   returned.  Otherwise the bounds of the innermost labeled
-   restriction are returned.  */
-static struct Lisp_Marker *
+   labeled_restrictions alist, as a marker, or return nil if BUF is
+   not in labeled_restrictions or is a killed buffer.  When OUTERMOST
+   is true, the restriction bounds that were current when the first
+   labeled restriction was entered are returned.  Otherwise the bounds
+   of the innermost labeled restriction are returned.  */
+static Lisp_Object
 labeled_restrictions_get_bound (Lisp_Object buf, bool begv, bool outermost)
 {
   if (NILP (Fbuffer_live_p (buf)))
-    return NULL;
+    return Qnil;
   Lisp_Object restrictions = assq_no_quit (buf, labeled_restrictions);
   if (NILP (restrictions))
-    return NULL;
+    return Qnil;
   restrictions = XCAR (XCDR (restrictions));
   Lisp_Object bounds
     = outermost
@@ -2709,7 +2708,7 @@ labeled_restrictions_get_bound (Lisp_Object buf, bool begv, bool outermost)
   eassert (! NILP (bounds));
   Lisp_Object marker = begv ? XCAR (bounds) : XCAR (XCDR (bounds));
   eassert (EQ (Fmarker_buffer (marker), buf));
-  return XMARKER (marker);
+  return marker;
 }
 
 /* Retrieve the label of the innermost labeled restriction in BUF.
@@ -2766,14 +2765,14 @@ labeled_restrictions_remove_in_current_buffer (void)
 static void
 unwind_reset_outermost_restriction (Lisp_Object buf)
 {
-  struct Lisp_Marker *begv
-    = labeled_restrictions_get_bound (buf, true, false);
-  struct Lisp_Marker *zv
-    = labeled_restrictions_get_bound (buf, false, false);
-  if (begv != NULL && zv != NULL)
+  Lisp_Object begv = labeled_restrictions_get_bound (buf, true, false);
+  Lisp_Object zv = labeled_restrictions_get_bound (buf, false, false);
+  if (! NILP (begv) && ! NILP (zv))
     {
-      SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos);
-      SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos);
+      SET_BUF_BEGV_BOTH (XBUFFER (buf),
+			 XMARKER (begv)->charpos, XMARKER (begv)->bytepos);
+      SET_BUF_ZV_BOTH (XBUFFER (buf),
+		       XMARKER (zv)->charpos, XMARKER (zv)->bytepos);
     }
   else
     labeled_restrictions_remove (buf);
@@ -2797,14 +2796,14 @@ reset_outermost_restrictions (void)
     {
       buf = XCAR (XCAR (val));
       eassert (BUFFERP (buf));
-      struct Lisp_Marker *begv
-	= labeled_restrictions_get_bound (buf, true, true);
-      struct Lisp_Marker *zv
-	= labeled_restrictions_get_bound (buf, false, true);
-      if (begv != NULL && zv != NULL)
+      Lisp_Object begv = labeled_restrictions_get_bound (buf, true, true);
+      Lisp_Object zv = labeled_restrictions_get_bound (buf, false, true);
+      if (! NILP (begv) && ! NILP (zv))
 	{
-	  SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos);
-	  SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos);
+	  SET_BUF_BEGV_BOTH (XBUFFER (buf),
+			     XMARKER (begv)->charpos, XMARKER (begv)->bytepos);
+	  SET_BUF_ZV_BOTH (XBUFFER (buf),
+			   XMARKER (zv)->charpos, XMARKER (zv)->bytepos);
 	  record_unwind_protect (unwind_reset_outermost_restriction, buf);
 	}
       else
@@ -2878,15 +2877,15 @@ DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
     }
   else
     {
-      struct Lisp_Marker *begv
-	= labeled_restrictions_get_bound (buf, true, false);
-      struct Lisp_Marker *zv
-	= labeled_restrictions_get_bound (buf, false, false);
-      eassert (begv != NULL && zv != NULL);
-      if (begv->charpos != BEGV || zv->charpos != ZV)
+      Lisp_Object begv = labeled_restrictions_get_bound (buf, true, false);
+      Lisp_Object zv = labeled_restrictions_get_bound (buf, false, false);
+      eassert (! NILP (begv) && ! NILP (zv));
+      if (XMARKER (begv)->charpos != BEGV || XMARKER (zv)->charpos != ZV)
 	current_buffer->clip_changed = 1;
-      SET_BUF_BEGV_BOTH (current_buffer, begv->charpos, begv->bytepos);
-      SET_BUF_ZV_BOTH (current_buffer, zv->charpos, zv->bytepos);
+      SET_BUF_BEGV_BOTH (current_buffer,
+			 XMARKER (begv)->charpos, XMARKER (begv)->bytepos);
+      SET_BUF_ZV_BOTH (current_buffer,
+		       XMARKER (zv)->charpos, XMARKER (zv)->bytepos);
       /* If the only remaining bounds in labeled_restrictions for
 	 current_buffer are the bounds that were set by the user, no
 	 labeled restriction is in effect in current_buffer anymore:
@@ -2933,15 +2932,13 @@ positions (integers or markers) bounding the text that should
     {
       /* Limit the start and end positions to those of the innermost
 	 labeled restriction.  */
-      struct Lisp_Marker *begv
-	= labeled_restrictions_get_bound (buf, true, false);
-      struct Lisp_Marker *zv
-	= labeled_restrictions_get_bound (buf, false, false);
-      eassert (begv != NULL && zv != NULL);
-      if (s < begv->charpos) s = begv->charpos;
-      if (s > zv->charpos) s = zv->charpos;
-      if (e < begv->charpos) e = begv->charpos;
-      if (e > zv->charpos) e = zv->charpos;
+      Lisp_Object begv = labeled_restrictions_get_bound (buf, true, false);
+      Lisp_Object zv = labeled_restrictions_get_bound (buf, false, false);
+      eassert (! NILP (begv) && ! NILP (zv));
+      if (s < XMARKER (begv)->charpos) s = XMARKER (begv)->charpos;
+      if (s > XMARKER (zv)->charpos) s = XMARKER (zv)->charpos;
+      if (e < XMARKER (begv)->charpos) e = XMARKER (begv)->charpos;
+      if (e > XMARKER (zv)->charpos) e = XMARKER (zv)->charpos;
     }
 
   /* Record the accessible range of the buffer when narrow-to-region

  reply	other threads:[~2023-05-09 21:48 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <166939872890.18950.12581667269687468681@vcs2.savannah.gnu.org>
     [not found] ` <20221125175209.51166C004B6@vcs2.savannah.gnu.org>
     [not found]   ` <jwvk028zxbs.fsf-monnier+emacs@gnu.org>
2022-12-30 16:38     ` bug#56682: feature/improved-locked-narrowing 9dee6df39c: Reworked locked narrowing Gregory Heytings
2022-12-30 16:41       ` Gregory Heytings
2022-12-30 17:01       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-30 17:25         ` Gregory Heytings
2022-12-30 18:51           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-12  9:34             ` Eli Zaretskii
2023-01-14 21:38               ` Gregory Heytings
2023-01-26  7:29                 ` Eli Zaretskii
2023-01-28 15:11                   ` Gregory Heytings
2023-01-28 15:36                     ` Eli Zaretskii
2023-01-30  9:00                       ` Gregory Heytings
2023-01-30 13:07                         ` Eli Zaretskii
2023-01-30 15:03                           ` Gregory Heytings
2023-01-30 17:11                             ` Eli Zaretskii
2023-01-30 17:24                               ` Juri Linkov
2023-01-30 17:52                                 ` Eli Zaretskii
2023-01-30 17:56                                   ` Juri Linkov
2023-01-30 18:05                                     ` Eli Zaretskii
2023-01-30 18:56                               ` Dmitry Gutov
2023-01-30 19:02                                 ` Eli Zaretskii
2023-01-30 21:07                                   ` Dmitry Gutov
2023-01-30 21:49                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-30 23:29                                       ` Dmitry Gutov
2023-01-31 12:14                                     ` Eli Zaretskii
2023-01-31 15:58                                       ` Dmitry Gutov
2023-01-31 15:17                                 ` Gregory Heytings
2023-01-31 16:03                                   ` Dmitry Gutov
2023-01-31 15:14                               ` Gregory Heytings
2023-01-31 16:25                                 ` Dmitry Gutov
2023-01-31 21:46                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-31 22:25                                     ` Dmitry Gutov
2023-02-01 18:55                                 ` Eli Zaretskii
2023-02-01 20:46                                   ` dick
2023-02-01 22:42                                   ` Gregory Heytings
2023-02-02  6:43                                     ` Eli Zaretskii
2023-02-03  0:20                                       ` Gregory Heytings
2023-02-03  7:39                                         ` Eli Zaretskii
2023-02-03 22:12                                           ` Gregory Heytings
2023-02-04  6:32                                             ` Eli Zaretskii
2023-02-09  1:57                                               ` Gregory Heytings
2023-02-09  7:01                                                 ` Eli Zaretskii
2023-02-09 10:33                                                   ` Gregory Heytings
2023-02-09 14:26                                                     ` Eli Zaretskii
2023-02-09 14:39                                                       ` Gregory Heytings
2023-02-09 15:46                                                         ` Eli Zaretskii
2023-02-09 16:11                                                           ` Gregory Heytings
2023-02-09 17:02                                                             ` Eli Zaretskii
2023-02-09 17:44                                                               ` Juri Linkov
2023-02-09 20:47                                                               ` Gregory Heytings
2023-02-09 22:46                                                                 ` Drew Adams
2023-02-09 23:06                                                                   ` Drew Adams
2023-02-13 18:11                                                                   ` Eli Zaretskii
2023-02-10  7:44                                                                 ` Eli Zaretskii
2023-02-10 23:05                                                                   ` Gregory Heytings
2023-02-09 17:31                                                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-09 17:43                                                             ` Eli Zaretskii
2023-02-09 17:57                                                             ` Juri Linkov
2023-02-10 16:46                                                   ` Andrea Corallo
2023-02-11  7:18                                                     ` Eli Zaretskii
2023-02-13 11:00                                                       ` Gregory Heytings
2023-02-13 18:10                                                         ` Eli Zaretskii
2023-02-14 10:30                                                           ` Gregory Heytings
2023-02-14 14:37                                                             ` Eli Zaretskii
2023-02-14 14:59                                                               ` Gregory Heytings
2023-02-14 16:55                                                                 ` Eli Zaretskii
2023-02-14 22:50                                                                   ` Gregory Heytings
2023-02-15 12:36                                                                     ` Eli Zaretskii
2023-02-15 13:37                                                                       ` Gregory Heytings
2023-02-15 14:10                                                                         ` Eli Zaretskii
2023-02-15 14:37                                                                           ` Gregory Heytings
2023-02-18 23:12                                                                             ` Gregory Heytings
2023-02-19  6:29                                                                               ` Eli Zaretskii
     [not found]                                                                                 ` <a9b3c867-aa6a-2979-a83-dd700e985c9@heytings.org>
2023-03-29 14:52                                                                                   ` Gregory Heytings
2023-04-01  0:27                                                                                     ` Gregory Heytings
2023-04-01  5:42                                                                                       ` Eli Zaretskii
2023-04-01  9:04                                                                                         ` Gregory Heytings
2023-04-01 11:11                                                                                     ` Eli Zaretskii
2023-04-01 14:26                                                                                       ` Gregory Heytings
2023-04-01 15:09                                                                                         ` Eli Zaretskii
2023-04-01 15:41                                                                                           ` Gregory Heytings
2023-04-01 16:21                                                                                             ` Eli Zaretskii
2023-04-01 17:01                                                                                               ` Gregory Heytings
2023-04-01 17:12                                                                                                 ` Eli Zaretskii
2023-04-01 21:56                                                                                                   ` Gregory Heytings
2023-04-02  5:16                                                                                                     ` Eli Zaretskii
2023-04-04  2:55                                                                                                       ` Richard Stallman
2023-04-04 10:50                                                                                                         ` Eli Zaretskii
     [not found]                                                                                                       ` <ccfcc63b8da74932424b@heytings.org>
2023-05-04  5:31                                                                                                         ` Eli Zaretskii
2023-05-04 15:45                                                                                                           ` Gregory Heytings
2023-05-05 15:26                                                                                                             ` Eli Zaretskii
2023-05-05 21:29                                                                                                               ` Gregory Heytings
2023-05-06  6:26                                                                                                                 ` Eli Zaretskii
2023-05-09 21:48                                                                                                                   ` Gregory Heytings [this message]
2023-05-10 14:00                                                                                                                     ` Eli Zaretskii
2023-05-12 11:12                                                                                                                       ` Eli Zaretskii
2023-05-12 12:50                                                                                                                         ` Gregory Heytings
2023-05-12 22:18                                                                                                                           ` Gregory Heytings
2023-05-13  6:41                                                                                                                             ` Eli Zaretskii
2023-01-30 14:46                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-30 15:05                           ` Gregory Heytings
2023-01-30 15:08                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24b4118b217952fab8dd@heytings.org \
    --to=gregory@heytings.org \
    --cc=56682@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).