Scaling/Resizing of sideline fonts
I would like to scale down the font size of the sideline messages. Currently, this doesn't work, because lsp-ui-sideline--compute-height injects a (height 1) and overrides the height setting from the faces.
I made a small patch to get what I want, but I guess there are more places to adapt. Now, I can change the face properties of the sideline font without: (set-face-attribute 'lsp-ui-sideline-global nil :height 0.75)
diff --git i/lsp-ui-sideline.el w/lsp-ui-sideline.el
index 2b3a2ef..0f901cc 100644
--- i/lsp-ui-sideline.el
+++ w/lsp-ui-sideline.el
@@ -270,8 +270,8 @@ MARKED-STRING is the string returned by `lsp-ui-sideline--extract-info'."
(replace-regexp-in-string "[\n\r\t ]+" " "))))
(defun lsp-ui-sideline--align (&rest lengths)
- (+ (apply '+ lengths)
- (if (display-graphic-p) 1 2)))
+ (list (* (window-font-width nil 'lsp-ui-sideline-global)
+ (+ (apply '+ lengths) (if (display-graphic-p) 1 2)))))
(defun lsp-ui-sideline--compute-height nil
"Return a fixed size for text in sideline."
@@ -433,7 +433,7 @@ Push sideline overlays on `lsp-ui-sideline--ovs'."
(add-face-text-property 0 len face nil message)
message))
(string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(lsp-ui-sideline--align len margin))))
- (propertize message 'display (lsp-ui-sideline--compute-height))))
+ message))
(pos-ov (lsp-ui-sideline--find-line len bol eol t offset))
(ov (and pos-ov (make-overlay (car pos-ov) (car pos-ov)))))
Right aligning a text in Emacs is much easier than I thought. The problem is, there's a bug in 27.1 that breaks :align-to when Emacs is compiled with --with-cairo. But there's already a fix in Emacs 28. For more infos see here: Why is (1 . width) zero?
This snippet aligns the text on the right side and I can scale down the font and scale up the default font with C-x C-+ and the text stays on the right side. That's pretty cool.
(set-face-attribute 'lsp-ui-sideline-global nil :height 0.75)
(let* ((text " abcd")
(len (length text))
)
(add-text-properties 0 len '(font-lock-face (error lsp-ui-sideline-global)) text)
(add-text-properties 0 1 `(display (space :align-to (- text (,(1- len) . width)))) text)
(insert "\n" (format "%S" text) "\n" text "\n"))
@jo-so do you have a patch using your fix? I would like to use it!
I tried the following snippet:
(set-face-attribute 'lsp-ui-sideline-global nil :family "Segoe UI Variable Static Small" :italic t :height 0.8)
(set-face-attribute 'lsp-ui-sideline-code-action nil :family "Segoe UI Variable Static Small" :italic t :height 0.8)
(set-face-attribute 'lsp-ui-sideline-symbol-info nil :family "Segoe UI Variable Static Small" :italic t :height 0.8)
(set-face-attribute 'lsp-ui-sideline-symbol nil :family "Segoe UI Variable Static Small" :italic t :height 0.8)
(set-face-attribute 'lsp-ui-sideline-current-symbol nil :family "Segoe UI Variable Static Small" :italic t :height 0.8)
However, only the "family" attribute is changed. I am seeing no italic or height difference. I cannot locate which face is overriding these lsp-ui faces. I even went into the lsp-ui-sideline source code to change the heights from 0.99 to 0.8 and byte compiled it, yet still no height change.
font family changes, but no italics or height change

friendly ping :)
Overriding lsp-ui-sideline--compute-height and lsp-ui-sideline--align once lsp has been loaded works for me (changes derived from comments above, thanks a lot @jo-so!):
;;
;; 2022-03-28 - fix sideline height computation
;;
(defun lsp-ui-sideline--compute-height nil
"Return a fixed size for text in sideline."
(let ((fontHeight (face-attribute 'lsp-ui-sideline-global :height)))
(if (null text-scale-mode-remapping)
'(height
(if (floatp fontHeight) fontHeight
(/ (face-attribute 'lsp-ui-sideline-global :height) 100.0)
)
;; Readjust height when text-scale-mode is used
(list 'height
(/ 1 (or (plist-get (cdr text-scale-mode-remapping) :height)
1)))))))
;;
;; 2022-03-28 - fix sideline alignment
;;
(defun lsp-ui-sideline--align (&rest lengths)
"Align sideline string by LENGTHS from the right of the window."
(list (* (window-font-width nil 'lsp-ui-sideline-global)
(+ (apply '+ lengths) (if (display-graphic-p) 1 2)))))
If you use use-package, this automates it for me:
(use-package lsp-ui :commands lsp-ui-mode
:config (progn
;;
;; 2022-03-28 - fix sideline height computation
;;
(defun lsp-ui-sideline--compute-height nil
"Return a fixed size for text in sideline."
(let ((fontHeight (face-attribute 'lsp-ui-sideline-global :height)))
(if (null text-scale-mode-remapping)
'(height
(if (floatp fontHeight) fontHeight
(/ (face-attribute 'lsp-ui-sideline-global :height) 100.0)
)
;; Readjust height when text-scale-mode is used
(list 'height
(/ 1 (or (plist-get (cdr text-scale-mode-remapping) :height)
1)))))))
;;
;; 2022-03-28 - fix sideline alignment
;;
(defun lsp-ui-sideline--align (&rest lengths)
"Align sideline string by LENGTHS from the right of the window."
(list (* (window-font-width nil 'lsp-ui-sideline-global)
(+ (apply '+ lengths) (if (display-graphic-p) 1 2)))))
))
I found that I can get the scaling to work 1:1 with the default font, without any configuration changes, for lsp-ui-sideline-global if I reset my font manually after lsp-ui loads for a buffer with something like
` (defun font-set-font-size (font-size) "Set the font size of the current font to the prefix arg or else ask for the font size at a prompt." (interactive "P") (if (not current-prefix-arg) (let ((font-size (read-number "Font size, e.g., 17: "))) (set-face-attribute 'default nil :height (* 10 font-size))) (set-face-attribute 'default nil :height (* 10 font-size))))
M-x font-set-font-size
`
This immediately makes the sideline font the same size as my regular font. This maybe tells me that a higher priority font is setting the initial scale for lsp-ui-sideline-global and by doing this I reset the scale and "fix" the small sideline font issue. If you want the sideline font smaller than your default, then this is not the fix - this is not my problem, for me it was very small compared to my default font. Hope this helps someone. Obviously you have to adjust for your own font definition.
Subsequently, I also found that setting the second and third parameters to t on set-frame-font also solves this when I set my default font for Emacs. So instead of:
(set-frame-font "-*-PragmataPro Mono-normal-normal-normal-*-20-*-*-*-m-0-iso10646-1")
I do
(set-frame-font "-*-PragmataPro Mono-normal-normal-normal-*-20-*-*-*-m-0-iso10646-1" t t)
and this was discovered because of https://github.com/peterhoeg/doomemacs/commit/416fe49b3d3940eb60754cd8d79b804777610401.
You'll notice that the second and third parameters of set-frame-font control "keep size" and "frame". This apparently impacts childframes which is what lsp-ui-sideline-global face is displayed in.