Merge branch 'master' into add_Chiese_version

pull/106/head
Samuel 2 years ago committed by GitHub
commit af2532be7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -648,15 +648,15 @@ print(vim.api.nvim_buf_get_option(10, 'shiftwidth')) -- 4
A few meta-accessors are available if you want to set options in a more "idiomatic" way. They essentially wrap the above API functions and allow you to manipulate options as if they were variables: A few meta-accessors are available if you want to set options in a more "idiomatic" way. They essentially wrap the above API functions and allow you to manipulate options as if they were variables:
- [`vim.o`](https://neovim.io/doc/user/lua.html#vim.o): behaves like `:set` - [`vim.o`](https://neovim.io/doc/user/lua.html#vim.o): behaves like `:let &{option-name}`
- [`vim.go`](https://neovim.io/doc/user/lua.html#vim.go): behaves like `:setglobal` - [`vim.go`](https://neovim.io/doc/user/lua.html#vim.go): behaves like `:let &g:{option-name}`
- [`vim.bo`](https://neovim.io/doc/user/lua.html#vim.bo): behaves like `:setlocal` for buffer-local options - [`vim.bo`](https://neovim.io/doc/user/lua.html#vim.bo): behaves like `:let &l:{option-name}` for buffer-local options
- [`vim.wo`](https://neovim.io/doc/user/lua.html#vim.wo): behaves like `:setlocal` for window-local options - [`vim.wo`](https://neovim.io/doc/user/lua.html#vim.wo): behaves like `:let &l:{option-name}` for window-local options
```lua ```lua
vim.o.smarttab = false vim.o.smarttab = false -- let &smarttab = v:false
print(vim.o.smarttab) -- false print(vim.o.smarttab) -- false
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: set isfname+=@-@ vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname = &isfname .. ',@-@'
print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@' print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'
vim.bo.shiftwidth = 4 vim.bo.shiftwidth = 4
@ -959,13 +959,14 @@ vim.api.nvim_buf_del_keymap(0, 'i', '<Tab>')
Neovim provides API functions for user-defined commands: Neovim provides API functions for user-defined commands:
- Global user commands: - Global user commands:
- [`vim.api.nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>) - [`vim.api.nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>)
- [`vim.api.nvim_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_del_user_command()>) - [`vim.api.nvim_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_del_user_command()>)
- Buffer-local user commands: - Buffer-local user commands:
- [`vim.api.nvim_buf_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_add_user_command()>) - [`vim.api.nvim_buf_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_add_user_command()>)
- [`vim.api.nvim_buf_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_del_user_command()>) - [`vim.api.nvim_buf_del_user_command()`](<https://neovim.io/doc/user/api.html#nvim_buf_del_user_command()>)
Let's start with `vim.api.nvim_add_user_command()` Let's start with `vim.api.nvim_create_user_command()`
The first argument passed to this function is the name of the command (which must start with an uppercase letter). The first argument passed to this function is the name of the command (which must start with an uppercase letter).
@ -974,7 +975,7 @@ The second argument is the code to execute when invoking said command. It can ei
A string (in which case it will be executed as Vimscript). You can use escape sequences like `<q-args>`, `<range>`, etc. like you would with `:command` A string (in which case it will be executed as Vimscript). You can use escape sequences like `<q-args>`, `<range>`, etc. like you would with `:command`
```lua ```lua
vim.api.nvim_add_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 }) vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)', { nargs = 1 })
-- :command! -nargs=1 Upper echo toupper(<q-args>) -- :command! -nargs=1 Upper echo toupper(<q-args>)
vim.cmd('Upper hello world') -- prints "HELLO WORLD" vim.cmd('Upper hello world') -- prints "HELLO WORLD"
@ -983,7 +984,7 @@ vim.cmd('Upper hello world') -- prints "HELLO WORLD"
Or a Lua function. It receives a dictionary-like table that contains the data normally provided by escape sequences (see [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>) for a list of available keys) Or a Lua function. It receives a dictionary-like table that contains the data normally provided by escape sequences (see [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>) for a list of available keys)
```lua ```lua
vim.api.nvim_add_user_command( vim.api.nvim_create_user_command(
'Upper', 'Upper',
function(opts) function(opts)
print(string.upper(opts.args)) print(string.upper(opts.args))
@ -992,7 +993,7 @@ vim.api.nvim_add_user_command(
) )
``` ```
The third argument lets you pass command attributes as a table (see [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)). Since you can already define buffer-local user commands with `vim.api.nvim_buf_add_user_command()`, `-buffer` is not a valid attribute. The third argument lets you pass command attributes as a table (see [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)). Since you can already define buffer-local user commands with `vim.api.nvim_buf_create_user_command()`, `-buffer` is not a valid attribute.
Two additional attributes are available: Two additional attributes are available:
@ -1002,7 +1003,7 @@ Two additional attributes are available:
The `-complete` attribute can take a Lua function in addition to the attributes listed in [`:help :command-complete`](https://neovim.io/doc/user/map.html#:command-complete). The `-complete` attribute can take a Lua function in addition to the attributes listed in [`:help :command-complete`](https://neovim.io/doc/user/map.html#:command-complete).
```lua ```lua
vim.api.nvim_add_user_command('Upper', function() end, { vim.api.nvim_create_user_command('Upper', function() end, {
nargs = 1, nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos) complete = function(ArgLead, CmdLine, CursorPos)
-- return completion candidates as a list-like table -- return completion candidates as a list-like table
@ -1014,7 +1015,7 @@ vim.api.nvim_add_user_command('Upper', function() end, {
Buffer-local user commands also take a buffer number as their first argument. This is an advantage over `-buffer` which can only define a command for the current buffer. Buffer-local user commands also take a buffer number as their first argument. This is an advantage over `-buffer` which can only define a command for the current buffer.
```lua ```lua
vim.api.nvim_buf_add_user_command(4, 'Upper', function() end, {}) vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})
``` ```
`vim.api.nvim_del_user_command()` takes a command name. `vim.api.nvim_del_user_command()` takes a command name.
@ -1033,8 +1034,6 @@ vim.api.nvim_buf_del_user_command(4, 'Upper')
See also: See also:
- [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>) - [`:help nvim_add_user_command()`](<https://neovim.io/doc/user/api.html#nvim_add_user_command()>)
- [`:help 40.2`](https://neovim.io/doc/user/usr_40.html#40.2)
- [`:help command-attributes`](https://neovim.io/doc/user/map.html#command-attributes)
### Caveats ### Caveats
@ -1056,7 +1055,7 @@ command! -nargs=1 -complete=custom,s:completion_function Test echo <q-args>
Passing a Lua function to `complete` makes it behave like `customlist` which leaves filtering up to the user: Passing a Lua function to `complete` makes it behave like `customlist` which leaves filtering up to the user:
```lua ```lua
vim.api.nvim_add_user_command('Test', function() end, { vim.api.nvim_create_user_command('Test', function() end, {
nargs = 1, nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos) complete = function(ArgLead, CmdLine, CursorPos)
return { return {
@ -1297,10 +1296,13 @@ Probably one of the most well-known transpilers for Lua. Adds a lots of convenie
A lisp that compiles to Lua. You can write configuration and plugins for Neovim in Fennel with the [Olical/aniseed](https://github.com/Olical/aniseed) or the [Hotpot](https://github.com/rktjmp/hotpot.nvim) plugin. Additionally, the [Olical/conjure](https://github.com/Olical/conjure) plugin provides an interactive development environment that supports Fennel (among other languages). A lisp that compiles to Lua. You can write configuration and plugins for Neovim in Fennel with the [Olical/aniseed](https://github.com/Olical/aniseed) or the [Hotpot](https://github.com/rktjmp/hotpot.nvim) plugin. Additionally, the [Olical/conjure](https://github.com/Olical/conjure) plugin provides an interactive development environment that supports Fennel (among other languages).
- [Teal](https://github.com/teal-language/tl)
The name Teal comes from pronouncing TL (typed lua). This is exactly what it tries to do - add strong typing to lua while otherwise remaining close to standard lua syntax. The [nvim-teal-maker](https://github.com/svermeulen/nvim-teal-maker) plugin can be used to write Neovim plugins or configuration files directly in Teal
Other interesting projects: Other interesting projects:
- [TypeScriptToLua/TypeScriptToLua](https://github.com/TypeScriptToLua/TypeScriptToLua) - [TypeScriptToLua/TypeScriptToLua](https://github.com/TypeScriptToLua/TypeScriptToLua)
- [teal-language/tl](https://github.com/teal-language/tl)
- [Haxe](https://haxe.org/) - [Haxe](https://haxe.org/)
- [SwadicalRag/wasm2lua](https://github.com/SwadicalRag/wasm2lua) - [SwadicalRag/wasm2lua](https://github.com/SwadicalRag/wasm2lua)
- [hengestone/lua-languages](https://github.com/hengestone/lua-languages) - [hengestone/lua-languages](https://github.com/hengestone/lua-languages)

@ -778,15 +778,16 @@ A few meta-accessors are available if you want to set options in a more
"idiomatic" way. They essentially wrap the above API functions and allow "idiomatic" way. They essentially wrap the above API functions and allow
you to manipulate options as if they were variables: you to manipulate options as if they were variables:
- |vim.o|: behaves like `:set` - |vim.o|: behaves like `:let &{option-name}`
- |vim.go|: behaves like `:setglobal` - |vim.go|: behaves like `:let &g:{option-name}`
- |vim.bo|: behaves like `:setlocal` for buffer-local options - |vim.bo|: behaves like `:let &l:{option-name}` for buffer-local options
- |vim.wo|: behaves like `:setlocal` for window-local options - |vim.wo|: behaves like `:let &l:{option-name}` for window-local options
> >
vim.o.smarttab = false vim.o.smarttab = false -- let &smarttab = v:false
print(vim.o.smarttab) -- false print(vim.o.smarttab) -- false
vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: set isfname+=@-@ vim.o.isfname = vim.o.isfname .. ',@-@' -- on Linux: let &isfname =
&isfname .. ',@-@'
print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@' print(vim.o.isfname) -- '@,48-57,/,.,-,_,+,,,#,$,%,~,=,@-@'
vim.bo.shiftwidth = 4 vim.bo.shiftwidth = 4
@ -1150,13 +1151,13 @@ in Neovim 0.7.0+
Neovim provides API functions for user-defined commands: Neovim provides API functions for user-defined commands:
- Global user commands: - Global user commands:
- |nvim_add_user_command()| - |nvim_create_user_command()|
- |nvim_del_user_command()| - |nvim_del_user_command()|
- Buffer-local user commands: - Buffer-local user commands:
- |nvim_buf_add_user_command()| - |nvim_buf_create_user_command()|
- |nvim_buf_del_user_command()| - |nvim_buf_del_user_command()|
Let's start with `vim.api.nvim_add_user_command()` Let's start with `vim.api.nvim_create_user_command()`
The first argument passed to this function is the name of the command The first argument passed to this function is the name of the command
(which must start with an uppercase letter). (which must start with an uppercase letter).
@ -1168,17 +1169,18 @@ A string (in which case it will be executed as Vimscript). You can use
escape sequences like `<q-args>`, `<range>`, etc. like you would with escape sequences like `<q-args>`, `<range>`, etc. like you would with
`:command` `:command`
> >
vim.api.nvim_add_user_command('Upper', 'echo toupper(<q-args>)', { vim.api.nvim_create_user_command('Upper', 'echo toupper(<q-args>)',
nargs = 1 }) { nargs = 1 })
-- :command! -nargs=1 Upper echo toupper(<q-args>) -- :command! -nargs=1 Upper echo toupper(<q-args>)
vim.cmd('Upper hello world') -- prints "HELLO WORLD" vim.cmd('Upper hello world') -- prints "HELLO WORLD"
< <
Or a Lua function. It receives a dictionary-like table that contains the Or a Lua function. It receives a dictionary-like table that
data normally provided by escape sequences (see |nvim_add_user_command()| contains the data normally provided by escape sequences (see
|nvim_create_user_command()|
> >
vim.api.nvim_add_user_command( vim.api.nvim_create_user_command(
'Upper', 'Upper',
function(opts) function(opts)
print(string.upper(opts.args)) print(string.upper(opts.args))
@ -1188,7 +1190,8 @@ data normally provided by escape sequences (see |nvim_add_user_command()|
< <
The third argument lets you pass command attributes as a table (see The third argument lets you pass command attributes as a table (see
|command-attributes|, `-buffer` is not a valid attribute. |command-attributes|`. Since you can already define buffer-local user commands
with |nvim_buf_create_user_command()|, `-buffer` is not a valid attribute.
Two additional attributes are available: Two additional attributes are available:
- `desc` allows you to control what gets displayed when you run `:command - `desc` allows you to control what gets displayed when you run `:command
@ -1201,7 +1204,7 @@ The `-complete` attribute can take a Lua function in addition to the
attributes listed in |:command-complete|. attributes listed in |:command-complete|.
> >
vim.api.nvim_add_user_command('Upper', function() end, { vim.api.nvim_create_user_command('Upper', function() end, {
nargs = 1, nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos) complete = function(ArgLead, CmdLine, CursorPos)
-- return completion candidates as a list-like table -- return completion candidates as a list-like table
@ -1215,7 +1218,7 @@ argument. This is an advantage over `-buffer` which can only define a
command for the current buffer. command for the current buffer.
> >
vim.api.nvim_buf_add_user_command(4, 'Upper', function() end, {}) vim.api.nvim_buf_create_user_command(4, 'Upper', function() end, {})
< <
`vim.api.nvim_del_user_command()` takes a command name. `vim.api.nvim_del_user_command()` takes a command name.
@ -1233,7 +1236,7 @@ its first argument, with `0` representing the current buffer.
< <
See also: See also:
- |nvim_add_user_command()| - |nvim_create_user_command()|
- |40.2| - |40.2|
- |command-attributes| - |command-attributes|
@ -1260,7 +1263,7 @@ Passing a Lua function to `complete` makes it behave like `customlist`
which leaves filtering up to the user: which leaves filtering up to the user:
> >
vim.api.nvim_add_user_command('Test', function() end, { vim.api.nvim_create_user_command('Test', function() end, {
nargs = 1, nargs = 1,
complete = function(ArgLead, CmdLine, CursorPos) complete = function(ArgLead, CmdLine, CursorPos)
return { return {
@ -1279,27 +1282,25 @@ which leaves filtering up to the user:
DEFINING AUTOCOMMANDS DEFINING AUTOCOMMANDS
*luaguide-defining-autocommands* *luaguide-defining-autocommands*
Augroups and autocommands do not have an interface yet but it is being (this section is a work in progress)
worked on:
Neovim 0.7.0 has API functions for autocommands. See `:help api-autocmd`
for details
- Pull request #12378: https://github.com/neovim/neovim/pull/12378
- Pull request #14661: https://github.com/neovim/neovim/pull/14661 lua: - Pull request #14661: https://github.com/neovim/neovim/pull/14661 lua:
autocmds take 2 autocmds take 2
In the meantime, you can either create autocommands in
Vimscript or use this wrapper from norcalli/nvim_utils:
https://github.com/norcalli/nvim_utils/blob/master/lua/nvim_utils.lua#L554-L567
============================================================================== ==============================================================================
DEFINING SYNTAX/HIGHLIGHTS DEFINING HIGHLIGHTS
*luaguide-defining-syntax-highlights* *luaguide-defining-highlights*
The syntax API is still a work in progress. Here are a couple of pointers: (this section is a work in progress)
- Issue #9876: https://github.com/neovim/neovim/issues/9876 Neovim 0.7.0 has API functions for highlight groups. See also:
- tjdevries/colorbuddy.vim, a library for creating colorschemes in Lua:
https://github.com/tjdevries/colorbuddy.vim - |nvim_set_hl()|
- |lua-treesitter| - |nvim_get_hl_by_id()|
- |nvim_get_hl_by_name()|
============================================================================== ==============================================================================
GENERAL TIPS AND RECOMMENDATIONS GENERAL TIPS AND RECOMMENDATIONS
@ -1573,10 +1574,17 @@ Olical/conjure: https://github.com/Olical/conjure plugin provides an
interactive development environment that supports Fennel among other interactive development environment that supports Fennel among other
languages . languages .
- Teal: https://github.com/teal-language/tl
The name Teal comes from pronouncing TL typed lua . This is exactly
what it tries to do - add strong typing to lua while otherwise
remaining close to standard lua syntax. The nvim-teal-maker:
https://github.com/svermeulen/nvim-teal-maker plugin can be used to
write Neovim plugins or configuration files directly in Teal
Other interesting projects: Other interesting projects:
- TypeScriptToLua/TypeScriptToLua: - TypeScriptToLua/TypeScriptToLua:
https://github.com/TypeScriptToLua/TypeScriptToLua https://github.com/TypeScriptToLua/TypeScriptToLua
- teal-language/tl: https://github.com/teal-language/tl
- Haxe: https://haxe.org/ - Haxe: https://haxe.org/
- SwadicalRag/wasm2lua: https://github.com/SwadicalRag/wasm2lua - SwadicalRag/wasm2lua: https://github.com/SwadicalRag/wasm2lua
- hengestone/lua-languages: https://github.com/hengestone/lua-languages - hengestone/lua-languages: https://github.com/hengestone/lua-languages

Loading…
Cancel
Save