From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14920 invoked from network); 15 Aug 2006 11:11:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Aug 2006 11:11:46 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 2554 invoked from network); 15 Aug 2006 11:11:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Aug 2006 11:11:40 -0000 Received: (qmail 6992 invoked by alias); 15 Aug 2006 11:11:30 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10610 Received: (qmail 6983 invoked from network); 15 Aug 2006 11:11:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Aug 2006 11:11:29 -0000 Received: (qmail 1438 invoked from network); 15 Aug 2006 11:11:28 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 15 Aug 2006 11:11:27 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly07d.srv.mailcontrol.com (MailControl) with ESMTP id k7FBBO3k032475 for ; Tue, 15 Aug 2006 12:11:25 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 15 Aug 2006 12:11:24 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.4/8.13.4) with ESMTP id k7FBBOiG012189 for ; Tue, 15 Aug 2006 12:11:24 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.4/8.13.4/Submit) with ESMTP id k7FBBOKU012186 for ; Tue, 15 Aug 2006 12:11:24 +0100 Message-Id: <200608151111.k7FBBOKU012186@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-users@sunsite.dk (Zsh users list) Subject: Function to describe keys not so briefly Date: Tue, 15 Aug 2006 12:11:24 +0100 From: Peter Stephenson X-OriginalArrivalTime: 15 Aug 2006 11:11:24.0649 (UTC) FILETIME=[8BCA5D90:01C6C05B] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-04-01 (www.mailcontrol.com) on 10.68.0.117 This is sort of related to the thread in zsh-users/10180. I've been wanting a function which probes zle key sequences in a bit more depth than describe-key-briefly. The following function can be called from the command line or used as a zle widget. It shows details about the bound widget and how it's implemented. If anyone likes it I'll add it to the distribution. ##start## # Pass the function a key sequence in the normal form used by the # first argument of "bindkey". The key sequence is analysed to find # out how it's bound and implemented. The bindkey keymap selection # options are understood. # # This can be used directly as a zle widget, in which case it prompts # for and reads a key sequence and displays the information about it # in the status area. # # The module zsh/zleparameter is requried for details of the widget, # and the module zsh/parameter is required for details of the # implementation function (if any). emulate -L zsh setopt extendedglob local opt mapname desc widget func local -a match mbegin mend keymap if zle; then local REPLY zle -R 'Enter key sequence:' zle read-command && widget=$REPLY set -- $KEYS mapname="the keymap $KEYMAP" else while getopts "M:" opt; do case $opt in (e) keymap=(-M emacs) ;; (v) keymap=(-M viins) ;; (a) keymap=(-M vicmd) ;; (M) keymap=(-M $OPTARG) ;; (*) return 1 ;; esac done shift $(( OPTIND - 1 )) if (( ${#keymap} )); then mapname="the keymap ${keymap[-1]}" else mapname="the current keymap" fi widget=${${(Q)${(z)"$(bindkey $keymap $1)"}}[2]} || return fi if [[ -z $widget || $widget = undefined-key ]]; then desc="${(qqV)1} is not bound in $mapname" else desc="${(qqV)1} is bound to the widget ${(qq)widget} in $mapname" zmodload -i zsh/zleparameter || return 1 local details=$widgets[$widget] case $details in (builtin) desc+=$'\n'"${(qq)widget} is a builtin widget" ;; (user:(#b)(*)) func=$match[1] desc+=$'\n'"${(qq)widget} is a user-defined widget" ;; (completion:(#b)([^:]#):(*)) func=$match[2] desc+=$'\n'"${(qq)widget} is a completion widget with style $match[1]" ;; (*) desc+=$'\n'"${(qq)widget} is not registered as a widget" ;; esac if [[ -n $func ]]; then local -a where where=($^fpath/$func(N)) desc+=$'\n'"${(qq)widget} is implemented by the function ${(qq)func}" if (( ${#where} )); then desc+=$'\n'"${(qq)func} is a function loaded from:" desc+=$'\n'" ${where[1]}" else desc+=$'\n'"${(qq)func} is not in the function path" fi zmodload -i zsh/parameter || return if [[ -z $functions[$func] ]]; then desc+=$'\n'"${(qq)func} is not defined nor marked for autoload" elif [[ $functions[$func] = "builtin autoload -X"(#b)(*) ]]; then desc+=$'\n'"${(qq)func} is marked for autoload" if [[ -n $match[1] ]]; then desc+=" (flags -$match[1])" fi else desc+=$'\n'"${(qq)func} is already defined as a function" fi fi fi if zle; then zle -M $desc else print -r -- $desc fi ##end## -- Peter Stephenson 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