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

Re: java class names completion widget



Hi Peter

On Wednesday 07 June 2006 14:47, Peter Stephenson wrote:
> (I'm going to assume you're already using the new completion system,
> which seems to be the case.)
yes

> You can actually do the case matching element within zsh without any new
> code; the difficult bit is the combination of completion and finding
> files, but that's difficult to hook in to completion regardless of
> whether the expansion is done inside or outside the shell.  Here's how
> you do the basic completion (given the problems this probably isn't what
> you want, so I'll look at another method later).  The following adds the
> smash case completion to the context after javac:
>
> zstyle ':completion:*:javac:*' matcher 'r:|[A-Z]=* r:|=*'

[skip]
Yeah, I've already played with this stuff. As you point out below, it doesn't 
search thru the nested folders, which is a very desired behaviour.
[skip]

> So instead let's hijack the _expand completer and provide a front end.
> The trouble with making this the normal contextual completer in place of
> _java is that you'll lose all the features of that and need to merge
> together what you want.  Hence what I suggest you do is use a separate
> completion when you want the special behaviour.  Then you'll have to
> remember to type a different key sequence for this, say C-x j.
>
> Here's the full code; put it in a file (say _expand_java_path) in your
> function path:
>
> #compdef -k complete-word ^xj
> local MATCH MBEGIN MEND
> # Turn the start of the string on the line into **/ followed
> # by the original prefix with upper case letters followed
> # by [^[:upper:]]# which matches any number of consecutive
> # non-upper-case characters.  This relies on the fact that
> # the completion system uses the EXTENDED_GLOB option.
> PREFIX="**/${PREFIX//(#m)[[:upper:]]/${MATCH}[^[:upper:]]#}"
> # Replace the end of the string similarly, adding *.java to
> # the pattern
> SUFFIX="${SUFFIX//(#m)[[:upper:]]/${MATCH}[^[:upper:]]#}*.java"
> # Now we've got a zsh recursive matching pattern; for example
> #   SHMa
> # has turned into
> #   **/S[^[:upper:]]#H[^[:upper:]]#M[^[:upper:]]#a*.java
> # Let the normal _expand completer get to work.
> _expand "$@"
>
> (Four lines of active code for the whole thing!)
>
> Those are the basics; there are many, many possible bells and whistles
> since all the features of the completion system are available for
> offering you matches, and actually the _expand completer does a bit to
> much work for us; we just want the globbing effect.
>
> In particular, the behaviour with ambiguous expansions could be better
> configured.  _expand turns on menu completion when inserting.  Currently
> it will cycle through possible expansions, then all expansions, then the
> original pattern (though it's not the original, it's the hacked version
> from _expand_java_path so isn't much use).  You can use the tag-order
> style to help.

Cool, this is what I've expected to get :)
It works, but how can I force it to use menu completion instead of cycling? 
Playing with 
zstyle ':completion:*' menu select
gives a bit weird effect:
(with descriptions turned on)

kos@kos ~/work/jrs $ S<^xj>
kos@kos ~/work/jrs $ src/org/kos/jrs/ShowCommand.java
---- expansions
src/org/kos/jrs/ShowCommand.java                                               
tests/org/kos/jrs/SubscriptionManagerMock.java
src/org/kos/jrs/SoftHashMap.java                                               
tests/org/kos/jrs/SubscriptionManagerTest.java
src/org/kos/jrs/SubscriptionManagerImpl.java                                   
whack/trunk/source/java/org/jivesoftware/whack/container/ServerContainer.java
src/org/kos/jrs/SubscriptionManager.java                                       
whack/trunk/source/java/org/jivesoftware/whack/SocketReadThread.java
src/org/kos/jrs/swap/SwapFileWritingContainer.java                             
whack/trunk/source/java/org/jivesoftware/whack/util/StringUtils.java
src/org/kos/jrs/swap/SwappableObjectContainer.java                             
whack/trunk/source/java/org/xmpp/packet/StreamError.java
src/org/kos/jrs/swap/SwappingMap.java
---- all expansions
---- original
src/org/kos/jrs/ShowCommand.java src/org/kos/jrs/SoftHashMap.java 
src/org/kos/jrs/SubscriptionManagerImpl.java 
src/org/kos/jrs/SubscriptionManager.java sr ...
**/S[^[:upper:]]#*.java
kos@kos ~/work/jrs $ src/org/kos/jrs/ShowCommand.java

As I understand it tries to show the menu but by some reason fallbacks to 
cycling.

Thanks a lot :)

-- 
/KoS
* Is this the party to who I am typing to?			      



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