From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kada Situ Newsgroups: gmane.emacs.help Subject: Re: automatic search/search and replace for a marked string Date: Sun, 23 Aug 2009 03:16:40 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0cd5c6feb115b10471cc65d0 X-Trace: ger.gmane.org 1251022683 8779 80.91.229.12 (23 Aug 2009 10:18:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 23 Aug 2009 10:18:03 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: lichtkind3@web.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 23 12:17:56 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MfA94-0002cK-Ud for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Aug 2009 12:17:55 +0200 Original-Received: from localhost ([127.0.0.1]:58575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfA94-0002Yl-6i for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Aug 2009 06:17:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfA7z-0002BI-9p for help-gnu-emacs@gnu.org; Sun, 23 Aug 2009 06:16:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfA7u-000288-NR for help-gnu-emacs@gnu.org; Sun, 23 Aug 2009 06:16:46 -0400 Original-Received: from [199.232.76.173] (port=42100 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfA7u-00027w-FZ for help-gnu-emacs@gnu.org; Sun, 23 Aug 2009 06:16:42 -0400 Original-Received: from mail-yw0-f184.google.com ([209.85.211.184]:64048) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfA7u-0008Es-1G for help-gnu-emacs@gnu.org; Sun, 23 Aug 2009 06:16:42 -0400 Original-Received: by ywh14 with SMTP id 14so2321821ywh.1 for ; Sun, 23 Aug 2009 03:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:cc:content-type; bh=eS5IbcrKyQR2w46BMNxA3HRKtKvZpqhfJ8nhDxunBRU=; b=QlXmclw1k1a4ReWNjkw8iy8ewsim/KBPVa9E+KZZibyZ9TPf979l6Nqi/qsYLVahgb R0UryDgXkymdMd08kh7E7Uu+Q90Ie3ExGqphBma0/J2HTHjH9blzpErqV+OFtOnnyYjb 36rhVEOFtGDhOntPye0lLREe9VDbXs27XYK9w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=YhKL0yXVE1pIjpGTb07aXvm/5eQvIq3HvbijCMfTcrbLhtJr/+Fx56lc1FhUwcNRZt TlPlOtPF/gxjCXlI37XeDs2/6EKb1WK0T5QIHEPzBfAsVoiE+Eb0Tz2KvgZ6UInlAFol wpOH76x3Ecih/LUkI7MLET43/7UqKKsbHue/M= Original-Received: by 10.150.173.39 with SMTP id v39mr5818659ybe.154.1251022600213; Sun, 23 Aug 2009 03:16:40 -0700 (PDT) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:67441 Archived-At: --000e0cd5c6feb115b10471cc65d0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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)) (defun region-search (beg end &optional direction) (setq deactivate-mark t) ;;(goto-char beg) ;;this would highlight the region as the first search result (setq isearch-forward direction isearch-regexp nil isearch-word t isearch-op-fun nil isearch-last-case-fold-search isearch-case-fold-search isearch-case-fold-search case-fold-search isearch-string (buffer-substring beg end) isearch-message "" isearch-cmds nil isearch-success t isearch-wrapped nil isearch-barrier (point) isearch-adjusted nil isearch-yank-flag nil isearch-error nil isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed) (> (window-height) (* 4 (abs search-slow-window-lines)))) isearch-other-end nil isearch-small-window nil isearch-just-started t isearch-start-hscroll (window-hscroll) isearch-opoint (point) search-ring-yank-pointer nil isearch-opened-overlays nil isearch-input-method-function input-method-function isearch-input-method-local-p (local-variable-p 'input-method-function) regexp-search-ring-yank-pointer nil isearch-original-minibuffer-message-timeout minibuffer-message-timeout minibuffer-message-timeout nil) (looking-at "") (setq isearch-window-configuration (if isearch-slow-terminal-mode (current-window-configuration) nil)) (let ((frame (window-frame (minibuffer-window)))) (unless (memq (frame-live-p frame) '(nil t)) (unless (frame-visible-p frame) (make-frame-visible frame)) (if minibuffer-auto-raise (raise-frame frame)))) (setq isearch-mode " Isearch") ;; forward? regexp? (force-mode-line-update) (isearch-push-state) (setq overriding-terminal-local-map isearch-mode-map) (run-hooks 'isearch-mode-hook) (isearch-update) (add-hook 'mouse-leave-buffer-hook 'isearch-done) (add-hook 'kbd-macro-termination-hook 'isearch-done) (isearch-update-string isearch-string)) (provide 'region-search) --000e0cd5c6feb115b10471cc65d0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I have used UltraEdit before I switched to emacs, there is a searching feat= ure 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 searc= h 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 sea= rch, 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. Jus= t don't do more than one F3 in a row, or you will end up with everythin= g between the
first searching result and the second result filled in your isearch input f= ield.
I am no Lisp expert, so if anyone likes to implement the missing p= art 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
;;=A0=A0=A0=A0= =A0=A0=A0=A0=A0 (eval-after-load "isearch" '(require 'reg= ion-search))
;;=A0=A0=A0=A0=A0=A0=A0=A0=A0 (global-set-key [f3] 'region-search-forwa= rd)
;;=A0=A0=A0=A0=A0=A0=A0=A0=A0 (global-set-key [(shift f3)] 'regi= on-search-backward)

;; most of the code=A0 borrowed from isearch.el<= br>(defun isearch-update-string (string)
=A0 "Pull STRING into search string."
=A0 ;; Downcase the stri= ng if not supposed to case-fold yanked strings.
=A0 (if (and isearch-cas= e-fold-search
=A0=A0=A0 =A0=A0 (eq 'not-yanks search-upper-case))=A0=A0=A0=A0=A0 (setq string (downcase string)))
=A0 (if isearch-regexp (setq string (regexp-quote string)))
=A0 (setq is= earch-string string
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-mess= age (mapconcat 'isearch-text-char-description
=A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0st= ring "")
=A0=A0=A0 ;; Don't move cursor in reverse search.
=A0=A0=A0 isearch-= yank-flag t)
=A0 (isearch-search-and-update))
(defun region-search-fo= rward (beg end)
=A0=A0=A0 (interactive "r")
=A0=A0=A0 (regi= on-search beg end t))
(defun region-search-backward (beg end)
=A0=A0=A0 (interactive "r&q= uot;)
=A0=A0=A0 (region-search beg end nil))

(defun region-search= (beg end &optional direction)
=A0=A0=A0 (setq deactivate-mark t)=A0=A0=A0 ;;(goto-char beg) ;;this would highlight the region as the first= search result
=A0=A0=A0 (setq isearch-forward direction
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 isearch-regexp nil
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ise= arch-word t
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-op-fun nil=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-last-case-fold-search ise= arch-case-fold-search
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-case-fold-search case-fold-= search
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-string (buffer-su= bstring beg end)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-message= ""
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-cmds nil=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-success t
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-wrapped nil
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-barrier (point)
=A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 isearch-adjusted nil
=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 isearch-yank-flag nil
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 isearch-error nil
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-sl= ow-terminal-mode (and (<=3D baud-rate search-slow-speed)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 (> (window-height)=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0(* 4<= br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 (abs search-slow-window-lines))))
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-other-end nil
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-small-window nil
=A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 isearch-just-started t
=A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 isearch-start-hscroll (window-hscroll)
=A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 isearch-opoint (point)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 search-ring-yank-pointer nil
=A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-opened-overlays nil
=A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-input-method-function input-metho= d-function
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-input-method-= local-p (local-variable-p 'input-method-function)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 regexp-search-ring-yank-pointer nil=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 isearch-original-minibuffer-mes= sage-timeout minibuffer-message-timeout
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 = =A0=A0=A0 minibuffer-message-timeout nil)
=A0=A0=A0 (looking-at "&q= uot;)
=A0 (setq isearch-window-configuration
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0= =A0=A0 (if isearch-slow-terminal-mode (current-window-configuration) nil))<= br>=A0=A0=A0 =A0 (let ((frame (window-frame (minibuffer-window))))
=A0= =A0=A0 (unless (memq (frame-live-p frame) '(nil t))
=A0=A0=A0=A0=A0 (unless (frame-visible-p frame)
=A0=A0=A0 (make-frame-vi= sible frame))
=A0=A0=A0=A0=A0 (if minibuffer-auto-raise
=A0=A0=A0 =A0= (raise-frame frame))))
=A0=A0=A0=A0=A0=A0=A0 (setq=A0 isearch-mode &quo= t; Isearch")=A0 ;; forward? regexp?
=A0=A0=A0 =A0=A0=A0 (force-mode= -line-update)
=A0=A0=A0 =A0=A0=A0 (isearch-push-state)
=A0=A0=A0 =A0=A0=A0 (setq overr= iding-terminal-local-map isearch-mode-map)
=A0=A0=A0 =A0=A0=A0 (run-hook= s 'isearch-mode-hook)
=A0=A0=A0 =A0=A0=A0 (isearch-update)
=A0=A0= =A0 =A0=A0=A0 (add-hook 'mouse-leave-buffer-hook 'isearch-done)
=A0=A0=A0 =A0=A0=A0 (add-hook 'kbd-macro-termination-hook 'isearch-= done)
=A0=A0=A0 =A0=A0=A0 (isearch-update-string isearch-string))
(provide 'region-search)
--000e0cd5c6feb115b10471cc65d0--