2008/6/19 Bram Moolenaar <[EMAIL PROTECTED]>: > > Bjorn Winckler wrote: > >> 2008/6/18 Tony Mechelynck <[EMAIL PROTECTED]>: >> > >> > On 18/06/08 12:03, bj=F6rn wrote: >> >> 2008/6/18 Tony Mechelynck<[EMAIL PROTECTED]>: >> >>> 'encoding' set to UTF-8 means the contents of _files being edited_ are >> >>> represented internally as UTF-8. IIUC, the menu locale is defined by >> >>> ":language messages" at the time the menu script is sourced: >> >> >> >> Thanks for clarifying that. So now that I can't rely on strings in >> >> Vim being utf-8, how do I find out which encoding they are in? (I'm >> >> sorry if this is obvious, but all this locale stuff is a bit of a >> >> mystery to me.) >> >> >> > >> > Try adding the line >> > >> > scriptencoding latin1 >> > >> > near the top of the menufiles, and in any case before the first >> > upper-ascii character. >> >> Let me clarify: I am not a script writer, instead I am writing a GUI >> port for Mac OS X. Thus, I need to implement functions like >> gui_mch_add_menu_item(). In this function I get passed a pointer to a >> vimmenu_T struct which contains a "dname" C-string specifying the name >> of a menu item. My question is: how do I find out which encoding this >> C-string is in? >> >> (From your previous post I found out that e.g. gui_mch_draw_string() >> will pass strings in the encoding specified by 'enc', thus I can look >> at output_conv to determine if I need to convert the string to utf-8 >> before drawing it. However, I cannot use the same method to decide if >> conversion is necessary for the titles of menu items.) > > Menu functions don't deal with more than one encoding. The Vim script > is written in a certain encoding. It must either match the value of > 'encoding' or specify the encoding actually used with the > :scriptencoding command. > > Thus in all the gui_*.c functions you can safely assume that all menu > text is in 'encoding'.
Bram, thanks for the answer. This presents a problem with scripts that do not use :scriptencoding like the HTML plugin. It (I'm only using it as an example since its the only problem I'm aware of) defines menu items whose titles contain characters with the 8th bit set (in latin-1 encoding). With 'enc=utf-8' these characters are not converted to utf-8 so when gui_mch_add_menu_item() is called MacVim chokes because it is fed menu titles with invalid utf-8 strings (since they are in fact latin-1). I can work around this problem by falling back to using latin-1 encoding when the utf-8 is invalid, but this doesn't seem like a good solution. I tried understanding how the other GUI ports deal with this issue in gui_mch_add_menu_item() but they all seem to assume that the value of 'enc' is respected. I don't know why they don't fail since I'm not familiar with the APIs used on those platforms. Have you got any suggestions how to deal with scripts that fail to set :scriptencoding? It seems to me this is a real problem since it makes the encoding of (e.g.) menu titles unpredictable, and its thus up to the OS APIs to deal with the issue (not very reliable since each OS behaves differently). Björn --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
