Subject: bug#76455: [PATCH] Allow truncate flymake end-of-line diagnostic summary

From: Elijah Gabe Pérez <[email-masked]>
Date: Thu, 20 Feb 2025 22:49:37 -0600

Tags: patch

This patch allow to user set a limit for
`flymake-show-diagnostics-at-end-of-line' summary text.

This way you can shorten long messages like:

(message ) ‘message’ called with 0 arguments, but requires 1 or more
           error message^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

to...

(message ) ‘message’ called with 0 arguments...
           error message^^^^^^^^^^^^^^^^^^^^^^^

This is related to bug#74691, which I also have this problem.

>From 09b591a3b261b656bdcdf0644e3a186bbd1e001d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Thu, 20 Feb 2025 22:20:29 -0600
Subject: [PATCH] Allow truncate flymake end-of-line diagnostic summary

* lisp/progmodes/flymake.el (flymake-max-length-eol-diagnostic-summary):
New user customizable variable.
(flymake--eol-overlay-summary): Allow truncate summary if
`flymake-max-length-eol-diagnostic-summary' is non-nil.
---
 lisp/progmodes/flymake.el | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 9dda53713f5..9fca65e6491 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -541,6 +541,12 @@ flymake-show-diagnostics-at-end-of-line
                  (const :tag "Don't display diagnostics at end-of-line" nil))
   :package-version '(Flymake . "1.3.6"))
 
+(defcustom flymake-max-length-eol-diagnostic-summary nil
+  "Set maximum string length to truncate in end-of-line summary diagnostic.
+If set to nil (default), there's not limit and string summary
+won't be truncated."
+  :type '(choice integer (const :tag "No limit" nil)))
+
 (define-obsolete-face-alias 'flymake-warnline 'flymake-warning "26.1")
 (define-obsolete-face-alias 'flymake-errline 'flymake-error "26.1")
 
@@ -819,9 +825,13 @@ flymake--delete-overlay
 (defun flymake--eol-overlay-summary (src-ovs)
   "Helper function for `flymake--update-eol-overlays'."
   (cl-flet ((summarize (d)
-              (propertize (flymake-diagnostic-oneliner d t) 'face
-                          (flymake--lookup-type-property (flymake--diag-type d)
-                                                         'eol-face))))
+              (propertize (concat (substring (flymake-diagnostic-oneliner d t)
+                                             0 flymake-max-length-eol-diagnostic-summary)
+                                  (if flymake-max-length-eol-diagnostic-summary
+                                      "..."))
+                          'face (flymake--lookup-type-property
+                                 (flymake--diag-type d)
+                                 'eol-face))))
     (let* ((diags
             (cl-sort
              (mapcar (lambda (o) (overlay-get o 'flymake-diagnostic)) src-ovs)
-- 
2.48.1

-- 
                                                   - E.G via GNU Emacs.