diff options
116 files changed, 978 insertions, 735 deletions
diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index e7ffdd66b6..698dfa3b3a 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -22,5 +22,5 @@ runs: with: path: .deps key: ${{ env.CACHE_KEY }}-${{ steps.image.outputs.version }}-${{ hashFiles('cmake**', - '.github/workflows/test.yml', 'CMakeLists.txt', + '.github/**', 'CMakeLists.txt', 'runtime/CMakeLists.txt', 'src/nvim/**/CMakeLists.txt') }} diff --git a/.github/scripts/install_deps.sh b/.github/scripts/install_deps.sh index 05e07bda1d..bcc9789908 100755 --- a/.github/scripts/install_deps.sh +++ b/.github/scripts/install_deps.sh @@ -13,6 +13,22 @@ os=$(uname -s) if [[ $os == Linux ]]; then sudo apt-get update sudo apt-get install -y attr build-essential cmake curl gettext libattr1-dev ninja-build unzip + + if [[ $CC == clang ]]; then + DEFAULT_CLANG_VERSION=$(echo | clang -dM -E - | grep __clang_major | awk '{print $3}') + CLANG_VERSION=17 + if ((DEFAULT_CLANG_VERSION >= CLANG_VERSION)); then + echo "Default clang version is $DEFAULT_CLANG_VERSION, which equal or larger than wanted version $CLANG_VERSION. Aborting!" + exit 1 + fi + + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh $CLANG_VERSION + sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-$CLANG_VERSION 100 + sudo update-alternatives --set clang /usr/bin/clang-$CLANG_VERSION + fi + if [[ -n $TEST ]]; then sudo apt-get install -y locales-all cpanminus fi diff --git a/.github/scripts/reviews.js b/.github/scripts/reviews.js index 3e5394c4bd..8fae929421 100644 --- a/.github/scripts/reviews.js +++ b/.github/scripts/reviews.js @@ -64,6 +64,10 @@ module.exports = async ({ github, context }) => { reviewers.add("mfussenegger"); } + if (labels.includes("options")) { + reviewers.add("famiu"); + } + if (labels.includes("platform:nix")) { reviewers.add("teto"); } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 585e0223f0..aed079cb60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,8 @@ jobs: lint: runs-on: ubuntu-22.04 timeout-minutes: 10 + env: + CC: clang steps: - uses: actions/checkout@v4 @@ -52,8 +54,7 @@ jobs: cmake -S cmake.deps -B .deps -G Ninja cmake --build .deps - - if: success() || failure() && steps.abort_job.outputs.status == 'success' - run: cmake -B build -G Ninja -D CI_LINT=ON + - run: cmake -B build -G Ninja -D CI_LINT=ON - if: "!cancelled()" name: Determine if run should be aborted @@ -77,12 +78,29 @@ jobs: run: cmake --build build --target lintc-clint - if: success() || failure() && steps.abort_job.outputs.status == 'success' + name: clang-tidy run: cmake --build build --target clang-tidy - if: success() || failure() && steps.abort_job.outputs.status == 'success' name: uncrustify run: cmake --build build --target lintc-uncrustify + clang-analyzer: + runs-on: ubuntu-22.04 + timeout-minutes: 20 + env: + CC: clang + steps: + - uses: actions/checkout@v4 + - run: ./.github/scripts/install_deps.sh + - uses: ./.github/actions/cache + - name: Build third-party deps + run: | + cmake -S cmake.deps -B .deps -G Ninja + cmake --build .deps + cmake -B build -G Ninja + - run: cmake --build build --target clang-analyzer + posix: name: ${{ matrix.runner }} ${{ matrix.flavor }} (cc=${{ matrix.cc }}) strategy: @@ -214,34 +232,6 @@ jobs: name: Show logs run: cat $(find "$LOG_DIR" -type f) - build-types: - runs-on: ubuntu-22.04 - timeout-minutes: 10 - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - run: ./.github/scripts/install_deps.sh - - - uses: ./.github/actions/cache - - - name: Build third-party deps - run: | - cmake -S cmake.deps -B .deps -G "Ninja Multi-Config" - cmake --build .deps - - - name: Configure - run: cmake -B build -G "Ninja Multi-Config" -D CMAKE_C_COMPILER=gcc -D CI_BUILD=ON - - - name: Release - run: cmake --build build --config Release - - - name: RelWithDebInfo - run: cmake --build build --config RelWithDebInfo - - - name: MinSizeRel - run: cmake --build build --config MinSizeRel - windows: runs-on: windows-2022 timeout-minutes: 45 @@ -307,9 +297,49 @@ jobs: cd test/old/testdir mingw32-make VERBOSE=1 + # This job tests the following things: + # - Check if Release, MinSizeRel and RelWithDebInfo compiles correctly. + # - Test the above build types with the GCC compiler specifically. + # Empirically the difference in warning levels between GCC and other + # compilers is particularly big. + # - Test if the build works with multi-config generators. We mostly use + # single-config generators so it's nice to have a small sanity check for + # multi-config. + build-types: + runs-on: ubuntu-22.04 + timeout-minutes: 10 + env: + CC: gcc + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: ./.github/scripts/install_deps.sh + + - uses: ./.github/actions/cache + + - name: Build third-party deps + run: | + cmake -S cmake.deps -B .deps -G "Ninja Multi-Config" + cmake --build .deps + + - name: Configure + run: cmake -B build -G "Ninja Multi-Config" -D CI_BUILD=ON + + - name: Release + run: cmake --build build --config Release + + - name: RelWithDebInfo + run: cmake --build build --config RelWithDebInfo + + - name: MinSizeRel + run: cmake --build build --config MinSizeRel + with-external-deps: runs-on: ubuntu-22.04 timeout-minutes: 10 + env: + CC: gcc steps: - uses: actions/checkout@v4 @@ -129,7 +129,7 @@ functionaltest-lua: | nvim $(BUILD_TOOL) -C build functionaltest FORMAT=formatc formatlua format -LINT=lintlua lintsh lintc clang-tidy lintcommit lint +LINT=lintlua lintsh lintc clang-tidy clang-analyzer lintcommit lint TEST=functionaltest unittest generated-sources benchmark $(FORMAT) $(LINT) $(TEST) doc: | build/.ran-cmake $(CMAKE_PRG) --build build --target $@ diff --git a/cmake.deps/deps.txt b/cmake.deps/deps.txt index bf12f1138c..6f6357aace 100644 --- a/cmake.deps/deps.txt +++ b/cmake.deps/deps.txt @@ -4,8 +4,8 @@ LIBUV_SHA256 7aa66be3413ae10605e1f5c9ae934504ffe317ef68ea16fdaa83e23905c681bd MSGPACK_URL https://github.com/msgpack/msgpack-c/releases/download/c-6.0.0/msgpack-c-6.0.0.tar.gz MSGPACK_SHA256 3654f5e2c652dc52e0a993e270bb57d5702b262703f03771c152bba51602aeba -LUAJIT_URL https://github.com/LuaJIT/LuaJIT/archive/becf5cc65d966a8926466dd43407c48bfea0fa13.tar.gz -LUAJIT_SHA256 6d7e8fc691d45fe837d05e2a03f3a41b0886a237544d30f74f1355ce2c8d9157 +LUAJIT_URL https://github.com/LuaJIT/LuaJIT/archive/656ecbcf8f669feb94e0d0ec4b4f59190bcd2e48.tar.gz +LUAJIT_SHA256 b73cc2968a16435e899a381d36744f65e3a2d6688213fcbce95aeac56ce38d53 LUA_URL https://www.lua.org/ftp/lua-5.1.5.tar.gz LUA_SHA256 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333 diff --git a/runtime/doc/dev_style.txt b/runtime/doc/dev_style.txt index 79e758a11e..0bc27ced15 100644 --- a/runtime/doc/dev_style.txt +++ b/runtime/doc/dev_style.txt @@ -859,6 +859,33 @@ execute, simply use `abort()`: >c abort(); } +Switch statements that are conditional on an enumerated value should not have +a `default` case if it is exhaustive. Explicit case labels are preferred over +`default`, even if it leads to multiple case labels for the same code. For +example, instead of: >c + + case A: + ... + case B: + ... + case C: + ... + default: + ... + +You should use: >c + + case A: + ... + case B: + ... + case C: + ... + case D: + case E: + case F: + ... + Return Values ~ Do not needlessly surround the `return` expression with parentheses. diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index ceacb2e5da..3098cc0fb7 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -57,9 +57,8 @@ The following changes may require adaptations in user config or plugins. • for `backspace=1` set `backspace=indent,eol` • for `backspace=2` set `backspace=indent,eol,start` (default behavior in Nvim) • for `backspace=3` set `backspace=indent,eol,nostop` - • paths in |'backupdir'|, |'path'| and |'cdpath'| can no longer be separated with - spaces (but paths themselves may contain spaces now). - • |'directory'| will no longer remove a `>` at the start of the option. + • |'backupdir'| and |'directory'| will no longer remove a `>` at the start + of the option. • |LanguageTree:parse()| will no longer parse injections by default and now requires an explicit range argument to be passed. If injections are diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 283c1e3612..e2af4d5bc1 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -136,10 +136,26 @@ To include white space in a string option value it has to be preceded with a backslash. To include a backslash you have to use two. Effectively this means that the number of backslashes in an option value is halved (rounded down). +In options 'path', 'cdpath', and 'tags', spaces have to be preceded with three +backslashes instead becuase they can be separated by either commas or spaces. +Comma-separated options like 'backupdir' and 'tags' will also require commas +to be escaped with two backslashes, whereas this is not needed for +non-comma-separated ones like 'makeprg'. +When setting options using |:let| and |literal-string|, you need to use one +fewer layer of backslash. A few examples: > - :set tags=tags\ /usr/tags results in "tags /usr/tags" - :set tags=tags\\,file results in "tags\,file" - :set tags=tags\\\ file results in "tags\ file" + :set makeprg=make\ file results in "make file" + :let &makeprg='make file' (same as above) + :set makeprg=make\\\ file results in "make\ file" + :set tags=tags\ /usr/tags results in "tags" and "/usr/tags" + :set tags=tags\\\ file results in "tags file" + :let &tags='tags\ file' (same as above) + + :set makeprg=make,file results in "make,file" + :set makeprg=make\\,file results in "make\,file" + :set tags=tags,file results in "tags" and "file" + :set tags=tags\\,file results in "tags,file" + :let &tags='tags\,file' (same as above) The "|" character separates a ":set" command from a following command. To include the "|" in the option value, use "\|" instead. This example sets the @@ -2552,7 +2568,7 @@ A jump table for the options with a short description can be found at |Q_op|. "auto": resize to the minimum amount of folds to display. "auto:[1-9]": resize to accommodate multiple folds up to the selected level - 0: to disable foldcolumn + "0": to disable foldcolumn "[1-9]": to display a fixed number of columns See |folding|. @@ -4499,6 +4515,10 @@ A jump table for the options with a short description can be found at |Q_op|. option may be relative or absolute. - Use commas to separate directory names: > :set path=.,/usr/local/include,/usr/include +< - Spaces can also be used to separate directory names. To have a + space in a directory name, precede it with an extra backslash, and + escape the space: > + :set path=.,/dir/with\\\ space < - To include a comma in a directory name precede it with an extra backslash: > :set path=.,/dir/with\\,comma @@ -6422,8 +6442,8 @@ A jump table for the options with a short description can be found at |Q_op|. 'tags' 'tag' string (default "./tags;,tags") global or local to buffer |global-local| Filenames for the tag command, separated by spaces or commas. To - include a space or comma in a file name, precede it with a backslash - (see |option-backslash| about including spaces and backslashes). + include a space or comma in a file name, precede it with backslashes + (see |option-backslash| about including spaces/commas and backslashes). When a file name starts with "./", the '.' is replaced with the path of the current file. But only when the 'd' flag is not included in 'cpoptions'. Environment variables are expanded |:set_env|. Also see diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt index 8784a395f2..9cf0e59854 100644 --- a/runtime/doc/ui.txt +++ b/runtime/doc/ui.txt @@ -211,6 +211,7 @@ the editor. - 'guifontwide' - 'linespace' - 'mousefocus' + - 'mousehide' - 'mousemoveevent' - 'pumblend' - 'showtabline' diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 4161d3b21e..d000d7c35c 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -657,9 +657,7 @@ Options: *'balloondelay'* *'bdlay'* *'ballooneval'* *'beval'* *'noballooneval'* *'nobeval'* *'balloonexpr'* *'bexpr'* - 'backupdir': paths can no longer be separated with spaces. bioskey (MS-DOS) - 'cdpath': paths can no longer be separated with spaces. conskey (MS-DOS) *'cp'* *'nocompatible'* *'nocp'* *'compatible'* (Nvim is always "nocompatible".) 'cpoptions' (gjkHw<*- and all POSIX flags were removed) @@ -724,7 +722,6 @@ Options: Use |g8| or |ga|. See |mbyte-combining|. *'maxmem'* Nvim delegates memory-management to the OS. *'maxmemtot'* Nvim delegates memory-management to the OS. - |'path'|: paths can no longer be separated with spaces. printoptions *'printdevice'* *'printencoding'* diff --git a/runtime/ftplugin/gpg.vim b/runtime/ftplugin/gpg.vim index 2415555e09..7fb4f47ed8 100644 --- a/runtime/ftplugin/gpg.vim +++ b/runtime/ftplugin/gpg.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: gpg(1) configuration file " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-09 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -17,17 +17,17 @@ setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 GpgKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+--' . <q-args> . '\b'' --hilite-search" man ' . 'gpg' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 GpgKeywordPrg \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s+--' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . 'gpg' endif - if exists(':Sman') == 2 + if exists(':GpgKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:GpgKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer GpgKeywordPrg' endif endif diff --git a/runtime/ftplugin/modconf.vim b/runtime/ftplugin/modconf.vim index d5eda5af21..22d18a9aad 100644 --- a/runtime/ftplugin/modconf.vim +++ b/runtime/ftplugin/modconf.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: modules.conf(5) configuration file " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-09 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -18,17 +18,17 @@ setlocal formatoptions-=t formatoptions+=croql if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 ModconfKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s{,8}' . <q-args> . '\b'' --hilite-search" man ' . 'modprobe.d' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 ModconfKeywordPrg \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s{,8}' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . 'modprobe.d' endif - if exists(':Sman') == 2 + if exists(':ModconfKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:ModconfKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer ModconfKeywordPrg' endif endif diff --git a/runtime/ftplugin/muttrc.vim b/runtime/ftplugin/muttrc.vim index 7a4eb7a8bb..c9f6df31d0 100644 --- a/runtime/ftplugin/muttrc.vim +++ b/runtime/ftplugin/muttrc.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: mutt RC File " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-04-19 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -20,17 +20,17 @@ let &l:include = '^\s*source\>' if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 MuttrcKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . <q-args> . '\b'' --hilite-search" man ' . 'muttrc' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 MuttrcKeywordPrg \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s+' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . 'muttrc' endif - if exists(':Sman') == 2 + if exists(':MuttrcKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:MuttrcKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer MuttrcKeywordPrg' endif endif diff --git a/runtime/ftplugin/readline.vim b/runtime/ftplugin/readline.vim index a696da2701..181d8ac661 100644 --- a/runtime/ftplugin/readline.vim +++ b/runtime/ftplugin/readline.vim @@ -32,17 +32,17 @@ endif if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 ReadlineKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . <q-args> . '\b'' --hilite-search" man ' . '3 readline' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 ReadlineKeywordPrg \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s+' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . '3 readline' endif - if exists(':Sman') == 2 + if exists(':ReadlineKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:ReadlineKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer ReadlineKeywordPrg' endif endif diff --git a/runtime/ftplugin/sshconfig.vim b/runtime/ftplugin/sshconfig.vim index c9a5cfaa68..4a054da52f 100644 --- a/runtime/ftplugin/sshconfig.vim +++ b/runtime/ftplugin/sshconfig.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: OpenSSH client configuration file " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-09 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -16,17 +16,17 @@ let b:undo_ftplugin = 'setlocal com< cms< fo<' if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 SshconfigKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s+' . <q-args> . '$'' --hilite-search" man ' . 'ssh_config' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 SshconfigKeywordPrg \ silent exe 'term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s+' . <q-args> . '$', '\') . ''' --hilite-search" man ' . 'ssh_config' endif - if exists(':Sman') == 2 + if exists(':SshconfigKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:SshconfigKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SshconfigKeywordPrg' endif endif diff --git a/runtime/ftplugin/sudoers.vim b/runtime/ftplugin/sudoers.vim index b4123620af..81ce7906a9 100644 --- a/runtime/ftplugin/sudoers.vim +++ b/runtime/ftplugin/sudoers.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: sudoers(5) configuration files " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-09 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -17,17 +17,17 @@ setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 SudoersKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''\b' . <q-args> . '\b'' --hilite-search" man ' . 'sudoers' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 SudoersKeywordPrg \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('\b' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . 'sudoers' endif - if exists(':Sman') == 2 + if exists(':SudoersKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:SudoersKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SudoersKeywordPrg' endif endif diff --git a/runtime/ftplugin/systemd.vim b/runtime/ftplugin/systemd.vim index e60a5e4960..8bcacdd381 100644 --- a/runtime/ftplugin/systemd.vim +++ b/runtime/ftplugin/systemd.vim @@ -1,6 +1,7 @@ " Vim filetype plugin file " Language: systemd.unit(5) " Keyword Lookup Support: Enno Nagel <enno.nagel+vim@gmail.com> +" Latest Revision: 2023-10-07 if !exists('b:did_ftplugin') " Looks a lot like dosini files. @@ -9,11 +10,11 @@ endif if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman silent exe '!' . KeywordLookup_systemd(<q-args>) | redraw! + command -buffer -nargs=1 SystemdKeywordPrg silent exe '!' . KeywordLookup_systemd(<q-args>) | redraw! elseif has('terminal') - command -buffer -nargs=1 Sman silent exe 'term ' . KeywordLookup_systemd(<q-args>) + command -buffer -nargs=1 SystemdKeywordPrg silent exe 'term ' . KeywordLookup_systemd(<q-args>) endif - if exists(':Sman') == 2 + if exists(':SystemdKeywordPrg') == 2 if !exists('*KeywordLookup_systemd') function KeywordLookup_systemd(keyword) abort let matches = matchlist(getline(search('\v^\s*\[\s*.+\s*\]\s*$', 'nbWz')), '\v^\s*\[\s*(\k+).*\]\s*$') @@ -26,11 +27,11 @@ if has('unix') && executable('less') endfunction endif setlocal iskeyword+=- - setlocal keywordprg=:Sman + setlocal keywordprg=:SystemdKeywordPrg if !exists('b:undo_ftplugin') || empty(b:undo_ftplugin) let b:undo_ftplugin = 'setlocal keywordprg< iskeyword<' else - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer SystemdKeywordPrg' endif endif endif diff --git a/runtime/ftplugin/udevrules.vim b/runtime/ftplugin/udevrules.vim index 83fb728a54..ec365f04c2 100644 --- a/runtime/ftplugin/udevrules.vim +++ b/runtime/ftplugin/udevrules.vim @@ -1,7 +1,7 @@ " Vim filetype plugin file " Language: udev(8) rules file " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-09 +" Latest Revision: 2023-10-07 if exists("b:did_ftplugin") finish @@ -17,17 +17,17 @@ setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql if has('unix') && executable('less') if !has('gui_running') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 UdevrulesKeywordPrg \ silent exe '!' . 'LESS= MANPAGER="less --pattern=''^\s{,8}' . <q-args> . '\b'' --hilite-search" man ' . 'udev' | \ redraw! elseif has('terminal') - command -buffer -nargs=1 Sman + command -buffer -nargs=1 UdevrulesKeywordPrg \ silent exe ':term ' . 'env LESS= MANPAGER="less --pattern=''' . escape('^\s{,8}' . <q-args> . '\b', '\') . ''' --hilite-search" man ' . 'udev' endif - if exists(':Sman') == 2 + if exists(':UdevrulesKeywordPrg') == 2 setlocal iskeyword+=- - setlocal keywordprg=:Sman - let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer Sman' + setlocal keywordprg=:UdevrulesKeywordPrg + let b:undo_ftplugin .= '| setlocal keywordprg< iskeyword< | sil! delc -buffer UdevrulesKeywordPrg' endif endif diff --git a/runtime/ftplugin/zsh.vim b/runtime/ftplugin/zsh.vim index ed75d04003..40986fccbe 100644 --- a/runtime/ftplugin/zsh.vim +++ b/runtime/ftplugin/zsh.vim @@ -2,7 +2,7 @@ " Language: Zsh shell script " Maintainer: Christian Brabandt <cb@256bit.org> " Previous Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2021-04-03 +" Latest Revision: 2023-10-07 " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-zsh @@ -20,17 +20,17 @@ let b:undo_ftplugin = "setl com< cms< fo< " if executable('zsh') && &shell !~# '/\%(nologin\|false\)$' if !has('gui_running') && executable('less') - command! -buffer -nargs=1 RunHelp silent exe '!MANPAGER= zsh -c "autoload -Uz run-help; run-help <args> 2>/dev/null | LESS= less"' | redraw! + command! -buffer -nargs=1 ZshKeywordPrg silent exe '!MANPAGER= zsh -c "autoload -Uz run-help; run-help <args> 2>/dev/null | LESS= less"' | redraw! elseif has('terminal') - command! -buffer -nargs=1 RunHelp silent exe ':term zsh -c "autoload -Uz run-help; run-help <args>"' + command! -buffer -nargs=1 ZshKeywordPrg silent exe ':term zsh -c "autoload -Uz run-help; run-help <args>"' else - command! -buffer -nargs=1 RunHelp echo system('zsh -c "autoload -Uz run-help; run-help <args> 2>/dev/null"') + command! -buffer -nargs=1 ZshKeywordPrg echo system('zsh -c "autoload -Uz run-help; run-help <args> 2>/dev/null"') endif if !exists('current_compiler') compiler zsh endif - setlocal keywordprg=:RunHelp - let b:undo_ftplugin .= 'keywordprg< | sil! delc -buffer RunHelp' + setlocal keywordprg=:ZshKeywordPrg + let b:undo_ftplugin .= 'keywordprg< | sil! delc -buffer ZshKeywordPrg' endif let b:match_words = '\<if\>:\<elif\>:\<else\>:\<fi\>' diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua index bdcc68d7cd..5a9b0b53ce 100644 --- a/runtime/lua/vim/_meta/api.lua +++ b/runtime/lua/vim/_meta/api.lua @@ -1,4 +1,4 @@ ---- @meta +--- @meta _ -- THIS FILE IS GENERATED -- DO NOT EDIT error('Cannot require a meta file') diff --git a/runtime/lua/vim/_meta/api_keysets.lua b/runtime/lua/vim/_meta/api_keysets.lua index ebd164712c..467409505e 100644 --- a/runtime/lua/vim/_meta/api_keysets.lua +++ b/runtime/lua/vim/_meta/api_keysets.lua @@ -1,4 +1,4 @@ ---- @meta +--- @meta _ -- THIS FILE IS GENERATED -- DO NOT EDIT error('Cannot require a meta file') diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua index 08ee1f97ba..a4e0e61248 100644 --- a/runtime/lua/vim/_meta/options.lua +++ b/runtime/lua/vim/_meta/options.lua @@ -1,4 +1,4 @@ ---- @meta +--- @meta _ -- THIS FILE IS GENERATED -- DO NOT EDIT error('Cannot require a meta file') @@ -2276,7 +2276,7 @@ vim.go.fcl = vim.go.foldclose --- "auto": resize to the minimum amount of folds to display. --- "auto:[1-9]": resize to accommodate multiple folds up to the --- selected level ---- 0: to disable foldcolumn +--- "0": to disable foldcolumn --- "[1-9]": to display a fixed number of columns --- See `folding`. --- @@ -4621,6 +4621,12 @@ vim.go.pm = vim.go.patchmode --- ``` --- :set path=.,/usr/local/include,/usr/include --- ``` +--- - Spaces can also be used to separate directory names. To have a +--- space in a directory name, precede it with an extra backslash, and +--- escape the space: +--- ``` +--- :set path=.,/dir/with\\\ space +--- ``` --- - To include a comma in a directory name precede it with an extra --- backslash: --- ``` @@ -6871,8 +6877,8 @@ vim.go.tagrelative = vim.o.tagrelative vim.go.tr = vim.go.tagrelative --- Filenames for the tag command, separated by spaces or commas. To ---- include a space or comma in a file name, precede it with a backslash ---- (see `option-backslash` about including spaces and backslashes). +--- include a space or comma in a file name, precede it with backslashes +--- (see `option-backslash` about including spaces/commas and backslashes). --- When a file name starts with "./", the '.' is replaced with the path --- of the current file. But only when the 'd' flag is not included in --- 'cpoptions'. Environment variables are expanded `:set_env`. Also see diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 06de2fdd1c..481ffd1831 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -1,4 +1,4 @@ ---- @meta +--- @meta _ -- THIS FILE IS GENERATED -- DO NOT EDIT error('Cannot require a meta file') @@ -8055,7 +8055,7 @@ function vim.fn.shellescape(string, special) end --- will be assumed. --- --- @param col? integer ---- @return any +--- @return integer function vim.fn.shiftwidth(col) end --- @param name string diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua index 1afe3d5f46..bf243e96fd 100755 --- a/scripts/gen_eval_files.lua +++ b/scripts/gen_eval_files.lua @@ -19,14 +19,14 @@ local DEP_API_DOC = 'runtime/doc/api.mpack' --- @field since integer local LUA_META_HEADER = { - '--- @meta', + '--- @meta _', '-- THIS FILE IS GENERATED', '-- DO NOT EDIT', "error('Cannot require a meta file')", } local LUA_API_META_HEADER = { - '--- @meta', + '--- @meta _', '-- THIS FILE IS GENERATED', '-- DO NOT EDIT', "error('Cannot require a meta file')", @@ -35,7 +35,7 @@ local LUA_API_META_HEADER = { } local LUA_OPTION_META_HEADER = { - '--- @meta', + '--- @meta _', '-- THIS FILE IS GENERATED', '-- DO NOT EDIT', "error('Cannot require a meta file')", diff --git a/src/mpack/lmpack.c b/src/mpack/lmpack.c index 957bac37cc..3c7108a337 100644 --- a/src/mpack/lmpack.c +++ b/src/mpack/lmpack.c @@ -233,7 +233,7 @@ static mpack_uint32_t lmpack_objlen(lua_State *L, int *is_array) while (lua_next(L, -2)) { lua_pop(L, 1); /* pop value */ isarr = isarr - && lua_isnumber(L, -1) /* lua number */ + && lua_type(L, -1) == LUA_TNUMBER /* lua number */ && (n = lua_tonumber(L, -1)) > 0 /* greater than 0 */ && (size_t)n == n; /* and integer */ max = isarr && (size_t)n > max ? (size_t)n : max; diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index db79de63cc..127d9cf5af 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -90,7 +90,7 @@ if(MSVC) target_compile_options(main_lib INTERFACE -W3) # Disable warnings that give too many false positives. - target_compile_options(main_lib INTERFACE -wd4311 -wd4146 -wd4003) + target_compile_options(main_lib INTERFACE -wd4311 -wd4146 -wd4003 -wd4715) target_compile_definitions(main_lib INTERFACE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE) target_sources(main_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/os/nvim.manifest) @@ -821,10 +821,32 @@ add_glob_target( FILES ${NVIM_SOURCES} ${NVIM_HEADERS} FLAGS --quiet EXCLUDE ${EXCLUDE_CLANG_TIDY}) + +# These are the same warnings as https://neovim.io/doc/reports/clang/. The +# checks we ignore are meant to be removed eventually, but we can only do so +# after we properly fix the problems without breaking CI. +add_glob_target( + TARGET clang-analyzer + COMMAND ${CLANG_TIDY_PRG} + FILES ${NVIM_SOURCES} ${NVIM_HEADERS} + FLAGS --quiet + --checks=' + -*, + clang-analyzer-*, + -clang-analyzer-core.NonNullParamChecker, + -clang-analyzer-core.NullDereference, + -clang-analyzer-core.UndefinedBinaryOperatorResult, + -clang-analyzer-core.uninitialized.Assign, + -clang-analyzer-optin.performance.Padding, + -clang-analyzer-security.insecureAPI.strcpy, + ' + EXCLUDE ${EXCLUDE_CLANG_TIDY}) + add_custom_target(copy_compile_commands COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR}/compile_commands.json) add_dependencies(copy_compile_commands nvim) add_dependencies(clang-tidy copy_compile_commands) +add_dependencies(clang-analyzer copy_compile_commands) if(CI_BUILD) set(LINT_OUTPUT_FORMAT gh_action) diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index 768ed869cc..d0efb58cb6 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -33,13 +33,11 @@ // Copy string or array of strings into an empty array. // Get the event number, unless it is an error. Then goto `goto_name`. #define GET_ONE_EVENT(event_nr, event_str, goto_name) \ - char *__next_ev; \ event_T event_nr = \ - event_name2nr(event_str.data.string.data, &__next_ev); \ - if (event_nr >= NUM_EVENTS) { \ - api_set_error(err, kErrorTypeValidation, "unexpected event"); \ + event_name2nr_str(event_str.data.string); \ + VALIDATE_S((event_nr < NUM_EVENTS), "event", event_str.data.string.data, { \ goto goto_name; \ - } + }); // ID for associating autocmds created via nvim_create_autocmd // Used to delete autocmds from nvim_del_autocmd @@ -296,7 +294,7 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err) case kCallbackPartial: PUT(autocmd_info, "callback", CSTR_AS_OBJ(callback_to_string(cb))); break; - default: + case kCallbackNone: abort(); } } else { diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 5a75d10043..867d1d5e5c 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -146,16 +146,14 @@ static Object optval_as_object(OptVal o) return BOOLEAN_OBJ(o.data.boolean); case kNone: return NIL; - default: - abort(); } + UNREACHABLE; case kOptValTypeNumber: return INTEGER_OBJ(o.data.number); case kOptValTypeString: return STRING_OBJ(o.data.string); - default: - abort(); } + UNREACHABLE; } /// Consume an API Object and convert it to an OptVal. diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c index dc6928f4b9..10152cb3c8 100644 --- a/src/nvim/api/private/converter.c +++ b/src/nvim/api/private/converter.c @@ -363,9 +363,6 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) tv->vval.v_string = xstrdup(name); break; } - - default: - abort(); } return true; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 25e752bea8..eaee94786c 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -610,9 +610,6 @@ void api_free_object(Object value) case kObjectTypeLuaRef: api_free_luaref(value.data.luaref); break; - - default: - abort(); } } @@ -800,10 +797,8 @@ Object copy_object(Object obj, Arena *arena) case kObjectTypeLuaRef: return LUAREF_OBJ(api_new_luaref(obj.data.luaref)); - - default: - abort(); } + UNREACHABLE; } void api_set_error(Error *err, ErrorType errType, const char *format, ...) @@ -884,9 +879,8 @@ char *api_typename(ObjectType t) return "Window"; case kObjectTypeTabpage: return "Tabpage"; - default: - abort(); } + UNREACHABLE; } HlMessage parse_hl_msg(Array chunks, Error *err) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index b8e0934669..ce3eca52b5 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -587,7 +587,7 @@ ArrayOf(String) nvim__get_runtime(Array pat, Boolean all, Dict(runtime) *opts, E FUNC_API_SINCE(8) FUNC_API_FAST { - VALIDATE((!opts->do_source || nlua_is_deferred_safe()), "%s", "'do_source' used in fast callback", + VALIDATE(!opts->do_source || nlua_is_deferred_safe(), "%s", "'do_source' used in fast callback", {}); if (ERROR_SET(err)) { return (Array)ARRAY_DICT_INIT; diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c index ca7086ab7f..2fd30bc5a5 100644 --- a/src/nvim/api/win_config.c +++ b/src/nvim/api/win_config.c @@ -279,8 +279,6 @@ Dictionary config_put_bordertext(Dictionary config, FloatConfig *fconfig, field_name = "footer"; field_pos_name = "footer_pos"; break; - default: - abort(); } Array bordertext = virt_text_to_array(vt, true); diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c index bab77a4a84..9dbb2c06e1 100644 --- a/src/nvim/arabic.c +++ b/src/nvim/arabic.c @@ -297,13 +297,12 @@ static int A_is_valid(int c) } // Do Arabic shaping on character "c". Returns the shaped character. -// out: "ccp" points to the first byte of the character to be shaped. // in/out: "c1p" points to the first composing char for "c". // in: "prev_c" is the previous character (not shaped) // in: "prev_c1" is the first composing char for the previous char // (not shaped) // in: "next_c" is the next character (not shaped). -int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c) +int arabic_shape(int c, int *c1p, int prev_c, int prev_c1, int next_c) { // Deal only with Arabic character, pass back all others if (!A_is_ok(c)) { @@ -347,14 +346,6 @@ int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c) curr_c = c; } - if ((curr_c != c) && (ccp != NULL)) { - char buf[MB_MAXBYTES + 1]; - - // Update the first byte of the character - utf_char2bytes(curr_c, buf); - *ccp = (uint8_t)buf[0]; - } - // Return the shaped character return curr_c; } diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index a40f7d8c26..2537269c5c 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -597,9 +597,9 @@ bool is_aucmd_win(win_T *win) return false; } -// Return the event number for event name "start". -// Return NUM_EVENTS if the event name was not found. -// Return a pointer to the next event name in "end". +/// Return the event number for event name "start". +/// Return NUM_EVENTS if the event name was not found. +/// Return a pointer to the next event name in "end". event_T event_name2nr(const char *start, char **end) { const char *p; @@ -623,6 +623,18 @@ event_T event_name2nr(const char *start, char **end) return event_names[i].event; } +/// Return the event number for event name "str". +/// Return NUM_EVENTS if the event name was not found. +event_T event_name2nr_str(String str) +{ + for (int i = 0; event_names[i].name != NULL; i++) { + if (str.size == event_names[i].len && STRNICMP(str.data, event_names[i].name, str.size) == 0) { + return event_names[i].event; + } + } + return NUM_EVENTS; +} + /// Return the name for event /// /// @param[in] event Event to return name for. @@ -1766,10 +1778,10 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force patcmd.data = data; // set v:cmdarg (only when there is a matching pattern) - save_cmdbang = (long)get_vim_var_nr(VV_CMDBANG); + save_cmdbang = get_vim_var_nr(VV_CMDBANG); if (eap != NULL) { save_cmdarg = set_cmdarg(eap, NULL); - set_vim_var_nr(VV_CMDBANG, (long)eap->forceit); + set_vim_var_nr(VV_CMDBANG, eap->forceit); } else { save_cmdarg = NULL; // avoid gcc warning } diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 1a2e2fbdae..5b223daeb0 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -274,8 +274,8 @@ typedef struct qf_info_S qf_info_T; typedef struct { proftime_T total; // total time used proftime_T slowest; // time of slowest call - long count; // nr of times used - long match; // nr of times matched + int count; // nr of times used + int match; // nr of times matched } syn_time_T; // These are items normally related to a buffer. But when using ":ownsyntax" @@ -440,10 +440,10 @@ struct file_buffer { disptick_T b_mod_tick_decor; // last display tick decoration providers // where invoked - long b_mtime; // last change time of original file - long b_mtime_ns; // nanoseconds of last change time - long b_mtime_read; // last change time when reading - long b_mtime_read_ns; // nanoseconds of last read time + int64_t b_mtime; // last change time of original file + int64_t b_mtime_ns; // nanoseconds of last change time + int64_t b_mtime_read; // last change time when reading + int64_t b_mtime_read_ns; // nanoseconds of last read time uint64_t b_orig_size; // size of original file in bytes int b_orig_mode; // mode of original file time_t b_last_used; // time when the buffer was last used; used @@ -1268,7 +1268,7 @@ struct window_S { int w_briopt_list; // additional indent for lists int w_briopt_vcol; // indent for specific column - long w_scbind_pos; + int w_scbind_pos; ScopeDictDictItem w_winvar; ///< Variable for "w:" dictionary. dict_T *w_vars; ///< Dictionary with w: variables. diff --git a/src/nvim/bufwrite.c b/src/nvim/bufwrite.c index 2e4dda78fc..c151da7ab7 100644 --- a/src/nvim/bufwrite.c +++ b/src/nvim/bufwrite.c @@ -339,7 +339,7 @@ static int buf_write_bytes(struct bw_info *ip) // Only checking conversion, which is OK if we get here. return OK; } - int wlen = (int)write_eintr(ip->bw_fd, buf, (size_t)len); + int wlen = write_eintr(ip->bw_fd, buf, (size_t)len); return (wlen < len) ? FAIL : OK; } @@ -619,14 +619,14 @@ static void emit_err(Error_T *e) #if defined(UNIX) -static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwriting, long *perm, +static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwriting, int *perm, bool *device, bool *newfile, Error_T *err) { *perm = -1; if (!os_fileinfo(fname, file_info_old)) { *newfile = true; } else { - *perm = (long)file_info_old->stat.st_mode; + *perm = (int)file_info_old->stat.st_mode; if (!S_ISREG(file_info_old->stat.st_mode)) { // not a file if (S_ISDIR(file_info_old->stat.st_mode)) { *err = set_err_num("E502", _("is a directory")); @@ -648,7 +648,7 @@ static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwritin #else -static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwriting, long *perm, +static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwriting, int *perm, bool *device, bool *newfile, Error_T *err) { // Check for a writable device name. @@ -688,7 +688,7 @@ static int get_fileinfo_os(char *fname, FileInfo *file_info_old, bool overwritin /// @param[out] newfile /// @param[out] readonly static int get_fileinfo(buf_T *buf, char *fname, bool overwriting, bool forceit, - FileInfo *file_info_old, long *perm, bool *device, bool *newfile, + FileInfo *file_info_old, int *perm, bool *device, bool *newfile, bool *readonly, Error_T *err) { if (get_fileinfo_os(fname, file_info_old, overwriting, perm, device, newfile, err) == FAIL) { @@ -723,7 +723,7 @@ static int get_fileinfo(buf_T *buf, char *fname, bool overwriting, bool forceit, } static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_old, vim_acl_T acl, - long perm, unsigned bkc, bool file_readonly, bool forceit, + int perm, unsigned bkc, bool file_readonly, bool forceit, int *backup_copyp, char **backupp, Error_T *err) { FileInfo file_info; @@ -755,7 +755,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o } } int fd = os_open(IObuff, - O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, (int)perm); + O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm); if (fd < 0) { // can't write in directory *backup_copyp = true; } else { @@ -764,7 +764,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o if (!os_fileinfo(IObuff, &file_info) || file_info.stat.st_uid != file_info_old->stat.st_uid || file_info.stat.st_gid != file_info_old->stat.st_gid - || (long)file_info.stat.st_mode != perm) { + || (int)file_info.stat.st_mode != perm) { *backup_copyp = true; } #endif @@ -911,7 +911,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o // if (file_info_new.stat.st_gid != file_info_old->stat.st_gid && os_chown(*backupp, (uv_uid_t)-1, (uv_gid_t)file_info_old->stat.st_gid) != 0) { - os_setperm(*backupp, ((int)perm & 0707) | (((int)perm & 07) << 3)); + os_setperm(*backupp, (perm & 0707) | ((perm & 07) << 3)); } # ifdef HAVE_XATTR os_copy_xattr(fname, *backupp); @@ -1193,7 +1193,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en } Error_T err = { 0 }; - long perm; // file permissions + int perm; // file permissions bool newfile = false; // true if file doesn't exist yet bool device = false; // writing to a device bool file_readonly = false; // overwritten file is read-only @@ -1255,7 +1255,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en && file_info_old.stat.st_uid == getuid() && vim_strchr(p_cpo, CPO_FWRITE) == NULL) { perm |= 0200; - (void)os_setperm(fname, (int)perm); + (void)os_setperm(fname, perm); made_writable = true; } #endif @@ -1658,7 +1658,7 @@ restore_backup: || file_info.stat.st_gid != file_info_old.stat.st_gid) { os_fchown(fd, (uv_uid_t)file_info_old.stat.st_uid, (uv_gid_t)file_info_old.stat.st_gid); if (perm >= 0) { // Set permission again, may have changed. - (void)os_setperm(wfname, (int)perm); + (void)os_setperm(wfname, perm); } } buf_set_file_id(buf); @@ -1679,7 +1679,7 @@ restore_backup: } #endif if (perm >= 0) { // Set perm. of new file same as old file. - (void)os_setperm(wfname, (int)perm); + (void)os_setperm(wfname, perm); } // Probably need to set the ACL before changing the user (can't set the // ACL on a file the user doesn't own). diff --git a/src/nvim/change.c b/src/nvim/change.c index abbfe2505e..acc657a1c2 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -831,7 +831,7 @@ int del_chars(int count, int fixpos) { int bytes = 0; char *p = get_cursor_pos_ptr(); - for (long i = 0; i < count && *p != NUL; i++) { + for (int i = 0; i < count && *p != NUL; i++) { int l = utfc_ptr2len(p); bytes += l; p += l; @@ -1829,7 +1829,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (flags & OPENLINE_MARKFIX) { mark_col_adjust(curwin->w_cursor.lnum, curwin->w_cursor.col + less_cols_off, - 1L, (long)-less_cols, 0); + 1L, -less_cols, 0); } // Always move extmarks - Here we move only the line where the // cursor is, the previous mark_adjust takes care of the lines after diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 5c8e922f90..32a2f1021c 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -168,9 +168,6 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error) channel_decref(chan); } break; - - default: - abort(); } return true; @@ -917,9 +914,6 @@ Dictionary channel_info(uint64_t id) case kChannelStreamSocket: stream_desc = "socket"; break; - - default: - abort(); } PUT(info, "stream", CSTR_TO_OBJ(stream_desc)); diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index c2469b6574..aef471a17b 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -156,8 +156,9 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files // and wildmatch characters, except '~'. for (int i = 0; i < numfiles; i++) { // for ":set path=" we need to escape spaces twice - if (xp->xp_backslash == XP_BS_THREE) { - p = vim_strsave_escaped(files[i], " "); + if (xp->xp_backslash & XP_BS_THREE) { + char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " "; + p = vim_strsave_escaped(files[i], pat); xfree(files[i]); files[i] = p; #if defined(BACKSLASH_IN_FILENAME) @@ -165,6 +166,14 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files xfree(files[i]); files[i] = p; #endif + } else if (xp->xp_backslash & XP_BS_COMMA) { + if (vim_strchr(files[i], ',') != NULL) { + p = vim_strsave_escaped(files[i], ","); + if (p != NULL) { + xfree(files[i]); + files[i] = p; + } + } } #ifdef BACKSLASH_IN_FILENAME p = vim_strsave_fnameescape(files[i], vse_what); @@ -890,7 +899,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) // Concatenate all matching names. Unless interrupted, this can be slow // and the result probably won't be used. - // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne) if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; for (int i = 0; i < xp->xp_numfiles; i++) { @@ -905,18 +913,19 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) } ss = xmalloc(len); *ss = NUL; + char *ssp = ss; for (int i = 0; i < xp->xp_numfiles; i++) { if (i > 0) { if (xp->xp_prefix == XP_PREFIX_NO) { - STRCAT(ss, "no"); + ssp = xstpcpy(ssp, "no"); } else if (xp->xp_prefix == XP_PREFIX_INV) { - STRCAT(ss, "inv"); + ssp = xstpcpy(ssp, "inv"); } } - STRCAT(ss, xp->xp_files[i]); + ssp = xstpcpy(ssp, xp->xp_files[i]); if (i != xp->xp_numfiles - 1) { - STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); + ssp = xstpcpy(ssp, (options & WILD_USE_NL) ? "\n" : " "); } } } @@ -2440,15 +2449,23 @@ static int expand_files_and_dirs(expand_T *xp, char *pat, char ***matches, int * pat = xstrdup(pat); for (int i = 0; pat[i]; i++) { if (pat[i] == '\\') { - if (xp->xp_backslash == XP_BS_THREE + if (xp->xp_backslash & XP_BS_THREE && pat[i + 1] == '\\' && pat[i + 2] == '\\' && pat[i + 3] == ' ') { STRMOVE(pat + i, pat + i + 3); - } - if (xp->xp_backslash == XP_BS_ONE - && pat[i + 1] == ' ') { + } else if (xp->xp_backslash & XP_BS_ONE + && pat[i + 1] == ' ') { STRMOVE(pat + i, pat + i + 1); + } else if ((xp->xp_backslash & XP_BS_COMMA) + && pat[i + 1] == '\\' + && pat[i + 2] == ',') { + STRMOVE(pat + i, pat + i + 2); +#ifdef BACKSLASH_IN_FILENAME + } else if ((xp->xp_backslash & XP_BS_COMMA) + && pat[i + 1] == ',') { + STRMOVE(pat + i, pat + i + 1); +#endif } } } diff --git a/src/nvim/cmdexpand_defs.h b/src/nvim/cmdexpand_defs.h index a302a32852..7c422aca18 100644 --- a/src/nvim/cmdexpand_defs.h +++ b/src/nvim/cmdexpand_defs.h @@ -40,9 +40,10 @@ typedef struct expand { /// values for xp_backslash enum { - XP_BS_NONE = 0, ///< nothing special for backslashes - XP_BS_ONE = 1, ///< uses one backslash before a space - XP_BS_THREE = 2, ///< uses three backslashes before a space + XP_BS_NONE = 0, ///< nothing special for backslashes + XP_BS_ONE = 0x1, ///< uses one backslash before a space + XP_BS_THREE = 0x2, ///< uses three backslashes before a space + XP_BS_COMMA = 0x4, ///< commas need to be escaped with a backslash }; /// values for xp_context when doing command line completion diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 8479675dfa..b0663416ef 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -82,7 +82,7 @@ static bool diff_need_update = false; // ex_diffupdate needs to be called #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; -static long diff_algorithm = 0; +static int diff_algorithm = 0; static int linematch_lines = 0; #define LBUFLEN 50 // length of line in diff file @@ -3402,7 +3402,7 @@ linenr_T diff_lnum_win(linenr_T lnum, win_T *wp) /// static int parse_diff_ed(char *line, diffhunk_T *hunk) { - long l1, l2; + int l1, l2; // The line must be one of three formats: // change: {first}[,{last}]c{first}[,{last}] @@ -3412,7 +3412,7 @@ static int parse_diff_ed(char *line, diffhunk_T *hunk) linenr_T f1 = getdigits_int32(&p, true, 0); if (*p == ',') { p++; - l1 = getdigits_long(&p, true, 0); + l1 = getdigits_int(&p, true, 0); } else { l1 = f1; } @@ -3420,10 +3420,10 @@ static int parse_diff_ed(char *line, diffhunk_T *hunk) return FAIL; // invalid diff format } int difftype = (uint8_t)(*p++); - long f2 = getdigits_long(&p, true, 0); + int f2 = getdigits_int(&p, true, 0); if (*p == ',') { p++; - l2 = getdigits_long(&p, true, 0); + l2 = getdigits_int(&p, true, 0); } else { l2 = f2; } @@ -3448,31 +3448,29 @@ static int parse_diff_ed(char *line, diffhunk_T *hunk) return OK; } -/// /// Parses unified diff with zero(!) context lines. /// Return FAIL if there is no diff information in "line". -/// static int parse_diff_unified(char *line, diffhunk_T *hunk) { // Parse unified diff hunk header: // @@ -oldline,oldcount +newline,newcount @@ char *p = line; if (*p++ == '@' && *p++ == '@' && *p++ == ' ' && *p++ == '-') { - long oldcount; - long newline; - long newcount; - long oldline = getdigits_long(&p, true, 0); + int oldcount; + linenr_T newline; + int newcount; + linenr_T oldline = getdigits_int32(&p, true, 0); if (*p == ',') { p++; - oldcount = getdigits_long(&p, true, 0); + oldcount = getdigits_int(&p, true, 0); } else { oldcount = 1; } if (*p++ == ' ' && *p++ == '+') { - newline = getdigits_long(&p, true, 0); + newline = getdigits_int(&p, true, 0); if (*p == ',') { p++; - newcount = getdigits_long(&p, true, 0); + newcount = getdigits_int(&p, true, 0); } else { newcount = 1; } @@ -3490,9 +3488,9 @@ static int parse_diff_unified(char *line, diffhunk_T *hunk) newline = 1; } - hunk->lnum_orig = (linenr_T)oldline; + hunk->lnum_orig = oldline; hunk->count_orig = oldcount; - hunk->lnum_new = (linenr_T)newline; + hunk->lnum_new = newline; hunk->count_new = newcount; return OK; @@ -3501,11 +3499,9 @@ static int parse_diff_unified(char *line, diffhunk_T *hunk) return FAIL; } -/// /// Callback function for the xdl_diff() function. /// Stores the diff output in a grow array. -/// -static int xdiff_out(long start_a, long count_a, long start_b, long count_b, void *priv) +static int xdiff_out(int start_a, int count_a, int start_b, int count_b, void *priv) { diffout_T *dout = (diffout_T *)priv; GA_APPEND(diffhunk_T, &(dout->dout_ga), ((diffhunk_T){ diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index e5d2ba7550..2d450087fd 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -12,7 +12,6 @@ #include <stdlib.h> #include <string.h> -#include "nvim/arabic.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -141,15 +140,6 @@ typedef struct { ///< to be added to wlv.vcol later } winlinevars_T; -/// for line_putchar. Contains the state that needs to be remembered from -/// putting one character to the next. -typedef struct { - const char *p; - int prev_c; ///< previous Arabic character - int prev_c1; ///< first composing char for prev_c -} LineState; -#define LINE_STATE(p) { p, 0, 0 } - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "drawline.c.generated.h" #endif @@ -220,10 +210,10 @@ static void line_check_overwrite(schar_T *dest, int cells, int maxcells, bool rl /// Put a single char from an UTF-8 buffer into a line buffer. /// -/// Handles composing chars and arabic shaping state. -static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, bool rl, int vcol) +/// Handles composing chars +static int line_putchar(buf_T *buf, const char **pp, schar_T *dest, int maxcells, bool rl, int vcol) { - const char *p = s->p; + const char *p = *pp; int cells = utf_ptr2cells(p); int c_len = utfc_ptr2len(p); int u8c, u8cc[MAX_MCO]; @@ -244,39 +234,14 @@ static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, b goto done; } else if ((uint8_t)(*p) < 0x80 && u8cc[0] == 0) { dest[0] = schar_from_ascii(*p); - s->prev_c = u8c; } else { - if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { - // Do Arabic shaping. - int pc, pc1, nc; - int pcc[MAX_MCO]; - int firstbyte = (uint8_t)(*p); - - // The idea of what is the previous and next - // character depends on 'rightleft'. - if (rl) { - pc = s->prev_c; - pc1 = s->prev_c1; - nc = utf_ptr2char(p + c_len); - s->prev_c1 = u8cc[0]; - } else { - pc = utfc_ptr2char(p + c_len, pcc); - nc = s->prev_c; - pc1 = pcc[0]; - } - s->prev_c = u8c; - - u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], pc, pc1, nc); - } else { - s->prev_c = u8c; - } dest[0] = schar_from_cc(u8c, u8cc); } if (cells > 1) { dest[rl ? -1 : 1] = 0; } done: - s->p += c_len; + *pp += c_len; return cells; } @@ -344,22 +309,22 @@ static void draw_virt_text(win_T *wp, buf_T *buf, int col_off, int *end_col, int static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, int max_col, int vcol, bool rl) { - LineState s = LINE_STATE(""); + const char *p = ""; int virt_attr = 0; size_t virt_pos = 0; while (rl ? col > max_col : col < max_col) { - if (*s.p == NUL) { + if (!*p) { if (virt_pos >= kv_size(vt)) { break; } virt_attr = 0; - s.p = next_virt_text_chunk(vt, &virt_pos, &virt_attr); - if (s.p == NULL) { + p = next_virt_text_chunk(vt, &virt_pos, &virt_attr); + if (p == NULL) { break; } } - if (*s.p == NUL) { + if (*p == NUL) { continue; } int attr; @@ -367,14 +332,14 @@ static int draw_virt_text_item(buf_T *buf, int col, VirtText vt, HlMode hl_mode, if (hl_mode == kHlModeCombine) { attr = hl_combine_attr(linebuf_attr[col], virt_attr); } else if (hl_mode == kHlModeBlend) { - through = (*s.p == ' '); + through = (*p == ' '); attr = hl_blend_attrs(linebuf_attr[col], virt_attr, &through); } else { attr = virt_attr; } schar_T dummy[2]; int maxcells = rl ? col - max_col : max_col - col; - int cells = line_putchar(buf, &s, through ? dummy : &linebuf_char[col], + int cells = line_putchar(buf, &p, through ? dummy : &linebuf_char[col], maxcells, rl, vcol); // If we failed to emit a char, we still need to put a space and advance. if (cells < 1) { @@ -1171,8 +1136,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl int multispace_pos = 0; // position in lcs-multispace string int line_attr_save; int line_attr_lowprio_save; - int prev_c = 0; // previous Arabic character - int prev_c1 = 0; // first composing char for prev_c bool search_attr_from_match = false; // if search_attr is from :match bool has_decor = false; // this buffer has decoration @@ -2160,28 +2123,6 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl } } else if (mb_l == 0) { // at the NUL at end-of-line mb_l = 1; - } else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) { - // Do Arabic shaping. - int pc, pc1, nc; - int pcc[MAX_MCO]; - - // The idea of what is the previous and next - // character depends on 'rightleft'. - if (wp->w_p_rl) { - pc = prev_c; - pc1 = prev_c1; - nc = utf_ptr2char(ptr + mb_l); - prev_c1 = u8cc[0]; - } else { - pc = utfc_ptr2char(ptr + mb_l, pcc); - nc = prev_c; - pc1 = pcc[0]; - } - prev_c = mb_c; - - mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); - } else { - prev_c = mb_c; } // If a double-width char doesn't fit display a '>' in the // last column; the character is displayed at the start of the diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c index e32a556daa..ca70c1f4ef 100644 --- a/src/nvim/drawscreen.c +++ b/src/nvim/drawscreen.c @@ -738,9 +738,8 @@ int win_get_bordertext_col(int total_col, int text_width, AlignTextPos align) return (total_col - text_width) / 2 + 1; case kAlignRight: return total_col - text_width + 1; - default: - abort(); } + UNREACHABLE; } static void win_redr_border(win_T *wp) @@ -1647,11 +1646,11 @@ static void win_update(win_T *wp, DecorProviders *providers) // When only displaying the lines at the top, set top_end. Used when // window has scrolled down for msg_scrolled. if (type == UPD_REDRAW_TOP) { - long j = 0; + int j = 0; for (int i = 0; i < wp->w_lines_valid; i++) { j += wp->w_lines[i].wl_size; if (j >= wp->w_upd_rows) { - top_end = (int)j; + top_end = j; break; } } @@ -1684,7 +1683,7 @@ static void win_update(win_T *wp, DecorProviders *providers) || (wp->w_topline == wp->w_lines[0].wl_lnum && wp->w_topfill > wp->w_old_topfill))) { // New topline is above old topline: May scroll down. - long j; + int j; if (hasAnyFolding(wp)) { linenr_T ln; @@ -1744,7 +1743,7 @@ static void win_update(win_T *wp, DecorProviders *providers) // needs updating. // try to find wp->w_topline in wp->w_lines[].wl_lnum - long j = -1; + int j = -1; int row = 0; for (int i = 0; i < wp->w_lines_valid; i++) { if (wp->w_lines[i].wl_valid @@ -2151,7 +2150,7 @@ static void win_update(win_T *wp, DecorProviders *providers) int new_rows = 0; // Able to count old number of rows: Count new window // rows, and may insert/delete lines - long j = idx; + int j = idx; for (l = lnum; l < mod_bot; l++) { if (hasFoldingWin(wp, l, NULL, &l, true, NULL)) { new_rows++; @@ -2212,14 +2211,14 @@ static void win_update(win_T *wp, DecorProviders *providers) while (true) { // stop at last valid entry in w_lines[] if (i >= wp->w_lines_valid) { - wp->w_lines_valid = (int)j; + wp->w_lines_valid = j; break; } wp->w_lines[j] = wp->w_lines[i]; // stop at a line that won't fit if (x + (int)wp->w_lines[j].wl_size > wp->w_grid.rows) { - wp->w_lines_valid = (int)j + 1; + wp->w_lines_valid = j + 1; break; } x += wp->w_lines[j++].wl_size; @@ -2391,10 +2390,10 @@ static void win_update(win_T *wp, DecorProviders *providers) wp->w_botline = lnum; } else if (dy_flags & DY_LASTLINE) { // 'display' has "lastline" // Last line isn't finished: Display "@@@" at the end. - // TODO(bfredl): this display ">@@@" when ">" was a left-halve - // maybe "@@@@" is preferred when this happens. + // If this would split a doublewidth char in two, we need to display "@@@@" instead grid_line_start(&wp->w_grid, wp->w_grid.rows - 1); - grid_line_fill(MAX(wp->w_grid.cols - 3, 0), wp->w_grid.cols, + int width = grid_line_getchar(MAX(wp->w_grid.cols - 3, 0), NULL) == NUL ? 4 : 3; + grid_line_fill(MAX(wp->w_grid.cols - width, 0), wp->w_grid.cols, wp->w_p_fcs_chars.lastline, at_attr); grid_line_flush(); set_empty_rows(wp, srow); @@ -2407,7 +2406,7 @@ static void win_update(win_T *wp, DecorProviders *providers) } else { if (eof) { // we hit the end of the file wp->w_botline = buf->b_ml.ml_line_count + 1; - long j = win_get_fill(wp, wp->w_botline); + int j = win_get_fill(wp, wp->w_botline); if (j > 0 && !wp->w_botfill && row < wp->w_grid.rows) { // Display filler text below last line. win_line() will check // for ml_line_count+1 and only draw filler lines diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 12226dac91..ee0860a8d1 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1645,7 +1645,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const lp->ll_n1 = 0; } else { // Is number or string. - lp->ll_n1 = (long)tv_get_number(&var1); + lp->ll_n1 = (int)tv_get_number(&var1); } tv_clear(&var1); @@ -1655,7 +1655,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const return NULL; } if (lp->ll_range && !lp->ll_empty2) { - lp->ll_n2 = (long)tv_get_number(&var2); + lp->ll_n2 = (int)tv_get_number(&var2); tv_clear(&var2); if (tv_blob_check_range(bloblen, lp->ll_n1, lp->ll_n2, quiet) == FAIL) { return NULL; @@ -1670,7 +1670,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const lp->ll_n1 = 0; } else { // Is number or string. - lp->ll_n1 = (long)tv_get_number(&var1); + lp->ll_n1 = (int)tv_get_number(&var1); } tv_clear(&var1); @@ -1687,7 +1687,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const // When no index given: "lp->ll_empty2" is true. // Otherwise "lp->ll_n2" is set to the second index. if (lp->ll_range && !lp->ll_empty2) { - lp->ll_n2 = (long)tv_get_number(&var2); // Is number or string. + lp->ll_n2 = (int)tv_get_number(&var2); // Is number or string. tv_clear(&var2); if (tv_list_check_range_index_two(lp->ll_list, &lp->ll_n1, lp->ll_li, @@ -1746,7 +1746,7 @@ void set_var_lval(lval_T *lp, char *endp, typval_T *rettv, int copy, const bool bool error = false; const char val = (char)tv_get_number_chk(rettv, &error); if (!error) { - tv_blob_set_append(lp->ll_blob, (int)lp->ll_n1, (uint8_t)val); + tv_blob_set_append(lp->ll_blob, lp->ll_n1, (uint8_t)val); } } } else if (op != NULL && *op != '=') { @@ -5641,7 +5641,7 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; - const char *prompt = ""; + const char *prompt; const char *defstr = ""; typval_T *cancelreturn = NULL; typval_T cancelreturn_strarg2 = TV_INITIAL_VALUE; @@ -5914,7 +5914,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist char **argv = tv_to_argv(&argvars[0], NULL, &executable); if (!argv) { if (!executable) { - set_vim_var_nr(VV_SHELL_ERROR, (long)-1); + set_vim_var_nr(VV_SHELL_ERROR, -1); } xfree(input); return; // Already did emsg. @@ -5944,7 +5944,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist xfree(input); - set_vim_var_nr(VV_SHELL_ERROR, (long)status); + set_vim_var_nr(VV_SHELL_ERROR, status); if (res == NULL) { if (retlist) { @@ -6088,9 +6088,6 @@ bool callback_call(Callback *const callback, const int argcount_in, typval_T *co case kCallbackNone: return false; break; - - default: - abort(); } funcexe_T funcexe = FUNCEXE_INIT; @@ -6120,7 +6117,7 @@ bool set_ref_in_callback(Callback *callback, int copyID, ht_stack_T **ht_stack, return set_ref_in_item(&tv, copyID, ht_stack, list_stack); break; - default: + case kCallbackLua: abort(); } return false; @@ -6231,7 +6228,7 @@ void timer_due_cb(TimeWatcher *tw, void *data) timer_decref(timer); } -uint64_t timer_start(const long timeout, const int repeat_count, const Callback *const callback) +uint64_t timer_start(const int64_t timeout, const int repeat_count, const Callback *const callback) { timer_T *timer = xmalloc(sizeof *timer); timer->refcount = 1; @@ -7122,7 +7119,7 @@ void set_vim_var_char(int c) /// Set v:count to "count" and v:count1 to "count1". /// /// @param set_prevcount if true, first set v:prevcount from v:count. -void set_vcount(long count, long count1, int set_prevcount) +void set_vcount(int64_t count, int64_t count1, bool set_prevcount) { if (set_prevcount) { vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr; diff --git a/src/nvim/eval.h b/src/nvim/eval.h index 38bcf8f50d..aee5fb11ca 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -53,11 +53,11 @@ typedef struct lval_S { list_T *ll_list; ///< The list or NULL. bool ll_range; ///< true when a [i:j] range was used. bool ll_empty2; ///< Second index is empty: [i:]. - long ll_n1; ///< First index for list. - long ll_n2; ///< Second index for list range. + int ll_n1; ///< First index for list. + int ll_n2; ///< Second index for list range. dict_T *ll_dict; ///< The Dictionary or NULL. dictitem_T *ll_di; ///< The dictitem or NULL. - char *ll_newkey; ///< New key for Dict in allocated memory or NULL. + char *ll_newkey; ///< New key for Dict in allocated memory or NULL. blob_T *ll_blob; ///< The Blob or NULL. } lval_T; @@ -225,7 +225,7 @@ typedef struct { int repeat_count; int refcount; int emsg_count; ///< Errors in a repeating timer. - long timeout; + int64_t timeout; bool stopped; bool paused; Callback callback; diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 5a47286980..14476e29d4 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -9636,6 +9636,7 @@ M.funcs = { name = 'shiftwidth', params = { { 'col', 'integer' } }, signature = 'shiftwidth([{col}])', + returns = 'integer', }, sign_define = { args = { 1, 2 }, diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index fc9904a2d9..4a0c4ca19a 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -152,9 +152,9 @@ static int conv_error(const char *const msg, const MPConvStack *const mpstack, ? 0 : (v.data.l.li == NULL ? tv_list_len(v.data.l.list) - 1 - : (int)tv_list_idx_of_item(v.data.l.list, - TV_LIST_ITEM_PREV(v.data.l.list, - v.data.l.li)))); + : tv_list_idx_of_item(v.data.l.list, + TV_LIST_ITEM_PREV(v.data.l.list, + v.data.l.li)))); const listitem_T *const li = (v.data.l.li == NULL ? tv_list_last(v.data.l.list) : TV_LIST_ITEM_PREV(v.data.l.list, diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index eb2e2fb1e2..b9d124532e 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -526,7 +526,7 @@ buf_T *get_buf_arg(typval_T *arg) /// "byte2line(byte)" function static void f_byte2line(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - long boff = (long)tv_get_number(&argvars[0]) - 1; + int boff = (int)tv_get_number(&argvars[0]) - 1; if (boff < 0) { rettv->vval.v_number = -1; } else { @@ -4990,9 +4990,10 @@ static int msgpackparse_convert_item(const msgpack_object data, const msgpack_un tv_list_append_owned_tv(ret_list, tv); return OK; } - default: + case MSGPACK_UNPACK_EXTRA_BYTES: abort(); } + UNREACHABLE; } static void msgpackparse_unpack_list(const list_T *const list, list_T *const ret_list) @@ -8708,8 +8709,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (!callback_from_typval(&callback, &argvars[1])) { return; } - rettv->vval.v_number = (varnumber_T)timer_start((const long)tv_get_number(&argvars[0]), repeat, - &callback); + rettv->vval.v_number = (varnumber_T)timer_start(tv_get_number(&argvars[0]), repeat, &callback); } /// "timer_stop(timerid)" function diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 1ff90dd201..ea118e4bc6 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -620,7 +620,7 @@ tv_list_copy_error: /// Get the list item in "l" with index "n1". "n1" is adjusted if needed. /// Return NULL if there is no such item. -listitem_T *tv_list_check_range_index_one(list_T *const l, long *const n1, const bool quiet) +listitem_T *tv_list_check_range_index_one(list_T *const l, int *const n1, const bool quiet) { listitem_T *li = tv_list_find_index(l, n1); if (li == NULL) { @@ -636,11 +636,11 @@ listitem_T *tv_list_check_range_index_one(list_T *const l, long *const n1, const /// If "n1" or "n2" is negative it is changed to the positive index. /// "li1" is the item for item "n1". /// Return OK or FAIL. -int tv_list_check_range_index_two(list_T *const l, long *const n1, const listitem_T *const li1, - long *const n2, const bool quiet) +int tv_list_check_range_index_two(list_T *const l, int *const n1, const listitem_T *const li1, + int *const n2, const bool quiet) { if (*n2 < 0) { - listitem_T *ni = tv_list_find(l, (int)(*n2)); + listitem_T *ni = tv_list_find(l, *n2); if (ni == NULL) { if (!quiet) { semsg(_(e_list_index_out_of_range_nr), (int64_t)(*n2)); @@ -670,11 +670,10 @@ int tv_list_check_range_index_two(list_T *const l, long *const n1, const listite /// "op" is the operator, normally "=" but can be "+=" and the like. /// "varname" is used for error messages. /// Returns OK or FAIL. -int tv_list_assign_range(list_T *const dest, list_T *const src, const long idx1_arg, - const long idx2, const bool empty_idx2, const char *const op, - const char *const varname) +int tv_list_assign_range(list_T *const dest, list_T *const src, const int idx1_arg, const int idx2, + const bool empty_idx2, const char *const op, const char *const varname) { - long idx1 = idx1_arg; + int idx1 = idx1_arg; listitem_T *const first_li = tv_list_find_index(dest, &idx1); listitem_T *src_li; @@ -1634,14 +1633,14 @@ const char *tv_list_find_str(list_T *const l, const int n) /// Like tv_list_find() but when a negative index is used that is not found use /// zero and set "idx" to zero. Used for first index of a range. -static listitem_T *tv_list_find_index(list_T *const l, long *const idx) +static listitem_T *tv_list_find_index(list_T *const l, int *const idx) FUNC_ATTR_WARN_UNUSED_RESULT { - listitem_T *li = tv_list_find(l, (int)(*idx)); + listitem_T *li = tv_list_find(l, *idx); if (li == NULL) { if (*idx < 0) { *idx = 0; - li = tv_list_find(l, (int)(*idx)); + li = tv_list_find(l, *idx); } } return li; @@ -1653,7 +1652,7 @@ static listitem_T *tv_list_find_index(list_T *const l, long *const idx) /// @param[in] item Item to search for. /// /// @return Index of an item or -1 if item is not in the list. -long tv_list_idx_of_item(const list_T *const l, const listitem_T *const item) +int tv_list_idx_of_item(const list_T *const l, const listitem_T *const item) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { if (l == NULL) { diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 00ba1334b0..d612b503a7 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -78,8 +78,6 @@ int process_spawn(Process *proc, bool in, bool out, bool err) case kProcessTypePty: status = pty_process_spawn((PtyProcess *)proc); break; - default: - abort(); } if (status) { @@ -239,8 +237,6 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL process_close_streams(proc); pty_process_close_master((PtyProcess *)proc); break; - default: - abort(); } // (Re)start timer to verify that stopped process(es) died. @@ -340,8 +336,6 @@ static void process_close(Process *proc) case kProcessTypePty: pty_process_close((PtyProcess *)proc); break; - default: - abort(); } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c57324d5e9..e9a42ae508 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3521,8 +3521,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n && (cmdpreview_ns <= 0 || preview_lines.lines_needed <= (linenr_T)p_cwh || lnum <= curwin->w_botline); lnum++) { - int nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, - (colnr_T)0, NULL, NULL); + int nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, + (colnr_T)0, NULL, NULL); if (nmatch) { colnr_T copycol; colnr_T matchcol; @@ -4087,9 +4087,9 @@ skip: // need to replace the line first (using \zs after \n). if (lastone || nmatch_tl > 0 - || (nmatch = (int)vim_regexec_multi(®match, curwin, - curbuf, sub_firstlnum, - matchcol, NULL, NULL)) == 0 + || (nmatch = vim_regexec_multi(®match, curwin, + curbuf, sub_firstlnum, + matchcol, NULL, NULL)) == 0 || regmatch.startpos[0].lnum > 0) { if (new_start != NULL) { // Copy the rest of the line, that didn't match. @@ -4149,8 +4149,8 @@ skip: copycol = 0; } if (nmatch == -1 && !lastone) { - nmatch = (int)vim_regexec_multi(®match, curwin, curbuf, - sub_firstlnum, matchcol, NULL, NULL); + nmatch = vim_regexec_multi(®match, curwin, curbuf, + sub_firstlnum, matchcol, NULL, NULL); } // 5. break if there isn't another match in this line @@ -4446,7 +4446,7 @@ void ex_global(exarg_T *eap) if (global_busy) { lnum = curwin->w_cursor.lnum; - match = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if ((type == 'g' && match) || (type == 'v' && !match)) { global_exe_one(cmd, lnum); } @@ -4455,7 +4455,7 @@ void ex_global(exarg_T *eap) // pass 1: set marks for each (not) matching line for (lnum = eap->line1; lnum <= eap->line2 && !got_int; lnum++) { // a match on this line? - match = (int)vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); + match = vim_regexec_multi(®match, curwin, curbuf, lnum, 0, NULL, NULL); if (regmatch.regprog == NULL) { break; // re-compiling regprog failed } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e18912c8a0..36355ce89b 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1630,7 +1630,7 @@ static int execute_cmd0(int *retv, exarg_T *eap, const char **errormsg, bool pre // Call the function to execute the builtin command or the preview callback. eap->errmsg = NULL; if (preview) { - *retv = (cmdnames[eap->cmdidx].cmd_preview_func)(eap, (int)cmdpreview_get_ns(), + *retv = (cmdnames[eap->cmdidx].cmd_preview_func)(eap, cmdpreview_get_ns(), cmdpreview_get_bufnr()); } else { (cmdnames[eap->cmdidx].cmd_func)(eap); @@ -3142,9 +3142,6 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; - if (name == NULL) { - return; - } while (*name == ':') { name++; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2a1dffacb7..2759dc9bb5 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2208,7 +2208,7 @@ handle_T cmdpreview_get_bufnr(void) return cmdpreview_bufnr; } -long cmdpreview_get_ns(void) +int cmdpreview_get_ns(void) { return cmdpreview_ns; } @@ -2998,16 +2998,6 @@ void realloc_cmdbuff(int len) } } -static char *arshape_buf = NULL; - -#if defined(EXITFREE) -void free_arshape_buf(void) -{ - xfree(arshape_buf); -} - -#endif - enum { MAX_CB_ERRORS = 1, }; /// Color expression cmdline using built-in expressions parser @@ -3317,98 +3307,7 @@ static void draw_cmdline(int start, int len) msg_putchar('*'); i += utfc_ptr2len(ccline.cmdbuff + start + i) - 1; } - } else if (p_arshape && !p_tbidi && len > 0) { - bool do_arabicshape = false; - int mb_l; - for (int i = start; i < start + len; i += mb_l) { - char *p = ccline.cmdbuff + i; - int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); - if (ARABIC_CHAR(u8c)) { - do_arabicshape = true; - break; - } - } - if (!do_arabicshape) { - goto draw_cmdline_no_arabicshape; - } - - static size_t buflen = 0; - assert(len >= 0); - - // Do arabic shaping into a temporary buffer. This is very - // inefficient! - if ((size_t)len * 2 + 2 > buflen) { - // Re-allocate the buffer. We keep it around to avoid a lot of - // alloc()/free() calls. - xfree(arshape_buf); - buflen = (size_t)len * 2 + 2; - arshape_buf = xmalloc(buflen); - } - - int newlen = 0; - if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { - // Prepend a space to draw the leading composing char on. - arshape_buf[0] = ' '; - newlen = 1; - } - - int prev_c = 0; - int prev_c1 = 0; - for (int i = start; i < start + len; i += mb_l) { - char *p = ccline.cmdbuff + i; - int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); - if (ARABIC_CHAR(u8c)) { - int pc; - int pc1 = 0; - int nc = 0; - // Do Arabic shaping. - if (cmdmsg_rl) { - // Displaying from right to left. - pc = prev_c; - pc1 = prev_c1; - prev_c1 = u8cc[0]; - if (i + mb_l >= start + len) { - nc = NUL; - } else { - nc = utf_ptr2char(p + mb_l); - } - } else { - // Displaying from left to right. - if (i + mb_l >= start + len) { - pc = NUL; - } else { - int pcc[MAX_MCO]; - - pc = utfc_ptr2char_len(p + mb_l, pcc, start + len - i - mb_l); - pc1 = pcc[0]; - } - nc = prev_c; - } - prev_c = u8c; - - u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); - - newlen += utf_char2bytes(u8c, arshape_buf + newlen); - if (u8cc[0] != 0) { - newlen += utf_char2bytes(u8cc[0], arshape_buf + newlen); - if (u8cc[1] != 0) { - newlen += utf_char2bytes(u8cc[1], arshape_buf + newlen); - } - } - } else { - prev_c = u8c; - memmove(arshape_buf + newlen, p, (size_t)mb_l); - newlen += mb_l; - } - } - - msg_outtrans_len(arshape_buf, newlen, 0); } else { -draw_cmdline_no_arabicshape: if (kv_size(ccline.last_colors.colors)) { for (size_t i = 0; i < kv_size(ccline.last_colors.colors); i++) { CmdlineColorChunk chunk = kv_A(ccline.last_colors.colors, i); diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c index fd9c2e8fe0..23fe0f82c6 100644 --- a/src/nvim/extmark.c +++ b/src/nvim/extmark.c @@ -615,7 +615,7 @@ void extmark_splice(buf_T *buf, int start_row, colnr_T start_col, int old_row, c bcount_t old_byte, int new_row, colnr_T new_col, bcount_t new_byte, ExtmarkOp undo) { - long offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true); + int offset = ml_find_line_or_offset(buf, start_row + 1, NULL, true); // On empty buffers, when editing the first line, the line is buffered, // causing offset to be < 0. While the buffer is not actually empty, the diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 7a46341797..796d66f74c 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1468,7 +1468,7 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch // copy next path buf[0] = 0; - copy_option_part(&dir, buf, MAXPATHL, ","); + copy_option_part(&dir, buf, MAXPATHL, " ,"); // get the stopdir string r_ptr = vim_findfile_stopdir(buf); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 05b48966ff..9e60f30cb5 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -212,7 +212,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, bool fenc_alloced; // fenc_next is in allocated memory char *fenc_next = NULL; // next item in 'fencs' or NULL bool advance_fenc = false; - long real_size = 0; + int real_size = 0; iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1 bool did_iconv = false; // true when iconv() failed and trying // 'charconvert' next @@ -947,11 +947,11 @@ retry: size = 0; } else { int ni; - long tlen = 0; + int tlen = 0; while (true) { p = (uint8_t *)ml_get(read_buf_lnum) + read_buf_col; int n = (int)strlen((char *)p); - if ((int)tlen + n + 1 > size) { + if (tlen + n + 1 > size) { // Filled up to "size", append partial line. // Change NL to NUL to reverse the effect done // below. @@ -2177,7 +2177,8 @@ void msg_add_lines(int insert_space, linenr_T lnum, off_T nchars) } } -bool time_differs(const FileInfo *file_info, long mtime, long mtime_ns) FUNC_ATTR_CONST +bool time_differs(const FileInfo *file_info, int64_t mtime, int64_t mtime_ns) + FUNC_ATTR_CONST { #if defined(__linux__) || defined(MSWIN) return file_info->stat.st_mtim.tv_nsec != mtime_ns @@ -2728,7 +2729,7 @@ int vim_rename(const char *from, const char *to) } int n; - while ((n = (int)read_eintr(fd_in, buffer, WRITEBUFSIZE)) > 0) { + while ((n = read_eintr(fd_in, buffer, WRITEBUFSIZE)) > 0) { if (write_eintr(fd_out, buffer, (size_t)n) != n) { errmsg = _("E208: Error writing to \"%s\""); break; @@ -2905,7 +2906,7 @@ int buf_check_timestamp(buf_T *buf) && (!(file_info_ok = os_fileinfo(buf->b_ffname, &file_info)) || time_differs(&file_info, buf->b_mtime, buf->b_mtime_ns) || (int)file_info.stat.st_mode != buf->b_orig_mode)) { - const int prev_b_mtime = (int)buf->b_mtime; + const int64_t prev_b_mtime = buf->b_mtime; retval = 1; @@ -3823,9 +3824,9 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs /// Version of read() that retries when interrupted by EINTR (possibly /// by a SIGWINCH). -long read_eintr(int fd, void *buf, size_t bufsize) +int read_eintr(int fd, void *buf, size_t bufsize) { - long ret; + ssize_t ret; while (true) { ret = read(fd, buf, (unsigned)bufsize); @@ -3833,25 +3834,25 @@ long read_eintr(int fd, void *buf, size_t bufsize) break; } } - return ret; + return (int)ret; } /// Version of write() that retries when interrupted by EINTR (possibly /// by a SIGWINCH). -long write_eintr(int fd, void *buf, size_t bufsize) +int write_eintr(int fd, void *buf, size_t bufsize) { - long ret = 0; + int ret = 0; // Repeat the write() so long it didn't fail, other than being interrupted // by a signal. - while (ret < (long)bufsize) { - long wlen = write(fd, (char *)buf + ret, (unsigned)(bufsize - (size_t)ret)); + while (ret < (int)bufsize) { + ssize_t wlen = write(fd, (char *)buf + ret, (unsigned)(bufsize - (size_t)ret)); if (wlen < 0) { if (errno != EINTR) { break; } } else { - ret += wlen; + ret += (int)wlen; } } return ret; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 6a9dbe9edc..2e38f9ca3d 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -363,7 +363,7 @@ int foldmethodIsDiff(win_T *wp) // closeFold() {{{2 /// Close fold for current window at position "pos". /// Repeat "count" times. -void closeFold(pos_T pos, long count) +void closeFold(pos_T pos, int count) { setFoldRepeat(pos, count, false); } @@ -417,7 +417,7 @@ void opFoldRange(pos_T firstpos, pos_T lastpos, int opening, int recurse, int ha // openFold() {{{2 /// Open fold for current window at position "pos". /// Repeat "count" times. -void openFold(pos_T pos, long count) +void openFold(pos_T pos, int count) { setFoldRepeat(pos, count, true); } @@ -847,7 +847,7 @@ void foldUpdateAll(win_T *win) /// @return FAIL if not moved. /// /// @param dir FORWARD or BACKWARD -int foldMoveTo(const bool updown, const int dir, const long count) +int foldMoveTo(const bool updown, const int dir, const int count) { int retval = FAIL; linenr_T lnum; @@ -856,7 +856,7 @@ int foldMoveTo(const bool updown, const int dir, const long count) checkupdate(curwin); // Repeat "count" times. - for (long n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { // Find nested folds. Stop when a fold is closed. The deepest fold // that moves the cursor is used. linenr_T lnum_off = 0; @@ -1136,7 +1136,7 @@ static void checkupdate(win_T *wp) // setFoldRepeat() {{{2 /// Open or close fold for current window at position `pos`. /// Repeat "count" times. -static void setFoldRepeat(pos_T pos, long count, int do_open) +static void setFoldRepeat(pos_T pos, int count, int do_open) { for (int n = 0; n < count; n++) { int done = DONE_NOTHING; @@ -1816,11 +1816,11 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo } } if (text == NULL) { - long count = lnume - lnum + 1; + int count = lnume - lnum + 1; vim_snprintf(buf, FOLD_TEXT_LEN, - NGETTEXT("+--%3ld line folded", - "+--%3ld lines folded ", count), + NGETTEXT("+--%3d line folded", + "+--%3d lines folded ", count), count); text = buf; } @@ -3304,8 +3304,8 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } } - long count = foldend - foldstart + 1; - char *txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count); + int count = foldend - foldstart + 1; + char *txt = NGETTEXT("+-%s%3d line: ", "+-%s%3d lines: ", count); size_t len = strlen(txt) + strlen(dashes) // for %s + 20 // for %3ld diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 2eab158bc4..7c8823e0d4 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -152,17 +152,17 @@ bool schar_high(schar_T sc) #endif } -void schar_get(char *buf_out, schar_T sc) -{ - if (schar_high(sc)) { #ifdef ORDER_BIG_ENDIAN - uint32_t idx = sc & (0x00FFFFFF); +# define schar_idx(sc) (sc & (0x00FFFFFF)) #else - uint32_t idx = sc >> 8; +# define schar_idx(sc) (sc >> 8) #endif - if (idx >= glyph_cache.h.n_keys) { - abort(); - } + +void schar_get(char *buf_out, schar_T sc) +{ + if (schar_high(sc)) { + uint32_t idx = schar_idx(sc); + assert(idx < glyph_cache.h.n_keys); xstrlcpy(buf_out, &glyph_cache.keys[idx], 32); } else { memcpy(buf_out, (char *)&sc, 4); @@ -170,6 +170,13 @@ void schar_get(char *buf_out, schar_T sc) } } +/// gets first raw UTF-8 byte of an schar +static char schar_get_first_byte(schar_T sc) +{ + assert(!(schar_high(sc) && schar_idx(sc) >= glyph_cache.h.n_keys)); + return schar_high(sc) ? glyph_cache.keys[schar_idx(sc)] : *(char *)≻ +} + /// @return ascii char or NUL if not ascii char schar_get_ascii(schar_T sc) { @@ -179,6 +186,90 @@ char schar_get_ascii(schar_T sc) return (sc < 0x80) ? (char)sc : NUL; #endif } + +static bool schar_in_arabic_block(schar_T sc) +{ + char first_byte = schar_get_first_byte(sc); + return ((uint8_t)first_byte & 0xFE) == 0xD8; +} + +/// Get the first two codepoints of an schar, or NUL when not available +static void schar_get_first_two_codepoints(schar_T sc, int *c0, int *c1) +{ + char sc_buf[MAX_SCHAR_SIZE]; + schar_get(sc_buf, sc); + + *c0 = utf_ptr2char(sc_buf); + int len = utf_ptr2len(sc_buf); + if (*c0 == NUL) { + *c1 = NUL; + } else { + *c1 = utf_ptr2char(sc_buf + len); + } +} + +void line_do_arabic_shape(schar_T *buf, int cols) +{ + int i = 0; + + for (i = 0; i < cols; i++) { + // quickly skip over non-arabic text + if (schar_in_arabic_block(buf[i])) { + break; + } + } + + if (i == cols) { + return; + } + + int c0prev = 0; + int c0, c1; + schar_get_first_two_codepoints(buf[i], &c0, &c1); + + for (; i < cols; i++) { + int c0next, c1next; + schar_get_first_two_codepoints(i + 1 < cols ? buf[i + 1] : 0, &c0next, &c1next); + + if (!ARABIC_CHAR(c0)) { + goto next; + } + + int c1new = c1; + int c0new = arabic_shape(c0, &c1new, c0next, c1next, c0prev); + + if (c0new == c0 && c1new == c1) { + goto next; // unchanged + } + + char scbuf[MAX_SCHAR_SIZE]; + schar_get(scbuf, buf[i]); + + char scbuf_new[MAX_SCHAR_SIZE]; + int len = utf_char2bytes(c0new, scbuf_new); + if (c1new) { + len += utf_char2bytes(c1new, scbuf_new + len); + } + + int off = utf_char2len(c0) + (c1 ? utf_char2len(c1) : 0); + size_t rest = strlen(scbuf + off); + if (rest + (size_t)off + 1 > MAX_SCHAR_SIZE) { + // TODO(bfredl): this cannot happen just yet, as we only construct + // schar_T values with up to MAX_MCO+1 composing codepoints. When code + // is improved so that MAX_SCHAR_SIZE becomes the only/sharp limit, + // we need be able to peel off a composing char which doesn't fit anymore. + abort(); + } + memcpy(scbuf_new + len, scbuf + off, rest); + buf[i] = schar_from_buf(scbuf_new, (size_t)len + rest); + +next: + c0prev = c0; + c0 = c0next; + c1 = c1next; + } +} + /// clear a line in the grid starting at "off" until "width" characters /// are cleared. void grid_clear_line(ScreenGrid *grid, size_t off, int width, bool valid) @@ -242,6 +333,15 @@ void grid_line_start(ScreenGrid *grid, int row) grid_line_first = (int)linebuf_size; grid_line_maxcol = grid->cols - grid_line_coloff; grid_line_last = 0; + + assert((size_t)grid_line_maxcol <= linebuf_size); + + if (rdb_flags & RDB_INVALID) { + // Current batch must not depend on previous contents of linebuf_char. + // Set invalid values which will cause assertion failures later if they are used. + memset(linebuf_char, 0xFF, sizeof(schar_T) * linebuf_size); + memset(linebuf_attr, 0xFF, sizeof(sattr_T) * linebuf_size); + } } /// Get present char from current rendered screen line @@ -287,11 +387,7 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) { const char *ptr = text; int len = textlen; - int c; int u8cc[MAX_MCO]; - int prev_c = 0; // previous Arabic character - int pc, nc, nc1; - int pcc[MAX_MCO]; assert(grid_line_grid); @@ -301,7 +397,6 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) while (col < max_col && (len < 0 || (int)(ptr - text) < len) && *ptr != NUL) { - c = (unsigned char)(*ptr); // check if this is the first byte of a multibyte int mbyte_blen = len > 0 ? utfc_ptr2len_len(ptr, (int)((text + len) - ptr)) @@ -316,37 +411,16 @@ int grid_line_puts(int col, const char *text, int textlen, int attr) u8cc[0] = 0; } - if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) { - // Do Arabic shaping. - if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) { - // Past end of string to be displayed. - nc = NUL; - nc1 = NUL; - } else { - nc = len >= 0 - ? utfc_ptr2char_len(ptr + mbyte_blen, pcc, - (int)((text + len) - ptr - mbyte_blen)) - : utfc_ptr2char(ptr + mbyte_blen, pcc); - nc1 = pcc[0]; - } - pc = prev_c; - prev_c = u8c; - u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); - } else { - prev_c = u8c; - } if (col + mbyte_cells > max_col) { // Only 1 cell left, but character requires 2 cells: // display a '>' in the last column to avoid wrapping. */ - c = '>'; u8c = '>'; u8cc[0] = 0; mbyte_cells = 1; } schar_T buf; - // TODO(bfredl): why not just keep the original byte sequence. arabshape is - // an edge case, treat it as such.. + // TODO(bfredl): why not just keep the original byte sequence. buf = schar_from_cc(u8c, u8cc); // When at the start of the text and overwriting the right half of a @@ -545,14 +619,12 @@ static int grid_char_needs_redraw(ScreenGrid *grid, int col, size_t off_to, int /// If "wrap" is true, then hint to the UI that "row" contains a line /// which has wrapped into the next row. void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol, int clear_width, - int rl, int bg_attr, bool wrap, bool invalid_row) + bool rl, int bg_attr, bool wrap, bool invalid_row) { bool redraw_next; // redraw_this for next character bool clear_next = false; int char_cells; // 1: normal char // 2: occupies two display cells - int start_dirty = -1, end_dirty = 0; - assert(0 <= row && row < grid->rows); // TODO(bfredl): check all callsites and eliminate // Check for illegal col, just in case @@ -591,6 +663,10 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol endcol = (clear_width > 0 ? clear_width : -clear_width); } + if (p_arshape && !p_tbidi) { + line_do_arabic_shape(linebuf_char + col, endcol - col); + } + if (bg_attr) { for (int c = col; c < endcol; c++) { linebuf_attr[c] = hl_combine_attr(bg_attr, linebuf_attr[c]); @@ -599,6 +675,8 @@ void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int col, int endcol redraw_next = grid_char_needs_redraw(grid, col, (size_t)col + off_to, endcol - col); + int start_dirty = -1, end_dirty = 0; + while (col < endcol) { char_cells = 1; if (col + 1 < endcol && linebuf_char[col + 1] == 0) { diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c index 14239f44cc..337f9e968d 100644 --- a/src/nvim/highlight.c +++ b/src/nvim/highlight.c @@ -332,7 +332,7 @@ void update_window_hl(win_T *wp, bool invalid) wp->w_ns_hl_active = ns_id; wp->w_ns_hl_attr = *(NSHlAttr *)pmap_get(int)(&ns_hl_attr, ns_id); - if (!wp->w_ns_hl_attr) { + if (!wp->w_ns_hl_attr) { // -V547 // No specific highlights, use the defaults. wp->w_ns_hl_attr = highlight_attr; } diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h index ae58ff8696..eec5d9c9f4 100644 --- a/src/nvim/highlight_defs.h +++ b/src/nvim/highlight_defs.h @@ -123,6 +123,7 @@ typedef enum { HLF_WBRNC, // Window bars of not-current windows HLF_CU, // Cursor HLF_BTITLE, // Float Border Title + HLF_BFOOTER, // Float Border Footer HLF_COUNT, // MUST be the last one } hlf_T; @@ -192,6 +193,7 @@ EXTERN const char *hlf_names[] INIT(= { [HLF_WBRNC] = "WinBarNC", [HLF_CU] = "Cursor", [HLF_BTITLE] = "FloatTitle", + [HLF_BFOOTER] = "FloatFooter", }); EXTERN int highlight_attr[HLF_COUNT + 1]; // Highl. attr for each context. diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 7f67a24ef1..b4e56504a7 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -108,7 +108,7 @@ static pos_T *ind_find_start_CORS(linenr_T *is_raw) static pos_T *find_start_rawstring(int ind_maxcomment) // XXX { pos_T *pos; - long cur_maxcomment = ind_maxcomment; + int cur_maxcomment = ind_maxcomment; while (true) { pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment); @@ -1508,10 +1508,10 @@ static pos_T *find_match_paren_after_brace(int ind_maxparen) // looking a few lines further. static int corr_ind_maxparen(pos_T *startpos) { - long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum; + int n = startpos->lnum - curwin->w_cursor.lnum; if (n > 0 && n < curbuf->b_ind_maxparen / 2) { - return curbuf->b_ind_maxparen - (int)n; + return curbuf->b_ind_maxparen - n; } return curbuf->b_ind_maxparen; } diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 3ada39c800..5ac40d7238 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3309,7 +3309,7 @@ static int ins_compl_get_exp(pos_T *ini) xfree(st.e_cpt_copy); // Make a copy of 'complete', in case the buffer is wiped out. st.e_cpt_copy = xstrdup((compl_cont_status & CONT_LOCAL) ? "." : curbuf->b_p_cpt); - st.e_cpt = st.e_cpt_copy == NULL ? "" : st.e_cpt_copy; + st.e_cpt = st.e_cpt_copy; st.last_match_pos = st.first_match_pos = *ini; } else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) { st.ins_buf = curbuf; // In case the buffer was wiped out. diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c index 897a263bf2..01c035a4dd 100644 --- a/src/nvim/linematch.c +++ b/src/nvim/linematch.c @@ -144,9 +144,9 @@ static int count_n_matched_chars(const char **sp, const size_t n, bool iwhite) return matched_chars; } -void fastforward_buf_to_lnum(const char **s, long lnum) +void fastforward_buf_to_lnum(const char **s, linenr_T lnum) { - for (long i = 0; i < lnum - 1; i++) { + for (int i = 0; i < lnum - 1; i++) { *s = strchr(*s, '\n'); if (!*s) { return; diff --git a/src/nvim/linematch.h b/src/nvim/linematch.h index 052d438617..129d2c7125 100644 --- a/src/nvim/linematch.h +++ b/src/nvim/linematch.h @@ -3,6 +3,8 @@ #include <stddef.h> +#include "nvim/pos.h" + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "linematch.h.generated.h" #endif diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 265c4bf5ca..cd8a9b0739 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -694,7 +694,7 @@ static int parser_get_timeout(lua_State *L) return 0; } - lua_pushinteger(L, (long)ts_parser_timeout_micros(*p)); + lua_pushinteger(L, (lua_Integer)ts_parser_timeout_micros(*p)); return 1; } diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c index 000aad85d1..5aba1b839b 100644 --- a/src/nvim/lua/xdiff.c +++ b/src/nvim/lua/xdiff.c @@ -71,8 +71,8 @@ static void get_linematch_results(lua_State *lstate, mmfile_t *ma, mmfile_t *mb, const char *diff_begin[2] = { ma->ptr, mb->ptr }; int diff_length[2] = { (int)count_a, (int)count_b }; - fastforward_buf_to_lnum(&diff_begin[0], start_a + 1); - fastforward_buf_to_lnum(&diff_begin[1], start_b + 1); + fastforward_buf_to_lnum(&diff_begin[0], (linenr_T)start_a + 1); + fastforward_buf_to_lnum(&diff_begin[1], (linenr_T)start_b + 1); int *decisions = NULL; size_t decisions_length = linematch_nbuffers(diff_begin, diff_length, 2, &decisions, iwhite); @@ -125,7 +125,7 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf) } // hunk_func callback used when opts.hunk_lines = true -static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data) +static int hunk_locations_cb(int start_a, int count_a, int start_b, int count_b, void *cb_data) { hunkpriv_t *priv = (hunkpriv_t *)cb_data; lua_State *lstate = priv->lstate; @@ -140,7 +140,7 @@ static int hunk_locations_cb(long start_a, long count_a, long start_b, long coun } // hunk_func callback used when opts.on_hunk is given -static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data) +static int call_on_hunk_cb(int start_a, int count_a, int start_b, int count_b, void *cb_data) { // Mimic extra offsets done by xdiff, see: // src/xdiff/xemit.c:284 diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 5eaf97ff87..b4034fe4f7 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -154,6 +154,14 @@ # define FALLTHROUGH #endif +#if defined(__clang__) || defined(__GNUC__) +# define UNREACHABLE __builtin_unreachable() +#elif defined(_MSVC_VER) +# define UNREACHABLE __assume(false) +#else +# define UNREACHABLE +#endif + // -V:STRUCT_CAST:641 /// Change type of structure pointers: cast `struct a *` to `struct b *` diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 2cfa264754..da98f5e6c0 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2074,7 +2074,7 @@ void f_hasmapto(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// /// @return A Dictionary. static Dictionary mapblock_fill_dict(const mapblock_T *const mp, const char *lhsrawalt, - const long buffer_value, const bool compatible) + const int buffer_value, const bool compatible) FUNC_ATTR_NONNULL_ARG(1) { Dictionary dict = ARRAY_DICT_INIT; @@ -2694,7 +2694,7 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf) int int_mode = get_map_mode(&p, 0); // Determine the desired buffer value - long buffer_value = (buf == NULL) ? 0 : buf->handle; + int buffer_value = (buf == NULL) ? 0 : buf->handle; for (int i = 0; i < MAX_MAPHASH; i++) { for (const mapblock_T *current_maphash = get_maphash(i, buf); diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 913c9b2a29..1646da0e44 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1315,7 +1315,7 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount // position. // "spaces_removed" is the number of spaces that were removed, matters when the // cursor is inside them. -void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, long col_amount, +void mark_col_adjust(linenr_T lnum, colnr_T mincol, linenr_T lnum_amount, colnr_T col_amount, int spaces_removed) { int fnum = curbuf->b_fnum; diff --git a/src/nvim/match.c b/src/nvim/match.c index d54e2ce58a..e087d4f45d 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -419,7 +419,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ FUNC_ATTR_NONNULL_ARG(2) { colnr_T matchcol; - long nmatched = 0; + int nmatched = 0; const int called_emsg_before = called_emsg; // for :{range}s/pat only highlight inside the range diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 716d05e27a..024e5777b3 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2396,7 +2396,7 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo } // The line was inserted below 'lnum' - ml_updatechunk(buf, lnum + 1, (long)len, ML_CHNK_ADDLINE); + ml_updatechunk(buf, lnum + 1, len, ML_CHNK_ADDLINE); return OK; } @@ -2546,11 +2546,11 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) buf->b_ml.ml_line_count--; int line_start = ((dp->db_index[idx]) & DB_INDEX_MASK); - long line_size; + int line_size; if (idx == 0) { // first line in block, text at the end - line_size = dp->db_txt_end - (unsigned)line_start; + line_size = (int)(dp->db_txt_end - (unsigned)line_start); } else { - line_size = ((dp->db_index[idx - 1]) & DB_INDEX_MASK) - (unsigned)line_start; + line_size = (int)(((dp->db_index[idx - 1]) & DB_INDEX_MASK) - (unsigned)line_start); } // Line should always have an NL char internally (represented as NUL), @@ -2788,7 +2788,7 @@ static void ml_flush_line(buf_T *buf) memmove(old_line - extra, new_line, (size_t)new_len); buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); // The else case is already covered by the insert and delete - ml_updatechunk(buf, lnum, (long)extra, ML_CHNK_UPDLINE); + ml_updatechunk(buf, lnum, extra, ML_CHNK_UPDLINE); } else { // Cannot do it in one data block: Delete and append. // Append first, because ml_delete_int() cannot delete the @@ -3705,7 +3705,7 @@ enum { /// Careful: ML_CHNK_ADDLINE may cause ml_find_line() to be called. /// ML_CHNK_DELLINE: Subtract len from parent chunk, possibly deleting it /// ML_CHNK_UPDLINE: Add len to parent chunk, as a signed entity. -static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) +static void ml_updatechunk(buf_T *buf, linenr_T line, int len, int updtype) { static buf_T *ml_upd_lastbuf = NULL; static linenr_T ml_upd_lastline; @@ -3732,8 +3732,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) // First line in empty buffer from ml_flush_line() -- reset buf->b_ml.ml_usedchunks = 1; buf->b_ml.ml_chunksize[0].mlcs_numlines = 1; - buf->b_ml.ml_chunksize[0].mlcs_totalsize = - (long)strlen(buf->b_ml.ml_line_ptr) + 1; + buf->b_ml.ml_chunksize[0].mlcs_totalsize = (int)strlen(buf->b_ml.ml_line_ptr) + 1; return; } @@ -3779,7 +3778,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) buf->b_ml.ml_chunksize + curix, (size_t)(buf->b_ml.ml_usedchunks - curix) * sizeof(chunksize_T)); // Compute length of first half of lines in the split chunk - long size = 0; + int size = 0; int linecnt = 0; while (curline < buf->b_ml.ml_line_count && linecnt < MLCS_MINL) { @@ -3893,14 +3892,14 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype) /// @param no_ff ignore 'fileformat' option, always use one byte for NL. /// /// @return -1 if information is not available -long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) +int ml_find_line_or_offset(buf_T *buf, linenr_T lnum, int *offp, bool no_ff) { linenr_T curline; int curix; - long size; + int size; bhdr_T *hp; int text_end; - long offset; + int offset; int ffdos = !no_ff && (get_fileformat(buf) == EOL_DOS); int extra = 0; @@ -3918,7 +3917,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) if (lnum == 0 || buf->b_ml.ml_line_lnum < lnum || !no_ff) { ml_flush_line(curbuf); } else if (can_cache && buf->b_ml.ml_line_offset > 0) { - return (long)buf->b_ml.ml_line_offset; + return (int)buf->b_ml.ml_line_offset; } if (buf->b_ml.ml_usedchunks == -1 @@ -3951,7 +3950,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) || (offset != 0 && offset > size + buf->b_ml.ml_chunksize[curix].mlcs_totalsize - + (long)ffdos * buf->b_ml.ml_chunksize[curix].mlcs_numlines))) { + + ffdos * buf->b_ml.ml_chunksize[curix].mlcs_numlines))) { curline += buf->b_ml.ml_chunksize[curix].mlcs_numlines; size += buf->b_ml.ml_chunksize[curix].mlcs_totalsize; if (offset && ffdos) { @@ -4039,9 +4038,9 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) } /// Goto byte in buffer with offset 'cnt'. -void goto_byte(long cnt) +void goto_byte(int cnt) { - long boff = cnt; + int boff = cnt; ml_flush_line(curbuf); // cached line may be dirty setpcmark(); diff --git a/src/nvim/memline_defs.h b/src/nvim/memline_defs.h index fd50a73f8c..028c9b8915 100644 --- a/src/nvim/memline_defs.h +++ b/src/nvim/memline_defs.h @@ -17,7 +17,7 @@ typedef struct info_pointer { typedef struct ml_chunksize { int mlcs_numlines; - long mlcs_totalsize; + int mlcs_totalsize; } chunksize_T; // Flags when calling ml_updatechunk() diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 997f465f02..fdfd63e25f 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -767,8 +767,6 @@ void free_all_mem(void) // Free all option values. Must come after closing windows. free_all_options(); - free_arshape_buf(); - // Clear registers. clear_registers(); ResetRedobuff(); diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 4a72464527..5eb8b41015 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -78,7 +78,7 @@ void ex_menu(exarg_T *eap) char *arg; char *p; int i; - long pri_tab[MENUDEPTH + 1]; + int pri_tab[MENUDEPTH + 1]; TriState enable = kNone; // kTrue for "menu enable", // kFalse for "menu disable vimmenu_T menuarg; @@ -129,7 +129,7 @@ void ex_menu(exarg_T *eap) } if (ascii_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !ascii_iswhite(*arg); i++) { - pri_tab[i] = getdigits_long(&arg, false, 0); + pri_tab[i] = getdigits_int(&arg, false, 0); if (pri_tab[i] == 0) { pri_tab[i] = 500; } @@ -265,7 +265,7 @@ theend: /// @param[out] menuarg menu entry /// @param[] pri_tab priority table /// @param[in] call_data Right hand side command -static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const long *const pri_tab, +static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const int *const pri_tab, const char *const call_data) { char *path_name; @@ -366,7 +366,7 @@ static int add_menu_path(const char *const menu_path, vimmenu_T *menuarg, const menu->en_name = NULL; menu->en_dname = NULL; } - menu->priority = (int)pri_tab[pri_idx]; + menu->priority = pri_tab[pri_idx]; menu->parent = parent; // Add after menu that has lower priority. diff --git a/src/nvim/message.c b/src/nvim/message.c index 67266b325c..c1acef8b0d 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -567,10 +567,10 @@ static char *get_emsg_lnum(void) if (SOURCING_NAME != NULL && (other_sourcing_name() || SOURCING_LNUM != last_sourcing_lnum) && SOURCING_LNUM != 0) { - const char *const p = _("line %4ld:"); + const char *const p = _("line %4" PRIdLINENR ":"); const size_t buf_len = 20 + strlen(p); char *const buf = xmalloc(buf_len); - snprintf(buf, buf_len, p, (long)SOURCING_LNUM); + snprintf(buf, buf_len, p, SOURCING_LNUM); return buf; } return NULL; @@ -693,8 +693,8 @@ bool emsg_multiline(const char *s, bool multiline) // Log (silent) errors as debug messages. if (SOURCING_NAME != NULL && SOURCING_LNUM != 0) { - DLOG("(:silent) %s (%s (line %ld))", - s, SOURCING_NAME, (long)SOURCING_LNUM); + DLOG("(:silent) %s (%s (line %" PRIdLINENR "))", + s, SOURCING_NAME, SOURCING_LNUM); } else { DLOG("(:silent) %s", s); } @@ -704,7 +704,7 @@ bool emsg_multiline(const char *s, bool multiline) // Log editor errors as INFO. if (SOURCING_NAME != NULL && SOURCING_LNUM != 0) { - ILOG("%s (%s (line %ld))", s, SOURCING_NAME, (long)SOURCING_LNUM); + ILOG("%s (%s (line %" PRIdLINENR "))", s, SOURCING_NAME, SOURCING_LNUM); } else { ILOG("%s", s); } @@ -1357,7 +1357,7 @@ bool messaging(void) void msgmore(int n) { - long pn; + int pn; if (global_busy // no messages now, wait until global is finished || !messaging()) { // 'lazyredraw' set, don't do messages now @@ -1380,11 +1380,11 @@ void msgmore(int n) if (pn > p_report) { if (n > 0) { vim_snprintf(msg_buf, MSG_BUF_LEN, - NGETTEXT("%ld more line", "%ld more lines", pn), + NGETTEXT("%d more line", "%d more lines", pn), pn); } else { vim_snprintf(msg_buf, MSG_BUF_LEN, - NGETTEXT("%ld line less", "%ld fewer lines", pn), + NGETTEXT("%d line less", "%d fewer lines", pn), pn); } if (got_int) { diff --git a/src/nvim/move.c b/src/nvim/move.c index 8eaf40d135..25dee0a114 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -340,9 +340,7 @@ void update_topline(win_T *wp) assert(wp->w_buffer != 0); if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) { if (wp->w_cursor.lnum < wp->w_botline) { - if (((long)wp->w_cursor.lnum - >= (long)wp->w_botline - *so_ptr - || hasAnyFolding(wp))) { + if ((wp->w_cursor.lnum >= wp->w_botline - *so_ptr || hasAnyFolding(wp))) { lineoff_T loff; // Cursor is (a few lines) above botline, check if there are @@ -1188,7 +1186,7 @@ void f_virtcol2col(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// /// @param line_count number of lines to scroll /// @param byfold if true, count a closed fold as one line -bool scrolldown(long line_count, int byfold) +bool scrolldown(linenr_T line_count, int byfold) { int done = 0; // total # of physical lines done int width1 = 0; @@ -1203,7 +1201,7 @@ bool scrolldown(long line_count, int byfold) // Make sure w_topline is at the first of a sequence of folded lines. (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); validate_cursor(); // w_wrow needs to be valid - for (long todo = line_count; todo > 0; todo--) { + for (int todo = line_count; todo > 0; todo--) { if (curwin->w_topfill < win_get_fill(curwin, curwin->w_topline) && curwin->w_topfill < curwin->w_height_inner - 1) { curwin->w_topfill++; @@ -1301,11 +1299,11 @@ bool scrolldown(long line_count, int byfold) if (curwin->w_cursor.lnum == curwin->w_topline && do_sms) { int so = get_scrolloff_value(curwin); - long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; + colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; // make sure the cursor is in the visible text validate_virtcol(); - long col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols; + colnr_T col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols; int row = 0; if (col >= width1) { col -= width1; @@ -1346,7 +1344,7 @@ bool scrollup(linenr_T line_count, int byfold) // 'smoothscroll': increase "w_skipcol" until it goes over the end of // the line, then advance to the next line. // folding: count each sequence of folded lines as one logical line. - for (long todo = line_count; todo > 0; todo--) { + for (int todo = line_count; todo > 0; todo--) { if (curwin->w_topfill > 0) { curwin->w_topfill--; } else { @@ -1428,7 +1426,7 @@ bool scrollup(linenr_T line_count, int byfold) int width2 = width1 + col_off2; int extra2 = col_off - col_off2; int so = get_scrolloff_value(curwin); - long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; + colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; int space_cols = (curwin->w_height_inner - 1) * width2; // If we have non-zero scrolloff, just ignore the marker as we are @@ -1479,7 +1477,7 @@ void adjust_skipcol(void) } int width2 = width1 + curwin_col_off2(); int so = get_scrolloff_value(curwin); - long scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; + colnr_T scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2; bool scrolled = false; validate_cheight(); @@ -1509,7 +1507,7 @@ void adjust_skipcol(void) redraw_later(curwin, UPD_NOT_VALID); return; // don't scroll in the other direction now } - long col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols; + colnr_T col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols; int row = 0; if (col >= width1) { col -= width1; @@ -2317,9 +2315,9 @@ void cursor_correct(void) /// and update the screen. /// /// @return FAIL for failure, OK otherwise. -int onepage(Direction dir, long count) +int onepage(Direction dir, int count) { - long n; + int n; int retval = OK; lineoff_T loff; linenr_T old_topline = curwin->w_topline; @@ -2560,7 +2558,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir) // Scroll 'scroll' lines up or down. void halfpage(bool flag, linenr_T Prenum) { - long scrolled = 0; + int scrolled = 0; int i; if (Prenum) { diff --git a/src/nvim/msgpack_rpc/unpacker.c b/src/nvim/msgpack_rpc/unpacker.c index 37e32729cc..5a65e6c5df 100644 --- a/src/nvim/msgpack_rpc/unpacker.c +++ b/src/nvim/msgpack_rpc/unpacker.c @@ -173,9 +173,6 @@ static void api_parse_enter(mpack_parser_t *parser, mpack_node_t *node) node->data[0].p = result; break; } - - default: - abort(); } } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 1a212661c5..f1bc46412f 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1496,7 +1496,7 @@ static int normal_check(VimState *state) /// Set v:prevcount only when "set_prevcount" is true. static void set_vcount_ca(cmdarg_T *cap, bool *set_prevcount) { - long count = cap->count0; + int64_t count = cap->count0; // multiply with cap->opcount the same way as above if (cap->opcount != 0) { @@ -1856,7 +1856,7 @@ void clear_showcmd(void) if (VIsual_active && !char_avail()) { int cursor_bot = lt(VIsual, curwin->w_cursor); - long lines; + int lines; colnr_T leftcol, rightcol; linenr_T top, bot; @@ -2115,8 +2115,7 @@ void do_check_scrollbind(bool check) && (curwin->w_topline != old_topline || curwin->w_topfill != old_topfill || curwin->w_leftcol != old_leftcol)) { - check_scrollbind(curwin->w_topline - old_topline, - (long)(curwin->w_leftcol - old_leftcol)); + check_scrollbind(curwin->w_topline - old_topline, curwin->w_leftcol - old_leftcol); } } else if (vim_strchr(p_sbo, 'j')) { // jump flag set in 'scrollopt' // When switching between windows, make sure that the relative @@ -2142,7 +2141,7 @@ void do_check_scrollbind(bool check) /// Synchronize any windows that have "scrollbind" set, based on the /// number of rows by which the current window has changed /// (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) -void check_scrollbind(linenr_T topline_diff, long leftcol_diff) +void check_scrollbind(linenr_T topline_diff, int leftcol_diff) { bool want_ver; bool want_hor; @@ -2468,7 +2467,7 @@ bool find_decl(char *ptr, size_t len, bool locally, bool thisblock, int flags_ar /// 'dist' must be positive. /// /// @return true if able to move cursor, false otherwise. -static bool nv_screengo(oparg_T *oap, int dir, long dist) +static bool nv_screengo(oparg_T *oap, int dir, int dist) { int linelen = (int)linetabsize(curwin, curwin->w_cursor.lnum); bool retval = true; @@ -2784,7 +2783,7 @@ static void nv_zet(cmdarg_T *cap) { colnr_T col; int nchar = cap->nchar; - long old_fdl = (long)curwin->w_p_fdl; + int old_fdl = (int)curwin->w_p_fdl; int old_fen = curwin->w_p_fen; int siso = get_sidescrolloff_value(curwin); diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 348a86a0f6..cb8d1dabc0 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -983,10 +983,12 @@ static int stuff_yank(int regname, char *p) yankreg_T *reg = get_yank_register(regname, YREG_YANK); if (is_append_register(regname) && reg->y_array != NULL) { char **pp = &(reg->y_array[reg->y_size - 1]); - char *lp = xmalloc(strlen(*pp) + strlen(p) + 1); - STRCPY(lp, *pp); - // TODO(philix): use xstpcpy() in stuff_yank() - STRCAT(lp, p); + const size_t ppl = strlen(*pp); + const size_t pl = strlen(p); + char *lp = xmalloc(ppl + pl + 1); + memcpy(lp, *pp, ppl); + memcpy(lp + ppl, p, pl); + *(lp + ppl + pl) = NUL; xfree(p); xfree(*pp); *pp = lp; @@ -2202,7 +2204,7 @@ bool swapchar(int op_type, pos_T *pos) } /// Insert and append operators for Visual mode. -void op_insert(oparg_T *oap, long count1) +void op_insert(oparg_T *oap, int count1) { int pre_textlen = 0; char *firstline; @@ -2491,7 +2493,7 @@ int op_change(oparg_T *oap) ins_len = (int)strlen(firstline) - pre_textlen; if (ins_len > 0) { - long offset; + int offset; char *newp; char *oldp; // Subsequent calls to ml_get() flush the firstline data - take a @@ -2932,7 +2934,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) pos_T old_pos; char *insert_string = NULL; bool allocated = false; - long cnt; + int cnt; const pos_T orig_start = curbuf->b_op_start; const pos_T orig_end = curbuf->b_op_end; unsigned cur_ve_flags = get_ve_flags(); @@ -3334,7 +3336,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) ptr += bd.startspaces; // insert the new text - for (long j = 0; j < count; j++) { + for (int j = 0; j < count; j++) { memmove(ptr, y_array[i], (size_t)yanklen); ptr += yanklen; @@ -5339,7 +5341,7 @@ void cursor_pos_info(dict_T *dict) linenr_T lnum; int eol_size; varnumber_T last_check = 100000L; - long line_count_selected = 0; + int line_count_selected = 0; if (get_fileformat(curbuf) == EOL_DOS) { eol_size = 2; } else { @@ -5398,7 +5400,7 @@ void cursor_pos_info(dict_T *dict) if (l_VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { char *s = NULL; - long len = 0L; + int len = 0L; switch (l_VIsual_mode) { case Ctrl_V: @@ -5406,7 +5408,7 @@ void cursor_pos_info(dict_T *dict) block_prep(&oparg, &bd, lnum, false); virtual_op = kNone; s = bd.textstart; - len = (long)bd.textlen; + len = bd.textlen; break; case 'V': s = ml_get(lnum); @@ -5429,7 +5431,7 @@ void cursor_pos_info(dict_T *dict) if (lnum == curbuf->b_ml.ml_line_count && !curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol) - && (long)strlen(s) < len) { + && (int)strlen(s) < len) { byte_count_cursor -= eol_size; } } diff --git a/src/nvim/option.c b/src/nvim/option.c index c0353e52be..6a3079e0a6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3461,9 +3461,8 @@ OptVal optval_copy(OptVal o) return o; case kOptValTypeString: return STRING_OPTVAL(copy_string(o.data.string, NULL)); - default: - abort(); } + UNREACHABLE; } // Match type of OptVal with the type of the target option. Returns true if the types match and @@ -3482,9 +3481,8 @@ static bool optval_match_type(OptVal o, int opt_idx) return flags & P_NUM; case kOptValTypeString: return flags & P_STRING; - default: - abort(); } + UNREACHABLE; } // Return C-string representation of OptVal. Caller must free the returned C-string. @@ -3505,9 +3503,8 @@ static char *optval_to_cstr(OptVal o) snprintf(buf, o.data.string.size + 3, "\"%s\"", o.data.string.data); return buf; } - default: - abort(); } + UNREACHABLE; } // Get an allocated string containing a list of valid types for an option. @@ -5496,6 +5493,9 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) xp->xp_backslash = XP_BS_ONE; } } + if (flags & P_COMMA) { + xp->xp_backslash |= XP_BS_COMMA; + } } // For an option that is a list of file names, or comma/colon-separated @@ -5511,8 +5511,12 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags) while (s > xp->xp_pattern && *(s - 1) == '\\') { s--; } - if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3)) - || (*p == ',' && (flags & P_COMMA) && ((p - s) % 1) == 0) + if ((*p == ' ' && ((xp->xp_backslash & XP_BS_THREE) && (p - s) < 3)) +#if defined(BACKSLASH_IN_FILENAME) + || (*p == ',' && (flags & P_COMMA) && (p - s) < 1) +#else + || (*p == ',' && (flags & P_COMMA) && (p - s) < 2) +#endif || (*p == ':' && (flags & P_COLON))) { xp->xp_pattern = p + 1; break; diff --git a/src/nvim/option_vars.h b/src/nvim/option_vars.h index 86e7f4cee8..a5263cd4a7 100644 --- a/src/nvim/option_vars.h +++ b/src/nvim/option_vars.h @@ -571,6 +571,7 @@ EXTERN char *p_mouse; ///< 'mouse' EXTERN char *p_mousem; ///< 'mousemodel' EXTERN int p_mousemev; ///< 'mousemoveevent' EXTERN int p_mousef; ///< 'mousefocus' +EXTERN int p_mh; ///< 'mousehide' EXTERN char *p_mousescroll; ///< 'mousescroll' EXTERN OptInt p_mousescroll_vert INIT(= MOUSESCROLL_VERT_DFLT); EXTERN OptInt p_mousescroll_hor INIT(= MOUSESCROLL_HOR_DFLT); diff --git a/src/nvim/options.lua b/src/nvim/options.lua index e70fe8614f..d5f41c5a89 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -2932,7 +2932,7 @@ return { "auto": resize to the minimum amount of folds to display. "auto:[1-9]": resize to accommodate multiple folds up to the selected level - 0: to disable foldcolumn + "0": to disable foldcolumn "[1-9]": to display a fixed number of columns See |folding|. ]=], @@ -5452,9 +5452,11 @@ return { ]=], enable_if = false, full_name = 'mousehide', + redraw = { 'ui_option' }, scope = { 'global' }, short_desc = N_('hide mouse pointer while typing'), type = 'bool', + varname = 'p_mh', }, { abbreviation = 'mousem', @@ -5924,6 +5926,10 @@ return { option may be relative or absolute. - Use commas to separate directory names: > :set path=.,/usr/local/include,/usr/include + < - Spaces can also be used to separate directory names. To have a + space in a directory name, precede it with an extra backslash, and + escape the space: > + :set path=.,/dir/with\\\ space < - To include a comma in a directory name precede it with an extra backslash: > :set path=.,/dir/with\\,comma @@ -8673,8 +8679,8 @@ return { deny_duplicates = true, desc = [=[ Filenames for the tag command, separated by spaces or commas. To - include a space or comma in a file name, precede it with a backslash - (see |option-backslash| about including spaces and backslashes). + include a space or comma in a file name, precede it with backslashes + (see |option-backslash| about including spaces/commas and backslashes). When a file name starts with "./", the '.' is replaced with the path of the current file. But only when the 'd' flag is not included in 'cpoptions'. Environment variables are expanded |:set_env|. Also see diff --git a/src/nvim/path.c b/src/nvim/path.c index 5d991ce719..15a8762da1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -848,7 +848,7 @@ static void expand_path_option(char *curdir, garray_T *gap) char *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { - copy_option_part(&path_option, buf, MAXPATHL, ","); + copy_option_part(&path_option, buf, MAXPATHL, " ,"); if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) { // Relative to current buffer: diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index e6d5831dd3..c532c08572 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -131,7 +131,7 @@ typedef struct qf_list_S { bool qf_multiline; bool qf_multiignore; bool qf_multiscan; - long qf_changedtick; + int qf_changedtick; } qf_list_T; /// Quickfix/Location list stack definition @@ -234,7 +234,7 @@ typedef struct { /// :vimgrep command arguments typedef struct vgr_args_S { - long tomatch; ///< maximum number of matches to find + int tomatch; ///< maximum number of matches to find char *spat; ///< search pattern int flags; ///< search modifier char **fnames; ///< list of files to search @@ -2756,7 +2756,7 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit, int int *opened_window) { qf_list_T *qfl = qf_get_curlist(qi); - long old_changetick = qfl->qf_changedtick; + int old_changetick = qfl->qf_changedtick; int old_qf_curlist = qi->qf_curlist; qfltype_T qfl_type = qfl->qfl_type; int retval = OK; @@ -2836,7 +2836,7 @@ static void qf_jump_goto_line(linenr_T qf_lnum, int qf_col, char qf_viscol, char // Move the cursor to the first line in the buffer pos_T save_cursor = curwin->w_cursor; curwin->w_cursor.lnum = 0; - if (!do_search(NULL, '/', '/', qf_pattern, (long)1, SEARCH_KEEP, NULL)) { + if (!do_search(NULL, '/', '/', qf_pattern, 1, SEARCH_KEEP, NULL)) { curwin->w_cursor = save_cursor; } } @@ -2891,7 +2891,7 @@ static void qf_jump_print_msg(qf_info_T *qi, int qf_index, qfline_T *qf_ptr, buf static int qf_jump_open_window(qf_info_T *qi, qfline_T *qf_ptr, bool newwin, int *opened_window) { qf_list_T *qfl = qf_get_curlist(qi); - long old_changetick = qfl->qf_changedtick; + int old_changetick = qfl->qf_changedtick; int old_qf_curlist = qi->qf_curlist; qfltype_T qfl_type = qfl->qfl_type; @@ -4051,7 +4051,7 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli // Call the 'quickfixtextfunc' function to get the list of lines to display in // the quickfix window for the entries 'start_idx' to 'end_idx'. -static list_T *call_qftf_func(qf_list_T *qfl, int qf_winid, long start_idx, long end_idx) +static list_T *call_qftf_func(qf_list_T *qfl, int qf_winid, int start_idx, int end_idx) { Callback *cb = &qftf_cb; list_T *qftf_list = NULL; @@ -4142,7 +4142,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q lnum = buf->b_ml.ml_line_count; } - list_T *qftf_list = call_qftf_func(qfl, qf_winid, lnum + 1, (long)qfl->qf_count); + list_T *qftf_list = call_qftf_func(qfl, qf_winid, lnum + 1, qfl->qf_count); listitem_T *qftf_li = tv_list_first(qftf_list); int prev_bufnr = -1; @@ -5227,7 +5227,7 @@ static bool vgr_qflist_valid(win_T *wp, qf_info_T *qi, unsigned qfid, char *titl /// Search for a pattern in all the lines in a buffer and add the matching lines /// to a quickfix list. static bool vgr_match_buflines(qf_list_T *qfl, char *fname, buf_T *buf, char *spat, - regmmatch_T *regmatch, long *tomatch, int duplicate_name, int flags) + regmmatch_T *regmatch, int *tomatch, int duplicate_name, int flags) FUNC_ATTR_NONNULL_ARG(1, 3, 4, 5, 6) { bool found_match = false; diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 3f792cd8d5..568f399664 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -893,11 +893,11 @@ static int64_t getoctchrs(void) // If the first character is '-', then the range is reversed. // Should end with 'end'. If minval is missing, zero is default, if maxval is // missing, a very big number is the default. -static int read_limits(long *minval, long *maxval) +static int read_limits(int *minval, int *maxval) { int reverse = false; char *first_char; - long tmp; + int tmp; if (*regparse == '-') { // Starts with '-', so reverse the range later. @@ -905,10 +905,10 @@ static int read_limits(long *minval, long *maxval) reverse = true; } first_char = regparse; - *minval = getdigits_long(®parse, false, 0); + *minval = getdigits_int(®parse, false, 0); if (*regparse == ',') { // There is a comma. if (ascii_isdigit(*++regparse)) { - *maxval = getdigits_long(®parse, false, MAX_LIMIT); + *maxval = getdigits_int(®parse, false, MAX_LIMIT); } else { *maxval = MAX_LIMIT; } @@ -2515,8 +2515,8 @@ bool vim_regexec_nl(regmatch_T *rmp, const char *line, colnr_T col) /// /// @return zero if there is no match. Return number of lines contained in the /// match otherwise. -long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, - proftime_T *tm, int *timed_out) +int vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, + proftime_T *tm, int *timed_out) FUNC_ATTR_NONNULL_ARG(1) { regexec_T rex_save; @@ -2535,7 +2535,7 @@ long vim_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, } rex_in_use = true; - long result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out); + int result = rmp->regprog->engine->regexec_multi(rmp, win, buf, lnum, col, tm, timed_out); rmp->regprog->re_in_use = false; // NFA engine aborted because it's very slow, use backtracking engine instead. diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index 0e1ea9d3b0..a38600c324 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -2466,8 +2466,8 @@ static uint8_t *regpiece(int *flagp) int op; uint8_t *next; int flags; - long minval; - long maxval; + int minval; + int maxval; ret = regatom(&flags); if (ret == NULL) { @@ -4869,7 +4869,7 @@ static bool regmatch(uint8_t *scan, proftime_T *tm, int *timed_out) /// @param timed_out flag set on timeout or NULL /// /// @return 0 for failure, or number of lines contained in the match. -static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out) +static int regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out) { rex.input = rex.line + col; rex.need_clear_subexpr = true; @@ -4939,12 +4939,12 @@ static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_o /// @param timed_out flag set on timeout or NULL /// /// @return 0 for failure, or number of lines contained in the match. -static long bt_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) +static int bt_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) { bt_regprog_T *prog; uint8_t *s; colnr_T col = startcol; - long retval = 0L; + int retval = 0; // Create "regstack" and "backpos" if they are not allocated yet. // We allocate *_INITIAL amount of bytes first and then set the grow size @@ -5175,8 +5175,8 @@ static int bt_regexec_nl(regmatch_T *rmp, uint8_t *line, colnr_T col, bool line_ /// /// @return zero if there is no match and number of lines contained in the match /// otherwise. -static long bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, - proftime_T *tm, int *timed_out) +static int bt_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, + proftime_T *tm, int *timed_out) { init_regexec_multi(rmp, win, buf, lnum); return bt_regexec_both(NULL, col, tm, timed_out); diff --git a/src/nvim/regexp_defs.h b/src/nvim/regexp_defs.h index ef155e8d46..8c2f5e4cd7 100644 --- a/src/nvim/regexp_defs.h +++ b/src/nvim/regexp_defs.h @@ -169,7 +169,7 @@ struct regengine { /// bt_regexec_nl or nfa_regexec_nl int (*regexec_nl)(regmatch_T *, uint8_t *, colnr_T, bool); /// bt_regexec_mult or nfa_regexec_mult - long (*regexec_multi)(regmmatch_T *, win_T *, buf_T *, linenr_T, colnr_T, proftime_T *, int *); + int (*regexec_multi)(regmmatch_T *, win_T *, buf_T *, linenr_T, colnr_T, proftime_T *, int *); // uint8_t *expr; }; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 3e573f1607..d33a0c867d 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -2541,7 +2541,7 @@ static int nfa_regpiece(void) int i; int op; int ret; - long minval, maxval; + int minval, maxval; bool greedy = true; // Braces are prefixed with '-' ? parse_state_T old_state; parse_state_T new_state; @@ -5792,7 +5792,7 @@ static int skip_to_start(int c, colnr_T *colp) // Check for a match with match_text. // Called after skip_to_start() has found regstart. // Returns zero for no match, 1 for a match. -static long find_match_text(colnr_T *startcol, int regstart, uint8_t *match_text) +static int find_match_text(colnr_T *startcol, int regstart, uint8_t *match_text) { #define PTR2LEN(x) utf_ptr2len(x) @@ -7207,7 +7207,7 @@ theend: /// @param timed_out flag set on timeout or NULL /// /// @return <= 0 for failure, number of lines contained in the match otherwise. -static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out) +static int nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out) { int i; regsubs_T subs, m; @@ -7334,10 +7334,10 @@ static long nfa_regtry(nfa_regprog_T *prog, colnr_T col, proftime_T *tm, int *ti /// /// @return <= 0 if there is no match and number of lines contained in the /// match otherwise. -static long nfa_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) +static int nfa_regexec_both(uint8_t *line, colnr_T startcol, proftime_T *tm, int *timed_out) { nfa_regprog_T *prog; - long retval = 0L; + int retval = 0; colnr_T col = startcol; if (REG_MULTI) { @@ -7631,8 +7631,8 @@ static int nfa_regexec_nl(regmatch_T *rmp, uint8_t *line, colnr_T col, bool line /// /// @par /// FIXME if this behavior is not compatible. -static long nfa_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, - proftime_T *tm, int *timed_out) +static int nfa_regexec_multi(regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, + proftime_T *tm, int *timed_out) { init_regexec_multi(rmp, win, buf, lnum); return nfa_regexec_both(NULL, col, tm, timed_out); diff --git a/src/nvim/search.c b/src/nvim/search.c index 2d13ad3f0d..8fb354bac7 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -2554,9 +2554,9 @@ static int is_zero_width(char *pattern, int move, pos_T *cur, Direction directio // start and end are in the same position. do { regmatch.startpos[0].col++; - nmatched = (int)vim_regexec_multi(®match, curwin, curbuf, - pos.lnum, regmatch.startpos[0].col, - NULL, NULL); + nmatched = vim_regexec_multi(®match, curwin, curbuf, + pos.lnum, regmatch.startpos[0].col, + NULL, NULL); if (nmatched != 0) { break; } diff --git a/src/nvim/spell_defs.h b/src/nvim/spell_defs.h index 0b95cfed8e..5c2ef67a96 100644 --- a/src/nvim/spell_defs.h +++ b/src/nvim/spell_defs.h @@ -120,7 +120,7 @@ struct slang_S { bool sl_add; // true if it's a .add file. uint8_t *sl_fbyts; // case-folded word bytes - long sl_fbyts_len; // length of sl_fbyts + int sl_fbyts_len; // length of sl_fbyts idx_T *sl_fidxs; // case-folded word indexes uint8_t *sl_kbyts; // keep-case word bytes idx_T *sl_kidxs; // keep-case word indexes diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index 25e08abb0e..3d3da3c3d6 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -1678,7 +1678,7 @@ static int *mb_str2wide(const char *s) /// @param prefixcnt when "prefixtree" is true: prefix count /// /// @return zero when OK, SP_ value for an error. -static int spell_read_tree(FILE *fd, uint8_t **bytsp, long *bytsp_len, idx_T **idxsp, +static int spell_read_tree(FILE *fd, uint8_t **bytsp, int *bytsp_len, idx_T **idxsp, bool prefixtree, int prefixcnt) FUNC_ATTR_NONNULL_ARG(1, 2, 4) { @@ -4214,7 +4214,7 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int wordnode_T *child; hash_T hash; hashitem_T *hi; - long len = 0; + int len = 0; unsigned nr, n; int compressed = 0; @@ -4262,7 +4262,7 @@ static int node_compress(spellinfo_T *spin, wordnode_T *node, hashtab_T *ht, int } } } - *tot += (int)len + 1; // add one for the node that stores the length + *tot += len + 1; // add one for the node that stores the length // Make a hash key for the node and its siblings, so that we can quickly // find a lookalike node. This must be done after compressing the sibling diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index fb467093ad..9af1bd862f 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -875,7 +875,7 @@ void draw_tabline(void) /// the v:lnum and v:relnum variables don't have to be updated. /// /// @return The width of the built status column string for line "lnum" -int build_statuscol_str(win_T *wp, linenr_T lnum, long relnum, statuscol_T *stcp) +int build_statuscol_str(win_T *wp, linenr_T lnum, linenr_T relnum, statuscol_T *stcp) { // Only update click definitions once per window per redraw. // Don't update when current width is 0, since it will be redrawn again if not empty. @@ -1170,7 +1170,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // { Determine the number of bytes to remove // Find the first character that should be included. - long n = 0; + int n = 0; while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) { group_len -= ptr2cells(t + n); n += utfc_ptr2len(t + n); @@ -1295,7 +1295,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n if (*fmt_p == STL_TABCLOSENR) { if (minwid == 0) { // %X ends the close label, go back to the previous tab label nr. - for (long n = curitem - 1; n >= 0; n--) { + for (int n = curitem - 1; n >= 0; n--) { if (stl_items[n].type == TabPage && stl_items[n].minwid >= 0) { minwid = stl_items[n].minwid; break; @@ -1540,8 +1540,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n } case STL_PERCENTAGE: - num = (int)(((long)wp->w_cursor.lnum * 100L) / - (long)wp->w_buffer->b_ml.ml_line_count); + num = ((wp->w_cursor.lnum * 100) / wp->w_buffer->b_ml.ml_line_count); break; case STL_ALTPERCENT: @@ -1592,11 +1591,11 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n base = kNumBaseHexadecimal; FALLTHROUGH; case STL_OFFSET: { - long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL, - false); + int l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL, + false); num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? - 0L : (int)l + 1 + ((State & MODE_INSERT) == 0 && empty_line ? - 0 : (int)wp->w_cursor.col); + 0L : l + 1 + ((State & MODE_INSERT) == 0 && empty_line ? + 0 : (int)wp->w_cursor.col); break; } case STL_BYTEVAL_X: @@ -1778,7 +1777,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n } // } - long l = vim_strsize(t); + int l = vim_strsize(t); // If this item is non-empty, record that the last thing // we put in the output buffer was an item @@ -1881,8 +1880,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // { Determine how many characters the number will take up when printed // Note: We have to cast the base because the compiler uses // unsigned ints for the enum values. - long num_chars = 1; - for (long n = num; n >= (int)base; n /= (int)base) { + int num_chars = 1; + for (int n = num; n >= (int)base; n /= (int)base) { num_chars++; } @@ -1905,7 +1904,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n num_chars += 2; // How many extra characters there are - long n = num_chars - maxwid; + int n = num_chars - maxwid; // { Reduce the number by base^n while (num_chars-- > maxwid) { @@ -2029,7 +2028,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // Truncate at the truncation point we found } else { // { Determine how many bytes to remove - long trunc_len = 0; + int trunc_len = 0; while (width >= maxwidth) { width -= ptr2cells(trunc_p + trunc_len); trunc_len += utfc_ptr2len(trunc_p + trunc_len); @@ -2049,7 +2048,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n // Note: The offset is one less than the truncation length because // the truncation marker `<` is not counted. - long item_offset = trunc_len - 1; + int item_offset = trunc_len - 1; for (int i = item_idx; i < itemcnt; i++) { // Items starting at or after the end of the truncated section need @@ -2124,7 +2123,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n if (hltab != NULL) { *hltab = stl_hltab; stl_hlrec_t *sp = stl_hltab; - for (long l = 0; l < itemcnt; l++) { + for (int l = 0; l < itemcnt; l++) { if (stl_items[l].type == Highlight) { sp->start = stl_items[l].start; sp->userhl = stl_items[l].minwid; @@ -2139,7 +2138,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n if (tabtab != NULL) { *tabtab = stl_tabtab; StlClickRecord *cur_tab_rec = stl_tabtab; - for (long l = 0; l < itemcnt; l++) { + for (int l = 0; l < itemcnt; l++) { if (stl_items[l].type == TabPage) { cur_tab_rec->start = stl_items[l].start; if (stl_items[l].minwid == 0) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6bb841b1f8..a35352136b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5646,11 +5646,11 @@ static void syntime_report(void) p = GA_APPEND_VIA_PTR(time_entry_T, &ga); p->total = spp->sp_time.total; total_total = profile_add(total_total, spp->sp_time.total); - p->count = (int)spp->sp_time.count; - p->match = (int)spp->sp_time.match; - total_count += (int)spp->sp_time.count; + p->count = spp->sp_time.count; + p->match = spp->sp_time.match; + total_count += spp->sp_time.count; p->slowest = spp->sp_time.slowest; - proftime_T tm = profile_divide(spp->sp_time.total, (int)spp->sp_time.count); + proftime_T tm = profile_divide(spp->sp_time.total, spp->sp_time.count); p->average = tm; p->id = spp->sp_syn.id; p->pattern = spp->sp_pattern; diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 169525da20..5d1bd09a6c 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -714,7 +714,7 @@ static bool is_filter_char(int c) return !!(tpf_flags & flag); } -void terminal_paste(long count, char **y_array, size_t y_size) +void terminal_paste(int count, char **y_array, size_t y_size) { if (y_size == 0) { return; @@ -1584,7 +1584,7 @@ static void refresh_terminal(Terminal *term) } return; } - long ml_before = buf->b_ml.ml_line_count; + linenr_T ml_before = buf->b_ml.ml_line_count; // refresh_ functions assume the terminal buffer is current aco_save_T aco; @@ -1594,7 +1594,7 @@ static void refresh_terminal(Terminal *term) refresh_screen(term, buf); aucmd_restbuf(&aco); - long ml_added = buf->b_ml.ml_line_count - ml_before; + int ml_added = buf->b_ml.ml_line_count - ml_before; adjust_topline(term, buf, ml_added); } @@ -1754,7 +1754,7 @@ static void refresh_screen(Terminal *term, buf_T *buf) term->invalid_end = -1; } -static void adjust_topline(Terminal *term, buf_T *buf, long added) +static void adjust_topline(Terminal *term, buf_T *buf, int added) { FOR_ALL_TAB_WINDOWS(tp, wp) { if (wp->w_buffer == buf) { diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 13e51b9a9e..f2b30fd14b 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -1108,15 +1108,13 @@ void format_lines(linenr_T line_count, bool avoid_fex) } if (next_leader_len > 0) { (void)del_bytes(next_leader_len, false, false); - mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, - (long)-next_leader_len, 0); + mark_col_adjust(curwin->w_cursor.lnum, 0, 0, -next_leader_len, 0); } else if (second_indent > 0) { // the "leader" for FO_Q_SECOND int indent = (int)getwhitecols_curline(); if (indent > 0) { (void)del_bytes(indent, false, false); - mark_col_adjust(curwin->w_cursor.lnum, - (colnr_T)0, 0L, (long)-indent, 0); + mark_col_adjust(curwin->w_cursor.lnum, 0, 0, -indent, 0); } } curwin->w_cursor.lnum--; diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 18a56c74ca..3d156ba24e 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -733,7 +733,7 @@ int current_sent(oparg_T *oap, int count, bool include) bool start_blank; int c; bool at_start_sent; - long ncount; + int ncount; start_pos = curwin->w_cursor; pos = start_pos; @@ -838,7 +838,7 @@ extend: } } if (ncount > 0) { - findsent_forward((int)ncount, true); + findsent_forward(ncount, true); } else { decl(&curwin->w_cursor); } @@ -1142,7 +1142,7 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include) again: // Search backwards for unclosed "<aaa>". // Put this position in start_pos. - for (long n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { if (do_searchpair("<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)", "", "</[^>]*>", BACKWARD, NULL, 0, diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 944c1d14c2..260bf55093 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -287,7 +287,7 @@ static void terminfo_start(TUIData *tui) const char *colorterm = os_getenv("COLORTERM"); const char *termprg = os_getenv("TERM_PROGRAM"); const char *vte_version_env = os_getenv("VTE_VERSION"); - long vtev = vte_version_env ? strtol(vte_version_env, NULL, 10) : 0; + int vtev = vte_version_env ? (int)strtol(vte_version_env, NULL, 10) : 0; bool iterm_env = termprg && strstr(termprg, "iTerm.app"); bool nsterm = (termprg && strstr(termprg, "Apple_Terminal")) || terminfo_is_term_family(term, "nsterm"); @@ -295,7 +295,7 @@ static void terminfo_start(TUIData *tui) || os_getenv("KONSOLE_PROFILE_NAME") || os_getenv("KONSOLE_DBUS_SESSION"); const char *konsolev_env = os_getenv("KONSOLE_VERSION"); - long konsolev = konsolev_env ? strtol(konsolev_env, NULL, 10) + int konsolev = konsolev_env ? (int)strtol(konsolev_env, NULL, 10) : (konsole ? 1 : 0); patch_terminfo_bugs(tui, term, colorterm, vtev, konsolev, iterm_env, nsterm); @@ -1135,8 +1135,6 @@ void tui_set_mode(TUIData *tui, ModeShape mode) int shape; switch (c.shape) { - default: - abort(); break; case SHAPE_BLOCK: shape = 1; break; case SHAPE_HOR: @@ -1456,7 +1454,7 @@ void tui_option_set(TUIData *tui, String name, Object value) } else if (strequal(name.data, "ttimeout")) { tui->input.ttimeout = value.data.boolean; } else if (strequal(name.data, "ttimeoutlen")) { - tui->input.ttimeoutlen = (long)value.data.integer; + tui->input.ttimeoutlen = (OptInt)value.data.integer; } else if (strequal(name.data, "verbose")) { tui->verbose = value.data.integer; } @@ -1689,7 +1687,7 @@ static int unibi_find_ext_bool(unibi_term *ut, const char *name) /// Several entries in terminfo are known to be deficient or outright wrong; /// and several terminal emulators falsely announce incorrect terminal types. static void patch_terminfo_bugs(TUIData *tui, const char *term, const char *colorterm, - long vte_version, long konsolev, bool iterm_env, bool nsterm) + int vte_version, int konsolev, bool iterm_env, bool nsterm) { unibi_term *ut = tui->ut; const char *xterm_version = os_getenv("XTERM_VERSION"); @@ -2019,7 +2017,7 @@ static void patch_terminfo_bugs(TUIData *tui, const char *term, const char *colo /// This adds stuff that is not in standard terminfo as extended unibilium /// capabilities. -static void augment_terminfo(TUIData *tui, const char *term, long vte_version, long konsolev, +static void augment_terminfo(TUIData *tui, const char *term, int vte_version, int konsolev, bool iterm_env, bool nsterm) { unibi_term *ut = tui->ut; diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 758ee036b4..7a109ba4d3 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -147,7 +147,7 @@ static const char e_write_error_in_undo_file_str[] = N_("E829: Write error in undo file: %s"); // used in undo_end() to report number of added and deleted lines -static long u_newcount, u_oldcount; +static int u_newcount, u_oldcount; // When 'u' flag included in 'cpoptions', we behave like vi. Need to remember // the action that "u" should do. @@ -507,7 +507,7 @@ int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int re if (size == 1) { uep = u_get_headentry(buf); prev_uep = NULL; - for (long i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { if (uep == NULL) { break; } @@ -589,7 +589,7 @@ int u_savecommon(buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int re if (size > 0) { uep->ue_array = xmalloc(sizeof(char *) * (size_t)size); linenr_T lnum; - long i; + int i; for (i = 0, lnum = top + 1; i < size; i++) { fast_breakcheck(); if (got_int) { @@ -2312,7 +2312,7 @@ static void u_undoredo(int undo, bool do_buf_event) // Use the first line that actually changed. Avoids that // undoing auto-formatting puts the cursor in the previous // line. - long i; + int i; for (i = 0; i < newsize && i < oldsize; i++) { if (strcmp(uep->ue_array[i], ml_get(top + 1 + (linenr_T)i)) != 0) { break; @@ -2334,7 +2334,7 @@ static void u_undoredo(int undo, bool do_buf_event) if (oldsize > 0) { newarray = xmalloc(sizeof(char *) * (size_t)oldsize); // delete backwards, it goes faster in most cases - long i; + int i; linenr_T lnum; for (lnum = bot - 1, i = oldsize; --i >= 0; lnum--) { // what can we do when we run out of memory? @@ -2352,7 +2352,7 @@ static void u_undoredo(int undo, bool do_buf_event) // insert the lines in u_array between top and bot if (newsize) { - long i; + int i; linenr_T lnum; for (lnum = top, i = 0; i < newsize; i++, lnum++) { // If the file is empty, there is an empty line 1 that we @@ -2420,13 +2420,13 @@ static void u_undoredo(int undo, bool do_buf_event) // Adjust Extmarks ExtmarkUndoObject undo_info; if (undo) { - for (long i = (int)kv_size(curhead->uh_extmark) - 1; i > -1; i--) { + for (int i = (int)kv_size(curhead->uh_extmark) - 1; i > -1; i--) { undo_info = kv_A(curhead->uh_extmark, i); extmark_apply_undo(undo_info, undo); } // redo } else { - for (long i = 0; i < (int)kv_size(curhead->uh_extmark); i++) { + for (int i = 0; i < (int)kv_size(curhead->uh_extmark); i++) { undo_info = kv_A(curhead->uh_extmark, i); extmark_apply_undo(undo_info, undo); } @@ -2457,7 +2457,7 @@ static void u_undoredo(int undo, bool do_buf_event) } // restore marks from before undo/redo - for (long i = 0; i < NMARKS; i++) { + for (int i = 0; i < NMARKS; i++) { if (curhead->uh_namedm[i].mark.lnum != 0) { free_fmark(curbuf->b_namedm[i]); curbuf->b_namedm[i] = curhead->uh_namedm[i]; @@ -2962,7 +2962,7 @@ static void u_freeentries(buf_T *buf, u_header_T *uhp, u_header_T **uhpp) } /// free entry 'uep' and 'n' lines in uep->ue_array[] -static void u_freeentry(u_entry_T *uep, long n) +static void u_freeentry(u_entry_T *uep, int n) { while (n > 0) { xfree(uep->ue_array[--n]); diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index aa7d6e3355..7dd29d3ea4 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -37,19 +37,19 @@ struct u_header { // the undo file in u_read_undo() union { u_header_T *ptr; // pointer to next undo header in list - long seq; + int seq; } uh_next; union { u_header_T *ptr; // pointer to previous header in list - long seq; + int seq; } uh_prev; union { u_header_T *ptr; // pointer to next header for alt. redo - long seq; + int seq; } uh_alt_next; union { u_header_T *ptr; // pointer to previous header for alt. redo - long seq; + int seq; } uh_alt_prev; int uh_seq; // sequence number, higher == newer undo int uh_walk; // used by undo_time() diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 4bab3f52cd..e7fa7cec2c 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -706,7 +706,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, return OK; } -static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, long *def, int *flags, int *complp, +static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, int *def, int *flags, int *complp, char **compl_arg, cmd_addr_T *addr_type_arg) FUNC_ATTR_NONNULL_ALL { @@ -773,7 +773,7 @@ two_count: return FAIL; } - *def = getdigits_long(&p, true, 0); + *def = getdigits_int(&p, true, 0); *argt |= EX_ZEROR; if (p != val + vallen || vallen == 0) { @@ -799,7 +799,7 @@ invalid_count: goto two_count; } - *def = getdigits_long(&p, true, 0); + *def = getdigits_int(&p, true, 0); if (p != val + vallen) { goto invalid_count; @@ -975,7 +975,7 @@ void ex_command(exarg_T *eap) { char *end; uint32_t argt = 0; - long def = -1; + int def = -1; int flags = 0; int context = EXPAND_NOTHING; char *compl_arg = NULL; diff --git a/src/nvim/version.c b/src/nvim/version.c index c3bfad4706..ddfadeb44e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -2773,7 +2773,7 @@ void intro_message(int colon) size_t lines_size = ARRAY_SIZE(lines); assert(lines_size <= LONG_MAX); - long blanklines = Rows - ((long)lines_size - 1L); + int blanklines = Rows - ((int)lines_size - 1); // Don't overwrite a statusline. Depends on 'cmdheight'. if (p_ls > 1) { @@ -2790,7 +2790,7 @@ void intro_message(int colon) sponsor = ((sponsor & 2) == 0) - ((sponsor & 4) == 0); // start displaying the message lines after half of the blank lines - long row = blanklines / 2; + int row = blanklines / 2; if (((row >= 2) && (Columns >= 50)) || colon) { for (int i = 0; i < (int)ARRAY_SIZE(lines); i++) { @@ -2827,7 +2827,7 @@ void intro_message(int colon) } if (*mesg != NUL) { - do_intro_line((int)row, mesg, 0); + do_intro_line(row, mesg, 0); } row++; diff --git a/src/nvim/window.c b/src/nvim/window.c index d688c58ff5..bb2e08158f 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6619,8 +6619,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) if (lnum < 1) { // can happen when starting up lnum = 1; } - wp->w_wrow = (int)((long)wp->w_fraction * (long)height - 1L) / FRACTION_MULT; - int line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1; + wp->w_wrow = (int)(wp->w_fraction * height - 1L) / FRACTION_MULT; + int line_size = plines_win_col(wp, lnum, wp->w_cursor.col) - 1; int sline = wp->w_wrow - line_size; if (sline >= 0) { @@ -6898,7 +6898,7 @@ char *grab_file_name(int count, linenr_T *file_lnum) if (file_lnum != NULL && ptr[len] == ':' && isdigit((uint8_t)ptr[len + 1])) { char *p = ptr + len + 1; - *file_lnum = (linenr_T)getdigits_long(&p, false, 0); + *file_lnum = getdigits_int32(&p, false, 0); } return find_file_name_in_path(ptr, len, options, count, curbuf->b_ffname); } @@ -6952,9 +6952,7 @@ char *file_name_in_line(char *line, int col, int options, int count, char *rel_f while (ptr > line) { if ((len = (size_t)(utf_head_off(line, ptr - 1))) > 0) { ptr -= len + 1; - } else if (vim_isfilec((uint8_t)ptr[-1]) - || (len >= 2 && path_has_drive_letter(ptr - 2)) - || ((options & FNAME_HYP) && path_is_url(ptr - 1))) { + } else if (vim_isfilec((uint8_t)ptr[-1]) || ((options & FNAME_HYP) && path_is_url(ptr - 1))) { ptr--; } else { break; diff --git a/src/xdiff/xdiff.h b/src/xdiff/xdiff.h index 49985a0e9a..634c320508 100644 --- a/src/xdiff/xdiff.h +++ b/src/xdiff/xdiff.h @@ -102,8 +102,8 @@ typedef struct s_xdemitcb { typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv); -typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a, - long start_b, long count_b, +typedef int (*xdl_emit_hunk_consume_func_t)(int start_a, int count_a, + int start_b, int count_b, void *cb_data); typedef struct s_xdemitconf { diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index ba267e7539..bcae35d724 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -43,6 +43,11 @@ describe('autocmd api', function() group = 0, command = 'ls', })) + + eq("Invalid 'event': 'foo'", pcall_err(meths.create_autocmd, 'foo', { command = '' })) + eq("Invalid 'event': 'VimEnter '", pcall_err(meths.create_autocmd, 'VimEnter ', { command = '' })) + eq("Invalid 'event': 'VimEnter foo'", pcall_err(meths.create_autocmd, 'VimEnter foo', { command = '' })) + eq("Invalid 'event': 'BufAdd,BufDelete'", pcall_err(meths.create_autocmd, 'BufAdd,BufDelete', { command = '' })) end) it('doesnt leak when you use ++once', function() diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua index 06fa13dca5..215217e771 100644 --- a/test/functional/core/path_spec.lua +++ b/test/functional/core/path_spec.lua @@ -1,10 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear +local command = helpers.command local eq = helpers.eq local eval = helpers.eval -local command = helpers.command -local insert = helpers.insert local feed = helpers.feed +local insert = helpers.insert local is_os = helpers.is_os local mkdir = helpers.mkdir local rmdir = helpers.rmdir @@ -130,3 +130,40 @@ describe('file search (gf, <cfile>)', function() test_cfile([[\\127.0.0.1\c$\temp\test-file.txt]], [[127.0.0.1]], [[\\127.0.0.1\c$\temp\test-file.txt]]) end) end) + +describe('file search with vim functions', function() + local test_folder = "path_spec_folder" + + setup(function() + mkdir(test_folder) + end) + + teardown(function() + rmdir(test_folder) + end) + + ---@param option "dir" | "file" + local function test_find_func(option, folder, item) + local folder_path = join_path(test_folder, folder) + mkdir(folder_path) + local expected = join_path(folder_path, item) + if option == "dir" then + mkdir(expected) + else + write_file(expected, '') + end + eq(expected, eval('find'..option..'(fnameescape(\''..item..'\'),fnameescape(\''..folder_path..'\'))')) + end + + it('finddir()', function() + test_find_func('dir', 'directory', 'folder') + -- test_find_func('dir', 'directory', 'folder name') + test_find_func('dir', 'folder name', 'directory') + end) + + it('findfile()', function() + test_find_func('file', 'directory', 'file.txt') + -- test_find_func('file', 'directory', 'file name.txt') + test_find_func('file', 'folder name', 'file.txt') + end) +end) diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 955a871d10..682eb48a27 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -1641,7 +1641,7 @@ describe('TUI', function() {13:℃}{12: ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }| {12:℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ }{15:$}{12: }| - ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ >{4:@@@}| + ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ ℃ {4:@@@@}| {5:[No Name] [+] }| | {3:-- TERMINAL --} | diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 01475a189d..05057ca080 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -215,7 +215,7 @@ describe('ui/cursor', function() m.hl_id = 64 m.attr = {background = Screen.colors.DarkGray} end - if m.id_lm then m.id_lm = 66 end + if m.id_lm then m.id_lm = 67 end end -- Assert the new expectation. diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua index cd2b48213d..db01c55e23 100644 --- a/test/functional/ui/embed_spec.lua +++ b/test/functional/ui/embed_spec.lua @@ -98,6 +98,7 @@ describe('--embed UI', function() -- attach immediately after startup, for early UI local screen = Screen.new(40, 8) + screen.rpc_async = true -- Avoid hanging. #24888 screen:attach {stdin_fd=3} screen:set_default_attr_ids { [1] = {bold = true, foreground = Screen.colors.Blue1}; diff --git a/test/functional/ui/fold_spec.lua b/test/functional/ui/fold_spec.lua index f42682ba69..7894c8296b 100644 --- a/test/functional/ui/fold_spec.lua +++ b/test/functional/ui/fold_spec.lua @@ -1156,7 +1156,7 @@ describe("folded lines", function() [2:---------------------------------------------]| [3:---------------------------------------------]| ## grid 2 - {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}| + {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}| {1:~ }| {1:~ }| {1:~ }| @@ -1168,7 +1168,7 @@ describe("folded lines", function() ]]) else screen:expect([[ - {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ العَرَبِيَّة·················}| + {5:^+-- 2 lines: å 语 x̎͂̀̂͛͛ ﺎﻠﻋَﺮَﺒِﻳَّﺓ·················}| {1:~ }| {1:~ }| {1:~ }| @@ -1337,7 +1337,7 @@ describe("folded lines", function() [2:---------------------------------------------]| [3:---------------------------------------------]| ## grid 2 - {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}| + {5:·················ﺔﻴَّﺑِﺮَﻌَﻟﺍ x̎͂̀̂͛͛ 语 å :senil 2 --^+}| {1: ~}| {1: ~}| {1: ~}| @@ -1349,7 +1349,7 @@ describe("folded lines", function() ]]) else screen:expect([[ - {5:·················ةيَّبِرَعَلا x̎͂̀̂͛͛ 语 å :senil 2 --^+}| + {5:·················ﺔﻴَّﺑِﺮَﻌَﻟﺍ x̎͂̀̂͛͛ 语 å :senil 2 --^+}| {1: ~}| {1: ~}| {1: ~}| diff --git a/test/functional/ui/multibyte_spec.lua b/test/functional/ui/multibyte_spec.lua index 417c7b797c..077dd1a779 100644 --- a/test/functional/ui/multibyte_spec.lua +++ b/test/functional/ui/multibyte_spec.lua @@ -177,6 +177,57 @@ describe("multibyte rendering", function() | ]], reset=true} end) + + it('works with arabic input and arabicshape', function() + command('set arabic') + + command('set noarabicshape') + feed('isghl!<esc>') + screen:expect{grid=[[ + ^!مالس| + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + | + ]]} + + command('set arabicshape') + screen:expect{grid=[[ + ^!ﻡﻼﺳ| + {1: ~}| + {1: ~}| + {1: ~}| + {1: ~}| + | + ]]} + end) + + it('works with arabic input and arabicshape and norightleft', function() + command('set arabic norightleft') + + command('set noarabicshape') + feed('isghl!<esc>') + screen:expect{grid=[[ + سلام^! | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + command('set arabicshape') + screen:expect{grid=[[ + ﺱﻼﻣ^! | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + end) end) describe('multibyte rendering: statusline', function() diff --git a/test/functional/ui/options_spec.lua b/test/functional/ui/options_spec.lua index 9d20229ce1..58cd68d94a 100644 --- a/test/functional/ui/options_spec.lua +++ b/test/functional/ui/options_spec.lua @@ -19,6 +19,7 @@ describe('UI receives option updates', function() linespace=0, pumblend=0, mousefocus=false, + mousehide=true, mousemoveevent=false, showtabline=1, termguicolors=false, @@ -133,6 +134,12 @@ describe('UI receives option updates', function() eq(expected, screen.options) end) + command("set nomousehide") + expected.mousehide = false + screen:expect(function() + eq(expected, screen.options) + end) + command("set mousemoveevent") expected.mousemoveevent = true screen:expect(function() diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index be7c2f291c..d3ffb07749 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -150,6 +150,7 @@ function Screen.new(width, height) msg_grid = nil, msg_grid_pos = nil, _session = nil, + rpc_async = false, messages = {}, msg_history = {}, showmode = {}, @@ -173,9 +174,13 @@ function Screen.new(width, height) _busy = false, }, Screen) local function ui(method, ...) - local status, rv = self._session:request('nvim_ui_'..method, ...) - if not status then - error(rv[2]) + if self.rpc_async then + self._session:notify('nvim_ui_'..method, ...) + else + local status, rv = self._session:request('nvim_ui_'..method, ...) + if not status then + error(rv[2]) + end end end self.uimeths = create_callindex(ui) diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index 54f5dd500b..90748a6076 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -1176,13 +1176,71 @@ func Test_cmdline_complete_various() mapclear delcom MyCmd + " Prepare for path completion + call mkdir('Xa b c', 'D') + defer delete('Xcomma,foobar.txt') + call writefile([], 'Xcomma,foobar.txt') + " completion for :set path= with multiple backslashes - call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') - call assert_equal('"set path=a\\\ b', @:) + call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set path=Xa\\\ b\\\ c/', @:) + set path& " completion for :set dir= with a backslash - call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') - call assert_equal('"set dir=a\ b', @:) + call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set dir=Xa\ b\ c/', @:) + set dir& + + " completion for :set tags= / set dictionary= with escaped commas + if has('win32') + " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to + " '\,' + call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:) + + call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set tags=Xcomma\,foobar.txt', @:) + + call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match + + " completion for :set dictionary= with escaped commas (same behavior, but + " different internal code path from 'set tags=' for escaping the output) + call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set tags=Xcomma\,foobar.txt', @:) + else + " In other platforms, backslashes are rounded down (since '\,' itself will + " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'. + call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match + + call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set tags=Xcomma\\,foobar.txt', @:) + + call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) + + " completion for :set dictionary= with escaped commas (same behavior, but + " different internal code path from 'set tags=' for escaping the output) + call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) + endif + set tags& + set dictionary& + + " completion for :set makeprg= with no escaped commas + call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set makeprg=Xcomma,foobar.txt', @:) + + if !has('win32') + " Cannot create file with backslash in file name in Windows, so only test + " this elsewhere. + defer delete('Xcomma\,fooslash.txt') + call writefile([], 'Xcomma\,fooslash.txt') + call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') + call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:) + endif + set makeprg& " completion for the :py3 commands call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') diff --git a/test/old/testdir/test_options.vim b/test/old/testdir/test_options.vim index 76b7cc920b..cc3f21b86b 100644 --- a/test/old/testdir/test_options.vim +++ b/test/old/testdir/test_options.vim @@ -316,16 +316,60 @@ func Test_set_completion() " Expand directories. call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') - call assert_match('./samples/ ', @:) - call assert_notmatch('./small.vim ', @:) + call assert_match(' ./samples/ ', @:) + call assert_notmatch(' ./summarize.vim ', @:) + set cdpath& " Expand files and directories. call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') - call assert_match('./samples/ ./sautest/ ./screendump.vim ./script_util.vim ./setup.vim ./shared.vim', @:) + call assert_match(' ./samples/.* ./summarize.vim', @:) call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) - set tags& + + " Expand files with spaces/commas in them. Make sure we delimit correctly. + " + " 'tags' allow for for spaces/commas to both act as delimiters, with actual + " spaces requiring double escape, and commas need a single escape. + " 'dictionary' is a normal comma-separated option where only commas act as + " delimiters, and both space/comma need one single escape. + " 'makeprg' is a non-comma-separated option. Commas don't need escape. + defer delete('Xfoo Xspace.txt') + defer delete('Xsp_dummy') + defer delete('Xbar,Xcomma.txt') + defer delete('Xcom_dummy') + call writefile([], 'Xfoo Xspace.txt') + call writefile([], 'Xsp_dummy') + call writefile([], 'Xbar,Xcomma.txt') + call writefile([], 'Xcom_dummy') + + call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:) + call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:) + call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:) + + call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:) + if has('win32') + " In Windows, '\,' is literal, see `:help filename-backslash`, so this + " means we treat it as one file name. + call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:) + else + " In other platforms, '\,' simply escape to ',', and indicate a delimiter + " to split into a separate file name. You need '\\,' to escape the comma + " as part of the file name. + call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:) + + call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:) + endif + call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:) + set tags& dictionary& makeprg& " Expanding the option names call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt') diff --git a/test/old/testdir/test_undo.vim b/test/old/testdir/test_undo.vim index b75b6f9b0d..a06731cc96 100644 --- a/test/old/testdir/test_undo.vim +++ b/test/old/testdir/test_undo.vim @@ -868,6 +868,7 @@ func Test_undo_after_write() call StopVimInTerminal(buf) call delete('Xtestfile.txt') + call delete('.Xtestfile.txt.un~') endfunc func Test_undo_range_normal() |