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