diff options
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/buffer.c | 46 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 24 |
2 files changed, 22 insertions, 48 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 9cd178eaeb..3613a8f8bc 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -380,8 +380,6 @@ void nvim_buf_set_lines(uint64_t channel_id, } } - win_T *save_curwin = NULL; - tabpage_T *save_curtab = NULL; size_t new_len = replacement.size; size_t old_len = (size_t)(end - start); ptrdiff_t extra = 0; // lines added to text, can be negative @@ -397,8 +395,8 @@ void nvim_buf_set_lines(uint64_t channel_id, } try_start(); - bufref_T save_curbuf = { NULL, 0, 0 }; - switch_to_win_for_buf(buf, &save_curwin, &save_curtab, &save_curbuf); + aco_save_T aco; + aucmd_prepbuf(&aco, (buf_T *)buf); if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to save undo information"); @@ -465,27 +463,21 @@ void nvim_buf_set_lines(uint64_t channel_id, // changed range, and move any in the remainder of the buffer. // Only adjust marks if we managed to switch to a window that holds // the buffer, otherwise line numbers will be invalid. - if (save_curbuf.br_buf == NULL) { - mark_adjust((linenr_T)start, - (linenr_T)(end - 1), - MAXLNUM, - (long)extra, - false); - } + mark_adjust((linenr_T)start, + (linenr_T)(end - 1), + MAXLNUM, + (long)extra, + false); changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra, true); - if (save_curbuf.br_buf == NULL) { - fix_cursor((linenr_T)start, (linenr_T)end, (linenr_T)extra); - } - end: for (size_t i = 0; i < new_len; i++) { xfree(lines[i]); } xfree(lines); - restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); + aucmd_restbuf(&aco); try_end(err); } @@ -1109,28 +1101,6 @@ free_exit: return 0; } -// Check if deleting lines made the cursor position invalid. -// Changed the lines from "lo" to "hi" and added "extra" lines (negative if -// deleted). -static void fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra) -{ - if (curwin->w_cursor.lnum >= lo) { - // Adjust the cursor position if it's in/after the changed - // lines. - if (curwin->w_cursor.lnum >= hi) { - curwin->w_cursor.lnum += extra; - check_cursor_col(); - } else if (extra < 0) { - curwin->w_cursor.lnum = lo; - check_cursor(); - } else { - check_cursor_col(); - } - changed_cline_bef_curs(); - } - invalidate_botline(); -} - // Normalizes 0-based indexes to buffer line numbers static int64_t normalize_index(buf_T *buf, int64_t index, bool *oob) { diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 94d1697083..a773234ea0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -15,6 +15,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/dispatch.h" #include "nvim/api/buffer.h" +#include "nvim/api/window.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/lua/executor.h" @@ -31,6 +32,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/fileio.h" #include "nvim/option.h" #include "nvim/state.h" #include "nvim/syntax.h" @@ -978,11 +980,12 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err) return 0; } if (scratch) { - WITH_BUFFER(buf, { - set_option_value("bh", 0L, "hide", OPT_LOCAL); - set_option_value("bt", 0L, "nofile", OPT_LOCAL); - set_option_value("swf", 0L, NULL, OPT_LOCAL); - }); + aco_save_T aco; + aucmd_prepbuf(&aco, buf); + set_option_value("bh", 0L, "hide", OPT_LOCAL); + set_option_value("bt", 0L, "nofile", OPT_LOCAL); + set_option_value("swf", 0L, NULL, OPT_LOCAL); + aucmd_restbuf(&aco); } return buf->b_fnum; } @@ -995,6 +998,8 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err) /// GUI with the |ui-multigrid| extension. External windows are only supported /// with multigrid GUIs, and are displayed as separate top-level windows. /// +/// For a general overview of floats, see |api-floatwin|. +/// /// Exactly one of `external` and `relative` must be specified. /// /// @param buffer handle of buffer to be displayed in the window @@ -1047,7 +1052,6 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary options, Error *err) FUNC_API_SINCE(6) { - win_T *old = curwin; FloatConfig config = FLOAT_CONFIG_INIT; if (!parse_float_config(options, &config, false, err)) { return 0; @@ -1056,11 +1060,11 @@ Window nvim_open_win(Buffer buffer, Boolean enter, if (!wp) { return 0; } - if (buffer > 0) { - nvim_set_current_buf(buffer, err); + if (enter) { + win_enter(wp, false); } - if (!enter) { - win_enter(old, false); + if (buffer > 0) { + nvim_win_set_buf(wp->handle, buffer, err); } return wp->handle; } |