March 13, 2003
This week I have been mostly working on:
User-defined syntax highlighting
This allows any user to define a simple language syntax without writing a scintilla lexer. The code basically implements a highly generic scintilla lexer in an external lexer dll. When this dll is loaded it looks for user syntax files and loads the settings from each into an instance of this generic lexer (note: this may be optimised in the future to only load on request for speed reasons).
The syntax for the languaged is defined using really simple XML, and therefore the same file can contain the elements required to make it a Scheme definition for PN2. One file defines both the syntax and the user-controllable elements such as colouring options and keywords.
Scintilla hotspot support
This allows certain styles in Scintilla to be marked as "hot spots". These spots are reactive - when the user moves the mouse over them the cursor changes to indicate that there is an associated action possible. When the user clicks (or double-clicks) a special "hot spot clicked" notification is sent to the container.
This will be used in Programmers Notepad 2 to allow clickable URLs and also in matching tools output such as compiler messages.
Header-switch for C++
Posted by Simon at March 13, 2003 02:07 PM
When using the cpp scheme, my local copy of PN2 now allows you to switch from a header to an implementation file or vice versa using a key combination.
I haven't entirely decided yet if I've implemented it the correct way, different file types will require different special functionality and I don't want the code to get really messy.
Cool stuff. Header switching would be very useful.
I don't know if the Scintilla engine or your lexers support this, but would it be possible to implement an auto-complete feature, like in MS or Borland compilers. It would require maintaining a list of all identifiers in the current document, and responding to some hotkey (e.g. Ctrl+space) to popup a list of words that begin with the already typed characters.
This will be implemented at some stage. It is not supported directly by scintilla, but SciTE - scintilla's demonstration editor - includes this feature.
Will the header switching also work in case the header file is not yet open in the editor? Say I've openend file.cpp for editing, and hit the key combination; will PN2 open file.h for me?
Also, you say: "I haven't entirely decided yet if I've implemented it the correct way". Couldn't you just (let the user) define a list of extension pairs which can be switched between? Like (.h,.c), (.h,.cpp), (.h,.rc), (.pas,.dfm). Then if file.ext is open in the editor, you should look for a pair that contains .ext, and either or open activate the companion file.
Currently the code works with the following mappings:
.h or .hpp or .hh
.cxx or .c. or .cpp or .cc
and yes the code will open the file if it's not already open (as long as it is in the same filesystem location as the current file). In fact, in the current version of the code it always opens the other file - even if it's already open. This will be fixed with "already open" code.
I will think about allowing the user to define extensions to swap between - while this is good customisability it adds a significant amount of complexity to a very simple feature.
Although there may not be an awful lot of languages that have file pairs, it would be very nice if PN2 would allow the user to customize them. For instance, for my PhD research I do a lot of programming in Ox (a C++ based matrix programming language), and there the pair is (.ox,.h): a rather uncommon combination that is unlikely to be hard-coded in PN2....
Do you have any C++ code that shows how to use the hotspots I cannot seem to get them to work in my code. I'm using the code below:
public void AddHotspot(int start,int end)
int li_EndStyle = EndStyled;
SetStyling((end - start ) + 1, 20);