How do I store a persistent history? - emacs

Im fairly new to Emacs (I'm using emacs now since 1 month) and migrated from vim. One "feature" of vim I really miss in Emacs, is the persistent history.
When I am starting vim I can easily open files I recently had open via the command history. But in Emacs when im in dired (or executing commands via M-x) and then pressing M-p I can only browse through the sessions history, and cannot open i.e. files I had opened in a previous session. So, now my question: Is it possible to store the Emacs-history persistent on my system, that when I re-open Emacs I can access my complete history?
(Btw. my Emacs Version is 24.3.1)
Thanks in regards,
Niklas

You can put (savehist-mode 1) in your .emacs to save your minibuffer history over several sessions. (You will need to restart for this to work)

For M-x specifically, look at the SMex package. It enhances M-x with a history, flex matching, better ordering, etc.

Related

Equivalent of vim mksession on emacs

I started working on vim about a year ago, and decided to try out emacs.
I really like it so far but there is a functionnality I'm missing on emacs : the ability to save your session as it is right now (the different buffers and local commands, aliases, etc) and reopen it later.
In vim, it takes a simple :mksession session.vim and :source session.vim
How can I find the same behaviour in emacs?

running multiple "emacs -nw" in different terminals

When I'm coding I'm using multiple "emacs nowindow mode", each one oppened in different terminal. It is really annoying when you have the same file on multiple emacs. Is there a way to synchronize them on save? (to update the other instances of emacs?)
I know that the best solution is not to do this :), but it is hard to break old habbits :)
Cheers,
Stole
p.s I work on Linux systems
It sounds like the ultimate problem you want to solve is working with the common files across Emacs frames. Emacs allows multiple client frames for a single running instance of Emacs. Unless you have technical motivations for entirely isolated instances of Emacs (i.e. isolated global state) I would recommend using this feature. That way you entirely avoid issues arising from concurrent edits to files.
Start the Emacs server from the command line via:
$ emacs --daemon
Alternately you can start the server after emacs has started using M-x server-start.
Then you can create client frames as you need them. Instead of typing emacs -nw, use:
$ emacsclient -nw
Depending on how you work you may need to exit Emacs differently to preserve other clients. Use C-x 5 0 (delete-frame) to close a single client rather than C-x C-c (save-buffers-kill-terminal).
Start your emacs instance in background when your session starts and then use emacsclient -nw to open a new frame in each terminal session. It's not exactly what you're doing but it is the closest I can think of.

saving perspectives when an emacs session is saved

I have been using perspectives package in emacs (from Nathan Weizenbaum, https://github.com/nex3/perspective-el). I save my emacs session on exit so that it saves the existing buffers and loads them up on next start. The line added in .emacs file to achieve this is : (desktop-save-mode 1). But it doesn't save perspectives, so that all the saved buffers open under a single perspective, when emacs is started. Is there any implementation that will achieve the saving of perspectives between emacs sessions?
desktop-save-mode is provided by package desktop which comes with emacs, it is not provided by perspective.el. Desktop mode can save and restore your buffers (with emacs 24.4 it can also save your windows and frames) but does not provide 'named window configurations'. Perhaps you can use bookmarks+ for this as #Drew suggests but I have never tried it.
The package perspectives does not provide a way save and load perspectives. See this issue. As an alternative I would like to suggest you the package workgroups2, it similar to perpective.el (it calls perspectives workgroups) and provides that feature you want.
This might be an alternative for you, depending on what you are looking for:
Starting with Emacs 24.4 (which will be released soon, and for which development snapshots are available), when you save an Emacs desktop (see desktop-save-mode and Bookmark+ desktop bookmarks), you can optionally save frame, window, and buffer states. Restoring a desktop then restores these as well (as far as possible).

Better control over where windows with cscope buffers in Emacs

Emacs is my editor of choice, and I use the cscope intergration xcscope.el provides. Recently I had a flirt with Vim. I decided to stay with Emacs, but one of the things I really liked in Vim was how I could control where my cscope windows should appear. Using cscope_maps.vim (http://cscope.sourceforge.net/cscope_maps.vim) I get shortcuts that let Vim open search results in the same buffer, a new horizontal or a new vertical split.
In Emacs a the cscope buffer just pops up in a window somewhere, according to some rules I don't know. My guess: A new window is opened if I have only one. If I have more, the one I've been away from for the longest time is used.
Pin Emacs buffers to windows (for cscope) is the only related topic I've found that helps a bit, but that doesn't make it near as flexible as the key bindings in Vim.
Anyone got a better cscope setup in Emacs than what xcscope.el provides? I don't know lisp, so I have no idea how hard it would be to make this work the way it does in Vim.
Emacs 24 (not yet released) changes radically how it is decided which buffers are displayed in which windows. In principle it should give you more fine-grained control. In any case, how you solve the problem for Emacs 24 will be different from how you solve it for older versions.
Consider filing an Emacs enhancement request to specifically get behavior more like what you had with Vim. To do that, use M-x report-emacs-bug.

Change the initial directory on emacs, and also some tips for a starter

How can I change the initial directory on emacs? I started using it today and there are a lot of things to learn!
Right now I'm using M-X cd and then I change the directory that I use for C-x C-f, but in a daily work I'm going to heavily use one particular directory so I need to make the change permanent.
Also if you have some tips for a starter it will be nice.
To set a default directory, simply put
(cd "/default/path/")
in your ~/.emacs file.
Emacs has a steep learning curve, but with constant use the most common commands will soon become second nature. As you discover more, emacs may become your favorite text editor, file manager, and email reader :)
To learn emacs, I'd start by pressing C-h t to start plowing through the excellent tutorial. Have a pad of paper beside you and write down the commands as you learn them. You'll use the crib sheet at first, but after a while, as I mentioned before, your fingers will learn the key combinations without your brain conciously intervening.
Good luck and have fun!
Default directory is determined by:
(setq default-directory "~/")
in this case, set to the users home dir, but it could be somewhere else.
If this variable is not set, the initial load point for find-file will be the directory where the emacs executable lives.
EDIT: on windows, a global HOME environment variable can be defined (HOME=c:\path\to\user\home\directory), ensuring that Emacs translates ~ to the correct value. This makes the Emacs settings usable across platforms.
Start up emacs only after changing to that "initial directory", effectively setting the current directory for emacs.
This is a solution specific to Windows.
Create a shortcut to emacs.exe" called GNU Emacs
Open Properties on the GNU Emacs shortcut
Set Start in to %USERPROFILE%\Documents
This solution works for multi-user workstations whether they are on or off Active Directory.
This shortcut will start Emacs in the current user's Documents folder.
Print out the Gnu Emacs Reference card and keep it by the desk.