mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 17:11:41 -05:00
Imenu items can now include markdown cells that look like headings.
This commit is contained in:
parent
00a4af6857
commit
55a522c806
2 changed files with 29 additions and 5 deletions
|
@ -203,6 +203,21 @@ a number will limit the number of lines in a cell output."
|
|||
(insert-image img ".")))
|
||||
(error (ein:log 'warn "Could not insert image: %s" err) nil)))
|
||||
|
||||
(defun ein:cell--markdown-heading-p (cell)
|
||||
"Check if cell is behaving like a heading cell.
|
||||
|
||||
Returns true if cell is a markdown cell, has at least one # character at the start of the line and is only one line long (i.e. does not contain any newline characters)."
|
||||
(and (ein:markdowncell-p cell)
|
||||
(string-match "^#+ " (ein:cell-get-text cell))
|
||||
(= 0 (seq-count #'(lambda (c)
|
||||
(char-equal c ?\n))
|
||||
(ein:cell-get-text cell)))))
|
||||
|
||||
(cl-defmethod ein:cell--markdown-heading-level ((cell ein:markdowncell))
|
||||
(progn
|
||||
(string-match "^#+" (ein:cell-get-text cell))
|
||||
(match-end 0)))
|
||||
|
||||
|
||||
;;; Cell factory
|
||||
|
||||
|
@ -227,6 +242,7 @@ a number will limit the number of lines in a cell output."
|
|||
(defun ein:cell-from-type (type &rest args)
|
||||
(apply (ein:cell-class-from-type type) args))
|
||||
|
||||
|
||||
(defun ein:cell--determine-cell-type (json-data)
|
||||
(let ((base-type (plist-get json-data :cell_type))
|
||||
(metadata (plist-get json-data :metadata)))
|
||||
|
|
|
@ -1326,12 +1326,20 @@ function."
|
|||
;; As Imenu does not provide the way to represent level *and*
|
||||
;; position, use #'s to do that.
|
||||
(cl-loop for cell in (when (ein:worksheet-p ein:%worksheet%)
|
||||
(seq-filter #'ein:headingcell-p
|
||||
(seq-filter #'(lambda (cell) (or (ein:headingcell-p cell)
|
||||
(ein:cell--markdown-heading-p cell)))
|
||||
(ein:worksheet-get-cells ein:%worksheet%)))
|
||||
for sharps = (cl-loop repeat (slot-value cell 'level) collect "#")
|
||||
for text = (ein:cell-get-text cell)
|
||||
for name = (ein:join-str "" (append sharps (list " " text)))
|
||||
collect (cons name (ein:cell-input-pos-min cell))))
|
||||
for sharps = (if (ein:headingcell-p cell)
|
||||
(cl-loop repeat (slot-value cell 'level) collect "#")
|
||||
(cl-loop repeat(progn
|
||||
(string-match "^#+" (ein:cell-get-text cell))
|
||||
(match-end 0))
|
||||
collect "#"))
|
||||
for text = (ein:cell-get-text cell)
|
||||
for name = (if (ein:headingcell-p cell)
|
||||
(ein:join-str "" (append sharps (list " " text)))
|
||||
text)
|
||||
collect (cons name (ein:cell-input-pos-min cell))))
|
||||
|
||||
(defun ein:worksheet-imenu-setup ()
|
||||
"Called via notebook mode hooks."
|
||||
|
|
Loading…
Add table
Reference in a new issue