Home Download Buy Blog Forum Support

Repeat Macro n Times

Repeat Macro n Times

Postby lkraven on Wed Aug 31, 2011 6:21 pm

Is there a way to quickly repeat a macro a specified number of times. I attempted to record a macro and use the repeating functionality of Vintage, but it's not working quite like vim does yet.

Would the best way to go about this if it doesn't exist to write a plugin to do it?
lkraven
 
Posts: 3
Joined: Wed Aug 31, 2011 6:19 pm

Re: Repeat Macro n Times

Postby lkraven on Sat Sep 03, 2011 4:34 pm

I wrote this little plugin to repeat macros. I guess I should move this over to the plugin development forum.

Only issue is that, while it works, it is really very slow for any large number of repetitions, and it locks up Sublime while it is running. Haven't really explored how else to make it happen. I am a neophyte python programmer, and just downloaded/purchased Sublime a few days ago.

Code: Select all
import sublime, sublime_plugin

class repeat_macro(sublime_plugin.WindowCommand):
   def run(self):
      self.window.show_input_panel("Repeat Macro Count:",
         "", self.on_done, None, None)
      pass

   def on_done(self, text):
      try:
         loopcount = int(text)
         if self.window.active_view():
            for x in xrange(1,loopcount):
               for cmds in sublime.get_macro():
                  self.window.active_view().run_command(
                     cmds['command'], cmds['args'])
         pass
      except ValueError:
         pass
lkraven
 
Posts: 3
Joined: Wed Aug 31, 2011 6:19 pm

Re: Repeat Macro n Times

Postby jps on Tue Sep 06, 2011 1:09 pm

btw, you should be able to just run the 'run_macro' command n times, rather than having to do it the long way via get_macro(). It'll be faster to do it this way, too, but depending on what the bottleneck is this may make no difference.

Repeating a macro n times is generally done to apply an operation to multiple lines. You can do this more directly in Sublime Text: select the lines of interest, then split the selection into lines (ctrl+shift+l or cmd+shift+l depending on platform), and then either do the edits directly, or just replay the macro once, and it'll apply to all lines.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Repeat Macro n Times

Postby kuroir on Wed Sep 07, 2011 2:19 am

jps wrote:split the selection into lines (ctrl+shift+l or cmd+shift+l depending on platform), and then either do the edits directly, or just replay the macro once, and it'll apply to all lines.


Now, that's a useful tip that should be stored somewhere!
kuroir
 
Posts: 71
Joined: Thu Sep 01, 2011 11:28 pm
Location: Mexico


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests