#982 GitHub style Bash backticks


GitHub uses a different style for Bash backticks, example

Instead of coloring the entire section they only color the
opening "$(" and closing ")"

This is desirable with Scintilla because keywords within backticks could be highlighted instead of the whole section being one color. I am not asking that this be implemented per se, but if someone could help me along with the code. I was able to do this

--- a/scintilla/lexers/LexBash.cxx
+++ b/scintilla/lexers/LexBash.cxx
@@ -628,7 +628,7 @@ static void ColouriseBashDoc(unsigned int startPos, int length, i
                                QuoteStack.Start(sc.ch, BASH_DELIM_BACKTICK);
                        } else if (sc.ch == '$') {
-                               if (sc.Match("$((")) {
+                               if (sc.Match("$((") || sc.Match("$(")) {^M
                                        sc.SetState(SCE_SH_OPERATOR);   // handle '((

but this doesnt give style to the "$(" and ")", only allow keyword styles within the


  • Kein-Hong Man

    Kein-Hong Man - 2013-04-01

    Here is a patch that has been casually tested.

    --- a/scintilla/lexers/LexBash.zzz
    +++ b/scintilla/lexers/LexBash.cxx
    @@ -644,8 +644,8 @@
                        QuoteStack.Start(sc.ch, BASH_DELIM_LSTRING);
                    } else if (sc.ch == '(') {
    -                   sc.ChangeState(SCE_SH_BACKTICKS);
    -                   QuoteStack.Start(sc.ch, BASH_DELIM_COMMAND);
    +                   sc.ChangeState(SCE_SH_OPERATOR);
    +                   cmdState = BASH_CMD_DELIM;
                    } else if (sc.ch == '`') {  // $` seen in a configure script, valid?
                        QuoteStack.Start(sc.ch, BASH_DELIM_BACKTICK);

    The $( and ) are styled as operators, anything else would be non-trivial. The cmdState line tells the lexer the next word may be a keyword.

  • Steven Penny

    Steven Penny - 2013-04-01

    Kein-Hong, thanks for you reply. However after looking again it appears my original patch already set $( and ) as operators. This is not desired because I would like to style the backticks independent of operators.

  • Kein-Hong Man

    Kein-Hong Man - 2013-04-01

    Assuming you don't want $() to clash with ``, you'll need a new style. Add the style entry in the appropriate places, then duplicate the relevant code running operators for the new $() style.

    BUT... the flaw or problem in the above solution is this: how does the closing parentheses know it needs to use the $( style? Matched $( and ) in its own style cannot be trivially implemented, since our lexer code is lower-level but faster compared to regexp or high-level matchers. So, styling it as operators is the quickest solution, else much more time will have to be invested.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks