Emacs : "set default font" and init.el - emacs

I want to set up my starting default font.
I choose a font in Options --> set Default Font. then I save it with Options --> Save Options.
This writes at the end of my ~/.emacs.d/init.el file :
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant italic :weight bold :height 241 :width normal :foundry "microsoft" :family "Trebuchet MS" "Courier New" :foundry "monotype" :slant normal :weight bold :height 240 :width normal "Courier New"))))
When starting emacs again, the selected font is not loaded. And there is no problem with the init.d file, as reported in *Messages* or by --debug-init.
It seems the mechanism by which "set default font" finds fonts and init.d finds fonts are different ...
What do I do wrong ?
Running on Ubuntu 14.04LTS, Emacs 24

This works for me (Emacs 27.1)
;; Set default font
(set-face-attribute 'default nil
:family "Courier New"
:height 120
:weight 'normal
:width 'normal)

You can set it in your init.el file the following:
(set-default-font "Inconsolata 12")
or monaco font
(set-default-font "Monaco 12")

Related

how does emacs choose which script to initialize with?

In both emacs 25.2.2 on Ubuntu 18.10, and 26.2 on arch we are experiencing the following weird behavior:
Ubuntu 18:
there is a .emacs file in my home directory.
If I run emacs, it works
.emacs sets indent style, font, and color
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :height 180 :width normal :foundry "urw" :family "Nimbus Mono L")))))
(set-background-color "black")
(set-foreground-color "green")
When emacs is run by gnome-settings, it does not set the font correctly, but does set the indent and the color. I therefore conclude that the font setting is not working when gnome is first set up.
On arch, running emacs looks ok. But then if we load the file and M-x eval-buffer the font changes. Evaluating twice changes the font again. Eval a third time does nothing.
Can anyone explain what is happening, and how we can reliably select a font regardless of when the command is run?

how to unset the foreground color of whitespace-mode for Emacs

In programming files, I use whitespace-mode to highlight the tab and long lines. The default highlighting is too garnish for me.I just want to highlight them with a gray background and keep whatever normal color it should be for the font. How could I set that?
The following setup does not work. I'd like the code beyond 80 columns appearing yellowish, as the characters inside 80 columns in the snapshot.
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
:background "#555"
:weight 'bold)
;; face for Tabs
(set-face-attribute 'whitespace-tab nil
:background "#555"
:weight 'bold)
set-face-attribute changes only the attributes you specify.
Set :foreground to nil:
(set-face-attribute 'whitespace-line nil
:foreground nil
:background "#555"
:weight 'bold)
For me the unpleasant color turned out to be trailing-whitespace and I'm using this:
;; whitepace looks rediculous in color themes.
(defadvice color-theme-install (after my-color-theme-install-after activate)
"Fix trailing-whitespace after color theme destroys it"
(set-face-attribute 'trailing-whitespace nil
:foreground 'unspecified
:inverse-video 'unspecified
:slant 'unspecified
:weight 'unspecified
:background "#fff"))

Emacs: how to specify where the true-type font is?

I want to make use of DejaVu font in emacs, on a cluster -- and I don't have access to install fonts system wide. I put fonts (they are free) in ~/.fonts. I want to make use of DejaVuSansMono.ttf. Normally I just put in .emacs:
(custom-set-variables
'(default ((t (:inherit nil :stipple nil :background "#ffffb1" :foreground "#141312" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 173 :width normal :foundry "monotype" :family "DejaVu Sans Mono")))))
But now emacs can't find the font!
So my question is - how can I help emacs to find the font? How can I specify the path to the font?
It looks like bdf-directory-list will fix it.
(setq bdf-directory-list '("/path/to/fonts"))
I can't try it right now - will be back later.

Changing a custom set face to display with those settings in certian emacs mode (text-mode, LaTeX-mode, etc..)

I had a custom-set-faces that I had used in an emacs startup file that was especially for when I launched latex files but I'm in the process of merging and updating my .emacs file so I don't launch a seperate start-up process for the latex file. I want to set it so this custom face is set only when latex mode is on. Since it is a custom face I don't think it is wise to set a LaTeX-mode-hook but I know there should be a way to do this. I only change the font and the text size basically for when I'm typing. I would also like this enabled for text-mode if possible. Attache the custom face below.
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans")))))
Instead of custom-set-faces you can set it with set-face-attribute, but it will still change the face "in all buffers".
(set-face-attribute 'default nil
:inherit nil
:stipple nil
:background "white"
:foreground "black"
:inverse-video nil
:box nil
:strike-through nil
:overline nil
:underline nil
:slant 'normal
:weight 'normal
:height 98
:width 'normal
:foundry "unknown"
:family "DejaVu Sans")
You should identify the right faces and only set them, don't set default. To identify which face is at point use this

Emacs customize-face loses/fails to recognise font-name it wrote to my .emacs itself

I used the Options/Set Default Font menu item to set my default emacs font to be LMMonoLtCond10 (it brought up a nice font-selector GUI widget to let me do this). My emacs immediately adopted the new font, and I was very happy. I then did Options/Save Options, and on inspecting my .emacs.d/init.el file saw that it had written the following there:
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black"
:inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal
:weight light :height 120 :width normal :foundry "unknown" :family "LMMonoLtCond10"))))
(There are a couple of other faces I've defined below that.)
Unfortunately, if I quit emacs, and restart, it completely fails to recreate the font configuration that I had selected. Instead, I think it's giving me LMRoman-12. Am I doing something wrong, or is this an emacs bug.
I'm using Emacs 23.1.1:
(emacs-version)
"GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.20.1)
of 2011-03-05 on palmer, modified by Debian"
on an Ubuntu system.
Sounds like it might be a bug. M-x report-emacs-bug