Skip to content

Commit

Permalink
Add scheme menu for C Shell.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Sep 10, 2018
1 parent a424871 commit 78fbccc
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 46 deletions.
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
* Ruby, [Screenshots](https://github.com/zufuliu/notepad2/wiki/Screenshots#ruby)
* Scala Script
* Shell Script
* Bash, [Screenshots](https://github.com/zufuliu/notepad2/wiki/Screenshots#shell-script)
* Bash likes (sh, bash, dash, ash, zsh, ksh), [Screenshots](https://github.com/zufuliu/notepad2/wiki/Screenshots#shell-script)
* C Shell (csh, tcsh)
* M4 Macro, limited support
* Android Dalvik Smali, [Screenshots](https://github.com/zufuliu/notepad2/wiki/Screenshots#android-smali)
* javap
Expand Down
19 changes: 14 additions & 5 deletions scintilla/lexers/LexBash.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,13 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in

#define IsCommentLine(line) IsLexCommentLine(line, styler, SCE_SH_COMMENTLINE)

#define MAX_BASH_WORD_LEN 7
#define MAX_BASH_WORD_LEN 15
static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, LexerWordList, Accessor &styler) {
if (styler.GetPropertyInt("fold") == 0)
return;
const bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
const bool isCShell = styler.GetPropertyInt("lexer.bash.csh.language") != 0;
const Sci_PositionU endPos = startPos + length;
int visibleChars = 0;
int skipHereCh = 0;
Expand Down Expand Up @@ -736,10 +737,18 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, LexerW
if (styleNext != SCE_SH_WORD) {
word[wordlen] = '\0';
wordlen = 0;
if (strcmp(word, "if") == 0 || strcmp(word, "case") == 0 || strcmp(word, "do") == 0) {
levelCurrent++;
} else if (strcmp(word, "fi") == 0 || strcmp(word, "esac") == 0 || strcmp(word, "done") == 0) {
levelCurrent--;
if (isCShell) {
if (strcmp(word, "if") == 0 || strcmp(word, "foreach") == 0 || strcmp(word, "switch") == 0 || strcmp(word, "while") == 0) {
levelCurrent++;
} else if (strcmp(word, "end") == 0 || strcmp(word, "endif") == 0 || strcmp(word, "endsw") == 0) {
levelCurrent--;
}
} else {
if (strcmp(word, "if") == 0 || strcmp(word, "case") == 0 || strcmp(word, "do") == 0) {
levelCurrent++;
} else if (strcmp(word, "fi") == 0 || strcmp(word, "esac") == 0 || strcmp(word, "done") == 0) {
levelCurrent--;
}
}
}
}
Expand Down
31 changes: 22 additions & 9 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,15 +882,28 @@ const char *EditKeywordIndent(const char *head, int *indent) {
}
break;
case SCLEX_BASH:
if (!strcmp(word, "if")) {
*indent = 2;
endPart = "fi";
} else if (!strcmp(word, "case")) {
*indent = 2;
endPart = "esac";
} else if (!strcmp(word, "do")) {
*indent = 2;
endPart = "done";
if (np2LexLangIndex == IDM_LANG_CSHELL) {
if (!strcmp(word, "if")) {
*indent = 2;
endPart = "endif";
} else if (!strcmp(word, "switch")) {
*indent = 2;
endPart = "endif";
} else if (!strcmp(word, "foreach") || !strcmp(word, "while")) {
*indent = 2;
endPart = "end";
}
} else {
if (!strcmp(word, "if")) {
*indent = 2;
endPart = "fi";
} else if (!strcmp(word, "case")) {
*indent = 2;
endPart = "esac";
} else if (!strcmp(word, "do")) {
*indent = 2;
endPart = "done";
}
}
break;
case SCLEX_MAKEFILE:
Expand Down
15 changes: 11 additions & 4 deletions src/EditLexers/stlBash.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include "EditLexer.h"
#include "EditStyle.h"

// https://en.wikipedia.org/wiki/Almquist_shell
// https://en.wikipedia.org/wiki/Bourne_shell
// https://www.gnu.org/software/bash/manual/
// https://en.wikipedia.org/wiki/C_shell
// https://en.wikipedia.org/wiki/KornShell
// https://en.wikipedia.org/wiki/Z_shell

static KEYWORDLIST Keywords_Bash = {{
// build-in
"alias true false yes no if then fi elif else end endif for foreach function functions in return "
"alias true false yes no if then fi elif else for function functions in return while "
" case esac eval ex exec do done du echo EOF "
// C Shell
"end endif foreach switch default breaksw endsw repeat "
// common
"ar asa awk banner basename bash bc bdiff break bunzip2 bzip2 cal calendar cat "
"ar asa awk banner basename bash bc bdiff break bunzip2 bzip2 cal calendar cat "
"cc cd chmod cksum clear cmp col comm compress continue cp cpio crypt csplit ctags cut date "
"dc dd declare deroff dev df diff diff3 dircmp dirname ed egrep "
"env exit expand export expr fc fgrep file find fmt fold "
Expand All @@ -18,7 +25,7 @@ static KEYWORDLIST Keywords_Bash = {{
"read readonly red rev rm rmdir sed select set sh shift size sleep sort spell split "
"start stop strings strip stty sum suspend sync tail tar tee test time times touch tr "
"trap tsort tty type typeset ulimit umask unalias uname uncompress unexpand uniq unpack "
"unset until uudecode uuencode vi vim vpax wait wc whence which while who wpaste wstart xargs "
"unset until uudecode uuencode vi vim vpax wait wc whence which who wpaste wstart xargs "
"zcat chgrp chown chroot dir dircolors factor groups hostid install link md5sum mkfifo mknod "
"nice pinky printenv ptx readlink seq sha1sum shred stat su tac unlink users vdir whoami yes dnl"

Expand All @@ -31,7 +38,7 @@ static KEYWORDLIST Keywords_Bash = {{
, "", "", "", "", "", "", ""
}};

EDITLEXER lexBash = { SCLEX_BASH, NP2LEX_BASH, L"Shell Script", L"sh; m4; in; po", L"", &Keywords_Bash,
EDITLEXER lexBash = { SCLEX_BASH, NP2LEX_BASH, L"Shell Script", L"sh; csh; zsh; bash; tcsh; m4; in; po", L"", &Keywords_Bash,
{
{ STYLE_DEFAULT, NP2STYLE_Default, L"Default", L"", L"" },
//{ SCE_SH_ERROR, 63531, L"Error", L"", L"" },
Expand Down
1 change: 1 addition & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4421,6 +4421,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
case IDM_LANG_SVG:

case IDM_LANG_BASH:
case IDM_LANG_CSHELL:
case IDM_LANG_M4:

case IDM_LANG_MATLAB:
Expand Down
1 change: 1 addition & 0 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ BEGIN
POPUP "Shell Script"
BEGIN
MENUITEM "Shell Script", IDM_LANG_BASH
MENUITEM "C Shell", IDM_LANG_CSHELL
MENUITEM "M4 Macro", IDM_LANG_M4
END
// "&SQL Dialect"
Expand Down
69 changes: 42 additions & 27 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) {
SciCall_SetProperty("lexer.css.less.language", ((np2LexLangIndex == IDM_LANG_LESS)? "1" : "0"));
SciCall_SetProperty("lexer.css.hss.language", ((np2LexLangIndex == IDM_LANG_HSS)? "1" : "0"));
break;

case NP2LEX_BASH:
SciCall_SetProperty("lexer.bash.csh.language", ((np2LexLangIndex == IDM_LANG_CSHELL)? "1" : "0"));
break;
}

Style_UpdateLexerKeywords(pLexNew);
Expand Down Expand Up @@ -1076,11 +1080,15 @@ PEDITLEXER __fastcall Style_SniffShebang(char *pchText) {
return &lexGroovy;
}
if (!strncmp(name, "scala", 5)) {
return (&lexScala);
return &lexScala;
}
}

if (!strncmp(name, "bash", 4) || !strncmp(name, "dash", 4) || !strncmp(name, "tcsh", 4)) {
if (!strncmp(name, "bash", 4) || !strncmp(name, "dash", 4)) {
return &lexBash;
}
if (!strncmp(name, "tcsh", 4)) {
np2LexLangIndex = IDM_LANG_CSHELL;
return &lexBash;
}
if (!strncmp(name, "perl", 4)) {
Expand Down Expand Up @@ -1116,7 +1124,11 @@ PEDITLEXER __fastcall Style_SniffShebang(char *pchText) {
if (!strncmp(name, "tcl", 3)) {
return &lexTcl;
}
if (!strncmp(name, "ash", 3) || !strncmp(name, "zsh", 3) || !strncmp(name, "ksh", 3) || !strncmp(name, "csh", 3)) {
if (!strncmp(name, "ash", 3) || !strncmp(name, "zsh", 3) || !strncmp(name, "ksh", 3)) {
return &lexBash;
}
if (!strncmp(name, "csh", 3)) {
np2LexLangIndex = IDM_LANG_CSHELL;
return &lexBash;
}
if (!strncmp(name, "ipy", 3)) {
Expand Down Expand Up @@ -1537,6 +1549,9 @@ void Style_GetCurrentLexerName(LPWSTR lpszName, int cchName) {
case IDM_LANG_BASH:
lang = L"Shell Script";
break;
case IDM_LANG_CSHELL:
lang = L"C Shell";
break;
case IDM_LANG_M4:
lang = L"M4 Macro";
break;
Expand Down Expand Up @@ -1583,88 +1598,87 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch, BOOL bCheckNames) {
if (!bCheckNames) {
//if (StrNCaseEqual(L"php", lpszMatch, 3) || StrCaseEqual(L"phtml", lpszMatch))) {
// np2LexLangIndex = IDM_LANG_PHP;
// return (&lexPHP);
// return &lexPHP;
//}
if (StrCaseEqual(L"jsp", lpszMatch)) {
np2LexLangIndex = IDM_LANG_JSP;
return (&lexHTML);
return &lexHTML;
}
if (StrCaseEqual(L"aspx", lpszMatch)) {
np2LexLangIndex = Style_GetDocTypeLanguage();
if (np2LexLangIndex == 0) {
np2LexLangIndex = IDM_LANG_ASPX_CS;
}
return (&lexHTML);
return &lexHTML;
}
if (StrCaseEqual(L"asp", lpszMatch)) {
np2LexLangIndex = Style_GetDocTypeLanguage();
if (np2LexLangIndex == 0) {
np2LexLangIndex = IDM_LANG_ASP_VBS;
}
return (&lexHTML);
return &lexHTML;
}

if (StrCaseEqual(L"xsd", lpszMatch)) {
np2LexLangIndex = IDM_LANG_XSD;
return (&lexXML);
return &lexXML;
}
if (StrNCaseEqual(L"xsl", lpszMatch, 3)) {
np2LexLangIndex = IDM_LANG_XSLT;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"dtd", lpszMatch)) {
np2LexLangIndex = IDM_LANG_DTD;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"pom", lpszMatch)) {
np2LexLangIndex = IDM_LANG_MAVEN_POM;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"resx", lpszMatch)) {
np2LexLangIndex = IDM_LANG_RESX;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"xaml", lpszMatch)) {
np2LexLangIndex = IDM_LANG_XAML;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"plist", lpszMatch)) {
np2LexLangIndex = IDM_LANG_PROPERTY_LIST;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"svg", lpszMatch)) {
np2LexLangIndex = IDM_LANG_SVG;
return (&lexXML);
return &lexXML;
}
if (StrCaseEqual(L"xml", lpszMatch)) {
np2LexLangIndex = Style_GetDocTypeLanguage();
return (&lexXML);
}
if (StrCaseEqual(L"sce", lpszMatch)) {
lexMatlab.rid = NP2LEX_SCILAB;
np2LexLangIndex = IDM_LANG_SCILAB;
return (&lexMatlab);
return &lexXML;
}
if (StrCaseEqual(L"sci", lpszMatch)) {
if (StrCaseEqual(L"sce", lpszMatch) || StrCaseEqual(L"sci", lpszMatch)) {
lexMatlab.rid = NP2LEX_SCILAB;
np2LexLangIndex = IDM_LANG_SCILAB;
return (&lexMatlab);
return &lexMatlab;
}
if (StrCaseEqual(L"m4", lpszMatch)) {
np2LexLangIndex = IDM_LANG_M4;
return (&lexBash);
return &lexBash;
}
if (StrCaseEqual(L"csh", lpszMatch) || StrCaseEqual(L"tcsh", lpszMatch)) {
np2LexLangIndex = IDM_LANG_CSHELL;
return &lexBash;
}
if (StrCaseEqual(L"scss", lpszMatch)) {
np2LexLangIndex = IDM_LANG_SCSS;
return (&lexCSS);
return &lexCSS;
}
if (StrCaseEqual(L"less", lpszMatch)) {
np2LexLangIndex = IDM_LANG_LESS;
return (&lexCSS);
return &lexCSS;
}
if (StrCaseEqual(L"hss", lpszMatch)) {
np2LexLangIndex = IDM_LANG_HSS;
return (&lexCSS);
return &lexCSS;
}
if (bAutoSelect && StrCaseEqual(L"m", lpszMatch)) {
PEDITLEXER lex = Style_DetectObjCAndMatlab();
Expand Down Expand Up @@ -1981,6 +1995,7 @@ void Style_SetLexerByLangIndex(HWND hwnd, int lang) {
break;

case IDM_LANG_BASH:
case IDM_LANG_CSHELL:
case IDM_LANG_M4:
Style_SetLexer(hwnd, &lexBash);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@
#define IDM_LANG_PMD_RULESET 41026
#define IDM_LANG_CHECKSTYLE 41027

#define IDM_LANG_CSHELL 41028

#define IDM_LANG_APACHE 41030
#define IDM_LANG_TOMCAT 41031
#define IDM_LANG_WEB_JAVA 41032
Expand Down

0 comments on commit 78fbccc

Please sign in to comment.