Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

75 righe
2.2 KiB

  1. Hacking on zsh-syntax-highlighting itself
  2. =========================================
  3. This document includes information for people working on z-sy-h itself: on the
  4. core driver (`zsh-syntax-highlighting.zsh`), on the highlighters in the
  5. distribution, and on the test suite. It does not target third-party
  6. highlighter authors (although they may find it an interesting read).
  7. The `main` highlighter
  8. ----------------------
  9. The following function `pz` is useful when working on the `main` highlighting:
  10. pq() {
  11. (( $#argv )) || return 0
  12. print -r -l -- ${(qqqq)argv}
  13. }
  14. pz() {
  15. local arg
  16. for arg; do
  17. pq ${(z)arg}
  18. done
  19. }
  20. It prints, for each argument, its token breakdown, similar to how the main
  21. loop of the `main` highlighter sees it.
  22. Testing the `brackets` highlighter
  23. ----------------------------------
  24. Since the test harness empties `ZSH_HIGHLIGHT_STYLES` and the `brackets`
  25. highlighter interrogates `ZSH_HIGHLIGHT_STYLES` to determine how to highlight,
  26. tests must set the `bracket-level-#` keys themselves. For example:
  27. ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
  28. ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
  29. BUFFER='echo ({x})'
  30. expected_region_highlight=(
  31. "6 6 bracket-level-1" # (
  32. "7 7 bracket-level-2" # {
  33. "9 9 bracket-level-2" # }
  34. "10 10 bracket-level-1" # )
  35. )
  36. Testing the `pattern` and `regexp` highlighters
  37. -----------------------------------------------
  38. Because the `pattern` and `regexp` highlighters modifies `region_highlight`
  39. directly instead of using `_zsh_highlight_add_highlight`, the test harness
  40. cannot get the `ZSH_HIGHLIGHT_STYLES` keys. Therefore, when writing tests, use
  41. the style itself as third word (cf. the
  42. [documentation for `expected_region_highlight`](docs/highlighters.md)). For example:
  43. ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
  44. BUFFER='rm -rf /'
  45. expected_region_highlight=(
  46. "1 8 fg=white,bold,bg=red" # rm -rf /
  47. )
  48. Miscellany
  49. ----------
  50. If you work on the driver (`zsh-syntax-highlighting.zsh`), you may find the following zstyle useful:
  51. zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-highlighting.plugin.zsh
  52. IRC channel
  53. -----------
  54. We're on #zsh-syntax-highlighting on freenode.