aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2017-10-02 13:28:18 +0100
committerJoão Távora2017-10-03 14:20:29 +0100
commitf964aa99733e087bc51bd46fde655eaeaa5ff52d (patch)
treebc3c49a553c800f00de6510a6064ea964c1c9824
parent602d9376dbce2646f601f87c1311443ee3feb021 (diff)
downloademacs-f964aa99733e087bc51bd46fde655eaeaa5ff52d.tar.gz
emacs-f964aa99733e087bc51bd46fde655eaeaa5ff52d.zip
Minimal tweak as an attempt to future-proof Flymake API
Discussed with Stefan that this should allow Flymake to request more from backends in the future, while also allowing backends to report more accurately. * lisp/progmodes/elisp-mode.el (elisp-flymake-checkdoc) (elisp-flymake-byte-compile): Adjust to new API. * lisp/progmodes/flymake-proc.el () (flymake-proc-legacy-flymake): Adjust to new API. * lisp/progmodes/flymake.el (flymake-diagnostic-functions): Review API again. (flymake--handle-report): Allow other keys. Change ACTION to REPORT-ACTION.
-rw-r--r--lisp/progmodes/elisp-mode.el4
-rw-r--r--lisp/progmodes/flymake-proc.el7
-rw-r--r--lisp/progmodes/flymake.el51
3 files changed, 36 insertions, 26 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index f7d2f397672..3690f673832 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1617,7 +1617,7 @@ ARGLIST is either a string, or a list of strings or symbols."
1617 collected)) 1617 collected))
1618 1618
1619;;;###autoload 1619;;;###autoload
1620(defun elisp-flymake-checkdoc (report-fn) 1620(defun elisp-flymake-checkdoc (report-fn &rest _args)
1621 "A Flymake backend for `checkdoc'. 1621 "A Flymake backend for `checkdoc'.
1622Calls REPORT-FN directly." 1622Calls REPORT-FN directly."
1623 (unless (derived-mode-p 'emacs-lisp-mode) 1623 (unless (derived-mode-p 'emacs-lisp-mode)
@@ -1670,7 +1670,7 @@ Calls REPORT-FN directly."
1670 "Buffer-local process started for byte-compiling the buffer.") 1670 "Buffer-local process started for byte-compiling the buffer.")
1671 1671
1672;;;###autoload 1672;;;###autoload
1673(defun elisp-flymake-byte-compile (report-fn) 1673(defun elisp-flymake-byte-compile (report-fn &rest _args)
1674 "A Flymake backend for elisp byte compilation. 1674 "A Flymake backend for elisp byte compilation.
1675Spawn an Emacs process that byte-compiles a file representing the 1675Spawn an Emacs process that byte-compiles a file representing the
1676current buffer state and calls REPORT-FN when done." 1676current buffer state and calls REPORT-FN when done."
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index b76d18ed313..47ec27f611b 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -715,7 +715,7 @@ May only be called in a dynamic environment where
715 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name)))) 715 (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name))))
716 716
717 717
718(defun flymake-proc-legacy-flymake (report-fn &optional interactive) 718(defun flymake-proc-legacy-flymake (report-fn &rest args)
719 "Flymake backend based on the original Flymake implementation. 719 "Flymake backend based on the original Flymake implementation.
720This function is suitable for inclusion in 720This function is suitable for inclusion in
721`flymake-diagnostic-types-alist'. For backward compatibility, it 721`flymake-diagnostic-types-alist'. For backward compatibility, it
@@ -729,8 +729,9 @@ can also be executed interactively independently of
729 (apply (flymake-make-report-fn 'flymake-proc-legacy-flymake) 729 (apply (flymake-make-report-fn 'flymake-proc-legacy-flymake)
730 diags 730 diags
731 (append args '(:force t)))) 731 (append args '(:force t))))
732 t)) 732 :interactive t))
733 (let ((proc flymake-proc--current-process) 733 (let ((interactive (plist-get args :interactive))
734 (proc flymake-proc--current-process)
734 (flymake-proc--report-fn report-fn)) 735 (flymake-proc--report-fn report-fn))
735 (when (processp proc) 736 (when (processp proc)
736 (process-put proc 'flymake-proc--obsolete t) 737 (process-put proc 'flymake-proc--obsolete t)
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 48ec361600a..c1a15bf9242 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -320,20 +320,28 @@ Return nil if the region is invalid."
320 (error (flymake-error "Invalid region line=%s col=%s" line col)))) 320 (error (flymake-error "Invalid region line=%s col=%s" line col))))
321 321
322(defvar flymake-diagnostic-functions nil 322(defvar flymake-diagnostic-functions nil
323 "Special hook of Flymake backends to check a buffer. 323 "Special hook of Flymake backends that check a buffer.
324 324
325The functions in this hook diagnose problems in a buffer’s 325The functions in this hook diagnose problems in a buffer’s
326contents and provide the Flymake user interface with information 326contents and provide information to the Flymake user interface
327about where and how to annotate problems diagnosed in a buffer. 327about where and how to annotate problems diagnosed in a buffer.
328 328
329Whenever Flymake or the user decides to re-check the buffer, each 329Whenever Flymake or the user decides to re-check the buffer, each
330function is called with a common calling convention, a single 330function is called with an arbitrary number of arguments:
331REPORT-FN argument and a list of keword value pairs, detailed 331
332below. Backend functions are expected to initiate the buffer 332* the first argument is always REPORT-FN, a callback function
333check, but aren't required to complete it check before exiting: 333 detailed below;
334if the computation involved is expensive, especially for large 334
335buffers, that task can be scheduled for the future using 335* the remaining arguments are keyword-value pairs in the
336asynchronous processes or other asynchronous mechanisms. 336 form (:KEY VALUE :KEY2 VALUE2...). Currently, Flymake provides
337 no such arguments, but backend functions must be prepared to
338 accept to accept and possibly ignore any number of them.
339
340Backend functions are expected to initiate the buffer check, but
341aren't required to complete it check before exiting: if the
342computation involved is expensive, especially for large buffers,
343that task can be scheduled for the future using asynchronous
344processes or other asynchronous mechanisms.
337 345
338In any case, backend functions are expected to return quickly or 346In any case, backend functions are expected to return quickly or
339signal an error, in which case the backend is disabled. Flymake 347signal an error, in which case the backend is disabled. Flymake
@@ -344,10 +352,10 @@ and on again, reset the list of disabled backends.
344If the function returns, Flymake considers the backend to be 352If the function returns, Flymake considers the backend to be
345\"running\". If it has not done so already, the backend is 353\"running\". If it has not done so already, the backend is
346expected to call the function REPORT-FN with a single argument 354expected to call the function REPORT-FN with a single argument
347ACTION followed by an optional list of keyword-value pairs 355REPORT-ACTION also followed by an optional list of keyword-value
348their values (:KEY1 VALUE1 :KEY2 VALUE2...). 356pairs in the form (:REPORT-KEY VALUE :REPORT-KEY2 VALUE2...).
349 357
350The possible values for ACTION are. 358Currently accepted values for REPORT-ACTION are:
351 359
352* A (possibly empty) list of diagnostic objects created with 360* A (possibly empty) list of diagnostic objects created with
353 `flymake-make-diagnostic', causing Flymake to annotate the 361 `flymake-make-diagnostic', causing Flymake to annotate the
@@ -365,7 +373,7 @@ The possible values for ACTION are.
365* The symbol `:panic', signalling that the backend has 373* The symbol `:panic', signalling that the backend has
366 encountered an exceptional situation and should be disabled. 374 encountered an exceptional situation and should be disabled.
367 375
368The recognized optional keyword arguments are: 376Currently accepted REPORT-KEY arguments are:
369 377
370* ‘:explanation’: value should give user-readable details of 378* ‘:explanation’: value should give user-readable details of
371 the situation encountered, if any. 379 the situation encountered, if any.
@@ -544,11 +552,12 @@ present the backend is disabled.")
544 "Tell if Flymake has running backends in this buffer" 552 "Tell if Flymake has running backends in this buffer"
545 (flymake-running-backends)) 553 (flymake-running-backends))
546 554
547(cl-defun flymake--handle-report (backend token action 555(cl-defun flymake--handle-report (backend token report-action
548 &key explanation force) 556 &key explanation force
557 &allow-other-keys)
549 "Handle reports from BACKEND identified by TOKEN. 558 "Handle reports from BACKEND identified by TOKEN.
550 559
551BACKEND, ACTION and EXPLANATION, and FORCE conform to the calling 560BACKEND, REPORT-ACTION and EXPLANATION, and FORCE conform to the calling
552convention described in `flymake-diagnostic-functions' (which 561convention described in `flymake-diagnostic-functions' (which
553see). Optional FORCE says to handle a report even if TOKEN was 562see). Optional FORCE says to handle a report even if TOKEN was
554not expected." 563not expected."
@@ -573,14 +582,14 @@ not expected."
573 (not force)) 582 (not force))
574 (flymake-error "Obsolete report from backend %s with explanation %s" 583 (flymake-error "Obsolete report from backend %s with explanation %s"
575 backend explanation)) 584 backend explanation))
576 ((eq :panic action) 585 ((eq :panic report-action)
577 (flymake--disable-backend backend explanation)) 586 (flymake--disable-backend backend explanation))
578 ((not (listp action)) 587 ((not (listp report-action))
579 (flymake--disable-backend backend 588 (flymake--disable-backend backend
580 (format "Unknown action %S" action)) 589 (format "Unknown action %S" report-action))
581 (flymake-error "Expected report, but got unknown key %s" action)) 590 (flymake-error "Expected report, but got unknown key %s" report-action))
582 (t 591 (t
583 (setq new-diags action) 592 (setq new-diags report-action)
584 (save-restriction 593 (save-restriction
585 (widen) 594 (widen)
586 ;; only delete overlays if this is the first report 595 ;; only delete overlays if this is the first report