Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Comment/Uncomment plus other Smart Editing for alternative languages
dmoore:
I'd like to make the comment/uncomment commands on the editor menu use lexer specific comments rather than "//"
the current code for uncomment is:
--- Code: --- while( startLine <= endLine )
{
// For each line: if it is commented, uncomment.
wxString strLine = stc->GetLine( startLine );
wxString Comment = _T("//");
int commentPos = strLine.Strip( wxString::leading ).Find( Comment );
if( commentPos == 0 )
{ // we know the comment is there (maybe preceded by white space)
int Pos = strLine.Find(Comment);
int start = stc->PositionFromLine( startLine ) + Pos;
int end = start + Comment.Length();
stc->SetTargetStart( start );
stc->SetTargetEnd( end );
stc->ReplaceTarget( wxEmptyString );
}
++startLine;
} // end while
--- End code ---
it looks like this is just a simple matter of replacing Comment= _T("//") with a lookup to the Scintilla lexer...
is there an easy way to grab the comment token(s) from the currently active Scintilla lexer?
In addition, I'd like to add some "smart editor" features when editing python code. Most important of these is to indent one level deeper after pressing Return/Enter on a line ending in ":" . Can someone recommend an easy way to do this/some related code to look at? Should I do it in a separate plugin (i.e. in my python plugin) or in the core C::B code?
Ceniza:
There's a method to get the current file's contents + the style/token of each character used by the current lexer, but you'll need to find which one applies to comments. If you think that's of any help check the Exporter plugin.
dmoore:
thanks. I'll take a look.
dmoore:
unless I'm mistaken, there is no consistent labelling of comment styles/tokens in scintilla for all languages. so to query scintilla for the comment token would seem to require different code for each language supported by cb, which is no better than simply hard coding the comment token for each language...
this leaves two alternatives:
1. add a comment (or "CommentBlock") property to each lexer property file (i.e. the xml files in CodeBlocks\share\CodeBlocks\lexers) containing the token or tokens. (Question: are these xml files available from cb's Config Manager?)
2. write a function that returns a hard coded token for each supported lexer, or nothing if the current language doesn't hasn't been hard coded (I've implemented this)
obviously 1 is better than 2, but 2 is still better than the current code... any thoughts?
also, can someone guide me on the preferred way to intercept keyboard input in the cb editor? As I said in my first post, I want to auto-indent python code when the user presses enter on a line ending with ":".
mandrav:
--- Quote ---also, can someone guide me on the preferred way to intercept keyboard input in the cb editor? As I said in my first post, I want to auto-indent python code when the user presses enter on a line ending with ":".
--- End quote ---
It all happens in cbEditor::OnEditorCharAdded() (cbeditor.cpp:2271). If you want to patch C::B for this, that's the code you should be hacking.
If you want to process these events outside C::B, see the documentation in the EditorHooks namespace (editor_hooks.h).
Navigation
[0] Message Index
[#] Next page
Go to full version