Misc. minor adjustments to Flymake

- Add a half-decent minor-mode menu;
- Fix "waiting for backends" mode line message;
- Adjust the flymake-diag-region API;
- Autoload the flymake-log macro;
- Auto-disable the legacy backend in more situations;
- Fix a couple of warnings in legacy backend.

* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Use new
flymake-diag-region.

* lisp/progmodes/flymake-proc.el
(flymake-proc-legacy-flymake): Do error when no
buffer-file-name or not writable.
(flymake-proc-legacy-flymake)
(flymake-proc-simple-cleanup): Don't reference flymake-last-change-time

* lisp/progmodes/flymake.el (flymake-diag-region):
Autoload.  Take buffer as first argument.

* lisp/progmodes/flymake.el (flymake-switch-to-log-buffer):
New command.
(flymake-menu): Add a simple menu.
(flymake--mode-line-format): Use menu.  Fix message.  Switch to
log buffer when clicking exceptional warnings.
This commit is contained in:
João Távora 2017-10-05 02:42:01 +01:00
parent 3d8df4d636
commit 7a1133f1ff
2 changed files with 80 additions and 61 deletions

View file

@ -522,13 +522,13 @@ Create parent directories as needed."
for buffer = (and full-file
(find-buffer-visiting full-file))
if (and (eq buffer (process-buffer proc)) message)
collect (with-current-buffer buffer
(pcase-let ((`(,beg . ,end)
(flymake-diag-region line-number col-number)))
(flymake-make-diagnostic
buffer beg end
(guess-type flymake-proc-diagnostic-type-pred message)
message)))
collect (pcase-let ((`(,beg . ,end)
(flymake-diag-region buffer line-number col-number)))
(flymake-make-diagnostic
buffer beg end
(with-current-buffer buffer
(guess-type flymake-proc-diagnostic-type-pred message))
message))
else
do (flymake-log 2 "Reference to file %s is out of scope" fname))
(error
@ -742,16 +742,18 @@ can also be executed interactively independently of
"There's already a Flymake process running in this buffer")
(kill-process proc))))
(when
;; A number of situations make us not want to error right away
;; (and disable ourselves), in case the situation changes in
;; the near future.
(and buffer-file-name
;; Since we write temp files in current dir, there's no point
;; trying if the directory is read-only (bug#8954).
(file-writable-p (file-name-directory buffer-file-name))
(or (not flymake-proc-compilation-prevents-syntax-check)
;; This particular situation make us not want to error right
;; away (and disable ourselves), in case the situation changes
;; in the near future.
(and (or (not flymake-proc-compilation-prevents-syntax-check)
(not (flymake-proc--compilation-is-running))))
(let ((init-f (flymake-proc--get-init-function buffer-file-name)))
(let ((init-f
(and
buffer-file-name
;; Since we write temp files in current dir, there's no point
;; trying if the directory is read-only (bug#8954).
(file-writable-p (file-name-directory buffer-file-name))
(flymake-proc--get-init-function buffer-file-name))))
(unless init-f (error "Can find a suitable init function"))
(flymake-proc--clear-buildfile-cache)
(flymake-proc--clear-project-include-dirs-cache)
@ -768,7 +770,6 @@ can also be executed interactively independently of
(flymake-log 0 "init function %s for %s failed, cleaning up"
init-f buffer-file-name))
(t
(setq flymake-last-change-time nil)
(setq proc
(let ((default-directory (or dir default-directory)))
(when dir
@ -878,8 +879,7 @@ can also be executed interactively independently of
(defun flymake-proc-simple-cleanup ()
"Do cleanup after `flymake-proc-init-create-temp-buffer-copy'.
Delete temp file."
(flymake-proc--safe-delete-file flymake-proc--temp-source-file-name)
(setq flymake-last-change-time nil))
(flymake-proc--safe-delete-file flymake-proc--temp-source-file-name))
(defun flymake-proc-get-real-file-name (file-name-from-err-msg)
"Translate file name from error message to \"real\" file name.

View file

@ -180,6 +180,11 @@ If nil, never start checking buffer automatically like this."
level)
"*Flymake log*")))
(defun flymake-switch-to-log-buffer ()
"Go to the *Flymake log* buffer."
(interactive)
(switch-to-buffer "*Flymake log*"))
;;;###autoload
(defmacro flymake-log (level msg &rest args)
"Log, at level LEVEL, the message MSG formatted with ARGS.
@ -282,41 +287,43 @@ verify FILTER, a function, and sort them by COMPARE (using KEY)."
(define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1")
(define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1")
(defun flymake-diag-region (line &optional col)
"Compute region (BEG . END) corresponding to LINE and COL.
If COL is nil, return a region just for LINE.
Return nil if the region is invalid."
;;;###autoload
(defun flymake-diag-region (buffer line &optional col)
"Compute BUFFER's region (BEG . END) corresponding to LINE and COL.
If COL is nil, return a region just for LINE. Return nil if the
region is invalid."
(condition-case-unless-debug _err
(let ((line (min (max line 1)
(line-number-at-pos (point-max) 'absolute))))
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(cl-flet ((fallback-bol
() (progn (back-to-indentation) (point)))
(fallback-eol
(beg)
(progn
(end-of-line)
(skip-chars-backward " \t\f\t\n" beg)
(if (eq (point) beg)
(line-beginning-position 2)
(point)))))
(if (and col (cl-plusp col))
(let* ((beg (progn (forward-char (1- col))
(point)))
(sexp-end (ignore-errors (end-of-thing 'sexp)))
(end (or (and sexp-end
(not (= sexp-end beg))
sexp-end)
(ignore-errors (goto-char (1+ beg)))))
(safe-end (or end
(fallback-eol beg))))
(cons (if end beg (fallback-bol))
safe-end))
(let* ((beg (fallback-bol))
(end (fallback-eol beg)))
(cons beg end))))))
(with-current-buffer buffer
(let ((line (min (max line 1)
(line-number-at-pos (point-max) 'absolute))))
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(cl-flet ((fallback-bol
() (progn (back-to-indentation) (point)))
(fallback-eol
(beg)
(progn
(end-of-line)
(skip-chars-backward " \t\f\t\n" beg)
(if (eq (point) beg)
(line-beginning-position 2)
(point)))))
(if (and col (cl-plusp col))
(let* ((beg (progn (forward-char (1- col))
(point)))
(sexp-end (ignore-errors (end-of-thing 'sexp)))
(end (or (and sexp-end
(not (= sexp-end beg))
sexp-end)
(ignore-errors (goto-char (1+ beg)))))
(safe-end (or end
(fallback-eol beg))))
(cons (if end beg (fallback-bol))
safe-end))
(let* ((beg (fallback-bol))
(end (fallback-eol beg)))
(cons beg end)))))))
(error (flymake-error "Invalid region line=%s col=%s" line col))))
(defvar flymake-diagnostic-functions nil
@ -872,8 +879,17 @@ applied."
(flymake-goto-next-error (- (or n 1)) filter interactive))
;;; Mode-line fanciness
;;; Mode-line and menu
;;;
(easy-menu-define flymake-menu flymake-mode-map "Flymake"
`("Flymake"
[ "Go to next error" flymake-goto-next-error t ]
[ "Go to previous error" flymake-goto-prev-error t ]
[ "Check now" flymake-start t ]
[ "Go to log buffer" flymake-switch-to-log-buffer t ]
"--"
[ "Turn off Flymake" flymake-mode t ]))
(defvar flymake--mode-line-format `(:eval (flymake--mode-line-format)))
(put 'flymake--mode-line-format 'risky-local-variable t)
@ -903,18 +919,16 @@ applied."
"mouse-1: go to log buffer ")
keymap
,(let ((map (make-sparse-keymap)))
(define-key map [mode-line mouse-1]
(lambda (_event)
(interactive "e")
(switch-to-buffer "*Flymake log*")))
(define-key map [mode-line down-mouse-1]
flymake-menu)
map))
,@(pcase-let ((`(,ind ,face ,explain)
(cond ((null known)
`("?" mode-line "No known backends"))
(some-waiting
`("Wait" compilation-mode-line-run
,(format "Waiting for %s running backends"
(length running))))
,(format "Waiting for %s running backend(s)"
(length some-waiting))))
(all-disabled
`("!" compilation-mode-line-run
"All backends disabled"))
@ -924,7 +938,12 @@ applied."
`((":"
(:propertize ,ind
face ,face
help-echo ,explain)))))
help-echo ,explain
keymap
,(let ((map (make-sparse-keymap)))
(define-key map [mode-line mouse-1]
'flymake-switch-to-log-buffer)
map))))))
,@(unless (or all-disabled
(null known))
(cl-loop