[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 13:05:34 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
lee <lee@yagibdah.de> 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.
Anyway, if you look into the code, you’ll see that this behaviour is
definetely intentional:
(defun 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)
(if (pos-visible-in-window-p (point-max))
(forward-line arg)
(scroll-up arg))
(scroll-lock-move-to-column scroll-lock-temporary-goal-column))
(defun 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)
(condition-case nil
(scroll-down arg)
(beginning-of-buffer (forward-line (- arg))))
(scroll-lock-move-to-column scroll-lock-temporary-goal-column))
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)
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)
- Re: prevent scroll-lock-mode from scrolling?, (continued)
Re: prevent scroll-lock-mode from scrolling?, lee, 2016/06/17
Re: prevent scroll-lock-mode from scrolling?, Eli Zaretskii, 2016/06/17
Re: prevent scroll-lock-mode from scrolling?, Eli Zaretskii, 2016/06/20
Re: prevent scroll-lock-mode from scrolling?, lee, 2016/06/20