emacs font setting does not load at start - emacs

I put my font setting at a separate font_settings.el file and load it with:
(load-library "font_settings")
at the end of init.el.
But every time I start Emacs, emacs seems not load the settings.
I have to eval-buffer to evaluate init.el to let it work.
So it seems the settings are OK but loading sequence or the way I load it is not right...
Any thoughts?
The code of font_settings.el is here (too long):
http://pastebin.com/ExpY1mTy

Is font_settings.el in your load-path? If not, put it there or add the directory that contains it:
(add-to-list 'load-path "/the/full/directory/name/my-directory/")
See the Emacs manual, node Lisp Libraries.
You can check whether the library was actually loaded by using C-h v load-history. (Alternatively, you can check whether something that the library defines actually gets defined.)

Related

Emacs: auto-complete-mode on but no auto-suggestions showing (Emacs lisp mode)

I'm puzzled as to why nothing pops up (in Emacs lisp mode) when I begin typing a function name. For example, after typing (def on a new line, I would assume that auto-complete should be showing me a alist of options which includes defun. Am not sure how long the default delay is, but I waited for a few seconds and nothing happened. Any suggestions?
Details regarding my installation process:
Installed using package-install via Melpa
Added the following two lines to my init.el file:
(require 'auto-complete-config)
(ac-config-default)
Confirmed that load-path includes the folder containing the .el files associated with auto-complete. (I have it set-up to recursively add all folders under path/to/my/.emacs.d/.)
Confirmed (via describe-variable) that ac-dictionary-directories includes the correct directories when Emacs starts up. As reference, it includes the following two directories:
ac-dictionary-directories is a variable defined in 'auto-complete.el'.
Its value is ("/home/dchaudh/Dropbox/dchaudhUbuntu/emacs/.emacs.d/elpa/auto-complete-20140824.1658/dict")
Confirmed that auto-complete-mode is on when I open my init.el file, which obviously triggers emacs-lisp-mode (I can see Emacs Lisp in my mode line). The following is included in the summary of active modes (i.e., via describe-mode):
Global-Auto-Complete minor mode (no indicator)
Toggle Auto-Complete mode in all buffers.
With prefix ARG, enable Global-Auto-Complete mode if ARG is positive;
otherwise, disable it. If called from Lisp, enable the mode if
ARG is omitted or nil.
Not a direct answer, but company works fine out of the box in emacs-lisp-mode, so you might want to try that one.
In my experience, other modes (e.g. flyspell) can interfere with auto-complete operation. (There is a workaround for slyspell built into auto-complete but you have to activate it in your. emacs file.)
I'd suggest trying it with an empty. emacs and then gradually adding parts of your configuration back in. You should be able to find the problem that way.

eval-when-compile not being honored?

I'm attempting to install ace-jump-mode for emacs 24.1.50.1.
I've installed it with M-x package-install, and calling M-x ace-jump-mode activates it and prompts for a letter, but upon entering a letter, I get the error:
Symbol's function definition is void: every
Running emacs -q (and then running (add-to-list 'load-path "~/.emacs.d/elpa") like I have in my .emacs file) allows me to load ace-jump-mode and it functions without an issue. Assuming thus that the error exists in my .emacs, I commented out everything in my .emacs, and reopened emacs regularly, but still get the error.
From some searching around, I think the issue is the code in ace-jump-mode.el
(eval-when-compile
(require 'cl))
is not working correctly when I don't use emacs -q. When I M-x load-library cl, everything works fine.
I imagine that since I can't find any references to this online, its not a common bug, so it must be an issue with my config. I know I could just load cl in my .emacs, but I don't see the need to load the entire package just for one function.
Does anyone know how to fix this? Or, how to load only one function from cl?
Thanks.
Emacs is self documenting, C-h f every will show you that this
function is defined in cl-extra not cl, but loading cl autoloads it, so
it does become available.
Some things with how cl is loaded may have changed with Emacs 24, which
broke this library, I'm not certain. Like you found out, the easiest fix is
to just
(require 'cl)
in your init file. This isn't as a big deal as you make it out. A lot of
libraries you might use will do this anyway, so it's likely you're just
changing the order things get loaded.
The alternative is to just submit a patch to the author of ace-jump-mode
that avoids using every, which is more inconvenient.
Finally, if you ever got ace-jump-mode to work it was because you loaded the
uncompiled ".el" file instead of the compiled ".elc" file, which would have
run (require 'cl), meaning that both cl and cl-seq will have been loaded
somewhere along the way. So there is no magic that can make this work
without loading those files.
(eval-when-compile <foo>) means that <foo> is only executed when compiling the file (or when running it uncompiled). So if you compile your file, the resulting file won't load cl, which is a problem since every is only defined when cl is loaded. (eval-when-compile <foo>) is used to load macros (such as ignore-errors), since these are only needed during compilation, but every is not a macro, hence your problem.

How can I save my Emacs settings?

I am using the Emacs editor, and every time I start Emacs, I lose my previous settings.
For example, every time I have to type:
M-x cua-mode RET
M-x auto-complete-mode RET
How can I save my settings in Emacs?
Thanks.
You can add them to your .emacs file.
(cua-mode)
(auto-complete-mode)
If you find that there are already things in your .emacs file, then you might want to add the commands at the end.
The best answer I can think of is to point you at the manual:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html
In particular, see the sections on "Easy Customization" and the "Init File"; but I would recommend at least skimming over everything in this section.
In your emacs directory there is a site-lisp folder. Normally it will be empty. you could create a file default.el in this folder. Add these two lines
(cua-mode t)
(auto-complete-mode)
and save it.This will be executed during Init. If you want to set environment variables for your emacs application only(not permanent) add a file called site-start.el in the site-lisp directory and define value for that variable ex:(setenv "VARIABLENAME" "value"). The site-lisp directory is in the standard search path for Lisp library.

Emacs c-mode autoloading failed

I want to load my file named "my-c-setup.el" when the c-mode is loading. So, I'm using the function "autoload".
With my python setup, it works well :
lang.el
(autoload 'python-mode "my-python-setup" "" t)
my-python-setup.el
(require 'python)
; ...
I'm trying to do the same with the c-mode, but i does not work :
lang.el
(autoload 'c-mode "my-c-setup" "" t)
my-c-setup.el
(setq c-basic-offset 4)
; ...
When I try to open a file in c-mode (test.c for example), I have the following error :
File mode specification error: (error "Autoloading failed to define function c-mode")
Autoload is not what you're looking for. What it does is simply load some code the first time it is needed, which is a handy way to extend Emacs' functionality while still keeping the start-up time low.
To solve your problem, we gotta think about what you really want to do: do you simply want some of your code to be loaded at some point, or do you want buffer-local customizations for ever buffer that is in c-mode?
If you simply want Emacs to load your code at start-up, either put your code directly into your .emacs file or use load-file or require instead of autoload:
load-file simply takes a file name, loads the lisp code in that file and evaluates it. So if your code is in a file named "/path/to/my-c-setup.el", you could put the following line in your .emacs, and the code will be loaded on every start-up:
(load-file "/path/to/my-c-setup.el")
Perhaps you don't want to give the absolute path name for every file you load. In that case, you could use the function load-library instead which is similar to load-file but tries to find the given filename in any of the directories stored in the variable load-path:
(add-to-list 'load-path "/path/to")
(load-library "my-c-setup.el")
The advantage is that you have to do the add-to-list part only once, and all subsequent calls to load-library will be able to find code in that directory.
An alternative way is the provide/require mechanism: you can make your .el-file "provide" some feature by putting a (provide 'feature) call in it, e.g.
(provide 'my-c-mode-customizations)
Then put an according (require 'feature) in your .emacs file, and your code will be loaded as well:
(require 'my-c-mode-customizations)
However, if you want your code only be loaded when c-mode is activated on a buffer, the way to achieve that is through Emacs' Hook mechanism:
A hook is a variable where you can
store a function or functions to be
called on a particular occasion by an
existing program.
Most major modes provide a customizable hook variable to which you can add functions that will be called whenever the major mode is invoked. For instance, c-mode provides c-mode-hook. In order for your own customizations to be called whenever c-mode is turned on for a buffer, put them in a function, say, my-c-mode-customizations and add the following line to your .emacs file:
(add-hook 'c-mode-hook 'my-c-mode-customizations)
Of course, you still need autoload for Emacs to actually find the definition of that function.
Lisp's autoload does not call a function when a file is loaded but tells lisp that the function is available and that the given file provides it. Whenever someone calls the (not yet defined) function, the file is loaded.
I think that c-mode is already defined and thus fails to re-register.
Autoload doesn't do what you think it does.
http://www.gnu.org/software/emacs/elisp/html_node/Autoload.html
What you probably want are mode-hooks or eval-after-load.
See eval-after-load vs. mode hook for the difference between the two.

How do I find which .emacs file has been loaded?

How do I get emacs to tell me the location of the .emacs file it has loaded?
My situation is simply when I do sudo emacs, it loads up a very different .emacs file than the one in my home directory. I can get around with by doing M-x eval-buffer on my own .emacs file, but that's a lot of extra steps, plus it doesnt seem to clear out the goofy binds in whatever .emacs file is being loaded. If anything, I'd simply like to find the .emacs file and remove some of the stranger binds (c-n, c-p, c-a all rebound to strange stuff)
My main question is still, how do I get emacs to tell me the location of the .emacs file it has loaded?
The init file used is stored in the variable 'user-init-file'. To see this use 'describe-variable' (C-h v), type in 'user-init-file' and it will display the file used.
You could try to see what file is found by:
C-x C-f ~/.emacs RET
~ gets translated to the value of the HOME environment variable. Emacs looks for .emacs, then .emacs.elc (the byte compiled version), then .emacs.el, then ~/.emacs.d/init.elc and ~/.emacs.d/init.el. This documentation shows the alternatives. It also depends on the environment variabls LOGNAME and USER.
You can also check out the contents of the *Messages* buffer - though you should set (setq message-log-max t) (if you can) to ensure that all the Messages are kept. Inside that buffer there are lines that look like:
Loading /home/tjackson/.emacs.tjackson.el (source)...
which will show what files were loaded.
You should also check out the Find-Init documentation that shows even more files that can be loaded like the site-start.el, and terminal specific initialization (new to me).
If you are on Linux, you could try this to see what files are opened by emacs when it launches.
sudo strace -o /tmp/emacs.txt -e open emacs