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