How can I open a file upon starting spacemacs (emacs)? - 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).

Related

emacs orgmode -- how to export html file to other directory instead of the same directory with .org file

emacs 24.2.1 and org mode version 8.0.3,Although I have referred to the resolution in Emacs Org-mode - Export to another directory?, add below statement to the .org file directly. after pressing C-c C-e h o,the .html file still come to the current directory.
#+bind: org-export-publishing-directory "~/org/exported_html/"
and i have also tried to add below statement to .emacs file. but still not work out what i want.
(setq org-export-publishing-directory "~/org/exported_html")
anyone who can give me an advice? thanks.
The var you're using is for publishing. What you do with C-c C-e is exporting (unless you then press P or such for publishing "projects"). I think your Org file must be part of a project, and then your variable would make sense. Not 100% sure, to be further tested.

Permanently add to emacs load path

I am trying to add "~/" to the emacs load path, because for whatever reason it is not there. I managed to find the command for adding to the emacs load path:
(add-to-list 'load-path "~/")
When I execute this command the load-path variable contains all the stuff it did before, and "~/" is added to the list. The problem is when I quit emacs, the next time it starts the "~/" had been removed from the list, the change is not persistent. How do I add something to the emacs load-path variable permanently?
Adding to the .emacs file won't work here, because the problem is that the .emacs file, which is in the ~/ directory, is not being loaded, so modifying the .emacs file won't fix this problem.
I guess there is a typo in phils' comment. The right way should be C-h v user-init-file RET. Maybe you customized this variable in some other places and you forgot. Try changing the value of this variable back to the default.

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.

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

How to open files automatically when starting emacs?

A newbie question and probably very bingable (had to use that word once :-)), but as I gather thats both ok for SO : How can you get files to open automatically when starting emacs?
I guess it sth. like executing the find file command in your .emacs but the exact notation isn't clear to me.
C-h b
This opens the help showing the correspondence between key-bindings and elisp functions.
Look for
C-x C-f
in it (you can do it by typing C-s C - x space C - f), you find find-file. Now, do
C-h f find-file
and it tells you, among other things, the syntax :
(find-file FILENAME &optional WILDCARDS)
So just try
(find-file "/path/to/your/file")
in your .emacs
Are you thinking of having it re-open files you've looked at before? The desktop package remembers files and re-opens them when you restart. Depending on your emacs version, you enable by simply adding this to your .emacs (for 22.1+ versions):
(desktop-save-mode 1)
And after that, it's pretty much automatic. Whatever files you had open before will be re-opened (provided you start from the same directory, b/c that's where the desktop configuration file is saved) - unless you add a change that forces a single desktop for all sessions.
There are bunches of variants of that functionality, which are listed in the session management page.
If you're calling it from the terminal , can't you just go
emacs FileName
You could desktop-save which basically restores the last session you were working with. When you restart emacs, it looks for a saved session in your folder and loads your files.
See link text