Skip to content

Commit

Permalink
Add scheme menu for MATLAB, Octave and Scilab.
Browse files Browse the repository at this point in the history
Fix auto-indentation and toggle comment bug for Julia, Octave and Scilab.
  • Loading branch information
zufuliu committed Sep 9, 2018
1 parent 3aafc49 commit 32a7535
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,22 @@ const char *EditKeywordIndent(const char *head, int *indent) {
*indent = 1;
} else if (!strcmp(word, "if") || !strcmp(word, "for") || !strcmp(word, "while") || !strcmp(word, "switch") || !strcmp(word, "try")) {
*indent = 2;
endPart = "end";
if (pLexCurrent->rid == NP2LEX_OCTAVE) {
if (strcmp(word, "if") == 0) {
endPart = "endif";
} else if (strcmp(word, "for") == 0) {
endPart = "endfor";
} else if (strcmp(word, "while") == 0) {
endPart = "endwhile";
} else if (strcmp(word, "switch") == 0) {
endPart = "endswitch";
} else if (strcmp(word, "try") == 0) {
endPart = "end_try_catch";
}
}
if (endPart == NULL) {
endPart = "end";
}
}
break;
case SCLEX_LUA:
Expand Down Expand Up @@ -1127,9 +1142,9 @@ void EditAutoIndent(HWND hwnd) {


void EditToggleCommentLine(HWND hwnd) {
BeginWaitCursor();
switch (pLexCurrent->iLexer) {
case SCLEX_CPP:
BeginWaitCursor();
switch (pLexCurrent->rid) {
case NP2LEX_AWK:
case NP2LEX_JAM:
Expand All @@ -1139,99 +1154,77 @@ void EditToggleCommentLine(HWND hwnd) {
EditToggleLineComments(hwnd, L"//", FALSE);
break;
}
EndWaitCursor();
break;
case SCLEX_CSS:
case SCLEX_PASCAL:
case SCLEX_VERILOG:
case SCLEX_FSHARP:
case SCLEX_GRAPHVIZ:
case SCLEX_JSON:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"//", FALSE);
EndWaitCursor();
break;
case SCLEX_VBSCRIPT:
case SCLEX_VB:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"'", TRUE);
EndWaitCursor();
break;
case SCLEX_PYTHON:
case SCLEX_RUBY:
case SCLEX_SMALI:
case SCLEX_MAKEFILE:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"#", FALSE);
EndWaitCursor();
break;
case SCLEX_BASH:
BeginWaitCursor();
EditToggleLineComments(hwnd, ((np2LexLangIndex == IDM_LANG_M4)? L"dnl " : L"#"), FALSE);
EndWaitCursor();
break;
case SCLEX_PERL:
case SCLEX_CONF:
case SCLEX_TCL:
case SCLEX_POWERSHELL:
case SCLEX_CMAKE:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"#", TRUE);
EndWaitCursor();
break;
case SCLEX_ASM:
case SCLEX_PROPERTIES:
case SCLEX_AU3:
case SCLEX_INNOSETUP:
BeginWaitCursor();
EditToggleLineComments(hwnd, L";", TRUE);
EndWaitCursor();
break;
case SCLEX_SQL:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"-- ", TRUE); // extra space
EndWaitCursor();
break;
case SCLEX_LUA:
case SCLEX_VHDL:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"--", TRUE);
EndWaitCursor();
break;
case SCLEX_BATCH:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"@rem ", TRUE);
EndWaitCursor();
break;
case SCLEX_LATEX:
EditToggleLineComments(hwnd, L"# ", TRUE);
break;
case SCLEX_MATLAB:
BeginWaitCursor();
if (pLexCurrent->rid == NP2LEX_JULIA) {
EditToggleLineComments(hwnd, L"#", FALSE);
} else if (pLexCurrent->rid == NP2LEX_SCILAB) {
EditToggleLineComments(hwnd, L"//", FALSE);
} else {
EditToggleLineComments(hwnd, L"%", FALSE);
}
EndWaitCursor();
break;
case SCLEX_LISP:
case SCLEX_LLVM:
BeginWaitCursor();
EditToggleLineComments(hwnd, L";", FALSE);
EndWaitCursor();
break;
case SCLEX_VIM:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"\" ", FALSE);
EndWaitCursor();
break;
case SCLEX_TEXINFO:
BeginWaitCursor();
EditToggleLineComments(hwnd, L"@c ", FALSE);
EndWaitCursor();
break;
default:
break;
}
EndWaitCursor();
}

void EditEncloseSelectionNewLine(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose) {
Expand Down Expand Up @@ -1298,7 +1291,13 @@ void EditToggleCommentBlock(HWND hwnd) {
EditEncloseSelectionNewLine(hwnd, L"\\begin{comment}", L"\\end{comment}");
break;
case SCLEX_MATLAB:
EditEncloseSelectionNewLine(hwnd, L"%{", L"%}");
if (pLexCurrent->rid == NP2LEX_JULIA) {
EditEncloseSelectionNewLine(hwnd, L"#=", L"=#");
} else if (pLexCurrent->rid == NP2LEX_SCILAB) {
EditEncloseSelectionNewLine(hwnd, L"/*", L"*/");
} else {
EditEncloseSelectionNewLine(hwnd, L"%{", L"%}");
}
break;
default:
break;
Expand Down
4 changes: 4 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4422,6 +4422,10 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {

case IDM_LANG_BASH:
case IDM_LANG_M4:

case IDM_LANG_MATLAB:
case IDM_LANG_OCTAVE:
case IDM_LANG_SCILAB:
Style_SetLexerByLangIndex(hwndEdit, LOWORD(wParam));
break;

Expand Down
6 changes: 6 additions & 0 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,12 @@ BEGIN
MENUITEM "ASP (V&BScript)", IDM_LANG_ASP_VBS
MENUITEM "ASP (J&Script)", IDM_LANG_ASP_JS
END
POPUP "Math"
BEGIN
MENUITEM "MATLAB", IDM_LANG_MATLAB
MENUITEM "Octave", IDM_LANG_OCTAVE
MENUITEM "Scilab", IDM_LANG_SCILAB
END
POPUP "Shell Script"
BEGIN
MENUITEM "Shell Script", IDM_LANG_BASH
Expand Down
36 changes: 36 additions & 0 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ PEDITLEXER Style_DetectObjCAndMatlab(void) {
return &lexCPP;
}
lexMatlab.rid = NP2LEX_OCTAVE;
np2LexLangIndex = IDM_LANG_OCTAVE;
return &lexMatlab;
}
break;
Expand All @@ -1384,6 +1385,7 @@ PEDITLEXER Style_DetectObjCAndMatlab(void) {
return &lexCPP;
}
break;
break;
case 'f': // Matlab function
if (strncmp(p, "function", 8) == 0 && (IsASpace(p[8]) || p[8] == '[')) {
return &lexMatlab;
Expand Down Expand Up @@ -1533,6 +1535,16 @@ void Style_GetCurrentLexerName(LPWSTR lpszName, int cchName) {
lang = L"M4 Macro";
break;

case IDM_LANG_MATLAB:
lang = L"MATLAB Code";
break;
case IDM_LANG_OCTAVE:
lang = L"Octave Code";
break;
case IDM_LANG_SCILAB:
lang = L"Scilab Code";
break;

default:
break;
}
Expand Down Expand Up @@ -1611,10 +1623,12 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch, BOOL bCheckNames) {
}
if (StrCaseEqual(L"sce", lpszMatch)) {
lexMatlab.rid = NP2LEX_SCILAB;
np2LexLangIndex = IDM_LANG_SCILAB;
return (&lexMatlab);
}
if (StrCaseEqual(L"sci", lpszMatch)) {
lexMatlab.rid = NP2LEX_SCILAB;
np2LexLangIndex = IDM_LANG_SCILAB;
return (&lexMatlab);
}
if (StrCaseEqual(L"m4", lpszMatch)) {
Expand Down Expand Up @@ -1939,6 +1953,19 @@ void Style_SetLexerByLangIndex(HWND hwnd, int lang) {
case IDM_LANG_M4:
Style_SetLexer(hwnd, &lexBash);
break;

case IDM_LANG_MATLAB:
lexMatlab.rid = NP2LEX_MATLAB;
Style_SetLexer(hwnd, &lexMatlab);
break;
case IDM_LANG_OCTAVE:
lexMatlab.rid = NP2LEX_OCTAVE;
Style_SetLexer(hwnd, &lexMatlab);
break;
case IDM_LANG_SCILAB:
lexMatlab.rid = NP2LEX_SCILAB;
Style_SetLexer(hwnd, &lexMatlab);
break;
}
}

Expand All @@ -1958,6 +1985,15 @@ void Style_UpdateSchemeMenu(HMENU hmenu) {
case NP2LEX_BASH:
lang = IDM_LANG_BASH;
break;
case NP2LEX_MATLAB:
lang = IDM_LANG_MATLAB;
break;
case NP2LEX_OCTAVE:
lang = IDM_LANG_OCTAVE;
break;
case NP2LEX_SCILAB:
lang = IDM_LANG_SCILAB;
break;
}
}
for (int i = IDM_LANG_DEFAULT; i < IDM_LANG_NULL; i++) {
Expand Down
4 changes: 4 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@
#define IDM_LANG_XSLT 41012
#define IDM_LANG_DTD 41013

#define IDM_LANG_MATLAB 41014
#define IDM_LANG_OCTAVE 41015
#define IDM_LANG_SCILAB 41016

#define IDM_LANG_ANT_BUILD 41021
#define IDM_LANG_MAVEN_POM 41022
#define IDM_LANG_MAVEN_SETTINGS 41023
Expand Down

0 comments on commit 32a7535

Please sign in to comment.