aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-01-19 09:55:03 +0000
committerLewis Russell <lewis6991@gmail.com>2023-01-25 11:48:52 +0000
commit632bc7954e3dec0ffed1c0cf90e0d8e32638fa74 (patch)
tree2405ad03f68bf1090163c6331c085a8cb0d2fdd8
parent5ec8bb73c268b8f23fe70374863ba3bafc036b22 (diff)
downloadrneovim-632bc7954e3dec0ffed1c0cf90e0d8e32638fa74.tar.gz
rneovim-632bc7954e3dec0ffed1c0cf90e0d8e32638fa74.tar.bz2
rneovim-632bc7954e3dec0ffed1c0cf90e0d8e32638fa74.zip
refactor(optionstr.c): break up did_set_string_option 6
-rw-r--r--src/nvim/optionstr.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index b1ae2fd409..1877160509 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -727,6 +727,42 @@ static void did_set_background(char **errmsg)
}
}
+// 'encoding', 'fileencoding' and 'makeencoding'
+static void did_set_encoding(buf_T *buf, char **varp, char **gvarp, int opt_flags, char **errmsg)
+{
+ if (gvarp == &p_fenc) {
+ if (!MODIFIABLE(buf) && opt_flags != OPT_GLOBAL) {
+ *errmsg = e_modifiable;
+ return;
+ }
+
+ if (vim_strchr(*varp, ',') != NULL) {
+ // No comma allowed in 'fileencoding'; catches confusing it
+ // with 'fileencodings'.
+ *errmsg = e_invarg;
+ return;
+ }
+
+ // May show a "+" in the title now.
+ redraw_titles();
+ // Add 'fileencoding' to the swap file.
+ ml_setflags(buf);
+ }
+
+ // canonize the value, so that strcmp() can be used on it
+ char *p = enc_canonize(*varp);
+ xfree(*varp);
+ *varp = p;
+ if (varp == &p_enc) {
+ // only encoding=utf-8 allowed
+ if (strcmp(p_enc, "utf-8") != 0) {
+ *errmsg = e_unsupportedoption;
+ return;
+ }
+ spell_reload();
+ }
+}
+
/// Handle string options that need some action to perform when changed.
/// The new value must be allocated.
///
@@ -857,35 +893,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
}
} else if (varp == &p_enc || gvarp == &p_fenc || gvarp == &p_menc) {
// 'encoding', 'fileencoding' and 'makeencoding'
- if (gvarp == &p_fenc) {
- if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) {
- errmsg = e_modifiable;
- } else if (vim_strchr(*varp, ',') != NULL) {
- // No comma allowed in 'fileencoding'; catches confusing it
- // with 'fileencodings'.
- errmsg = e_invarg;
- } else {
- // May show a "+" in the title now.
- redraw_titles();
- // Add 'fileencoding' to the swap file.
- ml_setflags(curbuf);
- }
- }
-
- if (errmsg == NULL) {
- // canonize the value, so that strcmp() can be used on it
- char *p = enc_canonize(*varp);
- xfree(*varp);
- *varp = p;
- if (varp == &p_enc) {
- // only encoding=utf-8 allowed
- if (strcmp(p_enc, "utf-8") != 0) {
- errmsg = e_unsupportedoption;
- } else {
- spell_reload();
- }
- }
- }
+ did_set_encoding(curbuf, varp, gvarp, opt_flags, &errmsg);
} else if (varp == &curbuf->b_p_keymap) {
if (!valid_filetype(*varp)) {
errmsg = e_invarg;