From 6957dec12d747a13a9bb835375d6cb50a3f21a64 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 12 Jul 2026 00:02:34 -0700 Subject: [PATCH] Change tooltip stuff --- init.el | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/init.el b/init.el index 89f4e91..b490aa1 100644 --- a/init.el +++ b/init.el @@ -1302,13 +1302,28 @@ display." (posframe-hide name)) (posframe-hide name)))) -(defun my/floating-tooltip (name msg) +(defun my/-floating-tooltip-fill-string (msg &optional width prefix) + "Fill MSG to WIDTH, defaulting to 80 characters. +If PREFIX is a number, add that many spaces before each continuation line. If +it is a string, add that string. If it is nil, add 5 spaces." + (with-temp-buffer + (insert msg) + (let ((fill-column (or width 80)) + (fill-prefix (if (natnump prefix) + (make-string prefix ? ) + prefix))) + (fill-region (point-min) (point-max))) + (buffer-string))) + +(defun my/floating-tooltip (name msg &optional width prefix) "If `display-graphic-p', call `my/posframe-tip', otherwise `popup-tip'. MSG is the message to show in the popup. NAME is the name of the buffer to pass -to `posframe-show' if the display is graphical." - (if (display-graphic-p) - (my/posframe-tip name msg) - (popup-tip msg))) +to `posframe-show' if the display is graphical. +WIDTH and PREFIX are as for `my/-floating-tooltip-fill-string'." + (let ((msg (my/-floating-tooltip-fill-string msg width prefix))) + (if (display-graphic-p) + (my/posframe-tip name msg) + (popup-tip msg)))) ;; flymake (use-package flymake @@ -1371,7 +1386,7 @@ If BUFFER is nil, the current buffer is used." out)) (defun my/-add-list-dot-to-string (str) - "Add a dot (•) to the starrt of STR. + "Add a dot (•) to the start of STR. If STR has multiple lines, add a space to the start of every other line." (cl-labels ((rec (acc strs need-add) (if strs @@ -1389,7 +1404,7 @@ If STR has multiple lines, add a space to the start of every other line." (let ((message)) (when-let* (((bound-and-true-p flymake-mode)) (diag (get-char-property (point) 'flymake-diagnostic))) - (cl-callf nconc message (string-split (flymake--diag-text diag) "\n" t))) + (cl-callf nconc message (list (flymake-diagnostic-text diag)))) (when (bound-and-true-p flycheck-mode) (cl-callf nconc message (mapcar 'flycheck-error-message (flycheck-overlay-errors-at (point))))) @@ -1407,7 +1422,8 @@ If STR has multiple lines, add a space to the start of every other line." (when message (my/floating-tooltip " *my-diagnostic-posframe*" (mapconcat #'my/-add-list-dot-to-string - message "\n"))))) + message "\n") + nil 4)))) (defconst my/consult-flymake-flycheck-narrow '((?e . "Error")