diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/autocmd.txt | 8 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 24 | ||||
-rw-r--r-- | runtime/doc/gui.txt | 5 | ||||
-rw-r--r-- | runtime/doc/insert.txt | 5 | ||||
-rw-r--r-- | runtime/doc/repeat.txt | 4 | ||||
-rw-r--r-- | runtime/doc/sponsor.txt | 20 | ||||
-rw-r--r-- | runtime/doc/syntax.txt | 28 | ||||
-rw-r--r-- | runtime/doc/tags | 5 | ||||
-rw-r--r-- | runtime/doc/testing.txt | 5 | ||||
-rw-r--r-- | runtime/doc/todo.txt | 13 | ||||
-rw-r--r-- | runtime/doc/version6.txt | 4 | ||||
-rw-r--r-- | runtime/doc/version8.txt | 4 | ||||
-rw-r--r-- | runtime/doc/vim9.txt | 62 | ||||
-rw-r--r-- | runtime/filetype.vim | 2 | ||||
-rw-r--r-- | runtime/ftplugin/jsonc.vim | 27 | ||||
-rw-r--r-- | runtime/indent/jsonc.vim | 189 | ||||
-rw-r--r-- | runtime/indent/pascal.vim | 4 | ||||
-rw-r--r-- | runtime/syntax/go.vim | 444 | ||||
-rw-r--r-- | runtime/syntax/jsonc.vim | 44 | ||||
-rw-r--r-- | runtime/syntax/vim.vim | 2 |
20 files changed, 752 insertions, 147 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 5f1231ccb0..5e1f61e88a 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 8.2. Last change: 2021 May 29 +*autocmd.txt* For Vim version 8.2. Last change: 2021 Jul 02 VIM REFERENCE MANUAL by Bram Moolenaar @@ -679,8 +679,10 @@ CursorHoldI Just like CursorHold, but in Insert mode. CursorMoved After the cursor was moved in Normal or Visual mode. Also when the text of the cursor line has been changed, e.g., with "x", "rx" or "p". - Not triggered when there is typeahead or when - an operator is pending. + Not triggered when there is typeahead, when + an operator is pending or when moving to + another window while remaining at the same + cursor position. For an example see |match-parens|. Note: This can not be skipped with `:noautocmd`. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 401f055f7d..e5f9b46517 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 8.2. Last change: 2021 Jun 23 +*eval.txt* For Vim version 8.2. Last change: 2021 Jul 01 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1588,7 +1588,17 @@ The lambda expression is also useful for Channel, Job and timer: > Handler called Handler called -Note how execute() is used to execute an Ex command. That's ugly though. +Note that it is possible to cause memory to be used and not freed if the +closure is referenced by the context it depends on: > + function Function() + let x = 0 + let F = {-> x} + endfunction +The closure uses "x" from the function scope, and "F" in that same scope +refers to the closure. This cycle results in the memory not being freed. +Recommendation: don't do this. + +Notice how execute() is used to execute an Ex command. That's ugly though. In Vim9 script you can use a command block, see |inline-function|. Lambda expressions have internal names like '<lambda>42'. If you get an error @@ -1963,7 +1973,8 @@ v:fcs_choice What should happen after a |FileChangedShell| event was Vim behaves like it is empty, there is no warning message. *v:fname* *fname-variable* -v:fname The file name set by 'includeexpr'. Empty otherwise. +v:fname When evaluating 'includeexpr': the file name that was + detected. Empty otherwise. *v:fname_in* *fname_in-variable* v:fname_in The name of the input file. Valid while evaluating: @@ -5803,7 +5814,7 @@ getmousepos() *getmousepos()* are zero. When the position is after the text then "column" is the - length of the text in bytes. + length of the text in bytes plus one. If the mouse is over a popup window then that window is used. @@ -8921,6 +8932,10 @@ screenpos({winid}, {lnum}, {col}) *screenpos()* The "curscol" value is where the cursor would be placed. For a Tab it would be the same as "endcol", while for a double width character it would be the same as "col". + The |conceal| feature is ignored here, the column numbers are + as if 'conceallevel' is zero. You can set the cursor to the + right position and use |screencol()| to get the value with + |conceal| taken into account. Can also be used as a |method|: > GetWinid()->screenpos(lnum, col) @@ -11892,6 +11907,7 @@ diff Compiled with |vimdiff| and 'diff' support. digraphs Compiled with support for digraphs. directx Compiled with support for DirectX and 'renderoptions'. dnd Compiled with support for the "~ register |quote_~|. +drop_file Compiled with |drop_file| support. ebcdic Compiled on a machine with ebcdic character set. emacs_tags Compiled with support for Emacs tags. eval Compiled with expression evaluation support. Always diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index c93a050480..decc7bf8a5 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -1,4 +1,4 @@ -*gui.txt* For Vim version 8.2. Last change: 2021 May 01 +*gui.txt* For Vim version 8.2. Last change: 2021 Jun 27 VIM REFERENCE MANUAL by Bram Moolenaar @@ -411,7 +411,8 @@ Mouse mapping with modifiers does not work for modeless selection. 3.7 Drag and drop *drag-n-drop* You can drag and drop one or more files into the Vim window, where they will -be opened as if a |:drop| command was used. +be opened as if a |:drop| command was used. You can check if this is +supported with the *drop_file* feature: `has('drop_file')`. If you hold down Shift while doing this, Vim changes to the first dropped file's directory. If you hold Ctrl Vim will always split a new window for the diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index d70b3e6012..3e77ee7ce7 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -1,4 +1,4 @@ -*insert.txt* For Vim version 8.2. Last change: 2020 Oct 16 +*insert.txt* For Vim version 8.2. Last change: 2021 Jul 05 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1073,7 +1073,8 @@ On the second invocation the arguments are: The function must return a List with the matching words. These matches usually include the "a:base" text. When there are no matches return an empty -List. +List. Note that the cursor may have moved since the first invocation, the +text may have been changed. In order to return more information than the matching words, return a Dict that contains the List. The Dict can have these items: diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt index 9e13bdb441..e344ec7dc7 100644 --- a/runtime/doc/repeat.txt +++ b/runtime/doc/repeat.txt @@ -1,4 +1,4 @@ -*repeat.txt* For Vim version 8.2. Last change: 2021 Jun 14 +*repeat.txt* For Vim version 8.2. Last change: 2021 Jun 27 VIM REFERENCE MANUAL by Bram Moolenaar @@ -846,7 +846,7 @@ About the additional commands in debug mode: ":cont", ":next", ":finish" (or shorter). *vim9-debug* When debugging a compiled :def function, "step" will stop before every -executed line, not every ingle nstruction. Thus it works mostly like a not +executed line, not every single instruction. Thus it works mostly like a not compiled function. Access to local variables is limited you can use: > echo varname But not much else. diff --git a/runtime/doc/sponsor.txt b/runtime/doc/sponsor.txt index bb8cc29c38..c0a8c51b5f 100644 --- a/runtime/doc/sponsor.txt +++ b/runtime/doc/sponsor.txt @@ -1,4 +1,4 @@ -*sponsor.txt* For Vim version 8.2. Last change: 2008 Jun 21 +*sponsor.txt* For Vim version 8.2. Last change: 2021 Jul 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -11,9 +11,8 @@ Fixing bugs and adding new features takes a lot of time and effort. To show your appreciation for the work and motivate Bram and others to continue working on Vim please send a donation. -Since Bram is back to a paid job the money will now be used to help children -in Uganda. See |uganda|. But at the same time donations increase Bram's -motivation to keep working on Vim! +Since Bram does not need the money it will be used to help children in Uganda, +see |uganda|. Donations increase Bram's motivation to keep working on Vim! For the most recent information about sponsoring look on the Vim web site: @@ -74,19 +73,6 @@ Other methods See |iccf-donations|. amount you transferred if you want to vote for features and show others you are a registered Vim user or sponsor. -Cash Small amounts can be sent with ordinary mail. Put something - around the money, so that it's not noticeable from the - outside. Mention your e-mail address if you want to vote for - features and show others you are a registered Vim user or - sponsor. - -You can use this permanent address: - Bram Moolenaar - Finsterruetihof 1 - 8134 Adliswil - Switzerland - - QUESTIONS AND ANSWERS *sponsor-faq* *register-faq* diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index da4bf8e1bc..e8ff255a7a 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1,4 +1,4 @@ -*syntax.txt* For Vim version 8.2. Last change: 2021 Jun 22 +*syntax.txt* For Vim version 8.2. Last change: 2021 Jul 02 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1420,11 +1420,17 @@ To select syntax highlighting file for Euphoria, as well as for auto-detecting the *.e and *.E file extensions as Euphoria file type, add the following line to your startup file: > - :let filetype_euphoria = "euphoria3" + :let g:filetype_euphoria = "euphoria3" < or > - :let filetype_euphoria = "euphoria4" + :let g:filetype_euphoria = "euphoria4" + +Elixir and Euphoria share the *.ex file extension. If the filetype is +specifically set as Euphoria with the g:filetype_euphoria variable, or the +file is determined to be Euphoria based on keywords in the file, then the +filetype will be set as Euphoria. Otherwise, the filetype will default to +Elixir. ERLANG *erlang.vim* *ft-erlang-syntax* @@ -1442,6 +1448,22 @@ To enable highlighting some special atoms, put this in your vimrc: > :let g:erlang_highlight_special_atoms = 1 +ELIXIR *elixir.vim* *ft-elixir-syntax* + +Elixir is a dynamic, functional language for building scalable and maintainable +applications. + +The following file extensions are auto-detected as Elixir file types: + + *.ex, *.exs, *.eex, *.leex, *.lock + +Elixir and Euphoria share the *.ex file extension. If the filetype is +specifically set as Euphoria with the g:filetype_euphoria variable, or the +file is determined to be Euphoria based on keywords in the file, then the +filetype will be set as Euphoria. Otherwise, the filetype will default to +Elixir. + + FLEXWIKI *flexwiki.vim* *ft-flexwiki-syntax* FlexWiki is an ASP.NET-based wiki package available at http://www.flexwiki.com diff --git a/runtime/doc/tags b/runtime/doc/tags index 2d3bb37931..9c99429b81 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -6190,6 +6190,8 @@ dos-backslash os_dos.txt /*dos-backslash* dos-colors os_dos.txt /*dos-colors* dos-file-formats os_dos.txt /*dos-file-formats* dos-locations os_dos.txt /*dos-locations* +dos-powershell os_dos.txt /*dos-powershell* +dos-pwsh os_dos.txt /*dos-pwsh* dos-shell os_dos.txt /*dos-shell* dos-standard-mappings os_dos.txt /*dos-standard-mappings* dos-temp-files os_dos.txt /*dos-temp-files* @@ -6202,6 +6204,7 @@ dp diff.txt /*dp* drag-n-drop gui.txt /*drag-n-drop* drag-n-drop-win32 gui_w32.txt /*drag-n-drop-win32* drag-status-line term.txt /*drag-status-line* +drop_file gui.txt /*drop_file* dtd.vim syntax.txt /*dtd.vim* dtd2vim insert.txt /*dtd2vim* dying-variable eval.txt /*dying-variable* @@ -6222,6 +6225,7 @@ efm-%> quickfix.txt /*efm-%>* efm-entries quickfix.txt /*efm-entries* efm-ignore quickfix.txt /*efm-ignore* eiffel.vim syntax.txt /*eiffel.vim* +elixir.vim syntax.txt /*elixir.vim* emacs-keys tips.txt /*emacs-keys* emacs-tags tagsrch.txt /*emacs-tags* emacs_tags tagsrch.txt /*emacs_tags* @@ -6571,6 +6575,7 @@ ft-docbkxml-syntax syntax.txt /*ft-docbkxml-syntax* ft-dosbatch-syntax syntax.txt /*ft-dosbatch-syntax* ft-dtd-syntax syntax.txt /*ft-dtd-syntax* ft-eiffel-syntax syntax.txt /*ft-eiffel-syntax* +ft-elixir-syntax syntax.txt /*ft-elixir-syntax* ft-erlang-syntax syntax.txt /*ft-erlang-syntax* ft-euphoria-syntax syntax.txt /*ft-euphoria-syntax* ft-flexwiki-syntax syntax.txt /*ft-flexwiki-syntax* diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index 8dc6dc3ad9..be2896e231 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -1,4 +1,4 @@ -*testing.txt* For Vim version 8.2. Last change: 2021 Jun 23 +*testing.txt* For Vim version 8.2. Last change: 2021 Jul 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -82,7 +82,8 @@ test_getvalue({name}) *test_getvalue()* *test_gui_drop_files()* test_gui_drop_files({list}, {row}, {col}, {mods}) Drop one or more files in {list} in the window at {row}, {col}. - This function only works when the GUI is running. + This function only works when the GUI is running and the + |drag-n-drop| feature is present. The supported values for {mods} are: 0x4 Shift diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index 0735598c33..655b74a401 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 8.2. Last change: 2021 Jun 26 +*todo.txt* For Vim version 8.2. Last change: 2021 Jul 05 VIM REFERENCE MANUAL by Bram Moolenaar @@ -38,11 +38,9 @@ browser use: https://github.com/vim/vim/issues/1234 *known-bugs* -------------------- Known bugs and current work ----------------------- -Memory eaten up by function returning a closure. #8439 -Circular reference. Should garbage collector find unused local variables? - Vim9 - Make everything work: - possible leak in test_vim9_builtin ? +- Make "for _ in range()" work, do not store the value in a var. - use CheckLegacyAndVim9Success(lines) in many more places - compile get_lambda_tv() in popup_add_timeout() - For builtin functions using tv_get_string*() use check_for_string() to be @@ -248,6 +246,10 @@ test_arglist func Test_all_not_allowed_from_cmdwin() hangs on MS-Windows. Mapping with partial match not executed properly in GTK. (Ingo Karkat, #7082) +Problem that a previous silent ":throw" causes a following try/catch not to +work. (ZyX, 2013 Sep 28) With examples: (Malcolm Rowe, 2015 Dec 24) +Also see #8487 for an example. + Patch for Template string: #4634 Have another look at the implementation. @@ -1420,9 +1422,6 @@ Appveyor build with self-installing executable, includes getting most interfaces: https://github.com/k-takata/vim/tree/chrisbra-appveyor-build result: https://ci.appveyor.com/project/k-takata/vim/history -Problem that a previous silent ":throw" causes a following try/catch not to -work. (ZyX, 2013 Sep 28) With examples: (Malcolm Rowe, 2015 Dec 24) - Problem using ":try" inside ":execute". (ZyX, 2013 Sep 15) Patch to make tests pass with EBCDIC. (Owen Leibman, 2016 Apr 10) diff --git a/runtime/doc/version6.txt b/runtime/doc/version6.txt index abf154422f..22a57aaa8a 100644 --- a/runtime/doc/version6.txt +++ b/runtime/doc/version6.txt @@ -2696,7 +2696,7 @@ Multi-byte: double-wide character. - Overstrike mode for the cmdline replaced only the first byte of a multibyte character. -- The cursor in Replace mode (also in the cmdline) was to small on a +- The cursor in Replace mode (also in the cmdline) was too small on a double-wide character. - When a multibyte character contained a 0x80 byte, it didn't work (was using a CSI byte instead). (Muraoka Taro) @@ -3546,7 +3546,7 @@ Added Simplified Chinese translation of the tutor. (Mendel L Chan) Added Russian keymap for yawerty keyboard. Added an explanation of using the vimrc file in the tutor. -Changed tutor.vim to get the right encoding for the Taiwainese tutor. +Changed tutor.vim to get the right encoding for the Taiwanese tutor. Added Russian tutor. (Andrey Kiselev) Added Polish tutor. (Mikolaj Machowski) diff --git a/runtime/doc/version8.txt b/runtime/doc/version8.txt index 313c38827f..9ed74cc5ba 100644 --- a/runtime/doc/version8.txt +++ b/runtime/doc/version8.txt @@ -35504,7 +35504,7 @@ Files: Filelist, src/testdir/Make_all.mak, src/testdir/check.vim, src/testdir/test_xxd.vim Patch 8.1.1545 -Problem: When the screen is to small there is no message about that. +Problem: When the screen is too small there is no message about that. (Daniel Hahler) Solution: Do not use :cquit. (closes #4534) Files: src/testdir/runtest.vim @@ -41104,7 +41104,7 @@ Files: src/buffer.c, src/testdir/test_popupwin.vim Patch 8.1.2419 Problem: With a long file name the hit-enter prompt appears. (J. Lewis Muir) -Solution: When checking for text to wrap don't do this when outputing a CR. +Solution: When checking for text to wrap don't do this when outputting a CR. Files: src/message.c, src/testdir/test_display.vim, src/testdir/dumps/Test_long_file_name_1.dump diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt index e8d97a9c3c..8b91cdd4b1 100644 --- a/runtime/doc/vim9.txt +++ b/runtime/doc/vim9.txt @@ -1,4 +1,4 @@ -*vim9.txt* For Vim version 8.2. Last change: 2021 Jun 25 +*vim9.txt* For Vim version 8.2. Last change: 2021 Jul 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -442,7 +442,8 @@ The function must already have been defined. > var Funcref = MyFunction When using `function()` the resulting type is "func", a function with any -number of arguments and any return type. The function can be defined later. +number of arguments and any return type (including void). The function can be +defined later. Lambda using => instead of -> ~ @@ -579,13 +580,18 @@ If the heredoc is inside a function 'cpoptions' must be set before :def and restored after the :enddef. In places where line continuation with a backslash is still needed, such as -splitting up a long Ex command, comments can start with #\ instead of "\: > - syn region Text +splitting up a long Ex command, comments can start with '#\ ': > + syn region Text \ start='foo' #\ comment \ end='bar' - -< *E1050* +Like with legacy script '"\ ' is used. This is also needed when line +continuation is used without a backslash and a line starts with a bar: > + au CursorHold * echom 'BEFORE bar' + #\ some comment + | echom 'AFTER bar' +< + *E1050* To make it possible for the operator at the start of the line to be recognized, it is required to put a colon before a range. This example will add "start" and print: > @@ -1084,10 +1090,8 @@ The following builtin types are supported: Not supported yet: tuple<a: {type}, b: {type}, ...> -These types can be used in declarations, but no value will have this type: - {type}|{type} {not implemented yet} - void - any +These types can be used in declarations, but no simple value will actually +have the "void" type. There is no array type, use list<{type}> instead. For a list constant an efficient implementation is used that avoids allocating lot of small pieces of @@ -1096,8 +1100,16 @@ memory. A partial and function can be declared in more or less specific ways: func any kind of function reference, no type checking for arguments or return value +func: void any number and type of arguments, no return + value func: {type} any number and type of arguments with specific return type + +func() function with no argument, does not return a + value +func(): void same +func(): {type} function with no argument and return type + func({type}) function with argument type, does not return a value func({type}): {type} function with argument type and return type @@ -1186,6 +1198,18 @@ dictionary. If there is a mix of types, the "any" type is used. > ['a', 'b', 'c'] list<string> [1, 'x', 3] list<any> +The common type of function references, if they do not all have the same +number of arguments, uses "(...)" to indicate the number of arguments is not +specified. For example: > + def Foo(x: bool) + enddef + def Bar(x: bool, y: bool) + enddef + var funclist = [Foo, Bar] + echo funclist->typename() +Results in: + list<func(...)> + For script-local variables in Vim9 script the type is checked, also when the variable was declared in a legacy function. @@ -1202,16 +1226,24 @@ In Vim9 script this has been made stricter. In most places it works just as before, if the value used matches the expected type. There will sometimes be an error, thus breaking backwards compatibility. For example: - Using a number other than 0 or 1 where a boolean is expected. *E1023* -- Using a string value when setting a number options. +- Using a string value when setting a number option. - Using a number where a string is expected. *E1024* One consequence is that the item type of a list or dict given to map() must not change. This will give an error in Vim9 script: > - map([1, 2, 3], (i, v) => 'item ' .. i) + vim9 echo map([1, 2, 3], (i, v) => 'item ' .. i) E1012: Type mismatch; expected number but got string -Instead use |mapnew()|. If the item type was determined to be "any" it can -change to a more specific type. E.g. when a list of mixed types gets changed -to a list of numbers. +Instead use |mapnew(): > + vim9 echo mapnew([1, 2, 3], (i, v) => 'item ' .. i) + ['item 0', 'item 1', 'item 2'] + +If the item type was determined to be "any" it can change to a more specific +type. E.g. when a list of mixed types gets changed to a list of numbers: > + var mylist = [1, 2.0, '3'] + # typename(mylist) == "list<any>" + map(mylist, (i, v) => 'item ' .. i) + # typename(mylist) == "list<string>", no error + Same for |extend()|, use |extendnew()| instead, and for |flatten()|, use |flattennew()| instead. diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 2cb3f0b1d0..13f8e942bb 100644 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1,7 +1,7 @@ " Vim support file to detect file types " " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2021 Jun 13 +" Last Change: 2021 Jul 03 " Listen very carefully, I will say this only once if exists("did_load_filetypes") diff --git a/runtime/ftplugin/jsonc.vim b/runtime/ftplugin/jsonc.vim new file mode 100644 index 0000000000..90d52cd0d3 --- /dev/null +++ b/runtime/ftplugin/jsonc.vim @@ -0,0 +1,27 @@ +" Vim filetype plugin +" Language: JSONC (JSON with Comments) +" Original Author: Izhak Jakov <izhak724@gmail.com> +" Acknowledgement: Based off of vim-jsonc maintained by Kevin Locke <kevin@kevinlocke.name> +" https://github.com/kevinoid/vim-jsonc +" License: MIT +" Last Change: 2021-07-01 + +runtime! ftplugin/json.vim + +if exists('b:did_ftplugin_jsonc') + finish +else + let b:did_ftplugin_jsonc = 1 +endif + +" A list of commands that undo buffer local changes made below. +let s:undo_ftplugin = [] + +" Set comment (formatting) related options. {{{1 +setlocal commentstring=//%s comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// +call add(s:undo_ftplugin, 'commentstring< comments<') + +" Let Vim know how to disable the plug-in. +call map(s:undo_ftplugin, "'execute ' . string(v:val)") +let b:undo_ftplugin = join(s:undo_ftplugin, ' | ') +unlet s:undo_ftplugin diff --git a/runtime/indent/jsonc.vim b/runtime/indent/jsonc.vim new file mode 100644 index 0000000000..bf8e501dd5 --- /dev/null +++ b/runtime/indent/jsonc.vim @@ -0,0 +1,189 @@ +" Vim indent file +" Language: JSONC (JSON with Comments) +" Original Author: Izhak Jakov <izhak724@gmail.com> +" Acknowledgement: Based off of vim-json maintained by Eli Parra <eli@elzr.com> +" https://github.com/elzr/vim-json +" Last Change: 2021-07-01 + +" 0. Initialization {{{1 +" ================= + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent + +" Now, set up our indentation expression and keys that trigger it. +setlocal indentexpr=GetJSONCIndent() +setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e + +" Only define the function once. +if exists("*GetJSONCIndent") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +" 1. Variables {{{1 +" ============ + +let s:line_term = '\s*\%(\%(\/\/\).*\)\=$' +" Regex that defines blocks. +let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term + +" 2. Auxiliary Functions {{{1 +" ====================== + +" Check if the character at lnum:col is inside a string. +function s:IsInString(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString' +endfunction + +" Find line above 'lnum' that isn't empty, or in a string. +function s:PrevNonBlankNonString(lnum) + let lnum = prevnonblank(a:lnum) + while lnum > 0 + " If the line isn't empty or in a string, end search. + let line = getline(lnum) + if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line))) + break + endif + let lnum = prevnonblank(lnum - 1) + endwhile + return lnum +endfunction + +" Check if line 'lnum' has more opening brackets than closing ones. +function s:LineHasOpeningBrackets(lnum) + let open_0 = 0 + let open_2 = 0 + let open_4 = 0 + let line = getline(a:lnum) + let pos = match(line, '[][(){}]', 0) + while pos != -1 + let idx = stridx('(){}[]', line[pos]) + if idx % 2 == 0 + let open_{idx} = open_{idx} + 1 + else + let open_{idx - 1} = open_{idx - 1} - 1 + endif + let pos = match(line, '[][(){}]', pos + 1) + endwhile + return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) +endfunction + +function s:Match(lnum, regex) + let col = match(getline(a:lnum), a:regex) + 1 + return col > 0 && !s:IsInString(a:lnum, col) ? col : 0 +endfunction + +" 3. GetJSONCIndent Function {{{1 +" ========================= + +function GetJSONCIndent() + if !exists("s:inside_comment") + let s:inside_comment = 0 + endif + + " 3.1. Setup {{{2 + " ---------- + + " Set up variables for restoring position in file. Could use v:lnum here. + let vcol = col('.') + + " 3.2. Work on the current line {{{2 + " ----------------------------- + + + " Get the current line. + let line = getline(v:lnum) + let ind = -1 + if s:inside_comment == 0 + " TODO iterate through all the matches in a line + let col = matchend(line, '\/\*') + if col > 0 && !s:IsInString(v:lnum, col) + let s:inside_comment = 1 + endif + endif + " If we're in the middle of a comment + if s:inside_comment == 1 + let col = matchend(line, '\*\/') + if col > 0 && !s:IsInString(v:lnum, col) + let s:inside_comment = 0 + endif + return ind + endif + if line =~ '^\s*//' + return ind + endif + + " If we got a closing bracket on an empty line, find its match and indent + " according to it. + let col = matchend(line, '^\s*[]}]') + + if col > 0 && !s:IsInString(v:lnum, col) + call cursor(v:lnum, col) + let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2) + + let pairstart = escape(bs[0], '[') + let pairend = escape(bs[1], ']') + let pairline = searchpair(pairstart, '', pairend, 'bW') + + if pairline > 0 + let ind = indent(pairline) + else + let ind = virtcol('.') - 1 + endif + + return ind + endif + + " If we are in a multi-line string, don't do anything to it. + if s:IsInString(v:lnum, matchend(line, '^\s*') + 1) + return indent('.') + endif + + " 3.3. Work on the previous line. {{{2 + " ------------------------------- + + let lnum = prevnonblank(v:lnum - 1) + + if lnum == 0 + return 0 + endif + + " Set up variables for current line. + let line = getline(lnum) + let ind = indent(lnum) + + " If the previous line ended with a block opening, add a level of indent. + " if s:Match(lnum, s:block_regex) + " return indent(lnum) + shiftwidth() + " endif + + " If the previous line contained an opening bracket, and we are still in it, + " add indent depending on the bracket type. + if line =~ '[[({]' + let counts = s:LineHasOpeningBrackets(lnum) + if counts[0] == '1' || counts[1] == '1' || counts[2] == '1' + return ind + shiftwidth() + else + call cursor(v:lnum, vcol) + end + endif + + " }}}2 + + return ind +endfunction + +" }}}1 + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim:set sw=2 sts=2 ts=8 noet: diff --git a/runtime/indent/pascal.vim b/runtime/indent/pascal.vim index c7955d669b..1f39fd1cad 100644 --- a/runtime/indent/pascal.vim +++ b/runtime/indent/pascal.vim @@ -2,7 +2,7 @@ " Language: Pascal " Maintainer: Neil Carter <n.carter@swansea.ac.uk> " Created: 2004 Jul 13 -" Last Change: 2017 Jun 13 +" Last Change: 2021 Jul 01 " " This is version 2.0, a complete rewrite. " @@ -20,6 +20,8 @@ setlocal indentkeys+==end;,==const,==type,==var,==begin,==repeat,==until,==for setlocal indentkeys+==program,==function,==procedure,==object,==private setlocal indentkeys+==record,==if,==else,==case +let b:undo_indent = "setl indentkeys< indentexpr<" + if exists("*GetPascalIndent") finish endif diff --git a/runtime/syntax/go.vim b/runtime/syntax/go.vim index e78f8cf27c..1439487f69 100644 --- a/runtime/syntax/go.vim +++ b/runtime/syntax/go.vim @@ -1,58 +1,109 @@ -" Vim syntax file -" Language: Go -" Maintainer: David Barnett (https://github.com/google/vim-ft-go) -" Last Change: 2014 Aug 16 - -" Options: -" There are some options for customizing the highlighting; the recommended -" settings are the default values, but you can write: -" let OPTION_NAME = 0 -" in your ~/.vimrc file to disable particular options. You can also write: -" let OPTION_NAME = 1 -" to enable particular options. At present, all options default to on. +" Copyright 2009 The Go Authors. All rights reserved. +" Use of this source code is governed by a BSD-style +" license that can be found in the LICENSE file. " -" - g:go_highlight_array_whitespace_error -" Highlights white space after "[]". -" - g:go_highlight_chan_whitespace_error -" Highlights white space around the communications operator that don't -" follow the standard style. -" - g:go_highlight_extra_types -" Highlights commonly used library types (io.Reader, etc.). -" - g:go_highlight_space_tab_error -" Highlights instances of tabs following spaces. -" - g:go_highlight_trailing_whitespace_error -" Highlights trailing white space. +" go.vim: Vim syntax file for Go. +" Language: Go +" Maintainer: Billie Cleek <bhcleek@gmail.com> +" Latest Revision: 2021-06-26 +" License: BSD-style. See LICENSE file in source repository. +" Repository: https://github.com/fatih/vim-go " Quit when a (custom) syntax file was already loaded -if exists('b:current_syntax') +if exists("b:current_syntax") finish endif -if !exists('g:g |