diff options
Diffstat (limited to 'src/nvim')
-rw-r--r-- | src/nvim/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/nvim/getchar.c | 4 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 30 | ||||
-rw-r--r-- | src/nvim/lua/vim.lua | 51 | ||||
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/mouse.c | 12 | ||||
-rw-r--r-- | src/nvim/po/sr.po | 52 |
7 files changed, 100 insertions, 65 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 4a698052ee..331ab16dd7 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -87,8 +87,8 @@ file(MAKE_DIRECTORY ${LINT_SUPPRESSES_ROOT}/src) file(GLOB NVIM_SOURCES *.c) file(GLOB NVIM_HEADERS *.h) -file(GLOB XDIFF_SOURCES ../xdiff/*.c) -file(GLOB XDIFF_HEADERS ../xdiff/*.h) +file(GLOB EXTERNAL_SOURCES ../xdiff/*.c ../mpack/*.c) +file(GLOB EXTERNAL_HEADERS ../xdiff/*.h ../mpack/*.h) foreach(subdir os @@ -171,8 +171,8 @@ foreach(sfile ${CONV_SOURCES}) message(FATAL_ERROR "${sfile} doesn't exist (it was added to CONV_SOURCES)") endif() endforeach() -# xdiff: inlined external project, we don't maintain it. #9306 -list(APPEND CONV_SOURCES ${XDIFF_SOURCES}) +# xdiff, mpack: inlined external project, we don't maintain it. #9306 +list(APPEND CONV_SOURCES ${EXTERNAL_SOURCES}) if(NOT MSVC) set_source_files_properties( @@ -471,7 +471,7 @@ endif() add_executable(nvim ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS} ${NVIM_GENERATED_SOURCES} ${NVIM_SOURCES} ${NVIM_HEADERS} - ${XDIFF_SOURCES} ${XDIFF_HEADERS}) + ${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS}) target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES}) install_helper(TARGETS nvim) @@ -602,7 +602,7 @@ add_library( EXCLUDE_FROM_ALL ${NVIM_SOURCES} ${NVIM_GENERATED_SOURCES} ${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS} - ${XDIFF_SOURCES} ${XDIFF_HEADERS} + ${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS} ) set_property(TARGET libnvim APPEND PROPERTY INCLUDE_DIRECTORIES ${LUA_PREFERRED_INCLUDE_DIRS}) @@ -632,7 +632,7 @@ else() EXCLUDE_FROM_ALL ${NVIM_SOURCES} ${NVIM_GENERATED_SOURCES} ${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS} - ${XDIFF_SOURCES} ${XDIFF_HEADERS} + ${EXTERNAL_SOURCES} ${EXTERNAL_HEADERS} ${UNIT_TEST_FIXTURES} ) target_link_libraries(nvim-test ${NVIM_TEST_LINK_LIBRARIES}) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 28f58e2c34..11e3b9bc2d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1563,8 +1563,8 @@ int vgetc(void) */ may_garbage_collect = false; - // Exec lua callbacks for on_keystroke - nlua_execute_log_keystroke(c); + // Execute Lua on_key callbacks. + nlua_execute_on_key(c); return c; } diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5cd9894f9d..d071203db1 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -33,6 +33,7 @@ #include "nvim/eval/userfunc.h" #include "nvim/event/time.h" #include "nvim/event/loop.h" +#include "mpack/lmpack.h" #include "nvim/os/os.h" @@ -506,6 +507,8 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_setfield(lstate, -2, "__tostring"); lua_setmetatable(lstate, -2); nlua_nil_ref = nlua_ref(lstate, -1); + lua_pushvalue(lstate, -1); + lua_setfield(lstate, LUA_REGISTRYINDEX, "mpack.NIL"); lua_setfield(lstate, -2, "NIL"); // vim._empty_dict_mt @@ -513,8 +516,23 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL lua_pushcfunction(lstate, &nlua_empty_dict_tostring); lua_setfield(lstate, -2, "__tostring"); nlua_empty_dict_ref = nlua_ref(lstate, -1); + lua_pushvalue(lstate, -1); + lua_setfield(lstate, LUA_REGISTRYINDEX, "mpack.empty_dict"); lua_setfield(lstate, -2, "_empty_dict_mt"); + // vim.mpack + luaopen_mpack(lstate); + lua_pushvalue(lstate, -1); + lua_setfield(lstate, -3, "mpack"); + + // package.loaded.mpack = vim.mpack + // otherwise luv will be reinitialized when require'mpack' + lua_getglobal(lstate, "package"); + lua_getfield(lstate, -1, "loaded"); + lua_pushvalue(lstate, -3); + lua_setfield(lstate, -2, "mpack"); + lua_pop(lstate, 3); + // internal vim._treesitter... API nlua_add_treesitter(lstate); @@ -1499,7 +1517,7 @@ int nlua_expand_pat(expand_T *xp, lua_getfield(lstate, -1, "_expand_pat"); luaL_checktype(lstate, -1, LUA_TFUNCTION); - // [ vim, vim._log_keystroke, buf ] + // [ vim, vim._on_key, buf ] lua_pushlstring(lstate, (const char *)pat, STRLEN(pat)); if (lua_pcall(lstate, 1, 2, 0) != 0) { @@ -1773,7 +1791,7 @@ char_u *nlua_register_table_as_callable(typval_T *const arg) return name; } -void nlua_execute_log_keystroke(int c) +void nlua_execute_on_key(int c) { char_u buf[NUMBUFLEN]; size_t buf_len = special_to_buf(c, mod_mask, false, buf); @@ -1787,17 +1805,17 @@ void nlua_execute_log_keystroke(int c) // [ vim ] lua_getglobal(lstate, "vim"); - // [ vim, vim._log_keystroke ] - lua_getfield(lstate, -1, "_log_keystroke"); + // [ vim, vim._on_key] + lua_getfield(lstate, -1, "_on_key"); luaL_checktype(lstate, -1, LUA_TFUNCTION); - // [ vim, vim._log_keystroke, buf ] + // [ vim, vim._on_key, buf ] lua_pushlstring(lstate, (const char *)buf, buf_len); if (lua_pcall(lstate, 1, 0, 0)) { nlua_error( lstate, - _("Error executing vim.log_keystroke lua callback: %.*s")); + _("Error executing vim.on_key Lua callback: %.*s")); } // [ vim ] diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 34b314b40d..c6bbdee7ad 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -4,6 +4,7 @@ -- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the -- `inspect` and `lpeg` modules. -- 2. runtime/lua/vim/shared.lua: Code shared between Nvim and tests. +-- (This will go away if we migrate to nvim as the test-runner.) -- 3. src/nvim/lua/: Compiled-into Nvim itself. -- -- Guideline: "If in doubt, put it in the runtime". @@ -426,26 +427,35 @@ function vim.notify(msg, log_level, _opts) end -local on_keystroke_callbacks = {} +function vim.register_keystroke_callback() + error('vim.register_keystroke_callback is deprecated, instead use: vim.on_key') +end + +local on_key_cbs = {} ---- Register a lua {fn} with an {id} to be run after every keystroke. +--- Adds Lua function {fn} with namespace id {ns_id} as a listener to every, +--- yes every, input key. --- ----@param fn function: Function to call. It should take one argument, which is a string. ---- The string will contain the literal keys typed. ---- See |i_CTRL-V| +--- The Nvim command-line option |-w| is related but does not support callbacks +--- and cannot be toggled dynamically. --- +---@param fn function: Callback function. It should take one string argument. +--- On each key press, Nvim passes the key char to fn(). |i_CTRL-V| --- If {fn} is nil, it removes the callback for the associated {ns_id} ----@param ns_id number? Namespace ID. If not passed or 0, will generate and return a new ---- namespace ID from |nvim_create_namesapce()| +---@param ns_id number? Namespace ID. If nil or 0, generates and returns a new +--- |nvim_create_namesapce()| id. --- ----@return number Namespace ID associated with {fn} +---@return number Namespace id associated with {fn}. Or count of all callbacks +---if on_key() is called without arguments. --- ----@note {fn} will be automatically removed if an error occurs while calling. ---- This is to prevent the annoying situation of every keystroke erroring ---- while trying to remove a broken callback. ----@note {fn} will not be cleared from |nvim_buf_clear_namespace()| ----@note {fn} will receive the keystrokes after mappings have been evaluated -function vim.register_keystroke_callback(fn, ns_id) +---@note {fn} will be removed if an error occurs while calling. +---@note {fn} will not be cleared by |nvim_buf_clear_namespace()| +---@note {fn} will receive the keys after mappings have been evaluated +function vim.on_key(fn, ns_id) + if fn == nil and ns_id == nil then + return #on_key_cbs + end + vim.validate { fn = { fn, 'c', true}, ns_id = { ns_id, 'n', true } @@ -455,20 +465,19 @@ function vim.register_keystroke_callback(fn, ns_id) ns_id = vim.api.nvim_create_namespace('') end - on_keystroke_callbacks[ns_id] = fn + on_key_cbs[ns_id] = fn return ns_id end ---- Function that executes the keystroke callbacks. +--- Executes the on_key callbacks. ---@private -function vim._log_keystroke(char) +function vim._on_key(char) local failed_ns_ids = {} local failed_messages = {} - for k, v in pairs(on_keystroke_callbacks) do + for k, v in pairs(on_key_cbs) do local ok, err_msg = pcall(v, char) if not ok then - vim.register_keystroke_callback(nil, k) - + vim.on_key(nil, k) table.insert(failed_ns_ids, k) table.insert(failed_messages, err_msg) end @@ -476,7 +485,7 @@ function vim._log_keystroke(char) if failed_ns_ids[1] then error(string.format( - "Error executing 'on_keystroke' with ns_ids of '%s'\n With messages: %s", + "Error executing 'on_key' with ns_ids '%s'\n Messages: %s", table.concat(failed_ns_ids, ", "), table.concat(failed_messages, "\n"))) end diff --git a/src/nvim/main.c b/src/nvim/main.c index b73f5aad76..716434f32e 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -334,7 +334,7 @@ int main(int argc, char **argv) // prepare screen now, so external UIs can display messages starting = NO_BUFFERS; screenclear(); - TIME_MSG("initialized screen early for UI"); + TIME_MSG("init screen for UI"); } init_default_mappings(); // Default mappings. diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 6c25525936..c599f4ea97 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -723,14 +723,20 @@ int mouse_check_fold(void) int click_row = mouse_row; int click_col = mouse_col; int mouse_char = ' '; + int max_row = Rows; + int max_col = Columns; + int multigrid = ui_has(kUIMultigrid); win_T *wp; wp = mouse_find_win(&click_grid, &click_row, &click_col); + if (wp && multigrid) { + max_row = wp->w_grid_alloc.Rows; + max_col = wp->w_grid_alloc.Columns; + } - if (wp && mouse_row >= 0 && mouse_row < Rows - && mouse_col >= 0 && mouse_col <= Columns) { - int multigrid = ui_has(kUIMultigrid); + if (wp && mouse_row >= 0 && mouse_row < max_row + && mouse_col >= 0 && mouse_col < max_col) { ScreenGrid *gp = multigrid ? &wp->w_grid_alloc : &default_grid; int fdc = win_fdccol_count(wp); int row = multigrid && mouse_grid == 0 ? click_row : mouse_row; diff --git a/src/nvim/po/sr.po b/src/nvim/po/sr.po index 1450ab5164..d34c1c3100 100644 --- a/src/nvim/po/sr.po +++ b/src/nvim/po/sr.po @@ -2,7 +2,7 @@ # # Do ":help uganda" in Vim to read copying and usage conditions. # Do ":help credits" in Vim to see a list of people who contributed. -# Copyright (C) 2017 +# Copyright (C) 2021 # This file is distributed under the same license as the Vim package. # FIRST AUTHOR Ivan Pešić <ivan.pesic@gmail.com>, 2017. # @@ -10,8 +10,8 @@ msgid "" msgstr "" "Project-Id-Version: Vim(Serbian)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-02-14 01:49+0400\n" -"PO-Revision-Date: 2021-02-14 01:54+0400\n" +"POT-Creation-Date: 2021-06-13 13:16+0400\n" +"PO-Revision-Date: 2021-06-13 13:50+0400\n" "Last-Translator: Ivan Pešić <ivan.pesic@gmail.com>\n" "Language-Team: Serbian\n" "Language: sr\n" @@ -97,6 +97,9 @@ msgstr "Извршавање %s" msgid "autocommand %s" msgstr "аутокоманда %s" +msgid "E972: Blob value does not have the right number of bytes" +msgstr "E972: Блоб вредност нема одговарајући број бајтова" + msgid "E831: bf_key_init() called with empty password" msgstr "E831: bf_key_init() је позвана са празном лозинком" @@ -866,7 +869,7 @@ msgid "E976: using Blob as a String" msgstr "E976: коришћење Blob као String" msgid "E908: using an invalid value as a String" -msgstr "E908: користи се недозвољена вредност као String" +msgstr "E908: Користи се неважећа вредност као Стринг: %s" msgid "E698: variable nested too deep for making a copy" msgstr "E698: променљива је предубоко угњеждена да би се направила копија" @@ -913,7 +916,7 @@ msgid "E928: String required" msgstr "E928: Захтева се String" msgid "E808: Number or Float required" -msgstr "E808: Захтева се Number или Float" +msgstr "E808: Захтева се Број или Покретни" msgid "add() argument" msgstr "add() аргумент" @@ -1130,6 +1133,9 @@ msgstr "" "\n" "# Преградне линије, копиране дословно:\n" +msgid "E503: \"%s\" is not a file or writable device" +msgstr "E503: „%s” није фајл или уређај на који може да се уписује" + msgid "Save As" msgstr "Сачувај као" @@ -4635,12 +4641,12 @@ msgstr "E531: Користите \":gui\" да покренете GUI" msgid "E589: 'backupext' and 'patchmode' are equal" msgstr "E589: 'backupext' и 'patchmode' су истоветни" -msgid "E834: Conflicts with value of 'listchars'" -msgstr "E834: У конфликту са вредношћу 'listchars'" - msgid "E835: Conflicts with value of 'fillchars'" msgstr "E835: У конфликту са вредношћу 'fillchars'" +msgid "E834: Conflicts with value of 'listchars'" +msgstr "E834: У конфликту са вредношћу 'listchars'" + msgid "E617: Cannot be changed in the GTK+ 2 GUI" msgstr "E617: Не може да се промени у GTK+ 2 GUI" @@ -5064,7 +5070,7 @@ msgstr "E554: Синтаксна грешка у %s{...}" #, c-format msgid "E888: (NFA regexp) cannot repeat %s" -msgstr "E888: (NFA regexp) не може да се понови %s" +msgstr "E888: (НКА регуларни израз) не може да се понови %s" msgid "" "E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be " @@ -5130,15 +5136,15 @@ msgid "External submatches:\n" msgstr "Спољна подпоклапања:\n" msgid "E865: (NFA) Regexp end encountered prematurely" -msgstr "E865: Крај (NFA) Regexp израза је достигнут прерано" +msgstr "E865: (НКА) прерано је достигнут крај регуларног израза" #, c-format msgid "E866: (NFA regexp) Misplaced %c" -msgstr "E866: (NFA regexp) %c је на погрешном месту" +msgstr "E866: (НКА регуларни израз) %c је на погрешном месту" #, c-format msgid "E877: (NFA regexp) Invalid character class: %d" -msgstr "E877: (NFA regexp) Неважећа карактер класа: %d" +msgstr "E877: (НКА регуларни израз) Неважећа карактер класа: %d" #, c-format msgid "E867: (NFA) Unknown operator '\\z%c'" @@ -6422,6 +6428,13 @@ msgstr "E853: Име аргумента је дуплирано: %s" msgid "E989: Non-default argument follows default argument" msgstr "E989: Неподразумевани аргумент следи иза подразумеваног аргумента" +msgid "E126: Missing :endfunction" +msgstr "E126: Недостаје :endfunction" + +#, c-format +msgid "W22: Text found after :endfunction: %s" +msgstr "W22: Пронађен текст након :endfunction: %s" + #, c-format msgid "E451: Expected }: %s" msgstr "E451: Очекује се }: %s" @@ -6497,17 +6510,6 @@ msgstr "E862: Овде не може да се користи g:" msgid "E932: Closure function should not be at top level: %s" msgstr "E932: Затварајућа функција не би требало да буде на највишем нивоу: %s" -msgid "E126: Missing :endfunction" -msgstr "E126: Недостаје :endfunction" - -#, c-format -msgid "W1001: Text found after :enddef: %s" -msgstr "W1001: Пронађен је текст након :enddef: %s" - -#, c-format -msgid "W22: Text found after :endfunction: %s" -msgstr "W22: Пронађен текст након :endfunction: %s" - #, c-format msgid "E707: Function name conflicts with variable: %s" msgstr "E707: Име функције је у конфликту са променљивом: %s" @@ -6983,8 +6985,8 @@ msgid "E475: Invalid value for argument %s: %s" msgstr "E475: Неважећа вредност за аргумент %s: %s" #, c-format -msgid "E15: Invalid expression: %s" -msgstr "E15: Неважећи израз: %s" +msgid "E15: Invalid expression: \"%s\"" +msgstr "E15: Неважећи израз: „%s”" msgid "E16: Invalid range" msgstr "E16: Неважећи опсег" |