diff -rupN orig/libgui/src/gui-preferences-sc.cc new/libgui/src/gui-preferences-sc.cc --- orig/libgui/src/gui-preferences-sc.cc 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/gui-preferences-sc.cc 2024-11-15 00:20:15.654854737 +0100 @@ -205,6 +205,7 @@ sc_pref sc_edit_debug_remove_breakpoints // run sc_pref sc_edit_run_run_file (QCoreApplication::translate ("shortcuts", "Run File"), sc_edit_run + ":run_file", OCTAVE_QT_KEYCOMBINATION (PRE, Qt::Key_F5)); sc_pref sc_edit_run_run_selection (QCoreApplication::translate ("shortcuts", "Run Selection"), sc_edit_run + ":run_selection", OCTAVE_QT_KEYCOMBINATION (PRE, Qt::Key_F9)); +sc_pref sc_edit_run_run_cell (QCoreApplication::translate ("shortcuts", "Run Cell"), sc_edit_run + ":run_cell", OCTAVE_QT_KEYCOMBINATION (CTRL, Qt::Key_Return)); // help sc_pref sc_edit_help_help_keyword (QCoreApplication::translate ("shortcuts", "Help on Keyword"), sc_edit_help + ":help_keyword", QKeySequence::HelpContents); diff -rupN orig/libgui/src/gui-preferences-sc.h new/libgui/src/gui-preferences-sc.h --- orig/libgui/src/gui-preferences-sc.h 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/gui-preferences-sc.h 2024-11-15 00:20:20.791036421 +0100 @@ -255,6 +255,7 @@ extern sc_pref sc_edit_debug_remove_brea const QString sc_edit_run ("editor_run"); extern sc_pref sc_edit_run_run_file; extern sc_pref sc_edit_run_run_selection; +extern sc_pref sc_edit_run_run_cell; // help const QString sc_edit_help ("editor_help"); diff -rupN orig/libgui/src/m-editor/file-editor-tab.cc new/libgui/src/m-editor/file-editor-tab.cc --- orig/libgui/src/m-editor/file-editor-tab.cc 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/file-editor-tab.cc 2024-11-15 00:20:29.968361055 +0100 @@ -1111,6 +1111,14 @@ void file_editor_tab::context_run (const m_edit_area->context_run (); } +void file_editor_tab::cell_run (const QWidget *ID) +{ + if (ID != this) + return; + + m_edit_area->cell_run (); +} + void file_editor_tab::toggle_bookmark (const QWidget *ID) { if (ID != this) diff -rupN orig/libgui/src/m-editor/file-editor-tab.h new/libgui/src/m-editor/file-editor-tab.h --- orig/libgui/src/m-editor/file-editor-tab.h 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/file-editor-tab.h 2024-11-15 00:20:40.896747630 +0100 @@ -152,6 +152,7 @@ public slots: void print_file (const QWidget *ID); void run_file (const QWidget *ID, bool step_into = false); void context_run (const QWidget *ID); + void cell_run (const QWidget *ID); void toggle_bookmark (const QWidget *ID); void next_bookmark (const QWidget *ID); void previous_bookmark (const QWidget *ID); diff -rupN orig/libgui/src/m-editor/file-editor.cc new/libgui/src/m-editor/file-editor.cc --- orig/libgui/src/m-editor/file-editor.cc 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/file-editor.cc 2024-11-15 00:22:45.957163824 +0100 @@ -725,6 +725,11 @@ void file_editor::request_context_run (b emit fetab_context_run (m_tab_widget->currentWidget ()); } +void file_editor::request_cell_run (bool) +{ + emit fetab_cell_run (m_tab_widget->currentWidget ()); +} + void file_editor::request_toggle_bookmark (bool) { emit fetab_toggle_bookmark (m_tab_widget->currentWidget ()); @@ -1473,6 +1478,7 @@ void file_editor::set_shortcuts () // Run menu settings.set_shortcut (m_run_action, sc_edit_run_run_file); + settings.set_shortcut (m_run_cell_action, sc_edit_run_run_cell); settings.set_shortcut (m_run_selection_action, sc_edit_run_run_selection); // Help menu @@ -2309,6 +2315,12 @@ void file_editor::construct () tr ("Save File and Run/Continue"), SLOT (request_run_file (bool))); + m_run_cell_action + = add_action (_run_menu, + tr ("Run &Cell"), + SLOT (request_cell_run (bool))); + m_run_cell_action->setEnabled (true); + m_run_selection_action = add_action (_run_menu, tr ("Run &Selection"), @@ -2542,6 +2554,8 @@ file_editor::make_file_editor_tab (const connect (this, &file_editor::fetab_context_edit, f, &file_editor_tab::context_edit); + connect (this, &file_editor::fetab_cell_run, f, &file_editor_tab::cell_run); + connect (this, QOverload::of (&file_editor::fetab_save_file), f, QOverload::of (&file_editor_tab::save_file)); diff -rupN orig/libgui/src/m-editor/file-editor.h new/libgui/src/m-editor/file-editor.h --- orig/libgui/src/m-editor/file-editor.h 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/file-editor.h 2024-11-15 00:21:04.633587283 +0100 @@ -142,6 +142,7 @@ signals: void fetab_print_file (const QWidget *ID); void fetab_run_file (const QWidget *ID, bool step_into = false); void fetab_context_run (const QWidget *ID); + void fetab_cell_run (const QWidget *ID); void fetab_toggle_bookmark (const QWidget *ID); void fetab_next_bookmark (const QWidget *ID); void fetab_previous_bookmark (const QWidget *ID); @@ -223,6 +224,7 @@ public slots: void request_save_file_as (bool); void request_run_file (bool); void request_step_into_file (); + void request_cell_run (bool); void request_context_run (bool); void request_toggle_bookmark (bool); void request_next_bookmark (bool); @@ -439,6 +441,7 @@ private: QAction *m_remove_bookmark_action; QAction *m_print_action; + QAction *m_run_cell_action; QAction *m_run_action; QAction *m_run_selection_action; diff -rupN orig/libgui/src/m-editor/octave-qscintilla.cc new/libgui/src/m-editor/octave-qscintilla.cc --- orig/libgui/src/m-editor/octave-qscintilla.cc 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/octave-qscintilla.cc 2024-11-15 00:22:17.211150591 +0100 @@ -371,6 +371,38 @@ void octave_qscintilla::context_run () } } +void octave_qscintilla::cell_run (void) +{ + long current_position = SendScintilla(SCI_GETCURRENTPOS); + + long cell_start, cell_end; + + bool found = findFirst("%%.*", true, true, false, false, false, -1, -1, true, false, false); + if(found) + cell_start = SendScintilla(SCI_GETSELECTIONEND); + else + cell_start = 0; + + found = findFirst("%%", false, true, false, false, true, -1, -1, true, false, false); + if(found) + cell_end = SendScintilla(SCI_GETSELECTIONSTART); + else + cell_end = SendScintilla(SCI_POSITIONFROMLINE, SendScintilla(SCI_GETLINECOUNT)); + + SendScintilla(SCI_SETSEL, cell_start, cell_end); + + if (hasSelectedText ()) + { + contextmenu_run (true); + + emit interpreter_event + ([] (interpreter&) + { command_editor::erase_empty_line (false); }); + } + + SendScintilla(SCI_GOTOPOS, current_position ); +} + void octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos) { @@ -676,7 +708,7 @@ void octave_qscintilla::smart_indent_lin "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$"}; QRegularExpression - begin_block_regexp {"^[\t ]*(?:if|elseif|else" + begin_cell_regexp {"^[\t ]*(?:if|elseif|else" "|for|while|do|parfor" "|switch|case|otherwise" "|function" @@ -685,12 +717,12 @@ void octave_qscintilla::smart_indent_lin "[\r\n\t #%]"}; QRegularExpression - mid_block_regexp {"^[\t ]*(?:elseif|else" + mid_cell_regexp {"^[\t ]*(?:elseif|else" "|unwind_protect_cleanup|catch)" "[\r\n\t #%]"}; QRegularExpression - end_block_regexp {"^[\t ]*(?:end" + end_cell_regexp {"^[\t ]*(?:end" "|end(for|function|if|parfor|switch|while" "|classdef|enumeration|events|methods|properties)" "|end_(try_catch|unwind_protect)" @@ -698,7 +730,7 @@ void octave_qscintilla::smart_indent_lin "[\r\n\t #%]"}; QRegularExpression - case_block_regexp {"^[\t ]*(?:case|otherwise)" + case_cell_regexp {"^[\t ]*(?:case|otherwise)" "[\r\n\t #%]"}; QRegularExpressionMatch match; @@ -721,7 +753,7 @@ void octave_qscintilla::smart_indent_lin indent_column = indentation (line); - match = begin_block_regexp.match (line_text); + match = begin_cell_regexp.match (line_text); if (match.hasMatch ()) { indent_column += indent_increment; @@ -741,7 +773,7 @@ void octave_qscintilla::smart_indent_lin { QString line_text = text (line); - match = end_block_regexp.match (line_text); + match = end_cell_regexp.match (line_text); if (match.hasMatch ()) { indent_column -= indent_increment; @@ -754,14 +786,14 @@ void octave_qscintilla::smart_indent_lin } } - match = mid_block_regexp.match (line_text); + match = mid_cell_regexp.match (line_text); if (match.hasMatch ()) indent_column -= indent_increment; - match = case_block_regexp.match (line_text); + match = case_cell_regexp.match (line_text); if (match.hasMatch ()) { - match = case_block_regexp.match (prev_line); + match = case_cell_regexp.match (prev_line); if (! match.hasMatch () && ! prev_line.contains ("switch")) indent_column -= indent_increment; @@ -770,7 +802,7 @@ void octave_qscintilla::smart_indent_lin setIndentation (line, indent_column); - match = begin_block_regexp.match (line_text); + match = begin_cell_regexp.match (line_text); if (match.hasMatch ()) { // Check for existing end statement in the same line @@ -886,7 +918,7 @@ void octave_qscintilla::contextmenu_run hist += line_history + "\n"; } - octave_stdout << hist.toStdString (); + //octave_stdout << hist.toStdString (); // Create tmp file with the code to be executed by the interpreter QPointer tmp_file = create_tmp_file ("m", code); diff -rupN orig/libgui/src/m-editor/octave-qscintilla.h new/libgui/src/m-editor/octave-qscintilla.h --- orig/libgui/src/m-editor/octave-qscintilla.h 2024-06-01 17:05:08.000000000 +0200 +++ new/libgui/src/m-editor/octave-qscintilla.h 2024-11-15 00:22:25.172431209 +0100 @@ -62,6 +62,7 @@ public: void context_help_doc (bool); void context_edit (); void context_run (); + void cell_run (void); void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); bool get_actual_word (); void clear_selection_markers ();