diff --git a/doc/source/index.rst b/doc/source/index.rst index 785e618..c8c129e 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -302,7 +302,9 @@ created via `ein:notebook-create-checkpoint`. :replace: s/C-c TAB/C-c C-i/ s/C-c RET/C-c C-m/ -.. el:function:: ein:worksheet-execute-all-cell +.. el:function:: ein:worksheet-execute-all-cells +.. el:function:: ein:worksheet-execute-all-cells-above +.. el:function:: ein:worksheet-execute-all-cells-below .. el:function:: ein:worksheet-delete-cell .. el:function:: ein:junk-rename .. el:function:: ein:iexec-mode diff --git a/features/execute-all-cells.feature b/features/execute-all-cells.feature new file mode 100644 index 0000000..3f170ed --- /dev/null +++ b/features/execute-all-cells.feature @@ -0,0 +1,52 @@ +@execute-all-cells +Scenario: Execute all cells + Given new python notebook + And I type "2 ** 3" + And I press "C-c C-b" + And I type "2 ** 4" + And I press "C-c C-b" + And I type "2 ** 5" + And I press "C-c C-b" + And I type "2 ** 6" + When I call "ein:worksheet-execute-all-cells" + And I wait 1 second + Then I should see "8" + And I should see "16" + And I should see "32" + And I should see "64" + +@execute-all-cells +Scenario: Execute all cells above + Given new python notebook + And I type "2 ** 3" + And I press "C-c C-b" + And I type "2 ** 4" + And I press "C-c C-b" + And I type "2 ** 5" + And I press "C-c C-b" + And I type "2 ** 6" + And I press "C-c C-p" + When I call "ein:worksheet-execute-all-cells-above" + And I wait 1 second + Then I should see "8" + And I should see "16" + And I should not see "32" + And I should not see "64" + +@execute-all-cells +Scenario: Execute all cells below + Given new python notebook + And I type "2 ** 3" + And I press "C-c C-b" + And I type "2 ** 4" + And I press "C-c C-b" + And I type "2 ** 5" + And I press "C-c C-b" + And I type "2 ** 6" + And I press "C-c C-p" + When I call "ein:worksheet-execute-all-cells-below" + And I wait 1 second + Then I should not see "8" + And I should not see "16" + And I should see "32" + And I should see "64" diff --git a/lisp/ein-notebook.el b/lisp/ein-notebook.el index 3897488..7a4c2c8 100644 --- a/lisp/ein-notebook.el +++ b/lisp/ein-notebook.el @@ -1276,8 +1276,12 @@ Tried add-function: the &rest from :around is an emacs-25 compilation issue." ("Execute cell and insert below" ein:worksheet-execute-cell-and-insert-below :active (ein:worksheet-at-codecell-p)) - ("Execute all" - ein:worksheet-execute-all-cell) + ("Execute all cells" + ein:worksheet-execute-all-cells) + ("Execute all cells above" + ein:worksheet-execute-all-cells-above) + ("Execute all cells below" + ein:worksheet-execute-all-cells-below) )) "---" ,@(ein:generate-menu diff --git a/lisp/ein-worksheet.el b/lisp/ein-worksheet.el index 4c65347..b0bc439 100644 --- a/lisp/ein-worksheet.el +++ b/lisp/ein-worksheet.el @@ -1053,11 +1053,39 @@ cell bellow." (ein:worksheet-get-current-cell))) (ein:worksheet-execute-cell-and-goto-next ws cell t)) -(defun ein:worksheet-execute-all-cell (ws) +;;; TODO add version number here before creating a new release +(define-obsolete-function-alias + 'ein:worksheet-execute-all-cell + 'ein:worksheet-execute-all-cells) + +(defun ein:worksheet-execute-all-cells (ws) "Execute all cells in the current worksheet buffer." (interactive (list (ein:worksheet--get-ws-or-error))) - (mapc #'ein:cell-execute - (seq-filter #'ein:codecell-p (ein:worksheet-get-cells ws)))) + (cl-loop for c in (ein:worksheet-get-cells ws) + when (ein:codecell-p c) + do (ein:cell-execute c))) + +(defun ein:worksheet-execute-all-cells-above (ws) + "Execute all cells above the current cell (exclusively) in the +current worksheet buffer." + (interactive (list (ein:worksheet--get-ws-or-error))) + (cl-loop with curr-cell-id = (ein:cell-id (ein:worksheet-get-current-cell)) + for c in (ein:worksheet-get-cells ws) + until (equal (ein:cell-id c) curr-cell-id) + when (ein:codecell-p c) + do (ein:cell-execute c))) + +(defun ein:worksheet-execute-all-cells-below (ws) + "Execute all cells below the current cell (inclusively) in the +current worksheet buffer." + (interactive (list (ein:worksheet--get-ws-or-error))) + (cl-loop with curr-cell-id = (ein:cell-id (ein:worksheet-get-current-cell)) + and curr-cell-reached? + for c in (ein:worksheet-get-cells ws) + when (and (not curr-cell-reached?) (equal (ein:cell-id c) curr-cell-id)) + do (setq curr-cell-reached? t) + when (and curr-cell-reached? (ein:codecell-p c)) + do (ein:cell-execute c))) ;;; Metadata