Mercurial > octave
diff libgui/src/m-editor/octave-qscintilla.cc @ 23689:b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
* file-editor-tab.cc (handle_cursor_moved): call smart_indent of _edit_area
instead former local method do_smart_indent;
(do_smart_indent) removed here
* file-editor-tab.h: removed do_smart_indent
* octave-qscintilla.cc (smart_indent): moved do_smart_indent to here, with
previous line and col as parameter
* octave-qscintilla.h: new method smart_indent
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sun, 25 Jun 2017 16:40:30 +0200 |
parents | cb36684b7a33 |
children | 3dccf8325377 |
line wrap: on
line diff
--- a/libgui/src/m-editor/octave-qscintilla.cc Sun Jun 25 08:56:45 2017 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sun Jun 25 16:40:30 2017 +0200 @@ -597,6 +597,56 @@ QsciScintilla::keyPressEvent (e); } +// Do smart indendation after if, for, ... +void +octave_qscintilla::smart_indent (int line, int col) +{ + QString prevline = text (line); + + QRegExp bkey = QRegExp ("^[\t ]*(if|for|while|switch|case|do|function" + "|unwind_protect|unwind_protect_cleanup|try)" + "[\n\t #%]"); + if (prevline.contains (bkey)) + { + indent (line+1); + setCursorPosition (line+1, + indentation (line) + + indentationWidth ()); + return; + } + + QRegExp mkey = QRegExp ("^[\t ]*(else|elseif|catch)[\t #%\n]"); + if (prevline.contains (mkey)) + { + int prev_ind = indentation (line-1); + int act_ind = indentation (line); + + if (prev_ind == act_ind) + unindent (line); + else if (prev_ind > act_ind) + { + setIndentation (line+1, prev_ind); + setCursorPosition (line+1, prev_ind); + } + return; + } + + QRegExp ekey = QRegExp ("^[\t ]*(end|endif|endfor|endwhile|until|endfunction" + "|end_try_catch|end_unwind_protext)[\t #%\n(;]"); + if (prevline.contains (ekey)) + { + if (indentation (line-1) <= indentation (line)) + { + unindent (line+1); + unindent (line); + setCursorPosition (line+1, + indentation (line)); + } + return; + } + +} + // Is a specific cursor position in a line or block comment? int octave_qscintilla::is_style_comment (int pos)