Beautify Perl code?


#1

Does anyone know if there is a way to JS beautify (or similar) code written in Perl with the ACE editor in C9? I know I’m in a minority with Perl (check out Mojolicious!) but it would be great to solve this.

thanks


#2

Hi,

Perl’s tidy has long preceeded any of the other tools, so, YES :slight_smile:


#3

Thanks for the pointer. I got perltidy to work OK with Vim from the command line but when I try and use it within ACE I get “vim command :%!perltidy not implemented”. Ideally I want to be able to press Ctrl + Shift + B to get the same result as with javascript - I guess this is just adding a keybinding once the command works?

thanks


#4

I know this is an old question but I wanted to share my solution.
This does not map to ctrl+shift+b but to F7, remap it how you like.
In your init script add:

var tabs = services.tabManager
services.commands.addCommand({
    name: "perltidy",
    bindKey: {win: "F7", mac: "F7"},
    isAvailable: function() {
         var editor = tabs.focussedTab && tabs.focussedTab.editor;
         return editor && editor.type == "ace" && editor.ace.session.syntax == "perl"
    },
   exec: function(e) {
         var tab = tabs.focussedTab;
         var path = tab.path;
         services.vfs.execFile("perltidy", { args: ["-b", "-bext='/'", '.' + path]}, function(err, stdout) {
            tabs.reload(tab, function() {});
         })
   }
})

#5

@Toon_Van_Dooren recently we have added a simpler method

add

          "@formatOnSave": false,
          "@formatter": "perltidy -b \"$file\""
    },

to project settings and you can the default format command ( ctrl-shift-b ) to format perl too.