Integrate Perltidy in UE

Integrate Perltidy in UE

1
NewbieNewbie
1

    Oct 25, 2006#1

    Hi,

    How is it possible to integrate Perltidy in the UE IDE, to use Perltidy directly out of the editor?

    Has anyone experience with Perltidy and Ultraedit?

    Ciao - Jens

    119
    Power UserPower User
    119

      Nov 01, 2006#2

      jens_g wrote:How is it possible to integrate Perltidy in the UE IDE, to use Perltidy directly out of the editor?
      You can create a user tool to run perltidy on the active file. See Advanced->Tool Configuration. Create a new tool with a command line of:

      Code: Select all

      perltidy "%f"
      You'll have to open up the resulting *.tdy file manually, although it's probably possible to create a macro to execute the tool and then open the file for you. Alternately, you could use perltidy's -b option but you'd have to be careful about overwriting your backup (and thus losing your original).

      I haven't had much luck getting PerlTidy to work on the selection, though. I think this is more of a UE problem as the selection is passed as an argument; there's no way to make it appear on STDIO. I've sent a feature request to IDM about this.

        Jun 27, 2007#3

        With the addition of scripting support in version 13 I was able to write a script to run perltidy on a selection. To use it, configure a tool named "perltidy file" with a command line of perltidy "%f" and a working directory of %P. Save the code below as perltidy.js. Add it to your list of scripts and configure your favorite hotkey. (I use Ctrl+Shift+T.)

        By itself, the user tool will run perltidy on the active file. Run through the script it will update only the current selection. If you need to undo the changes it's only a single step.

        Note: You may want to change the name/path of the temp file to something more appropriate for your system.

        Code: Select all

        /*
         * Run perltidy on the current selection
         */
        
        if (UltraEdit.activeDocument.isSel()) {
         var tidyin  = "C:\\Temp\\perltidy.txt";
         var tidyout = tidyin + '.tdy';
        
         // Hack! Thanks, jorrasdk
         // https://forums.ultraedit.com/viewtopic.php?f=52&t=4571
         var idx = getActiveDocumentIndex();
        
         // Switch to a clipboard that's probably not in use
         UltraEdit.selectClipboard(9);
        
         // Save selection to temporary file
         UltraEdit.activeDocument.copy();
         UltraEdit.newFile();
         UltraEdit.activeDocument.paste();
         UltraEdit.saveAs(tidyin);
        
         // Run perltidy on code from selection
         // Tool must exist and be configured to run 'perltidy "%f"'
         UltraEdit.runTool("perltidy file");
        
         // Close tempfile
         UltraEdit.closeFile(tidyin, 2);
        
         // Get perltidy output
         UltraEdit.open(tidyout);
         UltraEdit.activeDocument.selectAll();
         UltraEdit.activeDocument.copy();
         UltraEdit.closeFile(tidyout, 2);
        
         // Replace selection with output of perltidy
         UltraEdit.document[idx].paste(); // why doesn't activeDocument work here?
        
         // Restore the clipboard we were probably using before
         UltraEdit.selectClipboard(0);
        }
        
        /* Find the tab index of the active document */
        function getActiveDocumentIndex() {
         var tabindex = -1; /* start value */
        
         for (i = 0; i < UltraEdit.document.length; i++) {
         if (UltraEdit.activeDocument.path==UltraEdit.document[i].path) {
         tabindex = i;
         break;
         }
         }
         return tabindex;
        }