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.

Full log


View this message in rfc822 format

From: Noam Postavsky <npostavs <at> gmail.com>
To: Sean McAfee <eefacm <at> gmail.com>
Cc: 35334 <at> debbugs.gnu.org
Subject: 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)))))))




This bug report was last modified 6 years and 19 days ago.

Previous Next


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