[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/flymake-refactor 8e42a5d 06/12: Cleanup some flyma
From: |
Jo�o T�vora |
Subject: |
[Emacs-diffs] scratch/flymake-refactor 8e42a5d 06/12: Cleanup some flymake-ui.el internals |
Date: |
Wed, 27 Sep 2017 13:47:29 -0400 (EDT) |
branch: scratch/flymake-refactor
commit 8e42a5d65bd9cbbe8a08e59a7dda80d0c41e3626
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Cleanup some flymake-ui.el internals
* lisp/progmodes/flymake-ui.el (flymake-type-alist): Delete.
(flymake--lookup-type-property): New helper.
(flymake--diag-errorp): Use it.
(flymake--highlight-line): Don't use flymake-type-alist.
(flymake--disable-backend): Use flymake--stop-backend.
(flymake--stop-backend, flymake--run-backend): New helpers.
(flymake--start-syntax-check): Use them. Downgrade logs.
* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Use assoc-default.
---
lisp/progmodes/flymake-proc.el | 3 +-
lisp/progmodes/flymake-ui.el | 84 ++++++++++++++++++++++++++----------------
2 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index fb664f9..bbba180 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -409,7 +409,8 @@ Create parent directories as needed."
:error))
((functionp pred)
(let ((probe (funcall pred message)))
- (cond ((flymake-type-alist probe)
+ (cond ((assoc-default probe
+ flymake-diagnostic-types-alist)
probe)
(probe
:warning)
diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index bd46fcf..c0ffff3 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -346,20 +346,32 @@ with flymake-specific meaning can also be used.
(put 'flymake-note 'bitmap flymake-warning-bitmap)
(put 'flymake-note 'severity (warning-numeric-level :debug))
-(defun flymake-type-alist (diagnostic-type)
- "Look up DIAGNOSTIC-TYPE in `flymake-diagnostic-types-alist'."
- (assoc-default diagnostic-type
- flymake-diagnostic-types-alist))
+(defun flymake--lookup-type-property (type prop &optional default)
+ "Look up PROP for TYPE in `flymake-diagnostic-types-alist'.
+If TYPE doesn't declare PROP in either
+`flymake-diagnostic-types-alist' or its associated category,
+return DEFAULT."
+ (let ((alist-probe (assoc type flymake-diagnostic-types-alist)))
+ (cond (alist-probe
+ (let* ((alist (cdr alist-probe))
+ (prop-probe (assoc prop alist)))
+ (if prop-probe
+ (cdr prop-probe)
+ (if-let* ((cat (assoc-default 'category alist))
+ (plist (and (symbolp cat)
+ (symbol-plist cat)))
+ (cat-probe (plist-member plist prop)))
+ (cadr cat-probe)
+ default))))
+ (t
+ default))))
(defun flymake--diag-errorp (diag)
"Tell if DIAG is a flymake error or something else"
- ;; FIXME repeats some logic in ‘flymake--highlight-line’
- (if-let* ((alist (flymake-type-alist (flymake--diag-type diag)))
- (sev (or (assoc-default 'severity alist)
- (get (assoc-default 'category alist)
- 'severity))))
- (>= sev (warning-numeric-level :error))
- t))
+ (let ((sev (flymake--lookup-type-property 'severity
+ (flymake--diag-type diag)
+ (warning-numeric-level :error))))
+ (>= sev (warning-numeric-level :error))))
(defun flymake--fringe-overlay-spec (bitmap)
(and flymake-fringe-indicator-position
@@ -378,7 +390,8 @@ with flymake-specific meaning can also be used.
;; First copy over to ov every property in the relevant alist.
;;
(cl-loop for (k . v) in
- (flymake-type-alist (flymake--diag-type diagnostic))
+ (assoc-default (flymake--diag-type diagnostic)
+ flymake-diagnostic-types-alist)
do (overlay-put ov k v))
;; Now ensure some defaults are set
;;
@@ -523,7 +536,7 @@ A backend is disabled if it reported `:panic'.")
(format "unknown action %s (%s)"
action explanation))))
(unless (eq action :progress)
- (setq flymake--running-backends (delq backend flymake--running-backends))))
+ (flymake--stop-backend backend)))
(defun flymake-make-report-fn (backend)
"Make a suitable anonymous report function for BACKEND.
@@ -532,36 +545,43 @@ sources."
(lambda (&rest args)
(apply #'flymake--handle-report backend args)))
+(defun flymake--stop-backend (backend)
+ "Stop the backend BACKEND."
+ (setq flymake--running-backends (delq backend flymake--running-backends)))
+
+(defun flymake--run-backend (backend)
+ "Run the backend BACKEND."
+ (push backend flymake--running-backends)
+ ;; FIXME: Should use `condition-case-unless-debug'
+ ;; here, but that won't let me catch errors during
+ ;; testing where `debug-on-error' is always t
+ (condition-case err
+ (unless (funcall backend
+ (flymake-make-report-fn backend))
+ (flymake--stop-backend backend))
+ (error
+ (flymake--disable-backend backend :error
+ err)
+ (flymake--stop-backend backend))))
+
(defun flymake--start-syntax-check (&optional deferred)
+ "Start a syntax check.
+Start it immediately, or after current command if DEFERRED is
+non-nil."
(cl-labels
- ((remove
- (backend)
- (setq flymake--running-backends
- (delq backend flymake--running-backends)))
- (start
+ ((start
()
(remove-hook 'post-command-hook #'start 'local)
(setq flymake-check-start-time (float-time))
(dolist (backend flymake-diagnostic-functions)
(cond ((memq backend flymake--running-backends)
- (flymake-log 1 "Backend %s still running, not restarting"
+ (flymake-log 2 "Backend %s still running, not restarting"
backend))
((memq backend flymake--disabled-backends)
- (flymake-log 1 "Backend %s is disabled, not starting"
+ (flymake-log 2 "Backend %s is disabled, not starting"
backend))
(t
- (push backend flymake--running-backends)
- ;; FIXME: Should use `condition-case-unless-debug'
- ;; here, but that won't let me catch errors during
- ;; testing where `debug-on-error' is always t
- (condition-case err
- (unless (funcall backend
- (flymake-make-report-fn backend))
- (remove backend))
- (error
- (flymake--disable-backend backend :error
- err)
- (remove backend))))))))
+ (flymake--run-backend backend))))))
(if (and deferred
this-command)
(add-hook 'post-command-hook #'start 'append 'local)
- [Emacs-diffs] scratch/flymake-refactor updated (7140018 -> 3b6c736), Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor d68448f 01/12: More cleanup before advancing to backend redesign, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 245114e 08/12: Fix autoload conflict between flymake.el and flymake-ui.el, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 879dcef 04/12: Misc cleanup in flymake-proc.el, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor e1b913f 11/12: Re-implement wraparound for flymake-goto-next-error, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 8e42a5d 06/12: Cleanup some flymake-ui.el internals,
Jo�o T�vora <=
- [Emacs-diffs] scratch/flymake-refactor 3dfe11c 03/12: Simplify flymake logging and erroring., Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 820b460 10/12: Add interactive flymake-start function, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 4fea8a9 05/12: Allow filtering in flymake-goto-[next/prev]-error, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 4e2cbaa 07/12: Fancy mode-line construct for flymake-mode, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 3b6c736 12/12: Start rewriting flymake manual, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 26f1e0c 02/12: Replace flymake-backends with flymake-diagnostic-functions, Jo�o T�vora, 2017/09/27
- [Emacs-diffs] scratch/flymake-refactor 7a22358 09/12: A couple of new flymake backends for emacs-lisp-mode, Jo�o T�vora, 2017/09/27