Programatically remove entry from Atom's undo stack - coffeescript

I've written a small piece of coffeescript code for Atom editor to update a timestamp comment on certain files just before they are saved, and it works perfectly.
Unfortunately, this modification ends up, obviously, on Atom's undo stack, so if after saving these files I undo my changes, the timestamp is undone before the previous changes. For this reason I want to remove this timestamp update from the undo stack.
I know I can pack multiple changes into a single undo transaction using TextBuffer.transact() or TextEditor.transact(), but I can't find how to just remove last entry (or entries) from the undo stack.
Is the only solution to access directly the historyProvider and mess with the undostack Array? Frankly, right now I don't know which side-effects this can have, but I don't find anything in Atom API todo what I need.
Thanks a lot in advance, as always :)

Sorry for the auto-answer, but I found a way of achieving what I want.
Using Editor.insertText(text, {undo: 'skip'}, a text insertion can be removed from the undo stack, and the same option can be provided for setTextInRange, which is what I was using previously.

Related

Prevent Ctrl+Z deleting last line in SSMS after Script As->Alter View

I'm hoping there's just some way to disable this in SQL Server Management Studio (v17.9.1). When I Script As->Alter a view or stored procedure to a new query window, I can hit Ctrl+Z and it deletes the last line of text! I realize as I'm trying to explain this exactly what's happening: Sql is opening a new window and "pasting" the query line by line. Therefore when you undo you're removing the last line and so on.
This becomes a problem when you say, alter a view, make changes and execute, then decide to undo them all so you just hold Ctrl+Z then realize you've erased half your script instead of just going back to the starting point.
Does anyone know how to disable this or an elegant way of preventing it from happening?
This started out as a comment, but it's getting too long, so...
I don't think you can disable ctrl+z, but just like Newton's third law of motion - for every undo there's an equal and opposite redo - so if you've held ctrl+z pressed for too long, you can always restore the lines that ctrl+z deleted simply by using ctrl+y.
Other options are suggested by GSerg in his comments - you can always keep a copy of the original code in a different query window, or even a simple text editor.
One more option is to first save the content of the new query to a file, so you can always reload it's original state if you've messed things up too much.

Eclipse CVS compare: difference not disappearing after copying

In Eclipse, CVS text comparing works poorly against large numbers of difference between the local and the remote version. It's very desirable to update the the status of comparison every once in a while by a simple command. Basically it's reloading the local file, do the comparison again, to see where we have reached, and try not to make mistakes.
Unfortunately, "Team" - "Synchronize" again after editing every several lines is not convenient, neither does it solve our problem. As I have observed, when there are many differences, Eclipse can mark the already identical lines as different to the remote ones, if we use this approach to compare again.
How can we solve it in Eclipse?
At last I found a simple enough solution, but can be ignored easily: use the "Java structure compare" panel.
When doing the CVS comparison, above the two horizontal text area, we can see the "Java structure compare" panel.
The icon "+", "-" and arrows can show structurally how the two files are different.
Double-click on a method to edit. After several lines of work, double-click the method again to update the status of comparison. If the local version is identical to the remote one, all the color squares will dissappear from the vertical scroll bar on the right, clearly marking where we have reached. Also, after doing this, you jump to the next difference in this method, to start working again.
Re-"Synchronize" will mess the whole file up, so don't do it in the middle, unless you are at the final stage and have fewer enough differences.
Just a little piece of humble opinion about how to use Eclipse more efficiently. After all it's our daily tool. Better to learn these tricks as soon as possible.

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

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

Accidental commit; how to not push an unpushed commit in Magit Emacs

I did an accidental commit which really makes no sense to have anywhere in history. How can I remove this commit from existence (especially I don't want it appear remotely).
In the magit-status, it shows:
Unpushed commits:
fe73b07 updated gitignore
974e70d test
ab333e6 trying to go with a flat structure
What can I do?
Bonus: actually, I just want to keep the "updated gitignore" from this commit.
Point at test, press E to start a rebase. M-n two swap commits. C-c C-c to finalize.
Resolve merge conflicts if any and done.
This is more a git question than an emacs or magit question really. If I understand you correctly, you want to get rid of older commits. One way to go about this is to re-order your commits and than get rid of the last two commits.
The first amounts to picking the right commits during rebase, the latter amounts to using the right incantation of git reset. I would suggest you take a look at this link on reordering commits. In addition, I would urge you to take a (ton of) look(s) at this useful fixup section of the step-by-step adventure through git.
Like #abo-abo said, initiate an interactive rebase by putting point on the first commit you want to remove and then pressing E (on Magit's next version ee.
A new log-like view appears, with every line prefixed with an action, initially pick. Then press n to move to the first commit you want to remove, and k, which will strike out that line meaning to drop that commit. (That's what happens in the ui, when this information is later feed to Git, the line is actually removed). This also moves to the next line, which in this case is the other commit you want to remove. So press k again.
Now that all commits you want to remove are marked as such, press C-c C-c to tell Git to make it happen.

customizing emacs with "sidebars"

I'm tinkering about switching my IDE to emacs. (I'm still an emacs newbie.)
The problem is that I customized my IDE quite well and I'd regret to leave my helpers behind.
Let me explain:
Shows the current open files/buffers, allows fast switching with a hotkey (C-1, C-2, ...)
Shows the most recent texts on the "clipboard" or inserted by complete (no. 4), text insertable with a hotkey (C-b 1, C-b 2, ...) Last inserted shown in bold, insertable with C-`
The last inserted complete (no. 4) text, insertable with M-`
Autocomplete-ish list, gathered from all open files, regardless of their type with some magical logic. text insertable with a hotkey (M-1, M-2, ...)
I guess emacs has such features, but I'm a visual type I'd like to see what I have available.
Of course actual hotkeys don't matter much, but as you see having all that info visible makes it easy to hit the spot with the least keypresses.
My pain is that there is a plethora of emacs extensions providing various features, checking all seems to take a lifetime.
My question is:
are there any emacs extensions to achieve similar looks and behavour?
as I'm a programmer, which extensions could I take as a base to assemble something like this?
Thanks!
Elaborating a bit more:
I’m a python dev, so most of the code I’m writing is python. Add some HTML JS CSS XML to the picture.
One important thing is that completion needs to work across filetype boundaries, because python / HTML(template) / XML(config) / doctest identifiers are cross-referenced. It’s a huge pain with some IDEs that completion works only for python filetypes.
I have a lot of same named files but in different folders, like init.py, configure.zcml, etc. It seems to be a pain to switch between those by filename.
Better said that’s a list of recently inserted text. To be reused by the fewest keys as possible. Usually when coding I’m reusing the same identifiers/whatever within the same task. So it’s handy to have them listed instead having to retype the starting x chars to get completion again.
Usually best use of this feature is when changing/refactoring code. Like adding one more extra feature and the identifier is needed several times over the place.
TL;DR
Learn keyboard macros. Learn yasnippet.
Autocomplete mode is probably similar to what you have.
Get acquainted with emacs kill-ring before trying to change it, it wants to be your friend. Then you'll know what to look for when you DO want to change it.
Long Version
Shows the current open files/buffers, allows fast switching with a hotkey (C-1, C-2, ...)
You have three options for this.
My personal preference is to have all source files open at all times. So I don't need a visual list of open buffers. Whenever I want to switch to a file I hit C-= (which I've bound to iswitchb-buffer) and type a couple of unique letters. It's common to constantly switch between the same two buffers so I also bound C-backspace to previous-buffer.
Another option I can recommend is tabbar. It's not exactly like your setup, but it displays a list of open buffers (just like webpages in a browser) and it has functions for cycling through the tabs, so it shouldn't be hard to reproduce your C-number key bindings.
You could use speedbar or ecb. They would be the most similar to your current visual configuration, but I'd argue the other options are more efficient.
Shows the most recent texts on the "clipboard" or inserted by complete (no. 4), text insertable with a hotkey (C-b 1, C-b 2, ...) Last inserted shown in bold, insertable with...
I see you've sort of mixed the clipboard with completion history. When it comes to emacs, yasnippet and autocomplete are just so good you're better off going with them for completion (see below).
Emacs clipboard is called the kill-ring. I'm sure you know of C-y and M-y, so you can always recover anything you've cut in the past. Unfortunately, I don't know of any packages that constantly display the kill ring or allow you to yank a specific part of it (though that shouldn't be too hard to write), but at least you know what to search for (kill-ring).
The last inserted complete (no. 4) text, insertable with M-`
I'll be honest, I don't see that much use in this. If you have to repetitively insert text, you should learn keyboard macros. In fact, you should learn keyboard macros anyway, they're the first reason I got hooked to emacs.
Autocomplete-ish list, gathered from all open files, regardless of their type with some magical logic. text insertable with a hotkey (M-1, M-2, ...)
Emacs had many great completion options. In your case, the best one is probably autocomplete-mode. It pops-up completion options (much like your separate completions window), and I think it allows for quick selection of a specific option (like your M-number shortcuts). Also it has several different ways of deciding which completions to offer you (it calls them "sources") and one of them is to gather from all buffers.
In addition to that you have yasnippet, and I couldn't possibly recommend it enough. Seriously. Learning to use it and writing your own snippets will change the way you write code. You'll become a mage whose fingers produce pages of code flowing through your screen in blazing speeds. Use yasnippet!
Once you have it configured, every 3 or 4 keys you press will generate a line (or more) of code for you.
After all that, if you still miss something from your previous editor you'll write it yourself. :-)
Your setup looks exactly like https://github.com/emacsmirror/ecb.
To me at least, since I don't use side-bars:)
You should take a look at the extension speedbar. I have installed this extension, but I rarely use it even for a very large project.