I have a line in my .emacs which set a default font:
(set-default-font "Monaco-10")
It works fine for me, but I need two exceptions:
I need to change default font for a one file, for example ~/some. How can I do it?
I need to change default fonr for a gnux (M-x gnus). How can I achieve it?
Take a look at the variable `face-remapping-alist'. For example, you can have something like this:
(add-hook 'find-file-hook
(lambda ()
(if (equal "~/some" (abbreviate-file-name (buffer-file-name)))
(set (make-local-variable 'face-remapping-alist)
'((default :family "DejaVu Serif"))))))
In Emacs files are represented in buffers - you don't change the font of the file, but that of the buffer. Shift-LeftClick in a buffer and you'll get a font dialog. In it you should select:
Change Buffer Font...
You might take a look at the code this command is bound to and use it for your needs.
Related
hi: Each time I insert some text in emacs , it will highlight the newly added text. I wonder how to change the background color of the highlight, because the highlight background color is very close to the font color , as a result, I can hardly recognize the code that I am writing.
thank you soooo much
For issues with fonts (which Emacs calls faces) inside of Emacs, it is often helpfull to know the function 'list-faces-display'. You can call this with M-x and it will list all faces defined in the current frame. This can be helpfull both identifying which face is problematic, it will also give you its name which can be used to modify the face. For instance to change the foreground colour of the face named "button" you can call something like this:
(set-face-foreground 'button "cyan")
The effect will be immediately visible. Many aspects of faces can be changed, including colour, font familiy and font size.
Obviously, this will not help you if the problematic behaviour stems from the terminal emulator you are using, as it would appear from some of the comments to your question, then the problem is outside of Emacs and cannot be fixed from inside of Emacs. Even so, knowing about 'list-faces-display' is usefull.
I had this exact question and managed to solve it using the following ways. But I also had another thing in mind: a marker to show which lines are modified.
For tracking changes between the saved file and the buffer, we should use the highlight-changes-mode. But before enabling that mode, we need to prepare some stuff as explained beautifully here for the line marks:
;; a part to add the fringe marks to the gutter. To change the shape, read the explanation of it in this code.
(eval-after-load "hilit-chg"
'(progn
(defvar highlight-fringe-mark 'filled-square
"The fringe bitmap name marked at changed line.
Should be selected from `fringe-bitmaps'.")
(defadvice hilit-chg-make-ov (after hilit-chg-add-fringe activate)
(mapc (lambda (ov)
(if (overlay-get ov 'hilit-chg)
(let ((fringe-anchor (make-string 1 ?x)))
(put-text-property 0 1 'display
(list 'left-fringe highlight-fringe-mark)
fringe-anchor)
(overlay-put ov 'before-string fringe-anchor))
))
(overlays-at (ad-get-arg 1))))))
;; make the highlight-changes-mode reset when the file is saved
(add-hook 'local-write-file-hooks 'highlight-changes-rotate-faces)
(add-hook 'after-save-hook
(lambda ()
(when highlight-changes-mode
(save-restriction
(widen)
(highlight-changes-remove-highlight (point-min) (point-max))))))
make sure it is enabled globally except for buffers that start with ' and *
(setq highlight-changes-global-modes t)
(global-highlight-changes-mode)
make the mode to respect the syntax-highlighting
;; find the name of other faced using M-x ~list-faces-display~
(custom-set-faces
'(highlight-changes ((t (:background "dark green" :foreground nil)))))
(set-face-foreground 'highlight-changes nil)
(set-face-background 'highlight-changes "dark green")
Are there any standard techniques, packages or the like for managing font settings in emacs?
I would like to define default fixed and variable width fonts somewhere once, and set the fonts of faces in modes using those defaults. Eg, set org-mode's default font to the variable width default, and its code face to fixed the fixed width default.
Here's an adaptation of the system that I have. I've since defaulted to using just fixed pitch, but these calls will allow you to define the font to use for modes using the mode hook.
I call the method 'toggle-pitch to switch between fixed and variable pitch fonts on the fly when necessary as well.
(set-face-font 'default "Source Code Pro Semibold-9")
(set-face-font 'variable-pitch "Segoe UI Semibold-9")
(copy-face 'default 'fixed-pitch)
;;============================================================
;; toggle between variable pitch and fixed pitch font for
;; the current buffer
(defun fixed-pitch-mode ()
(buffer-face-mode -1))
(defun variable-pitch-mode ()
(buffer-face-mode t))
(defun toggle-pitch (&optional arg)
"Switch between the `fixed-pitch' face and the `variable-pitch' face"
(interactive)
(buffer-face-toggle 'variable-pitch))
;; enable buffer-face mode to provide buffer-local fonts
(buffer-face-mode)
;; Set the fonts to format correctly
;(add-hook 'text-mode-hook 'fixed-pitch-mode)
;(add-hook 'dired-mode-hook 'fixed-pitch-mode)
;(add-hook 'calendar-mode-hook 'fixed-pitch-mode)
;(add-hook 'org-agenda-mode-hook 'fixed-pitch-mode)
;(add-hook 'shell-mode-hook 'fixed-pitch-mode)
;(add-hook 'eshell-mode-hook 'fixed-pitch-mode)
;(add-hook 'bs-mode-hook 'fixed-pitch-mode)
;(add-hook 'w3m-mode-hook 'variable-pitch-mode)
;(add-hook 'org-mode-hook 'variable-pitch-mode)
(add-hook 'eww-mode-hook 'variable-pitch-mode)
A really useful way to set faces is to use the M-x list-faces-display function. This function will pop up a buffer with the face name on the left and an example on the right. This buffer then lets you customize any of the faces and to see what the face definition is. The one possible 'gotcha' is that it will only display the faces it knows about at the time you run the function. This means that if you haven't loaded org-mode for example, you may not see any org-mode face definitions.
One of the useful options when defining a face is the inherit option, which tells the face to inherit the settings of another face. Some of the inherited values can be overridden (such as face colour) in the 'main' face definition.
So, in your case, I would set the appropriate values for the default fixed and variable width fonts, then set the other faces i.e. org-mode faces to inherit from those definitions.
doing it this way shold eliminate the need to do any add-hook jiggery pokery
I finally solved it like this:
First set fixed-pitch and variable-pitch fonts for use in general:
(custom-set-faces
'(fixed-pitch ((t (:family "Input Mono Narrow"))))
'(variable-pitch ((t (:family "Arial")))))
Then in the hook for your mode:
(add-hook 'org-mode-hook nil :inherit 'variable-pitch)
For all my tasks I use URW Chancery L font in Emacs. But for some tasks,
like org-mode tables, shell or sunrise-commander, I would like to set mono-width font.
So, my question, how can I do it? All I found about it is set-default-font, which is not what I want.
Faces (i.e. the objects used to specify appearence of text such as font, color, ...) are mostly global in Emacs, although they can also be set on a frame basis, so you can do the above by creating a separate frame and change the `default' face to use in that frame.
This said, Emacs can also now also change face's appearence for specific buffers via face-remapping. E.g.
(face-remap-add-relative 'default '(:family "Monospace"))
should make the current buffer use Monospace. So adding the above to org-mode-hook might just solve your problem.
This snippet sets the "Arial" font family only in C mode:
(defun set-my-font ()
(overlay-put (make-overlay (point-min) (point-max) nil nil t)
'face '(:family "Monospace")))
(add-hook 'org-mode-hook 'set-my-font)
Replace with org-mode-hook with the desired mode(s), and it should work as well.
This solution effects creation of buffer-local font by setting the font family property of an overlay over the entire buffer. The overlay's face property only specifies the font family (Monospace), and Emacs redisplay is smart enough to merge it with other text properties, such as the colors specified by font-lock.
Did you try to customize org-table ?
You can modify it with org-menu > Customize > Customize > org-table
or use the command line
M-x set-face-font RET org-table RET -PfEd-DejaVu Sans Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1
Use tab to auto-complete and see other available fonts
Finaly you could also directly modify you init.el to have something like
(custom-set-faces
'(org-table ((t (:foreground "LightSkyBlue" :family "DejaVu Sans Mono")))))
I have an issue using Emacs 24.1.1 on Mac OS X. I'm editing Jade and CoffeeScript files, so I've turned on whitespace-mode for those file types.
What I'm seeing is that lines longer than 70 characters are highlighted with the whitespace-line font face, regardless of the setting of whitespace-line-column.
In this shot, it is clear that I've customized whitespace-line-column to track fill-column, and I've set fill-column to 120, but much shorter lines are being highlighted.
I've glanced over the code for the Jade mode and don't see anything that would explain the behavior, but I have only a passing understanding of Emacs Lisp.
Thanks in advance for any pointers!
You have to set whitespace-line-column before you activate whitespace-mode. That is, if you want to change its value it does not take effect unless you turn whitespace-mode off and on again. Ironically, that variable is not available for M-x customize until you have activated the mode once :-(
However, you can customize the global value of this variable by putting the following line in your .emacs file:
(setq whitespace-line-column 120)
Since your .emacs is evaluated when you start Emacs, the setting will take effect before you invoke whitespace-mode for the first time and should thus do what you want. If you don't want to set the value globally, but only for Jade files, put the following in your .emacs file instead:
(set (make-local-variable 'whitespace-line-column) 80)
(add-hook 'after-change-major-mode-hook
'(lambda () (when (eq major-mode 'jade-mode)
(setq whitespace-line-column 120))))
If you never want long lines to be highlighted specially at all, there is a third option you might want to consider. You could customize the variable whitespace-style (by typing M-x customize-variable ENTER whitespace-style ENTER) and in the value list remove the entries:
lines
lines-tail
(if any). This should turn off highlighting of long lines globally independent of the value of whitespace-line-column (again, only after you de- and re-activate whitespace mode).
I have the following code in my .emacs:
(if (null window-system)
(progn
(require 'color-theme)
(color-theme-initialize)
(color-theme-simple-1)))
When I open Emacs on the console, I can verify that the progn block runs (by a (message "Got here.")), and I see a flash that suggests that the color theme was loaded, but if it was loaded, it is overridden by something else. If, after loading, I open my .emacs file and submit the block above using C-x C-e, it works. I've tried doing:
(add-hook 'after-init-hook
(lambda ()
(progn
(require 'color-theme)
(color-theme-initialize)
(color-theme-simple-1))))
but that acts the same.
It may be relevant that I'm using Emacs 24, and that this code is not in my .emacs, but in ~/Dropbox/.emacs, which is loaded from my .emacs.
An additional note: I've tried M-x customize-themes, but none of those work acceptably on the console. They either produce a nearly unreadable light theme, or most of the text is invisible.
Emacs 24 has built-in theming, which doesn't use statements like (require 'color-theme). As Drew points out in the comments, there are differences between color themes and custom themes, and the new direction is towards the latter. Try M-x customize-themes to take a look. From .emacs, you can do things like (load-theme 'wombat t).
But...
It may still be going wrong for you. One thing that can mess it up like this is changing the face -- maybe in the custom-set-faces part of your .emacs file. Emacs's interactive customization automatically includes the color information (both background and foreground) of whatever theme you happen to be using at the time you set it, so this can definitely make trouble with color themes. If that is what's causing it, you can just set the particular attribute you care about with something like
(set-face-attribute 'default nil :height 120)
That will change the font size without changing the colors.
Emacs 24 have own theming system.
M-x customize-themes
or
(custom-set-variables
....
'(custom-enabled-themes (quote (selected-theme)))
)