jed-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Non-ascii chars in UTF-8 mode not bindable


=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>when you run jed or xjed in utf8â??mode you can't bind functions to
>nonâ??ascii keys like °, ´ or ¬, because they are multibyte sequences and
>they start all with the same charater. If you bind one, you loose all
>other.

Until I add a mechanism to support this, you might want to try to use
the following work-around.  Here is a sample usage:

  define alpha ()
  {
     insert ("\\alpha");
  }

  define beta ()
  {
     insert ("\\beta");
  }

  utf8_local_setkey ("alpha", "\u{03b1}");
  utf8_local_setkey ("beta", "\u{03b2}");

And here is the implementation of the utf8_local_setkey,
utf8_definekey, and utf8_setkey functions.  It's a bit ugly but I
think it works. --John

%-----------------------------------------------------
private variable UTF8_Keymaps = Assoc_Type[];
private variable Key_Sequence = NULL;

define utf8_handler ()
{
   variable byte = LAST_CHAR;
   variable byte_str = eval(sprintf("\\x%02X", byte));
   if (Key_Sequence == NULL)
     {
	if (0 == (byte & 0x80))
	  throw InvalidParmError, "Unexpected byte passed to utf8_handler";

	Key_Sequence = byte_str;
	return;
     }
   Key_Sequence = strcat (Key_Sequence, byte_str);
   if (strcharlen (Key_Sequence) != 1)
     {
	if (strbytelen (Key_Sequence) >= 6)
	  Key_Sequence = NULL;
	return;
     }

   variable keyseq = Key_Sequence;
   Key_Sequence = NULL;
   variable kmap = what_keymap ();
   if (0 == assoc_key_exists (UTF8_Keymaps, kmap))
     {
	insert (keyseq);
	return;
     }
   variable fmap = UTF8_Keymaps[keyseq];
   if (0 == assoc_key_exists (fmap, keyseq))
     {
	insert (keyseq);
	return;
     }
   variable func = fmap[keyseq];
   (@func)();
}

define utf8_definekey (func, keyseq, kmap)
{
   if ((strbytelen (keyseq) == 1)
       or (strcharlen (keyseq) != 1))
     {
	definekey (func, keyseq, kmap);
	return;
     }
   if (0 == assoc_key_exists (UTF8_Keymaps, kmap))
     UTF8_Keymaps[kmap] = Assoc_Type[Ref_Type];
   
   variable fmap = UTF8_Keymaps[kmap];
   fmap[keyseq] = func;
}

define utf8_setkey (func, key)
{
   utf8_definekey (func, key, "global");
}

define utf8_local_setkey (func, key)
{
   definekey (func, key, what_keymap ());
}

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]