emacs-devel
[Top][All Lists]
Advanced

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

Re: Edebug corrupting point in buffers; we need buffer-point and set-buf


From: Alan Mackenzie
Subject: Re: Edebug corrupting point in buffers; we need buffer-point and set-buffer-point, perhaps.
Date: Mon, 31 Oct 2022 14:32:12 +0000

Hello, Eli.

On Mon, Oct 31, 2022 at 15:16:28 +0200, Eli Zaretskii wrote:
> > Date: Mon, 31 Oct 2022 11:43:15 +0000
> > From: Alan Mackenzie <acm@muc.de>

> > A few weeks ago, I was attempting to edebug a program which itself
> > scanned through a buffer B.  That buffer was also displayed in a window
> > (or possibly two windows).  Each time the program went into edebug, the
> > point in B got corrupted.

> > Setting edebug-save-displayed-buffer-points didn't help.

> Did you try switch-to-buffer-preserve-window-point?

I wasn't aware of that variable.  Thanks!  It's quite something to get
your head around.

I don't think it's going to help me, since it's about preserving a
window point.  My problem in edebug is about preserving the _buffer_
point over the recursive edit.

Anyhow, I proposed buffer-point and set-buffer-point.  They would be a
lot faster than set-buffer followed by point and goto-char.  Here is my
first version of these.  What do you think?



diff --git a/src/buffer.c b/src/buffer.c
index b67b989326..34b7b4442f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1453,6 +1453,48 @@ returns the symbol `autosaved'.  */)
     return Qnil;
 }
 
+DEFUN ("buffer-point", Fbuffer_point, Sbuffer_point, 1, 1, 0,
+       doc: /* Return the buffer point of BUFFER-OR-NAME.
+The argument may be a buffer or the name of an existing buffer.  */)
+  (Lisp_Object buffer_or_name)
+{
+  Lisp_Object buffer;
+  struct buffer *b;
+
+  buffer = Fget_buffer (buffer_or_name);
+  if (NILP (buffer))
+    nsberror (buffer_or_name);
+  b = XBUFFER (buffer);
+  return (make_fixnum (b->pt));
+}
+
+DEFUN ("set-buffer-point", Fset_buffer_point, Sset_buffer_point, 2, 2, 0,
+       doc: /* Set the buffer point of BUFFER-OR-NAME to POS.
+BUFFER-OR-NAME is a buffer or the name of one.  POS is a buffer
+position, either a number or a marker.  If POS is outside the current
+visible region, the buffer point is set to the nearest place in it.
+Return the buffer point actually set.  */)
+  (Lisp_Object buffer_or_name, Lisp_Object pos)
+{
+  Lisp_Object buffer;
+  struct buffer *b;
+  ptrdiff_t p;
+
+  buffer = Fget_buffer (buffer_or_name);
+  if (NILP (buffer))
+    nsberror (buffer_or_name);
+  b = XBUFFER (buffer);
+
+  CHECK_FIXNUM_COERCE_MARKER (pos);
+  p = XFIXNUM (pos);
+  if (p < b->begv) p = b->begv;
+  if (p > b->zv) p = b->zv;
+
+  SET_PT (p);
+  return make_fixnum (p);
+}
+
+
 DEFUN ("force-mode-line-update", Fforce_mode_line_update,
        Sforce_mode_line_update, 0, 1, 0,
        doc: /* Force redisplay of the current buffer's mode line and header 
line.
@@ -5898,6 +5942,8 @@ There is no reason to change that value except for 
debugging purposes.  */);
   defsubr (&Sbuffer_local_value);
   defsubr (&Sbuffer_local_variables);
   defsubr (&Sbuffer_modified_p);
+  defsubr (&Sbuffer_point);
+  defsubr (&Sset_buffer_point);
   defsubr (&Sforce_mode_line_update);
   defsubr (&Sset_buffer_modified_p);
   defsubr (&Sbuffer_modified_tick);


-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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