* Re: how to customize _all_matches use?
[not found] ` <200706161906.l5GJ63Rq014600@rly16c.srv.mailcontrol.com>
@ 2007-06-18 18:24 ` Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2007-06-18 18:24 UTC (permalink / raw)
To: zsh-workers
On Sat, 16 Jun 2007 21:05:42 +0200
Vadim Zeitlin <vz-zsh@zeitlins.org> wrote:
> I wonder if _complete_help can somehow be used to show the
> context for another completer?
Here's an implementation of _complete_help or _complete_debug for the
_generic completer. After you've created a (non-completion) widget you
just need to type the key sequence for that, then the key sequence for the
generic widget, so it's a lot more useful than my first attempt. Even so,
it takes more lines to describe than to implement.
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.201
diff -u -r1.201 compsys.yo
--- Doc/Zsh/compsys.yo 16 Jun 2007 17:53:56 -0000 1.201
+++ Doc/Zsh/compsys.yo 18 Jun 2007 18:18:54 -0000
@@ -3179,6 +3179,42 @@
information available from the completion functions called, which in turn
is determined by the user's own styles and other settings.
)
+findex(_complete_help_generic)
+item(tt(_complete_help_generic))(
+Unlike other commands listed here, this must be created as a normal ZLE
+widget rather than a completion widget (i.e. with tt(zle -N)). It
+is used for generating help with a widget bound to the tt(_generic)
+widget that is described above.
+
+If this widget is created using the name of the function, as it is by
+default, then when executed it will read a key sequence. This is expected
+to be bound to a call to a completion function that uses the tt(_generic)
+widget. That widget will be executed, and information provided in
+the same format that the tt(_complete_help) widget displays for
+contextual completion.
+
+If the widget's name contains tt(debug), for example if it is created
+as `tt(zle -N _complete_debug_generic _complete_help_generic)', it
+will read and execute the keystring for a generic widget as before,
+but then generate debugging information as done by tt(_complete_debug)
+for contextual completion.
+
+If the widget's name contains tt(noread), it will not read a keystring
+but instead arrange that the next use of a generic widget run in
+the same shell will have the effect as described above.
+
+The widget works by setting the shell parameter
+tt(ZSH_TRACE_GENERIC_WIDGET) which is read by tt(_generic). Unsetting
+the parameter cancels any pending effect of the tt(noread) form.
+
+For example, after executing the following:
+
+example(zle -N _complete_debug_generic _complete_help_generic
+bindkey '^x:' _complete_debug_generic)
+
+typing `tt(C-x :)' followed by the key sequence for a generic widget
+will cause trace output for that widget to be saved to a file.
+)
findex(_complete_tag (^Xt))
item(tt(_complete_tag (^Xt)))(
This widget completes symbol tags created by the tt(etags) or tt(ctags)
Index: Completion/Base/Utility/_complete_help_generic
===================================================================
RCS file: Completion/Base/Utility/_complete_help_generic
diff -N Completion/Base/Utility/_complete_help_generic
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Completion/Base/Utility/_complete_help_generic 18 Jun 2007 18:18:54 -0000
@@ -0,0 +1,17 @@
+#autoload
+
+# Note this is a normal ZLE widget, not a completion widget.
+# A completion widget can't call another widget, while a normal
+# widget can.
+
+[[ $WIDGET = *noread* ]] || local ZSH_TRACE_GENERIC_WIDGET
+
+if [[ $WIDGET = *debug* ]]; then
+ ZSH_TRACE_GENERIC_WIDGET=_complete_debug
+else
+ ZSH_TRACE_GENERIC_WIDGET=_complete_help
+fi
+
+if [[ $WIDGET != *noread* ]]; then
+ zle read-command && zle $REPLY -w
+fi
Index: Completion/Base/Widget/_complete_debug
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_complete_debug,v
retrieving revision 1.5
diff -u -r1.5 _complete_debug
--- Completion/Base/Widget/_complete_debug 22 May 2005 15:46:36 -0000 1.5
+++ Completion/Base/Widget/_complete_debug 18 Jun 2007 18:18:54 -0000
@@ -11,7 +11,7 @@
setopt xtrace
: $ZSH_NAME $ZSH_VERSION
-_main_complete
+${1:-_main_complete}
integer ret=$?
unsetopt xtrace
Index: Completion/Base/Widget/_complete_help
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_complete_help,v
retrieving revision 1.5
diff -u -r1.5 _complete_help
--- Completion/Base/Widget/_complete_help 8 Jul 2002 08:59:40 -0000 1.5
+++ Completion/Base/Widget/_complete_help 18 Jun 2007 18:18:54 -0000
@@ -37,7 +37,7 @@
}
trap 'unfunction compadd zstyle' EXIT INT
- _main_complete
+ ${1:-_main_complete}
unfunction compadd zstyle
trap - EXIT INT
Index: Completion/Base/Widget/_generic
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Widget/_generic,v
retrieving revision 1.3
diff -u -r1.3 _generic
--- Completion/Base/Widget/_generic 24 Apr 2005 18:38:01 -0000 1.3
+++ Completion/Base/Widget/_generic 18 Jun 2007 18:18:54 -0000
@@ -1,5 +1,12 @@
#autoload
+if [[ -n $ZSH_TRACE_GENERIC_WIDGET ]]; then
+ local widget=$ZSH_TRACE_GENERIC_WIDGET
+ unset ZSH_TRACE_GENERIC_WIDGET
+ $widget _generic
+ return
+fi
+
local curcontext="${curcontext:-}"
if [[ -z "$curcontext" ]]; then
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-06-18 18:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <200706161725.l5GHPwPm004038@pwslaptop.csr.com>
[not found] ` <200706161906.l5GJ63Rq014600@rly16c.srv.mailcontrol.com>
2007-06-18 18:24 ` how to customize _all_matches use? Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).