-
Notifications
You must be signed in to change notification settings - Fork 7
/
flycheck-cask.el
108 lines (82 loc) · 3.64 KB
/
flycheck-cask.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;;; flycheck-cask.el --- Cask support in Flycheck -*- lexical-binding: t; -*-
;; Copyright (C) 2013-2015 Sebastian Wiesner <[email protected]>
;; Author: Sebastian Wiesner <[email protected]>
;; URL: https://github.com/flycheck/flycheck-cask
;; Keywords: tools, convenience
;; Version: 0.5-cvs
;; Package-Requires: ((emacs "24.3") (flycheck "0.14") (dash "2.4.0"))
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Add Cask support for Flycheck.
;; Configure Flycheck to initialize packages from Cask in Cask projects.
;;;; Setup
;; (add-hook 'flycheck-mode-hook #'flycheck-cask-setup)
;;; Code:
(require 'flycheck)
(require 'dash)
(require 'package)
(defgroup flycheck-cask nil
"Cask support for Flycheck."
:prefix "flycheck-cask-"
:group 'flycheck
:link '(url-link :tag "Github" "https://github.com/flycheck/flycheck-cask"))
(defcustom flycheck-cask-add-root-directory t
"When non-nil, add the root directory to the load path.
If this variable is non nil, add the root directory of a Cask
project to `flycheck-emacs-lisp-load-path'."
:group 'flycheck-cask
:type 'boolean)
(defcustom flycheck-cask-fall-back-to-package-user-dir nil
"When non-nil, fall back to `package-user-dir'.
When non-nil, fall back to packages from `package-user-dir' for
non-Cask projects."
:group 'flycheck-cask
:type 'directory)
(defun flycheck-cask-package-dir (root-dir)
"Get the package directory for ROOT-DIR."
(expand-file-name (format ".cask/%s.%s/elpa"
emacs-major-version
emacs-minor-version)
root-dir))
(defun flycheck-cask-initialize-cask-dir (directory)
"Initialise Flycheck for the given Cask DIRECTORY."
(setq-local flycheck-emacs-lisp-initialize-packages t)
(setq-local flycheck-emacs-lisp-package-user-dir
(flycheck-cask-package-dir directory))
(when (eq flycheck-emacs-lisp-load-path 'inherit)
;; Disable `load-path' inheritance if enabled.
(setq-local flycheck-emacs-lisp-load-path nil))
(when flycheck-cask-add-root-directory
(make-local-variable 'flycheck-emacs-lisp-load-path)
(add-to-list 'flycheck-emacs-lisp-load-path directory)))
;;;###autoload
(defun flycheck-cask-setup ()
"Setup Cask integration for Flycheck.
If the current file is part of a Cask project, as denoted by the
existence of a Cask file in the file's directory or any ancestor
thereof, configure Flycheck to initialze Cask packages while
syntax checking.
Set `flycheck-emacs-lisp-initialize-packages' and
`flycheck-emacs-lisp-package-user-dir' accordingly."
(when (buffer-file-name)
(-if-let (root-dir (locate-dominating-file (buffer-file-name) "Cask"))
(flycheck-cask-initialize-cask-dir root-dir)
(when flycheck-cask-fall-back-to-package-user-dir
(setq-local flycheck-emacs-lisp-initialize-packages t)
(setq-local flycheck-emacs-lisp-package-user-dir package-user-dir)))))
(provide 'flycheck-cask)
;; Local Variables:
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; flycheck-cask.el ends here