From: "João Távora" <joaotavora@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: casouri@gmail.com, spacibba@aol.com, emacs-devel@gnu.org
Subject: Re: c-ts-mode
Date: Thu, 7 Sep 2023 23:01:58 +0100 [thread overview]
Message-ID: <CALDnm50Dn6K0UHrsg+pROKW+3i8HV5mAcJdVdkzDEfp79oVeCQ@mail.gmail.com> (raw)
In-Reply-To: <83tts5ygv2.fsf@gnu.org>
On Thu, Sep 7, 2023 at 7:32 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: João Távora <joaotavora@gmail.com>
> > Date: Thu, 7 Sep 2023 19:23:33 +0100
> > Cc: casouri@gmail.com, spacibba@aol.com, emacs-devel@gnu.org
> >
> > The real challenge is writing the rules themselves. I'm missing
> > a kind of "debug rule" that doesn't do anything but prints out
> > contextual information from the node, parent-node, grandparents.
> > I made one but it's not very good. Is there something like that?
> > Wouldn't even need to be an indentation rule, more like a "describe
> > AST at point"...
>
> Did you try "M-x treesit-explore-mode RET"?
That's a great find, and so is M-x treesit-inspect-mode.
My rules are now done.
(setq c-ts-mode-indent-style
(lambda ()
(append '(((n-p-gp nil nil "namespace_definition") grand-parent 0)
((n-p-gp nil nil "linkage_specification") grand-parent 0))
(alist-get 'gnu (c-ts-mode--indent-styles 'cpp)))))
The lambda, cl-list*, the alist-get and the '--' are ugly but
beyond that, it's better than cc-mode's system, to be honest.
Anyway, to get the ugly out, here's an idea.
IMHO making c-ts-mode--indent-styles a public CL-style
generic function would be a good possibility.
It's a simple patch to allow that.
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 5f685e016d2..337c8c4eed1 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -165,9 +165,12 @@ c-ts-mode--get-indent-style
(let ((style
(if (functionp c-ts-mode-indent-style)
(funcall c-ts-mode-indent-style)
- (alist-get c-ts-mode-indent-style
(c-ts-mode--indent-styles mode)))))
+ (c-ts-mode-indent-styles c-ts-mode-indent-style mode))))
`((,mode ,@style))))
+(cl-defgeneric c-ts-mode-indent-styles (style mode)
+ (alist-get style (c-ts-mode--indent-styles mode)))
+
(defun c-ts-mode--prompt-for-style ()
"Prompt for an indent style and return the symbol for it."
(let ((mode (if (derived-mode-p 'c-ts-mode) 'c 'c++)))
With this patch, my rules become:
(cl-defmethod c-ts-mode-indent-styles ((_style (eql gnu)) (_m (eql cpp)))
(append '(((n-p-gp nil nil "namespace_definition") grand-parent 0)
((n-p-gp nil nil "linkage_specification") grand-parent 0))
(cl-call-next-method)))
Or maybe just
(cl-defmethod c-ts-mode-indent-styles (_style (_m (eql cpp)))
(append '(((n-p-gp nil nil "namespace_definition") grand-parent 0)
((n-p-gp nil nil "linkage_specification") grand-parent 0))
(cl-call-next-method)))
if I would like them to apply to other non-gnu styles, too.
A defcustom-style thing for customize lovers can also be added,
later for people that don't like defgeneric. Seems like a pretty
large DSL to code up in customize, though.
João
next prev parent reply other threads:[~2023-09-07 22:01 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <r6t7xfcchagyl72ltdrcavncbpvba7badcoh4yimleoynmzfvb.ref@elkspm3vozuv>
2023-08-30 23:52 ` c-ts-mode Ergus
2023-09-01 4:14 ` c-ts-mode Yuan Fu
2023-09-07 9:25 ` c-ts-mode João Távora
2023-09-07 9:37 ` c-ts-mode Eli Zaretskii
2023-09-07 15:58 ` c-ts-mode João Távora
2023-09-07 17:10 ` c-ts-mode Eli Zaretskii
2023-09-07 17:53 ` c-ts-mode João Távora
2023-09-07 18:13 ` c-ts-mode Eli Zaretskii
2023-09-07 18:23 ` c-ts-mode João Távora
2023-09-07 18:32 ` c-ts-mode Eli Zaretskii
2023-09-07 22:01 ` João Távora [this message]
2023-09-08 6:14 ` c-ts-mode Eli Zaretskii
2023-09-08 7:25 ` c-ts-mode João Távora
2023-09-08 11:25 ` c-ts-mode Eli Zaretskii
2023-09-08 12:38 ` c-ts-mode João Távora
2023-09-08 13:11 ` c-ts-mode Eli Zaretskii
2023-09-08 13:32 ` c-ts-mode Eli Zaretskii
2023-09-08 15:15 ` c-ts-mode João Távora
2023-09-08 15:34 ` c-ts-mode Eli Zaretskii
2023-09-08 15:56 ` c-ts-mode João Távora
2023-09-08 18:23 ` c-ts-mode Eli Zaretskii
2023-09-08 18:30 ` c-ts-mode João Távora
2023-09-08 18:54 ` c-ts-mode Eli Zaretskii
2023-09-08 19:42 ` c-ts-mode João Távora
2023-09-09 6:09 ` c-ts-mode Eli Zaretskii
2023-09-08 19:58 ` c-ts-mode Petteri Hintsanen
2023-09-08 20:27 ` c-ts-mode João Távora
2023-09-09 6:19 ` c-ts-mode Eli Zaretskii
2023-09-13 16:15 ` c-ts-mode Petteri Hintsanen
2023-09-12 0:34 ` c-ts-mode Yuan Fu
2023-09-12 7:45 ` c-ts-mode João Távora
2023-09-12 8:00 ` c-ts-mode Po Lu
2023-09-12 9:51 ` c-ts-mode João Távora
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=CALDnm50Dn6K0UHrsg+pROKW+3i8HV5mAcJdVdkzDEfp79oVeCQ@mail.gmail.com \
--to=joaotavora@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.