[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/flymake-refactor d68448f 26/52: More cleanup befor
From: |
Jo�o T�vora |
Subject: |
[Emacs-diffs] scratch/flymake-refactor d68448f 26/52: More cleanup before advancing to backend redesign |
Date: |
Sun, 1 Oct 2017 12:40:47 -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 12aa247 19/52: Protect against timer triggers when no flymake-mode, (continued)
- [Emacs-diffs] scratch/flymake-refactor 12aa247 19/52: Protect against timer triggers when no flymake-mode, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 740572e 05/52: Completely rewrite flymake's subprocess output processing, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 14db516 22/52: flymake-ui.el checks file names before considering diagnostics, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 61ba20b 21/52: Echo flymake error messages when navigating errors interactively, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor b2c4135 15/52: Clarify logic around flymake-diagnostic-types-alist, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor bac7512 12/52: New flymake-diagnostic-types-alist and more cleanup, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 7140018 25/52: Protect flymake-ui against commands like fill-paragraph, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor d3168cf 09/52: Make lisp/progmodes/flymake-ui.el some 150 lines lighter, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor f3b8a72 20/52: Refactor flymake-tests.el in preparation for more tests, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 593d4303 23/52: Add a new flymake test for multiple errors and warnings, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor d68448f 26/52: More cleanup before advancing to backend redesign,
Jo�o T�vora <=
- [Emacs-diffs] scratch/flymake-refactor 245114e 33/52: Fix autoload conflict between flymake.el and flymake-ui.el, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 4fea8a9 30/52: Allow filtering in flymake-goto-[next/prev]-error, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 192cb7f 24/52: flymake-ui.el highlights GCC notes detected by flymake-proc.el, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 879dcef 29/52: Misc cleanup in flymake-proc.el, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 820b460 35/52: Add interactive flymake-start function, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 8e42a5d 31/52: Cleanup some flymake-ui.el internals, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor e1b913f 36/52: Re-implement wraparound for flymake-goto-next-error, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 3dfe11c 28/52: Simplify flymake logging and erroring., Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 9329265 40/52: Treat flymake errors as just another type of diagnostic, Jo�o T�vora, 2017/10/01
- [Emacs-diffs] scratch/flymake-refactor 38c7d4f 41/52: Remove old flymake-display-err-menu-for-current-line, it's useless, Jo�o T�vora, 2017/10/01