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

PATCH: stub for dynamic directory name completion



This provides a hook for you to complete dynamic directory names by
redefining _dynamic_directory_name.  As it's entirely up to you there's
no point in providing any code, although we could agree a useful format:
I'm using colon-separated name parts where the context for later parts
depends on earlier parts.  It's still quite hard to define completion
generically, even with styles, because of the tree structure.  Maybe
someone from computer-science-land has some bright ideas.

Index: Completion/Zsh/Context/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/.distfiles,v
retrieving revision 1.4
diff -u -r1.4 .distfiles
--- Completion/Zsh/Context/.distfiles	13 Jun 2008 13:57:04 -0000	1.4
+++ Completion/Zsh/Context/.distfiles	29 Sep 2008 17:32:27 -0000
@@ -5,6 +5,7 @@
 _brace_parameter
 _condition
 _default
+_dynamic_directory_name
 _equal
 _first
 _in_vared
Index: Completion/Zsh/Context/_dynamic_directory_name
===================================================================
RCS file: Completion/Zsh/Context/_dynamic_directory_name
diff -N Completion/Zsh/Context/_dynamic_directory_name
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Zsh/Context/_dynamic_directory_name	29 Sep 2008 17:32:27 -0000
@@ -0,0 +1,7 @@
+#autoload
+
+# The core libraries don't check for dynamic directory name expansion;
+# this gets called from _subscript.  This is a placeholder for
+# people to overload.
+
+_message 'dynamic directory name: redefine _dynamic_directory_name to use'
Index: Completion/Zsh/Context/_subscript
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_subscript,v
retrieving revision 1.14
diff -u -r1.14 _subscript
--- Completion/Zsh/Context/_subscript	9 Apr 2008 13:06:55 -0000	1.14
+++ Completion/Zsh/Context/_subscript	29 Sep 2008 17:32:27 -0000
@@ -10,7 +10,16 @@
 
 compset -P '\(([^\(\)]|\(*\))##\)' # remove subscript flags
 
-if [[ "$PREFIX" = :* ]]; then
+# Look for a dynamic name expansion.  Completion only gives us
+# the stuff inside the square brackets; we need to find out what's
+# outside.  We ought to check for quoting, really, but given we've
+# got to the subscript code " ~[" is pretty likely to be a dynamic
+# name expansion.
+integer pos=$((CURSOR+1))
+while [[ pos > 1 && $BUFFER[pos-1] != '[' ]]; do (( pos-- )); done
+if [[ $BUFFER[1,pos] = *[[:space:]]##\~\[ ]]; then
+  _dynamic_directory_name
+elif [[ "$PREFIX" = :* ]]; then
   _wanted characters expl 'character class' \
       compadd -p: -S ':]' alnum alpha ascii blank cntrl digit graph \
                           lower print punct space upper xdigit


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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