|
-
October 15th, 2009, 05:39 PM
#1
How to compile NotePad2 and add custom syntax highlighting
The main reason behind this post is this morning I found my self wanting to write a ruby script and it not being syntax highlighted in a recent version of notepad2(unless you consider 2007 recent). So, knowing that NotePad2 is open source, I did what any self respecting hacker would do, I grabbed the source code and threw it into VS C++ 2008 Pro(I'll try it in express sometime during the next few hours). To my dismay however, it didn't compile and the source documentation is just above nonexistent. Oh how I love a challenge.
Anyways, here are the steps:
1. Grab the NotePad2 source, extract it, then get Scintilla 1.79; then extract the scintilla folder(you don't need the scite one) to the root of the NotePad2 project directory.
2. Open up the solution and upgrade it, there shouldn't be any errors.
3. Right click the NotePad2 project in the solution explorer and go to properties. Then go to Linker->General and disable incremental linking.
4. Edit scintilla/src/KeyWords.cxx and replace the following line(As per README):
Code:
#define LINK_LEXER(lexer) extern LexerModule lexer; ...
with
#define LINK_LEXER(lexer) void(0)
5. Add the following lines to Dlapi.h:
Code:
#ifndef LPSHELLICON
typedef struct IShellIcon IShellIcon, *LPSHELLICON;
#endif
6. Add the following to src/Styles.c (modified code from the last NotePad2 with Ruby):
Code:
KEYWORDLIST KeyWords_RUBY = {
"__FILE__ and def end in or self unless __LINE__ begin "
"defined? ensure module redo super until BEGIN break do false next rescue "
"then when END case else for nil retry true while alias class elsif if "
"not return undef yield",
"", "", "", "", "", "", "", "" };
EDITLEXER lexRUBY = { SCLEX_RUBY, 63022, L"Ruby", L"rb;ruby", L"", &KeyWords_RUBY, {
{ STYLE_DEFAULT, 63126, L"Default", L"", L"" },
//{ SCE_P_DEFAULT, L"Default", L"", L"" },
{ SCE_P_COMMENTLINE, 63127, L"Comment", L"fore:#007F00", L"" },
{ SCE_P_COMMENTBLOCK, 63127, L"Comment Block", L"fore:#007F00", L"" },
{ SCE_P_WORD, 63128, L"Keyword", L"fore:#00007F;bold", L"" },
{ SCE_P_IDENTIFIER, 63129, L"Identifier", L"", L"" },
{ SCE_P_NUMBER, 63130, L"Number", L"fore:#007F7F", L"" },
{ SCE_P_OPERATOR, 63132, L"Operator", L"bold", L"" },
{ SCE_P_STRING, 63211, L"String double quoted", L"fore:#FF8000", L"" },
{ SCE_P_CHARACTER, 63212, L"String single quoted", L"fore:#FF8000", L"" },
{ SCE_P_STRINGEOL, 63211, L"String not closed", L"fore:#FF8000", L"" },
{ SCE_P_TRIPLEDOUBLE, 63244, L"String triple double quotes", L"fore:#FF8000", L"" },
{ SCE_P_TRIPLE, 63245, L"String triple single quotes", L"fore:#FF8000", L"" },
{ SCE_P_CLASSNAME, 63246, L"Class name", L"fore:#0000FF;bold", L"" },
{ SCE_P_DEFNAME,63247, L"Function name", L"fore:#007F7F;bold", L"" },
{ -1, 00000, L"", L"", L"" } } };
6. While still in src/Styles.c add the Ruby Lex to the pLexArray:
Code:
...
&lexBAT,
&lexDIFF,
&lexRUBY
7. Edit src/Styles.h and change number of Lexs from 22 to 23:
Code:
#define NUMLEXERS 23
8. Add the Scintilla Ruby Lex to the project: Right click scintilla/src in the solution explorer and click Add->Existing Item, browse to the scintilla/src folder and add LexRuby.cxx.
9. Compile and Enjoy!!
If you wanted to add support for other languages, it'd be almost the same process, just include the LexWantedLang.cxx(setp 8) in your project and add the language info NotePad2 needs. The important thing to remember is to update NUMLEXERS(step 7) and to keep track of the language number(or ID, I don't know what the proper name is):
Code:
EDITLEXER lexRUBY = { SCLEX_RUBY, 63022, L"Ruby", L"rb;ruby", L"", &KeyWords_RUBY, {
{ STYLE_DEFAULT, 63126, L"Default", L"", L"" },
Another thing to keep in mind is the Style ID(again, not sure if that's the right name):
Code:
{ SCE_P_WORD, 63128, L"Keyword", L"fore:#00007F;bold", L"" },
I'll admit I have no idea what so ever as to what exactly these numbers do, but they're a required parameter and change depending on what you're declaring. you should be able to search through the existing languages and find the code you need.
Lastly, if you have 2 style definitions(more made up terminology) you should combine them with one statement(it won't cause errors to have two separate ones, but this was probably done for a reason):
Code:
{ MULTI_STYLE(SCE_POWERSHELL_STRING,SCE_POWERSHELL_CHARACTER,0,0), 63131, L"String", L"fore:#008000", L"" },
Hope this helps out people who love NotePad2 and wish to extend it.
-
October 15th, 2009, 06:47 PM
#2
Re: How to compile NotePad2 and add custom syntax highlighting
Do you have a question or is this an fyi?
-
October 16th, 2009, 04:30 AM
#3
Re: How to compile NotePad2 and add custom syntax highlighting
 Originally Posted by Arjay
Do you have a question or is this an fyi?
Just an FYI, I thought someone might find it useful. If there's a more appropriate place for this mini howto, please move it there.
-
October 16th, 2009, 07:07 AM
#4
Re: How to compile NotePad2 and add custom syntax highlighting
Maybe you can extend this a little and submit it as an article on the main site area.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|