Probably the easiest thing to do is:
-
If there is no selection, expand the selection to the current paragraph
-
Do what you want with the current selection.
This gives your command the robustness to allow the user to select exactly what they want and provide a sensible default if they don’t.
As @math2001 mentioned, you can use the built in functionality to expand the selection to the current paragraph; if there is no selection, this will select the paragraph that the cursor is currently in.
The command to do this is expand_selection_to_paragraph
(which you can determing by entering sublime.log_commands (True)
in the sublime console and then selecting the menu item to see what it’s doing). From the looks of the code above you already have a handle on how to determine if the current selection is empty.
In order to run the command, you can do something like:
view.run_command ("expand_selection_to_paragraph")