TransWikia.com

icicles search and replace; need help to do a successfull replace

Emacs Asked by space_held on December 16, 2021

I try to use Icicles to search and replace. I understand to search with it (some details, that I need), but I’m unable to do a replace.
The link below shows a recipe, that I try to follow, but it doesn’t seem to work.

Question on stackoverflow

Here is a recipe to do a search and replace:

this is text1
this is text2
and this is text3

I want to search for the string text and replace it with othertext.

Set option replacing whole search context to nil in my config.

Here we go:

  1. Initiate Icicles search: Menu: Edit-Search-Icicles-Search(regexp) or M-s M-s M-s
  2. Type text
  3. S-TAB and see the contexts
  4. C-down to first candidate. I do not want to narrow further on.
  5. Minibuffer shows choose an occurrence: text. Cursor in the minibuffer is at the end of text .
  6. I press S-RET. Nothing happens… no prompt.

Unfortunately that’s it. What is wrong?

One Answer

The key to use is C-S-RET, not S-RET. That's Control with Shift and Return.

And you do want to replace the whole context, if your context is text. So option icicle-search-replace-whole-candidate-flag should be non-nil.


I think that answers your question, but here is some more info, in case it helps.

There are of course other ways to perform the simple replacement described. Perhaps you narrowed down a more elaborate problem to this example, which gets to the heart of the problem you were having. But if not, let me point out two things:

  1. Icicles search helps even in this simple case, if you just want to replace certain occurrences, on demand, rather than being queried for each occurrence. That's really the only advantage it offers for such a simple case.

    And even for that there are other ways -- for example, if you use library Isearch+ then you can replace specific matches, on demand, using C-M-RET.

  2. Icicles search is especially for searching and replacing within defined contexts, not just replacing entire regexp matches.

    For example, you might want to search only for occurrences of text within matches for regexp is (text)[^ ]+. In that case you'd provide that regexp and the number 1, to define the context as matches for the first subgroup, which is (text). You'd then proceed the same way as for your example. That would exclude other occurrences of text.

    Even more generally, you might want to define the context that way, but then search for some text within matches for the context, e.g., search for xt within the matches for text within the matches for is (text)[^ ]+.

    In that case, you'd define the contexts the same way, but then use xt as your minibuffer input, to, first, filter to only contexts that contain xt (which doesn't do any filtering, in this case, since all matches for the context regexp contain xt), and second, replace particular such occurrences of xt.

    To replace only matches for your minibuffer input (e.g. only the xt in this case), you need to turn off option icicle-search-replace-whole-candidate-flag, because you don't want to replace the entire search context, but just the part that matches your input. You can toggle the option value anytime during search using M-_.


See Icicles - Search And Replace for more info.

Answered by Drew on December 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP