Skip to content
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
26 changes: 19 additions & 7 deletions jupyter-org-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ See also the docstring of `org-image-actual-width' for more details."
:group 'ob-jupyter
:type 'boolean)

(defcustom jupyter-org-want-keybinding t
"Whether to enable contextual keybindings."
:group 'ob-jupyter
:type 'boolean)

(defcustom jupyter-org-want-integration t
"Whether to enable `jupyter-org-interaction-mode' automatically on `org-mode' buffers."
:group 'ob-jupyter
:type 'boolean)

(defconst jupyter-org-mime-types '(:text/org
;; Prioritize images over html
:image/svg+xml :image/jpeg :image/png
Expand Down Expand Up @@ -823,12 +833,13 @@ and they only take effect when the variable
#'undefined
(jupyter-org--define-key-filter key))))))))

(jupyter-org-define-key (kbd "C-x C-e") #'jupyter-eval-line-or-region)
(jupyter-org-define-key (kbd "C-M-x") #'jupyter-eval-defun)
(jupyter-org-define-key (kbd "M-i") #'jupyter-inspect-at-point)
(jupyter-org-define-key (kbd "C-c M-:") #'jupyter-eval-string-command)
(jupyter-org-define-key (kbd "C-c C-r") #'jupyter-repl-restart-kernel)
(jupyter-org-define-key (kbd "C-c C-i") #'jupyter-repl-interrupt-kernel)
(when jupyter-org-want-keybinding
(jupyter-org-define-key (kbd "C-x C-e") #'jupyter-eval-line-or-region)
(jupyter-org-define-key (kbd "C-M-x") #'jupyter-eval-defun)
(jupyter-org-define-key (kbd "M-i") #'jupyter-inspect-at-point)
(jupyter-org-define-key (kbd "C-c M-:") #'jupyter-eval-string-command)
(jupyter-org-define-key (kbd "C-c C-r") #'jupyter-repl-restart-kernel)
(jupyter-org-define-key (kbd "C-c C-i") #'jupyter-repl-interrupt-kernel))

;;; Handling ANSI escapes in kernel output

Expand Down Expand Up @@ -939,7 +950,8 @@ C-x C-e `jupyter-eval-line-or-region'"
(lambda (x) (eq (car x) 'jupyter-org-font-lock-ansi-escapes))
org-font-lock-keywords))))

(add-hook 'org-mode-hook 'jupyter-org-interaction-mode)
(when jupyter-org-want-integration
(add-hook 'org-mode-hook 'jupyter-org-interaction-mode))

;;; Constructing org syntax trees

Expand Down
7 changes: 4 additions & 3 deletions ob-jupyter.el
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,11 @@ mapped to their appropriate minted language in
(defun org-babel-jupyter-make-local-aliases ()
(let ((default-directory user-emacs-directory))
(org-babel-jupyter-aliases-from-kernelspecs)))
(add-hook 'org-mode-hook #'org-babel-jupyter-make-local-aliases 10)

(add-hook 'org-export-before-processing-functions #'org-babel-jupyter-setup-export)
(add-hook 'org-export-before-parsing-functions #'org-babel-jupyter-strip-ansi-escapes)
(when jupyter-org-want-integration
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why should this be here? There would be no way to recognize Jupyter source blocks in the buffer if we don't make the aliases at some point and the other hooks only apply for Jupyter specific source blocks as well.

(add-hook 'org-mode-hook #'org-babel-jupyter-make-local-aliases 10)
(add-hook 'org-export-before-processing-functions #'org-babel-jupyter-setup-export)
(add-hook 'org-export-before-parsing-functions #'org-babel-jupyter-strip-ansi-escapes))

(provide 'ob-jupyter)

Expand Down