Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#982 GitHub style Bash backticks

Completed
open
nobody
None
5
2013-04-01
2013-03-31
Steven Penny
No

GitHub uses a different style for Bash backticks, example
http://github.com/git/git/blob/master/git-pull.sh

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
                                sc.SetState(SCE_SH_BACKTICKS);
                                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 '((
                                        continue;
                                }

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

Discussion

  • 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 @@
                        sc.ChangeState(SCE_SH_STRING);
                        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?
                        sc.ChangeState(SCE_SH_BACKTICKS);
                        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.