emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil a760514448 1/3: C-w support yank word when search-mod


From: ELPA Syncer
Subject: [nongnu] elpa/evil a760514448 1/3: C-w support yank word when search-module is 'evil-search
Date: Wed, 5 Oct 2022 12:58:34 -0400 (EDT)

branch: elpa/evil
commit a760514448178b0c6446dc66bb2613709bbcc6f2
Author: jixiuf <jixiuf@qq.com>
Commit: Tom Dalziel <33435574+tomdl89@users.noreply.github.com>

    C-w support yank word when search-module is 'evil-search
---
 evil-maps.el   |  2 +-
 evil-search.el | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/evil-maps.el b/evil-maps.el
index 3afb46da97..56540ca6d5 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -592,7 +592,7 @@ included in `evil-insert-state-bindings' by default."
 (define-key evil-ex-search-keymap "\C-p" 'previous-history-element)
 (define-key evil-ex-search-keymap "\C-u" 'evil-delete-whole-line)
 (define-key evil-ex-search-keymap "\C-v" #'quoted-insert)
-(define-key evil-ex-search-keymap "\C-w" 'backward-kill-word)
+(define-key evil-ex-search-keymap "\C-w" 'evil-search-yank-word)
 
 ;; ex command line
 (define-key evil-ex-completion-map "\d" #'evil-ex-delete-backward-char)
diff --git a/evil-search.el b/evil-search.el
index 4b14731581..ae63aeb7ba 100644
--- a/evil-search.el
+++ b/evil-search.el
@@ -920,7 +920,8 @@ message to be shown. This function does nothing if
   (remove-hook 'after-change-functions #'evil-ex-search-update-pattern t)
   (when evil-ex-search-overlay
     (delete-overlay evil-ex-search-overlay)
-    (setq evil-ex-search-overlay nil)))
+    (setq evil-ex-search-overlay nil))
+  (setq evil-ex-search-yank-point nil))
 (put 'evil-ex-search-stop-session 'permanent-local-hook t)
 
 (defun evil-ex-split-search-pattern (pattern direction)
@@ -1332,6 +1333,37 @@ a :substitute command with arguments."
   (evil-ex-delete-hl 'evil-ex-substitute)
   (evil-ex-delete-hl 'evil-ex-search))
 
+;; Yank text at point.
+(defvar evil-ex-search-yank-point nil)
+
+(defun evil-search-yank-word (&optional arg)
+  "Pull next word from buffer into search string."
+  (interactive)
+  (let ((fwd-fn #'forward-word)
+        (minibuf-content (minibuffer-contents-no-properties))
+        (word "") start)
+    (with-current-buffer evil-ex-current-buffer
+      ;; Start to initial point if C-w have never been hit.
+      (unless evil-ex-search-yank-point
+        (if (string-empty-p minibuf-content)
+            (setq evil-ex-search-yank-point evil-ex-search-start-point)
+          (setq evil-ex-search-yank-point (point))))
+      (save-excursion
+        (goto-char evil-ex-search-yank-point)
+        (setq start (point))
+        (when (looking-at-p (regexp-quote minibuf-content))
+          (forward-char (length minibuf-content))
+          (setq start (point))
+          (funcall fwd-fn 1))
+        (setq word (buffer-substring-no-properties start (point)))))
+    (when (equal evil-ex-search-case 'smart)
+      (let ((case-fold-search nil))
+        (unless (string-match-p "[A-Z]" minibuf-content)
+          (setq word (downcase word)))))
+    (evil-set-register ?s word)
+    (evil-paste-from-register ?s)))
+
+
 (provide 'evil-search)
 
 ;;; evil-search.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]