How to open files automatically when starting emacs? - 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

Related

Emacs keep opening lots of buffers (Clojure)

I'm a beginner in Clojure and for some reasons I decided that Emacs would be a good choice, because of its usage among the clojurists.
But something that's really anoying me is that Emacs (for working with Clojure projects) opens a bunch of buffers. i.e, when I click "Read a directory to operate in its files" and select the lein's project root, I need to select myproject.core.clj and Emacs keep all the super dirs openned in other buffers. When compiling with cider and working with many clj files, it's painful to keep on alternating through all those buffers.
How can I limitate the numbers of buffers that Emacs leave openned?
(I know C-x k)
(Sorry for any English mistakes)
I had a lot of trouble with this same problem when I first started using Emacs. The solution is to use something other than C-x b or C-x C-b to switch between buffers. In particular:
I use Projectile's C-c p f to switch to arbitrary files in my project. It works very nicely because it takes your .gitignore into account. This can be annoying in some cases, but for the most part it works very well.
I use project-explorer to browse through a tree view of all the files in my project. The ignore features of project-explorer aren't quite as nice as those of Projectile, but you can toggle them using M-o when you need to, which is a feature Projectile doesn't have. project-explorer-open doesn't have a default binding, so I bind it to C-x p.
I use Ido and ido-ubiquitous to make all selection commands (including C-c p f) much easier to use.
If you lose your REPL buffer in CIDER, you can get it back instantly using C-c C-z.
If you already have multiple windows in front of you, windmove provides an extremely fast way to switch between them.
You'll generally end up with a lot of open buffers anyway, but since you now have an easy way to switch between them, that's no longer a problem. You can find a full example of this sort of setup in my personal Emacs config.
Personally, I use C-x C-f to open files, and don't bother with opening buffers for directories.

Emacs sr-speedbar

I am currently trying to learn Emacs more in depth so that I can do more with my Emacs than just simple editing stuff...
I am making good progress and at the moment I am trying to configure the 'sr-speedbar' module to my liking, but some details I can't figure out myself:
Say that I've 2 open buffer windows A and B plus the speedbar window. If I open a file by pressing Enter in the speedbar window, then the new file always get opened in the same buffer window B (which I opened last). Can I somehow specify that the new content should be opened in buffer window A?
Currently the speedbar window refreshes itself automatically to the new location whenever I open a new file using 'C-x C-f'. This is actually pretty useful, but sometimes I don't want this when I am quickly trying things out in a tmp file. And the refresh also "destroys" my "tree-view" of the speedbar, where I expanded the directory contents rather than opening them directly. The question is, how can I suppress this "refreshing behaviour"? Can I somehow disable the automatic mode and trigger it manually if I need it?
And do you guys have more useful tips regarding speedbar navigation? How does a Emacs guru use speedbar or are there better alternatives?
Thx in advance for your help!
You can turn off the auto-refresh in your init file like this -
(require 'sr-speedbar)
(setq sr-speedbar-auto-refresh nil)
and/or turn it on and off later with the function sr-speedbar-refresh-toggle.
The defaults it (and speedbar) comes with are a bit odd though - it also doesn't show files that it doesn't recognize, uses images for buttons, and is set on the right side - so you can set these if you'd like -
(setq speedbar-show-unknown-files t) ; show all files
(setq speedbar-use-images nil) ; use text for buttons
(setq sr-speedbar-right-side nil) ; put on left side
I do use sr-speedbar for projects that have enough of a directory structure - otherwise I use the usual switch-to-buffer (C-x b), ibuffer (C-x C-b), and dired (C-x d), and another function that switches to the previous buffer. Also bound to single keys because they get used so much.
But... I'm still learning Emacs - I haven't tried helm, projectile, or project-explorer yet - they look interesting also.

How to make speedbar list the C functions + Unable to use sr-speedbar+macro+command history

I am new to Emacs on Windows XP and have multiple queries which I could not find/understand after a lot of search.
I understand that speedbar will support showing of C functions list. As mentioned in http://stackoverflow.com/questions/259364/how-do-i-configure-emacs-speedbar-for-c-sharp-mode, I added the code in .emacs as
(speedbar 1)
(add-to-list 'speedbar-fetch-etags-parse-list
'("\\.c" . speedbar-parse-c-or-c++tag))
I see the speedbar startup but it never shows the functions. Maybe I need to install etags but cannot find it. I also found gtags but could never find a binary
I copied sr-speedbar.el in ~/emacs.d/ directory. I added (require 'sr-speedbar) in .emacs, commented out speedbar related code, reloaded M-x ~/.emacs but did not find any sr-speedbar. If I uncomment speedbar code and comment sr-speedbar, it shows the speedbar on loading. Emacs is able to find sr-speedbar.el in ~/emacs.d/ directory since if I change filename, it shows an error: unable to find sr-speedbar.
I wanted to make a keyboard macro for logging using tramp and ssh. However, when I record a macro, I have to delete multiple characters to provide the path from the beginnig i.e. emacs automatically shows the last path and so I have to delete all the characeters and then start again with ssh://. The keyboard macro records all backspaces and returns error if the backspaces are more than the length of the current path. Is there a way to avoid it
I configured linum package. I want it to start at the beginning of emacs session automatically with typing M-x linum. How can I do that?
Is there way to retrieve command history (not shell commands) and then replay some command
Thanks again for patience on reading until the point :-)
For C, C++, and other languages, supported by CEDET/Semantic, the Speedbar is able to show functions & other objects. But you need to setup Semantic correctly, for example, you can use my article in CEDET.
As I understand, to enable linum-mode globally, you need to put (global-linum-mode 1) into your ~/.emacs
For 3, there are two options:
just type "/ssh:blabla" at the end of the pre-inserted directory (this directory will be ignored as witnessed by it becoming grey).
do C-a C-k to erase the content of the minibuffer.
For 5, there is repeat-complex-command bound to C-x ESC ESC and there is repeat bound to C-x z.

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