💾 Archived View for gem.librehacker.com › gemlog › starlog › 20240228-0.gmi captured on 2024-06-16 at 12:13:27. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

Emacs: Centered, Stable Cursor View (publ. 2024-02-29)

There are two thing I don't like about how Emacs handles the cursor by default:

(1) The cursor moves all over the place vertically as you next-line, scroll up, and such like.

(2) As you move vertically, the placement of the cursor tends to move all over the place horizontally. This is because it is trying to maintain a goal cursor position but also has to stay within the limits of the number of characters in each line.

I wanted something more like a typewriter, where you always are looking at the same place to edit the text. I got basically what I wanted with a combination of global-centered-cursor-mode and a few tweaks. The centered-cursor-mode package is not available in Guix, unfortunately, but was easy to pull with straight:

(straight-use-package 'centered-cursor-mode)
(global-centered-cursor-mode 1)

This keeps the cursor centered vertical all the time, except for at the beginning and end of the buffer. I set a few variables:

 '(ccm-recenter-at-end-of-file t)
 '(ccm-step-delay 0)
 '(ccm-step-size 2)

The ccm-recenter-at-end-of-file allows cursor to center when you reach the end of the buffer as well, but still not at the beginning. Setting ccm-step-delay to zero removes animation that could slow down the visual experience. I'm not sure if ccm-step-size has any relevance here, with a ccm-step-delay of zero, but I happen to have it defined at the moment for reasons I don't remember.

I've got context-lines set to 1, just so I can see I've maintained continuity:

(next-screen-context-lines 1)

I also generally prefer word-wrapping to be on:

(word-wrap t)

Honestly, I can't really remember why these are set:

(scroll-conservatively 101)
(scroll-preserve-screen-position 1)

This bit of "advice" elisp deals with the annoyance of the cursor jumping around left and right as I use previous-line and next-line:

(map nil (lambda (f)
           (advice-add f :before
            (lambda (&rest r)
              (setq temporary-goal-column (current-column)))))
     '(previous-line next-line))

I prefer to have visual-line-mode disabled since I want all my navigation and macros to be operating on real lines. However, this creates a problem — at least when using centered-cursor-mode with word-wrapping enabled — where scrolling potentially skips over reading some text if the real lines are longer than visual lines. This advice code turns visual-line-mode just long enough to do the scroll:

(advice-add 'ccm-scroll-up :before (lambda (&rest r) (visual-line-mode 1)))
(advice-add 'ccm-scroll-up :after (lambda (&rest r) (visual-line-mode -1)))
(advice-add 'ccm-scroll-down :before (lambda (&rest r) (visual-line-mode 1)))
(advice-add 'ccm-scroll-down :after (lambda (&rest r) (visual-line-mode -1)))

Something that would be interesting to try would be a mode where Emacs keeps the cursor horizontal centered as well, like a mechanical typewriter with a fixed strike location. The text would have to move left and right to accomodate. But I haven't heard of a package like this.

Copyright

This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.

CC BY-SA 4.0 Deed