From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel 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 Message-ID: References: <83v8o0dtg3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13563"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 31 15:33:51 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opVrL-0003HT-S4 for ged-emacs-devel@m.gmane-mx.org; Mon, 31 Oct 2022 15:33:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opVpv-0002y8-Ep; Mon, 31 Oct 2022 10:32:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opVpu-0002x7-4D for emacs-devel@gnu.org; Mon, 31 Oct 2022 10:32:22 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opVpr-0006Aa-A3 for emacs-devel@gnu.org; Mon, 31 Oct 2022 10:32:21 -0400 Original-Received: (qmail 97422 invoked by uid 3782); 31 Oct 2022 15:32:13 +0100 Original-Received: from acm.muc.de (p4fe15da4.dip0.t-ipconnect.de [79.225.93.164]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 31 Oct 2022 15:32:13 +0100 Original-Received: (qmail 16983 invoked by uid 1000); 31 Oct 2022 14:32:12 -0000 Content-Disposition: inline In-Reply-To: <83v8o0dtg3.fsf@gnu.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.5; envelope-from=acm@muc.de; helo=mx3.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298857 Archived-At: 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 > > 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).