diff --git a/ein-notebook.el b/ein-notebook.el index 54eb088..c03c81d 100644 --- a/ein-notebook.el +++ b/ein-notebook.el @@ -364,19 +364,30 @@ when the prefix argument is given." ;;; Cell selection. -(defun ein:notebook-goto-next-cell () - (interactive) - (ein:notebook-with-cell nil - (ein:aif (ein:cell-next cell) +(defun ein:notebook-goto-input (ewoc-node up) + (let* ((ewoc-data (ewoc-data ewoc-node)) + (cell (ein:$node-data ewoc-data)) + (path (ein:$node-path ewoc-data)) + (element (nth 1 path))) + (ein:aif + (if (memql element (if up '(input output footer) '(prompt))) + cell + (funcall (if up #'ein:cell-prev #'ein:cell-next) cell)) (ein:cell-goto it) - (ein:log 'warn "No next cell")))) + (ein:log 'warn "No %s input!" (if up "previous" "next"))))) -(defun ein:notebook-goto-prev-cell () +(defun ein:notebook-goto-input-in-notebook-buffer (up) + (ein:aif (ein:notebook-get-current-ewoc-node) + (ein:notebook-goto-input it up) + (ein:log 'warn "Not in notebook buffer!"))) + +(defun ein:notebook-goto-next-input-command () (interactive) - (ein:notebook-with-cell nil - (ein:aif (ein:cell-prev cell) - (ein:cell-goto it) - (ein:log 'warn "No previous cell")))) + (ein:notebook-goto-input-in-notebook-buffer nil)) + +(defun ein:notebook-goto-prev-input-command () + (interactive) + (ein:notebook-goto-input-in-notebook-buffer t)) ;;; Cell movement @@ -809,8 +820,8 @@ NAME is any non-empty string that does not contain '/' or '\\'." (define-key map "\C-c\C-b" 'ein:notebook-insert-cell-below-command) (define-key map "\C-c\C-t" 'ein:notebook-toggle-cell-type) (define-key map "\C-c\C-s" 'ein:notebook-split-cell-at-point) - (define-key map "\C-c\C-n" 'ein:notebook-goto-next-cell) - (define-key map "\C-c\C-p" 'ein:notebook-goto-prev-cell) + (define-key map "\C-c\C-n" 'ein:notebook-goto-next-input-command) + (define-key map "\C-c\C-p" 'ein:notebook-goto-prev-input-command) (define-key map (kbd "\C-c ") 'ein:notebook-move-cell-up-command) (define-key map (kbd "\C-c ") 'ein:notebook-move-cell-down-command) (define-key map "\C-c\C-f" 'ein:notebook-request-tool-tip-command) diff --git a/ein-smartrep.el b/ein-smartrep.el index 7a1bf9f..182e146 100644 --- a/ein-smartrep.el +++ b/ein-smartrep.el @@ -37,8 +37,8 @@ ("C-d" . ein:notebook-delete-cell-command) ("C-a" . ein:notebook-insert-cell-above-command) ("C-b" . ein:notebook-insert-cell-below-command) - ("C-n" . ein:notebook-goto-next-cell) - ("C-p" . ein:notebook-goto-prev-cell) + ("C-n" . ein:notebook-goto-next-input-command) + ("C-p" . ein:notebook-goto-prev-input-command) ("" . ein:notebook-move-cell-up-command) ("" . ein:notebook-move-cell-down-command) ))) diff --git a/tests/test-ein-notebook.el b/tests/test-ein-notebook.el index b5a539a..ac37005 100644 --- a/tests/test-ein-notebook.el +++ b/tests/test-ein-notebook.el @@ -186,12 +186,12 @@ (ein:cell-goto cell) (should (equal (ein:cell-get-text cell) "text"))) ;; check the "head" cell - (ein:notebook-goto-prev-cell) + (ein:notebook-goto-prev-input-command) (let ((cell (ein:notebook-get-current-cell))) (ein:cell-goto cell) (should (equal (ein:cell-get-text cell) "some\n"))))) -(ert-deftest ein:notebook-goto-next-cell-simple () +(ert-deftest ein:notebook-goto-next-input-command-simple () (with-current-buffer (eintest:notebook-make-empty) (loop for i downfrom 2 to 0 do (ein:notebook-insert-cell-above-command) @@ -201,10 +201,10 @@ (loop for i from 0 below 2 do (beginning-of-line) ; This is required, I need to check why do (should (looking-at (format "Cell %s" i))) - do (ein:notebook-goto-next-cell) + do (ein:notebook-goto-next-input-command) do (should (looking-at (format "Cell %s" (1+ i))))))) -(ert-deftest ein:notebook-goto-prev-cell-simple () +(ert-deftest ein:notebook-goto-prev-input-command-simple () (with-current-buffer (eintest:notebook-make-empty) (loop for i from 0 below 3 do (ein:notebook-insert-cell-below-command) @@ -214,7 +214,7 @@ (loop for i downfrom 2 to 1 do (beginning-of-line) ; This is required, I need to check why do (should (looking-at (format "Cell %s" i))) - do (ein:notebook-goto-prev-cell) + do (ein:notebook-goto-prev-input-command) do (should (looking-at (format "Cell %s" (1- i))))))) (ert-deftest ein:notebook-move-cell-up-command-simple ()