Re: automatic search/search and replace for a marked string
From:
Kada Situ
Subject:
Re: automatic search/search and replace for a marked string
Date:
Sun, 23 Aug 2009 03:16:40 -0700
I have used UltraEdit before I switched to emacs, there is a searching feature in UltraEdit that I want it so bad in emacs. Basically, in UltraEdit, you highlight some text, and press F3, it will automatically do the search of the lighlighted
text for you. Similarly, if you do Shift+F3 it will do the highlight search backward. I did a little isearch hacking, looks like I am able to port this feature to emacs. Well, most of it, except that you can't
continuously press F3 to do the incremental search. So, with region search, you highlight the text first, then press F3, the highlighted text will fill in the isearch input. From this point on, you can C-s or C-r. Just don't do more than one F3 in a row, or you will end up with everything between the
first searching result and the second result filled in your isearch input field. I am no Lisp expert, so if anyone likes to implement the missing part or improve the code, feel free to do so :)
--
___ K.S
;; save the following code as region-search.el ;; to install it, put the following code in your .emacs file ;; (eval-after-load "isearch" '(require 'region-search))
;; (global-set-key [f3] 'region-search-forward) ;; (global-set-key [(shift f3)] 'region-search-backward)
;; most of the code borrowed from isearch.el (defun isearch-update-string (string)
"Pull STRING into search string." ;; Downcase the string if not supposed to case-fold yanked strings. (if (and isearch-case-fold-search (eq 'not-yanks search-upper-case)) (setq string (downcase string)))
(if isearch-regexp (setq string (regexp-quote string))) (setq isearch-string string isearch-message (mapconcat 'isearch-text-char-description string "")
;; Don't move cursor in reverse search. isearch-yank-flag t) (isearch-search-and-update)) (defun region-search-forward (beg end) (interactive "r") (region-search beg end t))
(defun region-search-backward (beg end) (interactive "r") (region-search beg end nil))