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: Kaushal Modi
Subject: Re: How to get back to a place in a buffer, or: what is a window configuration?
Date: Wed, 03 Aug 2016 11:25:01 +0000

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

(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

(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

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

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

On Wed, Aug 3, 2016, 5:32 AM Marcin Borkowski <mbork@mbork.pl> wrote:

> Hi all,
>
> sometimes I work on a particular place in some buffer, and Emacs for
> some reason scrolls me out of that place.  I want then to get back to
> it.  Is there a way (in stock Emacs or with help of M?elpa) to
> accomplish that?
>
> Bonus points for a package/command which /temporarily/ disables C-v/M-v
> and other commands that might result in scrolling text in the window.
> (Narrowing to what is currently visible should do the trick, so
> a combination of M-r, C-e and C-SPC would probably do what I want.
> Coding that is three minutes, but maybe someone did it already?)
>
> Note that it's not the same as keeping a position in a register.
> A simple experiment shows that keeping a /window configurations/ seems
> to do what I want, but from reading the manual I'm not sure what
> a "window configuration" really is.  What does a "window configuration"
> consist of, exactly?
>
> TIA,
>
> --
> Marcin Borkowski
> http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
> Faculty of Mathematics and Computer Science
> Adam Mickiewicz University
>
> --

Kaushal Modi


reply via email to

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