Skip to content

Warn the user if they've activated the wrong major-mode #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#370](https://github.com/clojure-emacs/clojure-mode/issues/370): Warn the user if they seem to have activated the wrong major-mode.

## 5.2.0 (04/02/2016)

### Bugs fixed
Expand Down
36 changes: 36 additions & 0 deletions clojure-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,42 @@ instead of to `clojure-mode-map'."
(clojure-font-lock-setup)
(add-hook 'paredit-mode-hook #'clojure-paredit-setup))

(defcustom clojure-verify-major-mode t
"If non-nil, warn when activating the wrong major-mode."
:type 'boolean
:package-version '(clojure-mode "5.3.0"))

(defun clojure--check-wrong-major-mode ()
"Check if the current major-mode matches the file extension.
If it doesn't, issue a warning if `clojure-verify-major-mode' is
non-nil."
(when (and clojure-verify-major-mode
(stringp (buffer-file-name)))
(let* ((case-fold-search t)
(problem (cond ((and (string-match "\\.clj\\'" (buffer-file-name))
(not (eq major-mode 'clojure-mode)))
'clojure-mode)
((and (string-match "\\.cljs\\'" (buffer-file-name))
(not (eq major-mode 'clojurescript-mode)))
'clojurescript-mode)
((and (string-match "\\.cljc\\'" (buffer-file-name))
(not (eq major-mode 'clojurec-mode)))
'clojurec-mode)
((and (string-match "\\.cljx\\'" (buffer-file-name))
(not (eq major-mode 'clojurex-mode)))
'clojurex-mode))))
(when problem
(message "[WARNING] %s activated `%s' instead of `%s' in this buffer.
This could cause problems.
\(See `clojure-verify-major-mode' to disable this message.)"
(if (eq major-mode real-this-command)
"You have"
"Something in your configuration")
major-mode
problem)))))

(add-hook 'clojure-mode-hook #'clojure--check-wrong-major-mode)

(defsubst clojure-in-docstring-p ()
"Check whether point is in a docstring."
(eq (get-text-property (point) 'face) 'font-lock-doc-face))
Expand Down