This worked, but there’s a better way: the command M-m takes you to the start of a line, but after all initial whitespace.
I find it more intuitive to just make Home/C-a smarter:
;;"Redefine the Home/End keys to (nearly) the same as visual studio
;;behavior... special home and end by Shan-leung Maverick WOO
;;<sw77@cornell.edu>”
;;This is complex. In short, the 1st invocation of Home/End moves
;;to the beginning of the *text* line (ignoring prefixed whitespace); 2nd invocation moves
;;cursor to the beginning of the *absolute* line. Most of the time
;;this won’t matter or even be noticeable, but when it does (in
;;comments, for example) it will be quite convenient.
(global-set-key [home] ’my-smart-home)
(global-set-key [end] ‘my-smart-end)
(defun my-smart-home ()
“Odd home to beginning of line, even home to beginning of
text/code.”
(interactive)
(if (and (eq last-command ‘my-smart-home)
(/= (line-beginning-position) (point)))
(beginning-of-line)
(beginning-of-line-text)))
(defun my-smart-end ()
“Odd end to end of line, even end to begin of text/code.”
(interactive)
(if (and (eq last-command ‘my-smart-end)
(= (line-end-position) (point)))
(end-of-line-text)
(end-of-line)))
(defun end-of-line-text ()
“Move to end of current line and skip comments and trailing space.
Require `font-lock’.”
(interactive)
(end-of-line)
(let ((bol (line-beginning-position)))
(unless (eq font-lock-comment-face (get-text-property bol ’face))
(while (and (/= bol (point))
(eq font-lock-comment-face
(get-text-property (point) ’face)))
(backward-char 1))
(unless (= (point) bol)
(forward-char 1) (skip-chars-backward ” \t\n”))))) ;;Done with home and end keys.
So it’s just C-a to go where I usually want to, and then if that’s not good, just drum your fingers with a second C-a to go to the true beginning of the line. Quite intuitive. ‘Go to the start of the line—no, really go to the start of the line!’
I find it more intuitive to just make
Home
/C-a
smarter:So it’s just
C-a
to go where I usually want to, and then if that’s not good, just drum your fingers with a secondC-a
to go to the true beginning of the line. Quite intuitive. ‘Go to the start of the line—no, really go to the start of the line!’Ah,
beginning-of-line-text
is nice. It skips over the initial # or // of comments and the initial * of Org headings. I’ve now bound it to M-m.