aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-01-19 09:55:50 +0000
committerLewis Russell <lewis6991@gmail.com>2023-01-25 11:48:52 +0000
commita22702b5d551a5be0e656282e168f3ba2efeb552 (patch)
tree91ed33acf7e354356eb8c25213acda6594bdad5d
parent632bc7954e3dec0ffed1c0cf90e0d8e32638fa74 (diff)
downloadrneovim-a22702b5d551a5be0e656282e168f3ba2efeb552.tar.gz
rneovim-a22702b5d551a5be0e656282e168f3ba2efeb552.tar.bz2
rneovim-a22702b5d551a5be0e656282e168f3ba2efeb552.zip
refactor(optionstr.c): break up did_set_string_option 7
-rw-r--r--src/nvim/edit.c2
-rw-r--r--src/nvim/ex_getln.c4
-rw-r--r--src/nvim/option.c8
-rw-r--r--src/nvim/optionstr.c89
4 files changed, 55 insertions, 48 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 32c035b028..095d73f53f 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -3474,7 +3474,7 @@ static void ins_ctrl_hat(void)
State |= MODE_LANGMAP;
}
}
- set_iminsert_global();
+ set_iminsert_global(curbuf);
showmode();
// Show/unshow value of 'keymap' in status lines.
status_redraw_curbuf();
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index c62142310d..76c3680742 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1557,9 +1557,9 @@ static void command_line_toggle_langmap(CommandLineState *s)
if (s->b_im_ptr != NULL) {
if (s->b_im_ptr == &curbuf->b_p_iminsert) {
- set_iminsert_global();
+ set_iminsert_global(curbuf);
} else {
- set_imsearch_global();
+ set_imsearch_global(curbuf);
}
}
ui_cursor_shape(); // may show different cursor shape
diff --git a/src/nvim/option.c b/src/nvim/option.c
index a2be81d6bc..f5b172f4e0 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -4508,15 +4508,15 @@ void reset_modifiable(void)
}
/// Set the global value for 'iminsert' to the local value.
-void set_iminsert_global(void)
+void set_iminsert_global(buf_T *buf)
{
- p_iminsert = curbuf->b_p_iminsert;
+ p_iminsert = buf->b_p_iminsert;
}
/// Set the global value for 'imsearch' to the local value.
-void set_imsearch_global(void)
+void set_imsearch_global(buf_T *buf)
{
- p_imsearch = curbuf->b_p_imsearch;
+ p_imsearch = buf->b_p_imsearch;
}
static int expand_option_idx = -1;
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index 1877160509..b8b098d826 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -763,6 +763,53 @@ static void did_set_encoding(buf_T *buf, char **varp, char **gvarp, int opt_flag
}
}
+static void did_set_keymap(buf_T *buf, char **varp, int opt_flags, int *value_checked,
+ char **errmsg)
+{
+ if (!valid_filetype(*varp)) {
+ *errmsg = e_invarg;
+ return;
+ }
+
+ int secure_save = secure;
+
+ // Reset the secure flag, since the value of 'keymap' has
+ // been checked to be safe.
+ secure = 0;
+
+ // load or unload key mapping tables
+ *errmsg = keymap_init();
+
+ secure = secure_save;
+
+ // Since we check the value, there is no need to set P_INSECURE,
+ // even when the value comes from a modeline.
+ *value_checked = true;
+
+ if (*errmsg == NULL) {
+ if (*buf->b_p_keymap != NUL) {
+ // Installed a new keymap, switch on using it.
+ buf->b_p_iminsert = B_IMODE_LMAP;
+ if (buf->b_p_imsearch != B_IMODE_USE_INSERT) {
+ buf->b_p_imsearch = B_IMODE_LMAP;
+ }
+ } else {
+ // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
+ if (buf->b_p_iminsert == B_IMODE_LMAP) {
+ buf->b_p_iminsert = B_IMODE_NONE;
+ }
+ if (buf->b_p_imsearch == B_IMODE_LMAP) {
+ buf->b_p_imsearch = B_IMODE_USE_INSERT;
+ }
+ }
+ if ((opt_flags & OPT_LOCAL) == 0) {
+ set_iminsert_global(buf);
+ set_imsearch_global(buf);
+ }
+ status_redraw_buf(buf);
+ }
+}
+
/// Handle string options that need some action to perform when changed.
/// The new value must be allocated.
///
@@ -895,47 +942,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
// 'encoding', 'fileencoding' and 'makeencoding'
did_set_encoding(curbuf, varp, gvarp, opt_flags, &errmsg);
} else if (varp == &curbuf->b_p_keymap) {
- if (!valid_filetype(*varp)) {
- errmsg = e_invarg;
- } else {
- int secure_save = secure;
-
- // Reset the secure flag, since the value of 'keymap' has
- // been checked to be safe.
- secure = 0;
-
- // load or unload key mapping tables
- errmsg = keymap_init();
-
- secure = secure_save;
-
- // Since we check the value, there is no need to set P_INSECURE,
- // even when the value comes from a modeline.
- *value_checked = true;
- }
-
- if (errmsg == NULL) {
- if (*curbuf->b_p_keymap != NUL) {
- // Installed a new keymap, switch on using it.
- curbuf->b_p_iminsert = B_IMODE_LMAP;
- if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT) {
- curbuf->b_p_imsearch = B_IMODE_LMAP;
- }
- } else {
- // Cleared the keymap, may reset 'iminsert' and 'imsearch'.
- if (curbuf->b_p_iminsert == B_IMODE_LMAP) {
- curbuf->b_p_iminsert = B_IMODE_NONE;
- }
- if (curbuf->b_p_imsearch == B_IMODE_LMAP) {
- curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
- }
- }
- if ((opt_flags & OPT_LOCAL) == 0) {
- set_iminsert_global();
- set_imsearch_global();
- }
- status_redraw_curbuf();
- }
+ did_set_keymap(curbuf, varp, opt_flags, value_checked, &errmsg);
} else if (gvarp == &p_ff) { // 'fileformat'
if (!MODIFIABLE(curbuf) && !(opt_flags & OPT_GLOBAL)) {
errmsg = e_modifiable;