Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tld-with-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
kommen committed Oct 16, 2024
2 parents db53936 + dc74c45 commit 56fbdbc
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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

Expand Down
62 changes: 36 additions & 26 deletions clojure-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

;;; Code:
(require 'treesit)
(require 'lisp-mnt)

(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-node-eq "treesit.c")
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/clojure-ts-mode-util-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions test/samples/bug43.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
^{:a 1}
(def b 2)

^{:a 1}
(defn a
"hello" ;; <-
[] "world")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion test/utils/test-helper.el → test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ and point left there."
(delete-char -1)
,@body)))

(provide 'test-helper)
;;; test-helper.el ends here

0 comments on commit 56fbdbc

Please sign in to comment.