225 Commits
0.4.0 ... 0.5.x

Author SHA1 Message Date
Daniel Shahaf
eb67c0b84f Post-release version number bump. 2016-10-24 11:32:54 +00:00
Daniel Shahaf
15d4587514 Tag version 0.5.0. 2016-10-24 11:32:54 +00:00
Daniel Shahaf
e5a59f6b56 changelog: Update for post-branch changes. 2016-10-24 11:32:54 +00:00
Daniel Shahaf
b4d882dd59 Merge remote-tracking branch 'upstream/master' into 0.5.x
* upstream/master:
  Follow-up to 28d7056a7a: Fix test expectations.
2016-10-22 19:46:46 +00:00
Daniel Shahaf
035d3eb095 Follow-up to 28d7056a7a: Fix test expectations. 2016-10-22 17:46:42 +00:00
Daniel Shahaf
2e95ffc08f Merge remote-tracking branch 'upstream/master' into 0.5.x
* upstream/master:
  README: Set alt="" attributes.
  README: Add a third image.
  README: Add another image.
  README: Use a more minimal example iamge.
  README: Add before/after images
  changelog: Update through 28d7056a7a.
  'main': Escape '!' within double-quoted strings.
  [REVERTED] Post-branch version number bump.
    This reverts commit 1bdb88aee1.
2016-10-22 17:43:05 +00:00
Daniel Shahaf
b7e277106b README: Set alt="" attributes. 2016-10-20 01:04:41 +00:00
Daniel Shahaf
1495195eb5 README: Add a third image.
Also remove the existing image, thereby removing the filename expansion
example and the file-existence highlighting example.
2016-10-20 01:02:27 +00:00
Daniel Shahaf
50cbdbaebc README: Add another image. 2016-10-20 00:46:22 +00:00
Daniel Shahaf
242481c279 README: Use a more minimal example iamge. 2016-10-20 00:15:31 +00:00
Daniel Shahaf
cd9ec14a65 README: Add before/after images 2016-10-20 00:03:09 +00:00
Daniel Shahaf
24096c2e4f changelog: Update through 28d7056a7a. 2016-10-20 00:00:58 +00:00
Daniel Shahaf
28d7056a7a 'main': Escape '!' within double-quoted strings. 2016-10-19 23:56:25 +00:00
Daniel Shahaf
1bdb88aee1 Post-branch version number bump. 2016-10-19 23:08:18 +00:00
Daniel Shahaf
5dcf0cecd8 driver: Revert changes that depend on not-yet-released zsh features.
The $ISEARCHMATCH_ACTIVE and $SUFFIX_ACTIVE have not yet appeared in a zsh release.
2016-10-19 23:03:44 +00:00
Daniel Shahaf
31250c77bf Revert "apply suffix and isearch zle_highlights on top"
This reverts commit 79e4d3d124.
2016-10-19 23:03:19 +00:00
Daniel Shahaf
39ab1b7321 Revert "driver: Track rename of an unreleased upstream API."
This reverts commit 15db71abd0.
2016-10-19 23:03:19 +00:00
Daniel Shahaf
af0099465f Revert "driver: Enable highlighting during isearch under zsh≥5.3."
This reverts commit 4ad311ec0a.
2016-10-19 23:03:16 +00:00
Daniel Shahaf
d464d3857f changelog: Write arg0 entry. 2016-10-19 09:10:24 +00:00
Daniel Shahaf
f5c44ed7a2 changelog: Markup tweak. 2016-10-18 23:59:32 +00:00
Daniel Shahaf
2335986a39 changelog: Add the last few entries. One remains as a TODO. 2016-10-18 23:54:52 +00:00
Daniel Shahaf
e060a0a1c8 release.md: Record the specific command I used. 2016-10-18 22:53:17 +00:00
Daniel Shahaf
f3d0e141fd changelog: Review. 2016-10-18 22:53:17 +00:00
Daniel Shahaf
3c90a673f6 changelog: Update through 0020f592c1. 2016-10-18 22:53:17 +00:00
Daniel Shahaf
773d60c833 changelog: Update through d37c55c788. 2016-10-18 22:53:17 +00:00
Daniel Shahaf
2dff6e54ed changelog: Copyedit.
- Move an entry to another section.
- Fix commit hash width.
- Add missing punctuation.
2016-10-18 22:52:36 +00:00
Daniel Shahaf
0020f592c1 changelog: Update through cef49752fd. 2016-10-18 02:28:40 +00:00
Daniel Shahaf
56e4c38ab4 changelog: Start 0.5.0 section. Update through bc7f8ea433. 2016-10-18 02:28:39 +00:00
Daniel Shahaf
7d38d07255 'main': Followup to fdaeec4514: Update comment.
That revision was itself a followup to 51614ca2c9.
2016-10-17 20:46:46 +00:00
Daniel Shahaf
094329eb14 'main': Introduce style fallback for the command word.
Fixes #316.

* danielsh/i316-v2:
  'main': Enable fallback to the 'arg0' style.
  'main': Set fallback style for the 'arg0' style.
2016-09-28 13:25:05 +00:00
Daniel Shahaf
bccc3dc269 'main': Enable fallback to the 'arg0' style. 2016-09-28 13:22:29 +00:00
Daniel Shahaf
b4537a972e 'main': Set fallback style for the 'arg0' style.
The fallback style name uses '_' in anticipation of a future auto-fallback
feature keyed on style names.

'arg0' was previously known as 'commandtypefromthefuture'.
2016-09-28 13:22:09 +00:00
Daniel Shahaf
2b303f01b6 dev tools: Automagically handle newlines (\n) in $BUFFER. 2016-09-27 22:55:16 +00:00
Daniel Shahaf
79198759b3 tests: Also test arguments to an anonymous function. 2016-09-25 18:08:45 +00:00
Daniel Shahaf
dd51b7bebe Merge remote-tracking branch 'upstream/pr/374' into HEAD
* upstream/pr/374:
  'main': Directly count spaces to skip, don't leverage proc_buf length
2016-09-25 15:58:35 +00:00
Sebastian Gniazdowski
15461e7d21 'main': Directly count spaces to skip, don't leverage proc_buf length
Main highlighter run on itself, on the optimized version:

- optimized (8 runs, 3 last noted):
1.1201650000
1.1074430000
1.1263810000

- unoptimized (8 runs, 3 last noted):
1.5746400000
1.5115250000
1.5155440000

Average difference: 0.415907
2016-09-25 17:52:56 +02:00
Daniel Shahaf
44ef6e38e5 'main': Highlight several more special (non-alphabetic) parameters. 2016-09-25 14:51:02 +00:00
Daniel Shahaf
4afe670f7a 'main': Highlight shell's PID ($$) inside double quotes. 2016-09-25 14:40:58 +00:00
Daniel Shahaf
c3913e0d8e 'main': Highlight command substitutions inside double quotes.
Part of issue #139.
2016-09-25 14:40:02 +00:00
Daniel Shahaf
4fc35362ee 'main': Permit subshells to end at command position.
Fixes #344.
2016-09-25 12:06:39 +00:00
Daniel Shahaf
2bb8f0703d 'main': Highlight mismatched foreach/end.
Fixes #96.
2016-09-25 11:52:15 +00:00
Daniel Shahaf
a2876fb57d dev tools: Add a TODO to introduce code reuse. 2016-09-25 11:38:54 +00:00
Daniel Shahaf
b2733a64da 'main': Highlight mismatched do/done. 2016-09-25 11:38:54 +00:00
Daniel Shahaf
2755438e80 'main': Yet another test for mismatched braces. 2016-09-25 11:38:52 +00:00
Sebastian Gniazdowski
c6b6513ac0 'main' / *_check_path: Precompute $#BUFFER and use it for speed gain
Running main highlighter on itself (both runs are on the optimized
version):

- clean (8 runs, last 3 noted):
1.7007670000
1.7330720000
1.7038810000

- optimized (8 runs, last 3 noted):
1.5007230000
1.5142960000
1.4973320000

Average difference: 0.208456

When parsing main-highlighter with itself, the *_check_path function is
called 426 times. Note that there are 686 region_highlight resulting
entries.
2016-09-25 12:35:28 +02:00
Daniel Shahaf
a053768627 dev tools: Remove a superfluous empty line. 2016-09-25 08:11:01 +00:00
Daniel Shahaf
e5782e4ddf 'main': Highlight 'always' blocks.
Fixes #335.
2016-09-25 08:11:01 +00:00
Daniel Shahaf
8bf423d16d 'main': Don't find command positions within multiline array literals.
Fixes #333.
2016-09-24 17:55:18 +00:00
Daniel Shahaf
5627fd2045 dev tools: Stage the copyright block to make diffs smaller. 2016-09-24 17:07:01 +00:00
Daniel Shahaf
987c133486 dev tools: Tolerate invalid input. 2016-09-24 17:06:21 +00:00
Daniel Shahaf
a4196eda5e 'main': Restore compatibility with zsh-4.3.14 and older (after e3182c18de8f).
Fixes #368.
2016-09-23 15:55:06 +00:00
Daniel Shahaf
e15a09840e dev tools: Automate a recurring step: Set year correctly for new tests. 2016-09-23 06:37:28 +00:00
Daniel Shahaf
6f91850a01 'main': Highlight first command word in named functions defined in the sh syntax when MULTI_FUNC_DEF is set.
Fixes a subset of issue #237.
2016-09-23 06:37:26 +00:00
Daniel Shahaf
2fabf7ca64 'main': More tests for mismstached parentheses and braces. 2016-09-22 11:12:42 +00:00
Daniel Shahaf
51b9d79c3b 'main': Highlight mismatched parentheses and braces. 2016-09-22 11:12:42 +00:00
Daniel Shahaf
0a9b347483 driver: Warn just once when a highlighter is missing.
The heretofore code warned once per keypress.
2016-09-22 04:10:28 +00:00
Daniel Shahaf
02807f1826 'main': Support the IGNORE_BRACES option.
This is related to a future "unbalanced { ( ) }" check for issue #344.
2016-09-22 03:45:04 +00:00
Daniel Shahaf
a8a6384356 'main': Add tests for the IGNORE_BRACES option.
Also adds an XFail test for balanced braces for issue #344.
2016-09-22 03:41:53 +00:00
Daniel Shahaf
fdaeec4514 'main': Followup to 51614ca2c9: Run cheaper conditions first.
This was suggested on #355.
2016-09-08 19:09:29 +00:00
m0viefreak
4c4baede51 'brackets': Don't highlight corresponding bracket on accept-line 2016-09-08 15:22:43 +02:00
Alyssa Ross
da60234fb2 driver: Declare global variables
This caused warnings with `setopt warn_create_global`.
2016-08-31 16:26:09 +00:00
Daniel Shahaf
51614ca2c9 'main': Avoid triggering a zsh bug related to hashed commands.
This manifested in completion of the form «./foo<TAB>» where there happened to
be a program called 'foo' in $PATH.

Fixes #354.
Closes #355.
2016-08-30 02:56:23 +00:00
Daniel Shahaf
11c9081967 *: error messages: Fix quoting. 2016-08-16 19:01:25 +00:00
Daniel Shahaf
c7f7d2ff16 *: Change highlighters' namespace.
Fixes #329.

Merge remote-tracking branch 'danielsh/i329-v1'

* danielsh/i329-v1:
  highlighters: Rename entry points.
  driver: Rename highlighter entry points
2016-08-16 17:53:01 +00:00
Daniel Shahaf
c793e0dcea highlighters: Rename entry points.
This tracks the API change made in the previous commit, as suggested in the
(#if 0'd) deprecation warning.
2016-08-16 17:51:43 +00:00
Daniel Shahaf
a3d5dfcbda driver: Rename highlighter entry points
This updates the docs and the driver, in a manner backwards compatible with
existing highlighters.  (None of the highlighters are touched by this change,
yet tests continue to pass.)

Part of issue #329.
2016-08-16 17:51:43 +00:00
Daniel Shahaf
f91a7b885e driver: Followup to 80148f6c84: don't squat on the highlighters' namespace. 2016-08-16 17:49:18 +00:00
Daniel Shahaf
f3242cbd6a driver: Followup to d711563fe1: actually make the driver reentrant.
Re-fixes #305.
2016-08-16 17:22:39 +00:00
Daniel Shahaf
b2ba91f12f noop: Rewrap. 2016-08-16 17:09:42 +00:00
Daniel Shahaf
d1e0defceb README: Add a reference to upstream's documentation. 2016-08-16 17:09:04 +00:00
Daniel Shahaf
b7bb4f8657 README: Rephrase a question non-negatively^W neutrally. 2016-08-16 17:08:47 +00:00
Daniel Shahaf
2c002f9f89 noop: Add comments. 2016-08-16 13:40:31 +00:00
Daniel Shahaf
757d047f09 'main': The word after 'sudo' is only a non-command word if it is an option. 2016-08-16 13:31:05 +00:00
Daniel Shahaf
179b8e753f 'main': Test for redirection earlier.
This is a prerequisite for the next commit.

The incumbent code was wrong: the test of $in_redirection in the first hunk
would never have seen «(( in_redirection == 2 ))».  That had no visible
effect since options to sudo don't look like redirection operators.
2016-08-16 13:27:36 +00:00
Daniel Shahaf
6e2ef574c8 noop: Restructure code for clarity.
The structure now mirrors the stall construct at the top of the loop.
2016-08-16 13:25:43 +00:00
Daniel Shahaf
d1c773faa7 noop: Fix indentation. 2016-08-16 13:00:55 +00:00
Daniel Shahaf
295d62ec88 driver: Followup to last: make the value more unique.
Part of issue #305.
2016-08-12 09:43:54 +00:00
Daniel Shahaf
d711563fe1 driver: Make it reentrant.
This fixes an infinite recursion in zsh without zle-line-pre-redraw [≤5.2] in
the following situation:

% source zsh-syntax-highlighting.zsh
% eval "my-self-insert() { zle -M 'foobar'; ${(q)widgets[self-insert]#*:} \"\$@\" }"
% zle -N self-insert my-self-insert
% source zsh-syntax-highlighting.zsh

Fixes #305.
2016-08-12 09:19:36 +00:00
Daniel Shahaf
e2f863c151 minor: Fix typo in development usage message. 2016-08-12 09:19:36 +00:00
m0viefreak
4ad311ec0a driver: Enable highlighting during isearch under zsh≥5.3.
This patch causes a behaviour difference in the [i257] scenario:

- Before this change, the zle_highlight[isearch] is applied and z-sy-h's
  highlighting isn't.

- With this change, both zle_highlight[isearch] and z-sy-h's
  highlighting are applied, so «echo foo» renders the first word in green
  underline (fg=green from ZSH_HIGHLIGHT_STYLES[builtin], underline from
  zle_highlight[isearch]).

This patch causes the presuppositional FAQ entry added in
a8fe22d422 to be correct.

This is part of #261, of which #288 was a spin-off.

[i257] https://github.com/zsh-users/zsh-syntax-highlighting/pull/257#issuecomment-168394665
2016-07-30 20:08:12 +00:00
Daniel Shahaf
171a4eec2d Merge remote-tracking branch 'danielsh/m0vie-i288-v2' (revised version of upstream/pr/288)
* danielsh/m0vie-i288-v2:
  driver: Don't highlight in isearch
  driver: Always bind zle-line-finish and use it instead of accept-*
  driver: Widget binding: Support binding incomplete/nonexistent widgets
2016-07-29 21:09:31 +00:00
m0viefreak
a8fe22d422 driver: Don't highlight in isearch
zsh version 5.2 and lower don't support ISEARCHMATCH_ACTIVE and
we are unable to re-apply zle_highlight on top. Therefore it is
impossible to see the underlined matched area.

Since that information is more important, completely disable
highlighting in isearch in that case.

To do that, we need to make sure we are actually called when
something changes in isearch.

Trumps #257.

The FAQ entry presupposes #245 will be fixed (in time for the release) too.
2016-07-29 21:07:48 +00:00
m0viefreak
5bae621900 driver: Always bind zle-line-finish and use it instead of accept-*
Special handling for cursor imprint or partial path highlighting
is needed in more cases than accept-*. For example when accepting
a line from isearch, no accept-* widget is invoked.

The proper way is to use zle-line-finish.

Trumps #259.
Fixes #284.
2016-07-29 20:41:06 +00:00
m0viefreak
9e569bb0fe driver: Widget binding: Support binding incomplete/nonexistent widgets 2016-07-29 20:41:06 +00:00
Daniel Shahaf
add6825898 dev tools: Extend tests/generate.zsh. 2016-07-29 19:02:40 +00:00
Daniel Shahaf
8013dc3b8d dev tools: Add a script that generates a test-data file. 2016-07-29 18:58:37 +00:00
Daniel Shahaf
fa57633d81 'main': Enable test for issue #238. 2016-07-28 08:14:23 +00:00
Daniel Shahaf
0d41933c61 'main': Add test for issue #343, concerning the 'command' precommand. 2016-07-28 07:54:28 +00:00
Daniel Shahaf
e6fb61c42b 'main': Highlight a broken symlink as a file.
Merge remote-tracking branch 'upstream/pr/342'

* upstream/pr/342:
  'main': Highlight a broken symlink as a file.
  tests: Add an XFail test for issue #342.
2016-07-22 16:09:06 +00:00
Daniel Shahaf
6b69389bd9 'main': New test, related to issue #328.
The test passes so I'm adding it directly to master.
2016-07-22 15:52:43 +00:00
Daniel Shahaf
3409a2e4d2 *: s/echo/print/
Just in case one of the interpolated variables contains a backslash.
2016-07-21 04:01:50 +00:00
Daniel Shahaf
53083da821 'main': Highlight a broken symlink as a file.
Fixes #342.
2016-07-20 02:01:15 +00:00
Daniel Shahaf
95f7206a93 tests: Add an XFail test for issue #342. 2016-07-20 02:00:28 +00:00
Daniel Shahaf
fffe13a8fb docs: Minor tweak.
Suggested-by: Matthew Martin
2016-07-18 04:27:54 +00:00
Daniel Shahaf
80148f6c84 docs: State highlighters' designated namespace. 2016-07-12 07:05:37 +00:00
Daniel Shahaf
ba16cf2fb2 docs: s/myhighlighter/acme/g
Makes the text easier to read ("_zsh_highlight_myhighlighter_highlighter" is
a mouthful).
2016-07-12 07:03:18 +00:00
Daniel Shahaf
3e59ab41b6 driver: Change a variable name to avoid squatting the highlighters' namespace.
Part of issue #329.
2016-07-12 06:50:49 +00:00
Daniel Shahaf
d13da0cf00 'main': Support vi linewise region (REGION_ACTIVE == 2).
Merge remote-tracking branch 'danielshahaf/i267-linewise-region-v1'

* danielsh/i267-linewise-region-v1:
  tests: Add a regression test for issue #267, concerning highlighting a vi linewise region.
  Support linewise region.
2016-07-01 02:00:10 +00:00
Daniel Shahaf
ee07588cfd tests: Add a regression test for issue #267, concerning highlighting a vi linewise region. 2016-07-01 01:59:37 +00:00
m0viefreak
b9112aec79 driver: Widget binding: Use ${(k)widgets} instead of $(zle -la)
Avoids a fork.
2016-06-20 18:37:11 +00:00
m0viefreak
f3d3aaa00c 'main': Document _pathseparator styles 2016-06-12 09:06:30 +00:00
m0viefreak
9a934d291e 'main': Path separators: Leave styles empty by default
If the separator feature is disabled, this makes it possible to
change the main 'path' styles in a running session without the
need to touch the '_pathseparator' styles, too.
2016-06-11 14:19:17 +02:00
Daniel Shahaf
750aebc553 driver: Stop requiring function_argzero.
Instead, use the %N prompt expando, as suggested by Bart in users/21637.

Avoid the `print -P %N` syntax to save a fork on Cygwin, at the expense
of not supporting zsh's from 2001 through c. 2004 vintages.

Fixes #338.
2016-06-10 15:18:46 +00:00
Daniel Shahaf
d9e07b5082 'main': simple parameter expansions at command word: Don't use an undefined value.
Causes such expansions to be highlighted as [unknown-token] rather than as default (absent from $region_highlight).

Fixes #337.
2016-06-10 14:31:57 +00:00
Daniel Shahaf
da91264122 'main': Add missing arguments.
Part of #337.
2016-06-10 14:31:57 +00:00
Daniel Shahaf
e35a0b256e 'main': Try the "non-command word" codepath when a word may be either a command word or a non-command word.
Merge remote-tracking branch 'upstream/pr/331'

* upstream/pr/331:
  'main': Try the "non-command word" codepath when a word may be either a command word or a non-command word.
2016-06-05 16:58:12 +00:00
Daniel Shahaf
10a596f9fd dev docs: Document a useful tab completion setting. 2016-06-03 08:46:30 +00:00
Daniel Shahaf
4b77af73fb minor: Fix typo in comment.
Two instances.
2016-06-03 08:41:45 +00:00
Daniel Shahaf
47144ad974 'main': Fix issue #290, «Mishighlights "longloops" 'repeat'».
* upstream/pr/319:
  tests: Extend issue #290 test with another variant.
  'main': Fix issue #290, «Mishighlights "longloops" 'repeat'».
  tests: New test for issue #290, «Mishighlights "longloops" 'repeat'».
2016-06-03 04:32:25 +00:00
Daniel Shahaf
7fb6f99791 'main': Try the "non-command word" codepath when a word may be either a command word or a non-command word.
Fixes #231.
Fixes #330.
2016-06-03 04:25:00 +00:00
Daniel Shahaf
fccf92402b minor: tests: Formatting tweak to XPASS output.
Remove superfluous single quotes around the second hyphen.
2016-06-03 03:57:45 +00:00
Daniel Shahaf
29b30e0ca7 'main': Add XFail test for issue #330, concerning command word after array assignment. 2016-06-03 03:42:12 +00:00
Daniel Shahaf
f4036a09ce 'main': Highlight scalar assignments to argv
Assignments to positional parameters using scalar assignment syntax is
a feature: it is covered by upstream's test suite ("append to positional
parameter" in Test/A06assign.ztst).
2016-06-03 03:27:52 +00:00
Daniel Shahaf
14711a51f3 tests: Explicitly test 'default' style inside an array assignment. 2016-06-03 02:41:10 +00:00
Matthew Martin
91fa057a39 minor: 'main': Only search for prefixes if :h is a directory 2016-06-01 00:54:30 -05:00
Daniel Shahaf
f060622dc6 'main': Internal cleanup: drop $style_override.
Merge remote-tracking branch 'upstream/pr/326'

* upstream/pr/326:
  'main': Internal cleanup: drop $style_override.

Conflicts:
	highlighters/main/main-highlighter.zsh (context lines only)
2016-06-01 05:45:39 +00:00
m0viefreak
6cd39e7c70 'main': Highlight path separators
This commit is based on the work done by
Jorge Israel Peña (blaenk) in #136.

Changes:
* Adjusted to changes on the latest master branch.
* Use regular path highlighter colors by default.
* Break out early if the separator color is the same to
  improve performance.
* Tests.
2016-05-31 15:06:12 +00:00
Daniel Shahaf
a5b8bc0ef0 'main': Internal cleanup: drop $style_override.
Changes the interface of _zsh_highlight_main_highlighter_check_path().

Suggested-by: m0viefreak
2016-05-27 10:21:28 +00:00
m0viefreak
3b67e656bf 'main': Implement simple command type cache 2016-05-24 23:08:11 +02:00
m0viefreak
12b879caf7 'main': Use zsh/parameter instead of type -w
If possible, try to use the zsh/parameter module to get
information about a shell words.

This avoids subshells and is a huge speed improvement
on systems such as cygwin.

Note 1:
$commands does not know about PATH_DIRS. So in case
PATH_DIRS is set, 'type -w' is still used if nothing
else matches.

Note 2:
zsh/parameter can't distinguish between 'command' and
'hashed'. Adjusted the test for that case to XFAIL.

The ideal solution would be if whence had an option to
put the result in REPLY instead of printing it to stdout.
2016-05-13 20:25:07 +02:00
m0viefreak
61f43255ab 'main': Support multiple styles in _zsh_highlight_main_add_region_highlight 2016-05-13 20:25:04 +02:00
Daniel Shahaf
6362c757b6 tests: Extend issue #290 test with another variant.
The test being extended is highlighters/main/test-data/control-flow2.zsh.
2016-05-13 04:28:43 +00:00
Matthew Martin
d37c55c788 minor: tests: Add comment for NONE in expected_region_highlight 2016-05-12 22:59:06 -05:00
Matthew Martin
364f206a54 docs: Give example of test that modifies its environment 2016-05-12 22:48:07 -05:00
Matthew Martin
19acd8e844 docs: Mention $BUFFER 2016-05-12 22:48:03 -05:00
Matthew Martin
13018f3dd7 docs: Document use of NONE in expected_region_highlight 2016-05-12 22:47:55 -05:00
Matthew Martin
0f43026bf0 docs: Document writing tests 2016-05-12 22:40:34 -05:00
Matthew Martin
1082067f93 tests: Fail on stderr output
Closes #291.
2016-05-12 22:32:34 -05:00
Daniel Shahaf
ef68f50c04 'main': Fix issue #290, «Mishighlights "longloops" 'repeat'». 2016-05-13 03:30:11 +00:00
Daniel Shahaf
4832f18c50 tests: New test for issue #290, «Mishighlights "longloops" 'repeat'». 2016-05-13 02:50:24 +00:00
Daniel Shahaf
f146651913 Merge part of PR #298
* commit '2f18ba':
  'main': use zsh/parameter to resolve alias
  driver: load zsh/parameter if available
2016-05-13 02:27:29 +00:00
m0viefreak
2f18ba64e3 'main': use zsh/parameter to resolve alias
If possible, use zsh/parameter to avoid forks.

Fixes #263.
2016-05-13 02:27:03 +00:00
m0viefreak
3ce01076b5 driver: load zsh/parameter if available 2016-05-13 02:24:57 +00:00
Daniel Shahaf
def8c0da83 Bump copyright years. 2016-05-13 01:29:49 +00:00
Daniel Shahaf
4f5bb6cf96 Merge remote-tracking branch 'upstream/pr/308' into HEAD
* upstream/pr/308:
  'main': Fix issue #302, "Process substitution misparsed as redirection".
  'main': Factor out common code.  No functional change.
  'main': Add a regression test for issue #302, "Process substitution misparsed as redirection".
2016-05-13 01:24:01 +00:00
Daniel Shahaf
0ff354b44b docs: Namespace highlighters' styles.
Follow-up to 2176692704.

Part of #306.
2016-05-12 19:28:17 +00:00
Daniel Shahaf
7b82b88a71 'main': Don't leak the PATH_DIRS options.
Found-by: m0viefreak
(in #298)
2016-05-12 19:24:00 +00:00
Sebastian Gniazdowski
ef4bfe5bcc 'main': 2nd optimization that in my tests shows 2.2s -> 2.0s 2016-05-12 19:22:29 +00:00
Daniel Shahaf
5a98cd3a10 Merge remote-tracking branch 'upstream/pr/315' into HEAD
* upstream/pr/315:
  'main': optimization that in my tests shows 2.7s -> 2.2s
2016-05-12 18:30:50 +00:00
Sebastian Gniazdowski
02229ebd63 'main': optimization that in my tests shows 2.7s -> 2.2s
Consider indexing long buffers (say 300 chars). E.g. following line:
      integer offset=${${buf[start_pos+1,len]}[(i)$needle]}
will gradually go into large indices for first index [a,] and be kept
at large index for second index [,b]. Instead, we can remove already
processed characters from buf:
    proc_buf="${proc_buf[offset + $#arg + 1,-1]}"
$offset and $#arg are small, first index will not be large. $proc_buf
will be smaller and smaller and the second index [,-1] will run shorter
and shorter.
2016-05-12 18:29:09 +00:00
Daniel Shahaf
162c826452 docs: Honour $ZDOTDIR in code examples.
Keep references in prose as '~/.zshrc': using $ZDOTDIR in that context would
be confusing, and people who set $ZDOTDIR understand these references.
2016-05-12 13:29:10 +00:00
Daniel Shahaf
a00ed24ba3 docs: Simplify/clarify installation instructions.
This also removes an implicit assumption that ~/.zshrc is idempotent.
2016-05-12 13:25:59 +00:00
Daniel Shahaf
62f1c108f3 tests: New test to capture off-by-ones.
Inspired by #312.
2016-05-11 20:36:18 +00:00
m0viefreak
5fe8fd8bdc 'brackets': Fix for one-based indexing
Use correct indexing also for cursor-matchingbracket.

Fixup for 95d82568d8
2016-05-11 01:11:49 +02:00
Nils Luxton
2176692704 docs: Added style key prefix convention
Part of #306
2016-05-09 17:35:21 +01:00
Daniel Shahaf
a7a7f8b422 Support linewise region.
Fixes #267.
2016-05-09 04:10:02 +00:00
Daniel Shahaf
15db71abd0 driver: Track rename of an unreleased upstream API.
ISEARCH_ACTIVE was renamed ISEARCHMATCH_ACTIVE in workers/38921
(commit f06be0ffcf2c to zsh itself).

Fixes #299.
2016-05-09 03:38:27 +00:00
Daniel Shahaf
fc9c892a3f 'main': Fix issue #302, "Process substitution misparsed as redirection". 2016-05-09 03:29:27 +00:00
Daniel Shahaf
bfabffbf97 'main': Factor out common code. No functional change. 2016-05-09 03:26:29 +00:00
Daniel Shahaf
6889ff6bd2 'main': Add a regression test for issue #302, "Process substitution misparsed as redirection". 2016-05-09 03:26:06 +00:00
Matthew Martin
9cab566f53 docs: Document installation with other plugin managers
Closes #297.
2016-05-06 09:30:13 -05:00
Matthew Martin
bb341f186c dev docs: Document testing quirks 2016-05-05 16:25:37 -05:00
Matthew Martin
b5955213b9 tests: Add tests for 'brackets' and 'pattern' 2016-05-05 15:36:33 -05:00
Daniel Shahaf
f0bae44b76 tests: Followup to last: echo(1) is evil.
Use 'print -r --' instead, so literal backslashes in $BUFFER aren't expanded.

Found-by: Matthew Martin
2016-05-05 20:34:43 +00:00
Daniel Shahaf
3176b9567c minor: tests: Quote $BUFFER differently on output.
The new output improves readability of the 'main' highlighter's test output.
2016-05-05 19:33:56 +00:00
Daniel Shahaf
6aa57d60aa tests: TAP support: Emit a 'description' for all test points 2016-05-05 19:11:49 +00:00
Daniel Shahaf
f83bca0847 minor: tests: Introduce a local variable. No functional change. 2016-05-05 19:11:28 +00:00
Daniel Shahaf
70b5687d66 minor: tests: Tighten up local variable scope. 2016-05-05 19:11:07 +00:00
Daniel Shahaf
21207c336a tests: TAP compliance: Do not emit literal '#' in the 'description' part 2016-05-05 19:11:07 +00:00
Daniel Shahaf
56a867076c tests: Followup to fd061b5730: quote both expected and actual output. 2016-05-05 19:10:06 +00:00
Matthew Martin
f73f3d53d3 'brackets': Allow unset ZSH_HIGHLIGHT_STYLES
Without this when bracket_color_size is 0,
    $(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
errors with division by zero.
2016-05-05 13:56:09 -05:00
Matthew Martin
eaa4335c34 tests: Set ZSH_HIGHLIGHT_STYLES=() during tests
Since the _zsh_highlight_add_highlight that the tests use ignores
ZSH_HIGHLIGHT_STYLES, we can test both an injective mapping and an empty
mapping at once.
2016-05-05 12:31:52 -05:00
Matthew Martin
d3678ec7a8 tests: Remove unused_highlight 2016-05-05 12:28:43 -05:00
Matthew Martin
fd061b5730 tests: Test ZSH_HIGHLIGHT_STYLES keys directly
Closes #287. Testing the keys directly removes the need for
unused_highlight which will be removed next.
2016-05-05 12:28:39 -05:00
Matthew Martin
ccaf6f48a1 brackets: Fix bug introduced in 95d8256 2016-05-05 09:59:26 -05:00
Matthew Martin
e05b8e88ad 'brackets': Check if brackets match on first pass
This removes the need for the typepos array.
2016-05-04 20:50:55 -05:00
Matthew Martin
95d82568d8 'brackets': Use one-based indexing
zsh arrays start at one, and this will make the next commit easier.
2016-05-04 20:50:55 -05:00
Matthew Martin
f4d3dcb42f 'brackets': Move highlight call outside conditional 2016-05-04 20:50:55 -05:00
Matthew Martin
fd84010252 'brackets': Lift local declarations from inside loops 2016-05-04 20:50:55 -05:00
Daniel Shahaf
cef49752fd dev docs: Create HACKING.md.
Review-by: Matthew Martin
2016-05-05 01:20:32 +00:00
Daniel Shahaf
e8af14fe1f minor: Rewrap docs for uncompiled readability. 2016-05-03 15:00:48 +00:00
Matthew Martin
4da9889d15 tests: Use 'NONE' to denote no highlighting
'none' is a valid highlighting type. Since by convention styles are all
lowercase, 'NONE' shouldn't conflict with anything.

Closes #289.
2016-04-30 12:48:44 -05:00
Matthew Martin
c346f6eb6f docs: highlighters should use _zsh_highlight_add_highlight 2016-04-29 21:52:41 -05:00
Daniel Shahaf
f34714b8ee Bump copyright years. 2016-04-30 02:11:17 +00:00
Matthew Martin
341a3ae1f0 highlighters: Use _zsh_highlight_add_highlight
_zsh_highlight_add_highlight appends to region_highlight $1 $2 and the
next non-null parameter. If there is no non-null parameter, do nothing,
This is so that highlighters can add a style with fallbacks if the most
specific style is not defined. If none of the applicable styles are
defined, do the right thing and don't add an invalid entry to
region_highlight.

The pattern highlighter doesn't use this function as it'd need too large
of an API change.
2016-04-29 10:09:16 -05:00
Matthew Martin
089329660b highlighters: Pass around the style key instead of the style itself 2016-04-29 09:53:05 -05:00
Matthew Martin
a830613467 tests: Specify the style key instead of the style itself 2016-04-29 09:51:13 -05:00
Daniel Shahaf
c54c076cfa cleanup: Avoid colon after parameter expansion to avoid risking introducing a colon modifier. 2016-04-24 17:08:08 +00:00
m0viefreak
38c8fbea2d root-highlighter: use EUID instead of id -u command
No need to fork every time.
2016-04-23 06:43:01 +00:00
Daniel Shahaf
b52a485c5c brackets: Optimize a tiny bit.
Compute «${#BUFFER}» just once.  I haven't measured the effect of this, but
it might just avoid a strlen() every time around the loop, which could add
up for large ${BUFFER}s.

See issue #295.
2016-04-22 14:14:15 +00:00
Adam Kruszewski
d4f8edc9f3 plugin.zsh: Convert from symlink to plain file
Fixes zsh-users/zsh-syntax-highlighting#292 (compatibility with zsh-5.1.1/msys2 on windows).
2016-04-17 04:48:30 +00:00
Daniel Shahaf
367929502f release.md: Add a release checklist line item. 2016-04-05 05:49:18 +00:00
Matthew Martin
78290e043b tests: Expect the correct style 2016-04-03 20:43:13 -05:00
Matthew Martin
31ac2b36a9 tests: Quote style in expected_region_highlight 2016-04-02 09:45:24 -05:00
Matthew Martin
bb8d325c0c tests: Fix grep syntax
In basic regular expressions | is not a special character that spearates
branches, so use an extended regular expression.
2016-04-01 00:52:27 -05:00
m0viefreak
79e4d3d124 apply suffix and isearch zle_highlights on top 2016-03-28 18:24:29 +02:00
Daniel Shahaf
bc7f8ea433 'main': Restore support for zsh-4.3.10 and older.
zsh older than workers/28418 (zsh revision 23bdfc7fd2a012d5205ed22d18eb39e41c8fbc95)
doesn't support the «${name:offset:length}» syntax.  Therefore, use the older
«$name[start,end]» syntax instead.

Followup to 3cb58fd7d7, "Optimization: -1 is
extra computation of string length internally".

Fixes zsh-users/zsh-syntax-highlighting#279.
2016-03-23 01:32:44 +00:00
Daniel Shahaf
cb02451a4e widget binding: Fix crucial typo in last commit. 2016-03-18 15:14:09 +00:00
Daniel Shahaf
11d378332e widget binding: Further unbreak the build.
7e7e291b20 broke 'zle -C' completions, as reported in #278 just now.
2016-03-18 15:12:04 +00:00
Daniel Shahaf
6a634fac9f widget binding: Properly escape widget names at definition.
Re-Fixes zsh-users/zsh-syntax-highlighting#278.
2016-03-18 14:53:53 +00:00
Daniel Shahaf
47a664447c noop: Remove stray statement terminators and line joiners. 2016-03-18 14:47:53 +00:00
Daniel Shahaf
261c180a36 widget binding: Unbreak the build.
The last commit inadvertently broke interactive use, although the test suite passed.

See issue #278.
2016-03-18 14:41:18 +00:00
Daniel Shahaf
7e7e291b20 widget binding: Remove an unnecessary layer of indirection.
The 'eval' was never needed, and the lack of proper quoting of the interpolated
variables caused issues, such as #278.

Fixes zsh-users/zsh-syntax-highlighting#278.
2016-03-18 13:58:55 +00:00
m0viefreak
4849ef3307 Refactor the application of zle_highlight settings
- Extract duplicated code into a new function.
  This makes it easier to add support for other entries in the
  future, that cannot be accessed in the current version of zsh
  (isearch, suffix).
- Make decision logic more comprehensible.
- Respect deliberately empty entries in zle_highlight.
  Don't force the default value when the user deliberately sets
  an entry in zle_highlight to the empty string.
  For example
    zle_highligh(paste:)
  to disable paste highlighting completely.
2016-03-13 16:29:00 +01:00
Daniel Shahaf
4c23a2fd1b 'main': Highlight lone '!' correctly: it's not a history expansion.
While here, also add a test for the '!' reserved word (which is highlighted
since c216242b).
2016-03-13 02:47:25 +00:00
Daniel Shahaf
e635f766be docs: Clarify oh-my-zsh installation instructions.
Thanks to Andrew Janke.

Fixes zsh-users/zsh-syntax-highlighting#270.
2016-03-12 18:36:44 +00:00
Daniel Shahaf
18df692ae6 widget binding: Remove some too-wide exclusions
* m0vie/p_bindings:
  widget binding: don't exlude widgets with identical function name
  widget binding: don't exclude widgets starting with '_'
2016-03-12 17:24:03 +00:00
m0viefreak
487b122c48 widget binding: don't exclude widgets with identical function name
Skipping when $cur_widgets == user:$cur_widget was introduced
with 776453cb5b. However there
are cases where this is not just an 'already rebound' event, but
simply a normal widget whose function name happens to be identical
to its widget name.

Example:
expand-absolute-path is a widget whose function name is also
expand-absolute-path. No reason why this should be ignored.

Another example:
edit-command-line
2016-03-12 17:23:12 +00:00
Daniel Shahaf
7044c1986e docs: use https:// instead of git:// 2016-02-18 13:39:24 +00:00
Vishnu Ks
bdb23d1378 use https instead of git for url 2016-02-17 23:52:54 +05:30
Daniel Shahaf
e500ca2462 'main': Don't highlight in vared
This is a continuation of 451665cb2a which did
the same for the $PS3 prompt.

Reported-by: Sebastian Gniazdowski
2016-02-14 17:34:53 +02:00
Daniel Shahaf
e938825a85 Merge pull request #272 from psprint/master
Optimization: -1 is extra computation of string length internally
2016-02-14 14:32:01 +00:00
Sebastian Gniazdowski
3cb58fd7d7 Optimization: -1 is extra computation of string length internally
./parse.zsh "zplugin.zsh" > out_norm.txt 106,17s user 7,84s system 98% cpu 1:55,85 total

./parse.zsh "zplugin.zsh" > out_opt.txt 51,91s user 7,44s system 99% cpu 59,912 total

% wc -l zplugin.zsh
3188 zplugin.zsh
2016-02-12 08:31:14 +01:00
Daniel Shahaf
683f4837a0 changelog: Update for upcoming 0.4.1 release. 2016-01-27 20:48:56 +00:00
Daniel Shahaf
62a6be3d63 Version number bump.
Have master self-describe as 0.5.0-dev, since an 0.4.1 release is upcoming on
another branch.
2016-01-27 20:38:38 +00:00
Daniel Shahaf
451665cb2a 'main': Don't highlight at the $PS3 prompt.
The input to the $PS3 prompt is not commands, so the 'main' highlighter is
not applicable to it.

Fixes zsh-users/zsh-syntax-highlighting#268.
2016-01-20 22:10:49 +00:00
Daniel Shahaf
30d8f92df2 test harness: Properly quote error message interpolations.
No functional change, except that error messages are now more readable.
2016-01-20 22:02:25 +00:00
Daniel Shahaf
282c7134e8 Revert "wrapping: Don't add '--' when invoking widgets."
The '--' guard was correct; it was there to guard against arguments belonging
to the syntax «zle widget [ -n num ] [ -Nw ] [ -K keymap ] args».

For example, this affected using <backward-kill-word> over
    BUFFER="-w "
    CURSOR=3
after
    autoload -Uz select-word-style
    select-word-style default
    zstyle ':zle:backward-kill-word' word-style shell
.

This reverts commit c808d2187a.
2016-01-17 19:43:48 +00:00
Daniel Shahaf
28932316cc aliases: Highlight aliases with '=' in their LHS as error. (Part of issue #263.) 2016-01-11 15:27:48 +00:00
Daniel Shahaf
5e4b446dee aliases: Add a test for one variant of issue #263. 2016-01-11 15:07:18 +00:00
Daniel Shahaf
9b64ad750f tests: Add a 'print failures only' mode to 'make test', called 'make quiet-test'.
Fixes zsh-users/zsh-syntax-highlighting#262.

Currently, 'make quiet-test' uses Perl.  However, since it is considered a development
tool rather than a user-facing tool, users and downstream packages needn't install Perl.
Furthermore, even this dev-only dependency may be dropped in the future.

The only difference between tests/tap-filter here and the one in the issue is using
a `cat` subshell v. using 'undef $/; <STDIN>'.
2016-01-02 21:22:01 +00:00
Daniel Shahaf
936e2e9314 tests: Add another comment. No functional change. 2016-01-02 20:52:40 +00:00
m0viefreak
ed33d2cb13 widget binding: don't exclude widgets starting with '_'
Just because a widget starts with _ does not mean it should be
skipped when rebinding. The only reason widgets need to be skipped
is when their function name start with _zsh_highlight_widget*,
which is checked later.

Example:
_expand_alias (^Xa) needs to be wrapped.

The exclusion of _* was introduced in 186d80054a
to fix #65, but it is not needed. The relevant exclusion of
_zsh_highlight_widget* is already enough due to the case statement.
2016-01-02 14:29:04 +01:00
Daniel Shahaf
268656d52b tests: Add a comment. No functional change. 2016-01-01 16:35:00 +00:00
Daniel Shahaf
38c3ac8831 docs: Note that Debian package has migrated to (been added to) Debian stretch. 2015-12-16 22:22:00 +00:00
Daniel Shahaf
82f5eb17ec docs: Note Debian package name.
The Debian package should propagate to the "testing" suite (stretch) in a few days.
2015-12-12 11:04:38 +00:00
Daniel Shahaf
4f3910cbba Fix issue #248: Highlight 'pkexec' as a precommand. 2015-12-04 23:40:30 +00:00
Daniel Shahaf
73ee7c1f6c Fix part of issue #238, "fd redirections at command word".
This fixes fd's specified by a (single) digit.  The named fd syntax remains an XFail.
2015-11-29 03:16:01 +00:00
Daniel Shahaf
48ecd29180 tests: Add two XFail tests for issue #238, "fd redirections at command word". 2015-11-29 03:15:55 +00:00
Daniel Shahaf
430cf55368 tests: Cover [default]. 2015-11-29 02:56:07 +00:00
Daniel Shahaf
46cd970bc4 tests: Improve tests by using $unused_highlight.
The default for [redirection] is 'none', so it wasn't actually being tested.
2015-11-29 02:53:58 +00:00
Daniel Shahaf
09c4114eb9 command word: Do not attempt to interpret command separator tokens as anything else.
The important part of this change is removing the second conjunct from the
condition; the remainder of the change gives one example of when that matters.
2015-11-29 02:02:42 +00:00
Daniel Shahaf
cf685a3a27 changelog: Start 0.4.1 section.
Also fix an error in the title of the 0.4.0 section.
2015-11-29 02:00:51 +00:00
Daniel Shahaf
69b6c4e450 release.md: Clarify release procedure. 2015-11-27 23:24:22 +00:00
Daniel Shahaf
7338c54a25 Post-release version number bump. 2015-11-27 23:20:09 +00:00
145 changed files with 3353 additions and 524 deletions

View File

@@ -1 +1 @@
0.4.0 0.5.1-dev

View File

@@ -1,4 +1,4 @@
Copyright (c) 2010-2015 zsh-syntax-highlighting contributors Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted Redistribution and use in source and binary forms, with or without modification, are permitted

75
HACKING.md Normal file
View File

@@ -0,0 +1,75 @@
Hacking on zsh-syntax-highlighting itself
=========================================
This document includes information for people working on z-sy-h itself: on the
core driver (`zsh-syntax-highlighting.zsh`), on the highlighters in the
distribution, and on the test suite. It does not target third-party
highlighter authors (although they may find it an interesting read).
The `main` highlighter
----------------------
The following function `pz` is useful when working on the `main` highlighting:
pq() {
(( $#argv )) || return 0
print -r -l -- ${(qqqq)argv}
}
pz() {
local arg
for arg; do
pq ${(z)arg}
done
}
It prints, for each argument, its token breakdown, similar to how the main
loop of the `main` highlighter sees it.
Testing the `brackets` highlighter
----------------------------------
Since the test harness empties `ZSH_HIGHLIGHT_STYLES` and the `brackets`
highlighter interrogates `ZSH_HIGHLIGHT_STYLES` to determine how to highlight,
tests must set the `bracket-level-#` keys themselves. For example:
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
BUFFER='echo ({x})'
expected_region_highlight=(
"6 6 bracket-level-1" # (
"7 7 bracket-level-2" # {
"9 9 bracket-level-2" # }
"10 10 bracket-level-1" # )
)
Testing the `pattern` highlighter
---------------------------------
Because the `pattern` highlighter modifies `region_highlight` directly instead
of using `_zsh_highlight_add_highlight`, the test harness cannot get the
`ZSH_HIGHLIGHT_STYLES` keys. Therefore, when writing tests, use the style
itself as third word (cf. the [documentation for `expected_region_highlight`]
(docs/highlighters.md)). For example:
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
BUFFER='rm -rf /'
expected_region_highlight=(
"1 8 fg=white,bold,bg=red" # rm -rf /
)
Miscellany
----------
If you work on the driver (`zsh-syntax-highlighting.zsh`), you may find the following zstyle useful:
zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-highlighting.plugin.zsh
IRC channel
-----------
We're on #zsh-syntax-highlighting on freenode.

View File

@@ -4,22 +4,29 @@ How to install
### Using packages ### Using packages
* Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package]
* Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package]
* Gentoo: [mv overlay][gentoo-overlay] * Gentoo: [mv overlay][gentoo-overlay]
* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package]
* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package]
[arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting
[AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git
[debian-package]: https://packages.debian.org/zsh-syntax-highlighting
[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting
[brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb [brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb
[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting
### In your ~/.zshrc ### In your ~/.zshrc
Simply clone this repository and source the script: Simply clone this repository and source the script:
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
source ~/.zshrc
Then, enable syntax highlighting in the current interactive shell:
source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
If `git` is not installed, download and extract a snapshot of the latest If `git` is not installed, download and extract a snapshot of the latest
development tree from: development tree from:
@@ -29,16 +36,27 @@ Simply clone this repository and source the script:
Note the `source` command must be **at the end** of `~/.zshrc`. Note the `source` command must be **at the end** of `~/.zshrc`.
### With oh-my-zsh ### With a plugin manager
Oh-my-zsh is a zsh configuration framework. It lives at Note that `zsh-syntax-highlighting` must be the last plugin sourced.
<http://github.com/robbyrussell/oh-my-zsh>.
To install zsh-syntax-highlighting under oh-my-zsh: The zsh-syntax-highlighting authors recommend manual installation over the use
of a framework or plugin manager.
This list is incomplete as there are too many [frameworks / plugin managers]
(https://github.com/unixorn/awesome-zsh-plugins#frameworks) to list them all
here.
#### [Antigen](https://github.com/zsh-users/antigen)
Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in
your `.zshrc`.
#### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
1. Clone this repository in oh-my-zsh's plugins directory: 1. Clone this repository in oh-my-zsh's plugins directory:
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
2. Activate the plugin in `~/.zshrc`: 2. Activate the plugin in `~/.zshrc`:
@@ -48,13 +66,29 @@ To install zsh-syntax-highlighting under oh-my-zsh:
source ~/.zshrc source ~/.zshrc
Note that `zsh-syntax-highlighting` must be the last plugin sourced, #### [Prezto](https://github.com/sorin-ionescu/prezto)
so make it the last element of the `$plugins` array.
Zsh-syntax-highlighting is included with Prezto. See the [Prezto documentation]
(https://github.com/sorin-ionescu/prezto/tree/master/modules/syntax-highlighting)
to enable and configure highlighters.
#### [zgen](https://github.com/tarjoilija/zgen)
Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`.
#### [zplug](https://github.com/zplug/zplug)
Add `zplug "zsh-users/zsh-syntax-highlighting", nice:10` to your `.zshrc`.
#### [zplugin](https://github.com/psprint/zplugin)
Add `zplugin load zsh-users/zsh-syntax-highlighting` to the end of your
`.zshrc`.
### System-wide installation ### System-wide installation
Either of the above methods is suitable for a single-user installation, Any of the above methods is suitable for a single-user installation,
which requires no special privileges. If, however, you desire to install which requires no special privileges. If, however, you desire to install
zsh-syntax-highlighting system-wide, you may do so by running zsh-syntax-highlighting system-wide, you may do so by running
@@ -65,6 +99,3 @@ and directing your users to add
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
to their `.zshrc`s. to their `.zshrc`s.

View File

@@ -45,6 +45,9 @@ test:
done; \ done; \
exit $$result exit $$result
quiet-test:
$(MAKE) test QUIET=y
perf: perf:
@result=0; \ @result=0; \
for test in highlighters/*; do \ for test in highlighters/*; do \

View File

@@ -13,7 +13,19 @@ highlighing of commands whilst they are typed at a zsh prompt into an
interactive terminal. This helps in reviewing commands before running interactive terminal. This helps in reviewing commands before running
them, particularly in catching syntax errors. them, particularly in catching syntax errors.
[![Screenshot](images/preview-smaller.png)](images/preview.png) Some examples:
Before: [![Screenshot #1.1](images/before1-smaller.png)](images/before1.png)
<br/>
After:&nbsp; [![Screenshot #1.2](images/after1-smaller.png)](images/after1.png)
Before: [![Screenshot #2.1](images/before2-smaller.png)](images/before2.png)
<br/>
After:&nbsp; [![Screenshot #2.2](images/after2-smaller.png)](images/after2.png)
Before: [![Screenshot #3.1](images/before3-smaller.png)](images/before3.png)
<br/>
After:&nbsp; [![Screenshot #3.2](images/after3-smaller.png)](images/after3.png)
How to install How to install
@@ -32,6 +44,23 @@ custom widgets have been created (i.e., after all `zle -N` calls and after
running `compinit`). Widgets created later will work, but will not update the running `compinit`). Widgets created later will work, but will not update the
syntax highlighting. syntax highlighting.
### Does syntax highlighting work during incremental history search?
Highlighting the command line during an incremental history search
(with the `history-incremental-search-backward` widget, which is
bound by default to <kbd>Ctrl+R</kbd> in zsh's emacs keymap) requires zsh 5.3
or newer.
Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting]
of the matched portion of the buffer remains available, but zsh-syntax-highlighting's
additional highlighting is unavailable. (Those versions of zsh do not provide
enough information to allow computing the highlighting correctly.)
See [issue #288][i288] for details.
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288
### How are new releases announced? ### How are new releases announced?
There is currently no "push" announcements channel. However, the following There is currently no "push" announcements channel. However, the following

View File

@@ -1,9 +1,235 @@
up to 952a97dbc99a54bd86141b7a57625e748941a937 up to 0.5.0
# Changes in version 0.5.0
## Performance improvements:
We thank Sebastian Gniazdowski and "m0viefreak" for significant contributions
in this area.
- Optimize string operations in the `main` (default) highlighter.
(#372/3cb58fd7d7b9, 02229ebd6328, ef4bfe5bcc14, #372/c6b6513ac0d6, #374/15461e7d21c3)
- Command word highlighting: Use the `zsh/parameter` module to avoid forks.
Memoize (cache) the results.
(#298, 3ce01076b521, 2f18ba64e397, 12b879caf7a6; #320, 3b67e656bff5)
- Avoid forks in the driver and in the `root` highlighter.
(b9112aec798a, 38c8fbea2dd2)
# Changes in version 0.3.1 ## Added highlighting of:
- `pkexec` (a precommand).
(#248, 4f3910cbbaa5)
- Aliases that cannot be defined normally nor invoked normally (highlighted as an error).
(#263 (in part), 28932316cca6)
- Path separators (`/`) — the default behaviour remains to highlight path separators
and path components the same way.
(#136, #260, 6cd39e7c70d3, 9a934d291e7c, f3d3aaa00cc4)
- Assignments to individual positional arguments (`42=foo` to assign to `$42`).
(f4036a09cee3)
- Linewise region (the `visual-line-mode` widget, bound to `V` in zsh's `vi` keymap).
(#267, a7a7f8b42280, ee07588cfd9b)
- Command-lines recalled by `isearch` mode; requires zsh≥5.3.
(#261 (in part); #257; 4ad311ec0a68)
- Command-lines whilst the `IGNORE_BRACES` or `IGNORE_CLOSE_BRACES` option is in effect.
(a8a6384356af, 02807f1826a5)
- Mismatched parentheses and braces (in the `main` highlighter).
(51b9d79c3bb6, 2fabf7ca64b7, a4196eda5e6f, and others)
- Mismatched `do`/`done` keywords.
(b2733a64da93)
- Mismatched `foreach`/`end` keywords.
(#96, 2bb8f0703d8f)
- In Bourne-style function definitions, when the `MULTI_FUNC_DEF` option is set
(which is the default), highlight the first word in the function body as
a command word: `f() { g "$@" }`.
(6f91850a01e1)
- `always` blocks.
(#335, e5782e4ddfb6)
- Command substitutions inside double quotes, `"$(echo foo)"`.
(#139 (in part), c3913e0d8ead)
- Non-alphabetic parameters inside double quotes (`"$$"`, `"$#"`, `"$*"`, `"$@"`, `"$?"`, `"$-"`).
(4afe670f7a1b, 44ef6e38e5a7)
- Command words from future versions of zsh (forward compatibly).
This also adds an `arg0` style that all other command word styles fall back to.
(b4537a972eed, bccc3dc26943)
- Escaped history expansions inside double quotes: `: "\!"`
(28d7056a7a06, et seq)
## Fixed highlighting of:
- Command separator tokens in syntactically-invalid positions.
(09c4114eb980)
- Redirections with a file descriptor number at command word.
(#238 (in part), 73ee7c1f6c4a)
- The `select` prompt, `$PS3`.
(#268, 451665cb2a8b)
- Values of variables in `vared`.
(e500ca246286)
- `!` as an argument (neither a history expansion nor a reserved word).
(4c23a2fd1b90)
- "division by zero" error under the `brackets` highlighter when `$ZSH_HIGHLIGHT_STYLES` is empty.
(f73f3d53d3a6)
- Process substitutions, `<(pwd)` and `>(wc -l)`.
(#302, 6889ff6bd2ad, bfabffbf975c, fc9c892a3f15)
- The non-`SHORT_LOOPS` form of `repeat` loops: `repeat 42; do true; done`.
(#290, 4832f18c50a5, ef68f50c048f, 6362c757b6f7)
- Broken symlinks (are now highlighted as files).
(#342, 95f7206a9373, 53083da8215e)
- Lines accepted from `isearch` mode.
(#284; #257, #259, #288; 5bae6219008b, a8fe22d42251)
- Work around upstream bug that triggered when the command word was a relative
path, that when interpreted relative to a $PATH directory denoted a command;
the effect of that upstream bug was that the relative path was cached as
a "valid external command name".
(#354, #355, 51614ca2c994, fdaeec45146b, 7d38d07255e4;
upstream fix slated to be released in 5.3 (workers/39104))
- After accepting a line with the cursor on a bracket, the matching bracket
of the bracket under the cursor no longer remains highlighted (with the
`brackets` highlighter).
(4c4baede519a)
- The first word on a new line within an array assignment or initialization is no
longer considered a command position.
(8bf423d16d46)
- Subshells that end at command position, `(A=42)`, `(true;)`.
(#231, 7fb6f9979121; #344, 4fc35362ee5a)
- Command word after array assignment, `a=(lorem ipsum) pwd`.
(#330, 7fb6f9979121)
## API changes (for highlighter authors):
- New interface `_zsh_highlight_add_highlight`.
(341a3ae1f015, c346f6eb6fb6)
- tests: Specify the style key, not its value, in test expectations.
(a830613467af, fd061b5730bf, eaa4335c3441, among others)
- Module author documentation improvements.
(#306 (in part), 217669270418, 0ff354b44b6e, 80148f6c8402, 364f206a547f, and others)
- The driver no longer defines a `_zsh_highlight_${highlighter}_highlighter_cache`
variable, which is in the highlighters' namespace.
(3e59ab41b6b8, 80148f6c8402, f91a7b885e7d)
- Rename highlighter entry points. The old names remain supported for
backwards compatibility.
(a3d5dfcbdae9, c793e0dceab1)
- tests: Add the "NONE" expectation.
(4da9889d1545, 13018f3dd735, d37c55c788cd)
- tests: consider a test that writes to stderr to have failed.
(#291, 1082067f9315)
## Developer-visible changes:
- Add `make quiet-test`.
(9b64ad750f35)
- test harness: Better quote replaceables in error messages.
(30d8f92df225)
- test harness: Fix exit code for XPASS.
(bb8d325c0cbd)
- Create [HACKING.md](HACKING.md).
(cef49752fd0e)
- tests: Emit a description for PASS test points.
(6aa57d60aa64, f0bae44b76dd)
- tests: Create a script that generates a test file.
(8013dc3b8db6, et seq; `tests/generate.zsh`)
## Other changes:
- Under zsh≤5.2, widgets whose names start with a `_` are no longer excluded
from highlighting.
(ed33d2cb1388; reverts part of 186d80054a40 which was for #65)
- Under zsh≤5.2, widgets implemented by a function named after the widget are
no longer excluded from highlighting.
(487b122c480d; reverts part of 776453cb5b69)
- Under zsh≤5.2, shell-unsafe widget names can now be wrapped.
(#278, 6a634fac9fb9, et seq)
- Correct some test expectations.
(78290e043bc5)
- `zsh-syntax-highlighting.plugin.zsh`: Convert from symlink to plain file
for msys2 compatibility.
(#292, d4f8edc9f3ad)
- Document installation under some plugin managers.
(e635f766bef9, 9cab566f539b)
- Don't leak the `PATH_DIRS` option.
(7b82b88a7166)
- Don't require the `FUNCTION_ARGZERO` option to be set.
(#338, 750aebc553f2)
- Under zsh≤5.2, support binding incomplete/nonexistent widgets.
(9e569bb0fe04, part of #288)
- Make the driver reentrant, fixing possibility of infinite recursion
under zsh≤5.2 under interaction with theoretical third-party code.
(#305, d711563fe1bf, 295d62ec888d, f3242cbd6aba)
- Fix warnings when `WARN_CREATE_GLOBAL` is set prior to sourcing zsh-syntax-highlighting.
(z-sy-h already sets `WARN_CREATE_GLOBAL` internally.)
(da60234fb236)
- Warn only once, rather than once per keypress, when a highlighter is unavailable.
(0a9b347483ae)
# Changes in version 0.4.1
## Fixes:
- Arguments to widgets were not properly dash-escaped. Only matters for widgets
that take arguments (i.e., that are invoked as `zle ${widget} -- ${args}`).
(282c7134e8ac, reverts c808d2187a73)
# Changes in version 0.4.0
## Added highlighting of: ## Added highlighting of:
@@ -104,7 +330,7 @@ up to 952a97dbc99a54bd86141b7a57625e748941a937
(57624bb9f64b) (57624bb9f64b)
- widgets wrapping: Don't add '--' when invoking widgets. - widgets wrapping: Don't add '--' when invoking widgets.
(c808d2187a73) (c808d2187a73) [_reverted in 0.4.1_]
- Refresh highlighting upon `accept-*` widgets (`accept-line` et al). - Refresh highlighting upon `accept-*` widgets (`accept-line` et al).
(59fbdda64c21) (59fbdda64c21)

View File

@@ -49,29 +49,49 @@ highlighter's documentation for details and examples.
How to implement a new highlighter How to implement a new highlighter
---------------------------------- ----------------------------------
To create your own `myhighlighter` highlighter: To create your own `acme` highlighter:
* Create your script at * Create your script at
`highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. `highlighters/acme/acme-highlighter.zsh`.
* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. * Implement the `_zsh_highlight_highlighter_acme_predicate` function.
This function must return 0 when the highlighter needs to be called and This function must return 0 when the highlighter needs to be called and
non-zero otherwise, for example: non-zero otherwise, for example:
_zsh_highlight_myhighlighter_highlighter_predicate() { _zsh_highlight_highlighter_acme_predicate() {
# Call this highlighter in SVN working copies # Call this highlighter in SVN working copies
[[ -d .svn ]] [[ -d .svn ]]
} }
* Implement the `_zsh_highlight_myhighlighter_highlighter` function. * Implement the `_zsh_highlight_highlighter_acme_paint` function.
This function does the actual syntax highlighting, by modifying This function does the actual syntax highlighting, by calling
`region_highlight`, for example: `_zsh_highlight_add_highlight` with the start and end of the region to
be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default
style for that key in the highlighter script outside of any function with
`: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix
the key with your highlighter name and a colon. For example:
_zsh_highlight_myhighlighter_highlighter() { : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green}
# Colorize the whole buffer with blue background
region_highlight+=(0 $#BUFFER bg=blue) _zsh_highlight_highlighter_acme_paint() {
# Colorize the whole buffer with the 'aurora' style
_zsh_highlight_add_highlight 0 $#BUFFER acme:aurora
} }
* Name your own functions and global variables `_zsh_highlight_acme_*`.
- In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints
`_zsh_highlight_highlighter_acme_predicate` and
`_zsh_highlight_highlighter_acme_paint`
were named
`_zsh_highlight_acme_highlighter_predicate` and
`_zsh_highlight_highlighter_acme_paint` respectively.
These names are still supported for backwards compatibility;
however, support for them will be removed in a a future major or minor release (v0.x.0 or v1.0.0).
* Activate your highlighter in `~/.zshrc`: * Activate your highlighter in `~/.zshrc`:
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme)
* [Write tests](../tests/README.md).

View File

@@ -27,7 +27,9 @@ This highlighter defines the following styles:
* `commandseparator` - command separation tokens (`;`, `&&`) * `commandseparator` - command separation tokens (`;`, `&&`)
* `hashed-command` - hashed commands * `hashed-command` - hashed commands
* `path` - existing filenames * `path` - existing filenames
* `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default)
* `path_prefix` - prefixes of existing filenames * `path_prefix` - prefixes of existing filenames
* `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default)
* `globbing` - globbing expressions (`*.txt`) * `globbing` - globbing expressions (`*.txt`)
* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`)
* `single-hyphen-option` - single hyphen options (`-o`) * `single-hyphen-option` - single hyphen options (`-o`)
@@ -42,6 +44,7 @@ This highlighter defines the following styles:
* `assign` - parameter assignments * `assign` - parameter assignments
* `redirection` - redirection operators (`<`, `>`, etc) * `redirection` - redirection operators (`<`, `>`, etc)
* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
* `arg0` - a command word other than one of those enumrated above (other than a command, precommand, alias, function, or shell builtin command).
* `default` - everything else * `default` - everything else
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
@@ -63,4 +66,26 @@ The syntax for values is the same as the syntax of "types of highlighting" of
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
manual page][zshzle-Character-Highlighting]. manual page][zshzle-Character-Highlighting].
### Useless trivia
#### Forward compatibility.
zsh-syntax-highlighting attempts to be forward-compatible with zsh.
Specifically, we attempt to facilitate highlighting _command word_ types that
had not yet been invented when this version of zsh-syntax-highlighting was
released.
A _command word_ is something like a function name, external command name, et
cetera. (See
[Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines]
for a formal definition.)
If a new _kind_ of command word is ever added to zsh — something conceptually
different than "function" and "alias" and "external command" — then command words
of that (new) kind will be highlighted by the style `arg0_$kind`,
where `$kind` is the output of `type -w` on the new kind of command word. If that
style is not defined, then the style `arg0` will be used instead.
[zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting

View File

@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted # Redistribution and use in source and binary forms, with or without modification, are permitted
@@ -38,73 +38,70 @@
: ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout} : ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout}
# Whether the brackets highlighter should be called or not. # Whether the brackets highlighter should be called or not.
_zsh_highlight_brackets_highlighter_predicate() _zsh_highlight_highlighter_brackets_predicate()
{ {
_zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified
} }
# Brackets highlighting function. # Brackets highlighting function.
_zsh_highlight_brackets_highlighter() _zsh_highlight_highlighter_brackets_paint()
{ {
local level=0 pos local char style
local -A levelpos lastoflevel matching typepos local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos
region_highlight=() local -A levelpos lastoflevel matching
# Find all brackets and remember which one is matching # Find all brackets and remember which one is matching
for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do for (( pos = 1; pos <= buflen; pos++ )) ; do
local char="$BUFFER[pos+1]" char=$BUFFER[pos]
case $char in case $char in
["([{"]) ["([{"])
levelpos[$pos]=$((++level)) levelpos[$pos]=$((++level))
lastoflevel[$level]=$pos lastoflevel[$level]=$pos
_zsh_highlight_brackets_highlighter_brackettype "$char"
;; ;;
[")]}"]) [")]}"])
matching[$lastoflevel[$level]]=$pos matchingpos=$lastoflevel[$level]
matching[$pos]=$lastoflevel[$level]
levelpos[$pos]=$((level--)) levelpos[$pos]=$((level--))
_zsh_highlight_brackets_highlighter_brackettype "$char" if _zsh_highlight_brackets_match $matchingpos $pos; then
matching[$matchingpos]=$pos
matching[$pos]=$matchingpos
fi
;; ;;
['"'\']) ['"'\'])
# Skip everything inside quotes # Skip everything inside quotes
local quotetype=$char pos=$BUFFER[(ib:pos+1:)$char]
while (( $pos < ${#BUFFER} )) ; do
(( pos++ ))
[[ $BUFFER[$pos+1] == $quotetype ]] && break
done
;; ;;
esac esac
done done
# Now highlight all found brackets # Now highlight all found brackets
for pos in ${(k)levelpos}; do for pos in ${(k)levelpos}; do
if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then if (( $+matching[$pos] )); then
local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} if (( bracket_color_size )); then
local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 ))
local style=$ZSH_HIGHLIGHT_STYLES[$bracket_color_level]
region_highlight+=("$pos $((pos + 1)) $style")
else
local style=$ZSH_HIGHLIGHT_STYLES[bracket-error]
region_highlight+=("$pos $((pos + 1)) $style")
fi fi
else
style=bracket-error
fi
_zsh_highlight_add_highlight $((pos - 1)) $pos $style
done done
# If cursor is on a bracket, then highlight corresponding bracket, if any # If cursor is on a bracket, then highlight corresponding bracket, if any.
pos=$CURSOR if [[ $WIDGET != zle-line-finish ]]; then
pos=$((CURSOR + 1))
if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then
local otherpos=$matching[$pos] local -i otherpos=$matching[$pos]
local style=$ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket] _zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket
region_highlight+=("$otherpos $((otherpos + 1)) $style") fi
fi fi
} }
# Helper function to differentiate type # Helper function to differentiate type
_zsh_highlight_brackets_highlighter_brackettype() _zsh_highlight_brackets_match()
{ {
case $1 in case $BUFFER[$1] in
["()"]) typepos[$pos]=round;; \() [[ $BUFFER[$2] == \) ]];;
["[]"]) typepos[$pos]=bracket;; \[) [[ $BUFFER[$2] == \] ]];;
["{}"]) typepos[$pos]=curly;; \{) [[ $BUFFER[$2] == \} ]];;
*) ;; *) false;;
esac esac
} }

View File

@@ -0,0 +1,37 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
WIDGET=zle-line-finish
BUFFER=': $foo[bar]'
CURSOR=6 # cursor is zero-based
expected_region_highlight=(
"11 11 NONE"
)

View File

@@ -0,0 +1,39 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=
BUFFER=': ((( )))'
CURSOR=2 # cursor is zero-based
expected_region_highlight=(
"9 9 cursor-matchingbracket"
)

View File

@@ -0,0 +1,34 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=': (x)'
expected_region_highlight=(
"1 5 NONE"
)

View File

@@ -0,0 +1,51 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=
BUFFER=': ({[({[(x)]})]})'
expected_region_highlight=(
"3 3 bracket-level-1"
"4 4 bracket-level-2"
"5 5 bracket-level-3"
"6 6 bracket-level-1"
"7 7 bracket-level-2"
"8 8 bracket-level-3"
"9 9 bracket-level-1"
"11 11 bracket-level-1"
"12 12 bracket-level-3"
"13 13 bracket-level-2"
"14 14 bracket-level-1"
"15 15 bracket-level-3"
"16 16 bracket-level-2"
"17 17 bracket-level-1"
)

View File

@@ -27,11 +27,14 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
BUFFER='echo ({x}]' BUFFER='echo ({x}]'
expected_region_highlight=( expected_region_highlight=(
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( "6 6 bracket-error" # (
"7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { "7 7 bracket-level-2" # {
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } "9 9 bracket-level-2" # }
"10 10 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) "10 10 bracket-error" # )
) )

View File

@@ -0,0 +1,38 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
BUFFER=': {"{x}"}'
expected_region_highlight=(
"3 3 bracket-level-1"
"4 8 NONE"
"9 9 bracket-level-1"
)

View File

@@ -27,13 +27,17 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=
BUFFER='echo $(echo ${(z)array})' BUFFER='echo $(echo ${(z)array})'
expected_region_highlight=( expected_region_highlight=(
"7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( "7 7 bracket-level-1" # (
"14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { "14 14 bracket-level-2" # {
"15 15 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ( "15 15 bracket-level-3" # (
"17 17 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ) "17 17 bracket-level-3" # )
"23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } "23 23 bracket-level-2" # }
"24 24 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) "24 24 bracket-level-1" # )
) )

View File

@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
BUFFER=': "\"{x"'
expected_region_highlight=(
"3 9 NONE 'issue #303'"
)

View File

@@ -30,5 +30,5 @@
BUFFER='echo "foo ( bar"' BUFFER='echo "foo ( bar"'
expected_region_highlight=( expected_region_highlight=(
"1 16 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing "1 16 NONE" # We expect the brackets highlighter to do nothing
) )

View File

@@ -27,11 +27,14 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
BUFFER='echo ({x})' BUFFER='echo ({x})'
expected_region_highlight=( expected_region_highlight=(
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( "6 6 bracket-level-1" # (
"7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { "7 7 bracket-level-2" # {
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } "9 9 bracket-level-2" # }
"10 10 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) "10 10 bracket-level-1" # )
) )

View File

@@ -27,10 +27,13 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
BUFFER='echo ({x}' BUFFER='echo ({x}'
expected_region_highlight=( expected_region_highlight=(
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( "6 6 bracket-error" # (
"7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { "7 7 bracket-level-2" # {
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } "9 9 bracket-level-2" # }
) )

View File

@@ -27,10 +27,12 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
BUFFER='echo {x})' BUFFER='echo {x})'
expected_region_highlight=( expected_region_highlight=(
"6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # { "6 6 bracket-level-1" # {
"8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # } "8 8 bracket-level-1" # }
"9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) "9 9 bracket-error" # )
) )

View File

@@ -32,17 +32,16 @@
: ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout} : ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout}
# Whether the cursor highlighter should be called or not. # Whether the cursor highlighter should be called or not.
_zsh_highlight_cursor_highlighter_predicate() _zsh_highlight_highlighter_cursor_predicate()
{ {
# accept-* may trigger removal of cursor highlighting # remove cursor highlighting when the line is finished
[[ $WIDGET == accept-* ]] || [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved
_zsh_highlight_cursor_moved
} }
# Cursor highlighting function. # Cursor highlighting function.
_zsh_highlight_cursor_highlighter() _zsh_highlight_highlighter_cursor_paint()
{ {
[[ $WIDGET == accept-* ]] && return [[ $WIDGET == zle-line-finish ]] && return
region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]") _zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor
} }

View File

@@ -32,13 +32,13 @@
: ${ZSH_HIGHLIGHT_STYLES[line]:=} : ${ZSH_HIGHLIGHT_STYLES[line]:=}
# Whether the root highlighter should be called or not. # Whether the root highlighter should be called or not.
_zsh_highlight_line_highlighter_predicate() _zsh_highlight_highlighter_line_predicate()
{ {
_zsh_highlight_buffer_modified _zsh_highlight_buffer_modified
} }
# root highlighting function. # root highlighting function.
_zsh_highlight_line_highlighter() _zsh_highlight_highlighter_line_paint()
{ {
region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[line]") _zsh_highlight_add_highlight 0 $#BUFFER line
} }

View File

@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Copyright (c) 2010-2015 zsh-syntax-highlighting contributors # Copyright (c) 2010-2016 zsh-syntax-highlighting contributors
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without modification, are permitted # Redistribution and use in source and binary forms, with or without modification, are permitted
@@ -32,16 +32,12 @@
: ${ZSH_HIGHLIGHT_STYLES[default]:=none} : ${ZSH_HIGHLIGHT_STYLES[default]:=none}
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} : ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
: ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=}
: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=}
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
: ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none}
@@ -56,19 +52,46 @@
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} : ${ZSH_HIGHLIGHT_STYLES[redirection]:=none}
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} : ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
: ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green}
# Whether the highlighter should be called or not. # Whether the highlighter should be called or not.
_zsh_highlight_main_highlighter_predicate() _zsh_highlight_highlighter_main_predicate()
{ {
# accept-* may trigger removal of path_prefix highlighting # may need to remove path_prefix highlighting when the line ends
[[ $WIDGET == accept-* ]] || [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified
_zsh_highlight_buffer_modified
} }
# Helper to deal with tokens crossing line boundaries. # Helper to deal with tokens crossing line boundaries.
_zsh_highlight_main_add_region_highlight() { _zsh_highlight_main_add_region_highlight() {
integer start=$1 end=$2 integer start=$1 end=$2
local style=$3 shift 2
if (( $+argv[2] )); then
# Caller specified inheritance explicitly.
else
# Automate inheritance.
typeset -A fallback_of; fallback_of=(
alias arg0
suffix-alias arg0
builtin arg0
function arg0
command arg0
precommand arg0
hashed-command arg0
path_prefix path
# The path separator fallback won't ever be used, due to the optimisation
# in _zsh_highlight_main_highlighter_highlight_path_separators().
path_pathseparator path
path_prefix_pathseparator path_prefix
)
local needle=$1 value
while [[ -n ${value::=$fallback_of[$needle]} ]]; do
unset "fallback_of[$needle]" # paranoia against infinite loops
argv+=($value)
needle=$value
done
fi
# The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is
# relative to $BUFFER. # relative to $BUFFER.
@@ -77,37 +100,131 @@ _zsh_highlight_main_add_region_highlight() {
(( end < 0 )) && return # having end<0 would be a bug (( end < 0 )) && return # having end<0 would be a bug
(( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings
region_highlight+=("$start $end $style") _zsh_highlight_add_highlight $start $end "$@"
} }
# Wrapper around 'type -w'. # Get the type of a command.
# #
# Takes a single argument and outputs the output of 'type -w $1'. # Uses the zsh/parameter module if available to avoid forks, and a
# wrapper around 'type -w' as fallback.
# #
# NOTE: This runs 'setopt', but that should be safe since it'll only ever be # Takes a single argument.
# called inside a $(...) subshell, so the effects will be local. #
# The result will be stored in REPLY.
_zsh_highlight_main__type() { _zsh_highlight_main__type() {
if (( $#options_to_set )); then if (( $+_zsh_highlight_main__command_type_cache )); then
setopt $options_to_set; REPLY=$_zsh_highlight_main__command_type_cache[(e)$1]
if [[ -n "$REPLY" ]]; then
return
fi
fi
if (( $#options_to_set )); then
setopt localoptions $options_to_set;
fi
unset REPLY
if zmodload -e zsh/parameter; then
if (( $+aliases[(e)$1] )); then
REPLY=alias
elif (( $+saliases[(e)${1##*.}] )); then
REPLY='suffix alias'
elif (( $reswords[(Ie)$1] )); then
REPLY=reserved
elif (( $+functions[(e)$1] )); then
REPLY=function
elif (( $+builtins[(e)$1] )); then
REPLY=builtin
elif (( $+commands[(e)$1] )); then
REPLY=command
# zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly
# runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo
# exists and is in $PATH). Avoid triggering the bug, at the expense of
# falling through to the $() below, incurring a fork. (Issue #354.)
#
# The first disjunct mimics the isrelative() C call from the zsh bug.
elif { [[ $1 != */* ]] || is-at-least 5.3 } &&
! builtin type -w -- $1 >/dev/null 2>&1; then
REPLY=none
fi
fi
if ! (( $+REPLY )); then
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }"
fi
if (( $+_zsh_highlight_main__command_type_cache )); then
_zsh_highlight_main__command_type_cache[(e)$1]=$REPLY
fi
}
# Check whether the first argument is a redirection operator token.
# Report result via the exit code.
_zsh_highlight_main__is_redirection() {
# A redirection operator token:
# - starts with an optional single-digit number;
# - then, has a '<' or '>' character;
# - is not a process substitution [<(...) or >(...)].
[[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]]
}
# Resolve alias.
#
# Takes a single argument.
#
# The result will be stored in REPLY.
_zsh_highlight_main__resolve_alias() {
if zmodload -e zsh/parameter; then
REPLY=${aliases[$arg]}
else
REPLY="${"$(alias -- $arg)"#*=}"
fi
}
# Check that the top of $braces_stack has the expected value. If it does, set
# the style according to $2; otherwise, set style=unknown-token.
#
# $1: character expected to be at the top of $braces_stack
# $2: assignment to execute it if matches
_zsh_highlight_main__stack_pop() {
if [[ $braces_stack[1] == $1 ]]; then
braces_stack=${braces_stack:1}
eval "$2"
else
style=unknown-token
fi fi
LC_ALL=C builtin type -w -- $1 2>/dev/null
} }
# Main syntax highlighting function. # Main syntax highlighting function.
_zsh_highlight_main_highlighter() _zsh_highlight_highlighter_main_paint()
{ {
## Before we even 'emulate -L', we must test a few options that would reset. ## Before we even 'emulate -L', we must test a few options that would reset.
if [[ -o interactive_comments ]]; then if [[ -o interactive_comments ]]; then
local interactive_comments= # set to empty local interactive_comments= # set to empty
fi fi
if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then
local right_brace_is_recognised_everywhere=false
else
local right_brace_is_recognised_everywhere=true
fi
if [[ -o path_dirs ]]; then if [[ -o path_dirs ]]; then
integer path_dirs_was_set=1 integer path_dirs_was_set=1
else else
integer path_dirs_was_set=0 integer path_dirs_was_set=0
fi fi
if [[ -o multi_func_def ]]; then
integer multi_func_def=1
else
integer multi_func_def=0
fi
emulate -L zsh emulate -L zsh
setopt localoptions extendedglob bareglobqual setopt localoptions extendedglob bareglobqual
# At the PS3 prompt and in vared, highlight nothing.
#
# (We can't check this in _zsh_highlight_highlighter_main_predicate because
# if the predicate returns false, the previous value of region_highlight
# would be reused.)
if [[ $CONTEXT == (select|vared) ]]; then
return
fi
## Variable declarations and initializations ## Variable declarations and initializations
local start_pos=0 end_pos highlight_glob=true arg style local start_pos=0 end_pos highlight_glob=true arg style
local in_array_assignment=false # true between 'a=(' and the matching ')' local in_array_assignment=false # true between 'a=(' and the matching ')'
@@ -116,7 +233,15 @@ _zsh_highlight_main_highlighter()
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
local -a options_to_set # used in callees local -a options_to_set # used in callees
local buf="$PREBUFFER$BUFFER" local buf="$PREBUFFER$BUFFER"
region_highlight=() integer len="${#buf}"
integer pure_buf_len=$(( len - ${#PREBUFFER} )) # == $#BUFFER, used e.g. in *_check_path
# "R" for round
# "Q" for square
# "Y" for curly
# "D" for do/done
# "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while)
local braces_stack
if (( path_dirs_was_set )); then if (( path_dirs_was_set )); then
options_to_set+=( PATH_DIRS ) options_to_set+=( PATH_DIRS )
@@ -132,6 +257,7 @@ _zsh_highlight_main_highlighter()
) )
ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=(
'builtin' 'command' 'exec' 'nocorrect' 'noglob' 'builtin' 'command' 'exec' 'nocorrect' 'noglob'
'pkexec' # immune to #121 because it's usually not passed --option flags
) )
# Tokens that, at (naively-determined) "command position", are followed by # Tokens that, at (naively-determined) "command position", are followed by
@@ -152,6 +278,8 @@ _zsh_highlight_main_highlighter()
'!' # reserved word; unrelated to $histchars[1] '!' # reserved word; unrelated to $histchars[1]
) )
local -a match mbegin mend
# State machine # State machine
# #
# The states are: # The states are:
@@ -162,6 +290,7 @@ _zsh_highlight_main_highlighter()
# words) but not in "-ufoo" (one word). # words) but not in "-ufoo" (one word).
# - :regular: "Not a command word", and command delimiters are permitted. # - :regular: "Not a command word", and command delimiters are permitted.
# Mainly used to detect premature termination of commands. # Mainly used to detect premature termination of commands.
# - :always: The word 'always' in the «{ foo } always { bar }» syntax.
# #
# When the kind of a word is not yet known, $this_word / $next_word may contain # When the kind of a word is not yet known, $this_word / $next_word may contain
# multiple states. For example, after "sudo -i", the next word may be either # multiple states. For example, after "sudo -i", the next word may be either
@@ -189,8 +318,11 @@ _zsh_highlight_main_highlighter()
# #
local this_word=':start:' next_word local this_word=':start:' next_word
integer in_redirection integer in_redirection
# Processing buffer
local proc_buf="$buf"
for arg in ${interactive_comments-${(z)buf}} \ for arg in ${interactive_comments-${(z)buf}} \
${interactive_comments+${(zZ+c+)buf}}; do ${interactive_comments+${(zZ+c+)buf}}; do
# Initialize $next_word.
if (( in_redirection )); then if (( in_redirection )); then
(( --in_redirection )) (( --in_redirection ))
fi fi
@@ -200,12 +332,20 @@ _zsh_highlight_main_highlighter()
else else
# Stall $next_word. # Stall $next_word.
fi fi
# Initialize per-"simple command" [zshmisc(1)] variables:
#
# $already_added (see next paragraph)
# $style how to highlight $arg
# $in_array_assignment boolean flag for "between '(' and ')' of array assignment"
# $highlight_glob boolean flag for "'noglob' is in effect"
#
# $already_added is set to 1 to disable adding an entry to region_highlight # $already_added is set to 1 to disable adding an entry to region_highlight
# for this iteration. Currently, that is done for "" and $'' strings, # for this iteration. Currently, that is done for "" and $'' strings,
# which add the entry early so escape sequences within the string override # which add the entry early so escape sequences within the string override
# the string's color. # the string's color.
integer already_added=0 integer already_added=0
local style_override="" style=unknown-token
if [[ $this_word == *':start:'* ]]; then if [[ $this_word == *':start:'* ]]; then
in_array_assignment=false in_array_assignment=false
if [[ $arg == 'noglob' ]]; then if [[ $arg == 'noglob' ]]; then
@@ -213,7 +353,7 @@ _zsh_highlight_main_highlighter()
fi fi
fi fi
# advance $start_pos, skipping over whitespace in $buf. # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf.
if [[ $arg == ';' ]] ; then if [[ $arg == ';' ]] ; then
# We're looking for either a semicolon or a newline, whichever comes # We're looking for either a semicolon or a newline, whichever comes
# first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..}
@@ -224,25 +364,76 @@ _zsh_highlight_main_highlighter()
# indistinguishable from 'echo foo echo bar' (one command with three # indistinguishable from 'echo foo echo bar' (one command with three
# words for arguments). # words for arguments).
local needle=$'[;\n]' local needle=$'[;\n]'
integer offset=${${buf[start_pos+1,-1]}[(i)$needle]} integer offset=$(( ${proc_buf[(i)$needle]} - 1 ))
(( start_pos += offset - 1 )) (( start_pos += offset ))
(( end_pos = start_pos + $#arg )) (( end_pos = start_pos + $#arg ))
else else
((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) # The line was:
#
# integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}}))
#
# - len-start_pos is length of current proc_buf; basically: initial length minus where
# we are, and proc_buf is chopped to the "where we are" (compare the "previous value
# of start_pos" below, and the len-(start_pos-offset) = len-start_pos+offset)
# - what's after main minus sign is: length of proc_buf without spaces at the beginning
# - so what the line actually did, was computing length of the spaces!
# - this can be done via (#b) flag, like below
if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\[[:space:]])##)* ]]; then
# The first, outer parenthesis
integer offset="${#match[1]}"
else
integer offset=0
fi
((start_pos+=offset))
((end_pos=$start_pos+${#arg})) ((end_pos=$start_pos+${#arg}))
fi fi
# Compute the new $proc_buf. We advance it
# (chop off characters from the beginning)
# beyond what end_pos points to, by skipping
# as many characters as end_pos was advanced.
#
# end_pos was advanced by $offset (via start_pos)
# and by $#arg. Note the `start_pos=$end_pos`
# below.
#
# As for the [,len]. We could use [,len-start_pos+offset]
# here, but to make it easier on eyes, we use len and
# rely on the fact that Zsh simply handles that. The
# length of proc_buf is len-start_pos+offset because
# we're chopping it to match current start_pos, so its
# length matches the previous value of start_pos.
#
# Why [,-1] is slower than [,length] isn't clear.
proc_buf="${proc_buf[offset + $#arg + 1,len]}"
# Handle the INTERACTIVE_COMMENTS option.
#
# We use the (Z+c+) flag so the entire comment is presented as one token in $arg.
if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then
if [[ $this_word == *(':regular:'|':start:')* ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then
style=$ZSH_HIGHLIGHT_STYLES[comment] style=comment
else else
style=$ZSH_HIGHLIGHT_STYLES[unknown-token] # prematurely terminated style=unknown-token # prematurely terminated
fi fi
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
already_added=1 already_added=1
continue continue
fi fi
# Analyse the current word.
if _zsh_highlight_main__is_redirection $arg ; then
# A '<' or '>', possibly followed by a digit
in_redirection=2
fi
# Special-case the first word after 'sudo'.
if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then
this_word=${this_word//:sudo_opt:/}
fi
fi
# Parse the sudo command line # Parse the sudo command line
if (( ! in_redirection )); then if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]]; then if [[ $this_word == *':sudo_opt:'* ]]; then
@@ -262,18 +453,24 @@ _zsh_highlight_main_highlighter()
fi fi
fi fi
if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word # The Great Fork: is this a command word? Is this a non-command word?
if [[ $this_word == *':always:'* && $arg == 'always' ]]; then
# try-always construct
style=reserved-word # de facto a reserved word, although not de jure
next_word=':start:'
elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then
style=$ZSH_HIGHLIGHT_STYLES[precommand] style=precommand
elif [[ "$arg" = "sudo" ]]; then elif [[ "$arg" = "sudo" ]]; then
style=$ZSH_HIGHLIGHT_STYLES[precommand] style=precommand
next_word=${next_word//:regular:/} next_word=${next_word//:regular:/}
next_word+=':sudo_opt:' next_word+=':sudo_opt:'
next_word+=':start:' next_word+=':start:'
else else
_zsh_highlight_main_highlighter_expand_path $arg _zsh_highlight_main_highlighter_expand_path $arg
local expanded_arg="$REPLY" local expanded_arg="$REPLY"
local res="$(_zsh_highlight_main__type ${expanded_arg})" _zsh_highlight_main__type ${expanded_arg}
local res="$REPLY"
() { () {
# Special-case: command word is '$foo', like that, without braces or anything. # Special-case: command word is '$foo', like that, without braces or anything.
# #
@@ -283,26 +480,73 @@ _zsh_highlight_main_highlighter()
# parameters that refer to commands, functions, and builtins. # parameters that refer to commands, functions, and builtins.
local -a match mbegin mend local -a match mbegin mend
local MATCH; integer MBEGIN MEND local MATCH; integer MBEGIN MEND
if [[ $res == *': none' ]] && (( ${+parameters} )) && if [[ $res == none ]] && (( ${+parameters} )) &&
[[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]]; then [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] &&
res="$(_zsh_highlight_main__type ${(P)MATCH})" (( ${+parameters[${MATCH}]} ))
then
_zsh_highlight_main__type ${(P)MATCH}
res=$REPLY
fi fi
} }
case $res in case $res in
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; reserved) # reserved word
*': suffix alias') style=reserved-word
style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] case $arg in
($'\x7b')
braces_stack='Y'"$braces_stack"
;; ;;
*': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] ($'\x7d')
local aliased_command="${"$(alias -- $arg)"#*=}" # We're at command word, so no need to check $right_brace_is_recognised_everywhere
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) _zsh_highlight_main__stack_pop 'Y' style=reserved-word
if [[ $style == reserved-word ]]; then
next_word+=':always:'
fi
;; ;;
*': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; ('do')
*': function') style=$ZSH_HIGHLIGHT_STYLES[function];; braces_stack='D'"$braces_stack"
*': command') style=$ZSH_HIGHLIGHT_STYLES[command];; ;;
*': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; ('done')
*) if _zsh_highlight_main_highlighter_check_assign; then _zsh_highlight_main__stack_pop 'D' style=reserved-word
style=$ZSH_HIGHLIGHT_STYLES[assign] ;;
('foreach')
braces_stack='$'"$braces_stack"
;;
('end')
_zsh_highlight_main__stack_pop '$' style=reserved-word
;;
esac
;;
'suffix alias') style=suffix-alias;;
alias) () {
integer insane_alias
case $arg in
# Issue #263: aliases with '=' on their LHS.
#
# There are three cases:
#
# - Unsupported, breaks 'alias -L' output, but invokable:
('='*) :;;
# - Unsupported, not invokable:
(*'='*) insane_alias=1;;
# - The common case:
(*) :;;
esac
if (( insane_alias )); then
style=unknown-token
else
style=alias
_zsh_highlight_main__resolve_alias $arg
local alias_target="$REPLY"
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$alias_target"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg)
fi
}
;;
builtin) style=builtin;;
function) style=function;;
command) style=command;;
hashed) style=hashed-command;;
none) if _zsh_highlight_main_highlighter_check_assign; then
style=assign
if [[ $arg[-1] == '(' ]]; then if [[ $arg[-1] == '(' ]]; then
in_array_assignment=true in_array_assignment=true
else else
@@ -310,16 +554,20 @@ _zsh_highlight_main_highlighter()
# (For array assignments, the command doesn't start until the ")" token.) # (For array assignments, the command doesn't start until the ")" token.)
next_word+=':start:' next_word+=':start:'
fi fi
elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
style=$ZSH_HIGHLIGHT_STYLES[history-expansion] style=history-expansion
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && elif [[ $arg[0,1] == $histchars[2,2] ]]; then
[[ $this_word == *':regular:'* ]]; then style=history-expansion
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $this_word == *':regular:'* ]]; then
# This highlights empty commands (semicolon follows nothing) as an error. # This highlights empty commands (semicolon follows nothing) as an error.
# Zsh accepts them, though. # Zsh accepts them, though.
style=$ZSH_HIGHLIGHT_STYLES[commandseparator] style=commandseparator
elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then else
style=$ZSH_HIGHLIGHT_STYLES[redirection] style=unknown-token
(( in_redirection=2 )) fi
elif (( in_redirection == 2 )); then
style=redirection
elif [[ $arg[1,2] == '((' ]]; then elif [[ $arg[1,2] == '((' ]]; then
# Arithmetic evaluation. # Arithmetic evaluation.
# #
@@ -330,81 +578,122 @@ _zsh_highlight_main_highlighter()
# #
# We highlight just the opening parentheses, as a reserved word; this # We highlight just the opening parentheses, as a reserved word; this
# is how [[ ... ]] is highlighted, too. # is how [[ ... ]] is highlighted, too.
style=$ZSH_HIGHLIGHT_STYLES[reserved-word] style=reserved-word
_zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style
already_added=1 already_added=1
if [[ $arg[-2,-1] == '))' ]]; then if [[ $arg[-2,-1] == '))' ]]; then
_zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style
already_added=1 already_added=1
fi fi
elif [[ $arg == '()' || $arg == $'\x28' ]]; then elif [[ $arg == '()' ]]; then
# anonymous function # anonymous function
style=reserved-word
elif [[ $arg == $'\x28' ]]; then
# subshell # subshell
style=$ZSH_HIGHLIGHT_STYLES[reserved-word] style=reserved-word
braces_stack='R'"$braces_stack"
elif [[ $arg == $'\x29' ]]; then
# end of subshell
_zsh_highlight_main__stack_pop 'R' style=reserved-word
else else
if _zsh_highlight_main_highlighter_check_path; then if _zsh_highlight_main_highlighter_check_path; then
style=$ZSH_HIGHLIGHT_STYLES[path] style=$REPLY
else else
style=$ZSH_HIGHLIGHT_STYLES[unknown-token] style=unknown-token
fi fi
fi fi
;; ;;
*) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res arg0
already_added=1
;;
esac esac
fi fi
else # $arg is a non-command word fi
if (( ! already_added )) && [[ $style == unknown-token ]] && # not handled by the 'command word' codepath
{ (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] }
then # $arg is a non-command word
case $arg in case $arg in
$'\x29') # subshell or end of array assignment $'\x29') # subshell or end of array assignment
if $in_array_assignment; then if $in_array_assignment; then
style=$ZSH_HIGHLIGHT_STYLES[assign] style=assign
in_array_assignment=false in_array_assignment=false
next_word+=':start:'
else else
style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main__stack_pop 'R' style=reserved-word
fi;; fi;;
$'\x7d') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # block $'\x28\x29') # possibly a function definition
'--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; if (( multi_func_def )) || false # TODO: or if the previous word was a command word
'-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; then
"'"*) style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; next_word+=':start:'
'"'*) style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] fi
style=reserved-word
;;
$'\x7d') # right brace
#
# Parsing rule: # {
#
# Additionally, `tt(})' is recognized in any position if neither the
# tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set."""
if $right_brace_is_recognised_everywhere; then
_zsh_highlight_main__stack_pop 'Y' style=reserved-word
if [[ $style == reserved-word ]]; then
next_word+=':always:'
fi
else
# Fall through to the catchall case at the end.
fi
;|
'--'*) style=double-hyphen-option;;
'-'*) style=single-hyphen-option;;
"'"*) style=single-quoted-argument;;
'"'*) style=double-quoted-argument
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
_zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string
already_added=1 already_added=1
;; ;;
\$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] \$\'*) style=dollar-quoted-argument
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
_zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string
already_added=1 already_added=1
;; ;;
'`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; '`'*) style=back-quoted-argument;;
[*?]*|*[^\\][*?]*) [*?]*|*[^\\][*?]*)
$highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; $highlight_glob && style=globbing || style=default;;
*) if false; then *) if false; then
elif [[ $arg[0,1] = $histchars[0,1] ]]; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then
style=$ZSH_HIGHLIGHT_STYLES[history-expansion] # was handled by the $'\x7d' case above
elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then
style=history-expansion
elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $this_word == *':regular:'* ]]; then if [[ $this_word == *':regular:'* ]]; then
style=$ZSH_HIGHLIGHT_STYLES[commandseparator] style=commandseparator
else else
style=$ZSH_HIGHLIGHT_STYLES[unknown-token] style=unknown-token
fi fi
elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then elif (( in_redirection == 2 )); then
style=$ZSH_HIGHLIGHT_STYLES[redirection] style=redirection
(( in_redirection=2 ))
else else
if _zsh_highlight_main_highlighter_check_path; then if _zsh_highlight_main_highlighter_check_path; then
style=$ZSH_HIGHLIGHT_STYLES[path] style=$REPLY
else else
style=$ZSH_HIGHLIGHT_STYLES[default] style=default
fi fi
fi fi
;; ;;
esac esac
fi fi
# if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it if ! (( already_added )); then
[[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
(( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style [[ $style == path || $style == path_prefix ]] && _zsh_highlight_main_highlighter_highlight_path_separators
fi
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then
if [[ $arg == ';' ]] && $in_array_assignment; then
# literal newline inside an array assignment
next_word=':regular:'
else
next_word=':start:' next_word=':start:'
highlight_glob=true highlight_glob=true
fi
elif elif
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] || [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] ||
[[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then
@@ -415,11 +704,19 @@ _zsh_highlight_main_highlighter()
# The redirection mechanism assumes $this_word describes the word # The redirection mechanism assumes $this_word describes the word
# following the redirection. Make it so. # following the redirection. Make it so.
# #
# That word can be a command word with shortloops (`repeat 2 ls`)
# or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`).
#
# The repeat-count word will be handled like a redirection target. # The repeat-count word will be handled like a redirection target.
this_word=':start:' this_word=':start::regular:'
fi fi
start_pos=$end_pos start_pos=$end_pos
(( in_redirection == 0 )) && this_word=$next_word if (( in_redirection == 0 )); then
# This is the default/common codepath.
this_word=$next_word
else
# Stall $this_word.
fi
done done
} }
@@ -427,16 +724,34 @@ _zsh_highlight_main_highlighter()
_zsh_highlight_main_highlighter_check_assign() _zsh_highlight_main_highlighter_check_assign()
{ {
setopt localoptions extended_glob setopt localoptions extended_glob
[[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] ||
[[ $arg == [0-9]##(|[+])=* ]]
}
_zsh_highlight_main_highlighter_highlight_path_separators()
{
local pos style_pathsep
style_pathsep=${style}_pathseparator
[[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$style]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0
for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do
if [[ $BUFFER[pos] == / ]]; then
_zsh_highlight_main_add_region_highlight $((pos - 1)) $pos $style_pathsep
fi
done
} }
# Check if $arg is a path. # Check if $arg is a path.
# If yes, return 0 and in $REPLY the style to use.
# Else, return non-zero (and the contents of $REPLY is undefined).
_zsh_highlight_main_highlighter_check_path() _zsh_highlight_main_highlighter_check_path()
{ {
_zsh_highlight_main_highlighter_expand_path $arg; _zsh_highlight_main_highlighter_expand_path $arg;
local expanded_path="$REPLY" local expanded_path="$REPLY"
REPLY=path
[[ -z $expanded_path ]] && return 1 [[ -z $expanded_path ]] && return 1
[[ -L $expanded_path ]] && return 0
[[ -e $expanded_path ]] && return 0 [[ -e $expanded_path ]] && return 0
# Search the path in CDPATH # Search the path in CDPATH
@@ -446,14 +761,14 @@ _zsh_highlight_main_highlighter_check_path()
done done
# If dirname($arg) doesn't exist, neither does $arg. # If dirname($arg) doesn't exist, neither does $arg.
[[ ! -e ${expanded_path:h} ]] && return 1 [[ ! -d ${expanded_path:h} ]] && return 1
# If this word ends the buffer, check if it's the prefix of a valid path. # If this word ends the buffer, check if it's the prefix of a valid path.
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && if [[ ${BUFFER[1]} != "-" && $pure_buf_len == $end_pos ]] &&
[[ $WIDGET != accept-* ]]; then [[ $WIDGET != zle-line-finish ]]; then
local -a tmp local -a tmp
tmp=( ${expanded_path}*(N) ) tmp=( ${expanded_path}*(N) )
(( $#tmp > 0 )) && style_override=path_prefix && return 0 (( $#tmp > 0 )) && REPLY=path_prefix && return 0
fi fi
# It's not a path. # It's not a path.
@@ -472,7 +787,7 @@ _zsh_highlight_main_highlighter_highlight_string()
(( j = i + start_pos - 1 )) (( j = i + start_pos - 1 ))
(( k = j + 1 )) (( k = j + 1 ))
case "$arg[$i]" in case "$arg[$i]" in
'$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] '$' ) style=dollar-double-quoted-argument
# Look for an alphanumeric parameter name. # Look for an alphanumeric parameter name.
if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then
(( k += $#MATCH )) # highlight the parameter name (( k += $#MATCH )) # highlight the parameter name
@@ -480,12 +795,22 @@ _zsh_highlight_main_highlighter_highlight_string()
elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then
(( k += $#MATCH )) # highlight the parameter name and braces (( k += $#MATCH )) # highlight the parameter name and braces
(( i += $#MATCH )) # skip past it (( i += $#MATCH )) # skip past it
elif [[ $arg[i+1] == '$' ]]; then
# $$ - pid
(( k += 1 )) # highlight both dollar signs
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
elif [[ $arg[i+1] == [-#*@?] ]]; then
# $#, $*, $@, $?, $- - like $$ above
(( k += 1 )) # highlight both dollar signs
(( i += 1 )) # don't consider the second one as introducing another parameter expansion
elif [[ $arg[i+1] == $'\x28' ]]; then
# Highlight just the '$'.
else else
continue continue
fi fi
;; ;;
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] "\\") style=back-double-quoted-argument
if [[ \\\`\"\$ == *$arg[$i+1]* ]]; then if [[ \\\`\"\$${histchars[1]} == *$arg[$i+1]* ]]; then
(( k += 1 )) # Color following char too. (( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char. (( i += 1 )) # Skip parsing the escaped char.
else else
@@ -513,7 +838,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string()
(( j = i + start_pos - 1 )) (( j = i + start_pos - 1 ))
(( k = j + 1 )) (( k = j + 1 ))
case "$arg[$i]" in case "$arg[$i]" in
"\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] "\\") style=back-dollar-quoted-argument
for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do
[[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break
done done
@@ -529,7 +854,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string()
else else
if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then
# \x not followed by hex digits is probably an error # \x not followed by hex digits is probably an error
style=$ZSH_HIGHLIGHT_STYLES[unknown-token] style=unknown-token
fi fi
(( k += 1 )) # Color following char too. (( k += 1 )) # Color following char too.
(( i += 1 )) # Skip parsing the escaped char. (( i += 1 )) # Skip parsing the escaped char.
@@ -548,10 +873,28 @@ _zsh_highlight_main_highlighter_highlight_dollar_string()
# Does not perform filename generation (globbing). # Does not perform filename generation (globbing).
_zsh_highlight_main_highlighter_expand_path() _zsh_highlight_main_highlighter_expand_path()
{ {
(( $# == 1 )) || echo "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument" >&2 (( $# == 1 )) || print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument"
# The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}. # The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}.
setopt localoptions nonomatch setopt localoptions nonomatch
unset REPLY unset REPLY
: ${REPLY:=${(Q)~1}} : ${REPLY:=${(Q)~1}}
} }
# -------------------------------------------------------------------------------------------------
# Main highlighter initialization
# -------------------------------------------------------------------------------------------------
_zsh_highlight_main__precmd_hook() {
_zsh_highlight_main__command_type_cache=()
}
autoload -U add-zsh-hook
if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2>/dev/null; then
# Initialize command type cache
typeset -gA _zsh_highlight_main__command_type_cache
else
print -r -- >&2 'zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.'
# Make sure the cache is unset
unset _zsh_highlight_main__command_type_cache
fi

View File

@@ -0,0 +1,37 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# Issue #263 (more-pathological case): aliases[x=y]=z works; the ${(z)} splitter considers
# that a single word; but it's not looked up as an alias. Hence, highlight it as an error.
aliases[x=y]='lorem ipsum dolor sit amet'
BUFFER='x=y ls'
expected_region_highlight=(
"1 3 unknown-token" # x=y
)

View File

@@ -31,7 +31,6 @@ alias alias1="unused expansion"
alias -s alias2="echo" alias -s alias2="echo"
alias1() {} # to check that it's highlighted as an alias, not as a function alias1() {} # to check that it's highlighted as an alias, not as a function
ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight
BUFFER='x.alias2; alias1' BUFFER='x.alias2; alias1'
# Set expected_region_highlight as a function of zsh version. # Set expected_region_highlight as a function of zsh version.
@@ -43,9 +42,9 @@ BUFFER='x.alias2; alias1'
expected_region_highlight=() expected_region_highlight=()
if [[ "$(type -w x.alias2)" == *suffix* ]]; then if [[ "$(type -w x.alias2)" == *suffix* ]]; then
expected_region_highlight+=( expected_region_highlight+=(
"1 8 $ZSH_HIGHLIGHT_STYLES[suffix-alias]" # x.alias2 "1 8 suffix-alias" # x.alias2
) )
fi fi
expected_region_highlight+=( expected_region_highlight+=(
"11 16 $ZSH_HIGHLIGHT_STYLES[alias]" # alias1 "11 16 alias" # alias1
) )

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='{ ls } always { pwd }'
expected_region_highlight=(
'1 1 reserved-word' # {
'3 4 command' # ls
'6 6 reserved-word' # }
'8 13 reserved-word' # always
'15 15 reserved-word' # {
'17 19 builtin' # pwd
'21 21 reserved-word' # }
)

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=$'{\nls\n} always { pwd }'
expected_region_highlight=(
'1 1 reserved-word' # {
'2 2 unknown-token' # \n
'3 4 command' # ls
'5 5 commandseparator' # \n
'6 6 reserved-word' # }
'8 13 reserved-word' # always
'15 15 reserved-word' # {
'17 19 builtin' # pwd
'21 21 reserved-word' # }
)

View File

@@ -0,0 +1,43 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
setopt ignorebraces
BUFFER='echo { foo } always { bar }'
expected_region_highlight=(
'1 4 builtin' # echo
'6 6 default' # {
'8 10 default' # foo
'12 12 default' # }
'14 19 default' # always
'21 21 default' # {
'23 25 default' # bar
'27 27 default' # }
)

View File

@@ -27,14 +27,15 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
BUFFER='() echo hello; () { echo world }' BUFFER='() echo hello; () { echo world } "argument"'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () "1 2 reserved-word" # ()
"4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo "4 7 builtin" # echo
"9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello "9 13 default" # hello
"14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "14 14 commandseparator" # ;
"16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () "16 17 reserved-word" # ()
"19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { "19 19 reserved-word" # {
"21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo "21 24 builtin" # echo
"34 43 double-quoted-argument" # "argument"
) )

View File

@@ -35,6 +35,6 @@
BUFFER='(( x == 42 ))' BUFFER='(( x == 42 ))'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # (( "1 2 reserved-word" # ((
"12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # )) "12 13 reserved-word" # ))
) )

View File

@@ -27,9 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight
BUFFER='a+=(lorem ipsum)' BUFFER='a+=(lorem ipsum)'
expected_region_highlight=( expected_region_highlight=(
"1 4 $ZSH_HIGHLIGHT_STYLES[assign]" # a+=( "1 4 assign" # a+=(
) )

View File

@@ -0,0 +1,35 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='42=foo 43+=bar'
expected_region_highlight=(
"1 6 assign" # 42=foo
"8 14 assign" # 43+=bar
)

View File

@@ -27,12 +27,11 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight
BUFFER='(A=(hello world))' BUFFER='(A=(hello world))'
expected_region_highlight=( expected_region_highlight=(
"1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( "1 1 reserved-word" # (
"2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=( "2 4 assign" # A=(
"16 16 $ZSH_HIGHLIGHT_STYLES[assign]" # ) "16 16 assign" # )
"17 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) "17 17 reserved-word" # )
) )

View File

@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='A=(hello world) ls'
expected_region_highlight=(
"1 3 assign" # A=(
"15 15 assign" # )
"17 18 command" # ls
)

View File

@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='A=(hello world) b=42'
expected_region_highlight=(
"1 3 assign" # A=(
"15 15 assign" # )
"17 20 assign" # b=42
)

View File

@@ -27,10 +27,9 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight
BUFFER='A=1; echo hello world' BUFFER='A=1; echo hello world'
expected_region_highlight=( expected_region_highlight=(
"4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "4 4 commandseparator" # ;
"6 9 $ZSH_HIGHLIGHT_STYLES[command]" # echo "6 9 builtin" # echo
) )

View File

@@ -27,11 +27,10 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight
BUFFER='(A=1)' BUFFER='(A=1)'
expected_region_highlight=( expected_region_highlight=(
"1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( "1 1 reserved-word" # (
"2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 "2 4 assign" # A=1
"5 5 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #231'" # ) "5 5 reserved-word" # )
) )

View File

@@ -27,12 +27,12 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight
BUFFER='A=1 b=("foo" bar)' BUFFER='A=1 b=("foo" bar)'
expected_region_highlight=( expected_region_highlight=(
"1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 "1 3 assign" # A=1
"5 7 $ZSH_HIGHLIGHT_STYLES[assign]" # b=( "5 7 assign" # b=(
"8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" "8 12 double-quoted-argument" # "foo"
"17 17 $ZSH_HIGHLIGHT_STYLES[assign]" # ) "14 16 default" # bar
"17 17 assign" # )
) )

View File

@@ -27,9 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight
BUFFER='echo `echo 42`' BUFFER='echo `echo 42`'
expected_region_highlight=( expected_region_highlight=(
"6 14 $ZSH_HIGHLIGHT_STYLES[back-quoted-argument]" "6 14 back-quoted-argument"
) )

View File

@@ -31,5 +31,5 @@ PREBUFFER=$'echo \\\n'
BUFFER='noglob' BUFFER='noglob'
expected_region_highlight=( expected_region_highlight=(
"1 6 none" # 'noglob' highlighted as a string, not as a precomand "1 6 default" # 'noglob' highlighted as a string, not as a precomand
) )

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=$'() { echo }\n}'
# no special setopts
expected_region_highlight=(
'1 2 reserved-word' # ()
'4 4 reserved-word' # {
'6 9 builtin' # echo
'11 11 reserved-word' # }
'12 12 commandseparator' # \n
'13 13 unknown-token' # }
)

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=$'() { echo }\n}'
setopt ignorebraces
expected_region_highlight=(
'1 2 reserved-word' # ()
'4 4 reserved-word' # {
'6 9 builtin' # echo
'11 11 default' # }
'12 12 commandseparator' # \n
'13 13 reserved-word' # }
)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='() { echo foo )'
expected_region_highlight=(
'1 2 reserved-word' # ()
'4 4 reserved-word' # {
'6 9 builtin' # echo
'11 13 default' # foo
'15 15 unknown-token' # )
)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='() ( echo foo }'
expected_region_highlight=(
'1 2 reserved-word' # ()
'4 4 reserved-word' # (
'6 9 builtin' # echo
'11 13 default' # foo
'15 15 unknown-token' # }
)

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='echo )'
expected_region_highlight=(
'1 4 builtin' # echo
'6 6 unknown-token' # )
)

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='echo }'
expected_region_highlight=(
'1 4 builtin' # echo
'6 6 unknown-token' # }
)

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='echo { }'
expected_region_highlight=(
'1 4 builtin' # echo
'6 6 default' # {
'8 8 unknown-token' # }
)

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='(repeat 1; do)'
expected_region_highlight=(
'1 1 reserved-word' # (
'2 7 reserved-word' # repeat
'9 9 default' # 1
'10 10 commandseparator' # ;
'12 13 reserved-word' # do
'14 14 unknown-token' # )
)

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2012 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='for n in *; do echo $n; end'
expected_region_highlight=(
'1 3 reserved-word' # for
'5 5 default' # n
'7 8 default' # in
'10 10 globbing' # *
'11 11 commandseparator' # ;
'13 14 reserved-word' # do
'16 19 builtin' # echo
'21 22 default' # $n
'23 23 commandseparator' # ;
'25 27 unknown-token' # end
)

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='(ls&)'
expected_region_highlight=(
'1 1 reserved-word' # (
'2 3 command' # ls
'4 4 commandseparator' # &
'5 5 reserved-word' # )
)

View File

@@ -27,13 +27,11 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight
BUFFER=':; pwd &! ls' BUFFER=':; pwd &! ls'
expected_region_highlight=( expected_region_highlight=(
"2 2 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "2 2 commandseparator" # ;
"4 6 $ZSH_HIGHLIGHT_STYLES[builtin]" # pwd "4 6 builtin" # pwd
"8 9 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # &! "8 9 commandseparator" # &!
"11 12 $ZSH_HIGHLIGHT_STYLES[command]" # ls "11 12 command" # ls
) )

View File

@@ -32,6 +32,6 @@ setopt interactive_comments
BUFFER='# echo foo' BUFFER='# echo foo'
expected_region_highlight=( expected_region_highlight=(
"1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # # "1 1 comment" # #
"2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # " echo foo" "2 10 comment" # " echo foo"
) )

View File

@@ -32,7 +32,7 @@ unsetopt interactive_comments
BUFFER='# echo foo' BUFFER='# echo foo'
expected_region_highlight=( expected_region_highlight=(
"1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # # "1 1 unknown-token" # #
"3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" "3 6 default" # " echo foo"
"8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" "8 10 default" # " echo foo"
) )

View File

@@ -32,7 +32,7 @@ setopt interactive_comments
BUFFER='echo "foo #bar" #baz # quux' BUFFER='echo "foo #bar" #baz # quux'
expected_region_highlight=( expected_region_highlight=(
"1 4 $ZSH_HIGHLIGHT_STYLES[command]" # echo "1 4 builtin" # echo
"6 15 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo #bar" "6 15 double-quoted-argument" # "foo #bar"
"17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux "17 27 comment" # #baz # quux
) )

View File

@@ -31,6 +31,6 @@ x=/usr/bin/env
BUFFER='$x "argument"' BUFFER='$x "argument"'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # $x "1 2 command" # $x
"4 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "argument" "4 13 double-quoted-argument" # "argument"
) )

View File

@@ -27,25 +27,24 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight
BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls'
expected_region_highlight+=( expected_region_highlight+=(
"1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while "1 5 reserved-word" # while
"7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if "7 8 reserved-word" # if
"10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "10 13 builtin" # echo
"15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello "15 19 default" # Hello
"22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then "22 25 reserved-word" # then
"27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls "27 28 command" # ls
"30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / "30 30 path" # /
"31 31 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "31 31 commandseparator" # ;
"33 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # else "33 36 reserved-word" # else
"38 39 $ZSH_HIGHLIGHT_STYLES[command]" # ls "38 39 command" # ls
"42 43 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi "42 43 reserved-word" # fi
"46 47 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do "46 47 reserved-word" # do
"49 52 $ZSH_HIGHLIGHT_STYLES[command]" # stat "49 52 command" # stat
"54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" "54 56 double-quoted-argument" # "x"
"59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done "59 62 reserved-word" # done
"65 70 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat "65 70 reserved-word" # repeat
"75 76 $ZSH_HIGHLIGHT_STYLES[command]" # ls "75 76 command" # ls
) )

View File

@@ -0,0 +1,40 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='repeat 42; do ls; done'
expected_region_highlight+=(
"1 6 reserved-word" # repeat
"8 9 default" # 42
"10 10 commandseparator" # ;
"12 13 reserved-word" # do
"15 16 command" # ls
"17 17 commandseparator" # ;
"19 22 reserved-word" # done
)

View File

@@ -0,0 +1,39 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='repeat 42; ls; pwd'
expected_region_highlight+=(
"1 6 reserved-word" # repeat
"8 9 default" # 42
"10 10 commandseparator" # ;
"12 13 command" # ls
"14 14 commandseparator" # ;
"16 18 builtin" # pwd
)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=': "$$ $$foo"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'4 5 dollar-double-quoted-argument' # $$
'7 8 dollar-double-quoted-argument' # $$
'9 12 double-quoted-argument' # foo"
)

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=': "$- $# $* $@ $?"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'4 5 dollar-double-quoted-argument' # $-
'6 6 double-quoted-argument' # <space>
'7 8 dollar-double-quoted-argument' # $#
'9 9 double-quoted-argument' # <space>
'10 11 dollar-double-quoted-argument' # $*
'12 12 double-quoted-argument' # <space>
'13 14 dollar-double-quoted-argument' # $@
'15 15 double-quoted-argument' # <space>
'16 17 dollar-double-quoted-argument' # $?
'18 18 double-quoted-argument' # "
)

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=': "$(:)"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'4 4 dollar-double-quoted-argument' # $
'5 8 double-quoted-argument' # (:)"
)

View File

@@ -27,10 +27,9 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight
BUFFER=": \$'*' 'foo'" BUFFER=": \$'*' 'foo'"
expected_region_highlight=( expected_region_highlight=(
"3 6 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'*' - not a glob "3 6 dollar-quoted-argument" # $'*' - not a glob
"8 12 $ZSH_HIGHLIGHT_STYLES[single-quoted-argument]" # 'foo' "8 12 single-quoted-argument" # 'foo'
) )

View File

@@ -27,15 +27,14 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight
BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'"
expected_region_highlight=( expected_region_highlight=(
"3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo "3 7 dollar-quoted-argument" # $'foo
"8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba "8 11 back-dollar-quoted-argument" # \xba
"12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r "12 12 dollar-quoted-argument" # r
"13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead "13 18 back-dollar-quoted-argument" # \dead
"19 22 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef "19 22 dollar-quoted-argument" # beef
"23 24 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # \u "23 24 unknown-token" # \u
"25 29 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # zzzz' "25 29 dollar-quoted-argument" # zzzz'
) )

View File

@@ -28,11 +28,10 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Similar to double-quoted2.zsh # Similar to double-quoted2.zsh
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight
# This test checks that the '1' gets highlighted correctly. Do not append to the BUFFER. # This test checks that the '1' gets highlighted correctly. Do not append to the BUFFER.
BUFFER=": \$'\xa1" BUFFER=": \$'\xa1"
expected_region_highlight=( expected_region_highlight=(
"3 4 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $' "3 4 dollar-quoted-argument" # $'
"5 8 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xa1 "5 8 back-dollar-quoted-argument" # \xa1
) )

View File

@@ -27,9 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight
BUFFER='hello --world' BUFFER='hello --world'
expected_region_highlight=( expected_region_highlight=(
"7 13 $ZSH_HIGHLIGHT_STYLES[double-hyphen-option]" # --world "7 13 double-hyphen-option" # --world
) )

View File

@@ -31,15 +31,15 @@ BUFFER=': "foo$bar:\`:\":\$:'
BUFFER+=\\\\:\" BUFFER+=\\\\:\"
expected_region_highlight=( expected_region_highlight=(
"3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo "3 6 double-quoted-argument" # "foo
"7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar "7 10 dollar-double-quoted-argument" # $bar
"11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : "11 11 double-quoted-argument" # :
"12 13 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \` "12 13 back-double-quoted-argument" # \`
"14 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : "14 14 double-quoted-argument" # :
"15 16 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \$ "15 16 back-double-quoted-argument" # \$
"17 17 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : "17 17 double-quoted-argument" # :
"18 19 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \" "18 19 back-double-quoted-argument" # \"
"20 20 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : "20 20 double-quoted-argument" # :
"21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \\ "21 22 back-double-quoted-argument" # \\
"23 24 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # :" "23 24 double-quoted-argument" # :"
) )

View File

@@ -32,6 +32,6 @@
BUFFER=': "foo$bar' BUFFER=': "foo$bar'
expected_region_highlight=( expected_region_highlight=(
"3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo "3 6 double-quoted-argument" # "foo
"7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar "7 10 dollar-double-quoted-argument" # $bar
) )

View File

@@ -31,9 +31,9 @@ BUFFER=': "$" "$42foo"'
BUFFER+=\ \"\\\'\\x\" BUFFER+=\ \"\\\'\\x\"
expected_region_highlight=( expected_region_highlight=(
"3 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "$" "3 5 double-quoted-argument" # "$"
"7 7 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " "7 7 double-quoted-argument" # "
"8 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 "8 10 dollar-double-quoted-argument" # $42
"11 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" "11 14 double-quoted-argument" # foo"
"16 21 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "\'\x" - \' and \x are not escape sequences "16 21 double-quoted-argument" # "\'\x" - \' and \x are not escape sequences
) )

View File

@@ -30,7 +30,7 @@
BUFFER=': "${foo}bar"' BUFFER=': "${foo}bar"'
expected_region_highlight=( expected_region_highlight=(
"3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " "3 3 double-quoted-argument" # "
"4 9 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # ${foo} "4 9 dollar-double-quoted-argument" # ${foo}
"10 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # bar" "10 13 double-quoted-argument" # bar"
) )

View File

@@ -30,6 +30,6 @@
BUFFER='echo; ;' BUFFER='echo; ;'
expected_region_highlight=( expected_region_highlight=(
"5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "5 5 commandseparator" # ;
"7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; "7 7 unknown-token" # ;
) )

View File

@@ -0,0 +1,38 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2015 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# Same test data and expectations as empty-command.zsh; the only difference is:
touch ';'
BUFFER='echo; ;'
expected_region_highlight=(
"5 5 commandseparator" # ;
"7 7 unknown-token" # ;
)

View File

@@ -0,0 +1,38 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2015 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='exec {foo}>&/tmp ls'
expected_region_highlight=(
"1 4 precommand" # exec
"6 10 redirection 'issue #238'" # {foo}
"11 12 redirection" # >&
"13 16 path" # /tmp
"18 19 command 'issue #238'" # ls
)

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='f() pwd; f() { balanced braces }'
expected_region_highlight=(
'1 1 TBD "issue #223"' # f
'2 3 reserved-word' # ()
'5 7 builtin' # pwd
'8 8 commandseparator' # ;
'10 10 TBD "issue #223"' # f
'11 12 reserved-word' # ()
'14 14 reserved-word' # {
'16 23 unknown-token' # balanced
'25 30 default' # braces
'32 32 reserved-word' # }
)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='f g h () pwd'
expected_region_highlight=(
'1 1 TBD "issue #223"' # f
'3 3 TBD "issue #223"' # g
'5 5 TBD "issue #223"' # h
'7 8 reserved-word' # ()
'10 12 builtin' # pwd
)

View File

@@ -27,7 +27,6 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[function]=$unused_highlight
cd() { cd() {
builtin cd "$@" builtin cd "$@"
} }
@@ -36,11 +35,9 @@ ls() {
} }
BUFFER='cd;ls' BUFFER='cd;ls'
# Use $unused_highlight to see that function highlighting has precedence over command and builtin
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[function]" # cd "1 2 function" # cd
"4 5 $ZSH_HIGHLIGHT_STYLES[function]" # ls "4 5 function" # ls
) )
# don't 'unfunction cd ls', since cd() and ls() should still be a functions # don't 'unfunction cd ls', since cd() and ls() should still be a functions

View File

@@ -30,9 +30,9 @@
BUFFER=': foo* bar? *baz qux\?' BUFFER=': foo* bar? *baz qux\?'
expected_region_highlight=( expected_region_highlight=(
"1 1 $ZSH_HIGHLIGHT_STYLES[builtin]" # : "1 1 builtin" # :
"3 6 $ZSH_HIGHLIGHT_STYLES[globbing]" # foo* "3 6 globbing" # foo*
"8 11 $ZSH_HIGHLIGHT_STYLES[globbing]" # bar? "8 11 globbing" # bar?
"13 16 $ZSH_HIGHLIGHT_STYLES[globbing]" # *baz "13 16 globbing" # *baz
"18 22 $ZSH_HIGHLIGHT_STYLES[default]" # qux\? "18 22 default" # qux\?
) )

View File

@@ -28,9 +28,8 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
hash zsh_syntax_highlighting_hash=/doesnotexist hash zsh_syntax_highlighting_hash=/doesnotexist
ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight
BUFFER='zsh_syntax_highlighting_hash' BUFFER='zsh_syntax_highlighting_hash'
expected_region_highlight=( expected_region_highlight=(
"1 28 $ZSH_HIGHLIGHT_STYLES[hashed-command]" "1 28 hashed-command 'zsh/parameter cannot distinguish between hashed and command'"
) )

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER='echo "Hello\!"'
expected_region_highlight=(
'1 4 builtin' # echo
'6 11 double-quoted-argument' # "Hello
'12 13 back-double-quoted-argument' # \!
'14 14 double-quoted-argument' # "Hello\!"
)

View File

@@ -27,10 +27,12 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
BUFFER='!foo bar !baz' BUFFER='!foo bar !baz ! ; !'
expected_region_highlight=( expected_region_highlight=(
"1 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo "1 4 history-expansion" # !foo
"6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar "6 8 default" # bar
"10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz "10 13 history-expansion" # !baz
"15 15 default" # ! (before the semicolon)
"19 19 reserved-word" # ! (after the semicolon)
) )

View File

@@ -30,5 +30,5 @@
BUFFER='^foo^bar' BUFFER='^foo^bar'
expected_region_highlight=( expected_region_highlight=(
"1 8 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # ^foo^bar "1 8 history-expansion" # ^foo^bar
) )

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
_zsh_highlight_add_highlight()
{
region_highlight+=("$1 $2 ${(j.,.)argv[3,-1]}")
}
BUFFER='type'
expected_region_highlight=(
'1 4 builtin,arg0' # type
)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
BUFFER=$'foo=(\nbar) env'
expected_region_highlight=(
'1 5 assign' # foo=(
'6 6 commandseparator' # \n
'7 9 default' # bar
'10 10 assign' # )
'12 14 command' # env
)

View File

@@ -31,6 +31,6 @@ PREBUFFER=$'echo "foo1\n'
BUFFER='foo2" ./' BUFFER='foo2" ./'
expected_region_highlight=( expected_region_highlight=(
"1 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' "1 5 double-quoted-argument" # 'foo2"'
"7 8 $ZSH_HIGHLIGHT_STYLES[path]" # './' "7 8 path" # './'
) )

View File

@@ -27,9 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et # vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight
BUFFER=$'echo "foo1\n' BUFFER=$'echo "foo1\n'
expected_region_highlight=( expected_region_highlight=(
"6 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' "6 10 double-quoted-argument" # 'foo2"'
) )

View File

@@ -30,17 +30,17 @@
BUFFER='ps aux | grep java | sort | uniq | tail | head' BUFFER='ps aux | grep java | sort | uniq | tail | head'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps "1 2 command" # ps
"4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux "4 6 default" # aux
"8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | "8 8 commandseparator" # |
"10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep "10 13 command" # grep
"15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java "15 18 default" # java
"20 20 $ZSH_HIGHLIGHT_STYLES[default]" # | "20 20 commandseparator" # |
"22 25 $ZSH_HIGHLIGHT_STYLES[command]" # sort "22 25 command" # sort
"27 27 $ZSH_HIGHLIGHT_STYLES[default]" # | "27 27 commandseparator" # |
"29 32 $ZSH_HIGHLIGHT_STYLES[command]" # uniq "29 32 command" # uniq
"34 34 $ZSH_HIGHLIGHT_STYLES[default]" # | "34 34 commandseparator" # |
"36 39 $ZSH_HIGHLIGHT_STYLES[command]" # tail "36 39 command" # tail
"41 41 $ZSH_HIGHLIGHT_STYLES[default]" # | "41 41 commandseparator" # |
"43 46 $ZSH_HIGHLIGHT_STYLES[command]" # head "43 46 command" # head
) )

View File

@@ -31,5 +31,5 @@ alias x=command
BUFFER='x ls' BUFFER='x ls'
expected_region_highlight=( expected_region_highlight=(
"3 4 $ZSH_HIGHLIGHT_STYLES[command]" # ls "3 4 command" # ls
) )

View File

@@ -30,5 +30,5 @@
BUFFER=':; noglob echo *' BUFFER=':; noglob echo *'
expected_region_highlight=( expected_region_highlight=(
"16 16 $ZSH_HIGHLIGHT_STYLES[default]" # * "16 16 default" # *
) )

View File

@@ -30,6 +30,6 @@
BUFFER='noglob echo *; echo *' BUFFER='noglob echo *; echo *'
expected_region_highlight=( expected_region_highlight=(
"13 13 $ZSH_HIGHLIGHT_STYLES[default]" # * "13 13 default" # *
"21 21 $ZSH_HIGHLIGHT_STYLES[globbing]" # * "21 21 globbing" # *
) )

View File

@@ -0,0 +1,40 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
alias a=A
f() {}
BUFFER='a;f;'
expected_region_highlight=(
"1 1 alias" # f
"2 2 commandseparator" # ;
"3 3 function" # g
"4 4 commandseparator" # ;
)

View File

@@ -37,5 +37,5 @@ path+=( "$PWD"/foo )
BUFFER='bar/testing-issue-228' BUFFER='bar/testing-issue-228'
expected_region_highlight=( expected_region_highlight=(
"1 21 $ZSH_HIGHLIGHT_STYLES[command]" # bar/testing-issue-228 "1 21 command" # bar/testing-issue-228
) )

View File

@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
ln -s /nonexistent broken-symlink
BUFFER=': broken-symlink'
CURSOR=5 # to make path_prefix ineligible
expected_region_highlight=(
"3 16 path" # broken-symlink
)

View File

@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
lambda="''"
touch \$lambda
BUFFER=': \$lambda'
expected_region_highlight=(
"3 8 path" # \$lambda
)

View File

@@ -0,0 +1,53 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# ZSH_HIGHLIGHT_STYLES is empty in tests. The path-separator code however compares its values.
# Make sure the relevant ones are set to something.
ZSH_HIGHLIGHT_STYLES[path_pathseparator]=set
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]=set
mkdir A
touch A/mu
BUFFER='ls /bin/ / A/mu A/m'
expected_region_highlight=(
"4 4 path_pathseparator" # /
"5 7 path" # bin
"8 8 path_pathseparator" # /
"10 10 path_pathseparator" # /
"12 12 path" # A
"13 13 path_pathseparator" # /
"14 15 path" # mu
"17 17 path_prefix" # A
"18 18 path_prefix_pathseparator" # /
"19 19 path_prefix" # m
)

View File

@@ -0,0 +1,39 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
# may be used to endorse or promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
# ZSH_HIGHLIGHT_STYLES is empty in tests. The path-separator code however compares its values.
# For this test, make sure both these styles are set and identical:
ZSH_HIGHLIGHT_STYLES[path]=value
ZSH_HIGHLIGHT_STYLES[path_pathseparator]=value
BUFFER='ls /bin/'
expected_region_highlight=(
"4 8 path" # /bin/
)

View File

@@ -32,6 +32,6 @@ touch "A/mu with spaces"
BUFFER='ls A/mu\ with\ spaces' BUFFER='ls A/mu\ with\ spaces'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls "1 2 command" # ls
"4 19 $ZSH_HIGHLIGHT_STYLES[path]" # A/mu\ with\ spaces "4 19 path" # A/mu\ with\ spaces
) )

View File

@@ -31,6 +31,6 @@ HOME="."
BUFFER='ls ~' BUFFER='ls ~'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls "1 2 command" # ls
"4 4 $ZSH_HIGHLIGHT_STYLES[path]" # ~ "4 4 path" # ~
) )

View File

@@ -31,7 +31,7 @@ HOME="/nonexistent"
BUFFER='ls ~' BUFFER='ls ~'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls "1 2 command" # ls
"4 4 $ZSH_HIGHLIGHT_STYLES[default]" # ~ "4 4 default" # ~
) )

View File

@@ -34,6 +34,6 @@ hash -d D=mydir
BUFFER='ls ~D/path-tilde-named.test' BUFFER='ls ~D/path-tilde-named.test'
expected_region_highlight=( expected_region_highlight=(
"1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls "1 2 command" # ls
"4 27 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.test "4 27 path" # ~D/path-tilde-named.test
) )

Some files were not shown because too many files have changed in this diff Show More