mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 17:11:41 -05:00
notebook-mode as a proper minor mode
Previously `notebook-mode` was an ordinary function that called `notebook-minor-mode` to install `ein:notebook-mode-map`. Make `ein:notebook-mode` a proper minor mode via `define-minor-mode`. This has a few visible benefits primarily that `describe-mode` or `F1 m` will now show all the keybindings, and mode-line will reflect. As a consequence `ein:notebook-mode-hook` is no longer an explicit `defcustom` (proper minor modes get it for free). This had been a dangerous situation as the default hook containing critical functions could be overridden.
This commit is contained in:
parent
476a08f119
commit
4e8a9b51b5
3 changed files with 45 additions and 37 deletions
|
@ -90,7 +90,7 @@
|
|||
(interactive (list 'interactive))
|
||||
(cl-case command
|
||||
(interactive (company-begin-backend 'ein:company-backend) )
|
||||
(prefix (and (--filter (and (boundp it) (symbol-value it) (or (eql it 'ein:notebook-minor-mode)
|
||||
(prefix (and (--filter (and (boundp it) (symbol-value it) (or (eql it 'ein:notebook-mode)
|
||||
(eql it 'ein:connect-mode)))
|
||||
minor-mode-list)
|
||||
(ein:object-at-point)))
|
||||
|
|
|
@ -1319,12 +1319,6 @@ Use simple `python-mode' based notebook mode when MuMaMo is not installed::
|
|||
(const :tag "Plain" ein:notebook-plain-mode)))
|
||||
:group 'ein)
|
||||
|
||||
(defcustom ein:notebook-mode-hook
|
||||
'(ein:worksheet-imenu-setup ein:worksheet-reinstall-which-cell-hook)
|
||||
"Hook for `ein:notebook-mode'.
|
||||
This hook is run regardless the actual major mode used."
|
||||
:type '(repeat function)
|
||||
:group 'ein)
|
||||
|
||||
(defun ein:notebook-choose-mode ()
|
||||
"Return usable (defined) notebook mode."
|
||||
|
@ -1545,7 +1539,6 @@ watch the fireworks!"
|
|||
(defun ein:notebook-configure-eldoc ()
|
||||
"eldoc comments say: Major modes for other languages may use ElDoc by defining an
|
||||
appropriate function as the buffer-local value of `eldoc-documentation-function'."
|
||||
;; TODO
|
||||
(when ein:enable-eldoc-support
|
||||
(require 'eldoc nil t)
|
||||
(if (boundp 'eldoc-documentation-function)
|
||||
|
@ -1556,39 +1549,49 @@ appropriate function as the buffer-local value of `eldoc-documentation-function'
|
|||
eldoc-documentation-function))
|
||||
(setq-local eldoc-documentation-function #'ein:completer--get-eldoc-signature))))
|
||||
|
||||
(defun ein:notebook-mode ()
|
||||
(funcall (ein:notebook-choose-mode))
|
||||
(case ein:completion-backend
|
||||
(ein:use-ac-backend (ein:complete-on-dot-install ein:notebook-mode-map 'ein:notebook-complete-dot)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-ac-jedi-backend (ein:jedi-complete-on-dot-install ein:notebook-mode-map)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-company-backend
|
||||
(when (boundp 'company-backends) (add-to-list 'company-backends 'ein:company-backend))
|
||||
(company-mode +1))
|
||||
(ein:use-company-jedi-backend (warn "Support for jedi+company currently not implemented. Defaulting to just company-mode")
|
||||
(when (boundp 'company-backends)
|
||||
(add-to-list 'company-backends 'ein:company-backend))
|
||||
(company-mode +1))
|
||||
(define-minor-mode ein:notebook-mode
|
||||
"A mode for jupyter notebooks.
|
||||
|
||||
(t (warn "No autocompletion backend has been selected - see `ein:completion-backend'.")))
|
||||
(ein:aif ein:helm-kernel-history-search-key
|
||||
(define-key ein:notebook-mode-map it 'helm-ein-kernel-history))
|
||||
(ein:aif ein:anything-kernel-history-search-key
|
||||
(define-key ein:notebook-mode-map it 'anything-ein-kernel-history))
|
||||
(ein:notebook-minor-mode +1)
|
||||
(setq indent-tabs-mode nil) ;; Being T causes problems with Python code.
|
||||
(ein:notebook-configure-eldoc)
|
||||
(run-hooks 'ein:notebook-mode-hook))
|
||||
|
||||
(define-minor-mode ein:notebook-minor-mode
|
||||
"Minor mode to install `ein:notebook-mode-map' for `ein:notebook-mode'."
|
||||
\\{ein:notebook-mode-map}
|
||||
"
|
||||
:init-value nil
|
||||
:lighter " Notebook"
|
||||
:keymap ein:notebook-mode-map
|
||||
:group 'ein)
|
||||
:group 'ein
|
||||
|
||||
;; To avoid MuMaMo to discard `ein:notebook-minor-mode', make it
|
||||
;; BODY contains code to execute each time the mode is enabled or disabled.
|
||||
;; It is executed after toggling the mode, and before running MODE-hook.
|
||||
|
||||
(when ein:notebook-mode
|
||||
(funcall (ein:notebook-choose-mode)) ;; TODO odd seems out of place
|
||||
|
||||
(case ein:completion-backend
|
||||
(ein:use-ac-backend
|
||||
(assert (featurep 'ein-ac))
|
||||
(ein:complete-on-dot-install ein:notebook-mode-map 'ein:notebook-complete-dot)
|
||||
(auto-complete-mode))
|
||||
(ein:use-ac-jedi-backend
|
||||
(assert (featurep 'ein-ac))
|
||||
(ein:jedi-complete-on-dot-install ein:notebook-mode-map)
|
||||
(auto-complete-mode))
|
||||
(ein:use-company-backend
|
||||
(assert (featurep 'ein-company))
|
||||
(company-mode))
|
||||
(ein:use-company-jedi-backend
|
||||
(assert (featurep 'ein-company))
|
||||
(company-mode)))
|
||||
(ein:aif ein:helm-kernel-history-search-key
|
||||
(define-key ein:notebook-mode-map it 'helm-ein-kernel-history))
|
||||
(ein:aif ein:anything-kernel-history-search-key
|
||||
(define-key ein:notebook-mode-map it 'anything-ein-kernel-history))
|
||||
(setq indent-tabs-mode nil) ;; Being T causes problems with Python code.
|
||||
(ein:notebook-configure-eldoc)
|
||||
(ein:worksheet-imenu-setup)
|
||||
(ein:worksheet-reinstall-which-cell-hook)))
|
||||
|
||||
;; To avoid MuMaMo to discard `ein:notebook-mode', make it
|
||||
;; permanent local.
|
||||
(put 'ein:notebook-minor-mode 'permanent-local t)
|
||||
(put 'ein:notebook-mode 'permanent-local t)
|
||||
|
||||
(define-derived-mode ein:notebook-plain-mode fundamental-mode "ein:notebook"
|
||||
"IPython notebook mode without fancy coloring."
|
||||
|
|
|
@ -30,9 +30,12 @@
|
|||
(require 'ein-core)
|
||||
(require 'ein-events)
|
||||
(require 'view)
|
||||
(require 'ess-help nil t)
|
||||
|
||||
;; FIXME: Make a class with `:get-notebook-name' slot like `ein:worksheet'
|
||||
|
||||
(declare-function ess-help-underline "ess-help")
|
||||
|
||||
(defun ein:pager-new (name events)
|
||||
;; currently pager = name.
|
||||
(ein:pager-bind-events name events)
|
||||
|
@ -63,6 +66,8 @@
|
|||
(defun ein:pager-append-text (pager text)
|
||||
(ein:with-read-only-buffer (get-buffer-create pager)
|
||||
(insert (ansi-color-apply text))
|
||||
(if (featurep 'ess-help)
|
||||
(ess-help-underline))
|
||||
(unless (eql 'ein:pager-mode major-mode)
|
||||
(ein:pager-mode))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue