aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/buffer.c30
-rw-r--r--src/nvim/api/private/defs.h9
-rw-r--r--src/nvim/api/private/helpers.c104
-rw-r--r--src/nvim/api/private/helpers.h11
-rw-r--r--src/nvim/api/tabpage.c2
-rw-r--r--src/nvim/api/vim.c49
-rw-r--r--src/nvim/api/window.c14
-rw-r--r--src/nvim/edit.c1
-rw-r--r--src/nvim/eval.c29
-rw-r--r--src/nvim/ex_cmds.c12
-rw-r--r--src/nvim/ex_getln.c5
-rw-r--r--src/nvim/getchar.c6
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/normal.c6
-rw-r--r--src/nvim/os/channel.c44
-rw-r--r--src/nvim/os/msgpack_rpc.c46
-rw-r--r--src/nvim/os/provider.c9
-rw-r--r--src/nvim/os_unix.c41
-rw-r--r--src/nvim/popupmnu.c10
-rw-r--r--src/nvim/quickfix.c1
-rw-r--r--src/nvim/term.c44
-rw-r--r--src/nvim/version.c63
-rw-r--r--src/nvim/window.c99
23 files changed, 426 insertions, 213 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 8355bfe868..62559163d8 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -125,7 +125,7 @@ ArrayOf(String) buffer_get_slice(Buffer buffer,
int64_t lnum = start + (int64_t)i;
if (lnum > LONG_MAX) {
- set_api_error("Line index is too high", err);
+ api_set_error(err, Validation, _("Line index is too high"));
goto end;
}
@@ -175,7 +175,9 @@ void buffer_set_slice(Buffer buffer,
end = normalize_index(buf, end) + (include_end ? 1 : 0);
if (start > end) {
- set_api_error("start > end", err);
+ api_set_error(err,
+ Validation,
+ _("Argument \"start\" is higher than \"end\""));
return;
}
@@ -189,7 +191,9 @@ void buffer_set_slice(Buffer buffer,
for (size_t i = 0; i < new_len; i++) {
if (replacement.items[i].type != kObjectTypeString) {
- set_api_error("all items in the replacement array must be strings", err);
+ api_set_error(err,
+ Validation,
+ _("All items in the replacement array must be strings"));
goto end;
}
@@ -201,7 +205,7 @@ void buffer_set_slice(Buffer buffer,
switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
- set_api_error("Cannot save undo information", err);
+ api_set_error(err, Exception, _("Failed to save undo information"));
goto end;
}
@@ -211,7 +215,7 @@ void buffer_set_slice(Buffer buffer,
size_t to_delete = (new_len < old_len) ? (size_t)(old_len - new_len) : 0;
for (size_t i = 0; i < to_delete; i++) {
if (ml_delete((linenr_T)start, false) == FAIL) {
- set_api_error("Cannot delete line", err);
+ api_set_error(err, Exception, _("Failed to delete line"));
goto end;
}
}
@@ -228,12 +232,12 @@ void buffer_set_slice(Buffer buffer,
int64_t lnum = start + (int64_t)i;
if (lnum > LONG_MAX) {
- set_api_error("Index value is too high", err);
+ api_set_error(err, Validation, _("Index value is too high"));
goto end;
}
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
- set_api_error("Cannot replace line", err);
+ api_set_error(err, Exception, _("Failed to replace line"));
goto end;
}
// Mark lines that haven't been passed to the buffer as they need
@@ -246,12 +250,12 @@ void buffer_set_slice(Buffer buffer,
int64_t lnum = start + (int64_t)i - 1;
if (lnum > LONG_MAX) {
- set_api_error("Index value is too high", err);
+ api_set_error(err, Validation, _("Index value is too high"));
goto end;
}
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
- set_api_error("Cannot insert line", err);
+ api_set_error(err, Exception, _("Failed to insert line"));
goto end;
}
@@ -415,7 +419,7 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
}
if (ren_ret == FAIL) {
- set_api_error("failed to rename buffer", err);
+ api_set_error(err, Exception, _("Failed to rename buffer"));
}
}
@@ -425,7 +429,7 @@ void buffer_set_name(Buffer buffer, String name, Error *err)
/// @return true if the buffer is valid, false otherwise
Boolean buffer_is_valid(Buffer buffer)
{
- Error stub = {.set = false};
+ Error stub = ERROR_INIT;
return find_buffer_by_handle(buffer, &stub) != NULL;
}
@@ -460,7 +464,7 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err)
}
if (name.size != 1) {
- set_api_error("mark name must be a single character", err);
+ api_set_error(err, Validation, _("Mark name must be a single character"));
return rv;
}
@@ -478,7 +482,7 @@ ArrayOf(Integer, 2) buffer_get_mark(Buffer buffer, String name, Error *err)
}
if (posp == NULL) {
- set_api_error("invalid mark name", err);
+ api_set_error(err, Validation, _("Invalid mark name"));
return rv;
}
diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h
index 2dd229ec5f..76ac23a521 100644
--- a/src/nvim/api/private/defs.h
+++ b/src/nvim/api/private/defs.h
@@ -8,6 +8,7 @@
#define ARRAY_DICT_INIT {.size = 0, .capacity = 0, .items = NULL}
#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
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -16,8 +17,14 @@
#endif
// Basic types
+typedef enum {
+ kErrorTypeException,
+ kErrorTypeValidation
+} ErrorType;
+
typedef struct {
- char msg[256];
+ ErrorType type;
+ char msg[1024];
bool set;
} Error;
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 14a820aa1b..093cb0e55f 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -48,7 +48,7 @@ bool try_end(Error *err)
discard_current_exception();
}
- set_api_error("Keyboard interrupt", err);
+ api_set_error(err, Exception, _("Keyboard interrupt"));
got_int = false;
} else if (msg_list != NULL && *msg_list != NULL) {
int should_free;
@@ -64,7 +64,7 @@ bool try_end(Error *err)
free(msg);
}
} else if (did_throw) {
- set_api_error((char *)current_exception->value, err);
+ api_set_error(err, Exception, "%s", current_exception->value);
}
return err->set;
@@ -80,7 +80,7 @@ Object dict_get_value(dict_T *dict, String key, Error *err)
hashitem_T *hi = hash_find(&dict->dv_hashtab, (uint8_t *) key.data);
if (HASHITEM_EMPTY(hi)) {
- set_api_error("Key not found", err);
+ api_set_error(err, Validation, _("Key not found"));
return (Object) OBJECT_INIT;
}
@@ -101,17 +101,17 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err)
Object rv = OBJECT_INIT;
if (dict->dv_lock) {
- set_api_error("Dictionary is locked", err);
+ api_set_error(err, Exception, _("Dictionary is locked"));
return rv;
}
if (key.size == 0) {
- set_api_error("Empty dictionary keys aren't allowed", err);
+ api_set_error(err, Validation, _("Empty dictionary keys aren't allowed"));
return rv;
}
if (key.size > INT_MAX) {
- set_api_error("Key length is too high", err);
+ api_set_error(err, Validation, _("Key length is too high"));
return rv;
}
@@ -121,7 +121,7 @@ Object dict_set_value(dict_T *dict, String key, Object value, Error *err)
// Delete the key
if (di == NULL) {
// Doesn't exist, fail
- set_api_error("Key doesn't exist", err);
+ api_set_error(err, Validation, _("Key \"%s\" doesn't exist"), key.data);
} else {
// Return the old value
rv = vim_to_object(&di->di_tv);
@@ -170,7 +170,7 @@ Object get_option_from(void *from, int type, String name, Error *err)
Object rv = OBJECT_INIT;
if (name.size == 0) {
- set_api_error("Empty option name", err);
+ api_set_error(err, Validation, _("Empty option name"));
return rv;
}
@@ -181,7 +181,10 @@ Object get_option_from(void *from, int type, String name, Error *err)
type, from);
if (!flags) {
- set_api_error("invalid option name", err);
+ api_set_error(err,
+ Validation,
+ _("Invalid option name \"%s\""),
+ name.data);
return rv;
}
@@ -197,10 +200,16 @@ Object get_option_from(void *from, int type, String name, Error *err)
rv.data.string.data = stringval;
rv.data.string.size = strlen(stringval);
} else {
- set_api_error(N_("Unable to get option value"), err);
+ api_set_error(err,
+ Exception,
+ _("Unable to get value for option \"%s\""),
+ name.data);
}
} else {
- set_api_error(N_("internal error: unknown option type"), err);
+ api_set_error(err,
+ Exception,
+ _("Unknown type for option \"%s\""),
+ name.data);
}
return rv;
@@ -216,24 +225,33 @@ Object get_option_from(void *from, int type, String name, Error *err)
void set_option_to(void *to, int type, String name, Object value, Error *err)
{
if (name.size == 0) {
- set_api_error("Empty option name", err);
+ api_set_error(err, Validation, _("Empty option name"));
return;
}
int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
if (flags == 0) {
- set_api_error("invalid option name", err);
+ api_set_error(err,
+ Validation,
+ _("Invalid option name \"%s\""),
+ name.data);
return;
}
if (value.type == kObjectTypeNil) {
if (type == SREQ_GLOBAL) {
- set_api_error("unable to unset option", err);
+ api_set_error(err,
+ Exception,
+ _("Unable to unset option \"%s\""),
+ name.data);
return;
} else if (!(flags & SOPT_GLOBAL)) {
- set_api_error("cannot unset option that doesn't have a global value",
- err);
+ api_set_error(err,
+ Exception,
+ _("Cannot unset option \"%s\" "
+ "because it doesn't have a global value"),
+ name.data);
return;
} else {
unset_global_local_option(name.data, to);
@@ -245,7 +263,10 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
if (flags & SOPT_BOOL) {
if (value.type != kObjectTypeBoolean) {
- set_api_error("option requires a boolean value", err);
+ api_set_error(err,
+ Validation,
+ _("Option \"%s\" requires a boolean value"),
+ name.data);
return;
}
@@ -253,12 +274,18 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
} else if (flags & SOPT_NUM) {
if (value.type != kObjectTypeInteger) {
- set_api_error("option requires an integer value", err);
+ api_set_error(err,
+ Validation,
+ _("Option \"%s\" requires an integer value"),
+ name.data);
return;
}
if (value.data.integer > INT_MAX || value.data.integer < INT_MIN) {
- set_api_error("Option value outside range", err);
+ api_set_error(err,
+ Validation,
+ _("Value for option \"%s\" is outside range"),
+ name.data);
return;
}
@@ -266,7 +293,10 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
set_option_value_for(name.data, val, NULL, opt_flags, type, to, err);
} else {
if (value.type != kObjectTypeString) {
- set_api_error("option requires a string value", err);
+ api_set_error(err,
+ Validation,
+ _("Option \"%s\" requires a string value"),
+ name.data);
return;
}
@@ -296,7 +326,7 @@ buf_T *find_buffer_by_handle(Buffer buffer, Error *err)
buf_T *rv = handle_get_buffer(buffer);
if (!rv) {
- set_api_error("Invalid buffer id", err);
+ api_set_error(err, Validation, _("Invalid buffer id"));
}
return rv;
@@ -307,7 +337,7 @@ win_T * find_window_by_handle(Window window, Error *err)
win_T *rv = handle_get_window(window);
if (!rv) {
- set_api_error("Invalid window id", err);
+ api_set_error(err, Validation, _("Invalid window id"));
}
return rv;
@@ -318,7 +348,7 @@ tabpage_T * find_tab_by_handle(Tabpage tabpage, Error *err)
tabpage_T *rv = handle_get_tabpage(tabpage);
if (!rv) {
- set_api_error("Invalid tabpage id", err);
+ api_set_error(err, Validation, _("Invalid tabpage id"));
}
return rv;
@@ -376,7 +406,7 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
case kObjectTypeInteger:
if (obj.data.integer > INT_MAX || obj.data.integer < INT_MIN) {
- set_api_error("Integer value outside range", err);
+ api_set_error(err, Validation, _("Integer value outside range"));
return false;
}
@@ -424,7 +454,9 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
String key = item.key;
if (key.size == 0) {
- set_api_error("Empty dictionary keys aren't allowed", err);
+ api_set_error(err,
+ Validation,
+ _("Empty dictionary keys aren't allowed"));
// cleanup
dict_free(tv->vval.v_dict, true);
return false;
@@ -513,6 +545,7 @@ Dictionary api_metadata(void)
if (!metadata.size) {
msgpack_rpc_init_function_metadata(&metadata);
+ init_error_type_metadata(&metadata);
init_type_metadata(&metadata);
provider_init_feature_metadata(&metadata);
}
@@ -520,6 +553,21 @@ Dictionary api_metadata(void)
return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary;
}
+static void init_error_type_metadata(Dictionary *metadata)
+{
+ Dictionary types = ARRAY_DICT_INIT;
+
+ Dictionary exception_metadata = ARRAY_DICT_INIT;
+ PUT(exception_metadata, "id", INTEGER_OBJ(kErrorTypeException));
+
+ Dictionary validation_metadata = ARRAY_DICT_INIT;
+ PUT(validation_metadata, "id", INTEGER_OBJ(kErrorTypeValidation));
+
+ PUT(types, "Exception", DICTIONARY_OBJ(exception_metadata));
+ PUT(types, "Validation", DICTIONARY_OBJ(validation_metadata));
+
+ PUT(*metadata, "error_types", DICTIONARY_OBJ(types));
+}
static void init_type_metadata(Dictionary *metadata)
{
Dictionary types = ARRAY_DICT_INIT;
@@ -704,7 +752,9 @@ static void set_option_value_for(char *key,
if (try_end(err)) {
return;
}
- set_api_error("problem while switching windows", err);
+ api_set_error(err,
+ Exception,
+ _("Problem while switching windows"));
return;
}
set_option_value_err(key, numval, stringval, opt_flags, err);
@@ -745,6 +795,6 @@ static void set_option_value_err(char *key,
return;
}
- set_api_error(errmsg, err);
+ api_set_error(err, Exception, "%s", errmsg);
}
}
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
index f3ecdaacc4..f29deb53f9 100644
--- a/src/nvim/api/private/helpers.h
+++ b/src/nvim/api/private/helpers.h
@@ -8,10 +8,13 @@
#include "nvim/memory.h"
#include "nvim/lib/kvec.h"
-#define set_api_error(message, err) \
- do { \
- xstrlcpy(err->msg, message, sizeof(err->msg)); \
- err->set = true; \
+#define api_set_error(err, errtype, ...) \
+ do { \
+ snprintf((err)->msg, \
+ sizeof((err)->msg), \
+ __VA_ARGS__); \
+ (err)->set = true; \
+ (err)->type = kErrorType##errtype; \
} while (0)
#define OBJECT_OBJ(o) o
diff --git a/src/nvim/api/tabpage.c b/src/nvim/api/tabpage.c
index 91020d6850..72168d936a 100644
--- a/src/nvim/api/tabpage.c
+++ b/src/nvim/api/tabpage.c
@@ -116,7 +116,7 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
/// @return true if the tab page is valid, false otherwise
Boolean tabpage_is_valid(Tabpage tabpage)
{
- Error stub = {.set = false};
+ Error stub = ERROR_INIT;
return find_tab_by_handle(tabpage, &stub) != NULL;
}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 43f2aafdc8..93aa0439f0 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <stdint.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -117,7 +118,7 @@ Object vim_eval(String str, Error *err)
typval_T *expr_result = eval_expr((char_u *) str.data, NULL);
if (!expr_result) {
- set_api_error("Failed to eval expression", err);
+ api_set_error(err, Exception, _("Failed to evaluate expression"));
}
if (!try_end(err)) {
@@ -139,7 +140,7 @@ Object vim_eval(String str, Error *err)
Integer vim_strwidth(String str, Error *err)
{
if (str.size > INT_MAX) {
- set_api_error("String length is too high", err);
+ api_set_error(err, Validation, _("String length is too high"));
return 0;
}
@@ -194,7 +195,7 @@ ArrayOf(String) vim_list_runtime_paths(void)
void vim_change_directory(String dir, Error *err)
{
if (dir.size >= MAXPATHL) {
- set_api_error("directory string is too long", err);
+ api_set_error(err, Validation, _("Directory string is too long"));
return;
}
@@ -206,7 +207,7 @@ void vim_change_directory(String dir, Error *err)
if (vim_chdir((char_u *)string)) {
if (!try_end(err)) {
- set_api_error("failed to change directory", err);
+ api_set_error(err, Exception, _("Failed to change directory"));
}
return;
}
@@ -364,18 +365,13 @@ void vim_set_current_buffer(Buffer buffer, Error *err)
}
try_start();
- if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0) == FAIL) {
- if (try_end(err)) {
- return;
- }
-
- char msg[256];
- snprintf(msg, sizeof(msg), "failed to switch to buffer %d", (int)buffer);
- set_api_error(msg, err);
- return;
+ int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
+ if (!try_end(err) && result == FAIL) {
+ api_set_error(err,
+ Exception,
+ _("Failed to switch to buffer %" PRIu64),
+ buffer);
}
-
- try_end(err);
}
/// Gets the current list of window handles
@@ -422,16 +418,12 @@ void vim_set_current_window(Window window, Error *err)
try_start();
goto_tabpage_win(win_find_tabpage(win), win);
-
- if (win != curwin) {
- if (try_end(err)) {
- return;
- }
- set_api_error("did not switch to the specified window", err);
- return;
+ if (!try_end(err) && win != curwin) {
+ api_set_error(err,
+ Exception,
+ _("Failed to switch to window %" PRIu64),
+ window);
}
-
- try_end(err);
}
/// Gets the current list of tabpage handles
@@ -481,7 +473,12 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)
try_start();
goto_tabpage_tp(tp, true, true);
- try_end(err);
+ if (!try_end(err) && tp != curtab) {
+ api_set_error(err,
+ Exception,
+ _("Failed to switch to tabpage %" PRIu64),
+ tabpage);
+ }
}
/// Subscribes to event broadcasts
@@ -524,7 +521,7 @@ void vim_register_provider(uint64_t channel_id, String feature, Error *err)
xstrlcpy(buf, feature.data, sizeof(buf));
if (!provider_register(buf, channel_id)) {
- set_api_error("Feature doesn't exist", err);
+ api_set_error(err, Validation, _("Feature doesn't exist"));
}
}
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index dd256f2b6d..751518424b 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -57,7 +57,9 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
if (pos.size != 2 || pos.items[0].type != kObjectTypeInteger ||
pos.items[1].type != kObjectTypeInteger) {
- set_api_error("\"pos\" argument must be a [row, col] array", err);
+ api_set_error(err,
+ Validation,
+ _("Argument \"pos\" must be a [row, col] array"));
return;
}
@@ -69,12 +71,12 @@ void window_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
int64_t col = pos.items[1].data.integer;
if (row <= 0 || row > win->w_buffer->b_ml.ml_line_count) {
- set_api_error("cursor position outside buffer", err);
+ api_set_error(err, Validation, _("Cursor position outside buffer"));
return;
}
if (col > MAXCOL || col < 0) {
- set_api_error("Column value outside range", err);
+ api_set_error(err, Validation, _("Column value outside range"));
return;
}
@@ -117,7 +119,7 @@ void window_set_height(Window window, Integer height, Error *err)
}
if (height > INT_MAX || height < INT_MIN) {
- set_api_error("Height value outside range", err);
+ api_set_error(err, Validation, _("Height value outside range"));
return;
}
@@ -160,7 +162,7 @@ void window_set_width(Window window, Integer width, Error *err)
}
if (width > INT_MAX || width < INT_MIN) {
- set_api_error("Width value outside range", err);
+ api_set_error(err, Validation, _("Width value outside range"));
return;
}
@@ -283,7 +285,7 @@ Tabpage window_get_tabpage(Window window, Error *err)
/// @return true if the window is valid, false otherwise
Boolean window_is_valid(Window window)
{
- Error stub = {.set = false};
+ Error stub = ERROR_INIT;
return find_window_by_handle(window, &stub) != NULL;
}
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index b3f4e4d449..3b450e5245 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -7267,6 +7267,7 @@ static int ins_bs(int c, int mode, int *inserted_space_p)
}
--Insstart_orig.lnum;
Insstart_orig.col = MAXCOL;
+ Insstart = Insstart_orig;
}
/*
* In replace mode:
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 871f15c576..0dd261f53a 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -12483,25 +12483,18 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv)
ADD(args, vim_to_object(tv));
}
- bool errored;
- Object result;
- if (!channel_send_call((uint64_t)argvars[0].vval.v_number,
- (char *)argvars[1].vval.v_string,
- args,
- &result,
- &errored)) {
- EMSG2(_(e_invarg2), "Channel doesn't exist");
- return;
- }
-
- if (errored) {
- vim_report_error(result.data.string);
+ Error err = ERROR_INIT;
+ Object result = channel_send_call((uint64_t)argvars[0].vval.v_number,
+ (char *)argvars[1].vval.v_string,
+ args,
+ &err);
+ if (err.set) {
+ vim_report_error(cstr_as_string(err.msg));
goto end;
}
-
- Error conversion_error = {.set = false};
- if (!object_to_vim(result, rettv, &conversion_error)) {
- EMSG(_("Error converting the call result"));
+
+ if (!object_to_vim(result, rettv, &err)) {
+ EMSG2(_("Error converting the call result: %s"), err.msg);
}
end:
@@ -19454,7 +19447,7 @@ static void script_host_eval(char *method, typval_T *argvars, typval_T *rettv)
return;
}
- Error err = {.set = false};
+ Error err = ERROR_INIT;
object_to_vim(result, rettv, &err);
api_free_object(result);
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index b72d1941ec..163d20f13a 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1648,11 +1648,13 @@ void write_viminfo(char_u *file, int forceit)
if (fp_in != NULL) {
fclose(fp_in);
- /*
- * In case of an error keep the original viminfo file.
- * Otherwise rename the newly written file.
- */
- if (viminfo_errcnt || vim_rename(tempname, fname) == -1) {
+ /* In case of an error keep the original viminfo file. Otherwise
+ * rename the newly written file. Give an error if that fails. */
+ if (viminfo_errcnt == 0 && vim_rename(tempname, fname) == -1) {
+ viminfo_errcnt++;
+ EMSG2(_("E886: Can't rename viminfo file to %s!"), fname);
+ }
+ if (viminfo_errcnt > 0) {
os_remove((char *)tempname);
}
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 810df627c1..b8d8837092 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -5200,9 +5200,14 @@ static int ex_window(void)
RedrawingDisabled = i;
+ int save_KeyTyped = KeyTyped;
+
/* Trigger CmdwinLeave autocommands. */
apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, FALSE, curbuf);
+ /* Restore KeyTyped in case it is modified by autocommands */
+ KeyTyped = save_KeyTyped;
+
/* Restore the command line info. */
ccline = save_ccline;
cmdwin_type = 0;
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 0d61172d69..c3f6e2c2b6 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -2209,6 +2209,12 @@ static int vgetorpeek(int advance)
}
if (c < 0)
continue; /* end of input script reached */
+
+ // Allow mapping for just typed characters. When we get here c
+ // is the number of extra bytes and typebuf.tb_len is 1.
+ for (n = 1; n <= c; n++) {
+ typebuf.tb_noremap[typebuf.tb_off + n] = RM_YES;
+ }
typebuf.tb_len += c;
/* buffer full, don't map */
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 674786ff08..851022cd62 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -1059,6 +1059,10 @@ EXTERN int typebuf_was_filled INIT(= FALSE); /* received text from client
EXTERN int term_is_xterm INIT(= FALSE); /* xterm-like 'term' */
#endif
+#if defined(UNIX)
+EXTERN int xterm_conflict_mouse INIT(= FALSE);
+#endif
+
#ifdef BACKSLASH_IN_FILENAME
EXTERN char psepc INIT(= '\\'); /* normal path separator character */
EXTERN char psepcN INIT(= '/'); /* abnormal path separator character */
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index cc82630548..391828da28 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -845,7 +845,10 @@ getcount:
/* When getting a text character and the next character is a
* multi-byte character, it could be a composing character.
- * However, don't wait for it to arrive. */
+ * However, don't wait for it to arrive. Also, do enable mapping,
+ * because if it's put back with vungetc() it's too late to apply
+ * mapping. */
+ no_mapping--;
while (enc_utf8 && lang && (c = vpeekc()) > 0
&& (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) {
c = plain_vgetc();
@@ -857,6 +860,7 @@ getcount:
else
ca.ncharC2 = c;
}
+ no_mapping++;
}
--no_mapping;
--allow_keys;
diff --git a/src/nvim/os/channel.c b/src/nvim/os/channel.c
index 1670424e4e..5598b485ba 100644
--- a/src/nvim/os/channel.c
+++ b/src/nvim/os/channel.c
@@ -172,40 +172,36 @@ bool channel_send_event(uint64_t id, char *name, Array args)
/// Sends a method call to a channel
///
/// @param id The channel id
-/// @param name The method name, an arbitrary string
+/// @param method_name The method name, an arbitrary string
/// @param args Array with method arguments
-/// @param[out] result Pointer to return value received from the channel
/// @param[out] error True if the return value is an error
-/// @return True if the call was sent successfully, false otherwise.
-bool channel_send_call(uint64_t id,
- char *name,
- Array args,
- Object *result,
- bool *errored)
+/// @return Whatever the remote method returned
+Object channel_send_call(uint64_t id,
+ char *method_name,
+ Array args,
+ Error *err)
{
Channel *channel = NULL;
if (!(channel = pmap_get(uint64_t)(channels, id)) || !channel->enabled) {
+ api_set_error(err, Exception, _("Invalid channel \"%" PRIu64 "\""), id);
api_free_array(args);
- return false;
+ return NIL;
}
if (kv_size(channel->call_stack) > 20) {
// 20 stack depth is more than anyone should ever need for RPC calls
- *errored = true;
- char buf[256];
- snprintf(buf,
- sizeof(buf),
- "Channel %" PRIu64 " crossed maximum stack depth",
- channel->id);
- *result = STRING_OBJ(cstr_to_string(buf));
+ api_set_error(err,
+ Exception,
+ _("Channel %" PRIu64 " crossed maximum stack depth"),
+ channel->id);
api_free_array(args);
- return false;
+ return NIL;
}
uint64_t request_id = channel->next_request_id++;
// Send the msgpack-rpc request
- send_request(channel, request_id, name, args);
+ send_request(channel, request_id, method_name, args);
EventSource channel_source = channel->is_job
? job_event_source(channel->data.job)
@@ -224,10 +220,12 @@ bool channel_send_call(uint64_t id,
channel->enabled && // the channel is still enabled
kv_size(channel->call_stack) >= size); // the call didn't return
- *errored = frame.errored;
- *result = frame.result;
+ if (frame.errored) {
+ api_set_error(err, Exception, "%s", frame.result.data.string.data);
+ return NIL;
+ }
- return true;
+ return frame.result;
}
/// Subscribes to event broadcasts
@@ -433,7 +431,9 @@ static bool channel_write(Channel *channel, WBuffer *buffer)
static void send_error(Channel *channel, uint64_t id, char *err)
{
- channel_write(channel, serialize_response(id, err, NIL, &out_buffer));
+ Error e = ERROR_INIT;
+ api_set_error(&e, Exception, "%s", err);
+ channel_write(channel, serialize_response(id, &e, NIL, &out_buffer));
}
static void send_request(Channel *channel,
diff --git a/src/nvim/os/msgpack_rpc.c b/src/nvim/os/msgpack_rpc.c
index d7e3d33c4b..55bc006ad1 100644
--- a/src/nvim/os/msgpack_rpc.c
+++ b/src/nvim/os/msgpack_rpc.c
@@ -30,14 +30,14 @@ WBuffer *msgpack_rpc_call(uint64_t channel_id,
FUNC_ATTR_NONNULL_ARG(3)
{
uint64_t response_id;
- char *err = msgpack_rpc_validate(&response_id, req);
+ Error error = ERROR_INIT;
+ msgpack_rpc_validate(&response_id, req, &error);
- if (err) {
- return serialize_response(response_id, err, NIL, sbuffer);
+ if (error.set) {
+ return serialize_response(response_id, &error, NIL, sbuffer);
}
// dispatch the call
- Error error = { .set = false };
Object rv = msgpack_rpc_dispatch(channel_id, req, &error);
// send the response
msgpack_packer response;
@@ -47,12 +47,12 @@ WBuffer *msgpack_rpc_call(uint64_t channel_id,
ELOG("Error dispatching msgpack-rpc call: %s(request: id %" PRIu64 ")",
error.msg,
response_id);
- return serialize_response(response_id, error.msg, NIL, sbuffer);
+ return serialize_response(response_id, &error, NIL, sbuffer);
}
DLOG("Successfully completed mspgack-rpc call(request id: %" PRIu64 ")",
response_id);
- return serialize_response(response_id, NULL, rv, sbuffer);
+ return serialize_response(response_id, &error, rv, sbuffer);
}
/// Finishes the msgpack-rpc call with an error message.
@@ -112,10 +112,10 @@ WBuffer *serialize_request(uint64_t request_id,
/// Serializes a msgpack-rpc response
WBuffer *serialize_response(uint64_t response_id,
- char *err_msg,
+ Error *err,
Object arg,
msgpack_sbuffer *sbuffer)
- FUNC_ATTR_NONNULL_ARG(4)
+ FUNC_ATTR_NONNULL_ARG(2, 4)
{
msgpack_packer pac;
msgpack_packer_init(&pac, sbuffer, msgpack_sbuffer_write);
@@ -123,11 +123,11 @@ WBuffer *serialize_response(uint64_t response_id,
msgpack_pack_int(&pac, 1);
msgpack_pack_uint64(&pac, response_id);
- if (err_msg) {
- String err = {.size = strlen(err_msg), .data = err_msg};
- // error message
- msgpack_pack_bin(&pac, err.size);
- msgpack_pack_bin_body(&pac, err.data, err.size);
+ if (err->set) {
+ // error represented by a [type, message] array
+ msgpack_pack_array(&pac, 2);
+ msgpack_rpc_from_integer(err->type, &pac);
+ msgpack_rpc_from_string(cstr_as_string(err->msg), &pac);
// Nil result
msgpack_pack_nil(&pac);
} else {
@@ -146,43 +146,43 @@ WBuffer *serialize_response(uint64_t response_id,
return rv;
}
-static char *msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req)
+static void msgpack_rpc_validate(uint64_t *response_id,
+ msgpack_object *req,
+ Error *err)
{
// response id not known yet
*response_id = 0;
// Validate the basic structure of the msgpack-rpc payload
if (req->type != MSGPACK_OBJECT_ARRAY) {
- return "Request is not an array";
+ api_set_error(err, Validation, _("Request is not an array"));
}
if (req->via.array.size != 4) {
- return "Request array size should be 4";
+ api_set_error(err, Validation, _("Request array size should be 4"));
}
if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
- return "Id must be a positive integer";
+ api_set_error(err, Validation, _("Id must be a positive integer"));
}
// Set the response id, which is the same as the request
*response_id = req->via.array.ptr[1].via.u64;
if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
- return "Message type must be an integer";
+ api_set_error(err, Validation, _("Message type must be an integer"));
}
if (req->via.array.ptr[0].via.u64 != 0) {
- return "Message type must be 0";
+ api_set_error(err, Validation, _("Message type must be 0"));
}
if (req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN
&& req->via.array.ptr[2].type != MSGPACK_OBJECT_STR) {
- return "Method must be a string";
+ api_set_error(err, Validation, _("Method must be a string"));
}
if (req->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) {
- return "Paremeters must be an array";
+ api_set_error(err, Validation, _("Paremeters must be an array"));
}
-
- return NULL;
}
diff --git a/src/nvim/os/provider.c b/src/nvim/os/provider.c
index 2e7a677793..d4fffaa053 100644
--- a/src/nvim/os/provider.c
+++ b/src/nvim/os/provider.c
@@ -107,12 +107,11 @@ Object provider_call(char *method, Array args)
return NIL;
}
- bool error = false;
- Object result = NIL;
- channel_send_call(f->channel_id, method, args, &result, &error);
+ Error err = ERROR_INIT;
+ Object result = NIL = channel_send_call(f->channel_id, method, args, &err);
- if (error) {
- vim_report_error(result.data.string);
+ if (err.set) {
+ vim_report_error(cstr_as_string(err.msg));
api_free_object(result);
return NIL;
}
diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c
index a54ed000af..52f57f8262 100644
--- a/src/nvim/os_unix.c
+++ b/src/nvim/os_unix.c
@@ -761,11 +761,11 @@ void mch_setmouse(int on)
}
-/*
- * Set the mouse termcode, depending on the 'term' and 'ttymouse' options.
- */
+/// Sets the mouse termcode, depending on the 'term' and 'ttymouse' options.
void check_mouse_termcode(void)
{
+ xterm_conflict_mouse = false;
+
if (use_xterm_mouse()
&& use_xterm_mouse() != 3
) {
@@ -791,29 +791,31 @@ void check_mouse_termcode(void)
else
del_mouse_termcode(KS_NETTERM_MOUSE);
- /* conflicts with xterm mouse: "\033[" and "\033[M" */
- if (!use_xterm_mouse()
- )
+ // Conflicts with xterm mouse: "\033[" and "\033[M".
+ // Also conflicts with the xterm termresponse, skip this if it was requested
+ // already.
+ if (!use_xterm_mouse()) {
set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME)
? "\233" : "\033["));
- else
+ xterm_conflict_mouse = true;
+ }
+ else {
del_mouse_termcode(KS_DEC_MOUSE);
+ }
/* same as the dec mouse */
- if (use_xterm_mouse() == 3
- ) {
- set_mouse_termcode(KS_URXVT_MOUSE, (char_u *)(term_is_8bit(T_NAME)
- ? "\233"
- : "\033["));
-
+ if (use_xterm_mouse() == 3 && !did_request_esc_sequence()) {
+ set_mouse_termcode(KS_URXVT_MOUSE,
+ (char_u *)(term_is_8bit(T_NAME) ? "\233" : "\033["));
if (*p_mouse != NUL) {
- mch_setmouse(FALSE);
+ mch_setmouse(false);
setmouse();
}
- } else
+ resume_get_esc_sequence();
+ } else {
del_mouse_termcode(KS_URXVT_MOUSE);
- /* There is no conflict with xterm mouse */
- if (use_xterm_mouse() == 4
- ) {
+ }
+ // There is no conflict with xterm mouse.
+ if (use_xterm_mouse() == 4) {
set_mouse_termcode(KS_SGR_MOUSE, (char_u *)(term_is_8bit(T_NAME)
? "\233<"
: "\033[<"));
@@ -822,8 +824,9 @@ void check_mouse_termcode(void)
mch_setmouse(FALSE);
setmouse();
}
- } else
+ } else {
del_mouse_termcode(KS_SGR_MOUSE);
+ }
}
/*
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index 184285b5f6..19b92c5789 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -18,6 +18,7 @@
#include "nvim/search.h"
#include "nvim/strings.h"
#include "nvim/window.h"
+#include "nvim/edit.h"
static pumitem_T *pum_array = NULL; // items of displayed pum
static int pum_size; // nr of items in "pum_array"
@@ -540,7 +541,9 @@ static int pum_set_selected(int n, int repeat)
if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) {
g_do_tagpreview = p_pvh;
}
+ RedrawingDisabled++;
resized = prepare_tagpreview(false);
+ RedrawingDisabled--;
g_do_tagpreview = 0;
if (curwin->w_p_pvw) {
@@ -607,6 +610,13 @@ static int pum_set_selected(int n, int repeat)
curwin->w_cursor.col = 0;
if ((curwin != curwin_save) && win_valid(curwin_save)) {
+ // When the first completion is done and the preview
+ // window is not resized, skip the preview window's
+ // status line redrawing.
+ if (ins_compl_active() && !resized) {
+ curwin->w_redr_status = FALSE;
+ }
+
// Return cursor to where we were
validate_cursor();
redraw_later(SOME_VALID);
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index ce2a80adaa..3bc70b6b41 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1890,6 +1890,7 @@ static void qf_free(qf_info_T *qi, int idx)
}
free(qi->qf_lists[idx].qf_title);
qi->qf_lists[idx].qf_title = NULL;
+ qi->qf_lists[idx].qf_index = 0;
}
/*
diff --git a/src/nvim/term.c b/src/nvim/term.c
index d2c524e2e8..263b81fc3a 100644
--- a/src/nvim/term.c
+++ b/src/nvim/term.c
@@ -152,6 +152,9 @@ char *UP, *BC, PC;
# define TGETENT(b, t) tgetent((char *)(b), (char *)(t))
#endif /* HAVE_TGETENT */
+static int xt_index_in = 0;
+static int xt_index_out = 0;
+
static bool detected_8bit = false; // detected 8-bit terminal
static struct builtin_term builtin_termcaps[] =
@@ -2408,8 +2411,9 @@ void starttermcap(void)
may_req_termresponse();
/* Immediately check for a response. If t_Co changes, we don't
* want to redraw with wrong colors first. */
- if (crv_status != CRV_GET)
+ if (crv_status == CRV_SENT) {
check_for_codes_from_term();
+ }
}
}
}
@@ -2446,6 +2450,38 @@ void stoptermcap(void)
}
}
+#if defined(UNIX)
+/// Returns true when the xterm version was requested or anything else that
+/// would send an ESC sequence back to Vim.
+///
+/// If not sent yet, prevent it from being sent soon.
+/// Used to check whether it is OK to enable checking for DEC mouse codes,
+/// which conflict with may xterm ESC sequences.
+bool did_request_esc_sequence(void)
+{
+ if (crv_status == CRV_GET) {
+ crv_status = 0;
+ }
+ if (u7_status == U7_GET) {
+ u7_status = 0;
+ }
+ return crv_status == CRV_SENT || u7_status == U7_SENT
+ || xt_index_out > xt_index_in;
+}
+
+/// If requesting the version was disabled in did_request_esc_sequence(),
+/// enable it again.
+void resume_get_esc_sequence(void)
+{
+ if (crv_status == 0) {
+ crv_status = CRV_GET;
+ }
+ if (u7_status == 0) {
+ u7_status = U7_GET;
+ }
+}
+#endif
+
/*
* Request version string (for xterm) when needed.
* Only do this after switching to raw mode, otherwise the result will be
@@ -2458,6 +2494,8 @@ void stoptermcap(void)
* Insert mode.
* On Unix only do it when both output and input are a tty (avoid writing
* request to terminal while reading from a file).
+ * Do not do this when a mouse is being detected that starts with the same ESC
+ * sequence as the termresponse.
* The result is caught in check_termcode().
*/
void may_req_termresponse(void)
@@ -2470,6 +2508,7 @@ void may_req_termresponse(void)
# ifdef UNIX
&& isatty(1)
&& isatty(read_cmd_fd)
+ && !xterm_conflict_mouse
# endif
&& *T_CRV != NUL) {
LOG_TR("Sending CRV");
@@ -4130,9 +4169,6 @@ int show_one_termcode(char_u *name, char_u *code, int printit)
* termcap codes from the terminal itself.
* We get them one by one to avoid a very long response string.
*/
-static int xt_index_in = 0;
-static int xt_index_out = 0;
-
static void req_codes_from_term(void)
{
xt_index_out = 0;
diff --git a/src/nvim/version.c b/src/nvim/version.c
index da2b3630d9..5a0b01df28 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -184,8 +184,41 @@ static char *(features[]) = {
};
static int included_patches[] = {
- // Add new patch number below this line
- //410,
+ //444,
+ //443,
+ //442,
+ //441,
+ //440,
+ //439,
+ //438,
+ //437,
+ //436,
+ //435,
+ //434,
+ //433,
+ //432 NA
+ //431 NA
+ //430,
+ //429 NA
+ //428 NA
+ //427,
+ //426 NA
+ //425,
+ //424 NA
+ //423,
+ //422,
+ //421,
+ //420 NA
+ //419,
+ //418,
+ //417,
+ //416,
+ //415,
+ //414,
+ //413 NA
+ //412 NA
+ //411,
+ 410,
//409 NA
//408,
//407,
@@ -212,31 +245,31 @@ static int included_patches[] = {
//386,
//385,
//384 NA
- //383,
- //382,
- //381,
+ 383,
+ 382,
+ 381,
//380 NA
- //379,
+ 379,
//378,
- //377,
+ 377,
376,
//375,
- //374,
- //373 NA
- //372,
+ 374,
+ 373,
+ 372,
371,
370,
369,
368,
367,
//366,
- //365,
- //364,
+ 365,
+ 364,
//363,
362,
- //361,
+ 361,
//360,
- //359,
+ 359,
358,
357,
//356 NA
@@ -290,7 +323,7 @@ static int included_patches[] = {
308,
//307 NA
306,
- //305,
+ 305,
//304 NA
303,
302,
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 27fb160035..f5d8edc751 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -540,8 +540,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
int available;
int oldwin_height = 0;
int layout;
- frame_T *frp, *curfrp;
+ frame_T *frp, *curfrp, *frp2, *prevfrp;
int before;
+ int minheight;
+ int wmh1;
if (flags & WSP_TOP)
oldwin = firstwin;
@@ -561,30 +563,58 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
if (flags & WSP_VERT) {
+ int wmw1;
+ int minwidth;
+
layout = FR_ROW;
/*
* Check if we are able to split the current window and compute its
* width.
*/
- needed = p_wmw + 1;
- if (flags & WSP_ROOM)
- needed += p_wiw - p_wmw;
- if (p_ea || (flags & (WSP_BOT | WSP_TOP))) {
+ // Current window requires at least 1 space.
+ wmw1 = (p_wmw == 0 ? 1 : p_wmw);
+ needed = wmw1 + 1;
+ if (flags & WSP_ROOM) {
+ needed += p_wiw - wmw1;
+ }
+ if (flags & (WSP_BOT | WSP_TOP)) {
+ minwidth = frame_minwidth(topframe, NOWIN);
available = topframe->fr_width;
- needed += frame_minwidth(topframe, NULL);
- } else
- available = oldwin->w_width;
+ needed += minwidth;
+ } else if (p_ea) {
+ minwidth = frame_minwidth(oldwin->w_frame, NOWIN);
+ prevfrp = oldwin->w_frame;
+ for (frp = oldwin->w_frame->fr_parent; frp != NULL;
+ frp = frp->fr_parent) {
+ if (frp->fr_layout == FR_ROW) {
+ for (frp2 = frp->fr_child; frp2 != NULL; frp2 = frp2->fr_next) {
+ if (frp2 != prevfrp) {
+ minwidth += frame_minwidth(frp2, NOWIN);
+ }
+ }
+ }
+ prevfrp = frp;
+ }
+ available = topframe->fr_width;
+ needed += minwidth;
+ } else {
+ minwidth = frame_minwidth(oldwin->w_frame, NOWIN);
+ available = oldwin->w_frame->fr_width;
+ needed += minwidth;
+ }
if (available < needed && new_wp == NULL) {
EMSG(_(e_noroom));
return FAIL;
}
if (new_size == 0)
new_size = oldwin->w_width / 2;
- if (new_size > oldwin->w_width - p_wmw - 1)
- new_size = oldwin->w_width - p_wmw - 1;
- if (new_size < p_wmw)
- new_size = p_wmw;
+ if (new_size > available - minwidth - 1) {
+ new_size = available - minwidth - 1;
+ }
+ if (new_size < wmw1) {
+ new_size = wmw1;
+ }
/* if it doesn't fit in the current window, need win_equal() */
if (oldwin->w_width - new_size - 1 < p_wmw)
@@ -619,15 +649,36 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
* Check if we are able to split the current window and compute its
* height.
*/
- needed = p_wmh + STATUS_HEIGHT + need_status;
- if (flags & WSP_ROOM)
- needed += p_wh - p_wmh;
- if (p_ea || (flags & (WSP_BOT | WSP_TOP))) {
+ // Current window requires at least 1 space.
+ wmh1 = (p_wmh == 0 ? 1 : p_wmh);
+ needed = wmh1 + STATUS_HEIGHT;
+ if (flags & WSP_ROOM) {
+ needed += p_wh - wmh1;
+ }
+ if (flags & (WSP_BOT | WSP_TOP)) {
+ minheight = frame_minheight(topframe, NOWIN) + need_status;
+ available = topframe->fr_height;
+ needed += minheight;
+ } else if (p_ea) {
+ minheight = frame_minheight(oldwin->w_frame, NOWIN) + need_status;
+ prevfrp = oldwin->w_frame;
+ for (frp = oldwin->w_frame->fr_parent; frp != NULL;
+ frp = frp->fr_parent) {
+ if (frp->fr_layout == FR_COL) {
+ for (frp2 = frp->fr_child; frp2 != NULL; frp2 = frp2->fr_next) {
+ if (frp2 != prevfrp) {
+ minheight += frame_minheight(frp2, NOWIN);
+ }
+ }
+ }
+ prevfrp = frp;
+ }
available = topframe->fr_height;
- needed += frame_minheight(topframe, NULL);
+ needed += minheight;
} else {
- available = oldwin->w_height;
- needed += p_wmh;
+ minheight = frame_minheight(oldwin->w_frame, NOWIN) + need_status;
+ available = oldwin->w_frame->fr_height;
+ needed += minheight;
}
if (available < needed && new_wp == NULL) {
EMSG(_(e_noroom));
@@ -641,10 +692,12 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
if (new_size == 0)
new_size = oldwin_height / 2;
- if (new_size > oldwin_height - p_wmh - STATUS_HEIGHT)
- new_size = oldwin_height - p_wmh - STATUS_HEIGHT;
- if (new_size < p_wmh)
- new_size = p_wmh;
+ if (new_size > available - minheight - STATUS_HEIGHT) {
+ new_size = available - minheight - STATUS_HEIGHT;
+ }
+ if (new_size < wmh1) {
+ new_size = wmh1;
+ }
/* if it doesn't fit in the current window, need win_equal() */
if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh)