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.

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