Fix #1558: remember position on C-a/C-e

When the cursor is between the swap points.
This commit is contained in:
Henrik Lissner 2019-07-12 18:19:28 +02:00
parent 92ca6762ac
commit 17d7130804
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -29,35 +29,47 @@ lines, above and below, with only whitespace in between."
;; ;;
;; Commands ;; Commands
(defvar doom--last-backward-pt most-positive-fixnum)
;;;###autoload ;;;###autoload
(defun doom/backward-to-bol-or-indent () (defun doom/backward-to-bol-or-indent ()
"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)
(let ((pos (point)) (let ((pt (point)))
(indent (save-excursion (cl-destructuring-bind (bol . bot)
(beginning-of-visual-line) (save-excursion
(skip-chars-forward " \t\r") (beginning-of-visual-line)
(point)))) (cons (point)
(cond ((or (> pos indent) (= pos (line-beginning-position))) (progn (skip-chars-forward " \t\r")
(goto-char indent)) (point))))
((<= pos indent) (cond ((> pt bot)
(beginning-of-visual-line))))) (goto-char bot))
((= pt bol)
(goto-char (min doom--last-backward-pt bot))
(setq doom--last-backward-pt most-positive-fixnum))
((<= pt bot)
(setq doom--last-backward-pt pt)
(goto-char bol))))))
(defvar doom--last-forward-pt -1)
;;;###autoload ;;;###autoload
(defun doom/forward-to-last-non-comment-or-eol () (defun doom/forward-to-last-non-comment-or-eol ()
"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)
(let ((eol (save-excursion (if visual-line-mode (let ((eol (if (not visual-line-mode)
(end-of-visual-line) (line-end-position)
(end-of-line)) (save-excursion (end-of-visual-line) (point)))))
(point))))
(if (or (and (< (point) eol) (if (or (and (< (point) eol)
(sp-point-in-comment)) (sp-point-in-comment))
(not (sp-point-in-comment eol))) (not (sp-point-in-comment eol)))
(goto-char 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))) (let* ((bol (save-excursion (beginning-of-visual-line) (point)))
(boc (or (save-excursion (boc (or (save-excursion
(if (not comment-use-syntax) (if (not comment-use-syntax)
@ -72,9 +84,14 @@ true end of the line. The opposite of `doom/backward-to-bol-or-indent'."
(skip-chars-backward " " bol) (skip-chars-backward " " bol)
(point))) (point)))
eol))) eol)))
(when (> doom--last-forward-pt boc)
(setq boc doom--last-forward-pt))
(if (or (= eol (point)) (if (or (= eol (point))
(> boc (point))) (> boc (point)))
(goto-char boc) (progn
(goto-char boc)
(setq doom--last-forward-pt -1))
(setq doom--last-forward-pt (point))
(goto-char eol)))))) (goto-char eol))))))
;;;###autoload ;;;###autoload