# HG changeset patch # User Torsten # Date 1370193469 -7200 # Node ID 0f6f14e3ac6a76bb6a6d99c1d59e93b9b3728a02 # Parent 0495339998f8c4bbd53050f6f2ec5f4ad6f833f6 commenting selected lines in the editor uses comment string depending on lexer * file-editor-tab.h: new function comment_string * file-editor-tab.cc(comment_string): returns comment string depending on lexer name (do_comment_selected_text): get actual lexer and its comment string diff -r 0495339998f8 -r 0f6f14e3ac6a libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sun Jun 02 11:10:16 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Jun 02 19:17:49 2013 +0200 @@ -323,6 +323,21 @@ _lexer_apis->savePrepared (_prep_apis_file); } +QString +file_editor_tab::comment_string (const QString& lexer) +{ + if (lexer == "octave" || lexer == "matlab") + return QString("%"); + else if (lexer == "perl" || lexer == "bash" || lexer == "diff") + return QString("#"); + else if (lexer == "cpp") + return ("//"); + else if (lexer == "batch") + return ("REM "); + else + return ("%"); // should never happen +} + // slot for fetab_set_focus: sets the focus to the current edit area void file_editor_tab::set_focus (const QWidget *ID) @@ -714,6 +729,8 @@ int lineFrom, lineTo, colFrom, colTo; _edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + QString comment_str = comment_string (_edit_area->lexer ()->lexer ()); + if (colTo == 0) // the beginning of last line is not selected lineTo--; // stop at line above @@ -722,13 +739,13 @@ for (int i = lineFrom; i <= lineTo; i++) { if (comment) - _edit_area->insertAt ("%", i, 0); + _edit_area->insertAt (comment_str, i, 0); else { QString line (_edit_area->text (i)); - if (line.startsWith ("%")) + if (line.startsWith (comment_str)) { - _edit_area->setSelection (i, 0, i, 1); + _edit_area->setSelection (i, 0, i, comment_str.length ()); _edit_area->removeSelectedText (); } } diff -r 0495339998f8 -r 0f6f14e3ac6a libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sun Jun 02 11:10:16 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Jun 02 19:17:49 2013 +0200 @@ -176,6 +176,7 @@ int check_file_modified (); void do_comment_selected_text (bool comment); + QString comment_string (const QString&); void add_breakpoint_callback (const bp_info& info); void remove_breakpoint_callback (const bp_info& info);