Refactor & fix doom/forward-to-last-non-comment-or-eol

This commit is contained in:
Henrik Lissner 2018-02-01 16:35:55 -05:00
parent 7c48e7e5cc
commit dadfeec506
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -33,30 +33,30 @@ beginning of the line. The opposite of
;;;###autoload ;;;###autoload
(defun doom/forward-to-last-non-comment-or-eol () (defun doom/forward-to-last-non-comment-or-eol ()
"Move forward to the last non-blank character in the line, ignoring comments "Jumps between the last non-blank, non-comment character in the line and the
and trailing whitespace. If already there, move to the real end of the line. true end of the line. The opposite of `doom/backward-to-bol-or-indent'."
If already there, do nothing."
(interactive) (interactive)
(let* ((point (point)) (let ((eol (save-excursion (end-of-visual-line) (point))))
(eol (save-excursion (end-of-visual-line) (point))) (if (and (sp-point-in-comment) (not (= (point) eol)))
(bol (save-excursion (beginning-of-visual-line) (point))) (goto-char eol)
(eoc (or (if (not comment-use-syntax) (let* ((bol (save-excursion (beginning-of-visual-line) (point)))
(when (re-search-forward comment-start-skip eol t) (boc (or (save-excursion
(or (match-end 1) (match-beginning 0))) (if (not comment-use-syntax)
(save-excursion (progn
(goto-char eol) (goto-char bol)
(while (and (sp-point-in-comment) (when (re-search-forward comment-start-skip eol t)
(> (point) point)) (or (match-end 1) (match-beginning 0))))
(backward-char)) (goto-char eol)
(when (> (point) point) (while (and (sp-point-in-comment)
(skip-chars-backward " " bol) (> (point) bol))
(point)))) (backward-char))
eol)) (skip-chars-backward " " bol)
(goto-char-fn (if (featurep 'evil) #'evil-goto-char #'goto-char))) (point)))
(if (= eoc point) eol)))
(funcall goto-char-fn eol) (cond ((= boc (point))
(unless (= eol point) (goto-char eol))
(funcall goto-char-fn eoc))))) ((/= bol boc)
(goto-char boc)))))))
(defun doom--surrounded-p () (defun doom--surrounded-p ()
(and (looking-back "[[{(]\\(\s+\\|\n\\)?\\(\s\\|\t\\)*" (line-beginning-position)) (and (looking-back "[[{(]\\(\s+\\|\n\\)?\\(\s\\|\t\\)*" (line-beginning-position))