aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/os_dos.txt279
-rw-r--r--src/nvim/api/buffer.c150
-rw-r--r--src/nvim/eval.c8
-rw-r--r--src/nvim/terminal.c4
-rw-r--r--src/nvim/version.c5
-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/fnamemodify_spec.lua75
-rw-r--r--test/functional/plugin/shada_spec.lua8
-rw-r--r--test/functional/terminal/edit_spec.lua2
13 files changed, 370 insertions, 401 deletions
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/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/eval.c b/src/nvim/eval.c
index f71620a7b4..3c67625d1c 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -21993,7 +21993,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/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..275cb2063a 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
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/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)