unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Philip Kaludercic <philipk@posteo.net>,
	monnier@iro.umontreal.ca, dgutov@yandex.ru,
	theophilusx@gmail.com, emacs-devel@gnu.org
Subject: Re: Tree-sitter introduction documentation
Date: Fri, 30 Dec 2022 16:03:42 -0800	[thread overview]
Message-ID: <FF0D4FE4-0DB6-4EFA-933C-8B8E29D179A4@gmail.com> (raw)
In-Reply-To: <83y1qo6h7a.fsf@gnu.org>



> On Dec 30, 2022, at 7:31 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Fri, 30 Dec 2022 03:06:37 -0800
>> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
>> Eli Zaretskii <eliz@gnu.org>,
>> Dmitry Gutov <dgutov@yandex.ru>,
>> theophilusx@gmail.com,
>> emacs-devel@gnu.org
>> 
>>> I have asked the question before, but freedom or not, the above is a
>>> nuisance to run for every language.  If the process is as automatic as
>>> the above example demonstrates, shouldn't Emacs have a command to take a
>>> grammar and compile+install it?  I guess this could be more complicated
>>> if the grammar is generated using a custom tool-chain for each language
>>> (or is it always Javascript?), but nothing impossible.
>> 
>> Though the magic of programming, such command now exists: treesit-install-language-grammar. It needs recipes to work, though. The recipe would involve https://github.com, which I guess is probably too heretical to include in Emacs source, so I left the recipes empty. I tested the install command with these recipes:
>> 
>> (setq treesit-language-source-alist
>>      '((python "https://github.com/tree-sitter/tree-sitter-python.git")
>>        (typescript "https://github.com/tree-sitter/tree-sitter-typescript.git"
>>                    "typescript/src" "typescript")))
> 
> Thanks.  I did some minor fixes to the doc strings, but this command
> still "needs work"(TM).  See my comments below:
> 
>  This command requires Git, a C compiler and (sometimes) a C++ compiler,
>  and the linker to be installed and on PATH.  It also requires that the
>  recipe for LANG exists in `treesit-language-source-alist'.
> 
> I don't think treesit-language-source-alist is a good idea, especially
> if we don't intend populating it, at least not as a user-facing
> feature.  Instead, the command should ask the user for the relevant
> values, and offer recording the values on some file that would be read
> next time the user wants to install an updated library.

I consider this as a fallback method for installing language grammars. Because distress might not end up bundle language grammar for us, and even if they do, they can’t cover every grammar so some user would end up needing to install some grammar by themselves. If we don’t include this feature, someone will definitely write something like this and make it a third-party package (indeed, someone already has). So we might have it in Emacs and do it right.

This is the use case that I had in mind when writing this function: some major mode xxx-mode requires language grammar for xxx, so it has the following instruction in its readme:

Add installation recipe of tree-sitter-xxx to your config, and run treesit-install-language-grammar:

(add-to-list 'treesit-language-source-alist
             '(xxx "https://github.com/xxx/tree-sitter-xxx.git"))

> 
>  OUT-DIR is the directory to put the compiled library file, it
>  defaults to ~/.emacs.d/tree-sitter.
> 
> I don't understand what "defaults" means here, since OUT-DIR is not an
> optional argument of treesit--install-language-grammar-1.

Ah yes, fixed.

> 
>  (let* ((lang (symbol-name lang))
>         (default-directory "/tmp")
> 
> A literal "/tmp" is not portable and un-Emacsy; please use
> temporary-file-directory instead.
> 
>         (soext (pcase system-type
>                  ('darwin "dylib")
>                  ((or 'ms-dos 'cywin 'windows-nt) "dll")
> 
> MS-DOS doesn't use DLL files.  Please use dynamic-library-suffixes
> instead, it's already set up correctly.  And the code should be ready
> for that variable having a nil value.

Fixed those, thanks.

> 
>          (message "Cloning repository")
>          ;; git clone xxx --depth 1 --quiet workdir
>          (treesit--call-process-signal
>           "git" nil t nil "clone" url "--depth" "1" "--quiet"
>           workdir)
> 
> Why "--depth 1"?  This should be a defcustom, and the default should
> be to clone the full repository, IMO.  Also, what about updating the
> library when it is already installed, and the Git repository already
> exists for it?  Or are we going to clone anew each time and them
> remove the repository? that could make its cloning be slow in some
> cases.

Since the purpose of this command is to install the grammar, why would we want a full clone? For an “average user”, all they need is the library. If they wants to hack on the grammar, it makes more sense to install the toolchain and clone the repository themselves. And yes, this command clone anew each time and removes the repository. 

> 
>          ;; cp "${grammardir}"/grammar.js "${sourcedir}"
>          (copy-file (concat grammar-dir "/grammar.js")
>                     (concat source-dir "/grammar.js"))
> 
> Why is this part needed?  In any case, please don't use concat to
> produce file names, use expand-file-name instead.  Also, we should
> call copy-file with 4th argument non-nil, I think.

To be honest I don’t remember, it is in build.sh so I copied it verbatim. I’ll see what it’s for. (But I kept it for now.)

> 
>          (treesit--call-process-signal
>           cc nil t nil "-fPIC" "-c" "-I." "parser.c")
> 
> I wonder why we don't use 'compile' here.  That would show the
> compiler output without any extra efforts.

I wanted to keep it simple, synchronous, and quiet, and didn’t thought much about it.

> 
>          ;; Copy out.
>          (copy-file lib-name (concat out-dir "/") t)
> 
> See above: don't use concat here.
> 
> This command should also be mentioned in NEWS, where we describe how
> to install the grammar libraries.

I’ll do that if we decide this function is desirable and good.

> Bottom line: I think we need first to discuss how we want such a
> facility to work, and only then implement it.

I agree. I was worried about the feature freeze thing :-)

Yuan




  parent reply	other threads:[~2022-12-31  0:03 UTC|newest]

Thread overview: 138+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 14:47 Tree-sitter introduction documentation Perry Smith
2022-12-16 15:06 ` Eli Zaretskii
2022-12-16 15:24   ` João Távora
2022-12-16 15:36     ` Perry Smith
2022-12-16 15:43       ` João Távora
2022-12-16 17:56       ` Philip Kaludercic
2022-12-16 15:38     ` Eli Zaretskii
2022-12-16 15:48       ` João Távora
2022-12-16 15:53         ` Perry Smith
2022-12-16 16:02           ` João Távora
2022-12-18  9:59             ` Eli Zaretskii
2022-12-18 14:07               ` Perry Smith
2022-12-18 17:18                 ` Eli Zaretskii
2022-12-16 16:34         ` Eli Zaretskii
2022-12-17  0:03           ` Tim Cross
2022-12-17  8:42             ` Eli Zaretskii
2022-12-17 10:40               ` João Távora
2022-12-17 11:00                 ` Eli Zaretskii
2022-12-18  0:40               ` Tim Cross
2022-12-16 16:01       ` Manuel Giraud
2022-12-16 16:40         ` Eli Zaretskii
2022-12-16 16:47           ` Perry Smith
2022-12-16 17:21             ` Eli Zaretskii
2022-12-16 15:53     ` Manuel Giraud
2022-12-16 15:56       ` João Távora
2022-12-16 16:39       ` Eli Zaretskii
2022-12-16 17:15         ` Manuel Giraud
2022-12-16 17:23           ` Eli Zaretskii
2022-12-16 20:22             ` Ken Brown
2022-12-17  4:06               ` Tim Cross
2022-12-17 15:42                 ` Stefan Monnier
2022-12-17 17:41                   ` T.V Raman
2022-12-26 22:42                   ` Dmitry Gutov
2022-12-27 12:11                     ` Eli Zaretskii
2022-12-27 12:43                       ` Dmitry Gutov
2022-12-27 13:38                         ` Eli Zaretskii
2022-12-27 14:11                           ` Dmitry Gutov
2022-12-27 14:32                             ` Eli Zaretskii
2022-12-27 16:36                               ` Stefan Monnier
2022-12-27 16:44                                 ` Philip Kaludercic
2022-12-27 17:16                                   ` Eli Zaretskii
2022-12-27 17:20                                     ` Philip Kaludercic
2022-12-27 18:06                                       ` Eli Zaretskii
2022-12-27 17:33                                     ` Stefan Monnier
2022-12-30 11:06                                   ` Yuan Fu
2022-12-30 11:25                                     ` Philip Kaludercic
2022-12-30 11:54                                       ` tomas
2022-12-30 11:59                                         ` Philip Kaludercic
2022-12-30 12:27                                           ` tomas
2022-12-30 12:45                                             ` Philip Kaludercic
2022-12-30 14:26                                             ` Dmitry Gutov
2022-12-30 23:33                                       ` Yuan Fu
2022-12-30 15:31                                     ` Eli Zaretskii
2022-12-30 15:54                                       ` Philip Kaludercic
2022-12-30 16:17                                         ` Eli Zaretskii
2022-12-31  0:06                                         ` Yuan Fu
2022-12-31  0:12                                           ` Philip Kaludercic
2023-01-01  1:18                                             ` Yuan Fu
2023-01-02 19:10                                               ` [SPAM UNSURE] " Stephen Leake
2022-12-31  0:03                                       ` Yuan Fu [this message]
2022-12-31  0:25                                         ` Stefan Monnier
2023-01-01  1:16                                           ` Yuan Fu
2023-01-01  6:39                                             ` Eli Zaretskii
2023-01-02  0:31                                               ` Yuan Fu
2023-01-02  0:40                                                 ` Stefan Monnier
2023-01-03  6:58                                                   ` Yuan Fu
2023-01-02  3:34                                                 ` Eli Zaretskii
2022-12-31  9:24                                         ` Eli Zaretskii
2022-12-31 22:14                                           ` Yuan Fu
2023-01-01  1:12                                             ` Yuan Fu
2022-12-31  0:44                                       ` Gregory Heytings
2023-01-03  4:08                                       ` Richard Stallman
2023-01-03 12:14                                         ` Eli Zaretskii
2023-01-01  3:03                                     ` Richard Stallman
2023-01-01  6:54                                       ` Eli Zaretskii
2023-01-01 19:14                                         ` Gregory Heytings
2023-01-01 20:11                                           ` Eli Zaretskii
2023-01-03  4:06                                         ` Richard Stallman
2023-01-03 12:06                                           ` Eli Zaretskii
2022-12-27 17:10                                 ` Eli Zaretskii
2022-12-27 17:31                                   ` Stefan Monnier
2022-12-27 18:08                                     ` Eli Zaretskii
2022-12-27 18:44                                       ` Stefan Monnier
2022-12-27 20:06                                         ` Philip Kaludercic
2022-12-27 21:13                                           ` Stefan Monnier
2022-12-28  2:52                                             ` Yuan Fu
2022-12-28 13:10                                               ` Gregory Heytings
2022-12-28 13:38                                               ` Lynn Winebarger
2022-12-28 14:41                                                 ` Danny Freeman
2022-12-29 11:14                                               ` Philip Kaludercic
2022-12-29 15:27                                                 ` Gregory Heytings
2022-12-29 15:40                                                   ` Lynn Winebarger
2022-12-29 21:50                                                     ` [SPAM UNSURE] " Stephen Leake
2022-12-29 22:37                                                       ` Lynn Winebarger
2022-12-30 14:10                                                       ` Lynn Winebarger
2022-12-30 16:25                                                         ` Targeting libtreesitter from wisent and other parser generators for emacs Lynn Winebarger
2022-12-31  8:25                                                           ` Eli Zaretskii
2022-12-31 13:07                                                             ` Lynn Winebarger
2022-12-29 15:45                                                   ` Tree-sitter introduction documentation Philip Kaludercic
2022-12-29 17:00                                                     ` Gregory Heytings
2022-12-29 17:12                                                       ` Philip Kaludercic
2022-12-29 17:31                                                         ` Gregory Heytings
2022-12-29 18:12                                                           ` Philip Kaludercic
2022-12-29 18:28                                                             ` Eli Zaretskii
2022-12-29 18:44                                                               ` Stefan Monnier
2022-12-29 19:34                                                                 ` Eli Zaretskii
2022-12-29 19:48                                                                   ` Stefan Monnier
2022-12-29 19:59                                                                     ` Eli Zaretskii
2022-12-29 18:32                                                             ` Stefan Monnier
2022-12-29 16:32                                                   ` Eli Zaretskii
2022-12-29 16:53                                                     ` Philip Kaludercic
2022-12-29 16:59                                                       ` Eli Zaretskii
2022-12-29 17:01                                                         ` Philip Kaludercic
2022-12-29 17:03                                                       ` Stefan Monnier
2022-12-29 17:12                                                         ` Gregory Heytings
2022-12-29 17:13                                                         ` Philip Kaludercic
2022-12-29 17:04                                                     ` Gregory Heytings
2022-12-30  1:01                                                 ` Gregory Heytings
2022-12-30 11:00                                                   ` Philip Kaludercic
2022-12-30 12:07                                                     ` Gregory Heytings
2022-12-30 13:10                                                       ` Philip Kaludercic
2022-12-30 15:23                                                         ` Gregory Heytings
2022-12-28 12:56                                         ` Gregory Heytings
2022-12-28 14:41                                           ` Stefan Monnier
2022-12-27 19:53                                       ` Dmitry Gutov
2023-01-01  3:03                                         ` Richard Stallman
2022-12-27 13:51                         ` tomas
2022-12-27 15:58                         ` Stefan Monnier
2022-12-16 17:23   ` Perry Smith
2022-12-16 17:31     ` Eli Zaretskii
2022-12-16 19:08       ` Perry Smith
2022-12-16 19:37         ` Eli Zaretskii
2022-12-16 20:05           ` Perry Smith
  -- strict thread matches above, loose matches on Subject: below --
2022-12-17  4:50 Payas Relekar
2022-12-18  6:32 Pedro Andres Aranda Gutierrez
2022-12-18  8:07 ` Eli Zaretskii
2022-12-18 10:39   ` Pedro Andres Aranda Gutierrez
2022-12-18 11:44     ` Eli Zaretskii
2022-12-31  6:59 Pedro Andres Aranda Gutierrez
2022-12-31  7:47 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FF0D4FE4-0DB6-4EFA-933C-8B8E29D179A4@gmail.com \
    --to=casouri@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=philipk@posteo.net \
    --cc=theophilusx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).