From b79ed66e4a21d52f5870bb01f5145756bbbbf981 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 17 Jul 2025 22:19:00 -0400 Subject: [PATCH] vim-patch:8.1.1736: viminfo support is spread out Problem: Viminfo support is spread out. Solution: Move more viminfo code to viminfo.c. (Yegappan Lakshmanan, closes vim/vim#4717) Reorder code to make most functions static. https://github.com/vim/vim/commit/c3328169d5566b97a6a6921067017e4369dd7cd6 735aa4c4c89943b26f1d6ba0d3e076002490c09d was the partial port for the typedefs. This patch completes the viminfo->shada port. - get_shada_parameter() - find_shada_parameter() Other patches below are N/A. vim-patch:8.1.1728: wrong place for command line history viminfo support Problem: Wrong place for command line history viminfo support. Solution: Move it to viminfo.c. https://github.com/vim/vim/commit/5f32ece459d1f310b1b48b72e07dcd77d3261a76 vim-patch:8.1.1730: wrong place for mark viminfo support Problem: Wrong place for mark viminfo support. Solution: Move it to viminfo.c. (Yegappan Lakshmanan, closes vim/vim#4716) https://github.com/vim/vim/commit/1e78e69680a5f52970d9b1ef60710e556b09b8c2 Co-authored-by: Bram Moolenaar --- src/nvim/fileio.c | 14 ------------- src/nvim/option.c | 34 ------------------------------- src/nvim/optionstr.c | 1 + src/nvim/shada.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index c40371d4cf..61320945d4 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2049,20 +2049,6 @@ static char *readfile_charconvert(char *fname, char *fenc, int *fdp) return tmpname; } -/// Read marks for the current buffer from the ShaDa file, when we support -/// buffer marks and the buffer has a name. -static void check_marks_read(void) -{ - if (!curbuf->b_marks_read && get_shada_parameter('\'') > 0 - && curbuf->b_ffname != NULL) { - shada_read_marks(); - } - - // Always set b_marks_read; needed when 'shada' is changed to include - // the ' parameter after opening a buffer. - curbuf->b_marks_read = true; -} - /// Set the name of the current buffer. Use when the buffer doesn't have a /// name and a ":r" or ":w" command with a file name is used. int set_rw_fname(char *fname, char *sfname) diff --git a/src/nvim/option.c b/src/nvim/option.c index cbcb18fc4a..9f51d28b33 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1537,40 +1537,6 @@ void set_options_bin(int oldval, int newval, int opt_flags) didset_options_sctx(opt_flags, p_bin_dep_opts); } -/// Find the parameter represented by the given character (eg ', :, ", or /), -/// and return its associated value in the 'shada' string. -/// Only works for number parameters, not for 'r' or 'n'. -/// If the parameter is not specified in the string or there is no following -/// number, return -1. -int get_shada_parameter(int type) -{ - char *p = find_shada_parameter(type); - if (p != NULL && ascii_isdigit(*p)) { - return atoi(p); - } - return -1; -} - -/// Find the parameter represented by the given character (eg ''', ':', '"', or -/// '/') in the 'shada' option and return a pointer to the string after it. -/// Return NULL if the parameter is not specified in the string. -char *find_shada_parameter(int type) -{ - for (char *p = p_shada; *p; p++) { - if (*p == type) { - return p + 1; - } - if (*p == 'n') { // 'n' is always the last one - break; - } - p = vim_strchr(p, ','); // skip until next ',' - if (p == NULL) { // hit the end without finding parameter - break; - } - } - return NULL; -} - /// Expand environment variables for some string options. /// These string options cannot be indirect! /// If "val" is NULL expand the current value of the option. diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 9fb54ba03f..0144a227e1 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -43,6 +43,7 @@ #include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/regexp_defs.h" +#include "nvim/shada.h" #include "nvim/spell.h" #include "nvim/spellfile.h" #include "nvim/spellsuggest.h" diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 55a482d4f9..a9bda0100a 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -3772,3 +3772,51 @@ void shada_read_string(String string, const int flags) shada_read(&sd_reader, flags); close_file(&sd_reader); } + +/// Find the parameter represented by the given character (eg ', :, ", or /), +/// and return its associated value in the 'shada' string. +/// Only works for number parameters, not for 'r' or 'n'. +/// If the parameter is not specified in the string or there is no following +/// number, return -1. +int get_shada_parameter(int type) +{ + char *p = find_shada_parameter(type); + if (p != NULL && ascii_isdigit(*p)) { + return atoi(p); + } + return -1; +} + +/// Find the parameter represented by the given character (eg ''', ':', '"', or +/// '/') in the 'shada' option and return a pointer to the string after it. +/// Return NULL if the parameter is not specified in the string. +char *find_shada_parameter(int type) +{ + for (char *p = p_shada; *p; p++) { + if (*p == type) { + return p + 1; + } + if (*p == 'n') { // 'n' is always the last one + break; + } + p = vim_strchr(p, ','); // skip until next ',' + if (p == NULL) { // hit the end without finding parameter + break; + } + } + return NULL; +} + +/// Read marks for the current buffer from the ShaDa file, when we support +/// buffer marks and the buffer has a name. +void check_marks_read(void) +{ + if (!curbuf->b_marks_read && get_shada_parameter('\'') > 0 + && curbuf->b_ffname != NULL) { + shada_read_marks(); + } + + // Always set b_marks_read; needed when 'shada' is changed to include + // the ' parameter after opening a buffer. + curbuf->b_marks_read = true; +}