mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.91k stars 714 forks source link

improve `m` command to skip non matching characters #1149

Open alexherbo2 opened 7 years ago

alexherbo2 commented 7 years ago

Example:

function = argument => {
  …
}

Skipping non matching characters (>) would allow to select { … } block on declaration.

Delapouite commented 7 years ago

Not really related but I managed to get around this meaningful selection pattern in JavaScript with the following plugin: https://github.com/Delapouite/kakoune-grasp

For example for lambdas you can use grasp s arrow, or be more precise with grasp s arrow.body or grasp s arrow.params

mawww commented 6 years ago

Not really what was asked here, but matching characters are now controlled by the matching_pairs option, so javascript.kak could tweak this not to treat < and > as matching pairs.

andreyorst commented 5 years ago

There's more broken case ( is a cursor):

█
(
    case ${var} in
        a) echo "a!" ;;
        *) ;;
    esac
) > ${file}

Pressing m on the first opening ( will bring us to correct file position, but not semantically correct code point:

[(
     case ${var} in
         a)] echo "a!" ;;
         *) ;;
     esac
 ) > ${file}

Semantically correct selection would be:

[(
     case ${var} in
         a) echo "a!" ;;
         *) ;;
     esac
 )] > ${file}

Also, broken Rust example:

fn main() {
    if a < b {
        println!("a");
    }
}

fn some_function(a: i32)█-> i32 {
    a
}

pressing m will result into:

fn main() {
    if a [< b {
        println!("a");
    }
}

fn some_function(a: i32) ->] i32 {
    a
}

instead of semantically correct:

fn main() {
    if a < b {
        println!("a");
    }
}

fn some_function(a: i32) -> i32 [{
    a
}]

Though this case could be handled by adjusting matching_pairs