Fix #1558: remember position on C-a/C-e
When the cursor is between the swap points.
This commit is contained in:
parent
92ca6762ac
commit
17d7130804
1 changed files with 32 additions and 15 deletions
|
@ -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)
|
||||||
|
(save-excursion
|
||||||
(beginning-of-visual-line)
|
(beginning-of-visual-line)
|
||||||
(skip-chars-forward " \t\r")
|
(cons (point)
|
||||||
|
(progn (skip-chars-forward " \t\r")
|
||||||
(point))))
|
(point))))
|
||||||
(cond ((or (> pos indent) (= pos (line-beginning-position)))
|
(cond ((> pt bot)
|
||||||
(goto-char indent))
|
(goto-char bot))
|
||||||
((<= pos indent)
|
((= pt bol)
|
||||||
(beginning-of-visual-line)))))
|
(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)))
|
||||||
|
(progn
|
||||||
(goto-char boc)
|
(goto-char boc)
|
||||||
|
(setq doom--last-forward-pt -1))
|
||||||
|
(setq doom--last-forward-pt (point))
|
||||||
(goto-char eol))))))
|
(goto-char eol))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue