I have a function that sets Emacs' color theme to a theme defined by myself. In this function I do:
(set-face-attribute 'default cur-frame :foreground fg-color :background bg-color)
I then set the background color, foreground color, and cursor color for default-frame-alist, initial-frame-alist and special-display-frame-alist.
All of this works fine on my Mac. But when I use this on Linux, it looks fine for all frames that have already been opened, but on newly created frames it looks like this:
I do not have this problem with new frames if use the set-background-color / set-foreground-color functions instead of (set-face-attribute 'default ...). But if I do that I have to manually reset the colors for every frame that's already open.
I am using Emacs version 23.3 on both Mac and Ubuntu.
For clarification, this is the theme file I use:
my-color.el
set-face-attribute sets, as the name suggest, the attributes of a face (i.e., font-related properties), not the attributes of the frame. Use
(add-to-list 'default-frame-alist '(background-color . "lightgray"))
and similar to change frame-related properties.
(if (eq system-type 'darwin)
;; mac os x settings
(if (eq system-type 'gnu/linux)
(setq default-frame-alist '((background-color . "black")
(foreground-color . "gray")))))
something like this should help you maintain settings per OS.
It seems that it's better to use
(custom-set-faces
'(default ... )
'(region ... )
....
)
style to set faces, this way it will not have that problem.
Emacs uses1) (or does not paint over) the Gtk3.0 theme background in more recent Emacs versions. Changing background using e.g. set-background-color or default-frame-alist only works until I resize the window, after which the Gtk theme background "shines through" again.
I have not yet been able to figure out how to get emacs to always paint over the Gtk theme background, but at least I have found a way how to change the Gtk theme background color, for Emacs only: https://superuser.com/questions/699501/emacs-showing-grey-background-where-there-are-no-characters/937749#937749
So this does not fully solve changing the background color when you switch themes, but at least you can get rid of the black-white contrast you experience when opening new frames.
1) on my machine at least :)
Related
I am trying to customize the text color for web-emmet-helm mode (I don't know which one is setting this particular syntax element) so that I can read it on a black terminal background. honestly I'm not too picky about my background color, but with the default settings I can't find any one color that allows me to see everything.
Does anyone know how to customize the syntax elements indicated in the screenshot? I've done a lot of google searching but probably don't know the right keywords to use. I don't know any lisp but can stick some lines into init.el if you provide them.
Thank you!
Put the point (text cursor) where you want to know about the face (text style) and do M-x describe-face. This will bring up a help window describing the face, including the name. Then you can do M-x customize-face, enter the face name, change the fg color, bg color, and whatever else, and save it. Use M-x list-colors-display to see all the named colors, or use hex RGB to set the color.
Adding the following block to init.el does the trick. The face names are all listed at http://web-mode.org in the Customization section.
(defun pk-web-mode-hook ()
"Hooks for Web mode."
(set-face-attribute 'web-mode-html-tag-bracket-face nil :foreground "White")
(set-face-attribute 'web-mode-html-tag-face nil :foreground "Yellow")
)
(add-hook 'web-mode-hook 'pk-web-mode-hook)
Is it possible to set the background color of a specific emacs window?
I am using the "dedicated window" functionality to pin an emacs buffer to a frame. However, I also want that window to be recognizable as a dedicated window.
Currently I am using buffer-face-mode to set a buffer-specific default font with a slightly darker background color. However, this formatting also applies to windows viewing the same buffer, that are not dedicated to the buffer. Being able to set the font on a per-window basis would remove that problem.
Doing it for one specific window is not a feature Emacs supports right now. OTOH you can do it for a specific frame, so if your window is inside a frame with a single window (as is often the case for dedicated windows), you can definitely set the background-color frame-paramter (and should be able to set it directly from display-buffer-alist or special-display-regexps.
What you want is to specify the buffer as being "special-display". That does just what you want.
You can customize one or both of these options (variables):
special-display-regexps
special-display-buffer-names
That's the easy way. Emacs likes to consider these options obsolete since release 24.3, and it recommends that you use the incredibly complicated option display-buffer-alist instead.
This is all I do, to have all buffers with names that start and end with * to be displayed in their own, dedicated frames:
(setq special-display-regexps '("[ ]?[*][^*]+[*]"))
To get special-display frames to have different properties (i.e., frame parameters), such as a different color background, customize option special-display-frame-alist.
This is essentially the definition I use:
(setq special-display-alist
'((font . "-*-Lucida Console-normal-r-*-*-14-*-*-*-c-*-iso8859-1")
(width . 80)
(height . 14)
(mouse-color . "Yellow")
(cursor-color . "Yellow")
(menu-bar-lines . 1)
(foreground-color . "Black")
(background-color . "LightSteelBlue")
(top . 0)
(left . 0)
(unsplittable . t)
(user-position . t)
(vertical-scroll-bars . right)))
But I recommend that you use Customize to set the value of all such options.
The method that worked for me in Emacs 25.1.1 was using the face-remapping-alist variable. When the buffer is initialized, modify the :background attribute of the default face to the color you want. E.g., I make the background color of my Treemacs buffer different than everything else by adding something like this to my .emacs file:
(defun treemacs-mode-handler()
(set (make-local-variable 'face-remapping-alist)
'((default :background "#303030"))))
(add-hook 'treemacs-mode-hook 'treemacs-mode-handler)
mode is here : http://emacswiki.org/emacs/AutoComplete
and in the bottom:
I have a black background and when I use auto-complete, as soon as I
type something my cursor turns black, so now I can’t see it. Help! How
am I going to fix this problem?
Ok nevermind, fixed it. Just added (set-cursor-color “white”) to my
.emacs file after loading the auto-complete package.
So I just made it too. even (set-cursor-color “#ffffff”) but it doesn't help me. How can I solve this problem?
Correction: it works for emacs but doesn't work for emacsclient
Maybe I must to add some hook? But I need to make a proper hook then, not to add all my mess where I'm trying to solve the trouble setting everything foreground light background dark...
also here is off-topic question: why most of professional emacs users use light themes?
config:
(require 'auto-complete-config)
(ac-config-default)
(set-face-background 'ac-completion-face "darkgray")
(set-face-underline 'ac-completion-face "lightgray")
(set-face-background 'ac-yasnippet-candidate-face "black")
(set-face-underline 'ac-yasnippet-candidate-face "sandybrown")
(set-face-background 'ac-candidate-face "darkgray")
(set-face-underline 'ac-candidate-face "lightgray")
(set-face-background 'ac-selection-face "steelblue")
(set-cursor-color "#ffffff")
(provide 'auto-complete-settings)
Answers for comments:
(frame-parameter (selected-frame) 'cursor-color)
"black"
-- before autocomplete (when cursor light) and after when cursor goes dark.
The three faces which autocomplete uses are ac-candidate-face, ac-completion-face and ac-selection-face. Customising them should take care of your problem.
I'm not using autocomplete, but I can't reproduce this behaviour for the default face.
In 23.1.1 I can set the background colour of the default face using the same function you've specified, and it applies the change and sets it as the default value for all subsequent frames, including those from emacsclients.
Can you confirm that you're definitely talking to a server to which your changes have been made?
Here is what works for me:
(defun frame-bg (frame)
"Custom behaviours for new frames."
(with-selected-frame frame
(set-cursor-color "#ffffff")
))
(frame-bg (selected-frame))
(add-hook 'after-make-frame-functions 'frame-bg)
I agree that Heather's answer will work, but I found that all I needed to solve this problem was to put the following into my .emacs file (after enabling auto-complete-mode):
(set-cursor-color “white”)
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)))
)
The Emacs cperl-mode seems to get confused less than perl-mode, but the Skittles effect makes the thing unusable for me. Does anyone have or know of an example of a .emacs block that causes cperl-mode to use the colorization from perl-mode, ideally in a form readable enough that I can go back and turn back on the default colors one element at a time until I reach something I'm comfortable with?
In particular there is a hideously shade of light green used for some builtins that I find quite unreadable, and I prefer my variables to not have the leading $ and $$ and such tinted red along with the variable name. Most of the rest are merely distracting.
Press M-x customize-group RET cperl-faces RET and change coloring to your liking.
With colour themes, the problem is limited to arrays and hashes - and it turns out that that's because cperl-mode defines those faces as being bold-weight, which colour themes don't appear to affect (Solarized doesn't).
In Emacs 23.3 on Mac OS, the following restored the colours to how the colour theme defined them:
(custom-set-faces
'(cperl-array-face ((t (:weight normal))))
'(cperl-hash-face ((t (:weight normal))))
)
You can also use the 'real' perl-mode coloring by overwriting font-lock settings with those of perl-mode.
(require 'perl-mode)
(add-hook 'cperl-mode-hook
(lambda ()
(setq font-lock-defaults
'((perl-font-lock-keywords perl-font-lock-keywords-1 perl-font-lock-keywords-2)
nil nil ((?\_ . "w")) nil
(font-lock-syntactic-face-function . perl-font-lock-syntactic-face-function)))
(font-lock-refresh-defaults)))
You can change the color theme if you don't like the particular default colors.