zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-workers@sunsite.dk
Subject: [Contrib] digraphs / composition pairs
Date: Wed, 2 May 2007 22:22:58 -0700	[thread overview]
Message-ID: <20070503052258.GA93519@redoubt.spodhuis.org> (raw)

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 <pair> <hexval> [<pair> <hexval> ...]"
		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
}


                 reply	other threads:[~2007-05-03  5:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070503052258.GA93519@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).