Search This Blog

Tuesday, October 1, 2013

Sublime macro error

Macros are a very power full tools when working with text editors. If you repeatedly typing the same commands/characters to edit your text you can always try to capture them and save as a macro.

Problem

A macro that tries to capture the ALT+F3 keyboard shortcat to highly all the word occurrence in text (more about this here) doesn't work and is erroring out on the console with this message.
 
Unknown macro command find_all_under

Troubleshooting

You can reproduce this by trying these steps:
  • Create a new file with this content.
  •  
    Line : aaa
    comment1
    comment2
    comment3
    
    Line : bbb
    comment4
    comment5
    

  • Select menu tools -> record macro in sublime.
  • Highlight the ":" char and press ALT-F3 to mark two lines.
  • Stop macro and save it.
The file should look similar to this one:
 
[
 {
  "args":
  {
   "by": "characters",
   "extend": true,
   "forward": true
  },
  "command": "move"
 },
 {
  "args": null,
  "command": "find_all_under"
 }
]

When you try to execute this macro it doesn't work and you can see the error message in the console window.

Analysis and solution

The command find_all_under is documented and works fine. You can always try to run it manually from the console yourself.
 
view.window().run_command("find_all_under")

To create the automatic solution and let the editor to do the work for me I decided to write a Plugin using Sublime Python API. The code works perfectly fine and can be found on my github account: https://github.com/rtomaszewski/sublime under the file device_list.py. All what you need to do is to install this plugin and execute it manually or use a keyboard shortcat to trigger it.

Workaround example:
 
view.run_command("device_list")

References

Sublime Python API
http://www.sublimetext.com/docs/2/api_reference.html
http://docs.sublimetext.info/en/latest/reference/plugins.html

Commands
http://docs.sublimetext.info/en/latest/reference/commands.html
http://www.sublimetext.com/docs/commands
http://docs.sublimetext.info/en/latest/extensibility/commands.html

Debugging
http://www.sublimetext.com/forum/viewtopic.php?f=6&t=10106
http://sublimetext.userecho.com/topic/114638-ctrlshiftt-does-not-work/
http://www.sublimetext.com/forum/viewtopic.php?f=6&t=4961

No comments:

Post a Comment