yegappan / fileselect

File Selector Vim Plugin
BSD 2-Clause "Simplified" License
18 stars 2 forks source link

Use new lambda syntax. Respect whitespace rule in sublists. #15

Closed lacygoill closed 3 years ago

lacygoill commented 3 years ago

This PR updates the plugin so that it works on newer Vim versions.

Since 8.2.2257, we can no longer use the old syntax for lambdas:

{args -> expr}

We must use the new one:

(args) => expr

Since 8.2.2250, we must add whitespace around a colon in a sublist. See this issue for the rationale.

So, this no longer works:

var l = [1, 2, 3, 4, 5]
echo l[1:3]
       ^^^
        ✘

Instead, we must write:

echo l[1 : 3]
        ^^^
         ✔

Note that there is still no need to write a whitespace between the colon and a bracket. So, these work:

echo l[: 3]
      ^^
      ✔

echo l[1 :]
         ^^
         ✔

I also added some type checking for the used arguments of the lambdas, and for their returned value. This is possible since 8.2.1956.

I haven't type checked the unused arguments of the lambdas (_), but maybe you'll want to do it.


I replaced double quotes with single quotes whenever possible; to gain in consistency, and to code defensively (i.e. it suppresses special characters translation which could appear in a future refactoring).


I removed an unnecessary v: prefix in a v:true value.


Finally, I removed unnecessary quotes around a bufnr key. It was necessary in the past, because of a bug which was fixed in 8.2.2200. However, the issue re-appeared in 8.2.2227. The latter issue was fixed in 8.2.2257.

Note that 8.2.2257 is not the minimal version for the plugin to work. A different bug broke the plugin in 8.2.2254. The latter was fixed in 8.2.2261.

To summarize, the absolute minimum Vim version required for the plugin to work once the patch is applied should be 8.2.2261. I tested on 8.2.2269, and it seems to work.

lacygoill commented 3 years ago

Since 8.2.2257, we can no longer use the old syntax for lambdas:

{args -> expr}

We must use the new one:

(args) => expr

I forgot to mention that if expr is a dictionary, it needs to be surrounded with parentheses:

(args) => ({dict})
          ^      ^

This is to avoid an ambiguity with another syntax (which has yet to be implemented):

(args) => {Ex commands}

Note that all these new syntaxes (() => expr, () => ({dict}), () => {statements}) are directly inspired from JavaScript.