Skip to content

Commit

Permalink
plugin/emacs: Build and install Emacs plugins as ELPA packages
Browse files Browse the repository at this point in the history
Signed-off-by: wagner riffel <[email protected]>
  • Loading branch information
wgrr committed Aug 11, 2021
1 parent 15b9fd9 commit 7646781
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 119 deletions.
81 changes: 81 additions & 0 deletions cmake/FindQuickLintJsEmacs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (C) 2020 Matthew "strager" Glazar
# See end of file for extended copyright information.

if (QUICK_LINT_JS_EMACS)
set(QUICK_LINT_JS_EMACS "${QUICK_LINT_JS_EMACS}")
else ()
find_program(QUICK_LINT_JS_EMACS "emacs")
endif ()

if (NOT QUICK_LINT_JS_EMACS)
message(WARNING "Emacs not found. Skipping... ")
return ()
endif ()

execute_process(
COMMAND
${QUICK_LINT_JS_EMACS}
-Q -batch
--eval "(princ (format \"%s.%s\" emacs-major-version emacs-minor-version))"
RESULT_VARIABLE EMACS_EXIT_CODE
OUTPUT_VARIABLE EMACS_VERSION)

if (NOT EMACS_EXIT_CODE EQUAL 0)
message(WARNING "Emacs (${QUICK_LINT_JS_EMACS}) found but can't get its version. Skipping...")
return ()
endif()

if (NOT EMACS_VERSION GREATER_EQUAL 24.5)
message(WARNING "Emacs found (${QUICK_LINT_JS_EMACS}), but version ${EMACS_VERSION} is not supported. Skipping...")
return ()
endif ()

set(QUICK_LINT_JS_EMACS_FOUND TRUE)
message(STATUS "Found Emacs: (${QUICK_LINT_JS_EMACS}) suitable version ${EMACS_VERSION} minimum required is 24.5")

macro(emacs_pkg_target NAME FILE)
cmake_parse_arguments(
""
""
"OUTPUT"
""
${ARGN})

add_custom_command(
OUTPUT ${_OUTPUT}
COMMAND
${QUICK_LINT_JS_EMACS}
-Q -batch
-l package --eval "(package-initialize)"
--eval "(add-to-list 'package-directory-list \"${CMAKE_CACHEFILE_DIR}\")"
-l ${CMAKE_CURRENT_LIST_DIR}/quicklintjs-pkg.el
-f quicklintjs-batch-make-pkg
${FILE}
DEPENDS
${QUICK_LINT_JS_EMACS}
${CMAKE_CURRENT_LIST_DIR}/quicklintjs-pkg.el
${FILE}
VERBATIM)

add_custom_target(${NAME} ALL DEPENDS ${_OUTPUT})
endmacro ()

mark_as_advanced(QUICK_LINT_JS_EMACS)

# quick-lint-js finds bugs in JavaScript programs.
# Copyright (C) 2020 Matthew "strager" Glazar
#
# This file is part of quick-lint-js.
#
# quick-lint-js 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.
#
# quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
56 changes: 48 additions & 8 deletions plugin/emacs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,54 @@
cmake_minimum_required(VERSION 3.10)
include(GNUInstallDirs)

install(
FILES quicklintjs.el
FILES flycheck-quicklintjs.el
FILES lsp-quicklintjs.el
FILES eglot-quicklintjs.el
FILES flymake-quicklintjs.el
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp"
)
find_package(QuickLintJsEmacs)

if (QUICK_LINT_JS_EMACS_FOUND)
emacs_pkg_target(emacs-plugin-quicklintjs
${CMAKE_CURRENT_LIST_DIR}/quicklintjs.el 0.0.1
OUTPUT quicklintjs-0.0.1)

emacs_pkg_target(emacs-plugin-flycheck-quicklintjs
${CMAKE_CURRENT_LIST_DIR}/flycheck-quicklintjs.el 0.0.1
OUTPUT flycheck-quicklintjs-0.0.1)

emacs_pkg_target(emacs-plugin-flymake-quicklintjs
${CMAKE_CURRENT_LIST_DIR}/flymake-quicklintjs.el 0.0.1
OUTPUT flymake-quicklintjs-0.0.1)

emacs_pkg_target(emacs-plugin-eglot-quicklintjs
${CMAKE_CURRENT_LIST_DIR}/eglot-quicklintjs.el 0.0.1
OUTPUT eglot-quicklintjs-0.0.1)

emacs_pkg_target(emacs-plugin-lsp-quicklintjs
${CMAKE_CURRENT_LIST_DIR}/lsp-quicklintjs.el 0.0.1
OUTPUT lsp-quicklintjs-0.0.1)

add_dependencies(emacs-plugin-flycheck-quicklintjs
emacs-plugin-quicklintjs)
add_dependencies(emacs-plugin-flymake-quicklintjs
emacs-plugin-quicklintjs)
add_dependencies(emacs-plugin-eglot-quicklintjs
emacs-plugin-quicklintjs)
add_dependencies(emacs-plugin-lsp-quicklintjs
emacs-plugin-quicklintjs)

install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/quicklintjs-0.0.1
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flycheck-quicklintjs-0.0.1
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/flymake-quicklintjs-0.0.1
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/eglot-quicklintjs-0.0.1
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lsp-quicklintjs-0.0.1
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/emacs/site-lisp/elpa)
endif ()

# quick-lint-js finds bugs in JavaScript programs.
# Copyright (C) 2020 Matthew "strager" Glazar
Expand Down
48 changes: 28 additions & 20 deletions plugin/emacs/eglot-quicklintjs.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
;;; eglot-quicklintjs.el --- Eglot support for quick-lint-js -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Matthew "strager" Glazar

;; Version: 0.0.1
;; Author: Wagner Riffel <[email protected]>
;; URL: https://quick-lint-js.com
;; Keywords: languages, tools
;; Package-Requires: ((quicklintjs "0.0.1") (eglot "1.7") (emacs "26.1"))

;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Eglot support for quick-lint-js.
Expand All @@ -21,26 +44,11 @@
(require 'eglot)
(require 'quicklintjs)

(add-to-list 'eglot-server-programs `(js-mode . ,(quicklintjs-find-program
"--lsp-server")))
(provide 'eglot-quicklintjs)
;;;###autoload
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs `(js-mode . ,(quicklintjs-find-program
"--lsp-server"))))

;; quick-lint-js finds bugs in JavaScript programs.
;; Copyright (C) 2020 Matthew Glazar
;;
;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
(provide 'eglot-quicklintjs)

;;; eglot-quicklintjs.el ends here
53 changes: 31 additions & 22 deletions plugin/emacs/flycheck-quicklintjs.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
;;; flycheck-quicklintjs --- quick-lint-js Flycheck support -*- lexical-binding: t; -*-
;;; flycheck-quicklintjs.el --- quick-lint-js Flycheck support -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Matthew "strager" Glazar

;; Version: 0.0.1
;; Author: Wagner Riffel <[email protected]>
;; URL: https://quick-lint-js.com
;; Keywords: languages, tools
;; Package-Requires: ((quicklintjs "0.0.1") (flycheck "32-cvs") (emacs "24.5"))

;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

Expand Down Expand Up @@ -38,7 +61,7 @@
(require 'quicklintjs)

(defun flycheck-quicklintjs-parse-errors (output checker buffer)
"Parse quick-lint-js alist output format from OUTPUT"
"Parse CHECKER quick-lint-js alist output format from OUTPUT."
(mapcar (lambda (l)
(let ((region (nth 0 l))
(sev (nth 1 l))
Expand All @@ -51,8 +74,10 @@
:id code
:buffer buffer
:checker checker
:end-pos (cdr region)))) (car (read-from-string output))))
:end-pos (cdr region))))
(car (read-from-string output))))

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

(add-to-list 'flycheck-checkers 'javascript-quicklintjs t)
;;;###autoload
(with-eval-after-load 'flycheck
(add-to-list 'flycheck-checkers 'javascript-quicklintjs t))

(provide 'flycheck-quicklintjs)

;; quick-lint-js finds bugs in JavaScript programs.
;; Copyright (C) 2020 Matthew "strager" Glazar
;;
;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

;;; flycheck-quicklintjs.el ends here
53 changes: 31 additions & 22 deletions plugin/emacs/flymake-quicklintjs.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
;;; flymake-quicklintjs.el --- Flymake support for quick-lint-js -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Matthew "strager" Glazar

;; Version: 0.0.1
;; Author: Wagner Riffel <[email protected]>
;; URL: https://quick-lint-js.com
;; Keywords: languages, tools
;; Package-Requires: ((quicklintjs "0.0.1") (flymake "1.0.9") (emacs "26.1"))

;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

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

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

(provide 'flymake-quicklintjs)
;;;###autoload
(with-eval-after-load 'flymake
(add-hook 'flymake-diagnostic-functions #'flymake-quicklintjs nil t))

;; quick-lint-js finds bugs in JavaScript programs.
;; Copyright (C) 2020 Matthew Glazar
;;
;; This file is part of quick-lint-js.
;;
;; quick-lint-js 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.
;;
;; quick-lint-js 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 quick-lint-js. If not, see <https://www.gnu.org/licenses/>.
(provide 'flymake-quicklintjs)

;;; flymake-quicklintjs.el ends here
Loading

0 comments on commit 7646781

Please sign in to comment.