Add simple imenu support in notebook buffer

It concerns only heading cells.
This commit is contained in:
Takafumi Arakaki 2012-07-20 17:16:03 +02:00
parent 2154742c45
commit b228a312e5
2 changed files with 19 additions and 0 deletions

View file

@ -145,6 +145,7 @@ Called via `ein:notebook-mumamo-mode-hook'."
;; "Sync" `ein:notebook-mumamo-mode-map' with `ein:notebook-mode-map'.
(setcdr ein:notebook-mumamo-mode-map (cdr ein:notebook-mode-map))
(add-hook 'ein:notebook-mumamo-mode-hook 'ein:notebook-imenu-setup)
(add-hook 'ein:notebook-mumamo-mode-hook 'ein:notebook-setup-kill-buffer-hook)
(add-hook 'ein:notebook-mumamo-mode-hook
'ein:mumamo-indent-line-function-workaround-turn-on)

View file

@ -1148,6 +1148,20 @@ as usual."
(ein:kernel-kill kernel close-notebook (list ein:notebook))
(funcall close-notebook ein:notebook)))))
;;; Imenu
(defun ein:notebook-imenu-create-index ()
"`imenu-create-index-function' for notebook buffer."
(loop for cell in (ein:filter #'ein:headingcell-p
(ein:notebook-get-cells ein:notebook))
collect (cons (ein:cell-get-text cell)
(ein:cell-location cell :input))))
(defun ein:notebook-imenu-setup ()
"Called via notebook mode hooks."
(setq imenu-create-index-function #'ein:notebook-imenu-create-index))
;;; Notebook mode
@ -1237,9 +1251,13 @@ Do not use `python-mode'. Use plain mode when MuMaMo is not installed::
"IPython notebook mode without fancy coloring."
(font-lock-mode))
(add-hook 'ein:notebook-plain-mode-hook 'ein:notebook-imenu-setup)
(define-derived-mode ein:notebook-python-mode python-mode "ein:python"
"Use `python-mode' for whole notebook buffer.")
(add-hook 'ein:notebook-python-mode-hook 'ein:notebook-imenu-setup)
;; "Sync" `ein:notebook-plain-mode-map' with `ein:notebook-mode-map'.
;; This way, `ein:notebook-plain-mode-map' automatically changes when
;; `ein:notebook-mode-map' is changed.