unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* set-window-start moves point without scrolling
@ 2013-03-18 22:44 Michael Heerdegen
  2013-03-19  3:42 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2013-03-18 22:44 UTC (permalink / raw)
  To: emacs-devel

Hello,

this seems strange to me: in emacs -Q, eval this:

(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.  This
doesn't happen in Emacs 23, only in 24.  And it doesn't seem right - the
doc of `set-window-start' tells that point is only changed if would be
out of sight otherwise.  Is this a bug or a feature?


Regards,

Michael.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-window-start moves point without scrolling
  2013-03-18 22:44 set-window-start moves point without scrolling Michael Heerdegen
@ 2013-03-19  3:42 ` Eli Zaretskii
  2013-03-19 16:26   ` Michael Heerdegen
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2013-03-19  3:42 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: emacs-devel

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Mon, 18 Mar 2013 23:44:01 +0100
> 
> (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.  This
> doesn't happen in Emacs 23, only in 24.  And it doesn't seem right - the
> doc of `set-window-start' tells that point is only changed if would be
> out of sight otherwise.  Is this a bug or a feature?

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

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-window-start moves point without scrolling
  2013-03-19  3:42 ` Eli Zaretskii
@ 2013-03-19 16:26   ` Michael Heerdegen
  2013-03-19 17:40     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2013-03-19 16:26 UTC (permalink / raw)
  To: emacs-devel; +Cc: Magnar Sveen

Eli Zaretskii <eliz@gnu.org> 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):

  https://github.com/magnars/multiple-cursors.el

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)))
     ,@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?

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,

Michael. 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-window-start moves point without scrolling
  2013-03-19 16:26   ` Michael Heerdegen
@ 2013-03-19 17:40     ` Eli Zaretskii
  2013-03-19 18:38       ` Michael Heerdegen
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2013-03-19 17:40 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: magnars, emacs-devel

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Tue, 19 Mar 2013 17:26:42 +0100
> Cc: Magnar Sveen <magnars@gmail.com>
> 
> 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
case.

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

Yes.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-window-start moves point without scrolling
  2013-03-19 17:40     ` Eli Zaretskii
@ 2013-03-19 18:38       ` Michael Heerdegen
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2013-03-19 18:38 UTC (permalink / raw)
  To: emacs-devel; +Cc: magnars, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

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

That sounds good - thanks for checking! 


Regards,

Michael.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-19 18:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-18 22:44 set-window-start moves point without scrolling Michael Heerdegen
2013-03-19  3:42 ` Eli Zaretskii
2013-03-19 16:26   ` Michael Heerdegen
2013-03-19 17:40     ` Eli Zaretskii
2013-03-19 18:38       ` Michael Heerdegen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).