Add commands to execute all cells above/below current one

This commit is contained in:
Tomasz Mieszkowski 2019-11-10 13:28:17 +01:00 committed by dickmao
parent f842afc4df
commit b2267afcfa
4 changed files with 92 additions and 6 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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