Skip to content

Commit 8401fde

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

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

clojure-mode.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,36 @@ instead of to `clojure-mode-map'."
329329
(clojure-font-lock-setup)
330330
(add-hook 'paredit-mode-hook #'clojure-paredit-setup))
331331

332+
(defcustom clojure-verify-major-mode 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-verify-major-mode' is
340+
non-nil."
341+
(when (and clojure-verify-major-mode
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] %s activated `%s' instead of `%s' in this buffer.
352+
This is could cause problems.
353+
\(See `clojure-verify-major-mode' to disable this message.)"
354+
(if (eq major-mode real-this-command)
355+
"You have"
356+
"Something in your configuration")
357+
major-mode
358+
problem)))))
359+
360+
(add-hook 'clojure-mode-hook #'clojure--check-wrong-major-mode)
361+
332362
(defsubst clojure-in-docstring-p ()
333363
"Check whether point is in a docstring."
334364
(eq (get-text-property (point) 'face) 'font-lock-doc-face))

0 commit comments

Comments
 (0)