From b9d414e77c4f6396e202069fdd233b6687e6da64 Mon Sep 17 00:00:00 2001 From: Daniel Colascione Date: Thu, 22 Feb 2018 17:42:48 -0800 Subject: [PATCH] Add isearch-yank-symbol-or-char * doc/emacs/search.texi (Isearch Yank): Document new function, keybindings. * etc/NEWS: Mention isearch changes. * lisp/isearch.el (isearch--yank-char-or-syntax): New function. (isearch-yank-word-or-char): Call it. (isearch-yank-symbol-or-char): New function. (isearch-mode-map): Change 'C-M-w' binding from 'isearch-del-char' to isearch-yank-symbol-or-char; add 'C-M-d' binding for 'isearch-del-char'. --- doc/emacs/search.texi | 11 +++++++++-- etc/NEWS | 5 +++++ lisp/isearch.el | 24 +++++++++++++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 319f64fbae1..37446ca1c46 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -229,6 +229,13 @@ character or word at point to the search string. This is an easy way to search for another occurrence of the text at point. (The decision of whether to copy a character or a word is heuristic.) +@kindex C-M-w @r{(Incremental search)} +@findex isearch-yank-symbol-or-char + @kbd{C-M-w} (@code{isearch-yank-symbol-or-char}) appends the next +character or symbol at point to the search string. This is an easy way +to search for another occurrence of the symbol at point. (The decision +of whether to copy a character or a word is heuristic.) + @kindex M-s C-e @r{(Incremental search)} @findex isearch-yank-line Similarly, @kbd{M-s C-e} (@code{isearch-yank-line}) appends the rest @@ -250,11 +257,11 @@ appended text with an earlier kill, similar to the usual @kbd{M-y} in the echo area appends the current X selection (@pxref{Primary Selection}) to the search string (@code{isearch-yank-x-selection}). -@kindex C-M-w @r{(Incremental search)} +@kindex C-M-d @r{(Incremental search)} @kindex C-M-y @r{(Incremental search)} @findex isearch-del-char @findex isearch-yank-char - @kbd{C-M-w} (@code{isearch-del-char}) deletes the last character + @kbd{C-M-d} (@code{isearch-del-char}) deletes the last character from the search string, and @kbd{C-M-y} (@code{isearch-yank-char}) appends the character after point to the search string. An alternative method to add the character after point is to enter the diff --git a/etc/NEWS b/etc/NEWS index 70bafcd01b4..dacaf023bb1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -109,6 +109,11 @@ regular expression was previously invalid, but is now accepted: * Editing Changes in Emacs 27.1 ++++ +** New isearch bindings. +'C-M-w' in isearch changed from isearch-del-char to the new function +isearch-yank-symbol-or-char. isearch-del-char is now bound to 'C-M-d'. + --- ** New variable 'x-wait-for-event-timeout'. This controls how long Emacs will wait for updates to the graphical diff --git a/lisp/isearch.el b/lisp/isearch.el index 1835469bb2c..b6422401a88 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -480,7 +480,8 @@ This is like `describe-bindings', but displays only Isearch keys." (define-key map [?\S-\ ] 'isearch-printing-char) (define-key map "\C-w" 'isearch-yank-word-or-char) - (define-key map "\M-\C-w" 'isearch-del-char) + (define-key map "\M-\C-w" 'isearch-yank-symbol-or-char) + (define-key map "\M-\C-d" 'isearch-del-char) (define-key map "\M-\C-y" 'isearch-yank-char) (define-key map "\C-y" 'isearch-yank-kill) (define-key map "\M-s\C-e" 'isearch-yank-line) @@ -2089,17 +2090,26 @@ If optional ARG is non-nil, pull in the next ARG characters." (interactive "p") (isearch-yank-internal (lambda () (forward-char arg) (point)))) -(defun isearch-yank-word-or-char () - "Pull next character or word from buffer into search string." - (interactive) +(defun isearch--yank-char-or-syntax (syntax-list fn) (isearch-yank-internal (lambda () - (if (or (= (char-syntax (or (char-after) 0)) ?w) - (= (char-syntax (or (char-after (1+ (point))) 0)) ?w)) - (forward-word 1) + (if (or (memq (char-syntax (or (char-after) 0)) syntax-list) + (memq (char-syntax (or (char-after (1+ (point))) 0)) + syntax-list)) + (funcall fn 1) (forward-char 1)) (point)))) +(defun isearch-yank-word-or-char () + "Pull next character or word from buffer into search string." + (interactive) + (isearch--yank-char-or-syntax '(?w) 'forward-word)) + +(defun isearch-yank-symbol-or-char () + "Pull next character or word from buffer into search string." + (interactive) + (isearch--yank-char-or-syntax '(?w ?_) 'forward-symbol)) + (defun isearch-yank-word (&optional arg) "Pull next word from buffer into search string. If optional ARG is non-nil, pull in the next ARG words." -- 2.11.4.GIT