From Request Tracker Wiki
Jump to navigation Jump to search

PerlTidy is an tool open-source which, as the name implies, tidies perl code in a specific and highly configurable fashion. Here are BestPractical's preferred settings:

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

If you put that into ~/.perltidyrc you're all set.

It's rumored that any patch submitted which is the result of running that against a particular file will automatically be approved.

Emacs users can add the elisp code found on the CPerl Mode Page EmacsWiki's and call this from within the editor on regions and functions. The pertinent text is included below for convenience, but /you should really check the Emacs Wiki to be sure there isn't fresher, tastier stuff available/

Is there a way to get it to work consistently with

Yes, a way (but not a single way to do it) from the perltidy documentation itself :

“For the emacs editor, first mark a region and then pipe it through perltidy. For example, to format an entire file, select it with C-x h and then pipe it with M-1 M-| and then perltidy. The numeric argument, M-1 causes the output from perltidy to replace the marked text. See ``GNU Emacs Manual for more information,

If you have difficulty with an editor, try the -st flag, which will force perltidy to send output to standard output. This might be needed, for example, if the editor passes text to perltidy as temporary filename instead of through the standard input. If this works, you might put the -st flag in your .perltidyrc file.”

These functions can be used to get quick access to perltidy:

(defun perltidy-region ()
  "Run perltidy on the current region."
    (shell-command-on-region (point) (mark) "perltidy -q" nil t)))
(defun perltidy-defun ()
  "Run perltidy on the current defun."
  (save-excursion (mark-defun)