All,
I am attempting to add filetype and syntax highlighting support for R scripts. I am following the steps outlined in HACKING. I've added GEANY_FILETYPES_R to filetypes.h, initialized GEANY_FILETYPES_R in init_builtin_filetypes(), and updated data/filetype_extensions.conf. After rebuilding Geany, R scripts show up in the Filetypes menu under scripting languages and Geany recognizes *.R and *.r files as R scripts. So, the first step was successful.
On to the syntax highlighting. I shamelessly stole LexR.cxx from scintilla and I've created data/filetypes.r. I then wrote the styleset_r_init() and styleset_r() functions, added init_styleset_case(GEANY_FILETYPES_R, r) to highlighting_init_styles(), and added styleset_case(GEANY_FILETYPES_R, r) to highlighting_set_styles().
Unfortunately, the only style that is applied to R scripts is the default style. If I change the hex color codes in highlighting.c or in data/filetypes.r, the new colors will be used. However, none of the other styles are being used.
Below are my init_styleset_case() and styleset_case() functions. I'm sure it's something I've done wrong, but I can't see the problem. A pointer in the right direction would be appreciated.
TIA
Andrew
static void styleset_r_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { new_style_array(GEANY_FILETYPES_R, 12);
get_keyfile_hex(config, config_home, "styling", "default", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[0]); get_keyfile_hex(config, config_home, "styling", "comment", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[1]); get_keyfile_hex(config, config_home, "styling", "kword", "0xF70808", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[2]); get_keyfile_hex(config, config_home, "styling", "operator", "0x000fff", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[3]); get_keyfile_hex(config, config_home, "styling", "basekword", "0x000fff", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[4]); get_keyfile_hex(config, config_home, "styling", "otherkword", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[5]); get_keyfile_hex(config, config_home, "styling", "number", "0x000fff", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[6]); get_keyfile_hex(config, config_home, "styling", "string", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[7]); get_keyfile_hex(config, config_home, "styling", "string2", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[8]); get_keyfile_hex(config, config_home, "styling", "identifier", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[9]); get_keyfile_hex(config, config_home, "styling", "infix", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[10]); get_keyfile_hex(config, config_home, "styling", "infixeol", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[11]); style_sets[GEANY_FILETYPES_R].keywords = g_new(gchar*, 2); get_keyfile_keywords(config, config_home, "keywords", "primary", GEANY_FILETYPES_R, 0, "if source array matrix diag solve for"); style_sets[GEANY_FILETYPES_R].keywords[1] = NULL;
get_keyfile_wordchars(config, config_home, &style_sets[GEANY_FILETYPES_R].wordchars); }
static void styleset_r(ScintillaObject *sci) { const filetype_id ft_id = GEANY_FILETYPES_R;
styleset_common(sci, 5, ft_id);
apply_filetype_properties(sci, SCLEX_R, ft_id);
SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) style_sets[GEANY_FILETYPES_R].keywords[0]);
set_sci_style(sci, STYLE_DEFAULT, GEANY_FILETYPES_R, 0); set_sci_style(sci, SCE_R_DEFAULT, GEANY_FILETYPES_R, 0); set_sci_style(sci, SCE_R_COMMENT, GEANY_FILETYPES_R, 1); set_sci_style(sci, SCE_R_KWORD, GEANY_FILETYPES_R, 2); set_sci_style(sci, SCE_R_OPERATOR, GEANY_FILETYPES_R, 3); set_sci_style(sci, SCE_R_BASEKWORD, GEANY_FILETYPES_R, 4); set_sci_style(sci, SCE_R_OTHERKWORD, GEANY_FILETYPES_R, 5); set_sci_style(sci, SCE_R_NUMBER, GEANY_FILETYPES_R, 6); set_sci_style(sci, SCE_R_STRING, GEANY_FILETYPES_R, 7); set_sci_style(sci, SCE_R_STRING2, GEANY_FILETYPES_R, 8); set_sci_style(sci, SCE_R_IDENTIFIER, GEANY_FILETYPES_R, 9); set_sci_style(sci, SCE_R_INFIX, GEANY_FILETYPES_R, 10); set_sci_style(sci, SCE_R_INFIXEOL, GEANY_FILETYPES_R, 11); }
Scintilla needs to find the SCLEX_R lexer. Most of the default lexers are removed for Geany (scintilla/Lex*.cpp files) You should be able to download a copy of Scintilla 1.76 and copy the proper lexer file into Geany's scintilla dir. That should be the only thing left to do, if I recall...
Jay
On Sep 19, 2008, at 2:46 AM, Andrew Rowland wrote:
All,
I am attempting to add filetype and syntax highlighting support for R scripts. I am following the steps outlined in HACKING. I've added GEANY_FILETYPES_R to filetypes.h, initialized GEANY_FILETYPES_R in init_builtin_filetypes(), and updated data/filetype_extensions.conf. After rebuilding Geany, R scripts show up in the Filetypes menu under scripting languages and Geany recognizes *.R and *.r files as R scripts. So, the first step was successful.
On to the syntax highlighting. I shamelessly stole LexR.cxx from scintilla and I've created data/filetypes.r. I then wrote the styleset_r_init() and styleset_r() functions, added init_styleset_case(GEANY_FILETYPES_R, r) to highlighting_init_styles(), and added styleset_case(GEANY_FILETYPES_R, r) to highlighting_set_styles().
Unfortunately, the only style that is applied to R scripts is the default style. If I change the hex color codes in highlighting.c or in data/filetypes.r, the new colors will be used. However, none of the other styles are being used.
Below are my init_styleset_case() and styleset_case() functions. I'm sure it's something I've done wrong, but I can't see the problem. A pointer in the right direction would be appreciated.
TIA
Andrew
static void styleset_r_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { new_style_array(GEANY_FILETYPES_R, 12);
get_keyfile_hex(config, config_home, "styling", "default", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[0]); get_keyfile_hex(config, config_home, "styling", "comment", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[1]); get_keyfile_hex(config, config_home, "styling", "kword", "0xF70808", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[2]); get_keyfile_hex(config, config_home, "styling", "operator", "0x000fff", "0xffffff", "false", &style_sets[GEANY_FILETYPES_R].styling[3]); get_keyfile_hex(config, config_home, "styling", "basekword", "0x000fff", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[4]); get_keyfile_hex(config, config_home, "styling", "otherkword", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[5]); get_keyfile_hex(config, config_home, "styling", "number", "0x000fff", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[6]); get_keyfile_hex(config, config_home, "styling", "string", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[7]); get_keyfile_hex(config, config_home, "styling", "string2", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[8]); get_keyfile_hex(config, config_home, "styling", "identifier", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[9]); get_keyfile_hex(config, config_home, "styling", "infix", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[10]); get_keyfile_hex(config, config_home, "styling", "infixeol", "0x119911", "0xffffff", "true", &style_sets[GEANY_FILETYPES_R].styling[11]);
style_sets[GEANY_FILETYPES_R].keywords = g_new(gchar*, 2); get_keyfile_keywords(config, config_home, "keywords", "primary", GEANY_FILETYPES_R, 0, "if source array matrix diag solve for"); style_sets[GEANY_FILETYPES_R].keywords[1] = NULL;
get_keyfile_wordchars(config, config_home, &style_sets[GEANY_FILETYPES_R].wordchars); }
static void styleset_r(ScintillaObject *sci) { const filetype_id ft_id = GEANY_FILETYPES_R;
styleset_common(sci, 5, ft_id);
apply_filetype_properties(sci, SCLEX_R, ft_id);
SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) style_sets[GEANY_FILETYPES_R].keywords[0]);
set_sci_style(sci, STYLE_DEFAULT, GEANY_FILETYPES_R, 0); set_sci_style(sci, SCE_R_DEFAULT, GEANY_FILETYPES_R, 0); set_sci_style(sci, SCE_R_COMMENT, GEANY_FILETYPES_R, 1); set_sci_style(sci, SCE_R_KWORD, GEANY_FILETYPES_R, 2); set_sci_style(sci, SCE_R_OPERATOR, GEANY_FILETYPES_R, 3); set_sci_style(sci, SCE_R_BASEKWORD, GEANY_FILETYPES_R, 4); set_sci_style(sci, SCE_R_OTHERKWORD, GEANY_FILETYPES_R, 5); set_sci_style(sci, SCE_R_NUMBER, GEANY_FILETYPES_R, 6); set_sci_style(sci, SCE_R_STRING, GEANY_FILETYPES_R, 7); set_sci_style(sci, SCE_R_STRING2, GEANY_FILETYPES_R, 8); set_sci_style(sci, SCE_R_IDENTIFIER, GEANY_FILETYPES_R, 9); set_sci_style(sci, SCE_R_INFIX, GEANY_FILETYPES_R, 10); set_sci_style(sci, SCE_R_INFIXEOL, GEANY_FILETYPES_R, 11); }
Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
On Fri, 19 Sep 2008 05:46:19 -0400 Andrew Rowland weibullguy@charter.net wrote:
On to the syntax highlighting. I shamelessly stole LexR.cxx from scintilla and I've created data/filetypes.r. I then wrote the styleset_r_init() and styleset_r() functions, added init_styleset_case(GEANY_FILETYPES_R, r) to highlighting_init_styles (), and added styleset_case(GEANY_FILETYPES_R, r) to highlighting_set_styles().
Unfortunately, the only style that is applied to R scripts is the default style. If I change the hex color codes in highlighting.c or in data/filetypes.r, the new colors will be used. However, none of the other styles are being used.
As Jason Oster suggested, probably Scintilla isn't finding the lexer.
You need to edit: scintilla/KeyWords.cxx scintilla/Makefile.am (and scintilla/makefile.win32)
For an example, see the changes for LexBasic.cxx: http://geany.svn.sourceforge.net/viewvc/geany?view=rev&revision=1635
Regards, Nick
On Fri, 2008-09-19 at 17:17 +0100, Nick Treleaven wrote:
On Fri, 19 Sep 2008 05:46:19 -0400 Andrew Rowland weibullguy@charter.net wrote:
On to the syntax highlighting. I shamelessly stole LexR.cxx from scintilla and I've created data/filetypes.r. I then wrote the styleset_r_init() and styleset_r() functions, added init_styleset_case(GEANY_FILETYPES_R, r) to highlighting_init_styles (), and added styleset_case(GEANY_FILETYPES_R, r) to highlighting_set_styles().
Unfortunately, the only style that is applied to R scripts is the default style. If I change the hex color codes in highlighting.c or in data/filetypes.r, the new colors will be used. However, none of the other styles are being used.
As Jason Oster suggested, probably Scintilla isn't finding the lexer.
You need to edit: scintilla/KeyWords.cxx scintilla/Makefile.am (and scintilla/makefile.win32)
For an example, see the changes for LexBasic.cxx: http://geany.svn.sourceforge.net/viewvc/geany?view=rev&revision=1635
The link was the trick to figuring out everything that needed to be edited! Thanks for that. R script syntax highlighting is working now.
I'm not a Windows user, so I only made the changes necessary for a *nix build of Geany. The following is the resulting patch against version 0.14:
http://svn.cross-lfs.org/svn/repos/patches/geany/geany-0.14-R_highlighting-1...
I also added a link to the patch on the Geany Wishlist page.
Thanks again,
Andrew
On Fri, 19 Sep 2008 21:09:45 -0400 Andrew Rowland weibullguy@charter.net wrote:
The following is the resulting patch against version 0.14:
http://svn.cross-lfs.org/svn/repos/patches/geany/geany-0.14-R_highlighting-1...
Thanks, I'll look at porting it into SVN. BTW which version of Scintilla did you take LexR.cxx from? I'm a bit puzzled as to why some of the SciLexer.h define values have changed.
Regards, Nick
The defines in SciLexer.h should never change between Scintilla versions. This would cause API breakage, which I believe is [generally] against Niel's update policy.
Andrew, if you made any changes to those defines (other than additions) please consider reverting those changes back to the original settings.
I understand the problem from a personal perspective; I've been adding extra functionality to the CSS lexer, and it's a pain to see things like the style definitions and keyword lists all arranged out of any sort of logical order. But in practice, I have no choice but leaving those alone unless I want to risk breaking backward compatibility. :(
Jay
Nick Treleaven wrote:
On Fri, 19 Sep 2008 21:09:45 -0400 Andrew Rowland weibullguy@charter.net wrote:
The following is the resulting patch against version 0.14:
http://svn.cross-lfs.org/svn/repos/patches/geany/geany-0.14-R_highlighting-1...
Thanks, I'll look at porting it into SVN. BTW which version of Scintilla did you take LexR.cxx from? I'm a bit puzzled as to why some of the SciLexer.h define values have changed.
Regards, Nick _______________________________________________ Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
Jay and Nick,
I used the scintilla176.tgz archive.
When I was trying to get things working, I did rearrange the define values for R files for some reason I no longer recall. I've updated the patch using the original order of R defines, tested that it applies to version 0.14, rebuilt Geany and verified syntax highlighting works. Same URL as the original patch.
Andrew
On Thu, 2008-09-25 at 10:04 -0700, Jason Oster wrote:
The defines in SciLexer.h should never change between Scintilla versions. This would cause API breakage, which I believe is [generally] against Niel's update policy.
Andrew, if you made any changes to those defines (other than additions) please consider reverting those changes back to the original settings.
I understand the problem from a personal perspective; I've been adding extra functionality to the CSS lexer, and it's a pain to see things like the style definitions and keyword lists all arranged out of any sort of logical order. But in practice, I have no choice but leaving those alone unless I want to risk breaking backward compatibility. :(
Jay
Nick Treleaven wrote:
On Fri, 19 Sep 2008 21:09:45 -0400 Andrew Rowland weibullguy@charter.net wrote:
The following is the resulting patch against version 0.14:
http://svn.cross-lfs.org/svn/repos/patches/geany/geany-0.14-R_highlighting-1...
Thanks, I'll look at porting it into SVN. BTW which version of Scintilla did you take LexR.cxx from? I'm a bit puzzled as to why some of the SciLexer.h define values have changed.
Regards, Nick _______________________________________________ Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
On Fri, 26 Sep 2008 00:21:13 -0400 Andrew Rowland weibullguy@charter.net wrote:
I used the scintilla176.tgz archive.
When I was trying to get things working, I did rearrange the define values for R files for some reason I no longer recall. I've updated the patch using the original order of R defines, tested that it applies to version 0.14, rebuilt Geany and verified syntax highlighting works. Same URL as the original patch.
Thanks for the info. But the URL is the same patch as before - although presumably I can just remove the SciLexer.h changes from it myself and it will work.
Regards, Nick
On Fri, 2008-09-26 at 12:07 +0100, Nick Treleaven wrote:
On Fri, 26 Sep 2008 00:21:13 -0400 Andrew Rowland weibullguy@charter.net wrote:
I used the scintilla176.tgz archive.
When I was trying to get things working, I did rearrange the define values for R files for some reason I no longer recall. I've updated the patch using the original order of R defines, tested that it applies to version 0.14, rebuilt Geany and verified syntax highlighting works. Same URL as the original patch.
Thanks for the info. But the URL is the same patch as before - although presumably I can just remove the SciLexer.h changes from it myself and it will work.
Same URL, but what lives inside the patch should be different. I started over with a clean source tree of Geany-0.14 and didn't rearrange anything in SciLexer.h this time.
I discovered the tab issue after I created a REALLY big patch. Sorry if some of the tabs were converted to spaces in the final patch.
Just built svn and everything looks hunky-dory for my R scripts.
Thanks,
Andrew
Regards, Nick _______________________________________________ Geany mailing list Geany@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany
On Fri, 26 Sep 2008 13:46:12 -0400, Andrew Rowland weibullguy@charter.net wrote:
On Fri, 2008-09-26 at 12:07 +0100, Nick Treleaven wrote:
On Fri, 26 Sep 2008 00:21:13 -0400 Andrew Rowland weibullguy@charter.net wrote:
I used the scintilla176.tgz archive.
When I was trying to get things working, I did rearrange the define values for R files for some reason I no longer recall. I've updated the patch using the original order of R defines, tested that it applies to version 0.14, rebuilt Geany and verified syntax highlighting works. Same URL as the original patch.
Thanks for the info. But the URL is the same patch as before - although presumably I can just remove the SciLexer.h changes from it myself and it will work.
Same URL, but what lives inside the patch should be different. I started over with a clean source tree of Geany-0.14 and didn't rearrange anything in SciLexer.h this time.
I discovered the tab issue after I created a REALLY big patch. Sorry if some of the tabs were converted to spaces in the final patch.
Just built svn and everything looks hunky-dory for my R scripts.
I just updated the colours used for syntax highlighting of R files and added more keywords, also using two other keyword types of the Scintilla lexer.
Andrew, could you look at https://sourceforge.net/tracker/index.php?func=detail&aid=2121502&gr... and comment there is anything is still (or newly) wrong? Thanks.
We (Nick and me) don't use R files, so your feedback is very much appreciated.
Regards, Enrico
On Thu, 25 Sep 2008 17:40:36 +0100 Nick Treleaven nick.treleaven@btinternet.com wrote:
Thanks, I'll look at porting it into SVN.
Added to SVN, thanks for the patch. I couldn't easily find any example code, so please test it.
BTW we use tab indentation ;-) This was the hardest bit to port.
Regards, Nick