Issue #249 resolved

% (evil-jump-item) doesn't work correctly when inside quoted string and parentheses

Michael Chen
created an issue

When cursor ([C]) is in a quoted string inside parentheses such as: printf("exam[C]ple"), % should jump to the first parenthesis, but instead doesn't match anything in the line. Normal vim behavior should be to jump to the parentheses.

Comments (6)

  1. Frank Fischer repo owner
    • changed status to open

    I can't reproduce that.

    Please provide a minimal example starting with make emacs in evil's source. In this case, please provide a minimal test-file, too, because evil-jump-item depends on the concrete syntax-table of the major-mode being used.

  2. Michael Chen reporter
    make emacs
    i // insert mode
    printf("hello"); // write function with quoted argument
    <esc> // normal mode
    b // back to 2nd quote
    % // should find starting parenthesis, finds nothing instead

    This example will be in fundamental mode but it happens in c-mode as well. Using GNU Emacs 24.2.1 and evil 1.0.0.

  3. Frank Fischer repo owner

    Make evil-jump-item jump out of a string if appropriate.

    evil-jump-item is syntax sensitive: if (point) is not in a string/comment only the string/comment content is considered, if (point) is not in a string or comment, strings and comments are skipped.

    In one situation this may not be desired: if (point) is within a string but no jump-target is found within the string. Then the old behavior would not move (point) at all. This is a common case in programming modes, e.g.

    printf("some text");

    If point is within the string literal, then evil-jump-point should move to the opening parenthesis.

    The new behavior of evil-jump-item is now to look after the end of the string as if it has been called right after the end of string, if no appropriate jump target could be found within the string.

    This addresses issue #249.

    → <<cset e589510516da>>

  4. Frank Fischer repo owner

    Ah, now I understand the problem, I interpreted the issue wrong the first time ;)

    Note that % is still not the same as in evil, although your use case should work. The reason is that Evil's % is syntax-aware, i.e. if point is not in a string, strings are completely ignored and vice versa.

    For example if you have

    func(par1, "some string with ) parenthesis")

    and point is on the 1, then Vim would do nothing on % but Evil jumps to the open parenthesis because it ignores the string. This is a "feature" of Emacs/Evil.

  5. Log in to comment