Coder Social home page Coder Social logo

sublimeperltidy's Introduction

perltidy for Sublime Text 2/3

Build Status

PerlTidy is a plugin for Sublime Text 2/3, which integrates the command line application perltidy into Sublime Text. It indents and reformats Perl source code to make it easier to read.

Quick start

  • Ensure, you have a Perl interpreter and perltidy installed (hint: apt-get install perltidy, yum install perltidy, cpan[m] Perl::Tidy, ppm install Perl-Tidy)
  • Install this plugin in Sublime Text via Package Control, git or from ZIP (in Sublime Text the plugin is named PerlTidy, not SublimePerlTidy)
  • Open a Perl source file and hit Control+Shift+t

Read on for detailed installation, usage, configuration and customization instructions.

Table of contents

  • With Sublime Package Control: The easiest way to install PerlTidy is through Sublime Package Control. If you're not using it yet, get it. Seriously.

    Once you have installed Package Control, restart Sublime Text and bring up the Command Palette (press Control+Shift+P on Linux/Windows, Command+Shift+P on OS X, or select Tools->Command Palette... from menu). Select Package Control: Install Package, wait till latest package list has been fetched, then select PerlTidy from the list of available packages.

  • With Git: Clone the repository in your Sublime Text Packages directory. Please note that the destination directory must be PerlTidy.

      git clone https://github.com/vifo/SublimePerlTidy PerlTidy
    

The advantage of using either Package Control or git is, that the plugin will be automatically kept up-to-date with the latest version.

  • From ZIP: Download the latest version as a ZIP archive and copy the directory "SublimePerlTidy-master" from the archive to your Sublime Text Packages directory. Rename directory "SublimePerlTidy-master" to "PerlTidy".

The Packages directory locations are listed below. If using Sublime Text 3, be sure to replace "2" with "3" in directory names. Alternatively, selecting Preferences->Browse Packages... from Sublime Text menu will get you to the Packages directory also.

OS Packages location
OS X ~/Library/Application Support/Sublime Text 2/Packages/
Linux ~/.config/sublime-text-2/Packages/
Windows %APPDATA%\Sublime Text 2\Packages\

After PerlTidy installation, open a Perl file of your choice and:

  • hit Control+Shift+t
  • or open Command Palette, start typing "perltidy", select "PerlTidy: Tidy" and hit return

to reformat the entire file. PerlTidy also works on selections. Give it a try.

Though usage of PerlTidy is quite simple and PerlTidy will do its very best to Just Work™, most aspects can be configured to suite your needs.

PerlTidy will try to locate perltidy by:

  1. Checking the user setting "perltidy_cmd" for a (valid) user supplied perltidy location.

  2. Searching for "perltidy" ("perltidy.bat" on Windows) within directories specified in environment variable PATH.

  3. Searching for perltidy in platform specific default locations. These are:

  • On Windows (in given order):

    Default Strawberry Perl installation location C:\Strawberry, i.e.:

    "perltidy_cmd": [ "C:\\Strawberry\\perl\\bin\\perl.exe", "C:\\Strawberry\\perl\\site\\bin\\perltidy" ]

    Default ActivePerl 64-bit installation location C:\Perl64, i.e.:

    "perltidy_cmd": [ "C:\\Perl64\\bin\\perl.exe", "C:\\Perl64\\site\\bin\\perltidy" ]

    Default ActivePerl 32-bit installation location C:\Perl, i.e.:

    "perltidy_cmd": [ "C:\\Perl\\bin\\perl.exe", "C:\\Perl\\site\\bin\\perltidy" ]

    Default Cygwin installation location C:\cygwin, i.e.:

    "perltidy_cmd": [ "C:\\cygwin\\bin\\perl.exe", "/usr/local/bin/perltidy" ]

  • On Linux and OS X:

    /usr/bin/perltidy, /usr/local/bin/perltidy (which will most likely be in your PATH anyway), i.e.:

    "perltidy_cmd": [ "/usr/bin/perltidy" ]

Let PerlTidy try to locate perltidy first. If this does not work, adjust user setting "perltidy_cmd" as needed.

By default, PerlTidy uses perltidy options as suggested in Damian Conway's Perl Best Practices (PBP). Though I don't agree with all of the perltidy settings in the PBP set, using them results in slightly better readable Perl code, than using perltidy's defaults. Since perltidy already supports the PBP set using the command line switch -pbp or --perl-best-practices, introducing just another set of options seems unnecessary.

So the default PerlTidy options are:

"perltidy_options": [ "-pbp" ]

which, at least with a recent perltidy version is effectively the same as:

"perltidy_options": [
    "-l=78", "-i=4", "-ci=4", "-vt=2", "-cti=0", "-pt=1", "-bt=1", "-sbt=1", "-bbt=1", "-nsfs", "-nolq",
    "-wbb=\"% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=\"",
    "-st", "-se"
]

Ermmm, what?! Fear not, here are the explanations (and differences with perltidy defaults):

PBP Option perltidy Defaults Description
-l=78 -l=80 Maximum line width is 78/80 columns
-i=4 same Use 4 columns per indentation level
-ci=4 -ci=2 Continuation indentation is 4/2 columns
-vt=2 -vt=0 Vertical tightness set to maximum/minimum
-cti=0 same No extra indentation for closing tokens
-pt=1 same Medium parenthesis tightness
-bt=1 same Medium brace tightness
-sbt=1 same Medium square bracket tightness
-bbt=1 -bbt=0 Medium/minimal block brace tightness
-nsfs -sfs Additional space for semicolons in for loops disabled/enabled
-nolq -olq Outdenting of overly long quoted strings disabled/enabled
-wbb="..." none Break before these tokens (operators)
-st none Output to STDOUT
-se none Errors to STDERR

You may override any of the above settings by changing user setting "perltidy_options" in your preferences, preferably including the -pbp option like this:

"perltidy_options": [ "-pbp", "-l=120" ]

Please refer to the official perltidy Documentation and the perltidy Style Guide for an explanation of all options available.

Defaults to Control+Shift+t on all platforms. Feel free to change this in Preferences->Key Bindings - User by adding and adjusting following lines:

// PerlTidy key bindings
{
    "keys": ["ctrl+shift+t"],
    "command": "perl_tidy",
    "context": [ { "key": "selector", "operator": "equal", "operand": "source.perl", "match_all": true } ]
}

If you'd like to override specific settings, open Preferences->Settings - User and add/adjust the following lines:

// Specify full path to perltidy and optionally the Perl interpreter. If not
// specified, will search PATH for perltidy and fall back to platform default
// locations.
//
// Please note, that with Strawberry Perl/ActivePerl on Windows, you have to
// either specify the full path to the Perl interpreter AND the perltidy file
// (NOT "perltidy.bat"), OR the full path to the batch wrapper file
// "perltidy.bat". The former is preferred, we don't need the batch wrapper.
//
// Windows/Strawberry Perl/ActivePerl:
//"perltidy_cmd": [ "C:\\Strawberry\\perl\\bin\\perl.exe", "C:\\Strawberry\\perl\\site\\bin\\perltidy" ]
//"perltidy_cmd": [ "C:\\Perl\\bin\\perl.exe", "C:\\Perl\\site\\bin\\perltidy" ]
//
// Windows/Cygwin:
//"perltidy_cmd": [ "C:\\cygwin\\bin\\perl.exe", "/usr/local/bin/perltidy" ]
//
// Linux/OS X with non-standard location or explicit Perl interpreter:
//"perltidy_cmd": "/opt/perl/bin/perltidy"
//"perltidy_cmd": [ "/opt/perl-5.18.0/bin/perl", "/opt/perl-5.16.3/site/bin/perltidy" ]

// Specify possible perltidyrc files to search for within current project. The
// first matching perltidyrc will be used. Absolute paths may also be used, if
// you have a global perltidyrc. Defaults to [ ".perltidyrc", "perltidyrc" ].
//"perltidy_rc_paths": [ ".perltidyrc", "perltidyrc" ]
//"perltidy_rc_paths": [ "C:\\Users\\USERNAME\\AppData\\Roaming\\perltidyrc" ]

// Specify perltidy options. Defaults to: [ "-pbp" ]
//"perltidy_options": [ "-pbp" ]

// Specify, whether perltidy options given in "perltidy_options" take
// precedence over options found in perltidyrc files. Defaults to "false"
// (note: default value was "true" up to version 0.4.0). Adjust to "true" to
// reverse this order.
//"perltidy_options_take_precedence": false

// Log level for perltidy operations. Set to 1 to enable informational
// messages and to 2 for full debugging. Defaults to 0, so only warnings and
// errors will be displayed on the console.
//"perltidy_log_level": 0

// If, for some reason, you'd like to disable PerlTidy entirely, set
// "perltidy_enabled" to false. Defaults to true.
//"perltidy_enabled": true

You may override any of these settings per project, by adding a section named "settings" with overridden settings to your project file:

{
    "folders": [
        {
            "path": "..."
        }
    ],
    "settings": {
        "perltidy_log_level": 2,
        "perltidy_options": [ "-pbp", "-l=120", "-w" ]
    }
}

During normal operation, PerlTidy will emit warnings and errors to the Sublime Text console (open with Control+` or select View->Show Console from menu). In order to enable additional diagnostic messages, adjust user setting "perltidy_log_level" as follows:

  • 0 == Warnings and error messages only. This is the default.

  • 1 == Print system commands used for tidying up content and perltidyrc file paths used (if any).

  • 2 == Full debugging. In addition to the above, print where PerlTidy searches for perltidy and/or perltidyrc.

Windows Error 193

You are running Strawberry Perl/ActivePerl on Windows, and have set a custom path to perltidy via user setting "perltidy_cmd". While trying to run, PerlTidy bails out with the following error message on the ST console:

PerlTidy: Unable to run perltidy: "C:\Strawberry\perl\site\bin\perltidy" ...
PerlTidy: OS error was: WindowsError(193, '...')
PerlTidy: Maybe you have specified the path to "perltidy" instead of "perltidy.bat" in your "perltidy_cmd"?

You have specified the path to the raw Perl "perltidy" file (without extension), instead of the batch wrapper file "perltidy.bat". Windows is unable to execute the former file directly. Yes, typing "perltidy" in cmd.exe will work, but only due to the way, how cmd.exe handles files without an extension: it will try extensions specified in environment variable PATHEXT, eventually find the file "perltidy.bat" and run it.

TL;DR: Assuming you are running a vanilla Strawberry Perl/ActivePerl installation: adjust user setting "perltidy_cmd" to one of the following:

"perltidy_cmd": [ "C:\\Strawberry\\perl\\bin\\perl.exe", "C:\\Strawberry\\perl\\site\\bin\\perltidy" ]    # for Strawberry Perl
"perltidy_cmd": [ "C:\\Perl64\\bin\\perl.exe", "C:\\Perl64\\site\\bin\\perltidy" ]                        # for ActivePerl 64-bit
"perltidy_cmd": [ "C:\\Perl\\bin\\perl.exe", "C:\\Perl\\site\\bin\\perltidy" ]                            # for ActivePerl 32-bit

or, if you really need to use the batch wrapper for some (non-obvious) reasons, to:

"perltidy_cmd": "C:\\Strawberry\\perl\\site\\bin\\perltidy.bat"       # for Strawberry Perl
"perltidy_cmd": "C:\\Perl64\\site\\bin\\perltidy.bat                  # for ActivePerl 64-bit
"perltidy_cmd": "C:\\Perl\\site\\bin\\perltidy.bat"                   # for ActivePerl 32-bit

or just let PerlTidy figure out where perltidy is located by not setting "perltidy_cmd" at all.

In order to make bug hunting easier, please ensure, that you always run the latest version of PerlTidy. Apart from this, please ensure, that you've set PerlTidy log level to maximum ("perltidy_log_level": 2 in user settings), in order to get all debugging information possible. Also please include the following information, when submitting an issue:

  • Operating system name (i.e. "Windows XP SP3", not "Windows")

  • Operating system architecture (i.e. 32-bit, 64-bit)

  • Sublime Text build number (open Help->About)

  • Output from Sublime Text console

To gather this information quickly, open ST console, type in the following Python code as-is (in one line) and include its output in your issue:

from __future__ import print_function, unicode_literals;import platform, sublime, datetime;print('-' * 78);print('Date/time: {0}'.format(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S +0000')));print('Sublime Text version: {0}'.format(sublime.version()));print('Platform: {0}'.format(sublime.platform()));print('CPU architecture: {0}'.format(sublime.arch()));print('OS info: {0}'.format(repr(platform.platform())));print('-' * 78)

Standalone perltidy executable for Windows

If you're running Sublime Text on Windows and don't like to install a complete Perl interpreter just for using perltidy, grab the standalone perltidy executable from here and adjust your settings:

"perltidy_cmd": [ "C:\\WHEREVER_YOU_HAVE_DOWNLOADED_THE_EXE_TO\\perltidy-20121207-x86.exe" ]

This executable has been built with ActiveState ActivePerl 5.16.3.1603 x86 using PAR::Packer. It contains the Perl interpreter as well as the latest version of perltidy, including all required dependencies in a self contained executable (thus the size of 4.5 MB).

Please note: this executable works for me and is provided as-is, with no support whatsoever. If it also works for you, great! If not, please don't complain, but get a Perl interpreter and perltidy for Windows instead. Even better: fix errors, repackage (maybe using helper script "helpers/build_perltidy_20121207_x86.pl" as a starting point) and provide final executable to me for hosting on S3.

  • Implement automatic tidying of Perl files upon save. Until then, ST2-CommandOnSave might be an option to achieve this.

I spend a lot of my scarce free time working on this plugin, and would appreciate any support you'd care to offer. If using this plugin makes your coding life easier and more productive and you'd like to thank me, please consider:

  • making a donation via PayPal
  • star this plugin on GitHub
  • twitter, blog or in general spread the word.

Please note that you don't have to do any of the above in order for me to continue to work on this plugin. I will continue to do so, for as long as it interests me and inasmuch I have free time to spend. Similarly, a donation made in this way probably won't make me work on this plugin harder, unless I get so many donations that I can consider working on it full time (which at least for now seems unlikely at best).

Thank You!

Changes

Only latest changes are listed here. Refer to full change log for all changes.

v0.4.5 2014-01-05 22:15:00 +0100

  • Remove packages.json. Package Control versioning now done via git tags/semantic versioning.
  • Stripped leading "v" from all tags.

v0.4.4 2014-01-03 09:30:00 +0100

  • Bump version number in order to fix #22.

sublimeperltidy's People

Contributors

marcusramberg avatar plu avatar rbo avatar vifo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublimeperltidy's Issues

UI possible minor improvement...

Very minor... might not be possible... and is being really fussy!

When you run the perltidy command it feels as if it follows the following flow..

  1. run perl tidy on current buffer and get output
  2. replace buffer with tidied version
  3. scroll to where you were before

Is there any way to refresh in place? - because then your eye actually sees the changes going on you get a warm fuzzy feeling that you didn't have to do that yourself.

If you don't get what I mean please ask - or try the perltidy in textmate which seems to do it inline and give you fuzzies 😄

p.s. you get the fuzzy feeling when you select a block and perltidy

Recursively search for .perltidyrc file instead of having to specify locations for it

It would be great to have the option for the plugin to find the .perltidyrc file by simply recursively searching each parent directory for the file until it finds one. It should start in the same directory as the file that the command is initiated from and then move up the tree until a file is found.

For example, for a directory structure like this:

project/
|--.perltidyrc
|--folder/
|  |--subfolder/
|     |--file1.pl
|--file2.pl

When executing the plugin from file1.pl, the plugin would search in project/folder/subfolder/ and project/folder/ before finally finding the .perltidyrc file in the project/ folder and using that. Similarly, if executing for file2.pl, the plugin would start its search in the project/ folder and find it there immediately.

The plugin could also have a default search location in case the .perltidyrc file wasn't found anywhere in the parent directories. It could default to searching in paths like ~/.perltidyrc, etc.

I don't know a lot about how Sublime's plugin API works but it seems like you could get the current file's path from self.view and then simply do a search by calling dirname() on that path until you get to /.

Does not work if the file contains non ascii characters

I am using Sublime Text 2 on Windows 7 x64 with this plugin.
On some files, plugin does not work.

File example (UTF-8, russian):
package MyPack::I18N::ru;

use base 'MyPack::I18N';
use utf8;

our %Lexicon = (
_AUTO => 1,

Form viidation messages

validation_required =>
'Это поле обязательно',
error_auth => 'Неправильное имя пользователя или пароль!'
);

1;

Error from console:
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\PerlTidyCommand.py", line 36, in run
File ".\PerlTidyCommand.py", line 84, in tidy_region
File ".\subprocess.py", line 701, in communicate
File ".\subprocess.py", line 911, in _communicate
UnicodeEncodeError: 'ascii' codec can't encode characters in position 158-160: ordinal not in range(128)

Mandated option causing conflicts

`   # Ensure, that perltidy always returns LF line endings, so we match the
    # internal buffer line endings.
    cmd_final.append('-ole=unix')
`

This ole option can conflict with other options (eg ple). Also this option is not overridden by other internal options.

As I am a solely Linux user I do not have to worry about this option.

Unfortunately I am not much of a python hack so I cannot send you a PR.

Cheers

Stuart

Installation through cpanm on OS X El Capitan

I have installed perltidy via cpanm on an OS X system with El Capitan.

The location of the perltidy utility is /usr/local/bin/perltidy on my system. Default is documented as looking for "perltidy_cmd": "/opt/perl/bin/perltidy"

I'm not sure if this has anything to do with El Capitan or System Integrity (aka "rootless").

perltidy does not obey options

Opened from comment by squ1sh in pull #9

Hello, thanks for the work you put into making this! I'm having a problem I couldn't find in my searches with this module. For some reason when perltidy is executed, all arguments are completely ignored. I have been trying to do a simple "-l=120" and it won't take. The command from your module appears to be doing the right thing though which confuses me! I'm actually unsure if it's a bug in this module or it's some wacky setting I have stored on my local machine.

I see the following in the ST console, but I'm still getting the 80 line default.

run
None
None
[u'/usr/local/bin/perltidy', '-l=120', '-sbdl', '-bbt=1', '-pt=2', '-nbbc', '-ole=unix', '-w', '-se']

I'm able to get perltidy to obey arguments when I do

/usr/local/bin/perltidy -b someprogram.pl -l=120

Any help would be massively appreciated!

PerlTidy fails to run and generates an exception

I am using Sublime Text 2 with Mac OS X 10.6.8. When trying to run PerlTidy nothing happens but an exception is generated when I view the Sublime console. Perl::Tidy and perltidy (usr/local/bin) are installed and work. Not sure what to look for to resolve this issue.

My system info as well as the exception that I receive are provided below.

Thank!
Scott


Date/time: 2013-12-13 03:02:12 +0000
Sublime Text version: 2221
Platform: osx
CPU architecture: x64
OS info: 'Darwin-10.8.0-i386-64bit'


Exception AttributeError: "'Popen' object has no attribute 'child_created'" in <bound method Popen.del of <subprocess.Popen object at 0x11c03bfd0>> ignored
Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run

File "./PerlTidyCommand.py", line 123, in run
File "./PerlTidyCommand.py", line 156, in tidy_region
File "./perltidy/helpers.py", line 326, in run_perltidy
TypeError: init() keywords must be strings

st2-perltidy and cygwin

I'm trying to use your plugin with Cygwin, and getting the following error -

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 362, in run_
  File ".\PerlTidyCommand.py", line 65, in run
  File ".\PerlTidyCommand.py", line 295, in tidy_region
  File ".\subprocess.py", line 701, in communicate
  File ".\subprocess.py", line 911, in _communicate
IOError: [Errno 32] Broken pipe
Writing file /C/Users/pjayasim/AppData/Roaming/Sublime Text 2/Packages/PerlTidy/PerlTidyCommand.py with encoding UTF-8
Reloading plugin C:\Users\pjayasim\AppData\Roaming\Sublime Text 2\Packages\PerlTidy\PerlTidyCommand.py

Following is the preferences -

..
"perltidy_cmd": [ "C:\\Jayasimha\\Program\\cygwin\\bin\\perl.exe", "perltidy" ],
"perltidy_options": [ "-sbl", "-bbt=1", "-pt=2", "-nbbc", "-l=100", "-ole=unix", "-w", "-se" ],
..

Not sure if I'm missing something here. Would great if you could help.

Unable to install with current documentation

Hi,

Currently your project does not appear underneath Sublime's standard Package Control "install" menu.

Additionally I git cloned and placed the path in the correct place, but you have no instructions as to how to proceed from this point on. My attempts to use the keybindings you define do not do anything at all with the packages present or not (I did restart the application to be sure).

Finally your documentation within the cloned files indicates I need to press the "super" button on my mac, which I have no idea what that is.

There is a big need for this to work, it is surprising to me that it doesn't exist for sublime yet as Textmate has had it for a long time.

thanks

Windows doesn't work

Problem with Windows:

run
C:/strawberry/perl/site/bin/perltidy
C:/strawberry/perl/site/bin/perltidy
Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\PerlTidyCommand.py", line 31, in run
File ".\PerlTidyCommand.py", line 87, in tidy_region
AttributeError: 'Window' object has no attribute 'newFile'

Double newlines in output, when running under Windows

This bug has been reported by email.

If i format my perl source file (.pl/.pm) using SublimePerlTidy in Sublime2, the source looks pretty nice. But if i reopen the file using Sublime (or another editor), there are empty rows in it, e.g.:

Unformatted:

$VAR1 = {
Test =>
'Test2',
Test3=>
{ 'Test4' => 'Test5' },
 };

Formatted using SublimePerlTidy (Strg+Shift+t):

$VAR1 = {
    Test  => 'Test2',
    Test3 => { 'Test4' => 'Test5' },
};

Reopen the file:

$VAR1 = {

    Test  => 'Test2',

    Test3 => { 'Test4' => 'Test5' },

};

If i let perltidy progress the file using cmd-command:

"C:\Perl64\bin\perl.exe" "C:\Perl64\site\bin\perltidy" input_file.pl > output_file.pl

the output_file.pl is like i expect it. Some additional infos:

Windows 7
SublimePerlTidy 0.4
This is perl 5, version 16, subversion 1 (v5.16.1) (Binary build 1601 [296175] provided by ActiveState http://www.ActiveState.com)
Perl::Tidy is up to date (20121207).

PerlTidy: Checking for perltidy (user): "C:\Perl64\bin\perl.exe" "C:\Perl64\site\bin\perltidy"
PerlTidy: Using perltidy: "C:\Perl64\bin\perl.exe" "C:\Perl64\site\bin\perltidy"
PerlTidy: No perltidyrc found in project.
PerlTidy: Running command: "C:\Perl64\bin\perl.exe" "C:\Perl64\site\bin\perltidy" "-pbp" "-l=120"
PerlTidy: Command exited with code: 0

Date/time: 2013-06-20 08:27:04 +0000
Sublime Text version: 2217
Platform: windows
CPU architecture: x64
OS info: 'Windows-post2008Server-6.1.7601-SP1'

OSX is not using additional params when Shell=True

Not sure why, but my python on OSX Snow Leopard is ignoring the additional exe params when Shell=True

My patch:

diff --git a/PerlTidyCommand.py b/PerlTidyCommand.py
index 9bf6f30..9b94a15 100755
--- a/PerlTidyCommand.py
+++ b/PerlTidyCommand.py
@@ -20,9 +20,18 @@ import os.path
class PerlTidyCommand(sublime_plugin.TextCommand):
_perltidy_rc = ['.perltidyrc', 'perltidyrc']
_perltidy_cmd = None

  •   _perltidy_params = [
    
  •           "-i=2",         # 2 col indent
    
  •           "-bbt=1",   # add only some spaces in single-line curly braces
    
  •           "-pt=1",    # dont add spaces inside parenthesis
    
  •           "-nbbc",    # don't add blank lines before comments
    
  •           "-l=120",   # wrap at column 100
    
  •           "-ole=unix" # unix line endings
    
  •   ]
    
    def run(self, edit):
    
  •           print "run"
    
  •   #       print "run"
            if not os.path.isfile(self.get_perltidy_cmd()):
                    sublime.error_message("Perltidy Error: Command not found:" + self.get_perltidy_cmd());
                    return
    

    @@ -37,7 +46,7 @@ class PerlTidyCommand(sublime_plugin.TextCommand):
    self.tidy_region(edit,sublime.Region(0L, self.view.size()))

    def get_perltidy_cmd(self):
    
  •           print self.view.settings().get('perltidy_cmd')
    
  •   #       print self.view.settings().get('perltidy_cmd')
            if self._perltidy_cmd is None:
                    self._perltidy_cmd = self.view.settings().get('perltidy_cmd')
                    if self._perltidy_cmd is None:
    

    @@ -57,10 +66,10 @@ class PerlTidyCommand(sublime_plugin.TextCommand):
    # default command
    cmd = [
    self.get_perltidy_cmd(),

  •                   "-sbdl","-bbt=1","-pt=2", "-nbbc", "-l=100","-ole=unix",
                    "-w",
                    "-se"
            ]
    
  •           cmd += self._perltidy_params
    
            # try to find a perltidy rc file
            for folder in self.view.window().folders():
    

    @@ -72,7 +81,7 @@ class PerlTidyCommand(sublime_plugin.TextCommand):

            p = subprocess.Popen(
                    cmd,
    
  •                   shell   = True,
    
  •                   shell   = False, # On OSX True is ignoring additional params in cmd?
                    bufsize = -1,
                    stdout  = subprocess.PIPE,
                    stderr  = subprocess.PIPE,
    

Unexpected at this time?

Hi

I'm using Windows 7 and Submline Text 2.

I'm trying too set my own perltidy preferences in the user settings. I've successfully changed some options e.g."-ce", however the following option gives the error: < was unexpected at this time.

"perltidy_options": [

"-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=""
]

Many Thanks,

Ed

Can't locate Perl/Tidy.pm installed with cpanm in a local library (not default)

I'm getting this error on running PerlTidy in SublimeText2:

PerlTidy: Errors reported by perltidy during last run

Can't locate Perl/Tidy.pm in @inc (you may need to install the Perl::Tidy module) (@inc contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at /home/mihai/perl5/bin/perltidy line 7.
BEGIN failed--compilation aborted at /home/mihai/perl5/bin/perltidy line 7.

My Environment is set to use the system perl executable /usr/bin/perl, but i have all the modules ( including Perl::Tidy ) installed in ~/perl5/lib/perl5 . My shell environment variables point to that location with the PERL5LIB env var. However it seems that the SublimePerlTidy does not see it in the @inc path.

conflict using .perltidyrc and -pbp

Hi,

some minor issue, I stumbled upon the other day:

I only use .perltidyrc for my perltidy options, so I use this sublime text preferences:

{
    "perltidy_cmd": [ "/usr/local/bin/perltidy" ],
    "perltidy_options_take_precedence": false,
    "perltidy_rc_paths": [ "/home/myuser/.perltidyrc" ],
}

which results in the following perltidy call:

PerlTidy: Running command: "/usr/local/bin/perltidy" "-pbp" "-pro=/home/myuser/.perltidyrc" "-ole=unix"

But, since perltidy first reads the custom config file from -pro and then applies the -pbp paramter, all my options from my config file will be overwritten with -pbp.

I workaround this by clearing out perltidy_options with

{
    "perltidy_options": []
}

but maybe you could do this automatically, if perltidy_options_take_precedence is set to false?

Or at least, address this issue in the documentation.

Thank you and best regards,
whuut

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcb in position 39: invalid continuation byte

OS X 10.10.3
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
I have removed my .perltidyrc and am just using the settings.
Is this a Sublime or Plugin issue?

Writing file /Users/rgranger/Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings with encoding UTF-8 (atomic)
reloading Packages/User/Preferences.sublime-settings
found 1 files for base name Default.sublime-theme
theme loaded
PerlTidy: Checking for perltidy (user): "/usr/local/bin/perltidy"
PerlTidy: Using perltidy: "/usr/local/bin/perltidy"
PerlTidy: No perltidyrc found in project.
PerlTidy: Running command: "/usr/local/bin/perltidy" "-l=130" "-i=4" "-ci=4" "-bli" "-bbvt=1" "-lp" "-vt=2" "-cti=1" "-pt=1" "-bt=1" "-sbt=1" "-bbt=1" "-nsfs" "-nolq" "-st" "-se" "-ole=unix" "-nst" "/var/folders/bf/y_jb_ht53z33kv3736l1rh840000gp/T/tmpaghsw7" "-o=/var/folders/bf/y_jb_ht53z33kv3736l1rh840000gp/T/tmpg2w0fa"
PerlTidy: Command exited with code: 0
Traceback (most recent call last):
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
return self.run(edit)
File "PerlTidyCommand in /Users/rgranger/Library/Application Support/Sublime Text 3/Installed Packages/PerlTidy.sublime-package", line 123, in run
File "PerlTidyCommand in /Users/rgranger/Library/Application Support/Sublime Text 3/Installed Packages/PerlTidy.sublime-package", line 156, in tidy_region
File "perltidy.helpers in /Users/rgranger/Library/Application Support/Sublime Text 3/Installed Packages/PerlTidy.sublime-package", line 358, in run_perltidy
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcb in position 39: invalid continuation byte

Running PerlTidy with custom PerlTidy cmd locks up sublime text 2 & 3


Date/time: 2018-05-10 06:25:07 +0000
Sublime Text version: 3170
Platform: osx
CPU architecture: x64
OS info: 'Darwin-16.7.0-x86_64-i386-64bit'

This has been happening for a while (last 8 months or so) started with ST 2, so I upgrade to ST 3. No dice. I enabled logging level 2 without much luck.

If I restart sometimes it magically starts working. However, once it begins to crash ST3, I can't get it to stop until I reboot one or more times. It almost seems like its running the command without passing the filename as an argument. Any help in testing this theory would be welcome.

I tried changing my perltidy path to /bin/echo just to see what command it was running. Below is that output. I have to use an older version of perltidy unfortunately.

PerlTidy: Checking for perltidy (user): "/bin/echo"
PerlTidy: Using perltidy: "/bin/echo"
PerlTidy: Checking for perltidyrc: "/Users/jaime/Projects/Tally/trunk/.perltidyrc"
PerlTidy: File not found: "/Users/jaime/Projects/Tally/trunk/.perltidyrc"
PerlTidy: Checking for perltidyrc: "/Users/jaime/Projects/Tally/trunk/perltidyrc"
PerlTidy: File not found: "/Users/jaime/Projects/Tally/trunk/perltidyrc"
PerlTidy: No perltidyrc found in project.
PerlTidy: Running command: "/bin/echo" "-b" "-ole=unix"
PerlTidy: Command exited with code: 0

Running perltidy manually works fine btw.
my perltidy path: /Users/jaime/perl5/perlbrew/perls/perl-5.16.0/bin/Perltidy
so running /Users/jaime/perl5/perlbrew/perls/perl-5.16.0/bin/Perltidy -b /path/to/my/perl.pl runs fine. Any help is greatly appreciated.

Insert extra <CR> if contains unicode characters

If a file contains unicode characters, PerlTidy will work weirdly:

But the log seems alright:

PerlTidy: Checking for perltidy (user): "D:\Strawberry\perl\bin\perl.exe" "D:\Strawberry\perl\bin\perltidy"
PerlTidy: Using perltidy: "D:\Strawberry\perl\bin\perl.exe" "D:\Strawberry\perl\bin\perltidy"
PerlTidy: Checking for perltidyrc: "D:\MSYS2\home\Michael\summer_learning\learning-perl\.perltidyrc"
PerlTidy: File not found: "D:\MSYS2\home\Michael\summer_learning\learning-perl\.perltidyrc"
PerlTidy: Checking for perltidyrc: "D:\MSYS2\home\Michael\summer_learning\learning-perl\perltidyrc"
PerlTidy: File not found: "D:\MSYS2\home\Michael\summer_learning\learning-perl\perltidyrc"
PerlTidy: No perltidyrc found in project.
PerlTidy: Running command: "D:\Strawberry\perl\bin\perl.exe" "D:\Strawberry\perl\bin\perltidy" "-l=78" "-i=4" "-ci=4" "-vt=2" "-cti=1" "-pt=2" "-bt=1" "-sbt=1" "-bbt=1" "-bar" "-nsfs" "-nolq" "-wbb="% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x="" "-st" "-tqw" "-se" "-ce" "-ole=unix" "-nst" "c:\users\michael\appdata\local\temp\tmp47ines" "-o=c:\users\michael\appdata\local\temp\tmp6bzzyo"
PerlTidy: Command exited with code: 0

Other Info

  • OS Version: 10.0.14393 N/A Build 14393
  • Sublime Text: 3126
  • Perl: Strawberry Perl 5.26

Sublime-Settings:

{
    "perltidy_cmd":
    [
        "D:\\Strawberry\\perl\\bin\\perl.exe",
        "D:\\Strawberry\\perl\\bin\\perltidy"
    ],
    "perltidy_log_level": 2,
    "perltidy_options":
    [
        "-l=78",
        "-i=4",
        "-ci=4",
        "-vt=2",
        "-cti=1",
        "-pt=2",
        "-bt=1",
        "-sbt=1",
        "-bbt=1",
        "-bar",
        "-nsfs",
        "-nolq",
        "-wbb=\"% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=\"",
        "-st",
        "-tqw",
        "-se",
        "-ce"
    ],
    "default_encoding": "utf-8",
    "default_line_ending": "unix"
}

Using the wrong .perltidyrc file

It appears that Sublime uses ~/.perltidyrc regardless of what is in the project version of .perltidyrc. Even though the debug reports using project config.

PerlTidy: Checking for perltidy (user): "/Users/moltar/bin/perltidy"
PerlTidy: Using perltidy: "/Users/moltar/bin/perltidy"
PerlTidy: Checking for perltidyrc: "/Volumes/Secondary/Users/moltar/Development/numericable/Project/.perltidyrc"
PerlTidy: Using perltidyrc: "/Volumes/Secondary/Users/moltar/Development/numericable/Project/.perltidyrc"
PerlTidy: Running command: "/Users/moltar/bin/perltidy" "-pro=/Volumes/Secondary/Users/moltar/Development/numericable/Project/.perltidyrc" "-ole=unix"
PerlTidy: Command exited with code: 0

So as you can see from the debug output, it claims to use the project .perltidyrc file. However, the actual code is formatted with ~/.perltidyrc file. If I run the same command as in debug via CLI, I get correct output tho.

Also, if I hide ~/.perltidyrc file, I get correct output also.

Very strange.

Support for Unicode literals

Hi,

one line of a Perl module I'm writing looks like this:

$row->{tipo_doc_id_fmt} = '<não definido>' unless $row->{tipo_doc_id_fmt};

The file has use utf8 (not that perltidy cares about this) and the file is saved as UTF-8 text.

When I try to tidy that line I get this traceback on the console:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./PerlTidyCommand.py", line 31, in run
  File "./PerlTidyCommand.py", line 83, in tidy_region
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 691, in communicate
    return self._communicate(input)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1222, in _communicate
    bytes_written = os.write(self.stdin.fileno(), chunk)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 35: ordinal not in range(128)

It seems that having Unicode literals on my source code is not supported...

Package Control

Will you be updating this plugin so it shows in package control?

OS X problem

From the Console:

run
None
None
Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./PerlTidyCommand.py", line 31, in run
File "./PerlTidyCommand.py", line 87, in tidy_region
AttributeError: 'Window' object has no attribute 'newFile'

Thanks again.

perltidy_rc_paths setting not being read

Creating the following type of setting in Preferences.sublime-settings does not appear to be read by SublimePerlTidy (SublimeText 3 on Mac OS X 10.8.4).

"perltidy_rc_paths": [
    "/Users/jdoe/.perltidyrc",
    ".perltidyrc",
    "perltidyrc"
],

As a reference point, the "perltidy_cmd" setting works.

Default -pbp

Not sure if this is a bug or something wrong on my settings, but by default the following config is true:

"perltidy_options": [ "-pbp" ]

But even when a .perltidyrc file is available, the command is run as such:

perltidy -pbp -pro=/path/to/.perltidyrc

In my case, -pbp flag seems to have a preference, and none of the config options from the .perltidyrc file are picked up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.