I have this piece of Elisp code in my Emacs configuration file:
(when (string= (getenv "TERM") "screen")
(custom-set-variables
(custom-set-faces
'(font-lock-comment-face ((((class color)
(min-colors 8)
(background dark))
(foreground red)))))))
When I start Emacs I get Error setting nil: (setting-constant nil) from this code. Though it seems to work fine I'm aware that this might be a sign of some hidden problem. I don't know Elisp too well thus I need help. Can anyone offer an explanation of this error and tell me how to eliminate it? I'm using Emacs 24.3.1
There's quite a lot wrong with that, I'm afraid.
custom-set-faces and custom-set-variables are two separate forms; you shouldn't be calling one inside the other.
You shouldn't be wrapping a call to either of those functions in a conditional expression. Both forms are generated and updated automatically when you use the customize interface, and Emacs won't find them if they're not top-level forms in your init file. Which means it will create an additional copy of each one when it needs to. Which leads to...
You mustn't have multiple instances of these forms. In fact Emacs includes the following warning comments when it generates the form:
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
Right now you are encouraging that situation to occur.
Related
I would like to be able to specify a theme or set of custom faces that are specific to a file that will be opened in org-mode. Is there any way I can do that? I already have https://github.com/vic/color-theme-buffer-local but that doesn't provide a way to automatically apply it when a specific file opens.
An ideal solution would not involve hardcoding in my init.el, but would involve setting a variable or calling elisp in the loaded file (or a referenced setupfile).
For an example of why this would be useful, some files are very flat, and are more readable with one set of styles, and other files are deeply nested, and benefit from another set of styles.
The original poster has cited a particular library called color-theme-buffer-local ( https://github.com/vic/color-theme-buffer-local ), which the original poster wants to apply to a file opened in the major-mode known as org-mode -- only if a certain variable is t.
The following example uses the code cited in the instructions for color-theme-buffer-local by calling the line of code: (load-theme-buffer-local 'misterioso (current-buffer)) The variable my-favorite-variable will control when the previous line of code is called when opening an org-mode buffer -- i.e., when non-nil it applies, when nil it does not apply.
EDIT (November 16, 2014): The following is a revised answer based upon the desire of the original poster to use file-local variables:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables
http://www.gnu.org/software/emacs/manual/html_node/elisp/File-Local-Variables.html#File-Local-Variables
The behavior described by the original poster in the comment underneath this answer is due to the fact that the regular org-mode-hook is run before the file-local variables are taken into consideration. Therefore, the variable my-favorite-variable was still nil when the org-mode-hook ran its course (using the initial answer). The following revised answer uses the hack-local-variables-hook, which runs after the file-local variables are taken into consideration.
(defvar my-favorite-variable nil)
(defun my-favorite-function ()
(interactive)
(when
(with-current-buffer (current-buffer)
my-favorite-variable)
(load-theme-buffer-local 'misterioso (current-buffer))))
(add-hook 'hack-local-variables-hook 'my-favorite-function)
To my knowledge, color themes are global, for the whole Emacs session running. The same applies for background color which I'd like dark for shell buffers, and light otherwise; not possible ATM.
If you like light backgrounds, you can have a look at my color theme "Leuven" (in Emacs 24.4, in MELPA or on GitHub) and report improvements you'd find useful.
I'm trying to get doremi working in emacs. Specifically, at this stage, to allow me to quickly scroll through a condensed list of color-themes and see each theme as I go through it. For this I would use the 'M-x doremi-color-themes+' command.
What I've done:
Installed color-themes (successfull)
Installed doremi.el, doremi-cmd.el, ring+.el and added
(add-to-list 'loadpath "~/elisp/themes")
(add-to-list 'loadpath "~/elisp/doremi/")
(require 'color-theme)
(color-theme-initialize)
(color-theme-classic)
;; create a list of color themes to scroll through using 'doremi-cmd
(setq my-color-themes (list 'color-theme-classic
'color-theme-retro-green
'color-theme-gray30
'color-theme-subtle-hacker
'color-theme-jonadabian-slate))
(require 'doremi)
(require 'doremi-cmd)
(require 'ring+)
to the .emacs file.
What emacs does:
When I type the comand 'M-x doremi-color-themes+' into the mini-buffer it seems to accept that I've given it a valid command and tells me to use the and arrow keys to move through the list. But when I do that all that happens is the cursor moves up and down in the active window. No changing of color-themes.
Being somewhat new to emacs (and especially customising it) I'm sure I have missed a step or put something in the wrong place. Perhaps there's some sort of (setq 'bla-bla-bla (...)) I need to do?
Sorry for your trouble. Please state your Emacs version (M-x emacs-version), and your version of color-theme.el.
You do not need to require library ring+.el if you use Emacs 23 or later (its code was included in GnuEmacs 23.)
You do not need to use (color-theme-initialize) or (color-theme-classic). The former is done automatically by doremi-color-themes+.
Try starting from emacs -Q (i.e., no init file, ~/.emacs), to be sure there is no interference from stuff in your init file.
Your variable my-color-themes is not referenced anywhere. Instead of defining that variable, just customize user option doremi-color-themes. (Or leave its value nil, which means that all color themes will be cycled through.)
Feel free to contact me by email if you continue to have a problem. Or continue here, if you prefer.
[Just to be sure: you are using color-theme.el, right? There is a lot of confusion out there between Emacs "custom themes" and color themes. Do Re Mi supports both, but they are different critters.]
After a bit for back and forth with #Drew we found a solution to the problem.
It turned out the major problem was that I was using emacs in 'terminal mode' rather than as a GUI application. Bare in mind I'm using a mac.
In the context of Terminal, my arrow keys send escape sequences and so doremi cannot read the event as intended. So it just escapes and applies the message to the active buffer.
There is an answer.
By adding the following lines to my .emacs file (or whatever your init file for emacs is) I was able to redirect doremi to use two other keys. ie. not the up and down arrows.
(setq doremi-down-keys '(?n))
(setq doremi-up-keys '(?p))
Doing this tells doremi to use 'n' as the down key and 'p' as the up key. And all works just fine.
Because I am only new to the world of programming and computing I may often use incorrect terminology. If this is the case please let me know and I will edit accordingly for clarity and consistency.
I'm trying to set a theme - one only for terminal, and one only for gui.
I've read this thread: Run certain Emacs init commands only in GUI mode
Which led me here: https://superuser.com/questions/165335/how-can-i-show-the-emacs-menu-in-gui-emacs-frames-but-not-in-tty-frames-when-usi
And tried to create a function to suit my need.
(defun set-frame-theme (frame)
(let ((want-theme (memq (framep frame) '(x w32 ns))))
(set-frame-parameter frame '(load-theme '(if want-theme monokai solarized-dark) t))))
(add-hook 'after-make-frame-functions 'set-frame-theme)
It doesn't work.
I'm trying him to load monokai only if gui, otherwise load solarized-dark.
It does work for the GUI interface, but causes the terminal to seemingly crash.
Suggestions?
The emacs lisp function,
(display-graphic-p)
Will return true if emacs is running in a GUI.
In your .emacs, add the following to switch between your GUI and terminal themes
(if (display-graphic-p)
(load-GUI-theme)
(load-Terminal-theme))
For easier configuration, I have a simple function called is-in-terminal
(defun is-in-terminal()
(not (display-graphic-p)))
you could use this to write an easier to read function
(if (is-in-terminal)
(load-Terminal-theme)
(load-GUI-theme))
For a more complete approach to Terminal Only configuration I have a macro that works just like progn but only evaluates the body when Emacs is running without a GUI
(defmacro when-term (&rest body)
"Works just like `progn' but will only evaluate expressions in VAR when Emacs is running in a terminal else just nil."
`(when (is-in-terminal) ,#body))
Example Usage:
(when-term
(load-my-term-theme)
(set-some-keybindings)
(foo-bar))
This entire block will be totally ignored if running in a GUI, but will run if in Terminal.
All this code was taken from a file in my config, if interested you can check it out here:
https://github.com/jordonbiondo/Emacs/blob/master/Jorbi/jorbi-util.el
i could solve the issue with:
(if (display-graphic-p) (load-theme 'solarized-dark t))
the final t is to override the confirmation prompt in theme selection.
More here.
I too had the problem of emacs crashing when running in terminal mode while selecting a color-theme.
I would say this is not an issue with the color-theme but with emacs itself.
Updating to the newest version from HEAD did work for me as of time of this writing.
As mentioned at https://www.emacswiki.org/emacs/CustomizingFaces
"If you want different color schemes for different displays, you can customize this as well. In the customize buffer, click the [State] button and choose “Show all display specs”. Now you can use different specs for different displays."
Seems like an issue with the theme itself - nothing more and nothing less. uh well.
So I'm relatively new in trying to customize emacs. But I really need to customize is asap. Tabs are a pain in emacs as they are two spaces, and the text is all messed up when it is opened with any other editor after that.
Currently, I only have few lines in my ~/emacs.d/init.el file:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
(set-scroll-bar-mode 'right)
(require 'linum)
(global-linum-mode t)
I get an error while starting up emacs:
Loading encoded-kb...done
An error has occurred while loading `/Users/mycomp/.emacs.d/init.el':
Symbol's function definition is void: set-scroll-bar-mode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
I tried srtating it with the --debug-init option, but my lisp knowledge is not enough to help me figure out what's wrong. Any help on how to get this working or redirecting me to some GOOD tutorials on editing init.el files will be really helpful (yes i did google tutorials on editing the initialization file, but every one of them was terrible).
I'm assuming my code for getting line numbers on the left is also wrong. Could someone please help me with this? Thanks a lot.
I think this line may be the problem:
(setq load-path (concat (getenv "HOME") "/.emacs.d/"))
First of all, I don't think this is required to load ~/emacs.d/init.el. Secondly, if you do want to add a directory to your load-path, you should probably be doing it like this instead:
(add-to-list 'load-path "~/.emacs.d/")
This code adds the directory to the load-path, your code just clobbers it with the single directory.
Use 'M-x apropos' and 'M-x customize-apropos'. For now, those will make your life much easier when you want to customize things.
For instance, to customize things to do with scrolling, 'M-x customize-apropos RET scroll RET' will give you a list of all things that you can customize that have 'scroll' in them. You can look around and find the things that you want by searching the buffer. If you find a particular thing that you want, there's usually a group that it belongs to. You can click on that, and just customize those particular values. Make sure you save the settings.
It might take you a while to figure out what things are called. If you've got an idea, try the apropos search. If that doesn't turn up anything, google can probably sort it out for you.
For now, don't worry about hacking the elisp. This method will write values to your startup file (probably the .emacs?) and you can look and check the syntax later if you're really interested. I customize most of my stuff this way; I only bother actually modifying the file by hand when I'm trying to write my own hooks or functions.
I need CEDET for eassist (eassist-list-methods is quite handy). In eassist.el there's the line
(require 'semantic)
which fails if CEDET isn't loaded. The thing is that I don't need CEDET all the time and it takes a long time to load so I want to defer loading it until I call eassist-list-methods.
Is there a way to run
(load "cedet")
when semantic (or something else that is provided by CEDET) is required?
I'm looking for a simple solution that doesn't change eassist.el.
Genehack is probably right; I'm being too literal in answering the question. The best way to handle something like this is to figure out which function(s) are required by external code, and add autoloads for them.
But if autoload won't work in your case, the normal way to do something when a file is loaded is to do
(eval-after-load "semantic" '(load "cedet"))
But I just noticed that you say that semantic.el fails to load if CEDET hasn't been loaded first. As implied by the name, eval-after-load runs the code after the specified file is loaded.
You can try finding a different file to trigger loading, instead of using semantic.el. (Perhaps some other file that semantic.el requires.)
If necessary, you could hook into require:
(defadvice require (before CEDET-require activate)
(if (eq 'semantic (ad-get-arg 0))
(load "cedet")))
Although (load "cedet") should probably be (require 'cedet), or you'll wind up reloading it every time. (I'm not sure if CEDET has a (provide 'cedet), so I didn't do it that way in my example.)
Note that putting advice on require will not do anything if semantic has already been loaded, so you may need to check (featurep 'semantic) first and load cedet.el immediately if necessary.
Assuming you have all the CEDET stuff in your load-path something like:
(autoload 'eassist-list-methods "cedet" nil t)
in your .emacs.d/init.el (or other init file) should do the trick.
I might be misunderstanding you, but if not the answer is autoload: you want to load eassist.el only when you invoke one of its commands. When it loads it will load semantic or CEDET or whatever it needs -- that's not your problem (it should be taken care of by the design of library eassist.el).
(autoload 'eassist-list-methods "eassist" nil t)