Vivi
Vivi

Reputation: 4218

How to change the position of the cursor in "centered-cursor-mode" in Emacs?

I am using centered-cursor-mode in Emacs, and I really like it. It has been bothering me a lot, though, that the position of the cursor is set lower than the center, and I would actually prefer it to be higher than the center.

Every few months I get annoyed enough to try and do something about it, but I have so far been unsuccessful. My impression was that the answer was to change the numbers in this bit

(defcustom ccm-vpos-init '(round (window-text-height) 2)
  "This is the screen line position where the cursor initially stays."
  :group 'centered-cursor
  :tag "Vertical cursor position"
  :type '(choice (const :tag "Center" (round (window-text-height) 2))
                 (const :tag "Golden ratio" (round (* 21 (window-text-height)) 34)) 
                 (integer :tag "Lines from top" :value 10)))
(make-variable-buffer-local 'ccm-vpos-init)

but it doesn't seem like it.

Does anyone know how to change the centering position of the cursor in "centered-cursor-mode.el"?

Upvotes: 2

Views: 1428

Answers (1)

Thomas
Thomas

Reputation: 17422

You can adjust the line position in the current buffer with M-C-+ and M-C--. The prefix argument specifies how many lines you want to move the cursor, so e.g. if you want to have the cursor two lines higher, you would type:

C-u 2 C-M-+

For a more permanent solution, you can also customize the entry of the "Vertical cursor position" (aka ccm-vpos-init) as your question already suggests. Accessing that entry via M-x customize-group RET centered-cursor RET you'll find three basic options:

  • Centered (default)
  • Golden ratio
  • Lines from the top

IMHO the third option only makes sense if you always use the exact same window size (so horizontal split windows will be a problem) while the second point could perhaps be an option for you?

However, you can very easily add a forth option to the definition of ccm-vpos-init that allows you to position the cursor exactly where you want it, for instance:

(defcustom ccm-vpos-init '(round (window-text-height) 2)
  "This is the screen line position where the cursor initially stays."
  :group 'centered-cursor
  :tag "Vertical cursor position"
  :type '(choice (const :tag "Center" (round (window-text-height) 2))
                 (const :tag "Golden ratio" (round (* 21 (window-text-height)) 34))
                 (integer :tag "Lines from top" :value 10)
                 (const :tag "2 Lines above center" (- (round (window-text-height) 2) 2))))

The next time you start Emacs, this forth option will be available in the "Vertical cursor position" entry described above.

Upvotes: 2

Related Questions