2

Is there a command that will jump cursor to other iteration of the variable or function name under the cursor?

I suppose it wouldn't matter if the text is specifically a variable or function, but just another iteration of the same text.

For example, if I have foobar under my cursor can I jump to the next foobar in the file?

1

1 Answer 1

3

Different modes (e.g. languages) have different notions of variables and functions, so finding them can be mode-specific.

  1. A general answer, which lets you move forward among occurrences of the name at the cursor, is to use C-s followed by successive C-w to pick up the name at point, then repeated C-s to move to successive occurrences of the name.

    That picks up the name starting at the cursor. If the cursor is in the middle of the name it may still be enough to distinguish the occurrences. If not, before using it move the cursor back to the name beginning.

    This just searches for a name. It does not distinguish whether that name represents a function or a variable or something else.

  2. If you use library isearch+.el then you can use C-_ instead of C-w. That picks up symbols instead of words, for the search string.

  3. For Emacs-Lisp functions and variables: If you use library hl-defined.el then you can use command hdefd-highlight-mode to highlight all Lisp functions and variables (or just one or the other).

    If you also use library isearch-prop.el then you can use command isearchp-property-forward to search among zones of a given text (or overlay) property, including property face.

    This means you can use it to move among the function and variable occurrences highlighted by hdefd-highlight-mode. You just tell isearchp-property-forward that the property you want to search is face and the faces you want to search are hdefd-functions and hdefd-variables (or just one or the other).

    Example:

    M-x hdefd-highlight-mode      ; Turn on function & variable highlighting.
    
    M-x isearchp-property-forward RET RET hdefd-functions RET hdefd-variables RET RET
    

    This prompts you for whether to search text properties or overlay properties, or both. Both is the default, so just hit RET.

    Then it prompts you for the property. face is the default, so just hit RET.

    Then it prompts you for a face. Enter hdefd-functions. It prompts you again for a face -- enter hdefd-variables. It prompts you again for a face -- just hit RET without typing another face name.

    You are now searching within the highlighted function and variable occurrences. Just type a few characters that match a function or variable name, and you move to its occurrences (by repeating C-s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.