I am new to Sublime Text internals. I am trying to get a command executed while keeping the cursor position. I am in the following scenario:
I have a buffer with a C file. I also have a command called clang_format that I have to invoke. That command takes the selected region as input and reformats it. What I want to achieve is reformatting the complete buffer avoiding to loose the current position of the cursor. My initial attempt is:
class FormatBufferCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Here I should save the current position of the cursor
self.view.run_command('select_all')
self.view.run_command('clang_format')
self.view.sel().clear()
# Here I should restore the position
Can anyone help me to fill in the blanks?
Thanks in advance.