Skip to content

Commit c2149fc

Browse files
committed
plugin/emacs: Build install Emacs plugins as ELPA packages
Signed-off-by: wagner riffel <[email protected]>
1 parent 15b9fd9 commit c2149fc

File tree

8 files changed

+325
-119
lines changed

8 files changed

+325
-119
lines changed

cmake/FindQuickLintJsEmacs.cmake

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (C) 2020 Matthew "strager" Glazar
2+
# See end of file for extended copyright information.
3+
4+
if (QUICK_LINT_JS_EMACS)
5+
set(QUICK_LINT_JS_EMACS "${QUICK_LINT_JS_EMACS}")
6+
else ()
7+
find_program(QUICK_LINT_JS_EMACS "emacs")
8+
endif ()
9+
10+
if (NOT QUICK_LINT_JS_EMACS)
11+
message(WARNING "Emacs not found. Skipping... ")
12+
return ()
13+
endif ()
14+
15+
execute_process(
16+
COMMAND
17+
${QUICK_LINT_JS_EMACS}
18+
-Q -batch
19+
--eval "(princ (format \"%s.%s\" emacs-major-version emacs-minor-version))"
20+
RESULT_VARIABLE EMACS_EXIT_CODE
21+
OUTPUT_VARIABLE EMACS_VERSION)
22+
23+
if (NOT EMACS_EXIT_CODE EQUAL 0)
24+
message(WARNING "Emacs (${QUICK_LINT_JS_EMACS}) found but can't get its version. Skipping...")
25+
return ()
26+
endif()
27+
28+
if (NOT EMACS_VERSION GREATER_EQUAL 24.5)
29+
message(WARNING "Emacs found (${QUICK_LINT_JS_EMACS}), but version ${EMACS_VERSION} is not supported. Skipping...")
30+
return ()
31+
endif ()
32+
33+
set(QUICK_LINT_JS_EMACS_FOUND TRUE)
34+
message(STATUS "Found Emacs: (${QUICK_LINT_JS_EMACS}) suitable version ${EMACS_VERSION} minimum required is 24.5")
35+
36+
macro(emacs_pkg_target NAME FILE)
37+
cmake_parse_arguments(
38+
""
39+
""
40+
"OUTPUT"
41+
""
42+
${ARGN})
43+
44+
add_custom_command(
45+
OUTPUT ${_OUTPUT}
46+
COMMAND
47+
${QUICK_LINT_JS_EMACS}
48+
-Q -batch
49+
-l package --eval "(package-initialize)"
50+
--eval "(add-to-list 'package-directory-list \"${CMAKE_CACHEFILE_DIR}\")"
51+
-l ${CMAKE_CURRENT_LIST_DIR}/quicklintjs-pkg.el
52+
-f quicklintjs-batch-make-pkg
53+
${FILE}
54+
DEPENDS
55+
${QUICK_LINT_JS_EMACS}
56+
${CMAKE_CURRENT_LIST_DIR}/quicklintjs-pkg.el
57+
${FILE}
58+
VERBATIM)
59+
60+
add_custom_target(${NAME} ALL DEPENDS ${_OUTPUT})
61+
endmacro ()
62+
63+
mark_as_advanced(QUICK_LINT_JS_EMACS)
64+
65+
# quick-lint-js finds bugs in JavaScript programs.
66+
# Copyright (C) 2020 Matthew "strager" Glazar
67+
#
68+
# This file is part of quick-lint-js.
69+
#
70+
# quick-lint-js is free software: you can redistribute it and/or modify
71+
# it under the terms of the GNU General Public License as published by
72+
# the Free Software Foundation, either version 3 of the License, or
73+
# (at your option) any later version.
74+
#
75+
# quick-lint-js is distributed in the hope that it will be useful,
76+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
77+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78+
# GNU General Public License for more details.
79+
#
80+
# You should have received a copy of the GNU General Public License
81+
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

plugin/emacs/CMakeLists.txt

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,54 @@
44
cmake_minimum_required(VERSION 3.10)
55
include(GNUInstallDirs)
66

7-
install(
8-
FILES quicklintjs.el
9-
FILES flycheck-quicklintjs.el
10-
FILES lsp-quicklintjs.el
11-
FILES eglot-quicklintjs.el
12-
FILES flymake-quicklintjs.el
13-
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp"
14-
)
7+
find_package(QuickLintJsEmacs)
8+
9+
if (QUICK_LINT_JS_EMACS_FOUND)
10+
emacs_pkg_target(emacs-plugin-quicklintjs
11+
${CMAKE_CURRENT_LIST_DIR}/quicklintjs.el 0.0.1
12+
OUTPUT quicklintjs-0.0.1)
13+
14+
emacs_pkg_target(emacs-plugin-flycheck-quicklintjs
15+
${CMAKE_CURRENT_LIST_DIR}/flycheck-quicklintjs.el 0.0.1
16+
OUTPUT flycheck-quicklintjs-0.0.1)
17+
18+
emacs_pkg_target(emacs-plugin-flymake-quicklintjs
19+
${CMAKE_CURRENT_LIST_DIR}/flymake-quicklintjs.el 0.0.1
20+
OUTPUT flymake-quicklintjs-0.0.1)
21+
22+
emacs_pkg_target(emacs-plugin-eglot-quicklintjs
23+
${CMAKE_CURRENT_LIST_DIR}/eglot-quicklintjs.el 0.0.1
24+
OUTPUT eglot-quicklintjs-0.0.1)
25+
26+
emacs_pkg_target(emacs-plugin-lsp-quicklintjs
27+
${CMAKE_CURRENT_LIST_DIR}/lsp-quicklintjs.el 0.0.1
28+
OUTPUT lsp-quicklintjs-0.0.1)
29+
30+
add_dependencies(emacs-plugin-flycheck-quicklintjs
31+
emacs-plugin-quicklintjs)
32+
add_dependencies(emacs-plugin-flymake-quicklintjs
33+
emacs-plugin-quicklintjs)
34+
add_dependencies(emacs-plugin-eglot-quicklintjs
35+
emacs-plugin-quicklintjs)
36+
add_dependencies(emacs-plugin-lsp-quicklintjs
37+
emacs-plugin-quicklintjs)
38+
39+
install(
40+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/quicklintjs-0.0.1
41+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
42+
install(
43+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flycheck-quicklintjs-0.0.1
44+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
45+
install(
46+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flymake-quicklintjs-0.0.1
47+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
48+
install(
49+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/eglot-quicklintjs-0.0.1
50+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
51+
install(
52+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lsp-quicklintjs-0.0.1
53+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
54+
endif ()
1555

1656
# quick-lint-js finds bugs in JavaScript programs.
1757
# Copyright (C) 2020 Matthew "strager" Glazar

plugin/emacs/eglot-quicklintjs.el

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
;;; eglot-quicklintjs.el --- Eglot support for quick-lint-js -*- lexical-binding: t; -*-
22

3+
;; Copyright (C) 2020 Matthew "strager" Glazar
4+
5+
;; Version: 0.0.1
6+
;; Author: Wagner Riffel <[email protected]>
7+
;; URL: https://quick-lint-js.com
8+
;; Keywords: languages, tools
9+
;; Package-Requires: ((quicklintjs "0.0.1") (eglot "1.7") (emacs "26.1"))
10+
11+
;; This file is part of quick-lint-js.
12+
;;
13+
;; quick-lint-js is free software: you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
;;
18+
;; quick-lint-js is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
;;
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
25+
326
;;; Commentary:
427

528
;; Eglot support for quick-lint-js.
@@ -21,26 +44,11 @@
2144
(require 'eglot)
2245
(require 'quicklintjs)
2346

24-
(add-to-list 'eglot-server-programs `(js-mode . ,(quicklintjs-find-program
25-
"--lsp-server")))
26-
(provide 'eglot-quicklintjs)
47+
;;;###autoload
48+
(with-eval-after-load 'eglot
49+
(add-to-list 'eglot-server-programs `(js-mode . ,(quicklintjs-find-program
50+
"--lsp-server"))))
2751

28-
;; quick-lint-js finds bugs in JavaScript programs.
29-
;; Copyright (C) 2020 Matthew Glazar
30-
;;
31-
;; This file is part of quick-lint-js.
32-
;;
33-
;; quick-lint-js is free software: you can redistribute it and/or modify
34-
;; it under the terms of the GNU General Public License as published by
35-
;; the Free Software Foundation, either version 3 of the License, or
36-
;; (at your option) any later version.
37-
;;
38-
;; quick-lint-js is distributed in the hope that it will be useful,
39-
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
40-
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41-
;; GNU General Public License for more details.
42-
;;
43-
;; You should have received a copy of the GNU General Public License
44-
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
52+
(provide 'eglot-quicklintjs)
4553

4654
;;; eglot-quicklintjs.el ends here

plugin/emacs/flycheck-quicklintjs.el

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
;;; flycheck-quicklintjs --- quick-lint-js Flycheck support -*- lexical-binding: t; -*-
1+
;;; flycheck-quicklintjs.el --- quick-lint-js Flycheck support -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2020 Matthew "strager" Glazar
4+
5+
;; Version: 0.0.1
6+
;; Author: Wagner Riffel <[email protected]>
7+
;; URL: https://quick-lint-js.com
8+
;; Keywords: languages, tools
9+
;; Package-Requires: ((quicklintjs "0.0.1") (flycheck "32-cvs") (emacs "24.5"))
10+
11+
;; This file is part of quick-lint-js.
12+
;;
13+
;; quick-lint-js is free software: you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
;;
18+
;; quick-lint-js is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
;;
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
225

326
;;; Commentary:
427

@@ -38,7 +61,7 @@
3861
(require 'quicklintjs)
3962

4063
(defun flycheck-quicklintjs-parse-errors (output checker buffer)
41-
"Parse quick-lint-js alist output format from OUTPUT"
64+
"Parse CHECKER quick-lint-js alist output format from OUTPUT."
4265
(mapcar (lambda (l)
4366
(let ((region (nth 0 l))
4467
(sev (nth 1 l))
@@ -51,8 +74,10 @@
5174
:id code
5275
:buffer buffer
5376
:checker checker
54-
:end-pos (cdr region)))) (car (read-from-string output))))
77+
:end-pos (cdr region))))
78+
(car (read-from-string output))))
5579

80+
;;;###autoload
5681
(flycheck-define-command-checker 'javascript-quicklintjs
5782
"quick-lint-js finds bugs in JavaScript programs.
5883
@@ -70,26 +95,10 @@ https://quick-lint-js.com"
7095
(and error-code `(url . ,(format url error-code)))))
7196
:modes 'js-mode)
7297

73-
(add-to-list 'flycheck-checkers 'javascript-quicklintjs t)
98+
;;;###autoload
99+
(with-eval-after-load 'flycheck
100+
(add-to-list 'flycheck-checkers 'javascript-quicklintjs t))
74101

75102
(provide 'flycheck-quicklintjs)
76103

77-
;; quick-lint-js finds bugs in JavaScript programs.
78-
;; Copyright (C) 2020 Matthew "strager" Glazar
79-
;;
80-
;; This file is part of quick-lint-js.
81-
;;
82-
;; quick-lint-js is free software: you can redistribute it and/or modify
83-
;; it under the terms of the GNU General Public License as published by
84-
;; the Free Software Foundation, either version 3 of the License, or
85-
;; (at your option) any later version.
86-
;;
87-
;; quick-lint-js is distributed in the hope that it will be useful,
88-
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
89-
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90-
;; GNU General Public License for more details.
91-
;;
92-
;; You should have received a copy of the GNU General Public License
93-
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
94-
95104
;;; flycheck-quicklintjs.el ends here

plugin/emacs/flymake-quicklintjs.el

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
;;; flymake-quicklintjs.el --- Flymake support for quick-lint-js -*- lexical-binding: t; -*-
22

3+
;; Copyright (C) 2020 Matthew "strager" Glazar
4+
5+
;; Version: 0.0.1
6+
;; Author: Wagner Riffel <[email protected]>
7+
;; URL: https://quick-lint-js.com
8+
;; Keywords: languages, tools
9+
;; Package-Requires: ((quicklintjs "0.0.1") (flymake "1.0.9") (emacs "26.1"))
10+
11+
;; This file is part of quick-lint-js.
12+
;;
13+
;; quick-lint-js is free software: you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
;;
18+
;; quick-lint-js is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
;;
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
25+
326
;;; Commentary:
427

528
;; Flymake support for quick-lint-js.
@@ -14,7 +37,6 @@
1437
;; ;; Enable Flymake
1538
;; (unless (bound-and-true-p flymake-mode)
1639
;; (flymake-mode))
17-
;; (add-hook 'flymake-diagnostic-functions #'flymake-quicklintjs nil t)
1840
;;
1941
;; ;; Remove the time to wait after last change before automatically checking
2042
;; ;; buffer. The default is 0.5 (500ms)
@@ -43,8 +65,9 @@ Return a list of Flymake diagnostic objects in source buffer SRC-BUF."
4365
(defun flymake-quicklintjs--report-with-crash (qljs-stdout-buf
4466
qljs-stderr-buf
4567
src-buf report-fn)
46-
"Similar to `flymake-quicklintjs--report' but tries to recover errors from
47-
quick-lint-js crashes and logs whatever is in QLJS-STDERR-BUF"
68+
"Similar to `flymake-quicklintjs--report' but try to recover errors in\
69+
SRC-BUF when quick-lint-js crashes by inspecting QLJS-STDOUT-BUF.
70+
Whatever is in QLJS-STDERR-BUF is also logged as warning using `flymake-log'."
4871
(flymake-log :warning
4972
"quick-lint-js exited with a deadly signal.\n\
5073
Please consider filing a bug at\
@@ -70,7 +93,7 @@ qjls-stderr-buf:\n\
7093
(funcall report-fn '())))
7194

7295
(defun flymake-quicklintjs--report (qljs-stdout-buf src-buf report-fn)
73-
"Call REPORT-FN to highlight reports in SRC_BUF reported in QLJS-STDOUT-BUF.
96+
"Call REPORT-FN to highlight reports in SRC-BUF reported in QLJS-STDOUT-BUF.
7497
QLJS-STDOUT-BUF is entirely read and it's expected to be in
7598
QUICKLINTJS-OUTPUT-ALIST format."
7699
(with-current-buffer qljs-stdout-buf
@@ -124,24 +147,10 @@ REPORT-FN is Flymake's callback."
124147
(process-send-region flymake-quicklintjs--proc (point-min) (point-max))
125148
(process-send-eof flymake-quicklintjs--proc))))
126149

127-
(provide 'flymake-quicklintjs)
150+
;;;###autoload
151+
(with-eval-after-load 'flymake
152+
(add-hook 'flymake-diagnostic-functions #'flymake-quicklintjs nil t))
128153

129-
;; quick-lint-js finds bugs in JavaScript programs.
130-
;; Copyright (C) 2020 Matthew Glazar
131-
;;
132-
;; This file is part of quick-lint-js.
133-
;;
134-
;; quick-lint-js is free software: you can redistribute it and/or modify
135-
;; it under the terms of the GNU General Public License as published by
136-
;; the Free Software Foundation, either version 3 of the License, or
137-
;; (at your option) any later version.
138-
;;
139-
;; quick-lint-js is distributed in the hope that it will be useful,
140-
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
141-
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142-
;; GNU General Public License for more details.
143-
;;
144-
;; You should have received a copy of the GNU General Public License
145-
;; along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
154+
(provide 'flymake-quicklintjs)
146155

147156
;;; flymake-quicklintjs.el ends here

0 commit comments

Comments
 (0)