Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

134 rindas
4.6 KiB

  1. zsh-syntax-highlighting / highlighters
  2. ======================================
  3. Syntax highlighting is done by pluggable highlighters:
  4. * `main` - the base highlighter, and the only one [active by default][main].
  5. * `brackets` - [matches brackets][brackets] and parenthesis.
  6. * `pattern` - matches [user-defined patterns][pattern].
  7. * `regexp` - matches [user-defined regular expressions][regexp].
  8. * `cursor` - matches [the cursor position][cursor].
  9. * `root` - highlights the whole command line [if the current user is root][root].
  10. * `line` - applied to [the whole command line][line].
  11. [main]: highlighters/main.md
  12. [brackets]: highlighters/brackets.md
  13. [pattern]: highlighters/pattern.md
  14. [regexp]: highlighters/regexp.md
  15. [cursor]: highlighters/cursor.md
  16. [root]: highlighters/root.md
  17. [line]: highlighters/line.md
  18. Highlighter-independent settings
  19. --------------------------------
  20. By default, all command lines are highlighted. However, it is possible to
  21. prevent command lines longer than a fixed number of characters from being
  22. highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum
  23. length (in characters) of command lines to be highlighter. This is useful when
  24. editing very long command lines (for example, with the [`fned`][fned] utility
  25. function). Example:
  26. [fned]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zed
  27. ```zsh
  28. ZSH_HIGHLIGHT_MAXLENGTH=512
  29. ```
  30. How to activate highlighters
  31. ----------------------------
  32. To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in
  33. `~/.zshrc`, for example:
  34. ```zsh
  35. ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
  36. ```
  37. By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main`
  38. highlighter is active.
  39. How to tweak highlighters
  40. -------------------------
  41. Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` associative array.
  42. Navigate into the [individual highlighters' documentation](highlighters/) to
  43. see what styles (keys) each highlighter defines; the syntax for values is the
  44. same as the syntax of "types of highlighting" of the zsh builtin
  45. `$zle_highlight` array, which is documented in [the `zshzle(1)` manual
  46. page][zshzle-Character-Highlighting].
  47. [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
  48. Some highlighters support additional configuration parameters; see each
  49. highlighter's documentation for details and examples.
  50. How to implement a new highlighter
  51. ----------------------------------
  52. To create your own `acme` highlighter:
  53. * Create your script at
  54. `highlighters/acme/acme-highlighter.zsh`.
  55. * Implement the `_zsh_highlight_highlighter_acme_predicate` function.
  56. This function must return 0 when the highlighter needs to be called and
  57. non-zero otherwise, for example:
  58. ```zsh
  59. _zsh_highlight_highlighter_acme_predicate() {
  60. # Call this highlighter in SVN working copies
  61. [[ -d .svn ]]
  62. }
  63. ```
  64. * Implement the `_zsh_highlight_highlighter_acme_paint` function.
  65. This function does the actual syntax highlighting, by calling
  66. `_zsh_highlight_add_highlight` with the start and end of the region to
  67. be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default
  68. style for that key in the highlighter script outside of any function with
  69. `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix
  70. the key with your highlighter name and a colon. For example:
  71. ```zsh
  72. : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green}
  73. _zsh_highlight_highlighter_acme_paint() {
  74. # Colorize the whole buffer with the 'aurora' style
  75. _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora
  76. }
  77. ```
  78. If you need to test which options the user has set, test `zsyh_user_options`
  79. with a sensible default if the option is not present in supported zsh
  80. versions. For example:
  81. ```zsh
  82. [[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]
  83. ```
  84. The option name must be all lowercase with no underscores and not an alias.
  85. * Name your own functions and global variables `_zsh_highlight_acme_*`.
  86. - In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints
  87. `_zsh_highlight_highlighter_acme_predicate` and
  88. `_zsh_highlight_highlighter_acme_paint`
  89. were named
  90. `_zsh_highlight_acme_highlighter_predicate` and
  91. `_zsh_highlight_highlighter_acme_paint` respectively.
  92. These names are still supported for backwards compatibility;
  93. however, support for them will be removed in a future major or minor release (v0.x.0 or v1.0.0).
  94. * Activate your highlighter in `~/.zshrc`:
  95. ```zsh
  96. ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme)
  97. ```
  98. * [Write tests](../tests/README.md).