Skip to content

Commit 12b84ce

Browse files
committed
Warn the user if they've activated the wrong major-mode
clojure-emacs/cider#1611
1 parent cbd6a58 commit 12b84ce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

clojure-mode.el

+27
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,33 @@ instead of to `clojure-mode-map'."
329329
(clojure-font-lock-setup)
330330
(add-hook 'paredit-mode-hook #'clojure-paredit-setup))
331331

332+
(defcustom clojure-do-warnings t
333+
"If non-nil, `clojure-mode' will warn of possible user errors."
334+
:type 'boolean
335+
:package-version '(clojure-mode "5.3"))
336+
337+
(defun clojure--check-wrong-major-mode ()
338+
"Check if the current major-mode matches the file extension.
339+
If it doesn't, issue a warning if `clojure-do-warnings' is
340+
non-nil."
341+
(when (and clojure-do-warnings
342+
(stringp (buffer-file-name)))
343+
(let ((problem
344+
(cond ((and (string-match "\\.cljs\\'" (buffer-file-name))
345+
(not (eq major-mode 'clojurescript-mode)))
346+
'clojurescript-mode)
347+
((and (string-match "\\.clj[cx]\\'" (buffer-file-name))
348+
(not (eq major-mode 'clojurec-mode)))
349+
'clojurec-mode))))
350+
(when problem
351+
(message "[WARNING] Something in your configuration activated `%s' instead of `%s' in this buffer.%s%s"
352+
major-mode
353+
problem
354+
"\nThis is could cause problems."
355+
"\n(See `clojure-do-warnings' to disable this message.)")))))
356+
357+
(add-hook 'clojure-mode-hook #'clojure--check-wrong-major-mode)
358+
332359
(defsubst clojure-in-docstring-p ()
333360
"Check whether point is in a docstring."
334361
(eq (get-text-property (point) 'face) 'font-lock-doc-face))

0 commit comments

Comments
 (0)