mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
Merge branch 'master' into luaviml'/lua
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
// Much of this code was adapted from 'if_py_both.h' from the original
|
||||
// vim source
|
||||
#include <stdbool.h>
|
||||
@@ -62,7 +65,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
|
||||
index = convert_index(index);
|
||||
Array slice = nvim_buf_get_lines(0, buffer, index, index+1, true, err);
|
||||
|
||||
if (!err->set && slice.size) {
|
||||
if (!ERROR_SET(err) && slice.size) {
|
||||
rv = slice.items[0].data.string;
|
||||
}
|
||||
|
||||
@@ -168,7 +171,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
||||
end = normalize_index(buf, end, &oob);
|
||||
|
||||
if (strict_indexing && oob) {
|
||||
api_set_error(err, Validation, _("Index out of bounds"));
|
||||
api_set_error(err, kErrorTypeValidation, "Index out of bounds");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -184,7 +187,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
||||
int64_t lnum = start + (int64_t)i;
|
||||
|
||||
if (lnum > LONG_MAX) {
|
||||
api_set_error(err, Validation, _("Line index is too high"));
|
||||
api_set_error(err, kErrorTypeValidation, "Line index is too high");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -200,7 +203,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
|
||||
}
|
||||
|
||||
end:
|
||||
if (err->set) {
|
||||
if (ERROR_SET(err)) {
|
||||
for (size_t i = 0; i < rv.size; i++) {
|
||||
xfree(rv.items[i].data.string.data);
|
||||
}
|
||||
@@ -280,30 +283,31 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
||||
end = normalize_index(buf, end, &oob);
|
||||
|
||||
if (strict_indexing && oob) {
|
||||
api_set_error(err, Validation, _("Index out of bounds"));
|
||||
api_set_error(err, kErrorTypeValidation, "Index out of bounds");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (start > end) {
|
||||
api_set_error(err,
|
||||
Validation,
|
||||
_("Argument \"start\" is higher than \"end\""));
|
||||
kErrorTypeValidation,
|
||||
"Argument \"start\" is higher than \"end\"");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < replacement.size; i++) {
|
||||
if (replacement.items[i].type != kObjectTypeString) {
|
||||
api_set_error(err,
|
||||
Validation,
|
||||
_("All items in the replacement array must be strings"));
|
||||
kErrorTypeValidation,
|
||||
"All items in the replacement array must be strings");
|
||||
return;
|
||||
}
|
||||
// Disallow newlines in the middle of the line.
|
||||
if (channel_id != VIML_INTERNAL_CALL) {
|
||||
const String l = replacement.items[i].data.string;
|
||||
if (memchr(l.data, NL, l.size)) {
|
||||
api_set_error(err, Validation, _("string cannot contain newlines"));
|
||||
api_set_error(err, kErrorTypeValidation,
|
||||
"String cannot contain newlines");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -330,7 +334,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
||||
switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf);
|
||||
|
||||
if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
|
||||
api_set_error(err, Exception, _("Failed to save undo information"));
|
||||
api_set_error(err, kErrorTypeException, "Failed to save undo information");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -340,7 +344,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
||||
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) {
|
||||
api_set_error(err, Exception, _("Failed to delete line"));
|
||||
api_set_error(err, kErrorTypeException, "Failed to delete line");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
@@ -357,12 +361,12 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
||||
int64_t lnum = start + (int64_t)i;
|
||||
|
||||
if (lnum > LONG_MAX) {
|
||||
api_set_error(err, Validation, _("Index value is too high"));
|
||||
api_set_error(err, kErrorTypeValidation, "Index value is too high");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (ml_replace((linenr_T)lnum, (char_u *)lines[i], false) == FAIL) {
|
||||
api_set_error(err, Exception, _("Failed to replace line"));
|
||||
api_set_error(err, kErrorTypeException, "Failed to replace line");
|
||||
goto end;
|
||||
}
|
||||
// Mark lines that haven't been passed to the buffer as they need
|
||||
@@ -375,12 +379,12 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
||||
int64_t lnum = start + (int64_t)i - 1;
|
||||
|
||||
if (lnum > LONG_MAX) {
|
||||
api_set_error(err, Validation, _("Index value is too high"));
|
||||
api_set_error(err, kErrorTypeValidation, "Index value is too high");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (ml_append((linenr_T)lnum, (char_u *)lines[i], 0, false) == FAIL) {
|
||||
api_set_error(err, Exception, _("Failed to insert line"));
|
||||
api_set_error(err, kErrorTypeException, "Failed to insert line");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -566,11 +570,15 @@ void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err)
|
||||
|
||||
/// Gets the buffer number
|
||||
///
|
||||
/// @deprecated The buffer number now is equal to the object id,
|
||||
/// so there is no need to use this function.
|
||||
///
|
||||
/// @param buffer Buffer handle
|
||||
/// @param[out] err Error details, if any
|
||||
/// @return Buffer number
|
||||
Integer nvim_buf_get_number(Buffer buffer, Error *err)
|
||||
FUNC_API_SINCE(1)
|
||||
FUNC_API_DEPRECATED_SINCE(2)
|
||||
{
|
||||
Integer rv = 0;
|
||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||
@@ -627,7 +635,7 @@ void nvim_buf_set_name(Buffer buffer, String name, Error *err)
|
||||
}
|
||||
|
||||
if (ren_ret == FAIL) {
|
||||
api_set_error(err, Exception, _("Failed to rename buffer"));
|
||||
api_set_error(err, kErrorTypeException, "Failed to rename buffer");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,7 +647,9 @@ Boolean nvim_buf_is_valid(Buffer buffer)
|
||||
FUNC_API_SINCE(1)
|
||||
{
|
||||
Error stub = ERROR_INIT;
|
||||
return find_buffer_by_handle(buffer, &stub) != NULL;
|
||||
Boolean ret = find_buffer_by_handle(buffer, &stub) != NULL;
|
||||
api_clear_error(&stub);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Inserts a sequence of lines to a buffer at a certain index
|
||||
@@ -678,7 +688,8 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
|
||||
}
|
||||
|
||||
if (name.size != 1) {
|
||||
api_set_error(err, Validation, _("Mark name must be a single character"));
|
||||
api_set_error(err, kErrorTypeValidation,
|
||||
"Mark name must be a single character");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -696,7 +707,7 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
|
||||
}
|
||||
|
||||
if (posp == NULL) {
|
||||
api_set_error(err, Validation, _("Invalid mark name"));
|
||||
api_set_error(err, kErrorTypeValidation, "Invalid mark name");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -751,11 +762,11 @@ Integer nvim_buf_add_highlight(Buffer buffer,
|
||||
}
|
||||
|
||||
if (line < 0 || line >= MAXLNUM) {
|
||||
api_set_error(err, Validation, _("Line number outside range"));
|
||||
api_set_error(err, kErrorTypeValidation, "Line number outside range");
|
||||
return 0;
|
||||
}
|
||||
if (col_start < 0 || col_start > MAXCOL) {
|
||||
api_set_error(err, Validation, _("Column value outside range"));
|
||||
api_set_error(err, kErrorTypeValidation, "Column value outside range");
|
||||
return 0;
|
||||
}
|
||||
if (col_end < 0 || col_end > MAXCOL) {
|
||||
@@ -792,7 +803,7 @@ void nvim_buf_clear_highlight(Buffer buffer,
|
||||
}
|
||||
|
||||
if (line_start < 0 || line_start >= MAXLNUM) {
|
||||
api_set_error(err, Validation, _("Line number outside range"));
|
||||
api_set_error(err, kErrorTypeValidation, "Line number outside range");
|
||||
return;
|
||||
}
|
||||
if (line_end < 0 || line_end > MAXLNUM) {
|
||||
|
Reference in New Issue
Block a user