Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created January 7, 2011 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hchbaw/769487 to your computer and use it in GitHub Desktop.
Save hchbaw/769487 to your computer and use it in GitHub Desktop.
From d2f641ca50c792df09226b9cca3c0e66dc5dde9c Mon Sep 17 00:00:00 2001
From: Takeshi Banse <takebi@laafc.net>
Date: Fri, 7 Jan 2011 22:34:29 +0900
Subject: complete-word does not complete.
For example,
% bindkey "^I" complete-word
% bi<TAB>
does not work as expected. This includes `list-choices` and maybe some more.
I tackle this problem and make a series of patches which replaces the
clauses after the '# Bind all ZLE events from zle -la to highlighting
function.'.
This is too big for me to descibe its intentions at once in the squashed
patch form, so I split the commits in smaller chunks.
Please take a look some time.
Takeshi Banse (3):
Make this clause function and call it afterward.
Recreate the completion widget with its own function.
Carefully rebind the $clean_event.
zsh-syntax-highlighting.zsh | 50 ++++++++++++++++++++++++++----------------
1 files changed, 31 insertions(+), 19 deletions(-)
--
1.7.3.2.451.g1c2ab
From 802583ea9442dbd714d4b4e57d1c8ac0ca0967d5 Mon Sep 17 00:00:00 2001
From: Takeshi Banse <takebi@laafc.net>
Date: Fri, 7 Jan 2011 21:35:43 +0900
Subject: Make this clause function and call it afterward.
Signed-off-by: Takeshi Banse <takebi@laafc.net>
---
zsh-syntax-highlighting.zsh | 41 ++++++++++++++++++++++-------------------
1 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index c47239d..ed932cf 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -214,22 +214,25 @@ _zsh_highlight-zle-buffer() {
# reason). You can see the default setup using "zle -l -L".
# Bind all ZLE events from zle -la to highlighting function.
-local clean_event
-for event in $(zle -la); do
- case $event in
- _*|orig-*|.run-help|.which-command)
- ;;
- accept-and-menu-complete)
- eval "$event() { builtin zle .$event && _zsh_highlight-zle-buffer } ; zle -N $event"
- ;;
- [^\.]*complete*)
- eval "zle -C orig-$event .$event _main_complete ; $event() { builtin zle orig-$event && _zsh_highlight-zle-buffer } ; zle -N $event"
- ;;
- .*)
- clean_event=$event[2,${#event}] # Remove the leading dot in the event name
- eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
- ;;
- *)
- ;;
- esac
-done
+_zsh_highlight-install() {
+ local clean_event
+ for event in "$@"; do
+ case $event in
+ _*|orig-*|.run-help|.which-command)
+ ;;
+ accept-and-menu-complete)
+ eval "$event() { builtin zle .$event && _zsh_highlight-zle-buffer } ; zle -N $event"
+ ;;
+ [^\.]*complete*)
+ eval "zle -C orig-$event .$event _main_complete ; $event() { builtin zle orig-$event && _zsh_highlight-zle-buffer } ; zle -N $event"
+ ;;
+ .*)
+ clean_event=$event[2,${#event}] # Remove the leading dot in the event name
+ eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
+ ;;
+ *)
+ ;;
+ esac
+ done
+}
+_zsh_highlight-install "${(@f)"$(zle -la)"}"
--
1.7.3.2.451.g1c2ab
From 2fd0845b7730f861a2cc672af7d760d13498a29d Mon Sep 17 00:00:00 2001
From: Takeshi Banse <takebi@laafc.net>
Date: Fri, 7 Jan 2011 21:43:09 +0900
Subject: Recreate the completion widget with its own function.
Currently, each completion widgets will be re-installed, but its
function will be statically associated with `_main_complete`.
We can get this function name via $widget[$event] which is the
zsh's zsh/zleparameter module's feature. We can use this information
for `zle -C`ing.
Signed-off-by: Takeshi Banse <takebi@laafc.net>
---
zsh-syntax-highlighting.zsh | 37 ++++++++++++++++++++-----------------
1 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index ed932cf..957684a 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -215,24 +215,27 @@ _zsh_highlight-zle-buffer() {
# Bind all ZLE events from zle -la to highlighting function.
_zsh_highlight-install() {
+ zmodload zsh/zleparameter 2>/dev/null || {
+ echo 'zsh-syntax-highlighting:zmoadload error. exiting.' >&2; return -1
+ }
+ local -a events; : ${(A)events::=${@:#(_*|orig-*|.run-help|.which-command)}}
local clean_event
- for event in "$@"; do
- case $event in
- _*|orig-*|.run-help|.which-command)
- ;;
- accept-and-menu-complete)
- eval "$event() { builtin zle .$event && _zsh_highlight-zle-buffer } ; zle -N $event"
- ;;
- [^\.]*complete*)
- eval "zle -C orig-$event .$event _main_complete ; $event() { builtin zle orig-$event && _zsh_highlight-zle-buffer } ; zle -N $event"
- ;;
- .*)
- clean_event=$event[2,${#event}] # Remove the leading dot in the event name
- eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
- ;;
- *)
- ;;
- esac
+ for event in $events; do
+ if [[ "$widgets[$event]" == completion:* ]]; then
+ eval "zle -C orig-$event ${${${widgets[$event]}#*:}/:/ } ; $event() { builtin zle orig-$event && _zsh_highlight-zle-buffer } ; zle -N $event"
+ else
+ case $event in
+ accept-and-menu-complete)
+ eval "$event() { builtin zle .$event && _zsh_highlight-zle-buffer } ; zle -N $event"
+ ;;
+ .*)
+ clean_event=$event[2,${#event}] # Remove the leading dot in the event name
+ eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
+ ;;
+ *)
+ ;;
+ esac
+ fi
done
}
_zsh_highlight-install "${(@f)"$(zle -la)"}"
--
1.7.3.2.451.g1c2ab
From d2f641ca50c792df09226b9cca3c0e66dc5dde9c Mon Sep 17 00:00:00 2001
From: Takeshi Banse <takebi@laafc.net>
Date: Fri, 7 Jan 2011 21:49:19 +0900
Subject: Carefully rebind the $clean_event.
% bindkey "^I" complete-word
% bi<TAB>
If we had not source the zsh-syntax-highlighting.zsh, it could
complete something. This is due to that `complete-word` will be
rebinded with 'zle -N $clean_event'.
Signed-off-by: Takeshi Banse <takebi@laafc.net>
---
zsh-syntax-highlighting.zsh | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index 957684a..5ce9e92 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -230,7 +230,13 @@ _zsh_highlight-install() {
;;
.*)
clean_event=$event[2,${#event}] # Remove the leading dot in the event name
- eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
+ case ${widgets[$clean_event]-} in
+ (completion|user):*)
+ ;;
+ *)
+ eval "$clean_event() { builtin zle $event && _zsh_highlight-zle-buffer } ; zle -N $clean_event"
+ ;;
+ esac
;;
*)
;;
--
1.7.3.2.451.g1c2ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment