From b97586fbc181e8673c7542681ee68c1736311a5a Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 22 Jul 2012 15:40:41 +0200 Subject: [PATCH 1/4] Add ein-autoexec.el --- lisp/ein-autoexec.el | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lisp/ein-autoexec.el diff --git a/lisp/ein-autoexec.el b/lisp/ein-autoexec.el new file mode 100644 index 0000000..fbc4995 --- /dev/null +++ b/lisp/ein-autoexec.el @@ -0,0 +1,54 @@ +;;; ein-autoexec.el --- Automatic cell execution + +;; Copyright (C) 2012 Takafumi Arakaki + +;; Author: Takafumi Arakaki + +;; This file is NOT part of GNU Emacs. + +;; ein-autoexec.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-autoexec.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-autoexec.el. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(require 'ein-notebook) + +(defun ein:autoexec-after-change (beg end -ignore-len-) + "Called via `after-change-functions' hook." + (let ((cell (ein:notebook-get-current-cell beg))) + (when (and (ein:codecell-p cell) + this-command + (<= (ein:cell-input-pos-min cell) beg) + (>= (ein:cell-input-pos-max cell) end)) + (ein:notebook-execute-cell ein:notebook cell)))) + +(define-minor-mode ein:autoexec-mode + "Automatic cell execution minor mode." + :lighter " ein:au" + :group 'ein + (if ein:autoexec-mode + (add-hook 'after-change-functions 'ein:autoexec-after-change nil t) + (remove-hook 'after-change-functions 'ein:autoexec-after-change t))) + +;; To avoid MuMaMo to discard `ein:autoexec-after-change', make it +;; permanent local. +(put 'ein:autoexec-after-change 'permanent-local-hook t) +(put 'ein:autoexec-mode 'permanent-local t) + +(provide 'ein-autoexec) + +;;; ein-autoexec.el ends here From 15efdd2ce50b7f517fb2f01fbe9ac9263f7b26a8 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 22 Jul 2012 15:53:00 +0200 Subject: [PATCH 2/4] Add delay before auto execution --- lisp/ein-autoexec.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/ein-autoexec.el b/lisp/ein-autoexec.el index fbc4995..ce22e67 100644 --- a/lisp/ein-autoexec.el +++ b/lisp/ein-autoexec.el @@ -27,6 +27,23 @@ (require 'ein-notebook) +(defcustom ein:autoexec-delay 0.3 + "Delay before executing cell after change in second." + :type 'number + :group 'ein) + +(defvar ein:autoexec-timer nil) + +(defun ein:autoexec-execute-cell (cell) + "Call `ein:notebook-execute-cell' after `ein:autoexec-delay' second. +If the previous execution timer is not fired yet, cancel the timer." + (when ein:autoexec-timer + (cancel-timer ein:autoexec-timer)) + (setq ein:autoexec-timer + (run-with-idle-timer ein:autoexec-delay nil + #'ein:notebook-execute-cell + ein:notebook cell))) + (defun ein:autoexec-after-change (beg end -ignore-len-) "Called via `after-change-functions' hook." (let ((cell (ein:notebook-get-current-cell beg))) @@ -34,7 +51,7 @@ this-command (<= (ein:cell-input-pos-min cell) beg) (>= (ein:cell-input-pos-max cell) end)) - (ein:notebook-execute-cell ein:notebook cell)))) + (ein:autoexec-execute-cell cell)))) (define-minor-mode ein:autoexec-mode "Automatic cell execution minor mode." From 66ea6f6d1097ecb9a95fcf34dff3594ba389a362 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 22 Jul 2012 16:01:53 +0200 Subject: [PATCH 3/4] Add autoload for ein:autoexec-mode in ein.el --- lisp/ein.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisp/ein.el b/lisp/ein.el index 48750e9..771f40f 100644 --- a/lisp/ein.el +++ b/lisp/ein.el @@ -43,6 +43,9 @@ (autoload 'ein:connect-to-notebook "ein-connect" "Connect any buffer to notebook and its kernel." t) +(autoload 'ein:autoexec-mode "ein-autoexec" + "Automatic cell execution minor mode." t) + (autoload 'ein:dev-insert-mode-map "ein-dev") (autoload 'ein:dev-start-debug "ein-dev" "Enable debugging support." t) (autoload 'ein:dev-stop-debug "ein-dev" "Disable debugging support." t) From c6adb4ff567f25fcdb2012b2c6fb1bfc4144f908 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 22 Jul 2012 16:02:14 +0200 Subject: [PATCH 4/4] Document ein:autoexec-mode --- doc/source/conf.el | 1 + doc/source/index.rst | 3 +++ lisp/ein-autoexec.el | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/source/conf.el b/doc/source/conf.el index 093bbd2..f9c500f 100644 --- a/doc/source/conf.el +++ b/doc/source/conf.el @@ -8,6 +8,7 @@ (require 'ein-mumamo) (require 'ein-ac) (require 'ein-connect) +(require 'ein-autoexec) ;; Load `wid-edit'. Otherwise the following error will be raised: ;; Symbol's function definition is void: widget-button-press diff --git a/doc/source/index.rst b/doc/source/index.rst index 41e9ece..281de86 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -220,6 +220,7 @@ The following keybinds are available in notebook buffers. .. el:function:: ein:notebook-delete-cell-command .. el:function:: ein:notebook-rename-to-scratch-command .. el:function:: ein:notebook-kill-all-buffers +.. el:function:: ein:autoexec-mode Connected buffer ^^^^^^^^^^^^^^^^ @@ -304,6 +305,7 @@ Notebook .. el:variable:: ein:cell-traceback-level .. el:variable:: ein:cell-max-num-outputs .. el:variable:: ein:scratch-notebook-name-template +.. el:variable:: ein:autoexec-delay Connect ^^^^^^^ @@ -474,6 +476,7 @@ v0.1.1 * Add :el:symbol:`ein:pytools-pandas-to-ses`. * Add Imenu support. * Better heading cell faces. +* Add :el:symbol:`ein:autoexec-mode` v0.1 diff --git a/lisp/ein-autoexec.el b/lisp/ein-autoexec.el index ce22e67..28a09a3 100644 --- a/lisp/ein-autoexec.el +++ b/lisp/ein-autoexec.el @@ -54,7 +54,9 @@ If the previous execution timer is not fired yet, cancel the timer." (ein:autoexec-execute-cell cell)))) (define-minor-mode ein:autoexec-mode - "Automatic cell execution minor mode." + "Automatic cell execution minor mode. +Code cell at point will be automatically executed after any +change in its input area." :lighter " ein:au" :group 'ein (if ein:autoexec-mode