Created
April 17, 2025 12:00
-
-
Save bjourne/2bc9d13d6a4def32841464636675fe04 to your computer and use it in GitHub Desktop.
Best Elisp ever
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 smarter-move-beginning () | |
(interactive) | |
(let* ((at (point)) | |
(bol (line-beginning-position)) | |
(indent (save-excursion | |
(back-to-indentation) | |
(point)))) | |
(cond | |
((= at bol) | |
(if (bobp) | |
(progn | |
(beep) | |
(message "Beginning of buffer")) | |
(forward-line -1) | |
(end-of-line))) | |
((<= at indent) | |
(move-to-column 0)) | |
(t (back-to-indentation))))) | |
(defun smarter-move-end () | |
(interactive) | |
(let* ((at (point)) | |
(eol (line-end-position)) | |
(indent (save-excursion | |
(back-to-indentation) | |
(point)))) | |
(cond | |
((= at eol) | |
(if (eobp) | |
(progn | |
(beep) | |
(message "End of buffer")) | |
(forward-line 1) | |
(beginning-of-line))) | |
((< at indent) | |
(back-to-indentation)) | |
(t (end-of-line))))) | |
(global-set-key [remap move-beginning-of-line] 'smarter-move-beginning) | |
(global-set-key [remap move-end-of-line] 'smarter-move-end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment