How do I set fonts on Emacs for Mac? - macos

I downloaded Carbon emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.35) from http://emacsformacosx.com/. It defaults to using Monaco, and I would like to change it to use Inconsolata-dz. So I added:
(set-default-font "-apple-Inconsolata-dz-medium-normal-normal-*-10-*-*-*-m-0-iso10646-1")
to my ~/.emacs file. However, after I restart, it is still Monaco. It discovered that Option-T (or maybe Command-T) brings up a font dialog, and if I select Inconsolata-dz from that, it works great. But if I restart, it is back to Monaco. So I tried setting the font from the menu, and then going to Customize Faces and saving it, but still it does not work. The interesting thing is that if I do M-x describe-font after changing the font from the Option-T dialog, it says -apple-Inconsolata-dz-medium-normal-normal--10--*-*-m-0-iso10646-1.
So it looks like Emacs is simply ignoring this font for some reason. Why is that, and what can I do to get it to use this font?
Update: I tried Donkopotamus and Joost Diepenaat's recommendations and they also did not work, although I ended up getting Times as my font, instead of Monaco. However, they work great if I just use the Inconsolata (not Inconsolata-dz). So I'm wondering if there is some problem with fonts with a dash in their name?
Update2: Why is this off-topic? The close message says "questions [should ...] relate to programming or software development in some way"; many developers use emacs, and getting settings right is important. The top two entries on a search for "programming fonts" have a combined 150; so font configs seem to be important to programmers. Anyway, if it is off-topic, where is the appropriate place to post it?

I use plain Inconsolata. From my emacs.d/init.el:
(set-face-attribute 'default nil
:family "Inconsolata" :height (case system-type
('gnu/linux 130)
('darwin 145)) :weight 'normal)
If you're only running on OSX, you can simplify that to
(set-face-attribute 'default nil
:family "Inconsolata" :height 145 :weight 'normal)

I use Inconsolata. In my .emacs I simply set the default font to Inconsolata using
; check if we're on OSX
(when (featurep 'ns-win)
(custom-set-faces
'(default ((t (:height 140 :width normal :family "Inconsolata")))))
)

I've seen this behavior on Mac, and now I do this in my emacs init file:
(set-face-attribute 'default nil :foundry "apple" :family "Anonymous_Pro")
That works nicely for me, but note that I'm using a newer (HEAD) version of Emacs. You would presumably need to use "Inconsolata-dz" as the value for :family.
Without this, new frames would always pop up using the system-wide default monospaced font (Monaco), which is likely what's happening for you.
P.S. Your Emacs version is a Cocoa Emacs, not a Carbon Emacs.

Are you sure your .emacs is being read in? For example, are other things in there taking effect?
Assuming that is okay, I use this in my init file:
;; (insert "\n(set-default-font \"" (cdr (assoc 'font (frame-parameters))) "\")\n")
Note that it is intentionally commented out. Now set your font using Command-T, then go to the end of the above line and do C-x C-e . It will insert a command to set your font to whatever it is now. Save/exit/enter Emacs and you should have your font.

Related

emacsclient, restore all windows in a frame in terminal

The object: In terminal, on start, in one frame, restore emacs workspace. i.e. restore all "windows", to the state before C-x C-c.
Descriptions: The window restoration could be simply done in emacs GUI, by adding (desktop-save-mode 1) to the init.el file.
However, when running emacs as a Daemon, emacsclient does not perform the same way. With the same setup, it still remember the major mode of the file, as well as other buffers before exiting, but the window layout will not be restored. Only 1 major window is displayed depend on the default settings.
I did some research, poked into some functions/variables using the elisp build-in documentation. I checked (desktop-save-buffer 1), framset-save, framset-restore and none of them seems to work. Also I checked similar questions posted before, and I found someone's answer using the following script:
(setq desktop-restore-forces-onscreen nil)
(add-hook 'desktop-after-read-hook
(lambda ()
(frameset-restore
desktop-saved-frameset
:reuse-frames (eq desktop-restore-reuses-frames t)
:cleanup-frames (not (eq desktop-restore-reuses-frames 'keep))
:force-display desktop-restore-in-current-display
:force-onscreen desktop-restore-forces-onscreen)))
However this script is buggy, it opens a "GUI" frame, and could not be closed properly(reopen automatically whenever closed, and if possible, I prefer to open the frame in terminal, so that a terminal 'texteditor' setting is possibe, with some other minor merits).
Sorry for the tedious question, any help would be appreciated.
I don't really know the right way to do this, but I was able to restore a frameset created in a GUI frame into a terminal frame. The new frame must be big enough or it will throw an error. I did (setq foo (frameset-save (frame-list))) and (pp foo (get-buffer "*scratch*")) to dump a readable representation of the frameset to the *scratch* buffer. Then I edited it by hand to get rid of (display . ":0.0"). That seemed to be enough to get it to not force a GUI frame. Then I did (frameset-restore [frameset ...]) on the edited frameset.
If you look at frameset.el, there are filtering functions to edit a frameset programmatically. Also, if you look at the comments, the display parameter is treated specially. You should look at the details there.

How can I set the default font size in aquamacs emacs?

I am having difficulty setting the default size in aquamacs emacs, under Lion. If I add something like
(set-face-attribute 'default nil :height 180)
To my .emacs file, the default size of the minibuffer will be 18pt, but the other buffers will still open at the old default size.
Options | Appearance | Font for Fundamental Mode (make sure you choose save options when quitting Aquamacs)
In aquamacs, it is not intuitive (understatement).
Options> customise Aquaemacs>SPecific Face...
then type, "default", just as it said above. This gets you to the screen where you can look really hard to find the "Height in 1/10 point" value.
Good luck!
-TPC
Probably the same way you do it for vanilla Emacs.
When you say "default" size, what do you mean? If you mean the default for future Emacs sessions also, then customize face default. Function set-face-attribute does not set the face persistently.
If you mean set it only for the current Emacs session, and set it for all existing and all future frames, then your code looks correct to me. In that case, consider filing a bug: M-x report-emacs-bug.

Setting emacs font under windows

I'm having trouble to change the font for my emacs configuration.
I've tried using set-default-font, and managed to tab to my desired font, however, some elements are still rendered as the old font (ie python's class names and function names)
set-default-font is really old, and has been deprecated in Emacs 23 in favor of its new name set-frame-font (which isn't much better). The current Emacs manual suggests several ways to set the default font, but I'll assume you've found those already, seeing as you've tried set-default-font...
The elisp code I use is actually different from all the methods suggested there:
;; [in .emacs]
;; Use 10-pt Consolas as default font
(set-face-attribute 'default nil
:family "Consolas" :height 100)
set-face-attribute seems to stick better than set-default-font; at least it seems to use Consolas consistently even in things like Python class and function names.
M-x customize-face default will let you customize the default font.
If some things are still rendered in a font you don't like, then position your cursor to be over the offending text and type M-x customize-face; the face that your cursor is over will be the default one to customize.

What does "s-[keyname]" refer to in Emacs, and how do I tell Emacs to ignore it?

Background information:
I'm on a Mac, and I've just upgraded to Emacs 23.1 via http://emacsformacosx.com/. There are a few issues, notably the lack of full screen ability.
I've attempted to get around this last issue by installing Megazoomer, which adds a global input manager bound to Cmd-return. This causes the currently forward application to maximise. However, Emacs reports that <s-return> is undefined. I've never seen an s-[key] mentioned before, and Google isn't forthcoming with an answer.
So, two parts:
What does s-[key] mean? This is purely for my satisfaction; and
Can I tell Emacs to ignore this key combination and let the key combination carry through to the system (so that hopefully I can have full screen Emacs back again)?
EDIT: so 1) is resolved, and as to 2) I've got: (global-set-key (kbd "<s-return>") 'ignore), which at least stops the error. However, Emacs still swallows the key combination, which isn't ideal.
It's the Super key, like M- is the Meta key (alt key on a PC keyboard, Command key on your keyboard) and C- is the Control key.
I have of course never actually seen a super key on my keyboard... they are from a long gone era. Wikipedia has an image of this impressive "Space Cadet keyboard" which has all the modifiers you'll ever need:
With plain Emacs 23.1 on a Macbook Pro, I can map the right option key to super by
(setq ns-right-option-modifier 'super)
Your other choice seems to be the function key, which would be ns-function-modifier. However, fn might have other uses, whereas Emacs’ default is to map ns-right-option-modifier to ’left (ie, the same effect as the left option key, which I at any rate need to get the # character!), so the right option key is to some extent redundant.
Left-handers may want to reverse this.
For the question about what the s-[key] means, on ubuntu box it means the Windows® shaped key. What it means on the OSX systems, I do not know.
As for maximizing windows, could you try this?
(It should work, iif OSX runs an X server somewhere underneath it all)
(if (equal (window-system) 'x)
(progn
(defun toggle-fullscreen ()
"Toggles fullscreen"
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))
(global-set-key (kbd "C-c C-y") 'x-clipboard-yank)
(global-set-key (kbd "M-RET") 'toggle-fullscreen)))
This little snippet is what I use to toggle fullscreen on my *nix computers. And yanking from X's clipboard is a neat ability to have.
As for how to set keybindings, use global-set-key for mode independent keybindings.
(Add it to your .emacs file if you want it to be permanent.)
(setq ns-command-modifier nil)
That is supposed to do what you want. However, it's having somewhat unpredictable behaviour on machine when I test it, so be warned.

Changing the font in Aquamacs?

I've recently had a need to do a bit of lisp editing and I found the nifty Ready Lisp package for OS X, which is great, except Aquamacs automatically uses a proportional font (which is idiotic, IMHO) and I want to change it to a monospace font. However, I'm not really much of an EMACS user, and the preferences menu in Aquamacs is less than clear on where and how one might make such a change.
In Aquamacs 2.1, you can set the font through Options->Appearance->Font for Text Mode... That brings up the standard font chooser window, choose the font you like. Then, when you exit out of emacs (C-x C-c) you'll be prompted to save options, hit "y".
This is what I have in my .emacs for OS X:
(set-default-font "-apple-bitstream vera sans mono-medium-r-normal--0-0-0-0-m-0-mac-roman")
Now, I'm not sure Bitstream Vera comes standard on OS X, so you may have to either download it or choose a different font. You can search the X font names by running (x-list-fonts "searchterm") in an ELisp buffer (e.g. *scratch* - to run it, type it in and then type C-j on the same line).
From the EmacsWiki Aquamacs FAQ:
To change the font used to display the
current frame, go to the font panel.
You can do this with the keystroke
Apple-t, or via the menu: Options →
Show/Hide → Font Panel. Once there,
select the font you want.
To make the current frame’s font the
default, go to Options → Frame
Appearance Styles. Select “use current
style for foo mode”, where foo is the
mode of the current frame (e.g.,
foo=text for text mode), to use the
current style (including the font, but
also any other changes you’ve made to
the frame’s style) for all files of
this type. Select “use current style
as default” to use the current style
for all files for whose major mode no
special style has been defined.
There are also recommendations for monospaced fonts - Monaco or "Vera Sans Mono".
this is the one I use:
-apple-DejaVu_Sans_Mono-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1
You can set it in .emacs file like:
(set-default-font "-apple-DejaVu_Sans_Mono-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1")
You can download it from dejavu-fonts.org
Fast forward a decade, for recent Aquamacs like ver 3.3 please see the nice solution for setting a fixed-width by default at https://emacs.stackexchange.com/questions/45135/change-permanently-font-size-in-aquamacs
Here's the relevant bit for those who are REALLY impatient but please go upvote that answer, user #nega deserves credit here
(when window-system
(setq initial-frame-alist nil) ;; Undo Aquamacs forced defaults
(setq default-frame-alist nil) ;; Undo Aquamacs forced defaults
(aquamacs-autoface-mode -1) ;; Use one face (font) everywhere
(set-frame-font "Menlo-12") ;; Set the default font to Menlo size 12
;;(set-default-font "Menlo-12") ;; This would do the same.
)

Resources