[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: outline-mode treesitter support?
From: |
Huan Nguyen |
Subject: |
Re: outline-mode treesitter support? |
Date: |
Thu, 21 Dec 2023 05:03:03 +0100 |
> On Dec 20, 2023, at 18:08, Juri Linkov <juri@linkov.net> wrote:
>
>> OK, one way to extract treesit information for outline-minor-mode is by using
>> ‘treesit-simple-imenu’ because outline headings should correspond to imenu
>> entries.
>
> I don't know if this is a good idea, but with
>
> (setq-local outline-search-function #'outline-search-imenu
> outline-level (lambda () 1))
>
> this should do the trick:
>
> #+begin_src emacs-lisp
> (defun outline-search-imenu (&optional bound move backward looking-at)
> (unless imenu--index-alist
> (imenu--make-index-alist))
> (let* ((imenu-index (cdar imenu--index-alist))
> (imenu-positions (mapcar (lambda (i) (cdr i)) imenu-index)))
> (if looking-at
> (when (member (point-marker) imenu-positions)
> (set-match-data (list (pos-bol) (pos-eol)))
> t)
> (let ((found (if backward
> (seq-find (lambda (p) (< p (pos-bol))) (nreverse
> imenu-positions))
> (seq-find (lambda (p) (> p (pos-eol))) imenu-positions))))
> (if found
> (if (or (not bound) (if backward (>= found bound) (<= found
> bound)))
> (progn
> (goto-char found)
> (goto-char (pos-bol))
> (set-match-data (list (point) (pos-eol)))
> t)
> (when move (goto-char bound))
> nil)
> (when move (goto-char (or bound (if backward (point-min)
> (point-max)))))
> nil)))))
> #+end_src
Thanks for the example!