From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: c-ts-mode Date: Thu, 7 Sep 2023 23:01:58 +0100 Message-ID: References: <5F73CB5D-DB00-439F-AD7C-7E209EC83A35@gmail.com> <83jzt2z5mk.fsf@gnu.org> <83y1hhykni.fsf@gnu.org> <877cp1lvih.fsf@gmail.com> <83v8clyhqi.fsf@gnu.org> <83tts5ygv2.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9103"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com, spacibba@aol.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 08 00:03:21 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qeN5s-00028S-IS for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Sep 2023 00:03:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeN4s-0000Sg-MN; Thu, 07 Sep 2023 18:02:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeN4q-0000SN-GP for emacs-devel@gnu.org; Thu, 07 Sep 2023 18:02:16 -0400 Original-Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeN4n-0008B6-BZ; Thu, 07 Sep 2023 18:02:15 -0400 Original-Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bcde83ce9fso24827721fa.1; Thu, 07 Sep 2023 15:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694124130; x=1694728930; darn=gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZtrH60hw1HOZovSWh2qYvjU5YDyxSm+Q8sZHjYqbZy8=; b=U0xEm4kpC50Vp5HAu1w97BTzhAMxVQq1xKxGGm/T2DAnai6X56jvBX3RU9HZDR+Mac Fyt9/tA0v2V27dXBW940lIuvcsBu1esbVD7wHMiYWCHXt8ch8mC22SIgb7zHW3r6C8lh IC9JCS6QYYi0iAoRjaj2OiGN5cStg55EvjnX+mgoWYNK62XlVz3jAteA886GDujzkv/l MGqrZ4puyQeJPtfm6kpmFk7bPBTS3Vht/+RStIkKPlWM16YgRxrl8Bd4rbNIGmQSr2O+ Ayrm6nUbdCOxnRU4tQ4pTAuz8Oaj+UR+OdGtiMfQUhg4/koh7g6cwX77SMV7fQHDcy9K oMDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694124130; x=1694728930; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZtrH60hw1HOZovSWh2qYvjU5YDyxSm+Q8sZHjYqbZy8=; b=sCa5jdSOdbfDU4nHv9NOcuSmOv2SgwUbS4FALyJRhrop8eHw/6ycjWSh40cEW8hDpD GuqPAghJgOqX8Gep5CBIrHrZy9hrWQmp6NPxy6b4hquJQE2O5BhrQfwEBFhP9SPp3BdX LqhBB8BVYsJ2coTW8lJT1MT+Yoo/c3H2Gm0yLUL4qOGysqkCNbFtG44xpksOV5MxqvpQ OTutprKVVsJs4OowJx65GC1zlYnI+20TjeE2HxBHSG45NIy5bMOXztp2xJ6m9ItIKj6o 59uhaSZn4BMSDAn0ta+PA9QkF5E+j7VCAge9eiDG8ih8V6T/j8L7mO9IA5SVgE69BeVx DsFQ== X-Gm-Message-State: AOJu0YzkT3iVWEhhH5EHJRZjBOZ+m/leQLka4lta6CrssJIxPWKPdIiI Vx76Ph2idU+V0KpD9DyxMo9wAp1TZC9jslq533+yhFshxW3dIQ== X-Google-Smtp-Source: AGHT+IHBd21+wkahMdRiNWqk2wHDnQwdGATfY6iUqF/z9/SASwtoWMYGCh/Vb4XmGtbykeJDs0R+0mDt9fY+xlpnLFo= X-Received: by 2002:a2e:3c18:0:b0:2bd:1615:f9f8 with SMTP id j24-20020a2e3c18000000b002bd1615f9f8mr342912lja.45.1694124130055; Thu, 07 Sep 2023 15:02:10 -0700 (PDT) In-Reply-To: <83tts5ygv2.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::22f; envelope-from=joaotavora@gmail.com; helo=mail-lj1-x22f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310287 Archived-At: On Thu, Sep 7, 2023 at 7:32=E2=80=AFPM Eli Zaretskii wrote: > > > From: Jo=C3=A3o T=C3=A1vora > > 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=C3=A3o