From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26708 invoked from network); 20 Feb 2006 14:51:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 20 Feb 2006 14:51:21 -0000 Received: (qmail 47552 invoked from network); 20 Feb 2006 14:51:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 Feb 2006 14:51:12 -0000 Received: (qmail 14154 invoked by alias); 20 Feb 2006 14:51:02 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9947 Received: (qmail 14143 invoked from network); 20 Feb 2006 14:51:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 20 Feb 2006 14:51:01 -0000 Received: (qmail 45809 invoked from network); 20 Feb 2006 14:51:01 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 20 Feb 2006 14:51:00 -0000 Received: from exchange03.csr.com (uuk202166.uk.customer.alter.net [62.189.241.194] (may be forged)) by rly18c.srv.mailcontrol.com (MailControl) with ESMTP id k1KEot8m004126 for ; Mon, 20 Feb 2006 14:50:56 GMT Received: from csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 20 Feb 2006 14:50:55 +0000 To: zsh-users@sunsite.dk Subject: Re: swapping keys In-reply-to: <20060220141907.GA3663@let.rug.nl> References: <20060220141907.GA3663@let.rug.nl> Comments: In-reply-to Francisco Borges message dated "Mon, 20 Feb 2006 15:19:07 +0100." Date: Mon, 20 Feb 2006 14:50:41 +0000 From: Peter Stephenson Message-ID: X-OriginalArrivalTime: 20 Feb 2006 14:50:55.0332 (UTC) FILETIME=[0D6D1A40:01C6362D] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-06-00-02 (www.mailcontrol.com) on 10.67.0.128 Francisco Borges wrote: > One possible solution is to switch keys like "`~" and "1!" (I have to > confess I have only swapped "`~"). > > Since I am at it... Is it possible to swap keys inside zsh? Yes, it's fairly straightforward. As written it doesn't work for multibyte characters (e.g. you can't swap with a Euro or Yen or Pound Sterling in multibyte mode). That wouldn't be too hard to fix (but it's not as simple as just removing the test: you need a loop over bytes in the argument). # start # swapkeys X Y # swap keys X and Y so typing X gives Y and vice versa # swapkeys -d X Y # completely remove a previous swapping emulate -L zsh setopt cbases integer delete i local key hexkey if [[ $1 = -d ]]; then delete=1 shift fi if [[ $# -ne 2 || ${#1} -ne 1 || ${#2} -ne 1 ]]; then print "Usage: $0 [-d] key1 key2" >&2 return 1 fi for (( i = 1; i <= 2; i++ )); do key=$argv[i] hexkey=$(( [#16] #key )) if (( delete )); then zle -D insert-key-$hexkey bindkey $key self-insert else eval "insert-key-$hexkey () { LBUFFER+=\$'\\x${hexkey##0x}'; }" zle -N insert-key-$hexkey bindkey ${argv[3-i]} insert-key-$hexkey fi done # 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