(cl-incf i)))
menu)
+(defun flymake--fix-diagnostic (diag)
+ "Fix diagnostic DIAG."
+ (when-let* ((fixfn (flymake--diag-fix-function diag))
+ (fixes (funcall fixfn (flymake--diag-data diag)))
+ (edits (car (if (cdr fixes)
+ (alist-get
+ (completing-read (format-prompt "Fix" (caar fixes))
+ fixes nil t nil nil (caar fixes))
+ fixes nil nil #'string=)
+ (cdar fixes)))))
+ (if (functionp edits) (funcall edits) (refactor-apply-edits edits))
+ t))
+
(defun flymake-fix (pos)
"Fix Flymake diagnostic at POS."
(interactive "d")
;; TODO - fix _all_ diagnostics at point.
(if-let ((diags (flymake-diagnostics pos)))
- (if-let ((diag (seq-find #'flymake--diag-fix-function diags))
- (fixes (funcall (flymake--diag-fix-function diag)
- (flymake--diag-data diag)))
- (edits (car (if (cdr fixes)
- (alist-get
- (completing-read (format-prompt "Fix" (caar fixes))
- fixes nil t nil nil (caar fixes))
- fixes nil nil #'string=)
- (cdar fixes)))))
- (if (functionp edits) (funcall edits) (refactor-apply-edits edits))
- (message "No fix available for this diagnostic"))
+ (let ((diag (seq-find #'flymake--diag-fix-function diags)))
+ (if (and diag (flymake--fix-diagnostic diag))
+ (flymake--update-diagnostics-listings (current-buffer))
+ (message "No fix available for this diagnostic")))
(user-error "No diagnostic at this position")))
(cl-defun flymake--highlight-line (diagnostic &optional foreign)
(defvar-keymap flymake-diagnostics-buffer-mode-map
:doc "Keymap for Flyamke diagnostics list buffers."
"RET" #'flymake-diagnostics-buffer-goto-diagnostic
- "SPC" #'flymake-diagnostics-buffer-show-diagnostic)
+ "SPC" #'flymake-diagnostics-buffer-show-diagnostic
+ "C-c C-f" #'flymake-diagnostics-buffer-fix-diagnostic)
(defun flymake-diagnostics-buffer-show-diagnostic (pos &optional action)
"Show location of diagnostic at POS.
Optional argument ACTION is passed to `display-buffer', which see."
- (interactive "d")
+ (interactive "d" flymake-diagnostics-buffer-mode)
(let* ((id (or (tabulated-list-get-id pos)
(user-error "No diagnostic at this position")))
(diag (plist-get id :diagnostic))
(goto-char bbeg)))))
(current-buffer))))
+(defun flymake-diagnostics-buffer-fix-diagnostic (pos)
+ "Fix Flymake diagnostic at POS."
+ (interactive "d" flymake-diagnostics-buffer-mode)
+ (let* ((id (or (tabulated-list-get-id pos)
+ (user-error "No diagnostic at this position")))
+ (diag (plist-get id :diagnostic)))
+ (if (flymake--fix-diagnostic diag)
+ (revert-buffer)
+ (user-error "No fix available for this diagnostic"))))
+
(defun flymake-diagnostics-buffer-goto-diagnostic (pos)
"Show location of diagnostic at POS.
POS can be a buffer position or a button"
- (interactive "d")
+ (interactive "d" flymake-diagnostics-buffer-mode)
(pop-to-buffer
(flymake-diagnostics-buffer-show-diagnostic
(if (button-type pos) (button-start pos) pos))))
t nil))
for type = (flymake-diagnostic-type diag)
for backend = (flymake-diagnostic-backend diag)
+ for fixfn = (flymake--diag-fix-function diag)
for bname = (or (ignore-errors (symbol-name backend))
"(anonymous function)")
for data-vec = `[,(format "%s" line)
"\\1\\2" bname)
"(anon)")
'help-echo (format "From `%s' backend" backend))
+ ,(if fixfn "Yes" "")
(,(flymake-diagnostic-oneliner diag t)
mouse-face highlight
help-echo "mouse-2: visit this diagnostic"
(< (plist-get (car l1) :severity)
(plist-get (car l2) :severity))))
("Backend" 8 t)
+ ("Fix" 3 t)
("Message" 0 t)])
(define-derived-mode flymake-diagnostics-buffer-mode tabulated-list-mode