emacs-lsp / lsp-treemacs

lsp-mode :heart: treemacs
GNU General Public License v3.0
396 stars 46 forks source link

Configuring font size via treemacs-text-scale #112

Closed mcraveiro closed 2 years ago

mcraveiro commented 2 years ago

Hi lsp-treemacs developers,

thanks a lot for your mode, I find it extremely useful. I use LSP treemacs symbols quite a lot but I have one small problem with it: as my method names are quite large, I need to resize its font to a smaller one. In regular treemacs I've achieved this via treemacs-text-scale, _e.g.:

(setq treemacs-text-scale -2)

Is there an equivalent way to achieve this in lsp-treemacs?

Many thanks for your time.

Marco

yyoncho commented 2 years ago

AFACS it should work in lsp-treemac as well. We should investigate why that does not work with lsp-treemacs.

mcraveiro commented 2 years ago

Thanks for your prompt reply @yyoncho. Now you say that, I do see LSP Symbols (-2) on the window, same as I see in the treemacs window. Is there something you'd like me to try to check for why this is not kicking in? I will try to look at the code, but my elisp is not the best sadly.

Screenshot from 2021-09-18 19-37-39

yyoncho commented 2 years ago

Can you test if https://github.com/emacs-lsp/lsp-treemacs/commit/2e9f6f6dc45f49623f12f29bd4fd7055290c5e0f works fine?

mcraveiro commented 2 years ago

Absolute genius @yyoncho, worked straight away! Many thanks for your help and your prompt response.

mcraveiro commented 2 years ago

Actually, now look a bit more carefully, it seems like lsp-treemacs is a bit more aggressive in the scaling than treemacs itself:

Screenshot from 2021-09-19 08-22-14

We should be at -2 but lsp-treemacs is at -8 and on every refresh it gets smaller :-) I think something is not quite right. Let me investigate, at least I know where to look now. Thanks

yyoncho commented 2 years ago

Ok, I will make sure it is called only once.

mcraveiro commented 2 years ago

Actually, sorry, I think there is more to this than I first thought. For good measure, I commented out your code and looked more carefully and now I notice that lsp-treemacs "thinks" its scaling by -2, though the font is no different from no scaling:

Screenshot from 2021-09-19 08-30-07

You can see on the above screenshot that though both treemacs windows are at -2, they look like they are at different scales. Could this be something to do with the face we use for lsp-treemacs-symbols perhaps?

mcraveiro commented 2 years ago

OK I did some more experimentation, and I think the problem can be described as follows:

      (text-scale-adjust 0)
      (text-scale-adjust -2)

This resulted in -2 correctly rendered at -2:

Screenshot from 2021-09-19 08-44-48

As you can see this is the same as regular treemacs at -2:

Screenshot from 2021-09-19 08-44-59

This leads me to conclude that we must be missing some "refresh" on startup before rendering, if you pardon the layperson terminology :-) or better put, we are rendering before we check the value of treemacs-text-scale. hope this is helpful, and thanks for your time.

mcraveiro commented 2 years ago

Actually, is this too much of a hack? :-D

diff --git a/elpa/lsp-treemacs-20210904.2039/lsp-treemacs.el b/elpa/lsp-treemacs-20210904.2039/lsp-treemacs.el
index e3adef8..0b3c690 100644
--- a/elpa/lsp-treemacs-20210904.2039/lsp-treemacs.el
+++ b/elpa/lsp-treemacs-20210904.2039/lsp-treemacs.el
@@ -929,6 +929,9 @@ will be rendered an empty line between them."
       (setq-local treemacs-space-between-root-nodes nil)
       (lsp-treemacs--set-mode-line-format search-buffer title)
       (lsp-treemacs-generic-refresh)
+      (when treemacs-text-scale
+        (text-scale-adjust 0)
+        (text-scale-increase treemacs-text-scale))
       (when expand-depth (lsp-treemacs--expand 'LSP-Generic expand-depth))
       (current-buffer))))

Seems to solve my problem :-)

mcraveiro commented 2 years ago

Eh eh no, bad idea, my messages are now spammed with

Use +,-,0 for further adjustment

:-)

mcraveiro commented 2 years ago

OK I really don't know if this is a good fix or not, but it at least solves all my problems :-)

      (when treemacs-text-scale
        (text-scale-set treemacs-text-scale))

The main improvement over the previous approach is that the pesky Use +,-,0 for further adjustment now goes away.

yyoncho commented 2 years ago

I think this is the way to go

mcraveiro commented 2 years ago

I think this is the way to go

Excellent, raised a PR, let me know if there are any issues. Thanks for your time.