Add commands ein:worksheet-previous/next-input-history

This commit is contained in:
Takafumi Arakaki 2012-08-28 12:23:47 +02:00
parent 8ce439b927
commit a31184a5b6
2 changed files with 54 additions and 1 deletions

View file

@ -815,6 +815,8 @@ Do not use `python-mode'. Use plain mode when MuMaMo is not installed::
(define-key map (kbd "C-c C-.") 'ein:pytools-jump-to-source-command)
(define-key map "\M-," 'ein:pytools-jump-back-command)
(define-key map (kbd "C-c C-,") 'ein:pytools-jump-back-command)
(define-key map "\M-p" 'ein:worksheet-previous-input-history)
(define-key map "\M-n" 'ein:worksheet-next-input-history)
(define-key map (kbd "C-c C-/") 'ein:notebook-scratchsheet-open)
(easy-menu-define ein:notebook-menu map "EIN Notebook Mode Menu"
`("EIN Notebook"
@ -878,7 +880,11 @@ Do not use `python-mode'. Use plain mode when MuMaMo is not installed::
:active (ein:worksheet-at-codecell-p))
("Jump to definition" ein:pytools-jump-to-source-command)
("Go back to the previous jump point"
ein:pytools-jump-back-command))))
ein:pytools-jump-back-command)
("Previous input history"
ein:worksheet-previous-input-history)
("Next input history"
ein:worksheet-next-input-history))))
("Kernel"
,@(ein:generate-menu
'(("Restart kernel" ein:notebook-restart-kernel-command)

View file

@ -633,6 +633,53 @@ cell bellow."
(mapc #'ein:cell-execute
(ein:filter #'ein:codecell-p (ein:worksheet-get-cells ws))))
(defun ein:worksheet-insert-last-input-history (ws cell index)
(ein:kernel-history-request
(oref ws :kernel)
(list
:history_reply
(cons
(lambda (cell content -metadata-not-used-)
(destructuring-bind (session line-number input)
(car (plist-get content :history))
(if (eq (ein:worksheet-get-current-cell) cell)
(ein:cell-set-text cell input)
(ein:log 'warning
"Cursor moved from the cell after history request."))
(ein:log 'info "Input history inserted: session:%d line:%d"
session line-number)))
cell))
:hist-access-type "range"
:session 0
:start (- index)
:stop (- 1 index)))
(defvar ein:worksheet--history-index 0)
(defun ein:worksheet--get-history-index (inc)
(if (or (eq last-command 'ein:worksheet-previous-input-history)
(eq last-command 'ein:worksheet-next-input-history))
(progn
(setq ein:worksheet--history-index
(+ ein:worksheet--history-index inc))
(when (< ein:worksheet--history-index 0)
(setq ein:worksheet--history-index 0)
(error "This is the latest input"))
ein:worksheet--history-index)
(setq ein:worksheet--history-index 0)))
(defun ein:worksheet-previous-input-history (ws cell index)
(interactive (list (ein:worksheet--get-ws-or-error)
(ein:worksheet-get-current-cell)
(ein:worksheet--get-history-index +1)))
(ein:worksheet-insert-last-input-history ws cell index))
(defun ein:worksheet-next-input-history (ws cell index)
(interactive (list (ein:worksheet--get-ws-or-error)
(ein:worksheet-get-current-cell)
(ein:worksheet--get-history-index -1)))
(ein:worksheet-insert-last-input-history ws cell index))
;;; Generic getter