help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to get back to a place in a buffer, or: what is a window configu


From: Marcin Borkowski
Subject: Re: How to get back to a place in a buffer, or: what is a window configuration?
Date: Wed, 03 Aug 2016 20:31:49 +0200
User-agent: mu4e 0.9.16; emacs 25.1.50.6

On 2016-08-03, at 13:25, Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Here are a couple of things that might help you:
>
> (1) Setting scroll-preserve-screen-position to a non-nil value.
> If you happen to C-c/M-v so that the point changes its position, but if the
> above is set to t and you reverse the scroll direction, you will find the
> cursor at the exact same position where you last left it.
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Scrolling.html

I know that, and I set scroll-preserve-screen-position to t in my
init.el a long time ago.  But thanks anyway, it is not very well known!

> (2) Use C-u C-SPC
> When you do large vertical positions, emacs auto-saves the previous marks
> to the mark-ring. It is very convenient to jump back to those older marks
> by hitting C-u C-SPC.
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Mark-Ring.html

I know that, too, and I use it often.  But point position is not what
I'm asking for; I also want the point to get in the same place onthe
screen, IOW, I want to preserve the first visible line.

> (3) Use winner-mode
> This is a golden mode, used to conveniently jump back and forth window
> configurations. The awesome thing is that you do not need to manually save
> those configurations. All window configuration changes are auto-saved.
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Window-Convenience.html

I've heard about it, now that you recommend it, I'll try it out some
day, probably sooner than later, thanks!

> (4) Create mini wrapper functions to scroll current/other window without
> moving the cursor position. I have the below in my config.

I also had such functions some time ago, I must have deleted them from
my config.  OTOH, C-v/M-v with prefix arg seem to do the same, so hey
seem a bit redundant to me.

> ;;; Scrolling
> ;; Keep point at its screen position if the scroll command moved it
> vertically
> ;; out of the window, e.g. when scrolling by full screens using C-v.
> (setq scroll-preserve-screen-position t)
>
> ;; Scroll without moving the point/cursor
> (defun modi/scroll-up (ln)
>   "Scroll up by LN lines without moving the point.
> If LN is nil, defaults to 1 line."
>   (interactive "p")
>   (scroll-up ln))
>
> (defun modi/scroll-down (ln)
>   "Scroll down by LN lines without moving the point.
> If LN is nil, defaults to 1 line."
>   (interactive "p")
>   (scroll-down ln))
>
> (defun modi/scroll-other-window-up (ln)
>   "Scroll other window up by LN lines without moving the point.
> If LN is nil, defaults to 1 line."
>   (interactive "p")
>   (scroll-other-window ln))
>
> (defun modi/scroll-other-window-down (ln)
>   "Scroll other window down by LN lines without moving the point.
> If LN is nil, defaults to 1 line."
>   (interactive "p")
>   (scroll-other-window (- ln)))
>
> ;; Below bindings are made in global map and not in my minor mode as I want
> ;; other modes to override those bindings.
> (bind-keys
> ("<C-M-up>"    . modi/scroll-down)
> ("<C-M-down>"  . modi/scroll-up)
> ("<C-M-left>"  . modi/scroll-other-window-down)
> ("<C-M-right>" . modi/scroll-other-window-up))

Thanks a lot!

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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