Improve visual-line-mode support in doom/backward-to-bol-or-indent #396

This commit is contained in:
Henrik Lissner 2018-02-01 14:43:28 -05:00
parent 1e9b492399
commit 7c48e7e5cc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -17,17 +17,19 @@
;;;###autoload
(defun doom/backward-to-bol-or-indent ()
"Move back to the current line's indentation. If already there, move to the
beginning of the line instead. If at bol, do nothing."
"Jump between the indentation column (first non-whitespace character) and the
beginning of the line. The opposite of
`doom/forward-to-last-non-comment-or-eol'."
(interactive)
(if (bound-and-true-p visual-line-mode)
(beginning-of-visual-line)
(let ((ci (current-indentation))
(cc (current-column)))
(cond ((or (> cc ci) (= cc 0))
(back-to-indentation))
((<= cc ci)
(beginning-of-visual-line))))))
(let ((pos (point))
(indent (save-excursion
(beginning-of-visual-line)
(skip-chars-forward " \t\r")
(point))))
(cond ((or (> pos indent) (= pos (line-beginning-position)))
(goto-char indent))
((<= pos indent)
(beginning-of-visual-line)))))
;;;###autoload
(defun doom/forward-to-last-non-comment-or-eol ()