@@ -406,6 +406,7 @@ _zsh_highlight_main_highlighter_highlight_list()
406
406
# - :regular: "Not a command word", and command delimiters are permitted.
407
407
# Mainly used to detect premature termination of commands.
408
408
# - :always: The word 'always' in the «{ foo } always { bar }» syntax.
409
+ # - :function: Function names after 'function' or before '()'
409
410
#
410
411
# When the kind of a word is not yet known, $this_word / $next_word may contain
411
412
# multiple states. For example, after "sudo -i", the next word may be either
@@ -682,8 +683,25 @@ _zsh_highlight_main_highlighter_highlight_list()
682
683
# try-always construct
683
684
style=reserved-word # de facto a reserved word, although not de jure
684
685
next_word=' :start:'
686
+ elif [[ $this_word == * :function:* ]]; then
687
+ if [[ $arg == ' ()' ]]; then
688
+ style=reserved-word
689
+ next_word=' :start:'
690
+ elif [[ $arg == $' \x7b ' ]]; then
691
+ style=reserved-word
692
+ next_word=' :start:'
693
+ braces_stack=' Y' " $braces_stack "
694
+ else
695
+ style=function-definition
696
+ next_word=' :function:'
697
+ fi
685
698
elif [[ $this_word == * ' :start:' * ]]; then # $arg is the command word
686
- if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg ; then
699
+ if [[ $res != reserved && $arg != ' ()' && ( $args [1] == ' ()' ||
700
+ # TODO: Function names can be absurd; this handles the more common cases without invoking Cthulhu.
701
+ ( $zsyh_user_options [multifuncdef] == on && $args [(r)* [^[:alnum:]_-]* ] == ' ()' ) ) ]]; then
702
+ style=function-definition
703
+ next_word=:function:
704
+ elif (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg ; then
687
705
style=precommand
688
706
flags_with_argument=${precommand_options[$arg]%:* }
689
707
flags_sans_argument=${precommand_options[$arg]#*: }
@@ -756,6 +774,10 @@ _zsh_highlight_main_highlighter_highlight_list()
756
774
#
757
775
# The repeat-count word will be handled like a redirection target.
758
776
this_word=' :start::regular:'
777
+ ;;
778
+ (' function' )
779
+ next_word=' :function:'
780
+ ;;
759
781
esac
760
782
;;
761
783
' suffix alias' ) style=suffix-alias;;
@@ -849,16 +871,9 @@ _zsh_highlight_main_highlighter_highlight_list()
849
871
fi
850
872
_zsh_highlight_main__stack_pop ' R' reserved-word
851
873
fi ;;
852
- $' \x28\x29 ' ) # possibly a function definition
853
- if (( in_redirection )) || $in_array_assignment ; then
854
- style=unknown-token
855
- else
856
- if [[ $zsyh_user_options [multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
857
- then
858
- next_word+=' :start:'
859
- fi
860
- style=reserved-word
861
- fi
874
+ ' ()' )
875
+ # Function definition was handled above
876
+ style=unknown-token
862
877
;;
863
878
* ) if false ; then
864
879
elif [[ $arg = $' \x7d ' ]] && $right_brace_is_recognised_everywhere ; then
0 commit comments