-
Notifications
You must be signed in to change notification settings - Fork 1
/
flycheck-compcmdsjson.el
60 lines (48 loc) · 1.78 KB
/
flycheck-compcmdsjson.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
(require 'flycheck)
(require 'compcmdsjson-tiny)
(defvar-local flycheck-compcmdsjson/*last* nil)
(defun flycheck-compcmdsjson/run-and-capture-inc-dirs ()
(-select (lambda (s) (not (equal "" s)))
(split-string
(shell-command-to-string
"compile_commands_json_incdirs.py --print 2> /dev/null")
"\n")))
(defun flycheck-compcmdsjson/forget ()
(interactive)
(message "Resetting: flycheck-compcmdsjson/*last*")
(setq-local flycheck-compcmdsjson/*last* nil))
(defun flycheck-compcmdsjson/apply ()
(interactive)
;; reset
(when (not (null current-prefix-arg))
(flycheck-compcmdsjson/forget))
;; body
(when (and (null flycheck-compcmdsjson/*last*)
(not (eq flycheck-compcmdsjson/*last* :not-found)))
(message "Looking: compile_commands.json ...")
;;
(let ((path (compcmdsjson-tiny/find-nearest)))
(message "Found: %s" path)
;;
(if (null path)
(setq-local flycheck-compcmdsjson/*last* :not-found)
;; else:
(progn
;; pushd, cd
(let ((default-directory (f-parent path)))
(message "cd: %s" default-directory)
(cd default-directory)
;; run: "compile_commands_json_incdirs.py --print" ==> flycheck
(let ((inc-dirs
(flycheck-compcmdsjson/run-and-capture-inc-dirs)))
(message "inc-dirs: %s" inc-dirs)
(setq flycheck-gcc-include-path inc-dirs)
(setq flycheck-clang-include-path inc-dirs)
(setq flycheck-cppcheck-include-path inc-dirs))
;; bye
(setq-local flycheck-compcmdsjson/*last* path)
(flycheck-buffer)
)))
;; (message "pwd: %s" default-directory)
)))
(provide 'flycheck-compcmdsjson)