Skip to content

Commit 7ed634b

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

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### New features
6+
7+
* [#370](https://github.com/clojure-emacs/clojure-mode/issues/370): Warn the user if they seem to have activated the wrong major-mode.
8+
59
## 5.2.0 (04/02/2016)
610

711
### Bugs fixed

clojure-mode.el

+36
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,42 @@ 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, warn when activating the wrong major-mode."
334+
:type 'boolean
335+
:package-version '(clojure-mode "5.3.0"))
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* ((case-fold-search t)
344+
(problem (cond ((and (string-match "\\.clj\\'" (buffer-file-name))
345+
(not (eq major-mode 'clojure-mode)))
346+
'clojure-mode)
347+
((and (string-match "\\.cljs\\'" (buffer-file-name))
348+
(not (eq major-mode 'clojurescript-mode)))
349+
'clojurescript-mode)
350+
((and (string-match "\\.cljc\\'" (buffer-file-name))
351+
(not (eq major-mode 'clojurec-mode)))
352+
'clojurec-mode)
353+
((and (string-match "\\.cljx\\'" (buffer-file-name))
354+
(not (eq major-mode 'clojurex-mode)))
355+
'clojurex-mode))))
356+
(when problem
357+
(message "[WARNING] %s activated `%s' instead of `%s' in this buffer.
358+
This could cause problems.
359+
\(See `clojure-verify-major-mode' to disable this message.)"
360+
(if (eq major-mode real-this-command)
361+
"You have"
362+
"Something in your configuration")
363+
major-mode
364+
problem)))))
365+
366+
(add-hook 'clojure-mode-hook #'clojure--check-wrong-major-mode)
367+
332368
(defsubst clojure-in-docstring-p ()
333369
"Check whether point is in a docstring."
334370
(eq (get-text-property (point) 'face) 'font-lock-doc-face))

0 commit comments

Comments
 (0)