From 304ddb94007fd9474d798c94e135f4ea4dcb1b3f Mon Sep 17 00:00:00 2001 From: Andreas Gahr Date: Tue, 27 Sep 2011 16:08:23 +0200 Subject: [PATCH 1/2] make highlighting work for first entry in history. fixes #79 --- zsh-syntax-highlighting.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index b06777d..74febaa 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -203,5 +203,12 @@ _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${0:h}/highl return 1 } +# Reset scratch variables when commandline is done. +_zsh_highlight_preexec_hook() +{ + _ZSH_HIGHLIGHT_PRIOR_BUFFER= +} +add-zsh-hook preexec _zsh_highlight_preexec_hook + # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true From 603fce64b58f1613a0338022bd8d3f1b4788e6bb Mon Sep 17 00:00:00 2001 From: Andreas Gahr Date: Wed, 28 Sep 2011 16:35:19 +0200 Subject: [PATCH 2/2] 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 --- zsh-syntax-highlighting.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 74febaa..686daa4 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -207,8 +207,12 @@ _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${0:h}/highl _zsh_highlight_preexec_hook() { _ZSH_HIGHLIGHT_PRIOR_BUFFER= + _ZSH_HIGHLIGHT_PRIOR_CURSOR= } -add-zsh-hook preexec _zsh_highlight_preexec_hook +autoload -U add-zsh-hook +add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { + echo 'zsh-syntax-highlighting: failed loading add-zsh-hook.' >&2 + } # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true