[Top][All Lists]

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

Re: set-window-start moves point without scrolling

From: Michael Heerdegen
Subject: Re: set-window-start moves point without scrolling
Date: Tue, 19 Mar 2013 17:26:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> > (progn
> >   (setq-default scroll-margin 2)
> >   (pop-to-buffer (get-buffer-create "test"))
> >   (insert "1\n2\n3")
> >   (goto-char 1)
> >   (set-window-start nil (window-start)))
> > 
> > Then, point in buffer "test" is at the beginning of line 3.

> Feature.  You set the scroll-margin to 2, so Emacs avoids putting
> point inside the margin.

Ok, I see, thanks.

> Does this give you trouble in any real-life situation?

Dunno.  The background: yesterday, I tried "multiple-cursors" by Magnar
Sveen (whom I CC'd):


The idea is, yes, to simulate multiple cursors.

To avoid performing of automatic window scrolling when the current
editing command is performed at the positions of the "other" cursors,
these actions are wrapped in this macro:

(defmacro mc/save-window-scroll (&rest forms)
  "Saves and restores the window scroll position"
  `(let ((p (set-marker (make-marker) (point)))
         (start (set-marker (make-marker) (window-start)))
         (hscroll (window-hscroll)))
     (goto-char p)
     (set-window-start nil start)
     (set-window-hscroll nil hscroll)
     (set-marker p nil)
     (set-marker start nil)))

(the local vars should become uninterned symbols, but that's not related)

This code triggers the effect in my example above: point (i.e., the
"real" cursor) is moved as a side effect if point was in the first
visible window line and scroll-margin > 0.

How would a better implementation of this macro look like?  Would it be
sufficient to use a non-nil third argument for `set-window-start', or
would this not reverse automatic scrolling reliably?

BTW, I already tried to wrap the `set-window-hscroll' inside
`save-excursion' or (let ((scroll-margin 0)) ...), but this doesn't help
(I guess because scrolling is performed afterwards while redisplaying.)

Thanks so far,


reply via email to

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