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

From: Elijah Gabe Pérez <[email-masked]>
Date: Fri, 21 Feb 2025 11:47:15 -0600

Juri Linkov <[email-masked]> writes:

> Or truncate-string-to-width.

I didn't know about that function.
I've now updated the patch:

>From a1c1236ab472fe56b1aaa2542b47ca9cafbe5410 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.
---
 doc/misc/flymake.texi     |  4 ++++
 etc/NEWS                  |  8 ++++++++
 lisp/progmodes/flymake.el | 14 +++++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi
index 54835767928..cee7bb24c76 100644
--- a/doc/misc/flymake.texi
+++ b/doc/misc/flymake.texi
@@ -348,6 +348,10 @@ Customizable variables
 early aid that relieves you from moving around or reaching for the
 mouse to consult an error message.
 
+@item flymake-max-length-eol-diagnostic-summary
+When non-nil, set a maximum length for end-of-line diagnostic summary
+descriptions.
+
 @item flymake-error-eol
 A custom face for summarizing diagnostic error messages.
 
diff --git a/etc/NEWS b/etc/NEWS
index f06fb7ef151..19bcc29b381 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -280,8 +280,16 @@ When such value is used, the 'project-prompter' is called with it as the
 first argument.  This is a way for the callers to indicate, for example,
 the reason or the context why the project is asked for.
 
+** Flymake
+
++++
+*** New user option 'flymake-max-length-eol-diagnostic-summary'.
+When non-nil, set a maximum length for end-of-line diagnostic summary
+descriptions.
+
 ** Registers
 
+---
 *** New functions 'buffer-to-register' and 'file-to-register'.
 These allow users to interactively store file and buffers in registers.
 Killed buffers stored in a register using 'buffer-to-register' are
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 9dda53713f5..04a6d53ea40 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 summary length to truncate in end-of-line diagnostics.
+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,7 +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
+              (propertize (if flymake-max-length-eol-diagnostic-summary
+                              (truncate-string-to-width
+                               (flymake-diagnostic-oneliner d t)
+                               flymake-max-length-eol-diagnostic-summary
+                               nil nil t)
+                            (flymake-diagnostic-oneliner d t))
+                          'face
                           (flymake--lookup-type-property (flymake--diag-type d)
                                                          'eol-face))))
     (let* ((diags
-- 
2.48.1

-- 
                                                   - E.G via GNU Emacs.