2

I have this code in my .emacs file (set-default-font "Monaco 16"). When I start emacs when it is not open (by clicking on the shortcut for instance) it starts with Monaco 16 but when I create a new frame with C-x 5 2 it starts with the old default font, which is too small to read for me. Is there a way around this?



EDIT

When loading emacs throws an error and the problem appears to be with (set-default-font "Monaco 16" nil t) in my .emacs. What is wrong? I copy the emacs debug copy:

Debugger entered--Lisp error: (wrong-number-of-arguments #[(font-name &optional$
\203^X^@\305\304\306\"\307 _^Q\305\304\310\"\311 _^P\312\313 \314^KBC\"\210
\2039^@\312\313 \306\315        \307 \"B\310\315^H\311 \"BD\"\210*\316\317\320\$
  set-default-font("Monaco 16" nil t)
  eval-buffer(#<buffer  *load*> nil "/Users/a/.emacs" nil t)  ; Reading at buff$
  load-with-code-conversion("/Users/a/.emacs" "/Users/a/.emacs" t t)
  load("~/.emacs" t t)
  #[nil "^H\205\276^@   \306=\203^Q^@\307^H\310Q\202A^@ \311=\2033^@\312\307\31$
  command-line()
  normal-top-level()
3

set-default-font is deprecated. But anyway, it sounds like it is doing for you what the doc string says. The way you are calling it, it should change the font only for the current frame.

If you want it to change the default font for all frames, then pass it t as the third argument. For example: (set-default-font "Monaco 16" nil t).

Do C-h f set-default-font and you will see something like this:

,----
| set-default-font is an alias for `set-frame-font' in `frame.el'.
| 
| (set-default-font FONT &optional KEEP-SIZE FRAMES)
| 
| This function is obsolete since 23.1;
| use `set-frame-font' instead.
| 
| Set the default font to FONT.
| When called interactively, prompt for the name of a font, and use
| that font on the selected frame.  When called from Lisp, FONT
| should be a font name (a string), a font object, font entity, or
| font spec.
| 
| If KEEP-SIZE is nil, keep the number of frame lines and columns
| fixed.  If KEEP-SIZE is non-nil (or with a prefix argument), try
| to keep the current frame size fixed (in pixels) by adjusting the
| number of lines and columns.
| 
| If FRAMES is nil, apply the font to the selected frame only.
| If FRAMES is non-nil, it should be a list of frames to act upon,
| or t meaning all graphical frames.  Also, if FRAME is non-nil,
| alter the user's Customization settings as though the
| font-related attributes of the `default' face had been "set in
| this session", so that the font is applied to future frames.
`----
  • Great! I added (set-default-font "Monaco 16" nil t) and this works but as I mentioned above @lawlist answer, when I enter C-x 5 2 it opens a new frame with the contents of the buffer. Is this how it is supposed to be? Creating frames documentation gnu.org/software/emacs/manual/html_node/emacs/… doesn't seem to make this clear. – Zeynel Dec 24 '13 at 11:38
  • The doc string says: If FRAME is non-nil, alter the user's Customization settings as though the font-related attributes of the **default** face had been "set in this session", so that the font is applied to future frames. So it should affect all frames created in the same session. And that's what I see too. If you do not, and you start from emacs -Q, consider doing M-x report-emacs-bug. However, this function is deprecated, so they probably won't fix the bug (if there is one). – Drew Dec 24 '13 at 16:36
  • Hi Drew: (set-default-font "Monaca 16" nil t) throws an error. So what is the best way for me to set the default font? (I added the debug report to my question) – Zeynel Dec 29 '13 at 19:47
  • What is the error? I can guess that you spelled Monaco wrong ;-), but perhaps you only wrote it wrong here. Earlier you said that it worked. Without knowing what error is raised, it's difficult to help. What is the best way? The doc string says that set-default-font is obsolete since Emacs 23, and you should use set-frame-font instead. – Drew Dec 29 '13 at 20:11
  • I see you've now posted the error, and with a backtrace. Good. For some reason, your set-default-font is expecting a different number of arguments. What does C-h f set-default-font tell you? If it shows the signature as indicated in the backtrace (but which is cut off): FONT-NAME &optional KEEP-SIZE FRAMES, then what happens if you remove that sexp from your .emacs, and you use emacs -Q (no init file), and you do M-: (set-default-font "Monaco 16" nil t)? Does that work? – Drew Dec 30 '13 at 4:00
1

If this doesn't work for a GUI version of Emacs, then another setting is likely conflicting with it:

(set-face-attribute 'default nil :background "black" :foreground "white"
  :font "Courier" :height 180)
  • It's strange, now it opens a new frame with the contents of the existing buffer. Previously it was opening a new blank frame. – Zeynel Dec 24 '13 at 2:25
  • What version of Emacs are you using? – lawlist Dec 24 '13 at 2:31
  • Emacs version 24.3 (9.0) on OS X. – Zeynel Dec 24 '13 at 10:55
0

In Emacs 24.3 on Mac OS X 10.9, (set-frame-font "Monaco 10" nil t) fails for me with a "wrong number of arguments" error, but (set-frame-font "Monaco 10") succeeds. However, it's only effective in the selected/initial frame.

Thankfully, (set-face-attribute 'default nil :font "Monaco 10") works for me and is effective in all frames.

0

See accepted answer from: Emacs font settings not working in new frame

ie:

(add-to-list 'default-frame-alist
             '(font . "Source Code Pro-15:style=Light"))

retains the specified font across new frames, confirmed under Emacs 24.4

0

One workaround is to customize default-frame-alist. C-h v default-frame-alist click 'customize' If there is no 'font' paramater, click 'INS' and add `font` as the Parameter. As the value, add "Monaco 16" (the double quotes are essential)

Then 'Apply' it for this session, (and test it by opening a new frame C-x 5 2) and 'Apply and Save' it to your initialization file.

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.