SublimePerlTidy icon indicating copy to clipboard operation
SublimePerlTidy copied to clipboard

perltidy on save option?

Open ranguard opened this issue 12 years ago • 2 comments

Hi,

Another random idea - I've seen plugins ( http://www.klaascuvelier.be/2012/02/sublime-text-2-command-on-save/ ) that let you run commands on save, but thought it would be a fantastic option to have within this great plugin.

Just a though - keep up the good work :)

Leo

ranguard avatar Nov 01 '13 15:11 ranguard

Hi Leo,

it's on the list for the next release.

Cheers, V.

vifo avatar Dec 20 '13 19:12 vifo

I was able to implement this by adding a file called PerlTidyEventListener.py in ~/Library/Application Support/Sublime Text 2/Packages/PerlTidy/ with this code:

# -*- coding: utf-8 -*-

import sublime, sublime_plugin

class PerlTidyEventListener(sublime_plugin.EventListener):
    def on_pre_save(self, view):
        # Only run perltidy on perl files and if user requests this feature.
        run_on_save = view.settings().get('perltidy_run_on_save', False)
        if (run_on_save and view.match_selector(view.sel()[0].begin(), 'source.perl')):
            view.run_command('perl_tidy')

It checks for a user setting of perltidy_run_on_save. If this isn't set to true it is disabled by default.

cantpitch avatar Dec 13 '14 04:12 cantpitch