[Top][All Lists]

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

Re: prevent scroll-lock-mode from scrolling?

From: Dmitry Alexandrov
Subject: Re: prevent scroll-lock-mode from scrolling?
Date: Mon, 20 Jun 2016 19:12:58 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

lee <address@hidden> writes:

> Dmitry Alexandrov <address@hidden> writes:
>> lee <address@hidden> writes:
>>> Can you explain to me why the cursor remains at its position /on the
>>> screen/ while I'm scrolling with scroll-lock-mode enabled all the time
>>> like it should --- and then suddenly moves when the top or bottom of the
>>> buffer contents come into view?  That doesn't make any sense to me; the
>>> cursor still shouldn't move.
>> Given that there is no free space before the first line of a buffer,
>> this does make perfect sense with regard to scrolling backward (to the
>> top of a buffer).  The other way we would just get stuck with the point
>> in the middle of a screen not being able to reach first lines.  The
>> scrolling forward behaves the same way for sake of coherence, I guess.
> There is no free space beyond the last line of a buffer, either.

Well, by default in GNU Emacs there *is* free space beyond the last
line, which is taken in account while scrolling.  I have no idea how
could you disabled it.  Actually I would like to see some day an
opposite option in GNU Emacs — to enable empty lines above the top of a

> It doesn't make sense, though, because scroll-lock means that the cursor
> does not move when scrolling.  Why else would I use scroll-lock-mode?

As far as I understand, minor modes for Emacs are generally designed to
be used on permanent basis, not to be toggled every several keystrokes.
Since the algorithm you described prevents user from accessing to first
N lines of buffer, this algorithm would be perceived as broken.

>> However, if you do not like it, just remove the condition:
>> (defun my-scroll-lock-next-line (&optional arg)
>>   "Scroll up ARG lines keeping point fixed."
>>   (interactive "p")
>>   (or arg (setq arg 1))
>>   (scroll-lock-update-goal-column)
>>   (scroll-up arg)
>>   (scroll-lock-move-to-column scroll-lock-temporary-goal-column))
>> (defun my-scroll-lock-previous-line (&optional arg)
>>   "Scroll up ARG lines keeping point fixed."
>>   (interactive "p")
>>   (or arg (setq arg 1))
>>   (scroll-lock-update-goal-column)
>>   (scroll-down arg)
>>   (scroll-lock-move-to-column scroll-lock-temporary-goal-column))
>> (advice-add 'scroll-lock-next-line :override #'my-scroll-lock-next-line)
>> (advice-add 'scroll-lock-previous-line :override 
>> #'my-scroll-lock-previous-line)
> Thank you very much!  That does the trick

You are welcome.

> and I just found out that
> I have scroll-preserve-screen-position set to t and forgot about it ages
> ago.  The result of that is pretty much what scroll-lock-mode is
> supposed to do.
> I guess I'm a bit confused because emacs at work and emacs at home are
> configured differently.  I should be fine when I set
> scroll-preserve-screen-position to t at work, too.

Or maybe even to ‘always’ (or whatever you want to call it).

>> Also, if you are regularily toggling the ‘scroll-lock-mode’ on and off,
>> you might consider to use approach that, one might say, is more
>> ‘Emacsish’ — another keychord instead of mode:
>> (setq scroll-preserve-screen-position 'always)
>> (global-set-key (kbd "M-n") #'scroll-up-line)
>> (global-set-key (kbd "M-<down>") #'scroll-up-line)
>> (global-set-key (kbd "M-p") #'scroll-down-line)
>> (global-set-key (kbd "M-<up>") #'scroll-down-line)
> The idea was to make use of the ScrollLock key.  So I did that and found
> that when scroll-lock-mode is enabled, the point does move when it
> shouldn't.
> Since what scroll-lock-mode does is achieved by setting
> scroll-preserve-screen-position to t, what is the point or purpose of
> scroll-lock-mode?  That the cursor moves when it shouldn't?

First of all, I would not say that there is something wrong even with
existence of a minor mode that only toggles single variable.  However
you might notice that besides toggling ‘scroll-preserve-screen-position’
‘scroll-lock-mode’ at least re-defines several moving keys: ‘C-n’, ‘C-p’, etc.

> BTW, it seems that changing scroll-preserve-screen-position requires
> restarting emacs to take effect.


> Maybe that's what scroll-lock-mode is
> for, being able to change the behaviour without restarting?

As you already noticed, ‘scroll-lock-mode’ depends on state of
‘scroll-preserve-screen-position’.  How then could it evade such a
limitation if it existed?

reply via email to

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