Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: _expand completer and hashed dirs



On Sep 21,  3:47pm, Frank Terbeck wrote:
}
} While this works fine:
} 
}     % ls ~vi<tab>
}     % ls ~vim/
} 
} This doesn't:
} 
}     % ls ~vim<tab>
}     - all expansions -
}     /home/hawk/.vim
}     - original -
}     ~vim
} 
} I would much rather like to get 'ls ~vim/' out of it.

To the extent that there's an intention involved here, it's that the
presumption is that completion is supposed to save keystrokes; so if
you hit TAB at a position where exactly one other keystroke (in this
case a slash) would remove the ambiguity, you get offered the longer
possibility ... because if you meant the shorter one you would have
just typed that other key in the first place.

That said ...

} I've been playing with a number of styles, but they don't seem to
} have any impact on the situation.

    zstyle ':completion:*:expand:*' accept-exact true

would seem to be *supposed* to produce the effect you want, but the
definition of "words beginning with a tilde or parameter expansion"
is implemented so as to exclude words that have no suffix beyond the 
parameter or nameddir -- that is, as I noted above, it's making the
presumption that you wouldn't have used TAB at that position if your
intent was not to expand the word.

Here's a patch that implements accept-exact strict, which applies
in the way that you want.  I'll not commit this, for the following
reasons:

(1) "setopt rec_exact" behaves like strict rather than like true

(2) a better word than "strict" might be found

(3) a better (but changed from historical) behavior might be to
    extend yes/true/on/1 to behave as this makes strict, and have
    a different value ("prefix"?) to mean the current behavior

(4) I haven't had a chance to document it

Patch is bigger than would seem necessary because the "tmp" local
is clobbered after it's initially used to test accept-exact.


Index: Completion/Base/Completer/_expand
===================================================================
retrieving revision 1.10
diff -c -r1.10 _expand
--- _expand	18 Mar 2006 08:00:20 -0000	1.10
+++ _expand	21 Sep 2009 14:27:04 -0000
@@ -12,7 +12,7 @@
 [[ _matcher_num -gt 1 ]] && return 1
 
 local exp word sort expr expl subd suf=" " force opt asp tmp opre pre epre
-local continue=0
+local continue=0 exact
 
 (( $# )) &&
     while getopts gsco opt; do
@@ -38,16 +38,16 @@
      "${(e)word}" != (#s)(*[^\\]|)[][^*?\(\)\<\>\{\}\|]* ]] &&
   return 1
 
-zstyle -s ":completion:${curcontext}:" accept-exact tmp ||
-    [[ ! -o recexact ]] || tmp=1
+zstyle -s ":completion:${curcontext}:" accept-exact exact ||
+    [[ ! -o recexact ]] || exact=1
 
-if [[ "$tmp" != (yes|true|on|1) ]]; then
+if [[ "$exact" != (strict|yes|true|on|1) ]]; then
   { [[ "$word" = \~(|[-+]) ||
        ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ]] && return
1 }
   { [[ ( "$word" = \~* &&
${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) ||
        ( "$word" = *\$[a-zA-Z0-9_]## && 
          ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && continue=1 }
-  [[ continue -eq 1 && "$tmp" != continue ]] && return 1
+  [[ continue -eq 1 && "$exact" != continue ]] && return 1
 fi
 
 # In exp we will collect the expansions.
@@ -114,7 +114,8 @@
 
 (( $#exp )) || exp=("$subd[@]")
 
-[[ $#exp -eq 1 && "${exp[1]//\\}" = "${word//\\}"(|\(N\)) ]] && return 1
+[[ $#exp -eq 1 && ( "$exact" = "strict" ||
+                    "${exp[1]//\\}" = "${word//\\}"(|\(N\)) ) ]] && return 1
 
 # With subst-globs-only we bail out if there were no glob expansions,
 # regardless of any substitutions


-- 



Messages sorted by: Reverse Date, Date, Thread, Author