Mercurial > octave
changeset 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 | 8bba52bd04d2 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/octave-qscintilla.cc libgui/src/m-editor/octave-qscintilla.h |
diffstat | 4 files changed, 52 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Sun Jun 25 08:56:45 2017 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Jun 25 16:40:30 2017 +0200 @@ -2682,7 +2682,7 @@ { _lines_changed = false; if (_is_octave_file && _smart_indent && line == _line+1 && col < _col) - do_smart_indent (); + _edit_area->smart_indent (_line,_col); } _line = line; @@ -2831,54 +2831,6 @@ } } -void -file_editor_tab::do_smart_indent () -{ - QString prev_line = _edit_area->text (_line); - - QRegExp bkey = QRegExp ("^[\t ]*(if|for|while|switch|case|do|function" - "|unwind_protect|unwind_protect_cleanup|try)" - "[\n\t #%]"); - if (prev_line.contains (bkey)) - { - _edit_area->indent (_line+1); - _edit_area->setCursorPosition (_line+1, - _edit_area->indentation (_line) + - _edit_area->indentationWidth ()); - return; - } - - QRegExp mkey = QRegExp ("^[\t ]*(else|elseif|catch)[\t #%\n]"); - if (prev_line.contains (mkey)) - { - int prev_ind = _edit_area->indentation (_line-1); - int act_ind = _edit_area->indentation (_line); - - if (prev_ind == act_ind) - _edit_area->unindent (_line); - else if (prev_ind > act_ind) - { - _edit_area->setIndentation (_line+1, prev_ind); - _edit_area->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 (prev_line.contains (ekey)) - { - if (_edit_area->indentation (_line-1) <= _edit_area->indentation (_line)) - { - _edit_area->unindent (_line+1); - _edit_area->unindent (_line); - _edit_area->setCursorPosition (_line+1, - _edit_area->indentation (_line)); - } - return; - } - -} QString file_editor_tab::get_function_name ()
--- a/libgui/src/m-editor/file-editor-tab.h Sun Jun 25 08:56:45 2017 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Jun 25 16:40:30 2017 +0200 @@ -259,8 +259,6 @@ void add_octave_apis (octave_value_list key_ovl); QString get_function_name (); - void do_smart_indent (void); - QsciScintilla::EolMode detect_eol_mode (); void update_eol_indicator ();
--- 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)
--- a/libgui/src/m-editor/octave-qscintilla.h Sun Jun 25 08:56:45 2017 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.h Sun Jun 25 16:40:30 2017 +0200 @@ -58,6 +58,7 @@ int get_style (int pos = -1); int is_style_comment (int pos = -1); void set_auto_endif (int ai) { _auto_endif = ai; } + void smart_indent (int line, int col); signals: