Sublime Forum

SublimeText macros are no good

#21

Personally, I wish that Sublime would integrate Chain of Command (or the equivalent) into the Default package. I’m always skeptical of requests to add new features to core that are available in third-party packages, but I think the case here is very strong.

The legacy TextMate macro system is clunky and missing important features. Users often complain on the forum, and the best recommendation is usually to use Chain of Command. Adopting that as a first-party solution (and adding it to the official documentation) would lead new users to the best solution to a common problem. In addition, package developers could use chains without relying on another package.

4 Likes

#22

This is a plea for the implementation of a much more capable macro functionality. I love Sublime Text, but its biggest short-coming for me is this serious lack of command recording for seemingly anything beyond trivial text manipulation. I appreciate the recommendation for the Chain of Command solution, but I am struggling to get even simple cursor selections and movements to work with it while trying to use it with my example problem below, so I anticipate that its use-cases will be limited.

Veteran editors such as Vi and Emacs have strong macro support that I frequently find myself wishing Sublime had. Yesterday, for example, I was wanting to parse compiler debug output to give me the commands and how long the commands took to execute. The following is sample output (simplified for the example; have hundreds of lines with this structure):
#43 cmd: GET_SETTINGS time In : 515797
#23 time out: 515864
#44 cmd: UPDATE_SETTINGS time In : 515950
#24 time out: 516026
#45 cmd: WRITE_SETTINGS time In : 516112
#25 time out: 516183

To get the following:
GET_SETTINGS 67
UPDATE_SETTINGS 76
WRITE_SETTINGS 71

I am a novice with Python, but have some experience. I managed to write a plug-in to accomplish the above, but it took me at least a couple hours to get it working. Using Emacs I was able to craft a macro in under five minutes (including time to fix a couple mistakes) that does the same parsing. I anticipate that with more experience I might be able to craft a plug-in in around 15 minutes, but this requires Python experience which should not be a prerequisite for text editor users and is still an excessive amount of time for simple one-off tasks where I frequently use macros for such solutions in a minute or five.

Please implement better macro functionality.

2 Likes

#23

Unless your output has a lot more variation, just 30 seconds and multiple cursors will get you what you want. I got the following:

GET_SETTINGS 67
UPDATE_SETTINGS 76
WRITE_SETTINGS 71

Here is how I did it:

  • select cmd:
  • press ctrl+d to select all instances for multiple cursors
  • use home, ctrl+right/left and shift to select the junk
  • delete it
  • move past the part you want using ctrl+right, select more and delete
  • get the two numbers next to each other for each entry via the above method
  • type a - between the pairs of numbers
  • open the command palette and run the “Arithmetic” command
  • delete the -

Perhaps your real data is more varied so such an approach wouldn’t work. In general, for basic data massage, I find multiple cursors to be excellent. Beyond that you may want a script in some sort of language so you can tweak it each time as you find bad results, but this is just my opinion.

All that said, I’m sure there are some ways in which macros could be improved.

0 Likes

#24

I’m pleased that this caught your attention. Yes, after spending too much time on this, I did realize that some multi-cursor awesomeness would work and did use the Arithmetic command with success similar to what you did (love that Arithmetic feature!), which took me about the same amount of time as an Emacs macro to get it working. Frequently my macro desires include regex searches for each operation, which I haven’t found to be as easily resolved. Also, my task posted above was to assist a new-to-sublime co-worker who is benefiting from the plug-in I wrote. Yes, they could cut their teeth on Sublime commands, but if macros were more full-featured then they could be passed along for easy reuse at this level as well.

I did use a macro to simplify my double line segments in the example above into one line, but found that the macros wouldn’t use join_lines, which seems like something that should work. I wish the macros would somehow detect and indicate that incompatible commands were used that will not be included in the macro instead of leaving it to failed future results for discovery.

Again, I love Sublime Text and that multi-cursors could save the day on this one. Still, I wish the macro functionality could be expanded to the level of many peer editors - it’s my only reservation with Sublime. Thank you for your time, feedback, and consideration!

1 Like