sublimetext-codeformatter icon indicating copy to clipboard operation
sublimetext-codeformatter copied to clipboard

Add ability to replace chunks of code

Open twolfson opened this issue 12 years ago • 1 comments

There is a good proverb that I like:

Why write a program that throws lint errors when it can correct the code?

Last night, this idea rattled out of my head and it goes like this; combine the awareness of SublimeLinter with the formatters of CodeFormatter

  1. on_post_save, format code into memory or temporary file
  2. Diff original code against formatted code
  3. Show gutter warnings and highlight lines that vary based on diff
  4. Allow user to take action and apply diff to that section of code

Here is a mocked prototype I wrote:

selection_014

twolfson avatar Jun 26 '13 05:06 twolfson

For reference, the code of this prototype is very simple:

import sublime
import sublime_plugin


class ExampleCommand(sublime_plugin.EventListener):
    def on_post_save(self, view):
        line = view.line(view.sel()[0])
        view.add_regions('formmater-suggest',
            [line], 'python', 'circle', sublime.DRAW_OUTLINED)

I also ran the following in the terminal for a status message

sublime.status_message('CodeFormatter: Replace code with "view.add_regions(\'formmater-suggest\', [line], \'python\', \'circle\', sublime.DRAW_OUTLINED)"')

twolfson avatar Jun 26 '13 05:06 twolfson