diff options
-rw-r--r-- | runtime/ftplugin/fortran.vim | 11 | ||||
-rw-r--r-- | runtime/indent/fortran.vim | 21 | ||||
-rw-r--r-- | runtime/syntax/debcontrol.vim | 4 | ||||
-rw-r--r-- | runtime/syntax/fortran.vim | 30 | ||||
-rwxr-xr-x | src/clint.py | 1 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 2 | ||||
-rw-r--r-- | src/nvim/drawline.h | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/keycodes.c | 13 | ||||
-rw-r--r-- | src/nvim/keycodes.h | 6 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 13 | ||||
-rw-r--r-- | src/nvim/main.c | 128 | ||||
-rw-r--r-- | src/nvim/mapping.c | 44 | ||||
-rw-r--r-- | src/nvim/menu.c | 2 | ||||
-rw-r--r-- | src/nvim/message.c | 42 | ||||
-rw-r--r-- | src/nvim/message.h | 7 | ||||
-rw-r--r-- | src/nvim/option.c | 6 | ||||
-rw-r--r-- | src/nvim/regexp.c | 16 | ||||
-rw-r--r-- | src/nvim/usercmd.c | 2 | ||||
-rw-r--r-- | test/functional/vimscript/map_functions_spec.lua | 10 |
20 files changed, 161 insertions, 200 deletions
diff --git a/runtime/ftplugin/fortran.vim b/runtime/ftplugin/fortran.vim index a057db9a4b..d714a4ac4f 100644 --- a/runtime/ftplugin/fortran.vim +++ b/runtime/ftplugin/fortran.vim @@ -1,6 +1,6 @@ " Vim settings file -" Language: Fortran 2008 (and older: Fortran 2003, 95, 90, 77, 66) -" Version: (v54) 2023 December 5 +" Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) +" Version: (v55) 2023 December 22 " Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> " Joshua Hollett <j.hollett@uwinnipeg.ca> " Usage: For instructions, do :help fortran-plugin from Vim @@ -110,7 +110,9 @@ if !exists("b:match_words") let b:match_ignorecase = 1 let b:match_words = \ '(:),' . - \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' . + \ s:notend .'\<select\s\+type\>:' . s:notselect. '\<type\|class\>:\<end\s*select\>,' . + \ s:notend .'\<select\s\+rank\>:' . s:notselect. '\<rank\>:\<end\s*select\>,' . + \ s:notend .'\<select\>:' . s:notselect. '\<case\>:\<end\s*select\>,' . \ s:notelse . '\<if\s*(.\+)\s*then\>:' . \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'. \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'. @@ -119,6 +121,9 @@ if !exists("b:match_words") \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'. \ s:notend . '\<forall\>:\<end\s*forall\>,'. \ s:notend . '\<associate\>:\<end\s*associate\>,'. + \ s:notend . '\<change\s\+team\>:\<end\s*team\>,'. + \ s:notend . '\<critical\>:\<end\s*critical\>,'. + \ s:notend . '\<block\>:\<end\s*block\>,'. \ s:notend . '\<enum\>:\<end\s*enum\>,'. \ s:notend . '\<interface\>:\<end\s*interface\>,'. \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'. diff --git a/runtime/indent/fortran.vim b/runtime/indent/fortran.vim index 7130658f59..392b2d29d5 100644 --- a/runtime/indent/fortran.vim +++ b/runtime/indent/fortran.vim @@ -1,6 +1,6 @@ " Vim indent file -" Language: Fortran 2008 (and Fortran 2003, 95, 90, and 77) -" Version: (v49) 2023 December 1 +" Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) +" Version: (v50) 2023 December 22 " Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> " Joshua Hollett <j.hollett@uwinnipeg.ca> " Usage: For instructions, do :help fortran-indent from Vim @@ -22,8 +22,8 @@ let b:undo_indent = "setl inde< indk<" setlocal indentkeys+==~end,=~case,=~if,=~else,=~do,=~where,=~elsewhere,=~select setlocal indentkeys+==~endif,=~enddo,=~endwhere,=~endselect,=~elseif -setlocal indentkeys+==~type,=~interface,=~forall,=~associate,=~block,=~enum -setlocal indentkeys+==~endforall,=~endassociate,=~endblock,=~endenum +setlocal indentkeys+==~interface,=~forall,=~associate,=~block,=~enum,=~critical +setlocal indentkeys+==~endforall,=~endassociate,=~endblock,=~endenum,=~endcritical if exists("b:fortran_indent_more") || exists("g:fortran_indent_more") setlocal indentkeys+==~function,=~subroutine,=~module,=~contains,=~program setlocal indentkeys+==~endfunction,=~endsubroutine,=~endmodule @@ -49,7 +49,7 @@ if !exists("b:fortran_fixed_source") " Fixed-form file extension defaults let b:fortran_fixed_source = 1 else - " Modern fortran still allows both fixed and free source form + " Modern fortran compilers still allow both fixed and free source form " Assume fixed source form unless signs of free source form " are detected in the first five columns of the first s:lmax lines. " Detection becomes more accurate and time-consuming if more lines @@ -109,8 +109,9 @@ function FortranGetIndent(lnum) "Add a shiftwidth to statements following if, else, else if, case, class, "where, else where, forall, type, interface and associate statements - if prevstat =~? '^\s*\(case\|class\|else\|else\s*if\|else\s*where\)\>' - \ ||prevstat=~? '^\s*\(type\|interface\|associate\|enum\)\>' + if prevstat =~? '^\s*\(case\|class\s\+is\|else\|else\s*if\|else\s*where\)\>' + \ ||prevstat=~? '^\s*\(type\|rank\|interface\|associate\|enum\|critical\)\>' + \ ||prevstat=~? '^\s*change\s\+team\>' \ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>' \ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>' let ind = ind + shiftwidth() @@ -145,10 +146,10 @@ function FortranGetIndent(lnum) "Subtract a shiftwidth from else, else if, elsewhere, case, class, end if, " end where, end select, end forall, end interface, end associate, - " end enum, end type, end block and end type statements + " end enum, end type, end block, end team and end type statements if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*' - \. '\(else\|else\s*if\|else\s*where\|case\|class\|' - \. 'end\s*\(if\|where\|select\|interface\|' + \. '\(else\|else\s*if\|else\s*where\|case\|class\|rank\|type\s\+is\|' + \. 'end\s*\(if\|where\|select\|interface\|critical\|team\|' \. 'type\|forall\|associate\|enum\|block\)\)\>' let ind = ind - shiftwidth() " Fix indent for case statement immediately after select diff --git a/runtime/syntax/debcontrol.vim b/runtime/syntax/debcontrol.vim index af78ebc3ae..b173a7b3f7 100644 --- a/runtime/syntax/debcontrol.vim +++ b/runtime/syntax/debcontrol.vim @@ -3,7 +3,7 @@ " Maintainer: Debian Vim Maintainers " Former Maintainers: Gerfried Fuchs <alfie@ist.org> " Wichert Akkerman <wakkerma@debian.org> -" Last Change: 2023 Jan 16 +" Last Change: 2023 Dec 22 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/syntax/debcontrol.vim " Standard syntax initialization @@ -29,7 +29,7 @@ syn match debControlSpace "[ \t]" let s:kernels = ['linux', 'hurd', 'kfreebsd', 'knetbsd', 'kopensolaris', 'netbsd'] let s:archs = [ \ 'alpha', 'amd64', 'armeb', 'armel', 'armhf', 'arm64', 'avr32', 'hppa' - \, 'i386', 'ia64', 'lpia', 'm32r', 'm68k', 'mipsel', 'mips64el', 'mips' + \, 'i386', 'ia64', 'loong64', 'lpia', 'm32r', 'm68k', 'mipsel', 'mips64el', 'mips' \, 'powerpcspe', 'powerpc', 'ppc64el', 'ppc64', 'riscv64', 's390x', 's390', 'sh3eb' \, 'sh3', 'sh4eb', 'sh4', 'sh', 'sparc64', 'sparc', 'x32' \ ] diff --git a/runtime/syntax/fortran.vim b/runtime/syntax/fortran.vim index 7ed4f8a268..b7fae54d99 100644 --- a/runtime/syntax/fortran.vim +++ b/runtime/syntax/fortran.vim @@ -1,6 +1,6 @@ " Vim syntax file " Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, and 77) -" Version: (v107) 2023 December 17 +" Version: (v108) 2023 December 22 " Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> " Joshua Hollett <j.hollett@uwinnipeg.ca> " Usage: For instructions, do :help fortran-syntax from Vim @@ -75,6 +75,8 @@ syn match fortranConstructName "\(\<end\s*where\s\+\)\@14<=\a\w*" syn match fortranConstructName "\(\<end\s*block\s\+\)\@14<=\a\w*" syn match fortranConstructName "\(\<\%(exit\|cycle\)\s\+\)\@11<=\a\w*" syn match fortranConstructName "\(\<end\s*forall\s\+\)\@15<=\a\w*\>" +syn match fortranConstructName "\(\<end\s*critical\s\+\)\@17<=\a\w*\>" +syn match fortranConstructName "\(\<end\s*associate\s\+\)\@18<=\a\w*\>" syn match fortranUnitName "\(\(end\s*\)\?\(subroutine\|function\|module\|program\|submodule\)\s\+\)\@12<=\a\w\+" syn match fortranUnitHeader "\<end\s*$" @@ -84,10 +86,13 @@ syn keyword fortranIntrinsicR achar iachar transfer dble dprod dim lge lgt lle l syn keyword fortranIntrinsic command_argument_count get_command get_command_argument get_environment_variable is_iostat_end is_iostat_eor move_alloc new_line same_type_as extends_type_of syn keyword fortranIntrinsic selected_real_kind selected_int_kind selected_logical_kind selected_char_kind syn keyword fortranIntrinsic acosh asinh atanh bessel_j0 bessel_j1 bessel_jn bessel_y0 bessel_y1 bessel_yn erf erfc erfc_scaled gamma log_gamma hypot norm2 -syn keyword fortranIntrinsic adjustl adjustr all allocated any associated bit_size btest ceiling count cshift date_and_time digits -syn keyword fortranIntrinsic dot_product eoshift epsilon exponent floor fraction huge iand ibclr ibits ibset ieor ior ishft ishftc lbound len_trim matmul maxexponent maxloc maxval merge minexponent minloc -syn keyword fortranIntrinsic minval modulo mvbits nearest pack precision present product radix random_number random_seed range repeat reshape rrspacing scale scan set_exponent shape size spacing -syn keyword fortranIntrinsic spread sum system_clock tiny transpose trim ubound unpack verify +syn keyword fortranIntrinsic adjustl adjustr all allocated any associated bit_size btest ceiling cshift date_and_time digits +syn keyword fortranIntrinsic dot_product eoshift exponent floor fraction iand ibclr ibits ibset ieor ior ishft ishftc lbound len_trim matmul maxexponent maxloc merge minexponent minloc +syn keyword fortranIntrinsic modulo mvbits nearest pack precision present radix random_number random_seed range repeat reshape rrspacing scale scan set_exponent shape size spacing +"syn keyword fortranIntrinsic count epsilon maxval minval product sum huge tiny +" intrinsic names often used for variables in older Fortran code +syn match fortranIntrinsic '\<\(count\|epsilon\|maxval\|minval\|product\|sum\|huge\|tiny\)\>\ze\s*(' +syn keyword fortranIntrinsic spread system_clock transpose trim ubound unpack verify syn keyword fortranIntrinsic atomic_define atomic_ref execute_command_line leadz trailz storage_size merge_bits syn keyword fortranIntrinsic bge bgt ble blt dshiftl dshiftr findloc iall iany iparity image_index lcobound ucobound maskl maskr num_images parity popcnt poppar shifta shiftl shiftr this_image syn keyword fortranIntrinsic null cpu_time failed_images stopped_images image_status co_broadcast co_max co_min co_sum co_reduce @@ -99,7 +104,6 @@ syn keyword fortranIntrinsic iso_c_binding c_loc c_funloc c_sizeof c_associat syn keyword fortranIntrinsic out_of_range reduce random_init coshape syn keyword fortranIntrinsic acosd asind atand atan2d cosd sind tand acospi asinpi atanpi atan2pi cospi sinpi tanpi syn keyword fortranIntrinsic compiler_options compiler_version get_team team_number -"syn match fortranIntrinsic '\<\(count\|dot_product\|epsilon\|exponent\|fraction\|matmul\|maxval\|minval\|modulo\|nearest\|pack\|precision\|product\|radix\|random_number\|random_seed\|range\|repeat\|reshape\|rrspacing\|scale\|scan\|set_exponent\|shape\|size\|sum\|tiny\|transpose\)\>\ze\s*(' syn match fortranIntrinsic "\<real\s*("me=s+4 syn match fortranIntrinsic "\<logical\s*("me=s+7 syn match fortranIntrinsic "\<not\s*("me=s+3 @@ -351,8 +355,10 @@ if exists("fortran_fold") syn region fortranModule transparent fold keepend start="^\s*module\s\+\(procedure\)\@!\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\(module\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram syn region fortranFunction transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*\(\(\(real \|integer \|logical \|complex \|double \s*precision \)\s*\((\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\|type\s\+(\s*\w\+\s*) \|character \((\(\s*len\s*=\)\=\s*\d\+\s*)\|(\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\=\s*function\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|function\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule syn region fortranSubroutine transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*subroutine\s\+\z(\a\w*\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|subroutine\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule - syn region fortranBlockData transparent fold keepend start="\<block\s*data\(\s\+\z(\a\w*\)\)\=" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*\($\|block\s*data\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock + syn region fortranBlockData transparent fold keepend start="\<block\>" skip="^\s*[!#].*$" excludenl end="\<end\s*block\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock syn region fortranAssociate transparent fold keepend start="^\s*\<associate\s\+" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*associate" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction + syn region fortranCritical transparent fold keepend start="^\s*\<critical\s\+" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*critical" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction + syn region fortranTeam transparent fold keepend start="^\s*\<change\s\+team\>" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*team\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction syn region fortranInterface transparent fold keepend extend start="^\s*\(abstract \)\=\s*interface\>" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*interface\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock syn region fortranTypeDef transparent fold keepend extend start="^\s*type\s*\(,\s*\(public\|private\|abstract\)\)\=\s*::" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*type\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock,fortranInterface else @@ -361,8 +367,10 @@ if exists("fortran_fold") syn region fortranModule transparent fold keepend start="^\s*module\s\+\(procedure\)\@!\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\(module\(\s\+\z1\>\)\=\|$\)" contains=ALLBUT,fortranProgram syn region fortranFunction transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*\(\(\(real \|integer \|logical \|complex \|double \s*precision \)\s*\((\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\|type\s\+(\s*\w\+\s*) \|character \((\(\s*len\s*=\)\=\s*\d\+\s*)\|(\(\s*kind\s*=\)\=\s*\w\+\s*)\)\=\)\=\s*function\s\+\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|function\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule syn region fortranSubroutine transparent fold keepend extend start="^\s*\(elemental \|pure \|impure \|module \|recursive \)\=\s*subroutine\s\+\z(\a\w*\)" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|subroutine\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule - syn region fortranBlockData transparent fold keepend start="\<block\s*data\(\s\+\z(\a\w*\)\)\=" skip="^\s*[!#].*$" excludenl end="\<end\s*\($\|block\s*data\(\s\+\z1\>\)\=\)" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock - syn region fortranAssociate transparent fold keepend start="^\s*\<associate\s\+" skip="^\s*[!#].*$" excludenl end="\<end\s*associate" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction + syn region fortranBlockData transparent fold keepend start="\<block\>" skip="^\s*[!#].*$" excludenl end="\<end\s*block\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock + syn region fortranAssociate transparent fold keepend start="\<associate\>" skip="^\s*[!#].*$" excludenl end="\<end\s*associate\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction + syn region fortranCritical transparent fold keepend start="\<critical\>" skip="^\s*[!#].*$" excludenl end="\<end\s*critical\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction + syn region fortranTeam transparent fold keepend start="\<change\s\+team\>" skip="^\s*[!#].*$" excludenl end="\<end\s*team\>" contains=ALLBUT,fortranProgram,fortranModule,fortranSubroutine,fortranFunction syn region fortranInterface transparent fold keepend extend start="^\s*\(abstract \)\=\s*interface\>" skip="^\s*[!#].*$" excludenl end="\<end\s*interface\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock syn region fortranTypeDef transparent fold keepend extend start="^\s*type\s*\(,\s*\(public\|private\|abstract\)\)\=\s*::" skip="^\s*[!#].*$" excludenl end="\<end\s*type\>" contains=ALLBUT,fortranProgram,fortranModule,fortran77Loop,fortranCase,fortran90Loop,fortranIfBlock,fortranInterface endif @@ -372,12 +380,12 @@ if exists("fortran_fold") syn region fortran77Loop transparent fold keepend start="\<do\s\+\z(\d\+\)" end="^\s*\z1\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData syn region fortran90Loop transparent fold keepend extend start="\(\<end\s\+\)\@<!\<do\(\s\+\a\|\s*$\)" skip="^\([!c*]\|\s*#\).*$" excludenl end="\<end\s*do\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData syn region fortranIfBlock transparent fold keepend extend start="\(\<e\(nd\|lse\)\s\+\)\@<!\<if\s*(.\+)\s*then\>" skip="^\([!c*]\|\s*#\).*$" end="\<end\s*if\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData - syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\)\>" skip="^\([!c*]\|\s*#\).*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData + syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\|rank\)\>" skip="^\([!c*]\|\s*#\).*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData else syn region fortran77Loop transparent fold keepend start="\<do\s\+\z(\d\+\)" end="^\s*\z1\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData syn region fortran90Loop transparent fold keepend extend start="\(\<end\s\+\)\@<!\<do\(\s\+\a\|\s*$\)" skip="^\s*[!#].*$" excludenl end="\<end\s*do\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData syn region fortranIfBlock transparent fold keepend extend start="\(\<e\(nd\|lse\)\s\+\)\@<!\<if\s*(\(.\|&\s*\n\)\+)\(\s\|&\s*\n\)*then\>" skip="^\s*[!#].*$" end="\<end\s*if\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData - syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\)\>" skip="^\s*[!#].*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData + syn region fortranCase transparent fold keepend extend start="\<select\s*\(case\|type\|rank\)\>" skip="^\s*[!#].*$" end="\<end\s*select\>" contains=ALLBUT,fortranUnitHeader,fortranAttribute,fortranStorageClass,fortranType,fortranProgram,fortranModule,fortranSubroutine,fortranFunction,fortranBlockData endif endif diff --git a/src/clint.py b/src/clint.py index 32ed81f95c..2659abbb0e 100755 --- a/src/clint.py +++ b/src/clint.py @@ -912,7 +912,6 @@ def CheckIncludes(filename, lines, error): "src/nvim/globals.h", "src/nvim/grid.h", "src/nvim/highlight.h", - "src/nvim/keycodes.h", "src/nvim/lua/executor.h", "src/nvim/main.h", "src/nvim/mark.h", diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index aed286165a..860cca582c 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -461,7 +461,7 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt, Bool } char *ptr = NULL; - replace_termcodes(str.data, str.size, &ptr, 0, flags, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(str.data, str.size, &ptr, 0, flags, NULL, p_cpo); return cstr_as_string(ptr); } diff --git a/src/nvim/drawline.h b/src/nvim/drawline.h index 97a6ca2eee..9112deddb3 100644 --- a/src/nvim/drawline.h +++ b/src/nvim/drawline.h @@ -4,7 +4,6 @@ #include <stdint.h> #include "klib/kvec.h" -#include "nvim/decoration_defs.h" // IWYU pragma: keep #include "nvim/fold_defs.h" // IWYU pragma: keep #include "nvim/macros_defs.h" #include "nvim/pos_defs.h" diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a0e9b537e8..9abe347e94 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1486,7 +1486,7 @@ void print_line(linenr_T lnum, int use_number, int list) msg_start(); silent_mode = false; - info_message = true; // use os_msg(), not os_errmsg() + info_message = true; // use stdout, not stderr print_line_no_prefix(lnum, use_number, list); if (save_silent) { msg_putchar('\n'); diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 301c3846e7..d913beeb0c 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -852,8 +852,8 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER. /// /// When "flags" has REPTERM_FROM_PART, trailing <C-v> is included, otherwise it is removed (to make -/// ":map xx ^V" map xx to nothing). When cpo_flags contains FLAG_CPO_BSLASH, a backslash can be -/// used in place of <C-v>. All other <C-v> characters are removed. +/// ":map xx ^V" map xx to nothing). When cpo_val contains CPO_BSLASH, a backslash can be used in +/// place of <C-v>. All other <C-v> characters are removed. /// /// @param[in] from What characters to replace. /// @param[in] from_len Length of the "from" argument. @@ -867,20 +867,21 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// REPTERM_NO_SPECIAL do not accept <key> notation /// REPTERM_NO_SIMPLIFY do not simplify <C-H> into 0x08, etc. /// @param[out] did_simplify set when some <C-H> code was simplified, unless it is NULL. -/// @param[in] cpo_flags Relevant flags derived from p_cpo, see CPO_TO_CPO_FLAGS. +/// @param[in] cpo_val The value of 'cpoptions' to use. Only CPO_BSLASH matters. /// /// @return The same as what `*bufp` is set to. char *replace_termcodes(const char *const from, const size_t from_len, char **const bufp, const scid_T sid_arg, const int flags, bool *const did_simplify, - const int cpo_flags) - FUNC_ATTR_NONNULL_ARG(1, 3) + const char *const cpo_val) + FUNC_ATTR_NONNULL_ARG(1, 3, 7) { char key; size_t dlen = 0; const char *src; const char *const end = from + from_len - 1; - const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character + // backslash is a special character + const bool do_backslash = (vim_strchr(cpo_val, CPO_BSLASH) == NULL); const bool do_special = !(flags & REPTERM_NO_SPECIAL); bool allocated = (*bufp == NULL); diff --git a/src/nvim/keycodes.h b/src/nvim/keycodes.h index fafe205f4d..6aebad5b66 100644 --- a/src/nvim/keycodes.h +++ b/src/nvim/keycodes.h @@ -4,7 +4,6 @@ #include "nvim/ascii_defs.h" #include "nvim/eval/typval_defs.h" // IWYU pragma: keep -#include "nvim/option_vars.h" // Keycode definitions for special keys. // @@ -475,11 +474,6 @@ enum key_extra { /// This is a total of 6 tokens, and is currently the longest one possible. #define MAX_KEY_CODE_LEN 6 -#define FLAG_CPO_BSLASH 0x01 -#define CPO_TO_CPO_FLAGS ((vim_strchr((char *)p_cpo, CPO_BSLASH) == NULL) \ - ? 0 \ - : FLAG_CPO_BSLASH) - /// Flags for replace_termcodes() enum { REPTERM_FROM_PART = 1, diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 3e7cdd002e..6289ea3193 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -252,8 +252,7 @@ static int nlua_luv_thread_common_cfpcall(lua_State *lstate, int nargs, int nres if (status == LUA_ERRMEM && !(flags & LUVF_CALLBACK_NOEXIT)) { // Terminate this thread, as the main thread may be able to continue // execution. - os_errmsg(e_outofmem); - os_errmsg("\n"); + fprintf(stderr, "%s\n", e_outofmem); lua_close(lstate); #ifdef MSWIN ExitThread(0); @@ -640,8 +639,7 @@ static bool nlua_init_packages(lua_State *lstate, bool is_standalone) lua_getglobal(lstate, "require"); lua_pushstring(lstate, "vim._init_packages"); if (nlua_pcall(lstate, 1, 0)) { - os_errmsg(lua_tostring(lstate, -1)); - os_errmsg("\n"); + fprintf(stderr, "%s\n", lua_tostring(lstate, -1)); return false; } @@ -815,12 +813,12 @@ void nlua_init(char **argv, int argc, int lua_arg0) lua_State *lstate = luaL_newstate(); if (lstate == NULL) { - os_errmsg(_("E970: Failed to initialize lua interpreter\n")); + fprintf(stderr, _("E970: Failed to initialize lua interpreter\n")); os_exit(1); } luaL_openlibs(lstate); if (!nlua_state_init(lstate)) { - os_errmsg(_("E970: Failed to initialize builtin lua modules\n")); + fprintf(stderr, _("E970: Failed to initialize builtin lua modules\n")); #ifdef EXITFREE nlua_common_free_all_mem(lstate); #endif @@ -2307,8 +2305,7 @@ void nlua_init_defaults(void) lua_getglobal(L, "require"); lua_pushstring(L, "vim._defaults"); if (nlua_pcall(L, 1, 0)) { - os_errmsg(lua_tostring(L, -1)); - os_errmsg("\n"); + fprintf(stderr, "%s\n", lua_tostring(L, -1)); } } diff --git a/src/nvim/main.c b/src/nvim/main.c index dfa7c685a0..f01b6ecc8d 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -247,7 +247,7 @@ int main(int argc, char **argv) argv0 = argv[0]; if (!appname_is_valid()) { - os_errmsg("$NVIM_APPNAME must be a name or relative path.\n"); + fprintf(stderr, "$NVIM_APPNAME must be a name or relative path.\n"); exit(1); } @@ -336,7 +336,7 @@ int main(int argc, char **argv) ui_client_forward_stdin = !stdin_isatty; uint64_t rv = ui_client_start_server(params.argc, params.argv); if (!rv) { - os_errmsg("Failed to start Nvim server!\n"); + fprintf(stderr, "Failed to start Nvim server!\n"); os_exit(1); } ui_client_channel_id = rv; @@ -823,8 +823,7 @@ void preserve_exit(const char *errmsg) ui_client_stop(); } if (errmsg != NULL) { - os_errmsg(errmsg); - os_errmsg("\n"); + fprintf(stderr, "%s\n", errmsg); } if (ui_client_channel_id) { os_exit(1); @@ -835,7 +834,7 @@ void preserve_exit(const char *errmsg) FOR_ALL_BUFFERS(buf) { if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) { if (errmsg != NULL) { - os_errmsg("Vim: preserving files...\r\n"); + fprintf(stderr, "Vim: preserving files...\r\n"); } ml_sync_all(false, false, true); // preserve all swap files break; @@ -845,7 +844,7 @@ void preserve_exit(const char *errmsg) ml_close_all(false); // close all memfiles, without deleting if (errmsg != NULL) { - os_errmsg("Vim: Finished.\r\n"); + fprintf(stderr, "Vim: Finished.\r\n"); } getout(1); @@ -910,14 +909,11 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr, if (is_ui) { if (!chan) { - os_errmsg("Remote ui failed to start: "); - os_errmsg(connect_error); - os_errmsg("\n"); + fprintf(stderr, "Remote ui failed to start: %s\n", connect_error); os_exit(1); } else if (strequal(server_addr, os_getenv("NVIM"))) { - os_errmsg("Cannot attach UI of :terminal child to its parent. "); - os_errmsg("(Unset $NVIM to skip this check)"); - os_errmsg("\n"); + fprintf(stderr, "%s", "Cannot attach UI of :terminal child to its parent. "); + fprintf(stderr, "%s\n", "(Unset $NVIM to skip this check)"); os_exit(1); } @@ -941,15 +937,14 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr, Object o = nlua_exec(s, a, &err); api_free_array(a); if (ERROR_SET(&err)) { - os_errmsg(err.msg); - os_errmsg("\n"); + fprintf(stderr, "%s\n", err.msg); os_exit(2); } if (o.type == kObjectTypeDictionary) { rvobj.data.dictionary = o.data.dictionary; } else { - os_errmsg("vim._cs_remote returned unexpected value\n"); + fprintf(stderr, "vim._cs_remote returned unexpected value\n"); os_exit(2); } @@ -959,34 +954,33 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr, for (size_t i = 0; i < rvobj.data.dictionary.size; i++) { if (strequal(rvobj.data.dictionary.items[i].key.data, "errmsg")) { if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) { - os_errmsg("vim._cs_remote returned an unexpected type for 'errmsg'\n"); + fprintf(stderr, "vim._cs_remote returned an unexpected type for 'errmsg'\n"); os_exit(2); } - os_errmsg(rvobj.data.dictionary.items[i].value.data.string.data); - os_errmsg("\n"); + fprintf(stderr, "%s\n", rvobj.data.dictionary.items[i].value.data.string.data); os_exit(2); } else if (strequal(rvobj.data.dictionary.items[i].key.data, "result")) { if (rvobj.data.dictionary.items[i].value.type != kObjectTypeString) { - os_errmsg("vim._cs_remote returned an unexpected type for 'result'\n"); + fprintf(stderr, "vim._cs_remote returned an unexpected type for 'result'\n"); os_exit(2); } - os_msg(rvobj.data.dictionary.items[i].value.data.string.data); + printf("%s", rvobj.data.dictionary.items[i].value.data.string.data); } else if (strequal(rvobj.data.dictionary.items[i].key.data, "tabbed")) { if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) { - os_errmsg("vim._cs_remote returned an unexpected type for 'tabbed'\n"); + fprintf(stderr, "vim._cs_remote returned an unexpected type for 'tabbed'\n"); os_exit(2); } tabbed = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse; } else if (strequal(rvobj.data.dictionary.items[i].key.data, "should_exit")) { if (rvobj.data.dictionary.items[i].value.type != kObjectTypeBoolean) { - os_errmsg("vim._cs_remote returned an unexpected type for 'should_exit'\n"); + fprintf(stderr, "vim._cs_remote returned an unexpected type for 'should_exit'\n"); os_exit(2); } should_exit = rvobj.data.dictionary.items[i].value.data.boolean ? kTrue : kFalse; } } if (should_exit == kNone || tabbed == kNone) { - os_errmsg("vim._cs_remote didn't return a value for should_exit or tabbed, bailing\n"); + fprintf(stderr, "vim._cs_remote didn't return a value for should_exit or tabbed, bailing\n"); os_exit(2); } api_free_object(o); @@ -1377,7 +1371,7 @@ scripterror: vim_snprintf(IObuff, IOSIZE, _("Attempt to open script file again: \"%s %s\"\n"), argv[-1], argv[0]); - os_errmsg(IObuff); + fprintf(stderr, "%s", IObuff); os_exit(2); } parmp->scriptin = argv[0]; @@ -1614,7 +1608,7 @@ static void open_script_files(mparm_T *parmp) vim_snprintf(IObuff, IOSIZE, _("Cannot open for reading: \"%s\": %s\n"), parmp->scriptin, os_strerror(error)); - os_errmsg(IObuff); + fprintf(stderr, "%s", IObuff); os_exit(2); } } @@ -1624,9 +1618,8 @@ static void open_script_files(mparm_T *parmp) if (parmp->scriptout) { scriptout = os_fopen(parmp->scriptout, parmp->scriptout_append ? APPENDBIN : WRITEBIN); if (scriptout == NULL) { - os_errmsg(_("Cannot open for script output: \"")); - os_errmsg(parmp->scriptout); - os_errmsg("\"\n"); + fprintf(stderr, _("Cannot open for script output: \"")); + fprintf(stderr, "%s\"\n", parmp->scriptout); os_exit(2); } } @@ -2158,17 +2151,12 @@ static void print_mainerr(const char *errstr, const char *str) signal_stop(); // kill us with CTRL-C here, if you like - os_errmsg(prgname); - os_errmsg(": "); - os_errmsg(_(errstr)); + fprintf(stderr, "%s: %s", prgname, _(errstr)); if (str != NULL) { - os_errmsg(": \""); - os_errmsg(str); - os_errmsg("\""); + fprintf(stderr, ": \"%s\"", str); } - os_errmsg(_("\nMore info with \"")); - os_errmsg(prgname); - os_errmsg(" -h\"\n"); + fprintf(stderr, _("\nMore info with \"")); + fprintf(stderr, "%s -h\"\n", prgname); } /// Prints version information for "nvim -v" or "nvim --version". @@ -2176,7 +2164,7 @@ static void version(void) { // TODO(bfred): not like this? nlua_init(NULL, 0, -1); - info_message = true; // use os_msg(), not os_errmsg() + info_message = true; // use stdout, not stderr list_version(); msg_putchar('\n'); msg_didout = false; @@ -2187,38 +2175,38 @@ static void usage(void) { signal_stop(); // kill us with CTRL-C here, if you like - os_msg(_("Usage:\n")); - os_msg(_(" nvim [options] [file ...]\n")); - os_msg(_("\nOptions:\n")); - os_msg(_(" --cmd <cmd> Execute <cmd> before any config\n")); - os_msg(_(" +<cmd>, -c <cmd> Execute <cmd> after config and first file\n")); - os_msg(_(" -l <script> [args...] Execute Lua <script> (with optional args)\n")); - os_msg(_(" -S <session> Source <session> after loading the first file\n")); - os_msg(_(" -s <scriptin> Read Normal mode commands from <scriptin>\n")); - os_msg(_(" -u <config> Use this config file\n")); - os_msg("\n"); - os_msg(_(" -d Diff mode\n")); - os_msg(_(" -es, -Es Silent (batch) mode\n")); - os_msg(_(" -h, --help Print this help message\n")); - os_msg(_(" -i <shada> Use this shada file\n")); - os_msg(_(" -n No swap file, use memory only\n")); - os_msg(_(" -o[N] Open N windows (default: one per file)\n")); - os_msg(_(" -O[N] Open N vertical windows (default: one per file)\n")); - os_msg(_(" -p[N] Open N tab pages (default: one per file)\n")); - os_msg(_(" -R Read-only (view) mode\n")); - os_msg(_(" -v, --version Print version information\n")); - os_msg(_(" -V[N][file] Verbose [level][file]\n")); - os_msg("\n"); - os_msg(_(" -- Only file names after this\n")); - os_msg(_(" --api-info Write msgpack-encoded API metadata to stdout\n")); - os_msg(_(" --clean \"Factory defaults\" (skip user config and plugins, shada)\n")); - os_msg(_(" --embed Use stdin/stdout as a msgpack-rpc channel\n")); - os_msg(_(" --headless Don't start a user interface\n")); - os_msg(_(" --listen <address> Serve RPC API from this address\n")); - os_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n")); - os_msg(_(" --server <address> Specify RPC server to send commands to\n")); - os_msg(_(" --startuptime <file> Write startup timing messages to <file>\n")); - os_msg(_("\nSee \":help startup-options\" for all options.\n")); + printf(_("Usage:\n")); + printf(_(" nvim [options] [file ...]\n")); + printf(_("\nOptions:\n")); + printf(_(" --cmd <cmd> Execute <cmd> before any config\n")); + printf(_(" +<cmd>, -c <cmd> Execute <cmd> after config and first file\n")); + printf(_(" -l <script> [args...] Execute Lua <script> (with optional args)\n")); + printf(_(" -S <session> Source <session> after loading the first file\n")); + printf(_(" -s <scriptin> Read Normal mode commands from <scriptin>\n")); + printf(_(" -u <config> Use this config file\n")); + printf("\n"); + printf(_(" -d Diff mode\n")); + printf(_(" -es, -Es Silent (batch) mode\n")); + printf(_(" -h, --help Print this help message\n")); + printf(_(" -i <shada> Use this shada file\n")); + printf(_(" -n No swap file, use memory only\n")); + printf(_(" -o[N] Open N windows (default: one per file)\n")); + printf(_(" -O[N] Open N vertical windows (default: one per file)\n")); + printf(_(" -p[N] Open N tab pages (default: one per file)\n")); + printf(_(" -R Read-only (view) mode\n")); + printf(_(" -v, --version Print version information\n")); + printf(_(" -V[N][file] Verbose [level][file]\n")); + printf("\n"); + printf(_(" -- Only file names after this\n")); + printf(_(" --api-info Write msgpack-encoded API metadata to stdout\n")); + printf(_(" --clean \"Factory defaults\" (skip user config and plugins, shada)\n")); + printf(_(" --embed Use stdin/stdout as a msgpack-rpc channel\n")); + printf(_(" --headless Don't start a user interface\n")); + printf(_(" --listen <address> Serve RPC API from this address\n")); + printf(_(" --remote[-subcommand] Execute commands remotely on a server\n")); + printf(_(" --server <address> Specify RPC server to send commands to\n")); + printf(_(" --startuptime <file> Write startup timing messages to <file>\n")); + printf(_("\nSee \":help startup-options\" for all options.\n")); } // Check the result of the ATTENTION dialog: diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index cb50050344..63604352cf 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -303,11 +303,11 @@ static void showmap(mapblock_T *mp, bool local) /// @param[in] orig_rhs Original mapping RHS, with characters to replace. /// @param[in] rhs_lua Lua reference for Lua mappings. /// @param[in] orig_rhs_len `strlen` of orig_rhs. -/// @param[in] cpo_flags See param docs for @ref replace_termcodes. +/// @param[in] cpo_val See param docs for @ref replace_termcodes. /// @param[out] mapargs MapArguments struct holding the replaced strings. static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs_len, const char *const orig_rhs, const size_t orig_rhs_len, - const LuaRef rhs_lua, const int cpo_flags, + const LuaRef rhs_lua, const char *const cpo_val, MapArguments *const mapargs) { char lhs_buf[128]; @@ -324,7 +324,7 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs const int flags = REPTERM_FROM_PART | REPTERM_DO_LT; char *bufarg = lhs_buf; char *replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, 0, - flags, &did_simplify, cpo_flags); + flags, &did_simplify, cpo_val); if (replaced == NULL) { return false; } @@ -332,7 +332,7 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs xstrlcpy(mapargs->lhs, replaced, sizeof(mapargs->lhs)); if (did_simplify) { replaced = replace_termcodes(orig_lhs, orig_lhs_len, &bufarg, 0, - flags | REPTERM_NO_SIMPLIFY, NULL, cpo_flags); + flags | REPTERM_NO_SIMPLIFY, NULL, cpo_val); if (replaced == NULL) { return false; } @@ -342,14 +342,14 @@ static bool set_maparg_lhs_rhs(const char *const orig_lhs, const size_t orig_lhs mapargs->alt_lhs_len = 0; } - set_maparg_rhs(orig_rhs, orig_rhs_len, rhs_lua, 0, cpo_flags, mapargs); + set_maparg_rhs(orig_rhs, orig_rhs_len, rhs_lua, 0, cpo_val, mapargs); return true; } /// @see set_maparg_lhs_rhs static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len, - const LuaRef rhs_lua, const scid_T sid, const int cpo_flags, + const LuaRef rhs_lua, const scid_T sid, const char *const cpo_val, MapArguments *const mapargs) { mapargs->rhs_lua = rhs_lua; @@ -365,7 +365,7 @@ static void set_maparg_rhs(const char *const orig_rhs, const size_t orig_rhs_len } else { char *rhs_buf = NULL; char *replaced = replace_termcodes(orig_rhs, orig_rhs_len, &rhs_buf, sid, - REPTERM_DO_LT, NULL, cpo_flags); + REPTERM_DO_LT, NULL, cpo_val); mapargs->rhs_len = strlen(replaced); // NB: replace_termcodes may produce an empty string even if orig_rhs is non-empty // (e.g. a single ^V, see :h map-empty-rhs) @@ -492,7 +492,7 @@ static int str_to_mapargs(const char *strargs, bool is_unmap, MapArguments *mapa size_t orig_rhs_len = strlen(rhs_start); if (!set_maparg_lhs_rhs(lhs_to_replace, orig_lhs_len, rhs_start, orig_rhs_len, LUA_NOREF, - CPO_TO_CPO_FLAGS, mapargs)) { + p_cpo, mapargs)) { return 1; } @@ -1103,7 +1103,7 @@ bool map_to_exists(const char *const str, const char *const modechars, const boo char *buf = NULL; const char *const rhs = replace_termcodes(str, strlen(str), &buf, 0, - REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); + REPTERM_DO_LT, NULL, p_cpo); #define MAPMODE(mode, modechars, chr, modeflags) \ do { \ @@ -1189,16 +1189,16 @@ static bool expand_buffer = false; /// wider than the original description. The caller has to free the string /// afterwards. /// -/// @param cpo_flags Value of various flags present in &cpo +/// @param[in] cpo_val See param docs for @ref replace_termcodes. /// /// @return NULL when there is a problem. -static char *translate_mapping(char *str_in, int cpo_flags) +static char *translate_mapping(const char *const str_in, const char *const cpo_val) { - uint8_t *str = (uint8_t *)str_in; + const uint8_t *str = (const uint8_t *)str_in; garray_T ga; ga_init(&ga, 1, 40); - bool cpo_bslash = cpo_flags & FLAG_CPO_BSLASH; + const bool cpo_bslash = (vim_strchr(cpo_val, CPO_BSLASH) != NULL); for (; *str; str++) { int c = *str; @@ -1377,7 +1377,7 @@ int ExpandMappings(char *pat, regmatch_T *regmatch, int *numMatches, char ***mat continue; } - char *p = translate_mapping(mp->m_keys, CPO_TO_CPO_FLAGS); + char *p = translate_mapping(mp->m_keys, p_cpo); if (p == NULL) { continue; } @@ -1677,7 +1677,7 @@ char *eval_map_expr(mapblock_T *mp, int c) char *res = NULL; if (replace_keycodes) { - replace_termcodes(p, strlen(p), &res, 0, REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(p, strlen(p), &res, 0, REPTERM_DO_LT, NULL, p_cpo); } else { // Escape K_SPECIAL in the result to be able to use the string as typeahead. res = vim_strsave_escape_ks(p); @@ -2168,7 +2168,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) const int mode = get_map_mode((char **)&which, 0); char *keys_simplified = replace_termcodes(keys, strlen(keys), &keys_buf, 0, - flags, &did_simplify, CPO_TO_CPO_FLAGS); + flags, &did_simplify, p_cpo); mapblock_T *mp = NULL; int buffer_local; LuaRef rhs_lua; @@ -2178,7 +2178,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) // When the lhs is being simplified the not-simplified keys are // preferred for printing, like in do_map(). (void)replace_termcodes(keys, strlen(keys), &alt_keys_buf, 0, - flags | REPTERM_NO_SIMPLIFY, NULL, CPO_TO_CPO_FLAGS); + flags | REPTERM_NO_SIMPLIFY, NULL, p_cpo); rhs = check_map(alt_keys_buf, mode, exact, false, abbr, &mp, &buffer_local, &rhs_lua); } @@ -2343,14 +2343,14 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) bool buffer = tv_dict_get_number(d, "buffer") != 0; // mode from the dict is not used - set_maparg_rhs(orig_rhs, strlen(orig_rhs), rhs_lua, sid, CPO_TO_CPO_FLAGS, &args); + set_maparg_rhs(orig_rhs, strlen(orig_rhs), rhs_lua, sid, p_cpo, &args); mapblock_T **map_table = buffer ? curbuf->b_maphash : maphash; mapblock_T **abbr_table = buffer ? &curbuf->b_first_abbr : &first_abbr; // Delete any existing mapping for this lhs and mode. MapArguments unmap_args = MAP_ARGUMENTS_INIT; - set_maparg_lhs_rhs(lhs, strlen(lhs), "", 0, LUA_NOREF, 0, &unmap_args); + set_maparg_lhs_rhs(lhs, strlen(lhs), "", 0, LUA_NOREF, p_cpo, &unmap_args); unmap_args.buffer = buffer; buf_do_map(MAPTYPE_UNMAP, &unmap_args, mode, is_abbr, curbuf); xfree(unmap_args.rhs); @@ -2400,7 +2400,7 @@ void f_maplist(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) char *lhs = str2special_save(mp->m_keys, true, false); (void)replace_termcodes(lhs, strlen(lhs), &keys_buf, 0, flags, &did_simplify, - CPO_TO_CPO_FLAGS); + p_cpo); xfree(lhs); Dictionary dict = mapblock_fill_dict(mp, @@ -2440,7 +2440,7 @@ void f_mapcheck(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void add_map(char *lhs, char *rhs, int mode, bool buffer) { MapArguments args = MAP_ARGUMENTS_INIT; - set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, 0, &args); + set_maparg_lhs_rhs(lhs, strlen(lhs), rhs, strlen(rhs), LUA_NOREF, p_cpo, &args); args.buffer = buffer; buf_do_map(MAPTYPE_NOREMAP, &args, mode, false, curbuf); @@ -2720,7 +2720,7 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod if (!set_maparg_lhs_rhs(lhs.data, lhs.size, rhs.data, rhs.size, lua_funcref, - CPO_TO_CPO_FLAGS, &parsed_args)) { + p_cpo, &parsed_args)) { api_set_error(err, kErrorTypeValidation, "LHS exceeds maximum map length: %s", lhs.data); goto fail_and_free; } diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 383c9e7817..c4486222a5 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -226,7 +226,7 @@ void ex_menu(exarg_T *eap) } else { map_buf = NULL; map_to = replace_termcodes(map_to, strlen(map_to), &map_buf, 0, - REPTERM_DO_LT, NULL, CPO_TO_CPO_FLAGS); + REPTERM_DO_LT, NULL, p_cpo); } menuarg.modes = modes; menuarg.noremap[0] = noremap; diff --git a/src/nvim/message.c b/src/nvim/message.c index 895fba1372..2c0e8064fb 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -225,7 +225,7 @@ int verb_msg(const char *s) } /// Displays the string 's' on the status line -/// When terminal not initialized (yet) os_errmsg(..) is used. +/// When terminal not initialized (yet) printf("%s", ..) is used. /// /// @return true if wait_return() not called int msg(const char *s, const int attr) @@ -748,7 +748,7 @@ bool emsg_multiline(const char *s, bool multiline) /// emsg() - display an error message /// /// Rings the bell, if appropriate, and calls message() to do the real work -/// When terminal not initialized (yet) os_errmsg(..) is used. +/// When terminal not initialized (yet) fprintf(stderr, "%s", ..) is used. /// /// @return true if wait_return() not called bool emsg(const char *s) @@ -2635,9 +2635,9 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen) memcpy(p, s, (size_t)len); *(p + len) = '\0'; if (info_message) { - os_msg(buf); + printf("%s", buf); } else { - os_errmsg(buf); + fprintf(stderr, "%s", buf); } } @@ -2899,40 +2899,6 @@ static bool do_more_prompt(int typed_char) return retval; } -#if defined(MSWIN) -/// Headless (no UI) error message handler. -static void do_msg(const char *str, bool errmsg) -{ - static bool did_err = false; - assert(str != NULL); - wchar_t *utf16str; - int r = utf8_to_utf16(str, -1, &utf16str); - if (r != 0 && !did_err) { - did_err = true; - fprintf(stderr, "utf8_to_utf16 failed: %d", r); - ELOG("utf8_to_utf16 failed: %d", r); - } else if (r == 0) { - if (errmsg) { - fwprintf(stderr, L"%ls", utf16str); - } else { - wprintf(L"%ls", utf16str); - } - xfree(utf16str); - } -} - -void os_errmsg(const char *str) -{ - do_msg(str, true); -} - -/// Headless (no UI) message handler. -void os_msg(const char *str) -{ - do_msg(str, false); -} -#endif // MSWIN - void msg_moremsg(int full) { int attr = hl_combine_attr(HL_ATTR(HLF_MSG), HL_ATTR(HLF_M)); diff --git a/src/nvim/message.h b/src/nvim/message.h index 63d43fe47e..66165a3263 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -65,10 +65,3 @@ EXTERN int msg_listdo_overwrite INIT( = 0); // Prefer using semsg(), because perror() may send the output to the wrong // destination and mess up the screen. #define PERROR(msg) (void)semsg("%s: %s", (msg), strerror(errno)) - -#ifndef MSWIN -/// Headless (no UI) error message handler. -# define os_errmsg(str) fprintf(stderr, "%s", (str)) -/// Headless (no UI) message handler. -# define os_msg(str) printf("%s", (str)) -#endif diff --git a/src/nvim/option.c b/src/nvim/option.c index b86694ba85..2c5f18a5e1 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1487,10 +1487,10 @@ int do_set(char *arg, int opt_flags) if (silent_mode && did_show) { // After displaying option values in silent mode. silent_mode = false; - info_message = true; // use os_msg(), not os_errmsg() + info_message = true; // use stdout, not stderr msg_putchar('\n'); silent_mode = true; - info_message = false; // use os_msg(), not os_errmsg() + info_message = false; // use stdout, not stderr } return OK; @@ -4176,7 +4176,7 @@ static void showoneopt(vimoption_T *opt, int opt_flags) int save_silent = silent_mode; silent_mode = false; - info_message = true; // use os_msg(), not os_errmsg() + info_message = true; // use stdout, not stderr OptIndex opt_idx = get_opt_idx(opt); void *varp = get_varp_scope(opt, opt_flags); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 87f28a4379..d8bfc64c06 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -5865,8 +5865,8 @@ static bool regmatch(uint8_t *scan, const proftime_T *tm, int *timed_out) #ifdef REGEXP_DEBUG if (scan != NULL && regnarrate) { - os_errmsg((char *)regprop(scan)); - os_errmsg("(\n"); + fprintf(stderr, "%s", (char *)regprop(scan)); + fprintf(stderr, "%s", "(\n"); } #endif @@ -5892,18 +5892,18 @@ static bool regmatch(uint8_t *scan, const proftime_T *tm, int *timed_out) #ifdef REGEXP_DEBUG if (regnarrate) { - os_errmsg((char *)regprop(scan)); - os_errmsg("...\n"); + fprintf(stderr, "%s", (char *)regprop(scan)); + fprintf(stderr, "%s", "...\n"); if (re_extmatch_in != NULL) { int i; - os_errmsg(_("External submatches:\n")); + fprintf(stderr, _("External submatches:\n")); for (i = 0; i < NSUBEXP; i++) { - os_errmsg(" \""); + fprintf(stderr, "%s", " \""); if (re_extmatch_in->matches[i] != NULL) { - os_errmsg((char *)re_extmatch_in->matches[i]); + fprintf(stderr, "%s", (char *)re_extmatch_in->matches[i]); } - os_errmsg("\"\n"); + fprintf(stderr, "%s", "\"\n"); } } } diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 86c0dc8367..148620865a 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -872,7 +872,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, char *rep_buf = NULL; garray_T *gap; - replace_termcodes(rep, strlen(rep), &rep_buf, 0, 0, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(rep, strlen(rep), &rep_buf, 0, 0, NULL, p_cpo); if (rep_buf == NULL) { // Can't replace termcodes - try using the string as is rep_buf = xstrdup(rep); diff --git a/test/functional/vimscript/map_functions_spec.lua b/test/functional/vimscript/map_functions_spec.lua index acba5e9708..e3cc653e12 100644 --- a/test/functional/vimscript/map_functions_spec.lua +++ b/test/functional/vimscript/map_functions_spec.lua @@ -180,6 +180,16 @@ end) describe('mapset()', function() before_each(clear) + it('can restore mapping with backslash in lhs', function() + meths.set_keymap('n', '\\ab', 'a', {}) + eq('\nn \\ab a', exec_capture("nmap \\ab")) + local mapargs = funcs.maparg('\\ab', 'n', false, true) + meths.set_keymap('n', '\\ab', 'b', {}) + eq('\nn \\ab b', exec_capture("nmap \\ab")) + funcs.mapset('n', false, mapargs) + eq('\nn \\ab a', exec_capture("nmap \\ab")) + end) + it('can restore mapping description from the dict returned by maparg()', function() meths.set_keymap('n', 'lhs', 'rhs', {desc = 'map description'}) eq('\nn lhs rhs\n map description', exec_capture("nmap lhs")) |