SystemCrafters / crafted-emacs

A sensible base Emacs configuration.
MIT License
739 stars 117 forks source link

Problems with emacsclient #195

Closed fernandovmacedo closed 2 years ago

fernandovmacedo commented 2 years ago

I've cloned the repo, ran a normal emacs instance and everything was fine. But when I run emacs as daemon the theme font is not loaded correctly, the font size is different and the start screen is not shown, it goes directly to the scratch buffer.

jeffbowman commented 2 years ago

Not sure on the font issue, but I believe I have fixed the issue showing the startup screen in emacsclient. Can you please pull the updates and try again.

For the font issue, how are you setting it? Are you setting it in your early-config.el file?

Thanks for the report!

fernandovmacedo commented 2 years ago

Thank you for the quick reply. The problem with the start screen was solved with the commit.

The problem with the fonts persists. I am using the default example-config. I've tried to move block

  (custom-set-variables
     '(rational-ui-default-font
       '(:font "JetBrains Mono" :weight light :height 185)))

to early-config (maybe, if this is the right way, the example-config should be changed as well), but even there I see two problems. In both emacs and emacsclient the height parameter is not respected. Aside from that, the font seems to be loaded correctly in the emacs regular instance, but don't load in the emacsclient.

jeffbowman commented 2 years ago

Hm... not sure, I'll see if I can debug it. Maybe @jeastman could help with this also?

This is what I have in my early-config.el and I don't have a problem with the faces, heights, etc. but I'm not using the code from the example either.

;; Set the default font face before displaying the frame to avoid
;; resize issues.
(cond
 ((string-equal (symbol-name system-type) "windows-nt")
  ;; Windows does not have Anonymous Pro, use Courier New instead
  (custom-set-faces (backquote (default ((t (:family "Courier New" :height 140)))))
                    (backquote (fixed-pitch ((t (:height 140 :inherit (default))))))
                    (backquote (fixed-pitch-serif ((t (:height 140 :inherit (default))))))))
 ((string-equal (symbol-name system-type) "darwin")
  ;; MacOS does not have Anonymous Pro, use Monaco instead
  (custom-set-faces (backquote (default ((t (:family "Monaco" :height 180)))))
                    (backquote (fixed-pitch ((t (:height 180 :inherit (default))))))
                    (backquote (fixed-pitch-serif ((t (:height 180 :inherit (default))))))))
 (t
  ;; Linux systems, can easily install this font
  (custom-set-faces (backquote (default ((t (:family "Anonymous Pro" :height 180)))))
                    (backquote (fixed-pitch ((t (:height 180 :inherit (default))))))
                    (backquote (fixed-pitch-serif ((t (:height 180 :inherit (default)))))))))

Following that pattern, you could probably use something like this:

(custom-set-faces (backquote (default ((t (:family: "JetBrains Mono" :weight light :height 185))))))

The issue might be the :font keyword, I'm not sure that is a supported spec keyword in Emacs, but I'll have to do some research.

jeffbowman commented 2 years ago

The :font keyword is allowed, however, the example file is incorrect. The correct usage of :font would be:

  (custom-set-variables
     '(rational-ui-default-font
       '(:font "JetBrains Mono Light 18")))

I am not seeing this font being set when I use a minimal configuration to only set the font (ie, no rational modules and I manually set the face in early-config.el) regardless if I run emacs or emacsclient.

Still working on it.

fernandovmacedo commented 2 years ago

I've deleted the code block setting the rational font and added (add-to-list 'default-frame-alist '(font . "JetBrains Mono")) to my early-config.el and that solved the problem.

I did by blindly copying and pasting from stackoverflow. What was the problem or why this has solved the issue, I don't know.

jeffbowman commented 2 years ago

Here is why that worked:

During startup, the early-init.el and subsequently (in our case) the early-config.el file is loaded. This happens before any graphical elements are created. You modified the default-frame-alist which is the list of parameters for all frames launched by Emacs. The very first frame can have different parameters from the rest by modifying the initial-frame-alist. The parameters in this list only affect the first frame (not the subsequent ones - those are controlled by the default-frame-alist).

The initial graphical frame is created with the initial (or when that is nil the default) parameters just before the init.el and subsequently in our case the config.el files are loaded. Your config.el file might load more configuration for the UI as well.

However, there is one more place to configure UI settings, that is the emacs-startup-hook.

Once the emacs-startup-hook is run, Emacs then runs the frame-notice-user-settings function to update the frame.

So, you can set the font as you did in the default-frame-alist, or you can add code like the following to your config.el which is maybe the slightly more recommended approach compared to others:

 (add-hook 'emacs-startup-hook
      (lambda ()
        (custom-set-faces
         `(default ((t (:font "JetBrains Mono Light 12"))))
         `(fixed-pitch-serif ((t (:inherit (default))))))))

I'll update the example as this method will also resolve the issue you were seeing.

jeffbowman commented 2 years ago

Closing after pushing an update to the examples and with the OP finding a solution.