* automatic search/search and replace for a marked string
@ 2009-08-22 11:07 lichtkind
2009-08-22 13:58 ` Xah Lee
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: lichtkind @ 2009-08-22 11:07 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I have marked a string. Now I want to search for this string in the
whole text. I know that I can search with C-R or C-S. and type in the
searchstring. I'm looking for a way, that the marked string is
automatic the searchstring. This should also work for the other
search/ search and replace types.
Regards
lichtkind
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
2009-08-22 11:07 automatic search/search and replace for a marked string lichtkind
@ 2009-08-22 13:58 ` Xah Lee
2009-08-22 14:27 ` Pascal J. Bourguignon
2009-08-23 22:05 ` A.Politz
2 siblings, 0 replies; 9+ messages in thread
From: Xah Lee @ 2009-08-22 13:58 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 22, 4:07 am, lichtkind <lichtki...@web.de> wrote:
> Hello,
>
> I have marked a string. Now I want to search for this string in the
> whole text. I know that I can search with C-R or C-S. and type in the
> searchstring. I'm looking for a way, that the marked string is
> automatic the searchstring. This should also work for the other
> search/ search and replace types.
if u are using emacs 22, then you can do this:
“Ctrl+s Ctrl+w”. This will search the current word, but you must move
your cursor to the beginning of the word first.
In emacs 23, the above is deprecated. Basically, now you start it with
M-s as prefix, then press some other key. It's rather complex and very
not intuitive. I have 10 years of using emacs, but i did spent some 5
or 10 min reading the release notes... but i haven't figured it out.
You can, type M-s then C-h, to get a list of shortcuts that has M-s as
start. You can read their command names there.
here's the output:
Global Bindings Starting With M-s:
key binding
--- -------
M-s h Prefix Command
M-s o occur
M-s w isearch-forward-word
M-s h f hi-lock-find-patterns
M-s h l highlight-lines-matching-regexp
M-s h p highlight-phrase
M-s h r highlight-regexp
M-s h u unhighlight-regexp
M-s h w hi-lock-write-interactive-patterns
ok, i just gave another try with M-s w. Spent another 2 min on this.
Dunno what the fuck it is going.
someday i'll give a hour or two on this, maybe then i'll know the
answer.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
2009-08-22 11:07 automatic search/search and replace for a marked string lichtkind
2009-08-22 13:58 ` Xah Lee
@ 2009-08-22 14:27 ` Pascal J. Bourguignon
2009-08-22 15:12 ` Andy Stewart
` (2 more replies)
2009-08-23 22:05 ` A.Politz
2 siblings, 3 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-22 14:27 UTC (permalink / raw)
To: help-gnu-emacs
lichtkind <lichtkind3@web.de> writes:
> Hello,
>
> I have marked a string. Now I want to search for this string in the
> whole text. I know that I can search with C-R or C-S. and type in the
> searchstring. I'm looking for a way, that the marked string is
> automatic the searchstring. This should also work for the other
> search/ search and replace types.
M-w C-s M-y
You would normally paste (yank) with C-y, but strangely in the C-s
minibuffer, you have to use M-y.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
2009-08-22 14:27 ` Pascal J. Bourguignon
@ 2009-08-22 15:12 ` Andy Stewart
2009-08-22 15:14 ` Eric Abrahamsen
[not found] ` <mailman.5145.1250957330.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 9+ messages in thread
From: Andy Stewart @ 2009-08-22 15:12 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> lichtkind <lichtkind3@web.de> writes:
>
>> Hello,
>>
>> I have marked a string. Now I want to search for this string in the
>> whole text. I know that I can search with C-R or C-S. and type in the
>> searchstring. I'm looking for a way, that the marked string is
>> automatic the searchstring. This should also work for the other
>> search/ search and replace types.
I think you're looking for LazySearch, at
http://www.emacswiki.org/emacs/LazySearch
See http://www.emacswiki.org/emacs/LazySearch#toc3 for install
LazySearch library.
-- Andy
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
2009-08-22 14:27 ` Pascal J. Bourguignon
2009-08-22 15:12 ` Andy Stewart
@ 2009-08-22 15:14 ` Eric Abrahamsen
[not found] ` <mailman.5145.1250957330.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 9+ messages in thread
From: Eric Abrahamsen @ 2009-08-22 15:14 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 22, 2009, at 10:27 PM, Pascal J. Bourguignon wrote:
> lichtkind <lichtkind3@web.de> writes:
>
>> Hello,
>>
>> I have marked a string. Now I want to search for this string in the
>> whole text. I know that I can search with C-R or C-S. and type in the
>> searchstring. I'm looking for a way, that the marked string is
>> automatic the searchstring. This should also work for the other
>> search/ search and replace types.
>
> M-w C-s M-y
>
> You would normally paste (yank) with C-y, but strangely in the C-s
> minibuffer, you have to use M-y.
There's also some relevant stuff in Isearch Yanking: (info
"(emacs)Isearch Yank"))
E
>
> --
> __Pascal Bourguignon__
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
[not found] ` <mailman.5145.1250957330.2239.help-gnu-emacs@gnu.org>
@ 2009-08-22 17:07 ` lichtkind
0 siblings, 0 replies; 9+ messages in thread
From: lichtkind @ 2009-08-22 17:07 UTC (permalink / raw)
To: help-gnu-emacs
I use Version 22.3
M-w C-s M-y is a little bit strange, but works.
I will take a look at Lazy Search, too.
Thank you.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
@ 2009-08-23 10:16 Kada Situ
2009-08-23 16:41 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Kada Situ @ 2009-08-23 10:16 UTC (permalink / raw)
To: lichtkind3; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 4474 bytes --]
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)
[-- Attachment #2: Type: text/html, Size: 5203 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: automatic search/search and replace for a marked string
2009-08-23 10:16 Kada Situ
@ 2009-08-23 16:41 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2009-08-23 16:41 UTC (permalink / raw)
To: 'Kada Situ', lichtkind3; +Cc: help-gnu-emacs
> there is a searching feature in UltraEdit that I want it so bad in emacs.
Your wish has been granted.
> you highlight some text, and press F3, it will automatically do the
> search of the lighlighted text for you.
1. Select the text.
2. `C-s' or `C-r' (isearch forward or backward)
3. `M-y' (copy the selected text as the search text
4. `C-s' or `C-r' (isearch forward or backward)
The Emacs manual is your friend. See node `Isearch Yank'.
(You can of course bind `F3' and `S-F3' in place of, or in addition to, `C-s'
and `C-r', if you really want those keys.)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: automatic search/search and replace for a marked string
2009-08-22 11:07 automatic search/search and replace for a marked string lichtkind
2009-08-22 13:58 ` Xah Lee
2009-08-22 14:27 ` Pascal J. Bourguignon
@ 2009-08-23 22:05 ` A.Politz
2 siblings, 0 replies; 9+ messages in thread
From: A.Politz @ 2009-08-23 22:05 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 22, 1:07 pm, lichtkind <lichtki...@web.de> wrote:
> Hello,
>
> I have marked a string. Now I want to search for this string in the
> whole text. I know that I can search with C-R or C-S. and type in the
> searchstring. I'm looking for a way, that the marked string is
> automatic the searchstring. This should also work for the other
> search/ search and replace types.
>
> Regards
> lichtkind
As for isearch.
(defun isearch-yank-region ()
(interactive)
(when (and transient-mark-mode mark-active)
(deactivate-mark)
(isearch-yank-string
(buffer-substring-no-properties
(region-beginning)
(region-end)))))
From here you have 3 choices.
1. Make the region the default search string
(add-hook 'isearch-mode-hook
#'(lambda nil
(isearch-update)
(isearch-yank-region)))
2. Define a key to yank the region as a search string
(define-key isearch-mode-map (kbd "M-w") 'isearch-yank-region)
3. Define new special purpose commands.
(defun isearch-region-forward (regexp-flag)
(interactive "P")
(let ((isearch-mode-hook isearch-mode-hook))
(add-hook 'isearch-mode-hook 'isearch-yank-region)
(isearch-forward regexp-flag)))
As for the other commands, like query-replace etc. They already
use the region as a way to determine the part of the buffer to
operate on...
-ap
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-08-23 22:05 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-22 11:07 automatic search/search and replace for a marked string lichtkind
2009-08-22 13:58 ` Xah Lee
2009-08-22 14:27 ` Pascal J. Bourguignon
2009-08-22 15:12 ` Andy Stewart
2009-08-22 15:14 ` Eric Abrahamsen
[not found] ` <mailman.5145.1250957330.2239.help-gnu-emacs@gnu.org>
2009-08-22 17:07 ` lichtkind
2009-08-23 22:05 ` A.Politz
-- strict thread matches above, loose matches on Subject: below --
2009-08-23 10:16 Kada Situ
2009-08-23 16:41 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).