More Emacs for the favorite IDE

We would like to share with you the details on Emacs specific features introduced in IntelliJ IDEA 11 release last year and some new which are upcoming in IntelliJ IDEA 11.1. Meet Kill rings, Sticky selection, Adjust line and more.

Kill rings

Emacs provides a concept of kill ring. IntelliJ IDEA supports it by introducing a bunch of editor actions that accumulate adjacent removed blocks of code. For example, traditional way to move multiline block of text is to select it, invoke Cut action, move caret to the target position and invoke Paste. Emacs users may achieve that by pointing caret to the target block start, performing C-k (Ctrl-K, Cut up to Line End) necessary number of times, moving caret to the right position and executing C-y (Ctrl+Y, Paste).

It may sound more complicated than really is, but it’s a neat feature that is hard to give up when you get used to it.

Sticky selection

Emacs allows to switch the editor to a special mode when every caret move changes selection boundary offset. E.g. we can copy a target block by positioning caret at the start position, moving it to the target end position holding Shift and eventually performing Copy. Emacs way is to move caret to the start position, enter Sticky selection mode (C-SPC, Control+Space), move caret to the target position (no need to hold Shift) and calling M-w (Alt+W, Save to Kill Ring).

It’s also possible to swap caret position between sticky selection boundaries using standard Emacs shortcut C-x C-x (Control-X-X).

Adjust line

It’s just Tab. Has a special behavior for Python code editing as it cycles active line via the appropriate indent levels.

Other

More standard actions are configured to the default Emacs shortcuts in IntelliJ IDEA Emacs keymap.

Afterword

Just a couple of words in conclusion. Original Emacs feature set is enormous and it is hardly possible to add them all to IntelliJ IDEA. However, we are glad to provide those that are commonly used and would be interesting for the big number of our users.

Despite the fact that all these features are inspired by Emacs and have standard bindings in default Emacs keymap, they can be easely configured for any local keymap.

All the features including new are available in the latest IntelliJ IDEA 11.1 EAP build. Don’t hesitate to submit feature requests to the tracker. Any feedback here is also appreciated.

This entry was posted in New Features and tagged , . Bookmark the permalink.

23 Responses to More Emacs for the favorite IDE

  1. Fredrik says:

    Wat? Wut? What did you try say? Explain the IDEA features not the Emacs features. “it’s just tab”? Oh well, I’ll check the help instead. Thanks anyway.

  2. Stephen Friedrich says:

    Yes, would be nice if you could explain the concept for the IDEA users without referring to emacs specifics like keystrokes:

    I mapped Ctrl-Shift-X to “Kill region”, then invoked it.
    First problem: If there’s no selection I think it should automatically kill the current line (just like cut and copy work on the current line by default).
    So I killed a couple of lines by first selecting each one.
    Then I hit ctrl-v someplace else. Second problem: Only the last line reappeared.

    What the heck?

  3. Denis.Zhdanov says:

    ‘Tab’ is a standard Emacs hotkey for ‘adjust line’. It is bound to the ‘Emacs Tab’ action at the Emacs IJ keymap. The action has special behavior when it’s invoked on a python source file.

  4. Denis.Zhdanov says:

    @Stephen: why did you use ‘Kill selected region’ action? The post mentions ‘Cut up to Line End’. It doesn’t require any selection and automatically concatenates adjacent killed text.

  5. Fredrik says:

    I for one like Emacs and I’m sure these are great features, but I think the post lacks a lot of information that makes it understandable in itself for someone who hasn’t worked with emacs-like features in IDEA before. Perhaps you could flesh it out and dumb it down a bit for easier consumption?

    TAB in emacs adjust indention (like ctrl-alt-i but without advancing to the next line), in my expierience, but maybe that just (my) defaults…

  6. Denis.Zhdanov says:

    @Fredrik: I see your point but doubt that that additional information would persuade Emacs-unaware users to try it. Moreover, I believe that they would not like reading the post about ‘crazy Emacs stuff’ if it’s big.

    Regarding the ‘Emacs Tab’ vs ‘Indent Line’ – the thing here is a special processing for Python sources. IJ hasn’t had the one.

  7. Stephen Friedrich says:

    @Denis: I used “Kill selected region” because killing to line end does not make much sense to me.
    However I frequently want to cut non-adjacent several lines and paste them somewhere else.

    Also: Why the heck is the action named “Cut up to Line End” if it does not “Cut”, but “Kill” (i.e. cut and append to clipboard?). Since the GUI “improvements” in IDEA 11 there no longer is any additional description for actions in the keymap configuration dialog, so that is _very_ surprising.

    And finally WHY DOESN’T IT WORK? I “killed” several regions but still the clipboard contains only a single one?!

  8. Denis.Zhdanov says:

    @Stephen: IJ doesn’t have any special support for concatenating non-adjacent regions into the single one. Current workaround is to copy/cut target regions and use ‘Paste from History’ action (Ctrl+Shift+V) to paste each of them.

    Regarding the name (‘Cut up to Line End’) – agree that that is confusing. Current state is based on historical reasons – there was a ‘Cut up to Line End’ action and it has been made kill rings-aware.

    About the feature’s availability – please submit corresponding ticket to the tracker and provide description on what did you perform (initial source file, what actions against what regions have been performed, expected and results etc ). I doubt that such a discussion would be interesting for another blog readers.

  9. Stephen Friedrich says:

    @Dennis: Sorry, I am totally misunderstood the feature. I though “kill” just meant “cut & append to clipboard”.
    If it works only for adjacent killed regions I do indeed have no use for it.

    My interest was awakened, because more than seven years ago I suggested “Cut & Append (to clipboard)” and “Copy & Append” actions: http://youtrack.jetbrains.com/issue/IDEABKL-174
    When I read the blog I thought that you finally implemented such actions.
    I do think that they make a lot of sense!

  10. Denis.Zhdanov says:

    @Stephen: Agree, it looks interesting. Moved the ticket to the main tracker

  11. Phil Shapiro says:

    It’s great to see IntelliJ pick up features from emacs — there are many features in emacs that have been around for a long time that other editors could benefit from.

    Although from what you describe, you haven’t implemented a kill ring. If you read the page you linked to, a kill ring is more or less a stack for the clipboard. What you’re describing sounds like http://www.gnu.org/software/emacs/manual/html_node/emacs/Appending-Kills.html

    Also I’ve never heard of an emacs concept called sticky selection, it sounds like you’re implementing an emacs buffer mark. This isn’t a mode, although if you use transient mark mode in emacs it can seem like it is.

    One trivial emacs command I miss is transpose http://www.gnu.org/software/emacs/manual/html_node/emacs/Transpose.html

    This command swaps two characters or two words at the current point. Since this (like many emacs shortcuts) are now built into all Mac OS X edit fields, I miss it even more when I remember I’m in IntelliJ and I can’t use it.

    My most missed emacs feature is editor macros. This is a bit more work to implement, but there is probably a reasonable subset of features that could still be useful. For example, in most cases I would just start recording, do a series of edits, and then stop recording, and then playback the macro a bunch of times.

  12. Denis.Zhdanov says:

    @Phil: that’s right its more like appending kills. Basically, we have had for a while functionality similar to the kill ring (check ‘Paste From History’ action, Ctrl+Shit+V). We’ve added support for combining adjacent text into the single entry.

    Regarding the sticky selection – we don’t have a notion of point & mark at IJ editor and it’s not worth to copy it as is from Emacs. Our goal is to get convenient features and adapt them to the IJ environment.

    ‘Transpose’ action looks fine. Could you create corresponding feature request at the tracker?

    Macros – they are supported indeed – http://www.jetbrains.com/idea/webhelp/using-macros-in-the-editor.html It’s also possible to assign shortcuts for them.

  13. Phil Shapiro says:

    @Denis.Zhdanov thanks for the reply and the info about editor macros and paste from history, I’ll definitely check both of these out! And yes I’ll file a request for transpose.

  14. demonkoryu says:

    If you would now move on to proper Vim emulation, I’d be eternally thankful.

  15. Denis.Zhdanov says:

    There is a dedicated VIM plugin for the IJ already – http://plugins.intellij.net/plugin/?id=164. It’s officially supported by the JetBrains team, so, you are free to report any found problems and submit feature request to the tracker – http://youtrack.jetbrains.com/issues/VIM

  16. Kevin Turner says:

    Okay, so what’s the difference between “Kill selected region,” “Save to Kill Ring”, and “Cut”? Is there documentation for each of these I’m missing somewhere?

  17. Przemek says:

    I love Emacs and superior editing capabilities and I’m glad that some of them are now in IDEA.
    For those who have never used Emacs it may sound strange, but Emacs has plenty of productivity boost features and its text editing capabilities are not met by any modern IDE.

  18. kevin says:

    Why not go the rest of the way and allow on-the-fly customization in Groovy, in the same way that users can instantaneously customize Emacs using Emacs-LISP?

  19. Peter Bommel says:

    Sadly, I did not get what this is all about. Please be so kind and supply a short video as documentation. Thanks

  20. Yoram says:

    @Phil Shapiro

    In phpstorm There is a way to transpose Characters. You just need to install the “String Manipulation” plugin. It has a shortcut to transpose characters “Alt a”. I changed it to Ctrl-t for my emacs memories

    It took me some times to find that so i Hope it will help some ones

  21. zeller says:

    All these Emacs features are great!
    Now the only job left is to reduce the memory consumption to 8M for a fresh install :)

  22. Maria says:

    Hi there,

    Thanks! I tried out the emacs shortcuts, and there were some things about the implementation that drove me a little crazy, so instead I’m trying to implement my favorite emacs shortcuts into the default MacOS keymap. When I tried to implement tab as auto-indent it gave me all kinds of warnings about it being assigned to other actions. This seems unlikely to affect me, since indenting code is all I ever use tab for, but is it going to have consequences I am not anticipating?
    thanks,
    maria

  23. randible says:

    Thanks so much zeller! That plugin worked great!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">