Skip to content

Commit

Permalink
Open TSV file using tab as delimiter, issue #892.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 6, 2025
1 parent 8f03f50 commit 65fef4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/FileExt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Config File

CSV File
csv
tsv


D Source
Expand Down
2 changes: 1 addition & 1 deletion src/EditLexers/stlDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ EDITLEXER lexCSV = {
0, 0,
//CSV Settings--Autogenerated -- end of section automatically generated
EDITLEXER_HOLE(L"CSV File", Styles_CSV),
L"csv",
L"csv; tsv",
&Keywords_NULL,
Styles_CSV
};
Expand Down
11 changes: 10 additions & 1 deletion src/Styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ static WCHAR favoriteSchemesConfig[MAX_FAVORITE_SCHEMES_CONFIG_SIZE];
// Currently used lexer
PEDITLEXER pLexCurrent = &lexTextFile;
int np2LexLangIndex = 0;
static bool tabSeparatedValue; // for TSV file
static int iCsvOption = ('\"' << 8) | ',';

#define CsvOption_BackslashEscape (1 << 15)
Expand Down Expand Up @@ -2402,6 +2403,13 @@ static void Style_UpdateLexerLang(LPCEDITLEXER pLex, LPCWSTR lpszExt, LPCWSTR lp
}
break;

case NP2LEX_CSV:
if (StrCaseEqual(L"tsv", lpszExt)) {
tabSeparatedValue = true;
iCsvOption = ('\"' << 8) | '\t';
}
break;

case NP2LEX_HTML:
if (StrCaseEqual(L"jsp", lpszExt)) {
np2LexLangIndex = IDM_LEXER_JSP;
Expand Down Expand Up @@ -2619,6 +2627,7 @@ bool Style_SetLexerFromFile(LPCWSTR lpszFile) noexcept {
LPCWSTR lpszExt = nullptr;
PEDITLEXER pLexNew = nullptr;
PEDITLEXER pLexSniffed;
tabSeparatedValue = false;

if (bAutoSelect) {
pLexNew = Style_GetLexerFromFile(lpszFile, !fNoCGIGuess, &lpszExt, &bDotFile);
Expand Down Expand Up @@ -2722,7 +2731,7 @@ bool Style_SetLexerFromFile(LPCWSTR lpszFile) noexcept {
pLexNew = pLexArray[iDefaultLexerIndex];
}
// Apply the new lexer
if (pLexNew->iLexer == SCLEX_CSV) {
if (pLexNew->iLexer == SCLEX_CSV && !tabSeparatedValue) {
Style_SniffCSV();
}
Style_SetLexer(pLexNew, true);
Expand Down

0 comments on commit 65fef4d

Please sign in to comment.