Sublime Forum

Plugin is broken with upgrade to 4166 and beyond

#1

Hello everyone,

I have several python plugins that I use for work that are no longer functional with the update to build 4166 and 4169.

In short: I am no longer able to use TextCommand plugins to insert text into a new file. Here is the snippet of code that is no longer functional:
newFile = self.view.window().new_file()
newFile.insert(edit,0,output)

from some output string that is generated earlier in the plugin. I’ve narrowed it down to these lines by using print statements to validate the output string. The string is correct in the console so I know that the rest of the plugin is working as expected to create the output string. But I can no longer insert that string into a new file. When I run the plugin I do not get any error messages and it does open a new file but the output string does not get inserted into it.

Thank you for your help!

0 Likes

#2

From the changelog:

API: Fixed crash when an edit token is passed to the wrong view

The edit token that you use is apparently not valid for the new view, and it’s not possible anymore to use it on different views. But you could just run the built-in insert command on the new view instead:

newFile = self.view.window().new_file()
newFile.run_command('insert', {'characters': output})
3 Likes

View.replace() not working in build 4169
#3

This is interesting but I’m not sure that this is the same issue - I’ve been using these scripts for years and I’ve never seen a crash when running them.

The code snipped you posted does fix my issue, thank you. I can’t find any information in the API about calling run_command with the insert function and I also can’t figure out where you got the “characters” key for the dictionary in the second argument. Can you help me find that info so I can figure out this code? Thanks again for the snippet

0 Likes

#4

There is no official document which lists commands and their args. There is community-collected information in plugin https://packagecontrol.io/packages/CommandsBrowser

0 Likes

#5

Thank you for the info, this is helpful. Out of curiosity - do you know how the plugin author was able to collect these commands into a list if they aren’t in publicly available documentation? I’m still a little bit confused about how this knowledge has come to be.

I’ve updated my scripts to use this new run_command and they are all working correctly now.

0 Likes

#6

It has been explained in its readme.

0 Likes

#7

The readme states that the core command list is not exposed by Sublime. So I’m curious how the author was able to compile them into a list if they aren’t documented or exposed by Sublime. Does that make sense? Maybe I’m not being clear about what I’m asking

0 Likes

#8

I would read it as someone occasionally find them somewhere.

0 Likes

#9

That kind of makes it sound like the commands are out there just waiting to be discovered but I’m still not really clear how that works or where some of these discoveries might take place. Do you mean in documentation? Or do you mean something else?

0 Likes

#10
  • Built-in menu files
  • sublime.log_commands(True)
1 Like

#11

Thank you! For future reference this response is much more helpful than saying “It has been explained in its readme” and could have saved a few posts. But I’m glad we got here eventually, have a great day! :blush:

0 Likes