[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/flymake-refactor d68448f 01/12: More cleanup befor
From: |
João Távora |
Subject: |
[Emacs-diffs] scratch/flymake-refactor d68448f 01/12: More cleanup before advancing to backend redesign |
Date: |
Wed, 27 Sep 2017 13:47:27 -0400 (EDT) |
branch: scratch/flymake-refactor
commit d68448fc81cbd55d7b972b95dfefa22ed8e0ffeb
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
More cleanup before advancing to backend redesign
Diagnostics are reported for buffers, not necessarily files. It’s the
backend’s responsibility to compute the buffer where the diagnostic is
applicable. For now, this has to match the buffer where flymake-mode
is active and which is at the origin of the backend call.
flymake-ui.el knows nothing about line/column diagnostics (except for
backward-compatible flymake-ler-make-ler, which must yet be tested).
It’s also the backend’s reponsibility to compute a BEG and END
positions for the diagnostic in the relevant buffer.
* lisp/progmodes/flymake-proc.el
(flymake-proc--diagnostics-for-pattern): Convert LINE/COL to
region here. Check file buffer here.
(flymake-proc--process-sentinel): Don’t kill output buffer if
high enough log level.
* lisp/progmodes/flymake-ui.el (flymake-diag-region): Make
this a utility function.
(flymake--highlight-line): Diagnostic has region now.
(flymake-popup-current-error-menu): Don’t add file and line
numbers to already this silly menu.
(flymake--fix-line-numbers): Remove.
(flymake-report): No need to fix diagnostics here.
---
lisp/progmodes/flymake-proc.el | 33 ++++++++++++--------
lisp/progmodes/flymake-ui.el | 68 ++++++++++++++++++++----------------------
2 files changed, 53 insertions(+), 48 deletions(-)
diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index fb40467..96700ef 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -424,18 +424,24 @@ Create parent directories as needed."
for col-string = (and col-idx (match-string col-idx))
for col-number = (and col-string
(string-to-number col-string))
- collect (with-current-buffer (process-buffer proc)
- (flymake-make-diagnostic
- :file fname
- :line line-number
- :col col-number
- :type (guess-type flymake-proc-diagnostic-type-pred
message)
- :text message
- :full-file (and fname
- (funcall
- (flymake-proc--get-real-file-name-function
- fname)
- fname)))))
+ for full-file = (with-current-buffer (process-buffer proc)
+ (and fname
+ (funcall
+ (flymake-proc--get-real-file-name-function
+ fname)
+ fname)))
+ for buffer = (and full-file
+ (find-buffer-visiting full-file))
+ if (eq buffer (process-buffer proc))
+ 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)))
+ else
+ do (flymake-log 2 "No buffer found for diagnosed file %s" fname))
(error
(flymake-log 1 "Error parsing process output for pattern %s: %s"
pattern err)
@@ -487,7 +493,8 @@ Create parent directories as needed."
(flymake-log 2 "process %d exited with code %d"
(process-id process) exit-status)
- (kill-buffer (process-get process 'flymake-proc--output-buffer))
+ (unless (> flymake-log-level 2)
+ (kill-buffer (process-get process 'flymake-proc--output-buffer)))
(condition-case-unless-debug err
(progn
(flymake-log 3 "cleaning up using %s" cleanup-f)
diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index 25d8493..6678759 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -144,10 +144,29 @@ are the string substitutions (see the function `format')."
(message "%s" msg))))
(cl-defstruct (flymake--diag
- (:constructor flymake-make-diagnostic))
- file line col type text full-file)
-(define-obsolete-function-alias 'flymake-ler-make 'flymake-make-diagnostic
"26.1"
- "Constructor for objects of type `flymake--diag'")
+ (:constructor flymake--diag-make))
+ buffer beg end type text)
+
+(defun flymake-make-diagnostic (buffer
+ beg
+ end
+ type
+ text)
+ "Mark BUFFER's region from BEG to END with a flymake diagnostic.
+TYPE is a key to `flymake-diagnostic-types-alist' and TEXT is a
+description of the problem detected in this region."
+ (flymake--diag-make :buffer buffer :beg beg :end end :type type :text text))
+
+(defun flymake-ler-make-ler (file line type text &optional full-file)
+ (let* ((file (or full-file file))
+ (buf (find-buffer-visiting file)))
+ (unless buf (error "No buffer visiting %s" file))
+ (pcase-let* ((`(,beg . ,end)
+ (with-current-buffer buf
+ (flymake-diag-region line nil))))
+ (flymake-make-diagnostic buf beg end type text))))
+
+(make-obsolete 'flymake-ler-make-ler 'flymake-make-diagnostic "26.1")
(cl-defun flymake--overlays (&key beg end filter compare key)
"Get flymake-related overlays.
@@ -206,15 +225,14 @@ verify FILTER, 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 (diagnostic)
- "Return the region (BEG . END) for DIAGNOSTIC.
+(defun flymake-diag-region (line col)
+ "Compute region (BEG . END) corresponding to LINE and COL.
Or nil if the region is invalid."
- ;; FIXME: make this a generic function
(condition-case-unless-debug _err
- (save-excursion
- (goto-char (point-min))
- (let ((line (flymake--diag-line diagnostic))
- (col (flymake--diag-col diagnostic)))
+ (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)))
@@ -301,8 +319,9 @@ with flymake-specific meaning can also be used.
(defun flymake--highlight-line (diagnostic)
"Highlight buffer with info in DIAGNOSTIC."
- (when-let* ((region (flymake--diag-region diagnostic))
- (ov (make-overlay (car region) (cdr region))))
+ (when-let* ((ov (make-overlay
+ (flymake--diag-beg diagnostic)
+ (flymake--diag-end diagnostic))))
;; First copy over to ov every property in the relevant alist.
;;
(cl-loop for (k . v) in
@@ -365,12 +384,7 @@ with flymake-specific meaning can also be used.
(user-error "No flymake problem for current line")))
(menu (mapcar (lambda (ov)
(let ((diag (overlay-get ov 'flymake--diagnostic)))
- (cons (format "%s - %s(%s)"
- (flymake--diag-text diag)
- (or (flymake--diag-file diag)
- "(no file)")
- (or (flymake--diag-line diag)
- "?"))
+ (cons (flymake--diag-text diag)
ov)))
diag-overlays))
(event (if (mouse-event-p event)
@@ -422,26 +436,10 @@ with flymake-specific meaning can also be used.
(flymake-log 0 "switched OFF Flymake mode for buffer %s due to fatal status
%s, warning %s"
(buffer-name) status warning))
-(defun flymake--fix-line-numbers (diagnostic)
- "Ensure DIAGNOSTIC has sensible error lines"
- (setf (flymake--diag-line diagnostic)
- (min (max (flymake--diag-line diagnostic)
- 1)
- (line-number-at-pos (point-max) 'absolute))))
-
(defun flymake-report (diagnostics)
(save-restriction
(widen)
(flymake-delete-own-overlays)
- (setq diagnostics
- (cl-remove-if-not
- (lambda (diag)
- (let ((ff (flymake--diag-full-file diag)))
- (and ff
- (equal (expand-file-name ff)
- (expand-file-name (buffer-file-name))))))
- diagnostics))
- (mapc #'flymake--fix-line-numbers diagnostics)
(mapc #'flymake--highlight-line diagnostics)
(let ((err-count (cl-count-if #'flymake--diag-errorp diagnostics))
(warn-count (cl-count-if-not #'flymake--diag-errorp diagnostics)))
- [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 <=
- [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, 2017/09/27
- [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