From 6441f892edceb368e5cbf76f2ead9b11ac79e00c Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Tue, 20 Oct 2026 16:38:11 -0700 Subject: [PATCH] Refactor to avoid future Vim merge conflicts Change how different parts of the MacVim-specific code are added on top of Vim in order to reduce repetitive merge conflicts when sycing from upstream. This should hopefully help reduce churn. The main strategy is to move declarations to the top rather than at the end, which is frequently touched by Vim upstream. We also want to avoid having to manually re-calculate index numbers which is error-prone. For keymap.h, we now allocates a fixed offset (210) to the MacVim-specific keys like trackpad gesture swipes. Previously we always re-calculated the numeric values of these keys every time upstream added more keys, but it made the value of "\" inconsistent which is not supposed to be how key values work. Now, we should have a stable value for them that would persist. The value is large enough that there should be very little chance for upstream Vim to add enough keys to cause a conflict. --- src/evalvars.c | 10 +++++++--- src/keymap.h | 19 ++++++++++++------- src/proto/evalfunc.pro | 11 +++++------ src/proto/gui_xim.pro | 16 ++++++++-------- src/proto/mouse.pro | 7 +++---- src/proto/normal.pro | 7 +++---- src/proto/option.pro | 19 +++++++++---------- src/proto/optionstr.pro | 11 +++++------ src/proto/os_macosx.pro | 6 +++--- src/vim.h | 8 ++++++-- 10 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/evalvars.c b/src/evalvars.c index 331601d736..5c38008ea4 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -49,8 +49,14 @@ static struct vimvar char vv_flags; // VV_COMPAT, VV_RO, VV_RO_SBX } vimvars[VV_LEN] = { + // MacVim-specific value go here + // We put this at the beginning using C99 designated initializers to + // reduce merge conflicts. + [VV_OS_APPEARANCE] = {VV_NAME("os_appearance", VAR_NUMBER), NULL, VV_RO}, + // The order here must match the VV_ defines in vim.h! // Initializing a union does not work, leave tv.vval empty to get zero's. + [0] = {VV_NAME("count", VAR_NUMBER), NULL, VV_COMPAT+VV_RO}, {VV_NAME("count1", VAR_NUMBER), NULL, VV_RO}, {VV_NAME("prevcount", VAR_NUMBER), NULL, VV_RO}, @@ -169,9 +175,7 @@ static struct vimvar {VV_NAME("termosc", VAR_STRING), NULL, VV_RO}, {VV_NAME("vim_did_init", VAR_NUMBER), NULL, VV_RO}, {VV_NAME("clipproviders", VAR_DICT), NULL, VV_RO}, - {VV_NAME("imagebackend", VAR_STRING), NULL, VV_RO}, - // MacVim-specific value go here - {VV_NAME("os_appearance", VAR_NUMBER), NULL, VV_RO}, + {VV_NAME("imagebackend", VAR_STRING), NULL, VV_RO} }; // shorthand diff --git a/src/keymap.h b/src/keymap.h index 1b326afc74..74168a7e7e 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -150,6 +150,18 @@ */ enum key_extra { + // MacVim-specific changes + // We put this at the beginning to reduce merge conflicts. The values + // starting at 210 should be large enough to avoid any overlap with regular + // Vim keys, while giving a stable values for these over different builds. +#ifdef FEAT_GUI_MACVIM + KE_SWIPELEFT = 210, // Swipe trackpad left + KE_SWIPERIGHT, // Swipe trackpad right + KE_SWIPEUP, // Swipe trackpad up + KE_SWIPEDOWN, // Swipe trackpad down + KE_FORCECLICK, // Force click on trackpad +#endif + KE_S_UP = 4 // shift-up , KE_S_DOWN = 5 // shift-down @@ -282,13 +294,6 @@ enum key_extra , KE_WILD = 108 // triggers wildmode completion , KE_OSC = 109 // finished OSC sequence , KE_COMPLETE_DELAY = 110 // 'autocompletedelay' expired -#ifdef FEAT_GUI_MACVIM - , KE_SWIPELEFT = 111 // Swipe trackpad left - , KE_SWIPERIGHT = 112 // Swipe trackpad right - , KE_SWIPEUP = 113 // Swipe trackpad up - , KE_SWIPEDOWN = 114 // Swipe trackpad down - , KE_FORCECLICK = 115 // Force click on trackpad -#endif }; /* diff --git a/src/proto/evalfunc.pro b/src/proto/evalfunc.pro index 9042316819..d902266db4 100644 --- a/src/proto/evalfunc.pro +++ b/src/proto/evalfunc.pro @@ -1,3 +1,8 @@ +// MacVim only +void f_getcurpos(typval_T *argvars, typval_T *rettv); +void f_getpos(typval_T *argvars, typval_T *rettv); +void f_getregion(typval_T *argvars, typval_T *rettv); + // evalfunc.c int arg_type_modifiable(type_T *type, int arg_idx); char_u *get_function_name(expand_T *xp, int idx); @@ -29,10 +34,4 @@ void mzscheme_call_vim(char_u *name, typval_T *args, typval_T *rettv); void range_list_materialize(list_T *list); long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long time_limit); int get_yank_type(char_u **pp, char_u *yank_type, long *block_len); - -// MacVim only -void f_getcurpos(typval_T *argvars, typval_T *rettv); -void f_getpos(typval_T *argvars, typval_T *rettv); -void f_getregion(typval_T *argvars, typval_T *rettv); - // vim: ft=c diff --git a/src/proto/gui_xim.pro b/src/proto/gui_xim.pro index 57d8441140..34470dcc1f 100644 --- a/src/proto/gui_xim.pro +++ b/src/proto/gui_xim.pro @@ -1,3 +1,11 @@ +// MacVim +void call_imactivatefunc(int active); +int call_imstatusfunc(void); +void im_preedit_start_macvim(void); +void im_preedit_end_macvim(void); +void im_preedit_abandon_macvim(void); +void im_preedit_changed_macvim(char *preedit_string, int cursor_index); + // gui_xim.c char *did_set_imactivatefunc(optset_T *args); char *did_set_imstatusfunc(optset_T *args); @@ -18,12 +26,4 @@ int preedit_get_status(void); int im_is_preediting(void); void xim_set_status_area(void); int xim_get_status_area_height(void); - -// MacVim -void call_imactivatefunc(int active); -int call_imstatusfunc(void); -void im_preedit_start_macvim(void); -void im_preedit_end_macvim(void); -void im_preedit_abandon_macvim(void); -void im_preedit_changed_macvim(char *preedit_string, int cursor_index); // vim: ft=c diff --git a/src/proto/mouse.pro b/src/proto/mouse.pro index 50b8bdcd8b..98f9dd7dd8 100644 --- a/src/proto/mouse.pro +++ b/src/proto/mouse.pro @@ -1,3 +1,6 @@ +// MacVim-only +int get_fpos_of_mouse(pos_T *mpos); + // mouse.c void mouse_set_vert_scroll_step(long step); void mouse_set_hor_scroll_step(long step); @@ -24,8 +27,4 @@ int mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump, int *pline win_T *mouse_find_win(int *rowp, int *colp, mouse_find_T popup); int vcol2col(win_T *wp, linenr_T lnum, int vcol, colnr_T *coladdp); void f_getmousepos(typval_T *argvars, typval_T *rettv); - -// MacVim-only -int get_fpos_of_mouse(pos_T *mpos); - // vim: ft=c diff --git a/src/proto/normal.pro b/src/proto/normal.pro index c1f2b700b3..91cc7a5535 100644 --- a/src/proto/normal.pro +++ b/src/proto/normal.pro @@ -1,3 +1,6 @@ +// MacVim only +void nv_put(cmdarg_T *cap); + // normal.c int check_text_or_curbuf_locked(oparg_T *oap); void normal_cmd(oparg_T *oap, int toplevel); @@ -34,8 +37,4 @@ void nv_g_home_m_cmd(cmdarg_T *cap); int unadjust_for_sel(void); int unadjust_for_sel_inner(pos_T *pp); void set_cursor_for_append_to_line(void); - -// MacVim only -void nv_put(cmdarg_T *cap); - // vim: ft=c diff --git a/src/proto/option.pro b/src/proto/option.pro index 1ae8b27e95..e458e29dd6 100644 --- a/src/proto/option.pro +++ b/src/proto/option.pro @@ -1,3 +1,12 @@ +// MacVim options +char *did_set_antialias(optset_T *args); +char *did_set_blur(optset_T *args); +char *did_set_columnspace(optset_T *args); +char *did_set_fullscreen(optset_T *args); +char *did_set_macligatures(optset_T *args); +char *did_set_macthinstrokes(optset_T *args); +char *did_set_transparency(optset_T *args); + // option.c void set_init_1(int clean_arg); void set_fencs_unicode(void); @@ -95,16 +104,6 @@ char *did_set_wlsteal(optset_T *args); char *did_set_wltimeoutlen(optset_T *args); char *did_set_wrap(optset_T *args); char *did_set_xhistory(optset_T *args); - -// MacVim options -char *did_set_antialias(optset_T *args); -char *did_set_blur(optset_T *args); -char *did_set_columnspace(optset_T *args); -char *did_set_fullscreen(optset_T *args); -char *did_set_macligatures(optset_T *args); -char *did_set_macthinstrokes(optset_T *args); -char *did_set_transparency(optset_T *args); - void check_redraw(long_u flags); int findoption(char_u *arg); getoption_T get_option_value(char_u *name, long *numval, char_u **stringval, int *flagsp, int scope); diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro index 74c3d03780..f9b7a834da 100644 --- a/src/proto/optionstr.pro +++ b/src/proto/optionstr.pro @@ -1,3 +1,8 @@ +// MacVim options +char *did_set_fuoptions(optset_T *args); +int expand_set_fuoptions(optexpand_T *args, int *numMatches, char_u ***matches); +int check_fuoptions(void); + // optionstr.c void didset_string_options(void); void trigger_optionset_string(int opt_idx, int opt_flags, char_u *oldval, char_u *oldval_l, char_u *oldval_g, char_u *newval); @@ -222,10 +227,4 @@ int check_ff_value(char_u *p); void save_clear_shm_value(void); void restore_shm_value(void); void export_myvimdir(void); - -// MacVim options -char *did_set_fuoptions(optset_T *args); -int expand_set_fuoptions(optexpand_T *args, int *numMatches, char_u ***matches); -int check_fuoptions(void); - // vim: ft=c diff --git a/src/proto/os_macosx.pro b/src/proto/os_macosx.pro index db7ed611bd..47feca516f 100644 --- a/src/proto/os_macosx.pro +++ b/src/proto/os_macosx.pro @@ -1,10 +1,10 @@ +// MacVim +void macosx_fork(void); + // manually generated from os_macosx.m void process_cfrunloop(void); bool sound_mch_play(const char_u* event, long sound_id, soundcb_T *callback, bool playfile); void sound_mch_stop(long sound_id); void sound_mch_clear(void); void sound_mch_free(void); - -// MacVim -void macosx_fork(void); // vim: ft=c diff --git a/src/vim.h b/src/vim.h index 14093802c0..e954aa2ccf 100644 --- a/src/vim.h +++ b/src/vim.h @@ -2280,9 +2280,13 @@ typedef int sock_T; #define VV_VIM_DID_INIT 116 #define VV_CLIPPROVIDERS 117 #define VV_IMAGEBACKEND 118 +#define VV_LEN 119 // number of v: vars + // MacVim-specific values go here -#define VV_OS_APPEARANCE 119 -#define VV_LEN 120 // number of v: vars +enum { VV_VIM_UPSTREAM_LEN = VV_LEN }; +#define VV_OS_APPEARANCE VV_VIM_UPSTREAM_LEN +#undef VV_LEN +#define VV_LEN VV_VIM_UPSTREAM_LEN + 1 // used for v_number in VAR_BOOL and VAR_SPECIAL #define VVAL_FALSE 0L // VAR_BOOL