If you use library Icicles then you can easily do this kind of thing. What you are asking for (if I understand correctly), is to search only within certain search contexts.
For example, as in this case, you might want to search only within function definitions - the search contexts are function definitions. In Lisp, this would be things like defun
s.
Icicles has several predefined Icicles search commands for searching definitions like this. These are collectively called Icicles Imenu commands.
To search only command definitions, you can use command icicle-imenu-command-full
. To search only non-interactive function definitions, use command icicle-imenu-non-interactive-function-full
.
Beyond searching definitions, you can easily define any kind of contexts to be searched. The simplest way is by providing a regexp. Command icicle-search
prompts you for the search context-defining regexp. You can alternatively use a function to define the search contexts.
Other possibilities include:
Searching the text of different kinds of THINGs (e.g., sexps, sentences, lists,
strings, comments, XML elements,...), i.e., ignoring other text outside the THINGs.
Searching zones of text that have given text or overlay properties, i.e., ignoring other text.
NOTE:
Other answers here that mention occur
and similar (helm-occur
) provide a limited kind of context searching: the search contexts are just the lines of a buffer.
That is much more limited that, say, searching within whole function definitions, which is what I think you are asking for. With Icicles, command icicle-occur
(bound to C-c '
) lets you search within lines as search contexts.
helm-swoop
, but your question (and especially the title) is not very clear on this. Maybe I just didn't get your question because I'm not familiar with helm.imenu
worked great for me! Except I search for a generic solution to my question