zsh-workers
 help / color / mirror / code / Atom feed
* Patch: Add file types to _expand completions
@ 2021-03-21 15:24 Marlon Richert
  2021-03-27 16:26 ` Lawrence Velázquez
  2021-03-30 23:25 ` Oliver Kiddle
  0 siblings, 2 replies; 3+ messages in thread
From: Marlon Richert @ 2021-03-21 15:24 UTC (permalink / raw)
  To: Zsh hackers list

This adds file types to `_expand` completions, so they can be colored
through complist.

diff --git a/Completion/Base/Completer/_expand
b/Completion/Base/Completer/_expand
index def522a76..8e3a84f30 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -11,7 +11,7 @@ setopt localoptions nonomatch

 [[ _matcher_num -gt 1 ]] && return 1

-local exp word sort expr expl subd suf=" " force opt asp tmp opre pre epre
+local exp word sort expr expl subd pref suf=" " force opt asp tmp opre pre epre
 local continue=0

 (( $# )) &&
@@ -214,9 +214,10 @@ else
  normal=( "$normal[@]" "$i" )
       fi
     done
-    (( $#dir ))    && compadd "$expl[@]" -UQ -qS/ -a dir
-    (( $#space ))  && compadd "$expl[@]" -UQ -qS " " -a space
-    (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal
+  pref="${${word:#[~/]*}:+$PWD}/"
+  (( $#dir ))    && compadd "$expl[@]" -fW "$pref" -UQ -qS/ -a dir
+  (( $#space ))  && compadd "$expl[@]" -fW "$pref" -UQ -qS " " -a space
+  (( $#normal )) && compadd "$expl[@]" -fW "$pref" -UQ -qS "" -a normal
   fi
   if _requested all-expansions; then
     local disp dstr
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index f6474c4a1..463686633 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -44,6 +44,25 @@
 >line: {: dir1/}{}
 >line: {: dir2/}{}

+  comptest $': *\t\t\t\t\t\t\t'
+0:_expand shows file types
+>line: {: dir1/}{}
+>DESCRIPTION:{expansions}
+>DI:{dir1}
+>DI:{dir2}
+>FI:{file1}
+>FI:{file2}
+>DESCRIPTION:{all expansions}
+>NO:{dir1 dir2 file1 file2}
+>DESCRIPTION:{original}
+>NO:{*}
+>line: {: dir1/}{}
+>line: {: dir2/}{}
+>line: {: file1 }{}
+>line: {: file2 }{}
+>line: {: dir1 dir2 file1 file2 }{}
+>line: {: *}{}
+
   comptesteval '_users () { compadd user1 user2 }'
   comptest $': ~\t\t\t\t\t'
 0:tilde
diff --git a/Test/comptest b/Test/comptest
index a36e301e0..cdb3ecc61 100644
--- a/Test/comptest
+++ b/Test/comptest
@@ -40,6 +40,7 @@ KEYTIMEOUT=1
 setopt zle
 autoload -U compinit
 compinit -u
+zstyle ":completion:*" completer _expand _complete _ignored
 zstyle ":completion:*:default" list-colors "no=<NO>" "fi=<FI>"
"di=<DI>" "ln=<LN>" "pi=<PI>" "so=<SO>" "bd=<BD>" "cd=<CD>" "ex=<EX>"
"mi=<MI>" "tc=<TC>" "sp=<SP>" "lc=<LC>" "ec=<EC>\n" "rc=<RC>"
 zstyle ":completion:*" group-name ""
 zstyle ":completion:*:messages" format "<MESSAGE>%d</MESSAGE>
@@ -50,9 +51,9 @@ zstyle ":completion:*:options" verbose yes
 zstyle ":completion:*:values" verbose yes
 setopt noalwayslastprompt listrowsfirst completeinword
 zmodload zsh/complist
-expand-or-complete-with-report () {
-  print -lr "<WIDGET><expand-or-complete>"
-  zle expand-or-complete
+complete-word-with-report () {
+  print -lr "<WIDGET><complete-word>"
+  zle complete-word
   print -lr - "<LBUFFER>$LBUFFER</LBUFFER>" "<RBUFFER>$RBUFFER</RBUFFER>"
   zle clear-screen
   zle -R
@@ -80,11 +81,11 @@ zle-finish () {
   (( $+mark )) && print -lr "MARK: $mark"
   zle accept-line
 }
-zle -N expand-or-complete-with-report
+zle -N complete-word-with-report
 zle -N list-choices-with-report
 zle -N comp-finish
 zle -N zle-finish
-bindkey "^I" expand-or-complete-with-report
+bindkey "^I" complete-word-with-report
 bindkey "^D" list-choices-with-report
 bindkey "^Z" comp-finish
 bindkey "^X" zle-finish


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-30 23:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 15:24 Patch: Add file types to _expand completions Marlon Richert
2021-03-27 16:26 ` Lawrence Velázquez
2021-03-30 23:25 ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).