From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60983: 29.0.60; Tree-sitter user-level control Date: Sun, 29 Jan 2023 20:12:39 +0100 Message-ID: <87pmaxqhnc.fsf@thornhill.no> References: <83tu0kkuqo.fsf@gnu.org> <87tu0k3y6t.fsf@thornhill.no> <83mt6ckqts.fsf@gnu.org> <87zgacgiwe.fsf@thornhill.no> <834jshhvjh.fsf@gnu.org> <806A8560-A675-423F-9CFC-67D50D14E304@thornhill.no> <83y1pl79el.fsf@gnu.org> Reply-To: Theodor Thornhill 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="4501"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60983@debbugs.gnu.org To: Eli Zaretskii , Yuan Fu , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 29 20:13:16 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1pMD75-000125-2b for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 Jan 2023 20:13:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMD6x-0004Nk-JT; Sun, 29 Jan 2023 14:13:07 -0500 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 1pMD6s-0004NI-T2 for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2023 14:13:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pMD6s-0004sO-Kk for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2023 14:13:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pMD6s-0007qk-Fj for bug-gnu-emacs@gnu.org; Sun, 29 Jan 2023 14:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Jan 2023 19:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60983 X-GNU-PR-Package: emacs Original-Received: via spool by 60983-submit@debbugs.gnu.org id=B60983.167501956630147 (code B ref 60983); Sun, 29 Jan 2023 19:13:02 +0000 Original-Received: (at 60983) by debbugs.gnu.org; 29 Jan 2023 19:12:46 +0000 Original-Received: from localhost ([127.0.0.1]:45409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMD6b-0007qA-EZ for submit@debbugs.gnu.org; Sun, 29 Jan 2023 14:12:45 -0500 Original-Received: from out-58.mta0.migadu.com ([91.218.175.58]:11705) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pMD6Z-0007q1-18 for 60983@debbugs.gnu.org; Sun, 29 Jan 2023 14:12:44 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1675019561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gos7vuyU1vJeqh4HTKOThzmMMmirA6iPI+6jNd6VMLE=; b=vj5jib/9kr2TsNIIVUD9HJcYsldmLAPPj3pjEdkEVgu1jV3OtcJaEY3sEv5bxBhQ6m3nez I5E5x57/nwB8MA/9JblNVxYvXK+p5vsNm1f++sq9LAng67AIvdtzZPCYo85YVpKQmcdRgi LP5gYiC8rBgGbIS4T3EpuiL9FNOH+Ujlukw48ZhUml4oERXpqfi0jl10Q/nyM1Xfu3STAc XbSZMtzhP5zeH7CeCNU7nQp0fRiMsbJcpKZuWNksE2qVpPFJIbHKlW/FLgy0ThhPoSBAk5 CdP2nxGYlHSMomwWM9EAiJ8pyzV/rVFQnPDCYCo9CHT+ZVzoXrh/YJRFVSDWLg== In-Reply-To: <83y1pl79el.fsf@gnu.org> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:254377 Archived-At: Eli Zaretskii writes: >> From: Yuan Fu >> Date: Mon, 23 Jan 2023 15:55:30 -0800 >> Cc: Eli Zaretskii , >> Bug Report Emacs >>=20 >> >> Thanks. What about the questions I asked regarding indentation >> >> features, and specifically about c-ts-mode-indent-style? >> >=20 >> > I am working on that, but I hit some issues where I cannot make treesi= t recognize the new settings before the whole treesit-major-mode-setup reru= ns. Just setting the symbol doesn't work, and reenabling the mode inside of= the :set function isn't the best idea maybe? >> >=20 >> > I'd love some pointers to how other modes do similar stuff, but I didn= 't really find anything. >>=20 >> One common approach is to iterate over all live buffer and reset the var= iable (in this case treesit-simple-indent-rules) on applicate buffers (in t= his case c/c++-ts-mode buffers). >>=20 >> It would be nice to also have a command c-ts-mode-set-style (like c-set-= style) that takes a style symbol and sets treesit-simple-indent-rules accor= dingly. And in major-mode setup, ie, c-ts-mode=E2=80=99s body, you call it = with c-ts-mode-indent-style. > > This command now exists, courtesy of Theo, but I see some strange > misbehavior with it in c++-ts-mode, related to keymap inheritance: > > emacs -Q > M-x c-ts-mode RET > C-h c C-c C-q > =3D> C-c C-q runs the command c-ts-mode-indent-defun > > But > > M-x c++-ts-mode RET > C-h c C-c C-q > =3D> C-c C-q is undefined > > This is strange, since the binding is defined in c-ts-mode-map, which > is used in c-ts-base-mode: > > (defvar-keymap c-ts-mode-map > :doc "Keymap for the C language with tree-sitter" > :parent prog-mode-map > "C-c C-q" #'c-ts-mode-indent-defun > "C-c ." #'c-ts-mode-set-style) > > ;;;###autoload > (define-derived-mode c-ts-base-mode prog-mode "C" > "Major mode for editing C, powered by tree-sitter. > > \\{c-ts-mode-map}" > :syntax-table c-ts-mode--syntax-table > > and both c-ts-mode and c++-ts-mode derive from c-ts-base-mode: > > (define-derived-mode c-ts-mode c-ts-base-mode "C" > "Major mode for editing C, powered by tree-sitter. > > (define-derived-mode c++-ts-mode c-ts-base-mode "C++" > "Major mode for editing C++, powered by tree-sitter. > > What's missing here? Stefan, any advice? I'm sure you know this, but adding the below patch "fixes" it. It seems like the inheritance isn't registered somehow without a defined mode-map? Theo diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 612c41bf07..e9f9eea69c 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -703,6 +703,10 @@ c-ts-mode-map "C-c C-q" #'c-ts-mode-indent-defun "C-c ." #'c-ts-mode-set-style) =20 +(defvar-keymap c++-ts-mode-map + :doc "Keymap for the C++ language with tree-sitter" + :parent c-ts-mode-map) + ;;;###autoload (define-derived-mode c-ts-base-mode prog-mode "C" "Major mode for editing C, powered by tree-sitter. @@ -810,7 +814,9 @@ c++-ts-mode (add-to-list \\=3D'major-mode-remap-alist \\=3D'(c-or-c++-mode . c-or-c++-ts-mode)) =20 -in your configuration." +in your configuration. + +\\{c++-ts-mode-map}" :group 'c++ =20 (when (treesit-ready-p 'cpp)