Commit graph

167 commits

Author SHA1 Message Date
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