From acb6b1e2a8ce6c1b7fdc53cc404231cdf4e18e0d Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sun, 9 Sep 2018 14:44:05 +0200 Subject: [PATCH] + add: option to merge Lexer's KeyWord List into AutoCompletion List --- language/common_res.h | 46 ++++++----- language/np3_af_za/menu_af_za.rc | Bin 43226 -> 43382 bytes language/np3_de_de/menu_de_de.rc | Bin 44952 -> 45092 bytes language/np3_en_gb/menu_en_gb.rc | Bin 43356 -> 43512 bytes language/np3_en_us/menu_en_us.rc | Bin 43330 -> 43486 bytes language/np3_es_es/menu_es_es.rc | Bin 43714 -> 43870 bytes language/np3_fr_fr/menu_fr_fr.rc | Bin 45832 -> 45988 bytes language/np3_ja_jp/menu_ja_jp.rc | Bin 41916 -> 42072 bytes language/np3_nl_nl/menu_nl_nl.rc | Bin 44876 -> 45032 bytes language/np3_zh_cn/menu_zh_cn.rc | Bin 41324 -> 41480 bytes src/Edit.c | 137 +++++++++++++++++++++++-------- src/Notepad3.c | 17 +++- src/StyleLexers/EditLexer.h | 2 +- 13 files changed, 143 insertions(+), 59 deletions(-) diff --git a/language/common_res.h b/language/common_res.h index 380c2c367..d2d50c6d8 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -504,32 +504,34 @@ #define IDM_VIEW_MARKOCCUR_CURRENT 40451 #define IDM_VIEW_MARKOCCUR_VISIBLE 40452 #define IDM_VIEW_AUTOCOMPLETEWORDS 40453 -#define IDM_VIEW_ACCELWORDNAV 40454 -#define IDM_VIEW_NOPRESERVECARET 40455 -#define IDM_VIEW_HYPERLINKHOTSPOTS 40456 -#define IDM_VIEW_CURRENTSCHEME 40457 -#define IDM_VIEW_SCROLLPASTEOF 40458 -#define IDM_VIEW_TOGGLE_VIEW 40459 -#define IDM_VIEW_CHASING_DOCTAIL 40460 -#define IDM_VIEW_TOGGLETB 40461 -#define IDM_SET_RENDER_TECH_DEFAULT 40462 -#define IDM_SET_RENDER_TECH_D2D 40463 -#define IDM_SET_RENDER_TECH_D2DRETAIN 40464 -#define IDM_SET_RENDER_TECH_D2DDC 40465 -#define IDM_SET_BIDIRECTIONAL_NONE 40466 -#define IDM_SET_BIDIRECTIONAL_L2R 40467 -#define IDM_SET_BIDIRECTIONAL_R2L 40468 +#define IDM_VIEW_AUTOCLEXKEYWORDS 40454 +#define IDM_VIEW_ACCELWORDNAV 40455 +#define IDM_VIEW_NOPRESERVECARET 40456 +#define IDM_VIEW_HYPERLINKHOTSPOTS 40457 +#define IDM_VIEW_CURRENTSCHEME 40458 +#define IDM_VIEW_SCROLLPASTEOF 40459 +#define IDM_VIEW_TOGGLE_VIEW 40460 +#define IDM_VIEW_CHASING_DOCTAIL 40461 +#define IDM_VIEW_TOGGLETB 40462 -#define IDM_HELP_ABOUT 40500 -#define IDM_HELP_CMD 40501 -#define IDM_HELP_ONLINEDOCUMENTATION 40502 +#define IDM_SET_RENDER_TECH_DEFAULT 40500 +#define IDM_SET_RENDER_TECH_D2D 40501 +#define IDM_SET_RENDER_TECH_D2DRETAIN 40502 +#define IDM_SET_RENDER_TECH_D2DDC 40503 +#define IDM_SET_BIDIRECTIONAL_NONE 40504 +#define IDM_SET_BIDIRECTIONAL_L2R 40505 +#define IDM_SET_BIDIRECTIONAL_R2L 40506 -#define IDM_TRAY_RESTORE 40600 -#define IDM_TRAY_EXIT 40601 -#define IDM_SETPASS 40602 +#define IDM_HELP_ABOUT 40600 +#define IDM_HELP_CMD 40601 +#define IDM_HELP_ONLINEDOCUMENTATION 40602 #define IDM_HELP_ADMINEXE 40603 #define IDM_HELP_UPDATEWEBSITE 40604 -#define IDM_EDIT_INSERT_GUID 40605 + +#define IDM_TRAY_RESTORE 40700 +#define IDM_TRAY_EXIT 40701 +#define IDM_SETPASS 40702 +#define IDM_EDIT_INSERT_GUID 40705 #define IDS_ENC_ANSI 61000 diff --git a/language/np3_af_za/menu_af_za.rc b/language/np3_af_za/menu_af_za.rc index 122b1b0b99efc93d7861842edbe8ffd36574732a..074d51fab7422d61dcc974c022f5912b46b7cd08 100644 GIT binary patch delta 88 zcmcb0k?GqdrVTo6?4=AP4EYQSlLK{x<$V}Z87hFdh(VV@jlmnpssysaf$~KRDGbGv l8*?Nl2ek4Cx-vunWnCE}fpY!~K@2XF7dC5e)@s|J1OPB27fJvC delta 14 Wcmex%iRsowrVTo6n@_Z@Qvv`zWe2MO diff --git a/language/np3_de_de/menu_de_de.rc b/language/np3_de_de/menu_de_de.rc index 8941cf2f8782e5ad49d27009d226ec696ce9c7ac..40a786781848d34607453a6edc2530e45ca02107 100644 GIT binary patch delta 323 zcmbPnpJ~YhrVZ1085K59=T!$$`=vH2Og6Gq**wKsjS8RR8}B$vALfKD3;u|7|3C7?`53)pi^mbjyd1tBOMt)3Ej@6 zK=N|uYM^v|mn);N0)rYu7|`e-fa+ZtB7y4tfxdH@%-E_u gIjTnuXnkW(E-(-_zwf;XqE7aI<_1!GXWteE0H+9N7ytkO delta 242 zcmZ4TfN92krVZ108Fe>L=T!$$`=vH20I5Q2Pew-F$%WR+oA23d05SXRCiCht1Tp+! zNM^`psA4FcywFZ_a)P?d<`R1ceNJ5lH->zMJcg3Vi7LXAFXZI`4YAK($OqK|700P}}9o zD6h+)#t_Dk%232m2DBsx2#Xm?7@h#FOJT@lNS{2{PI~f&N})+TUX!2or~!5H_T~bO V-CW&w6GVkh_{rVRmYlcid@CLd`PkoRFoWvBq+A_iRsH3n}Ws}jfxXUGSNq%agu7R-?p ebz}%-2x0JNaAxpfaAk-9s&ZwB+$`PZs0;wcS`DrVSQtlM7lnCa-E0lJ{XqWvBq+A_iRsH3n}Ws}jfxXUGSNq%agu7A%mQ l9Mj4p=*kcQlyzl@1j_j{1TnZwe&{Mbd4hn*X0tXPWdM}-7$*P# delta 14 Wcmcb2nd#6arVSQto3FHSDFXmHVFvO5 diff --git a/language/np3_es_es/menu_es_es.rc b/language/np3_es_es/menu_es_es.rc index 061baf88d25b6d9f866989bebf22d124b5dc7e15..371b37fcee1a8f5bb7ddc0dd6ef6e3085f260637 100644 GIT binary patch delta 98 zcmX?fmFeC!rVanvElU|n81fku7@UD*E<*uB4nrzXBo!#)10*YexQIcQL5;y1$f^Xg q!h!0F7*ZIDCvU8h6m?_>We8#L2kQ1=aAk-9s&ZwB+|!5he`1hT?` q>WUarChM=2o*dW9Bk0Ny0hDuPhy=>`GXycXOl~aI-t5+QNCg1hVi@26 delta 14 WcmZ4ToT=j((+0P`&5!yHsQ>^t)(49K diff --git a/language/np3_ja_jp/menu_ja_jp.rc b/language/np3_ja_jp/menu_ja_jp.rc index 08dd86515efbbbf990674d1ca3bd6835d7d6b6b3..b612145af81efc77066ae5aaac35432800f12891 100644 GIT binary patch delta 110 zcmdmUoax31rVScR){YFN3?&Tt3|GXycXOg>nrJ^6wT%VwRX35o#x CEF3HV delta 18 acmca{f@#ljrVScRlP~D7Y(CL6K@k9069~fq diff --git a/language/np3_nl_nl/menu_nl_nl.rc b/language/np3_nl_nl/menu_nl_nl.rc index 72e781561f2d3bfec669a2d44d1c5a1cf1c8dfb1..781b8fa6a610dc7e1159b285cbc2a9e1b5de98d0 100644 GIT binary patch delta 86 zcmX?ekLksIrVW1GlLflC44oPB8FCp47;+d=8A^ayfx!nzRseAkgD!&_gEx>>31o!> h)fF+MFceRoUo1Jfpo@pol_3Hs>&g(hS-RU$1ppHI77PFY delta 18 acmaEHpXtm!rVW1GlM@WsHh<{;p$q_B9SLy& diff --git a/language/np3_zh_cn/menu_zh_cn.rc b/language/np3_zh_cn/menu_zh_cn.rc index eb93fa7eba708094b53fb84e04135068841de941..0ac28463ce4769d82ddfb8e0c8a2b6e9c60cce3d 100644 GIT binary patch delta 106 zcmaEJh^gZU(}q(G){YFN3?&Tt3A0Oeg7B7w603_%PolLMQyH=k-)qyPYudm1wU delta 14 WcmeA;!t~}4(}q(Go6{N>DF6UDSO--A diff --git a/src/Edit.c b/src/Edit.c index 9b9c9e4f1..d6ddf60d8 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -97,6 +97,8 @@ extern bool bForceLoadASCIIasUTF8; extern bool bLoadNFOasOEM; extern bool bNoEncodingTags; +extern bool g_bAutoCompleteWords; +extern bool g_bAutoCLexerKeyWords; extern bool g_bAccelWordNavigation; extern int g_iReplacedOccurrences; @@ -6595,12 +6597,41 @@ static int __fastcall wordcmpi(PWLIST a, PWLIST b) { // ---------------------------------------------- +static const char* __fastcall _strNextLexKeyWord(const char* strg, const char* const wdroot, DocPosCR* pwdlen) +{ + char const sep = ' '; + bool found = false; + const char* start = strg; + do { + start = StrStrIA(start, wdroot); + if (start) { + if ((start == strg) || (start[-1] == sep)) { // word begin + found = true; + break; + } + ++start; + } + } while (start && *start); + + if (found) { + DocPosCR len = *pwdlen; + while (start[len] && (start[len] != sep)) { ++len; } + *pwdlen = len; + } + else { + *pwdlen = 0; + } + return (found ? start : NULL); +} + +// ---------------------------------------------- + void EditCompleteWord(HWND hwnd, bool autoInsert) { UNUSED(hwnd); // OLD: "_abcdefghijklmnopqrstuvwxyz0123456789" - char const * ALLOWED_WORD_CHARS = AutoCompleteWordASCII; + char const* ALLOWED_WORD_CHARS = AutoCompleteWordASCII; if (ALLOWED_WORD_CHARS[0] == '\0') { ALLOWED_WORD_CHARS = g_bAccelWordNavigation ? WordCharsAccelerated : WordCharsDefault; @@ -6632,53 +6663,94 @@ void EditCompleteWord(HWND hwnd, bool autoInsert) StringCchCopyNA(pRoot, COUNTOF(pRoot), pLine + iStartWordPos, (size_t)iRootLen); - - DocPosCR const iDocLen = (DocPosCR)SciCall_GetTextLength(); - struct Sci_TextToFind ft = { { 0, 0 }, 0, { 0, 0 } }; - ft.lpstrText = pRoot; - ft.chrg.cpMax = iDocLen; - - DocPos iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); - int iNumWords = 0; size_t iWListSize = 0; - PWLIST pwlWord = NULL; - PWLIST pWLItem = NULL; PWLIST pListHead = NULL; - while ((iPosFind >= 0) && (iPosFind < iDocLen)) + if (g_bAutoCompleteWords) { - DocPos wordEnd = (DocPosCR)(iPosFind + iRootLen); + DocPosCR const iDocLen = (DocPosCR)SciCall_GetTextLength(); + struct Sci_TextToFind ft = { { 0, 0 }, 0, { 0, 0 } }; + ft.lpstrText = pRoot; + ft.chrg.cpMax = iDocLen; - if (iPosFind != (iCurrentPos - iRootLen)) + DocPos iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); + PWLIST pwlNewWord = NULL; + while ((iPosFind >= 0) && (iPosFind < iDocLen)) { - while ((wordEnd < iDocLen) && StrChrIA(ALLOWED_WORD_CHARS, SciCall_GetCharAt(wordEnd))) { ++wordEnd; } + DocPos wordEnd = (DocPosCR)(iPosFind + iRootLen); - DocPos const wordLength = (wordEnd - iPosFind); - if (wordLength > iRootLen) + if (iPosFind != (iCurrentPos - iRootLen)) { - if (!pwlWord) { pwlWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } - if (pwlWord) - { - StringCchCopyNA(pwlWord->word, _MAX_AUTOC_WORD_LEN, SciCall_GetRangePointer(iPosFind, wordLength), wordLength); + while ((wordEnd < iDocLen) && StrChrIA(ALLOWED_WORD_CHARS, SciCall_GetCharAt(wordEnd))) { ++wordEnd; } - PWLIST pPrev = NULL; - LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlWord, wordcmp); - if (!pWLItem) { // not found - //LL_INSERT_INORDER(pListHead, pwlWord, wordcmpi); - LL_APPEND_ELEM(pListHead, pPrev, pwlWord); - ++iNumWords; - iWListSize += (wordLength + 1); - pwlWord = NULL; // alloc new + DocPos const wordLength = (wordEnd - iPosFind); + if (wordLength > iRootLen) + { + if (!pwlNewWord) { pwlNewWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } + if (pwlNewWord) + { + StringCchCopyNA(pwlNewWord->word, _MAX_AUTOC_WORD_LEN, SciCall_GetRangePointer(iPosFind, wordLength), wordLength); + + PWLIST pPrev = NULL; + PWLIST pWLItem = NULL; + LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlNewWord, wordcmp); + if (!pWLItem) { // not found + //LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi); + LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord); + ++iNumWords; + iWListSize += (wordLength + 1); + pwlNewWord = NULL; // alloc new + } } } } + ft.chrg.cpMin = (DocPosCR)wordEnd; + iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); } - ft.chrg.cpMin = (DocPosCR)wordEnd; - iPosFind = SciCall_FindText(SCFIND_WORDSTART, &ft); + if (pwlNewWord) { FreeMem(pwlNewWord); pwlNewWord = NULL; } } - if (pwlWord) { FreeMem(pwlWord); pwlWord = NULL; } + + // -------------------------------------------------------------------------- + + if (g_bAutoCLexerKeyWords) + { + PKEYWORDLIST const pKeyWordList = Style_GetCurrentLexerPtr()->pKeyWords; + + PWLIST pwlNewWord = NULL; + for (int i = 0; i <= KEYWORDSET_MAX; ++i) { + const char* word = pKeyWordList->pszKeyWords[i]; + do { + DocPosCR wlen = iRootLen; + word = _strNextLexKeyWord(word, pRoot, &wlen); + if (word) { + if (wlen > iRootLen) { + if (!pwlNewWord) { pwlNewWord = (PWLIST)AllocMem(sizeof(WLIST), HEAP_ZERO_MEMORY); } + if (pwlNewWord) + { + StringCchCopyNA(pwlNewWord->word, _MAX_AUTOC_WORD_LEN, word, wlen); + + PWLIST pPrev = NULL; + PWLIST pWLItem = NULL; + LL_SEARCH_ORDERED(pListHead, pPrev, pWLItem, pwlNewWord, wordcmp); + if (!pWLItem) { // not found + //LL_INSERT_INORDER(pListHead, pwlNewWord, wordcmpi); + LL_APPEND_ELEM(pListHead, pPrev, pwlNewWord); + ++iNumWords; + iWListSize += (wlen + 1); + pwlNewWord = NULL; // alloc new + } + } + } + word += (wlen ? wlen : 1); + } + } while (word && word[0]); + } + if (pwlNewWord) { FreeMem(pwlNewWord); pwlNewWord = NULL; } + } + + // -------------------------------------------------------------------------- if (iNumWords > 0) { @@ -6696,6 +6768,7 @@ void EditCompleteWord(HWND hwnd, bool autoInsert) char* const pList = AllocMem(iWListSize, HEAP_ZERO_MEMORY); if (pList) { PWLIST pTmp = NULL; + PWLIST pWLItem = NULL; LL_FOREACH_SAFE(pListHead, pWLItem, pTmp) { if (pWLItem->word[0]) { StringCchCatA(pList, iWListSize, sep); diff --git a/src/Notepad3.c b/src/Notepad3.c index 45b67a2b5..b55d3f43f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -211,6 +211,7 @@ bool g_bMarkOccurrencesMatchWords; bool g_bMarkOccurrencesCurrentWord; bool g_bUseOldStyleBraceMatching; bool g_bAutoCompleteWords; +bool g_bAutoCLexerKeyWords; bool g_bAccelWordNavigation; bool g_bDenyVirtualSpaceAccess; bool g_bCodeFoldingAvailable; @@ -2932,6 +2933,8 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) EnableCmd(hmenu,IDM_EDIT_COMPLETEWORD,!e && !ro); CheckCmd(hmenu,IDM_VIEW_AUTOCOMPLETEWORDS,g_bAutoCompleteWords && !ro); + CheckCmd(hmenu,IDM_VIEW_AUTOCLEXKEYWORDS, g_bAutoCLexerKeyWords && !ro); + CheckCmd(hmenu,IDM_VIEW_ACCELWORDNAV,g_bAccelWordNavigation); CheckCmd(hmenu, IDM_VIEW_MARKOCCUR_ONOFF, (g_iMarkOccurrences > 0)); @@ -4735,9 +4738,12 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_AUTOCOMPLETEWORDS: g_bAutoCompleteWords = (g_bAutoCompleteWords) ? false : true; // toggle - if (!g_bAutoCompleteWords) { - SciCall_AutoCCancel(); // close the auto completion list - } + SciCall_AutoCCancel(); + break; + + case IDM_VIEW_AUTOCLEXKEYWORDS: + g_bAutoCLexerKeyWords = (g_bAutoCLexerKeyWords) ? false : true; // toggle + SciCall_AutoCCancel(); break; case IDM_VIEW_ACCELWORDNAV: @@ -6341,7 +6347,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) else if (scn->ch == '?') { _HandleTinyExpr(); } - else if (g_bAutoCompleteWords && !SciCall_AutoCActive() && !_IsInlineIMEActive()) { + else if ((g_bAutoCompleteWords || g_bAutoCLexerKeyWords) && !SciCall_AutoCActive() && !_IsInlineIMEActive()) { EditCompleteWord(g_hwndEdit, false); } } @@ -6772,6 +6778,8 @@ void LoadSettings() bAutoIndent = IniSectionGetBool(pIniSection, L"AutoIndent", true); g_bAutoCompleteWords = IniSectionGetBool(pIniSection, L"AutoCompleteWords", false); + + g_bAutoCLexerKeyWords = IniSectionGetBool(pIniSection, L"AutoCLexerKeyWords", false); g_bAccelWordNavigation = IniSectionGetBool(pIniSection, L"AccelWordNavigation", false); @@ -7127,6 +7135,7 @@ void SaveSettings(bool bSaveSettingsNow) { IniSectionSetBool(pIniSection, L"ScrollPastEOF", bScrollPastEOF); IniSectionSetBool(pIniSection, L"AutoIndent", bAutoIndent); IniSectionSetBool(pIniSection, L"AutoCompleteWords", g_bAutoCompleteWords); + IniSectionSetBool(pIniSection, L"AutoCLexerKeyWords", g_bAutoCLexerKeyWords); IniSectionSetBool(pIniSection, L"AccelWordNavigation", g_bAccelWordNavigation); IniSectionSetBool(pIniSection, L"ShowIndentGuides", bShowIndentGuides); IniSectionSetBool(pIniSection, L"TabsAsSpaces", bTabsAsSpacesG); diff --git a/src/StyleLexers/EditLexer.h b/src/StyleLexers/EditLexer.h index a28b7bdc2..a36a0fd68 100644 --- a/src/StyleLexers/EditLexer.h +++ b/src/StyleLexers/EditLexer.h @@ -33,7 +33,7 @@ typedef struct _editstyle typedef struct _keywordlist { - char *pszKeyWords[KEYWORDSET_MAX + 1]; + char* pszKeyWords[KEYWORDSET_MAX + 1]; } KEYWORDLIST, *PKEYWORDLIST;