From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Steinar Bang Newsgroups: gmane.emacs.help Subject: Re: JavaScript/TypeScript: What do people in 2024, on emacs 29, use for .js, .jsx, .ts and .tsx? Date: Fri, 14 Jun 2024 18:04:08 +0200 Message-ID: <87zfrncxzb.fsf@dod.no> References: <77493010-0b8f-4173-88ed-e726b89a3fad@gutov.dev> <87v8816txt.fsf@dod.no> <877ckd7kr6.fsf@dod.no> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20525"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 14 18:05:17 2024 Return-path: Envelope-to: geh-help-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 1sI9QR-00055r-S3 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 14 Jun 2024 18:05:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sI9Pj-00043k-JY; Fri, 14 Jun 2024 12:04:31 -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 1sI9Pg-00043L-Mt for help-gnu-emacs@gnu.org; Fri, 14 Jun 2024 12:04:29 -0400 Original-Received: from schwantz.bang.priv.no ([95.217.129.251]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sI9Pd-0006So-W3 for help-gnu-emacs@gnu.org; Fri, 14 Jun 2024 12:04:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dod.no; s=sb; t=1718381049; bh=AQ8AWFHvO2V5Om7hqWYmgEz772yJXHjpwcE+KYRbzcA=; h=From:To:Subject:In-Reply-To:References:Date:From; b=IpXebbQpZARCjAkJTnOITpyJ73dcOhBHtWqIWEalx5RhLLtSxHU3nhw0NhGNvoiNC C7rSOsWlaPpUuoJWLeA9Py5sN3VqVZ65r6WMpHKavYXJhvtSx/+C9AsI29F1l1goxa pZ6BfxkRSx5oJyNJjUJIaFMHSmofMQimlcRtkQqo= Original-Received: from marquez (unknown [84.210.69.52]) by schwantz.bang.priv.no (Postfix) with ESMTPSA id 39C55987 for ; Fri, 14 Jun 2024 16:04:09 +0000 (UTC) In-Reply-To: (Dmitry Gutov's message of "Sun, 14 Jan 2024 23:00:04 +0200") Received-SPF: none client-ip=95.217.129.251; envelope-from=sb@dod.no; helo=schwantz.bang.priv.no X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:146893 Archived-At: A short update 6 months after the previous posting on this thread. I installed emacs 29.3 from debian backports on the current debian stable (12.5 "bookworm"). 29.3 has tree-sitter support built in, and in the debian package, linked in (in the form of https://packages.debian.org/bookworm/libtree-sitter0 ) You can list the available built-in supported (or "potentially supported") tree-sitter language modes with: 'C-h a ts-mode RET' What you need in addition to emacs and the above library, are .so files containing tree-sitter parsers for the various languages. If you use the interactive commands in emacs, the parsers will be downloaded and built and placed into ~/.emacs.d/tree-sitter/. Here is my ~/.emacs.d/tree-sitter/ directory: /home/sb/.emacs.d/tree-sitter: drwxr-xr-x 2 sb sb 4096 Jun 8 20:25 . drwx------ 7 sb sb 4096 Jun 14 00:14 .. -rwxr-xr-x 1 sb sb 95512 Jun 8 20:25 libtree-sitter-css.so -rwxr-xr-x 1 sb sb 382736 Jun 4 22:54 libtree-sitter-javascript.so -rwxr-xr-x 1 sb sb 524000 Jun 4 22:53 libtree-sitter-java.so -rwxr-xr-x 1 sb sb 4113952 Jun 8 20:13 libtree-sitter-kotlin.so -rwxr-xr-x 1 sb sb 2286424 Jun 8 18:40 libtree-sitter-tsx.so -rwxr-xr-x 1 sb sb 2224840 Jun 8 18:40 libtree-sitter-typescript.so The css, javascript, java and kotlin .so files, I compiled using the command: 'M-x treesit-install-language-grammar RET RET' The command will clone the .so repo to a temp directory, build the .so and move it to ~/.emacs.d/tree-sitter/ However the treesit-install-language-grammar command failed on the typescript repo, which actually contains two separate tree-sitter parsers, the typescript parser and the tsx parser. So for typescript and tsx I had to clone the repo and build with make from the top and then copy over the resulting .so files. Activating the tree-sitter modes is done with the following addition to ~/.emacs: https://gist.github.com/steinarb/10f5bfb968295ccbef298c67b1f28e9a Where there is an existing non-ts mode, I have used major-mode-remap-alist to replace it (then the ts version of the mode will replace all of the language extension triggerings of the original). Where there is no existing non-ts mode (i.e. typescript and tsx) I use auto-mode-alist in the time tested way. The treesit-language-available-p will test true if the tree-sitter mode for the language is available and has a tree-sitter .so available. As for the current state of the tree-sitter based modes they currently only seem to do syntax highlighting and indentation (but they do so very fast and stable). But what I read from this commit https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=c79a509384d33dab6a964ef9a97cbc9a1f1b5bf7 is that perhaps the ts-modes are based on their non-ts alternatives, so that, maybe, just maybe, everything available in the non-ts-mode will also be available in the ts-mode...? Turning back to typescript: please note that as the tree-sitter parsers for typescript and tsx are separate, so are the language modes (different modes bound to .ts and tsx files).