dail8859 / LuaScript

Notepad++ plugin for Lua scripting capabilities

Home Page:https://dail8859.github.io/LuaScript/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change File Encoding

xylographe opened this issue · comments

I was looking for a way to change file encoding.
Apparently, this would require NPPM_[GS]ETBUFFERENCODING?
If that is correct, is there any chance those might be added in the near future?

Hi @xylographe!

Just looking at the API for those messages should be pretty easy to add in for the next release. I just never had a need for them so I never got around to it.

Until then you can trigger the menu options manually using the MenuCommand call.

For example:

npp:MenuCommand(IDM_FORMAT_UTF_8)

I'm not sure how exactly the IDM_xxx constants map to the menu items so it might take a little trial and effort to find exactly which ones you need.

Thank you, Justin!

The MenuCommand works great!
IDM_FORMAT_CONV2_AS_UTF_8 converts to utf8, IDM_FORMAT_CONV2_UTF_8 to utf8-bom. Exactly what I was looking for. 😄 This is very useful in OnBeforeSave event to enforce – depending on BufferLangType[] – correct encoding, correct EOL, etc.

Is there a set of defined constants that are used for NPPM_[GS]ETBUFFERENCODING anywhere? Not sure where these values come from.

enum UniMode was defined in SciTEBase.h. But, that file seems to have been removed/renamed.

EDIT: It's in Parameters.h

Thank you for adding BufferEncoding[].

In startup.lua I added,

UniMode = { ANSI = 0; UTF8_BOM = 1; UTF16BE_BOM = 2; UTF16LE_BOM = 3; UTF8 = 4; ASCII = 5; UTF16BE = 6; UTF16LE = 7 }

Perhaps, it might be convenient to make a UniMode table available through npp (e.g. npp.UniMode.UTF8)?