Skip to content

Commit

Permalink
nvim_add_user_command() now supports <f-args>
Browse files Browse the repository at this point in the history
  • Loading branch information
hituzi-no-sippo committed Mar 14, 2022
1 parent 41316a9 commit e77935d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 115 deletions.
26 changes: 0 additions & 26 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -1047,32 +1047,6 @@ vim.api.nvim_buf_del_user_command(4, 'Upper')

#### 警告

`<args>``<f-args>`のエスケープシーケンスはLua関数で使用できず、`args`キーは常にコマンドに渡される引数を含む文字列です。各引数を個別に取得する場合、文字列を手動でトークン化しないといけません。`<f-args>`の動作は`-narg`属性によって微妙に変化することを、気に留めておいてください。

```vim
command! -nargs=1 Test1 echo [<f-args>]
command! -nargs=* Test2 echo [<f-args>]
Test1 this is a\ test
" prints `['this is a\ test']`
Test2 this is a\ test
" prints `['this', 'is', 'a test']`
```

`:Test1` コマンドは入力した内容をそのまま表示します。`:Test2`は単語で区切り、バックスラッシュ`\`で始まるとき以外、空白を除去します。

Lua関数を使用したときは、`nargs`属性は`args`の値を変更しません:
```lua
vim.api.nvim_add_user_command('Test1', function(opts) print(opts.args) end, { nargs = 1 })
vim.api.nvim_add_user_command('Test2', function(opts) print(opts.args) end, { nargs = '*' })
```
```vim
Test1 this is a\ test
" prints `this is a\ test`
Test2 this is a\ test
" prints `this is a\ test`
```

`-complete=custom`属性は自動的に補完候補をフィルタリングし、ワイルドカード([`:help wildcard`](https://neovim.io/doc/user/editing.html#wildcard))をサポートする機能を組み込みます:

```vim
Expand Down
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1025,31 +1025,6 @@ See also:

### Caveats

The `<args>` and `<f-args>` escape sequences are not available when using a Lua function, the `args` key is always a string containing the arguments passed to the command. If you need to get each argument separately, the string has to be tokenized manually. Keep in mind that the behavior of `<f-args>` is subtly different depending on the `-nargs` attribute.

```vim
command! -nargs=1 Test1 echo [<f-args>]
command! -nargs=* Test2 echo [<f-args>]
Test1 this is a\ test
" prints `['this is a\ test']`
Test2 this is a\ test
" prints `['this', 'is', 'a test']`
```
The `:Test1` command prints what was typed verbatim. `:Test2` separates each word and gets rid of whitespace except when preceded by a backslash `\`.

When using a Lua function, the `nargs` attribute does not change the value of `args`:
```lua
vim.api.nvim_add_user_command('Test1', function(opts) print(opts.args) end, { nargs = 1 })
vim.api.nvim_add_user_command('Test2', function(opts) print(opts.args) end, { nargs = '*' })
```
```vim
Test1 this is a\ test
" prints `this is a\ test`
Test2 this is a\ test
" prints `this is a\ test`
```

The `-complete=custom` attribute automatically filters completion candidates and has built-in wildcard ([`:help wildcard`](https://neovim.io/doc/user/editing.html#wildcard)) support:

```vim
Expand Down
30 changes: 0 additions & 30 deletions doc/nvim-lua-guide.jax
Original file line number Diff line number Diff line change
Expand Up @@ -1169,36 +1169,6 @@ Neovimはユーザーコマンドを作成するAPI関数を提供します。

警告~

`<args>``<f-args>`のエスケープシーケンスはLua関数で使用できず、`args`キーは常にコマンドに渡される引数を含む文字列です。
各引数を個別に取得する場合、文字列を手動でトークン化しないといけません。
`<f-args>`の動作は`-narg`属性によって微妙に変化することを、気に留めておいてください。

>
command! -nargs=1 Test1 echo [<f-args>]
command! -nargs=* Test2 echo [<f-args>]
Test1 this is a\ test
" prints `['this is a\ test']`
Test2 this is a\ test
" prints `['this', 'is', 'a test']`
<
`:Test1` コマンドは入力した内容をそのまま表示します。
`:Test2`は単語で区切り、バックスラッシュ`\`で始まるとき以外、空白を除去します。

Lua関数を使用したときは、`nargs`属性は`args`の値を変更しません:
>
vim.api.nvim_add_user_command('Test1', function(opts) print(opts.args)
end, { nargs = 1 })
vim.api.nvim_add_user_command('Test2', function(opts) print(opts.args)
end, { nargs = '*' })
<
>
Test1 this is a\ test
" prints `this is a\ test`
Test2 this is a\ test
" prints `this is a\ test`
<

`-complete=custom`属性は自動的に補完候補をフィルタリングし、
ワイルドカード(|wildcard|)をサポートする機能を組み込みます:

Expand Down
34 changes: 0 additions & 34 deletions doc/nvim-lua-guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1239,40 +1239,6 @@ See also:

Caveats~

The `<args>` and `<f-args>` escape sequences are not available when using
a Lua function, the `args` key is always a string containing the arguments
passed to the command. If you need to get each argument separately, the
string has to be tokenized manually. Keep in mind that the behavior of
`<f-args>` is subtly different depending on the `-nargs` attribute.

>
command! -nargs=1 Test1 echo [<f-args>]
command! -nargs=* Test2 echo [<f-args>]
Test1 this is a\ test
" prints `['this is a\ test']`
Test2 this is a\ test
" prints `['this', 'is', 'a test']`
<
The `:Test1` command prints what was typed verbatim. `:Test2` separates
each word and gets rid of whitespace except when preceded by a backslash
`\`.

When using a Lua function, the `nargs` attribute does not change the
value of `args`:
>
vim.api.nvim_add_user_command('Test1', function(opts) print(opts.args)
end, { nargs = 1 })
vim.api.nvim_add_user_command('Test2', function(opts) print(opts.args)
end, { nargs = '*' })
<
>
Test1 this is a\ test
" prints `this is a\ test`
Test2 this is a\ test
" prints `this is a\ test`
<

The `-complete=custom` attribute automatically filters completion
candidates and has built-in wildcard (|wildcard| support:

Expand Down

0 comments on commit e77935d

Please sign in to comment.