Last active
April 6, 2025 14:24
-
-
Save mmarshall540/58b0374295f2760c9ee5058d3225a22d to your computer and use it in GitHub Desktop.
Beginning-of-line or indentation on one key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my/mbol-advice (arg) | |
"With prefix ARG other than 1, return t. | |
Else, go `back-to-indentation', and if point hasn't moved, return t." | |
(if (eq arg 1) | |
(let ((start (point))) | |
(back-to-indentation) | |
(eq start (point))) | |
t)) | |
(advice-add 'move-beginning-of-line :before-while 'my/mbol-advice) |
Updated so that if a prefix argument other than 1 is passed, move-beginning-of-line
will be immediately called using the prefix argument, since back-to-indentation
doesn't use a prefix argument.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is some simple code to implement my preferred behavior on the "C-a" (or "<home>") key. It goes to the first non-whitespace character on the line (just like "M-m" would do). If pressed a second time (or if point was already at that location), it moves to beginning-of-line.
There are many other ways you could do this, even packages you could install for a more fine-grained approach (e.g. MWIM).
There's also a built-in feature that applies only in
org-mode
buffers. You can configure that by setting the value oforg-special-ctrl-a/e
. (The code in this gist won't interfere with it.)