From 2e11e72b6d4a79d3a0594ece0d113a149520c9a6 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 22 Jan 2019 15:10:52 +0100 Subject: [PATCH] Update flycheck. Signed-off-by: Andreas Gerler --- bba.org | 2 +- .../flycheck-autoloads.el | 0 .../flycheck-buttercup.el | 0 .../flycheck-ert.el | 0 .../flycheck-pkg.el | 2 +- .../flycheck.el | 296 +++++++++++++++--- elpa/flycheck-readme.txt | 30 -- 7 files changed, 247 insertions(+), 83 deletions(-) rename elpa/{flycheck-20181018.1021 => flycheck-20190108.351}/flycheck-autoloads.el (100%) rename elpa/{flycheck-20181018.1021 => flycheck-20190108.351}/flycheck-buttercup.el (100%) rename elpa/{flycheck-20181018.1021 => flycheck-20190108.351}/flycheck-ert.el (100%) rename elpa/{flycheck-20181018.1021 => flycheck-20190108.351}/flycheck-pkg.el (83%) rename elpa/{flycheck-20181018.1021 => flycheck-20190108.351}/flycheck.el (97%) delete mode 100644 elpa/flycheck-readme.txt diff --git a/bba.org b/bba.org index fa817b68..dabea7ab 100644 --- a/bba.org +++ b/bba.org @@ -606,7 +606,7 @@ log-format. #+BEGIN_SRC emacs-lisp :tangle yes (if (>= emacs-major-version 24) (progn - (add-to-list 'load-path "~/.emacs.d/elpa/flycheck-20180823.826") + (add-to-list 'load-path "~/.emacs.d/elpa/flycheck-20190108.351") (require 'flycheck) (add-hook 'after-init-hook #'global-flycheck-mode) (flycheck-define-checker puppet-lint diff --git a/elpa/flycheck-20181018.1021/flycheck-autoloads.el b/elpa/flycheck-20190108.351/flycheck-autoloads.el similarity index 100% rename from elpa/flycheck-20181018.1021/flycheck-autoloads.el rename to elpa/flycheck-20190108.351/flycheck-autoloads.el diff --git a/elpa/flycheck-20181018.1021/flycheck-buttercup.el b/elpa/flycheck-20190108.351/flycheck-buttercup.el similarity index 100% rename from elpa/flycheck-20181018.1021/flycheck-buttercup.el rename to elpa/flycheck-20190108.351/flycheck-buttercup.el diff --git a/elpa/flycheck-20181018.1021/flycheck-ert.el b/elpa/flycheck-20190108.351/flycheck-ert.el similarity index 100% rename from elpa/flycheck-20181018.1021/flycheck-ert.el rename to elpa/flycheck-20190108.351/flycheck-ert.el diff --git a/elpa/flycheck-20181018.1021/flycheck-pkg.el b/elpa/flycheck-20190108.351/flycheck-pkg.el similarity index 83% rename from elpa/flycheck-20181018.1021/flycheck-pkg.el rename to elpa/flycheck-20190108.351/flycheck-pkg.el index 0835bf3f..35d60b6d 100644 --- a/elpa/flycheck-20181018.1021/flycheck-pkg.el +++ b/elpa/flycheck-20190108.351/flycheck-pkg.el @@ -1,4 +1,4 @@ -(define-package "flycheck" "20181018.1021" "On-the-fly syntax checking" +(define-package "flycheck" "20190108.351" "On-the-fly syntax checking" '((dash "2.12.1") (pkg-info "0.4") (let-alist "1.0.4") diff --git a/elpa/flycheck-20181018.1021/flycheck.el b/elpa/flycheck-20190108.351/flycheck.el similarity index 97% rename from elpa/flycheck-20181018.1021/flycheck.el rename to elpa/flycheck-20190108.351/flycheck.el index 4f86d67a..3faac22f 100644 --- a/elpa/flycheck-20181018.1021/flycheck.el +++ b/elpa/flycheck-20190108.351/flycheck.el @@ -211,6 +211,8 @@ attention to case differences." markdown-markdownlint-cli markdown-mdl nix + nix-linter + opam perl perl-perlcritic php @@ -556,6 +558,10 @@ The following events are known: Check syntax a short time (see `flycheck-idle-change-delay') after the last change to the buffer. +`idle-buffer-switch' + Check syntax a short time (see `flycheck-idle-buffer-switch-delay') + after the user switches to a buffer. + `new-line' Check syntax immediately after a new line was inserted into the buffer. @@ -575,13 +581,15 @@ If nil, never check syntax automatically. In this case, use :group 'flycheck :type '(set (const :tag "After the buffer was saved" save) (const :tag "After the buffer was changed and idle" idle-change) + (const + :tag "After switching the current buffer" idle-buffer-switch) (const :tag "After a new line was inserted" new-line) (const :tag "After `flycheck-mode' was enabled" mode-enabled)) :package-version '(flycheck . "0.12") :safe #'flycheck-symbol-list-p) (defcustom flycheck-idle-change-delay 0.5 - "How many seconds to wait before checking syntax automatically. + "How many seconds to wait after a change before checking syntax. After the buffer was changed, Flycheck will wait as many seconds as the value of this variable before starting a syntax check. If @@ -595,6 +603,39 @@ This variable has no effect, if `idle-change' is not contained in :package-version '(flycheck . "0.13") :safe #'numberp) +(defcustom flycheck-idle-buffer-switch-delay 0.5 + "How many seconds to wait after switching buffers before checking syntax. + +After the user switches to a new buffer, Flycheck will wait as +many seconds as the value of this variable before starting a +syntax check. If the user switches to another buffer during this +time, whether a syntax check is still performed depends on the +value of `flycheck-buffer-switch-check-intermediate-buffers'. + +This variable has no effect if `idle-buffer-switch' is not +contained in `flycheck-check-syntax-automatically'." + :group 'flycheck + :type 'number + :package-version '(flycheck . "32") + :safe #'numberp) + +(defcustom flycheck-buffer-switch-check-intermediate-buffers nil + "Whether to check syntax in a buffer you only visit briefly. + +If nil, then when you switch to a buffer but switch to another +buffer before the syntax check is performed, then the check is +canceled. If non-nil, then syntax checks due to switching +buffers are always performed. This only affects buffer switches +that happen less than `flycheck-idle-buffer-switch-delay' seconds +apart. + +This variable has no effect if `idle-buffer-switch' is not +contained in `flycheck-check-syntax-automatically'." + :group 'flycheck + :type 'boolean + :package-version '(flycheck . "32") + :safe #'booleanp) + (defcustom flycheck-standard-error-navigation t "Whether to support error navigation with `next-error'. @@ -2431,7 +2472,14 @@ buffer manually. next-error-function :unset)) (when flycheck-standard-error-navigation - (setq next-error-function #'flycheck-next-error-function))) + (setq next-error-function #'flycheck-next-error-function)) + + ;; This hook must be added globally since otherwise we cannot + ;; detect a change from a buffer where Flycheck is enabled to a + ;; buffer where Flycheck is not enabled, and therefore cannot + ;; notice that there has been any change when the user switches + ;; back to the buffer where Flycheck is enabled. + (add-hook 'buffer-list-update-hook #'flycheck-handle-buffer-switch)) (t (unless (eq flycheck-old-next-error-function :unset) (setq next-error-function flycheck-old-next-error-function)) @@ -2742,54 +2790,105 @@ current syntax check." (flycheck-error-list-refresh) (flycheck-hide-error-buffer)) -(defun flycheck-teardown () - "Teardown Flycheck in the current buffer.. +(defun flycheck--empty-variables () + "Empty variables used by Flycheck." + (kill-local-variable 'flycheck--idle-trigger-timer) + (kill-local-variable 'flycheck--idle-trigger-conditions)) + +(defun flycheck-teardown (&optional ignore-global) + "Teardown Flycheck in the current buffer. Completely clear the whole Flycheck state. Remove overlays, kill -running checks, and empty all variables used by Flycheck." +running checks, and empty all variables used by Flycheck. + +Unless optional argument IGNORE-GLOBAL is non-nil, check to see +if no more Flycheck buffers remain (aside from the current +buffer), and if so then clean up global hooks." (flycheck-safe-delete-temporaries) (flycheck-stop) (flycheck-clean-deferred-check) (flycheck-clear) - (flycheck-cancel-error-display-error-at-point-timer)) + (flycheck-cancel-error-display-error-at-point-timer) + (flycheck--clear-idle-trigger-timer) + (flycheck--empty-variables) + (unless (or ignore-global + (seq-some (lambda (buf) + (and (not (equal buf (current-buffer))) + (buffer-local-value 'flycheck-mode buf))) + (buffer-list))) + (flycheck-global-teardown 'ignore-local))) ;;; Automatic syntax checking in a buffer -(defun flycheck-may-check-automatically (&optional condition) - "Determine whether the buffer may be checked under CONDITION. +(defun flycheck-may-check-automatically (&rest conditions) + "Determine whether the buffer may be checked under one of CONDITIONS. Read-only buffers may never be checked automatically. -If CONDITION is non-nil, determine whether syntax may checked -automatically according to +If CONDITIONS are given, determine whether syntax may be checked +under at least one of them, according to `flycheck-check-syntax-automatically'." (and (not (or buffer-read-only (flycheck-ephemeral-buffer-p))) (file-exists-p default-directory) - (or (not condition) - (memq condition flycheck-check-syntax-automatically)))) + (or (not conditions) + (seq-some + (lambda (condition) + (memq condition flycheck-check-syntax-automatically)) + conditions)))) + +(defvar-local flycheck--idle-trigger-timer nil + "Timer used to trigger a syntax check after an idle delay.") + +(defvar-local flycheck--idle-trigger-conditions nil + "List of conditions under which an idle syntax check will be triggered. +This will be some subset of the allowable values for +`flycheck-check-syntax-automatically'. + +For example, if the user switches to a buffer and then makes an +edit, this list will have the values `idle-change' and +`idle-buffer-switch' in it, at least until the idle timer +expires.") (defun flycheck-buffer-automatically (&optional condition force-deferred) "Automatically check syntax at CONDITION. Syntax is not checked if `flycheck-may-check-automatically' -returns nil for CONDITION. +returns nil for CONDITION. (CONDITION may be a single condition +or a list of them.) The syntax check is deferred if FORCE-DEFERRED is non-nil, or if `flycheck-must-defer-check' returns t." - (when (and flycheck-mode (flycheck-may-check-automatically condition)) + (when (and flycheck-mode (if (listp condition) + (apply #'flycheck-may-check-automatically + condition) + (flycheck-may-check-automatically condition))) + (flycheck--clear-idle-trigger-timer) + (setq flycheck--idle-trigger-conditions nil) (if (or force-deferred (flycheck-must-defer-check)) (flycheck-buffer-deferred) (with-demoted-errors "Error while checking syntax automatically: %S" (flycheck-buffer))))) -(defvar-local flycheck-idle-change-timer nil - "Timer to mark the idle time since the last change.") +(defun flycheck--clear-idle-trigger-timer () + "Clear the idle trigger timer." + (when flycheck--idle-trigger-timer + (cancel-timer flycheck--idle-trigger-timer) + (setq flycheck--idle-trigger-timer nil))) -(defun flycheck-clear-idle-change-timer () - "Clear the idle change timer." - (when flycheck-idle-change-timer - (cancel-timer flycheck-idle-change-timer) - (setq flycheck-idle-change-timer nil))) +(defun flycheck--handle-idle-trigger (buffer) + "Run a syntax check in BUFFER if appropriate. +This function is called by `flycheck--idle-trigger-timer'." + (let ((current-buffer (current-buffer))) + (when (buffer-live-p buffer) + (with-current-buffer buffer + (unless (or flycheck-buffer-switch-check-intermediate-buffers + (eq buffer current-buffer)) + (setq flycheck--idle-trigger-conditions + (delq 'idle-buffer-switch + flycheck--idle-trigger-conditions))) + (when flycheck--idle-trigger-conditions + (flycheck-buffer-automatically flycheck--idle-trigger-conditions) + (setq flycheck--idle-trigger-conditions nil)))))) (defun flycheck-handle-change (beg end _len) "Handle a buffer change between BEG and END. @@ -2802,29 +2901,54 @@ buffer." ;; Save and restore the match data, as recommended in (elisp)Change Hooks (save-match-data (when flycheck-mode - ;; The buffer was changed, thus clear the idle timer - (flycheck-clear-idle-change-timer) (if (string-match-p (rx "\n") (buffer-substring beg end)) (flycheck-buffer-automatically 'new-line 'force-deferred) - (setq flycheck-idle-change-timer - (run-at-time flycheck-idle-change-delay nil - #'flycheck--handle-idle-change-in-buffer + (when (memq 'idle-change flycheck-check-syntax-automatically) + (flycheck--clear-idle-trigger-timer) + (cl-pushnew 'idle-change flycheck--idle-trigger-conditions) + (setq flycheck--idle-trigger-timer + (run-at-time flycheck-idle-change-delay nil + #'flycheck--handle-idle-trigger + (current-buffer)))))))) + +(defvar flycheck--last-buffer (current-buffer) + "The current buffer or the buffer that was previously current. +This is usually equal to the current buffer, unless the user just +switched buffers. After a buffer switch, it is the previous +buffer.") + +(defun flycheck-handle-buffer-switch () + "Handle a possible switch to another buffer. + +If a buffer switch actually happened, schedule a syntax check." + ;; Switching buffers here is weird, but unfortunately necessary. It + ;; turns out that `with-temp-buffer' triggers + ;; `buffer-list-update-hook' twice, and the value of + ;; `current-buffer' is bogus in one of those triggers (the one just + ;; after the temp buffer is killed). If we rely on the bogus value, + ;; Flycheck will think that the user is switching back and forth + ;; between different buffers during the `with-temp-buffer' call + ;; (note: two different normal buffers, not the current buffer and + ;; the temp buffer!), and that would trigger spurious syntax checks. + ;; It seems that reading (window-buffer) gets us the correct current + ;; buffer in all important real-life situations (although it doesn't + ;; necessarily catch uses of `set-buffer'). + (with-current-buffer (window-buffer) + (unless (or (equal flycheck--last-buffer (current-buffer)) + ;; Don't bother keeping track of changes to and from + ;; the minibuffer, as they will never require us to + ;; run a syntax check. + (minibufferp)) + (setq flycheck--last-buffer (current-buffer)) + (when (and flycheck-mode + (memq 'idle-buffer-switch flycheck-check-syntax-automatically)) + (flycheck--clear-idle-trigger-timer) + (cl-pushnew 'idle-buffer-switch flycheck--idle-trigger-conditions) + (setq flycheck--idle-trigger-timer + (run-at-time flycheck-idle-buffer-switch-delay nil + #'flycheck--handle-idle-trigger (current-buffer))))))) -(defun flycheck--handle-idle-change-in-buffer (buffer) - "Handle an expired idle timer in BUFFER since the last change. -This thin wrapper around `flycheck-handle-idle-change' is needed -because some users override that function, as described in URL -`https://github.com/flycheck/flycheck/pull/1305'." - (when (buffer-live-p buffer) - (with-current-buffer buffer - (flycheck-handle-idle-change)))) - -(defun flycheck-handle-idle-change () - "Handle an expired idle timer since the last change." - (flycheck-clear-idle-change-timer) - (flycheck-buffer-automatically 'idle-change)) - (defun flycheck-handle-save () "Handle a save of the buffer." (flycheck-buffer-automatically 'save)) @@ -2921,16 +3045,21 @@ Command `flycheck-mode' is only enabled if ;; 'flycheck ) -(defun flycheck-global-teardown () +(defun flycheck-global-teardown (&optional ignore-local) "Teardown Flycheck in all buffers. Completely clear the whole Flycheck state in all buffers, stop all running checks, remove all temporary files, and empty all -variables of Flycheck." - (dolist (buffer (buffer-list)) - (with-current-buffer buffer - (when flycheck-mode - (flycheck-teardown))))) +variables of Flycheck. + +Also remove global hooks. (If optional argument IGNORE-LOCAL is +non-nil, then only do this and skip per-buffer teardown.)" + (unless ignore-local + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (when flycheck-mode + (flycheck-teardown 'ignore-global))))) + (remove-hook 'buffer-list-update-hook #'flycheck-handle-buffer-switch)) ;; Clean up the entire state of Flycheck when Emacs is killed, to get rid of any ;; pending temporary files. @@ -8472,6 +8601,38 @@ See URL `http://www.lua.org/'." ": stdin:" line ": " (message) line-end)) :modes lua-mode) +(flycheck-define-checker opam + "A Opam syntax and style checker using opam lint. + +See URL `https://opam.ocaml.org/doc/man/opam-lint.html'." + :command ("opam" "lint" "-") + :standard-input t + :error-patterns + ((error line-start ; syntax error + (one-or-more space) "error " (id ?2) + ": File format error" + (or (and " at line " line ", column " column ": " (message)) + (and ": " (message))) + line-end) + (error line-start + (one-or-more space) "error " (id ?3) + (minimal-match (zero-or-more not-newline)) + "at line " line ", column " column ": " (message) + line-end) + (error line-start + (one-or-more space) "error " (id (one-or-more num)) + ": " (message (one-or-more not-newline)) + line-end) + (warning line-start + (one-or-more space) "warning " (id (one-or-more num)) + ": " (message) + line-end)) + :error-filter + (lambda (errors) + (flycheck-increment-error-columns + (flycheck-fill-empty-line-numbers errors))) + :modes tuareg-opam-mode) + (flycheck-def-option-var flycheck-perl-include-path nil perl "A list of include directories for Perl. @@ -9095,7 +9256,7 @@ See URL `https://github.com/jimhester/lintr'." line-end) (error line-start (file-name) ":" line ":" column ": error: " (message) line-end)) - :modes ess-mode + :modes (ess-mode ess-r-mode) :predicate ;; Don't check ESS files which do not contain R, and make sure that lintr is ;; actually available @@ -9294,6 +9455,36 @@ See URL `https://nixos.org/nix/manual/#sec-nix-instantiate'." (lambda (errors) (flycheck-sanitize-errors (flycheck-remove-error-file-names "(string)" errors))) + :next-checkers ((warning . nix-linter)) + :modes nix-mode) + +(defun flycheck-parse-nix-linter (output checker buffer) + "Parse nix-linter warnings from JSON OUTPUT. + +CHECKER and BUFFER denote the CHECKER that returned OUTPUT and +the BUFFER that was checked respectively. + +See URL `https://github.com/Synthetica9/nix-linter' for more +information about nix-linter." + (mapcar (lambda (err) + (let-alist err + (flycheck-error-new-at + .pos.spanBegin.sourceLine + .pos.spanBegin.sourceColumn + 'warning + .description + :id .offense + :checker checker + :buffer buffer + :filename (buffer-file-name buffer)))) + (flycheck-parse-json output))) + +(flycheck-define-checker nix-linter + "Nix checker using nix-linter. + +See URL `https://github.com/Synthetica9/nix-linter'." + :command ("nix-linter" "--json-stream" source) + :error-parser flycheck-parse-nix-linter :modes nix-mode) (defun flycheck-locate-sphinx-source-directory () @@ -9681,9 +9872,12 @@ This syntax checker requires Rust 1.17 or newer. See URL ;; root. (let ((root (flycheck-rust-cargo-workspace-root))) (seq-do (lambda (err) - (setf (flycheck-error-filename err) - (expand-file-name - (flycheck-error-filename err) root))) + ;; Some errors are crate level and do not have a + ;; filename + (when (flycheck-error-filename err) + (setf (flycheck-error-filename err) + (expand-file-name + (flycheck-error-filename err) root)))) (flycheck-rust-error-filter errors)))) :error-explainer flycheck-rust-error-explainer :modes rust-mode @@ -9747,7 +9941,7 @@ This syntax checker needs Rust 1.18 or newer. See URL "A Rust syntax checker using clippy. See URL `https://github.com/rust-lang-nursery/rust-clippy'." - :command ("cargo" "+nightly" "clippy" "--message-format=json") + :command ("cargo" "clippy" "--message-format=json") :error-parser flycheck-parse-cargo-rustc :error-filter flycheck-rust-error-filter :error-explainer flycheck-rust-error-explainer diff --git a/elpa/flycheck-readme.txt b/elpa/flycheck-readme.txt deleted file mode 100644 index 43e7c7fc..00000000 --- a/elpa/flycheck-readme.txt +++ /dev/null @@ -1,30 +0,0 @@ -On-the-fly syntax checking for GNU Emacs 24. - -Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs, -intended as replacement for the older Flymake extension which is part of GNU -Emacs. - -Flycheck automatically checks buffers for errors while you type, and reports -warnings and errors directly in the buffer and in an optional IDE-like error -list. - -It comes with a rich interface for custom syntax checkers and other -extensions, and has already many 3rd party extensions adding new features. - -Please read the online manual at http://www.flycheck.org for more -information. You can open the manual directly from Emacs with `M-x -flycheck-manual'. - -# Setup - -Flycheck works best on Unix systems. It does not officially support Windows, -but tries to maintain Windows compatibility and should generally work fine on -Windows, too. - -To enable Flycheck add the following to your init file: - - (add-hook 'after-init-hook #'global-flycheck-mode) - -Flycheck will then automatically check buffers in supported languages, as -long as all necessary tools are present. Use `flycheck-verify-setup' to -troubleshoot your Flycheck setup. -- 2.47.3