Mercurial > octave
diff libgui/src/m-editor/octave-qscintilla.cc @ 23236:4cd5f975d26c
automatically add a comment string when line breaking in line comments
* file-editor-tab.cc (handle_char_added): insert a comment string at the
beginning of a new line when breaking a comment line
* octave-qscintilla.cc: include headers of the used qscintilla lexers;
(get_style): new function providing the style at specific/current position;
(is_style_comment): new function for detecting lin or block comment styles;
* octave-qscintilla.h: new functions get_style and is_style_comment, new
enum for return values of is_style_comment
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sat, 25 Feb 2017 21:13:35 +0100 |
parents | aaf20024db6f |
children | c763214a8260 |
line wrap: on
line diff
--- a/libgui/src/m-editor/octave-qscintilla.cc Sat Feb 25 20:54:02 2017 +0100 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sat Feb 25 21:13:35 2017 +0100 @@ -28,13 +28,21 @@ #if defined (HAVE_QSCINTILLA) +#include <Qsci/qscilexer.h> + #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) # define HAVE_LEXER_OCTAVE 1 +# include <Qsci/qscilexeroctave.h> #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H) # define HAVE_LEXER_MATLAB 1 +# include <Qsci/qscilexermatlab.h> #endif +#include <Qsci/qscilexercpp.h> +#include <Qsci/qscilexerbash.h> +#include <Qsci/qscilexerperl.h> +#include <Qsci/qscilexerbatch.h> +#include <Qsci/qscilexerdiff.h> -#include <Qsci/qscilexer.h> #include <Qsci/qscicommandset.h> #include <QShortcut> #include <QMessageBox> @@ -400,6 +408,66 @@ clearIndicatorRange (0, 0, end_line, end_col, indicator_style); } +// provide the style at a specific position +int +octave_qscintilla::get_style (int pos) +{ + int position; + if (pos < 0) + // The positition has to be reduced by 2 for getting the real style (?) + position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2; + else + position = pos; + + return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position); +} + +// Is a specific cursor position in a line or block comment? +int +octave_qscintilla::is_style_comment (int pos) +{ + int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER); + int style = get_style (pos); + + switch (lexer) + { + case SCLEX_CPP: + return (ST_LINE_COMMENT * ( + style == QsciLexerCPP::CommentLine + || style == QsciLexerCPP::CommentLineDoc) + + ST_BLOCK_COMMENT * ( + style == QsciLexerCPP::Comment + || style == QsciLexerCPP::CommentDoc + || style == QsciLexerCPP::CommentDocKeyword + || style == QsciLexerCPP::CommentDocKeywordError) + ); + +#if defined (HAVE_LEXER_MATLAB) + case SCLEX_MATLAB: + return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment)); +#endif +#if defined (HAVE_LEXER_OCTAVE) + case SCLEX_OCTAVE: + return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment)); +#endif + + case SCLEX_PERL: + return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment)); + + case SCLEX_BATCH: + return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment)); + + case SCLEX_DIFF: + return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment)); + + case SCLEX_BASH: + return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment)); + + } + + return ST_NONE; +} + // Function returning the true cursor position where the tab length // is taken into account. void