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

Re: compctl tips needed on words with common prefix



On Jun 17, 12:33pm, Paul Lew wrote:
} Subject: Re: compctl tips needed on words with common prefix
}
} >>>>> "Bart" == Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
} 
}     Bart> What you mean to say, I think, is that any of (co1 co2 co3)
}     Bart> may appear *after* "co ".  Right?  In that case, what you
}     Bart> want is "c[-1,co]":
} 
}     Bart> compctl -k "(ci co construct cinema)" \
}     Bart> -x "c[-1,co]" -k "(co1 co2 co3)" \
}     Bart> - "c[-1,construct]" -k "(cons1 cons2)" -- xxx 
} 
} That works.  But my situation is a little different, what I would like
} is to have "co1 co2 co3" be part of the completion words as long as
} there is a word "co" in front, i.e.,
} 
}       xxx co co1 co2	       or
}       xxx co co3 co1 co2
} 
} Do c[offset,string] require a fixed offset or can be a range?

Yes, the offset must be fixed for c[].

} Also, I still want to be able to complete the 'construct'.

Your best bet might be to go with compctl -K and write yourself a function
to perform the pattern matching.  The built-in mechanisms aren't designed
to deal easily with so many words with common prefixes.  (If your command
looked like "xxx -co co1 co2 -construct cons1" then it'd be much easier.)

Here's a sample that illustrates two possible approaches to your problem
that don't use a -K function:

	compctl -k "(ci co construct cinema)" \
	-x "c[-1,co]" -k "(co1 co2 co3)" \
	- "C[-1,co[123]]" -k "(co1 co2 co3 construct)" \
	- "c[-1,construct], C[-1,cons[12]]" -k "(cons1 cons2)" -- xxx

The first approach is to use separate rules "c[-1,co]" and "C[-1,co[123]]"
which tell what to complete after a word matching "co" and after a word
matching the glob pattern "co[123]", respectively.  This requires that you
maintain the (co1 co2 co3) list in two places, and also keep the glob up
to date, if those items in the -k list ever change.

The second uses alternative patterns "c[-1,construct], C[-1,cons[12]]"
which match either "construct" or the glob "cons[12]".  This is a bit
simpler to maintain (one list and the equivalent glob) but does not permit
you e.g. to complete "co" following "cons1".

Good luck.  (I hesitate to inquire further about the "xxx cinema" part ...)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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