From b518770dea6daeba90f5c16a9b194f16b7de39c9 Mon Sep 17 00:00:00 2001 From: canou Date: Mon, 12 Aug 2013 21:51:00 +0200 Subject: [PATCH] Add support for DOS, OS/2 and Windows batch files * Uses existing LexOthers.cxx from Scintilla already in use by Geany * "identifier" style mapping goes to "string" for better presentation even if it's semantically incorrect, we'll change it back if it causes issues for anyone. * Filetype configuration and keywords taken from Don Ho's Notepad++. Closes #160 --- data/filetype_extensions.conf | 1 + data/filetypes.batch | 40 ++++++++++++++++++++++++++++++++++++++++ scintilla/src/Catalogue.cxx | 1 + src/filetypes.c | 6 ++++++ src/filetypes.h | 1 + src/highlighting.c | 2 ++ src/highlightingmappings.h | 21 +++++++++++++++++++++ 7 files changed, 72 insertions(+) create mode 100644 data/filetypes.batch diff --git a/data/filetype_extensions.conf b/data/filetype_extensions.conf index 9accfa312..a20d2b226 100644 --- a/data/filetype_extensions.conf +++ b/data/filetype_extensions.conf @@ -8,6 +8,7 @@ ActionScript=*.as; Ada=*.adb;*.ads; Asciidoc=*.asciidoc; ASM=*.asm; +Batch=*.bat;*.cmd;*.nt; CAML=*.ml;*.mli; C=*.c;*.h; C++=*.cpp;*.cxx;*.c++;*.cc;*.h;*.hpp;*.hxx;*.h++;*.hh;*.C;*.H; diff --git a/data/filetypes.batch b/data/filetypes.batch new file mode 100644 index 000000000..df2fe393b --- /dev/null +++ b/data/filetypes.batch @@ -0,0 +1,40 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# Edit these in the colorscheme .conf file instead +default=default +comment=comment_line +label=label +word=keyword_1 +hide=other +command=function +operator=operator +identifier=string + +[keywords] +# all items must be in one line +keywords=rem set if else exist errorlevel for in do break call copy chcp cd chdir choice cls country ctty date del erase dir echo exit goto loadfix loadhigh mkdir md move path pause prompt rename ren rmdir rd shift time type ver verify vol com con lpt nul defined not errorlevel cmdextversion +keywords_optional= + +[settings] +# default extension used when saving files +extension=bat + +# the following characters are these which a "word" can contains, see documentation +#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 + +# single comments, like # in this file +comment_single=:: +# multiline comments +#comment_open= +#comment_close= + +# set to false if a comment character/string should start at column 0 of a line, true uses any +# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d + #command_example(); +# setting to false would generate this +# command_example(); +# This setting works only for single line comments +comment_use_indent=true + +# context action command (please see Geany's main documentation for details) +context_action_cmd= diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index 37b2a3c93..f1f3e5ab0 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -85,6 +85,7 @@ int Scintilla_LinkLexers() { LINK_LEXER(lmAda); LINK_LEXER(lmAsm); LINK_LEXER(lmBash); + LINK_LEXER(lmBatch); LINK_LEXER(lmCaml); LINK_LEXER(lmCmake); LINK_LEXER(lmCOBOL); diff --git a/src/filetypes.c b/src/filetypes.c index a6405ec95..aee2af574 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -510,6 +510,12 @@ static void init_builtin_filetypes(void) ft->name = g_strdup("Abaqus"); filetype_make_title(ft, TITLE_SOURCE_FILE); ft->group = GEANY_FILETYPE_GROUP_SCRIPT; + +#define BATCH + ft = filetypes[GEANY_FILETYPES_BATCH]; + ft->name = g_strdup("Batch"); + filetype_make_title(ft, TITLE_FILE); + ft->group = GEANY_FILETYPE_GROUP_SCRIPT; } diff --git a/src/filetypes.h b/src/filetypes.h index 58cca9290..7db83b0dd 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -92,6 +92,7 @@ typedef enum GEANY_FILETYPES_OBJECTIVEC, GEANY_FILETYPES_ASCIIDOC, GEANY_FILETYPES_ABAQUS, + GEANY_FILETYPES_BATCH, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ } diff --git a/src/highlighting.c b/src/highlighting.c index c6c29139f..92676284e 100644 --- a/src/highlighting.c +++ b/src/highlighting.c @@ -1045,6 +1045,7 @@ void highlighting_init_styles(guint filetype_idx, GKeyFile *config, GKeyFile *co init_styleset_case(ADA); init_styleset_case(ASM); init_styleset_case(BASIC); + init_styleset_case(BATCH); init_styleset_case(C); init_styleset_case(CAML); init_styleset_case(CMAKE); @@ -1125,6 +1126,7 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft) styleset_case(ADA); styleset_case(ASM); styleset_case(BASIC); + styleset_case(BATCH); styleset_case(C); styleset_case(CAML); styleset_case(CMAKE); diff --git a/src/highlightingmappings.h b/src/highlightingmappings.h index 9dca7a3d9..20102a038 100644 --- a/src/highlightingmappings.h +++ b/src/highlightingmappings.h @@ -196,6 +196,27 @@ static const HLKeyword highlighting_keywords_BASIC[] = #define highlighting_properties_BASIC EMPTY_PROPERTIES +/* BATCH */ +#define highlighting_lexer_BATCH SCLEX_BATCH +static const HLStyle highlighting_styles_BATCH[] = +{ + { SCE_BAT_DEFAULT, "default", FALSE }, + { SCE_BAT_COMMENT, "comment", FALSE }, + { SCE_BAT_LABEL, "label", FALSE }, + { SCE_BAT_WORD, "word", FALSE }, + { SCE_BAT_HIDE, "hide", FALSE }, + { SCE_BAT_COMMAND, "command", FALSE }, + { SCE_BAT_IDENTIFIER, "identifier", FALSE }, + { SCE_BAT_OPERATOR, "operator", FALSE } +}; +static const HLKeyword highlighting_keywords_BATCH[] = +{ + { 0, "keywords", FALSE }, + { 1, "keywords_optional", FALSE } +}; +#define highlighting_properties_BATCH EMPTY_PROPERTIES + + /* C */ /* Also used by some other SCLEX_CPP-based filetypes */ #define highlighting_lexer_C SCLEX_CPP -- 2.11.4.GIT