Fixes two issues:
1. Where C-e would throw the cursor somewhere on another line (or at
   BOF).
2. Fixes #1802; where the cursor would stop a character shy of true
   end-of-text.
This commit is contained in:
Henrik Lissner 2020-01-01 16:18:50 -05:00
parent f0e05c1a44
commit 2ef0ed90a4
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -64,69 +64,71 @@ POS defaults to the current position."
;; ;;
;;; Commands ;;; Commands
(defvar doom--last-backward-pt most-positive-fixnum) (defun doom--bol-bot-eot-eol (&optional pos)
;;;###autoload (let* ((bol (if visual-line-mode
(defun doom/backward-to-bol-or-indent ()
"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)
(let ((pt (point)))
(cl-destructuring-bind (bol . bot)
(save-excursion (save-excursion
(beginning-of-visual-line) (beginning-of-visual-line)
(cons (point) (point))
(progn (skip-chars-forward " \t\r") (line-beginning-position)))
(point)))) (bot (save-excursion
(cond ((> pt bot) (goto-char bol)
(goto-char bot)) (skip-chars-forward " \t\r")
((= pt bol) (point)))
(goto-char (min doom--last-backward-pt bot)) (eol (if visual-line-mode
(setq doom--last-backward-pt most-positive-fixnum)) (save-excursion (end-of-visual-line) (point))
((<= pt bot) (line-end-position)))
(setq doom--last-backward-pt pt) (eot (or (save-excursion
(goto-char bol))))))
(defvar doom--last-forward-pt -1)
;;;###autoload
(defun doom/forward-to-last-non-comment-or-eol ()
"Jumps between the last non-blank, non-comment character in the line and the
true end of the line. The opposite of `doom/backward-to-bol-or-indent'."
(interactive)
(let ((eol (if (not visual-line-mode)
(line-end-position)
(save-excursion (end-of-visual-line) (point)))))
(if (or (and (< (point) eol)
(sp-point-in-comment))
(not (sp-point-in-comment eol)))
(if (= (point) eol)
(progn
(goto-char doom--last-forward-pt)
(setq doom--last-forward-pt -1))
(setq doom--last-forward-pt (point))
(goto-char eol))
(let* ((bol (save-excursion (beginning-of-visual-line) (point)))
(boc (or (save-excursion
(if (not comment-use-syntax) (if (not comment-use-syntax)
(progn (progn
(goto-char bol) (goto-char bol)
(when (re-search-forward comment-start-skip eol t) (when (re-search-forward comment-start-skip eol t)
(or (match-end 1) (match-beginning 0)))) (or (match-end 1) (match-beginning 0))))
(goto-char eol) (goto-char eol)
(while (and (sp-point-in-comment) (while (and (doom-point-in-comment-p)
(> (point) bol)) (> (point) bol))
(backward-char)) (backward-char))
(skip-chars-backward " " bol) (skip-chars-backward " " bol)
(unless (or (eq (char-after) 32) (eolp))
(forward-char))
(point))) (point)))
eol))) eol)))
(when (> doom--last-forward-pt boc) (list bol bot eot eol)))
(setq boc doom--last-forward-pt))
(if (or (= eol (point)) (defvar doom--last-backward-pt nil)
(> boc (point))) ;;;###autoload
(progn (defun doom/backward-to-bol-or-indent (&optional point)
(goto-char boc) "Jump between the indentation column (first non-whitespace character) and the
(setq doom--last-forward-pt -1)) beginning of the line. The opposite of
(setq doom--last-forward-pt (point)) `doom/forward-to-last-non-comment-or-eol'."
(interactive "d")
(let ((pt (or point (point))))
(cl-destructuring-bind (bol bot _eot eol)
(doom--bol-bot-eot-eol pt)
(cond ((> pt bot)
(goto-char bot))
((= pt bol)
(goto-char (or doom--last-backward-pt bot))
(setq doom--last-backward-pt nil))
((<= pt bot)
(setq doom--last-backward-pt pt)
(goto-char bol))))))
(defvar doom--last-forward-pt nil)
;;;###autoload
(defun doom/forward-to-last-non-comment-or-eol (&optional point)
"Jumps between the last non-blank, non-comment character in the line and the
true end of the line. The opposite of `doom/backward-to-bol-or-indent'."
(interactive "d")
(let ((pt (or point (point))))
(cl-destructuring-bind (_bol _bot eot eol)
(doom--bol-bot-eot-eol pt)
(cond ((< pt eot)
(goto-char eot))
((= pt eol)
(goto-char (or doom--last-forward-pt eot))
(setq doom--last-forward-pt nil))
((>= pt eot)
(setq doom--last-backward-pt pt)
(goto-char eol)))))) (goto-char eol))))))
;;;###autoload ;;;###autoload