aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--ISSUE_TEMPLATE.md12
-rw-r--r--runtime/autoload/remote/host.vim2
-rw-r--r--runtime/doc/eval.txt5
-rw-r--r--runtime/doc/os_dos.txt279
-rw-r--r--runtime/doc/vim_diff.txt48
-rw-r--r--runtime/doc/windows.txt2
-rwxr-xr-xscripts/vim-patch.sh4
-rw-r--r--src/nvim/CMakeLists.txt2
-rw-r--r--src/nvim/api/buffer.c150
-rw-r--r--src/nvim/buffer.c229
-rw-r--r--src/nvim/buffer_defs.h4
-rw-r--r--src/nvim/charset.c100
-rw-r--r--src/nvim/edit.c13
-rw-r--r--src/nvim/eval.c95
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/os/fs.c2
-rw-r--r--src/nvim/path.c237
-rw-r--r--src/nvim/terminal.c4
-rw-r--r--src/nvim/version.c7
-rw-r--r--test/functional/api/buffer_spec.lua151
-rw-r--r--test/functional/api/server_requests_spec.lua4
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua2
-rw-r--r--test/functional/helpers.lua2
-rw-r--r--test/functional/legacy/105_filename_modifiers_spec.lua81
-rw-r--r--test/functional/legacy/eval_spec.lua18
-rw-r--r--test/functional/legacy/fnamemodify_spec.lua75
-rw-r--r--test/functional/plugin/shada_spec.lua8
-rw-r--r--test/functional/terminal/edit_spec.lua2
-rw-r--r--test/functional/viml/completion_spec.lua12
-rw-r--r--test/unit/buffer_spec.lua10
31 files changed, 802 insertions, 764 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 07557c6580..5798a74369 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,7 +59,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
# version string, else it is combined with the result of `git describe`.
set(NVIM_VERSION_MAJOR 0)
set(NVIM_VERSION_MINOR 1)
-set(NVIM_VERSION_PATCH 3)
+set(NVIM_VERSION_PATCH 4)
set(NVIM_VERSION_PRERELEASE "-dev") # for package maintainers
file(TO_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git FORCED_GIT_DIR)
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
index 4abcc4eae1..e0185844ad 100644
--- a/ISSUE_TEMPLATE.md
+++ b/ISSUE_TEMPLATE.md
@@ -1,9 +1,15 @@
- Neovim version:
-- Operating system:
-- Terminal emulator:
+- [ ] Vim behaves differently?
+ - Vim version:
+- Operating system/version:
+- Terminal name/version:
+- `$TERM`:
### Actual behaviour
### Expected behaviour
-### Steps to reproduce
+### Steps to reproduce using `nvim -u NONE`
+
+1. `nvim -u NONE`
+2.
diff --git a/runtime/autoload/remote/host.vim b/runtime/autoload/remote/host.vim
index 0b4eef158d..1aead649a0 100644
--- a/runtime/autoload/remote/host.vim
+++ b/runtime/autoload/remote/host.vim
@@ -36,7 +36,7 @@ endfunction
" Get a host channel, bootstrapping it if necessary
function! remote#host#Require(name) abort
- if empty(s:hosts)
+ if empty(s:plugins_for_host)
call remote#host#LoadRemotePlugins()
endif
if !has_key(s:hosts, a:name)
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 27fe449933..6a1eac6814 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -916,6 +916,11 @@ just above, except that indexes out of range cause an error. Examples: >
Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an
error.
+Watch out for confusion between a namespace and a variable followed by a colon
+for a sublist: >
+ mylist[n:] " uses variable n
+ mylist[s:] " uses namespace s:, error!
+
expr8.name entry in a |Dictionary| *expr-entry*
diff --git a/runtime/doc/os_dos.txt b/runtime/doc/os_dos.txt
deleted file mode 100644
index 1601d65ffd..0000000000
--- a/runtime/doc/os_dos.txt
+++ /dev/null
@@ -1,279 +0,0 @@
-*os_dos.txt* For Vim version 7.4. Last change: 2006 Mar 30
-
-
- VIM REFERENCE MANUAL by Bram Moolenaar
-
-
- *dos* *DOS*
-This file documents some particularities of the Win32
-version of Vim. Also see |os_win32.txt|.
-
-1. File locations |dos-locations|
-2. Using backslashes |dos-backslash|
-3. Standard mappings |dos-standard-mappings|
-4. Screen output and colors |dos-colors|
-5. File formats |dos-file-formats|
-6. :cd command |dos-:cd|
-7. Interrupting |dos-CTRL-Break|
-8. Temp files |dos-temp-files|
-9. Shell option default |dos-shell|
-
-==============================================================================
-1. File locations *dos-locations*
-
-If you keep the Vim executable in the directory that contains the help and
-syntax subdirectories, there is no need to do anything special for Vim to
-work. No registry entries or environment variables need to be set. Just make
-sure that the directory is in your search path, or use a shortcut on the
-desktop.
-
-Your vimrc files ("_vimrc" and "_gvimrc") are normally located one directory
-up from the runtime files. If you want to put them somewhere else, set the
-environment variable $VIM to the directory where you keep them. Example: >
- set VIM=C:\user\piet
-Will find "c:\user\piet\_vimrc".
-Note: This would only be needed when the computer is used by several people.
-Otherwise it's simpler to keep your _vimrc file in the default place.
-
-If you move the executable to another location, you also need to set the $VIM
-environment variable. The runtime files will be found in "$VIM/vim{version}".
-Example: >
- set VIM=E:\vim
-Will find the version 5.4 runtime files in "e:\vim\vim54".
-Note: This is _not_ recommended. The preferred way is to keep the executable
-in the runtime directory.
-
-If you move your executable AND want to put your "_vimrc" and "_gvimrc" files
-somewhere else, you must set $VIM to where you vimrc files are, and set
-$VIMRUNTIME to the runtime files. Example: >
- set VIM=C:\usr\piet
- set VIMRUNTIME=E:\vim\vim54
-Will find "c:\user\piet\_vimrc" and the runtime files in "e:\vim\vim54".
-
-See |$VIM| and |$VIMRUNTIME| for more information.
-
-You can set environment variables for each user separately under
-"Start/Settings/Control Panel->System", or through the properties in the menu
-of "My Computer", under the Environment Tab.
-
-==============================================================================
-2. Using backslashes *dos-backslash*
-
-Using backslashes in file names can be a problem. Vi halves the number of
-backslashes for some commands. Vim is a bit more tolerant and does not remove
-backslashes from a file name, so ":e c:\foo\bar" works as expected. But when
-a backslash occurs before a special character (space, comma, backslash, etc.),
-Vim removes the backslash. Use slashes to avoid problems: ":e c:/foo/bar"
-works fine. Vim replaces the slashes with backslashes internally to avoid
-problems with some MS-DOS programs and Win32 programs.
-
-When you prefer to use forward slashes, set the 'shellslash' option. Vim will
-then replace backslashes with forward slashes when expanding file names. This
-is especially useful when using a Unix-like 'shell'.
-
-==============================================================================
-3. Standard mappings *dos-standard-mappings*
-
-The mappings for CTRL-PageUp and CTRL-PageDown have been removed, they now
-jump to the next or previous tab page |<C-PageUp>| |<C-PageDown>|
-
-If you want them to move to the first and last screen line you can use these
-mappings:
-
-key key code Normal/Visual mode Insert mode ~
-CTRL-PageUp <M-N><M-C-D> H <C-O>H
-CTRL-PageDown <M-N>v L$ <C-O>L<C-O>$
-
-Additionally, these keys are available for copy/cut/paste.
-In the Win32 version, they also use the clipboard.
-
-Shift-Insert paste text (from clipboard) *<S-Insert>*
-CTRL-Insert copy Visual text (to clipboard) *<C-Insert>*
-CTRL-Del cut Visual text (to clipboard) *<C-Del>*
-Shift-Del cut Visual text (to clipboard) *<S-Del>*
-
-These mappings accomplish this (Win32 version of Vim):
-
-key key code Normal Visual Insert ~
-Shift-Insert <M-N><M-T> "*P "-d"*P <C-R><C-O>*
-CTRL-Insert <M-N><M-U> "*y
-Shift-Del <M-N><M-W> "*d
-CTRL-Del <M-N><M-X> "*d
-
-Or these mappings (non-Win32 version of Vim):
-
-key key code Normal Visual Insert ~
-Shift-Insert <M-N><M-T> P "-dP <C-R><C-O>"
-CTRL-Insert <M-N><M-U> y
-Shift-Del <M-N><M-W> d
-CTRL-Del <M-N><M-X> d
-
-When the clipboard is supported, the "* register is used.
-
-==============================================================================
-4. Screen output and colors *dos-colors*
-
-The default output method for the screen is to use bios calls. This works
-right away on most systems. You do not need ansi.sys. You can use ":mode" to
-set the current screen mode. See |:mode|.
-
-To change the screen colors that Vim uses, you can use the |:highlight|
-command. The Normal highlight group specifies the colors Vim uses for normal
-text. For example, to get grey text on a blue background: >
- :hi Normal ctermbg=Blue ctermfg=grey
-See |highlight-groups| for other groups that are available.
-
-A DOS console does not support attributes like bold and underlining. You can
-set the color used in five modes with nine terminal options. Note that this
-is not necessary since you can set the color directly with the ":highlight"
-command; these options are for backward compatibility with older Vim versions.
-The |'highlight'| option specifies which of the five modes is used for which
-action. >
-
- :set t_mr=^V^[\|xxm start of invert mode
- :set t_md=^V^[\|xxm start of bold mode
- :set t_me=^V^[\|xxm back to normal text
-
- :set t_so=^V^[\|xxm start of standout mode
- :set t_se=^V^[\|xxm back to normal text
-
- :set t_us=^V^[\|xxm start of underline mode
- :set t_ue=^V^[\|xxm back to normal text
-
- :set t_ZH=^V^[\|xxm start of italics mode
- :set t_ZR=^V^[\|xxm back to normal text
-
-^V is CTRL-V
-^[ is <Esc>
-You must replace xx with a decimal code, which is the foreground color number
-and background color number added together:
-
-COLOR FOREGROUND BACKGROUND ~
-Black 0 0
-DarkBlue 1 16
-DarkGreen 2 32
-DarkCyan 3 48
-DarkRed 4 64
-DarkMagenta 5 80
-Brown, DarkYellow 6 96
-LightGray 7 112
-DarkGray 8 128 *
-Blue, LightBlue 9 144 *
-Green, LightGreen 10 160 *
-Cyan, LightCyan 11 176 *
-Red, LightRed 12 192 *
-Magenta, LightMagenta 13 208 *
-Yellow, LightYellow 14 224 *
-White 15 240 *
-
-* Depending on the display mode, the color codes above 128 may not be
- available, and code 128 will make the text blink.
-
-When you use 0, the color is reset to the one used when you started Vim
-(usually 7, lightgray on black, but you can override this. If you have
-overridden the default colors in a command prompt, you may need to adjust
-some of the highlight colors in your vimrc---see below).
-This is the default for t_me.
-
-The defaults for the various highlight modes are:
- t_mr 112 reverse mode: Black text (0) on LightGray (112)
- t_md 15 bold mode: White text (15) on Black (0)
- t_me 0 normal mode (revert to default)
-
- t_so 31 standout mode: White (15) text on DarkBlue (16)
- t_se 0 standout mode end (revert to default)
-
- t_czh 225 italic mode: DarkBlue text (1) on Yellow (224)
- t_czr 0 italic mode end (revert to default)
-
- t_us 67 underline mode: DarkCyan text (3) on DarkRed (64)
- t_ue 0 underline mode end (revert to default)
-
-These colors were chosen because they also look good when using an inverted
-display, but you can change them to your liking.
-
-Example: >
- :set t_mr=^V^[\|97m " start of invert mode: DarkBlue (1) on Brown (96)
- :set t_md=^V^[\|67m " start of bold mode: DarkCyan (3) on DarkRed (64)
- :set t_me=^V^[\|112m " back to normal mode: Black (0) on LightGray (112)
-
- :set t_so=^V^[\|37m " start of standout mode: DarkMagenta (5) on DarkGreen
- (32)
- :set t_se=^V^[\|112m " back to normal mode: Black (0) on LightGray (112)
-
-==============================================================================
-5. File formats *dos-file-formats*
-
-If the 'fileformat' option is set to "dos" (which is the default), Vim accepts
-a single <NL> or a <CR><NL> pair for end-of-line (<EOL>). When writing a
-file, Vim uses <CR><NL>. Thus, if you edit a file and write it, Vim replaces
-<NL> with <CR><NL>.
-
-If the 'fileformat' option is set to "unix", Vim uses a single <NL> for <EOL>
-and shows <CR> as ^M.
-
-You can use Vim to replace <NL> with <CR><NL> by reading in any mode and
-writing in Dos mode (":se ff=dos").
-You can use Vim to replace <CR><NL> with <NL> by reading in Dos mode and
-writing in Unix mode (":se ff=unix").
-
-Vim sets 'fileformat' automatically when 'fileformats' is not empty (which is
-the default), so you don't really have to worry about what you are doing.
- |'fileformat'| |'fileformats'|
-
-If you want to edit a script file or a binary file, you should set the
-'binary' option before loading the file. Script files and binary files may
-contain single <NL> characters which Vim would replace with <CR><NL>. You can
-set 'binary' automatically by starting Vim with the "-b" (binary) option.
-
-==============================================================================
-6. :cd command *dos-:cd*
-
-The ":cd" command recognizes the drive specifier and changes the current
-drive. Use ":cd c:" to make drive C the active drive. Use ":cd d:\foo" to go
-to the directory "foo" in the root of drive D. Vim also recognizes UNC names
-if the system supports them; e.g., ":cd \\server\share\dir". |:cd|
-
-==============================================================================
-7. Interrupting *dos-CTRL-Break*
-
-Use CTRL-Break instead of CTRL-C to interrupt searches. Vim does not detect
-the CTRL-C until it tries to read a key.
-
-==============================================================================
-8. Temp files *dos-temp-files*
-
-Vim uses standard Windows functions to obtain a temporary file name (for
-filtering). The first of these directories that exists and in which Vim can
-create a file is used:
- $TMP
- $TEMP
- current directory
-
-==============================================================================
-9. Shell option default *dos-shell*
-
-The default for the 'sh' ('shell') option is "cmd.exe" on Windows.
-If SHELL is defined, Vim uses SHELL instead, and if SHELL is not defined
-but COMSPEC is, Vim uses COMSPEC. Vim starts external commands with
-"<shell> /c <command_name>". Typing CTRL-Z starts a new command
-subshell. Return to Vim with "exit". |'shell'| |CTRL-Z|
-
-If you are running a third-party shell, you may need to set the
-|'shellcmdflag'| ('shcf') and |'shellquote'| ('shq') or |'shellxquote'|
-('sxq') options. Unfortunately, this also depends on the version of Vim used.
-For example, with the MKS Korn shell or with bash, the values of the options
-on Win32 should be:
-
-'shellcmdflag' -c
-'shellquote' (empty)
-'shellxquote' "
-
-For Win32, this starts the shell as:
- <shell> -c "command name >file"
-
-When starting up, Vim checks for the presence of "sh" anywhere in the 'shell'
-option. If it is present, Vim sets the 'shellcmdflag' and 'shellquote' or
-'shellxquote' options will be set as described above.
-
- vim:tw=78:ts=8:ft=help:norl:
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 8722fced26..17e16911bc 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -21,10 +21,10 @@ these differences.
==============================================================================
1. Configuration *nvim-configuration*
-- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing
+- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for storing
configuration.
- Use `$XDG_CONFIG_HOME/nvim` instead of `.vim` to store configuration files.
-- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent
+- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent
session information.
==============================================================================
@@ -73,56 +73,56 @@ are always available and may be used simultaneously in separate plugins. The
|nvim-python|).
|mkdir()| behaviour changed:
-1. Assuming /tmp/foo does not exist and /tmp can be written to
+1. Assuming /tmp/foo does not exist and /tmp can be written to
mkdir('/tmp/foo/bar', 'p', 0700) will create both /tmp/foo and /tmp/foo/bar
with 0700 permissions. Vim mkdir will create /tmp/foo with 0755.
-2. If you try to create an existing directory with `'p'` (e.g. mkdir('/',
+2. If you try to create an existing directory with `'p'` (e.g. mkdir('/',
'p')) mkdir() will silently exit. In Vim this was an error.
3. mkdir() error messages now include strerror() text when mkdir fails.
'encoding' cannot be changed after startup.
|string()| and |:echo| behaviour changed:
-1. No maximum recursion depth limit is applied to nested container
+1. No maximum recursion depth limit is applied to nested container
structures.
-2. |string()| fails immediately on nested containers, not when recursion limit
+2. |string()| fails immediately on nested containers, not when recursion limit
was exceeded.
2. When |:echo| encounters duplicate containers like >
let l = []
echo [l, l]
<
- it does not use "[...]" (was: "[[], [...]]", now: "[[], []]"). "..." is
+ it does not use "[...]" (was: "[[], [...]]", now: "[[], []]"). "..." is
only used for recursive containers.
-3. |:echo| printing nested containers adds "@level" after "..." designating
- the level at which recursive container was printed: |:echo-self-refer|.
- Same thing applies to |string()| (though it uses construct like
- "{E724@level}"), but this is not reliable because |string()| continues to
+3. |:echo| printing nested containers adds "@level" after "..." designating
+ the level at which recursive container was printed: |:echo-self-refer|.
+ Same thing applies to |string()| (though it uses construct like
+ "{E724@level}"), but this is not reliable because |string()| continues to
error out.
-4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled
+4. Stringifyed infinite and NaN values now use |str2float()| and can be evaled
back.
-Viminfo text files were replaced with binary (messagepack) ShaDa files.
+Viminfo text files were replaced with binary (messagepack) ShaDa files.
Additional differences:
- |shada-c| has no effect.
- |shada-s| now limits size of every item and not just registers.
-- When reading ShaDa files items are merged according to the timestamp.
+- When reading ShaDa files items are merged according to the timestamp.
|shada-merging|
-- 'viminfo' option got renamed to 'shada'. Old option is kept as an alias for
+- 'viminfo' option got renamed to 'shada'. Old option is kept as an alias for
compatibility reasons.
-- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old
+- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old
commands are still kept.
- |:oldfiles| supports !.
-- When writing (|:wshada| without bang or at exit) it merges much more data,
- and does this according to the timestamp. Vim merges only marks.
+- When writing (|:wshada| without bang or at exit) it merges much more data,
+ and does this according to the timestamp. Vim merges only marks.
|shada-merging|
-- ShaDa file format was designed with forward and backward compatibility in
+- ShaDa file format was designed with forward and backward compatibility in
mind. |shada-compatibility|
-- Some errors make ShaDa code keep temporary file in-place for user to decide
- what to do with it. Vim deletes temporary file in these cases.
+- Some errors make ShaDa code keep temporary file in-place for user to decide
+ what to do with it. Vim deletes temporary file in these cases.
|shada-error-handling|
-- Vim keeps no timestamps at all, neither in viminfo file nor in the instance
+- Vim keeps no timestamps at all, neither in viminfo file nor in the instance
itself.
- ShaDa file keeps search direction (|v:searchforward|), viminfo does not.
@@ -141,8 +141,8 @@ Meta (alt) chords are recognized (even in the terminal).
Note: Meta chords are case-sensitive (<M-a> is distinguished from <M-A>).
-Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants (even in
-the terminal). Specifically, the following are known to work:
+Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants
+(even in the terminal). Specifically, the following are known to work:
<C-Tab>, <C-S-Tab>
<C-BS>, <C-S-BS>
<C-Enter>, <C-S-Enter>
diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt
index eee171b7da..29c8aaf808 100644
--- a/runtime/doc/windows.txt
+++ b/runtime/doc/windows.txt
@@ -706,7 +706,7 @@ can also get to them with the buffer list commands, like ":bnext".
*:bufdo*
:[range]bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list or if
- [range[ is given only for buffers for which their
+ [range] is given only for buffers for which their
buffer name is in the [range]. It works like doing
this: >
:bfirst
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh
index 7612a2ada0..4dc24a8cdf 100755
--- a/scripts/vim-patch.sh
+++ b/scripts/vim-patch.sh
@@ -65,7 +65,7 @@ get_vim_sources() {
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
- git clone --depth=1000 https://github.com/vim/vim.git "${VIM_SOURCE_DIR}"
+ git clone https://github.com/vim/vim.git "${VIM_SOURCE_DIR}"
cd "${VIM_SOURCE_DIR}"
else
if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then
@@ -243,7 +243,7 @@ list_vim_patches() {
local patch_number="${vim_tag:5}" # Remove prefix like "v7.4."
# Tagged Vim patch, check version.c:
is_missing="$(sed -n '/static int included_patches/,/}/p' "${NEOVIM_SOURCE_DIR}/src/nvim/version.c" |
- grep -x -e "[[:space:]]*//[[:space:]]${patch_number} NA" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")"
+ grep -x -e "[[:space:]]*//[[:space:]]${patch_number} NA.*" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")"
vim_commit="${vim_tag#v}"
else
# Untagged Vim patch (e.g. runtime updates), check the Neovim git log:
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 966cd9efc6..487b554d6d 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -77,7 +77,6 @@ list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove})
# Handle legacy files that don't yet pass -Wconversion.
set(CONV_SOURCES
buffer.c
- charset.c
diff.c
edit.c
eval.c
@@ -91,7 +90,6 @@ set(CONV_SOURCES
message.c
misc1.c
ops.c
- path.c
regexp.c
screen.c
search.c
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index fa4b8e5f7d..c25a9789c5 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -45,14 +45,22 @@ Integer buffer_line_count(Buffer buffer, Error *err)
/// Gets a buffer line
///
+/// @deprecated use buffer_get_lines instead.
+/// for positive indices (including 0) use
+/// "buffer_get_lines(buffer, index, index+1, true)"
+/// for negative indices use
+/// "buffer_get_lines(buffer, index-1, index, true)"
+///
/// @param buffer The buffer handle
/// @param index The line index
/// @param[out] err Details of an error that may have occurred
/// @return The line string
String buffer_get_line(Buffer buffer, Integer index, Error *err)
{
- String rv = {.size = 0};
- Array slice = buffer_get_line_slice(buffer, index, index, true, true, err);
+ String rv = { .size = 0 };
+
+ index = convert_index(index);
+ Array slice = buffer_get_lines(buffer, index, index+1, true, err);
if (!err->set && slice.size) {
rv = slice.items[0].data.string;
@@ -65,6 +73,12 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// Sets a buffer line
///
+/// @deprecated use buffer_set_lines instead.
+/// for positive indices use
+/// "buffer_set_lines(buffer, index, index+1, true, [line])"
+/// for negative indices use
+/// "buffer_set_lines(buffer, index-1, index, true, [line])"
+///
/// @param buffer The buffer handle
/// @param index The line index
/// @param line The new line.
@@ -72,23 +86,34 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
{
Object l = STRING_OBJ(line);
- Array array = {.items = &l, .size = 1};
- buffer_set_line_slice(buffer, index, index, true, true, array, err);
+ Array array = { .items = &l, .size = 1 };
+ index = convert_index(index);
+ buffer_set_lines(buffer, index, index+1, true, array, err);
}
/// Deletes a buffer line
///
+/// @deprecated use buffer_set_lines instead.
+/// for positive indices use
+/// "buffer_set_lines(buffer, index, index+1, true, [])"
+/// for negative indices use
+/// "buffer_set_lines(buffer, index-1, index, true, [])"
/// @param buffer The buffer handle
/// @param index The line index
/// @param[out] err Details of an error that may have occurred
void buffer_del_line(Buffer buffer, Integer index, Error *err)
{
Array array = ARRAY_DICT_INIT;
- buffer_set_line_slice(buffer, index, index, true, true, array, err);
+ index = convert_index(index);
+ buffer_set_lines(buffer, index, index+1, true, array, err);
}
/// Retrieves a line range from the buffer
///
+/// @deprecated use buffer_get_lines(buffer, newstart, newend, false)
+/// where newstart = start + int(not include_start) - int(start < 0)
+/// newend = end + int(include_end) - int(end < 0)
+/// int(bool) = 1 if bool is true else 0
/// @param buffer The buffer handle
/// @param start The first line index
/// @param end The last line index
@@ -103,16 +128,48 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
Boolean include_end,
Error *err)
{
+ start = convert_index(start) + !include_start;
+ end = convert_index(end) + include_end;
+ return buffer_get_lines(buffer, start , end, false, err);
+}
+
+
+/// Retrieves a line range from the buffer
+///
+/// Indexing is zero-based, end-exclusive. Negative indices are interpreted
+/// as length+1+index, i e -1 refers to the index past the end. So to get the
+/// last element set start=-2 and end=-1.
+///
+/// Out-of-bounds indices are clamped to the nearest valid value, unless
+/// `strict_indexing` is set.
+///
+/// @param buffer The buffer handle
+/// @param start The first line index
+/// @param end The last line index (exclusive)
+/// @param strict_indexing whether out-of-bounds should be an error.
+/// @param[out] err Details of an error that may have occurred
+/// @return An array of lines
+ArrayOf(String) buffer_get_lines(Buffer buffer,
+ Integer start,
+ Integer end,
+ Boolean strict_indexing,
+ Error *err)
+{
Array rv = ARRAY_DICT_INIT;
buf_T *buf = find_buffer_by_handle(buffer, err);
- if (!buf || !inbounds(buf, start)) {
+ if (!buf) {
return rv;
}
- start = normalize_index(buf, start) + (include_start ? 0 : 1);
- include_end = include_end || (end >= buf->b_ml.ml_line_count);
- end = normalize_index(buf, end) + (include_end ? 1 : 0);
+ bool oob = false;
+ start = normalize_index(buf, start, &oob);
+ end = normalize_index(buf, end, &oob);
+
+ if (strict_indexing && oob) {
+ api_set_error(err, Validation, _("Index out of bounds"));
+ return rv;
+ }
if (start >= end) {
// Return 0-length array
@@ -152,8 +209,14 @@ end:
return rv;
}
+
/// Replaces a line range on the buffer
///
+/// @deprecated use buffer_set_lines(buffer, newstart, newend, false, lines)
+/// where newstart = start + int(not include_start) + int(start < 0)
+/// newend = end + int(include_end) + int(end < 0)
+/// int(bool) = 1 if bool is true else 0
+///
/// @param buffer The buffer handle
/// @param start The first line index
/// @param end The last line index
@@ -170,20 +233,52 @@ void buffer_set_line_slice(Buffer buffer,
ArrayOf(String) replacement,
Error *err)
{
+ start = convert_index(start) + !include_start;
+ end = convert_index(end) + include_end;
+ buffer_set_lines(buffer, start, end, false, replacement, err);
+}
+
+
+/// Replaces line range on the buffer
+///
+/// Indexing is zero-based, end-exclusive. Negative indices are interpreted
+/// as length+1+index, i e -1 refers to the index past the end. So to change
+/// or delete the last element set start=-2 and end=-1.
+///
+/// To insert lines at a given index, set both start and end to the same index.
+/// To delete a range of lines, set replacement to an empty array.
+///
+/// Out-of-bounds indices are clamped to the nearest valid value, unless
+/// `strict_indexing` is set.
+///
+/// @param buffer The buffer handle
+/// @param start The first line index
+/// @param end The last line index (exclusive)
+/// @param strict_indexing whether out-of-bounds should be an error.
+/// @param replacement An array of lines to use as replacement
+/// @param[out] err Details of an error that may have occurred
+void buffer_set_lines(Buffer buffer,
+ Integer start,
+ Integer end,
+ Boolean strict_indexing,
+ ArrayOf(String) replacement,
+ Error *err)
+{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return;
}
- if (!inbounds(buf, start)) {
+ bool oob = false;
+ start = normalize_index(buf, start, &oob);
+ end = normalize_index(buf, end, &oob);
+
+ if (strict_indexing && oob) {
api_set_error(err, Validation, _("Index out of bounds"));
return;
}
- start = normalize_index(buf, start) + (include_start ? 0 : 1);
- include_end = include_end || (end >= buf->b_ml.ml_line_count);
- end = normalize_index(buf, end) + (include_end ? 1 : 0);
if (start > end) {
api_set_error(err,
@@ -457,6 +552,8 @@ Boolean buffer_is_valid(Buffer buffer)
/// Inserts a sequence of lines to a buffer at a certain index
///
+/// @deprecated use buffer_set_lines(buffer, lnum, lnum, true, lines)
+///
/// @param buffer The buffer handle
/// @param lnum Insert the lines after `lnum`. If negative, it will append
/// to the end of the buffer.
@@ -467,8 +564,9 @@ void buffer_insert(Buffer buffer,
ArrayOf(String) lines,
Error *err)
{
- bool end_start = lnum < 0;
- buffer_set_line_slice(buffer, lnum, lnum, !end_start, end_start, lines, err);
+ // "lnum" will be the index of the line after inserting,
+ // no matter if it is negative or not
+ buffer_set_lines(buffer, lnum, lnum, true, lines, err);
}
/// Return a tuple (row,col) representing the position of the named mark
@@ -632,20 +730,26 @@ static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
}
// Normalizes 0-based indexes to buffer line numbers
-static int64_t normalize_index(buf_T *buf, int64_t index)
+static int64_t normalize_index(buf_T *buf, int64_t index, bool *oob)
{
+ int64_t line_count = buf->b_ml.ml_line_count;
// Fix if < 0
- index = index < 0 ? buf->b_ml.ml_line_count + index : index;
+ index = index < 0 ? line_count + index +1 : index;
+
+ // Check for oob
+ if (index > line_count) {
+ *oob = true;
+ index = line_count;
+ } else if (index < 0) {
+ *oob = true;
+ index = 0;
+ }
// Convert the index to a vim line number
index++;
- // Fix if > line_count
- index = index > buf->b_ml.ml_line_count ? buf->b_ml.ml_line_count : index;
return index;
}
-// Returns true if the 0-indexed `index` is within the 1-indexed buffer bounds.
-static bool inbounds(buf_T *buf, int64_t index)
+static int64_t convert_index(int64_t index)
{
- linenr_T nlines = buf->b_ml.ml_line_count;
- return index >= -nlines && index < nlines;
+ return index < 0 ? index - 1 : index;
}
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 8d3769cb54..c514c4378e 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -264,17 +264,16 @@ open_buffer (
return retval;
}
-/*
- * Return TRUE if "buf" points to a valid buffer (in the buffer list).
- */
-int buf_valid(buf_T *buf)
+/// Check that "buf" points to a valid buffer (in the buffer list).
+bool buf_valid(buf_T *buf)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
FOR_ALL_BUFFERS(bp) {
if (bp == buf) {
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
/*
@@ -2062,16 +2061,15 @@ void buflist_setfpos(buf_T *const buf, win_T *const win,
}
-/*
- * Return true when "wip" has 'diff' set and the diff is only for another tab
- * page. That's because a diff is local to a tab page.
- */
+/// Check that "wip" has 'diff' set and the diff is only for another tab page.
+/// That's because a diff is local to a tab page.
static bool wininfo_other_tab_diff(wininfo_T *wip)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
if (wip->wi_opt.wo_diff) {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- /* return false when it's a window in the current tab page, thus
- * the buffer was in diff mode here */
+ // return false when it's a window in the current tab page, thus
+ // the buffer was in diff mode here
if (wip->wi_win == wp) {
return false;
}
@@ -2428,52 +2426,62 @@ void buflist_altfpos(win_T *win)
buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE);
}
-/*
- * Return TRUE if 'ffname' is not the same file as current file.
- * Fname must have a full path (expanded by path_get_absolute_path()).
- */
-int otherfile(char_u *ffname)
+/// Check that "ffname" is not the same file as current file.
+/// Fname must have a full path (expanded by path_get_absolute_path()).
+///
+/// @param ffname full path name to check
+bool otherfile(char_u *ffname)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
return otherfile_buf(curbuf, ffname, NULL, false);
}
-static int otherfile_buf(buf_T *buf, char_u *ffname,
- FileID *file_id_p, bool file_id_valid)
+/// Check that "ffname" is not the same file as the file loaded in "buf".
+/// Fname must have a full path (expanded by path_get_absolute_path()).
+///
+/// @param buf buffer to check
+/// @param ffname full path name to check
+/// @param file_id_p information about the file at "ffname".
+/// @param file_id_valid whether a valid "file_id_p" was passed in.
+static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p,
+ bool file_id_valid)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
- /* no name is different */
+ // no name is different
if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) {
- return TRUE;
+ return true;
}
if (fnamecmp(ffname, buf->b_ffname) == 0) {
- return FALSE;
+ return false;
}
{
FileID file_id;
- /* If no struct stat given, get it now */
+ // If no struct stat given, get it now
if (file_id_p == NULL) {
file_id_p = &file_id;
file_id_valid = os_fileid((char *)ffname, file_id_p);
}
if (!file_id_valid) {
// file_id not valid, assume files are different.
- return TRUE;
+ return true;
}
- /* Use dev/ino to check if the files are the same, even when the names
- * are different (possible with links). Still need to compare the
- * name above, for when the file doesn't exist yet.
- * Problem: The dev/ino changes when a file is deleted (and created
- * again) and remains the same when renamed/moved. We don't want to
- * stat() each buffer each time, that would be too slow. Get the
- * dev/ino again when they appear to match, but not when they appear
- * to be different: Could skip a buffer when it's actually the same
- * file. */
+ // Use dev/ino to check if the files are the same, even when the names
+ // are different (possible with links). Still need to compare the
+ // name above, for when the file doesn't exist yet.
+ // Problem: The dev/ino changes when a file is deleted (and created
+ // again) and remains the same when renamed/moved. We don't want to
+ // stat() each buffer each time, that would be too slow. Get the
+ // dev/ino again when they appear to match, but not when they appear
+ // to be different: Could skip a buffer when it's actually the same
+ // file.
if (buf_same_file_id(buf, file_id_p)) {
buf_set_file_id(buf);
- if (buf_same_file_id(buf, file_id_p))
- return FALSE;
+ if (buf_same_file_id(buf, file_id_p)) {
+ return false;
+ }
}
}
- return TRUE;
+ return true;
}
// Set file_id for a buffer.
@@ -2490,11 +2498,14 @@ void buf_set_file_id(buf_T *buf)
}
}
-// return TRUE if file_id in buffer "buf" matches with "file_id".
+/// Check that file_id in buffer "buf" matches with "file_id".
+///
+/// @param buf buffer
+/// @param file_id file id
static bool buf_same_file_id(buf_T *buf, FileID *file_id)
+ FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
- return buf->file_id_valid
- && os_fileid_equal(&(buf->file_id), file_id);
+ return buf->file_id_valid && os_fileid_equal(&(buf->file_id), file_id);
}
/*
@@ -2777,23 +2788,28 @@ void maketitle(void)
resettitle();
}
-/*
- * Used for title and icon: Check if "str" differs from "*last". Set "*last"
- * from "str" if it does.
- * Return TRUE when "*last" changed.
- */
-static int ti_change(char_u *str, char_u **last)
+/// Used for title and icon: Check if "str" differs from "*last". Set "*last"
+/// from "str" if it does by freeing the old value of "*last" and duplicating
+/// "str".
+///
+/// @param str desired title string
+/// @param[in,out] last current title string
+//
+/// @return true when "*last" changed.
+static bool ti_change(char_u *str, char_u **last)
+ FUNC_ATTR_WARN_UNUSED_RESULT
{
if ((str == NULL) != (*last == NULL)
|| (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) {
xfree(*last);
- if (str == NULL)
+ if (str == NULL) {
*last = NULL;
- else
+ } else {
*last = vim_strsave(str);
- return TRUE;
+ }
+ return true;
}
- return FALSE;
+ return false;
}
/*
@@ -3929,26 +3945,29 @@ void get_rel_pos(win_T *wp, char_u *buf, int buflen)
: (int)(above * 100L / (above + below)));
}
-/*
- * Append (file 2 of 8) to "buf[buflen]", if editing more than one file.
- * Return TRUE if it was appended.
- */
-static int
-append_arg_number (
- win_T *wp,
- char_u *buf,
- int buflen,
- int add_file /* Add "file" before the arg number */
-)
+/// Append (file 2 of 8) to "buf[buflen]", if editing more than one file.
+///
+/// @param wp window whose buffers to check
+/// @param[in,out] buf string buffer to add the text to
+/// @param buflen length of the string buffer
+/// @param add_file if true, add "file" before the arg number
+///
+/// @return true if it was appended.
+static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file)
+ FUNC_ATTR_NONNULL_ALL
{
- char_u *p;
+ // Nothing to do
+ if (ARGCOUNT <= 1) {
+ return false;
+ }
- if (ARGCOUNT <= 1) /* nothing to do */
- return FALSE;
+ char_u *p = buf + STRLEN(buf); // go to the end of the buffer
+
+ // Early out if the string is getting too long
+ if (p - buf + 35 >= buflen) {
+ return false;
+ }
- p = buf + STRLEN(buf); /* go to the end of the buffer */
- if (p - buf + 35 >= buflen) /* getting too long */
- return FALSE;
*p++ = ' ';
*p++ = '(';
if (add_file) {
@@ -3956,9 +3975,10 @@ append_arg_number (
p += 5;
}
vim_snprintf((char *)p, (size_t)(buflen - (p - buf)),
- wp->w_arg_idx_invalid ? "(%d) of %d)"
- : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT);
- return TRUE;
+ wp->w_arg_idx_invalid
+ ? "(%d) of %d)"
+ : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT);
+ return true;
}
/*
@@ -4592,11 +4612,16 @@ char_u *buf_spname(buf_T *buf)
return NULL;
}
-/*
- * Find a window for buffer "buf".
- * If found true is returned and "wp" and "tp" are set to the window and tabpage.
- * If not found false is returned.
- */
+/// Find a window for buffer "buf".
+/// If found true is returned and "wp" and "tp" are set to
+/// the window and tabpage.
+/// If not found, false is returned.
+///
+/// @param buf buffer to find a window for
+/// @param[out] wp stores the found window
+/// @param[out] tp stores the found tabpage
+///
+/// @return true if a window was found for the buffer.
bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp)
{
*wp = NULL;
@@ -5110,50 +5135,54 @@ void set_buflisted(int on)
}
}
-/*
- * Read the file for "buf" again and check if the contents changed.
- * Return TRUE if it changed or this could not be checked.
- */
-int buf_contents_changed(buf_T *buf)
+/// Read the file for "buf" again and check if the contents changed.
+/// Return true if it changed or this could not be checked.
+///
+/// @param buf buffer to check
+///
+/// @return true if the buffer's contents have changed
+bool buf_contents_changed(buf_T *buf)
+ FUNC_ATTR_NONNULL_ALL
{
- buf_T *newbuf;
- int differ = TRUE;
- linenr_T lnum;
- aco_save_T aco;
- exarg_T ea;
+ bool differ = true;
- /* Allocate a buffer without putting it in the buffer list. */
- newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
- if (newbuf == NULL)
- return TRUE;
+ // Allocate a buffer without putting it in the buffer list.
+ buf_T *newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
+ if (newbuf == NULL) {
+ return true;
+ }
- /* Force the 'fileencoding' and 'fileformat' to be equal. */
+ // Force the 'fileencoding' and 'fileformat' to be equal.
+ exarg_T ea;
prep_exarg(&ea, buf);
- /* set curwin/curbuf to buf and save a few things */
+ // set curwin/curbuf to buf and save a few things
+ aco_save_T aco;
aucmd_prepbuf(&aco, newbuf);
if (ml_open(curbuf) == OK
&& readfile(buf->b_ffname, buf->b_fname,
- (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
- &ea, READ_NEW | READ_DUMMY) == OK) {
- /* compare the two files line by line */
+ (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
+ &ea, READ_NEW | READ_DUMMY) == OK) {
+ // compare the two files line by line
if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) {
- differ = FALSE;
- for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
- if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) {
- differ = TRUE;
+ differ = false;
+ for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) {
+ if (STRCMP(ml_get_buf(buf, lnum, false), ml_get(lnum)) != 0) {
+ differ = true;
break;
}
+ }
}
}
xfree(ea.cmd);
- /* restore curwin/curbuf and a few other things */
+ // restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
- if (curbuf != newbuf) /* safety check */
- wipe_buffer(newbuf, FALSE);
+ if (curbuf != newbuf) { // safety check
+ wipe_buffer(newbuf, false);
+ }
return differ;
}
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 936a14b903..86e63eb52c 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -533,9 +533,9 @@ struct file_buffer {
/*
* Character table, only used in charset.c for 'iskeyword'
- * 32 bytes of 8 bits: 1 bit per character 0-255.
+ * bitset with 4*64=256 bits: 1 bit per character 0-255.
*/
- char_u b_chartab[32];
+ uint64_t b_chartab[4];
/* Table used for mappings local to a buffer. */
mapblock_T *(b_maphash[256]);
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 4e329b5cd8..83e2aaa6e6 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -32,16 +32,16 @@
#endif
-static int chartab_initialized = FALSE;
+static bool chartab_initialized = false;
-// b_chartab[] is an array of 32 bytes, each bit representing one of the
+// b_chartab[] is an array with 256 bits, each bit representing one of the
// characters 0-255.
#define SET_CHARTAB(buf, c) \
- (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7))
+ (buf)->b_chartab[(unsigned)(c) >> 6] |= (1ull << ((c) & 0x3f))
#define RESET_CHARTAB(buf, c) \
- (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7))
+ (buf)->b_chartab[(unsigned)(c) >> 6] &= ~(1ull << ((c) & 0x3f))
#define GET_CHARTAB(buf, c) \
- ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7)))
+ ((buf)->b_chartab[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f)))
/// Fill chartab[]. Also fills curbuf->b_chartab[] with flags for keyword
/// characters for current buffer.
@@ -69,12 +69,12 @@ static int chartab_initialized = FALSE;
/// an error, OK otherwise.
int init_chartab(void)
{
- return buf_init_chartab(curbuf, TRUE);
+ return buf_init_chartab(curbuf, true);
}
/// Helper for init_chartab
///
-/// @param global FALSE: only set buf->b_chartab[]
+/// @param global false: only set buf->b_chartab[]
///
/// @return FAIL if 'iskeyword', 'isident', 'isfname' or 'isprint' option has
/// an error, OK otherwise.
@@ -84,13 +84,13 @@ int buf_init_chartab(buf_T *buf, int global)
int c2;
char_u *p;
int i;
- int tilde;
- int do_isalpha;
+ bool tilde;
+ bool do_isalpha;
if (global) {
// Set the default size for printable characters:
// From <Space> to '~' is 1 (printable), others are 2 (not printable).
- // This also inits all 'isident' and 'isfname' flags to FALSE.
+ // This also inits all 'isident' and 'isfname' flags to false.
c = 0;
while (c < ' ') {
@@ -133,7 +133,7 @@ int buf_init_chartab(buf_T *buf, int global)
}
}
- // Init word char flags all to FALSE
+ // Init word char flags all to false
memset(buf->b_chartab, 0, (size_t)32);
if (enc_dbcs != 0) {
@@ -169,11 +169,11 @@ int buf_init_chartab(buf_T *buf, int global)
}
while (*p) {
- tilde = FALSE;
- do_isalpha = FALSE;
+ tilde = false;
+ do_isalpha = false;
if ((*p == '^') && (p[1] != NUL)) {
- tilde = TRUE;
+ tilde = true;
++p;
}
@@ -212,7 +212,7 @@ int buf_init_chartab(buf_T *buf, int global)
// standard function isalpha(). This takes care of locale for
// single-byte characters).
if (c == '@') {
- do_isalpha = TRUE;
+ do_isalpha = true;
c = 1;
c2 = 255;
} else {
@@ -231,7 +231,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (i == 0) {
// (re)set ID flag
if (tilde) {
- chartab[c] &= ~CT_ID_CHAR;
+ chartab[c] &= (uint8_t)~CT_ID_CHAR;
} else {
chartab[c] |= CT_ID_CHAR;
}
@@ -244,18 +244,18 @@ int buf_init_chartab(buf_T *buf, int global)
|| (p_altkeymap && (F_isalpha(c) || F_isdigit(c))))
&& !(enc_dbcs && (MB_BYTE2LEN(c) == 2))) {
if (tilde) {
- chartab[c] = (chartab[c] & ~CT_CELL_MASK)
- + ((dy_flags & DY_UHEX) ? 4 : 2);
- chartab[c] &= ~CT_PRINT_CHAR;
+ chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK)
+ + ((dy_flags & DY_UHEX) ? 4 : 2));
+ chartab[c] &= (uint8_t)~CT_PRINT_CHAR;
} else {
- chartab[c] = (chartab[c] & ~CT_CELL_MASK) + 1;
+ chartab[c] = (uint8_t)((chartab[c] & ~CT_CELL_MASK) + 1);
chartab[c] |= CT_PRINT_CHAR;
}
}
} else if (i == 2) {
// (re)set fname flag
if (tilde) {
- chartab[c] &= ~CT_FNAME_CHAR;
+ chartab[c] &= (uint8_t)~CT_FNAME_CHAR;
} else {
chartab[c] |= CT_FNAME_CHAR;
}
@@ -280,7 +280,7 @@ int buf_init_chartab(buf_T *buf, int global)
}
}
}
- chartab_initialized = TRUE;
+ chartab_initialized = true;
return OK;
}
@@ -333,7 +333,8 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET
{
char_u *res;
char_u *p;
- int l, c;
+ int c;
+ size_t l;
char_u hexbuf[11];
if (has_mbyte) {
@@ -343,7 +344,7 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET
p = s;
while (*p != NUL) {
- if ((l = (*mb_ptr2len)(p)) > 1) {
+ if ((l = (size_t)(*mb_ptr2len)(p)) > 1) {
c = (*mb_ptr2char)(p);
p += l;
@@ -354,7 +355,7 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET
len += STRLEN(hexbuf);
}
} else {
- l = byte2cells(*p++);
+ l = (size_t)byte2cells(*p++);
if (l > 0) {
len += l;
@@ -366,14 +367,14 @@ char_u *transstr(char_u *s) FUNC_ATTR_NONNULL_RET
}
res = xmallocz(len);
} else {
- res = xmallocz(vim_strsize(s));
+ res = xmallocz((size_t)vim_strsize(s));
}
*res = NUL;
p = s;
while (*p != NUL) {
- if (has_mbyte && ((l = (*mb_ptr2len)(p)) > 1)) {
+ if (has_mbyte && ((l = (size_t)(*mb_ptr2len)(p)) > 1)) {
c = (*mb_ptr2char)(p);
if (vim_isprintc(c)) {
@@ -477,9 +478,9 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
i += (*mb_ptr2len)(STR_PTR(i));
} else {
if (buf == NULL) {
- GA_CHAR(i) = TOLOWER_LOC(GA_CHAR(i));
+ GA_CHAR(i) = (char_u)TOLOWER_LOC(GA_CHAR(i));
} else {
- buf[i] = TOLOWER_LOC(buf[i]);
+ buf[i] = (char_u)TOLOWER_LOC(buf[i]);
}
++i;
}
@@ -493,7 +494,7 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
// Catch 22: chartab[] can't be initialized before the options are
// initialized, and initializing options may cause transchar() to be called!
-// When chartab_initialized == FALSE don't use chartab[].
+// When chartab_initialized == false don't use chartab[].
// Does NOT work for multi-byte characters, c must be <= 255.
// Also doesn't work for the first byte of a multi-byte, "c" must be a
// character!
@@ -518,7 +519,7 @@ char_u* transchar(int c)
if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || F_ischar(c)))
|| ((c < 256) && vim_isprintc_strict(c))) {
// printable character
- transchar_buf[i] = c;
+ transchar_buf[i] = (char_u)c;
transchar_buf[i + 1] = NUL;
} else {
transchar_nonprint(transchar_buf + i, c);
@@ -564,7 +565,7 @@ void transchar_nonprint(char_u *buf, int c)
// 0x00 - 0x1f and 0x7f
buf[0] = '^';
// DEL displayed as ^?
- buf[1] = c ^ 0x40;
+ buf[1] = (char_u)(c ^ 0x40);
buf[2] = NUL;
} else if (enc_utf8 && (c >= 0x80)) {
@@ -572,12 +573,12 @@ void transchar_nonprint(char_u *buf, int c)
} else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) {
// 0xa0 - 0xfe
buf[0] = '|';
- buf[1] = c - 0x80;
+ buf[1] = (char_u)(c - 0x80);
buf[2] = NUL;
} else {
// 0x80 - 0x9f and 0xff
buf[0] = '~';
- buf[1] = (c - 0x80) ^ 0x40;
+ buf[1] = (char_u)((c - 0x80) ^ 0x40);
buf[2] = NUL;
}
}
@@ -592,11 +593,11 @@ void transchar_hex(char_u *buf, int c)
buf[0] = '<';
if (c > 255) {
- buf[++i] = nr2hex((unsigned)c >> 12);
- buf[++i] = nr2hex((unsigned)c >> 8);
+ buf[++i] = (char_u)nr2hex((unsigned)c >> 12);
+ buf[++i] = (char_u)nr2hex((unsigned)c >> 8);
}
- buf[++i] = nr2hex((unsigned)c >> 4);
- buf[++i] = nr2hex((unsigned)c);
+ buf[++i] = (char_u)(nr2hex((unsigned)c >> 4));
+ buf[++i] = (char_u)(nr2hex((unsigned)c));
buf[++i] = '>';
buf[++i] = NUL;
}
@@ -734,9 +735,8 @@ int vim_strnsize(char_u *s, int len)
/// @return Number of characters.
#define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \
if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) { \
- int ts; \
- ts = (buf)->b_p_ts; \
- return (int)(ts - (col % ts)); \
+ const int ts = (int) (buf)->b_p_ts; \
+ return (ts - (int)(col % ts)); \
} else { \
return ptr2cells(p); \
}
@@ -1137,7 +1137,7 @@ static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp)
int n;
if ((*s == TAB) && (!wp->w_p_list || lcs_tab1)) {
- n = wp->w_buffer->b_p_ts;
+ n = (int)wp->w_buffer->b_p_ts;
return n - (col % n);
}
n = ptr2cells(s);
@@ -1205,11 +1205,11 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
char_u *line; // start of the line
int incr;
int head;
- int ts = wp->w_buffer->b_p_ts;
+ int ts = (int)wp->w_buffer->b_p_ts;
int c;
vcol = 0;
- line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
+ line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
if (pos->col == MAXCOL) {
// continue until the NUL
@@ -1329,7 +1329,7 @@ colnr_T getvcol_nolist(pos_T *posp)
int list_save = curwin->w_p_list;
colnr_T vcol;
- curwin->w_p_list = FALSE;
+ curwin->w_p_list = false;
getvcol(curwin, posp, NULL, &vcol, NULL);
curwin->w_p_list = list_save;
return vcol;
@@ -1358,7 +1358,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
endadd = 0;
// Cannot put the cursor on part of a wide character.
- ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
+ ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
if (pos->col < (colnr_T)STRLEN(ptr)) {
int c = (*mb_ptr2char)(ptr + pos->col);
@@ -1595,7 +1595,7 @@ bool vim_islower(int c)
if (c >= 0x100) {
if (has_mbyte) {
- return iswlower(c);
+ return iswlower((wint_t)c);
}
// islower() can't handle these chars and may crash
@@ -1626,7 +1626,7 @@ bool vim_isupper(int c)
if (c >= 0x100) {
if (has_mbyte) {
- return iswupper(c);
+ return iswupper((wint_t)c);
}
// isupper() can't handle these chars and may crash
@@ -1653,7 +1653,7 @@ int vim_toupper(int c)
if (c >= 0x100) {
if (has_mbyte) {
- return towupper(c);
+ return (int)towupper((wint_t)c);
}
// toupper() can't handle these chars and may crash
@@ -1680,7 +1680,7 @@ int vim_tolower(int c)
if (c >= 0x100) {
if (has_mbyte) {
- return towlower(c);
+ return (int)towlower((wint_t)c);
}
// tolower() can't handle these chars and may crash
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 1c33c4d549..614a5d43be 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -2358,13 +2358,13 @@ void set_completion(colnr_T startcol, list_T *list)
int save_w_wrow = curwin->w_wrow;
compl_curr_match = compl_first_match;
- if (compl_no_insert) {
+ if (compl_no_insert || compl_no_select) {
ins_complete(K_DOWN, false);
- } else {
- ins_complete(Ctrl_N, false);
if (compl_no_select) {
- ins_complete(Ctrl_P, false);
+ ins_complete(K_UP, false);
}
+ } else {
+ ins_complete(Ctrl_N, false);
}
// Lazily show the popup menu, unless we got interrupted.
@@ -4239,9 +4239,10 @@ void ins_compl_check_keys(int frequency)
static int ins_compl_key2dir(int c)
{
if (c == Ctrl_P || c == Ctrl_L
- || (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP
- || c == K_S_UP || c == K_UP)))
+ || c == K_PAGEUP || c == K_KPAGEUP
+ || c == K_S_UP || c == K_UP) {
return BACKWARD;
+ }
return FORWARD;
}
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index f71620a7b4..5477e79cad 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -174,6 +174,7 @@ static char *e_illvar = N_("E461: Illegal variable name: %s");
static char *e_float_as_string = N_("E806: using Float as a String");
static char_u * const empty_string = (char_u *)"";
+static char_u * const namespace_char = (char_u *)"abglstvw";
static dictitem_T globvars_var; /* variable used for g: */
#define globvarht globvardict.dv_hashtab
@@ -17873,21 +17874,28 @@ static int get_env_len(char_u **arg)
return len;
}
-/*
- * Get the length of the name of a function or internal variable.
- * "arg" is advanced to the first non-white character after the name.
- * Return 0 if something is wrong.
- */
-static int get_id_len(char_u **arg)
-{
- char_u *p;
+// Get the length of the name of a function or internal variable.
+// "arg" is advanced to the first non-white character after the name.
+// Return 0 if something is wrong.
+static int get_id_len(char_u **arg) {
+ char_u *p;
int len;
- /* Find the end of the name. */
- for (p = *arg; eval_isnamec(*p); ++p)
- ;
- if (p == *arg) /* no name found */
+ // Find the end of the name.
+ for (p = *arg; eval_isnamec(*p); p++) {
+ if (*p == ':') {
+ // "s:" is start of "s:var", but "n:" is not and can be used in
+ // slice "[n:]". Also "xx:" is not a namespace.
+ len = (int)(p - *arg);
+ if (len > 1
+ || (len == 1 && vim_strchr(namespace_char, **arg) == NULL)) {
+ break;
+ }
+ }
+ }
+ if (p == *arg) { // no name found
return 0;
+ }
len = (int)(p - *arg);
*arg = skipwhite(p);
@@ -17958,28 +17966,29 @@ static int get_name_len(char_u **arg, char_u **alias, int evaluate, int verbose)
return len;
}
-/*
- * Find the end of a variable or function name, taking care of magic braces.
- * If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the
- * start and end of the first magic braces item.
- * "flags" can have FNE_INCL_BR and FNE_CHECK_START.
- * Return a pointer to just after the name. Equal to "arg" if there is no
- * valid name.
- */
-static char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end, int flags)
+// Find the end of a variable or function name, taking care of magic braces.
+// If "expr_start" is not NULL then "expr_start" and "expr_end" are set to the
+// start and end of the first magic braces item.
+// "flags" can have FNE_INCL_BR and FNE_CHECK_START.
+// Return a pointer to just after the name. Equal to "arg" if there is no
+// valid name.
+static char_u *find_name_end(char_u *arg, char_u **expr_start,
+ char_u **expr_end, int flags)
{
int mb_nest = 0;
int br_nest = 0;
- char_u *p;
+ char_u *p;
+ int len;
if (expr_start != NULL) {
*expr_start = NULL;
*expr_end = NULL;
}
- /* Quick check for valid starting character. */
- if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{')
+ // Quick check for valid starting character.
+ if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') {
return arg;
+ }
for (p = arg; *p != NUL
&& (eval_isnamec(*p)
@@ -17994,30 +18003,44 @@ static char_u *find_name_end(char_u *arg, char_u **expr_start, char_u **expr_end
if (*p == NUL)
break;
} else if (*p == '"') {
- /* skip over "str\"ing" to avoid counting [ and ] inside it. */
- for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p))
- if (*p == '\\' && p[1] != NUL)
+ // skip over "str\"ing" to avoid counting [ and ] inside it.
+ for (p = p + 1; *p != NUL && *p != '"'; mb_ptr_adv(p)) {
+ if (*p == '\\' && p[1] != NUL) {
++p;
- if (*p == NUL)
+ }
+ }
+ if (*p == NUL) {
break;
+ }
+ } else if (br_nest == 0 && mb_nest == 0 && *p == ':') {
+ // "s:" is start of "s:var", but "n:" is not and can be used in
+ // slice "[n:]". Also "xx:" is not a namespace.
+ len = (int)(p - arg);
+ if (len > 1
+ || (len == 1 && vim_strchr(namespace_char, *arg) == NULL)) {
+ break;
+ }
}
if (mb_nest == 0) {
- if (*p == '[')
+ if (*p == '[') {
++br_nest;
- else if (*p == ']')
+ } else if (*p == ']') {
--br_nest;
+ }
}
if (br_nest == 0) {
if (*p == '{') {
mb_nest++;
- if (expr_start != NULL && *expr_start == NULL)
+ if (expr_start != NULL && *expr_start == NULL) {
*expr_start = p;
+ }
} else if (*p == '}') {
mb_nest--;
- if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL)
+ if (expr_start != NULL && mb_nest == 0 && *expr_end == NULL) {
*expr_end = p;
+ }
}
}
}
@@ -21993,7 +22016,15 @@ repeat:
}
if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') {
+ // vim_strsave_shellescape() needs a NUL terminated string.
+ c = (*fnamep)[*fnamelen];
+ if (c != NUL) {
+ (*fnamep)[*fnamelen] = NUL;
+ }
p = vim_strsave_shellescape(*fnamep, false, false);
+ if (c != NUL) {
+ (*fnamep)[*fnamelen] = c;
+ }
xfree(*bufp);
*bufp = *fnamep = p;
*fnamelen = STRLEN(p);
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 618245ea23..40b5718071 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -922,8 +922,8 @@ EXTERN int KeyTyped; // TRUE if user typed current char
EXTERN int KeyStuffed; // TRUE if current char from stuffbuf
EXTERN int maptick INIT(= 0); // tick for each non-mapped char
-EXTERN char_u chartab[256]; /* table used in charset.c; See
- init_chartab() for explanation */
+EXTERN uint8_t chartab[256]; // table used in charset.c; See
+ // init_chartab() for explanation
EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */
EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 2e671653ed..34d8fde4f1 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -166,7 +166,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
// Glue together the given directory from $PATH with name and save into
// buf.
STRLCPY(buf, path, e - path + 1);
- append_path((char *) buf, (const char *) name, (int)buf_len);
+ append_path((char *) buf, (const char *) name, buf_len);
if (is_executable(buf)) {
// Check if the caller asked for a copy of the path.
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 5cd93ab811..22a3f96cfa 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -268,16 +268,13 @@ char_u *shorten_dir(char_u *str)
*/
bool dir_of_file_exists(char_u *fname)
{
- char_u *p;
- int c;
- bool retval;
-
- p = path_tail_with_sep(fname);
- if (p == fname)
+ char_u *p = path_tail_with_sep(fname);
+ if (p == fname) {
return true;
- c = *p;
+ }
+ char_u c = *p;
*p = NUL;
- retval = os_isdir(fname);
+ bool retval = os_isdir(fname);
*p = c;
return retval;
}
@@ -539,15 +536,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
size_t wildoff, int flags, bool didstar)
FUNC_ATTR_NONNULL_ALL
{
- char_u *buf;
- char_u *p, *s, *e;
int start_len = gap->ga_len;
- char_u *pat;
- int starts_with_dot;
- int matches;
- int len;
+ size_t len;
bool starstar = false;
- static int stardepth = 0; /* depth for "**" expansion */
+ static int stardepth = 0; // depth for "**" expansion
/* Expanding "**" may take a long time, check for CTRL-C. */
if (stardepth > 0) {
@@ -558,16 +550,14 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
// Make room for file name. When doing encoding conversion the actual
// length may be quite a bit longer, thus use the maximum possible length.
- buf = xmalloc(MAXPATHL);
-
- /*
- * Find the first part in the path name that contains a wildcard.
- * When EW_ICASE is set every letter is considered to be a wildcard.
- * Copy it into "buf", including the preceding characters.
- */
- p = buf;
- s = buf;
- e = NULL;
+ char_u *buf = xmalloc(MAXPATHL);
+
+ // Find the first part in the path name that contains a wildcard.
+ // When EW_ICASE is set every letter is considered to be a wildcard.
+ // Copy it into "buf", including the preceding characters.
+ char_u *p = buf;
+ char_u *s = buf;
+ char_u *e = NULL;
const char_u *path_end = path;
while (*path_end != NUL) {
/* May ignore a wildcard that has a backslash before it; it will
@@ -588,7 +578,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
e = p;
}
if (has_mbyte) {
- len = (*mb_ptr2len)(path_end);
+ len = (size_t)(*mb_ptr2len)(path_end);
STRNCPY(p, path_end, len);
p += len;
path_end += len;
@@ -613,9 +603,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
if (p[0] == '*' && p[1] == '*')
starstar = true;
- /* convert the file pattern to a regexp pattern */
- starts_with_dot = (*s == '.');
- pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
+ // convert the file pattern to a regexp pattern
+ int starts_with_dot = (*s == '.');
+ char_u *pat = file_pat_to_reg_pat(s, e, NULL, false);
if (pat == NULL) {
xfree(buf);
return 0;
@@ -646,9 +636,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
if (!didstar && stardepth < 100 && starstar && e - s == 2
&& *path_end == '/') {
STRCPY(s, path_end + 1);
- ++stardepth;
- (void)do_path_expand(gap, buf, (int)(s - buf), flags, true);
- --stardepth;
+ stardepth++;
+ (void)do_path_expand(gap, buf, (size_t)(s - buf), flags, true);
+ stardepth--;
}
*s = NUL;
@@ -703,10 +693,11 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
xfree(buf);
vim_regfree(regmatch.regprog);
- matches = gap->ga_len - start_len;
- if (matches > 0)
+ size_t matches = (size_t)(gap->ga_len - start_len);
+ if (matches > 0) {
qsort(((char_u **)gap->ga_data) + start_len, matches,
- sizeof(char_u *), pstrcmp);
+ sizeof(char_u *), pstrcmp);
+ }
return matches;
}
@@ -736,27 +727,24 @@ static int find_previous_pathsep(char_u *path, char_u **psep)
*/
static bool is_unique(char_u *maybe_unique, garray_T *gap, int i)
{
- int candidate_len;
- int other_path_len;
- char_u **other_paths = (char_u **)gap->ga_data;
- char_u *rival;
+ char_u **other_paths = (char_u **)gap->ga_data;
for (int j = 0; j < gap->ga_len; j++) {
- if (j == i)
- continue; /* don't compare it with itself */
-
- candidate_len = (int)STRLEN(maybe_unique);
- other_path_len = (int)STRLEN(other_paths[j]);
- if (other_path_len < candidate_len)
- continue; /* it's different when it's shorter */
-
- rival = other_paths[j] + other_path_len - candidate_len;
+ if (j == i) {
+ continue; // don't compare it with itself
+ }
+ size_t candidate_len = STRLEN(maybe_unique);
+ size_t other_path_len = STRLEN(other_paths[j]);
+ if (other_path_len < candidate_len) {
+ continue; // it's different when it's shorter
+ }
+ char_u *rival = other_paths[j] + other_path_len - candidate_len;
if (fnamecmp(maybe_unique, rival) == 0
- && (rival == other_paths[j] || vim_ispathsep(*(rival - 1))))
- return false; /* match */
+ && (rival == other_paths[j] || vim_ispathsep(*(rival - 1)))) {
+ return false; // match
+ }
}
-
- return true; /* no match found */
+ return true; // no match found
}
/*
@@ -770,12 +758,8 @@ static bool is_unique(char_u *maybe_unique, garray_T *gap, int i)
*/
static void expand_path_option(char_u *curdir, garray_T *gap)
{
- char_u *path_option = *curbuf->b_p_path == NUL
- ? p_path : curbuf->b_p_path;
- char_u *buf;
- int len;
-
- buf = xmalloc(MAXPATHL);
+ char_u *path_option = *curbuf->b_p_path == NUL ? p_path : curbuf->b_p_path;
+ char_u *buf = xmalloc(MAXPATHL);
while (*path_option != NUL) {
copy_option_part(&path_option, buf, MAXPATHL, " ,");
@@ -787,26 +771,27 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
if (curbuf->b_ffname == NULL)
continue;
char_u *p = path_tail(curbuf->b_ffname);
- len = (int)(p - curbuf->b_ffname);
- if (len + (int)STRLEN(buf) >= MAXPATHL)
+ size_t len = (size_t)(p - curbuf->b_ffname);
+ if (len + STRLEN(buf) >= MAXPATHL) {
continue;
- if (buf[1] == NUL)
+ }
+ if (buf[1] == NUL) {
buf[len] = NUL;
- else
+ } else {
STRMOVE(buf + len, buf + 2);
+ }
memmove(buf, curbuf->b_ffname, len);
simplify_filename(buf);
- } else if (buf[0] == NUL)
- /* relative to current directory */
- STRCPY(buf, curdir);
- else if (path_with_url((char *)buf))
- /* URL can't be used here */
- continue;
- else if (!path_is_absolute_path(buf)) {
- /* Expand relative path to their full path equivalent */
- len = (int)STRLEN(curdir);
- if (len + (int)STRLEN(buf) + 3 > MAXPATHL)
+ } else if (buf[0] == NUL) {
+ STRCPY(buf, curdir); // relative to current directory
+ } else if (path_with_url((char *)buf)) {
+ continue; // URL can't be used here
+ } else if (!path_is_absolute_path(buf)) {
+ // Expand relative path to their full path equivalent
+ size_t len = STRLEN(curdir);
+ if (len + STRLEN(buf) + 3 > MAXPATHL) {
continue;
+ }
STRMOVE(buf + len + 1, buf);
STRCPY(buf, curdir);
buf[len] = PATHSEP;
@@ -860,31 +845,25 @@ static char_u *get_path_cutoff(char_u *fname, garray_T *gap)
*/
static void uniquefy_paths(garray_T *gap, char_u *pattern)
{
- int len;
- char_u **fnames = (char_u **)gap->ga_data;
+ char_u **fnames = (char_u **)gap->ga_data;
bool sort_again = false;
- char_u *pat;
- char_u *file_pattern;
- char_u *curdir;
regmatch_T regmatch;
garray_T path_ga;
- char_u **in_curdir = NULL;
- char_u *short_name;
+ char_u **in_curdir = NULL;
+ char_u *short_name;
ga_remove_duplicate_strings(gap);
ga_init(&path_ga, (int)sizeof(char_u *), 1);
- /*
- * We need to prepend a '*' at the beginning of file_pattern so that the
- * regex matches anywhere in the path. FIXME: is this valid for all
- * possible patterns?
- */
- len = (int)STRLEN(pattern);
- file_pattern = xmalloc(len + 2);
+ // We need to prepend a '*' at the beginning of file_pattern so that the
+ // regex matches anywhere in the path. FIXME: is this valid for all
+ // possible patterns?
+ size_t len = STRLEN(pattern);
+ char_u *file_pattern = xmalloc(len + 2);
file_pattern[0] = '*';
file_pattern[1] = NUL;
STRCAT(file_pattern, pattern);
- pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE);
+ char_u *pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, true);
xfree(file_pattern);
if (pat == NULL)
return;
@@ -895,11 +874,11 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
if (regmatch.regprog == NULL)
return;
- curdir = xmalloc(MAXPATHL);
+ char_u *curdir = xmalloc(MAXPATHL);
os_dirname(curdir, MAXPATHL);
expand_path_option(curdir, &path_ga);
- in_curdir = xcalloc(gap->ga_len, sizeof(char_u *));
+ in_curdir = xcalloc((size_t)gap->ga_len, sizeof(char_u *));
for (int i = 0; i < gap->ga_len && !got_int; i++) {
char_u *path = fnames[i];
@@ -908,7 +887,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
char_u *pathsep_p;
char_u *path_cutoff;
- len = (int)STRLEN(path);
+ len = STRLEN(path);
is_in_curdir = fnamencmp(curdir, path, dir_end - path) == 0
&& curdir[dir_end - path] == NUL;
if (is_in_curdir)
@@ -1113,9 +1092,8 @@ static bool has_special_wildchar(char_u *p)
int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
char_u ***file, int flags)
{
- int i;
garray_T ga;
- char_u *p;
+ char_u *p;
static bool recursive = false;
int add_pat;
bool did_expand_in_path = false;
@@ -1140,11 +1118,11 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
* avoids starting the shell for each argument separately.
* For `=expr` do use the internal function.
*/
- for (i = 0; i < num_pat; i++) {
+ for (int i = 0; i < num_pat; i++) {
if (has_special_wildchar(pat[i])
- && !(vim_backtick(pat[i]) && pat[i][1] == '=')
- )
+ && !(vim_backtick(pat[i]) && pat[i][1] == '=')) {
return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
+ }
}
#endif
@@ -1155,7 +1133,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
*/
ga_init(&ga, (int)sizeof(char_u *), 30);
- for (i = 0; i < num_pat; ++i) {
+ for (int i = 0; i < num_pat; ++i) {
add_pat = -1;
p = pat[i];
@@ -1212,7 +1190,9 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
recursive = true;
did_expand_in_path = true;
} else {
- add_pat = path_expand(&ga, p, flags);
+ size_t tmp_add_pat = path_expand(&ga, p, flags);
+ assert(tmp_add_pat <= INT_MAX);
+ add_pat = (int)tmp_add_pat;
}
}
}
@@ -1261,14 +1241,12 @@ static int expand_backtick(
int flags /* EW_* flags */
)
{
- char_u *p;
- char_u *cmd;
- char_u *buffer;
+ char_u *p;
+ char_u *buffer;
int cnt = 0;
- int i;
- /* Create the command: lop off the backticks. */
- cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2);
+ // Create the command: lop off the backticks.
+ char_u *cmd = vim_strnsave(pat + 1, STRLEN(pat) - 2);
if (*cmd == '=') /* `={expr}`: Expand expression */
buffer = eval_to_string(cmd + 1, &p, TRUE);
@@ -1288,7 +1266,7 @@ static int expand_backtick(
++p;
/* add an entry if it is not empty */
if (p > cmd) {
- i = *p;
+ char_u i = *p;
*p = NUL;
addfile(gap, cmd, flags);
*p = i;
@@ -1541,9 +1519,8 @@ find_file_name_in_path (
char_u *rel_fname /* file we are searching relative to */
)
{
- char_u *file_name;
- int c;
- char_u *tofree = NULL;
+ char_u *file_name;
+ char_u *tofree = NULL;
if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) {
tofree = eval_includeexpr(ptr, len);
@@ -1554,8 +1531,8 @@ find_file_name_in_path (
}
if (options & FNAME_EXP) {
- file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS,
- TRUE, rel_fname);
+ file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true,
+ rel_fname);
/*
* If the file could not be found in a normal way, try applying
@@ -1572,7 +1549,7 @@ find_file_name_in_path (
}
}
if (file_name == NULL && (options & FNAME_MESS)) {
- c = ptr[len];
+ char_u c = ptr[len];
ptr[len] = NUL;
EMSG2(_("E447: Can't find file \"%s\" in path"), ptr);
ptr[len] = c;
@@ -1631,7 +1608,7 @@ bool vim_isAbsName(char_u *name)
/// @param force is a flag to force expanding even if the path is absolute
///
/// @return FAIL for failure, OK otherwise
-int vim_FullName(const char *fname, char *buf, int len, bool force)
+int vim_FullName(const char *fname, char *buf, size_t len, bool force)
FUNC_ATTR_NONNULL_ARG(2)
{
int retval = OK;
@@ -2017,14 +1994,12 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file,
*/
int match_suffix(char_u *fname)
{
- int fnamelen, setsuflen;
- char_u *setsuf;
-#define MAXSUFLEN 30 /* maximum length of a file suffix */
+#define MAXSUFLEN 30 // maximum length of a file suffix
char_u suf_buf[MAXSUFLEN];
- fnamelen = (int)STRLEN(fname);
- setsuflen = 0;
- for (setsuf = p_su; *setsuf; ) {
+ size_t fnamelen = STRLEN(fname);
+ size_t setsuflen = 0;
+ for (char_u *setsuf = p_su; *setsuf; ) {
setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
if (setsuflen == 0) {
char_u *tail = path_tail(fname);
@@ -2035,10 +2010,10 @@ int match_suffix(char_u *fname)
break;
}
} else {
- if (fnamelen >= setsuflen
- && fnamencmp(suf_buf, fname + fnamelen - setsuflen,
- (size_t)setsuflen) == 0)
+ if (fnamelen >= setsuflen &&
+ fnamencmp(suf_buf, fname + fnamelen - setsuflen, setsuflen) == 0) {
break;
+ }
setsuflen = 0;
}
}
@@ -2049,7 +2024,7 @@ int match_suffix(char_u *fname)
///
/// @param directory Directory name, relative to current directory.
/// @return `FAIL` for failure, `OK` for success.
-int path_full_dir_name(char *directory, char *buffer, int len)
+int path_full_dir_name(char *directory, char *buffer, size_t len)
{
int SUCCESS = 0;
int retval = OK;
@@ -2091,10 +2066,10 @@ int path_full_dir_name(char *directory, char *buffer, int len)
// Append to_append to path with a slash in between.
// Append to_append to path with a slash in between.
-int append_path(char *path, const char *to_append, int max_len)
+int append_path(char *path, const char *to_append, size_t max_len)
{
- int current_length = STRLEN(path);
- int to_append_length = STRLEN(to_append);
+ size_t current_length = strlen(path);
+ size_t to_append_length = strlen(to_append);
// Do not append empty strings.
if (to_append_length == 0) {
@@ -2129,12 +2104,14 @@ int append_path(char *path, const char *to_append, int max_len)
/// Expand a given file to its absolute path.
///
-/// @param fname The filename which should be expanded.
-/// @param buf Buffer to store the absolute path of `fname`.
-/// @param len Length of `buf`.
-/// @param force Also expand when `fname` is already absolute.
-/// @return `FAIL` for failure, `OK` for success.
-static int path_get_absolute_path(const char_u *fname, char_u *buf, int len, int force)
+/// @param fname filename which should be expanded.
+/// @param buf buffer to store the absolute path of "fname".
+/// @param len length of "buf".
+/// @param force also expand when "fname" is already absolute.
+///
+/// @return FAIL for failure, OK for success.
+static int path_get_absolute_path(const char_u *fname, char_u *buf,
+ size_t len, int force)
{
char_u *p;
*buf = NUL;
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 42fd81f643..63a7e20880 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -411,6 +411,10 @@ static int terminal_execute(VimState *state, int key)
apply_autocmds(EVENT_FOCUSLOST, NULL, NULL, false, curbuf);
break;
+ // Temporary fix until paste events gets implemented
+ case K_PASTE:
+ break;
+
case K_LEFTMOUSE:
case K_LEFTDRAG:
case K_LEFTRELEASE:
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 98abb30b00..ebf21d162f 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -69,9 +69,14 @@ static char *features[] = {
// clang-format off
static int included_patches[] = {
+ 1654,
+ 1652,
+ 1643,
+ 1641,
1574,
1570,
1511,
+ 1425,
1366,
// 1219 NA
@@ -188,7 +193,7 @@ static int included_patches[] = {
// 1108,
// 1107,
// 1106 NA
- // 1105,
+ 1105,
// 1104 NA
// 1103 NA
// 1102,
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index c924988d06..a15d489a1f 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -1,8 +1,8 @@
-- Sanity checks for buffer_* API calls via msgpack-rpc
local helpers = require('test.functional.helpers')
-local clear, nvim, buffer, curbuf, curwin, eq, ok =
- helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
- helpers.eq, helpers.ok
+local clear, nvim, buffer = helpers.clear, helpers.nvim, helpers.buffer
+local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq
+local curbufmeths, ok = helpers.curbufmeths, helpers.ok
describe('buffer_* functions', function()
before_each(clear)
@@ -35,10 +35,11 @@ describe('buffer_* functions', function()
eq('', curbuf('get_line', 0))
end)
- it('get_line: out-of-bounds returns empty string', function()
+ it('get_line: out-of-bounds is an error', function()
curbuf('set_line', 0, 'line1.a')
- eq('', curbuf('get_line', 1))
- eq('', curbuf('get_line', -2))
+ eq(1, curbuf('line_count')) -- sanity
+ eq(false, pcall(curbuf, 'get_line', 1))
+ eq(false, pcall(curbuf, 'get_line', -2))
end)
it('set_line, del_line: out-of-bounds is an error', function()
@@ -68,14 +69,16 @@ describe('buffer_* functions', function()
eq({}, curbuf('get_line_slice', -4, -5, true, true))
end)
- it('set_line_slice: out-of-bounds is an error', function()
+ it('set_line_slice: out-of-bounds extends past end', function()
curbuf('set_line_slice', 0, 0, true, true, {'a', 'b', 'c'})
eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 2, true, true)) --sanity
eq({'c'}, curbuf('get_line_slice', -1, 4, true, true))
eq({'a', 'b', 'c'}, curbuf('get_line_slice', 0, 5, true, true))
- eq(false, pcall(curbuf, 'set_line_slice', 4, 5, true, true, {'d'}))
- eq(false, pcall(curbuf, 'set_line_slice', -4, -5, true, true, {'d'}))
+ curbuf('set_line_slice', 4, 5, true, true, {'d'})
+ eq({'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true))
+ curbuf('set_line_slice', -4, -5, true, true, {'e'})
+ eq({'e', 'a', 'b', 'c', 'd'}, curbuf('get_line_slice', 0, 5, true, true))
end)
it('works', function()
@@ -101,6 +104,136 @@ describe('buffer_* functions', function()
end)
end)
+ describe('{get,set}_lines', function()
+ local get_lines, set_lines = curbufmeths.get_lines, curbufmeths.set_lines
+ local line_count = curbufmeths.line_count
+
+ it('has correct line_count when inserting and deleting', function()
+ eq(1, line_count())
+ set_lines(-1, -1, true, {'line'})
+ eq(2, line_count())
+ set_lines(-1, -1, true, {'line'})
+ eq(3, line_count())
+ set_lines(-2, -1, true, {})
+ eq(2, line_count())
+ set_lines(-2, -1, true, {})
+ set_lines(-2, -1, true, {})
+ -- There's always at least one line
+ eq(1, line_count())
+ end)
+
+ it('can get, set and delete a single line', function()
+ eq({''}, get_lines(0, 1, true))
+ set_lines(0, 1, true, {'line1'})
+ eq({'line1'}, get_lines(0, 1, true))
+ set_lines(0, 1, true, {'line2'})
+ eq({'line2'}, get_lines(0, 1, true))
+ set_lines(0, 1, true, {})
+ eq({''}, get_lines(0, 1, true))
+ end)
+
+ it('can get a single line with strict indexing', function()
+ set_lines(0, 1, true, {'line1.a'})
+ eq(1, line_count()) -- sanity
+ eq(false, pcall(get_lines, 1, 2, true))
+ eq(false, pcall(get_lines, -3, -2, true))
+ end)
+
+ it('can get a single line with non-strict indexing', function()
+ set_lines(0, 1, true, {'line1.a'})
+ eq(1, line_count()) -- sanity
+ eq({}, get_lines(1, 2, false))
+ eq({}, get_lines(-3, -2, false))
+ end)
+
+ it('can set and delete a single line with strict indexing', function()
+ set_lines(0, 1, true, {'line1.a'})
+ eq(false, pcall(set_lines, 1, 2, true, {'line1.b'}))
+ eq(false, pcall(set_lines, -3, -2, true, {'line1.c'}))
+ eq({'line1.a'}, get_lines(0, -1, true))
+ eq(false, pcall(set_lines, 1, 2, true, {}))
+ eq(false, pcall(set_lines, -3, -2, true, {}))
+ eq({'line1.a'}, get_lines(0, -1, true))
+ end)
+
+ it('can set and delete a single line with non-strict indexing', function()
+ set_lines(0, 1, true, {'line1.a'})
+ set_lines(1, 2, false, {'line1.b'})
+ set_lines(-4, -3, false, {'line1.c'})
+ eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true))
+ set_lines(3, 4, false, {})
+ set_lines(-5, -4, false, {})
+ eq({'line1.c', 'line1.a', 'line1.b'}, get_lines(0, -1, true))
+ end)
+
+ it('can handle NULs', function()
+ set_lines(0, 1, true, {'ab\0cd'})
+ eq({'ab\0cd'}, get_lines(0, -1, true))
+ end)
+
+ it('works with multiple lines', function()
+ eq({''}, get_lines(0, -1, true))
+ -- Replace buffer
+ for _, mode in pairs({false, true}) do
+ set_lines(0, -1, mode, {'a', 'b', 'c'})
+ eq({'a', 'b', 'c'}, get_lines(0, -1, mode))
+ eq({'b', 'c'}, get_lines(1, -1, mode))
+ eq({'b'}, get_lines(1, 2, mode))
+ eq({}, get_lines(1, 1, mode))
+ eq({'a', 'b'}, get_lines(0, -2, mode))
+ eq({'b'}, get_lines(1, -2, mode))
+ eq({'b', 'c'}, get_lines(-3, -1, mode))
+ set_lines(1, 2, mode, {'a', 'b', 'c'})
+ eq({'a', 'a', 'b', 'c', 'c'}, get_lines(0, -1, mode))
+ set_lines(-2, -1, mode, {'a', 'b', 'c'})
+ eq({'a', 'a', 'b', 'c', 'a', 'b', 'c'},
+ get_lines(0, -1, mode))
+ set_lines(0, -4, mode, {})
+ eq({'a', 'b', 'c'}, get_lines(0, -1, mode))
+ set_lines(0, -1, mode, {})
+ eq({''}, get_lines(0, -1, mode))
+ end
+ end)
+
+ it('can get line ranges with non-strict indexing', function()
+ set_lines(0, -1, true, {'a', 'b', 'c'})
+ eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+
+ eq({}, get_lines(3, 4, false))
+ eq({}, get_lines(3, 10, false))
+ eq({}, get_lines(-5, -5, false))
+ eq({}, get_lines(3, -1, false))
+ eq({}, get_lines(-3, -4, false))
+ end)
+
+ it('can get line ranges with strict indexing', function()
+ set_lines(0, -1, true, {'a', 'b', 'c'})
+ eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+
+ eq(false, pcall(get_lines, 3, 4, true))
+ eq(false, pcall(get_lines, 3, 10, true))
+ eq(false, pcall(get_lines, -5, -5, true))
+ -- empty or inverted ranges are not errors
+ eq({}, get_lines(3, -1, true))
+ eq({}, get_lines(-3, -4, true))
+ end)
+
+ it('set_line_slice: out-of-bounds can extend past end', function()
+ set_lines(0, -1, true, {'a', 'b', 'c'})
+ eq({'a', 'b', 'c'}, get_lines(0, -1, true)) --sanity
+
+ eq({'c'}, get_lines(-2, 5, false))
+ eq({'a', 'b', 'c'}, get_lines(0, 6, false))
+ eq(false, pcall(set_lines, 4, 6, true, {'d'}))
+ set_lines(4, 6, false, {'d'})
+ eq({'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
+ eq(false, pcall(set_lines, -6, -6, true, {'e'}))
+ set_lines(-6, -6, false, {'e'})
+ eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
+ end)
+
+ end)
+
describe('{get,set}_var', function()
it('works', function()
curbuf('set_var', 'lua', {1, 2, {['3'] = 1}})
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index c0099e44c4..1b33275803 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -165,8 +165,8 @@ describe('server -> client', function()
eq('SOME TEXT', eval("rpcrequest(vim, 'buffer_get_line', "..buf..", 0)"))
- -- Call get_line_slice(buf, range [0,0], includes start, includes end)
- eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_line_slice', "..buf..", 0, 0, 1, 1)"))
+ -- Call get_lines(buf, range [0,0], strict_indexing)
+ eq({'SOME TEXT'}, eval("rpcrequest(vim, 'buffer_get_lines', "..buf..", 0, 1, 1)"))
end)
it('returns an error if the request failed', function()
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index 965b19581a..0e46aa5641 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -14,7 +14,7 @@ describe('TextYankPost', function()
execute('autocmd TextYankPost * let g:event = copy(v:event)')
execute('autocmd TextYankPost * let g:count += 1')
- curbufmeths.set_line_slice(0, -1, true, true, {
+ curbufmeths.set_lines(0, -1, true, {
'foo\0bar',
'baz text',
})
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 55c97d451b..4e294029ab 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -320,7 +320,7 @@ local function curbuf_contents()
-- previously sent keys are processed(vim_eval is a deferred function, and
-- only processed after all input)
wait()
- return table.concat(curbuf('get_line_slice', 0, -1, true, true), '\n')
+ return table.concat(curbuf('get_lines', 0, -1, true), '\n')
end
local function curwin(method, ...)
diff --git a/test/functional/legacy/105_filename_modifiers_spec.lua b/test/functional/legacy/105_filename_modifiers_spec.lua
deleted file mode 100644
index 3413667022..0000000000
--- a/test/functional/legacy/105_filename_modifiers_spec.lua
+++ /dev/null
@@ -1,81 +0,0 @@
--- Test filename modifiers.
-
-local helpers = require('test.functional.helpers')
-local clear = helpers.clear
-local execute, expect = helpers.execute, helpers.expect
-
-describe('filename modifiers', function()
- setup(clear)
-
- it('is working', function()
- local tmpdir = helpers.nvim('eval', 'resolve("/tmp")')
-
- execute('cd ' .. tmpdir)
- execute([=[set shell=sh]=])
- execute([=[set shellslash]=])
- execute([=[let tab="\t"]=])
- execute([=[command -nargs=1 Put :let expr=<q-args> | $put =expr.tab.strtrans(string(eval(expr)))]=])
- execute([=[let $HOME=fnamemodify('.', ':p:h:h:h')]=])
- execute([=[Put fnamemodify('.', ':p' )[-1:]]=])
- execute([=[Put fnamemodify('.', ':p:h' )[-1:]]=])
- execute([=[Put fnamemodify('test.out', ':p' )[-1:]]=])
- execute([=[Put fnamemodify('test.out', ':.' )]=])
- execute([=[Put fnamemodify('../testdir/a', ':.' )]=])
- execute([=[Put fnamemodify('test.out', ':~' )]=])
- execute([=[Put fnamemodify('../testdir/a', ':~' )]=])
- execute([=[Put fnamemodify('../testdir/a', ':t' )]=])
- execute([=[Put fnamemodify('.', ':p:t' )]=])
- execute([=[Put fnamemodify('test.out', ':p:t' )]=])
- execute([=[Put fnamemodify('test.out', ':p:e' )]=])
- execute([=[Put fnamemodify('test.out', ':p:t:e' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r:r' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':r:r:r' )]=])
- execute([=[Put substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '')]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:e' )]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')]=])
- execute([=[Put fnamemodify('abc.fb2.tar.gz', ':e:e:r' )]=])
- execute([=[Put fnamemodify('abc def', ':S' )]=])
- execute([=[Put fnamemodify('abc" "def', ':S' )]=])
- execute([=[Put fnamemodify('abc"%"def', ':S' )]=])
- execute([=[Put fnamemodify('abc'' ''def', ':S' )]=])
- execute([=[Put fnamemodify('abc''%''def', ':S' )]=])
- execute([=[Put fnamemodify("abc\ndef", ':S' )]=])
- execute([=[set shell=tcsh]=])
- execute([=[Put fnamemodify("abc\ndef", ':S' )]=])
- execute([=[1 delete _]=])
-
- -- Assert buffer contents.
- expect([=[
- fnamemodify('.', ':p' )[-1:] '/'
- fnamemodify('.', ':p:h' )[-1:] 'p'
- fnamemodify('test.out', ':p' )[-1:] 't'
- fnamemodify('test.out', ':.' ) 'test.out'
- fnamemodify('../testdir/a', ':.' ) '../testdir/a'
- fnamemodify('test.out', ':~' ) 'test.out'
- fnamemodify('../testdir/a', ':~' ) '../testdir/a'
- fnamemodify('../testdir/a', ':t' ) 'a'
- fnamemodify('.', ':p:t' ) ''
- fnamemodify('test.out', ':p:t' ) 'test.out'
- fnamemodify('test.out', ':p:e' ) 'out'
- fnamemodify('test.out', ':p:t:e' ) 'out'
- fnamemodify('abc.fb2.tar.gz', ':r' ) 'abc.fb2.tar'
- fnamemodify('abc.fb2.tar.gz', ':r:r' ) 'abc.fb2'
- fnamemodify('abc.fb2.tar.gz', ':r:r:r' ) 'abc'
- substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', '') ']=] .. tmpdir .. [=[/abc.fb2'
- fnamemodify('abc.fb2.tar.gz', ':e' ) 'gz'
- fnamemodify('abc.fb2.tar.gz', ':e:e' ) 'tar.gz'
- fnamemodify('abc.fb2.tar.gz', ':e:e:e' ) 'fb2.tar.gz'
- fnamemodify('abc.fb2.tar.gz', ':e:e:e:e') 'fb2.tar.gz'
- fnamemodify('abc.fb2.tar.gz', ':e:e:r' ) 'tar'
- fnamemodify('abc def', ':S' ) '''abc def'''
- fnamemodify('abc" "def', ':S' ) '''abc" "def'''
- fnamemodify('abc"%"def', ':S' ) '''abc"%"def'''
- fnamemodify('abc'' ''def', ':S' ) '''abc''\'''' ''\''''def'''
- fnamemodify('abc''%''def', ':S' ) '''abc''\''''%''\''''def'''
- fnamemodify("abc\ndef", ':S' ) '''abc^@def'''
- fnamemodify("abc\ndef", ':S' ) '''abc\^@def''']=])
- end)
-end)
diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua
index e0a4e10746..d1ed96cc2e 100644
--- a/test/functional/legacy/eval_spec.lua
+++ b/test/functional/legacy/eval_spec.lua
@@ -693,4 +693,22 @@ describe('eval', function()
start:
6]])
end)
+
+ it('substring and variable name', function()
+ execute("let str = 'abcdef'")
+ execute('let n = 3')
+ eq('def', eval('str[n:]'))
+ eq('abcd', eval('str[:n]'))
+ eq('d', eval('str[n:n]'))
+ execute('unlet n')
+ execute('let nn = 3')
+ eq('def', eval('str[nn:]'))
+ eq('abcd', eval('str[:nn]'))
+ eq('d', eval('str[nn:nn]'))
+ execute('unlet nn')
+ execute('let b:nn = 4')
+ eq('ef', eval('str[b:nn:]'))
+ eq('abcde', eval('str[:b:nn]'))
+ eq('e', eval('str[b:nn:b:nn]'))
+ end)
end)
diff --git a/test/functional/legacy/fnamemodify_spec.lua b/test/functional/legacy/fnamemodify_spec.lua
new file mode 100644
index 0000000000..2a32aea127
--- /dev/null
+++ b/test/functional/legacy/fnamemodify_spec.lua
@@ -0,0 +1,75 @@
+-- Test filename modifiers.
+
+local helpers = require('test.functional.helpers')
+local clear, source = helpers.clear, helpers.source
+local call, eq, nvim = helpers.call, helpers.eq, helpers.meths
+
+local function expected_empty()
+ eq({}, nvim.get_vvar('errors'))
+end
+
+describe('filename modifiers', function()
+ before_each(function()
+ clear()
+
+ source([=[
+ func Test_fnamemodify()
+ let tmpdir = resolve('/tmp')
+ execute 'cd '. tmpdir
+ set shell=sh
+ set shellslash
+ let $HOME=fnamemodify('.', ':p:h:h:h')
+ call assert_equal('/', fnamemodify('.', ':p')[-1:])
+ call assert_equal('p', fnamemodify('.', ':p:h')[-1:])
+ call assert_equal('t', fnamemodify('test.out', ':p')[-1:])
+ call assert_equal('test.out', fnamemodify('test.out', ':.'))
+ call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':.'))
+ call assert_equal('test.out', fnamemodify('test.out', ':~'))
+ call assert_equal('../testdir/a', fnamemodify('../testdir/a', ':~'))
+ call assert_equal('a', fnamemodify('../testdir/a', ':t'))
+ call assert_equal('', fnamemodify('.', ':p:t'))
+ call assert_equal('test.out', fnamemodify('test.out', ':p:t'))
+ call assert_equal('out', fnamemodify('test.out', ':p:e'))
+ call assert_equal('out', fnamemodify('test.out', ':p:t:e'))
+ call assert_equal('abc.fb2.tar', fnamemodify('abc.fb2.tar.gz', ':r'))
+ call assert_equal('abc.fb2', fnamemodify('abc.fb2.tar.gz', ':r:r'))
+ call assert_equal('abc', fnamemodify('abc.fb2.tar.gz', ':r:r:r'))
+ call assert_equal(tmpdir .'/abc.fb2', substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(nvim/testdir/.*\)', '\1', ''))
+ call assert_equal('gz', fnamemodify('abc.fb2.tar.gz', ':e'))
+ call assert_equal('tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e'))
+ call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e'))
+ call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e:e'))
+ call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r'))
+ call assert_equal('''abc def''', fnamemodify('abc def', ':S'))
+ call assert_equal('''abc" "def''', fnamemodify('abc" "def', ':S'))
+ call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S'))
+ call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S'))
+ call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S'))
+ new foo.txt
+ call assert_equal(expand('%:r:S'), shellescape(expand('%:r')))
+ call assert_equal('foo,''foo'',foo.txt', join([expand('%:r'), expand('%:r:S'), expand('%')], ','))
+ quit
+
+ call assert_equal("'abc\ndef'", fnamemodify("abc\ndef", ':S'))
+ set shell=tcsh
+ call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S'))
+ endfunc
+
+ func Test_expand()
+ new
+ call assert_equal("", expand('%:S'))
+ quit
+ endfunc
+ ]=])
+ end)
+
+ it('is working', function()
+ call('Test_fnamemodify')
+ expected_empty()
+ end)
+
+ it('works for :S in an unnamed buffer', function()
+ call('Test_expand')
+ expected_empty()
+ end)
+end)
diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua
index 4100a30452..a3f617eeb0 100644
--- a/test/functional/plugin/shada_spec.lua
+++ b/test/functional/plugin/shada_spec.lua
@@ -2215,7 +2215,7 @@ describe('In plugin/shada.vim', function()
describe('event BufWriteCmd', function()
it('works', function()
nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_line_slice', 0, 0, true, true, {
+ curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value',
' + n name \'A\'',
@@ -2271,7 +2271,7 @@ describe('In plugin/shada.vim', function()
describe('event FileWriteCmd', function()
it('works', function()
nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_line_slice', 0, 0, true, true, {
+ curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value',
' + n name \'A\'',
@@ -2310,7 +2310,7 @@ describe('In plugin/shada.vim', function()
describe('event FileAppendCmd', function()
it('works', function()
nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_line_slice', 0, 0, true, true, {
+ curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value',
' + n name \'A\'',
@@ -2512,7 +2512,7 @@ describe('syntax/shada.vim', function()
it('works', function()
nvim_command('syntax on')
nvim_command('setlocal syntax=shada')
- curbuf('set_line_slice', 0, 0, true, true, {
+ curbuf('set_lines', 0, 1, true, {
'Header with timestamp ' .. epoch .. ':',
' % Key Value',
' + t "test"',
diff --git a/test/functional/terminal/edit_spec.lua b/test/functional/terminal/edit_spec.lua
index 6da1521121..dcc4a54610 100644
--- a/test/functional/terminal/edit_spec.lua
+++ b/test/functional/terminal/edit_spec.lua
@@ -70,6 +70,6 @@ describe(':edit term://*', function()
end
exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
scr:expect(exp_screen)
- eq(bufcontents, curbufmeths.get_line_slice(1, -1, true, true))
+ eq(bufcontents, curbufmeths.get_lines(1, -1, true))
end)
end)
diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua
index 20eee24524..01b2bad059 100644
--- a/test/functional/viml/completion_spec.lua
+++ b/test/functional/viml/completion_spec.lua
@@ -100,6 +100,18 @@ describe('completion', function()
feed('o<C-r>=TestComplete()<CR><ESC>')
eq('', eval('getline(3)'))
end)
+ it('does not change modified state if noinsert', function()
+ execute('set completeopt+=menuone,noinsert')
+ execute('setlocal nomodified')
+ feed('i<C-r>=TestComplete()<CR><ESC>')
+ eq(0, eval('&l:modified'))
+ end)
+ it('does not change modified state if noselect', function()
+ execute('set completeopt+=menuone,noselect')
+ execute('setlocal nomodified')
+ feed('i<C-r>=TestComplete()<CR><ESC>')
+ eq(0, eval('&l:modified'))
+ end)
end)
describe("refresh:always", function()
diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua
index a2e7bd91af..b7f82064d7 100644
--- a/test/unit/buffer_spec.lua
+++ b/test/unit/buffer_spec.lua
@@ -41,13 +41,13 @@ describe('buffer functions', function()
describe('buf_valid', function()
it('should view NULL as an invalid buffer', function()
- eq(0, buffer.buf_valid(NULL))
+ eq(false, buffer.buf_valid(NULL))
end)
it('should view an open buffer as valid', function()
local buf = buflist_new(path1, buffer.BLN_LISTED)
- eq(1, buffer.buf_valid(buf))
+ eq(true, buffer.buf_valid(buf))
end)
it('should view a closed and hidden buffer as valid', function()
@@ -55,7 +55,7 @@ describe('buffer functions', function()
close_buffer(NULL, buf, 0, 0)
- eq(1, buffer.buf_valid(buf))
+ eq(true, buffer.buf_valid(buf))
end)
it('should view a closed and unloaded buffer as valid', function()
@@ -63,7 +63,7 @@ describe('buffer functions', function()
close_buffer(NULL, buf, buffer.DOBUF_UNLOAD, 0)
- eq(1, buffer.buf_valid(buf))
+ eq(true, buffer.buf_valid(buf))
end)
it('should view a closed and wiped buffer as invalid', function()
@@ -71,7 +71,7 @@ describe('buffer functions', function()
close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0)
- eq(0, buffer.buf_valid(buf))
+ eq(false, buffer.buf_valid(buf))
end)
end)