From 9ed62bfc99ab07202680308fb979606e4865ad3b Mon Sep 17 00:00:00 2001 From: Zoey Llewellyn Hewll Date: Mon, 22 Apr 2024 16:29:46 +0800 Subject: [PATCH] add elisp support --- book/src/generated/lang-support.md | 1 + languages.toml | 14 ++++++ runtime/queries/elisp/highlights.scm | 72 ++++++++++++++++++++++++++++ runtime/queries/elisp/tags.scm | 5 ++ 4 files changed, 92 insertions(+) create mode 100644 runtime/queries/elisp/highlights.scm create mode 100644 runtime/queries/elisp/tags.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 8418138c8def..494a18126d39 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -42,6 +42,7 @@ | edoc | ✓ | | | | | eex | ✓ | | | | | ejs | ✓ | | | | +| elisp | ✓ | | | | | elixir | ✓ | ✓ | ✓ | `elixir-ls` | | elm | ✓ | ✓ | | `elm-language-server` | | elvish | ✓ | | | `elvish` | diff --git a/languages.toml b/languages.toml index ecf1b49fd040..4a8b58433e92 100644 --- a/languages.toml +++ b/languages.toml @@ -3579,3 +3579,17 @@ language-servers = ["pest-language-server"] [[grammar]] name = "pest" source = { git = "https://github.com/pest-parser/tree-sitter-pest", rev = "a8a98a824452b1ec4da7f508386a187a2f234b85" } + +[[language]] +name = "elisp" +scope = "source.elisp" +file-types = ["el"] +comment-tokens = [";"] + +[language.auto-pairs] +'(' = ')' +'"' = '"' + +[[grammar]] +name = "elisp" +source = { git = "https://github.com/Wilfred/tree-sitter-elisp", rev = "e5524fdccf8c22fc726474a910e4ade976dfc7bb" } diff --git a/runtime/queries/elisp/highlights.scm b/runtime/queries/elisp/highlights.scm new file mode 100644 index 000000000000..d78b960f0463 --- /dev/null +++ b/runtime/queries/elisp/highlights.scm @@ -0,0 +1,72 @@ +;; Special forms +[ + "and" + "catch" + "cond" + "condition-case" + "defconst" + "defvar" + "function" + "if" + "interactive" + "lambda" + "let" + "let*" + "or" + "prog1" + "prog2" + "progn" + "quote" + "save-current-buffer" + "save-excursion" + "save-restriction" + "setq" + "setq-default" + "unwind-protect" + "while" +] @keyword + +;; Function definitions +[ + "defun" + "defsubst" + ] @keyword +(function_definition name: (symbol) @function) +(function_definition parameters: (list (symbol) @variable.parameter)) +(function_definition docstring: (string) @comment) + +;; Highlight macro definitions the same way as function definitions. +"defmacro" @keyword +(macro_definition name: (symbol) @function) +(macro_definition parameters: (list (symbol) @variable.parameter)) +(macro_definition docstring: (string) @comment) + +(comment) @comment + +(integer) @number +(float) @number +(char) @number + +(string) @string + +[ + "(" + ")" + "#[" + "[" + "]" +] @punctuation.bracket + +[ + "`" + "#'" + "'" + "," + ",@" +] @operator + +;; Highlight nil and t as constants, unlike other symbols +[ + "nil" + "t" +] @constant.builtin diff --git a/runtime/queries/elisp/tags.scm b/runtime/queries/elisp/tags.scm new file mode 100644 index 000000000000..7abcb9a4d6ce --- /dev/null +++ b/runtime/queries/elisp/tags.scm @@ -0,0 +1,5 @@ +;; defun/defsubst +(function_definition name: (symbol) @name) @definition.function + +;; Treat macros as function definitions for the sake of TAGS. +(macro_definition name: (symbol) @name) @definition.function