You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB

  1. # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  2. # Copyright (c) 2018 Sebastian Gniazdowski
  3. #
  4. # This chroma does a narrow, obscure but prestigious parsing of fpath+=( elem1
  5. # elem2 ... ) construct to provide *the* *future* contents of $fpath to
  6. # -autoload.ch, so that it can detect functions in those provided directories
  7. # `elem1', `elem2', etc. and highlight the functions with `correct-subtle'
  8. # instead of `incorrect-subtle'. Basically all thit is for command-lines like:
  9. #
  10. # % fpath+=( `pwd` ); autoload my-fun-from-PWD
  11. # Keep chroma-takever state meaning: until ; or similar (see $__arg_type below)
  12. # The 8192 sum takes care that the next token will be routed to this chroma
  13. (( next_word = 2 | 8192 ))
  14. local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
  15. local -a deserialized
  16. (( __first_call )) && {
  17. case $__wrd in
  18. (fpath=\()
  19. FAST_HIGHLIGHT[fpath_peq_mode]=1
  20. ;;
  21. (fpath+=\()
  22. FAST_HIGHLIGHT[fpath_peq_mode]=2
  23. ;;
  24. (FPATH=)
  25. FAST_HIGHLIGHT[fpath_peq_mode]=4
  26. ;;
  27. (FPATH+=)
  28. FAST_HIGHLIGHT[fpath_peq_mode]=8
  29. ;;
  30. esac
  31. if (( FAST_HIGHLIGHT[fpath_peq_mode] & 5 )); then
  32. FAST_HIGHLIGHT[chroma-fpath_peq-elements]="! ${FAST_HIGHLIGHT[chroma-fpath_peq-elements]}"
  33. fi
  34. return 1
  35. } || {
  36. # Following call, i.e. not the first one
  37. # Check if chroma should end – test if token is of type
  38. # "starts new command", if so pass-through – chroma ends
  39. [[ "$__arg_type" = 3 ]] && return 2
  40. [[ "$__wrd" != ")" ]] && {
  41. deserialized=( "${(Q@)${(z@)FAST_HIGHLIGHT[chroma-fpath_peq-elements]}}" )
  42. [[ -z "${deserialized[1]}" && ${#deserialized} -eq 1 ]] && deserialized=()
  43. # Support ~ and $VAR, for [a-zA-Z_][a-ZA-Z0-9_]# characters in "VAR"
  44. deserialized+=( "${(Q)${${(j: :)__wrd}//(#b)((\$([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#))|(\$\{([0-9]##|[a-zA-Z_][a-zA-Z0-9_]#)\})|(#s)~)/${(P)${${${${match[1]##\$\{(#c0,1)}%\}}:#\~}:-HOME}}}}" )
  45. FAST_HIGHLIGHT[chroma-fpath_peq-elements]="${(j: :)${(q@)deserialized}}"
  46. }
  47. return 1
  48. }
  49. (( this_word = next_word ))
  50. _start_pos=$_end_pos
  51. return 0
  52. # vim:ft=zsh:et:sw=4