dired-sidebar icon indicating copy to clipboard operation
dired-sidebar copied to clipboard

Dired-sidebar Custom font problem.

Open Blade6570 opened this issue 1 year ago • 3 comments

Even if I have (customize-set-variable 'dired-sidebar-use-custom-font t) in my init file, sidebar fails to inherit my font. I found out that removing (buffer-face-mode-invoke 'variable-pitch t) in the dired-sidebar-set-font function fixes the font issue.

The variable-pitch face can be customized too and if it is not then may be sidebar fails to inherit the custom fonts. Maybe you have more insights on this.

Blade6570 avatar Mar 01 '23 08:03 Blade6570

Looking at dired-sidebar-face in 'Customize' says it's not customizable. Maybe something broke in 29.1?

chainedghost avatar Oct 29 '23 19:10 chainedghost

I'm guessing this is the same issue, but dired-sidebar-face no longer honors the :background property I had set to use a different color. I see that it was switched from a variable to a face sometime last year, but neither setting works. I'm still using Emacs 28.2.

ra4ul avatar Nov 18 '23 03:11 ra4ul

I am currently using this until someone figures this out:

  (when (member "Noto Sans" (font-family-list))
    (defun my-set-dired-font-family ()
      (face-remap-add-relative 'default :family "Noto Sans"))
    (add-hook 'dired-mode-hook 'my-set-dired-font-family))

chainedghost avatar Nov 22 '23 19:11 chainedghost

@jojojames Is this a bug or just a configuration issue? It seems like the user's choice of font for the sidebar either doesn't get applied at all, or does but gets clobbered immediately.

frou avatar Feb 26 '24 06:02 frou

Hi, thanks very much for dired sidebar. I am experimenting with replacing treemacs with it (due to some issues on windows) and so far, so amazing. I have one question, which is related to this ticket I believe. I'd like to also customise my font, as the OP; but in my case, I just want to make the font size a couple of points smaller than the current size. Can someone provide an example of how to use dired-sidebar-face please? I tried following on from @chainedghost above, e.g.:

  (when (member "Noto Sans" (font-family-list))
    (defun my-set-dired-font-family ()
      (face-remap-add-relative 'default :family "Noto Sans"))
    (add-hook 'dired-mode-hook 'my-set-dired-font-family))

but could not quite understand how this applies to changing the font in dired-sidebar I'm afraid. Many thanks for your time.

mcraveiro avatar Mar 01 '24 17:03 mcraveiro

Actually, whilst checking your docs, I bumped into ibuffer-sidebar [1], which has a similar approach:

(use-package ibuffer-sidebar
  :load-path "~/.emacs.d/fork/ibuffer-sidebar"
  :ensure nil
  :commands (ibuffer-sidebar-toggle-sidebar)
  :config
  (setq ibuffer-sidebar-use-custom-font t)
  (setq ibuffer-sidebar-face `(:family "Helvetica" :height 140)))

I think I just need to play around with dired-sidebar-face in a similar fashion. Cheers

[1] https://github.com/jojojames/ibuffer-sidebar?tab=readme-ov-file

mcraveiro avatar Mar 01 '24 18:03 mcraveiro

Right, I think I just about got to the point of the original poster, and all my woes are indeed related to variable-pitch. The implementation of ibuffer-sidebar says:

(defun ibuffer-sidebar-set-font ()
  "Customize font in `ibuffer-sidebar'.

Set font to a variable width (proportional) in the current buffer."
  (interactive)
  (setq-local buffer-face-mode-face ibuffer-sidebar-face)
  (buffer-face-mode))

With this I can set the height with no problems. But the implementation of dired-sidebar says:

(defun dired-sidebar-set-font ()
  "Customize font in `dired-sidebar'.

Set font to a variable width (proportional) in the current buffer."
  (interactive)
  (require 'face-remap)
  (setq-local buffer-face-mode-face 'dired-sidebar-face)
  (buffer-face-mode-invoke 'variable-pitch t))

With this I cannot change the font size. However, when I do:

(defun dired-sidebar-set-font ()
  "Customize font in `dired-sidebar'.

Set font to a variable width (proportional) in the current buffer."
  (interactive)
  (require 'face-remap)
  (setq-local buffer-face-mode-face 'dired-sidebar-face)
  ;; (buffer-face-mode-invoke 'variable-pitch t)
  (buffer-face-mode)
  )

And then a couple of evals:

(setq dired-sidebar-face `(:height 70 :family "Source Code Pro"))
(dired-sidebar-set-font)

This produces the desired result:

Screenshot from 2024-03-01 19-47-36

Now, I must prefix all of this by saying I have no great knowledge of emacs lisp, so this hackery may all be very dodgy :-) but at least it works for me. Can you explain why dired-sidebar works differently from ibuffer-sidebar on this regard? Tia

mcraveiro avatar Mar 01 '24 19:03 mcraveiro

Not sure why the implementations are different, it's been a few years since I wrote both but the ibuffer implementation should be newer. I copied it to dired-sidebar. https://github.com/jojojames/dired-sidebar/commit/573658021fd6e6cf032d789de29aca4e5dd258fd

jojojames avatar Mar 20 '24 19:03 jojojames