1

I have the following function in my emacs config:

(defun *make-frame-pretty (frame)
  "`*make-frame-pretty' will apply additional theme settings to make it prettier"
  ;; Add a fringe.
  ;; It's quite nice and makes things easier to read
  (set-fringe-mode
   (/ (- (frame-pixel-width)
         (* 75 (frame-char-width)))
      16))

  (set-default-font "Fira Code"))
(add-hook 'after-make-frame-functions '*make-frames-pretty t)

Outside the function, when starting emacs directly, this code applies the font and fringe size, however when starting an emacs daemon and then starting a client frame, it doesn't apply. When setup as a function as a hook like this, it doesn't apply at all.

How can I get this code to run when a new frame is created?

1

These appearance settings are controlled via frame parameters. The simple way to set them is to add the parameters you want to default-frame-alist and initial-frame-alist. The font is font and the fringe is left-fringe and right-fringe.

(setq my-frame-alist '((font . "Fira Code")
                       (left-fringe . 10)
                       (right-fringe . 10)))
(setq default-frame-alist (append my-frame-alist default-frame-alist))
(setq initial-frame-alist (append my-frame-alist initial-frame-alist))

This method doesn't allow you to make the fringe size depend on the frame's initial size. If you want to do that then you have to do it from after-make-frame-functions. I think (but I haven't tested) that the problem you're running into is that after-make-frame-functions run before the frame is selected, but set-fringe-mode and set-default-font apply to the selected frame. So to get an automatic fringe size, change *make-frames-pretty to select the new frame.

(defun *make-frame-pretty (frame)
  "`*make-frame-pretty' will apply additional theme settings to make it prettier"
  (with-selected-frame frame
    ;; Add a fringe.
    ;; It's quite nice and makes things easier to read
    (set-fringe-mode
     (/ (- (frame-pixel-width)
           (* 75 (frame-char-width)))
        16))
   (set-default-font "Fira Code")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.