diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 9dda53713f5..44cbc18b8b0 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el @@ -748,34 +748,41 @@ flymake--severity (flymake--lookup-type-property type 'severity (warning-numeric-level :error))) -(defun flymake--indicator-overlay-spec (indicator) +(defun flymake--indicator-overlay-spec (type) "Return INDICATOR as propertized string to use in error indicators." - (let* ((value (if (symbolp indicator) + (let* ((indicator (flymake--lookup-type-property + type + (cond ((eq flymake-indicator-type 'fringes) + 'flymake-bitmap) + ((eq flymake-indicator-type 'margins) + 'flymake-margin-string)) + (alist-get 'bitmap (alist-get type ; backward compat + flymake-diagnostic-types-alist)))) + (value (if (symbolp indicator) (symbol-value indicator) indicator)) - (indicator-car (if (listp value) - (car value) - value)) - (indicator-cdr (if (listp value) - (cdr value)))) + (valuelist (if (listp value) + value + (list value))) + (indicator-car (car valuelist))) + (cond ((and (symbolp indicator-car) flymake-fringe-indicator-position) (propertize "!" 'display - (cons flymake-fringe-indicator-position - (if (listp value) - value - (list value))))) + (cons flymake-fringe-indicator-position valuelist))) ((and (stringp indicator-car) flymake-margin-indicator-position) (propertize "!" 'display `((margin ,flymake-margin-indicator-position) - ,(propertize - indicator-car - 'face - `(:inherit (,indicator-cdr - default))))))))) + ,(propertize indicator-car + 'face `(:inherit (,(cdr valuelist) default)) + 'mouse-face 'highlight + 'help-echo "Open Flymake diagnostics" + 'keymap `,(define-keymap + (format "<%s> " flymake-margin-indicator-position) + #'flymake-mouse-show-buffer-diagnostics)))))))) (defun flymake--resize-margins (&optional orig-width) "Resize current window margins according to `flymake-margin-indicator-position'. @@ -941,16 +948,7 @@ flymake--highlight-line (overlay-put ov prop (flymake--lookup-type-property type prop value))))) (default-maybe 'face 'flymake-error) - (default-maybe 'before-string - (flymake--indicator-overlay-spec - (flymake--lookup-type-property - type - (cond ((eq flymake-indicator-type 'fringes) - 'flymake-bitmap) - ((eq flymake-indicator-type 'margins) - 'flymake-margin-string)) - (alist-get 'bitmap (alist-get type ; backward compat - flymake-diagnostic-types-alist))))) + (default-maybe 'before-string (flymake--indicator-overlay-spec type)) ;; (default-maybe 'after-string ;; (flymake--diag-text diagnostic)) (default-maybe 'help-echo @@ -1369,12 +1367,31 @@ flymake-start nil))) (flymake--import-foreign-diagnostics)))))) -(defvar flymake-mode-map - (let ((map (make-sparse-keymap))) - (define-key map `[,flymake-fringe-indicator-position mouse-1] - #'flymake-show-buffer-diagnostics) - map) - "Keymap for `flymake-mode'.") +(defun flymake-mouse-show-buffer-diagnostics (event) + "Show diagnostics buffer on mouse click in the margin or fringe. +This uses two different approaches to work. +For margin it is set as a char property of the margin character directly. +While in the fringe it is set as part of the `flymake-mode-map'." + (interactive "e") + (mouse-minibuffer-check event) + (let* ((posn (event-end event)) + (pos (posn-point posn))) + (when (numberp pos) + (with-selected-window (posn-window posn) + (with-current-buffer (window-buffer) + (goto-char pos) + (when (catch 'found + (dolist (overlay (overlays-in pos (1+ pos))) + (when (overlay-get overlay 'flymake-overlay) + (throw 'found t)))) + (flymake-show-buffer-diagnostics))))))) + +;; Set the fringe mouse-1 action directly and perform the filtering +;; latter iterating over the overlays. +(defvar-keymap flymake-mode-map + :doc "Keymap for `flymake-mode'." + (format "<%s> " flymake-fringe-indicator-position) + #'flymake-mouse-show-buffer-diagnostics) ;;;###autoload (define-minor-mode flymake-mode