3636 semantic_prompt:: { Osc133ClickEventsMarkers , SemanticPromptMarkers } ,
3737 } ,
3838 utils:: text_manipulation,
39- EditCommand , ExampleHighlighter , Highlighter , LineBuffer , Menu , MenuEvent , MouseButton ,
40- Prompt , PromptHistorySearch , ReedlineMenu , Signal , UndoBehavior , ValidationResult ,
41- Validator ,
39+ AbbrExpandContext , EditCommand , ExampleHighlighter , Highlighter , LineBuffer , Menu ,
40+ MenuEvent , MouseButton , Prompt , PromptHistorySearch , ReedlineMenu , Signal , UndoBehavior ,
41+ ValidationResult , Validator ,
4242 } ,
4343 crossterm:: {
4444 cursor:: { SetCursorStyle , Show } ,
@@ -626,8 +626,8 @@ impl Reedline {
626626 ///
627627 /// Overwrites any existing abbreviations with the same key.
628628 ///
629- /// Note, by default abbreviations are expanded within string literals . To change this behavior
630- /// override the `is_inside_string_literal` function defined by [`Highlighter`].
629+ /// Note, by default abbreviations are expanded everywhere . To suppress expansion in certain
630+ /// syntactic positions (e.g. string literals), override [`Highlighter::should_expand_abbr `].
631631 pub fn with_abbreviations ( mut self , abbreviations : HashMap < String , String > ) -> Self {
632632 self . abbreviations . extend ( abbreviations) ;
633633 self
@@ -1758,10 +1758,8 @@ impl Reedline {
17581758
17591759 /// Expands an abbreviation at the word before the cursor, if any exists
17601760 ///
1761- /// Note, this method uses the `is_inside_string_literal` function defined by [`Highlighter`]
1762- /// to decide whether to expand an abbreviation when the cursor is inside a string literal.
1763- /// Unless overridden, `is_inside_string_literal` returns `false`, resulting in abbreviations
1764- /// being expanded even when inside a string literal.
1761+ /// Calls [`Highlighter::should_expand_abbr`] with [`AbbrExpandContext::WordAbbreviation`]
1762+ /// to decide whether expansion is permitted at the cursor position
17651763 fn try_expand_abbreviation_at_cursor ( & mut self , submitted : bool ) -> Option < ReedlineEvent > {
17661764 let buffer = self . editor . get_buffer ( ) ;
17671765 let cursor_position_in_buffer = self . editor . insertion_point ( ) ;
@@ -1787,10 +1785,11 @@ impl Reedline {
17871785 // The first char in the buffer is a space or there are consecutive spaces
17881786 return None ;
17891787 }
1790- if self
1791- . highlighter
1792- . is_inside_string_literal ( buffer, word_start)
1793- {
1788+ if !self . highlighter . should_expand_abbr (
1789+ buffer,
1790+ word_start,
1791+ AbbrExpandContext :: WordAbbreviation ,
1792+ ) {
17941793 return None ;
17951794 }
17961795
@@ -1826,10 +1825,11 @@ impl Reedline {
18261825 }
18271826 }
18281827
1829- if self
1830- . highlighter
1831- . is_inside_string_literal ( buffer, parsed. remainder . len ( ) )
1832- {
1828+ if !self . highlighter . should_expand_abbr (
1829+ buffer,
1830+ parsed. remainder . len ( ) ,
1831+ AbbrExpandContext :: BangExpansion ,
1832+ ) {
18331833 return None ;
18341834 }
18351835
@@ -2564,7 +2564,7 @@ mod tests {
25642564 set_buffer_at_end ( & mut reedline, buffer) ;
25652565 assert ! (
25662566 reedline. try_expand_abbreviation_at_cursor( true ) . is_some( ) ,
2567- "must expand when highlighter does not override is_inside_string_literal "
2567+ "must expand when highlighter does not override should_expand_abbr "
25682568 ) ;
25692569 }
25702570
@@ -2648,7 +2648,7 @@ mod tests {
26482648 set_buffer_at_end ( & mut reedline, buffer) ;
26492649 assert ! (
26502650 reedline. parse_bang_command( ) . is_some( ) ,
2651- "must expand when highlighter does not override is_inside_string_literal "
2651+ "must expand when highlighter does not override should_expand_abbr "
26522652 ) ;
26532653 }
26542654}
0 commit comments