Thursday, May 31, 2018

Re: statusline, display hand-defined IPA or other arbitrary text for character under cursor

On Wednesday, May 30, 2018 at 2:03:21 PM UTC-6, Kenneth Reid Beesley wrote:
> In my 'set statusline' in .gvimrc, I have a very helpful 0x%04B code that displays the hex code point value (minimum four hex digits, zero padded) of the buffer character under the cursor.
>
> In addition to that, I'd like to be able to display an arbitrary hand-defined character or string of characters that might represent the pronunciation (e.g. in the International Phonetic Alphabet) or a keymap input sequence.
>
> In particular, I have defined a Japanese-hiragana keymap that allows me to type hi, which is intercepted by the keymap, which places the Japanese hiragana character 0x3072 in the (g)vim buffer. The line in the keymap looks like this:
>
> hi <Char-0x3072>
>
> That works just fine.
> But in addition, I'd essentially like the status line to display the reverse, such that when the cursor is on a 0x3072 character, I'd also like the statusline to display (for my own benefit) the letters hi. I don't expect vim to know that 0x3072 should cause "hi" to be displayed in the statusline---rather I would define that somewhere, in a kind of reverse-keymap file.
>
> The same mechanism could be used to display IPA symbols, or whatever, when the cursor is on a Greek, Russian, Georgian, or whatever character.

I'm using gvim (MacVim).

I've got at least the beginnings of a solution (corrections and suggestions would be welcome). The attached file revkeymap.vim (which resides in ~/.vim/plugin/) defines the function Revkeymap(), which defines a dict mapping code point values to the little strings that I want to be displayed. So, for example, the Japanese hiragana character 0x3072 is mapped to "hi", 0x3073 is mapped to "bi", etc. The function retrieves the current character under the cursor, converts it to a number (the code point value), looks up the code point value in the dict, and returns the associated string. If they key is not in the dict, then an empty string is returned.

The function is called in 'set statusline' as %{Revkeymap()}, so the "hi" string gets returned and displayed in the statusline when the cursor is over the 0x3072 character. The mapping could be extended, of course, to define IPA displays for Russian, Greek, Georgian, or whatever characters.

My problem now is that I can input the hiragana characters, but the glyphs must be coming from some default font in the operating system (I'm using MacVim). The glyphs are wider than the glyphs in the mono font specified with 'set guifont', and so the cursor doesn't align properly with the glyphs. The buffer has a mixture of Roman character glyphs (from the mono font) and wider hiragana glyphs (from who-knows-where).

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment