patch 9.1.1341: cannot define completion triggers
Problem: Cannot define completion triggers and act upon it
Solution: add the new option 'isexpand' and add the complete_match()
function to return the completion matches according to the
'isexpand' setting (glepnir)
Currently, completion trigger position is determined solely by the
'iskeyword' pattern (\k\+$), which causes issues when users need
different completion behaviors - such as triggering after '/' for
comments or '.' for methods. Modifying 'iskeyword' to include these
characters has undesirable side effects on other Vim functionality that
relies on keyword definitions.
Introduce a new buffer-local option 'isexpand' that allows specifying
different completion triggers and add the complete_match() function that
finds the appropriate start column for completion based on these
triggers, scanning backwards from cursor position.
This separation of concerns allows customized completion behavior
without affecting iskeyword-dependent features. The option's
buffer-local nature enables per-filetype completion triggers.
closes: #16716
Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/option.c b/src/option.c
index cfdeb44..ab9ee66 100644
--- a/src/option.c
+++ b/src/option.c
@@ -6400,6 +6400,9 @@
clear_string_option(&buf->b_p_cot);
buf->b_cot_flags = 0;
break;
+ case PV_ISE:
+ clear_string_option(&buf->b_p_ise);
+ break;
case PV_DICT:
clear_string_option(&buf->b_p_dict);
break;
@@ -6518,6 +6521,7 @@
case PV_INC: return (char_u *)&(curbuf->b_p_inc);
#endif
case PV_COT: return (char_u *)&(curbuf->b_p_cot);
+ case PV_ISE: return (char_u *)&(curbuf->b_p_ise);
case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
#ifdef FEAT_COMPL_FUNC
@@ -6600,6 +6604,8 @@
#endif
case PV_COT: return *curbuf->b_p_cot != NUL
? (char_u *)&(curbuf->b_p_cot) : p->var;
+ case PV_ISE: return *curbuf->b_p_ise != NUL
+ ? (char_u *)&(curbuf->b_p_ise) : p->var;
case PV_DICT: return *curbuf->b_p_dict != NUL
? (char_u *)&(curbuf->b_p_dict) : p->var;
case PV_TSR: return *curbuf->b_p_tsr != NUL
@@ -7431,6 +7437,7 @@
buf->b_cot_flags = 0;
buf->b_p_dict = empty_option;
buf->b_p_tsr = empty_option;
+ buf->b_p_ise = empty_option;
#ifdef FEAT_COMPL_FUNC
buf->b_p_tsrfu = empty_option;
#endif