diff --git a/init.example.el b/init.example.el index ad85c66ce..e6a24f692 100644 --- a/init.example.el +++ b/init.example.el @@ -41,6 +41,7 @@ :tools dired ; making dired pretty [functional] + ein ; tame Jupyter notebooks with emacs electric-indent ; smarter, keyword-based electric-indent eshell ; a consistent, cross-platform shell (WIP) gist ; interacting with github gists diff --git a/modules/tools/ein/README.org b/modules/tools/ein/README.org new file mode 100644 index 000000000..bd54c8474 --- /dev/null +++ b/modules/tools/ein/README.org @@ -0,0 +1,39 @@ +#+TITLE: :tools ein + +* EIN -- Emacs IPython Notebook + +Tool to work with Jupyter notebooks within emacs. + +* Table of Contents :TOC: +- [[EIN -- Emacs IPython Notebook][EIN -- Emacs IPython Notebook]] +- [[Install][Install]] +- [[Usage][Usage]] +- [[Configuration][Configuration]] + +* Install +Add =:tool ein= to your ~doom!~ call in your private ~init.el~. + +* Usage +Three functions are available to start EIN: + 1. ~ein:jupyter-server-start~ --- Start a jupyter server within emacs + 2. ~ein:notebooklist-login~ --- Login to an existing jupyter server + 3. ~ein:notebooklist-open~ --- Open the list of jupyter notebooks + +These functions do not have default key bindings. + +When ~ein:jupyter-server-start~ is called, after successfully finishing, +~ein:notebooklist-login~ and ~ein:notebooklist-open~ will be automatically +called. + +When in the ~Notebook List~ buffer, the key ~o~ calls ~ace-link~ to speed up the +process of selecting links in the buffer. + +If ~company-mode~ is enabled as a module, ~company-ein~ will be used for +completion purposes. + +* Configuration +Specify the default directory where EIN searches for notebooks using: + +~(set! :ein-notebook-dir "~/my-notebooks")~ + + diff --git a/modules/tools/ein/autoload.el b/modules/tools/ein/autoload.el new file mode 100644 index 000000000..d30f5119e --- /dev/null +++ b/modules/tools/ein/autoload.el @@ -0,0 +1,26 @@ +;;; tools/ein/autoload.el -*- lexical-binding: t; -*- + +;;;###autoload +(defun +ein/ace-link-ein () + "Ace jump to links in ein notebooklist." + (interactive) + (let ((res (avy-with +ein/ace-link-ein + (avy--process + (+ein--collect-ein-buffer-links) + #'avy--overlay-pre)))) + ;(avy--style-fn avy-style))))) + (when (numberp res) + (goto-char (1+ res)) + (widget-button-press (point))))) + +;;;###autoload +(defun +ein--collect-ein-buffer-links () + (interactive) + (let ((end (window-end)) + points) + (save-excursion + (goto-char (window-start)) + (while (re-search-forward "~?/.+\\|\s\\[" end t) + (push (+ (match-beginning 0) 1) points)) + (nreverse points)))) + diff --git a/modules/tools/ein/config.el b/modules/tools/ein/config.el new file mode 100644 index 000000000..273358a29 --- /dev/null +++ b/modules/tools/ein/config.el @@ -0,0 +1,38 @@ +;;; tools/ein/config.el -*- lexical-binding: t; -*- + +(defvar +ein-notebook-dir "~/" + "Default directory from where Jupyter notebooks are to be opened.") + +(def-setting! :ein-notebook-dir (dir) + "Set the default directory from where to open Jupyter notebooks." + `(setq +ein-notebook-dir ,dir)) + + +(def-package! ein + :commands (ein:notebooklist-open ein:notebooklist-login ein:jupyter-server-start) + :init + (set! :popup "\\*ein:*" :ignore) + (set! :popup "\\*ein:notebooklist *" '((side . left)) '((size . 40) (select))) + ;; Ace-link on notebook list buffers + (add-hook! 'ein:notebooklist-mode-hook + (map! :map ein:notebooklist-mode-map + "o" #'+ein/ace-link-ein)) + ;; Ein uses request to store http cookies. Store them in the cache dir. + (setq request-storage-directory (concat doom-cache-dir "/request")) + ;; Auto complete with company + (set! :company-backend '(ein:notebook-multilang-mode ein:notebook-python-mode ein:notebook-plain-mode) + 'ein:company-backend) + :config + ;; Manually load the autoloads of EIN. This takes time... + (load "ein-loaddefs.el" nil t t) + (setq + ;; Slide images into rows so that we can navigate buffers with images more easily + ein:slice-image t + ein:jupyter-default-notebook-directory +ein-notebook-dir + ein:jupyter-default-server-command "/usr/bin/jupyter" + ein:jupyter-server-args '("--no-browser") + ein:notebook-modes + '(ein:notebook-multilang-mode ein:notebook-python-mode ein:notebook-plain-mode)) + ;; Avy is required for showing links in the notebook list with ace-link. + (require 'avy)) + diff --git a/modules/tools/ein/packages.el b/modules/tools/ein/packages.el new file mode 100644 index 000000000..19ab85d38 --- /dev/null +++ b/modules/tools/ein/packages.el @@ -0,0 +1,4 @@ +;; -*- no-byte-compile: t; -*- +;;; tools/ein/packages.el + +(package! ein)