aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/CMakeLists.txt48
-rw-r--r--src/nvim/api/buffer.c180
-rw-r--r--src/nvim/api/dispatch_deprecated.lua69
-rw-r--r--src/nvim/api/private/defs.h7
-rw-r--r--src/nvim/api/private/dispatch.h23
-rw-r--r--src/nvim/api/private/handle.c16
-rw-r--r--src/nvim/api/private/handle.h3
-rw-r--r--src/nvim/api/private/helpers.c73
-rw-r--r--src/nvim/api/tabpage.c59
-rw-r--r--src/nvim/api/ui.c105
-rw-r--r--src/nvim/api/vim.c136
-rw-r--r--src/nvim/api/window.c73
-rw-r--r--src/nvim/buffer.c22
-rw-r--r--src/nvim/buffer_defs.h48
-rw-r--r--src/nvim/charset.c8
-rw-r--r--src/nvim/cursor.c1
-rw-r--r--src/nvim/cursor.h1
-rw-r--r--src/nvim/cursor_shape.c1
-rw-r--r--src/nvim/diff.c1
-rw-r--r--src/nvim/digraph.c1
-rw-r--r--src/nvim/edit.c9
-rw-r--r--src/nvim/eval.c1275
-rw-r--r--src/nvim/eval.lua331
-rw-r--r--src/nvim/event/process.c3
-rw-r--r--src/nvim/ex_cmds.c23
-rw-r--r--src/nvim/ex_cmds2.c4
-rw-r--r--src/nvim/ex_cmds_defs.h83
-rw-r--r--src/nvim/ex_docmd.c175
-rw-r--r--src/nvim/ex_eval.c1
-rw-r--r--src/nvim/ex_getln.c1
-rw-r--r--src/nvim/farsi.c1
-rw-r--r--src/nvim/file_search.c113
-rw-r--r--src/nvim/fileio.c127
-rw-r--r--src/nvim/fileio.h2
-rw-r--r--src/nvim/fold.c9
-rw-r--r--src/nvim/func_attr.h1
-rw-r--r--src/nvim/garray.c1
-rw-r--r--src/nvim/getchar.c2
-rw-r--r--src/nvim/hardcopy.c1
-rw-r--r--src/nvim/hashtab.c1
-rw-r--r--src/nvim/iconv.h2
-rw-r--r--src/nvim/if_cscope.c1
-rw-r--r--src/nvim/indent.c1
-rw-r--r--src/nvim/indent_c.c1
-rw-r--r--src/nvim/main.c3
-rw-r--r--src/nvim/map.c7
-rw-r--r--src/nvim/map.h3
-rw-r--r--src/nvim/mark.c1
-rw-r--r--src/nvim/mbyte.c1
-rw-r--r--src/nvim/memfile.c1
-rw-r--r--src/nvim/memline.c95
-rw-r--r--src/nvim/memory.c10
-rw-r--r--src/nvim/memory.h1
-rw-r--r--src/nvim/menu.c2
-rw-r--r--src/nvim/message.c1
-rw-r--r--src/nvim/misc1.c68
-rw-r--r--src/nvim/misc2.c486
-rw-r--r--src/nvim/misc2.h12
-rw-r--r--src/nvim/mouse.c1
-rw-r--r--src/nvim/move.c1
-rw-r--r--src/nvim/msgpack_rpc/channel.c3
-rw-r--r--src/nvim/msgpack_rpc/defs.h28
-rw-r--r--src/nvim/msgpack_rpc/helpers.c6
-rw-r--r--src/nvim/normal.c30
-rw-r--r--src/nvim/ops.c29
-rw-r--r--src/nvim/option.c151
-rw-r--r--src/nvim/option.h2
-rw-r--r--src/nvim/os/env.c1
-rw-r--r--src/nvim/os/fs.c1
-rw-r--r--src/nvim/os/input.c2
-rw-r--r--src/nvim/os/shell.c43
-rw-r--r--src/nvim/os/signal.c14
-rw-r--r--src/nvim/os/users.c1
-rw-r--r--src/nvim/os_unix.c1
-rw-r--r--src/nvim/path.c1
-rw-r--r--src/nvim/popupmnu.c110
-rw-r--r--src/nvim/quickfix.c25
-rw-r--r--src/nvim/regexp.c1
-rw-r--r--src/nvim/regexp_nfa.c7
-rw-r--r--src/nvim/screen.c35
-rw-r--r--src/nvim/search.c1
-rw-r--r--src/nvim/shada.c3
-rw-r--r--src/nvim/spell.c1
-rw-r--r--src/nvim/state.c34
-rw-r--r--src/nvim/strings.c1
-rw-r--r--src/nvim/syntax.c35
-rw-r--r--src/nvim/tag.c1
-rw-r--r--src/nvim/terminal.c13
-rw-r--r--src/nvim/testdir/Makefile1
-rw-r--r--src/nvim/testdir/test_alot.vim2
-rw-r--r--src/nvim/testdir/test_feedkeys.vim10
-rw-r--r--src/nvim/testdir/test_help_tagjump.vim10
-rw-r--r--src/nvim/testdir/test_syn_attr.vim24
-rw-r--r--src/nvim/testdir/test_usercommands.vim48
-rw-r--r--src/nvim/testdir/test_window_id.vim8
-rw-r--r--src/nvim/tui/input.c5
-rw-r--r--src/nvim/tui/tui.c8
-rw-r--r--src/nvim/types.h1
-rw-r--r--src/nvim/ui.c17
-rw-r--r--src/nvim/ui.h5
-rw-r--r--src/nvim/ui_bridge.c1
-rw-r--r--src/nvim/undo.c1
-rw-r--r--src/nvim/version.c19
-rw-r--r--src/nvim/window.c44
104 files changed, 2534 insertions, 1986 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 5c4df1be0b..7c2c2feebc 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -11,22 +11,28 @@ endif()
endif()
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)
-set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)
+set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendispatch.lua)
file(GLOB API_HEADERS api/*.h)
file(GLOB MSGPACK_RPC_HEADERS msgpack_rpc/*.h)
-set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
+set(API_METADATA ${PROJECT_BINARY_DIR}/api_metadata.mpack)
+set(FUNCS_DATA ${PROJECT_BINARY_DIR}/funcs_data.mpack)
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include)
+set(GENERATED_API_DISPATCH ${GENERATED_DIR}/api/private/dispatch.c)
set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h)
set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h)
+set(GENERATED_FUNCS_HASH_INPUT ${GENERATED_DIR}/funcs.generated.h.gperf)
+set(GENERATED_FUNCS ${GENERATED_DIR}/funcs.generated.h)
set(GENERATED_EVENTS_ENUM ${GENERATED_INCLUDES_DIR}/auevents_enum.generated.h)
set(GENERATED_EVENTS_NAMES_MAP ${GENERATED_DIR}/auevents_name_map.generated.h)
set(GENERATED_OPTIONS ${GENERATED_DIR}/options.generated.h)
set(EX_CMDS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genex_cmds.lua)
+set(FUNCS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/geneval.lua)
set(EVENTS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gen_events.lua)
set(OPTIONS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genoptions.lua)
set(EVENTS_LIST_FILE ${PROJECT_SOURCE_DIR}/src/nvim/auevents.lua)
set(EX_CMDS_DEFS_FILE ${PROJECT_SOURCE_DIR}/src/nvim/ex_cmds.lua)
+set(EVAL_DEFS_FILE ${PROJECT_SOURCE_DIR}/src/nvim/eval.lua)
set(OPTIONS_LIST_FILE ${PROJECT_SOURCE_DIR}/src/nvim/options.lua)
set(UNICODE_TABLES_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genunicodetables.lua)
set(UNICODE_DIR ${PROJECT_SOURCE_DIR}/unicode)
@@ -36,6 +42,7 @@ set(EASTASIANWIDTH_FILE ${UNICODE_DIR}/EastAsianWidth.txt)
set(GENERATED_UNICODE_TABLES ${GENERATED_DIR}/unicode_tables.generated.h)
include_directories(${GENERATED_DIR})
+include_directories(${CACHED_GENERATED_DIR})
include_directories(${GENERATED_INCLUDES_DIR})
file(MAKE_DIRECTORY ${GENERATED_DIR})
@@ -82,7 +89,7 @@ endforeach()
list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove})
-# Handle legacy files that don't yet pass -Wconversion.
+# Legacy files that do not yet pass -Wconversion.
set(CONV_SOURCES
buffer.c
diff.c
@@ -112,6 +119,15 @@ endforeach()
if(NOT MSVC)
set_source_files_properties(
${CONV_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion")
+ # gperf generates ANSI-C with incorrect linkage, ignore it.
+ check_c_compiler_flag(-Wno-static-in-inline HAS_WNO_STATIC_IN_INLINE_FLAG)
+ if(HAS_WNO_STATIC_IN_INLINE_FLAG)
+ set_source_files_properties(
+ eval.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-static-in-inline -Wno-conversion")
+ else()
+ set_source_files_properties(
+ eval.c PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion")
+ endif()
endif()
if(DEFINED MIN_LOG_LEVEL)
@@ -138,9 +154,13 @@ separate_arguments(C_FLAGS_${build_type}_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS_${bu
set(gen_cflags ${gen_cflags} ${C_FLAGS_${build_type}_ARRAY} ${C_FLAGS_ARRAY})
foreach(sfile ${NEOVIM_SOURCES}
- "${PROJECT_SOURCE_DIR}/src/nvim/regexp_nfa.c")
+ "${PROJECT_SOURCE_DIR}/src/nvim/regexp_nfa.c"
+ ${GENERATED_API_DISPATCH})
get_filename_component(full_d ${sfile} PATH)
file(RELATIVE_PATH d "${PROJECT_SOURCE_DIR}/src/nvim" "${full_d}")
+ if(${d} MATCHES "^[.][.]")
+ file(RELATIVE_PATH d "${GENERATED_DIR}" "${full_d}")
+ endif()
get_filename_component(f ${sfile} NAME)
get_filename_component(r ${sfile} NAME_WE)
if(NOT ${d} EQUAL ".")
@@ -183,17 +203,18 @@ add_custom_command(OUTPUT ${GENERATED_UNICODE_TABLES}
${EASTASIANWIDTH_FILE}
)
-add_custom_command(OUTPUT ${MSGPACK_DISPATCH}
- COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${MSGPACK_DISPATCH}
+add_custom_command(OUTPUT ${GENERATED_API_DISPATCH} ${API_METADATA}
+ COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${CMAKE_CURRENT_LIST_DIR} ${API_HEADERS} ${GENERATED_API_DISPATCH} ${API_METADATA}
DEPENDS
${API_HEADERS}
${MSGPACK_RPC_HEADERS}
${DISPATCH_GENERATOR}
+ ${CMAKE_CURRENT_LIST_DIR}/api/dispatch_deprecated.lua
)
list(APPEND NEOVIM_GENERATED_SOURCES
"${PROJECT_BINARY_DIR}/config/auto/pathdef.c"
- "${MSGPACK_DISPATCH}"
+ "${GENERATED_API_DISPATCH}"
"${GENERATED_EX_CMDS_ENUM}"
"${GENERATED_EX_CMDS_DEFS}"
"${GENERATED_EVENTS_ENUM}"
@@ -208,6 +229,19 @@ add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
DEPENDS ${EX_CMDS_GENERATOR} ${EX_CMDS_DEFS_FILE}
)
+if(NOT GPERF_PRG)
+ message(FATAL_ERROR "gperf was not found.")
+endif()
+add_custom_command(OUTPUT ${GENERATED_FUNCS} ${FUNCS_DATA}
+ COMMAND ${LUA_PRG} ${FUNCS_GENERATOR}
+ ${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_DIR} ${API_METADATA} ${FUNCS_DATA}
+ COMMAND ${GPERF_PRG}
+ ${GENERATED_FUNCS_HASH_INPUT} --output-file=${GENERATED_FUNCS}
+ DEPENDS ${FUNCS_GENERATOR} ${EVAL_DEFS_FILE} ${API_METADATA}
+)
+list(APPEND NEOVIM_GENERATED_SOURCES
+ "${GENERATED_FUNCS}")
+
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
COMMAND ${LUA_PRG} ${EVENTS_GENERATOR}
${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index c3bc1f52af..c4415ddf94 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -14,7 +14,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/ex_cmds.h"
#include "nvim/mark.h"
#include "nvim/fileio.h"
@@ -32,7 +31,7 @@
/// @param buffer The buffer handle
/// @param[out] err Details of an error that may have occurred
/// @return The line count
-Integer buffer_line_count(Buffer buffer, Error *err)
+Integer nvim_buf_line_count(Buffer buffer, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -45,11 +44,11 @@ Integer buffer_line_count(Buffer buffer, Error *err)
/// Gets a buffer line
///
-/// @deprecated use buffer_get_lines instead.
+/// @deprecated use nvim_buf_get_lines instead.
/// for positive indices (including 0) use
-/// "buffer_get_lines(buffer, index, index+1, true)"
+/// "nvim_buf_get_lines(buffer, index, index+1, true)"
/// for negative indices use
-/// "buffer_get_lines(buffer, index-1, index, true)"
+/// "nvim_buf_get_lines(buffer, index-1, index, true)"
///
/// @param buffer The buffer handle
/// @param index The line index
@@ -60,7 +59,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
String rv = { .size = 0 };
index = convert_index(index);
- Array slice = buffer_get_lines(buffer, index, index+1, true, err);
+ Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
if (!err->set && slice.size) {
rv = slice.items[0].data.string;
@@ -73,11 +72,11 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// Sets a buffer line
///
-/// @deprecated use buffer_set_lines instead.
+/// @deprecated use nvim_buf_set_lines instead.
/// for positive indices use
-/// "buffer_set_lines(buffer, index, index+1, true, [line])"
+/// "nvim_buf_set_lines(buffer, index, index+1, true, [line])"
/// for negative indices use
-/// "buffer_set_lines(buffer, index-1, index, true, [line])"
+/// "nvim_buf_set_lines(buffer, index-1, index, true, [line])"
///
/// @param buffer The buffer handle
/// @param index The line index
@@ -88,16 +87,16 @@ void buffer_set_line(Buffer buffer, Integer index, String line, Error *err)
Object l = STRING_OBJ(line);
Array array = { .items = &l, .size = 1 };
index = convert_index(index);
- buffer_set_lines(buffer, index, index+1, true, array, err);
+ nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
}
/// Deletes a buffer line
///
-/// @deprecated use buffer_set_lines instead.
+/// @deprecated use nvim_buf_set_lines instead.
/// for positive indices use
-/// "buffer_set_lines(buffer, index, index+1, true, [])"
+/// "nvim_buf_set_lines(buffer, index, index+1, true, [])"
/// for negative indices use
-/// "buffer_set_lines(buffer, index-1, index, true, [])"
+/// "nvim_buf_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
@@ -105,12 +104,12 @@ void buffer_del_line(Buffer buffer, Integer index, Error *err)
{
Array array = ARRAY_DICT_INIT;
index = convert_index(index);
- buffer_set_lines(buffer, index, index+1, true, array, err);
+ nvim_buf_set_lines(0, buffer, index, index+1, true, array, err);
}
/// Retrieves a line range from the buffer
///
-/// @deprecated use buffer_get_lines(buffer, newstart, newend, false)
+/// @deprecated use nvim_buf_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
@@ -122,15 +121,15 @@ void buffer_del_line(Buffer buffer, Integer index, Error *err)
/// @param[out] err Details of an error that may have occurred
/// @return An array of lines
ArrayOf(String) buffer_get_line_slice(Buffer buffer,
- Integer start,
- Integer end,
- Boolean include_start,
- Boolean include_end,
- Error *err)
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ 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);
+ return nvim_buf_get_lines(0, buffer, start , end, false, err);
}
@@ -149,11 +148,12 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer,
/// @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)
+ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
+ 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);
@@ -191,7 +191,9 @@ ArrayOf(String) buffer_get_lines(Buffer buffer,
Object str = STRING_OBJ(cstr_to_string(bufstr));
// Vim represents NULs as NLs, but this may confuse clients.
- strchrsub(str.data.string.data, '\n', '\0');
+ if (channel_id != INVALID_CHANNEL) {
+ strchrsub(str.data.string.data, '\n', '\0');
+ }
rv.items[i] = str;
}
@@ -212,7 +214,7 @@ end:
/// Replaces a line range on the buffer
///
-/// @deprecated use buffer_set_lines(buffer, newstart, newend, false, lines)
+/// @deprecated use nvim_buf_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
@@ -226,16 +228,16 @@ end:
// array will simply delete the line range)
/// @param[out] err Details of an error that may have occurred
void buffer_set_line_slice(Buffer buffer,
- Integer start,
- Integer end,
- Boolean include_start,
- Boolean include_end,
- ArrayOf(String) replacement,
- Error *err)
+ Integer start,
+ Integer end,
+ Boolean include_start,
+ Boolean include_end,
+ ArrayOf(String) replacement, // NOLINT
+ Error *err)
{
start = convert_index(start) + !include_start;
end = convert_index(end) + include_end;
- buffer_set_lines(buffer, start, end, false, replacement, err);
+ nvim_buf_set_lines(0, buffer, start, end, false, replacement, err);
}
@@ -257,12 +259,13 @@ void buffer_set_line_slice(Buffer buffer,
/// @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)
+void nvim_buf_set_lines(uint64_t channel_id,
+ Buffer buffer,
+ Integer start,
+ Integer end,
+ Boolean strict_indexing,
+ ArrayOf(String) replacement, // NOLINT
+ Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -309,7 +312,7 @@ void buffer_set_lines(Buffer buffer,
// line and convert NULs to newlines to avoid truncation.
lines[i] = xmallocz(l.size);
for (size_t j = 0; j < l.size; j++) {
- if (l.data[j] == '\n') {
+ if (l.data[j] == '\n' && channel_id != INVALID_CHANNEL) {
api_set_error(err, Exception, _("string cannot contain newlines"));
new_len = i + 1;
goto end;
@@ -412,7 +415,7 @@ end:
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
/// @return The variable value
-Object buffer_get_var(Buffer buffer, String name, Error *err)
+Object nvim_buf_get_var(Buffer buffer, String name, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -429,6 +432,41 @@ Object buffer_get_var(Buffer buffer, String name, Error *err)
/// @param name The variable name
/// @param value The variable value
/// @param[out] err Details of an error that may have occurred
+void nvim_buf_set_var(Buffer buffer, String name, Object value, Error *err)
+{
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+
+ if (!buf) {
+ return;
+ }
+
+ dict_set_value(buf->b_vars, name, value, false, false, err);
+}
+
+/// Removes a buffer-scoped (b:) variable
+///
+/// @param buffer The buffer handle
+/// @param name The variable name
+/// @param[out] err Details of an error that may have occurred
+void nvim_buf_del_var(Buffer buffer, String name, Error *err)
+{
+ buf_T *buf = find_buffer_by_handle(buffer, err);
+
+ if (!buf) {
+ return;
+ }
+
+ dict_set_value(buf->b_vars, name, NIL, true, false, err);
+}
+
+/// Sets a buffer-scoped (b:) variable
+///
+/// @deprecated
+///
+/// @param buffer The buffer handle
+/// @param name The variable name
+/// @param value The variable value
+/// @param[out] err Details of an error that may have occurred
/// @return The old value or nil if there was no previous value.
///
/// @warning It may return nil if there was no previous value
@@ -441,18 +479,17 @@ Object buffer_set_var(Buffer buffer, String name, Object value, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(buf->b_vars, name, value, false, err);
+ return dict_set_value(buf->b_vars, name, value, false, true, err);
}
/// Removes a buffer-scoped (b:) variable
///
+/// @deprecated
+///
/// @param buffer The buffer handle
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
-/// @return The old value or nil if there was no previous value.
-///
-/// @warning It may return nil if there was no previous value
-/// or if previous value was `v:null`.
+/// @return The old value
Object buffer_del_var(Buffer buffer, String name, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -461,16 +498,17 @@ Object buffer_del_var(Buffer buffer, String name, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(buf->b_vars, name, NIL, true, err);
+ return dict_set_value(buf->b_vars, name, NIL, true, true, err);
}
+
/// Gets a buffer option value
///
/// @param buffer The buffer handle
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
/// @return The option value
-Object buffer_get_option(Buffer buffer, String name, Error *err)
+Object nvim_buf_get_option(Buffer buffer, String name, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -488,7 +526,7 @@ Object buffer_get_option(Buffer buffer, String name, Error *err)
/// @param name The option name
/// @param value The option value
/// @param[out] err Details of an error that may have occurred
-void buffer_set_option(Buffer buffer, String name, Object value, Error *err)
+void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -504,7 +542,7 @@ void buffer_set_option(Buffer buffer, String name, Object value, Error *err)
/// @param buffer The buffer handle
/// @param[out] err Details of an error that may have occurred
/// @return The buffer number
-Integer buffer_get_number(Buffer buffer, Error *err)
+Integer nvim_buf_get_number(Buffer buffer, Error *err)
{
Integer rv = 0;
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -521,7 +559,7 @@ Integer buffer_get_number(Buffer buffer, Error *err)
/// @param buffer The buffer handle
/// @param[out] err Details of an error that may have occurred
/// @return The buffer name
-String buffer_get_name(Buffer buffer, Error *err)
+String nvim_buf_get_name(Buffer buffer, Error *err)
{
String rv = STRING_INIT;
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -538,7 +576,7 @@ String buffer_get_name(Buffer buffer, Error *err)
/// @param buffer The buffer handle
/// @param name The buffer name
/// @param[out] err Details of an error that may have occurred
-void buffer_set_name(Buffer buffer, String name, Error *err)
+void nvim_buf_set_name(Buffer buffer, String name, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -567,7 +605,7 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
///
/// @param buffer The buffer handle
/// @return true if the buffer is valid, false otherwise
-Boolean buffer_is_valid(Buffer buffer)
+Boolean nvim_buf_is_valid(Buffer buffer)
{
Error stub = ERROR_INIT;
return find_buffer_by_handle(buffer, &stub) != NULL;
@@ -575,7 +613,7 @@ 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)
+/// @deprecated use nvim_buf_set_lines(buffer, lnum, lnum, true, lines)
///
/// @param buffer The buffer handle
/// @param lnum Insert the lines after `lnum`. If negative, it will append
@@ -589,7 +627,7 @@ void buffer_insert(Buffer buffer,
{
// "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);
+ nvim_buf_set_lines(0, buffer, lnum, lnum, true, lines, err);
}
/// Return a tuple (row,col) representing the position of the named mark
@@ -598,7 +636,7 @@ void buffer_insert(Buffer buffer,
/// @param name The mark's name
/// @param[out] err Details of an error that may have occurred
/// @return The (row, col) tuple
-ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err)
+ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
{
Array rv = ARRAY_DICT_INIT;
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -648,7 +686,7 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err)
/// called with src_id = 0, an unique source id is generated and returned.
/// Succesive calls can pass in it as "src_id" to add new highlights to the same
/// source group. All highlights in the same group can then be cleared with
-/// buffer_clear_highlight. If the highlight never will be manually deleted
+/// nvim_buf_clear_highlight. If the highlight never will be manually deleted
/// pass in -1 for "src_id".
///
/// If "hl_group" is the empty string no highlight is added, but a new src_id
@@ -666,13 +704,13 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err)
/// or -1 to highlight to end of line
/// @param[out] err Details of an error that may have occurred
/// @return The src_id that was used
-Integer buffer_add_highlight(Buffer buffer,
- Integer src_id,
- String hl_group,
- Integer line,
- Integer col_start,
- Integer col_end,
- Error *err)
+Integer nvim_buf_add_highlight(Buffer buffer,
+ Integer src_id,
+ String hl_group,
+ Integer line,
+ Integer col_start,
+ Integer col_end,
+ Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
@@ -708,11 +746,11 @@ Integer buffer_add_highlight(Buffer buffer,
/// @param line_end End of range of lines to clear (exclusive)
/// or -1 to clear to end of file.
/// @param[out] err Details of an error that may have occurred
-void buffer_clear_highlight(Buffer buffer,
- Integer src_id,
- Integer line_start,
- Integer line_end,
- Error *err)
+void nvim_buf_clear_highlight(Buffer buffer,
+ Integer src_id,
+ Integer line_start,
+ Integer line_end,
+ Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
diff --git a/src/nvim/api/dispatch_deprecated.lua b/src/nvim/api/dispatch_deprecated.lua
new file mode 100644
index 0000000000..5650a77ac0
--- /dev/null
+++ b/src/nvim/api/dispatch_deprecated.lua
@@ -0,0 +1,69 @@
+local deprecated_aliases = {
+ nvim_buf_add_highlight="buffer_add_highlight",
+ nvim_buf_clear_highlight="buffer_clear_highlight",
+ nvim_buf_get_lines="buffer_get_lines",
+ nvim_buf_get_mark="buffer_get_mark",
+ nvim_buf_get_name="buffer_get_name",
+ nvim_buf_get_number="buffer_get_number",
+ nvim_buf_get_option="buffer_get_option",
+ nvim_buf_get_var="buffer_get_var",
+ nvim_buf_is_valid="buffer_is_valid",
+ nvim_buf_line_count="buffer_line_count",
+ nvim_buf_set_lines="buffer_set_lines",
+ nvim_buf_set_name="buffer_set_name",
+ nvim_buf_set_option="buffer_set_option",
+ nvim_call_function="vim_call_function",
+ nvim_command="vim_command",
+ nvim_command_output="vim_command_output",
+ nvim_del_current_line="vim_del_current_line",
+ nvim_err_write="vim_err_write",
+ nvim_err_writeln="vim_report_error",
+ nvim_eval="vim_eval",
+ nvim_feedkeys="vim_feedkeys",
+ nvim_get_api_info="vim_get_api_info",
+ nvim_get_color_by_name="vim_name_to_color",
+ nvim_get_color_map="vim_get_color_map",
+ nvim_get_current_buf="vim_get_current_buffer",
+ nvim_get_current_line="vim_get_current_line",
+ nvim_get_current_tabpage="vim_get_current_tabpage",
+ nvim_get_current_win="vim_get_current_window",
+ nvim_get_option="vim_get_option",
+ nvim_get_var="vim_get_var",
+ nvim_get_vvar="vim_get_vvar",
+ nvim_input="vim_input",
+ nvim_list_bufs="vim_get_buffers",
+ nvim_list_runtime_paths="vim_list_runtime_paths",
+ nvim_list_tabpages="vim_get_tabpages",
+ nvim_list_wins="vim_get_windows",
+ nvim_out_write="vim_out_write",
+ nvim_replace_termcodes="vim_replace_termcodes",
+ nvim_set_current_buf="vim_set_current_buffer",
+ nvim_set_current_dir="vim_change_directory",
+ nvim_set_current_line="vim_set_current_line",
+ nvim_set_current_tabpage="vim_set_current_tabpage",
+ nvim_set_current_win="vim_set_current_window",
+ nvim_set_option="vim_set_option",
+ nvim_strwidth="vim_strwidth",
+ nvim_subscribe="vim_subscribe",
+ nvim_tabpage_get_var="tabpage_get_var",
+ nvim_tabpage_get_win="tabpage_get_window",
+ nvim_tabpage_is_valid="tabpage_is_valid",
+ nvim_tabpage_list_wins="tabpage_get_windows",
+ nvim_ui_detach="ui_detach",
+ nvim_ui_try_resize="ui_try_resize",
+ nvim_unsubscribe="vim_unsubscribe",
+ nvim_win_get_buf="window_get_buffer",
+ nvim_win_get_cursor="window_get_cursor",
+ nvim_win_get_height="window_get_height",
+ nvim_win_get_option="window_get_option",
+ nvim_win_get_position="window_get_position",
+ nvim_win_get_tabpage="window_get_tabpage",
+ nvim_win_get_var="window_get_var",
+ nvim_win_get_width="window_get_width",
+ nvim_win_is_valid="window_is_valid",
+ nvim_win_set_cursor="window_set_cursor",
+ nvim_win_set_height="window_set_height",
+ nvim_win_set_option="window_set_option",
+ nvim_win_set_width="window_set_width",
+}
+return deprecated_aliases
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index 5fb95a163f..a6710193ff 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -9,13 +9,15 @@
#define STRING_INIT {.data = NULL, .size = 0}
#define OBJECT_INIT { .type = kObjectTypeNil }
#define ERROR_INIT { .set = false }
-#define REMOTE_TYPE(type) typedef uint64_t type
+#define REMOTE_TYPE(type) typedef handle_T type
#ifdef INCLUDE_GENERATED_DECLARATIONS
# define ArrayOf(...) Array
# define DictionaryOf(...) Dictionary
#endif
+typedef int handle_T;
+
// Basic types
typedef enum {
kErrorTypeException,
@@ -31,6 +33,9 @@ typedef enum {
/// Used as the message ID of notifications.
#define NO_RESPONSE UINT64_MAX
+/// Used as channel_id when the call is local
+#define INVALID_CHANNEL UINT64_MAX
+
typedef struct {
ErrorType type;
char msg[1024];
diff --git a/src/nvim/api/private/dispatch.h b/src/nvim/api/private/dispatch.h
new file mode 100644
index 0000000000..d91456c306
--- /dev/null
+++ b/src/nvim/api/private/dispatch.h
@@ -0,0 +1,23 @@
+#ifndef NVIM_API_PRIVATE_DISPATCH_H
+#define NVIM_API_PRIVATE_DISPATCH_H
+
+#include "nvim/api/private/defs.h"
+
+typedef Object (*ApiDispatchWrapper)(uint64_t channel_id,
+ uint64_t request_id,
+ Array args,
+ Error *error);
+
+/// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores
+/// functions of this type.
+typedef struct {
+ ApiDispatchWrapper fn;
+ bool async; // function is always safe to run immediately instead of being
+ // put in a request queue for handling when nvim waits for input.
+} MsgpackRpcRequestHandler;
+
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "api/private/dispatch.h.generated.h"
+#endif
+
+#endif // NVIM_API_PRIVATE_DISPATCH_H
diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c
index 69df7294ad..acb0fb332a 100644
--- a/src/nvim/api/private/handle.c
+++ b/src/nvim/api/private/handle.c
@@ -5,30 +5,26 @@
#include "nvim/map.h"
#include "nvim/api/private/handle.h"
-#define HANDLE_INIT(name) name##_handles = pmap_new(uint64_t)()
+#define HANDLE_INIT(name) name##_handles = pmap_new(handle_T)()
#define HANDLE_IMPL(type, name) \
- static PMap(uint64_t) *name##_handles = NULL; \
+ static PMap(handle_T) *name##_handles = NULL; /* NOLINT */ \
\
- type *handle_get_##name(uint64_t handle) \
+ type *handle_get_##name(handle_T handle) \
{ \
- return pmap_get(uint64_t)(name##_handles, handle); \
+ return pmap_get(handle_T)(name##_handles, handle); \
} \
\
void handle_register_##name(type *name) \
{ \
- assert(!name->handle); \
- name->handle = next_handle++; \
- pmap_put(uint64_t)(name##_handles, name->handle, name); \
+ pmap_put(handle_T)(name##_handles, name->handle, name); \
} \
\
void handle_unregister_##name(type *name) \
{ \
- pmap_del(uint64_t)(name##_handles, name->handle); \
+ pmap_del(handle_T)(name##_handles, name->handle); \
}
-static uint64_t next_handle = 1;
-
HANDLE_IMPL(buf_T, buffer)
HANDLE_IMPL(win_T, window)
HANDLE_IMPL(tabpage_T, tabpage)
diff --git a/src/nvim/api/private/handle.h b/src/nvim/api/private/handle.h
index 804e266dc3..30bbfbee1b 100644
--- a/src/nvim/api/private/handle.h
+++ b/src/nvim/api/private/handle.h
@@ -3,9 +3,10 @@
#include "nvim/vim.h"
#include "nvim/buffer_defs.h"
+#include "nvim/api/private/defs.h"
#define HANDLE_DECLS(type, name) \
- type *handle_get_##name(uint64_t handle); \
+ type *handle_get_##name(handle_T handle); \
void handle_register_##name(type *name); \
void handle_unregister_##name(type *name);
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index c88bf2127a..fc114bae16 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -104,10 +104,11 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
/// @param value The new value
/// @param del Delete key in place of setting it. Argument `value` is ignored in
/// this case.
+/// @param retval If true the old value will be converted and returned.
/// @param[out] err Details of an error that may have occurred
-/// @return the old value, if any
+/// @return The old value if `retval` is true and the key was present, else NIL
Object dict_set_value(dict_T *dict, String key, Object value, bool del,
- Error *err)
+ bool retval, Error *err)
{
Object rv = OBJECT_INIT;
@@ -135,7 +136,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
// Delete the entry
hashitem_T *hi = hash_find(&dict->dv_hashtab, di->di_key);
hash_remove(&dict->dv_hashtab, hi);
@@ -156,7 +159,9 @@ Object dict_set_value(dict_T *dict, String key, Object value, bool del,
dict_add(dict, di);
} else {
// Return the old value
- rv = vim_to_object(&di->di_tv);
+ if (retval) {
+ rv = vim_to_object(&di->di_tv);
+ }
clear_tv(&di->di_tv);
}
@@ -507,6 +512,10 @@ Object vim_to_object(typval_T *obj)
buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
{
+ if (buffer == 0) {
+ return curbuf;
+ }
+
buf_T *rv = handle_get_buffer(buffer);
if (!rv) {
@@ -518,6 +527,10 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
win_T * find_window_by_handle(Window window, Error *err)
{
+ if (window == 0) {
+ return curwin;
+ }
+
win_T *rv = handle_get_window(window);
if (!rv) {
@@ -529,6 +542,10 @@ win_T * find_window_by_handle(Window window, Error *err)
tabpage_T * find_tab_by_handle(Tabpage tabpage, Error *err)
{
+ if (tabpage == 0) {
+ return curtab;
+ }
+
tabpage_T *rv = handle_get_tabpage(tabpage);
if (!rv) {
@@ -572,10 +589,16 @@ String cstr_as_string(char *str) FUNC_ATTR_PURE
return (String) {.data = str, .size = strlen(str)};
}
+/// Converts from type Object to a VimL value.
+///
+/// @param obj Object to convert from.
+/// @param tv Conversion result is placed here. On failure member v_type is
+/// set to VAR_UNKNOWN (no allocation was made for this variable).
+/// returns true if conversion is successful, otherwise false.
bool object_to_vim(Object obj, typval_T *tv, Error *err)
{
tv->v_type = VAR_UNKNOWN;
- tv->v_lock = 0;
+ tv->v_lock = VAR_UNLOCKED;
switch (obj.type) {
case kObjectTypeNil:
@@ -616,9 +639,8 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
}
break;
- case kObjectTypeArray:
- tv->v_type = VAR_LIST;
- tv->vval.v_list = list_alloc();
+ case kObjectTypeArray: {
+ list_T *list = list_alloc();
for (uint32_t i = 0; i < obj.data.array.size; i++) {
Object item = obj.data.array.items[i];
@@ -627,45 +649,51 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
if (!object_to_vim(item, &li->li_tv, err)) {
// cleanup
listitem_free(li);
- list_free(tv->vval.v_list, true);
+ list_free(list, true);
return false;
}
- list_append(tv->vval.v_list, li);
+ list_append(list, li);
}
- tv->vval.v_list->lv_refcount++;
+ list->lv_refcount++;
+
+ tv->v_type = VAR_LIST;
+ tv->vval.v_list = list;
break;
+ }
- case kObjectTypeDictionary:
- tv->v_type = VAR_DICT;
- tv->vval.v_dict = dict_alloc();
+ case kObjectTypeDictionary: {
+ dict_T *dict = dict_alloc();
for (uint32_t i = 0; i < obj.data.dictionary.size; i++) {
KeyValuePair item = obj.data.dictionary.items[i];
String key = item.key;
if (key.size == 0) {
- api_set_error(err,
- Validation,
+ api_set_error(err, Validation,
_("Empty dictionary keys aren't allowed"));
// cleanup
- dict_free(tv->vval.v_dict, true);
+ dict_free(dict, true);
return false;
}
- dictitem_T *di = dictitem_alloc((uint8_t *) key.data);
+ dictitem_T *di = dictitem_alloc((uint8_t *)key.data);
if (!object_to_vim(item.value, &di->di_tv, err)) {
// cleanup
dictitem_free(di);
- dict_free(tv->vval.v_dict, true);
+ dict_free(dict, true);
return false;
}
- dict_add(tv->vval.v_dict, di);
+ dict_add(dict, di);
}
- tv->vval.v_dict->dv_refcount++;
+ dict->dv_refcount++;
+
+ tv->v_type = VAR_DICT;
+ tv->vval.v_dict = dict;
break;
+ }
default:
abort();
}
@@ -764,12 +792,15 @@ static void init_type_metadata(Dictionary *metadata)
Dictionary buffer_metadata = ARRAY_DICT_INIT;
PUT(buffer_metadata, "id", INTEGER_OBJ(kObjectTypeBuffer));
+ PUT(buffer_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_buf_")));
Dictionary window_metadata = ARRAY_DICT_INIT;
PUT(window_metadata, "id", INTEGER_OBJ(kObjectTypeWindow));
+ PUT(window_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_win_")));
Dictionary tabpage_metadata = ARRAY_DICT_INIT;
PUT(tabpage_metadata, "id", INTEGER_OBJ(kObjectTypeTabpage));
+ PUT(tabpage_metadata, "prefix", STRING_OBJ(cstr_to_string("nvim_tabpage_")));
PUT(types, "Buffer", DICTIONARY_OBJ(buffer_metadata));
PUT(types, "Window", DICTIONARY_OBJ(window_metadata));
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index c8311b0aa0..8b1fb041e2 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -14,7 +14,7 @@
/// @param tabpage The tabpage
/// @param[out] err Details of an error that may have occurred
/// @return The windows in `tabpage`
-ArrayOf(Window) tabpage_get_windows(Tabpage tabpage, Error *err)
+ArrayOf(Window) nvim_tabpage_list_wins(Tabpage tabpage, Error *err)
{
Array rv = ARRAY_DICT_INIT;
tabpage_T *tab = find_tab_by_handle(tabpage, err);
@@ -43,7 +43,7 @@ ArrayOf(Window) tabpage_get_windows(Tabpage tabpage, Error *err)
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
/// @return The variable value
-Object tabpage_get_var(Tabpage tabpage, String name, Error *err)
+Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
@@ -60,6 +60,44 @@ Object tabpage_get_var(Tabpage tabpage, String name, Error *err)
/// @param name The variable name
/// @param value The variable value
/// @param[out] err Details of an error that may have occurred
+void nvim_tabpage_set_var(Tabpage tabpage,
+ String name,
+ Object value,
+ Error *err)
+{
+ tabpage_T *tab = find_tab_by_handle(tabpage, err);
+
+ if (!tab) {
+ return;
+ }
+
+ dict_set_value(tab->tp_vars, name, value, false, false, err);
+}
+
+/// Removes a tab-scoped (t:) variable
+///
+/// @param tabpage handle
+/// @param name The variable name
+/// @param[out] err Details of an error that may have occurred
+void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
+{
+ tabpage_T *tab = find_tab_by_handle(tabpage, err);
+
+ if (!tab) {
+ return;
+ }
+
+ dict_set_value(tab->tp_vars, name, NIL, true, false, err);
+}
+
+/// Sets a tab-scoped (t:) variable
+///
+/// @deprecated
+///
+/// @param tabpage handle
+/// @param name The variable name
+/// @param value The variable value
+/// @param[out] err Details of an error that may have occurred
/// @return The old value or nil if there was no previous value.
///
/// @warning It may return nil if there was no previous value
@@ -72,18 +110,17 @@ Object tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(tab->tp_vars, name, value, false, err);
+ return dict_set_value(tab->tp_vars, name, value, false, true, err);
}
/// Removes a tab-scoped (t:) variable
///
+/// @deprecated
+///
/// @param tabpage handle
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
-/// @return The old value or nil if there was no previous value.
-///
-/// @warning It may return nil if there was no previous value
-/// or if previous value was `v:null`.
+/// @return The old value
Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
@@ -92,7 +129,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(tab->tp_vars, name, NIL, true, err);
+ return dict_set_value(tab->tp_vars, name, NIL, true, true, err);
}
/// Gets the current window in a tab page
@@ -100,7 +137,7 @@ Object tabpage_del_var(Tabpage tabpage, String name, Error *err)
/// @param tabpage The tab page handle
/// @param[out] err Details of an error that may have occurred
/// @return The Window handle
-Window tabpage_get_window(Tabpage tabpage, Error *err)
+Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
{
Window rv = 0;
tabpage_T *tab = find_tab_by_handle(tabpage, err);
@@ -110,7 +147,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
}
if (tab == curtab) {
- return vim_get_current_window();
+ return nvim_get_current_win();
} else {
FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
if (wp == tab->tp_curwin) {
@@ -126,7 +163,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
///
/// @param tabpage The tab page handle
/// @return true if the tab page is valid, false otherwise
-Boolean tabpage_is_valid(Tabpage tabpage)
+Boolean nvim_tabpage_is_valid(Tabpage tabpage)
{
Error stub = ERROR_INIT;
return find_tab_by_handle(tabpage, &stub) != NULL;
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 1703d49296..56b41f1eea 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -8,8 +8,10 @@
#include "nvim/memory.h"
#include "nvim/map.h"
#include "nvim/msgpack_rpc/channel.h"
+#include "nvim/api/ui.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/popupmnu.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/ui.c.generated.h"
@@ -44,8 +46,9 @@ void remote_ui_disconnect(uint64_t channel_id)
xfree(ui);
}
-void ui_attach(uint64_t channel_id, Integer width, Integer height,
- Boolean enable_rgb, Error *err)
+void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
+ Dictionary options, Error *err)
+ FUNC_API_NOEVAL
{
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI already attached for channel"));
@@ -57,14 +60,11 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height,
_("Expected width > 0 and height > 0"));
return;
}
- UIData *data = xmalloc(sizeof(UIData));
- data->channel_id = channel_id;
- data->buffer = (Array)ARRAY_DICT_INIT;
UI *ui = xcalloc(1, sizeof(UI));
ui->width = (int)width;
ui->height = (int)height;
- ui->rgb = enable_rgb;
- ui->data = data;
+ ui->rgb = true;
+ ui->pum_external = false;
ui->resize = remote_ui_resize;
ui->clear = remote_ui_clear;
ui->eol_clear = remote_ui_eol_clear;
@@ -88,37 +88,100 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height,
ui->suspend = remote_ui_suspend;
ui->set_title = remote_ui_set_title;
ui->set_icon = remote_ui_set_icon;
+ ui->event = remote_ui_event;
+
+ for (size_t i = 0; i < options.size; i++) {
+ ui_set_option(ui, options.items[i].key, options.items[i].value, err);
+ if (err->set) {
+ xfree(ui);
+ return;
+ }
+ }
+
+ UIData *data = xmalloc(sizeof(UIData));
+ data->channel_id = channel_id;
+ data->buffer = (Array)ARRAY_DICT_INIT;
+ ui->data = data;
+
pmap_put(uint64_t)(connected_uis, channel_id, ui);
ui_attach_impl(ui);
- return;
}
-void ui_detach(uint64_t channel_id, Error *err)
+/// @deprecated
+void ui_attach(uint64_t channel_id, Integer width, Integer height,
+ Boolean enable_rgb, Error *err)
+{
+ Dictionary opts = ARRAY_DICT_INIT;
+ PUT(opts, "rgb", BOOLEAN_OBJ(enable_rgb));
+ nvim_ui_attach(channel_id, width, height, opts, err);
+ api_free_dictionary(opts);
+}
+
+void nvim_ui_detach(uint64_t channel_id, Error *err)
+ FUNC_API_NOEVAL
{
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI is not attached for channel"));
+ return;
}
remote_ui_disconnect(channel_id);
}
-Object ui_try_resize(uint64_t channel_id, Integer width,
- Integer height, Error *err)
+
+void nvim_ui_try_resize(uint64_t channel_id, Integer width,
+ Integer height, Error *err)
+ FUNC_API_NOEVAL
{
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, Exception, _("UI is not attached for channel"));
+ return;
}
if (width <= 0 || height <= 0) {
api_set_error(err, Validation,
_("Expected width > 0 and height > 0"));
- return NIL;
+ return;
}
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
ui->width = (int)width;
ui->height = (int)height;
ui_refresh();
- return NIL;
+}
+
+void nvim_ui_set_option(uint64_t channel_id, String name,
+ Object value, Error *error)
+ FUNC_API_NOEVAL
+{
+ if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
+ api_set_error(error, Exception, _("UI is not attached for channel"));
+ return;
+ }
+ UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
+
+ ui_set_option(ui, name, value, error);
+ if (!error->set) {
+ ui_refresh();
+ }
+}
+
+static void ui_set_option(UI *ui, String name, Object value, Error *error) {
+ if (strcmp(name.data, "rgb") == 0) {
+ if (value.type != kObjectTypeBoolean) {
+ api_set_error(error, Validation, _("rgb must be a Boolean"));
+ return;
+ }
+ ui->rgb = value.data.boolean;
+ } else if (strcmp(name.data, "popupmenu_external") == 0) {
+ if (value.type != kObjectTypeBoolean) {
+ api_set_error(error, Validation,
+ _("popupmenu_external must be a Boolean"));
+ return;
+ }
+ ui->pum_external = value.data.boolean;
+ } else {
+ api_set_error(error, Validation, _("No such ui option"));
+ }
}
static void push_call(UI *ui, char *name, Array args)
@@ -341,3 +404,19 @@ static void remote_ui_set_icon(UI *ui, char *icon)
ADD(args, STRING_OBJ(cstr_to_string(icon)));
push_call(ui, "set_icon", args);
}
+
+static void remote_ui_event(UI *ui, char *name, Array args, bool *args_consumed)
+{
+ Array my_args = ARRAY_DICT_INIT;
+ // Objects are currently single-reference
+ // make a copy, but only if necessary
+ if (*args_consumed) {
+ for (size_t i = 0; i < args.size; i++) {
+ ADD(my_args, copy_object(args.items[i]));
+ }
+ } else {
+ my_args = args;
+ *args_consumed = true;
+ }
+ push_call(ui, name, my_args);
+}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index ac7cc65ee4..d8cdad961b 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -14,6 +14,7 @@
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
+#include "nvim/file_search.h"
#include "nvim/window.h"
#include "nvim/types.h"
#include "nvim/ex_docmd.h"
@@ -21,7 +22,7 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/eval.h"
-#include "nvim/misc2.h"
+#include "nvim/option.h"
#include "nvim/syntax.h"
#include "nvim/getchar.h"
#include "nvim/os/input.h"
@@ -36,7 +37,7 @@
///
/// @param str The command str
/// @param[out] err Details of an error that may have occurred
-void vim_command(String str, Error *err)
+void nvim_command(String str, Error *err)
{
// Run the command
try_start();
@@ -52,17 +53,13 @@ void vim_command(String str, Error *err)
/// @param escape_csi the string needs escaping for K_SPECIAL/CSI bytes
/// @see feedkeys()
/// @see vim_strsave_escape_csi
-void vim_feedkeys(String keys, String mode, Boolean escape_csi)
+void nvim_feedkeys(String keys, String mode, Boolean escape_csi)
{
bool remap = true;
bool insert = false;
bool typed = false;
bool execute = false;
- if (keys.size == 0) {
- return;
- }
-
for (size_t i = 0; i < mode.size; ++i) {
switch (mode.data[i]) {
case 'n': remap = false; break;
@@ -73,6 +70,10 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi)
}
}
+ if (keys.size == 0 && !execute) {
+ return;
+ }
+
char *keys_esc;
if (escape_csi) {
// Need to escape K_SPECIAL and CSI before putting the string in the
@@ -92,18 +93,23 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi)
typebuf_was_filled = true;
}
if (execute) {
+ int save_msg_scroll = msg_scroll;
+
+ /* Avoid a 1 second delay when the keys start Insert mode. */
+ msg_scroll = false;
exec_normal(true);
+ msg_scroll |= save_msg_scroll;
}
}
-/// Passes input keys to Neovim. Unlike `vim_feedkeys`, this will use a
+/// Passes input keys to Neovim. Unlike `nvim_feedkeys`, this will use a
/// lower-level input buffer and the call is not deferred.
/// This is the most reliable way to emulate real user input.
///
/// @param keys to be typed
/// @return The number of bytes actually written, which can be lower than
/// requested if the buffer becomes full.
-Integer vim_input(String keys)
+Integer nvim_input(String keys)
FUNC_API_ASYNC
{
return (Integer)input_enqueue(keys);
@@ -113,7 +119,7 @@ Integer vim_input(String keys)
///
/// @see replace_termcodes
/// @see cpoptions
-String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
+String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
Boolean special)
{
if (str.size == 0) {
@@ -133,10 +139,10 @@ String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
return cstr_as_string(ptr);
}
-String vim_command_output(String str, Error *err)
+String nvim_command_output(String str, Error *err)
{
do_cmdline_cmd("redir => v:command_output");
- vim_command(str, err);
+ nvim_command(str, err);
do_cmdline_cmd("redir END");
if (err->set) {
@@ -153,7 +159,7 @@ String vim_command_output(String str, Error *err)
/// @param str The expression str
/// @param[out] err Details of an error that may have occurred
/// @return The expanded object
-Object vim_eval(String str, Error *err)
+Object nvim_eval(String str, Error *err)
{
Object rv = OBJECT_INIT;
// Evaluate the expression
@@ -180,7 +186,7 @@ Object vim_eval(String str, Error *err)
/// @param args Functions arguments packed in an Array
/// @param[out] err Details of an error that may have occurred
/// @return Result of the function call
-Object vim_call_function(String fname, Array args, Error *err)
+Object nvim_call_function(String fname, Array args, Error *err)
{
Object rv = OBJECT_INIT;
if (args.size > MAX_FUNC_ARGS) {
@@ -229,7 +235,7 @@ free_vim_args:
/// @param str Some text
/// @param[out] err Details of an error that may have occurred
/// @return The number of cells
-Integer vim_strwidth(String str, Error *err)
+Integer nvim_strwidth(String str, Error *err)
{
if (str.size > INT_MAX) {
api_set_error(err, Validation, _("String length is too high"));
@@ -242,7 +248,7 @@ Integer vim_strwidth(String str, Error *err)
/// Gets a list of paths contained in 'runtimepath'
///
/// @return The list of paths
-ArrayOf(String) vim_list_runtime_paths(void)
+ArrayOf(String) nvim_list_runtime_paths(void)
{
Array rv = ARRAY_DICT_INIT;
uint8_t *rtp = p_rtp;
@@ -283,7 +289,7 @@ ArrayOf(String) vim_list_runtime_paths(void)
///
/// @param dir The new working directory
/// @param[out] err Details of an error that may have occurred
-void vim_change_directory(String dir, Error *err)
+void nvim_set_current_dir(String dir, Error *err)
{
if (dir.size >= MAXPATHL) {
api_set_error(err, Validation, _("Directory string is too long"));
@@ -311,7 +317,7 @@ void vim_change_directory(String dir, Error *err)
///
/// @param[out] err Details of an error that may have occurred
/// @return The current line string
-String vim_get_current_line(Error *err)
+String nvim_get_current_line(Error *err)
{
return buffer_get_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
}
@@ -320,7 +326,7 @@ String vim_get_current_line(Error *err)
///
/// @param line The line contents
/// @param[out] err Details of an error that may have occurred
-void vim_set_current_line(String line, Error *err)
+void nvim_set_current_line(String line, Error *err)
{
buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err);
}
@@ -328,7 +334,7 @@ void vim_set_current_line(String line, Error *err)
/// Deletes the current line
///
/// @param[out] err Details of an error that may have occurred
-void vim_del_current_line(Error *err)
+void nvim_del_current_line(Error *err)
{
buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
}
@@ -338,7 +344,7 @@ void vim_del_current_line(Error *err)
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
/// @return The variable value
-Object vim_get_var(String name, Error *err)
+Object nvim_get_var(String name, Error *err)
{
return dict_get_value(&globvardict, name, err);
}
@@ -348,26 +354,46 @@ Object vim_get_var(String name, Error *err)
/// @param name The variable name
/// @param value The variable value
/// @param[out] err Details of an error that may have occurred
+void nvim_set_var(String name, Object value, Error *err)
+{
+ dict_set_value(&globvardict, name, value, false, false, err);
+}
+
+/// Removes a global variable
+///
+/// @param name The variable name
+/// @param[out] err Details of an error that may have occurred
+void nvim_del_var(String name, Error *err)
+{
+ dict_set_value(&globvardict, name, NIL, true, false, err);
+}
+
+/// Sets a global variable
+///
+/// @deprecated
+///
+/// @param name The variable name
+/// @param value The variable value
+/// @param[out] err Details of an error that may have occurred
/// @return The old value or nil if there was no previous value.
///
/// @warning It may return nil if there was no previous value
/// or if previous value was `v:null`.
Object vim_set_var(String name, Object value, Error *err)
{
- return dict_set_value(&globvardict, name, value, false, err);
+ return dict_set_value(&globvardict, name, value, false, true, err);
}
/// Removes a global variable
///
+/// @deprecated
+///
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
-/// @return The old value or nil if there was no previous value.
-///
-/// @warning It may return nil if there was no previous value
-/// or if previous value was `v:null`.
+/// @return The old value
Object vim_del_var(String name, Error *err)
{
- return dict_set_value(&globvardict, name, NIL, true, err);
+ return dict_set_value(&globvardict, name, NIL, true, true, err);
}
/// Gets a vim variable
@@ -375,7 +401,7 @@ Object vim_del_var(String name, Error *err)
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
/// @return The variable value
-Object vim_get_vvar(String name, Error *err)
+Object nvim_get_vvar(String name, Error *err)
{
return dict_get_value(&vimvardict, name, err);
}
@@ -385,7 +411,7 @@ Object vim_get_vvar(String name, Error *err)
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
/// @return The option value
-Object vim_get_option(String name, Error *err)
+Object nvim_get_option(String name, Error *err)
{
return get_option_from(NULL, SREQ_GLOBAL, name, err);
}
@@ -395,7 +421,7 @@ Object vim_get_option(String name, Error *err)
/// @param name The option name
/// @param value The new option value
/// @param[out] err Details of an error that may have occurred
-void vim_set_option(String name, Object value, Error *err)
+void nvim_set_option(String name, Object value, Error *err)
{
set_option_to(NULL, SREQ_GLOBAL, name, value, err);
}
@@ -403,7 +429,7 @@ void vim_set_option(String name, Object value, Error *err)
/// Writes a message to vim output buffer
///
/// @param str The message
-void vim_out_write(String str)
+void nvim_out_write(String str)
{
write_msg(str, false);
}
@@ -411,25 +437,25 @@ void vim_out_write(String str)
/// Writes a message to vim error buffer
///
/// @param str The message
-void vim_err_write(String str)
+void nvim_err_write(String str)
{
write_msg(str, true);
}
/// Higher level error reporting function that ensures all str contents
-/// are written by sending a trailing linefeed to `vim_err_write`
+/// are written by sending a trailing linefeed to `nvim_err_write`
///
/// @param str The message
-void vim_report_error(String str)
+void nvim_err_writeln(String str)
{
- vim_err_write(str);
- vim_err_write((String) {.data = "\n", .size = 1});
+ nvim_err_write(str);
+ nvim_err_write((String) { .data = "\n", .size = 1 });
}
/// Gets the current list of buffer handles
///
/// @return The number of buffers
-ArrayOf(Buffer) vim_get_buffers(void)
+ArrayOf(Buffer) nvim_list_bufs(void)
{
Array rv = ARRAY_DICT_INIT;
@@ -450,7 +476,7 @@ ArrayOf(Buffer) vim_get_buffers(void)
/// Gets the current buffer
///
/// @reqturn The buffer handle
-Buffer vim_get_current_buffer(void)
+Buffer nvim_get_current_buf(void)
{
return curbuf->handle;
}
@@ -459,7 +485,7 @@ Buffer vim_get_current_buffer(void)
///
/// @param id The buffer handle
/// @param[out] err Details of an error that may have occurred
-void vim_set_current_buffer(Buffer buffer, Error *err)
+void nvim_set_current_buf(Buffer buffer, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -472,7 +498,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err)
if (!try_end(err) && result == FAIL) {
api_set_error(err,
Exception,
- _("Failed to switch to buffer %" PRIu64),
+ _("Failed to switch to buffer %d"),
buffer);
}
}
@@ -480,7 +506,7 @@ void vim_set_current_buffer(Buffer buffer, Error *err)
/// Gets the current list of window handles
///
/// @return The number of windows
-ArrayOf(Window) vim_get_windows(void)
+ArrayOf(Window) nvim_list_wins(void)
{
Array rv = ARRAY_DICT_INIT;
@@ -501,7 +527,7 @@ ArrayOf(Window) vim_get_windows(void)
/// Gets the current window
///
/// @return The window handle
-Window vim_get_current_window(void)
+Window nvim_get_current_win(void)
{
return curwin->handle;
}
@@ -509,7 +535,7 @@ Window vim_get_current_window(void)
/// Sets the current window
///
/// @param handle The window handle
-void vim_set_current_window(Window window, Error *err)
+void nvim_set_current_win(Window window, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -522,7 +548,7 @@ void vim_set_current_window(Window window, Error *err)
if (!try_end(err) && win != curwin) {
api_set_error(err,
Exception,
- _("Failed to switch to window %" PRIu64),
+ _("Failed to switch to window %d"),
window);
}
}
@@ -530,7 +556,7 @@ void vim_set_current_window(Window window, Error *err)
/// Gets the current list of tabpage handles
///
/// @return The number of tab pages
-ArrayOf(Tabpage) vim_get_tabpages(void)
+ArrayOf(Tabpage) nvim_list_tabpages(void)
{
Array rv = ARRAY_DICT_INIT;
@@ -551,7 +577,7 @@ ArrayOf(Tabpage) vim_get_tabpages(void)
/// Gets the current tab page
///
/// @return The tab page handle
-Tabpage vim_get_current_tabpage(void)
+Tabpage nvim_get_current_tabpage(void)
{
return curtab->handle;
}
@@ -560,7 +586,7 @@ Tabpage vim_get_current_tabpage(void)
///
/// @param handle The tab page handle
/// @param[out] err Details of an error that may have occurred
-void vim_set_current_tabpage(Tabpage tabpage, Error *err)
+void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
{
tabpage_T *tp = find_tab_by_handle(tabpage, err);
@@ -573,7 +599,7 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)
if (!try_end(err) && tp != curtab) {
api_set_error(err,
Exception,
- _("Failed to switch to tabpage %" PRIu64),
+ _("Failed to switch to tabpage %d"),
tabpage);
}
}
@@ -582,7 +608,8 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)
///
/// @param channel_id The channel id (passed automatically by the dispatcher)
/// @param event The event type string
-void vim_subscribe(uint64_t channel_id, String event)
+void nvim_subscribe(uint64_t channel_id, String event)
+ FUNC_API_NOEVAL
{
size_t length = (event.size < METHOD_MAXLEN ? event.size : METHOD_MAXLEN);
char e[METHOD_MAXLEN + 1];
@@ -595,7 +622,8 @@ void vim_subscribe(uint64_t channel_id, String event)
///
/// @param channel_id The channel id (passed automatically by the dispatcher)
/// @param event The event type string
-void vim_unsubscribe(uint64_t channel_id, String event)
+void nvim_unsubscribe(uint64_t channel_id, String event)
+ FUNC_API_NOEVAL
{
size_t length = (event.size < METHOD_MAXLEN ?
event.size :
@@ -606,12 +634,12 @@ void vim_unsubscribe(uint64_t channel_id, String event)
channel_unsubscribe(channel_id, e);
}
-Integer vim_name_to_color(String name)
+Integer nvim_get_color_by_name(String name)
{
return name_to_color((uint8_t *)name.data);
}
-Dictionary vim_get_color_map(void)
+Dictionary nvim_get_color_map(void)
{
Dictionary colors = ARRAY_DICT_INIT;
@@ -623,8 +651,8 @@ Dictionary vim_get_color_map(void)
}
-Array vim_get_api_info(uint64_t channel_id)
- FUNC_API_ASYNC
+Array nvim_get_api_info(uint64_t channel_id)
+ FUNC_API_ASYNC FUNC_API_NOEVAL
{
Array rv = ARRAY_DICT_INIT;
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index f644453358..166e43f698 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -11,7 +11,6 @@
#include "nvim/window.h"
#include "nvim/screen.h"
#include "nvim/move.h"
-#include "nvim/misc2.h"
/// Gets the current buffer in a window
@@ -19,7 +18,7 @@
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return The buffer handle
-Buffer window_get_buffer(Window window, Error *err)
+Buffer nvim_win_get_buf(Window window, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -35,7 +34,7 @@ Buffer window_get_buffer(Window window, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the (row, col) tuple
-ArrayOf(Integer, 2) window_get_cursor(Window window, Error *err)
+ArrayOf(Integer, 2) nvim_win_get_cursor(Window window, Error *err)
{
Array rv = ARRAY_DICT_INIT;
win_T *win = find_window_by_handle(window, err);
@@ -53,7 +52,7 @@ ArrayOf(Integer, 2) window_get_cursor(Window window, Error *err)
/// @param window The window handle
/// @param pos the (row, col) tuple representing the new position
/// @param[out] err Details of an error that may have occurred
-void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
+void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -99,7 +98,7 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the height in rows
-Integer window_get_height(Window window, Error *err)
+Integer nvim_win_get_height(Window window, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -116,7 +115,7 @@ Integer window_get_height(Window window, Error *err)
/// @param window The window handle
/// @param height the new height in rows
/// @param[out] err Details of an error that may have occurred
-void window_set_height(Window window, Integer height, Error *err)
+void nvim_win_set_height(Window window, Integer height, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -142,7 +141,7 @@ void window_set_height(Window window, Integer height, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return the width in columns
-Integer window_get_width(Window window, Error *err)
+Integer nvim_win_get_width(Window window, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -159,7 +158,7 @@ Integer window_get_width(Window window, Error *err)
/// @param window The window handle
/// @param width the new width in columns
/// @param[out] err Details of an error that may have occurred
-void window_set_width(Window window, Integer width, Error *err)
+void nvim_win_set_width(Window window, Integer width, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -186,7 +185,7 @@ void window_set_width(Window window, Integer width, Error *err)
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
/// @return The variable value
-Object window_get_var(Window window, String name, Error *err)
+Object nvim_win_get_var(Window window, String name, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -203,6 +202,41 @@ Object window_get_var(Window window, String name, Error *err)
/// @param name The variable name
/// @param value The variable value
/// @param[out] err Details of an error that may have occurred
+void nvim_win_set_var(Window window, String name, Object value, Error *err)
+{
+ win_T *win = find_window_by_handle(window, err);
+
+ if (!win) {
+ return;
+ }
+
+ dict_set_value(win->w_vars, name, value, false, false, err);
+}
+
+/// Removes a window-scoped (w:) variable
+///
+/// @param window The window handle
+/// @param name The variable name
+/// @param[out] err Details of an error that may have occurred
+void nvim_win_del_var(Window window, String name, Error *err)
+{
+ win_T *win = find_window_by_handle(window, err);
+
+ if (!win) {
+ return;
+ }
+
+ dict_set_value(win->w_vars, name, NIL, true, false, err);
+}
+
+/// Sets a window-scoped (w:) variable
+///
+/// @deprecated
+///
+/// @param window The window handle
+/// @param name The variable name
+/// @param value The variable value
+/// @param[out] err Details of an error that may have occurred
/// @return The old value or nil if there was no previous value.
///
/// @warning It may return nil if there was no previous value
@@ -215,18 +249,17 @@ Object window_set_var(Window window, String name, Object value, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(win->w_vars, name, value, false, err);
+ return dict_set_value(win->w_vars, name, value, false, true, err);
}
/// Removes a window-scoped (w:) variable
///
+/// @deprecated
+///
/// @param window The window handle
/// @param name The variable name
/// @param[out] err Details of an error that may have occurred
-/// @return The old value or nil if there was no previous value.
-///
-/// @warning It may return nil if there was no previous value
-/// or if previous value was `v:null`.
+/// @return The old value
Object window_del_var(Window window, String name, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -235,7 +268,7 @@ Object window_del_var(Window window, String name, Error *err)
return (Object) OBJECT_INIT;
}
- return dict_set_value(win->w_vars, name, NIL, true, err);
+ return dict_set_value(win->w_vars, name, NIL, true, true, err);
}
/// Gets a window option value
@@ -244,7 +277,7 @@ Object window_del_var(Window window, String name, Error *err)
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
/// @return The option value
-Object window_get_option(Window window, String name, Error *err)
+Object nvim_win_get_option(Window window, String name, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -262,7 +295,7 @@ Object window_get_option(Window window, String name, Error *err)
/// @param name The option name
/// @param value The option value
/// @param[out] err Details of an error that may have occurred
-void window_set_option(Window window, String name, Object value, Error *err)
+void nvim_win_set_option(Window window, String name, Object value, Error *err)
{
win_T *win = find_window_by_handle(window, err);
@@ -278,7 +311,7 @@ void window_set_option(Window window, String name, Object value, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return The (row, col) tuple with the window position
-ArrayOf(Integer, 2) window_get_position(Window window, Error *err)
+ArrayOf(Integer, 2) nvim_win_get_position(Window window, Error *err)
{
Array rv = ARRAY_DICT_INIT;
win_T *win = find_window_by_handle(window, err);
@@ -296,7 +329,7 @@ ArrayOf(Integer, 2) window_get_position(Window window, Error *err)
/// @param window The window handle
/// @param[out] err Details of an error that may have occurred
/// @return The tab page that contains the window
-Tabpage window_get_tabpage(Window window, Error *err)
+Tabpage nvim_win_get_tabpage(Window window, Error *err)
{
Tabpage rv = 0;
win_T *win = find_window_by_handle(window, err);
@@ -312,7 +345,7 @@ Tabpage window_get_tabpage(Window window, Error *err)
///
/// @param window The window handle
/// @return true if the window is valid, false otherwise
-Boolean window_is_valid(Window window)
+Boolean nvim_win_is_valid(Window window)
{
Error stub = ERROR_INIT;
return find_window_by_handle(window, &stub) != NULL;
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index c934d44e70..b42ad1c18a 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -36,6 +36,7 @@
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
+#include "nvim/file_search.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
@@ -48,7 +49,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
@@ -1397,8 +1397,7 @@ buflist_new (
}
if (buf != curbuf || curbuf == NULL) {
buf = xcalloc(1, sizeof(buf_T));
- handle_register_buffer(buf);
- /* init b: variables */
+ // init b: variables
buf->b_vars = dict_alloc();
init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE);
}
@@ -1451,11 +1450,12 @@ buflist_new (
lastbuf = buf;
buf->b_fnum = top_file_num++;
- if (top_file_num < 0) { /* wrap around (may cause duplicates) */
+ handle_register_buffer(buf);
+ if (top_file_num < 0) { // wrap around (may cause duplicates)
EMSG(_("W14: Warning: List of file names overflow"));
if (emsg_silent == 0) {
ui_flush();
- os_delay(3000L, true); /* make sure it is noticed */
+ os_delay(3000L, true); // make sure it is noticed
}
top_file_num = 1;
}
@@ -5231,12 +5231,12 @@ wipe_buffer (
int aucmd /* When TRUE trigger autocommands. */
)
{
- if (buf->b_fnum == top_file_num - 1)
- --top_file_num;
-
- if (!aucmd) /* Don't trigger BufDelete autocommands here. */
+ if (!aucmd) {
+ // Don't trigger BufDelete autocommands here.
block_autocmds();
- close_buffer(NULL, buf, DOBUF_WIPE, FALSE);
- if (!aucmd)
+ }
+ close_buffer(NULL, buf, DOBUF_WIPE, false);
+ if (!aucmd) {
unblock_autocmds();
+ }
}
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 46687f344c..ab5987612c 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -461,9 +461,10 @@ typedef struct {
*/
struct file_buffer {
- uint64_t handle; // unique identifier for the buffer
- memline_T b_ml; /* associated memline (also contains line
- count) */
+ handle_T handle; // unique id for the buffer (buffer number)
+#define b_fnum handle
+
+ memline_T b_ml; // associated memline (also contains line count
buf_T *b_next; /* links in list of buffers */
buf_T *b_prev;
@@ -487,8 +488,6 @@ struct file_buffer {
bool file_id_valid;
FileID file_id;
- int b_fnum; /* buffer number for this file. */
-
bool b_changed; /* 'modified': Set to true if something in the
file has been changed and not written out. */
int b_changedtick; /* incremented for each change, also for undo */
@@ -799,28 +798,27 @@ struct diffblock_S {
# define SNAP_AUCMD_IDX 1
# define SNAP_COUNT 2
-/*
- * Tab pages point to the top frame of each tab page.
- * Note: Most values are NOT valid for the current tab page! Use "curwin",
- * "firstwin", etc. for that. "tp_topframe" is always valid and can be
- * compared against "topframe" to find the current tab page.
- */
+/// Tab pages point to the top frame of each tab page.
+/// Note: Most values are NOT valid for the current tab page! Use "curwin",
+/// "firstwin", etc. for that. "tp_topframe" is always valid and can be
+/// compared against "topframe" to find the current tab page.
typedef struct tabpage_S tabpage_T;
struct tabpage_S {
- uint64_t handle;
- tabpage_T *tp_next; /* next tabpage or NULL */
- frame_T *tp_topframe; /* topframe for the windows */
- win_T *tp_curwin; /* current window in this Tab page */
- win_T *tp_prevwin; /* previous window in this Tab page */
- win_T *tp_firstwin; /* first window in this Tab page */
- win_T *tp_lastwin; /* last window in this Tab page */
- long tp_old_Rows; /* Rows when Tab page was left */
- long tp_old_Columns; /* Columns when Tab page was left */
- long tp_ch_used; /* value of 'cmdheight' when frame size
- was set */
+ handle_T handle;
+ tabpage_T *tp_next; ///< next tabpage or NULL
+ frame_T *tp_topframe; ///< topframe for the windows
+ win_T *tp_curwin; ///< current window in this Tab page
+ win_T *tp_prevwin; ///< previous window in this Tab page
+ win_T *tp_firstwin; ///< first window in this Tab page
+ win_T *tp_lastwin; ///< last window in this Tab page
+ long tp_old_Rows; ///< Rows when Tab page was left
+ long tp_old_Columns; ///< Columns when Tab page was left
+ long tp_ch_used; ///< value of 'cmdheight' when frame size
+ ///< was set
+
diff_T *tp_first_diff;
buf_T *(tp_diffbuf[DB_COUNT]);
- int tp_diff_invalid; ///< list of diffs is outdated */
+ int tp_diff_invalid; ///< list of diffs is outdated
frame_T *(tp_snapshot[SNAP_COUNT]); ///< window layout snapshots
dictitem_T tp_winvar; ///< variable for "t:" Dictionary
dict_T *tp_vars; ///< internal variables, local to tab page
@@ -936,8 +934,8 @@ struct matchitem {
* All row numbers are relative to the start of the window, except w_winrow.
*/
struct window_S {
- uint64_t handle;
- int w_id; ///< unique window ID
+ handle_T handle; ///< unique identifier for the window
+
buf_T *w_buffer; ///< buffer we are a window into (used
///< often, keep it the first item!)
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 22ca0fb0cc..78f5d96fc7 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -19,10 +19,11 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
+#include "nvim/option.h"
#include "nvim/os_unix.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/path.h"
@@ -1739,8 +1740,11 @@ char_u* skiptowhite_esc(char_u *p) {
/// @return Number read from the string.
intmax_t getdigits(char_u **pp)
{
+ errno = 0;
intmax_t number = strtoimax((char *)*pp, (char **)pp, 10);
- assert(errno != ERANGE);
+ if (number == INTMAX_MAX || number == INTMAX_MIN) {
+ assert(errno != ERANGE);
+ }
return number;
}
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index afaa6022c9..3ba9da34f2 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -9,6 +9,7 @@
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/screen.h"
+#include "nvim/state.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
diff --git a/src/nvim/cursor.h b/src/nvim/cursor.h
index 09cc5a813c..1cbe8a609e 100644
--- a/src/nvim/cursor.h
+++ b/src/nvim/cursor.h
@@ -4,7 +4,6 @@
#include <stdbool.h>
#include "nvim/vim.h"
-#include "nvim/misc2.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor.h.generated.h"
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index 87425ca567..b50462664c 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -3,7 +3,6 @@
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/cursor_shape.h"
-#include "nvim/misc2.h"
#include "nvim/ex_getln.h"
#include "nvim/charset.h"
#include "nvim/strings.h"
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index 4826e70727..ef5acf4845 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -21,7 +21,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/normal.h"
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index 4512b97967..6ba6e659a6 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -17,7 +17,6 @@
#include "nvim/getchar.h"
#include "nvim/mbyte.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/garray.h"
#include "nvim/normal.h"
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index a71104cfb6..18d5ea533d 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -29,7 +29,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/move.h"
#include "nvim/normal.h"
@@ -463,6 +462,8 @@ static void insert_enter(InsertState *s)
o_lnum = curwin->w_cursor.lnum;
}
+ foldUpdateAll(curwin);
+ foldOpenCursor();
if (s->cmdchar != 'r' && s->cmdchar != 'v') {
apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL, false, curbuf);
}
@@ -2472,6 +2473,7 @@ void ins_compl_show_pum(void)
int cur = -1;
colnr_T col;
int lead_len = 0;
+ bool array_changed = false;
if (!pum_wanted() || !pum_enough_matches())
return;
@@ -2483,7 +2485,8 @@ void ins_compl_show_pum(void)
update_screen(0);
if (compl_match_array == NULL) {
- /* Need to build the popup menu list. */
+ array_changed = true;
+ // Need to build the popup menu list.
compl_match_arraysize = 0;
compl = compl_first_match;
/*
@@ -2586,7 +2589,7 @@ void ins_compl_show_pum(void)
// Use the cursor to get all wrapping and other settings right.
col = curwin->w_cursor.col;
curwin->w_cursor.col = compl_col;
- pum_display(compl_match_array, compl_match_arraysize, cur);
+ pum_display(compl_match_array, compl_match_arraysize, cur, array_changed);
curwin->w_cursor.col = col;
}
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index bb46898135..c762ce9fff 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -44,7 +44,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/map.h"
#include "nvim/file_search.h"
@@ -63,6 +62,7 @@
#include "nvim/search.h"
#include "nvim/sha256.h"
#include "nvim/spell.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tag.h"
@@ -90,6 +90,8 @@
#include "nvim/os/dl.h"
#include "nvim/os/input.h"
#include "nvim/event/loop.h"
+#include "nvim/lib/kvec.h"
+#include "nvim/lib/khash.h"
#include "nvim/lib/queue.h"
#include "nvim/eval/typval_encode.h"
@@ -442,6 +444,22 @@ typedef struct {
ufunc_T *callback;
} timer_T;
+typedef void (*FunPtr)(void);
+
+/// Prototype of C function that implements VimL function
+typedef void (*VimLFunc)(typval_T *args, typval_T *rvar, FunPtr data);
+
+/// Structure holding VimL function definition
+typedef struct fst {
+ char *name; ///< Name of the function.
+ uint8_t min_argc; ///< Minimal number of arguments.
+ uint8_t max_argc; ///< Maximal number of arguments.
+ VimLFunc func; ///< Function implementation.
+ FunPtr data; ///< Userdata for function implementation.
+} VimLFuncDef;
+
+KHASH_MAP_INIT_STR(functions, VimLFuncDef)
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "eval.c.generated.h"
#endif
@@ -6681,331 +6699,9 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate)
return OK;
}
-/*
- * Array with names and number of arguments of all internal functions
- * MUST BE KEPT SORTED IN strcmp() ORDER FOR BINARY SEARCH!
- */
-static struct fst {
- char *f_name; /* function name */
- char f_min_argc; /* minimal number of arguments */
- char f_max_argc; /* maximal number of arguments */
- void (*f_func)(typval_T *args, typval_T *rvar);
- /* implementation of function */
-} functions[] =
-{
- { "abs", 1, 1, f_abs },
- { "acos", 1, 1, f_acos }, // WJMc
- { "add", 2, 2, f_add },
- { "and", 2, 2, f_and },
- { "api_info", 0, 0, f_api_info },
- { "append", 2, 2, f_append },
- { "argc", 0, 0, f_argc },
- { "argidx", 0, 0, f_argidx },
- { "arglistid", 0, 2, f_arglistid },
- { "argv", 0, 1, f_argv },
- { "asin", 1, 1, f_asin }, // WJMc
- { "assert_equal", 2, 3, f_assert_equal },
- { "assert_exception", 1, 2, f_assert_exception },
- { "assert_fails", 1, 2, f_assert_fails },
- { "assert_false", 1, 2, f_assert_false },
- { "assert_match", 2, 3, f_assert_match },
- { "assert_notequal", 2, 3, f_assert_notequal },
- { "assert_notmatch", 2, 3, f_assert_notmatch },
- { "assert_true", 1, 2, f_assert_true },
- { "atan", 1, 1, f_atan },
- { "atan2", 2, 2, f_atan2 },
- { "browse", 4, 4, f_browse },
- { "browsedir", 2, 2, f_browsedir },
- { "bufexists", 1, 1, f_bufexists },
- { "buffer_exists", 1, 1, f_bufexists }, // obsolete
- { "buffer_name", 1, 1, f_bufname }, // obsolete
- { "buffer_number", 1, 1, f_bufnr }, // obsolete
- { "buflisted", 1, 1, f_buflisted },
- { "bufloaded", 1, 1, f_bufloaded },
- { "bufname", 1, 1, f_bufname },
- { "bufnr", 1, 2, f_bufnr },
- { "bufwinnr", 1, 1, f_bufwinnr },
- { "byte2line", 1, 1, f_byte2line },
- { "byteidx", 2, 2, f_byteidx },
- { "byteidxcomp", 2, 2, f_byteidxcomp },
- { "call", 2, 3, f_call },
- { "ceil", 1, 1, f_ceil },
- { "changenr", 0, 0, f_changenr },
- { "char2nr", 1, 2, f_char2nr },
- { "cindent", 1, 1, f_cindent },
- { "clearmatches", 0, 0, f_clearmatches },
- { "col", 1, 1, f_col },
- { "complete", 2, 2, f_complete },
- { "complete_add", 1, 1, f_complete_add },
- { "complete_check", 0, 0, f_complete_check },
- { "confirm", 1, 4, f_confirm },
- { "copy", 1, 1, f_copy },
- { "cos", 1, 1, f_cos },
- { "cosh", 1, 1, f_cosh },
- { "count", 2, 4, f_count },
- { "cscope_connection", 0, 3, f_cscope_connection },
- { "cursor", 1, 3, f_cursor },
- { "deepcopy", 1, 2, f_deepcopy },
- { "delete", 1, 2, f_delete },
- { "dictwatcheradd", 3, 3, f_dictwatcheradd },
- { "dictwatcherdel", 3, 3, f_dictwatcherdel },
- { "did_filetype", 0, 0, f_did_filetype },
- { "diff_filler", 1, 1, f_diff_filler },
- { "diff_hlID", 2, 2, f_diff_hlID },
- { "empty", 1, 1, f_empty },
- { "escape", 2, 2, f_escape },
- { "eval", 1, 1, f_eval },
- { "eventhandler", 0, 0, f_eventhandler },
- { "executable", 1, 1, f_executable },
- { "execute", 1, 1, f_execute },
- { "exepath", 1, 1, f_exepath },
- { "exists", 1, 1, f_exists },
- { "exp", 1, 1, f_exp },
- { "expand", 1, 3, f_expand },
- { "extend", 2, 3, f_extend },
- { "feedkeys", 1, 2, f_feedkeys },
- { "file_readable", 1, 1, f_filereadable }, // obsolete
- { "filereadable", 1, 1, f_filereadable },
- { "filewritable", 1, 1, f_filewritable },
- { "filter", 2, 2, f_filter },
- { "finddir", 1, 3, f_finddir },
- { "findfile", 1, 3, f_findfile },
- { "float2nr", 1, 1, f_float2nr },
- { "floor", 1, 1, f_floor },
- { "fmod", 2, 2, f_fmod },
- { "fnameescape", 1, 1, f_fnameescape },
- { "fnamemodify", 2, 2, f_fnamemodify },
- { "foldclosed", 1, 1, f_foldclosed },
- { "foldclosedend", 1, 1, f_foldclosedend },
- { "foldlevel", 1, 1, f_foldlevel },
- { "foldtext", 0, 0, f_foldtext },
- { "foldtextresult", 1, 1, f_foldtextresult },
- { "foreground", 0, 0, f_foreground },
- { "function", 1, 1, f_function },
- { "garbagecollect", 0, 1, f_garbagecollect },
- { "get", 2, 3, f_get },
- { "getbufline", 2, 3, f_getbufline },
- { "getbufvar", 2, 3, f_getbufvar },
- { "getchar", 0, 1, f_getchar },
- { "getcharmod", 0, 0, f_getcharmod },
- { "getcharsearch", 0, 0, f_getcharsearch },
- { "getcmdline", 0, 0, f_getcmdline },
- { "getcmdpos", 0, 0, f_getcmdpos },
- { "getcmdtype", 0, 0, f_getcmdtype },
- { "getcmdwintype", 0, 0, f_getcmdwintype },
- { "getcompletion", 2, 2, f_getcompletion },
- { "getcurpos", 0, 0, f_getcurpos },
- { "getcwd", 0, 2, f_getcwd },
- { "getfontname", 0, 1, f_getfontname },
- { "getfperm", 1, 1, f_getfperm },
- { "getfsize", 1, 1, f_getfsize },
- { "getftime", 1, 1, f_getftime },
- { "getftype", 1, 1, f_getftype },
- { "getline", 1, 2, f_getline },
- { "getloclist", 1, 1, f_getqflist },
- { "getmatches", 0, 0, f_getmatches },
- { "getpid", 0, 0, f_getpid },
- { "getpos", 1, 1, f_getpos },
- { "getqflist", 0, 0, f_getqflist },
- { "getreg", 0, 3, f_getreg },
- { "getregtype", 0, 1, f_getregtype },
- { "gettabvar", 2, 3, f_gettabvar },
- { "gettabwinvar", 3, 4, f_gettabwinvar },
- { "getwinposx", 0, 0, f_getwinposx },
- { "getwinposy", 0, 0, f_getwinposy },
- { "getwinvar", 2, 3, f_getwinvar },
- { "glob", 1, 4, f_glob },
- { "glob2regpat", 1, 1, f_glob2regpat },
- { "globpath", 2, 5, f_globpath },
- { "has", 1, 1, f_has },
- { "has_key", 2, 2, f_has_key },
- { "haslocaldir", 0, 2, f_haslocaldir },
- { "hasmapto", 1, 3, f_hasmapto },
- { "highlightID", 1, 1, f_hlID }, // obsolete
- { "highlight_exists", 1, 1, f_hlexists }, // obsolete
- { "histadd", 2, 2, f_histadd },
- { "histdel", 1, 2, f_histdel },
- { "histget", 1, 2, f_histget },
- { "histnr", 1, 1, f_histnr },
- { "hlID", 1, 1, f_hlID },
- { "hlexists", 1, 1, f_hlexists },
- { "hostname", 0, 0, f_hostname },
- { "iconv", 3, 3, f_iconv },
- { "indent", 1, 1, f_indent },
- { "index", 2, 4, f_index },
- { "input", 1, 3, f_input },
- { "inputdialog", 1, 3, f_inputdialog },
- { "inputlist", 1, 1, f_inputlist },
- { "inputrestore", 0, 0, f_inputrestore },
- { "inputsave", 0, 0, f_inputsave },
- { "inputsecret", 1, 2, f_inputsecret },
- { "insert", 2, 3, f_insert },
- { "invert", 1, 1, f_invert },
- { "isdirectory", 1, 1, f_isdirectory },
- { "islocked", 1, 1, f_islocked },
- { "items", 1, 1, f_items },
- { "jobclose", 1, 2, f_jobclose },
- { "jobpid", 1, 1, f_jobpid },
- { "jobresize", 3, 3, f_jobresize },
- { "jobsend", 2, 2, f_jobsend },
- { "jobstart", 1, 2, f_jobstart },
- { "jobstop", 1, 1, f_jobstop },
- { "jobwait", 1, 2, f_jobwait },
- { "join", 1, 2, f_join },
- { "json_decode", 1, 1, f_json_decode },
- { "json_encode", 1, 1, f_json_encode },
- { "keys", 1, 1, f_keys },
- { "last_buffer_nr", 0, 0, f_last_buffer_nr }, // obsolete
- { "len", 1, 1, f_len },
- { "libcall", 3, 3, f_libcall },
- { "libcallnr", 3, 3, f_libcallnr },
- { "line", 1, 1, f_line },
- { "line2byte", 1, 1, f_line2byte },
- { "lispindent", 1, 1, f_lispindent },
- { "localtime", 0, 0, f_localtime },
- { "log", 1, 1, f_log },
- { "log10", 1, 1, f_log10 },
- { "map", 2, 2, f_map },
- { "maparg", 1, 4, f_maparg },
- { "mapcheck", 1, 3, f_mapcheck },
- { "match", 2, 4, f_match },
- { "matchadd", 2, 5, f_matchadd },
- { "matchaddpos", 2, 5, f_matchaddpos },
- { "matcharg", 1, 1, f_matcharg },
- { "matchdelete", 1, 1, f_matchdelete },
- { "matchend", 2, 4, f_matchend },
- { "matchlist", 2, 4, f_matchlist },
- { "matchstr", 2, 4, f_matchstr },
- { "max", 1, 1, f_max },
- { "min", 1, 1, f_min },
- { "mkdir", 1, 3, f_mkdir },
- { "mode", 0, 1, f_mode },
- { "msgpackdump", 1, 1, f_msgpackdump },
- { "msgpackparse", 1, 1, f_msgpackparse },
- { "nextnonblank", 1, 1, f_nextnonblank },
- { "nr2char", 1, 2, f_nr2char },
- { "or", 2, 2, f_or },
- { "pathshorten", 1, 1, f_pathshorten },
- { "pow", 2, 2, f_pow },
- { "prevnonblank", 1, 1, f_prevnonblank },
- { "printf", 2, MAX_FUNC_ARGS, f_printf },
- { "pumvisible", 0, 0, f_pumvisible },
- { "py3eval", 1, 1, f_py3eval },
- { "pyeval", 1, 1, f_pyeval },
- { "range", 1, 3, f_range },
- { "readfile", 1, 3, f_readfile },
- { "reltime", 0, 2, f_reltime },
- { "reltimefloat", 1, 1, f_reltimefloat },
- { "reltimestr", 1, 1, f_reltimestr },
- { "remove", 2, 3, f_remove },
- { "rename", 2, 2, f_rename },
- { "repeat", 2, 2, f_repeat },
- { "resolve", 1, 1, f_resolve },
- { "reverse", 1, 1, f_reverse },
- { "round", 1, 1, f_round },
- { "rpcnotify", 2, MAX_FUNC_ARGS, f_rpcnotify },
- { "rpcrequest", 2, MAX_FUNC_ARGS, f_rpcrequest },
- { "rpcstart", 1, 2, f_rpcstart },
- { "rpcstop", 1, 1, f_rpcstop },
- { "screenattr", 2, 2, f_screenattr },
- { "screenchar", 2, 2, f_screenchar },
- { "screencol", 0, 0, f_screencol },
- { "screenrow", 0, 0, f_screenrow },
- { "search", 1, 4, f_search },
- { "searchdecl", 1, 3, f_searchdecl },
- { "searchpair", 3, 7, f_searchpair },
- { "searchpairpos", 3, 7, f_searchpairpos },
- { "searchpos", 1, 4, f_searchpos },
- { "serverlist", 0, 0, f_serverlist },
- { "serverstart", 0, 1, f_serverstart },
- { "serverstop", 1, 1, f_serverstop },
- { "setbufvar", 3, 3, f_setbufvar },
- { "setcharsearch", 1, 1, f_setcharsearch },
- { "setcmdpos", 1, 1, f_setcmdpos },
- { "setfperm", 2, 2, f_setfperm },
- { "setline", 2, 2, f_setline },
- { "setloclist", 2, 4, f_setloclist },
- { "setmatches", 1, 1, f_setmatches },
- { "setpos", 2, 2, f_setpos },
- { "setqflist", 1, 3, f_setqflist },
- { "setreg", 2, 3, f_setreg },
- { "settabvar", 3, 3, f_settabvar },
- { "settabwinvar", 4, 4, f_settabwinvar },
- { "setwinvar", 3, 3, f_setwinvar },
- { "sha256", 1, 1, f_sha256 },
- { "shellescape", 1, 2, f_shellescape },
- { "shiftwidth", 0, 0, f_shiftwidth },
- { "simplify", 1, 1, f_simplify },
- { "sin", 1, 1, f_sin },
- { "sinh", 1, 1, f_sinh },
- { "sort", 1, 3, f_sort },
- { "soundfold", 1, 1, f_soundfold },
- { "spellbadword", 0, 1, f_spellbadword },
- { "spellsuggest", 1, 3, f_spellsuggest },
- { "split", 1, 3, f_split },
- { "sqrt", 1, 1, f_sqrt },
- { "str2float", 1, 1, f_str2float },
- { "str2nr", 1, 2, f_str2nr },
- { "strchars", 1, 2, f_strchars },
- { "strdisplaywidth", 1, 2, f_strdisplaywidth },
- { "strftime", 1, 2, f_strftime },
- { "stridx", 2, 3, f_stridx },
- { "string", 1, 1, f_string },
- { "strlen", 1, 1, f_strlen },
- { "strpart", 2, 3, f_strpart },
- { "strridx", 2, 3, f_strridx },
- { "strtrans", 1, 1, f_strtrans },
- { "strwidth", 1, 1, f_strwidth },
- { "submatch", 1, 2, f_submatch },
- { "substitute", 4, 4, f_substitute },
- { "synID", 3, 3, f_synID },
- { "synIDattr", 2, 3, f_synIDattr },
- { "synIDtrans", 1, 1, f_synIDtrans },
- { "synconcealed", 2, 2, f_synconcealed },
- { "synstack", 2, 2, f_synstack },
- { "system", 1, 2, f_system },
- { "systemlist", 1, 3, f_systemlist },
- { "tabpagebuflist", 0, 1, f_tabpagebuflist },
- { "tabpagenr", 0, 1, f_tabpagenr },
- { "tabpagewinnr", 1, 2, f_tabpagewinnr },
- { "tagfiles", 0, 0, f_tagfiles },
- { "taglist", 1, 1, f_taglist },
- { "tan", 1, 1, f_tan },
- { "tanh", 1, 1, f_tanh },
- { "tempname", 0, 0, f_tempname },
- { "termopen", 1, 2, f_termopen },
- { "test", 1, 1, f_test },
- { "timer_start", 2, 3, f_timer_start },
- { "timer_stop", 1, 1, f_timer_stop },
- { "tolower", 1, 1, f_tolower },
- { "toupper", 1, 1, f_toupper },
- { "tr", 3, 3, f_tr },
- { "trunc", 1, 1, f_trunc },
- { "type", 1, 1, f_type },
- { "undofile", 1, 1, f_undofile },
- { "undotree", 0, 0, f_undotree },
- { "uniq", 1, 3, f_uniq },
- { "values", 1, 1, f_values },
- { "virtcol", 1, 1, f_virtcol },
- { "visualmode", 0, 1, f_visualmode },
- { "wildmenumode", 0, 0, f_wildmenumode },
- { "win_getid", 0, 2, f_win_getid },
- { "win_gotoid", 1, 1, f_win_gotoid },
- { "win_id2tabwin", 1, 1, f_win_id2tabwin },
- { "win_id2win", 1, 1, f_win_id2win },
- { "winbufnr", 1, 1, f_winbufnr },
- { "wincol", 0, 0, f_wincol },
- { "winheight", 1, 1, f_winheight },
- { "winline", 0, 0, f_winline },
- { "winnr", 0, 1, f_winnr },
- { "winrestcmd", 0, 0, f_winrestcmd },
- { "winrestview", 1, 1, f_winrestview },
- { "winsaveview", 0, 0, f_winsaveview },
- { "winwidth", 1, 1, f_winwidth },
- { "wordcount", 0, 0, f_wordcount },
- { "writefile", 2, 3, f_writefile },
- { "xor", 2, 2, f_xor },
-};
+#ifdef INCLUDE_GENERATED_DECLARATIONS
+# include "funcs.generated.h"
+#endif
/*
@@ -7024,15 +6720,25 @@ char_u *get_function_name(expand_T *xp, int idx)
if (name != NULL)
return name;
}
- if (++intidx < (int)ARRAY_SIZE(functions)) {
- STRCPY(IObuff, functions[intidx].f_name);
- STRCAT(IObuff, "(");
- if (functions[intidx].f_max_argc == 0)
- STRCAT(IObuff, ")");
- return IObuff;
+ while ( (size_t)++intidx < ARRAY_SIZE(functions)
+ && functions[intidx].name[0] == '\0') {
}
- return NULL;
+ if ((size_t)intidx >= ARRAY_SIZE(functions)) {
+ return NULL;
+ }
+
+ const char *const key = functions[intidx].name;
+ const size_t key_len = strlen(key);
+ memcpy(IObuff, key, key_len);
+ IObuff[key_len] = '(';
+ if (functions[intidx].max_argc == 0) {
+ IObuff[key_len + 1] = ')';
+ IObuff[key_len + 2] = NUL;
+ } else {
+ IObuff[key_len + 1] = NUL;
+ }
+ return IObuff;
}
/*
@@ -7057,32 +6763,16 @@ char_u *get_expr_name(expand_T *xp, int idx)
-/*
- * Find internal function in table above.
- * Return index, or -1 if not found
- */
-static int
-find_internal_func (
- char_u *name /* name of the function */
-)
+/// Find internal function in hash functions
+///
+/// @param[in] name Name of the function.
+///
+/// Returns pointer to the function definition or NULL if not found.
+static VimLFuncDef *find_internal_func(const char *const name)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_NONNULL_ALL
{
- int first = 0;
- int last = (int)ARRAY_SIZE(functions) - 1;
-
- /*
- * Find the function name in the table. Binary search.
- */
- while (first <= last) {
- int x = first + ((unsigned)(last - first)) / 2;
- int cmp = STRCMP(name, functions[x].f_name);
- if (cmp < 0)
- last = x - 1;
- else if (cmp > 0)
- first = x + 1;
- else
- return x;
- }
- return -1;
+ size_t len = strlen(name);
+ return find_internal_func_gperf(name, len);
}
/*
@@ -7200,7 +6890,6 @@ call_func (
#define ERROR_NONE 5
#define ERROR_OTHER 6
int error = ERROR_NONE;
- int i;
int llen;
ufunc_T *fp;
#define FLEN_FIXED 40
@@ -7222,12 +6911,13 @@ call_func (
fname_buf[0] = K_SPECIAL;
fname_buf[1] = KS_EXTRA;
fname_buf[2] = (int)KE_SNR;
- i = 3;
- if (eval_fname_sid(name)) { /* "<SID>" or "s:" */
- if (current_SID <= 0)
+ int i = 3;
+ if (eval_fname_sid(name)) { // "<SID>" or "s:"
+ if (current_SID <= 0) {
error = ERROR_SCRIPT;
- else {
- sprintf((char *)fname_buf + 3, "%" PRId64 "_", (int64_t)current_SID);
+ } else {
+ vim_snprintf((char *)fname_buf + 3, ARRAY_SIZE(fname_buf) - 3,
+ "%" PRId64 "_", (int64_t)current_SID);
i = (int)STRLEN(fname_buf);
}
}
@@ -7294,18 +6984,16 @@ call_func (
}
}
} else {
- /*
- * Find the function name in the table, call its implementation.
- */
- i = find_internal_func(fname);
- if (i >= 0) {
- if (argcount < functions[i].f_min_argc)
+ // Find the function name in the table, call its implementation.
+ VimLFuncDef *const fdef = find_internal_func((char *)fname);
+ if (fdef != NULL) {
+ if (argcount < fdef->min_argc) {
error = ERROR_TOOFEW;
- else if (argcount > functions[i].f_max_argc)
+ } else if (argcount > fdef->max_argc) {
error = ERROR_TOOMANY;
- else {
+ } else {
argvars[argcount].v_type = VAR_UNKNOWN;
- functions[i].f_func(argvars, rettv);
+ fdef->func(argvars, rettv, fdef->data);
error = ERROR_NONE;
}
}
@@ -7416,13 +7104,10 @@ static inline int get_float_arg(typval_T *argvars, float_T *f)
// Some versions of glibc on i386 have an optimization that makes it harder to
// call math functions indirectly from inside an inlined function, causing
// compile-time errors. Avoid `inline` in that case. #3072
-#ifndef ARCH_32
-inline
-#endif
-static void float_op_wrapper(typval_T *argvars, typval_T *rettv,
- float_T (*function)(float_T))
+static void float_op_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T f;
+ float_T (*function)(float_T) = (float_T (*)(float_T))fptr;
rettv->v_type = VAR_FLOAT;
if (get_float_arg(argvars, &f) == OK) {
@@ -7432,13 +7117,40 @@ static void float_op_wrapper(typval_T *argvars, typval_T *rettv,
}
}
+static void api_wrapper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ ApiDispatchWrapper fn = (ApiDispatchWrapper)fptr;
+
+ Array args = ARRAY_DICT_INIT;
+
+ for (typval_T *tv = argvars; tv->v_type != VAR_UNKNOWN; tv++) {
+ ADD(args, vim_to_object(tv));
+ }
+
+ Error err = ERROR_INIT;
+ Object result = fn(INVALID_CHANNEL, NO_RESPONSE, args, &err);
+
+ if (err.set) {
+ nvim_err_writeln(cstr_as_string(err.msg));
+ goto end;
+ }
+
+ if (!object_to_vim(result, rettv, &err)) {
+ EMSG2(_("Error converting the call result: %s"), err.msg);
+ }
+
+end:
+ api_free_array(args);
+ api_free_object(result);
+}
+
/*
* "abs(expr)" function
*/
-static void f_abs(typval_T *argvars, typval_T *rettv)
+static void f_abs(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (argvars[0].v_type == VAR_FLOAT) {
- float_op_wrapper(argvars, rettv, &fabs);
+ float_op_wrapper(argvars, rettv, (FunPtr)&fabs);
} else {
varnumber_T n;
int error = FALSE;
@@ -7454,17 +7166,9 @@ static void f_abs(typval_T *argvars, typval_T *rettv)
}
/*
- * "acos()" function
- */
-static void f_acos(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &acos);
-}
-
-/*
* "add(list, item)" function
*/
-static void f_add(typval_T *argvars, typval_T *rettv)
+static void f_add(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
list_T *l;
@@ -7483,7 +7187,7 @@ static void f_add(typval_T *argvars, typval_T *rettv)
/*
* "and(expr, expr)" function
*/
-static void f_and(typval_T *argvars, typval_T *rettv)
+static void f_and(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
& get_tv_number_chk(&argvars[1], NULL);
@@ -7491,7 +7195,7 @@ static void f_and(typval_T *argvars, typval_T *rettv)
/// "api_info()" function
-static void f_api_info(typval_T *argvars, typval_T *rettv)
+static void f_api_info(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
Dictionary metadata = api_metadata();
(void)object_to_vim(DICTIONARY_OBJ(metadata), rettv, NULL);
@@ -7501,7 +7205,7 @@ static void f_api_info(typval_T *argvars, typval_T *rettv)
/*
* "append(lnum, string/list)" function
*/
-static void f_append(typval_T *argvars, typval_T *rettv)
+static void f_append(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long lnum;
char_u *line;
@@ -7556,7 +7260,7 @@ static void f_append(typval_T *argvars, typval_T *rettv)
/*
* "argc()" function
*/
-static void f_argc(typval_T *argvars, typval_T *rettv)
+static void f_argc(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = ARGCOUNT;
}
@@ -7564,13 +7268,13 @@ static void f_argc(typval_T *argvars, typval_T *rettv)
/*
* "argidx()" function
*/
-static void f_argidx(typval_T *argvars, typval_T *rettv)
+static void f_argidx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = curwin->w_arg_idx;
}
/// "arglistid" function
-static void f_arglistid(typval_T *argvars, typval_T *rettv)
+static void f_arglistid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = -1;
win_T *wp = find_tabwin(&argvars[0], &argvars[1]);
@@ -7582,7 +7286,7 @@ static void f_arglistid(typval_T *argvars, typval_T *rettv)
/*
* "argv(nr)" function
*/
-static void f_argv(typval_T *argvars, typval_T *rettv)
+static void f_argv(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int idx;
@@ -7689,19 +7393,19 @@ static void assert_equal_common(typval_T *argvars, assert_type_T atype)
}
// "assert_equal(expected, actual[, msg])" function
-static void f_assert_equal(typval_T *argvars, typval_T *rettv)
+static void f_assert_equal(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_equal_common(argvars, ASSERT_EQUAL);
}
// "assert_notequal(expected, actual[, msg])" function
-static void f_assert_notequal(typval_T *argvars, typval_T *rettv)
+static void f_assert_notequal(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_equal_common(argvars, ASSERT_NOTEQUAL);
}
/// "assert_exception(string[, msg])" function
-static void f_assert_exception(typval_T *argvars, typval_T *rettv)
+static void f_assert_exception(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
garray_T ga;
@@ -7722,7 +7426,7 @@ static void f_assert_exception(typval_T *argvars, typval_T *rettv)
}
/// "assert_fails(cmd [, error])" function
-static void f_assert_fails(typval_T *argvars, typval_T *rettv)
+static void f_assert_fails(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *cmd = get_tv_string_chk(&argvars[0]);
garray_T ga;
@@ -7782,7 +7486,7 @@ static void assert_bool(typval_T *argvars, bool is_true)
}
// "assert_false(actual[, msg])" function
-static void f_assert_false(typval_T *argvars, typval_T *rettv)
+static void f_assert_false(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_bool(argvars, false);
}
@@ -7806,43 +7510,27 @@ static void assert_match_common(typval_T *argvars, assert_type_T atype)
}
/// "assert_match(pattern, actual[, msg])" function
-static void f_assert_match(typval_T *argvars, typval_T *rettv)
+static void f_assert_match(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_match_common(argvars, ASSERT_MATCH);
}
/// "assert_notmatch(pattern, actual[, msg])" function
-static void f_assert_notmatch(typval_T *argvars, typval_T *rettv)
+static void f_assert_notmatch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_match_common(argvars, ASSERT_NOTMATCH);
}
// "assert_true(actual[, msg])" function
-static void f_assert_true(typval_T *argvars, typval_T *rettv)
+static void f_assert_true(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
assert_bool(argvars, true);
}
/*
- * "asin()" function
- */
-static void f_asin(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &asin);
-}
-
-/*
- * "atan()" function
- */
-static void f_atan(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &atan);
-}
-
-/*
* "atan2()" function
*/
-static void f_atan2(typval_T *argvars, typval_T *rettv)
+static void f_atan2(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T fx, fy;
@@ -7857,7 +7545,7 @@ static void f_atan2(typval_T *argvars, typval_T *rettv)
/*
* "browse(save, title, initdir, default)" function
*/
-static void f_browse(typval_T *argvars, typval_T *rettv)
+static void f_browse(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
@@ -7866,9 +7554,9 @@ static void f_browse(typval_T *argvars, typval_T *rettv)
/*
* "browsedir(title, initdir)" function
*/
-static void f_browsedir(typval_T *argvars, typval_T *rettv)
+static void f_browsedir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- f_browse(argvars, rettv);
+ f_browse(argvars, rettv, NULL);
}
@@ -7904,7 +7592,7 @@ static buf_T *find_buffer(typval_T *avar)
/*
* "bufexists(expr)" function
*/
-static void f_bufexists(typval_T *argvars, typval_T *rettv)
+static void f_bufexists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = (find_buffer(&argvars[0]) != NULL);
}
@@ -7912,7 +7600,7 @@ static void f_bufexists(typval_T *argvars, typval_T *rettv)
/*
* "buflisted(expr)" function
*/
-static void f_buflisted(typval_T *argvars, typval_T *rettv)
+static void f_buflisted(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
@@ -7923,7 +7611,7 @@ static void f_buflisted(typval_T *argvars, typval_T *rettv)
/*
* "bufloaded(expr)" function
*/
-static void f_bufloaded(typval_T *argvars, typval_T *rettv)
+static void f_bufloaded(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
@@ -7973,7 +7661,7 @@ static buf_T *get_buf_tv(typval_T *tv, int curtab_only)
/*
* "bufname(expr)" function
*/
-static void f_bufname(typval_T *argvars, typval_T *rettv)
+static void f_bufname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
@@ -7991,7 +7679,7 @@ static void f_bufname(typval_T *argvars, typval_T *rettv)
/*
* "bufnr(expr)" function
*/
-static void f_bufnr(typval_T *argvars, typval_T *rettv)
+static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
int error = FALSE;
@@ -8021,7 +7709,7 @@ static void f_bufnr(typval_T *argvars, typval_T *rettv)
/*
* "bufwinnr(nr)" function
*/
-static void f_bufwinnr(typval_T *argvars, typval_T *rettv)
+static void f_bufwinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
@@ -8043,7 +7731,7 @@ static void f_bufwinnr(typval_T *argvars, typval_T *rettv)
/*
* "byte2line(byte)" function
*/
-static void f_byte2line(typval_T *argvars, typval_T *rettv)
+static void f_byte2line(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long boff = 0;
@@ -8082,7 +7770,7 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
/*
* "byteidx()" function
*/
-static void f_byteidx(typval_T *argvars, typval_T *rettv)
+static void f_byteidx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
byteidx(argvars, rettv, FALSE);
}
@@ -8090,7 +7778,7 @@ static void f_byteidx(typval_T *argvars, typval_T *rettv)
/*
* "byteidxcomp()" function
*/
-static void f_byteidxcomp(typval_T *argvars, typval_T *rettv)
+static void f_byteidxcomp(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
byteidx(argvars, rettv, TRUE);
}
@@ -8130,7 +7818,7 @@ int func_call(char_u *name, typval_T *args, dict_T *selfdict, typval_T *rettv)
/*
* "call(func, arglist)" function
*/
-static void f_call(typval_T *argvars, typval_T *rettv)
+static void f_call(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *func;
dict_T *selfdict = NULL;
@@ -8161,17 +7849,9 @@ static void f_call(typval_T *argvars, typval_T *rettv)
}
/*
- * "ceil({float})" function
- */
-static void f_ceil(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &ceil);
-}
-
-/*
* "changenr()" function
*/
-static void f_changenr(typval_T *argvars, typval_T *rettv)
+static void f_changenr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = curbuf->b_u_seq_cur;
}
@@ -8179,7 +7859,7 @@ static void f_changenr(typval_T *argvars, typval_T *rettv)
/*
* "char2nr(string)" function
*/
-static void f_char2nr(typval_T *argvars, typval_T *rettv)
+static void f_char2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (has_mbyte) {
int utf8 = 0;
@@ -8198,7 +7878,7 @@ static void f_char2nr(typval_T *argvars, typval_T *rettv)
/*
* "cindent(lnum)" function
*/
-static void f_cindent(typval_T *argvars, typval_T *rettv)
+static void f_cindent(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T pos;
linenr_T lnum;
@@ -8216,7 +7896,7 @@ static void f_cindent(typval_T *argvars, typval_T *rettv)
/*
* "clearmatches()" function
*/
-static void f_clearmatches(typval_T *argvars, typval_T *rettv)
+static void f_clearmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
clear_matches(curwin);
}
@@ -8224,7 +7904,7 @@ static void f_clearmatches(typval_T *argvars, typval_T *rettv)
/*
* "col(string)" function
*/
-static void f_col(typval_T *argvars, typval_T *rettv)
+static void f_col(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
colnr_T col = 0;
pos_T *fp;
@@ -8261,7 +7941,7 @@ static void f_col(typval_T *argvars, typval_T *rettv)
/*
* "complete()" function
*/
-static void f_complete(typval_T *argvars, typval_T *rettv)
+static void f_complete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int startcol;
@@ -8290,7 +7970,7 @@ static void f_complete(typval_T *argvars, typval_T *rettv)
/*
* "complete_add()" function
*/
-static void f_complete_add(typval_T *argvars, typval_T *rettv)
+static void f_complete_add(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0);
}
@@ -8298,7 +7978,7 @@ static void f_complete_add(typval_T *argvars, typval_T *rettv)
/*
* "complete_check()" function
*/
-static void f_complete_check(typval_T *argvars, typval_T *rettv)
+static void f_complete_check(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int saved = RedrawingDisabled;
@@ -8311,7 +7991,7 @@ static void f_complete_check(typval_T *argvars, typval_T *rettv)
/*
* "confirm(message, buttons[, default [, type]])" function
*/
-static void f_confirm(typval_T *argvars, typval_T *rettv)
+static void f_confirm(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *message;
char_u *buttons = NULL;
@@ -8359,31 +8039,15 @@ static void f_confirm(typval_T *argvars, typval_T *rettv)
/*
* "copy()" function
*/
-static void f_copy(typval_T *argvars, typval_T *rettv)
+static void f_copy(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
var_item_copy(NULL, &argvars[0], rettv, false, 0);
}
/*
- * "cos()" function
- */
-static void f_cos(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &cos);
-}
-
-/*
- * "cosh()" function
- */
-static void f_cosh(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &cosh);
-}
-
-/*
* "count()" function
*/
-static void f_count(typval_T *argvars, typval_T *rettv)
+static void f_count(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long n = 0;
int ic = FALSE;
@@ -8448,7 +8112,7 @@ static void f_count(typval_T *argvars, typval_T *rettv)
*
* Checks the existence of a cscope connection.
*/
-static void f_cscope_connection(typval_T *argvars, typval_T *rettv)
+static void f_cscope_connection(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int num = 0;
char_u *dbpath = NULL;
@@ -8472,7 +8136,7 @@ static void f_cscope_connection(typval_T *argvars, typval_T *rettv)
/// Moves the cursor to the specified line and column.
///
/// @returns 0 when the position could be set, -1 otherwise.
-static void f_cursor(typval_T *argvars, typval_T *rettv)
+static void f_cursor(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long line, col;
long coladd = 0;
@@ -8528,7 +8192,7 @@ static void f_cursor(typval_T *argvars, typval_T *rettv)
/*
* "deepcopy()" function
*/
-static void f_deepcopy(typval_T *argvars, typval_T *rettv)
+static void f_deepcopy(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int noref = 0;
@@ -8544,7 +8208,7 @@ static void f_deepcopy(typval_T *argvars, typval_T *rettv)
}
// "delete()" function
-static void f_delete(typval_T *argvars, typval_T *rettv)
+static void f_delete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u nbuf[NUMBUFLEN];
char_u *name;
@@ -8582,7 +8246,7 @@ static void f_delete(typval_T *argvars, typval_T *rettv)
}
// dictwatcheradd(dict, key, funcref) function
-static void f_dictwatcheradd(typval_T *argvars, typval_T *rettv)
+static void f_dictwatcheradd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (check_restricted() || check_secure()) {
return;
@@ -8627,7 +8291,7 @@ static void f_dictwatcheradd(typval_T *argvars, typval_T *rettv)
}
// dictwatcherdel(dict, key, funcref) function
-static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv)
+static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (check_restricted() || check_secure()) {
return;
@@ -8688,7 +8352,7 @@ static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv)
/*
* "did_filetype()" function
*/
-static void f_did_filetype(typval_T *argvars, typval_T *rettv)
+static void f_did_filetype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = did_filetype;
}
@@ -8696,7 +8360,7 @@ static void f_did_filetype(typval_T *argvars, typval_T *rettv)
/*
* "diff_filler()" function
*/
-static void f_diff_filler(typval_T *argvars, typval_T *rettv)
+static void f_diff_filler(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = diff_check_fill(curwin, get_tv_lnum(argvars));
}
@@ -8704,7 +8368,7 @@ static void f_diff_filler(typval_T *argvars, typval_T *rettv)
/*
* "diff_hlID()" function
*/
-static void f_diff_hlID(typval_T *argvars, typval_T *rettv)
+static void f_diff_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum = get_tv_lnum(argvars);
static linenr_T prev_lnum = 0;
@@ -8753,7 +8417,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv)
/*
* "empty({expr})" function
*/
-static void f_empty(typval_T *argvars, typval_T *rettv)
+static void f_empty(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
bool n = true;
@@ -8791,7 +8455,7 @@ static void f_empty(typval_T *argvars, typval_T *rettv)
/*
* "escape({string}, {chars})" function
*/
-static void f_escape(typval_T *argvars, typval_T *rettv)
+static void f_escape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
@@ -8803,7 +8467,7 @@ static void f_escape(typval_T *argvars, typval_T *rettv)
/*
* "eval()" function
*/
-static void f_eval(typval_T *argvars, typval_T *rettv)
+static void f_eval(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s;
@@ -8827,7 +8491,7 @@ static void f_eval(typval_T *argvars, typval_T *rettv)
/*
* "eventhandler()" function
*/
-static void f_eventhandler(typval_T *argvars, typval_T *rettv)
+static void f_eventhandler(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = vgetc_busy;
}
@@ -8835,7 +8499,7 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv)
/*
* "executable()" function
*/
-static void f_executable(typval_T *argvars, typval_T *rettv)
+static void f_executable(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *name = get_tv_string(&argvars[0]);
@@ -8845,7 +8509,7 @@ static void f_executable(typval_T *argvars, typval_T *rettv)
}
// "execute(command)" function
-static void f_execute(typval_T *argvars, typval_T *rettv)
+static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int save_msg_silent = msg_silent;
garray_T *save_capture_ga = capture_ga;
@@ -8877,7 +8541,7 @@ static void f_execute(typval_T *argvars, typval_T *rettv)
}
/// "exepath()" function
-static void f_exepath(typval_T *argvars, typval_T *rettv)
+static void f_exepath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *arg = get_tv_string(&argvars[0]);
char_u *path = NULL;
@@ -8891,7 +8555,7 @@ static void f_exepath(typval_T *argvars, typval_T *rettv)
/*
* "exists()" function
*/
-static void f_exists(typval_T *argvars, typval_T *rettv)
+static void f_exists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p;
char_u *name;
@@ -8952,17 +8616,9 @@ static void f_exists(typval_T *argvars, typval_T *rettv)
}
/*
- * "exp()" function
- */
-static void f_exp(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &exp);
-}
-
-/*
* "expand()" function
*/
-static void f_expand(typval_T *argvars, typval_T *rettv)
+static void f_expand(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s;
size_t len;
@@ -9091,7 +8747,7 @@ void dict_extend(dict_T *d1, dict_T *d2, char_u *action)
* "extend(list, list [, idx])" function
* "extend(dict, dict [, action])" function
*/
-static void f_extend(typval_T *argvars, typval_T *rettv)
+static void f_extend(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *arg_errmsg = (char_u *)N_("extend() argument");
@@ -9163,7 +8819,7 @@ static void f_extend(typval_T *argvars, typval_T *rettv)
/*
* "feedkeys()" function
*/
-static void f_feedkeys(typval_T *argvars, typval_T *rettv)
+static void f_feedkeys(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *keys, *flags = NULL;
char_u nbuf[NUMBUFLEN];
@@ -9175,18 +8831,17 @@ static void f_feedkeys(typval_T *argvars, typval_T *rettv)
return;
keys = get_tv_string(&argvars[0]);
- if (*keys != NUL) {
- if (argvars[1].v_type != VAR_UNKNOWN) {
- flags = get_tv_string_buf(&argvars[1], nbuf);
- }
- vim_feedkeys(cstr_as_string((char *)keys),
- cstr_as_string((char *)flags), true);
+ if (argvars[1].v_type != VAR_UNKNOWN) {
+ flags = get_tv_string_buf(&argvars[1], nbuf);
}
+
+ nvim_feedkeys(cstr_as_string((char *)keys),
+ cstr_as_string((char *)flags), true);
}
/// "filereadable()" function
-static void f_filereadable(typval_T *argvars, typval_T *rettv)
+static void f_filereadable(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = get_tv_string(&argvars[0]);
rettv->vval.v_number =
@@ -9197,7 +8852,7 @@ static void f_filereadable(typval_T *argvars, typval_T *rettv)
* Return 0 for not writable, 1 for writable file, 2 for a dir which we have
* rights to write into.
*/
-static void f_filewritable(typval_T *argvars, typval_T *rettv)
+static void f_filewritable(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char *filename = (char *)get_tv_string(&argvars[0]);
rettv->vval.v_number = os_file_is_writable(filename);
@@ -9412,7 +9067,7 @@ theend:
/*
* "filter()" function
*/
-static void f_filter(typval_T *argvars, typval_T *rettv)
+static void f_filter(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
filter_map(argvars, rettv, FALSE);
}
@@ -9420,7 +9075,7 @@ static void f_filter(typval_T *argvars, typval_T *rettv)
/*
* "finddir({fname}[, {path}[, {count}]])" function
*/
-static void f_finddir(typval_T *argvars, typval_T *rettv)
+static void f_finddir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
findfilendir(argvars, rettv, FINDFILE_DIR);
}
@@ -9428,7 +9083,7 @@ static void f_finddir(typval_T *argvars, typval_T *rettv)
/*
* "findfile({fname}[, {path}[, {count}]])" function
*/
-static void f_findfile(typval_T *argvars, typval_T *rettv)
+static void f_findfile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
findfilendir(argvars, rettv, FINDFILE_FILE);
}
@@ -9436,7 +9091,7 @@ static void f_findfile(typval_T *argvars, typval_T *rettv)
/*
* "float2nr({float})" function
*/
-static void f_float2nr(typval_T *argvars, typval_T *rettv)
+static void f_float2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T f;
@@ -9451,17 +9106,9 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv)
}
/*
- * "floor({float})" function
- */
-static void f_floor(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &floor);
-}
-
-/*
* "fmod()" function
*/
-static void f_fmod(typval_T *argvars, typval_T *rettv)
+static void f_fmod(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T fx, fy;
@@ -9476,7 +9123,7 @@ static void f_fmod(typval_T *argvars, typval_T *rettv)
/*
* "fnameescape({string})" function
*/
-static void f_fnameescape(typval_T *argvars, typval_T *rettv)
+static void f_fnameescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_string = vim_strsave_fnameescape(
get_tv_string(&argvars[0]), FALSE);
@@ -9486,7 +9133,7 @@ static void f_fnameescape(typval_T *argvars, typval_T *rettv)
/*
* "fnamemodify({fname}, {mods})" function
*/
-static void f_fnamemodify(typval_T *argvars, typval_T *rettv)
+static void f_fnamemodify(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *fname;
char_u *mods;
@@ -9537,7 +9184,7 @@ static void foldclosed_both(typval_T *argvars, typval_T *rettv, int end)
/*
* "foldclosed()" function
*/
-static void f_foldclosed(typval_T *argvars, typval_T *rettv)
+static void f_foldclosed(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
foldclosed_both(argvars, rettv, FALSE);
}
@@ -9545,7 +9192,7 @@ static void f_foldclosed(typval_T *argvars, typval_T *rettv)
/*
* "foldclosedend()" function
*/
-static void f_foldclosedend(typval_T *argvars, typval_T *rettv)
+static void f_foldclosedend(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
foldclosed_both(argvars, rettv, TRUE);
}
@@ -9553,7 +9200,7 @@ static void f_foldclosedend(typval_T *argvars, typval_T *rettv)
/*
* "foldlevel()" function
*/
-static void f_foldlevel(typval_T *argvars, typval_T *rettv)
+static void f_foldlevel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
@@ -9565,7 +9212,7 @@ static void f_foldlevel(typval_T *argvars, typval_T *rettv)
/*
* "foldtext()" function
*/
-static void f_foldtext(typval_T *argvars, typval_T *rettv)
+static void f_foldtext(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
char_u *s;
@@ -9618,7 +9265,7 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv)
/*
* "foldtextresult(lnum)" function
*/
-static void f_foldtextresult(typval_T *argvars, typval_T *rettv)
+static void f_foldtextresult(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
char_u *text;
@@ -9645,14 +9292,14 @@ static void f_foldtextresult(typval_T *argvars, typval_T *rettv)
/*
* "foreground()" function
*/
-static void f_foreground(typval_T *argvars, typval_T *rettv)
+static void f_foreground(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
}
/*
* "function()" function
*/
-static void f_function(typval_T *argvars, typval_T *rettv)
+static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s;
@@ -9684,7 +9331,7 @@ static void f_function(typval_T *argvars, typval_T *rettv)
/*
* "garbagecollect()" function
*/
-static void f_garbagecollect(typval_T *argvars, typval_T *rettv)
+static void f_garbagecollect(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
/* This is postponed until we are back at the toplevel, because we may be
* using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */
@@ -9697,7 +9344,7 @@ static void f_garbagecollect(typval_T *argvars, typval_T *rettv)
/*
* "get()" function
*/
-static void f_get(typval_T *argvars, typval_T *rettv)
+static void f_get(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
listitem_T *li;
list_T *l;
@@ -9773,7 +9420,7 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli
/*
* "getbufline()" function
*/
-static void f_getbufline(typval_T *argvars, typval_T *rettv)
+static void f_getbufline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
linenr_T end;
@@ -9796,7 +9443,7 @@ static void f_getbufline(typval_T *argvars, typval_T *rettv)
/*
* "getbufvar()" function
*/
-static void f_getbufvar(typval_T *argvars, typval_T *rettv)
+static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
buf_T *save_curbuf;
@@ -9849,7 +9496,7 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv)
/*
* "getchar()" function
*/
-static void f_getchar(typval_T *argvars, typval_T *rettv)
+static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
varnumber_T n;
int error = FALSE;
@@ -9933,7 +9580,7 @@ static void f_getchar(typval_T *argvars, typval_T *rettv)
/*
* "getcharmod()" function
*/
-static void f_getcharmod(typval_T *argvars, typval_T *rettv)
+static void f_getcharmod(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = mod_mask;
}
@@ -9941,7 +9588,7 @@ static void f_getcharmod(typval_T *argvars, typval_T *rettv)
/*
* "getcharsearch()" function
*/
-static void f_getcharsearch(typval_T *argvars, typval_T *rettv)
+static void f_getcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_dict_alloc(rettv);
@@ -9955,7 +9602,7 @@ static void f_getcharsearch(typval_T *argvars, typval_T *rettv)
/*
* "getcmdline()" function
*/
-static void f_getcmdline(typval_T *argvars, typval_T *rettv)
+static void f_getcmdline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_cmdline_str();
@@ -9964,7 +9611,7 @@ static void f_getcmdline(typval_T *argvars, typval_T *rettv)
/*
* "getcmdpos()" function
*/
-static void f_getcmdpos(typval_T *argvars, typval_T *rettv)
+static void f_getcmdpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = get_cmdline_pos() + 1;
}
@@ -9972,7 +9619,7 @@ static void f_getcmdpos(typval_T *argvars, typval_T *rettv)
/*
* "getcmdtype()" function
*/
-static void f_getcmdtype(typval_T *argvars, typval_T *rettv)
+static void f_getcmdtype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = xmallocz(1);
@@ -9982,7 +9629,7 @@ static void f_getcmdtype(typval_T *argvars, typval_T *rettv)
/*
* "getcmdwintype()" function
*/
-static void f_getcmdwintype(typval_T *argvars, typval_T *rettv)
+static void f_getcmdwintype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -9991,7 +9638,7 @@ static void f_getcmdwintype(typval_T *argvars, typval_T *rettv)
}
// "getcompletion()" function
-static void f_getcompletion(typval_T *argvars, typval_T *rettv)
+static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *pat;
expand_T xpc;
@@ -10021,12 +9668,11 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv)
}
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
- if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL)) {
- int i;
-
+ rettv_list_alloc(rettv);
+ if (pat != NULL) {
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
- for (i = 0; i < xpc.xp_numfiles; i++) {
+ for (int i = 0; i < xpc.xp_numfiles; i++) {
list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
}
}
@@ -10043,7 +9689,7 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv)
/// @pre An argument may not be -1 if preceding arguments are not all -1.
///
/// @post The return value will be a string.
-static void f_getcwd(typval_T *argvars, typval_T *rettv)
+static void f_getcwd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
// Possible scope of working directory to return.
CdScope scope = kCdScopeInvalid;
@@ -10128,26 +9774,20 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv)
if (from) {
break;
}
- case kCdScopeTab: // FALLTHROUGH
+ case kCdScopeTab: // FALLTHROUGH
assert(tp);
from = tp->localdir;
if (from) {
break;
}
- case kCdScopeGlobal: // FALLTHROUGH
- // The `globaldir` variable is not always set.
- if (globaldir) {
+ case kCdScopeGlobal: // FALLTHROUGH
+ if (globaldir) { // `globaldir` is not always set.
from = globaldir;
- } else {
- // We have to copy the OS path directly into output string.
- if (os_dirname(cwd, MAXPATHL) == FAIL) {
- EMSG(_("E41: Could not display path."));
- goto end;
- }
+ } else if (os_dirname(cwd, MAXPATHL) == FAIL) { // Get the OS CWD.
+ from = (char_u *)""; // Return empty string on failure.
}
break;
- case kCdScopeInvalid:
- // We should never get here
+ case kCdScopeInvalid: // We should never get here
assert(false);
}
@@ -10159,14 +9799,14 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv)
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(rettv->vval.v_string);
#endif
-end:
+
xfree(cwd);
}
/*
* "getfontname()" function
*/
-static void f_getfontname(typval_T *argvars, typval_T *rettv)
+static void f_getfontname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -10175,7 +9815,7 @@ static void f_getfontname(typval_T *argvars, typval_T *rettv)
/*
* "getfperm({fname})" function
*/
-static void f_getfperm(typval_T *argvars, typval_T *rettv)
+static void f_getfperm(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *perm = NULL;
char_u flags[] = "rwx";
@@ -10196,7 +9836,7 @@ static void f_getfperm(typval_T *argvars, typval_T *rettv)
/*
* "getfsize({fname})" function
*/
-static void f_getfsize(typval_T *argvars, typval_T *rettv)
+static void f_getfsize(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char *fname = (char *)get_tv_string(&argvars[0]);
@@ -10223,7 +9863,7 @@ static void f_getfsize(typval_T *argvars, typval_T *rettv)
/*
* "getftime({fname})" function
*/
-static void f_getftime(typval_T *argvars, typval_T *rettv)
+static void f_getftime(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char *fname = (char *)get_tv_string(&argvars[0]);
@@ -10238,7 +9878,7 @@ static void f_getftime(typval_T *argvars, typval_T *rettv)
/*
* "getftype({fname})" function
*/
-static void f_getftype(typval_T *argvars, typval_T *rettv)
+static void f_getftype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *fname;
char_u *type = NULL;
@@ -10314,7 +9954,7 @@ static void f_getftype(typval_T *argvars, typval_T *rettv)
/*
* "getline(lnum, [end])" function
*/
-static void f_getline(typval_T *argvars, typval_T *rettv)
+static void f_getline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
linenr_T end;
@@ -10335,7 +9975,7 @@ static void f_getline(typval_T *argvars, typval_T *rettv)
/*
* "getmatches()" function
*/
-static void f_getmatches(typval_T *argvars, typval_T *rettv)
+static void f_getmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
matchitem_T *cur = curwin->w_match_head;
int i;
@@ -10384,7 +10024,7 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv)
/*
* "getpid()" function
*/
-static void f_getpid(typval_T *argvars, typval_T *rettv)
+static void f_getpid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = os_get_pid();
}
@@ -10420,7 +10060,7 @@ static void getpos_both(typval_T *argvars, typval_T *rettv, bool getcurpos)
/*
* "getcurpos(string)" function
*/
-static void f_getcurpos(typval_T *argvars, typval_T *rettv)
+static void f_getcurpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
getpos_both(argvars, rettv, true);
}
@@ -10428,7 +10068,7 @@ static void f_getcurpos(typval_T *argvars, typval_T *rettv)
/*
* "getpos(string)" function
*/
-static void f_getpos(typval_T *argvars, typval_T *rettv)
+static void f_getpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
getpos_both(argvars, rettv, false);
}
@@ -10436,7 +10076,7 @@ static void f_getpos(typval_T *argvars, typval_T *rettv)
/*
* "getqflist()" and "getloclist()" functions
*/
-static void f_getqflist(typval_T *argvars, typval_T *rettv)
+static void f_getqflist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_list_alloc(rettv);
win_T *wp = NULL;
@@ -10450,7 +10090,7 @@ static void f_getqflist(typval_T *argvars, typval_T *rettv)
}
/// "getreg()" function
-static void f_getreg(typval_T *argvars, typval_T *rettv)
+static void f_getreg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *strregname;
int regname;
@@ -10496,7 +10136,7 @@ static void f_getreg(typval_T *argvars, typval_T *rettv)
/*
* "getregtype()" function
*/
-static void f_getregtype(typval_T *argvars, typval_T *rettv)
+static void f_getregtype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *strregname;
int regname;
@@ -10528,7 +10168,7 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
/*
* "gettabvar()" function
*/
-static void f_gettabvar(typval_T *argvars, typval_T *rettv)
+static void f_gettabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *oldcurwin;
tabpage_T *tp, *oldtabpage;
@@ -10567,7 +10207,7 @@ static void f_gettabvar(typval_T *argvars, typval_T *rettv)
/*
* "gettabwinvar()" function
*/
-static void f_gettabwinvar(typval_T *argvars, typval_T *rettv)
+static void f_gettabwinvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
getwinvar(argvars, rettv, 1);
}
@@ -10575,7 +10215,7 @@ static void f_gettabwinvar(typval_T *argvars, typval_T *rettv)
/*
* "getwinposx()" function
*/
-static void f_getwinposx(typval_T *argvars, typval_T *rettv)
+static void f_getwinposx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = -1;
}
@@ -10583,7 +10223,7 @@ static void f_getwinposx(typval_T *argvars, typval_T *rettv)
/*
* "getwinposy()" function
*/
-static void f_getwinposy(typval_T *argvars, typval_T *rettv)
+static void f_getwinposy(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = -1;
}
@@ -10647,7 +10287,7 @@ static win_T *find_tabwin(typval_T *wvp, typval_T *tvp)
}
/// "getwinvar()" function
-static void f_getwinvar(typval_T *argvars, typval_T *rettv)
+static void f_getwinvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
getwinvar(argvars, rettv, 0);
}
@@ -10718,7 +10358,7 @@ getwinvar (
/*
* "glob()" function
*/
-static void f_glob(typval_T *argvars, typval_T *rettv)
+static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int options = WILD_SILENT|WILD_USE_NL;
expand_T xpc;
@@ -10762,7 +10402,7 @@ static void f_glob(typval_T *argvars, typval_T *rettv)
}
/// "globpath()" function
-static void f_globpath(typval_T *argvars, typval_T *rettv)
+static void f_globpath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int flags = 0; // Flags for globpath.
int error = false;
@@ -10813,7 +10453,7 @@ static void f_globpath(typval_T *argvars, typval_T *rettv)
}
// "glob2regpat()" function
-static void f_glob2regpat(typval_T *argvars, typval_T *rettv)
+static void f_glob2regpat(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error
@@ -10826,7 +10466,7 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv)
/*
* "has()" function
*/
-static void f_has(typval_T *argvars, typval_T *rettv)
+static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int i;
char_u *name;
@@ -10994,7 +10634,7 @@ static void f_has(typval_T *argvars, typval_T *rettv)
/*
* "has_key()" function
*/
-static void f_has_key(typval_T *argvars, typval_T *rettv)
+static void f_has_key(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (argvars[0].v_type != VAR_DICT) {
EMSG(_(e_dictreq));
@@ -11018,7 +10658,7 @@ static void f_has_key(typval_T *argvars, typval_T *rettv)
/// @pre An argument may not be -1 if preceding arguments are not all -1.
///
/// @post The return value will be either the number `1` or `0`.
-static void f_haslocaldir(typval_T *argvars, typval_T *rettv)
+static void f_haslocaldir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
// Possible scope of working directory to return.
CdScope scope = kCdScopeInvalid;
@@ -11111,7 +10751,7 @@ static void f_haslocaldir(typval_T *argvars, typval_T *rettv)
/*
* "hasmapto()" function
*/
-static void f_hasmapto(typval_T *argvars, typval_T *rettv)
+static void f_hasmapto(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *name;
char_u *mode;
@@ -11136,7 +10776,7 @@ static void f_hasmapto(typval_T *argvars, typval_T *rettv)
/*
* "histadd()" function
*/
-static void f_histadd(typval_T *argvars, typval_T *rettv)
+static void f_histadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
HistoryType histype;
char_u *str;
@@ -11162,7 +10802,7 @@ static void f_histadd(typval_T *argvars, typval_T *rettv)
/*
* "histdel()" function
*/
-static void f_histdel(typval_T *argvars, typval_T *rettv)
+static void f_histdel(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int n;
char_u buf[NUMBUFLEN];
@@ -11189,7 +10829,7 @@ static void f_histdel(typval_T *argvars, typval_T *rettv)
/*
* "histget()" function
*/
-static void f_histget(typval_T *argvars, typval_T *rettv)
+static void f_histget(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
HistoryType type;
int idx;
@@ -11214,7 +10854,7 @@ static void f_histget(typval_T *argvars, typval_T *rettv)
/*
* "histnr()" function
*/
-static void f_histnr(typval_T *argvars, typval_T *rettv)
+static void f_histnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int i;
@@ -11233,7 +10873,7 @@ static void f_histnr(typval_T *argvars, typval_T *rettv)
/*
* "highlightID(name)" function
*/
-static void f_hlID(typval_T *argvars, typval_T *rettv)
+static void f_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = syn_name2id(get_tv_string(&argvars[0]));
}
@@ -11241,7 +10881,7 @@ static void f_hlID(typval_T *argvars, typval_T *rettv)
/*
* "highlight_exists()" function
*/
-static void f_hlexists(typval_T *argvars, typval_T *rettv)
+static void f_hlexists(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = highlight_exists(get_tv_string(&argvars[0]));
}
@@ -11249,7 +10889,7 @@ static void f_hlexists(typval_T *argvars, typval_T *rettv)
/*
* "hostname()" function
*/
-static void f_hostname(typval_T *argvars, typval_T *rettv)
+static void f_hostname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char hostname[256];
@@ -11261,7 +10901,7 @@ static void f_hostname(typval_T *argvars, typval_T *rettv)
/*
* iconv() function
*/
-static void f_iconv(typval_T *argvars, typval_T *rettv)
+static void f_iconv(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf1[NUMBUFLEN];
char_u buf2[NUMBUFLEN];
@@ -11291,7 +10931,7 @@ static void f_iconv(typval_T *argvars, typval_T *rettv)
/*
* "indent()" function
*/
-static void f_indent(typval_T *argvars, typval_T *rettv)
+static void f_indent(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
@@ -11305,7 +10945,7 @@ static void f_indent(typval_T *argvars, typval_T *rettv)
/*
* "index()" function
*/
-static void f_index(typval_T *argvars, typval_T *rettv)
+static void f_index(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
list_T *l;
listitem_T *item;
@@ -11436,7 +11076,7 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog)
* "input()" function
* Also handles inputsecret() when inputsecret is set.
*/
-static void f_input(typval_T *argvars, typval_T *rettv)
+static void f_input(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_user_input(argvars, rettv, FALSE);
}
@@ -11444,7 +11084,7 @@ static void f_input(typval_T *argvars, typval_T *rettv)
/*
* "inputdialog()" function
*/
-static void f_inputdialog(typval_T *argvars, typval_T *rettv)
+static void f_inputdialog(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_user_input(argvars, rettv, TRUE);
}
@@ -11452,7 +11092,7 @@ static void f_inputdialog(typval_T *argvars, typval_T *rettv)
/*
* "inputlist()" function
*/
-static void f_inputlist(typval_T *argvars, typval_T *rettv)
+static void f_inputlist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
listitem_T *li;
int selected;
@@ -11488,7 +11128,7 @@ static garray_T ga_userinput = {0, 0, sizeof(tasave_T), 4, NULL};
/*
* "inputrestore()" function
*/
-static void f_inputrestore(typval_T *argvars, typval_T *rettv)
+static void f_inputrestore(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (!GA_EMPTY(&ga_userinput)) {
--ga_userinput.ga_len;
@@ -11504,7 +11144,7 @@ static void f_inputrestore(typval_T *argvars, typval_T *rettv)
/*
* "inputsave()" function
*/
-static void f_inputsave(typval_T *argvars, typval_T *rettv)
+static void f_inputsave(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
// Add an entry to the stack of typeahead storage.
tasave_T *p = GA_APPEND_VIA_PTR(tasave_T, &ga_userinput);
@@ -11514,19 +11154,19 @@ static void f_inputsave(typval_T *argvars, typval_T *rettv)
/*
* "inputsecret()" function
*/
-static void f_inputsecret(typval_T *argvars, typval_T *rettv)
+static void f_inputsecret(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- ++cmdline_star;
- ++inputsecret_flag;
- f_input(argvars, rettv);
- --cmdline_star;
- --inputsecret_flag;
+ cmdline_star++;
+ inputsecret_flag++;
+ f_input(argvars, rettv, NULL);
+ cmdline_star--;
+ inputsecret_flag--;
}
/*
* "insert()" function
*/
-static void f_insert(typval_T *argvars, typval_T *rettv)
+static void f_insert(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long before = 0;
listitem_T *item;
@@ -11565,7 +11205,7 @@ static void f_insert(typval_T *argvars, typval_T *rettv)
/*
* "invert(expr)" function
*/
-static void f_invert(typval_T *argvars, typval_T *rettv)
+static void f_invert(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = ~get_tv_number_chk(&argvars[0], NULL);
}
@@ -11573,7 +11213,7 @@ static void f_invert(typval_T *argvars, typval_T *rettv)
/*
* "isdirectory()" function
*/
-static void f_isdirectory(typval_T *argvars, typval_T *rettv)
+static void f_isdirectory(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = os_isdir(get_tv_string(&argvars[0]));
}
@@ -11581,7 +11221,7 @@ static void f_isdirectory(typval_T *argvars, typval_T *rettv)
/*
* "islocked()" function
*/
-static void f_islocked(typval_T *argvars, typval_T *rettv)
+static void f_islocked(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
lval_T lv;
char_u *end;
@@ -11693,13 +11333,13 @@ static void dict_list(typval_T *argvars, typval_T *rettv, int what)
/*
* "items(dict)" function
*/
-static void f_items(typval_T *argvars, typval_T *rettv)
+static void f_items(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_list(argvars, rettv, 2);
}
// "jobclose(id[, stream])" function
-static void f_jobclose(typval_T *argvars, typval_T *rettv)
+static void f_jobclose(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -11758,7 +11398,7 @@ static void f_jobclose(typval_T *argvars, typval_T *rettv)
}
// "jobpid(id)" function
-static void f_jobpid(typval_T *argvars, typval_T *rettv)
+static void f_jobpid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -11783,7 +11423,7 @@ static void f_jobpid(typval_T *argvars, typval_T *rettv)
}
// "jobsend()" function
-static void f_jobsend(typval_T *argvars, typval_T *rettv)
+static void f_jobsend(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -11828,7 +11468,7 @@ static void f_jobsend(typval_T *argvars, typval_T *rettv)
}
// "jobresize(job, width, height)" function
-static void f_jobresize(typval_T *argvars, typval_T *rettv)
+static void f_jobresize(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -11915,7 +11555,7 @@ static char **tv_to_argv(typval_T *cmd_tv, char **cmd)
}
// "jobstart()" function
-static void f_jobstart(typval_T *argvars, typval_T *rettv)
+static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -11999,7 +11639,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv)
}
// "jobstop()" function
-static void f_jobstop(typval_T *argvars, typval_T *rettv)
+static void f_jobstop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -12027,7 +11667,7 @@ static void f_jobstop(typval_T *argvars, typval_T *rettv)
}
// "jobwait(ids[, timeout])" function
-static void f_jobwait(typval_T *argvars, typval_T *rettv)
+static void f_jobwait(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -12137,7 +11777,7 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv)
/*
* "join()" function
*/
-static void f_join(typval_T *argvars, typval_T *rettv)
+static void f_join(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
garray_T ga;
char_u *sep;
@@ -12165,7 +11805,7 @@ static void f_join(typval_T *argvars, typval_T *rettv)
}
/// json_decode() function
-static void f_json_decode(typval_T *argvars, typval_T *rettv)
+static void f_json_decode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char numbuf[NUMBUFLEN];
char *s = NULL;
@@ -12199,7 +11839,7 @@ static void f_json_decode(typval_T *argvars, typval_T *rettv)
}
/// json_encode() function
-static void f_json_encode(typval_T *argvars, typval_T *rettv)
+static void f_json_encode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (char_u *) encode_tv2json(&argvars[0], NULL);
@@ -12208,7 +11848,7 @@ static void f_json_encode(typval_T *argvars, typval_T *rettv)
/*
* "keys()" function
*/
-static void f_keys(typval_T *argvars, typval_T *rettv)
+static void f_keys(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_list(argvars, rettv, 0);
}
@@ -12216,7 +11856,7 @@ static void f_keys(typval_T *argvars, typval_T *rettv)
/*
* "last_buffer_nr()" function.
*/
-static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv)
+static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int n = 0;
@@ -12232,7 +11872,7 @@ static void f_last_buffer_nr(typval_T *argvars, typval_T *rettv)
/*
* "len()" function
*/
-static void f_len(typval_T *argvars, typval_T *rettv)
+static void f_len(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
switch (argvars[0].v_type) {
case VAR_STRING:
@@ -12303,7 +11943,7 @@ static void libcall_common(typval_T *argvars, typval_T *rettv, int out_type)
/*
* "libcall()" function
*/
-static void f_libcall(typval_T *argvars, typval_T *rettv)
+static void f_libcall(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
libcall_common(argvars, rettv, VAR_STRING);
}
@@ -12311,7 +11951,7 @@ static void f_libcall(typval_T *argvars, typval_T *rettv)
/*
* "libcallnr()" function
*/
-static void f_libcallnr(typval_T *argvars, typval_T *rettv)
+static void f_libcallnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
libcall_common(argvars, rettv, VAR_NUMBER);
}
@@ -12319,7 +11959,7 @@ static void f_libcallnr(typval_T *argvars, typval_T *rettv)
/*
* "line(string)" function
*/
-static void f_line(typval_T *argvars, typval_T *rettv)
+static void f_line(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum = 0;
pos_T *fp;
@@ -12334,7 +11974,7 @@ static void f_line(typval_T *argvars, typval_T *rettv)
/*
* "line2byte(lnum)" function
*/
-static void f_line2byte(typval_T *argvars, typval_T *rettv)
+static void f_line2byte(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
@@ -12350,7 +11990,7 @@ static void f_line2byte(typval_T *argvars, typval_T *rettv)
/*
* "lispindent(lnum)" function
*/
-static void f_lispindent(typval_T *argvars, typval_T *rettv)
+static void f_lispindent(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T pos;
linenr_T lnum;
@@ -12368,7 +12008,7 @@ static void f_lispindent(typval_T *argvars, typval_T *rettv)
/*
* "localtime()" function
*/
-static void f_localtime(typval_T *argvars, typval_T *rettv)
+static void f_localtime(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = (varnumber_T)time(NULL);
}
@@ -12444,26 +12084,9 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
}
/*
- * "log()" function
- */
-static void f_log(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &log);
-}
-
-/*
- * "log10()" function
- */
-static void f_log10(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &log10);
-}
-
-
-/*
* "map()" function
*/
-static void f_map(typval_T *argvars, typval_T *rettv)
+static void f_map(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
filter_map(argvars, rettv, TRUE);
}
@@ -12471,7 +12094,7 @@ static void f_map(typval_T *argvars, typval_T *rettv)
/*
* "maparg()" function
*/
-static void f_maparg(typval_T *argvars, typval_T *rettv)
+static void f_maparg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_maparg(argvars, rettv, TRUE);
}
@@ -12479,7 +12102,7 @@ static void f_maparg(typval_T *argvars, typval_T *rettv)
/*
* "mapcheck()" function
*/
-static void f_mapcheck(typval_T *argvars, typval_T *rettv)
+static void f_mapcheck(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_maparg(argvars, rettv, FALSE);
}
@@ -12644,7 +12267,7 @@ theend:
/*
* "match()" function
*/
-static void f_match(typval_T *argvars, typval_T *rettv)
+static void f_match(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
find_some_match(argvars, rettv, 1);
}
@@ -12652,7 +12275,7 @@ static void f_match(typval_T *argvars, typval_T *rettv)
/*
* "matchadd()" function
*/
-static void f_matchadd(typval_T *argvars, typval_T *rettv)
+static void f_matchadd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
char_u *grp = get_tv_string_buf_chk(&argvars[0], buf); /* group */
@@ -12695,7 +12318,7 @@ static void f_matchadd(typval_T *argvars, typval_T *rettv)
conceal_char);
}
-static void f_matchaddpos(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ALL
+static void f_matchaddpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = -1;
@@ -12756,7 +12379,7 @@ static void f_matchaddpos(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_
/*
* "matcharg()" function
*/
-static void f_matcharg(typval_T *argvars, typval_T *rettv)
+static void f_matcharg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_list_alloc(rettv);
@@ -12778,7 +12401,7 @@ static void f_matcharg(typval_T *argvars, typval_T *rettv)
/*
* "matchdelete()" function
*/
-static void f_matchdelete(typval_T *argvars, typval_T *rettv)
+static void f_matchdelete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = match_delete(curwin,
(int)get_tv_number(&argvars[0]), TRUE);
@@ -12787,7 +12410,7 @@ static void f_matchdelete(typval_T *argvars, typval_T *rettv)
/*
* "matchend()" function
*/
-static void f_matchend(typval_T *argvars, typval_T *rettv)
+static void f_matchend(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
find_some_match(argvars, rettv, 0);
}
@@ -12795,7 +12418,7 @@ static void f_matchend(typval_T *argvars, typval_T *rettv)
/*
* "matchlist()" function
*/
-static void f_matchlist(typval_T *argvars, typval_T *rettv)
+static void f_matchlist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
find_some_match(argvars, rettv, 3);
}
@@ -12803,7 +12426,7 @@ static void f_matchlist(typval_T *argvars, typval_T *rettv)
/*
* "matchstr()" function
*/
-static void f_matchstr(typval_T *argvars, typval_T *rettv)
+static void f_matchstr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
find_some_match(argvars, rettv, 2);
}
@@ -12863,7 +12486,7 @@ static void max_min(typval_T *argvars, typval_T *rettv, int domax)
/*
* "max()" function
*/
-static void f_max(typval_T *argvars, typval_T *rettv)
+static void f_max(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
max_min(argvars, rettv, TRUE);
}
@@ -12871,7 +12494,7 @@ static void f_max(typval_T *argvars, typval_T *rettv)
/*
* "min()" function
*/
-static void f_min(typval_T *argvars, typval_T *rettv)
+static void f_min(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
max_min(argvars, rettv, FALSE);
}
@@ -12879,7 +12502,7 @@ static void f_min(typval_T *argvars, typval_T *rettv)
/*
* "mkdir()" function
*/
-static void f_mkdir(typval_T *argvars, typval_T *rettv)
+static void f_mkdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *dir;
char_u buf[NUMBUFLEN];
@@ -12921,7 +12544,7 @@ static void f_mkdir(typval_T *argvars, typval_T *rettv)
/*
* "mode()" function
*/
-static void f_mode(typval_T *argvars, typval_T *rettv)
+static void f_mode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[3];
@@ -12975,7 +12598,7 @@ static void f_mode(typval_T *argvars, typval_T *rettv)
}
/// "msgpackdump()" function
-static void f_msgpackdump(typval_T *argvars, typval_T *rettv)
+static void f_msgpackdump(typval_T *argvars, typval_T *rettv, FunPtr fptr)
FUNC_ATTR_NONNULL_ALL
{
if (argvars[0].v_type != VAR_LIST) {
@@ -13003,7 +12626,7 @@ static void f_msgpackdump(typval_T *argvars, typval_T *rettv)
}
/// "msgpackparse" function
-static void f_msgpackparse(typval_T *argvars, typval_T *rettv)
+static void f_msgpackparse(typval_T *argvars, typval_T *rettv, FunPtr fptr)
FUNC_ATTR_NONNULL_ALL
{
if (argvars[0].v_type != VAR_LIST) {
@@ -13084,7 +12707,7 @@ f_msgpackparse_exit:
/*
* "nextnonblank()" function
*/
-static void f_nextnonblank(typval_T *argvars, typval_T *rettv)
+static void f_nextnonblank(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
@@ -13102,7 +12725,7 @@ static void f_nextnonblank(typval_T *argvars, typval_T *rettv)
/*
* "nr2char()" function
*/
-static void f_nr2char(typval_T *argvars, typval_T *rettv)
+static void f_nr2char(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
@@ -13126,7 +12749,7 @@ static void f_nr2char(typval_T *argvars, typval_T *rettv)
/*
* "or(expr, expr)" function
*/
-static void f_or(typval_T *argvars, typval_T *rettv)
+static void f_or(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
| get_tv_number_chk(&argvars[1], NULL);
@@ -13135,7 +12758,7 @@ static void f_or(typval_T *argvars, typval_T *rettv)
/*
* "pathshorten()" function
*/
-static void f_pathshorten(typval_T *argvars, typval_T *rettv)
+static void f_pathshorten(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_tv_string_chk(&argvars[0]);
@@ -13148,7 +12771,7 @@ static void f_pathshorten(typval_T *argvars, typval_T *rettv)
/*
* "pow()" function
*/
-static void f_pow(typval_T *argvars, typval_T *rettv)
+static void f_pow(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
float_T fx, fy;
@@ -13163,7 +12786,7 @@ static void f_pow(typval_T *argvars, typval_T *rettv)
/*
* "prevnonblank()" function
*/
-static void f_prevnonblank(typval_T *argvars, typval_T *rettv)
+static void f_prevnonblank(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
@@ -13185,7 +12808,7 @@ static va_list ap;
/*
* "printf()" function
*/
-static void f_printf(typval_T *argvars, typval_T *rettv)
+static void f_printf(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -13211,7 +12834,7 @@ static void f_printf(typval_T *argvars, typval_T *rettv)
/*
* "pumvisible()" function
*/
-static void f_pumvisible(typval_T *argvars, typval_T *rettv)
+static void f_pumvisible(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (pum_visible())
rettv->vval.v_number = 1;
@@ -13220,7 +12843,7 @@ static void f_pumvisible(typval_T *argvars, typval_T *rettv)
/*
* "pyeval()" function
*/
-static void f_pyeval(typval_T *argvars, typval_T *rettv)
+static void f_pyeval(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
script_host_eval("python", argvars, rettv);
}
@@ -13228,7 +12851,7 @@ static void f_pyeval(typval_T *argvars, typval_T *rettv)
/*
* "py3eval()" function
*/
-static void f_py3eval(typval_T *argvars, typval_T *rettv)
+static void f_py3eval(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
script_host_eval("python3", argvars, rettv);
}
@@ -13236,7 +12859,7 @@ static void f_py3eval(typval_T *argvars, typval_T *rettv)
/*
* "range()" function
*/
-static void f_range(typval_T *argvars, typval_T *rettv)
+static void f_range(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long start;
long end;
@@ -13271,7 +12894,7 @@ static void f_range(typval_T *argvars, typval_T *rettv)
/*
* "readfile()" function
*/
-static void f_readfile(typval_T *argvars, typval_T *rettv)
+static void f_readfile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int binary = FALSE;
char_u *fname;
@@ -13470,7 +13093,7 @@ static int list2proftime(typval_T *arg, proftime_T *tm) FUNC_ATTR_NONNULL_ALL
/// one argument it returns the time passed since the argument.
/// With two arguments it returns the time passed between
/// the two arguments.
-static void f_reltime(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ALL
+static void f_reltime(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
proftime_T res;
proftime_T start;
@@ -13516,7 +13139,7 @@ static void f_reltime(typval_T *argvars, typval_T *rettv) FUNC_ATTR_NONNULL_ALL
/// @return The string representation of the argument, the format is the
/// number of seconds followed by a dot, followed by the number
/// of microseconds.
-static void f_reltimestr(typval_T *argvars, typval_T *rettv)
+static void f_reltimestr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
FUNC_ATTR_NONNULL_ALL
{
proftime_T tm;
@@ -13531,7 +13154,7 @@ static void f_reltimestr(typval_T *argvars, typval_T *rettv)
/*
* "remove()" function
*/
-static void f_remove(typval_T *argvars, typval_T *rettv)
+static void f_remove(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
list_T *l;
listitem_T *item, *item2;
@@ -13616,7 +13239,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv)
/*
* "rename({from}, {to})" function
*/
-static void f_rename(typval_T *argvars, typval_T *rettv)
+static void f_rename(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
@@ -13630,7 +13253,7 @@ static void f_rename(typval_T *argvars, typval_T *rettv)
/*
* "repeat()" function
*/
-static void f_repeat(typval_T *argvars, typval_T *rettv)
+static void f_repeat(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p;
int n;
@@ -13664,7 +13287,7 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
/*
* "resolve()" function
*/
-static void f_resolve(typval_T *argvars, typval_T *rettv)
+static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p;
#ifdef HAVE_READLINK
@@ -13838,7 +13461,7 @@ fail:
/*
* "reverse({list})" function
*/
-static void f_reverse(typval_T *argvars, typval_T *rettv)
+static void f_reverse(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
list_T *l;
listitem_T *li, *ni;
@@ -14009,16 +13632,8 @@ theend:
return retval;
}
-/*
- * "round({float})" function
- */
-static void f_round(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &round);
-}
-
// "rpcnotify()" function
-static void f_rpcnotify(typval_T *argvars, typval_T *rettv)
+static void f_rpcnotify(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -14054,7 +13669,7 @@ static void f_rpcnotify(typval_T *argvars, typval_T *rettv)
}
// "rpcrequest()" function
-static void f_rpcrequest(typval_T *argvars, typval_T *rettv)
+static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -14127,7 +13742,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv)
}
if (err.set) {
- vim_report_error(cstr_as_string(err.msg));
+ nvim_err_writeln(cstr_as_string(err.msg));
goto end;
}
@@ -14140,7 +13755,7 @@ end:
}
// "rpcstart()" function (DEPRECATED)
-static void f_rpcstart(typval_T *argvars, typval_T *rettv)
+static void f_rpcstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
@@ -14199,8 +13814,15 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv)
}
// "rpcstop()" function
-static void f_rpcstop(typval_T *argvars, typval_T *rettv)
+static void f_rpcstop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
+ rettv->v_type = VAR_NUMBER;
+ rettv->vval.v_number = 0;
+
+ if (check_restricted() || check_secure()) {
+ return;
+ }
+
if (argvars[0].v_type != VAR_NUMBER) {
// Wrong argument types
EMSG(_(e_invarg));
@@ -14209,7 +13831,7 @@ static void f_rpcstop(typval_T *argvars, typval_T *rettv)
// if called with a job, stop it, else closes the channel
if (pmap_get(uint64_t)(jobs, argvars[0].vval.v_number)) {
- f_jobstop(argvars, rettv);
+ f_jobstop(argvars, rettv, NULL);
} else {
rettv->vval.v_number = channel_close(argvars[0].vval.v_number);
}
@@ -14218,7 +13840,7 @@ static void f_rpcstop(typval_T *argvars, typval_T *rettv)
/*
* "screenattr()" function
*/
-static void f_screenattr(typval_T *argvars, typval_T *rettv)
+static void f_screenattr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int row;
int col;
@@ -14237,7 +13859,7 @@ static void f_screenattr(typval_T *argvars, typval_T *rettv)
/*
* "screenchar()" function
*/
-static void f_screenchar(typval_T *argvars, typval_T *rettv)
+static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int row;
int col;
@@ -14264,7 +13886,7 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv)
*
* First column is 1 to be consistent with virtcol().
*/
-static void f_screencol(typval_T *argvars, typval_T *rettv)
+static void f_screencol(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = ui_current_col() + 1;
}
@@ -14272,7 +13894,7 @@ static void f_screencol(typval_T *argvars, typval_T *rettv)
/*
* "screenrow()" function
*/
-static void f_screenrow(typval_T *argvars, typval_T *rettv)
+static void f_screenrow(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = ui_current_row() + 1;
}
@@ -14280,7 +13902,7 @@ static void f_screenrow(typval_T *argvars, typval_T *rettv)
/*
* "search()" function
*/
-static void f_search(typval_T *argvars, typval_T *rettv)
+static void f_search(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int flags = 0;
@@ -14290,7 +13912,7 @@ static void f_search(typval_T *argvars, typval_T *rettv)
/*
* "searchdecl()" function
*/
-static void f_searchdecl(typval_T *argvars, typval_T *rettv)
+static void f_searchdecl(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int locally = 1;
int thisblock = 0;
@@ -14383,7 +14005,7 @@ theend:
/*
* "searchpair()" function
*/
-static void f_searchpair(typval_T *argvars, typval_T *rettv)
+static void f_searchpair(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = searchpair_cmn(argvars, NULL);
}
@@ -14391,7 +14013,7 @@ static void f_searchpair(typval_T *argvars, typval_T *rettv)
/*
* "searchpairpos()" function
*/
-static void f_searchpairpos(typval_T *argvars, typval_T *rettv)
+static void f_searchpairpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T match_pos;
int lnum = 0;
@@ -14556,7 +14178,7 @@ do_searchpair (
/*
* "searchpos()" function
*/
-static void f_searchpos(typval_T *argvars, typval_T *rettv)
+static void f_searchpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T match_pos;
int lnum = 0;
@@ -14579,7 +14201,7 @@ static void f_searchpos(typval_T *argvars, typval_T *rettv)
}
/// "serverlist()" function
-static void f_serverlist(typval_T *argvars, typval_T *rettv)
+static void f_serverlist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
size_t n;
char **addrs = server_address_list(&n);
@@ -14597,7 +14219,7 @@ static void f_serverlist(typval_T *argvars, typval_T *rettv)
}
/// "serverstart()" function
-static void f_serverstart(typval_T *argvars, typval_T *rettv)
+static void f_serverstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; // Address of the new server
@@ -14625,7 +14247,7 @@ static void f_serverstart(typval_T *argvars, typval_T *rettv)
}
/// "serverstop()" function
-static void f_serverstop(typval_T *argvars, typval_T *rettv)
+static void f_serverstop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (check_restricted() || check_secure()) {
return;
@@ -14644,7 +14266,7 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv)
/*
* "setbufvar()" function
*/
-static void f_setbufvar(typval_T *argvars, typval_T *rettv)
+static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
buf_T *buf;
aco_save_T aco;
@@ -14686,7 +14308,7 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv)
}
}
-static void f_setcharsearch(typval_T *argvars, typval_T *rettv)
+static void f_setcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_T *d;
dictitem_T *di;
@@ -14723,7 +14345,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv)
/*
* "setcmdpos()" function
*/
-static void f_setcmdpos(typval_T *argvars, typval_T *rettv)
+static void f_setcmdpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int pos = (int)get_tv_number(&argvars[0]) - 1;
@@ -14733,7 +14355,7 @@ static void f_setcmdpos(typval_T *argvars, typval_T *rettv)
/// "setfperm({fname}, {mode})" function
-static void f_setfperm(typval_T *argvars, typval_T *rettv)
+static void f_setfperm(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = 0;
@@ -14766,7 +14388,7 @@ static void f_setfperm(typval_T *argvars, typval_T *rettv)
/*
* "setline()" function
*/
-static void f_setline(typval_T *argvars, typval_T *rettv)
+static void f_setline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum;
char_u *line = NULL;
@@ -14891,7 +14513,7 @@ skip_args:
/*
* "setloclist()" function
*/
-static void f_setloclist(typval_T *argvars, typval_T *rettv)
+static void f_setloclist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *win;
@@ -14906,7 +14528,7 @@ static void f_setloclist(typval_T *argvars, typval_T *rettv)
/*
* "setmatches()" function
*/
-static void f_setmatches(typval_T *argvars, typval_T *rettv)
+static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
list_T *l;
listitem_T *li;
@@ -14997,7 +14619,7 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv)
/*
* "setpos()" function
*/
-static void f_setpos(typval_T *argvars, typval_T *rettv)
+static void f_setpos(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
pos_T pos;
int fnum;
@@ -15039,7 +14661,7 @@ static void f_setpos(typval_T *argvars, typval_T *rettv)
/*
* "setqflist()" function
*/
-static void f_setqflist(typval_T *argvars, typval_T *rettv)
+static void f_setqflist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
set_qf_ll_list(NULL, argvars, rettv);
}
@@ -15047,7 +14669,7 @@ static void f_setqflist(typval_T *argvars, typval_T *rettv)
/*
* "setreg()" function
*/
-static void f_setreg(typval_T *argvars, typval_T *rettv)
+static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int regname;
char_u *strregname;
@@ -15142,7 +14764,7 @@ free_lstval:
/*
* "settabvar()" function
*/
-static void f_settabvar(typval_T *argvars, typval_T *rettv)
+static void f_settabvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
tabpage_T *save_curtab;
tabpage_T *tp;
@@ -15179,7 +14801,7 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv)
/*
* "settabwinvar()" function
*/
-static void f_settabwinvar(typval_T *argvars, typval_T *rettv)
+static void f_settabwinvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
setwinvar(argvars, rettv, 1);
}
@@ -15187,7 +14809,7 @@ static void f_settabwinvar(typval_T *argvars, typval_T *rettv)
/*
* "setwinvar()" function
*/
-static void f_setwinvar(typval_T *argvars, typval_T *rettv)
+static void f_setwinvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
setwinvar(argvars, rettv, 0);
}
@@ -15247,7 +14869,7 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
}
/// f_sha256 - sha256({string}) function
-static void f_sha256(typval_T *argvars, typval_T *rettv)
+static void f_sha256(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = get_tv_string(&argvars[0]);
const char_u *hash = sha256_bytes(p, (int) STRLEN(p) , NULL, 0);
@@ -15260,7 +14882,7 @@ static void f_sha256(typval_T *argvars, typval_T *rettv)
/*
* "shellescape({string})" function
*/
-static void f_shellescape(typval_T *argvars, typval_T *rettv)
+static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_string = vim_strsave_shellescape(
get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), true);
@@ -15270,7 +14892,7 @@ static void f_shellescape(typval_T *argvars, typval_T *rettv)
/*
* shiftwidth() function
*/
-static void f_shiftwidth(typval_T *argvars, typval_T *rettv)
+static void f_shiftwidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = get_sw_value(curbuf);
}
@@ -15278,7 +14900,7 @@ static void f_shiftwidth(typval_T *argvars, typval_T *rettv)
/*
* "simplify()" function
*/
-static void f_simplify(typval_T *argvars, typval_T *rettv)
+static void f_simplify(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p;
@@ -15288,22 +14910,6 @@ static void f_simplify(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING;
}
-/*
- * "sin()" function
- */
-static void f_sin(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &sin);
-}
-
-/*
- * "sinh()" function
- */
-static void f_sinh(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &sinh);
-}
-
/// struct used in the array that's given to qsort()
typedef struct {
listitem_T *item;
@@ -15651,13 +15257,13 @@ theend:
}
/// "sort"({list})" function
-static void f_sort(typval_T *argvars, typval_T *rettv)
+static void f_sort(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
do_sort_uniq(argvars, rettv, true);
}
/// "uniq({list})" function
-static void f_uniq(typval_T *argvars, typval_T *rettv)
+static void f_uniq(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
do_sort_uniq(argvars, rettv, false);
}
@@ -15665,7 +15271,7 @@ static void f_uniq(typval_T *argvars, typval_T *rettv)
//
// "reltimefloat()" function
//
-static void f_reltimefloat(typval_T *argvars , typval_T *rettv)
+static void f_reltimefloat(typval_T *argvars , typval_T *rettv, FunPtr fptr)
FUNC_ATTR_NONNULL_ALL
{
proftime_T tm;
@@ -15680,7 +15286,7 @@ static void f_reltimefloat(typval_T *argvars , typval_T *rettv)
/*
* "soundfold({word})" function
*/
-static void f_soundfold(typval_T *argvars, typval_T *rettv)
+static void f_soundfold(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s;
@@ -15692,7 +15298,7 @@ static void f_soundfold(typval_T *argvars, typval_T *rettv)
/*
* "spellbadword()" function
*/
-static void f_spellbadword(typval_T *argvars, typval_T *rettv)
+static void f_spellbadword(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *word = (char_u *)"";
hlf_T attr = HLF_COUNT;
@@ -15736,7 +15342,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv)
/*
* "spellsuggest()" function
*/
-static void f_spellsuggest(typval_T *argvars, typval_T *rettv)
+static void f_spellsuggest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *str;
int typeerr = FALSE;
@@ -15776,7 +15382,7 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv)
}
}
-static void f_split(typval_T *argvars, typval_T *rettv)
+static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *str;
char_u *end;
@@ -15845,17 +15451,9 @@ static void f_split(typval_T *argvars, typval_T *rettv)
}
/*
- * "sqrt()" function
- */
-static void f_sqrt(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &sqrt);
-}
-
-/*
* "str2float()" function
*/
-static void f_str2float(typval_T *argvars, typval_T *rettv)
+static void f_str2float(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = skipwhite(get_tv_string(&argvars[0]));
@@ -15866,7 +15464,7 @@ static void f_str2float(typval_T *argvars, typval_T *rettv)
}
// "str2nr()" function
-static void f_str2nr(typval_T *argvars, typval_T *rettv)
+static void f_str2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int base = 10;
char_u *p;
@@ -15905,7 +15503,7 @@ static void f_str2nr(typval_T *argvars, typval_T *rettv)
/*
* "strftime({format}[, {time}])" function
*/
-static void f_strftime(typval_T *argvars, typval_T *rettv)
+static void f_strftime(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u result_buf[256];
time_t seconds;
@@ -15956,7 +15554,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv)
/*
* "stridx()" function
*/
-static void f_stridx(typval_T *argvars, typval_T *rettv)
+static void f_stridx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
char_u *needle;
@@ -15989,7 +15587,7 @@ static void f_stridx(typval_T *argvars, typval_T *rettv)
/*
* "string()" function
*/
-static void f_string(typval_T *argvars, typval_T *rettv)
+static void f_string(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (char_u *) encode_tv2string(&argvars[0], NULL);
@@ -15998,7 +15596,7 @@ static void f_string(typval_T *argvars, typval_T *rettv)
/*
* "strlen()" function
*/
-static void f_strlen(typval_T *argvars, typval_T *rettv)
+static void f_strlen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = (varnumber_T)(STRLEN(
get_tv_string(&argvars[0])));
@@ -16007,7 +15605,7 @@ static void f_strlen(typval_T *argvars, typval_T *rettv)
/*
* "strchars()" function
*/
-static void f_strchars(typval_T *argvars, typval_T *rettv)
+static void f_strchars(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s = get_tv_string(&argvars[0]);
int skipcc = 0;
@@ -16032,7 +15630,7 @@ static void f_strchars(typval_T *argvars, typval_T *rettv)
/*
* "strdisplaywidth()" function
*/
-static void f_strdisplaywidth(typval_T *argvars, typval_T *rettv)
+static void f_strdisplaywidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s = get_tv_string(&argvars[0]);
int col = 0;
@@ -16046,7 +15644,7 @@ static void f_strdisplaywidth(typval_T *argvars, typval_T *rettv)
/*
* "strwidth()" function
*/
-static void f_strwidth(typval_T *argvars, typval_T *rettv)
+static void f_strwidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *s = get_tv_string(&argvars[0]);
@@ -16056,7 +15654,7 @@ static void f_strwidth(typval_T *argvars, typval_T *rettv)
/*
* "strpart()" function
*/
-static void f_strpart(typval_T *argvars, typval_T *rettv)
+static void f_strpart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p;
int n;
@@ -16096,7 +15694,7 @@ static void f_strpart(typval_T *argvars, typval_T *rettv)
/*
* "strridx()" function
*/
-static void f_strridx(typval_T *argvars, typval_T *rettv)
+static void f_strridx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u buf[NUMBUFLEN];
char_u *needle;
@@ -16142,7 +15740,7 @@ static void f_strridx(typval_T *argvars, typval_T *rettv)
/*
* "strtrans()" function
*/
-static void f_strtrans(typval_T *argvars, typval_T *rettv)
+static void f_strtrans(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = transstr(get_tv_string(&argvars[0]));
@@ -16151,7 +15749,7 @@ static void f_strtrans(typval_T *argvars, typval_T *rettv)
/*
* "submatch()" function
*/
-static void f_submatch(typval_T *argvars, typval_T *rettv)
+static void f_submatch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int error = FALSE;
int no = (int)get_tv_number_chk(&argvars[0], &error);
@@ -16180,7 +15778,7 @@ static void f_submatch(typval_T *argvars, typval_T *rettv)
/*
* "substitute()" function
*/
-static void f_substitute(typval_T *argvars, typval_T *rettv)
+static void f_substitute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u patbuf[NUMBUFLEN];
char_u subbuf[NUMBUFLEN];
@@ -16201,7 +15799,7 @@ static void f_substitute(typval_T *argvars, typval_T *rettv)
/*
* "synID(lnum, col, trans)" function
*/
-static void f_synID(typval_T *argvars, typval_T *rettv)
+static void f_synID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int id = 0;
long lnum;
@@ -16223,7 +15821,7 @@ static void f_synID(typval_T *argvars, typval_T *rettv)
/*
* "synIDattr(id, what [, mode])" function
*/
-static void f_synIDattr(typval_T *argvars, typval_T *rettv)
+static void f_synIDattr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = NULL;
int id;
@@ -16299,7 +15897,7 @@ static void f_synIDattr(typval_T *argvars, typval_T *rettv)
/*
* "synIDtrans(id)" function
*/
-static void f_synIDtrans(typval_T *argvars, typval_T *rettv)
+static void f_synIDtrans(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int id;
@@ -16316,7 +15914,7 @@ static void f_synIDtrans(typval_T *argvars, typval_T *rettv)
/*
* "synconcealed(lnum, col)" function
*/
-static void f_synconcealed(typval_T *argvars, typval_T *rettv)
+static void f_synconcealed(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long lnum;
long col;
@@ -16363,7 +15961,7 @@ static void f_synconcealed(typval_T *argvars, typval_T *rettv)
/*
* "synstack(lnum, col)" function
*/
-static void f_synstack(typval_T *argvars, typval_T *rettv)
+static void f_synstack(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long lnum;
long col;
@@ -16494,12 +16092,12 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv,
}
/// f_system - the VimL system() function
-static void f_system(typval_T *argvars, typval_T *rettv)
+static void f_system(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_system_output_as_rettv(argvars, rettv, false);
}
-static void f_systemlist(typval_T *argvars, typval_T *rettv)
+static void f_systemlist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
get_system_output_as_rettv(argvars, rettv, true);
}
@@ -16508,7 +16106,7 @@ static void f_systemlist(typval_T *argvars, typval_T *rettv)
/*
* "tabpagebuflist()" function
*/
-static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv)
+static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
tabpage_T *tp;
win_T *wp = NULL;
@@ -16533,7 +16131,7 @@ static void f_tabpagebuflist(typval_T *argvars, typval_T *rettv)
/*
* "tabpagenr()" function
*/
-static void f_tabpagenr(typval_T *argvars, typval_T *rettv)
+static void f_tabpagenr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int nr = 1;
char_u *arg;
@@ -16597,7 +16195,7 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
/*
* "tabpagewinnr()" function
*/
-static void f_tabpagewinnr(typval_T *argvars, typval_T *rettv)
+static void f_tabpagewinnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int nr = 1;
tabpage_T *tp;
@@ -16614,7 +16212,7 @@ static void f_tabpagewinnr(typval_T *argvars, typval_T *rettv)
/*
* "tagfiles()" function
*/
-static void f_tagfiles(typval_T *argvars, typval_T *rettv)
+static void f_tagfiles(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *fname;
tagname_T tn;
@@ -16635,7 +16233,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
/*
* "taglist()" function
*/
-static void f_taglist(typval_T *argvars, typval_T *rettv)
+static void f_taglist(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *tag_pattern;
@@ -16651,14 +16249,14 @@ static void f_taglist(typval_T *argvars, typval_T *rettv)
/*
* "tempname()" function
*/
-static void f_tempname(typval_T *argvars, typval_T *rettv)
+static void f_tempname(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_tempname();
}
// "termopen(cmd[, cwd])" function
-static void f_termopen(typval_T *argvars, typval_T *rettv)
+static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (check_restricted() || check_secure()) {
return;
@@ -16733,9 +16331,9 @@ static void f_termopen(typval_T *argvars, typval_T *rettv)
// Save the job id and pid in b:terminal_job_{id,pid}
Error err;
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_id"),
- INTEGER_OBJ(rettv->vval.v_number), false, &err);
+ INTEGER_OBJ(rettv->vval.v_number), false, false, &err);
dict_set_value(curbuf->b_vars, cstr_as_string("terminal_job_pid"),
- INTEGER_OBJ(pid), false, &err);
+ INTEGER_OBJ(pid), false, false, &err);
Terminal *term = terminal_open(topts);
data->term = term;
@@ -16747,30 +16345,13 @@ static void f_termopen(typval_T *argvars, typval_T *rettv)
/*
* "test(list)" function: Just checking the walls...
*/
-static void f_test(typval_T *argvars, typval_T *rettv)
+static void f_test(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
/* Used for unit testing. Change the code below to your liking. */
}
-/*
- * "tan()" function
- */
-static void f_tan(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &tan);
-}
-
-/*
- * "tanh()" function
- */
-static void f_tanh(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &tanh);
-}
-
-
/// "timer_start(timeout, callback, opts)" function
-static void f_timer_start(typval_T *argvars, typval_T *rettv)
+static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
long timeout = get_tv_number(&argvars[0]);
timer_T *timer;
@@ -16825,7 +16406,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv)
// "timer_stop(timerid)" function
-static void f_timer_stop(typval_T *argvars, typval_T *rettv)
+static void f_timer_stop(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (argvars[0].v_type != VAR_NUMBER) {
EMSG(_(e_number_exp));
@@ -16914,7 +16495,7 @@ void timer_teardown(void)
/*
* "tolower(string)" function
*/
-static void f_tolower(typval_T *argvars, typval_T *rettv)
+static void f_tolower(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *p = vim_strsave(get_tv_string(&argvars[0]));
rettv->v_type = VAR_STRING;
@@ -16945,7 +16526,7 @@ static void f_tolower(typval_T *argvars, typval_T *rettv)
/*
* "toupper(string)" function
*/
-static void f_toupper(typval_T *argvars, typval_T *rettv)
+static void f_toupper(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = strup_save(get_tv_string(&argvars[0]));
@@ -16954,7 +16535,7 @@ static void f_toupper(typval_T *argvars, typval_T *rettv)
/*
* "tr(string, fromstr, tostr)" function
*/
-static void f_tr(typval_T *argvars, typval_T *rettv)
+static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *in_str;
char_u *fromstr;
@@ -17052,17 +16633,9 @@ error:
}
/*
- * "trunc({float})" function
- */
-static void f_trunc(typval_T *argvars, typval_T *rettv)
-{
- float_op_wrapper(argvars, rettv, &trunc);
-}
-
-/*
* "type(expr)" function
*/
-static void f_type(typval_T *argvars, typval_T *rettv)
+static void f_type(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int n = -1;
@@ -17098,7 +16671,7 @@ static void f_type(typval_T *argvars, typval_T *rettv)
/*
* "undofile(name)" function
*/
-static void f_undofile(typval_T *argvars, typval_T *rettv)
+static void f_undofile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->v_type = VAR_STRING;
{
@@ -17121,7 +16694,7 @@ static void f_undofile(typval_T *argvars, typval_T *rettv)
/*
* "undotree()" function
*/
-static void f_undotree(typval_T *argvars, typval_T *rettv)
+static void f_undotree(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_dict_alloc(rettv);
@@ -17144,7 +16717,7 @@ static void f_undotree(typval_T *argvars, typval_T *rettv)
/*
* "values(dict)" function
*/
-static void f_values(typval_T *argvars, typval_T *rettv)
+static void f_values(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_list(argvars, rettv, 1);
}
@@ -17152,7 +16725,7 @@ static void f_values(typval_T *argvars, typval_T *rettv)
/*
* "virtcol(string)" function
*/
-static void f_virtcol(typval_T *argvars, typval_T *rettv)
+static void f_virtcol(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
colnr_T vcol = 0;
pos_T *fp;
@@ -17171,7 +16744,7 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv)
/*
* "visualmode()" function
*/
-static void f_visualmode(typval_T *argvars, typval_T *rettv)
+static void f_visualmode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u str[2];
@@ -17188,34 +16761,40 @@ static void f_visualmode(typval_T *argvars, typval_T *rettv)
/*
* "wildmenumode()" function
*/
-static void f_wildmenumode(typval_T *argvars, typval_T *rettv)
+static void f_wildmenumode(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
if (wild_menu_showing)
rettv->vval.v_number = 1;
}
+/// "win_findbuf()" function
+static void f_win_findbuf(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ rettv_list_alloc(rettv);
+ win_findbuf(argvars, rettv->vval.v_list);
+}
+
/// "win_getid()" function
-static void f_win_getid(typval_T *argvars, typval_T *rettv)
+static void f_win_getid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = win_getid(argvars);
}
/// "win_gotoid()" function
-static void f_win_gotoid(typval_T *argvars, typval_T *rettv)
+static void f_win_gotoid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = win_gotoid(argvars);
}
/// "win_id2tabwin()" function
-static void f_win_id2tabwin(typval_T *argvars, typval_T *rettv)
+static void f_win_id2tabwin(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- if (rettv_list_alloc(rettv) != FAIL) {
- win_id2tabwin(argvars, rettv->vval.v_list);
- }
+ rettv_list_alloc(rettv);
+ win_id2tabwin(argvars, rettv->vval.v_list);
}
/// "win_id2win()" function
-static void f_win_id2win(typval_T *argvars, typval_T *rettv)
+static void f_win_id2win(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = win_id2win(argvars);
}
@@ -17223,7 +16802,7 @@ static void f_win_id2win(typval_T *argvars, typval_T *rettv)
/*
* "winbufnr(nr)" function
*/
-static void f_winbufnr(typval_T *argvars, typval_T *rettv)
+static void f_winbufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *wp;
@@ -17237,7 +16816,7 @@ static void f_winbufnr(typval_T *argvars, typval_T *rettv)
/*
* "wincol()" function
*/
-static void f_wincol(typval_T *argvars, typval_T *rettv)
+static void f_wincol(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
validate_cursor();
rettv->vval.v_number = curwin->w_wcol + 1;
@@ -17246,7 +16825,7 @@ static void f_wincol(typval_T *argvars, typval_T *rettv)
/*
* "winheight(nr)" function
*/
-static void f_winheight(typval_T *argvars, typval_T *rettv)
+static void f_winheight(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *wp;
@@ -17260,7 +16839,7 @@ static void f_winheight(typval_T *argvars, typval_T *rettv)
/*
* "winline()" function
*/
-static void f_winline(typval_T *argvars, typval_T *rettv)
+static void f_winline(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
validate_cursor();
rettv->vval.v_number = curwin->w_wrow + 1;
@@ -17269,7 +16848,7 @@ static void f_winline(typval_T *argvars, typval_T *rettv)
/*
* "winnr()" function
*/
-static void f_winnr(typval_T *argvars, typval_T *rettv)
+static void f_winnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int nr = 1;
@@ -17280,7 +16859,7 @@ static void f_winnr(typval_T *argvars, typval_T *rettv)
/*
* "winrestcmd()" function
*/
-static void f_winrestcmd(typval_T *argvars, typval_T *rettv)
+static void f_winrestcmd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
int winnr = 1;
garray_T ga;
@@ -17303,7 +16882,7 @@ static void f_winrestcmd(typval_T *argvars, typval_T *rettv)
/*
* "winrestview()" function
*/
-static void f_winrestview(typval_T *argvars, typval_T *rettv)
+static void f_winrestview(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_T *dict;
@@ -17353,7 +16932,7 @@ static void f_winrestview(typval_T *argvars, typval_T *rettv)
/*
* "winsaveview()" function
*/
-static void f_winsaveview(typval_T *argvars, typval_T *rettv)
+static void f_winsaveview(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
dict_T *dict;
@@ -17457,7 +17036,7 @@ static char_u *save_tv_as_string(typval_T *tv, ssize_t *len, bool endnl)
/*
* "winwidth(nr)" function
*/
-static void f_winwidth(typval_T *argvars, typval_T *rettv)
+static void f_winwidth(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
win_T *wp;
@@ -17469,14 +17048,14 @@ static void f_winwidth(typval_T *argvars, typval_T *rettv)
}
/// "wordcount()" function
-static void f_wordcount(typval_T *argvars, typval_T *rettv)
+static void f_wordcount(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv_dict_alloc(rettv);
cursor_pos_info(rettv->vval.v_dict);
}
/// "writefile()" function
-static void f_writefile(typval_T *argvars, typval_T *rettv)
+static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = 0; // Assuming success.
@@ -17521,7 +17100,7 @@ static void f_writefile(typval_T *argvars, typval_T *rettv)
/*
* "xor(expr, expr)" function
*/
-static void f_xor(typval_T *argvars, typval_T *rettv)
+static void f_xor(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
^ get_tv_number_chk(&argvars[1], NULL);
@@ -18603,7 +18182,7 @@ static linenr_T get_tv_lnum(typval_T *argvars)
lnum = get_tv_number_chk(&argvars[0], NULL);
if (lnum == 0) { /* no valid number, try using line() */
rettv.v_type = VAR_NUMBER;
- f_line(argvars, &rettv);
+ f_line(argvars, &rettv, NULL);
lnum = rettv.vval.v_number;
clear_tv(&rettv);
}
@@ -20431,7 +20010,7 @@ void free_all_functions(void)
int translated_function_exists(char_u *name)
{
if (builtin_function(name, -1)) {
- return find_internal_func(name) >= 0;
+ return find_internal_func((char *)name) != NULL;
}
return find_func(name) != NULL;
}
@@ -22190,9 +21769,15 @@ static inline bool common_job_start(TerminalJobData *data, typval_T *rettv)
Process *proc = (Process *)&data->proc;
if (proc->type == kProcessTypePty && proc->detach) {
EMSG2(_(e_invarg2), "terminal/pty job cannot be detached");
+ xfree(data->proc.pty.term_name);
+ shell_free_argv(proc->argv);
+ free_term_job_data_event((void **)&data);
return false;
}
+ data->id = next_chan_id++;
+ pmap_put(uint64_t)(jobs, data->id, data);
+
data->refcount++;
char *cmd = xstrdup(proc->argv[0]);
if (!process_spawn(proc)) {
@@ -22207,7 +21792,6 @@ static inline bool common_job_start(TerminalJobData *data, typval_T *rettv)
}
xfree(cmd);
- data->id = next_chan_id++;
if (data->rpc) {
// the rpc channel takes over the in and out streams
@@ -22224,7 +21808,6 @@ static inline bool common_job_start(TerminalJobData *data, typval_T *rettv)
rstream_init(proc->err, 0);
rstream_start(proc->err, on_job_stderr, data);
}
- pmap_put(uint64_t)(jobs, data->id, data);
rettv->vval.v_number = data->id;
return true;
}
@@ -22246,6 +21829,7 @@ static inline void free_term_job_data_event(void **argv)
dict_unref(data->self);
}
queue_free(data->events);
+ pmap_del(uint64_t)(jobs, data->id);
xfree(data);
}
@@ -22352,7 +21936,6 @@ static void on_process_exit(Process *proc, int status, void *d)
process_job_event(data, data->on_exit, "exit", NULL, 0, status);
- pmap_del(uint64_t)(jobs, data->id);
term_job_data_decref(data);
}
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
new file mode 100644
index 0000000000..3c371fc264
--- /dev/null
+++ b/src/nvim/eval.lua
@@ -0,0 +1,331 @@
+-- File containing table with all functions.
+--
+-- Keys:
+--
+-- args Number of arguments, list with maximum and minimum number of arguments
+-- or list with a minimum number of arguments only. Defaults to zero
+-- arguments.
+-- func Name of the C function which implements the VimL function. Defaults to
+-- `f_{funcname}`.
+
+local varargs = function(nr)
+ return {nr}
+end
+
+return {
+ funcs={
+ abs={args=1},
+ acos={args=1, func="float_op_wrapper", data="&acos"}, -- WJMc
+ add={args=2},
+ ['and']={args=2},
+ api_info={},
+ append={args=2},
+ argc={},
+ argidx={},
+ arglistid={args={0, 2}},
+ argv={args={0, 1}},
+ asin={args=1, func="float_op_wrapper", data="&asin"}, -- WJMc
+ assert_equal={args={2, 3}},
+ assert_exception={args={1, 2}},
+ assert_fails={args={1, 2}},
+ assert_false={args={1, 2}},
+ assert_match={args={2, 3}},
+ assert_notequal={args={2, 3}},
+ assert_notmatch={args={2, 3}},
+ assert_true={args={1, 2}},
+ atan={args=1, func="float_op_wrapper", data="&atan"},
+ atan2={args=2},
+ browse={args=4},
+ browsedir={args=2},
+ bufexists={args=1},
+ buffer_exists={args=1, func='f_bufexists'}, -- obsolete
+ buffer_name={args=1, func='f_bufname'}, -- obsolete
+ buffer_number={args=1, func='f_bufnr'}, -- obsolete
+ buflisted={args=1},
+ bufloaded={args=1},
+ bufname={args=1},
+ bufnr={args={1, 2}},
+ bufwinnr={args=1},
+ byte2line={args=1},
+ byteidx={args=2},
+ byteidxcomp={args=2},
+ call={args={2, 3}},
+ ceil={args=1, func="float_op_wrapper", data="&ceil"},
+ changenr={},
+ char2nr={args={1, 2}},
+ cindent={args=1},
+ clearmatches={},
+ col={args=1},
+ complete={args=2},
+ complete_add={args=1},
+ complete_check={},
+ confirm={args={1, 4}},
+ copy={args=1},
+ cos={args=1, func="float_op_wrapper", data="&cos"},
+ cosh={args=1, func="float_op_wrapper", data="&cosh"},
+ count={args={2, 4}},
+ cscope_connection={args={0, 3}},
+ cursor={args={1, 3}},
+ deepcopy={args={1, 2}},
+ delete={args={1,2}},
+ dictwatcheradd={args=3},
+ dictwatcherdel={args=3},
+ did_filetype={},
+ diff_filler={args=1},
+ diff_hlID={args=2},
+ empty={args=1},
+ escape={args=2},
+ eval={args=1},
+ eventhandler={},
+ executable={args=1},
+ execute={args=1},
+ exepath={args=1},
+ exists={args=1},
+ exp={args=1, func="float_op_wrapper", data="&exp"},
+ expand={args={1, 3}},
+ extend={args={2, 3}},
+ feedkeys={args={1, 2}},
+ file_readable={args=1, func='f_filereadable'}, -- obsolete
+ filereadable={args=1},
+ filewritable={args=1},
+ filter={args=2},
+ finddir={args={1, 3}},
+ findfile={args={1, 3}},
+ float2nr={args=1},
+ floor={args=1, func="float_op_wrapper", data="&floor"},
+ fmod={args=2},
+ fnameescape={args=1},
+ fnamemodify={args=2},
+ foldclosed={args=1},
+ foldclosedend={args=1},
+ foldlevel={args=1},
+ foldtext={},
+ foldtextresult={args=1},
+ foreground={},
+ ['function']={args=1},
+ garbagecollect={args={0, 1}},
+ get={args={2, 3}},
+ getbufline={args={2, 3}},
+ getbufvar={args={2, 3}},
+ getchar={args={0, 1}},
+ getcharmod={},
+ getcharsearch={},
+ getcmdline={},
+ getcmdpos={},
+ getcmdtype={},
+ getcmdwintype={},
+ getcompletion={args=2},
+ getcurpos={},
+ getcwd={args={0,2}},
+ getfontname={args={0, 1}},
+ getfperm={args=1},
+ getfsize={args=1},
+ getftime={args=1},
+ getftype={args=1},
+ getline={args={1, 2}},
+ getloclist={args=1, func='f_getqflist'},
+ getmatches={},
+ getpid={},
+ getpos={args=1},
+ getqflist={},
+ getreg={args={0, 3}},
+ getregtype={args={0, 1}},
+ gettabvar={args={2, 3}},
+ gettabwinvar={args={3, 4}},
+ getwinposx={},
+ getwinposy={},
+ getwinvar={args={2, 3}},
+ glob={args={1, 4}},
+ glob2regpat={args=1},
+ globpath={args={2, 5}},
+ has={args=1},
+ has_key={args=2},
+ haslocaldir={args={0,2}},
+ hasmapto={args={1, 3}},
+ highlightID={args=1, func='f_hlID'}, -- obsolete
+ highlight_exists={args=1, func='f_hlexists'}, -- obsolete
+ histadd={args=2},
+ histdel={args={1, 2}},
+ histget={args={1, 2}},
+ histnr={args=1},
+ hlID={args=1},
+ hlexists={args=1},
+ hostname={},
+ iconv={args=3},
+ indent={args=1},
+ index={args={2, 4}},
+ input={args={1, 3}},
+ inputdialog={args={1, 3}},
+ inputlist={args=1},
+ inputrestore={},
+ inputsave={},
+ inputsecret={args={1, 2}},
+ insert={args={2, 3}},
+ invert={args=1},
+ isdirectory={args=1},
+ islocked={args=1},
+ items={args=1},
+ jobclose={args={1, 2}},
+ jobpid={args=1},
+ jobresize={args=3},
+ jobsend={args=2},
+ jobstart={args={1, 2}},
+ jobstop={args=1},
+ jobwait={args={1, 2}},
+ join={args={1, 2}},
+ json_decode={args=1},
+ json_encode={args=1},
+ keys={args=1},
+ last_buffer_nr={}, -- obsolete
+ len={args=1},
+ libcall={args=3},
+ libcallnr={args=3},
+ line={args=1},
+ line2byte={args=1},
+ lispindent={args=1},
+ localtime={},
+ log={args=1, func="float_op_wrapper", data="&log"},
+ log10={args=1, func="float_op_wrapper", data="&log10"},
+ map={args=2},
+ maparg={args={1, 4}},
+ mapcheck={args={1, 3}},
+ match={args={2, 4}},
+ matchadd={args={2, 5}},
+ matchaddpos={args={2, 5}},
+ matcharg={args=1},
+ matchdelete={args=1},
+ matchend={args={2, 4}},
+ matchlist={args={2, 4}},
+ matchstr={args={2, 4}},
+ max={args=1},
+ min={args=1},
+ mkdir={args={1, 3}},
+ mode={args={0, 1}},
+ msgpackdump={args=1},
+ msgpackparse={args=1},
+ nextnonblank={args=1},
+ nr2char={args={1, 2}},
+ ['or']={args=2},
+ pathshorten={args=1},
+ pow={args=2},
+ prevnonblank={args=1},
+ printf={args=varargs(2)},
+ pumvisible={},
+ py3eval={args=1},
+ pyeval={args=1},
+ range={args={1, 3}},
+ readfile={args={1, 3}},
+ reltime={args={0, 2}},
+ reltimefloat={args=1},
+ reltimestr={args=1},
+ remove={args={2, 3}},
+ rename={args=2},
+ ['repeat']={args=2},
+ resolve={args=1},
+ reverse={args=1},
+ round={args=1, func="float_op_wrapper", data="&round"},
+ rpcnotify={args=varargs(2)},
+ rpcrequest={args=varargs(2)},
+ rpcstart={args={1, 2}},
+ rpcstop={args=1},
+ screenattr={args=2},
+ screenchar={args=2},
+ screencol={},
+ screenrow={},
+ search={args={1, 4}},
+ searchdecl={args={1, 3}},
+ searchpair={args={3, 7}},
+ searchpairpos={args={3, 7}},
+ searchpos={args={1, 4}},
+ serverlist={},
+ serverstart={args={0, 1}},
+ serverstop={args=1},
+ setbufvar={args=3},
+ setcharsearch={args=1},
+ setcmdpos={args=1},
+ setfperm={args=2},
+ setline={args=2},
+ setloclist={args={2, 4}},
+ setmatches={args=1},
+ setpos={args=2},
+ setqflist={args={1, 3}},
+ setreg={args={2, 3}},
+ settabvar={args=3},
+ settabwinvar={args=4},
+ setwinvar={args=3},
+ sha256={args=1},
+ shellescape={args={1, 2}},
+ shiftwidth={},
+ simplify={args=1},
+ sin={args=1, func="float_op_wrapper", data="&sin"},
+ sinh={args=1, func="float_op_wrapper", data="&sinh"},
+ sort={args={1, 3}},
+ soundfold={args=1},
+ spellbadword={args={0, 1}},
+ spellsuggest={args={1, 3}},
+ split={args={1, 3}},
+ sqrt={args=1, func="float_op_wrapper", data="&sqrt"},
+ str2float={args=1},
+ str2nr={args={1, 2}},
+ strchars={args={1,2}},
+ strdisplaywidth={args={1, 2}},
+ strftime={args={1, 2}},
+ stridx={args={2, 3}},
+ string={args=1},
+ strlen={args=1},
+ strpart={args={2, 3}},
+ strridx={args={2, 3}},
+ strtrans={args=1},
+ strwidth={args=1},
+ submatch={args={1, 2}},
+ substitute={args=4},
+ synID={args=3},
+ synIDattr={args={2, 3}},
+ synIDtrans={args=1},
+ synconcealed={args=2},
+ synstack={args=2},
+ system={args={1, 2}},
+ systemlist={args={1, 3}},
+ tabpagebuflist={args={0, 1}},
+ tabpagenr={args={0, 1}},
+ tabpagewinnr={args={1, 2}},
+ tagfiles={},
+ taglist={args=1},
+ tan={args=1, func="float_op_wrapper", data="&tan"},
+ tanh={args=1, func="float_op_wrapper", data="&tanh"},
+ tempname={},
+ termopen={args={1, 2}},
+ test={args=1},
+ timer_start={args={2,3}},
+ timer_stop={args=1},
+ tolower={args=1},
+ toupper={args=1},
+ tr={args=3},
+ trunc={args=1, func="float_op_wrapper", data="&trunc"},
+ type={args=1},
+ undofile={args=1},
+ undotree={},
+ uniq={args={1, 3}},
+ values={args=1},
+ virtcol={args=1},
+ visualmode={args={0, 1}},
+ wildmenumode={},
+ win_findbuf={args=1},
+ win_getid={args={0,2}},
+ win_gotoid={args=1},
+ win_id2tabwin={args=1},
+ win_id2win={args=1},
+ winbufnr={args=1},
+ wincol={},
+ winheight={args=1},
+ winline={},
+ winnr={args={0, 1}},
+ winrestcmd={},
+ winrestview={args=1},
+ winsaveview={},
+ winwidth={args=1},
+ wordcount={},
+ writefile={args={2, 3}},
+ xor={args=2},
+ },
+}
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index f507e3d71d..51f20b7eac 100644
--- a/src/nvim/event/process.c
+++ b/src/nvim/event/process.c
@@ -17,8 +17,7 @@
# include "event/process.c.generated.h"
#endif
-// {SIGNAL}_TIMEOUT is the time (in nanoseconds) that a process has to cleanly
-// exit before we send SIGNAL to it
+// Time (ns) for a process to exit cleanly before we send TERM/KILL.
#define TERM_TIMEOUT 1000000000
#define KILL_TIMEOUT (TERM_TIMEOUT * 2)
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index b7691997d7..9cf53f0d73 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1711,11 +1711,11 @@ int do_write(exarg_T *eap)
goto theend;
}
- /* If 'filetype' was empty try detecting it now. */
+ // If 'filetype' was empty try detecting it now.
if (*curbuf->b_p_ft == NUL) {
- if (au_has_group((char_u *)"filetypedetect"))
- (void)do_doautocmd((char_u *)"filetypedetect BufRead",
- TRUE);
+ if (au_has_group((char_u *)"filetypedetect")) {
+ (void)do_doautocmd((char_u *)"filetypedetect BufRead", true, NULL);
+ }
do_modelines(0);
}
@@ -4053,9 +4053,7 @@ void ex_global(exarg_T *eap)
smsg(_("Pattern not found: %s"), pat);
}
} else {
- start_global_changes();
global_exe(cmd);
- end_global_changes();
}
ml_clearmarked(); /* clear rest of the marks */
vim_regfree(regmatch.regprog);
@@ -4565,12 +4563,15 @@ int find_help_tags(char_u *arg, int *num_matches, char_u ***matches, int keep_la
break;
}
- /*
- * If tag starts with ', toss everything after a second '. Fixes
- * CTRL-] on 'option'. (would include the trailing '.').
- */
- if (*s == '\'' && s > arg && *arg == '\'')
+ // If tag starts with ', toss everything after a second '. Fixes
+ // CTRL-] on 'option'. (would include the trailing '.').
+ if (*s == '\'' && s > arg && *arg == '\'') {
break;
+ }
+ // Also '{' and '}'. Fixes CTRL-] on '{address}'.
+ if (*s == '}' && s > arg && *arg == '{') {
+ break;
+ }
}
*d = NUL;
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 6d24ba91f2..f68663c60c 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -27,7 +27,6 @@
#include "nvim/mbyte.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/memory.h"
#include "nvim/move.h"
@@ -1983,8 +1982,6 @@ void ex_listdo(exarg_T *eap)
save_ei = au_event_disable(",Syntax");
}
- start_global_changes();
-
if (eap->cmdidx == CMD_windo
|| eap->cmdidx == CMD_tabdo
|| P_HID(curbuf)
@@ -2181,7 +2178,6 @@ void ex_listdo(exarg_T *eap)
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
curbuf->b_fname, true, curbuf);
}
- end_global_changes();
}
/// Add files[count] to the arglist of the current window after arg "after".
diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h
index 421c14b495..8148eb5cee 100644
--- a/src/nvim/ex_cmds_defs.h
+++ b/src/nvim/ex_cmds_defs.h
@@ -126,56 +126,53 @@ struct exarg {
struct condstack *cstack; ///< condition stack for ":if" etc.
};
-#define FORCE_BIN 1 /* ":edit ++bin file" */
-#define FORCE_NOBIN 2 /* ":edit ++nobin file" */
-
-/* Values for "flags" */
-#define EXFLAG_LIST 0x01 /* 'l': list */
-#define EXFLAG_NR 0x02 /* '#': number */
-#define EXFLAG_PRINT 0x04 /* 'p': print */
-
-/*
- * used for completion on the command line
- */
-typedef struct expand {
- int xp_context; /* type of expansion */
- char_u *xp_pattern; /* start of item to expand */
- int xp_pattern_len; /* bytes in xp_pattern before cursor */
- char_u *xp_arg; /* completion function */
- int xp_scriptID; /* SID for completion function */
- int xp_backslash; /* one of the XP_BS_ values */
+#define FORCE_BIN 1 // ":edit ++bin file"
+#define FORCE_NOBIN 2 // ":edit ++nobin file"
+
+// Values for "flags"
+#define EXFLAG_LIST 0x01 // 'l': list
+#define EXFLAG_NR 0x02 // '#': number
+#define EXFLAG_PRINT 0x04 // 'p': print
+
+// used for completion on the command line
+struct expand {
+ int xp_context; // type of expansion
+ char_u *xp_pattern; // start of item to expand
+ int xp_pattern_len; // bytes in xp_pattern before cursor
+ char_u *xp_arg; // completion function
+ int xp_scriptID; // SID for completion function
+ int xp_backslash; // one of the XP_BS_ values
#ifndef BACKSLASH_IN_FILENAME
- int xp_shell; /* TRUE for a shell command, more
- characters need to be escaped */
+ int xp_shell; // TRUE for a shell command, more
+ // characters need to be escaped
#endif
- int xp_numfiles; /* number of files found by
- file name completion */
- char_u **xp_files; /* list of files */
- char_u *xp_line; /* text being completed */
- int xp_col; /* cursor position in line */
-} expand_T;
-
-/* values for xp_backslash */
-#define XP_BS_NONE 0 /* nothing special for backslashes */
-#define XP_BS_ONE 1 /* uses one backslash before a space */
-#define XP_BS_THREE 2 /* uses three backslashes before a space */
+ int xp_numfiles; // number of files found by file name completion
+ char_u **xp_files; // list of files
+ char_u *xp_line; // text being completed
+ int xp_col; // cursor position in line
+};
+
+// values for xp_backslash
+#define XP_BS_NONE 0 // nothing special for backslashes
+#define XP_BS_ONE 1 // uses one backslash before a space
+#define XP_BS_THREE 2 // uses three backslashes before a space
/// Command modifiers ":vertical", ":browse", ":confirm", ":hide", etc. set a
/// flag. This needs to be saved for recursive commands, put them in a
/// structure for easy manipulation.
typedef struct {
- int hide; ///< TRUE when ":hide" was used
- int split; ///< flags for win_split()
- int tab; ///< > 0 when ":tab" was used
- int confirm; ///< TRUE to invoke yes/no dialog
- int keepalt; ///< TRUE when ":keepalt" was used
- int keepmarks; ///< TRUE when ":keepmarks" was used
- int keepjumps; ///< TRUE when ":keepjumps" was used
- int lockmarks; ///< TRUE when ":lockmarks" was used
- int keeppatterns; ///< TRUE when ":keeppatterns" was used
- bool noswapfile; ///< true when ":noswapfile" was used
- bool browse; ///< TRUE to invoke file dialog
- char_u *save_ei; ///< saved value of 'eventignore'
+ int split; ///< flags for win_split()
+ int tab; ///< > 0 when ":tab" was used
+ bool browse; ///< true to invoke file dialog
+ bool confirm; ///< true to invoke yes/no dialog
+ bool hide; ///< true when ":hide" was used
+ bool keepalt; ///< true when ":keepalt" was used
+ bool keepjumps; ///< true when ":keepjumps" was used
+ bool keepmarks; ///< true when ":keepmarks" was used
+ bool keeppatterns; ///< true when ":keeppatterns" was used
+ bool lockmarks; ///< true when ":lockmarks" was used
+ bool noswapfile; ///< true when ":noswapfile" was used
+ char_u *save_ei; ///< saved value of 'eventignore'
} cmdmod_T;
#endif // NVIM_EX_CMDS_DEFS_H
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 1e54f03ba0..45407b7f12 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -36,7 +36,6 @@
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/file_search.h"
#include "nvim/garray.h"
@@ -345,7 +344,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
msg_list = saved_msg_list;
return FAIL;
}
- ++call_depth;
+ call_depth++;
+ start_batch_changes();
cstack.cs_idx = -1;
cstack.cs_looplevel = 0;
@@ -952,7 +952,8 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline,
did_endif = FALSE; /* in case do_cmdline used recursively */
- --call_depth;
+ call_depth--;
+ end_batch_changes();
return retval;
}
@@ -1325,24 +1326,24 @@ static char_u * do_one_cmd(char_u **cmdlinep,
case 'c': if (!checkforcmd(&ea.cmd, "confirm", 4))
break;
- cmdmod.confirm = TRUE;
+ cmdmod.confirm = true;
continue;
case 'k': if (checkforcmd(&ea.cmd, "keepmarks", 3)) {
- cmdmod.keepmarks = TRUE;
+ cmdmod.keepmarks = true;
continue;
}
if (checkforcmd(&ea.cmd, "keepalt", 5)) {
- cmdmod.keepalt = TRUE;
+ cmdmod.keepalt = true;
continue;
}
if (checkforcmd(&ea.cmd, "keeppatterns", 5)) {
- cmdmod.keeppatterns = TRUE;
+ cmdmod.keeppatterns = true;
continue;
}
if (!checkforcmd(&ea.cmd, "keepjumps", 5))
break;
- cmdmod.keepjumps = TRUE;
+ cmdmod.keepjumps = true;
continue;
/* ":hide" and ":hide | cmd" are not modifiers */
@@ -1350,11 +1351,11 @@ static char_u * do_one_cmd(char_u **cmdlinep,
|| *p == NUL || ends_excmd(*p))
break;
ea.cmd = p;
- cmdmod.hide = TRUE;
+ cmdmod.hide = true;
continue;
case 'l': if (checkforcmd(&ea.cmd, "lockmarks", 3)) {
- cmdmod.lockmarks = TRUE;
+ cmdmod.lockmarks = true;
continue;
}
@@ -4362,12 +4363,15 @@ static void ex_autocmd(exarg_T *eap)
*/
static void ex_doautocmd(exarg_T *eap)
{
- char_u *arg = eap->arg;
+ char_u *arg = eap->arg;
int call_do_modelines = check_nomodeline(&arg);
+ bool did_aucmd;
- (void)do_doautocmd(arg, TRUE);
- if (call_do_modelines) /* Only when there is no <nomodeline>. */
+ (void)do_doautocmd(arg, true, &did_aucmd);
+ // Only when there is no <nomodeline>.
+ if (call_do_modelines && did_aucmd) {
do_modelines(0);
+ }
}
/*
@@ -5154,6 +5158,24 @@ static char_u *uc_split_args(char_u *arg, size_t *lenp)
return buf;
}
+static size_t add_cmd_modifier(char_u *buf, char *mod_str, bool *multi_mods)
+{
+ size_t result = STRLEN(mod_str);
+ if (*multi_mods) {
+ result++;
+ }
+
+ if (buf != NULL) {
+ if (*multi_mods) {
+ STRCAT(buf, " ");
+ }
+ STRCAT(buf, mod_str);
+ }
+
+ *multi_mods = true;
+ return result;
+}
+
/*
* Check for a <> code in a user command.
* "code" points to the '<'. "len" the length of the <> (inclusive).
@@ -5178,8 +5200,8 @@ uc_check_code (
char_u *p = code + 1;
size_t l = len - 2;
int quote = 0;
- enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER,
- ct_LT, ct_NONE } type = ct_NONE;
+ enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_MODS,
+ ct_REGISTER, ct_LT, ct_NONE } type = ct_NONE;
if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-') {
quote = (*p == 'q' || *p == 'Q') ? 1 : 2;
@@ -5187,23 +5209,26 @@ uc_check_code (
l -= 2;
}
- ++l;
- if (l <= 1)
+ l++;
+ if (l <= 1) {
type = ct_NONE;
- else if (STRNICMP(p, "args>", l) == 0)
+ } else if (STRNICMP(p, "args>", l) == 0) {
type = ct_ARGS;
- else if (STRNICMP(p, "bang>", l) == 0)
+ } else if (STRNICMP(p, "bang>", l) == 0) {
type = ct_BANG;
- else if (STRNICMP(p, "count>", l) == 0)
+ } else if (STRNICMP(p, "count>", l) == 0) {
type = ct_COUNT;
- else if (STRNICMP(p, "line1>", l) == 0)
+ } else if (STRNICMP(p, "line1>", l) == 0) {
type = ct_LINE1;
- else if (STRNICMP(p, "line2>", l) == 0)
+ } else if (STRNICMP(p, "line2>", l) == 0) {
type = ct_LINE2;
- else if (STRNICMP(p, "lt>", l) == 0)
+ } else if (STRNICMP(p, "lt>", l) == 0) {
type = ct_LT;
- else if (STRNICMP(p, "reg>", l) == 0 || STRNICMP(p, "register>", l) == 0)
+ } else if (STRNICMP(p, "reg>", l) == 0 || STRNICMP(p, "register>", l) == 0) {
type = ct_REGISTER;
+ } else if (STRNICMP(p, "mods>", l) == 0) {
+ type = ct_MODS;
+ }
switch (type) {
case ct_ARGS:
@@ -5311,6 +5336,87 @@ uc_check_code (
break;
}
+ case ct_MODS:
+ {
+ result = quote ? 2 : 0;
+ if (buf != NULL) {
+ if (quote) {
+ *buf++ = '"';
+ }
+ *buf = '\0';
+ }
+
+ bool multi_mods = false;
+
+ // :aboveleft and :leftabove
+ if (cmdmod.split & WSP_ABOVE) {
+ result += add_cmd_modifier(buf, "aboveleft", &multi_mods);
+ }
+ // :belowright and :rightbelow
+ if (cmdmod.split & WSP_BELOW) {
+ result += add_cmd_modifier(buf, "belowright", &multi_mods);
+ }
+ // :botright
+ if (cmdmod.split & WSP_BOT) {
+ result += add_cmd_modifier(buf, "botright", &multi_mods);
+ }
+
+ typedef struct {
+ bool *set;
+ char *name;
+ } mod_entry_T;
+ static mod_entry_T mod_entries[] = {
+ { &cmdmod.browse, "browse" },
+ { &cmdmod.confirm, "confirm" },
+ { &cmdmod.hide, "hide" },
+ { &cmdmod.keepalt, "keepalt" },
+ { &cmdmod.keepjumps, "keepjumps" },
+ { &cmdmod.keepmarks, "keepmarks" },
+ { &cmdmod.keeppatterns, "keeppatterns" },
+ { &cmdmod.lockmarks, "lockmarks" },
+ { &cmdmod.noswapfile, "noswapfile" }
+ };
+ // the modifiers that are simple flags
+ for (size_t i = 0; i < ARRAY_SIZE(mod_entries); i++) {
+ if (*mod_entries[i].set) {
+ result += add_cmd_modifier(buf, mod_entries[i].name, &multi_mods);
+ }
+ }
+
+ // TODO(vim): How to support :noautocmd?
+ // TODO(vim): How to support :sandbox?
+
+ // :silent
+ if (msg_silent > 0) {
+ result += add_cmd_modifier(buf, emsg_silent > 0 ? "silent!" : "silent",
+ &multi_mods);
+ }
+ // :tab
+ if (cmdmod.tab > 0) {
+ result += add_cmd_modifier(buf, "tab", &multi_mods);
+ }
+ // :topleft
+ if (cmdmod.split & WSP_TOP) {
+ result += add_cmd_modifier(buf, "topleft", &multi_mods);
+ }
+
+ // TODO(vim): How to support :unsilent?
+
+ // :verbose
+ if (p_verbose > 0) {
+ result += add_cmd_modifier(buf, "verbose", &multi_mods);
+ }
+ // :vertical
+ if (cmdmod.split & WSP_VERT) {
+ result += add_cmd_modifier(buf, "vertical", &multi_mods);
+ }
+ if (quote && buf != NULL) {
+ buf += result - 2;
+ *buf = '"';
+ }
+ break;
+ }
+
case ct_REGISTER:
result = eap->regname ? 1 : 0;
if (quote)
@@ -9360,7 +9466,7 @@ static void ex_filetype(exarg_T *eap)
}
}
if (*arg == 'd') {
- (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE);
+ (void)do_doautocmd((char_u *)"filetypedetect BufRead", true, NULL);
do_modelines(0);
}
} else if (STRCMP(arg, "off") == 0) {
@@ -9511,20 +9617,15 @@ static void ex_foldopen(exarg_T *eap)
static void ex_folddo(exarg_T *eap)
{
- linenr_T lnum;
-
- start_global_changes();
-
- /* First set the marks for all lines closed/open. */
- for (lnum = eap->line1; lnum <= eap->line2; ++lnum)
- if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed))
+ // First set the marks for all lines closed/open.
+ for (linenr_T lnum = eap->line1; lnum <= eap->line2; ++lnum) {
+ if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) {
ml_setmarked(lnum);
+ }
+ }
- /* Execute the command on the marked lines. */
- global_exe(eap->arg);
- ml_clearmarked(); /* clear rest of the marks */
-
- end_global_changes();
+ global_exe(eap->arg); // Execute the command on the marked lines.
+ ml_clearmarked(); // clear rest of the marks
}
static void ex_terminal(exarg_T *eap)
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index 82d4c2b2d5..f518fa0d66 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -15,7 +15,6 @@
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index cd28554970..1a97dc3d6f 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -34,7 +34,6 @@
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/cursor_shape.h"
#include "nvim/keymap.h"
diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c
index 61e17128ea..eb22ad1428 100644
--- a/src/nvim/farsi.c
+++ b/src/nvim/farsi.c
@@ -15,7 +15,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/vim.h"
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 78b224f04c..c6cfba8142 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1,48 +1,44 @@
-/* TODO: make some #ifdef for this */
-/*--------[ file searching ]-------------------------------------------------*/
-/*
- * File searching functions for 'path', 'tags' and 'cdpath' options.
- * External visible functions:
- * vim_findfile_init() creates/initialises the search context
- * vim_findfile_free_visited() free list of visited files/dirs of search
- * context
- * vim_findfile() find a file in the search context
- * vim_findfile_cleanup() cleanup/free search context created by
- * vim_findfile_init()
- *
- * All static functions and variables start with 'ff_'
- *
- * In general it works like this:
- * First you create yourself a search context by calling vim_findfile_init().
- * It is possible to give a search context from a previous call to
- * vim_findfile_init(), so it can be reused. After this you call vim_findfile()
- * until you are satisfied with the result or it returns NULL. On every call it
- * returns the next file which matches the conditions given to
- * vim_findfile_init(). If it doesn't find a next file it returns NULL.
- *
- * It is possible to call vim_findfile_init() again to reinitialise your search
- * with some new parameters. Don't forget to pass your old search context to
- * it, so it can reuse it and especially reuse the list of already visited
- * directories. If you want to delete the list of already visited directories
- * simply call vim_findfile_free_visited().
- *
- * When you are done call vim_findfile_cleanup() to free the search context.
- *
- * The function vim_findfile_init() has a long comment, which describes the
- * needed parameters.
- *
- *
- *
- * ATTENTION:
- * ==========
- * Also we use an allocated search context here, this functions are NOT
- * thread-safe!!!!!
- *
- * To minimize parameter passing (or because I'm to lazy), only the
- * external visible functions get a search context as a parameter. This is
- * then assigned to a static global, which is used throughout the local
- * functions.
- */
+// File searching functions for 'path', 'tags' and 'cdpath' options.
+//
+// External visible functions:
+// vim_findfile_init() creates/initialises the search context
+// vim_findfile_free_visited() free list of visited files/dirs of search
+// context
+// vim_findfile() find a file in the search context
+// vim_findfile_cleanup() cleanup/free search context created by
+// vim_findfile_init()
+//
+// All static functions and variables start with 'ff_'
+//
+// In general it works like this:
+// First you create yourself a search context by calling vim_findfile_init().
+// It is possible to give a search context from a previous call to
+// vim_findfile_init(), so it can be reused. After this you call vim_findfile()
+// until you are satisfied with the result or it returns NULL. On every call it
+// returns the next file which matches the conditions given to
+// vim_findfile_init(). If it doesn't find a next file it returns NULL.
+//
+// It is possible to call vim_findfile_init() again to reinitialise your search
+// with some new parameters. Don't forget to pass your old search context to
+// it, so it can reuse it and especially reuse the list of already visited
+// directories. If you want to delete the list of already visited directories
+// simply call vim_findfile_free_visited().
+//
+// When you are done call vim_findfile_cleanup() to free the search context.
+//
+// The function vim_findfile_init() has a long comment, which describes the
+// needed parameters.
+//
+//
+//
+// ATTENTION:
+// ==========
+// We use an allocated search context, these functions are NOT thread-safe!!!!!
+//
+// To minimize parameter passing (or because I'm too lazy), only the
+// external visible functions get a search context as a parameter. This is
+// then assigned to a static global, which is used throughout the local
+// functions.
#include <assert.h>
#include <string.h>
@@ -59,7 +55,7 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
+#include "nvim/option.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/strings.h"
@@ -1526,3 +1522,28 @@ theend:
return file_name;
}
+/// Change to a file's directory.
+/// Caller must call shorten_fnames()!
+/// @return OK or FAIL
+int vim_chdirfile(char_u *fname)
+{
+ char_u dir[MAXPATHL];
+
+ STRLCPY(dir, fname, MAXPATHL);
+ *path_tail_with_sep(dir) = NUL;
+ return os_chdir((char *)dir) == 0 ? OK : FAIL;
+}
+
+/// Change directory to "new_dir". Search 'cdpath' for relative directory names.
+int vim_chdir(char_u *new_dir)
+{
+ char_u *dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
+ FNAME_MESS, curbuf->b_ffname);
+ if (dir_name == NULL) {
+ return -1;
+ }
+ int r = os_chdir((char *)dir_name);
+ xfree(dir_name);
+ return r;
+}
+
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index e0b6ae1215..c0d4a71b35 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -32,7 +32,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/normal.h"
@@ -44,6 +43,7 @@
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/sha256.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/types.h"
@@ -3773,8 +3773,9 @@ static int set_rw_fname(char_u *fname, char_u *sfname)
/* Do filetype detection now if 'filetype' is empty. */
if (*curbuf->b_p_ft == NUL) {
- if (au_has_group((char_u *)"filetypedetect"))
- (void)do_doautocmd((char_u *)"filetypedetect BufRead", FALSE);
+ if (au_has_group((char_u *)"filetypedetect")) {
+ (void)do_doautocmd((char_u *)"filetypedetect BufRead", false, NULL);
+ }
do_modelines(0);
}
@@ -4446,11 +4447,95 @@ bool vim_fgets(char_u *buf, int size, FILE *fp) FUNC_ATTR_NONNULL_ALL
return eof == NULL;
}
-/*
- * os_rename() only works if both files are on the same file system, this
- * function will (attempts to?) copy the file across if rename fails -- webb
- * Return -1 for failure, 0 for success.
- */
+/// Read 2 bytes from "fd" and turn them into an int, MSB first.
+int get2c(FILE *fd)
+{
+ int n;
+
+ n = getc(fd);
+ n = (n << 8) + getc(fd);
+ return n;
+}
+
+/// Read 3 bytes from "fd" and turn them into an int, MSB first.
+int get3c(FILE *fd)
+{
+ int n;
+
+ n = getc(fd);
+ n = (n << 8) + getc(fd);
+ n = (n << 8) + getc(fd);
+ return n;
+}
+
+/// Read 4 bytes from "fd" and turn them into an int, MSB first.
+int get4c(FILE *fd)
+{
+ // Use unsigned rather than int otherwise result is undefined
+ // when left-shift sets the MSB.
+ unsigned n;
+
+ n = (unsigned)getc(fd);
+ n = (n << 8) + (unsigned)getc(fd);
+ n = (n << 8) + (unsigned)getc(fd);
+ n = (n << 8) + (unsigned)getc(fd);
+ return (int)n;
+}
+
+/// Read 8 bytes from `fd` and turn them into a time_t, MSB first.
+time_t get8ctime(FILE *fd)
+{
+ time_t n = 0;
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ n = (n << 8) + getc(fd);
+ }
+ return n;
+}
+
+/// Reads a string of length "cnt" from "fd" into allocated memory.
+/// @return pointer to the string or NULL when unable to read that many bytes.
+char *read_string(FILE *fd, size_t cnt)
+{
+ char *str = xmallocz(cnt);
+ for (size_t i = 0; i < cnt; i++) {
+ int c = getc(fd);
+ if (c == EOF) {
+ xfree(str);
+ return NULL;
+ }
+ str[i] = (char)c;
+ }
+ return str;
+}
+
+/// Writes a number to file "fd", most significant bit first, in "len" bytes.
+/// @returns false in case of an error.
+bool put_bytes(FILE *fd, uintmax_t number, size_t len)
+{
+ assert(len > 0);
+ for (size_t i = len - 1; i < len; i--) {
+ if (putc((int)(number >> (i * 8)), fd) == EOF) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/// Writes time_t to file "fd" in 8 bytes.
+/// @returns FAIL when the write failed.
+int put_time(FILE *fd, time_t time_)
+{
+ uint8_t buf[8];
+ time_to_bytes(time_, buf);
+ return fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd) == 1 ? OK : FAIL;
+}
+
+/// os_rename() only works if both files are on the same file system, this
+/// function will (attempts to?) copy the file across if rename fails -- webb
+//
+/// @return -1 for failure, 0 for success
int vim_rename(char_u *from, char_u *to)
{
int fd_in;
@@ -6058,13 +6143,18 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd,
int
do_doautocmd (
char_u *arg,
- int do_msg /* give message for no matching autocmds? */
+ int do_msg, // give message for no matching autocmds?
+ bool *did_something
)
{
char_u *fname;
int nothing_done = TRUE;
int group;
+ if (did_something != NULL) {
+ *did_something = false;
+ }
+
/*
* Check for a legal group name. If not, use AUGROUP_ALL.
*/
@@ -6093,8 +6183,12 @@ do_doautocmd (
fname, NULL, TRUE, group, curbuf, NULL))
nothing_done = FALSE;
- if (nothing_done && do_msg)
+ if (nothing_done && do_msg) {
MSG(_("No matching autocommands"));
+ }
+ if (did_something != NULL) {
+ *did_something = !nothing_done;
+ }
return aborting() ? FAIL : OK;
}
@@ -6123,13 +6217,14 @@ void ex_doautoall(exarg_T *eap)
/* find a window for this buffer and save some values */
aucmd_prepbuf(&aco, buf);
- /* execute the autocommands for this buffer */
- retval = do_doautocmd(arg, FALSE);
+ bool did_aucmd;
+ // execute the autocommands for this buffer
+ retval = do_doautocmd(arg, false, &did_aucmd);
- if (call_do_modelines) {
- /* Execute the modeline settings, but don't set window-local
- * options if we are using the current window for another
- * buffer. */
+ if (call_do_modelines && did_aucmd) {
+ // Execute the modeline settings, but don't set window-local
+ // options if we are using the current window for another
+ // buffer.
do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0);
}
diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h
index d93f3f3eb3..ceb101167d 100644
--- a/src/nvim/fileio.h
+++ b/src/nvim/fileio.h
@@ -12,6 +12,8 @@
#define READ_DUMMY 0x10 /* reading into a dummy buffer */
#define READ_KEEP_UNDO 0x20 /* keep undo info*/
+#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
+
/*
* Struct to save values in before executing autocommands for a buffer that is
* not the current buffer.
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index ac3cf959c8..70030b8525 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -22,7 +22,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
@@ -762,16 +761,12 @@ void clearFolding(win_T *win)
*/
void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
{
- if (compl_busy) {
- return;
- }
-
- fold_T *fp;
- if (wp->w_buffer->terminal) {
+ if (compl_busy || State & INSERT) {
return;
}
// Mark all folds from top to bot as maybe-small.
+ fold_T *fp;
(void)foldFind(&wp->w_folds, top, &fp);
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot) {
diff --git a/src/nvim/func_attr.h b/src/nvim/func_attr.h
index ea017ab0c8..d98fe5b22b 100644
--- a/src/nvim/func_attr.h
+++ b/src/nvim/func_attr.h
@@ -185,6 +185,7 @@
#ifdef DEFINE_FUNC_ATTRIBUTES
# define FUNC_API_ASYNC
# define FUNC_API_NOEXPORT
+# define FUNC_API_NOEVAL
# define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
# define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x)
# define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) REAL_FATTR_ALLOC_SIZE_PROD(x, y)
diff --git a/src/nvim/garray.c b/src/nvim/garray.c
index 98cec69b54..9ed3b901ef 100644
--- a/src/nvim/garray.c
+++ b/src/nvim/garray.c
@@ -8,7 +8,6 @@
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/log.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/path.h"
#include "nvim/garray.h"
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index ae1857f318..dad0ac33cd 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -29,7 +29,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
#include "nvim/move.h"
@@ -38,6 +37,7 @@
#include "nvim/option.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index 1c9b8e18ef..7d4bfd0290 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -23,7 +23,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/option.h"
#include "nvim/path.h"
diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c
index 2da937633e..7d4ae61fc4 100644
--- a/src/nvim/hashtab.c
+++ b/src/nvim/hashtab.c
@@ -28,7 +28,6 @@
#include "nvim/hashtab.h"
#include "nvim/message.h"
#include "nvim/memory.h"
-#include "nvim/misc2.h"
// Magic value for algorithm that walks through the array.
#define PERTURB_SHIFT 5
diff --git a/src/nvim/iconv.h b/src/nvim/iconv.h
index 4ac0d3fdd4..bf29b15247 100644
--- a/src/nvim/iconv.h
+++ b/src/nvim/iconv.h
@@ -24,10 +24,10 @@
// defined, we provide a type shim (pull in errno.h and define iconv_t).
// This enables us to still load and use iconv dynamically at runtime.
#ifdef USE_ICONV
+# include <errno.h>
# ifdef HAVE_ICONV_H
# include <iconv.h>
# else
-# include <errno.h>
typedef void *iconv_t;
# endif
#endif
diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c
index 8684957393..3ed85677fc 100644
--- a/src/nvim/if_cscope.c
+++ b/src/nvim/if_cscope.c
@@ -20,7 +20,6 @@
#include "nvim/eval.h"
#include "nvim/fileio.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index f197669a97..7f31bb8c5c 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -10,7 +10,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/regexp.h"
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index efe8e73a3c..6f03cf6037 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -12,7 +12,6 @@
#include "nvim/indent_c.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
-#include "nvim/misc2.h"
#include "nvim/option.h"
#include "nvim/search.h"
#include "nvim/strings.h"
diff --git a/src/nvim/main.c b/src/nvim/main.c
index b5c51e3444..a153931d8a 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -30,7 +30,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/log.h"
#include "nvim/memory.h"
@@ -58,13 +57,13 @@
#include "nvim/event/loop.h"
#include "nvim/os/signal.h"
#include "nvim/event/process.h"
-#include "nvim/msgpack_rpc/defs.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/msgpack_rpc/server.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/handle.h"
+#include "nvim/api/private/dispatch.h"
/* Maximum number of commands from + or -c arguments. */
#define MAX_ARG_CMDS 10
diff --git a/src/nvim/map.c b/src/nvim/map.c
index 398e74268f..73af487f90 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -6,7 +6,7 @@
#include "nvim/map_defs.h"
#include "nvim/vim.h"
#include "nvim/memory.h"
-#include "nvim/msgpack_rpc/defs.h"
+#include "nvim/api/private/dispatch.h"
#include "nvim/lib/khash.h"
@@ -20,6 +20,8 @@
#define int_eq kh_int_hash_equal
#define linenr_T_hash kh_int_hash_func
#define linenr_T_eq kh_int_hash_equal
+#define handle_T_hash kh_int_hash_func
+#define handle_T_eq kh_int_hash_equal
#if defined(ARCH_64)
@@ -141,7 +143,8 @@ MAP_IMPL(cstr_t, uint64_t, DEFAULT_INITIALIZER)
MAP_IMPL(cstr_t, ptr_t, DEFAULT_INITIALIZER)
MAP_IMPL(ptr_t, ptr_t, DEFAULT_INITIALIZER)
MAP_IMPL(uint64_t, ptr_t, DEFAULT_INITIALIZER)
-#define MSGPACK_HANDLER_INITIALIZER {.fn = NULL, .async = false}
+MAP_IMPL(handle_T, ptr_t, DEFAULT_INITIALIZER)
+#define MSGPACK_HANDLER_INITIALIZER { .fn = NULL, .async = false }
MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER)
#define KVEC_INITIALIZER { .size = 0, .capacity = 0, .items = NULL }
MAP_IMPL(linenr_T, bufhl_vec_T, KVEC_INITIALIZER)
diff --git a/src/nvim/map.h b/src/nvim/map.h
index c7d9894bd1..ba3e84cb31 100644
--- a/src/nvim/map.h
+++ b/src/nvim/map.h
@@ -5,7 +5,7 @@
#include "nvim/map_defs.h"
#include "nvim/api/private/defs.h"
-#include "nvim/msgpack_rpc/defs.h"
+#include "nvim/api/private/dispatch.h"
#include "nvim/bufhl_defs.h"
#define MAP_DECLS(T, U) \
@@ -29,6 +29,7 @@ MAP_DECLS(cstr_t, uint64_t)
MAP_DECLS(cstr_t, ptr_t)
MAP_DECLS(ptr_t, ptr_t)
MAP_DECLS(uint64_t, ptr_t)
+MAP_DECLS(handle_T, ptr_t)
MAP_DECLS(String, MsgpackRpcRequestHandler)
MAP_DECLS(linenr_T, bufhl_vec_T)
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index fe802e48ba..2a65cf396b 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -21,7 +21,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/path.h"
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 26d94aa6fa..f577fd847e 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -84,7 +84,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/option.h"
#include "nvim/screen.h"
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c
index 9fb03c4ac7..43412e3916 100644
--- a/src/nvim/memfile.c
+++ b/src/nvim/memfile.c
@@ -48,7 +48,6 @@
#include "nvim/fileio.h"
#include "nvim/memline.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 08e82071d7..5505335769 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -55,7 +55,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/option.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
@@ -3964,20 +3963,19 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp)
return size;
}
-/*
- * Goto byte in buffer with offset 'cnt'.
- */
+/// Goto byte in buffer with offset 'cnt'.
void goto_byte(long cnt)
{
long boff = cnt;
linenr_T lnum;
- ml_flush_line(curbuf); /* cached line may be dirty */
+ ml_flush_line(curbuf); // cached line may be dirty
setpcmark();
- if (boff)
- --boff;
+ if (boff) {
+ boff--;
+ }
lnum = ml_find_line_or_offset(curbuf, (linenr_T)0, &boff);
- if (lnum < 1) { /* past the end */
+ if (lnum < 1) { // past the end
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
curwin->w_curswant = MAXCOL;
coladvance((colnr_T)MAXCOL);
@@ -3989,7 +3987,84 @@ void goto_byte(long cnt)
}
check_cursor();
- /* Make sure the cursor is on the first byte of a multi-byte char. */
- if (has_mbyte)
+ // Make sure the cursor is on the first byte of a multi-byte char.
+ if (has_mbyte) {
mb_adjust_cursor();
+ }
+}
+
+/// Increment the line pointer "lp" crossing line boundaries as necessary.
+/// Return 1 when going to the next line.
+/// Return 2 when moving forward onto a NUL at the end of the line).
+/// Return -1 when at the end of file.
+/// Return 0 otherwise.
+int inc(pos_T *lp)
+{
+ char_u *p = ml_get_pos(lp);
+
+ if (*p != NUL) { // still within line, move to next char (may be NUL)
+ if (has_mbyte) {
+ int l = (*mb_ptr2len)(p);
+
+ lp->col += l;
+ return (p[l] != NUL) ? 0 : 2;
+ }
+ lp->col++;
+ lp->coladd = 0;
+ return (p[1] != NUL) ? 0 : 2;
+ }
+ if (lp->lnum != curbuf->b_ml.ml_line_count) { // there is a next line
+ lp->col = 0;
+ lp->lnum++;
+ lp->coladd = 0;
+ return 1;
+ }
+ return -1;
+}
+
+/// Same as inc(), but skip NUL at the end of non-empty lines.
+int incl(pos_T *lp)
+{
+ int r;
+
+ if ((r = inc(lp)) >= 1 && lp->col) {
+ r = inc(lp);
+ }
+ return r;
+}
+
+int dec(pos_T *lp)
+{
+ char_u *p;
+
+ lp->coladd = 0;
+ if (lp->col > 0) { // still within line
+ lp->col--;
+ if (has_mbyte) {
+ p = ml_get(lp->lnum);
+ lp->col -= (*mb_head_off)(p, p + lp->col);
+ }
+ return 0;
+ }
+ if (lp->lnum > 1) { // there is a prior line
+ lp->lnum--;
+ p = ml_get(lp->lnum);
+ lp->col = (colnr_T)STRLEN(p);
+ if (has_mbyte) {
+ lp->col -= (*mb_head_off)(p, p + lp->col);
+ }
+ return 1;
+ }
+ return -1; // at start of file
+}
+
+/// Same as dec(), but skip NUL at the end of non-empty lines.
+int decl(pos_T *lp)
+{
+ int r;
+
+ if ((r = dec(lp)) == 1 && lp->col) {
+ r = dec(lp);
+ }
+ return r;
}
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index 8db47b79c1..3e041be4d3 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -440,6 +440,16 @@ void do_outofmem_msg(size_t size)
}
}
+/// Writes time_t to "buf[8]".
+void time_to_bytes(time_t time_, uint8_t buf[8])
+{
+ // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
+ // systems, thus we can't use put_bytes() here.
+ for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) {
+ buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8));
+ }
+}
+
#if defined(EXITFREE)
#include "nvim/file_search.h"
diff --git a/src/nvim/memory.h b/src/nvim/memory.h
index 7b477da2f5..62cc78360c 100644
--- a/src/nvim/memory.h
+++ b/src/nvim/memory.h
@@ -3,6 +3,7 @@
#include <stdint.h> // for uint8_t
#include <stddef.h> // for size_t
+#include <time.h> // for time_t
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "memory.h.generated.h"
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 3c2394d579..7c0eee64dd 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -18,9 +18,9 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 725c6b080a..1de2347b12 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -22,7 +22,6 @@
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
#include "nvim/ops.h"
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index d72d8e8513..4ab059c923 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -31,7 +31,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/mouse.h"
@@ -41,6 +40,7 @@
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
#include "nvim/ui.h"
@@ -742,10 +742,14 @@ open_line (
if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE)
== FAIL)
goto theend;
- /* Postpone calling changed_lines(), because it would mess up folding
- * with markers. */
- mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
- did_append = TRUE;
+ // Postpone calling changed_lines(), because it would mess up folding
+ // with markers.
+ // Skip mark_adjust when adding a line after the last one, there can't
+ // be marks there.
+ if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) {
+ mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
+ }
+ did_append = true;
} else {
/*
* In VREPLACE mode we are starting to replace the next line.
@@ -1742,18 +1746,6 @@ int gchar_pos(pos_T *pos)
}
/*
- * Skip to next part of an option argument: Skip space and comma.
- */
-char_u *skip_to_option_part(char_u *p)
-{
- if (*p == ',')
- ++p;
- while (*p == ' ')
- ++p;
- return p;
-}
-
-/*
* Call this function when something in the current buffer is changed.
*
* Most often called through changed_bytes() and changed_lines(), which also
@@ -1871,7 +1863,11 @@ void appended_lines(linenr_T lnum, long count)
*/
void appended_lines_mark(linenr_T lnum, long count)
{
- mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
+ // Skip mark_adjust when adding a line after the last one, there can't
+ // be marks there.
+ if (lnum + count < curbuf->b_ml.ml_line_count) {
+ mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
+ }
changed_lines(lnum + 1, 0, lnum + 1, count);
}
@@ -2683,6 +2679,42 @@ void fast_breakcheck(void)
}
}
+// Call shell. Calls os_call_shell, with 'shellxquote' added.
+int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
+{
+ int retval;
+ proftime_T wait_time;
+
+ if (p_verbose > 3) {
+ verbose_enter();
+ smsg(_("Calling shell to execute: \"%s\""),
+ cmd == NULL ? p_sh : cmd);
+ ui_putc('\n');
+ verbose_leave();
+ }
+
+ if (do_profiling == PROF_YES) {
+ prof_child_enter(&wait_time);
+ }
+
+ if (*p_sh == NUL) {
+ EMSG(_(e_shellempty));
+ retval = -1;
+ } else {
+ // The external command may update a tags file, clear cached tags.
+ tag_freematch();
+
+ retval = os_call_shell(cmd, opts, extra_shell_arg);
+ }
+
+ set_vim_var_nr(VV_SHELL_ERROR, (varnumber_T)retval);
+ if (do_profiling == PROF_YES) {
+ prof_child_exit(&wait_time);
+ }
+
+ return retval;
+}
+
/// Get the stdout of an external command.
/// If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not
/// NULL store the length there.
diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c
deleted file mode 100644
index 368f83cfb5..0000000000
--- a/src/nvim/misc2.c
+++ /dev/null
@@ -1,486 +0,0 @@
-/*
- * misc2.c: Various functions.
- */
-#include <assert.h>
-#include <inttypes.h>
-#include <string.h>
-
-#include "nvim/vim.h"
-#include "nvim/ascii.h"
-#include "nvim/misc2.h"
-#include "nvim/file_search.h"
-#include "nvim/buffer.h"
-#include "nvim/charset.h"
-#include "nvim/cursor.h"
-#include "nvim/diff.h"
-#include "nvim/edit.h"
-#include "nvim/eval.h"
-#include "nvim/ex_cmds.h"
-#include "nvim/ex_docmd.h"
-#include "nvim/ex_getln.h"
-#include "nvim/fileio.h"
-#include "nvim/fold.h"
-#include "nvim/getchar.h"
-#include "nvim/macros.h"
-#include "nvim/mark.h"
-#include "nvim/mbyte.h"
-#include "nvim/memfile.h"
-#include "nvim/memline.h"
-#include "nvim/memory.h"
-#include "nvim/message.h"
-#include "nvim/misc1.h"
-#include "nvim/move.h"
-#include "nvim/option.h"
-#include "nvim/ops.h"
-#include "nvim/os_unix.h"
-#include "nvim/path.h"
-#include "nvim/quickfix.h"
-#include "nvim/regexp.h"
-#include "nvim/screen.h"
-#include "nvim/search.h"
-#include "nvim/spell.h"
-#include "nvim/strings.h"
-#include "nvim/syntax.h"
-#include "nvim/tag.h"
-#include "nvim/ui.h"
-#include "nvim/window.h"
-#include "nvim/os/os.h"
-#include "nvim/os/shell.h"
-
-
-#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "misc2.c.generated.h"
-#endif
-/*
- * Return TRUE if in the current mode we need to use virtual.
- */
-int virtual_active(void)
-{
- /* While an operator is being executed we return "virtual_op", because
- * VIsual_active has already been reset, thus we can't check for "block"
- * being used. */
- if (virtual_op != MAYBE)
- return virtual_op;
- return ve_flags == VE_ALL
- || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
- || ((ve_flags & VE_INSERT) && (State & INSERT));
-}
-
-/*
- * Increment the line pointer "lp" crossing line boundaries as necessary.
- * Return 1 when going to the next line.
- * Return 2 when moving forward onto a NUL at the end of the line).
- * Return -1 when at the end of file.
- * Return 0 otherwise.
- */
-int inc(pos_T *lp)
-{
- char_u *p = ml_get_pos(lp);
-
- if (*p != NUL) { /* still within line, move to next char (may be NUL) */
- if (has_mbyte) {
- int l = (*mb_ptr2len)(p);
-
- lp->col += l;
- return (p[l] != NUL) ? 0 : 2;
- }
- lp->col++;
- lp->coladd = 0;
- return (p[1] != NUL) ? 0 : 2;
- }
- if (lp->lnum != curbuf->b_ml.ml_line_count) { /* there is a next line */
- lp->col = 0;
- lp->lnum++;
- lp->coladd = 0;
- return 1;
- }
- return -1;
-}
-
-/*
- * incl(lp): same as inc(), but skip the NUL at the end of non-empty lines
- */
-int incl(pos_T *lp)
-{
- int r;
-
- if ((r = inc(lp)) >= 1 && lp->col)
- r = inc(lp);
- return r;
-}
-
-int dec(pos_T *lp)
-{
- char_u *p;
-
- lp->coladd = 0;
- if (lp->col > 0) { /* still within line */
- lp->col--;
- if (has_mbyte) {
- p = ml_get(lp->lnum);
- lp->col -= (*mb_head_off)(p, p + lp->col);
- }
- return 0;
- }
- if (lp->lnum > 1) { /* there is a prior line */
- lp->lnum--;
- p = ml_get(lp->lnum);
- lp->col = (colnr_T)STRLEN(p);
- if (has_mbyte)
- lp->col -= (*mb_head_off)(p, p + lp->col);
- return 1;
- }
- return -1; /* at start of file */
-}
-
-/*
- * decl(lp): same as dec(), but skip the NUL at the end of non-empty lines
- */
-int decl(pos_T *lp)
-{
- int r;
-
- if ((r = dec(lp)) == 1 && lp->col)
- r = dec(lp);
- return r;
-}
-
-/*
- * Return TRUE when 'shell' has "csh" in the tail.
- */
-int csh_like_shell(void)
-{
- return strstr((char *)path_tail(p_sh), "csh") != NULL;
-}
-
-/*
- * Isolate one part of a string option where parts are separated with
- * "sep_chars".
- * The part is copied into "buf[maxlen]".
- * "*option" is advanced to the next part.
- * The length is returned.
- */
-size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen, char *sep_chars)
-{
- size_t len = 0;
- char_u *p = *option;
-
- /* skip '.' at start of option part, for 'suffixes' */
- if (*p == '.')
- buf[len++] = *p++;
- while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) {
- /*
- * Skip backslash before a separator character and space.
- */
- if (p[0] == '\\' && vim_strchr((char_u *)sep_chars, p[1]) != NULL)
- ++p;
- if (len < maxlen - 1)
- buf[len++] = *p;
- ++p;
- }
- buf[len] = NUL;
-
- if (*p != NUL && *p != ',') /* skip non-standard separator */
- ++p;
- p = skip_to_option_part(p); /* p points to next file name */
-
- *option = p;
- return len;
-}
-
-/*
- * Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
- */
-int get_fileformat(buf_T *buf)
-{
- int c = *buf->b_p_ff;
-
- if (buf->b_p_bin || c == 'u')
- return EOL_UNIX;
- if (c == 'm')
- return EOL_MAC;
- return EOL_DOS;
-}
-
-/*
- * Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val"
- * argument.
- */
-int
-get_fileformat_force (
- buf_T *buf,
- exarg_T *eap /* can be NULL! */
-)
-{
- int c;
-
- if (eap != NULL && eap->force_ff != 0)
- c = eap->cmd[eap->force_ff];
- else {
- if ((eap != NULL && eap->force_bin != 0)
- ? (eap->force_bin == FORCE_BIN) : buf->b_p_bin)
- return EOL_UNIX;
- c = *buf->b_p_ff;
- }
- if (c == 'u')
- return EOL_UNIX;
- if (c == 'm')
- return EOL_MAC;
- return EOL_DOS;
-}
-
-/// Set the current end-of-line type to EOL_UNIX, EOL_MAC, or EOL_DOS.
-///
-/// Sets 'fileformat'.
-///
-/// @param eol_style End-of-line style.
-/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
-void set_fileformat(int eol_style, int opt_flags)
-{
- char *p = NULL;
-
- switch (eol_style) {
- case EOL_UNIX:
- p = FF_UNIX;
- break;
- case EOL_MAC:
- p = FF_MAC;
- break;
- case EOL_DOS:
- p = FF_DOS;
- break;
- }
-
- // p is NULL if "eol_style" is EOL_UNKNOWN.
- if (p != NULL) {
- set_string_option_direct((char_u *)"ff",
- -1,
- (char_u *)p,
- OPT_FREE | opt_flags,
- 0);
- }
-
- // This may cause the buffer to become (un)modified.
- check_status(curbuf);
- redraw_tabline = TRUE;
- need_maketitle = TRUE; // Set window title later.
-}
-
-/*
- * Return the default fileformat from 'fileformats'.
- */
-int default_fileformat(void)
-{
- switch (*p_ffs) {
- case 'm': return EOL_MAC;
- case 'd': return EOL_DOS;
- }
- return EOL_UNIX;
-}
-
-// Call shell. Calls os_call_shell, with 'shellxquote' added.
-int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
-{
- char_u *ncmd;
- int retval;
- proftime_T wait_time;
-
- if (p_verbose > 3) {
- verbose_enter();
- smsg(_("Calling shell to execute: \"%s\""),
- cmd == NULL ? p_sh : cmd);
- ui_putc('\n');
- verbose_leave();
- }
-
- if (do_profiling == PROF_YES)
- prof_child_enter(&wait_time);
-
- if (*p_sh == NUL) {
- EMSG(_(e_shellempty));
- retval = -1;
- } else {
- /* The external command may update a tags file, clear cached tags. */
- tag_freematch();
-
- if (cmd == NULL || *p_sxq == NUL)
- retval = os_call_shell(cmd, opts, extra_shell_arg);
- else {
- char_u *ecmd = cmd;
-
- if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0) {
- ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', FALSE);
- }
- ncmd = xmalloc(STRLEN(ecmd) + STRLEN(p_sxq) * 2 + 1);
- STRCPY(ncmd, p_sxq);
- STRCAT(ncmd, ecmd);
- /* When 'shellxquote' is ( append ).
- * When 'shellxquote' is "( append )". */
- STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
- : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
- : p_sxq);
- retval = os_call_shell(ncmd, opts, extra_shell_arg);
- xfree(ncmd);
-
- if (ecmd != cmd)
- xfree(ecmd);
- }
- }
-
- set_vim_var_nr(VV_SHELL_ERROR, (varnumber_T) retval);
- if (do_profiling == PROF_YES) {
- prof_child_exit(&wait_time);
- }
-
- return retval;
-}
-
-/*
- * VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to
- * NORMAL State with a condition. This function returns the real State.
- */
-int get_real_state(void)
-{
- if (State & NORMAL) {
- if (VIsual_active) {
- if (VIsual_select)
- return SELECTMODE;
- return VISUAL;
- } else if (finish_op)
- return OP_PENDING;
- }
- return State;
-}
-
-/*
- * Change to a file's directory.
- * Caller must call shorten_fnames()!
- * Return OK or FAIL.
- */
-int vim_chdirfile(char_u *fname)
-{
- char_u dir[MAXPATHL];
-
- STRLCPY(dir, fname, MAXPATHL);
- *path_tail_with_sep(dir) = NUL;
- return os_chdir((char *)dir) == 0 ? OK : FAIL;
-}
-
-/*
- * Change directory to "new_dir". Search 'cdpath' for relative directory names.
- */
-int vim_chdir(char_u *new_dir)
-{
- char_u *dir_name;
- int r;
-
- dir_name = find_directory_in_path(new_dir, STRLEN(new_dir),
- FNAME_MESS, curbuf->b_ffname);
- if (dir_name == NULL)
- return -1;
- r = os_chdir((char *)dir_name);
- xfree(dir_name);
- return r;
-}
-
-/*
- * Read 2 bytes from "fd" and turn them into an int, MSB first.
- */
-int get2c(FILE *fd)
-{
- int n;
-
- n = getc(fd);
- n = (n << 8) + getc(fd);
- return n;
-}
-
-/*
- * Read 3 bytes from "fd" and turn them into an int, MSB first.
- */
-int get3c(FILE *fd)
-{
- int n;
-
- n = getc(fd);
- n = (n << 8) + getc(fd);
- n = (n << 8) + getc(fd);
- return n;
-}
-
-/*
- * Read 4 bytes from "fd" and turn them into an int, MSB first.
- */
-int get4c(FILE *fd)
-{
- /* Use unsigned rather than int otherwise result is undefined
- * when left-shift sets the MSB. */
- unsigned n;
-
- n = (unsigned)getc(fd);
- n = (n << 8) + (unsigned)getc(fd);
- n = (n << 8) + (unsigned)getc(fd);
- n = (n << 8) + (unsigned)getc(fd);
- return (int)n;
-}
-
-/*
- * Read 8 bytes from "fd" and turn them into a time_t, MSB first.
- */
-time_t get8ctime(FILE *fd)
-{
- time_t n = 0;
- int i;
-
- for (i = 0; i < 8; ++i)
- n = (n << 8) + getc(fd);
- return n;
-}
-
-/// Reads a string of length "cnt" from "fd" into allocated memory.
-/// @return pointer to the string or NULL when unable to read that many bytes.
-char *read_string(FILE *fd, size_t cnt)
-{
- uint8_t *str = xmallocz(cnt);
- for (size_t i = 0; i < cnt; i++) {
- int c = getc(fd);
- if (c == EOF) {
- xfree(str);
- return NULL;
- }
- str[i] = (uint8_t)c;
- }
- return (char *)str;
-}
-
-/// Writes a number to file "fd", most significant bit first, in "len" bytes.
-/// @returns false in case of an error.
-bool put_bytes(FILE *fd, uintmax_t number, size_t len)
-{
- assert(len > 0);
- for (size_t i = len - 1; i < len; i--) {
- if (putc((int)(number >> (i * 8)), fd) == EOF) {
- return false;
- }
- }
- return true;
-}
-
-/// Writes time_t to file "fd" in 8 bytes.
-/// @returns FAIL when the write failed.
-int put_time(FILE *fd, time_t time_)
-{
- uint8_t buf[8];
- time_to_bytes(time_, buf);
- return fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd) == 1 ? OK : FAIL;
-}
-
-/// Writes time_t to "buf[8]".
-void time_to_bytes(time_t time_, uint8_t buf[8])
-{
- // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits
- // systems, thus we can't use put_bytes() here.
- for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) {
- buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8));
- }
-}
diff --git a/src/nvim/misc2.h b/src/nvim/misc2.h
deleted file mode 100644
index 28b5b775d2..0000000000
--- a/src/nvim/misc2.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef NVIM_MISC2_H
-#define NVIM_MISC2_H
-
-#include "nvim/os/shell.h"
-
-#define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y))
-
-#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "misc2.h.generated.h"
-#endif
-
-#endif // NVIM_MISC2_H
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 5efac2623c..2ebe199f47 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -4,6 +4,7 @@
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/window.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/screen.h"
#include "nvim/syntax.h"
diff --git a/src/nvim/move.c b/src/nvim/move.c
index b129c5cb7a..4c814f3ae0 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -24,7 +24,6 @@
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/popupmnu.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index 8b5f212d66..cd12f258b6 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -465,8 +465,7 @@ static void on_request_event(void **argv)
} else {
api_free_object(result);
}
- // All arguments were freed already, but we still need to free the array
- xfree(args.items);
+ api_free_array(args);
decref(channel);
xfree(e);
}
diff --git a/src/nvim/msgpack_rpc/defs.h b/src/nvim/msgpack_rpc/defs.h
deleted file mode 100644
index 5611636d4f..0000000000
--- a/src/nvim/msgpack_rpc/defs.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef NVIM_MSGPACK_RPC_DEFS_H
-#define NVIM_MSGPACK_RPC_DEFS_H
-
-
-/// The rpc_method_handlers table, used in msgpack_rpc_dispatch(), stores
-/// functions of this type.
-typedef struct {
- Object (*fn)(uint64_t channel_id,
- uint64_t request_id,
- Array args,
- Error *error);
- bool async; // function is always safe to run immediately instead of being
- // put in a request queue for handling when nvim waits for input.
-} MsgpackRpcRequestHandler;
-
-/// Initializes the msgpack-rpc method table
-void msgpack_rpc_init_method_table(void);
-
-// Add a handler to the method table
-void msgpack_rpc_add_method_handler(String method,
- MsgpackRpcRequestHandler handler);
-
-void msgpack_rpc_init_function_metadata(Dictionary *metadata);
-
-MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name,
- size_t name_len)
- FUNC_ATTR_NONNULL_ARG(1);
-#endif // NVIM_MSGPACK_RPC_DEFS_H
diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c
index 9195b10614..33e9bb1c07 100644
--- a/src/nvim/msgpack_rpc/helpers.c
+++ b/src/nvim/msgpack_rpc/helpers.c
@@ -4,9 +4,9 @@
#include <msgpack.h>
+#include "nvim/api/private/dispatch.h"
#include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/helpers.h"
-#include "nvim/msgpack_rpc/defs.h"
#include "nvim/lib/kvec.h"
#include "nvim/vim.h"
#include "nvim/log.h"
@@ -40,7 +40,7 @@ static msgpack_sbuffer sbuffer;
return false; \
} \
\
- *arg = data.via.u64; \
+ *arg = (handle_T)data.via.i64; \
return true; \
} \
\
@@ -49,7 +49,7 @@ static msgpack_sbuffer sbuffer;
{ \
msgpack_packer pac; \
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
- msgpack_pack_uint64(&pac, o); \
+ msgpack_pack_int64(&pac, o); \
msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
msgpack_sbuffer_clear(&sbuffer); \
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index c95e5e1a15..d0a9d3aca7 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -36,7 +36,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/move.h"
#include "nvim/mouse.h"
@@ -2110,6 +2109,20 @@ static void op_function(oparg_T *oap)
}
}
+// Move the current tab to tab in same column as mouse or to end of the
+// tabline if there is no tab there.
+static void move_tab_to_mouse(void)
+{
+ int tabnr = tab_page_click_defs[mouse_col].tabnr;
+ if (tabnr <= 0) {
+ tabpage_move(9999);
+ } else if (tabnr < tabpage_index(curtab)) {
+ tabpage_move(tabnr - 1);
+ } else {
+ tabpage_move(tabnr);
+ }
+}
+
/*
* Do the appropriate action for the current mouse click in the current mode.
* Not used for Command-line mode.
@@ -2346,12 +2359,7 @@ do_mouse (
if (mouse_row == 0 && firstwin->w_winrow > 0) {
if (is_drag) {
if (in_tab_line) {
- if (tab_page_click_defs[mouse_col].type == kStlClickTabClose) {
- tabpage_move(9999);
- } else {
- int tabnr = tab_page_click_defs[mouse_col].tabnr;
- tabpage_move(tabnr < tabpage_index(curtab) ? tabnr - 1 : tabnr);
- }
+ move_tab_to_mouse();
}
return false;
}
@@ -2466,10 +2474,7 @@ do_mouse (
}
return true;
} else if (is_drag && in_tab_line) {
- tabpage_move(tab_page_click_defs[mouse_col].type == kStlClickTabClose
- ? 9999
- : tab_page_click_defs[mouse_col].tabnr - 1);
- in_tab_line = false;
+ move_tab_to_mouse();
return false;
}
@@ -5919,6 +5924,9 @@ static void nv_replace(cmdarg_T *cap)
curwin->w_set_curswant = true;
set_last_insert(cap->nchar);
}
+
+ foldUpdateAll(curwin);
+ foldOpenCursor();
}
/*
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index e8a79fa820..388a72adce 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -30,13 +30,13 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/path.h"
#include "nvim/screen.h"
#include "nvim/search.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
@@ -51,10 +51,10 @@ static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */
static bool clipboard_didwarn_unnamed = false;
-// for behavior between start_global_changes() and end_global_changes())
+// for behavior between start_batch_changes() and end_batch_changes())
static bool clipboard_delay_update = false; // delay clipboard update
-static int global_change_count = 0; // if set, inside global changes
-static bool clipboard_needs_update = false; // the clipboard was updated
+static int batch_change_count = 0; // inside a script
+static bool clipboard_needs_update = false; // clipboard was updated
/*
* structure used by block_prep, op_delete and op_yank for blockwise operators
@@ -3110,8 +3110,13 @@ error:
if (dir == FORWARD)
curbuf->b_op_start.lnum++;
}
- mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
- (linenr_T)MAXLNUM, nr_lines, 0L);
+ // Skip mark_adjust when adding lines after the last one, there
+ // can't be marks there.
+ if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines
+ < curbuf->b_ml.ml_line_count) {
+ mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
+ (linenr_T)MAXLNUM, nr_lines, 0L);
+ }
// note changed text for displaying and folding
if (y_type == kMTCharWise) {
@@ -5630,20 +5635,20 @@ static void set_clipboard(int name, yankreg_T *reg)
(void)eval_call_provider("clipboard", "set", args);
}
-/// Avoid clipboard (slow) during batch operations (:global).
-void start_global_changes(void)
+/// Avoid clipboard (slow) during batch operations (i.e., a script).
+void start_batch_changes(void)
{
- if (++global_change_count > 1) {
+ if (++batch_change_count > 1) {
return;
}
clipboard_delay_update = true;
clipboard_needs_update = false;
}
-/// Update the clipboard after :global changes finished.
-void end_global_changes(void)
+/// Update the clipboard after batch changes finished.
+void end_batch_changes(void)
{
- if (--global_change_count > 0) {
+ if (--batch_change_count > 0) {
// recursive
return;
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index e53dbfc75a..d8908cca90 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -6585,10 +6585,8 @@ int get_sw_value(buf_T *buf)
return (int)result;
}
-/*
- * Return the effective softtabstop value for the current buffer, using the
- * 'tabstop' value when 'softtabstop' is negative.
- */
+// Return the effective softtabstop value for the current buffer,
+// using the effective shiftwidth value when 'softtabstop' is negative.
int get_sts_value(void)
{
long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
@@ -6714,3 +6712,148 @@ unsigned int get_bkc_value(buf_T *buf)
{
return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
}
+
+/// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
+int get_fileformat(buf_T *buf)
+{
+ int c = *buf->b_p_ff;
+
+ if (buf->b_p_bin || c == 'u') {
+ return EOL_UNIX;
+ }
+ if (c == 'm') {
+ return EOL_MAC;
+ }
+ return EOL_DOS;
+}
+
+/// Like get_fileformat(), but override 'fileformat' with "p" for "++opt=val"
+/// argument.
+///
+/// @param eap can be NULL!
+int get_fileformat_force(buf_T *buf, exarg_T *eap)
+{
+ int c;
+
+ if (eap != NULL && eap->force_ff != 0) {
+ c = eap->cmd[eap->force_ff];
+ } else {
+ if ((eap != NULL && eap->force_bin != 0)
+ ? (eap->force_bin == FORCE_BIN) : buf->b_p_bin) {
+ return EOL_UNIX;
+ }
+ c = *buf->b_p_ff;
+ }
+ if (c == 'u') {
+ return EOL_UNIX;
+ }
+ if (c == 'm') {
+ return EOL_MAC;
+ }
+ return EOL_DOS;
+}
+
+/// Return the default fileformat from 'fileformats'.
+int default_fileformat(void)
+{
+ switch (*p_ffs) {
+ case 'm': return EOL_MAC;
+ case 'd': return EOL_DOS;
+ }
+ return EOL_UNIX;
+}
+
+/// Set the current end-of-line type to EOL_UNIX, EOL_MAC, or EOL_DOS.
+///
+/// Sets 'fileformat'.
+///
+/// @param eol_style End-of-line style.
+/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
+void set_fileformat(int eol_style, int opt_flags)
+{
+ char *p = NULL;
+
+ switch (eol_style) {
+ case EOL_UNIX:
+ p = FF_UNIX;
+ break;
+ case EOL_MAC:
+ p = FF_MAC;
+ break;
+ case EOL_DOS:
+ p = FF_DOS;
+ break;
+ }
+
+ // p is NULL if "eol_style" is EOL_UNKNOWN.
+ if (p != NULL) {
+ set_string_option_direct((char_u *)"ff",
+ -1,
+ (char_u *)p,
+ OPT_FREE | opt_flags,
+ 0);
+ }
+
+ // This may cause the buffer to become (un)modified.
+ check_status(curbuf);
+ redraw_tabline = true;
+ need_maketitle = true; // Set window title later.
+}
+
+/// Skip to next part of an option argument: Skip space and comma.
+char_u *skip_to_option_part(char_u *p)
+{
+ if (*p == ',') {
+ p++;
+ }
+ while (*p == ' ') {
+ p++;
+ }
+ return p;
+}
+
+/// Isolate one part of a string option separated by `sep_chars`.
+///
+/// @param[in,out] option advanced to the next part
+/// @param[in,out] buf copy of the isolated part
+/// @param[in] maxlen length of `buf`
+/// @param[in] sep_chars chars that separate the option parts
+///
+/// @return length of `*option`
+size_t copy_option_part(char_u **option, char_u *buf, size_t maxlen,
+ char *sep_chars)
+{
+ size_t len = 0;
+ char_u *p = *option;
+
+ // skip '.' at start of option part, for 'suffixes'
+ if (*p == '.') {
+ buf[len++] = *p++;
+ }
+ while (*p != NUL && vim_strchr((char_u *)sep_chars, *p) == NULL) {
+ // Skip backslash before a separator character and space.
+ if (p[0] == '\\' && vim_strchr((char_u *)sep_chars, p[1]) != NULL) {
+ p++;
+ }
+ if (len < maxlen - 1) {
+ buf[len++] = *p;
+ }
+ p++;
+ }
+ buf[len] = NUL;
+
+ if (*p != NUL && *p != ',') { // skip non-standard separator
+ p++;
+ }
+ p = skip_to_option_part(p); // p points to next file name
+
+ *option = p;
+ return len;
+}
+
+/// Return TRUE when 'shell' has "csh" in the tail.
+int csh_like_shell(void)
+{
+ return strstr((char *)path_tail(p_sh), "csh") != NULL;
+}
+
diff --git a/src/nvim/option.h b/src/nvim/option.h
index 3a43b859a8..cf167cdd2c 100644
--- a/src/nvim/option.h
+++ b/src/nvim/option.h
@@ -1,6 +1,8 @@
#ifndef NVIM_OPTION_H
#define NVIM_OPTION_H
+#include "nvim/ex_cmds_defs.h" // for exarg_T
+
/* flags for buf_copy_options() */
#define BCO_ENTER 1 /* going to enter the buffer */
#define BCO_ALWAYS 2 /* always copy the options */
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index edc430410c..83a0262545 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -12,7 +12,6 @@
#include "nvim/os/os.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/eval.h"
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index e63b8b6793..008952fa97 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -21,7 +21,6 @@
#include "nvim/message.h"
#include "nvim/assert.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/path.h"
#include "nvim/strings.h"
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index c0c73364c0..6873e32f34 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -19,7 +19,7 @@
#include "nvim/getchar.h"
#include "nvim/main.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
+#include "nvim/state.h"
#define READ_BUFFER_SIZE 0xfff
#define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4)
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index ba52b9f661..661b12accc 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -19,7 +19,6 @@
#include "nvim/message.h"
#include "nvim/memory.h"
#include "nvim/ui.h"
-#include "nvim/misc2.h"
#include "nvim/screen.h"
#include "nvim/memline.h"
#include "nvim/option_defs.h"
@@ -54,12 +53,12 @@ char **shell_build_argv(const char *cmd, const char *extra_args)
size_t i = tokenize(p_sh, rv);
if (extra_args) {
- rv[i++] = xstrdup(extra_args); // Push a copy of `extra_args`
+ rv[i++] = xstrdup(extra_args); // Push a copy of `extra_args`
}
if (cmd) {
- i += tokenize(p_shcf, rv + i); // Split 'shellcmdflag'
- rv[i++] = xstrdup(cmd); // Push a copy of the command.
+ i += tokenize(p_shcf, rv + i); // Split 'shellcmdflag'
+ rv[i++] = shell_xescape_xquote(cmd); // Copy (and escape) `cmd`.
}
rv[i] = NULL;
@@ -548,3 +547,39 @@ static void shell_write_cb(Stream *stream, void *data, int status)
{
stream_close(stream, NULL, NULL);
}
+
+/// Applies 'shellxescape' (p_sxe) and 'shellxquote' (p_sxq) to a command.
+///
+/// @param cmd Command string
+/// @return Escaped/quoted command string (allocated).
+static char *shell_xescape_xquote(const char *cmd)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT
+{
+ if (*p_sxq == NUL) {
+ return xstrdup(cmd);
+ }
+
+ const char *ecmd = cmd;
+ if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0) {
+ ecmd = (char *)vim_strsave_escaped_ext((char_u *)cmd, p_sxe, '^', false);
+ }
+ size_t ncmd_size = strlen(ecmd) + STRLEN(p_sxq) * 2 + 1;
+ char *ncmd = xmalloc(ncmd_size);
+
+ // When 'shellxquote' is ( append ).
+ // When 'shellxquote' is "( append )".
+ if (STRCMP(p_sxq, "(") == 0) {
+ vim_snprintf(ncmd, ncmd_size, "(%s)", ecmd);
+ } else if (STRCMP(p_sxq, "\"(") == 0) {
+ vim_snprintf(ncmd, ncmd_size, "\"(%s)\"", ecmd);
+ } else {
+ vim_snprintf(ncmd, ncmd_size, "%s%s%s", p_sxq, ecmd, p_sxq);
+ }
+
+ if (ecmd != cmd) {
+ xfree((void *)ecmd);
+ }
+
+ return ncmd;
+}
+
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index 4abc9cfc36..1ac6d3f5e1 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -2,6 +2,9 @@
#include <stdbool.h>
#include <uv.h>
+#ifndef WIN32
+# include <signal.h> // for sigset_t
+#endif
#include "nvim/ascii.h"
#include "nvim/vim.h"
@@ -11,7 +14,6 @@
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/event/signal.h"
#include "nvim/os/signal.h"
#include "nvim/event/loop.h"
@@ -29,6 +31,16 @@ static bool rejecting_deadly;
void signal_init(void)
{
+#ifndef WIN32
+ // Ensure a clean slate by unblocking all signals. For example, if SIGCHLD is
+ // blocked, libuv may hang after spawning a subprocess on Linux. #5230
+ sigset_t mask;
+ sigemptyset(&mask);
+ if (pthread_sigmask(SIG_SETMASK, &mask, NULL) != 0) {
+ ELOG("Could not unblock signals, nvim might behave strangely.");
+ }
+#endif
+
signal_watcher_init(&main_loop, &spipe, NULL);
signal_watcher_init(&main_loop, &shup, NULL);
signal_watcher_init(&main_loop, &squit, NULL);
diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c
index 8ebb7562ef..1c94ef0067 100644
--- a/src/nvim/os/users.c
+++ b/src/nvim/os/users.c
@@ -6,7 +6,6 @@
#include "nvim/os/os.h"
#include "nvim/garray.h"
#include "nvim/memory.h"
-#include "nvim/misc2.h"
#include "nvim/strings.h"
#ifdef HAVE_PWD_H
# include <pwd.h>
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index def7e3b0e5..08294fa6a0 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -27,7 +27,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/mouse.h"
#include "nvim/garray.h"
#include "nvim/path.h"
diff --git a/src/nvim/path.c b/src/nvim/path.c
index a2617973b1..a79b7139f1 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -18,7 +18,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index 5ad621e666..947814de4f 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -7,12 +7,12 @@
#include <stdbool.h>
#include "nvim/vim.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/popupmnu.h"
#include "nvim/charset.h"
#include "nvim/ex_cmds.h"
#include "nvim/memline.h"
-#include "nvim/misc2.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/screen.h"
@@ -21,6 +21,7 @@
#include "nvim/memory.h"
#include "nvim/window.h"
#include "nvim/edit.h"
+#include "nvim/ui.h"
static pumitem_T *pum_array = NULL; // items of displayed pum
static int pum_size; // nr of items in "pum_array"
@@ -36,8 +37,10 @@ static int pum_scrollbar; // TRUE when scrollbar present
static int pum_row; // top row of pum
static int pum_col; // left column of pum
-static int pum_do_redraw = FALSE; // do redraw anyway
+static bool pum_is_visible = false;
+static bool pum_external = false;
+static bool pum_wants_external = false;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "popupmnu.c.generated.h"
@@ -53,7 +56,10 @@ static int pum_do_redraw = FALSE; // do redraw anyway
/// @param array
/// @param size
/// @param selected index of initially selected item, none if out of range
-void pum_display(pumitem_T *array, int size, int selected)
+/// @param array_changed if true, array contains different items since last call
+/// if false, a new item is selected, but the array
+/// is the same
+void pum_display(pumitem_T *array, int size, int selected, bool array_changed)
{
int w;
int def_width;
@@ -68,20 +74,55 @@ void pum_display(pumitem_T *array, int size, int selected)
int above_row = cmdline_row;
int redo_count = 0;
+ if (!pum_is_visible) {
+ // To keep the code simple, we only allow changing the
+ // draw mode when the popup menu is not being displayed
+ pum_external = pum_wants_external;
+ }
+
redo:
+ // Mark the pum as visible already here,
+ // to avoid that must_redraw is set when 'cursorcolumn' is on.
+ pum_is_visible = true;
+ validate_cursor_col();
+
+ // anchor position: the start of the completed word
+ row = curwin->w_wrow + curwin->w_winrow;
+ if (curwin->w_p_rl) {
+ col = curwin->w_wincol + curwin->w_width - curwin->w_wcol - 1;
+ } else {
+ col = curwin->w_wincol + curwin->w_wcol;
+ }
+
+ if (pum_external) {
+ Array args = ARRAY_DICT_INIT;
+ if (array_changed) {
+ Array arr = ARRAY_DICT_INIT;
+ for (i = 0; i < size; i++) {
+ Array item = ARRAY_DICT_INIT;
+ ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_text)));
+ ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_kind)));
+ ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_extra)));
+ ADD(item, STRING_OBJ(cstr_to_string((char *)array[i].pum_info)));
+ ADD(arr, ARRAY_OBJ(item));
+ }
+ ADD(args, ARRAY_OBJ(arr));
+ ADD(args, INTEGER_OBJ(selected));
+ ADD(args, INTEGER_OBJ(row));
+ ADD(args, INTEGER_OBJ(col));
+ ui_event("popupmenu_show", args);
+ } else {
+ ADD(args, INTEGER_OBJ(selected));
+ ui_event("popupmenu_select", args);
+ }
+ return;
+ }
+
def_width = PUM_DEF_WIDTH;
max_width = 0;
kind_width = 0;
extra_width = 0;
- // Pretend the pum is already there to avoid that must_redraw is set when
- // 'cuc' is on.
- pum_array = (pumitem_T *)1;
- validate_cursor_col();
- pum_array = NULL;
-
- row = curwin->w_wrow + curwin->w_winrow;
-
if (firstwin->w_p_pvw) {
top_clear = firstwin->w_height;
} else {
@@ -194,13 +235,6 @@ redo:
pum_base_width = max_width;
pum_kind_width = kind_width;
- // Calculate column
- if (curwin->w_p_rl) {
- col = curwin->w_wincol + curwin->w_width - curwin->w_wcol - 1;
- } else {
- col = curwin->w_wincol + curwin->w_wcol;
- }
-
// if there are more items than room we need a scrollbar
if (pum_height < size) {
pum_scrollbar = 1;
@@ -641,9 +675,9 @@ static int pum_set_selected(int n, int repeat)
// Update the screen before drawing the popup menu.
// Enable updating the status lines.
- pum_do_redraw = TRUE;
+ pum_is_visible = false;
update_screen(0);
- pum_do_redraw = FALSE;
+ pum_is_visible = true;
if (!resized && win_valid(curwin_save)) {
no_u_sync++;
@@ -653,9 +687,9 @@ static int pum_set_selected(int n, int repeat)
// May need to update the screen again when there are
// autocommands involved.
- pum_do_redraw = TRUE;
+ pum_is_visible = false;
update_screen(0);
- pum_do_redraw = FALSE;
+ pum_is_visible = true;
}
}
}
@@ -672,10 +706,17 @@ static int pum_set_selected(int n, int repeat)
/// Undisplay the popup menu (later).
void pum_undisplay(void)
{
+ pum_is_visible = false;
pum_array = NULL;
- redraw_all_later(SOME_VALID);
- redraw_tabline = TRUE;
- status_redraw_all();
+
+ if (pum_external) {
+ Array args = ARRAY_DICT_INIT;
+ ui_event("popupmenu_hide", args);
+ } else {
+ redraw_all_later(SOME_VALID);
+ redraw_tabline = true;
+ status_redraw_all();
+ }
}
/// Clear the popup menu. Currently only resets the offset to the first
@@ -685,12 +726,16 @@ void pum_clear(void)
pum_first = 0;
}
-/// Overruled when "pum_do_redraw" is set, used to redraw the status lines.
-///
-/// @return TRUE if the popup menu is displayed.
-int pum_visible(void)
+/// @return true if the popup menu is displayed.
+bool pum_visible(void)
{
- return !pum_do_redraw && pum_array != NULL;
+ return pum_is_visible;
+}
+
+/// @return true if the popup menu is displayed and drawn on the grid.
+bool pum_drawn(void)
+{
+ return pum_visible() && !pum_external;
}
/// Gets the height of the menu.
@@ -701,3 +746,8 @@ int pum_get_height(void)
{
return pum_height;
}
+
+void pum_set_external(bool external)
+{
+ pum_wants_external = external;
+}
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 20bd0a62b8..a7aff15121 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -27,7 +27,6 @@
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/normal.h"
@@ -1732,15 +1731,29 @@ void qf_list(exarg_T *eap)
EMSG(_(e_quickfix));
return;
}
+
+ bool plus = false;
+ if (*arg == '+') {
+ arg++;
+ plus = true;
+ }
if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) {
EMSG(_(e_trailing));
return;
}
- i = qi->qf_lists[qi->qf_curlist].qf_count;
- if (idx1 < 0)
- idx1 = (-idx1 > i) ? 0 : idx1 + i + 1;
- if (idx2 < 0)
- idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
+ if (plus) {
+ i = qi->qf_lists[qi->qf_curlist].qf_index;
+ idx2 = i + idx1;
+ idx1 = i;
+ } else {
+ i = qi->qf_lists[qi->qf_curlist].qf_count;
+ if (idx1 < 0) {
+ idx1 = (-idx1 > i) ? 0 : idx1 + i + 1;
+ }
+ if (idx2 < 0) {
+ idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
+ }
+ }
if (qi->qf_lists[qi->qf_curlist].qf_nonevalid)
all = TRUE;
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index f8fd7d4ef8..64a70c295a 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -59,7 +59,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/strings.h"
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index 92dbd693ea..35308b7411 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -11,7 +11,6 @@
#include <limits.h>
#include "nvim/ascii.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
/*
@@ -4855,9 +4854,15 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// recursive_regmatch(). Allow interrupting them with CTRL-C.
fast_breakcheck();
if (got_int) {
+#ifdef NFA_REGEXP_DEBUG_LOG
+ fclose(debug);
+#endif
return false;
}
if (nfa_time_limit != NULL && profile_passed_limit(*nfa_time_limit)) {
+#ifdef NFA_REGEXP_DEBUG_LOG
+ fclose(debug);
+#endif
return false;
}
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 61c88b5875..9a2eeda8b2 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -108,7 +108,6 @@
#include "nvim/menu.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/normal.h"
@@ -120,6 +119,7 @@
#include "nvim/regexp.h"
#include "nvim/search.h"
#include "nvim/spell.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/terminal.h"
@@ -420,9 +420,10 @@ void update_screen(int type)
}
}
end_search_hl();
- /* May need to redraw the popup menu. */
- if (pum_visible())
+ // May need to redraw the popup menu.
+ if (pum_drawn()) {
pum_redraw();
+ }
/* Reset b_mod_set flags. Going through all windows is probably faster
* than going through all buffers (there could be many buffers). */
@@ -4827,15 +4828,12 @@ void win_redr_status(win_T *wp)
wp->w_redr_status = FALSE;
if (wp->w_status_height == 0) {
- /* no status line, can only be last window */
- redraw_cmdline = TRUE;
- } else if (!redrawing()
- /* don't update status line when popup menu is visible and may be
- * drawn over it */
- || pum_visible()
- ) {
- /* Don't redraw right now, do it later. */
- wp->w_redr_status = TRUE;
+ // no status line, can only be last window
+ redraw_cmdline = true;
+ } else if (!redrawing() || pum_drawn()) {
+ // Don't redraw right now, do it later. Don't update status line when
+ // popup menu is visible and may be drawn over it
+ wp->w_redr_status = true;
} else if (*p_stl != NUL || *wp->w_p_stl != NUL) {
/* redraw custom status line */
redraw_custom_statusline(wp);
@@ -7081,9 +7079,9 @@ void showruler(int always)
{
if (!always && !redrawing())
return;
- if (pum_visible()) {
- /* Don't redraw right now, do it later. */
- curwin->w_redr_status = TRUE;
+ if (pum_drawn()) {
+ // Don't redraw right now, do it later.
+ curwin->w_redr_status = true;
return;
}
if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) {
@@ -7119,9 +7117,10 @@ static void win_redr_ruler(win_T *wp, int always)
if (wp == lastwin && lastwin->w_status_height == 0)
if (edit_submode != NULL)
return;
- /* Don't draw the ruler when the popup menu is visible, it may overlap. */
- if (pum_visible())
+ // Don't draw the ruler when the popup menu is visible, it may overlap.
+ if (pum_drawn()) {
return;
+ }
if (*p_ruf) {
int save_called_emsg = called_emsg;
@@ -7371,7 +7370,7 @@ void screen_resize(int width, int height)
redrawcmdline();
} else {
update_topline();
- if (pum_visible()) {
+ if (pum_drawn()) {
redraw_later(NOT_VALID);
ins_compl_show_pum(); /* This includes the redraw. */
} else
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 6e2b69fff7..5f4df3be92 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -31,7 +31,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/move.h"
#include "nvim/mouse.h"
#include "nvim/normal.h"
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index fe62f06e59..01c0807d82 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -27,7 +27,6 @@
#include "nvim/api/private/helpers.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
-#include "nvim/misc2.h"
#include "nvim/ex_getln.h"
#include "nvim/search.h"
#include "nvim/regexp.h"
@@ -2976,7 +2975,7 @@ shada_write_file_nomerge: {}
if (sd_writer.cookie == NULL) {
xfree(fname);
xfree(tempname);
- if (sd_reader.close != NULL) {
+ if (sd_reader.cookie != NULL) {
sd_reader.close(&sd_reader);
}
return FAIL;
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 610fb660e7..ba7f31be25 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -312,7 +312,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/garray.h"
#include "nvim/normal.h"
#include "nvim/option.h"
diff --git a/src/nvim/state.c b/src/nvim/state.c
index 30133e2201..f792ec00a4 100644
--- a/src/nvim/state.c
+++ b/src/nvim/state.c
@@ -2,10 +2,12 @@
#include "nvim/lib/kvec.h"
+#include "nvim/ascii.h"
#include "nvim/state.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/getchar.h"
+#include "nvim/option_defs.h"
#include "nvim/ui.h"
#include "nvim/os/input.h"
@@ -61,3 +63,35 @@ getkey:
}
}
}
+
+/// Return TRUE if in the current mode we need to use virtual.
+int virtual_active(void)
+{
+ // While an operator is being executed we return "virtual_op", because
+ // VIsual_active has already been reset, thus we can't check for "block"
+ // being used.
+ if (virtual_op != MAYBE) {
+ return virtual_op;
+ }
+ return ve_flags == VE_ALL
+ || ((ve_flags & VE_BLOCK) && VIsual_active && VIsual_mode == Ctrl_V)
+ || ((ve_flags & VE_INSERT) && (State & INSERT));
+}
+
+/// VISUAL, SELECTMODE and OP_PENDING State are never set, they are equal to
+/// NORMAL State with a condition. This function returns the real State.
+int get_real_state(void)
+{
+ if (State & NORMAL) {
+ if (VIsual_active) {
+ if (VIsual_select) {
+ return SELECTMODE;
+ }
+ return VISUAL;
+ } else if (finish_op) {
+ return OP_PENDING;
+ }
+ }
+ return State;
+}
+
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 37a0fb82da..c1800a0639 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -5,7 +5,6 @@
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/strings.h"
-#include "nvim/misc2.h"
#include "nvim/file_search.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index f7a8e4f8b9..6fd7603629 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -25,7 +25,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/keymap.h"
#include "nvim/garray.h"
#include "nvim/option.h"
@@ -6598,6 +6597,9 @@ do_highlight (
else {
if (is_normal_group) {
HL_TABLE()[idx].sg_attr = 0;
+ // Need to update all groups, because they might be using "bg" and/or
+ // "fg", which have been changed now.
+ highlight_attr_set_all();
// If the normal group has changed, it is simpler to refresh every UI
ui_refresh();
} else
@@ -6999,11 +7001,15 @@ highlight_color (
if (font || sp)
return NULL;
if (modec == 'c') {
- if (fg)
+ if (fg) {
n = HL_TABLE()[id - 1].sg_cterm_fg - 1;
- else
+ } else {
n = HL_TABLE()[id - 1].sg_cterm_bg - 1;
- sprintf((char *)name, "%d", n);
+ }
+ if (n < 0) {
+ return NULL;
+ }
+ snprintf((char *)name, sizeof(name), "%d", n);
return name;
}
/* term doesn't have color */
@@ -7262,6 +7268,23 @@ int syn_get_final_id(int hl_id)
return hl_id;
}
+/// Refresh the color attributes of all highlight groups.
+static void highlight_attr_set_all(void)
+{
+ for (int idx = 0; idx < highlight_ga.ga_len; idx++) {
+ struct hl_group *sgp = &HL_TABLE()[idx];
+ if (sgp->sg_rgb_bg_name != NULL) {
+ sgp->sg_rgb_bg = name_to_color(sgp->sg_rgb_bg_name);
+ }
+ if (sgp->sg_rgb_fg_name != NULL) {
+ sgp->sg_rgb_fg = name_to_color(sgp->sg_rgb_fg_name);
+ }
+ if (sgp->sg_rgb_sp_name != NULL) {
+ sgp->sg_rgb_sp = name_to_color(sgp->sg_rgb_sp_name);
+ }
+ set_hl_attr(idx);
+ }
+}
/*
* Translate the 'highlight' option into attributes in highlight_attr[] and
@@ -7703,6 +7726,10 @@ RgbValue name_to_color(uint8_t *name)
&& isxdigit(name[6]) && name[7] == NUL) {
// rgb hex string
return strtol((char *)(name + 1), NULL, 16);
+ } else if (!STRICMP(name, "bg") || !STRICMP(name, "background")) {
+ return normal_bg;
+ } else if (!STRICMP(name, "fg") || !STRICMP(name, "foreground")) {
+ return normal_fg;
}
for (int i = 0; color_name_table[i].name != NULL; i++) {
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index dfecfb776d..81256b4f01 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -26,7 +26,6 @@
#include "nvim/mbyte.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/file_search.h"
#include "nvim/garray.h"
#include "nvim/memory.h"
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 90636326a5..ff98dc9f22 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -127,7 +127,7 @@ struct terminal {
// we can't store a direct reference to the buffer because the
// refresh_timer_cb may be called after the buffer was freed, and there's
// no way to know if the memory was reused.
- uint64_t buf_handle;
+ handle_T buf_handle;
// program exited
bool closed, destroy;
// some vterm properties
@@ -623,11 +623,12 @@ static void buf_set_term_title(buf_T *buf, char *title)
FUNC_ATTR_NONNULL_ALL
{
Error err;
- api_free_object(dict_set_value(buf->b_vars,
- cstr_as_string("term_title"),
- STRING_OBJ(cstr_as_string(title)),
- false,
- &err));
+ dict_set_value(buf->b_vars,
+ cstr_as_string("term_title"),
+ STRING_OBJ(cstr_as_string(title)),
+ false,
+ false,
+ &err);
}
static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile
index 57c99e9845..ff0f729460 100644
--- a/src/nvim/testdir/Makefile
+++ b/src/nvim/testdir/Makefile
@@ -37,6 +37,7 @@ NEW_TESTS = \
test_help_tagjump.res \
test_langmap.res \
test_syntax.res \
+ test_usercommands.res \
test_timers.res \
test_viml.res \
test_visual.res \
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index daf6f026ba..f0efd6e4ed 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -3,8 +3,10 @@
source test_assign.vim
source test_cursor_func.vim
+source test_feedkeys.vim
source test_cmdline.vim
source test_menu.vim
source test_popup.vim
source test_regexp_utf8.vim
+source test_syn_attr.vim
source test_unlet.vim
diff --git a/src/nvim/testdir/test_feedkeys.vim b/src/nvim/testdir/test_feedkeys.vim
new file mode 100644
index 0000000000..33cd58949d
--- /dev/null
+++ b/src/nvim/testdir/test_feedkeys.vim
@@ -0,0 +1,10 @@
+" Test feedkeys() function.
+
+func Test_feedkeys_x_with_empty_string()
+ new
+ call feedkeys("ifoo\<Esc>")
+ call assert_equal('', getline('.'))
+ call feedkeys('', 'x')
+ call assert_equal('foo', getline('.'))
+ quit!
+endfunc
diff --git a/src/nvim/testdir/test_help_tagjump.vim b/src/nvim/testdir/test_help_tagjump.vim
index 9f9207d27d..42f8391aba 100644
--- a/src/nvim/testdir/test_help_tagjump.vim
+++ b/src/nvim/testdir/test_help_tagjump.vim
@@ -37,4 +37,14 @@ func Test_help_tagjump()
call assert_equal("help", &filetype)
call assert_true(getline('.') =~ '\*arglistid()\*')
helpclose
+
+ exec "help! 'autoindent'."
+ call assert_equal("help", &filetype)
+ call assert_true(getline('.') =~ "\\*'autoindent'\\*")
+ helpclose
+
+ exec "help! {address}."
+ call assert_equal("help", &filetype)
+ call assert_true(getline('.') =~ '\*{address}\*')
+ helpclose
endfunc
diff --git a/src/nvim/testdir/test_syn_attr.vim b/src/nvim/testdir/test_syn_attr.vim
new file mode 100644
index 0000000000..809442eb94
--- /dev/null
+++ b/src/nvim/testdir/test_syn_attr.vim
@@ -0,0 +1,24 @@
+" Test syntax highlighting functions.
+
+func Test_missing_attr()
+ hi Mine cterm=italic
+ call assert_equal('Mine', synIDattr(hlID("Mine"), "name"))
+ call assert_equal('1', synIDattr(hlID("Mine"), "italic", 'cterm'))
+ hi Mine cterm=inverse
+ call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm'))
+ hi Mine cterm=standout gui=undercurl
+ call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm'))
+ call assert_equal('1', synIDattr(hlID("Mine"), "undercurl", 'gui'))
+ hi Mine cterm=NONE gui=NONE
+ call assert_equal('', synIDattr(hlID("Mine"), "italic", 'cterm'))
+ call assert_equal('', synIDattr(hlID("Mine"), "inverse", 'cterm'))
+ call assert_equal('', synIDattr(hlID("Mine"), "standout", 'cterm'))
+ call assert_equal('', synIDattr(hlID("Mine"), "undercurl", 'gui'))
+
+ if has('gui')
+ hi Mine guifg=blue guibg=red font=something
+ call assert_equal('blue', synIDattr(hlID("Mine"), "fg", 'gui'))
+ call assert_equal('red', synIDattr(hlID("Mine"), "bg", 'gui'))
+ call assert_equal('something', synIDattr(hlID("Mine"), "font", 'gui'))
+ endif
+endfunc
diff --git a/src/nvim/testdir/test_usercommands.vim b/src/nvim/testdir/test_usercommands.vim
new file mode 100644
index 0000000000..f593d16dbf
--- /dev/null
+++ b/src/nvim/testdir/test_usercommands.vim
@@ -0,0 +1,48 @@
+" Tests for user defined commands
+
+" Test for <mods> in user defined commands
+function Test_cmdmods()
+ let g:mods = ''
+
+ command! -nargs=* MyCmd let g:mods .= '<mods> '
+
+ MyCmd
+ aboveleft MyCmd
+ belowright MyCmd
+ botright MyCmd
+ browse MyCmd
+ confirm MyCmd
+ hide MyCmd
+ keepalt MyCmd
+ keepjumps MyCmd
+ keepmarks MyCmd
+ keeppatterns MyCmd
+ lockmarks MyCmd
+ noswapfile MyCmd
+ silent MyCmd
+ tab MyCmd
+ topleft MyCmd
+ verbose MyCmd
+ vertical MyCmd
+
+ aboveleft belowright botright browse confirm hide keepalt keepjumps
+ \ keepmarks keeppatterns lockmarks noswapfile silent tab
+ \ topleft verbose vertical MyCmd
+
+ call assert_equal(' aboveleft belowright botright browse confirm ' .
+ \ 'hide keepalt keepjumps keepmarks keeppatterns lockmarks ' .
+ \ 'noswapfile silent tab topleft verbose vertical aboveleft ' .
+ \ 'belowright botright browse confirm hide keepalt keepjumps ' .
+ \ 'keepmarks keeppatterns lockmarks noswapfile silent tab topleft ' .
+ \ 'verbose vertical ', g:mods)
+
+ let g:mods = ''
+ command! -nargs=* MyQCmd let g:mods .= '<q-mods> '
+
+ vertical MyQCmd
+ call assert_equal('"vertical" ', g:mods)
+
+ delcommand MyCmd
+ delcommand MyQCmd
+ unlet g:mods
+endfunction
diff --git a/src/nvim/testdir/test_window_id.vim b/src/nvim/testdir/test_window_id.vim
index b9e9f45c49..fa3ebd757e 100644
--- a/src/nvim/testdir/test_window_id.vim
+++ b/src/nvim/testdir/test_window_id.vim
@@ -5,6 +5,7 @@ func Test_win_getid()
let id1 = win_getid()
split two
let id2 = win_getid()
+ let bufnr2 = bufnr('%')
split three
let id3 = win_getid()
tabnew
@@ -12,6 +13,7 @@ func Test_win_getid()
let id4 = win_getid()
split five
let id5 = win_getid()
+ let bufnr5 = bufnr('%')
tabnext
wincmd w
@@ -67,5 +69,11 @@ func Test_win_getid()
call assert_equal([1, nr2], win_id2tabwin(id2))
call assert_equal([2, nr4], win_id2tabwin(id4))
+ call assert_equal([], win_findbuf(9999))
+ call assert_equal([id2], win_findbuf(bufnr2))
+ call win_gotoid(id5)
+ split
+ call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5)))
+
only!
endfunc
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index 3ef4d34c9a..68ea00ee63 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -5,7 +5,6 @@
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/main.h"
-#include "nvim/misc2.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
#include "nvim/event/rstream.h"
@@ -216,8 +215,8 @@ static int get_key_code_timeout(void)
// Check 'ttimeout' to determine if we should send ESC after 'ttimeoutlen'.
// See :help 'ttimeout' for more information
Error err = ERROR_INIT;
- if (vim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
- ms = vim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
+ if (nvim_get_option(cstr_as_string("ttimeout"), &err).data.boolean) {
+ ms = nvim_get_option(cstr_as_string("ttimeoutlen"), &err).data.integer;
}
return (int)ms;
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index d220df508a..bfc03dfb81 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -83,6 +83,7 @@ UI *tui_start(void)
UI *ui = xcalloc(1, sizeof(UI));
ui->stop = tui_stop;
ui->rgb = p_tgc;
+ ui->pum_external = false;
ui->resize = tui_resize;
ui->clear = tui_clear;
ui->eol_clear = tui_eol_clear;
@@ -106,6 +107,7 @@ UI *tui_start(void)
ui->suspend = tui_suspend;
ui->set_title = tui_set_title;
ui->set_icon = tui_set_icon;
+ ui->event = tui_event;
return ui_bridge_attach(ui, tui_main, tui_scheduler);
}
@@ -650,6 +652,12 @@ static void tui_set_icon(UI *ui, char *icon)
{
}
+// NB: if we start to use this, the ui_bridge must be updated
+// to make a copy for the tui thread
+static void tui_event(UI *ui, char *name, Array args, bool *args_consumed)
+{
+}
+
static void invalidate(UI *ui, int top, int bot, int left, int right)
{
TUIData *data = ui->data;
diff --git a/src/nvim/types.h b/src/nvim/types.h
index bfe8be2091..35a5d1e2bd 100644
--- a/src/nvim/types.h
+++ b/src/nvim/types.h
@@ -13,4 +13,5 @@ typedef unsigned char char_u;
// Can hold one decoded UTF-8 character.
typedef uint32_t u8char_T;
+typedef struct expand expand_T;
#endif // NVIM_TYPES_H
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index d968cbc390..dd278893c2 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -12,10 +12,8 @@
#include "nvim/ex_cmds2.h"
#include "nvim/fold.h"
#include "nvim/main.h"
-#include "nvim/mbyte.h"
#include "nvim/ascii.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/mbyte.h"
#include "nvim/garray.h"
#include "nvim/memory.h"
@@ -27,6 +25,7 @@
#include "nvim/os/time.h"
#include "nvim/os/input.h"
#include "nvim/os/signal.h"
+#include "nvim/popupmnu.h"
#include "nvim/screen.h"
#include "nvim/syntax.h"
#include "nvim/window.h"
@@ -35,6 +34,7 @@
#else
# include "nvim/msgpack_rpc/server.h"
#endif
+#include "nvim/api/private/helpers.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ui.c.generated.h"
@@ -143,6 +143,15 @@ void ui_set_icon(char *icon)
UI_CALL(flush);
}
+void ui_event(char *name, Array args)
+{
+ bool args_consumed = false;
+ UI_CALL(event, name, args, &args_consumed);
+ if (!args_consumed) {
+ api_free_array(args);
+ }
+}
+
// May update the shape of the cursor.
void ui_cursor_shape(void)
{
@@ -156,15 +165,18 @@ void ui_refresh(void)
}
int width = INT_MAX, height = INT_MAX;
+ bool pum_external = true;
for (size_t i = 0; i < ui_count; i++) {
UI *ui = uis[i];
width = ui->width < width ? ui->width : width;
height = ui->height < height ? ui->height : height;
+ pum_external &= ui->pum_external;
}
row = col = 0;
screen_resize(width, height);
+ pum_set_external(pum_external);
}
void ui_resize(int new_width, int new_height)
@@ -519,3 +531,4 @@ static void ui_mode_change(void)
UI_CALL(mode_change, mode);
conceal_check_cursur_line();
}
+
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index 5934d2fee9..d14bc5812c 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -5,6 +5,8 @@
#include <stdbool.h>
#include <stdint.h>
+#include "api/private/defs.h"
+
typedef struct {
bool bold, underline, undercurl, italic, reverse;
int foreground, background, special;
@@ -13,7 +15,7 @@ typedef struct {
typedef struct ui_t UI;
struct ui_t {
- bool rgb;
+ bool rgb, pum_external;
int width, height;
void *data;
void (*resize)(UI *ui, int rows, int columns);
@@ -39,6 +41,7 @@ struct ui_t {
void (*suspend)(UI *ui);
void (*set_title)(UI *ui, char *title);
void (*set_icon)(UI *ui, char *icon);
+ void (*event)(UI *ui, char *name, Array args, bool *args_consumed);
void (*stop)(UI *ui);
};
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index 6290fb3d87..34b95baf6c 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -31,6 +31,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData));
rv->ui = ui;
rv->bridge.rgb = ui->rgb;
+ rv->bridge.pum_external = ui->pum_external;
rv->bridge.stop = ui_bridge_stop;
rv->bridge.resize = ui_bridge_resize;
rv->bridge.clear = ui_bridge_clear;
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index fc5d6acaa4..d80aaf443a 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -99,6 +99,7 @@
#include "nvim/quickfix.h"
#include "nvim/screen.h"
#include "nvim/sha256.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/types.h"
#include "nvim/os/os.h"
diff --git a/src/nvim/version.c b/src/nvim/version.c
index f28bffa91d..c2f9ed49e7 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -15,7 +15,6 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
-#include "nvim/misc2.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
@@ -306,7 +305,7 @@ static int included_patches[] = {
// 1974 NA
1973,
// 1972,
- // 1971,
+ 1971,
// 1970,
// 1969 NA
// 1968,
@@ -364,7 +363,7 @@ static int included_patches[] = {
// 1916 NA
// 1915 NA
// 1914,
- // 1913,
+ 1913,
// 1912,
// 1911,
// 1910,
@@ -377,11 +376,11 @@ static int included_patches[] = {
// 1903,
// 1902 NA
// 1901 NA
- // 1900,
+ 1900,
// 1899 NA
- // 1898,
+ 1898,
// 1897,
- // 1896,
+ 1896,
// 1895,
// 1894 NA
// 1893,
@@ -721,7 +720,7 @@ static int included_patches[] = {
// 1561 NA
// 1560 NA
// 1559,
- // 1558,
+ 1558,
1557,
// 1556 NA
// 1555 NA
@@ -732,7 +731,7 @@ static int included_patches[] = {
1550,
// 1549,
1548,
- // 1547,
+ 1547,
1546,
// 1545 NA
// 1544 NA
@@ -744,9 +743,9 @@ static int included_patches[] = {
// 1538 NA
// 1537 NA
// 1536 NA
- // 1535,
+ 1535,
// 1534 NA
- // 1533,
+ 1533,
// 1532 NA
// 1531 NA
// 1530 NA
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 350b54d595..e9a66ad907 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -28,7 +28,6 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/misc2.h"
#include "nvim/file_search.h"
#include "nvim/garray.h"
#include "nvim/move.h"
@@ -41,6 +40,7 @@
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
+#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/terminal.h"
@@ -2926,7 +2926,9 @@ void win_init_size(void)
*/
static tabpage_T *alloc_tabpage(void)
{
+ static int last_tp_handle = 0;
tabpage_T *tp = xcalloc(1, sizeof(tabpage_T));
+ tp->handle = ++last_tp_handle;
handle_register_tabpage(tp);
/* init t: variables */
@@ -2976,6 +2978,9 @@ int win_new_tabpage(int after, char_u *filename)
xfree(newtp);
return FAIL;
}
+
+ newtp->localdir = tp->localdir ? vim_strsave(tp->localdir) : NULL;
+
curtab = newtp;
/* Create a new empty window. */
@@ -3683,21 +3688,20 @@ win_T *buf_jump_open_tab(buf_T *buf)
return NULL;
}
-static int last_win_id = 0;
-
/*
* Allocate a window structure and link it in the window list when "hidden" is
* FALSE.
*/
static win_T *win_alloc(win_T *after, int hidden)
{
- /*
- * allocate window structure and linesizes arrays
- */
+ static int last_win_id = 0;
+
+ // allocate window structure and linesizes arrays
win_T *new_wp = xcalloc(1, sizeof(win_T));
- handle_register_window(new_wp);
win_alloc_lines(new_wp);
- new_wp->w_id = ++last_win_id;
+
+ new_wp->handle = ++last_win_id;
+ handle_register_window(new_wp);
/* init w: variables */
new_wp->w_vars = dict_alloc();
@@ -5681,7 +5685,7 @@ static bool frame_check_width(frame_T *topfrp, int width)
int win_getid(typval_T *argvars)
{
if (argvars[0].v_type == VAR_UNKNOWN) {
- return curwin->w_id;
+ return curwin->handle;
}
int winnr = get_tv_number(&argvars[0]);
win_T *wp;
@@ -5703,7 +5707,7 @@ int win_getid(typval_T *argvars)
}
for ( ; wp != NULL; wp = wp->w_next) {
if (--winnr == 0) {
- return wp->w_id;
+ return wp->handle;
}
}
}
@@ -5719,7 +5723,7 @@ int win_gotoid(typval_T *argvars)
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
wp != NULL; wp = wp->w_next) {
- if (wp->w_id == id) {
+ if (wp->handle == id) {
goto_tabpage_win(tp, wp);
return 1;
}
@@ -5739,7 +5743,7 @@ void win_id2tabwin(typval_T *argvars, list_T *list)
for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
wp != NULL; wp = wp->w_next) {
- if (wp->w_id == id) {
+ if (wp->handle == id) {
list_append_number(list, tabnr);
list_append_number(list, winnr);
return;
@@ -5760,10 +5764,24 @@ int win_id2win(typval_T *argvars)
int id = get_tv_number(&argvars[0]);
for (wp = firstwin; wp != NULL; wp = wp->w_next) {
- if (wp->w_id == id) {
+ if (wp->handle == id) {
return nr;
}
nr++;
}
return 0;
}
+
+void win_findbuf(typval_T *argvars, list_T *list)
+{
+ int bufnr = get_tv_number(&argvars[0]);
+
+ for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+ for (win_T *wp = tp == curtab ? firstwin : tp->tp_firstwin;
+ wp != NULL; wp = wp->w_next) {
+ if (wp->w_buffer->b_fnum == bufnr) {
+ list_append_number(list, wp->handle);
+ }
+ }
+ }
+}