Home Download Buy Blog Forum Support

EmacsKillRing plugin for ST2?

EmacsKillRing plugin for ST2?

Postby stiang on Sat Jan 29, 2011 12:42 pm

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 (http://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.
stiang
 
Posts: 39
Joined: Sat Jan 29, 2011 12:34 pm

Re: EmacsKillRing plugin for ST2?

Postby guillermooo on Sat Jan 29, 2011 7:10 pm

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 http://www.sublimetext.com/docs/api-reference to get started.

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

HTH
Guillermo
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: EmacsKillRing plugin for ST2?

Postby adzenith on Sat Jan 29, 2011 7:44 pm

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.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: EmacsKillRing plugin for ST2?

Postby guillermooo on Sat Jan 29, 2011 7:54 pm

adzenith wrote: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?


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?
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: EmacsKillRing plugin for ST2?

Postby adzenith on Sat Jan 29, 2011 8:25 pm

guillermooo wrote: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?


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 :)
Code: Select all
import sublime
def onDone(string):
  print string
v = sublime.active_window().show_input_panel("Kill ring index:","0",onDone,0,0)
Last edited by adzenith on Sat Jan 29, 2011 10:10 pm, edited 1 time in total.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: EmacsKillRing plugin for ST2?

Postby adzenith on Sat Jan 29, 2011 10:09 pm

...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.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: EmacsKillRing plugin for ST2?

Postby stiang on Sun Jan 30, 2011 9:26 am

adzenith wrote: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.


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.
stiang
 
Posts: 39
Joined: Sat Jan 29, 2011 12:34 pm

Re: EmacsKillRing plugin for ST2?

Postby Iorlas on Sun Jan 30, 2011 11:22 am

Maybe this features can be merged into editor? I think, some things from killring can be merged with original idea of editor.
Iorlas
 
Posts: 13
Joined: Sun Jan 30, 2011 5:47 am

Re: EmacsKillRing plugin for ST2?

Postby stiang on Mon Jan 31, 2011 8:46 am

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?
stiang
 
Posts: 39
Joined: Sat Jan 29, 2011 12:34 pm

Re: EmacsKillRing plugin for ST2?

Postby lunixbochs on Mon Jan 31, 2011 9:02 am

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
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Next

Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests