branch: elpa/gptel
commit b4138f1cbfcb33656765a738a6b1406887a271e3
Author: kovan <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>
gptel: Fix header-line alignment for variable-pitch fonts
gptel.el (gptel--header-line-info): Use pixel-based alignment via
`string-pixel-width' when available (Emacs 29+) instead of
character-count-based calculation with a hardcoded offset. This
fixes truncation and misalignment of header-line buttons when
using non-default or variable-pitch fonts.
For Emacs < 29, fall back to string-width which correctly handles
wide characters.
Fix #763.
---
gptel.el | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/gptel.el b/gptel.el
index 4599dfa705..8c40d8cff5 100644
--- a/gptel.el
+++ b/gptel.el
@@ -828,19 +828,22 @@ Search between BEG and END."
toggle-tools)
'mouse-face 'highlight
'help-echo "Select tools"))))
- (concat
- (propertize
- " " 'display
- `(space :align-to (- right
- ,(+ 5 (length model) (length system)
- (length track-media) (length context) (length
tools)))))
- tools (and track-media " ") track-media (and context " ") context " "
system " "
- (propertize
- (buttonize (concat "[" model "]")
- (lambda (&rest _) (gptel-menu)))
- 'mouse-face 'highlight
- 'help-echo "Model in use"))))
- "Information segment for the header-line in gptel-mode.")
+ (let ((rhs (concat
+ tools (and track-media " ") track-media
+ (and context " ") context " " system " "
+ (propertize
+ (buttonize (concat "[" model "]")
+ (lambda (&rest _) (gptel-menu)))
+ 'mouse-face 'highlight
+ 'help-echo "Model in use"))))
+ (concat
+ (propertize
+ " " 'display
+ (if (fboundp 'string-pixel-width)
+ `(space :align-to (- right (,(string-pixel-width rhs))))
+ `(space :align-to (- right ,(+ 5 (string-width rhs))))))
+ rhs))))
+ "Information segment for the header-line in `gptel-mode'.")
(defun gptel-use-header-line ()
"Set up the header-line for a gptel buffer.