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.

51 lines
1.8 KiB

  1. # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  2. # Copyright (c) 2018 Sebastian Gniazdowski
  3. #
  4. # Chroma for vim, shows last opened files under prompt.
  5. #
  6. # $1 - 0 or 1, denoting if it's first call to the chroma, or following one
  7. #
  8. # $2 - the current token, also accessible by $__arg from the above scope -
  9. # basically a private copy of $__arg; the token can be eg.: "grep"
  10. #
  11. # $3 - a private copy of $_start_pos, i.e. the position of the token in the
  12. # command line buffer, used to add region_highlight entry (see man),
  13. # because Zsh colorizes by *ranges* in command line buffer
  14. #
  15. # $4 - a private copy of $_end_pos from the above scope
  16. #
  17. (( next_word = 2 | 8192 ))
  18. local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
  19. local __style __chars
  20. integer __idx1 __idx2
  21. local -a __viminfo
  22. # First call, i.e. command starts, i.e. "grep" token etc.
  23. (( __first_call )) && {
  24. (( ${+commands[vim]} )) && __style=${FAST_THEME_NAME}command || __style=${FAST_THEME_NAME}unknown-token
  25. { __viminfo=( ${(f)"$(<$HOME/.viminfo)"} ); } >> /dev/null
  26. __viminfo=( "${${(M)__viminfo[@]:#>*}[@]:t}" )
  27. __viminfo=( "${__viminfo[@]:#COMMIT_EDITMSG}" )
  28. zle -M "Last opened:"$'\n'"${(F)__viminfo[1,5]}"
  29. } || {
  30. # Pass almost everything to big loop
  31. return 1
  32. }
  33. # Add region_highlight entry (via `reply' array).
  34. #
  35. # This is a common place of adding such entry, but any above
  36. # code can do it itself (and it does, see other chromas) and
  37. # skip setting __style to disable this code.
  38. [[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  39. # We aren't passing-through (no return 1 occured), do obligatory things ourselves.
  40. (( this_word = next_word ))
  41. _start_pos=$_end_pos
  42. return 0
  43. # vim:ft=zsh:et:sw=4