Skip to content

Instantly share code, notes, and snippets.

@x4lldux
Created May 25, 2013 14:13
Show Gist options
  • Save x4lldux/5649195 to your computer and use it in GitHub Desktop.
Save x4lldux/5649195 to your computer and use it in GitHub Desktop.
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