Sublime Forum

EmacsKillRing plugin for ST2?

#1

Hi,

ST2 looks great, and for the first time in years I’m seriously considering switching from TextMate.

One thing that I could never get from TM was the ability to do set-mark-command and yank, like one can with Emacs. It looks like this is possible in ST with the EmacsKillRing plugin (sublime-text-community-packages. … lRing.html), but this does not appear to work with the ST2 alpha.

Does anybody know what would have to be done to get this to work with ST2? It would be so great to finally have the kill ring in a modern editor.

0 Likes

#2

I’ve just glanced through the code and it seems to use api functions unavailable at the moment in v2. I’m not familiar with Emacs’ kill ring, so I’m not sure whether the plugin could be rewritten to work around that.

Sublime 2 has introduced a few new concepts in the api, like the EventListener class and the Edit object (source: memory), which haven’t been explained yet.

If you want to poke around and have a go, though, bring up the python console (ctrl + ~) and dir() away sublime (m), sublime_plugin (m), view (o), window (o) et al.

The major change breaking compatibility with v1.x plugins is the new naming conventions in accordance with PEP8. Other than that, you can still peruse the v1.x api docs at sublimetext.com/docs/api-reference to get started.

I’m pretty sure there will be more info on the api pretty soon.

HTH
Guillermo

0 Likes

#3

As far as I can tell EventListener is just a class that defines callbacks on_selection_modified.
Guillermo: I’m not sure which functions you were looking at in the killring plugin source that Sublime Text 2 doesn’t have yet—I glanced through the killring plugin code, and it looked pretty simple. Were there any in particular that stood out?
stiang: you could probably just grab the code from that page and modify it to work with ST2. If you’d like, I could take a shot at this—I’m trying to get better with the ST2 API.

0 Likes

#4

In particular, I was referring to the quick panel. Maybe it isn’t essential for this plugin, but as far as I know, it hasn’t made it into the api yet?

0 Likes

#5

I too thought it hadn’t, but just this morning I was pleasantly surprised to find it while reading through help(sublime.Window) – it’s right at the bottom so I saw it right when I typed the command :smile:

import sublime def onDone(string): print string v = sublime.active_window().show_input_panel("Kill ring index:","0",onDone,0,0)

0 Likes

#6

…aaaaaaaand obviously you were talking about the quick panel whereas I found the input panel. So… never mind. You could still do it, but you’d have to use the input panel instead of the quick panel.

0 Likes

#7

If you would be willing to take a crack at it I would be super grateful! My understanding of ST (not to mention my Python fu) is too sketchy at the moment. It would be great to be able to evaluate ST2 for a while with kill ring support, before diving deeper and figuring out how to tweak/write plugins.

My understanding is that the only command that requires showing a panel is yank-any. This is the least important command as far as I am concerned, so if there is a problem with the quick panel (which I am assuming is needed to show a selection of regions for yank-any), skipping that particular functionality is perfectly fine with me.

0 Likes

#8

Maybe this features can be merged into editor? I think, some things from killring can be merged with original idea of editor.

0 Likes

#9

Actually, I was able to get the EmacsKillRing working on my own, sans the quick panel to show yank choices (I get “AttributeError: ‘Window’ object has no attribute ‘show_quick_panel’”). It wasn’t nearly as difficult as I had imagined.

But there is one change I’d like to make. Setting the mark currently gives no visual cue beyond a message in the status bar. I would prefer the behaviour you get on newer Emacsen, where setting the mark anchors a (visible) selection that updates as you move the cursor around. The selection should continue to update until you abort by pressing ctrl-g or perform a command (like kill-region).

Is this possible in ST2? If the event system can tell me when the cursor moves I suppose it could be possible to listen for cursor movements, then check if a mark has been set, and if so, update the visible selection, no? If this sounds feasible, is there some documentation on the (new) event system or an example I could peruse?

0 Likes

#10

you’re looking for on_selection_modified and the syntax highlighting api (an example of the latter for st2 is in my sublimeflakes module

you can get positions of cursor(s) and selection(s) then define highlight regions

0 Likes

#11

Thanks, that worked like a charm! I haven’t yet understood how I can change the background color of the region (it appears to stay the same no matter what scope I try), but that’s not terribly important.

Sublime Text is a lot of fun to hack around with…

0 Likes

#12

@stiang : do you plan to release your code on GitHub or something like this?

thanx

0 Likes

#13

Sure, you can pick it up here: github.com/stiang/EmacsKillRing

0 Likes