bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Feature suggestion: yanking sexps to incremental search


From: Colin Walters
Subject: Re: Feature suggestion: yanking sexps to incremental search
Date: 21 Oct 2000 19:44:45 -0400
User-agent: Microsoft Gnus Express, Build 5.0808 (5.8.8)

azure@vvf.fi (Hannu Koivisto) writes:

> I think it would be convenient if isearch-mode-map had a binding
> for yanking sexps, not just words (C-w), from buffer onto end of
> search string.  This would make it easier to search for symbols,
> for instance.  Perhaps M-C-w could be used as that binding?

Seems like a good feature; here is an implementation of your
suggestion.  (note that I do not represent the opinion of the Emacs
maintainers; I just saw your message on g.e.bug.)

walters@meta:~$ diff -u /usr/src/emacs-20.7/lisp/isearch.el ~/lisp/isearch.el
--- /usr/src/emacs-20.7/lisp/isearch.el Wed May 31 07:43:30 2000
+++ /home/walters/lisp/isearch.el       Sat Oct 21 19:42:00 2000
@@ -284,6 +284,7 @@
     
       (define-key map "\C-w" 'isearch-yank-word)
       (define-key map "\C-y" 'isearch-yank-line)
+      (define-key map "\C-\M-y" 'isearch-yank-sexp)
 
       ;; Define keys for regexp chars * ? |.
       ;; Nothing special for + because it matches at least once.
@@ -1028,6 +1029,23 @@
          (goto-char isearch-other-end))
      (buffer-substring (point) (line-end-position)))))
 
+(defun isearch-yank-sexp ()
+  "Pull the sexp following point from buffer into search string."
+  (interactive)
+  (isearch-yank-string
+   (save-excursion
+     (and (not isearch-forward) isearch-other-end
+         (goto-char isearch-other-end))
+     (condition-case ()
+        (save-excursion
+          (let ((end (progn (forward-sexp)
+                            (point))))
+            (buffer-substring (progn (backward-sexp)
+                                     (point))
+                              end)))
+       (error (progn (message "Unable to find balanced sexp")
+                    (sit-for 1))
+             "")))))
 
 (defun isearch-search-and-update ()
   ;; Do the search and update the display.



reply via email to

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