Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: scroll buffer not point

Tags:

emacs

Is it possible to scroll the entire visible portion of the buffer in Emacs, but leave point where it is. Example: point is towards the bottom of the window and I want to see some text which has scrolled off the top of the window without moving point.

Edit: I suppose C-l C-l sort of does what I wanted.

like image 764
SabreWolfy Avatar asked Jan 24 '12 19:01

SabreWolfy


4 Answers

try these. Change M-n and M-p key bindings according to your taste

;;; scrollers
(global-set-key "\M-n" "\C-u1\C-v")
(global-set-key "\M-p" "\C-u1\M-v")
like image 91
kindahero Avatar answered Nov 14 '22 12:11

kindahero


;;;_*======================================================================
;;;_* define a function to scroll with the cursor in place, moving the
;;;_* page instead
;; Navigation Functions
(defun scroll-down-in-place (n)
  (interactive "p")
  (previous-line n)
  (unless (eq (window-start) (point-min))
    (scroll-down n)))

(defun scroll-up-in-place (n)
  (interactive "p")
  (next-line n)
  (unless (eq (window-end) (point-max))
    (scroll-up n)))

(global-set-key "\M-n" 'scroll-up-in-place)
(global-set-key "\M-p" 'scroll-down-in-place)
like image 23
Chris McMahan Avatar answered Nov 14 '22 11:11

Chris McMahan


This might be of use. According to the EmacsWiki page on Scrolling;

The variable scroll-preserve-screen-position may be useful to some. When you scroll down, and up again, point should end up at the same position you started out with. The value can be toggled by the built in mode M-x scroll-lock-mode.

like image 8
Marvin Pinto Avatar answered Nov 14 '22 12:11

Marvin Pinto


I think this is better:

(defun gcm-scroll-down ()
      (interactive)
      (scroll-up 1))
    (defun gcm-scroll-up ()
      (interactive)
      (scroll-down 1))
    (global-set-key [(control down)] 'gcm-scroll-down)
    (global-set-key [(control up)]   'gcm-scroll-up)

reference : emacs wiki

like image 3
Bilal Qadri Avatar answered Nov 14 '22 12:11

Bilal Qadri