From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13457 invoked from network); 3 May 2007 05:23:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.0 (2007-05-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=no version=3.2.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 May 2007 05:23:16 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 55114 invoked from network); 3 May 2007 05:23:09 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 May 2007 05:23:09 -0000 Received: (qmail 15406 invoked by alias); 3 May 2007 05:23:05 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23385 Received: (qmail 15395 invoked from network); 3 May 2007 05:23:04 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 May 2007 05:23:04 -0000 Received: (qmail 54730 invoked from network); 3 May 2007 05:23:04 -0000 Received: from redoubt.spodhuis.org (HELO mx.spodhuis.org) (193.202.115.177) by a.mx.sunsite.dk with SMTP; 3 May 2007 05:23:00 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=first1; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:MIME-Version:Content-Type:Content-Disposition; b=d42i59ZUeLdY6+M2N5Vi3nzNWf92TI0fJyWGRrmCmuGSOaHvPuWTHAti7PtjHPVMsGvlXn7rrwUlqWE2+RZSgoZVwc2VeWI498lnAuh2ajdxpQR5f2sfDQWDjxSfaXu+NrZacMMVA8/Y7+x3u9lyvCi0kFP+UbnATJlty3vL49Q=; Received: by smtp.spodhuis.org with local id 1HjTmM-000OLD-Qy; Thu, 03 May 2007 05:22:58 +0000 Date: Wed, 2 May 2007 22:22:58 -0700 From: Phil Pennock To: zsh-workers@sunsite.dk Subject: [Contrib] digraphs / composition pairs Message-ID: <20070503052258.GA93519@redoubt.spodhuis.org> Mail-Followup-To: zsh-workers@sunsite.dk MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline After reading about insert-composed-char, I wanted to be able to add my own definitions; I don't see a reason why all possible compose sequences need to be centrally maintained. Eg, in vim I like having the smiley faces available (even if I never do use them ...) I'm a bit unsure about the function naming; vim calls these digraphs and I'd quite like some compatibility, but normal single-letter options are also valid composition sequences. Otherwise, I'd name the main function "digraph" and give it a -d option to take decimal values, for vim compatibility. If these get accepted, they should get renamed by someone with a better sense of naming aesthetics. vim: digraph :) 9786 :( 9785 zsh: add_composition_pair ':)' 263A ':(' 2639 digraph_decimal ':)' 9786 ':(' 9785 This also provides a digraphs command, which produces a list of all digraphs. Something's nagging at me about there being a supplied zsh method of doing "fmt" reliably internally ... function add_composition_pair { emulate -L zsh if (( $# % 2 )) then print -u2 "Usage: $0 [ ...]" return 1 fi if (( ${+zsh_accented_chars} == 0 )) then autoload -U define-composed-chars define-composed-chars unfunction define-composed-chars fi while (( $# )) do local pair="$1" val="$2" shift 2 local -A existing existing=( ${=zsh_accented_chars[${pair[2]}]} ) if [[ -n ${(k)existing[${pair[1]}]} ]] then noglob unset existing[${pair[1]}] zsh_accented_chars[${pair[2]}]=" ${(kv)existing}" fi zsh_accented_chars[${pair[2]}]+=" ${pair[1]} $val" done } function digraph_decimal { local pair val local -a acp for pair val in "$@" do [[ -n $val ]] && val=$(( [#16] 10#$val)) acp+=($pair ${val#0x}) done add_composition_pair $acp } function digraphs { local p1 p2 p v local -A nested all if (( ${+zsh_accented_chars} == 0 )) then autoload -U define-composed-chars define-composed-chars unfunction define-composed-chars fi for p2 in ${(k)zsh_accented_chars} do nested=(${=zsh_accented_chars[$p2]}) for p1 in ${(k)nested} do v=${nested[$p1]} [[ ${#v} -gt 4 ]] && v=${(l.8..0.)v} || v=${(l.4..0.)v} all[$p1$p2]=$v done done for p in ${(ko)all} do print -- "${(q)p} ${all[$p]} \U${(l.8..0.)all[$p]}" done }