From 65fef4deebf33412538eeb6452949a46090ca7b4 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Mon, 6 Jan 2025 19:36:48 +0800 Subject: [PATCH] Open TSV file using tab as delimiter, issue #892. --- doc/FileExt.txt | 1 + src/EditLexers/stlDefault.cpp | 2 +- src/Styles.cpp | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/FileExt.txt b/doc/FileExt.txt index 2c1d29452e..154f6bee0f 100644 --- a/doc/FileExt.txt +++ b/doc/FileExt.txt @@ -265,6 +265,7 @@ Config File CSV File csv + tsv D Source diff --git a/src/EditLexers/stlDefault.cpp b/src/EditLexers/stlDefault.cpp index 9455a6d8ee..d550b644fc 100644 --- a/src/EditLexers/stlDefault.cpp +++ b/src/EditLexers/stlDefault.cpp @@ -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 }; diff --git a/src/Styles.cpp b/src/Styles.cpp index 4f26edde0b..25e68a7c4a 100644 --- a/src/Styles.cpp +++ b/src/Styles.cpp @@ -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) @@ -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; @@ -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); @@ -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);