emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: outline-mode treesitter support?


From: Juri Linkov
Subject: Re: outline-mode treesitter support?
Date: Wed, 20 Dec 2023 19:08:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]