Add new notification for lexer plugin

The NPPN_EXTERNALLEXERBUFFER is sent to plugins with buffer ID (idFrom) when a new lexer is applied to the buffer in question.

Fix #12351, close #13091
This commit is contained in:
Don Ho 2023-02-10 19:54:31 +01:00
parent 4d107e2691
commit 03a5c4795b
4 changed files with 20 additions and 0 deletions

View File

@ -746,3 +746,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
//scnNotification->nmhdr.code = NPPN_CMDLINEPLUGINMSG;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = pluginMessage; //where pluginMessage is pointer of type wchar_t
#define NPPN_EXTERNALLEXERBUFFER (NPPN_FIRST + 29) // To notify lexer plugins that the buffer (in idFrom) is just applied to a external lexer
//scnNotification->nmhdr.code = NPPN_EXTERNALLEXERBUFFER;
//scnNotification->nmhdr.hwndFrom = hwndNpp;
//scnNotification->nmhdr.idFrom = BufferID; //where pluginMessage is pointer of type wchar_t

View File

@ -2132,6 +2132,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE;
}
case NPPM_INTERNAL_EXTERNALLEXERBUFFER:
{
// A buffer is just applied to an external lexer, let's send a notification to lexer plugin
// so the concerning plugin can manage it (associate the buffer & lexer instance).
SCNotification scnN{};
scnN.nmhdr.code = NPPN_EXTERNALLEXERBUFFER;
scnN.nmhdr.hwndFrom = hwnd;
scnN.nmhdr.idFrom = lParam;
_pluginsManager.notify(&scnN);
return TRUE;
}
case WM_QUERYENDSESSION:
{
// app should return TRUE or FALSE immediately upon receiving this message,

View File

@ -902,6 +902,8 @@ void ScintillaEditView::setExternalLexer(LangType typeDoc)
return;
execute(SCI_SETILEXER, 0, reinterpret_cast<LPARAM>(iLex5));
::SendMessage(_hParent, NPPM_INTERNAL_EXTERNALLEXERBUFFER, 0, (LPARAM)getCurrentBufferID());
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
const wchar_t* lexerNameW = wmc.char2wchar(externalLexer._name.c_str(), CP_ACP);
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerNameW);

View File

@ -649,6 +649,7 @@
#define NPPM_INTERNAL_NPCFORMCHANGED (NOTEPADPLUS_USER_INTERNAL + 73)
#define NPPM_INTERNAL_NPCLAUNCHSTYLECONF (NOTEPADPLUS_USER_INTERNAL + 74)
#define NPPM_INTERNAL_CLOSEDOC (NOTEPADPLUS_USER_INTERNAL + 75)
#define NPPM_INTERNAL_EXTERNALLEXERBUFFER (NOTEPADPLUS_USER_INTERNAL + 76)
// See Notepad_plus_msgs.h
//#define NOTEPADPLUS_USER (WM_USER + 1000)