mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 01:21:38 -05:00
Implementing ExecuteTime in ein.
If you want to try this in your installation of ein then place a call to (require 'ein-timestamp) in your init file after loading ein.
This commit is contained in:
parent
9ad9b4f4e6
commit
4e0deb86ae
1 changed files with 61 additions and 0 deletions
61
lisp/ein-timestamp.el
Normal file
61
lisp/ein-timestamp.el
Normal file
|
@ -0,0 +1,61 @@
|
|||
;;; ein-timestamp.el --- Elisp implementation of the ExecuteTime nbextension
|
||||
|
||||
;; Copyright (C) 2018- John M. Miller
|
||||
|
||||
;; Author: John M. Miller <millejoh at mac.com>
|
||||
|
||||
;; This file is NOT part of GNU Emacs.
|
||||
|
||||
;; ein-timestamp.el is free software: you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; ein-timestamp.el is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with ein-kernel.el. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; A rough approximation of the ExecuteTime (https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/execute_time/readme.html) nbextension
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ein-kernel)
|
||||
(require 'ein-cell)
|
||||
|
||||
(defun ein:timestamp--shell-reply-hook (msg-type header content metadata)
|
||||
(when (string-equal msg-type "execute_reply")
|
||||
(let ((start-time (plist-get metadata :started))
|
||||
(end-time (plist-get header :date)))
|
||||
(plist-put metadata :execute-time (cons start-time end-time)))))
|
||||
|
||||
(defun ein:timestamp--execute-reply-hook (cell content metadata)
|
||||
(if-let ((etime (plist-get metadata :execute-time)))
|
||||
(if (ein:cell-metadata cell)
|
||||
(plist-put (ein:cell-metadata cell)
|
||||
:execute-time
|
||||
etime)
|
||||
(setf (ein:cell-metadata cell) (list :execute-time etime))))
|
||||
(ein:cell-running-set cell nil)
|
||||
(ewoc-invalidate (ein:basecell--ewoc cell) (ein:cell-element-get cell :footer)))
|
||||
|
||||
(defmethod ein:cell-insert-footer :after ((cell ein:codecell))
|
||||
(if (slot-value cell 'running)
|
||||
(ein:insert-read-only "Execution pending\n\n")
|
||||
(if-let ((etime (plist-get (ein:cell-metadata cell) :execute-time)))
|
||||
(let ((start-time (date-to-time (car etime)))
|
||||
(end-time (date-to-time (cdr etime))))
|
||||
(ein:insert-read-only (format "Last executed %s in %ss\n\n"
|
||||
(current-time-string start-time)
|
||||
(float-time (time-subtract end-time start-time))))))))
|
||||
|
||||
(add-hook 'ein:on-shell-reply-functions 'ein:timestamp--shell-reply-hook)
|
||||
(add-hook 'ein:on-execute-reply-functions 'ein:timestamp--execute-reply-hook)
|
||||
|
||||
(provide 'ein-timestamp)
|
||||
|
Loading…
Add table
Reference in a new issue