Top search in emacs with scope extension

Suppose we have the following text:

(print "thIis-is-a-text") 

and the cursor is in the word "this", which is between char 'h' and 'i'.

In emacs, if I type Cs Cw , the text to search for is 'is',

again Cw is 'is-is',

again Cw is 'is-is-a',

again Cw is 'is-is-a-text',

again Cw is "is-is-a-text" "...

And there is the emacs expand region plugin: "The spread area increases the selected area with semantic units. Just keep pressing the key until it selects what you want."

So, I want to make Cs Cw smarter: combine with an extension scope.

The cursor between char 'h' and 'i' in the word 'this' again, my goal:

when I type Cs Cw , the word 'this' will be the search text,

again will be "this-is-a-text",

again will be "this-is-a-text",

will print this-is-a-text "" again,

will be 'again (type "this-is-a-text")',

.... (behaves like an expansion area, maybe this is not a good example ...)

As I sometimes find, expanding an area is very useful in finding texts, I hope someone can write some codes to achieve this for me, since I'm new to emacs and elisp. Thank you, please forgive my broken English! :)

+4
source share
2 answers

There's a very simple package called thingopt that uses thingatpt to do something similar to an extension area. I used the modified version for a long time, which adds support for isearch. This question reminded me of a fork and put up a pull request. My init.el has the following:

 (define-key isearch-mode-map (kbd "CSs") 'upward-isearch-thing) (define-key isearch-mode-map (kbd "M-3") 'upward-isearch-thing) (global-set-key (kbd "CSs") 'upward-mark-thing) (global-set-key (kbd "M-3") 'upward-mark-thing) (setq upward-mark-thing-list '(email url word symbol string (up-list . *) paragraph )) 

I tried the extension area and I think I will like it, but it looks a lot more complicated and I have to add isearch support before I start using it. I hope I (or someone else) someday come to him.

+3
source
 (defadvice isearch-yank-word-or-char (before move-to-beginning-of-word) (unless (eq last-command this-command) (goto-char (car (bounds-of-thing-at-point 'word))))) (ad-activate 'isearch-yank-word-or-char) 
+1
source

All Articles