Created
May 25, 2013 14:13
-
-
Save x4lldux/5649195 to your computer and use it in GitHub Desktop.
Smarter beginning of the line
This file contains 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
;; Smart beginning of the line | |
(defun x4-smarter-beginning-of-line () | |
"Move point to beginning-of-line or first non-whitespace character or first non-whitespace after a comment sign." | |
(interactive "^") | |
(let ( | |
(oldpos (point)) | |
(indentpos (progn | |
(back-to-indentation) | |
(point) | |
) | |
) | |
(textpos (progn | |
(beginning-of-line-text) | |
(point) | |
) | |
) | |
) | |
(cond | |
((> oldpos textpos) (beginning-of-line-text)) | |
((and (<= oldpos textpos) (> oldpos indentpos)) (back-to-indentation)) | |
((and (<= oldpos indentpos) (> oldpos (line-beginning-position))) (beginning-of-line)) | |
(t (beginning-of-line-text)) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment