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

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

Related

How can I open a file upon starting spacemacs (emacs)?

I want to open a few (or at least one) .org file(s) upon starting spacemacs and I can not achieve this. I suspect it would be the same lisp code for spacemacs and emacs.
Thus far I found this little snippet
(find-file "~/todo.org") from this blog post
but it doesn't work when I put it down in the end of my .spacemacs file. I'm not sure if I should put it in init.el file because I think part of spacemacs philosophy is to just add everything to the .spacemacs file to make it easy.
Are you sure there is no buffer for that file, perhaps not displayed? (From your comment the answer to this is that the buffer is present but not displayed.)
Try with an init file that has only that find-file expression. If that works (displays the file buffer) then ensure that you put that expression last in your init file.
If that simple change (putting the sexp last) doesn't (also) work then bisect your init file to find out what other code there is interfering.
You should add (find-file "your-file") inside the function dotspacemacs/user-config.
Try adding it as the last line in the function (I tested it here and it worked).
To find the "correct" init.el file use the command SPC f e d (or M-x spacemacs/find-dotfile).

emacs font setting does not load at start

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.)

Bookmarks+ list bookmarks crashes Emacs

I am using Ubuntu 12.04 and GNU Emacs 23.3.1.
I just tried the bookmarks+ library (http://www.emacswiki.org/emacs/BookmarkPlus) I downloaded the files from that site, e.g. bookmarks+.el from http://www.emacswiki.org/emacs/download/bookmark%2b.el
I put the files in my ~/emacs directory, and I put
(setq load-path
(append (list nil "~/emacs")
load-path))
(require 'bookmark+)
in my ~/.emacs startup file. To debug I have deleted everything else in my ~/.emacs..
To make it simple, lets say I now start Emacs as follows:
bash$ emacs ~/.emacs &
Then I add a single bookmark using C-x p m, and then enter
C-x r l to bring up the bookmarks buffer, and I get the follwing screen shot:
Now there are several ways to make Emacs crash:
I can just wait some seconds
I can try to change buffer with C-x b
I can select the bookmark and then return to the .emacs buffer, and then press C-x b again..
When it crashes the frame is grayed and nothing happens, whereas in the Gnome terminal I get the error message
*** glibc detected *** emacs: realloc(): invalid next size: 0x000000000228e1a0 ***
If you have the same problem after trying a different Emacs build (order not too important, and items are not necessarily related -- i.e., try one or more of these things):
Remove nil from your sexp that updates load-path. And remove ~/.emacs, unless it is a directory. load-path should be a list of directory names. And it should include the directory where the Bookmark+ files are located. Typically, you do (add-to-list 'load-path "/some/directory") to add a directory to load-path.
For your testing, unless you have already done so, remove your bookmarks file. IOW start from zero, as you tried to do by emptying your .emacs. Start with no bookmarks.
What happens if you do the same things (e.g. C-x r l followed by C-x b) without loading Bookmark+, i.e., using the vanilla Emacs bookmark code?
Remove any byte-compiled Bookmark+ files, so you use *.el files, not *.elc. Then set debug-on-error to t. (But if Emacs is crashing then you probably won't get a Lisp backtrace.)
Try M-x debug-on-entry switch-to-buffer (or whatever other function you think the crash might occur in), and then step through the debugger using d (or skip through parts you don't care about, using c). For the most clarity (detail), load the Lisp source file that defines the function that you pass to debug-on-entry. E.g., if it is switch-to-buffer then in recent Emacs builds the file would be window.el. Do C-h f switch-to-buffer (or whatever function) to see just what file to load. Load the file using load-file or load-library (with an explicit .el suffix), not require, so you load the *.el.
Every Emacs crash indicates an Emacs bug (Emacs should never crash). If the crash creates a file emacs_backtrace.txt in the current directory then use M-x report-emacs-bug and include that file in your bug report.
If debugging this helps narrow down the cause of the crash, then consider using M-x report-emacs-bug to report the narrowed-down recipe to reproduce the crash.

How to open an org-mode file automatically in Emacs

How to open files automatically when starting emacs? does not work either under Windows or under Linux.
After adding the find-file command I received a message
so I disabled the auto-save, but the file does not load anyway.
(add-to-list 'load-path "~/emacs/org-8.0.3")
(setq auto-save-default nil)
(find-file "/home/uwe/Dropbox/orgmode.org")
You probably want to set the initial-buffer-choice variable so that it switches to your org file after running your init.el.
(setq
org-default-notes-file "/home/uwe/Dropbox/orgmode.org"
initial-buffer-choice org-default-notes-file)
The message you see proves that the file is indeed loaded just fine. All it tells you is that there's some auto-save file left over, indicating that some edits were not saved last time. You can ignore the message (which is not an error message), or you can use M-x recover-this-file RET to recover the unsaved changes from the auto-save file.
I strongly recommend you don't disable auto-saving.
IOW what you think doesn't work (automatically loading orgmode.org) actually does work. The only thing that doesn't work the way you want is that this file is not displayed and instead the *scratch* buffer is displayed. The reason for this depends on how you started Emacs. And the fix for it depends on all the different ways you might start Emacs (e.g. if you only ever start Emacs in the exact same way, it's easier).
Don't disable the auto-save, it could save ours files.
Anyway, delete #orgmode.org, if the diff between the two file don't interest you.

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.