Commit graph

237 commits

Author SHA1 Message Date
m0viefreak
3c43da5ffe driver: Improve comment about ^r pattern match bug
The bug is not specific to 5.3.1.
2017-07-30 19:08:21 +02:00
m0viefreak
f2ba507bbc driver: Adjust zsh version for probing for pattern match bug 2017-07-30 19:08:21 +02:00
jsoizo
ad522a0914 driver: Fix printing error message to file when cannot resolve highlighters directory location
Fixes #426.

Review-by: Matthew Martin, me
2017-04-09 16:47:42 +00:00
Daniel Shahaf
462779629a driver: Workaround pattern isearch bug in zsh ≤ 5.3.1, already fixed upstream.
Merge remote-tracking branch 'upstream/pr/415'

* upstream/pr/415:
  workaround for PAT_STATIC bug in zsh
2017-03-29 09:18:59 +00:00
Daniel Shahaf
be083d7f37 driver: Improve «unhandled ZLE widget 'foo'» error message.
Fixes #409.
2017-03-05 14:38:52 +00:00
Christian Höltje
835fec7f3c workaround for PAT_STATIC bug in zsh
ZSH versions less than 5.3.2 (or 5.4) have a bug that prevents
`history-incremental-pattern-search-backward` for working
correctly (the history stops searching after the first found item).

Closes #407
2017-02-09 17:58:36 -05:00
vinter
aac4a44238 driver: Fix duplicated slash in error message
Fixes #400.
2016-12-16 10:20:04 +00:00
Daniel Shahaf
74949c2d91 driver: Don't undefine aliases that begin with a '+', to workaround an upstream bug.
Fixes #392.
2016-12-03 13:54:47 +00:00
Daniel Shahaf
8d5afe47f7 driver: Be immune to 'alias' having been redefined. 2016-12-01 09:06:32 +00:00
Daniel Shahaf
2dce602727 driver: Be immune to weird aliases in the calling scope.
Fixes #390.
2016-11-11 08:35:19 +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
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
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
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
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
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
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
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
m0viefreak
b9112aec79 driver: Widget binding: Use ${(k)widgets} instead of $(zle -la)
Avoids a fork.
2016-06-20 18:37:11 +00: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
4b77af73fb minor: Fix typo in comment.
Two instances.
2016-06-03 08:41:45 +00:00
m0viefreak
3ce01076b5 driver: load zsh/parameter if available 2016-05-13 02:24:57 +00: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
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
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
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
79e4d3d124 apply suffix and isearch zle_highlights on top 2016-03-28 18:24:29 +02: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
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
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
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
84734ba950 versionstamp: Better $ZSH_HIGHLIGHT_REVISION reporting when running from git. 2015-11-25 03:55:20 +00:00
Daniel Shahaf
635a68f7b4 driver: Fix error message wording 2015-11-25 03:54:33 +00:00
Daniel Shahaf
8f19af6b31 driver: Tolerate KSH_ARRAYS being set in the calling context.
Fixes zsh-users/zsh-syntax-highlighting#162.
2015-11-17 00:48:22 +00:00
Daniel Shahaf
c808d2187a wrapping: Don't add '--' when invoking widgets.
It's the widget's caller's responsibility, not ours, to add '--' where due.  If
we do it, two instances of '--' might result.  (I haven't been able to provoke
this problem.)

If this commit causes problems, the cause would be widget-callers that don't
pass '--' although they should.
2015-10-28 08:30:05 +02:00
Daniel Shahaf
7e6d960a08 noop: Break out a helper function. 2015-10-28 08:30:05 +02:00
Daniel Shahaf
083c47b007 regerssion: Look for .version and .revision-hash in the correct place.
Fixes zsh-users/zsh-syntax-highlighting#215.
2015-10-21 06:55:00 +00:00
Daniel Shahaf
c30301d474 Drop unnecessary shebang lines.
All these files should be sourced, not executed; and Debian's lintian complains:

W: zsh-syntax-highlighting: script-not-executable usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
2015-10-20 11:49:51 +00:00
Daniel Shahaf
0a7035170a versioning: Expose .revision-hash as $ZSH_HIGHLIGHT_REVISION.
Currently, this only works in installed trees and exported tarballs; the
parameter is left unset when running directly from a git worktree.
2015-10-20 03:07:04 +00:00
Daniel Shahaf
3576df29aa Don't leak $REPLY into global scope.
Fixes issue #213.
2015-10-20 00:21:11 +00:00
Daniel Shahaf
f48f5400c1 Revert "Do wrap the 'yank' widget, because that works."
This reverts commit 8e7c26f489.

Currently, after a 'yank', paste highlighting (via $YANK_ACTIVE in zsh 5.1.1)
is applied but other highlighting (e.g., string highlighting when the yanked
text is «"foo» as a new word) is not.

See issue #183 for context.

Conflicts:
	zsh-syntax-highlighting.zsh
2015-10-19 13:40:51 +00:00
Daniel Shahaf
766b350a7d Wrap yank-pop.
As explained in #143 (which was a PR for #99), 'yank-pop' only works when the
previous widget has the ZLE_YANK flag, which means wrapping the 'yank' widget
breaks the 'yank-pop' widget (makes it a no-op).  However, that is a reason
against wrapping the 'yank' widget, but not against wrapping the 'yank-pop'
widget.  Indeed, if 'yank-pop' is wrapped but 'yank' isn't, then yank-pop
functions correctly and updates highlighting properly.

To unbreak yank-pop, either 'yank' should be excluded from wrapping, or one of
the fixes mentioned on issue #183 should be applied.
2015-10-19 08:34:08 +00:00
Daniel Shahaf
9c56c624e9 versionstamp: Handle NO_FUNCTION_ARGZERO.
Sourcing zsh-syntax-highlighting.zsh without FUNCTION_ARGZERO doesn't work (for
reasons unrelated to this branch), but now errors out gracefully.  The failure mode
before this branch was:

    zsh-syntax-highlighting: highlighters directory '/usr/local/bin/highlighters' not found.

where /usr/local/bin is dirname() of the zsh binary.
2015-10-19 07:21:20 +00:00
Daniel Shahaf
43386376d8 Set the version number.
Store it in a separate file so OS packages and 'make install' (issue #177) can
reuse it.
2015-10-19 07:20:57 +00:00
Daniel Shahaf
3fdaec3d4a WARN_CREATE_GLOBAL: Plug yet another instance. 2015-09-26 16:27:08 +00:00
Daniel Shahaf
dd12dde93a Fix errors with non-reserved-word typeset.
Follow-up to 908c4fe150.

Intended to fix fix zsh-users/zsh-syntax-highlighting#206.
2015-09-25 17:53:22 +00:00
Daniel Shahaf
cb5589db73 Don't wrap set-local-history.
See issue #137.  A reproduction recipe for testing this change:

$ zsh -f
% bindkey -e
% source <the script from http://www.zsh.org/mla/users/2014/msg00321.html users/18584>
% source zsh-syntax-highlighting.zsh
% echo foo
% echo bar
% <^R>echo<^R>

This finds the 'echo foo' with this change but not without it.
2015-09-25 15:35:03 +00:00
Daniel Shahaf
35c4bb7bdc More WARN_CREATE_GLOBAL cleanups.
Followup to 908c4fe150.
Found by test-perfs.zsh.
2015-09-25 13:04:37 +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
00862cf4fa Followup to e5c2a88db0 (merged in 51102bf83f):
Have widgets return EXIT_SUCCESS.
2015-09-18 12:38:24 +00:00
Daniel Shahaf
e5c2a88db0 Highlight yanks/pastes on top of syntax highlighting.
Let $zle_highlight[paste] override $region_highlight.
2015-09-10 19:31:36 +00:00
Daniel Shahaf
0e31d6e1a2 Highlight the region on top of syntax highlighting.
Let $zle_highlight[region] override $region_highlight.
2015-09-08 20:22:22 +00:00
Daniel Shahaf
f78919d941 Preserve $? of wrapped widgets. 2015-09-05 21:44:11 +00:00
Daniel Shahaf
8e7c26f489 Do wrap the 'yank' widget, because that works.
Partly reverts eb9870f4db which was PR #143 to
fix issue #99.
2015-09-05 12:50:32 +00:00
nicoulaj
3dc5741900 Merge pull request #140 from randomize/pr_fix_issue_#77
Pr fix issue #77
2014-09-24 22:58:20 +02:00
Vincent Bernat
74a183447d zle: don't override yank/yank-pop
`yank-pop` relies on the fact that the last zle command is `yank` or
`yank-pop` to work correctly. Rewriting them prevents this check to work
correctly breaking `yank-pop`.

This fix just disallow overriding of those two zle commands. As a
side-effect, syntax highlighting will not happen when using.

This fixes #99.
2014-06-29 11:52:32 +02:00
Randy
7edd08156e Chaned main highlighter alorithm to resolve issue #77 2014-03-29 22:52:10 +02:00
Evan Pitstick
dffbab0c92 a more simple and universal way (for zsh projects) to find highlight dir path 2013-10-09 12:02:34 -04:00
Evan Pitstick
0fcc2629d2 Finds highlighters dir a little better 2013-03-08 00:57:16 -05:00
Jan M. Binder
966eb851ca Added quotes to suppress error 2012-04-07 11:48:11 +02:00
NAKAMURA Yoshitaka
56b134f5d6 fix "_zsh_highlight_widget_XXX:zle: unknown option: X" error 2011-11-01 20:02:03 +09:00
Andreas Gahr
603fce64b5 autoload add-zsh-hook && provide a nicer error message if that fails due to old zsh version, or similar situations. Reset another variable in hook function; it can't hurt 2011-09-28 16:35:19 +02:00
Andreas Gahr
304ddb9400 make highlighting work for first entry in history. fixes #79 2011-09-27 16:08:23 +02:00
Takeshi Banse
b0fee4e758 pass args down to each original zle call
Signed-off-by: Takeshi Banse <takebi@laafc.net>
2011-09-07 01:39:52 +08:00
Takeshi Banse
9706996d3b make _zsh_highlight nounset-able
Signed-off-by: Takeshi Banse <takebi@laafc.net>
2011-08-24 14:18:23 +09:00
Simon Heimlicher
854038010f Added || true to ensure zero exit code 2011-08-03 09:40:19 +00:00
Julien Nicoulaud
186d80054a Fix #65, sourcing the script multiples times should not cause issues anymore 2011-08-02 20:25:49 +02:00
Julien Nicoulaud
0e331cd654 Isolate setup code in functions to ease messing with zsh-syntax-highlighting 2011-07-31 17:59:55 +02:00
Julien Nicoulaud
5003fa7c9b We don't need this hook as we have already bound every widget we could find (stop me if I'm wrong) 2011-07-31 17:14:56 +02:00
Julien Nicoulaud
4ff08dcfa6 Fix #53: Prefix all defined functions with _zsh_highlight 2011-07-26 23:16:52 +02:00
Julien Nicoulaud
776453cb5b Fix #46: Conflict with url-quote-magic 2011-07-26 22:50:53 +02:00
Julien Nicoulaud
3b27ad778d More efficient way to strip leading dot 2011-07-25 22:30:06 +02:00
Valodim
5f68accccf Don't highlight if buffer is longer than $ZSH_HIGHLIGHT_MAXLENGTH 2011-07-25 14:51:43 +02:00
garinger
1858be26bd exclude .beep 2011-07-07 00:25:44 +08:00
Julien Nicoulaud
28720c77aa Some fixes consecutive to pull request #61 merge
* Allow to override highlighters directory through `ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR`
* Handle spaces in the directory path
* Use Zsh builtin "h" modifier instead of `dirname`
2011-06-30 20:08:43 +02:00
Ted Naleid
4ed9f9a68f fix for issue #60, unrecognized modifier 'A' on startup 2011-06-29 21:32:58 -05:00
Julien Nicoulaud
e04f6ab862 Safety checks before looking up cursor position 2011-06-17 12:36:07 +02:00
Julien Nicoulaud
f6af27b8a6 More reliable way to hook precmd 2011-06-17 12:35:26 +02:00
Guido
71e797a8b5 Much easier and less error prone way to start highlighting immediately after the creation of a new command line. 2011-06-16 13:57:34 -07:00
Guido
56801a6b42 * added a workaround to start highlighting immediately after the creation of a new command line. 2011-06-16 04:26:51 -07:00
Julien Nicoulaud
bb7fcb79fa Fix #56: tolerance to WARN_GLOBAL option 2011-06-12 23:09:59 +02:00