Skip to content

Commit 1ffd3b8

Browse files
committed
Add defcustom for major-mode remapping
1 parent 9662b6c commit 1ffd3b8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

clojure-ts-mode.el

+26-3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ double quotes on the third column."
119119
:safe #'booleanp
120120
:package-version '(clojure-ts-mode . "0.2.3"))
121121

122+
(defcustom clojure-ts-auto-redirect t
123+
"When non-nil, redirect all `clojure-mode' buffers to `clojure-ts-mode'."
124+
:safe #'booleanp
125+
:type 'boolean
126+
:package-version '(clojure-ts-mode . "0.2.4"))
127+
128+
(defvar clojure-ts-mode-remappings
129+
'((clojure-mode . clojure-ts-mode)
130+
(clojurescript-mode . clojure-ts-clojurescript-mode)
131+
(clojurec-mode . clojure-ts-clojurec-mode))
132+
"Alist of entries to `major-mode-remap-alist'.")
133+
122134
(defvar clojure-ts--debug nil
123135
"Enables debugging messages, shows current node in mode-line.
124136
Only intended for use at development time.")
@@ -1080,13 +1092,24 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
10801092
(add-to-list 'auto-mode-alist '("\\.cljd\\'" . clojure-ts-clojuredart-mode))
10811093
(add-to-list 'auto-mode-alist '("\\.jank\\'" . clojure-ts-jank-mode)))
10821094

1095+
(defun clojure-ts-activate ()
1096+
"Redirect all `clojure-mode' buffers to use `clojure-ts-mode'."
1097+
(interactive)
1098+
(dolist (entry clojure-ts-mode-remappings)
1099+
(add-to-list 'major-mode-remap-alist entry)))
1100+
1101+
(defun clojure-ts-deactivate ()
1102+
"Revert the redirecting of of `clojure-mode' buffers to `clojure-ts-mode'."
1103+
(interactive)
1104+
(dolist (entry clojure-ts-mode-remappings)
1105+
(setq major-mode-remap-alist (remove entry major-mode-remap-alist))))
1106+
10831107
(if (treesit-available-p)
10841108
;; Redirect clojure-mode to clojure-ts-mode if clojure-mode is present
10851109
(if (require 'clojure-mode nil 'noerror)
10861110
(progn
1087-
(add-to-list 'major-mode-remap-alist '(clojure-mode . clojure-ts-mode))
1088-
(add-to-list 'major-mode-remap-alist '(clojurescript-mode . clojure-ts-clojurescript-mode))
1089-
(add-to-list 'major-mode-remap-alist '(clojurec-mode . clojure-ts-clojurec-mode))
1111+
(when clojure-ts-auto-redirect
1112+
(clojure-ts-activate))
10901113
(clojure-ts--register-novel-modes))
10911114
;; When Clojure-mode is not present, setup auto-modes ourselves
10921115
(progn

0 commit comments

Comments
 (0)