Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Smarter beginning of the line
;; 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