From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier 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: Wed, 25 Jan 2023 16:16:33 -0500 Message-ID: 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> <833580ipdo.fsf@gnu.org> <87lelq8jay.fsf@thornhill.no> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18959"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: eliz@gnu.org, 60983@debbugs.gnu.org, casouri@gmail.com To: Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 25 22:17:29 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 1pKn96-0004f0-Ud for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Jan 2023 22:17:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKn8t-0000JJ-5Q; Wed, 25 Jan 2023 16:17:16 -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 1pKn8h-0000J4-5u for bug-gnu-emacs@gnu.org; Wed, 25 Jan 2023 16:17:03 -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 1pKn8g-0000Rb-U3 for bug-gnu-emacs@gnu.org; Wed, 25 Jan 2023 16:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pKn8g-00064I-AZ for bug-gnu-emacs@gnu.org; Wed, 25 Jan 2023 16:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Jan 2023 21:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60983 X-GNU-PR-Package: emacs X-Debbugs-Original-Cc: Eli Zaretskii , bug-gnu-emacs@gnu.org, casouri@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.167468141223307 (code B ref -1); Wed, 25 Jan 2023 21:17:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Jan 2023 21:16:52 +0000 Original-Received: from localhost ([127.0.0.1]:60099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKn8V-00063q-UF for submit@debbugs.gnu.org; Wed, 25 Jan 2023 16:16:52 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:59454) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKn8S-00063h-Gu for submit@debbugs.gnu.org; Wed, 25 Jan 2023 16:16:50 -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 1pKn8R-0000Gk-Vp for bug-gnu-emacs@gnu.org; Wed, 25 Jan 2023 16:16:48 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKn8P-0000QG-Rr; Wed, 25 Jan 2023 16:16:47 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6404D443A9C; Wed, 25 Jan 2023 16:16:43 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 7CFB8443A96; Wed, 25 Jan 2023 16:16:34 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1674681394; bh=QadmvehcZN1ubl00G1mbBXSwt0Yw9gpm57p3kWIImLI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=mCybwPcnWILJSz6cPyKyfWYOFA/AAFbcQFIgdbWktXDzhpPLInScG6ZaufyIlpg4N CLVOdjRGvf7NId+9xbn06yZRNoAZRv8TBPAk7T5ZTr+EGK+SWSnMTDOjD3tIUv67G2 ISob4q8wICHseUh8Of+Yz7vIPhFvJRTs9MEWRGAtHTmULE3Qow6GrMgCA8HCsZFmgY pRpfi0XK1NfJ6a/AoiSOq0Kp11m0nI1lMqlluVwdy1tvybtMD3kG2G7taW8PGleW4Z 8ZVrNaZ1648gJj8dCAO3VY3myHh0NjdGPzQTlSbl1hxaX1oaRoFGCzbetXarKuiedz tmzJBYnJWV9LQ== Original-Received: from pastel (unknown [45.72.216.69]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 522AE122514; Wed, 25 Jan 2023 16:16:34 -0500 (EST) In-Reply-To: <87lelq8jay.fsf@thornhill.no> (Theodor Thornhill's message of "Wed, 25 Jan 2023 21:12:53 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:254155 Archived-At: > -(defcustom c-ts-mode-indent-style 'gnu > +(defcustom c-ts-mode-indent-style "gnu" > "Style used for indentation. > > The selected style could be one of GNU, K&R, LINUX or BSD. If > @@ -100,13 +100,33 @@ c-ts-mode-indent-style > set instead. This function is expected return a list that > follows the form of `treesit-simple-indent-rules'." > :version "29.1" > - :type '(choice (symbol :tag "Gnu" 'gnu) > - (symbol :tag "K&R" 'k&r) > - (symbol :tag "Linux" 'linux) > - (symbol :tag "BSD" 'bsd) > + :type '(choice (string :tag "Gnu" "gnu") > + (string :tag "K&R" "k&r") > + (string :tag "Linux" "linux") > + (string :tag "BSD" "bsd") > (function :tag "A function for user customized style" ignore)) > + :set #'c-ts-mode--indent-style > :group 'c) Why change to strings? BTW the previous code seems wrong: instead of (symbol :tag "FOO" 'foo) it should be (symbol :tag "FOO" foo) since `'foo` is not a symbol but a list (of two symbols). > +(defun c-ts-mode--indent-style (sym val) > + "Custom setter for `c-ts-mode-indent-style'." > + (set-default sym val)) Hmm... why bother use a `:set`ter if it doesn't do anything more than the default does? Shouldn't it call `treesit--indent-rules-optimize` to (re)set `treesit-simple-indent-rules`? [ Presumably in all relevant buffers, since the defcustom setting is global. ] > +(defun c-ts-mode-set-style () > + (interactive) > + (or (eq major-mode 'c-ts-mode) (eq major-mode 'c++-ts-mode) > + (error "Buffer %s is not a c-ts-mode (c-ts-mode-set-style)" > + (buffer-name))) > + (if-let ((mode (cond ((eq major-mode 'c-ts-mode) 'c) > + ((eq major-mode 'c++-ts-mode) 'cpp) > + (t nil))) > + (choice (completing-read "Select style: " '("gnu" "k&r" "linux" "bsd")))) Here, we probably want to specify `must-match` to `completing-read` (which makes it unnecessary to check `if-let`, I think) and we should provide a default. Also we should probably use the (c-ts-mode--indent-styles mode) alist rather than hardcode the set of styles. > + (c-ts-mode--indent-style 'c-ts-mode-indent-style choice) > + (kill-local-variable 'treesit-simple-indent-rules) > + (setq-local treesit-simple-indent-rules > + (treesit--indent-rules-optimize > + (c-ts-mode--set-indent-style mode))))) Here we presumably want to do the (setq-local treesit-simple-indent-rules ...) every time (and set `c-ts-mode-indent-style` buffer locally rather than via `c-ts-mode--indent-style`, or otherwise provide an additional arg to `c-ts-mode--indent-style` to say whether it applies globally or only to the current buffer). BTW, the naming of `c-ts-mode--indent-style` and `c-ts-mode--set-indent-style` is confusing. Also: why `kill-local-variable` just before the `setq-local`? > - (pcase c-ts-mode-indent-style > - ('gnu (alist-get 'gnu (c-ts-mode--indent-styles mode))) > - ('k&r (alist-get 'k&r (c-ts-mode--indent-styles mode))) > - ('bsd (alist-get 'bsd (c-ts-mode--indent-styles mode))) > - ('linux (alist-get 'linux (c-ts-mode--indent-styles mode))))))) > + (alist-get c-ts-mode-indent-style > + (c-ts-mode--indent-styles mode) nil nil #'equal)))) Thanks :-) Stefan