emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

Offline Usage and Add New Langauge #224

Closed drcxd closed 2 years ago

drcxd commented 2 years ago

For some reason I need to use Emacs in an offline environment. However, it seems that turning on tree-sitter-mode will try to connect to github.com (through tsc-dyn), which would fail of course if the computer is offline. This makes the package totally unusable in an offline environment. Is there any way to circumvent this network connection? I could download all necessary files and then send them into the offline environment.

In addition, is there anyway I can add language support for languages which are not currently supported by major mode or tree-sitter-langs? The language I intend to use is Lua and I could find some parser or binding for it. However, no documents I have found described how to add a new language support using these parsers or bindings. Is that possible?

lambdadog commented 2 years ago

To add support for a language to tree-sitter-mode, you'll want to run

(add-to-list 'tree-sitter-load-path "/path/to/lua.so")
(add-to-list 'tree-sitter-major-mode-language-alist '(lua-mode . lua))

Note that "lua" is the name of both the .so file and the value added to the alist, these must match.

For highlighting support with tree-sitter-hl, you will need to set tree-sitter-hl-default-patterns (buffer-local) once your mode has loaded -- many tree-sitter parsers will already contain a "highlights" query file, (highlights.scm), but you may want to change these queries or write your own, as they are often designed for usage on websites such as github, rather than in-editor highlighting.

speeeeed commented 1 year ago

@drcxd Do you use treesitter offline now? I have the same problem.

drcxd commented 1 year ago

@drcxd Do you use treesitter offline now? I have the same problem.

@speeeeed I do figure out how to use it offline. First, you have to install tree-sitter and tree-sitter-langs packages in an online environment and make sure it works. Then in your offline environment install those packages and all the other external dependencies (cargo or rust, see the error message in emacs if you do not know what to install). Finally, copy these three folders in your .emacs.d/elpa/ directory:

to the corresponding directory in your offline environment, where xxxx is the package version number.

This works for me. And personally speaking, as a C/C++ programmer, tree-sitter doesn't do a better job than the regular expression coloring scheme, especially when it comes to heavily macroed code. The tree-sitter packages now are also difficult to use. It has external dependencies, requires online environment. For me, it does not worth it to use tree-sitter as a not that accurate coloring resolution. Maybe it works better for some other languages.