Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The next generation Clojure major mode for Emacs, powered by TreeSitter

License

NotificationsYou must be signed in to change notification settings

clojure-emacs/clojure-ts-mode

Repository files navigation

NonGNU ELPAMELPA StableMELPALicense GPL 3Lint Status

Clojure Tree-Sitter Mode

clojure-ts-mode is an Emacs major mode that provides font-lock (syntaxhighlighting), indentation, and navigation support for theClojure(Script) programming language, powered by thetree-sitter-clojuretree-sitter grammar.

Configuration

To see a list of available configuration options doM-x customize-group <RET> clojure-ts.

Most configuration changes will require reverting any activeclojure-ts-mode buffers.

Indentation

clojure-ts-mode currently supports 2 different indentation strategies:

Set the varclojure-ts-indent-style to change it.

(setq clojure-ts-indent-style'fixed)

Note: You can findthis article comparing semantic and fixed indentation useful.

Font Locking

To highlight entire richcomment expression with the comment font face, set

(setq clojure-ts-comment-macro-font-lock-bodyt)

By default this isnil, so that anything within acomment expression ishighlighted like regular clojure code.

Highlight markdown syntax in docstrings

By default markdown syntax is highlighted in the docstrings usingmarkdown_inline grammar. To disable this feature set

(setopt clojure-ts-use-markdown-inlinenil)

Navigation and Evaluation

To make forms inside of(comment ...) forms appear as top-level forms for evaluation and navigation, set

(setq clojure-ts-toplevel-inside-comment-formt)

Fill paragraph

To change the maximal line length used byM-x prog-fill-reindent-defun (alsobound toM-q by default) to reformat docstrings and comments it's possible tocustomizeclojure-ts-fill-paragraph variable (by default set to the value ofEmacs'fill-paragraph value).

Every new line in the docstrings is indented byclojure-ts-docstring-fill-prefix-width number of spaces (set to 2 by defaultwhich matches theclojure-mode settings).

Rationale

clojure-mode has served us wellfor a very long time, but it suffers from a fewlong-standingproblems, related toEmacs limitations baked into its design. The introduction of built-in supportfor Tree-sitter in Emacs 29 provides a natural opportunity to address many ofthem. Enterclojure-ts-mode.

Keep in mind that the transition toclojure-ts-mode won't happen overnight for several reasons:

  • getting to feature parity withclojure-mode will take some time
  • tools that depend onclojure-mode will need to be updated to work withclojure-ts-mode
  • we still need to support users of older Emacs versions that don't support Tree-sitter

That's whyclojure-ts-mode is being developed independently ofclojure-modeand will one day replace it when the time is right. (e.g. 3 major Emacs versiondown the road, so circa Emacs 32)

You can read more about the vision forclojure-ts-modehere.

Current Status

This library is still under development. Breaking changes should be expected.

Installation

Emacs 29

This package requires Emacs 29 built with tree-sitter support from theemacs-29 branch.

If you decide to build Emacs from source there's some useful information on this in the Emacs repository:

To check if your Emacs supports tree sitter run the following (e.g. by usingM-:):

(treesit-available-p)

Install clojure-ts-mode

clojure-ts-mode is available onMElPA andNonGNU ELPA.It can be installed with

(package-install'clojure-ts-mode)

package-vc

Emacs 29 also includespackage-vc-install, so you can run

(package-vc-install"https://github.com/clojure-emacs/clojure-ts-mode")

to install this package from source.

Manual installation

You can install it by cloning the repository and adding it to your load path.

git clone https://github.com/clojure-emacs/clojure-ts-mode.git
(add-to-list'load-path"~/path/to/clojure-ts-mode/")

Once installed, evaluate clojure-ts-mode.el and you should be ready to go.

Install tree-sitter grammars

The compile tree-sitter clojure shared library must be available to Emacs.Additionally, the tree-sittermarkdown_inline shared librarywill also be used for docstrings if available.

If you havegit and a C compiler (cc) available on your system'sPATH,then these steps should not be necessary. clojure-ts-mode will install thegrammars when you first open a Clojure file andclojure-ts-ensure-grammars isset tot (the default).

If clojure-ts-mode fails to automatically install the grammar, you have the option to install it manually.

From your OS

Some distributions may package the tree-sitter-clojure grammar in their package repositories.If yours does you may be able to install tree-sitter-clojure with your system package manager.

If the version packaged by your OS is out of date, you may see errors in the*Messages* buffer or your clojure buffers will not have any syntax highlighting.

If this happens you should install the grammar manually withM-x treesit-install-language-grammar <RET> clojure and follow the prompts.Recommended values for these prompts can be seen inclojure-ts-grammar-recipes.

Compile From Source

If all else fails, you can attempt to download and compile manually.All you need isgit and a C compiler (GCC works well).

To start, clonetree-sitter-clojure.

Then run the following code (depending on your OS) from the tree-sitter-clojure repository on your machine.

Linux

mkdir -p distcc -c -I./src src/parser.c -o"parser.o"cc -fPIC -shared src/parser.o -o"dist/libtree-sitter-clojure.so"

macOS

mkdir -p distcc -c -I./src src/parser.c -o"parser.o"cc -fPIC -shared src/parser.o -o"dist/libtree-sitter-clojure.dylib"

Windows

I don't know how to do this on Windows. Patches welcome!

Finally, in emacs

Then tell Emacs where to find the shared library by adding something like this to your init file:

(setq treesit-extra-load-path '("~/path/to/tree-sitter-clojure/dist"))

OR you can move thelibtree-sitter-clojure.so/libtree-sitter-clojure.dylib to a directory namedtree-sitterunder youruser-emacs-directory (typically~/.emacs.d on Unix systems).

Migrating to clojure-ts-mode

If you are migrating toclojure-ts-mode note thatclojure-mode is still required for cider and clj-refactor packages to work properly.

After installing the package do the following.

  • Check the value ofclojure-mode-hook and copy all relevant hooks toclojure-ts-mode-hook.
(add-hook'clojure-ts-mode-hook#'cider-mode)(add-hook'clojure-ts-mode-hook#'enable-paredit-mode)(add-hook'clojure-ts-mode-hook#'rainbow-delimiters-mode)(add-hook'clojure-ts-mode-hook#'clj-refactor-mode)
  • Update.dir-locals.el in all of your Clojure projects to activate directory local variables inclojure-ts-mode.
((clojure-mode  (cider-clojure-cli-aliases.":test:repl")) (clojure-ts-mode  (cider-clojure-cli-aliases.":test:repl")))

Frequently Asked Questions

Doesclojure-ts-mode work with CIDER?

Yes! Preliminary support forclojure-ts-mode was released inCIDER1.14. Make sure tograb the latest CIDER from MELPA/GitHub. Note thatclojure-mode is stillneeded for some APIs that haven't yet been ported toclojure-ts-mode.

For now, when you take care of the keybindings for the CIDER commands you useand ensurecider-mode is enabled forclojure-ts-mode buffers in your config,most functionality should already work:

(add-hook'clojure-ts-mode-hook#'cider-mode)

Check outthis article for more details.

Doesclojure-ts-mode work withinf-clojure?

Currently, there is anopen PR adding support for inf-clojure.

License

Copyright © 2022-2025 Danny Freeman andcontributors.

Distributed under the GNU General Public License; typeC-h C-c to view it.

About

The next generation Clojure major mode for Emacs, powered by TreeSitter

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp