From 6501d42f0b9ce6e6cfe075348315c63aea046588 Mon Sep 17 00:00:00 2001 From: Justin Burkett Date: Sat, 20 Jul 2019 23:07:52 -0400 Subject: Teach more commands about evil-respect-visual-line-mode The following commands now act on visual lines when evil-respect-visual-line-mode is non-nil: evil-insert-line evil-append-line evil-find-char evil-find-char-backward evil-find-char-to evil-find-char-to-backward --- evil-commands.el | 37 ++++++++++++++++++++++++++++++------- evil-vars.el | 14 ++++++++++---- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 225cfa1..5feea84 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -652,16 +652,27 @@ Movement is restricted to the current line unless `evil-cross-lines' is non-nil. :type inclusive (interactive "") (setq count (or count 1)) - (let ((fwd (> count 0))) + (let ((fwd (> count 0)) + (visual (and evil-respect-visual-line-mode + visual-line-mode))) (setq evil-last-find (list #'evil-find-char char fwd)) (when fwd (forward-char)) (let ((case-fold-search nil)) (unless (prog1 (search-forward (char-to-string char) - (unless evil-cross-lines - (if fwd - (line-end-position) - (line-beginning-position))) + (cond (evil-cross-lines) + ((and fwd visual) + (save-excursion + (end-of-visual-line) + (point))) + (fwd + (line-end-position)) + (visual + (save-excursion + (beginning-of-visual-line) + (point))) + (t + (line-beginning-position))) t count) (when fwd (backward-char))) (user-error "Can't find %c" char))))) @@ -2354,7 +2365,16 @@ non nil it should be number > 0. The insertion will be repeated in the next VCOUNT - 1 lines below the current one." (interactive "p") (push (point) buffer-undo-list) - (back-to-indentation) + (if (and visual-line-mode + evil-respect-visual-line-mode) + (goto-char + (max (save-excursion + (back-to-indentation) + (point)) + (save-excursion + (beginning-of-visual-line) + (point)))) + (back-to-indentation)) (setq evil-insert-count count evil-insert-lines nil evil-insert-vcount @@ -2371,7 +2391,10 @@ The insertion will be repeated COUNT times. If VCOUNT is non nil it should be number > 0. The insertion will be repeated in the next VCOUNT - 1 lines below the current one." (interactive "p") - (evil-move-end-of-line) + (if (and visual-line-mode + evil-respect-visual-line-mode) + (evil-end-of-visual-line) + (evil-move-end-of-line)) (setq evil-insert-count count evil-insert-lines nil evil-insert-vcount diff --git a/evil-vars.el b/evil-vars.el index a28a93f..d95450c 100644 --- a/evil-vars.el +++ b/evil-vars.el @@ -217,17 +217,23 @@ a line." :group 'evil) (defcustom evil-respect-visual-line-mode nil - "Whether to remap movement commands when `visual-line-mode' is active. -This variable must be set before Evil is loaded. The commands -swapped are + "Whether movement commands respect `visual-line-mode'. +This variable must be set before Evil is loaded. When +`visual-line-mode' is active, the following commands are swapped `evil-next-line' <-> `evil-next-visual-line' `evil-previous-line' <-> `evil-previous-visual-line' `evil-beginning-of-line' <-> `evil-beginning-of-visual-line' -`evil-end-of-line' <-> `evil-end-of-visual-line'" +`evil-end-of-line' <-> `evil-end-of-visual-line' + +The commands `evil-insert-line', `evil-append-line', +`evil-find-char', `evil-find-char-backward', `evil-find-char-to' +and `evil-find-char-to-backward' are also made aware of visual +lines." :type 'boolean :group 'evil) + (defcustom evil-repeat-find-to-skip-next t "Whether a repeat of t or T should skip an adjacent character." :type 'boolean -- cgit v1.0 From b450e0f49400211426a18d86a6ae35e182457a84 Mon Sep 17 00:00:00 2001 From: Justin Burkett Date: Sun, 28 Jul 2019 17:00:09 -0400 Subject: Fix previous commit when evil-cross-lines is t --- evil-commands.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evil-commands.el b/evil-commands.el index 5feea84..fc8641c 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -660,7 +660,8 @@ Movement is restricted to the current line unless `evil-cross-lines' is non-nil. (let ((case-fold-search nil)) (unless (prog1 (search-forward (char-to-string char) - (cond (evil-cross-lines) + (cond (evil-cross-lines + nil) ((and fwd visual) (save-excursion (end-of-visual-line) -- cgit v1.0