Commit graph

405 commits

Author SHA1 Message Date
Daniel Shahaf
8652a8f4e4 Bump copyright years. 2017-12-25 08:42:30 +00:00
Matthew Martin
bdbe214453 main: Add *-quoted-argument-unclosed styles
Closes #277.
2017-12-24 00:03:55 -06:00
Matthew Martin
dc1b2f6fa4 main: Highlight partially quoted arguments correctly
Closes #130
2017-12-23 14:45:49 -06:00
Matthew Martin
25ae1c0121 main: Add ' helper function 2017-12-23 14:45:47 -06:00
Matthew Martin
dcb115c74c main: Make " and $' helper functions responsible for highlighting quote 2017-12-20 15:52:03 -06:00
Matthew Martin
f623b07fb0 main: Remove trailing whitespace 2017-12-20 15:52:03 -06:00
Matthew Martin
ab1013ae0d main: A redirection token is an invalid redirection target
Closes #466.
2017-12-19 23:01:42 -06:00
Matthew Martin
b07ada1255 driver: Run under emulate -L zsh and add zsyh_user_options 2017-12-16 09:33:51 -06:00
Matthew Martin
2411195c20 main: Expand paths before removing quoting
Fixes highlighting of `ls \~`. Closes #328.
2017-12-12 07:58:35 -06:00
Matthew Martin
6a6d40208c main: Add fallback for useroptions if zsh/parameter is absent 2017-12-11 07:26:54 -06:00
Daniel Shahaf
fb948f5331 noop: Add comments. 2017-12-07 03:06:56 +00:00
Daniel Shahaf
26a82113b0 'main': Highlight 'sudo' correctly when it's not installed.
No test because _zsh_highlight_main__type() falls back to 'type -w' which runs
'rehash' implicitly, so on systems where 'sudo' is installed it's not possible
to simulate its being absent.

Test by forcing _zsh_highlight_main__type() to return 'none' when the
argument is [[ $1 == 'sudo' ]], and: (1) Run 'make test' and confirm
that all tests either pass, or fail and the first test point that fails
is one that expects "sudo" at command position to be highlighted as
'command'; (2) In an interactive zsh, 'sudo' at command position is
highlighted as an error.
2017-12-07 00:00:13 +00:00
Matthew Martin
7177ba005f main: Split declaration and assignment
Unbreak build for 5.0.8 and earlier.
2017-11-24 16:35:25 -06:00
Matthew Martin
2a50614579 main: Save user options in a single variable 2017-11-24 16:07:44 -06:00
Daniel Shahaf
73cb832702 'main': Highlight mismatched 'if'/'fi'.
Also 'then'/'elif'/'else'.
2017-03-05 17:33:36 +00:00
Daniel Shahaf
237f89ad62 'main': Don't consider «$*» a glob. 2017-02-11 23:49:13 +00:00
Daniel Shahaf
76ea9e1df3 'main': Highlight possible history expansions in double-quoted strings. 2016-11-22 07:09:29 +00:00
Daniel Shahaf
9396ad5c5f 'main': Fix highlighting of comments followed by non-comments (on a subsequent line).
Merge remote-tracking branch 'upstream/pr/385'

* upstream/pr/385:
  'main': Add regression test for previous commit.
  'main': Fix bug: no start_pos=$end_pos in comment short path

Fixes #385.
2016-11-02 15:54:56 +00:00
Sebastian Gniazdowski
5625e30b87 'main': Fix bug: no start_pos=$end_pos in comment short path 2016-11-02 10:58:15 +01:00
Daniel Shahaf
fed37a90ac 'main': Fix a bug concerning command word with embedded colon-space sequences.
Such a command word would, if not valid, fall through to the `type -w` case,
where the output would be misparsed, consequently the forward-compatible [arg0]
style would be used.
2016-11-02 03:16:45 +00:00
Daniel Shahaf
28d7056a7a 'main': Escape '!' within double-quoted strings. 2016-10-19 23:56:25 +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
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
b2733a64da 'main': Highlight mismatched do/done. 2016-09-25 11:38:54 +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
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
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
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
51b9d79c3b 'main': Highlight mismatched parentheses and braces. 2016-09-22 11:12:42 +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
fdaeec4514 'main': Followup to 51614ca2c9: Run cheaper conditions first.
This was suggested on #355.
2016-09-08 19:09:29 +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
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
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
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
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
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
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
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
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
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
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
ef68f50c04 'main': Fix issue #290, «Mishighlights "longloops" 'repeat'». 2016-05-13 03:30:11 +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
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
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
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
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
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
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
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
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
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
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
28932316cc aliases: Highlight aliases with '=' in their LHS as error. (Part of issue #263.) 2016-01-11 15:27:48 +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
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
17fbcad8ac 'main': Fix state check.
At this time, no user-visible consequences are known.
2015-11-18 16:37:38 +00:00
Daniel Shahaf
29fd6ec1de Support the '|&', '&!', '&|' command separators. 2015-11-17 20:19:19 +00:00
Daniel Shahaf
3ed0f7f823 noop: Consolidate two identical conditionals. 2015-11-17 20:07:14 +00:00
Daniel Shahaf
2dbcb575e5 internal: Document the ':regular' state. 2015-11-17 19:40:58 +00:00
Daniel Shahaf
4fcfb15913 Highlight parameter expansions that are a command word.
Fixes zsh-users/zsh-syntax-highlighting#101.
2015-11-17 01:37:58 +00:00
Daniel Shahaf
bdc1449733 noop: Break out a helper function. 2015-11-17 01:37:12 +00:00
Daniel Shahaf
6e3720f39d dollar-double-quoted-argument: Support the syntax «"${foo}"». (Issue #186.) 2015-11-17 00:40:02 +00:00
Daniel Shahaf
96ee5116b1 Fix issue #228, "Support the PATH_DIRS option". 2015-11-16 23:14:48 +00:00
Daniel Shahaf
b285c7b821 brackets: Highlight closing ')' of array assignments correctly. (Issue #226.)
Followup to c0dafd1d85, which changed the highlight of
those ')'s from <nothing> to [reserved-word].
2015-11-16 18:44:44 +00:00
Daniel Shahaf
c0dafd1d85 brackets: Highlight the closing brackets of subshells and blocks. (Issue #226.) 2015-10-30 20:20:30 +02:00
Daniel Shahaf
28abb960de noop: Follow-up to last: improve readability. 2015-10-30 20:14:03 +02:00
Daniel Shahaf
a59f442d2d brackets: Highlight the closing brackets of arithmetic expansion. (Issue #226.) 2015-10-30 17:28:48 +00:00
Daniel Shahaf
8b4adbd991 Fix issue #222, "command word after repeat". 2015-10-30 13:31:43 +00:00
Daniel Shahaf
9e178f9f39 subshells: Highlight the opening parenthesis correctly. (Issue #166.)
Followup to 0d1bfbcbfa.
2015-10-30 11:38:32 +02:00
Daniel Shahaf
d3deffbf46 minor: Fix WARN_CREATE_GLOBAL warnings issued by zsh 5.1.1-dev-0.
The following warnings are issued by zsh as of zsh-workers/37018 (commit
de9effbce601 to zsh itself):

_zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter match created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter mbegin created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter mend created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_dollar_string:17: numeric parameter parameter MBEGIN created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_dollar_string:17: numeric parameter parameter MEND created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_dollar_string:17: scalar parameter MATCH created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string
_zsh_highlight_main_highlighter_highlight_string:11: array parameter match created globally in function _zsh_highlight_main_highlighter_highlight_string
_zsh_highlight_main_highlighter_highlight_string:11: array parameter mbegin created globally in function _zsh_highlight_main_highlighter_highlight_string
_zsh_highlight_main_highlighter_highlight_string:11: array parameter mend created globally in function _zsh_highlight_main_highlighter_highlight_string
_zsh_highlight_main_highlighter_highlight_string:11: numeric parameter parameter MBEGIN created globally in function _zsh_highlight_main_highlighter_highlight_string
_zsh_highlight_main_highlighter_highlight_string:11: numeric parameter parameter MEND created globally in function _zsh_highlight_main_highlighter_highlight_string
_zsh_highlight_main_highlighter_highlight_string:11: scalar parameter MATCH created globally in function _zsh_highlight_main_highlighter_highlight_string
2015-10-30 10:12:04 +02:00
Daniel Shahaf
8ab8c815ec Fix syntax error with zsh-5.0.5-dev-1 and older.
zsh prior to workers/32609 (commit 9d47e8398d299e53ffe4e7ddf3731d2fedae9948)
does not support the (-n)-less «[[ $var ]]» syntax.

Fixes zsh-users/zsh-syntax-highlighting#225.
2015-10-30 09:34:16 +02:00
Daniel Shahaf
afa6bb3882 states work: Extend state machine documentation. 2015-10-30 08:38:45 +02:00
Daniel Shahaf
1ac39b0af1 comments: Mark prematurely-terminated command as an error.
This is already done for commands prematurely terminated by ";".
2015-10-30 08:38:45 +02:00
Daniel Shahaf
693de99a90 comments: Fix issue #163 and #167: Highlight comments. 2015-10-30 08:38:44 +02:00
Daniel Shahaf
2f05620b19 sudo: Flag an error when a required argument is missing. 2015-10-29 12:01:13 +00:00
Daniel Shahaf
9cb87473cc sudo: Tweak state computations.
This causes the ':start:' state to be set in $next_word in iteration N-1,
rather than to only be added to $this_word in iteration N.
2015-10-29 12:01:13 +00:00
Daniel Shahaf
a3047a9121 sudo: Highlight an empty sudo; as an error.
The word following 'sudo' was considered :regular:, although it isn't.
2015-10-29 12:01:13 +00:00
Daniel Shahaf
86e9249709 sudo/redirections: Fix remaining part of issue #221, "sudo and redirection don't mix". 2015-10-29 12:01:13 +00:00
Daniel Shahaf
0d1bfbcbfa Highlight subshells and anonymous functions correctly.
Fixes zsh-users/zsh-syntax-highlighting#166.
Fixes zsh-users/zsh-syntax-highlighting#194.
Builds upon the issue #207 work.
2015-10-29 12:01:13 +00:00
Daniel Shahaf
c216242b46 command word: Highlight more reserved words. Part of issue #207. 2015-10-29 12:01:13 +00:00
Daniel Shahaf
2218e26bf8 command word: Highlight 'else' correctly. Part of issue #207. 2015-10-29 12:01:13 +00:00
Daniel Shahaf
b397b12ac1 command word: Start fixing issue #207, "Word following certain reserved words should be a command word". 2015-10-29 12:01:13 +00:00
Daniel Shahaf
01d7eeb3c7 Fix issue #205, "';' after assignment is highlighted as unknown-token". 2015-10-29 12:01:13 +00:00
Daniel Shahaf
6d6fb8b03e redirections: Document handling of redirections and possibly fix a latent bug.
The change of behaviour is triggered by test-data/sudo-redirection.zsh: the iteration
on "otheruser" sets $next_word to ":regular::sudo_opt::start::sudo_opt::start:" before
this patch, but to ":regular::sudo_opt::start:" after it (note the deduplication).
2015-10-29 12:01:13 +00:00
Daniel Shahaf
be006aded5 sudo/redirections: Fix part of issue #221, "sudo and redirection don't mix". 2015-10-29 12:01:11 +00:00
Daniel Shahaf
c6355a31b7 Followup to last: re-fix issue #9 and add test for it.
The fix for issue #9 was accidentally broken by the penultimate commit.

Note that we don't care about aliases to ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
entries, since the code deals with aliases at command position.
2015-10-29 12:01:11 +00:00
Daniel Shahaf
018bc45f21 Followup to last: tighten the fix and ask a question. 2015-10-29 12:01:11 +00:00
Daniel Shahaf
2c9f8c8c95 Fix issue #209, "precommand modifiers at non-command-word position". 2015-10-29 12:01:11 +00:00
Daniel Shahaf
88cf98d9c4 states work: Documents the various states. 2015-10-29 12:01:11 +00:00
Daniel Shahaf
0aa6a5db78 states work: Convert $new_expression parsing. 2015-10-29 12:01:11 +00:00
Daniel Shahaf
10b1da64e6 states work: Convert sudo parsing. 2015-10-29 12:01:11 +00:00
Daniel Shahaf
2080a441ac minor: Remove redundant setting of $highlight_glob. 2015-10-28 09:58:13 +02:00
Daniel Shahaf
59fbdda64c main: Refresh highlighting upon accept-* widgets (accept-line et al).
Use this to remove [path_prefix] highlighting during accept-* widgets.
This causes ": file.tx<CR>" to remove the underline from "file.tx", like
": file.tx<SPACE>" already does.  (Assume 'file.txt' exists.)
2015-10-28 09:24:08 +02:00
Daniel Shahaf
fb5ce43799 noop: Rename a local variable for clarity. 2015-10-27 11:59:25 +02:00
Daniel Shahaf
98aee7f8b9 Remove path_approx.
Fixes zsh-users/zsh-syntax-highlighting#187.
Adds a test for zsh-users/zsh-syntax-highlighting#204.
2015-10-27 04:29:05 +00:00
Daniel Shahaf
c687bddea3 Drop unnecessary shebang lines, part 2.
Follow-up to the last commit.

E: zsh-syntax-highlighting: missing-dep-for-interpreter zsh => zsh | zsh-beta (usr/share/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh)
W: zsh-syntax-highlighting: executable-not-elf-or-script usr/share/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
2015-10-20 12:06:07 +00:00
Daniel Shahaf
e138cfd765 command word: Protect against the case that the command word starts with a minus. 2015-10-02 13:27:21 +00:00
Daniel Shahaf
07fd773d7e noop: Add comments. 2015-09-30 01:26:27 +00:00
Daniel Shahaf
5cd1fb26c0 Resolve tilde expansions in command word.
This causes '~/bin/foo' to highlight as a command, rather than as a file.

Part of issue #201.
2015-09-30 00:49:34 +00:00
Daniel Shahaf
faed2fa49e internal: Fix docstrings. 2015-09-29 23:45:44 +00:00
Daniel Shahaf
69203b1a1d Don't highlight escaped globbing.
Fixes zsh-users/zsh-syntax-highlighting#193.
2015-09-29 23:44:57 +00:00
Daniel Shahaf
800158745a Highlight quoted command words correctly.
Fixes zsh-users/zsh-syntax-highlighting#147.
2015-09-28 19:49:39 +00:00
Daniel Shahaf
7b4598a764 Highlight arithmetic expansions.
Fixes zsh-users/zsh-syntax-highlighting#188 in the case that both the
opening '((' and closing '))' have been typed,  The case that only the
opening '((' have been typed is also fixed, but requires a zsh development
build (zsh-5.1.1-52-g4bed2cf or newer); see comments within.
2015-09-28 13:55:38 +00:00
Daniel Shahaf
52a2ef644b Don't highlight escaped globbing.
Fixes zsh-users/zsh-syntax-highlighting#193.
2015-09-27 16:28:32 +00:00
Daniel Shahaf
6488284814 back-dollar-quoted-argument: Highlight incomplete escape sequences as unknown-token
Followup to 219184f046, which fixed issue #196.
2015-09-27 15:59:04 +00:00
Daniel Shahaf
79e8c2dd48 Don't highlight syntax elements as paths.
Without this, redirections, history expansions, and command separators would
be matched by path_approx.

A test case is simply LBUFFER="<" RBUFFER="" (highlighted as redirection with this
fix and as path_approx without it).

Fixes zsh-users/zsh-syntax-highlighting#204.
2015-09-26 18:28:48 +00:00
Daniel Shahaf
4ec821b2b1 Highlight redirections.
Fixes zsh-users/zsh-syntax-highlighting#23.

* danielsh/i23-highlight-redirections:
  Highlight redirections.
2015-09-26 17:58:07 +00:00
Daniel Shahaf
6732783d46 back-dollar-quoted-argument: Correct an off-by-one.
Highlight the last character of a «\xHH» escape when it is the last thing in
LBUFFER.  This is similar to what b0cc02ed86 did
for issue #186.
2015-09-26 01:09:37 +00:00
Daniel Shahaf
0788514cbd back-dollar-quoted-argument: Correct octal escape syntax.
A leading zero, as in '\0NNN', is permitted by 'echo' but not by 'print',
and «$''» follows 'print'.
2015-09-25 21:54:37 +00:00
Daniel Shahaf
8a43bd2cd9 back-dollar-quoted-argument: Highlight \uHHHH and \UHHHHHHHH escapes. 2015-09-25 21:45:38 +00:00
Daniel Shahaf
98366ade11 back-dollar-quoted-argument: Don't consider \0xHH a hex escape sequence.
A leading zero is not permitted in the '\xHH' syntax.
2015-09-25 21:45:38 +00:00
Daniel Shahaf
78ad649d47 back-dollar-quoted-argument: Don't consider comma a hex character.
Character class syntax does not ignore commas between ranges.
2015-09-25 21:45:38 +00:00
Daniel Shahaf
69fcb40275 Highlight backslash escapes within $'' strings.
Correct highlighting of backslash escapes within "" strings: highlight only
the four specific escape sequences defined there.

Fixes zsh-users/zsh-syntax-highlighting#196.
2015-09-25 21:45:38 +00:00
Daniel Shahaf
f4164ac86c internal: Document a function-local variable. 2015-09-25 21:22:09 +00:00
Daniel Shahaf
9c7a1109c8 WARN_CREATE_GLOBAL: don't leak the arithmetic for loop's index variable.
Found by code inspection; WARN_CREATE_GLOBAL missed this.
2015-09-25 20:57:51 +00:00
Daniel Shahaf
040df93c01 Highlight redirections.
Fixes zsh-users/zsh-syntax-highlighting#23.
2015-09-25 12:42:34 +00:00
Daniel Shahaf
66eb801358 dollar-double-quoted-argument: Handle «"foo$"» correctly. 2015-09-24 19:03:17 +00:00
Daniel Shahaf
b0cc02ed86 dollar-double-quoted-argument: Highlight "$foo" better.
Now, «"$42foo"» doesn't highlight the «foo», and «"$bar» highlights the «r».
2015-09-24 19:03:00 +00:00
Daniel Shahaf
908c4fe150 Stop leaking variables into global namespace.
Set WARN_CREATE_GLOBAL to prevent recurrence.

Fixes zsh-users/zsh-syntax-highlighting#192.
2015-09-24 18:01:06 +00:00
Daniel Shahaf
9e80fe8f02 Bump copyright years. 2015-09-24 16:46:28 +00:00
Daniel Shahaf
5fb4cb2f72 Fix regression: Highlight ';' as commandseparator.
This was broken by c2b9327b07
and tracked as zsh-users/zsh-syntax-highlighting#199.

This fixes the vanilla-newline.zsh test, which was was (consciously) broken
by the previous commit.
2015-09-23 14:50:22 +00:00
Daniel Shahaf
a8afbdf2f5 Support $''-quoted strings.
This does not yet highlight backslash escapes within them.
2015-09-10 20:02:39 +00:00
Daniel Shahaf
555e142e66 suffix aliases: Highlight differently.
Add an underline, since they are at command word position but will be executed
by something else.

Suggested-by: Daniel Hahler
2015-09-08 10:13:16 +00:00
Daniel Shahaf
e13c5a1611 Highlight 'noglob' correctly in more cases.
Fixes zsh-users/zsh-syntax-highlighting#189.
2015-09-07 18:07:59 +00:00
Daniel Shahaf
8515b7e0c5 Highlight ? as globbing.
Fixes zsh-users/zsh-syntax-highlighting#94.
2015-09-07 18:05:56 +00:00
Daniel Shahaf
dc701501e5 Highlight ? as globbing.
Fixes zsh-users/zsh-syntax-highlighting#94.
2015-09-07 18:03:14 +00:00
Daniel Shahaf
9310d8ae71 Support suffix aliases
Fixes zsh-users/zsh-syntax-highlighting#126.
2015-09-07 17:59:52 +00:00
Daniel Shahaf
b3ceea8511 Highlight 'noglob' correctly in more cases.
Fixes zsh-users/zsh-syntax-highlighting#189.
2015-09-07 09:09:17 +00:00
Daniel Shahaf
a0b5bc6c71 Fix bug in previous commit (d330b49b33)
'local' is a reserved word in zsh 5.1 but not in earlier versions [1].
Therefore, under zsh older than 5.1, quoting is required.

This manifested as random «builtin=''» in emitted to the terminal, and
commands (such as 'echo') highlighted as errors (in red).

[1] https://github.com/zsh-users/zsh/blob/master/README#L46
    (the section "Incompatibilites between 5.0.8 and 5.1")
2015-09-07 01:26:11 +00:00
Daniel Shahaf
d330b49b33 Fix variable leakage into global namespace.
Similar to zsh-users/zsh-syntax-highlighting#97.
2015-09-06 19:20:49 +00:00
Daniel Shahaf
7f41967a17 Highlight array appends: foo+=(bar baz).
Fixes zsh-users/zsh-syntax-highlighting#181.
2015-09-05 09:38:02 +00:00
Daniel Shahaf
51aed8a765 Merge remote-tracking branch 'upstream/pr/179'
* upstream/pr/179:
  Don't parse first word of array assignment as command
2015-09-04 17:57:08 +00:00
Daniel Shahaf
42495cc5d6 Merge remote-tracking branch 'upstream/pr/161'
* upstream/pr/161:
  Don't highlight prefix redirections as error
2015-09-04 17:27:25 +00:00
Daniel Shahaf
c2b9327b07 Support literal newlines, part 2 2015-09-02 09:30:08 +00:00
Daniel Shahaf
52ece975c3 Update comments. No functional change. 2015-09-02 02:37:43 +00:00
Daniel Shahaf
b9b67b9f78 Don't parse first word of array assignment as command
Fixes zsh-users/zsh-syntax-highlighting#178
2015-08-28 09:52:52 +00:00
Daniel Shahaf
359d48bf78 Don't highlight prefix redirections as error
Fixes zsh-users/zsh-syntax-highlighting#146
2015-02-16 02:44:56 +00:00
Daniel Shahaf
ff4d402e9a Highlight the first part of multiline strings correctly
Given the following input:
    PREBUFFER=$'echo "foo\n'
    BUFFER='bar"'
This patch causes the '"foo' part to be highlighted as a string.  There
is no test because the tests only check highlighting of BUFFER, and 'bar"'
is already highlighted correctly.
2015-02-02 15:12:59 +00:00
Daniel Shahaf
384be15b13 Support literal newlines 2015-01-27 10:23:59 +00:00
Daniel Shahaf
23cacb12fe Support backslash continuations 2015-01-27 10:23:59 +00:00
Daniel Shahaf
667495bfb7 Support multiline strings 2015-01-27 10:23:58 +00:00
Daniel Shahaf
2c5acaefa9 Refactoring, no functional change
The new function will be used in the next commit.
2015-01-27 10:23:58 +00:00
sonnym
04f9c8884f highlight ^old^new pattern
by extending the already in place mechanism of checking for the first
histchar to check for the second as well
2013-12-07 05:11:19 -05:00
Julien Nicoulaud
f289a9f8e7 Merge pull request #125 from acatton/fix-121
Fix #121: sudo syntax highlighting incorrectly
2013-11-19 11:42:03 -08:00
Julien Nicoulaud
8ac964186d Merge pull request #131 from MarkLodato/array-assignments
Properly highlight array assignments
2013-11-19 11:40:29 -08:00
Julien Nicoulaud
ffce2a0b20 Merge pull request #133 from lucc/master
protect alias expansion from interpreting aliases as options
2013-11-19 11:39:40 -08:00
Lucas Hoffmann
784a5dc35b protect alias expansion from interpreting aliases as options
If one defines aliases like `++` the alias builtin tries to interprete these
as options so they have to be protected like this

    alias -- ++=true

The same goes for a call to `alias` in order to expand the alias again.
2013-11-05 00:50:20 +01:00
Mark Lodato
441f1a8aad highlight array assignments of the form x[y]=...
This code is more lenient than bash.  Examples:

    $ x[y[]=
    zsh: no matches found: x[y[]=
    $ x[][]=
    zsh: no matches found: x[][]=

The proper solution is to look inside the [...] and make sure that all
unescaped/unquoted square brackes are matched, but that is a heck of
a lot more complicated than this simple 8-character patch.
2013-10-30 00:53:46 -04:00
Mark Lodato
c62cb54e9d do not remove quotes when checking assignments
Zsh does not allow the variable name or the equals sign to be quoted or
escaped.  The previous code incorrectly highlighted the following
examples as assignments:

    $ 'x=y'
    zsh: command not found: x=y
    $ x\=y
    zsh: command not found: x=y
    $ "x"=y
    zsh: command not found: x=y
    $ \x=y
    zsh: command not found: x=y
2013-10-30 00:00:16 -04:00
Akinori MUSHA
0fc6b07509 Do not leak a variable: cdpath_dir.
Leaking a variable that holds a path in CDPATH could easily end up appearing on your prompt like `~cdpath_dir/subdir`.
2013-10-21 21:18:38 +09:00
Antoine Catton
3b3a58be91 Fix #121: sudo syntax highlighting incorrectly
Parse sudo command line in order to highlight the options correctly
2013-09-28 19:33:34 -06:00
Julien Nicoulaud
08b80022ca Merge pull request #123 from Shura0/master
Highlighted dollar variable ver. 2
2013-08-09 00:47:32 -07:00
Shura
a7ee0597ef Update main-highlighter.zsh
Comments added
2013-08-09 10:24:14 +04:00
Julien Nicoulaud
3677b75731 Merge pull request #115 from Valodim/master
add separate path_prefix and path_approx hilights
2013-08-08 07:31:46 -07:00
Владимир
57c01d19de Update main-highlighter.zsh
Add support of CDPATH
2013-08-07 03:21:15 +03:00
Shura
8abcf187f6 dollar variable and backslash codes highlighting 2013-07-29 17:33:34 +04:00
Vincent Breitmoser
228f5a6aad add separate path_prefix and path_approx hilights 2013-07-25 04:41:09 +02:00
evan
19981ef9ea added sudo as a precommand 2012-08-17 15:52:09 -04:00
Jud Porter
d82eee5212 add emulate -L zsh to _zsh_highlight_main_highlighter. resolves issue #83 2011-12-02 16:44:33 -05:00
Julien Nicoulaud
f824e5e84d Options should only be set locally 2011-09-24 14:42:55 +02:00
Andreas Gahr
024c1c46f7 next try. fix for issue #76 without brakeing fix for #21 2011-09-24 20:39:34 +08:00
Julien Nicoulaud
8d4cde6301 (Hopefully) fix #21 (tilde and hashed directories in paths) 2011-09-20 19:13:37 +02:00
Julien Nicoulaud
db8f98fc53 Set default style for pipes and stuff to none 2011-09-20 19:13:37 +02:00
Andreas Gahr
287167d453 fix for issue #76. This was more ore less forgotten in pull request #75 2011-09-20 19:13:37 +02:00
Andreas Gahr
670961ad01 handle highlighting for precommands; handle highlighting for commands separators 2011-09-20 19:13:37 +02:00
Andreas Gahr
f84f9319d8 supposed fix for issue #73 and issue #74 2011-09-09 16:07:49 +02:00
Julien Nicoulaud
a6d105131c Fix #21: No highlighting when using tilde 2011-09-06 19:21:40 +02:00
Takeshi Banse
4a8b184632 pass ${arg} explicit
Signed-off-by: Takeshi Banse <takebi@laafc.net>
2011-09-07 01:14:45 +08:00
Valodim
f27ef7a279 after exec token we can expect a command 2011-08-02 00:55:55 +08:00
Julien Nicoulaud
e7d7ccfe35 Group if statements in f26310d97e 2011-06-16 14:54:24 +02:00
Guido
f26310d97e * enable command lines starting with a hyphen. 2011-06-16 04:28:59 -07:00
Julien Nicoulaud
0772ddd346 Big refactoring.
* Don't override user defined styles
* Better modularisation of highlighters
* Allow to define which highlighters are activated
* Allow to define the order in which they are defined
* Minor performance optimizations
* Fixed some variables leak
* Improve documentation
* Brackets highlighter: use ZSH_HIGHLIGHT_STYLES instead of a specific array
2011-06-12 22:57:14 +02:00