unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Huan Nguyen <nguyenthieuhuan@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: emacs-devel@gnu.org
Subject: Re: outline-mode treesitter support?
Date: Thu, 21 Dec 2023 05:03:03 +0100	[thread overview]
Message-ID: <41ED492A-0520-49CE-BA9F-35085BEFEDEF@gmail.com> (raw)
In-Reply-To: <864jgc94yp.fsf@mail.linkov.net>



> 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!


  reply	other threads:[~2023-12-21  4:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 11:43 outline-mode treesitter support? Huan Nguyen
2023-12-19 13:00 ` Eli Zaretskii
2023-12-19 13:25   ` Huan Nguyen
2023-12-19 13:42     ` Eli Zaretskii
2023-12-19 17:14 ` Juri Linkov
2023-12-19 18:31   ` Huan Nguyen
2023-12-20  7:50     ` Juri Linkov
2023-12-20 17:08       ` Juri Linkov
2023-12-21  4:03         ` Huan Nguyen [this message]
2024-01-10  7:19           ` Juri Linkov
2024-01-24 17:23             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41ED492A-0520-49CE-BA9F-35085BEFEDEF@gmail.com \
    --to=nguyenthieuhuan@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).