I use emacs for development and very often need to move to the start of a line (C-a). However if the line is indented, I\'d like to move to the point at which code st
Common idiom among modern IDE is to move at the first/last non-whitespace on second press:
(defun my--smart-beginning-of-line ()
"Move point to `beginning-of-line'. If repeat command it cycle
position between `back-to-indentation' and `beginning-of-line'."
(interactive "^")
(if (and (eq last-command 'my--smart-beginning-of-line)
(= (line-beginning-position) (point)))
(back-to-indentation)
(beginning-of-line)))
(defun my--smart-end-of-line ()
"Move point to `end-of-line'. If repeat command it cycle
position between last non-whitespace and `end-of-line'."
(interactive "^")
(if (and (eq last-command 'my--smart-end-of-line)
(= (line-end-position) (point)))
(skip-syntax-backward " " (line-beginning-position))
(end-of-line)))
(global-set-key [home] 'my--smart-beginning-of-line)
(global-set-key [end] 'my--smart-end-of-line)
This code firstly move to actual begin/end, new behavior show up on subsequent presses. So any old keyboard macros will work as expected!