mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+fix: Python Line Comment : respect indents
+add: Python stream comment hack
This commit is contained in:
parent
098d9661e8
commit
76020253b2
@ -3741,10 +3741,10 @@ void EditToggleLineCommentsSimple(LPCWSTR pwszComment, bool bInsertAtStart, LnCm
|
||||
|
||||
if (StrIsNotEmpty(pwszComment)) {
|
||||
char mszPostfix[64 * 3] = { '\0' };
|
||||
WideCharToMultiByteEx(Encoding_SciCP, 0, pwszComment, -1, mszPrefix, COUNTOF(mszPrefix), NULL, NULL);
|
||||
WideCharToMultiByte(Encoding_SciCP, 0, pwszComment, -1, mszPrefix, COUNTOF(mszPrefix), NULL, NULL);
|
||||
StringCchCopyA(mszComment, COUNTOF(mszComment), mszPrefix);
|
||||
if (StrIsNotEmpty(Settings2.LineCommentPostfixStrg)) {
|
||||
WideCharToMultiByteEx(Encoding_SciCP, 0, Settings2.LineCommentPostfixStrg, -1, mszPostfix, COUNTOF(mszPostfix), NULL, NULL);
|
||||
WideCharToMultiByte(Encoding_SciCP, 0, Settings2.LineCommentPostfixStrg, -1, mszPostfix, COUNTOF(mszPostfix), NULL, NULL);
|
||||
StringCchCatA(mszComment, COUNTOF(mszComment), mszPostfix);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,12 +9,13 @@
|
||||
|
||||
void Lexer_GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen)
|
||||
{
|
||||
#define SET_STREAMCOMMENT_STRG(X,Y) { StringCchCopy(beg_out, maxlen, (X)); StringCchCopy(end_out, maxlen, (Y)); }
|
||||
|
||||
if (beg_out && end_out && maxlen) {
|
||||
|
||||
switch (SciCall_GetLexer()) {
|
||||
case SCLEX_AU3:
|
||||
StringCchCopy(beg_out, maxlen, L"#cs");
|
||||
StringCchCopy(end_out, maxlen, L"#ce");
|
||||
SET_STREAMCOMMENT_STRG(L"#cs", L"#ce");
|
||||
break;
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_CPP:
|
||||
@ -28,40 +29,36 @@ void Lexer_GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen)
|
||||
case SCLEX_RUST:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
StringCchCopy(beg_out, maxlen, L"/*");
|
||||
StringCchCopy(end_out, maxlen, L"*/");
|
||||
SET_STREAMCOMMENT_STRG(L"/*", L"*/");
|
||||
break;
|
||||
case SCLEX_HTML: {
|
||||
int const cStyleBeg = SciCall_GetStyleIndexAt(Sci_GetLineStartPosition(SciCall_GetSelectionStart()));
|
||||
int const cStyleEnd = SciCall_GetStyleIndexAt(SciCall_GetSelectionEnd());
|
||||
if (((min_i(cStyleBeg, cStyleEnd) >= SCE_HPHP_DEFAULT) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HPHP_OPERATOR)) ||
|
||||
((min_i(cStyleBeg, cStyleEnd) >= SCE_HJ_START) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HJA_REGEX))) {
|
||||
StringCchCopy(beg_out, maxlen, L"/*");
|
||||
StringCchCopy(end_out, maxlen, L"*/");
|
||||
SET_STREAMCOMMENT_STRG(L"/*", L"*/");
|
||||
break;
|
||||
}
|
||||
}
|
||||
// [[fallthrough]] // -> XML
|
||||
case SCLEX_XML:
|
||||
StringCchCopy(beg_out, maxlen, L"<!--");
|
||||
StringCchCopy(end_out, maxlen, L"-->");
|
||||
SET_STREAMCOMMENT_STRG(L"<!--", L"-->");
|
||||
break;
|
||||
case SCLEX_INNOSETUP:
|
||||
case SCLEX_PASCAL:
|
||||
StringCchCopy(beg_out, maxlen, L"{");
|
||||
StringCchCopy(end_out, maxlen, L"}");
|
||||
SET_STREAMCOMMENT_STRG(L"{", L"}");
|
||||
break;
|
||||
case SCLEX_LUA:
|
||||
StringCchCopy(beg_out, maxlen, L"--[[");
|
||||
StringCchCopy(end_out, maxlen, L"]]");
|
||||
SET_STREAMCOMMENT_STRG(L"--[[", L"]]");
|
||||
break;
|
||||
case SCLEX_COFFEESCRIPT:
|
||||
StringCchCopy(beg_out, maxlen, L"###");
|
||||
StringCchCopy(end_out, maxlen, L"###");
|
||||
SET_STREAMCOMMENT_STRG(L"###", L"###");
|
||||
break;
|
||||
case SCLEX_MATLAB:
|
||||
StringCchCopy(beg_out, maxlen, L"%{");
|
||||
StringCchCopy(end_out, maxlen, L"%}");
|
||||
SET_STREAMCOMMENT_STRG(L"%{", L"%}");
|
||||
break;
|
||||
case SCLEX_PYTHON:
|
||||
SET_STREAMCOMMENT_STRG(L"_=\"\"\"", L"\"\"\"");
|
||||
break;
|
||||
// ------------------
|
||||
case SCLEX_CONTAINER:
|
||||
@ -82,7 +79,6 @@ void Lexer_GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen)
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_REGISTRY:
|
||||
case SCLEX_RUBY:
|
||||
@ -92,8 +88,7 @@ void Lexer_GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen)
|
||||
case SCLEX_VBSCRIPT:
|
||||
case SCLEX_YAML:
|
||||
default:
|
||||
StringCchCopy(beg_out, maxlen, L"");
|
||||
StringCchCopy(end_out, maxlen, L"");
|
||||
SET_STREAMCOMMENT_STRG(L"", L"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -102,6 +97,8 @@ void Lexer_GetStreamCommentStrgs(LPWSTR beg_out, LPWSTR end_out, size_t maxlen)
|
||||
|
||||
bool Lexer_GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
{
|
||||
#define SET_COMMENT_STRG(X,S) { StringCchCopy(pre_out, maxlen, (X)); return (S); }
|
||||
|
||||
if (pre_out && maxlen) {
|
||||
|
||||
switch (SciCall_GetLexer()) {
|
||||
@ -112,12 +109,10 @@ bool Lexer_GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
case SCLEX_KOTLIN:
|
||||
case SCLEX_PASCAL:
|
||||
case SCLEX_RUST:
|
||||
StringCchCopy(pre_out, maxlen, L"//");
|
||||
return false;
|
||||
SET_COMMENT_STRG(L"//", false);
|
||||
case SCLEX_VB:
|
||||
case SCLEX_VBSCRIPT:
|
||||
StringCchCopy(pre_out, maxlen, L"'");
|
||||
return false;
|
||||
SET_COMMENT_STRG(L"'", false);
|
||||
case SCLEX_AVS:
|
||||
case SCLEX_BASH:
|
||||
case SCLEX_CMAKE:
|
||||
@ -128,14 +123,14 @@ bool Lexer_GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
case SCLEX_PERL:
|
||||
case SCLEX_PHPSCRIPT:
|
||||
case SCLEX_POWERSHELL:
|
||||
case SCLEX_PYTHON:
|
||||
case SCLEX_R:
|
||||
case SCLEX_RUBY:
|
||||
case SCLEX_TCL:
|
||||
case SCLEX_TOML:
|
||||
case SCLEX_YAML:
|
||||
StringCchCopy(pre_out, maxlen, L"#");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L"#", true);
|
||||
case SCLEX_PYTHON:
|
||||
SET_COMMENT_STRG(L"#", false);
|
||||
case SCLEX_AHK:
|
||||
case SCLEX_ASM:
|
||||
case SCLEX_AU3:
|
||||
@ -143,24 +138,19 @@ bool Lexer_GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
case SCLEX_NSIS: // "#" could also be used instead
|
||||
case SCLEX_PROPERTIES:
|
||||
case SCLEX_REGISTRY:
|
||||
StringCchCopy(pre_out, maxlen, L";");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L";", true);
|
||||
case SCLEX_LUA:
|
||||
case SCLEX_SQL:
|
||||
case SCLEX_VHDL:
|
||||
StringCchCopy(pre_out, maxlen, L"--");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L"--", true);
|
||||
case SCLEX_BATCH: // "::" could also be used instead
|
||||
StringCchCopy(pre_out, maxlen, L"rem ");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L"rem ", true);
|
||||
case SCLEX_LATEX:
|
||||
case SCLEX_MATLAB:
|
||||
StringCchCopy(pre_out, maxlen, L"%");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L"%", true);
|
||||
case SCLEX_FORTRAN:
|
||||
case SCLEX_F77:
|
||||
StringCchCopy(pre_out, maxlen, L"!");
|
||||
return true;
|
||||
SET_COMMENT_STRG(L"!", true);
|
||||
// ------------------
|
||||
case SCLEX_CONTAINER:
|
||||
assert("SciCall_GetLexer() UNDEFINED!" && 0);
|
||||
@ -173,21 +163,17 @@ bool Lexer_GetLineCommentStrg(LPWSTR pre_out, size_t maxlen)
|
||||
int const cStyleBeg = SciCall_GetStyleIndexAt(Sci_GetLineStartPosition(SciCall_GetSelectionStart()));
|
||||
int const cStyleEnd = SciCall_GetStyleIndexAt(SciCall_GetSelectionEnd());
|
||||
if (((min_i(cStyleBeg, cStyleEnd) >= SCE_HPHP_DEFAULT) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HPHP_OPERATOR)) || (min_i(cStyleBeg, cStyleEnd) == SCE_HPHP_COMPLEX_VARIABLE) ||
|
||||
((min_i(cStyleBeg, cStyleEnd) >= SCE_HJ_START) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HJA_REGEX))) {
|
||||
StringCchCopy(pre_out, maxlen, L"//");
|
||||
return false;
|
||||
}
|
||||
((min_i(cStyleBeg, cStyleEnd) >= SCE_HJ_START) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HJA_REGEX)))
|
||||
SET_COMMENT_STRG(L"//", false);
|
||||
if (((min_i(cStyleBeg, cStyleEnd) >= SCE_HP_START) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HP_IDENTIFIER)) ||
|
||||
((min_i(cStyleBeg, cStyleEnd) >= SCE_HPA_START) && (max_i(cStyleBeg, cStyleEnd) <= SCE_HPA_IDENTIFIER))) {
|
||||
StringCchCopy(pre_out, maxlen, L"#");
|
||||
return false;
|
||||
SET_COMMENT_STRG(L"#", false);
|
||||
}
|
||||
}
|
||||
// [[fallthrough]] // -> XML
|
||||
case SCLEX_XML:
|
||||
default:
|
||||
StringCchCopy(pre_out, maxlen, L"");
|
||||
break;
|
||||
SET_COMMENT_STRG(L"", false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user