Sublime Forum

Accepting arguments to python plugins

#1

I’m trying to write a basic plugin that will create a vertical split and clone the current file to the new pane, or optionally open a specified file in the new pane. Is there a way I can accpet an argument so that a user could write “Split” or “Split: <file_name>” and get this behavior?

When I search “sublime arguments to python plugins” I get some “unofficial documentation page” saying “All commands can receive an arbitrarily long number of keyword arguments that must be valid JSON types.” but I don’t really understand what the bit about JSON types means, or how to set it up such that it receives those arguments.

0 Likes

#2

I assume you mean this page. They were started by Guillermo López-Anglada, whom I assume posts here.

Anyway, here is some sample code with JSON args (last line)

if not braces: new_sels = ] for sel in sels: new_sels.append(self.view.find('\}', sel.end())) sels.clear() for sel in new_sels: sels.add(sel) self.view.run_command("expand_selection", {"to": "brackets"})

0 Likes

#3

JSON args refers to data types that would be valid in JSON, which is a nested combination of the Python types tuple, list, dict, int, float, str, bool and None.

0 Likes