GNU bug report logs - #35334
26.2; Changes to position of point are undone during with-current-buffer if window is visible but not current

Previous Next

Package: emacs;

Reported by: Sean McAfee <eefacm <at> gmail.com>

Date: Sat, 20 Apr 2019 04:01:01 UTC

Severity: normal

Found in version 26.2

Fixed in version 26.3

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35334 in the body.
You can then email your comments to 35334 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sat, 20 Apr 2019 04:01:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sean McAfee <eefacm <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 20 Apr 2019 04:01:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sean McAfee <eefacm <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.2; Changes to position of point are undone during
 with-current-buffer if window is visible but not current
Date: Fri, 19 Apr 2019 21:00:02 -0700
[Message part 1 (text/plain, inline)]
Starting from emacs -Q:

Create a new buffer named "a".  Insert ten asterisks and move point to
the beginning of the buffer.

Split the window and select the scratch buffer in one of them, leaving
buffer "a" visible in the other.  In the scratch buffer, evaluate this
Lisp expression:

(with-current-buffer "a" (goto-char 5) (insert "foo"))

You can see "foo" inserted at position 5 in buffer "a", but point
remains at the beginning of the buffer.

Go to buffer "a", delete the "foo", and move to the beginning of the
buffer again.  Go to the scratch buffer and make it the sole visible
window.  Evaluate the above Lisp expression again.  Go to buffer "a".
"foo" has been inserted at position 5 as before, but now point is at
position 8, after the "foo".

I would expect point to move to position 8 in both cases, and I don't
see anything in the documentation for with-current-buffer or goto-char
to suggest that it ever wouldn't.



In GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll
bars)
 of 2019-04-19 built on SeanMc
Windowing system distributor 'The X.Org Foundation', version 11.0.11906000
System Description:    Ubuntu 18.04.2 LTS

Recent messages:
C-x C-g is undefined
C-. is undefined
Undo!
C-. is undefined
nil
Undo!
Mark activated
nil
Quit
Undo!

Configured features:
XAW3D XPM JPEG TIFF GIF PNG SOUND GPM DBUS GSETTINGS GLIB NOTIFY ACL
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM THREADS LCMS2

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 96878 15032)
 (symbols 48 20303 1)
 (miscs 40 69 168)
 (strings 32 29315 1561)
 (string-bytes 1 758564)
 (vectors 16 14757)
 (vector-slots 8 508710 8162)
 (floats 8 51 278)
 (intervals 56 278 13)
 (buffers 992 12))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sat, 20 Apr 2019 04:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Sat, 20 Apr 2019 00:10:26 -0400
Sean McAfee <eefacm <at> gmail.com> writes:

> I would expect point to move to position 8 in both cases, and I don't
> see anything in the documentation for with-current-buffer or goto-char
> to suggest that it ever wouldn't.

How about in (elisp) Window Point?

   * Selecting a window sets the value of point in its buffer from the
     window's value of point.  Conversely, deselecting a window sets the
     window's value of point from that of the buffer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sun, 21 Apr 2019 23:34:02 GMT) Full text and rfc822 format available.

Message #11 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Sean McAfee <eefacm <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2; Changes to position of point are undone during
 with-current-buffer if window is visible but not current
Date: Sun, 21 Apr 2019 16:32:48 -0700
[Message part 1 (text/plain, inline)]
On Fri, Apr 19, 2019 at 9:10 PM Noam Postavsky <npostavs <at> gmail.com> wrote:

> Sean McAfee <eefacm <at> gmail.com> writes:
> > I would expect point to move to position 8 in both cases, and I don't
> > see anything in the documentation for with-current-buffer or goto-char
> > to suggest that it ever wouldn't.
>
> How about in (elisp) Window Point?
>
>    * Selecting a window sets the value of point in its buffer from the
>      window's value of point.  Conversely, deselecting a window sets the
>      window's value of point from that of the buffer.
>

Okay, I wasn't fully aware of these window-point semantics.  I'll take a
step back and describe my actual problem, of which the bug I thought I was
reporting was the simplest case I could reduce it to.

Starting with two windows visible, the scratch buffer and a window showing
empty buffer "a", I evaluate this expression in the scratch buffer:

(start-process "count" "a" "bash" "-c" "for i in {1..10}; echo $i; sleep 1;
done")

I see the numbers 1-10 inserted into buffer "a", one second apart, as
expected.  The position of point in buffer "a" follows the new lines as
they're inserted.

Now I define the function ordinary-insertion-filter, as found on this page:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Filter-Functions.html

That function is described as "mimicking the actions of the default
filter."  However, if I erase buffer "a" and evaluate this expression in
the scratch buffer:

(let ((proc (start-process "count" "a" "bash" "-c" "for i in {1..10}; echo
$i; sleep 1; done")))
  (set-process-filter proc #'ordinary-insertion-filter))

...then I see the numbers inserted as before, but now the position of point
in buffer "a" doesn't move; it stays at the beginning of the buffer.  If I
select the window showing buffer "a" as the numbers are still being
inserted and move point to the end of the buffer, then point starts
following the new numbers.  But if I select the scratch buffer again, point
in buffer "a" stops following the new numbers.

Is this the expected behavior?
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Mon, 22 Apr 2019 02:39:02 GMT) Full text and rfc822 format available.

Message #14 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Sun, 21 Apr 2019 22:38:41 -0400
Sean McAfee <eefacm <at> gmail.com> writes:

> Starting with two windows visible, the scratch buffer and a window showing
> empty buffer "a", I evaluate this expression in the scratch buffer:
>
> (start-process "count" "a" "bash" "-c" "for i in {1..10}; echo $i; sleep 1; done")

[missing a "do" before the "echo $i", by the way]

> I see the numbers 1-10 inserted into buffer "a", one second apart, as
> expected.  The position of point in buffer "a" follows the new lines as
> they're inserted.
>
> Now I define the function ordinary-insertion-filter, as found on this page:
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Filter-Functions.html
>
> That function is described as "mimicking the actions of the default
> filter."  However, if I erase buffer "a" and evaluate this expression in
> the scratch buffer:
>
> (let ((proc (start-process "count" "a" "bash" "-c" "for i in {1..10}; echo $i; sleep 1; done")))
>   (set-process-filter proc #'ordinary-insertion-filter))
>
> ...then I see the numbers inserted as before, but now the position of point
> in buffer "a" doesn't move

Okay, interesting.  The difference seems to be that
`internal-default-process-filter' actually uses `insert-before-markers'
rather than plain `insert'.  I guess the window point is implemented as
a marker, so inserting this way happens to move it as well.

     (defun ordinary-insertion-filter (proc string)
       (when (buffer-live-p (process-buffer proc))
         (with-current-buffer (process-buffer proc)
           (let ((moving (= (point) (process-mark proc))))
             (save-excursion
               ;; Insert the text, advancing the process marker.
               (goto-char (process-mark proc))
               (insert-before-markers string) ; <------------ change here
               (set-marker (process-mark proc) (point)))
             (if moving (goto-char (process-mark proc)))))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Mon, 22 Apr 2019 07:24:02 GMT) Full text and rfc822 format available.

Message #17 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org, eefacm <at> gmail.com
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Mon, 22 Apr 2019 10:22:58 +0300
> From: Noam Postavsky <npostavs <at> gmail.com>
> Date: Sun, 21 Apr 2019 22:38:41 -0400
> Cc: 35334 <at> debbugs.gnu.org
> 
> I guess the window point is implemented as a marker

Yes, see the comments in window.h.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sat, 27 Apr 2019 21:07:01 GMT) Full text and rfc822 format available.

Message #20 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Sean McAfee <eefacm <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2; Changes to position of point are undone during
 with-current-buffer if window is visible but not current
Date: Sat, 27 Apr 2019 14:05:57 -0700
[Message part 1 (text/plain, inline)]
On Sun, Apr 21, 2019 at 7:38 PM Noam Postavsky <npostavs <at> gmail.com> wrote:

>                (insert-before-markers string) ; <------------ change here
>

OK, since I now have a workaround, or rather the appropriate code to use in
my situation, the bug is resolved from my perspective.

Perhaps the "Process Filter Functions" manual page could stand to be
touched up a bit, though.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sat, 27 Apr 2019 21:09:02 GMT) Full text and rfc822 format available.

Message #23 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Sat, 27 Apr 2019 17:07:51 -0400
>      (defun ordinary-insertion-filter (proc string)
>        (when (buffer-live-p (process-buffer proc))
>          (with-current-buffer (process-buffer proc)
>            (let ((moving (= (point) (process-mark proc))))
>              (save-excursion
>                ;; Insert the text, advancing the process marker.
>                (goto-char (process-mark proc))
>                (insert-before-markers string) ; <------------ change here
>                (set-marker (process-mark proc) (point)))
>              (if moving (goto-char (process-mark proc)))))))

If we make this update in the manual, would that sufficiently clarify
the sitatuation, or do we need anything else?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Sun, 28 Apr 2019 02:20:01 GMT) Full text and rfc822 format available.

Message #26 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Sat, 27 Apr 2019 22:19:17 -0400
Sean McAfee <eefacm <at> gmail.com> writes:

> On Sun, Apr 21, 2019 at 7:38 PM Noam Postavsky <npostavs <at> gmail.com> wrote:
>
>>                (insert-before-markers string) ; <------------ change here
>>
>
> OK, since I now have a workaround, or rather the appropriate code to use in
> my situation, the bug is resolved from my perspective.
>
> Perhaps the "Process Filter Functions" manual page could stand to be
> touched up a bit, though.

Oh, we sent at the same time.  By "touched up a bit" did you have in
mind anything apart from making that change quoted above?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Tue, 30 Apr 2019 22:00:02 GMT) Full text and rfc822 format available.

Message #29 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Sean McAfee <eefacm <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2; Changes to position of point are undone during
 with-current-buffer if window is visible but not current
Date: Tue, 30 Apr 2019 14:58:45 -0700
[Message part 1 (text/plain, inline)]
On Sat, Apr 27, 2019 at 7:19 PM Noam Postavsky <npostavs <at> gmail.com> wrote:

> Sean McAfee <eefacm <at> gmail.com> writes:
> > Perhaps the "Process Filter Functions" manual page could stand to be
> > touched up a bit, though.
>
> Oh, we sent at the same time.  By "touched up a bit" did you have in
> mind anything apart from making that change quoted above?
>
>
Nope, that should do it.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35334; Package emacs. (Wed, 01 May 2019 00:56:02 GMT) Full text and rfc822 format available.

Message #32 received at 35334 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: Re: bug#35334: 26.2;
 Changes to position of point are undone during with-current-buffer if
 window is visible but not current
Date: Tue, 30 Apr 2019 20:55:19 -0400
close 35334 26.3
quit

Sean McAfee <eefacm <at> gmail.com> writes:

> On Sat, Apr 27, 2019 at 7:19 PM Noam Postavsky <npostavs <at> gmail.com> wrote:
>
>> Sean McAfee <eefacm <at> gmail.com> writes:
>> > Perhaps the "Process Filter Functions" manual page could stand to be
>> > touched up a bit, though.
>>
>> Oh, we sent at the same time.  By "touched up a bit" did you have in
>> mind anything apart from making that change quoted above?
>>
>>
> Nope, that should do it.

Okay, pushed to emacs-26 (I accidentally put the wrong bug number in the
commit message though).

ec02c736d6 2019-04-30T20:51:24-04:00 "Update process filter example (Bug#35044)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ec02c736d65f2fd3a8a17e4e8dc143bf15d9600d





bug marked as fixed in version 26.3, send any further explanations to 35334 <at> debbugs.gnu.org and Sean McAfee <eefacm <at> gmail.com> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 01 May 2019 00:56:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 29 May 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 333 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.