Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,11 @@
;;; License: GPLv3

;;; Code:
;;;; jupter repl minor mode keymap
(spacemacs/set-leader-keys-for-minor-mode 'use-jupyter-repl-mode
"'" 'jupyter-run-repl
"cc" 'jupyter-load-file
"cC" '(lambda (file) (interactive "f\file: ") (progn (jupyter-load-file file) (jupyter-repl-pop-to-buffer)))
"sB" '(lambda () (interactive) (progn (jupyter-eval-buffer (current-buffer)) (jupyter-repl-pop-to-buffer)))
"sb" 'jupyter-eval-buffer
"sF" '(lambda () (interactive) (progn (jupyter-eval-defun) (jupyter-repl-pop-to-buffer)))
"sf" 'jupyter-eval-defun
"si" 'jupyter-run-repl
"sR" '(lambda () (interactive) (progn (jupyter-eval-line-or-region 'null) (jupyter-repl-pop-to-buffer)))
"sr" 'jupyter-eval-line-or-region)

;;;; jupyter repl minor mode
(defvar use-jupyter-repl-mode nil)
;; (defvar use-jupyter-repl-mode nil)

;;;###autoload
(define-minor-mode use-jupyter-repl-mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a local package, i.e. a file and then loaded in packages.el, this might also fix needing to use the keybinging twice

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file should be in a subfolder local (see for example the +completion/helm layer with helm-spacemacs-help

"Minor mode that will use a jupyter-repl from package
emacs-jupyter instead of the default repl.
Expand All @@ -34,12 +23,28 @@ Dependancies:
Jupyter kernel corresponding to the major-mode language.
This needs to be installed on your system."
:group 'jupyter-repl
;; :lighter "j-repl"
:lighter "jrepl"
:init-value nil
(cond
(use-jupyter-repl-mode
(add-hook 'after-revert-hook 'use-jupyter-repl-mode nil t))
(t
(remove-hook 'after-revert-hook 'use-jupyter-repl-mode t))))

;;;; use-jupyter-repl
(defun use-jupyter-repl ()
"Checks whether a jupyter repl kernel is associated with this buffer.
If there is, then set repl keybindings to use it. Otherwise, associate the
buffer with a repl. If no repl is running for the major-mode, ask to start one."
(interactive)
(if (eq jupyter-current-client nil)
(call-interactively 'jupyter-repl-associate-buffer))
(call-interactively 'use-jupyter-repl-mode))

;;;; use-jupyter-eval-pop
(defun use-jupyter-eval-pop (func &rest args)
(interactive)
(call-interactively func 'args)
(jupyter-repl-pop-to-buffer))

;;; funcs.el ends here
46 changes: 36 additions & 10 deletions packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,71 @@
(defconst jupyter-packages
'(
company
jupyter
;; (jupyter :location (recipe :fetcher file :path "~/.spacemacs.d/emacs-jupyter"))
;; upate may 27, 2023
(jupyter :Location (recipe :fetcher github :repo "emacs-jupyter/jupyter"))
;; (jupyter :location local)
;; jupyter
smartparens
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. added here and then have an init-use-jupyter-repl...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this (use-jupyter... :location local)

websocket
zmq
))

(defun jupyter/init-jupyter ()
(if (executable-find "jupyter")
(use-package jupyter
:defer t
:demand t
:init
(progn
(spacemacs/set-leader-keys
"aja" 'jupyter-repl-associate-buffer
"ajc" 'jupyter-connect-repl
"ajr" 'jupyter-run-repl
"ajs" 'jupyter-server-list-kernels
"ajt" 'use-jupyter-repl-mode
)
"ajt" 'use-jupyter-repl)
(spacemacs/set-leader-keys-for-major-mode 'jupyter-repl-mode
"i" 'jupyter-inspect-at-point
"l" 'jupyter-load-file
"s" 'jupyter-repl-scratch-buffer
"I" 'jupyter-repl-interrupt-kernel
"R" 'jupyter-repl-restart-kernel))
:config
(progn
"R" 'jupyter-repl-restart-kernel)
(spacemacs/set-leader-keys-for-minor-mode 'use-jupyter-repl-mode
"'" 'jupyter-run-repl
"cc" 'jupyter-load-file
"cC" '(lambda () (interactive) (use-jupyter-eval-pop 'jupyter-load-file))
"sB" '(lambda () (interactive) (use-jupyter-eval-pop 'jupyter-eval-buffer))
"sb" 'jupyter-eval-buffer
"sF" '(lambda () (interactive) (use-jupyter-eval-pop 'jupyter-eval-defun))
"sf" 'jupyter-eval-defun
"si" 'jupyter-run-repl
"sR" '(lambda () (interactive) (use-jupyter-eval-pop 'jupyter-eval-line-or-region))
"sr" 'jupyter-eval-line-or-region)
(when (eq dotspacemacs-editing-style 'vim)
(evil-define-key '(insert normal) jupyter-repl-mode-map
(kbd "C-j") 'jupyter-repl-history-next
(kbd "C-k") 'jupyter-repl-history-previous
(kbd "C-l") 'jupyter-repl-clear-cells
;; (kbd "C-l") 'jupyter-repl-clear-cells
(kbd "M-j") 'jupyter-repl-forward-cell
(kbd "M-k") 'jupyter-repl-backward-cell
(kbd "C-s") 'jupyter-repl-scratch-buffer
(kbd "C-R") 'jupyter-repl-history-next-matching
(kbd "C-r") 'jupyter-repl-history-previous-matching))
))
(kbd "C-R") 'isearch-forward
(kbd "C-r") 'isearch-backward))))

(message "jupyter was not found in your path, jupyter is not loaded")))

(defun jupyter/post-init-company ()
(spacemacs|add-company-backends :backends company-capf :modes jupyter-repl-mode))

(defun jupyter/post-init-smartparens ()
(add-hook 'jupyter-repl-mode-hook 'smartparens-mode))

(defun jupyter/init-websocket ()
(use-package websocket
:defer t))

(defun jupyter/init-zmq ()
(use-package zmq
:defer t))

;;; packages.el ends here