Fix C-a/C-e #1802
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:
parent
f0e05c1a44
commit
2ef0ed90a4
1 changed files with 52 additions and 50 deletions
|
@ -64,70 +64,72 @@ POS defaults to the current position."
|
||||||
;;
|
;;
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
(defvar doom--last-backward-pt most-positive-fixnum)
|
(defun doom--bol-bot-eot-eol (&optional pos)
|
||||||
|
(let* ((bol (if visual-line-mode
|
||||||
|
(save-excursion
|
||||||
|
(beginning-of-visual-line)
|
||||||
|
(point))
|
||||||
|
(line-beginning-position)))
|
||||||
|
(bot (save-excursion
|
||||||
|
(goto-char bol)
|
||||||
|
(skip-chars-forward " \t\r")
|
||||||
|
(point)))
|
||||||
|
(eol (if visual-line-mode
|
||||||
|
(save-excursion (end-of-visual-line) (point))
|
||||||
|
(line-end-position)))
|
||||||
|
(eot (or (save-excursion
|
||||||
|
(if (not comment-use-syntax)
|
||||||
|
(progn
|
||||||
|
(goto-char bol)
|
||||||
|
(when (re-search-forward comment-start-skip eol t)
|
||||||
|
(or (match-end 1) (match-beginning 0))))
|
||||||
|
(goto-char eol)
|
||||||
|
(while (and (doom-point-in-comment-p)
|
||||||
|
(> (point) bol))
|
||||||
|
(backward-char))
|
||||||
|
(skip-chars-backward " " bol)
|
||||||
|
(unless (or (eq (char-after) 32) (eolp))
|
||||||
|
(forward-char))
|
||||||
|
(point)))
|
||||||
|
eol)))
|
||||||
|
(list bol bot eot eol)))
|
||||||
|
|
||||||
|
(defvar doom--last-backward-pt nil)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/backward-to-bol-or-indent ()
|
(defun doom/backward-to-bol-or-indent (&optional point)
|
||||||
"Jump between the indentation column (first non-whitespace character) and the
|
"Jump between the indentation column (first non-whitespace character) and the
|
||||||
beginning of the line. The opposite of
|
beginning of the line. The opposite of
|
||||||
`doom/forward-to-last-non-comment-or-eol'."
|
`doom/forward-to-last-non-comment-or-eol'."
|
||||||
(interactive)
|
(interactive "d")
|
||||||
(let ((pt (point)))
|
(let ((pt (or point (point))))
|
||||||
(cl-destructuring-bind (bol . bot)
|
(cl-destructuring-bind (bol bot _eot eol)
|
||||||
(save-excursion
|
(doom--bol-bot-eot-eol pt)
|
||||||
(beginning-of-visual-line)
|
|
||||||
(cons (point)
|
|
||||||
(progn (skip-chars-forward " \t\r")
|
|
||||||
(point))))
|
|
||||||
(cond ((> pt bot)
|
(cond ((> pt bot)
|
||||||
(goto-char bot))
|
(goto-char bot))
|
||||||
((= pt bol)
|
((= pt bol)
|
||||||
(goto-char (min doom--last-backward-pt bot))
|
(goto-char (or doom--last-backward-pt bot))
|
||||||
(setq doom--last-backward-pt most-positive-fixnum))
|
(setq doom--last-backward-pt nil))
|
||||||
((<= pt bot)
|
((<= pt bot)
|
||||||
(setq doom--last-backward-pt pt)
|
(setq doom--last-backward-pt pt)
|
||||||
(goto-char bol))))))
|
(goto-char bol))))))
|
||||||
|
|
||||||
(defvar doom--last-forward-pt -1)
|
(defvar doom--last-forward-pt nil)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/forward-to-last-non-comment-or-eol ()
|
(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
|
"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'."
|
true end of the line. The opposite of `doom/backward-to-bol-or-indent'."
|
||||||
(interactive)
|
(interactive "d")
|
||||||
(let ((eol (if (not visual-line-mode)
|
(let ((pt (or point (point))))
|
||||||
(line-end-position)
|
(cl-destructuring-bind (_bol _bot eot eol)
|
||||||
(save-excursion (end-of-visual-line) (point)))))
|
(doom--bol-bot-eot-eol pt)
|
||||||
(if (or (and (< (point) eol)
|
(cond ((< pt eot)
|
||||||
(sp-point-in-comment))
|
(goto-char eot))
|
||||||
(not (sp-point-in-comment eol)))
|
((= pt eol)
|
||||||
(if (= (point) eol)
|
(goto-char (or doom--last-forward-pt eot))
|
||||||
(progn
|
(setq doom--last-forward-pt nil))
|
||||||
(goto-char doom--last-forward-pt)
|
((>= pt eot)
|
||||||
(setq doom--last-forward-pt -1))
|
(setq doom--last-backward-pt pt)
|
||||||
(setq doom--last-forward-pt (point))
|
(goto-char eol))))))
|
||||||
(goto-char eol))
|
|
||||||
(let* ((bol (save-excursion (beginning-of-visual-line) (point)))
|
|
||||||
(boc (or (save-excursion
|
|
||||||
(if (not comment-use-syntax)
|
|
||||||
(progn
|
|
||||||
(goto-char bol)
|
|
||||||
(when (re-search-forward comment-start-skip eol t)
|
|
||||||
(or (match-end 1) (match-beginning 0))))
|
|
||||||
(goto-char eol)
|
|
||||||
(while (and (sp-point-in-comment)
|
|
||||||
(> (point) bol))
|
|
||||||
(backward-char))
|
|
||||||
(skip-chars-backward " " bol)
|
|
||||||
(point)))
|
|
||||||
eol)))
|
|
||||||
(when (> doom--last-forward-pt boc)
|
|
||||||
(setq boc doom--last-forward-pt))
|
|
||||||
(if (or (= eol (point))
|
|
||||||
(> boc (point)))
|
|
||||||
(progn
|
|
||||||
(goto-char boc)
|
|
||||||
(setq doom--last-forward-pt -1))
|
|
||||||
(setq doom--last-forward-pt (point))
|
|
||||||
(goto-char eol))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/backward-kill-to-bol-and-indent ()
|
(defun doom/backward-kill-to-bol-and-indent ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue