Sublime Forum

Macro recording stopped working

#1

I’ve recorded macros successfully in the last couple of days, but today my macro recording doesn’t seem to be working. I’m starting and stopping the recorder from the Tools menu. The status bar reports (accurately) when recording has started and when it has stopped. But after that, my “Playback Macro” option is grayed out, and selecting “Save Macro…” does nothing. The operation I’m trying to record is some menu-selection toggling related to word wrapping. I’ve looked all over, but I’m flummoxed. Any ideas about where to start troubleshooting? Running ST3 on Ubuntu. (Note, I’ve tried quitting and restarting, as suggested in an earlier thread, but no dice.)

0 Likes

#2

Macros can only record what we refer to as TextCommand commands; that is, things that change the state of a file (as opposed to things like doing a search). That said, the command for toggling the setting reports itself as such a command so one would think that it can be captured in a macro, but for whatever reason it can’t.

You can however manually add it to a macro if you’d like to. sublime-macro files are just JSON files that list commands to execute and their arguments, so you can manually edit in the command that you want. For example:

[
	{ "command": "insert", "args": {"characters": "Some text I inserted"} },
	{ "command": "toggle_setting", "args": {"setting": "word_wrap"} },
]

That said, in my testing although toggle_setting won’t record, other commands would, and in that case you can save the macro as normal (the Save Macro command does nothing if there’s no macro to save). Were you trying to record something else with your macro that also wasn’t captured?

0 Likes

#3

Thanks for your note. I’ve poked around with JSON files just a bit, with some success, so I’ll take a shot at creating one to do what I’m trying to accomplish. For now, all I’m trying to record is this menu sequence: View > Word Wrap Column > Automatic. That’s it. I’m wanting to bind it to a key combo. This will a half-step toward something I was asking about on the forum yesterday, here, but which can’t currently be done.

0 Likes

#4

For the record, you don’t need to put the command in a macro; you can just bind toggle_setting with the arguments shown above to a key directly if you want to toggle word wrap.

This is demonstrated in the following video (which shows a simple plugin that enhances the built in command to make it more powerful, but you don’t need a custom plugin for what you’re doing here):

0 Likes

#5

Thanks, man. You’re very good with the videos.

On this thing I’m trying to do: I’m not looking to toggle the word wrap. I want word wrap always on. What I’m trying to change is “Tools > Word Wrap Column” from 70 (my default) to Automatic and back again. Initially I wanted a solution such that when I shrunk the ST window to half screen, Word Wrap Column would automatically change from 70 to Automatic, and when I restored to full screen (or distraction free), Word Wrap Column would pop back to 70.

As it appeared that wasn’t possible, per that discussion, I decided I would like to bind that choice (Word Wrap Column > Automatic) onto a key. Once I figured that out, I was going to bind its complementary choice ( Word Wrap Column > 70) onto a different key. So at Ieast, if I couldn’t have it happening automatically when I shrunk and grew the window, I could at least have the options handy with a couple of key presses. I hope I’ve explained it clearly. But yeah, it’s not a matter of toggling Word Wrap–that’s always going to be on for me.

0 Likes

#6

In that case, you perhaps want the plugin that’s outlined in that video. A wrap width of 0 corresponds to Automatic, so you could toggle the setting between 70 and 0 using that plugin to get what you want.

0 Likes

#7

Oh, nice. I’m going to dig into that tonight and hopefully get it up and running. Thanks again for your help.

0 Likes

#8

All right. I couldn’t wait until tonight to try it… so I’ve added this to my Default.sublime-keymap, in my User directory:

// Standard: Toggle wrap width. Requires plug-in ToggleSettingExt to work
{ “keys”: [“ctrl+e”], “command”: “toggle_setting_ext”, “args”: { “setting”: “wrap_width”, “options”: [70, 0] }}

And I’ve saved your plugin code here: Sublime Text 3/Packages/toggle_setting_ext/toggle_setting_ext.py

But it doesn’t seem to be working. I’m seeing confusing advice online about where/how to store the plugin, and I’m such an amateur I’m sure I’ve screwed it up somehow, but I can’t see it.

0 Likes

#9

That is indeed the correct key binding for this (verified locally), so the issue is likely the location of the plugin.

A potentially confusing thing is that there are technically two folders named Packages. One of them is inside of the location where Sublime Text is actually installed (which contains a variety of sublime-package files, which are the packages that Sublime ships with) and the other is inside of the user specific configuration area.

Loose plugin files like this need to go in the latter location; Sublime will only load sublime-package files from the folder in the installation location (and in general, you shouldn’t mess with that location).

The folder you want to be working in can be found by using Preferences > Browse Packages from the menu or command palette. One of the folders in there is your User package, so you could put the plugin in there. Alternately you could create a distinct folder for it in this Packages folder such as what you have above and put the file in there as well.

If that’s the location you used, then you can check in the Sublime console (View > Show Console) to see if there are any errors displayed. For something like this, you should see a line that says it’s reloading the plugin using the name that you see above. If you don’t see any line about the plugin reloading (including if you were to open the file and save it with no changes, just to update the file time), then the plugin is in a place that Sublime’s not considering.

There’s a guide for this in general in my video on how to use plugins. I also have one that tries to demystify packages in Sublime Text that explains the various places packages can exist and the different forms they can take.

0 Likes

#10

You’re the best. Thanks for all your time and know-how. I will get back to this tonight and get it ironed out, and I’ll watch the other two videos as well. Will report results. Thanks once again.

1 Like

#11

Well, if you can believe this, the fault was mine: I made a couple of errors in simply copying and pasting your plugin code–the console view helped me track things down. I’d left off the last parenthesis and the opening two lines–before your commented section. Duh. Once I got that squared away, everything worked great. I am really grateful for your help, and your videos are a solid resource I’m sure I’ll be returning to. Take care.

1 Like