Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to center screen horizontally around cursor on emacs?

I'm familiar with and use very frequently the C-l (recenter-top-bottom) to

Move current line to window center, top, and bottom, successively.

I'd like to have an equivalent command to move the current column to window center, left and right borders, successively. Either built-in or a snippet of Elisp.

like image 476
agentofuser Avatar asked Aug 08 '09 17:08

agentofuser


1 Answers

Here you go:

(defun my-horizontal-recenter ()
  "make the point horizontally centered in the window"
  (interactive)
  (let ((mid (/ (window-width) 2))
        (line-len (save-excursion (end-of-line) (current-column)))
        (cur (current-column)))
    (if (< mid cur)
        (set-window-hscroll (selected-window)
                            (- cur mid)))))

And the obvious binding (from obvio171) is:

(global-set-key (kbd "C-S-l") 'my-horizontal-recenter)
like image 122
Trey Jackson Avatar answered Oct 13 '22 07:10

Trey Jackson