diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af2ea8..c669d0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## main (unreleased) - [#38]: Add support for `in-ns` forms in `clojure-ts-find-ns`. +- [#46]: Fix missing `comment-add` variable in `clojure-ts-mode-variables` mentioned in [#26] +- Add imenu support for `deftest` definitions. +- [#53]: Let `clojure-ts-mode` derive from `clojure-mode` for Emacs 30+. ## 0.2.2 (2024-02-16) diff --git a/README.md b/README.md index bbe54cc..62d8414 100644 --- a/README.md +++ b/README.md @@ -214,9 +214,7 @@ After installing the package do the following. ### Does `clojure-ts-mode` work with CIDER? -~~Not yet out of the box, but that [should change soon](https://github.com/clojure-emacs/cider/pull/3461). Feel free to help out with the remaining work, so we can expedite the process.~~ - -Support for `clojure-ts-mode` has landed on the `master` branch of CIDER (and will be part of CIDER 1.14 when it's released). Make sure to grab the latest CIDER from MELPA/GitHub. +Yes! Preliminary support for `clojure-ts-mode` was released in [CIDER 1.14](https://github.com/clojure-emacs/cider/releases/tag/v1.14.0). Make sure to grab the latest CIDER from MELPA/GitHub. Note that `clojure-mode` is still needed for some APIs that haven't yet been ported to `clojure-ts-mode`. For now, when you take care of the keybindings for the CIDER commands you use and ensure `cider-mode` is enabled for `clojure-ts-mode` buffers in your config, most functionality should already work: @@ -228,7 +226,7 @@ Check out [this article](https://metaredux.com/posts/2024/02/19/cider-preliminar ### Does `clojure-ts-mode` work with `inf-clojure`? -[Ditto.](https://github.com/clojure-emacs/inf-clojure/pull/215) +Currently, there is an [open PR](https://github.com/clojure-emacs/inf-clojure/pull/215) adding support for inf-clojure. ## License diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index 9fe4a50..5582647 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -54,7 +54,6 @@ ;;; Code: (require 'treesit) -(require 'lisp-mnt) (declare-function treesit-parser-create "treesit.c") (declare-function treesit-node-eq "treesit.c") @@ -71,8 +70,7 @@ :link '(emacs-commentary-link :tag "Commentary" "clojure-mode")) (defconst clojure-ts-mode-version - (eval-when-compile - (lm-version (or load-file-name buffer-file-name))) + "0.2.2" "The current version of `clojure-ts-mode'.") (defcustom clojure-ts-comment-macro-font-lock-body nil @@ -580,7 +578,7 @@ Can be called directly, but intended for use as `treesit-defun-name-function'." (treesit-node-text name))))))) (defvar clojure-ts--function-type-regexp - (rx string-start (or (seq "defn" (opt "-")) "defmethod") string-end) + (rx string-start (or (seq "defn" (opt "-")) "defmethod" "deftest") string-end) "Regular expression for matching definition nodes that resemble functions.") (defun clojure-ts--function-node-p (node) @@ -891,7 +889,10 @@ forms like deftype, defrecord, reify, proxy, etc." (defun clojure-ts-mode-display-version () "Display the current `clojure-mode-version' in the minibuffer." (interactive) - (message "clojure-ts-mode (version %s)" clojure-ts-mode-version)) + (let ((pkg-version (package-get-version))) + (if pkg-version + (message "clojure-ts-mode %s (package: %s)" clojure-ts-mode-version pkg-version) + (message "clojure-ts-mode %s" clojure-ts-mode-version)))) (defconst clojure-ts-grammar-recipes '((clojure "https://github.com/sogaiu/tree-sitter-clojure.git" @@ -918,6 +919,7 @@ forms like deftype, defrecord, reify, proxy, etc." (defun clojure-ts-mode-variables (&optional markdown-available) "Initialize buffer-local variables for `clojure-ts-mode'. See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE." + (setq-local comment-add 1) (setq-local comment-start ";") (setq-local treesit-font-lock-settings (clojure-ts--font-lock-settings markdown-available)) @@ -971,6 +973,11 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE." (when (fboundp 'transpose-sexps-default-function) (setq-local transpose-sexps-function #'transpose-sexps-default-function))))) +;; For Emacs 30+, so that `clojure-ts-mode' is treated as deriving from +;; `clojure-mode' +(when (fboundp 'derived-mode-add-parents) + (derived-mode-add-parents 'clojure-ts-mode '(clojure-mode))) + ;;;###autoload (define-derived-mode clojure-ts-clojurescript-mode clojure-ts-mode "ClojureScript[TS]" "Major mode for editing ClojureScript code. @@ -1000,27 +1007,30 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE." (add-to-list 'auto-mode-alist '("\\.cljd\\'" . clojure-ts-clojuredart-mode)) (add-to-list 'auto-mode-alist '("\\.jank\\'" . clojure-ts-jank-mode))) -;; Redirect clojure-mode to clojure-ts-mode if clojure-mode is present -(if (require 'clojure-mode nil 'noerror) - (progn - (add-to-list 'major-mode-remap-alist '(clojure-mode . clojure-ts-mode)) - (add-to-list 'major-mode-remap-alist '(clojurescript-mode . clojure-ts-clojurescript-mode)) - (add-to-list 'major-mode-remap-alist '(clojurec-mode . clojure-ts-clojurec-mode)) - (clojure-ts--register-novel-modes)) - ;; Clojure-mode is not present, setup auto-modes ourselves - ;; Regular clojure/edn files - ;; I believe dtm is for datomic queries and datoms, which are just edn. - (add-to-list 'auto-mode-alist - '("\\.\\(clj\\|dtm\\|edn\\)\\'" . clojure-ts-mode)) - (add-to-list 'auto-mode-alist '("\\.cljs\\'" . clojure-ts-clojurescript-mode)) - (add-to-list 'auto-mode-alist '("\\.cljc\\'" . clojure-ts-clojurec-mode)) - ;; boot build scripts are Clojure source files - (add-to-list 'auto-mode-alist '("\\(?:build\\|profile\\)\\.boot\\'" . clojure-ts-mode)) - ;; babashka scripts are Clojure source files - (add-to-list 'interpreter-mode-alist '("bb" . clojure-ts-mode)) - ;; nbb scripts are ClojureScript source files - (add-to-list 'interpreter-mode-alist '("nbb" . clojure-ts-clojurescript-mode)) - (clojure-ts--register-novel-modes)) +(if (treesit-available-p) + ;; Redirect clojure-mode to clojure-ts-mode if clojure-mode is present + (if (require 'clojure-mode nil 'noerror) + (progn + (add-to-list 'major-mode-remap-alist '(clojure-mode . clojure-ts-mode)) + (add-to-list 'major-mode-remap-alist '(clojurescript-mode . clojure-ts-clojurescript-mode)) + (add-to-list 'major-mode-remap-alist '(clojurec-mode . clojure-ts-clojurec-mode)) + (clojure-ts--register-novel-modes)) + ;; When Clojure-mode is not present, setup auto-modes ourselves + (progn + ;; Regular clojure/edn files + ;; I believe dtm is for datomic queries and datoms, which are just edn. + (add-to-list 'auto-mode-alist + '("\\.\\(clj\\|dtm\\|edn\\)\\'" . clojure-ts-mode)) + (add-to-list 'auto-mode-alist '("\\.cljs\\'" . clojure-ts-clojurescript-mode)) + (add-to-list 'auto-mode-alist '("\\.cljc\\'" . clojure-ts-clojurec-mode)) + ;; boot build scripts are Clojure source files + (add-to-list 'auto-mode-alist '("\\(?:build\\|profile\\)\\.boot\\'" . clojure-ts-mode)) + ;; babashka scripts are Clojure source files + (add-to-list 'interpreter-mode-alist '("bb" . clojure-ts-mode)) + ;; nbb scripts are ClojureScript source files + (add-to-list 'interpreter-mode-alist '("nbb" . clojure-ts-clojurescript-mode)) + (clojure-ts--register-novel-modes))) + (message "Clojure TS Mode will not be activated as tree-sitter support is missing.")) (defvar clojure-ts--find-ns-query (treesit-query-compile diff --git a/test/clojure-ts-mode-util-test.el b/test/clojure-ts-mode-util-test.el index b4c2e13..5581a2c 100644 --- a/test/clojure-ts-mode-util-test.el +++ b/test/clojure-ts-mode-util-test.el @@ -23,7 +23,6 @@ (require 'clojure-ts-mode) (require 'buttercup) -(require 'test-helper "test/utils/test-helper") (describe "clojure-ts-mode-version" (it "should not be nil" diff --git a/test/samples/bug43.clj b/test/samples/bug43.clj new file mode 100644 index 0000000..85cfda1 --- /dev/null +++ b/test/samples/bug43.clj @@ -0,0 +1,7 @@ +^{:a 1} + (def b 2) + +^{:a 1} +(defn a + "hello" ;; <- + [] "world") diff --git a/test/docstrings.clj b/test/samples/docstrings.clj similarity index 100% rename from test/docstrings.clj rename to test/samples/docstrings.clj diff --git a/test/indentation.clj b/test/samples/indentation.clj similarity index 100% rename from test/indentation.clj rename to test/samples/indentation.clj diff --git a/test/native.jank b/test/samples/native.jank similarity index 100% rename from test/native.jank rename to test/samples/native.jank diff --git a/test/test.clj b/test/samples/test.clj similarity index 100% rename from test/test.clj rename to test/samples/test.clj diff --git a/test/utils/test-helper.el b/test/test-helper.el similarity index 98% rename from test/utils/test-helper.el rename to test/test-helper.el index b7ac0d4..38bce56 100644 --- a/test/utils/test-helper.el +++ b/test/test-helper.el @@ -46,5 +46,4 @@ and point left there." (delete-char -1) ,@body))) -(provide 'test-helper) ;;; test-helper.el ends here