[Top][All Lists]

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

Re: set-window-start moves point without scrolling

From: Eli Zaretskii
Subject: Re: set-window-start moves point without scrolling
Date: Tue, 19 Mar 2013 19:40:16 +0200

> From: Michael Heerdegen <address@hidden>
> Date: Tue, 19 Mar 2013 17:26:42 +0100
> Cc: Magnar Sveen <address@hidden>
> 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)))
>      ,@forms
>      (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?

I think using a non-nil 3rd argument to set-window-start should do
what you want.  At least it does that in your recipe that started this
thread.  My reading of the code which deals with the effect of the
optional arg to set-window-start is that passing a non-nil value there
inhibits the code which forces point outside the scroll margin in this

> 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.)


reply via email to

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