From e0aee1554454aff8183076b442b2903e5fa072c1 Mon Sep 17 00:00:00 2001 From: dickmao Date: Sat, 29 Feb 2020 16:37:21 -0500 Subject: [PATCH] Bring ipython-notebook up to date. --- CHANGELOG.develop | 1 + layers/+lang/ipython-notebook/packages.el | 252 +++++----------------- 2 files changed, 51 insertions(+), 202 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 9de754687..e38a720e7 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -2095,6 +2095,7 @@ Other: **** IPython Notebook - Added support for auto-completion with =company= (thanks to tutysara) - Added =ob-ipython= (thanks to Alejandro Catalina) +- DRY and tidiness update (thanks to dickmao) - Key bindings: - ~SPC a i l~ to login (thanks to Ben Mabey) - ~SPC m s~ to split cell at point (thanks to Jaakko Luttinen) diff --git a/layers/+lang/ipython-notebook/packages.el b/layers/+lang/ipython-notebook/packages.el index 12f40bb5d..eae2a5ce8 100644 --- a/layers/+lang/ipython-notebook/packages.el +++ b/layers/+lang/ipython-notebook/packages.el @@ -9,214 +9,62 @@ ;; ;;; License: GPLv3 -(setq ipython-notebook-packages - '( - company - ein - ob-ipython - websocket - request - request-deferred - dash - s - skewer-mode - )) - -(defun ipython-notebook/init-websocket () - (use-package websocket - :defer t - :init)) - -(defun ipython-notebook/init-request-deferred () - (use-package request-deferred - :defer t - :init)) - -(defun ipython-notebook/init-dash () - (use-package dash - :defer t - :init)) - -(defun ipython-notebook/init-s () - (use-package s - :defer t - :init)) - -(defun ipython-notebook/post-init-skewer-mode ()) - -(defun ipython-notebook/post-init-request ()) - -(defun ipython-notebook/post-init-company ()) - -(defun ipython-notebook/init-ein-notebook () - (use-package ein-notebook - :defer t - :init)) - -(defun ipython-notebook/init-ein-subpackages () - (use-package ein-subpackages - :defer t - :init)) +(setq ipython-notebook-packages '(ein ob-ipython)) (defun ipython-notebook/init-ein () (use-package ein - :defer t - :commands (ein:notebooklist-open ein:notebooklist-login ein:run ein:stop) :init - (progn - (spacemacs/set-leader-keys - "ayl" 'ein:notebooklist-login - "ayo" 'ein:notebooklist-open - "ayr" 'ein:run - "ays" 'ein:stop) - (spacemacs/declare-prefix "ay" "ipython notebook") - (with-eval-after-load 'ein-notebooklist - (evilified-state-evilify-map ein:notebooklist-mode-map - :mode ein:notebooklist-mode - :bindings - (kbd "o") 'spacemacs/ace-buffer-links) - (define-key ein:notebooklist-mode-map "o" 'spacemacs/ace-buffer-links))) + (spacemacs/set-leader-keys "ayl" 'ein:login + "ayr" 'ein:run + "ays" 'ein:stop) + (spacemacs/declare-prefix "ay" "ipython notebook") :config - (progn - (defun spacemacs/ein:worksheet-merge-cell-next () - (interactive) - (ein:worksheet-merge-cell (ein:worksheet--get-ws-or-error) (ein:worksheet-get-current-cell) t t)) - - (defun spacemacs//concat-leader (key) - (if dotspacemacs-major-mode-leader-key - (concat dotspacemacs-major-mode-leader-key key) - (concat "," key))) - - (spacemacs/set-leader-keys-for-minor-mode 'ein:notebook-mode - "y" 'ein:worksheet-copy-cell-km - "p" 'ein:worksheet-yank-cell-km - "d" 'ein:worksheet-kill-cell-km - "h" 'ein:notebook-worksheet-open-prev-or-last-km - "i" 'ein:worksheet-insert-cell-below-km - "I" 'ein:worksheet-insert-cell-above-km - "j" 'ein:worksheet-goto-next-input-km - "k" 'ein:worksheet-goto-prev-input-km - "l" 'ein:notebook-worksheet-open-next-or-first-km - "H" 'ein:notebook-worksheet-move-prev-km - "J" 'ein:worksheet-move-cell-down-km - "K" 'ein:worksheet-move-cell-up-km - "L" 'ein:notebook-worksheet-move-next-km - "t" 'ein:worksheet-toggle-output-km - "R" 'ein:worksheet-rename-sheet-km - "RET" 'ein:worksheet-execute-cell-and-goto-next-km - ;; Output - "C-l" 'ein:worksheet-clear-output-km - "C-S-l" 'ein:worksheet-clear-all-output-km - ;;Console - "C-o" 'ein:console-open - ;; Merge cells - "C-k" 'ein:worksheet-merge-cell-km - "C-j" 'spacemacs/ein:worksheet-merge-cell-next - "s" 'ein:worksheet-split-cell-at-point-km - ;; Notebook - "C-s" 'ein:notebook-save-notebook-command-km - "C-r" 'ein:notebook-rename-command-km - "1" 'ein:notebook-worksheet-open-1th-km - "2" 'ein:notebook-worksheet-open-2th-km - "3" 'ein:notebook-worksheet-open-3th-km - "4" 'ein:notebook-worksheet-open-4th-km - "5" 'ein:notebook-worksheet-open-5th-km - "6" 'ein:notebook-worksheet-open-6th-km - "7" 'ein:notebook-worksheet-open-7th-km - "8" 'ein:notebook-worksheet-open-8th-km - "9" 'ein:notebook-worksheet-open-last-km - "+" 'ein:notebook-worksheet-insert-next-km - "-" 'ein:notebook-worksheet-delete-km - "x" 'ein:notebook-close-km - "u" 'ein:worksheet-change-cell-type-km - "fs" 'ein:notebook-save-notebook-command-km) - - ;; keybindings for ipython notebook traceback mode - (spacemacs/set-leader-keys-for-major-mode 'ein:traceback-mode - "RET" 'ein:tb-jump-to-source-at-point-command - "n" 'ein:tb-next-item - "p" 'ein:tb-prev-item - "q" 'bury-buffer) - - ;; keybindings mirror ipython web interface behavior - (evil-define-minor-mode-key 'insert 'ein:notebook-mode + (mapc + (lambda (mode) + (evil-define-minor-mode-key + mode 'ein:notebook-mode (kbd "") 'ein:worksheet-execute-cell-km - (kbd "") 'ein:worksheet-execute-cell-and-goto-next-km) - - ;; keybindings mirror ipython web interface behavior - (evil-define-minor-mode-key 'hybrid 'ein:notebook-mode - (kbd "") 'ein:worksheet-execute-cell-km - (kbd "") 'ein:worksheet-execute-cell-and-goto-next-km) - - (evil-define-minor-mode-key 'normal 'ein:notebook-mode - ;; keybindings mirror ipython web interface behavior - (kbd "") 'ein:worksheet-execute-cell-km - (kbd "") 'ein:worksheet-execute-cell-and-goto-next-km - "gj" 'ein:worksheet-goto-next-input-km - "gk" 'ein:worksheet-goto-prev-input-km) - - ;; if this is not required then the following keygindings fail - (require 'ein-notebook) - (define-key ein:notebook-mode-map (kbd "M-j") 'ein:worksheet-move-cell-down-km) - (define-key ein:notebook-mode-map (kbd "M-k") 'ein:worksheet-move-cell-up-km) - - (spacemacs|define-transient-state ipython-notebook - :title "iPython Notebook Transient State" - :doc " - Operations on Cells^^^^^^ On Worksheets^^^^ Other - ----------------------------^^^^^^ ------------------------^^^^ ----------------------------------^^^^ - [_k_/_j_]^^ select prev/next [_h_/_l_] select prev/next [_t_]^^ toggle output - [_K_/_J_]^^ move up/down [_H_/_L_] move left/right [_C-l_/_C-S-l_] clear/clear all output - [_C-k_/_C-j_]^^ merge above/below [_1_.._9_] open [1st..last] [_C-o_]^^ open console - [_O_/_o_]^^ insert above/below [_+_/_-_] create/delete [_C-s_/_C-r_] save/rename notebook - [_y_/_p_/_d_] copy/paste ^^^^ [_x_]^^ close notebook - [_u_]^^^^ change type ^^^^ [_q_]^^ quit transient-state - [_RET_]^^^^ execute" - :evil-leader-for-mode (ein:notebook-mode . ".") - :bindings - ("q" nil :exit t) - ("?" spacemacs//ipython-notebook-ms-toggle-doc) - ("h" ein:notebook-worksheet-open-prev-or-last-km) - ("j" ein:worksheet-goto-next-input-km) - ("k" ein:worksheet-goto-prev-input-km) - ("l" ein:notebook-worksheet-open-next-or-first-km-km) - ("H" ein:notebook-worksheet-move-prev-km-km) - ("J" ein:worksheet-move-cell-down-km) - ("K" ein:worksheet-move-cell-up-km) - ("L" ein:notebook-worksheet-move-next-km-km) - ("t" ein:worksheet-toggle-output-km) - ("d" ein:worksheet-kill-cell-km) - ("R" ein:worksheet-rename-sheet-km) - ("y" ein:worksheet-copy-cell-km) - ("p" ein:worksheet-yank-cell-km) - ("o" ein:worksheet-insert-cell-below-km) - ("O" ein:worksheet-insert-cell-above-km) - ("u" ein:worksheet-change-cell-type-km) - ("RET" ein:worksheet-execute-cell-and-goto-next-km) - ;; Output - ("C-l" ein:worksheet-clear-output-km) - ("C-S-l" ein:worksheet-clear-all-output-km) - ;;Console - ("C-o" ein:console-open-km) - ;; Merge and split cells - ("C-k" ein:worksheet-merge-cell-km) - ("C-j" spacemacs/ein:worksheet-merge-cell-next) - ("s" ein:worksheet-split-cell-at-point-km) - ;; Notebook - ("C-s" ein:notebook-save-notebook-command-km) - ("C-r" ein:notebook-rename-command-km) - ("1" ein:notebook-worksheet-open-1th-km) - ("2" ein:notebook-worksheet-open-2th-km) - ("3" ein:notebook-worksheet-open-3th-km) - ("4" ein:notebook-worksheet-open-4th-km) - ("5" ein:notebook-worksheet-open-5th-km) - ("6" ein:notebook-worksheet-open-6th-km) - ("7" ein:notebook-worksheet-open-7th-km) - ("8" ein:notebook-worksheet-open-8th-km) - ("9" ein:notebook-worksheet-open-last-km) - ("+" ein:notebook-worksheet-insert-next-km) - ("-" ein:notebook-worksheet-delete-km) - ("x" ein:notebook-close-km))))) + (kbd "") 'ein:worksheet-execute-cell-and-goto-next-km)) + '(insert hybrid normal)) + (with-eval-after-load 'ein-notebook + (evil-define-key nil ein:notebooklist-mode-map "o" 'spacemacs/ace-buffer-links) + (let ((bindings '(("j" ein:worksheet-goto-next-input-km) + ("k" ein:worksheet-goto-prev-input-km) + ("J" ein:worksheet-move-cell-down-km) + ("K" ein:worksheet-move-cell-up-km) + ("e" ein:worksheet-toggle-output-km) + ("d" ein:worksheet-kill-cell-km) + ("y" ein:worksheet-copy-cell-km) + ("p" ein:worksheet-yank-cell-km) + ("m" ein:worksheet-merge-cell-km) + ("s" ein:worksheet-split-cell-at-point-km) + ("o" ein:worksheet-insert-cell-below-km) + ("O" ein:worksheet-insert-cell-above-km) + ("t" ein:worksheet-toggle-cell-type-km) + ("C-m" ein:worksheet-execute-cell-km) + ("l" ein:worksheet-clear-output-km) + ("L" ein:worksheet-clear-all-output-km) + ("C-s" ein:notebook-save-notebook-command-km) + ("C-r" ein:notebook-rename-command-km) + ("x" ein:notebook-close-km) + ("z" ein:notebook-kernel-interrupt-command-km)))) + (apply #'spacemacs/set-leader-keys-for-minor-mode + (quote ein:notebook-mode) + (cl-mapcan + (lambda (bind) + (if (fboundp (cl-second bind)) + bind + (prog1 nil + (display-warning + 'warn (format "ipython-notebook/init-ein: undefined %s" + (cl-second bind)))))) + (copy-tree bindings))) + (eval (append '(spacemacs|define-transient-state + ipython-notebook + :title "iPython Notebook Transient State" + :bindings + ("q" nil :exit t)) + bindings)))))) (defun ipython-notebook/pre-init-ob-ipython () (spacemacs|use-package-add-hook org