all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Filippo Argiolas <filippo.argiolas@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: spacibba@aol.com, emacs-devel@gnu.org, casouri@gmail.com
Subject: Re: A few questions about c++-ts-mode.
Date: Mon, 13 May 2024 08:23:55 +0200	[thread overview]
Message-ID: <CAOdrLG+z90M356dfmOr=mZV4LtpPEGjksOgscmAYFOQAAWog-A@mail.gmail.com> (raw)
In-Reply-To: <86cypv8rb6.fsf@gnu.org>

On Thu, May 9, 2024 at 7:53 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Filippo Argiolas <filippo.argiolas@gmail.com>
> > Date: Thu, 9 May 2024 07:34:58 +0200
> > Cc: Ergus <spacibba@aol.com>, emacs-devel@gnu.org, casouri@gmail.com
> >
> > > If the only solution is language injection, then doing that our usual
> > > way (with regexps etc.) is easier and more flexible.  I thought I saw
> > > some commits in the C++ grammar that actually support that in the
> > > grammar itself.  If there is such support, we should use it, IMO.
> > >
> >
> > Sorry to intrude, may I ask what's the problem with language
> > injection? it seems the perfect use case for this.
>
> I didn't say there was a problem, I said that doing it with regexp
> etc. would be easier and more flexible.
>
> Language injection AFAIU requires an additional grammar library, which
> means someone must compile it, the end-user must ensure it's
> installed, etc.  IOW, it makes the disadvantages of tree-sitter more
> prominent, for the benefit of a very minor feature.  From where I
> stand, that makes the balance tip in favor of the simpler solution,
> which users could more easily activate and customize.

I know you disagree with this path, and I tend to agree, but a little
experimenting I guess won't hurt.
I did some experiment to see how really easy and flexible this would
be with current code and language injections.
It's pretty basic but I must say I'm pretty pleased about how easy
this was. Tree-sitter is really powerful and nice to work with.
Still not happy about the faces I'm using but it's a start.
Grammars are from [1] for doxygen and [2] for printf format strings.

(defvar fa/ts-font-lock-settings
  (treesit-font-lock-rules
   :language 'printf
   :feature 'format
   :override 'prepend
   '((format) @font-lock-constant-face)
   :language 'doxygen
   :feature 'doxy
   :override 'prepend
   '((tag_name) @font-lock-doc-markup-face
     (brief_header) @font-lock-doc-face
     (storageclass) @font-lock-keyword-face
     (type) @font-lock-type-face
     (identifier) @font-lock-variable-name-face
     (function_link) @font-lock-function-name-face
     (link) @link
     (emphasis) @bold
     (code_block (code_block_content) @default)
     (code_word (code) @default)
     ((tag_name) @bold (:match ".note" @bold))
     ((tag_name) @warning (:match ".warning" @warning))
     ((tag_name) @error (:match ".error" @error)))
))

(add-hook 'c-ts-mode-hook
          (lambda () (setq-local treesit-font-lock-settings
                 (append treesit-font-lock-settings
                     fa/ts-font-lock-settings))))
(defvar fa/ts-range-settings
  (treesit-range-rules
   :embed 'printf
   :local t
   :host 'c
   '((call_expression (argument_list (string_literal (string_content)
@capture))))
   :embed 'doxygen
   :local t
   :host 'c
   '(((comment) @capture (:match "/\\*[\\*!]" @capture)))))

(add-hook 'c-ts-mode-hook
          (lambda ()
            (setq-local treesit-range-settings (append treesit-range-settings
                                                       fa/ts-range-settings))))

1. https://github.com/tree-sitter-grammars/tree-sitter-doxygen
2. https://github.com/pstuifzand/tree-sitter-printf



  parent reply	other threads:[~2024-05-13  6:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fakigaygsqcunvvbm2zscn7qlkxi234f574ul3hl5vrhymm22k.ref@syjmsievkpp3>
2024-05-07 22:59 ` A few questions about c++-ts-mode Ergus
2024-05-08  0:19   ` Yuan Fu
2024-05-08  1:26     ` Ergus
2024-05-09  4:29       ` Yuan Fu
2024-05-09  6:18         ` Filippo Argiolas
2024-05-12 20:11         ` Ergus
2024-05-08 13:35     ` Eli Zaretskii
2024-05-08 21:05       ` Ergus
2024-05-09  0:16         ` Yuan Fu
2024-05-09  5:17           ` Eli Zaretskii
2024-05-09  5:03         ` Eli Zaretskii
2024-05-09  5:34           ` Filippo Argiolas
2024-05-09  5:53             ` Eli Zaretskii
2024-05-09  6:11               ` Filippo Argiolas
2024-05-09  7:03                 ` Eli Zaretskii
2024-05-13  6:23               ` Filippo Argiolas [this message]
2024-05-13  8:10                 ` Filippo Argiolas

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

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

  git send-email \
    --in-reply-to='CAOdrLG+z90M356dfmOr=mZV4LtpPEGjksOgscmAYFOQAAWog-A@mail.gmail.com' \
    --to=filippo.argiolas@gmail.com \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=spacibba@aol.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.