Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace a-list with a hashtable #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 57 additions & 112 deletions tree-sitter-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,118 +94,63 @@ See `tree-sitter-langs-repos'."
(advice-add 'tree-sitter-load :before #'tree-sitter-langs--init-load-path)

;;;###autoload
(defun tree-sitter-langs--init-major-mode-alist (&rest _args)
"Link known major modes to languages provided by the bundle."
(dolist
(entry (reverse
'((ada-mode . ada)
(agda-mode . agda)
(agda2-mode . agda)
(arduino-mode . arduino)
(astro-mode . astro)
(fasm-mode . asm)
(fish-mode . fish)
(masm-mode . asm)
(nasm-mode . asm)
(sh-mode . bash)
(beancount-mode . beancount)
(bibtex-mode . bibtex)
(c-mode . c)
(caml-mode . ocaml)
(clojure-mode . clojure)
(lisp-mode . commonlisp)
(lisp-interaction-mode . commonlisp)
(csharp-mode . c-sharp)
(c++-mode . cpp)
(cmake-mode . cmake)
(d-mode . d)
(dart-mode . dart)
(dockerfile-mode . dockerfile)
(css-mode . css)
(csv-mode . csv)
(elm-mode . elm)
(elixir-mode . elixir)
(emacs-lisp-mode . elisp)
(erlang-mode . erlang)
(ess-r-mode . r)
(fennel-mode . fennel)
(f90-mode . fortran)
(fortran-mode . fortran)
(gdscript-mode . gdscript)
(git-commit-mode . gitcommit)
(git-rebase-mode . git-rebase)
(gitattributes-mode . gitattributes)
(gitignore-mode . gitignore)
(glsl-mode . glsl)
(go-mode . go)
(groovy-mode . groovy)
(jenkinsfile-mode . groovy)
(haskell-mode . haskell)
(hcl-mode . hcl)
(terraform-mode . hcl)
(heex-mode . heex)
(hlsl-mode . hlsl)
(html-mode . html)
(markdown-mode . markdown)
(mhtml-mode . html)
(nix-mode . nix)
(jai-mode . jai)
(java-mode . java)
(javascript-mode . javascript)
(js-mode . javascript)
(js2-mode . javascript)
(js3-mode . javascript)
(json-mode . json)
(jsonc-mode . json)
(jsonnet-mode . jsonnet)
(julia-mode . julia)
(kotlin-mode . kotlin)
(latex-mode . latex)
(lua-mode . lua)
(makefile-mode . make)
(makefile-automake-mode . make)
(makefile-gmake-mode . make)
(makefile-makepp-mode . make)
(makefile-bsdmake-mode . make)
(makefile-imake-mode . make)
(matlab-mode . matlab)
(mermaid-mode . mermaid)
(meson-mode . meson)
(noir-mode . noir)
(ocaml-mode . ocaml)
(org-mode . org)
(pascal-mode . pascal)
(perl-mode . perl)
(php-mode . php)
(prisma-mode . prisma)
(python-mode . python)
(pygn-mode . pgn)
(rjsx-mode . javascript)
(rst-mode . rst)
(ruby-mode . ruby)
(rust-mode . rust)
(rustic-mode . rust)
(scala-mode . scala)
(scheme-mode . scheme)
(solidity-mode . solidity)
(smithy-mode . smithy)
(sql-mode . sql)
(swift-mode . swift)
(toml-mode . toml)
(conf-toml-mode . toml)
(tcl-mode . tcl)
(tuareg-mode . ocaml)
(typescript-mode . typescript)
(typst-mode . typst)
(verilog-mode . verilog)
(vhdl-mode . vhdl)
(nxml-mode . xml)
(yaml-mode . yaml)
(k8s-mode . yaml)
(zig-mode . zig))))
(cl-pushnew entry tree-sitter-major-mode-language-alist
:key #'car))
(advice-remove 'tree-sitter--setup #'tree-sitter-langs--init-major-mode-alist))
(let ((entry nil))
(defun tree-sitter-langs--init-major-mode-alist(&rest _args)
"Link known major modes to languages provided by the bundle."
(setq major-mode-table (make-hash-table :test 'eq))
(dolist (entry
'((agda2-mode . agda)
(sh-mode . bash)
(c-mode . c)
(caml-mode . ocaml)
(clojure-mode . clojure)
(csharp-mode . c-sharp)
(c++-mode . cpp)
(d-mode . d)
(css-mode . css)
(elm-mode . elm)
(elixir-mode . elixir)
(erlang-mode . erlang)
(ess-r-mode . r)
(fennel-mode . fennel)
(go-mode . go)
(haskell-mode . haskell)
(hcl-mode . hcl)
(terraform-mode . hcl)
(html-mode . html)
(markdown-mode . markdown)
(mhtml-mode . html)
(nix-mode . nix)
(java-mode . java)
(javascript-mode . javascript)
(js-mode . javascript)
(js2-mode . javascript)
(js3-mode . javascript)
(json-mode . json)
(jsonc-mode . json)
(julia-mode . julia)
(lua-mode . lua)
(ocaml-mode . ocaml)
(perl-mode . perl)
(php-mode . php)
(prisma-mode . prisma)
(python-mode . python)
(pygn-mode . pgn)
(rjsx-mode . javascript)
(ruby-mode . ruby)
(rust-mode . rust)
(rustic-mode . rust)
(scala-mode . scala)
(swift-mode . swift)
(toml-mode . toml)
(tuareg-mode . ocaml)
(typescript-mode . typescript)
(verilog-mode . verilog)
(yaml-mode . yaml)
(zig-mode . zig)))
(when (not (gethash (car entry) major-mode-table))
(puthash (car entry) (cdr entry) major-mode-table)))
(advice-remove 'tree-sitter--setup #'tree-sitter-langs--init-major-mode-alist)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right since the variable tree-sitter-major-mode-language-alist doesn't get updated.


;;;###autoload
(advice-add 'tree-sitter--setup :before #'tree-sitter-langs--init-major-mode-alist)
Expand Down
Loading