Does `evil-mode` have vim like `changes` function? - emacs

As per vim wiki:
Vim remembers the locations where changes occurred. Each position
(column number, line number) is recorded in a change list, and each
buffer has a separate change list that records the last 100 positions
where an undo-able change occurred.
One can then use g; to move to the last change in the change list. This list survives through different sessions. This means, that even if one did not make any change to the file after opening it in a new session, g; will move the cursor/point to the line where the latest change occurred in previous session.
From what I can tell, evil-mode does not have the change list per buffer which survives session. Or does it?

You probably want to have a look at Undo Tree, which is used by evil-mode if undo-tree is installed. I do not think that it has the g; functionality that you describe though. It can, however, maintain undo history between sessions.

Take a look at goto-last-change on melpa. Evil has default integration through g;.

Related

Emacs multiple-cursor - Cut and yank in multiple lines

Using the 'multiple-cursor' emacs package,
when I mark a word and cut ('C-w') in different multiple cursors, the only word in the 'active' cursor I control is cut.
I want to select different words in multiple positions and yank it to other relative position.
When I first tried this I remember some yes or no option at the screen bottom, but I couldn't really notice this at first and some keystroke made it to "no". I guess this might have been an option for multiple-cut. But I don't know how to revert this choice.
How do you do multiple cut and yank in emacs?
This works by default, so at some point you have indeed asked the library not do do this.
These settings are stored (by default) in ~/.emacs.d/.mc-lists.el
Just edit that file appropriately, and then M-x eval-buffer RET to make those same changes in the running instance.

How to temporary select and edit some lines in a buffer?

I'm stuck on this problem. I have a file with almost 10k lines. Some of them should be deleted and I can get an hint from their content, e.g. if they contains a certain pattern "xyz", maybe they must be deleted. So, my idea is to:
* select only those lines containing each pattern in my list
* manually inspect them and change the ones actually to be deleted prepending them a "--" (or similar)
* ...and at the very end, delete all the lines starting with "--".
As keep-lines actually delete all the un-kept lines (TIL), is there any other way to do what I need? Thanks in advance.
One idea would be to use M-x occur to select possible candidates. Then, use "e" in the Occur buffer to enter "Occur Edit Mode". In this mode, edits in the Occur buffer are reflected into the originating buffer. So maybe you can just delete lines there altogether.
You might like to try M-x all. It's like M-x occur except that buffer changes get propagated to the original buffer. all can be installed from GNU ELPA (i.e. via M-x list-packages).
It sounds like you could do this with query-replace-regexp.
M-C-% (or M-x query-replace-regexp)
Enter ^.*xyz.*$ as your search term and leave the replace term blank (hit enter)
Inspect each matching line in turn, hit space to delete or n to leave. Make sure you start at the beginning of the buffer to catch everything.
You can get hide-lines and use M-x hine-lines-not-matching. Since it's still the same buffer (just displayed differently), you can edit the visible lines as you wish.

How to view history of various commands in Emacs

Commands entered after pressing M-x can be viewed using the up/down arrow keys.
How can I get a list of all the commands including menu bar invocation, commands
triggered using mouse clicks, etc. in Emacs?
For a complete list of history, type C-h l (lowercase "L").
Note: this list is complete in the sense that it keeps all events and commands that happened recently, but it's not complete in the sense that it only keeps track of the last 300 or so events (and corresponding commands).
I've used mwe-log-commands to make screencasts. It shows events and the commands they trigger as you work in Emacs.
command-log-mode
I've just forked it and made it into a proper minor-mode and global-minor-mode along with some other improvements as command-log-mode.
Give it a shot and file issues against me if the documentation is unclear or if you find any bugs.
So you want the history of of all commands, regardless of where they are executed? I don't know if emacs provides this by default, but you can add your own function to post-command-hook which is executed after every command, so you can use it to collect all the executed commands.
M-x view-lossage
From emacs documentation
(view-lossage)
Display last few input keystrokes and the commands run. For
convenience this uses the same format as edit-last-kbd-macro. See
lossage-size to update the number of recorded keystrokes.
To record all your input, use open-dribble-file.
(open-dribble-file FILE)
Start writing input events to a dribble file called FILE. Any
previously open dribble file will be closed first. If FILE is nil,
just close the dribble file, if any. If the file is still open when
Emacs exits, it will be closed then.
The events written to the file include keyboard and mouse input
events, but not events from executing keyboard macros. The events are
written to the dribble file immediately without line buffering.
Be aware that this records all characters you type! This may include
sensitive information such as passwords.

How do I stop Emacs from changing my split buffers?

I have a number of splits open, looking at various buffers. But when I for example check the help on a function it will replace one of the splits with the help buffer. Once I'm done reading the help I have to go back to the correct buffer manually which is a pain. How do I get Emacs to be nicer to my buffers?
Update: Help will let you press q to go back to the previous buffer. But causing the Emacs backtrace to pop up also steals one of my buffer windows and it doesn't have a q.
Update: Backtrace DOES have q to go back. My original question still remains: how do I ask Emacs not to steal one of my splits?
Adding the line(push "*Help*" special-display-buffer-names) to the init file should make subsequent invocations of the help buffer to appear in its own frame(what the desktop usually calls "window"), and leave the original frame with its configuration alone.
See Special Buffer Frames.
You could also use winner-mode. It came up on planet.emacsen.org a while back.
Winner Mode is a global minor mode. When activated, it allows to “undo” (and “redo”) changes in the window configuration with the key commands ‘C-c left’ and ‘C-c right’.
That way you can undo any changes to your splits immediately after they happen.
I hope this will help you :
C-x 0 to remove the current window
C-x 1 to keep only the current window
you can use windmove by adding the following line in your .emacs :
(windmove-default-keybindings)
Then, you can move the point between windows using S-right S-left S-up and S-down
There are lots of ways to store and restore emacs windows, see emacswiki.org on the subject.
What I do is just go to that changed buffer, C-x k it, and the current buffer in that window will be the previous buffer.
It may be possible to define advice for the help that saves the current window and buffer state and restores it with a simple keybind. But this is outside my basic elisp knowledge.

Emacs reselect region, as Vim shortcut 'gv' does

In vim, visual block can be recall by 'gv' command so that multiple commands can be applied easily. (such as, comment out, then indent, then do_something_fun).
In Emacs, how can this be achieved?
[C-xC-x] only works when current cursor position stays where previous block ended.
If previous block was changed, the closest is to go through 'point-to-register' and 'jump-to-register'.
Just I am curious if there is an Emacs built-in command making this in one shot.
If Transient Mark mode is off, the region is always active. If it's on (which it sounds like is your situation), you can set mark-even-if-inactive to non-nil to allow region commands to work while the region isn't highlighted.
However, note you also can cycle back through previous mark positions using C-u C-SPC -- this will pop the mark ring. Once you're back to where you want to be, C-x C-x will rehighlight the region you want. (It may take a little bit of playing with this feature to get a feel for it, but it's why I can't switch away from Emacs now.)
If I understand correctly what you are asking for, then you don't need to do anything. When you select a region in emacs, it stays selected until you select a new one. So you could select the region and then perform as many actions as you want.
Sounds like you're looking for the secondary selection, which stays put even as the region might change. (It stays put until you move it.)
See:
the Emacs manual, node Secondary Selection
Emacs wiki page Secondary Selection
library second-sel.el:
Also narrow-to-region (CTRL-x n n ) applies every command from then on just to that region- you can't hurt the rest of the buffer, it doesn't even show. After done editing , widen (CTRL-x n w )to get back the whole buffer.
CMM
If you use evil-mode, just press gv like in vim.
Since the answers here and for other similar SO questions didn't help for me (CUA-mode, Emacs 24, not only indent-rigidly), I continued searching and finally found a reselect-last-region defined in this collection of custom function (starting line 670). That worked like a charm for me - and hopefully does for others still arriving here.