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

PATCH: matching completer function



This updates the README file (mentioning the completer functions and
re-sorting the filenames alphabetically) and adds a new completer
function `_match' (glob_complete always was a misnomer and currently
all completer function have verb-ish names).

This is intended to be used after `_complete', as in:

  compconf completer=_complete:_match:_correct:_approximate

If you use it, you should not set `globcomplete' because then matching 
would be done in all completion functions, of course. Also, you'll
probably don't want to use it with `expand-or-complete', but instead
with `complete-word', because due to `globcomplete' being unset,
patterns would then be expanded immediatly.
There is also a configuration key allowing you to first try matching
without the notorious `*' inserted at the cursor position.

Maybe I should put all the configuration stuff into README(?).

Bye
 Sven

--- oc/README	Mon Mar 22 14:54:42 1999
+++ Completion/README	Tue Mar 23 11:40:22 1999
@@ -14,7 +14,8 @@
 This will rebind any keys which do completion to use the new system.
 For more detailed instructions, including how to add new completions, see
 the top of Core/compinit. For information about how to configure the code,
-see the comment at the top of Core/_main_complete.
+see the comment at the top of Core/_main_complete and the completer
+functions.
 
 The subdirectories contain:
 
@@ -30,21 +31,30 @@
     This dumps the completions status for faster initialisation.  The
     easiest way of doing this is to use the -d option to compinit rather
     than calling compdump directly.
-  _sep_parts
-    Utility used for completing words with multiple separate parts, such as
-    `<user>@<host>'
-  _multi_parts
-    Utility for completion parts of words given a separator character and 
-    a list of words.
+  _approximate
+    A completer function that does correcting completion.
   _compalso
     Utility for calling a function to add additional completions to an
     already existing set.
+  _complete
+    The main completer function that generates the completions by calling
+    the context and command specific functions.
+  _correct
+    A completer function that attempts correction on the word from the
+    line. Unlike _approximate this does only correction, not completion.
   _files
     A frontend to _path_files which will default to any old file if the
     specified file was not found.
+  _match
+    A completer function that temporarily swicthes on pattern matching
+    when comparing the string from the line with possible completions.
   _main_complete
     The main entry point called by the key bindings which compinit sets
-    up (the main `completion widget' in zsh jargon).
+    up (the main `completion widget' in zsh jargon). This mainly calls
+    completer functions like _complete.
+  _multi_parts
+    Utility for completion parts of words given a separator character and 
+    a list of words.
   _normal
     The function called by _main_complete to handle the most common
     cases, such as completing a command name or its arguments.  This
@@ -56,6 +66,9 @@
     replaces the standard -f, -g and -/ options for the basic completion
     commands:  it can do various extra tricks, such as expanding a whole
     path at once, e.g. F/C/C/_p<TAB> -> Functions/Completion/Core/_path_files
+  _sep_parts
+    Utility used for completing words with multiple separate parts, such as
+    `<user>@<host>'
 Base:
   You will almost certainly want these files, too, which handle standard
   tasks like completing files.  However, you may want to edit them for
--- Completion/Core/_match	Tue Mar 23 11:56:01 1999
+++ Completion/Core/_match	Tue Mar 23 11:51:50 1999
@@ -0,0 +1,53 @@
+#autoload
+
+# This is inteded to be used as a completer function after the normal
+# completer as in: `compconf completer=_complete:_match'.
+# It temporarily switches on pattern matching, allowing you to
+# try completion on patterns without having to setopt glob_complete.
+#
+# Note, however, that this is only really useful if you don't use the
+# expand-or-complete function because otherwise the pattern will
+# be expanded using globbing.
+#
+# Configuration key used:
+#
+#  match_original
+#    If this is set to a `only', pattern matching will only be tried
+#    with the string from the line. If it is set to any other non-empty
+#    string, the original pattern will be tried first and if that yields
+#    no completions, matching will be tried again with a `*' inserted
+#    at the cursor position. If this key is not set or set to an empty
+#    string, matching will only be attempted with the `*' inserted.
+
+local tmp opm="$compstate[pattern_match]" ret=0
+
+# Do nothing if we don't have a pattern or there are still global
+# match specifications to try.
+
+tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
+[[ "$tmp:q" = "$tmp" ||
+   compstate[matcher] -ne compstate[total_matchers] ]] && return 1
+
+# Try completion without inserting a `*'?
+
+if [[ -n "$compconfig[match_original]" ]]; then
+  compstate[matcher]=-1
+  compstate[pattern_match]='-'
+  _complete && ret=1
+  compstate[pattern_match]="$opm"
+  compstate[matcher]="$compstate[total_matchers]"
+
+  (( ret )) && return 0
+fi
+
+# No completion with inserting `*'?
+
+[[ "$compconfig[match_original]" = only ]] && return 1
+
+compstate[matcher]=-1
+compstate[pattern_match]='*'
+_complete && ret=1
+compstate[pattern_match]="$opm"
+compstate[matcher]="$compstate[total_matchers]"
+
+return 1-ret

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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