diff options
31 files changed, 4264 insertions, 3188 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim index 05a92bc224..01cde4631e 100644 --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -3,7 +3,7 @@ vim9script # Vim functions for file type detection # # Maintainer: Bram Moolenaar <Bram@vim.org> -# Last Change: 2022 Apr 06 +# Last Change: 2022 Apr 13 # These functions are moved here from runtime/filetype.vim to make startup # faster. diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 3b738b744f..0bbfd34a72 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 8.2. Last change: 2022 Apr 08 +*autocmd.txt* For Vim version 8.2. Last change: 2022 Apr 17 VIM REFERENCE MANUAL by Bram Moolenaar @@ -95,6 +95,7 @@ Or use `:execute`: > :augroup mine | exe "au! BufRead *" | augroup END :augroup mine | exe "au BufRead * set tw=70" | augroup END +< *autocmd-expand* Note that special characters (e.g., "%", "<cword>") in the ":autocmd" arguments are not expanded when the autocommand is defined. These will be expanded when the Event is recognized, and the {cmd} is executed. The only @@ -473,13 +474,15 @@ BufRead or BufReadPost When starting to edit a new buffer, after executing the modelines. See |BufWinEnter| for when you need to do something after processing the modelines. - This does NOT work for ":r file". Not used - when the file doesn't exist. Also used after - successfully recovering a file. - Also triggered for the filetypedetect group - when executing ":filetype detect" and when - writing an unnamed buffer in a way that the - buffer gets a name. + Also triggered: + - when writing an unnamed buffer in a way that + the buffer gets a name + - after successfully recovering a file + - for the filetypedetect group when executing + ":filetype detect" + Not triggered: + - for the `:read file` command + - when the file doesn't exist *BufReadCmd* BufReadCmd Before starting to edit a new buffer. Should read the file into the buffer. |Cmd-event| @@ -707,9 +710,38 @@ CursorMoved After the cursor was moved in Normal or Visual CursorMovedI After the cursor was moved in Insert mode. Not triggered when the popup menu is visible. Otherwise the same as CursorMoved. + *DiffUpdated* +DiffUpdated After diffs have been updated. Depending on + what kind of diff is being used (internal or + external) this can be triggered on every + change or when doing |:diffupdate|. + *DirChangedPre* +DirChangedPre The working directory is going to be changed, + as with |DirChanged|. The pattern is like + with |DirChanged|. The new directory can be + found in v:event.directory. + *DirChanged* +DirChanged The working directory has changed in response + to the |:cd| or |:tcd| or |:lcd| commands, or + as a result of the 'autochdir' option. + The pattern can be: + "window" to trigger on `:lcd` + "tabpage" to trigger on `:tcd` + "global" to trigger on `:cd` + "auto" to trigger on 'autochdir'. + "drop" to trigger on editing a file + <afile> is set to the new directory name. *EncodingChanged* EncodingChanged Fires off after the 'encoding' option has been changed. Useful to set up fonts, for example. + *ExitPre* +ExitPre When using `:quit`, `:wq` in a way it makes + Vim exit, or using `:qall`, just after + |QuitPre|. Can be used to close any + non-essential window. Exiting may still be + cancelled if there is a modified buffer that + isn't automatically saved, use |VimLeavePre| + for really exiting. *FileAppendCmd* FileAppendCmd Before appending to a file. Should do the appending to the file. Use the '[ and '] @@ -737,35 +769,6 @@ FileChangedRO Before making the first change to a read-only *E881* If the number of lines changes saving for undo may fail and the change will be aborted. - *DiffUpdated* -DiffUpdated After diffs have been updated. Depending on - what kind of diff is being used (internal or - external) this can be triggered on every - change or when doing |:diffupdate|. - *DirChangedPre* -DirChangedPre The working directory is going to be changed, - as with |DirChanged|. The pattern is like - with |DirChanged|. The new directory can be - found in v:event.directory. - *DirChanged* -DirChanged The working directory has changed in response - to the |:cd| or |:tcd| or |:lcd| commands, or - as a result of the 'autochdir' option. - The pattern can be: - "window" to trigger on `:lcd` - "tabpage" to trigger on `:tcd` - "global" to trigger on `:cd` - "auto" to trigger on 'autochdir'. - "drop" to trigger on editing a file - <afile> is set to the new directory name. - *ExitPre* -ExitPre When using `:quit`, `:wq` in a way it makes - Vim exit, or using `:qall`, just after - |QuitPre|. Can be used to close any - non-essential window. Exiting may still be - cancelled if there is a modified buffer that - isn't automatically saved, use |VimLeavePre| - for really exiting. *FileChangedShell* FileChangedShell When Vim notices that the modification time of a file has changed since editing started. diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index e99a81302a..8695edd2dd 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -1,4 +1,4 @@ -*builtin.txt* For Vim version 8.2. Last change: 2022 Apr 06 +*builtin.txt* For Vim version 8.2. Last change: 2022 Apr 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -2046,7 +2046,7 @@ execute({command} [, {silent}]) *execute()* It is not possible to use `:redir` anywhere in {command}. To get a list of lines use |split()| on the result: > - split(execute('args'), "\n") + execute('args')->split("\n") < To execute a command in another window than the current one use `win_execute()`. @@ -2237,6 +2237,8 @@ expand({string} [, {nosuf} [, {list}]]) *expand()* a function <SID> "<SNR>123_" where "123" is the current script ID |<SID>| + <script> sourced script file, or script file + where the current function was defined <stack> call stack <cword> word under the cursor <cWORD> WORD under the cursor diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index 04bd238d11..fdae0da959 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -614,9 +614,10 @@ attack or other people reading your file). When Vim exits the directory and all files in it are deleted. When Vim has the setuid bit set this may cause problems, the temp file is owned by the setuid user but the filter command probably runs as the original user. -On MS-Windows the first of these directories that works is used: $TMP, -$TEMP, c:\TMP, c:\TEMP. -For Unix the list of directories is: $TMPDIR, /tmp, current-dir, $HOME. +Directory for temporary files is created in the first of these directories +that works: + Unix: $TMPDIR, /tmp, current-dir, $HOME. + Windows: $TMP, $TEMP, c:\TMP, c:\TEMP For MS-Windows the GetTempFileName() system function is used. For other systems the tmpnam() library function is used. diff --git a/runtime/doc/channel.txt b/runtime/doc/channel.txt index 43862d8a2a..01a9e3695d 100644 --- a/runtime/doc/channel.txt +++ b/runtime/doc/channel.txt @@ -1,4 +1,4 @@ -*channel.txt* For Vim version 8.2. Last change: 2022 Apr 05 +*channel.txt* For Vim version 8.2. Last change: 2022 Apr 16 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index cd9b988a74..2ef09fa5b8 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -1,4 +1,4 @@ -*cmdline.txt* For Vim version 8.2. Last change: 2022 Feb 04 +*cmdline.txt* For Vim version 8.2. Last change: 2022 Apr 09 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index 74e1d9268c..5130986a0e 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -1,4 +1,4 @@ -*editing.txt* For Vim version 8.2. Last change: 2022 Apr 03 +*editing.txt* For Vim version 8.2. Last change: 2022 Apr 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -445,7 +445,8 @@ does apply like to other wildcards. Environment variables in the expression are expanded when evaluating the expression, thus this works: > :e `=$HOME .. '/.vimrc'` -This does not work, $HOME is inside a string and used literally: > +This uses $HOME inside a string and it will be used literally, most likely not +what you intended: > :e `='$HOME' .. '/.vimrc'` If the expression returns a string then names are to be separated with line @@ -1694,7 +1695,7 @@ session or with another command (e.g., a filter command). Then you will know which version of the file you want to keep. The accuracy of the time check depends on the filesystem. On Unix it is -usually sub-second. With old file sytems and on MS-Windows it is normally one +usually sub-second. With old file systems and on MS-Windows it is normally one second. Use `has('nanotime')` to check if sub-second time stamp checks are available. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 95d14ef5b2..40f0bf85e7 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 8.2. Last change: 2022 Apr 06 +*eval.txt* For Vim version 8.2. Last change: 2022 Apr 17 VIM REFERENCE MANUAL by Bram Moolenaar @@ -4723,7 +4723,7 @@ parentheses can be cut out from |v:exception| with the ":substitute" command. : :try : - : " something with arithmetics and I/O + : " something with arithmetic and I/O : :catch /^EXCEPT:MATHERR:RANGE/ : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "") diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index f538329dfe..aeea3cd5a7 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 8.2. Last change: 2022 Apr 07 +*filetype.txt* For Vim version 8.2. Last change: 2022 Apr 09 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 6b9eb57968..3823a962d2 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1,4 +1,4 @@ -*map.txt* For Vim version 8.2. Last change: 2022 Apr 03 +*map.txt* For Vim version 8.2. Last change: 2022 Apr 14 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1324,7 +1324,8 @@ underscore. Example: > could define a mapping "<SNR>23_Add". When defining a function in a script, "s:" can be prepended to the name to -make it local to the script. But when a mapping is executed from outside of +make it local to the script (in |Vim9| script functions without a prefix are +local to the script). But when a mapping is executed from outside of the script, it doesn't know in which script the function was defined. To avoid this problem, use "<SID>" instead of "s:". The same translation is done as for mappings. This makes it possible to define a call to the function in diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index ede51125f1..61469dead8 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -1,4 +1,4 @@ -*motion.txt* For Vim version 8.2. Last change: 2021 Dec 27 +*motion.txt* For Vim version 8.2. Last change: 2022 Apr 18 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1078,7 +1078,7 @@ in the current file (an indent is removed and a long line is truncated to fit in the window). The marker ">" indicates the current position in the jumplist. It may not be -shown when filtering the |:jump| command using |:filter| +shown when filtering the |:jumps| command using |:filter| You are currently in line 1167. If you then use the CTRL-O command, the cursor is put in line 1154. This results in: diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 2ed4a8f31a..cd048456d3 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 8.2. Last change: 2022 Apr 07 +*options.txt* For Vim version 8.2. Last change: 2022 Apr 13 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 9a4014b045..27b1b1b248 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -1,4 +1,4 @@ -*starting.txt* For Vim version 8.2. Last change: 2022 Feb 01 +*starting.txt* For Vim version 8.2. Last change: 2022 Apr 12 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index dfb0fb7758..98127af61d 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -215,7 +215,7 @@ A syntax group name doesn't specify any color or attributes itself. The name for a highlight or syntax group must consist of ASCII letters, digits and the underscore. As a regexp: "[a-zA-Z0-9_]*". However, Vim does not give -an error when using other characters. The maxium length of a group name is +an error when using other characters. The maximum length of a group name is about 200 bytes. *E1249* To be able to allow each user to pick their favorite set of colors, there must diff --git a/runtime/doc/tags b/runtime/doc/tags index d6455b22b9..c85ee7d5ea 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -1457,6 +1457,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* --echo-wid starting.txt /*--echo-wid* --help starting.txt /*--help* --literal starting.txt /*--literal* +--log starting.txt /*--log* --nofork starting.txt /*--nofork* --noplugin starting.txt /*--noplugin* --not-a-term starting.txt /*--not-a-term* @@ -2003,6 +2004,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* :<cfile> cmdline.txt /*:<cfile>* :<client> cmdline.txt /*:<client>* :<cword> cmdline.txt /*:<cword>* +:<script> cmdline.txt /*:<script>* :<sfile> cmdline.txt /*:<sfile>* :<sflnum> cmdline.txt /*:<sflnum>* :<slnum> cmdline.txt /*:<slnum>* @@ -2082,6 +2084,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* :Termdebug terminal.txt /*:Termdebug* :TermdebugCommand terminal.txt /*:TermdebugCommand* :Texplore pi_netrw.txt /*:Texplore* +:Until terminal.txt /*:Until* :UseVimball pi_vimball.txt /*:UseVimball* :Vexplore pi_netrw.txt /*:Vexplore* :VimballList pi_vimball.txt /*:VimballList* @@ -3722,6 +3725,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX* <range> map.txt /*<range>* <reg> map.txt /*<reg>* <register> map.txt /*<register>* +<script> cmdline.txt /*<script>* <sfile> cmdline.txt /*<sfile>* <sflnum> cmdline.txt /*<sflnum>* <slnum> cmdline.txt /*<slnum>* @@ -4057,7 +4061,6 @@ E1081 eval.txt /*E1081* E1083 editing.txt /*E1083* E1084 eval.txt /*E1084* E1085 eval.txt /*E1085* -E1086 eval.txt /*E1086* E1087 vim9.txt /*E1087* E1089 eval.txt /*E1089* E109 eval.txt /*E109* @@ -4222,7 +4225,6 @@ E1231 map.txt /*E1231* E1232 builtin.txt /*E1232* E1233 builtin.txt /*E1233* E1234 vim9.txt /*E1234* -E1235 vim9.txt /*E1235* E1236 vim9.txt /*E1236* E1237 map.txt /*E1237* E1238 vim9.txt /*E1238* @@ -4260,6 +4262,7 @@ E1266 if_pyth.txt /*E1266* E127 eval.txt /*E127* E1270 change.txt /*E1270* E1271 vim9.txt /*E1271* +E1274 cmdline.txt /*E1274* E128 eval.txt /*E128* E129 eval.txt /*E129* E13 message.txt /*E13* @@ -4780,9 +4783,6 @@ E610 editing.txt /*E610* E611 eval.txt /*E611* E612 sign.txt /*E612* E613 print.txt /*E613* -E614 editing.txt /*E614* -E615 editing.txt /*E615* -E616 editing.txt /*E616* E617 options.txt /*E617* E618 print.txt /*E618* E619 print.txt /*E619* @@ -5772,6 +5772,7 @@ autocmd-disable autocmd.txt /*autocmd-disable* autocmd-events autocmd.txt /*autocmd-events* autocmd-events-abc autocmd.txt /*autocmd-events-abc* autocmd-execute autocmd.txt /*autocmd-execute* +autocmd-expand autocmd.txt /*autocmd-expand* autocmd-groups autocmd.txt /*autocmd-groups* autocmd-intro autocmd.txt /*autocmd-intro* autocmd-list autocmd.txt /*autocmd-list* @@ -6082,6 +6083,7 @@ channel-functions-details channel.txt /*channel-functions-details* channel-mode channel.txt /*channel-mode* channel-more channel.txt /*channel-more* channel-noblock channel.txt /*channel-noblock* +channel-onetime-callback channel.txt /*channel-onetime-callback* channel-open channel.txt /*channel-open* channel-open-options channel.txt /*channel-open-options* channel-raw channel.txt /*channel-raw* @@ -7607,6 +7609,7 @@ hitest.vim syntax.txt /*hitest.vim* hjkl usr_02.txt /*hjkl* hl-ColorColumn syntax.txt /*hl-ColorColumn* hl-Conceal syntax.txt /*hl-Conceal* +hl-CurSearch syntax.txt /*hl-CurSearch* hl-Cursor syntax.txt /*hl-Cursor* hl-CursorColumn syntax.txt /*hl-CursorColumn* hl-CursorIM syntax.txt /*hl-CursorIM* diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 671c90f13c..3d367bcd78 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -1285,6 +1285,8 @@ Put focus on the gdb window to type commands there. Some common ones are: - next execute the current line and stop at the next line - step execute the current line and stop at the next statement, entering functions +- until execute until past the current cursor line or past a specified + position or the current stack frame returns - finish execute until leaving the current function - where show the stack - frame N go to the Nth stack frame @@ -1303,6 +1305,7 @@ gdb: *:Step* execute the gdb "step" command *:Over* execute the gdb "next" command (`:Next` is a Vim command) + *:Until* execute the gdb "until" command *:Finish* execute the gdb "finish" command *:Continue* execute the gdb "continue" command *:Stop* interrupt the program diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index feb9aa6af8..3da86fea70 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 8.2. Last change: 2022 Apr 06 +*todo.txt* For Vim version 8.2. Last change: 2022 Apr 18 VIM REFERENCE MANUAL by Bram Moolenaar @@ -38,6 +38,8 @@ browser use: https://github.com/vim/vim/issues/1234 *known-bugs* -------------------- Known bugs and current work ----------------------- +Use "`=expr`" in heredoc also in :def function. #10216 Yegappan will do it. + Once Vim9 is stable: - Use Vim9 for more runtime files. - Check code coverage, add more tests if needed. @@ -151,7 +153,6 @@ Terminal debugger: - Add option to not open the program window. It's not used when attaching to an already running program. (M. Kelly) - When only gdb window exists, on "quit" edit another buffer. -- Use a sign group - Termdebug does not work when Vim was built with mzscheme: gdb hangs just after "run". Everything else works, including communication channel. Not initializing mzscheme avoid the problem, thus it's not some #ifdef. @@ -202,6 +203,11 @@ Terminal emulator window: - When 'encoding' is not utf-8, or the job is using another encoding, setup conversions. +CurSearch highlight is wrong when searching for a space, matches all spaces +instead of only the current one. + +Can deref_func_name() and deref_function_name() be merged? + When using 'cryptmethod' xchaha20 the undo file is not encrypted. Need to handle extra bytes. @@ -223,8 +229,6 @@ Fails in line 64 of Ch_communicate, no exception is thrown. Patch for Template string: #4634 Have another look at the implementation. -Add expanding <script> which works like <sfile> everywhere. #9189 - Rename getdigraphlist -> digraph_getlist() etc. Can "CSI nr X" be used instead of outputting spaces? Is it faster? #8002 @@ -255,6 +259,14 @@ Idea: when typing ":e /some/dir/" and "dir" does not exist, highlight in red. initialization to figure out the default value from 'shell'. Add a test for this. +With concealed text mouse click doesn't put the cursor in the right position. +(Herb Sitz) Fix by Christian Brabandt, 2011 Jun 16. Doesn't work properly, +need to make the change in where RET_WIN_BUF_CHARTABSIZE() is called. +IDEA: when drawing the text, store the text byte index in ScreenLinesIdx[]. +When converting screen column to text position use this. +Store the line number and byte index for the start of the line, when +converting the screen line to text position use this, add the byte offset. + MS-Windows: did path modifier :p:8 stop working? #8600 Add support for "underdouble", "underdot" and "underdash". #9553 @@ -1920,10 +1932,6 @@ On MS-Windows a temp dir with a & init causes system() to fail. (Ben Fritz, Patch 7.3.116 was the wrong solution. Christian Brabandt has another incomplete patch. (2011 Jul 13) -With concealed text mouse click doesn't put the cursor in the right position. -(Herb Sitz) Fix by Christian Brabandt, 2011 Jun 16. Doesn't work properly, -need to make the change in where RET_WIN_BUF_CHARTABSIZE() is called. - Syntax region with 'concealends' and a 'cchar' value, 'conceallevel' set to 2, only one of the two ends gets the cchar displayed. (Brett Stahlman, 2010 Aug 21, Ben Fritz, 2010 Sep 14) diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt index b30e5f3d4a..adf03537b4 100644 --- a/runtime/doc/vim9.txt +++ b/runtime/doc/vim9.txt @@ -1,4 +1,4 @@ -*vim9.txt* For Vim version 8.2. Last change: 2022 Mar 30 +*vim9.txt* For Vim version 8.2. Last change: 2022 Apr 14 VIM REFERENCE MANUAL by Bram Moolenaar diff --git a/runtime/filetype.vim b/runtime/filetype.vim index 09d0d7c3c7..a43b5c6fb5 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: 2022 Apr 07 +" Last Change: 2022 Apr 13 " Listen very carefully, I will say this only once if exists("did_load_filetypes") diff --git a/runtime/indent/README.txt b/runtime/indent/README.txt index 8b114365c6..649870636e 100644 --- a/runtime/indent/README.txt +++ b/runtime/indent/README.txt @@ -31,7 +31,7 @@ Always use ":setlocal" to set 'indentexpr'. This avoids it being carried over to other buffers. To trigger the indenting after typing a word like "endif", add the word to the -'cinkeys' option with "+=". +'indentkeys' option with "+=". You normally set 'indentexpr' to evaluate a function and then define that function. That function only needs to be defined once for as long as Vim is diff --git a/runtime/indent/krl.vim b/runtime/indent/krl.vim new file mode 100644 index 0000000000..cc3cbd1abb --- /dev/null +++ b/runtime/indent/krl.vim @@ -0,0 +1,130 @@ +" Vim indent file +" Language: Kuka Robot Language +" Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de> +" Version: 3.0.0 +" Last Change: 15. Apr 2022 +" Credits: Based on indent/vim.vim + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nolisp +setlocal nocindent +setlocal nosmartindent +setlocal autoindent +setlocal indentexpr=GetKrlIndent() +setlocal indentkeys=!^F,o,O,=~end,0=~else,0=~case,0=~default,0=~until,0=~continue,=~part +let b:undo_indent = "setlocal lisp< cindent< smartindent< autoindent< indentexpr< indentkeys<" + +if get(g:,'krlSpaceIndent',1) + " Use spaces, not tabs, for indention, 2 is enough. + " More or even tabs would waste valuable space on the teach pendant. + setlocal softtabstop=2 + setlocal shiftwidth=2 + setlocal expandtab + setlocal shiftround + let b:undo_indent = b:undo_indent." softtabstop< shiftwidth< expandtab< shiftround<" +endif + +" Only define the function once. +if exists("*GetKrlIndent") + finish +endif +let s:keepcpo = &cpo +set cpo&vim + +function GetKrlIndent() abort + + let currentLine = getline(v:lnum) + if currentLine =~? '\v^;(\s*(end)?fold>)@!' && !get(g:, 'krlCommentIndent', 0) + " If current line has a ; in column 1 and is no fold, keep zero indent. + " This may be usefull if code is commented out at the first column. + return 0 + endif + + " Find a non-blank line above the current line. + let preNoneBlankLineNum = s:KrlPreNoneBlank(v:lnum - 1) + if preNoneBlankLineNum == 0 + " At the start of the file use zero indent. + return 0 + endif + + let preNoneBlankLine = getline(preNoneBlankLineNum) + let ind = indent(preNoneBlankLineNum) + + " Define add 'shiftwidth' pattern + let addShiftwidthPattern = '\v^\s*(' + if get(g:, 'krlIndentBetweenDef', 1) + let addShiftwidthPattern ..= '(global\s+)?def(fct|dat)?\s+\$?\w' + let addShiftwidthPattern ..= '|' + endif + let addShiftwidthPattern ..= 'if>|while>|for>|loop>' + let addShiftwidthPattern ..= '|else>' + let addShiftwidthPattern ..= '|case>|default>' + let addShiftwidthPattern ..= '|repeat>' + let addShiftwidthPattern ..= '|skip>|(ptp_)?spline>' + let addShiftwidthPattern ..= '|time_block\s+(start|part)>' + let addShiftwidthPattern ..= '|const_vel\s+start>' + let addShiftwidthPattern ..= ')' + + " Define Subtract 'shiftwidth' pattern + let subtractShiftwidthPattern = '\v^\s*(' + if get(g:, 'krlIndentBetweenDef', 1) + let subtractShiftwidthPattern ..= 'end(fct|dat)?>' + let subtractShiftwidthPattern ..= '|' + endif + let subtractShiftwidthPattern ..= 'end(if|while|for|loop)>' + let subtractShiftwidthPattern ..= '|else>' + let subtractShiftwidthPattern ..= '|case>|default>|endswitch>' + let subtractShiftwidthPattern ..= '|until>' + let subtractShiftwidthPattern ..= '|end(skip|spline)>' + let subtractShiftwidthPattern ..= '|time_block\s+(part|end)>' + let subtractShiftwidthPattern ..= '|const_vel\s+end>' + let subtractShiftwidthPattern ..= ')' + + " Add shiftwidth + if preNoneBlankLine =~? addShiftwidthPattern + let ind += &sw + endif + + " Subtract shiftwidth + if currentLine =~? subtractShiftwidthPattern + let ind = ind - &sw + endif + + " First case after a switch gets the indent of the switch. + if currentLine =~? '\v^\s*case>' + \&& preNoneBlankLine =~? '\v^\s*switch>' + let ind = ind + &sw + endif + + " align continue with the following instruction + if currentLine =~? '\v^\s*continue>' + \&& getline(v:lnum + 1) =~? subtractShiftwidthPattern + let ind = ind - &sw + endif + + return ind +endfunction + +" This function works almost like prevnonblank() but handles &-headers, +" comments and continue instructions like blank lines +function s:KrlPreNoneBlank(lnum) abort + + let nPreNoneBlank = prevnonblank(a:lnum) + + while nPreNoneBlank > 0 && getline(nPreNoneBlank) =~? '\v^\s*(\&\w\+|;|continue>)' + " Previouse none blank line irrelevant. Look further aback. + let nPreNoneBlank = prevnonblank(nPreNoneBlank - 1) + endwhile + + return nPreNoneBlank +endfunction + +let &cpo = s:keepcpo +unlet s:keepcpo + +" vim:sw=2 sts=2 et diff --git a/runtime/indent/testdir/krl.in b/runtime/indent/testdir/krl.in new file mode 100644 index 0000000000..ec90feb08b --- /dev/null +++ b/runtime/indent/testdir/krl.in @@ -0,0 +1,148 @@ +; vim: set ft=krl : + +; START_INDENT + +def One() +int i +If i==1 then +While i>=1 +For i=1 to 5 step 2 +Loop +i = i+1 +EndLoop +EndFor +EndWhile +Else +Repeat +Switch i +Case 1 +Skip 123 +i = i+1 +EndSkip 123 +Spline with $acc=100, $vel.cp=3 +slin {x 100} +scirc {x 110, y 110}, {x 120, y 90} +slin {x 200} c_dis +Time_Block Start +slin {x 300} c_dis +Time_Block Part = 22.2 +slin {y 400} c_dis +Time_Block Part = 33.3 +Time_Block End = 10 +slin {y 200} c_dis +Const_Vel Start +100 OnStart +slin {y 300} c_dis +slin {x 100} +Const_Vel End -5.5 +slin {y 200} c_dis +EndSpline +Case 2,3 +PTP_Spline with $acc=100, $vel.ptp=100 +sptp {a1 0} c_ptp +sptp {a1 90} +EndSpline c_spl +Defau |