From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Filippo Argiolas Newsgroups: gmane.emacs.devel Subject: Re: A few questions about c++-ts-mode. Date: Mon, 13 May 2024 08:23:55 +0200 Message-ID: References: <865xvoa0jr.fsf@gnu.org> <86jzk38tm7.fsf@gnu.org> <86cypv8rb6.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="22520"; mail-complaints-to="usenet@ciao.gmane.io" Cc: spacibba@aol.com, emacs-devel@gnu.org, casouri@gmail.com To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 13 08:25:12 2024 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 1s6P7Y-0005cg-9e for ged-emacs-devel@m.gmane-mx.org; Mon, 13 May 2024 08:25:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6P6f-0003NI-RO; Mon, 13 May 2024 02:24:19 -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 1s6P6a-0003Mw-AN for emacs-devel@gnu.org; Mon, 13 May 2024 02:24:12 -0400 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s6P6Y-0002vc-9w; Mon, 13 May 2024 02:24:11 -0400 Original-Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ee42b97b32so31512895ad.2; Sun, 12 May 2024 23:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715581447; x=1716186247; 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=wvyRiJhaXvJ9ynh8YgPYSB5IPN9d+F9qSYqH6RO3kSI=; b=CQurnIZKUCUzuJoeIDvm5IL8tZ7MRm/KbQrK6egdNIHUp8r1N8XntqcmXZ9cEm0DxP nnLYbAu4AE0kifBhZYFdJ2JEDn7Gw5INhLlF3S/UxWV+tz38TVvWi/nw7zlUyqt2LRBp HFd+Ck4s90R1vl2GqOlP1n+ocUzfSad9vCTlqSl2S5olkMNtxRii/g8Gs9u+yUnptwbC qisgy1nAq8Yg3tD4bCIQTo9Iq03Sq4umRspzLogKzUK0zVyWjzW4KSv8HTZ8JisPt/c/ nivviZeEOIWaJcDbkCsEccjh662sTTG2ORWd/D9KNgQHe6DR/6OVWdtUezXatE1P+9P6 +O2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715581447; x=1716186247; 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=wvyRiJhaXvJ9ynh8YgPYSB5IPN9d+F9qSYqH6RO3kSI=; b=j29rBALtsUXM9IB6t3rdqEMIgBmqvfsKs4J9zx5+rwMUsJ4aMCQ37aLwDL7A1En7GD zePlECDMdWpS1saQoHDzDVYdLCxes+gb3esmD4hvhI3EC+q42EtBcdfyxA8HJUzm/OFY r+93JlS67l5yR3VTE0+GjJIzxWOcHaw4JXO6BY95+OgoWxvv0vJn8Lboqj7TY6akFvbM /h76NqkEXbMYrB2jsWwZLAE6qpGc5dkDV3fcKxnBBLJ97WuHj94AYf217M61GgIG9ho5 CBrpdJbV3/VFqKf/G79AR5IcoM1O4xux0LHyH8qfFt2FA7n7bFL50ktKft56DtPYMh5V 0ZmQ== X-Forwarded-Encrypted: i=1; AJvYcCWGn09f+jnag92sdmk0MREptu+Sl308hi+U72ZnKaa4Ygmzcsh33rP3lNga1bxfdmYmVDOKaFan+ZHTXmCdy+WTlWOw X-Gm-Message-State: AOJu0YyTzWA0HSjzq6NgIEF5br21mriW4OKBY8Mc5zYHTY/mO8sXn3O7 itAGBT1vOq9yfPNwjoPehLwuV0DNkVn0bEU1cMxnO/c5arl4w99huU4mVC1/wByGFQt5iGMvqUK ClmpRBOBbrH7Z5rZmDfD7AQc+o9vI6bgw X-Google-Smtp-Source: AGHT+IEc5LYlxC2de2F/OKc6USoy8hGN5XqZdVgm8AvlCQsAExjZOvf9WkS1NwcF620Lx17wHnlw+05Q0k0crNxM1FE= X-Received: by 2002:a17:90b:3650:b0:2b2:88f7:1f7f with SMTP id 98e67ed59e1d1-2b6cc56490fmr7691074a91.10.1715581446668; Sun, 12 May 2024 23:24:06 -0700 (PDT) In-Reply-To: <86cypv8rb6.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=filippo.argiolas@gmail.com; helo=mail-pl1-x62e.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:319196 Archived-At: On Thu, May 9, 2024 at 7:53=E2=80=AFAM Eli Zaretskii wrote: > > > From: Filippo Argiolas > > Date: Thu, 9 May 2024 07:34:58 +0200 > > Cc: Ergus , 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-settin= gs fa/ts-range-settings= )))) 1. https://github.com/tree-sitter-grammars/tree-sitter-doxygen 2. https://github.com/pstuifzand/tree-sitter-printf