Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jplindstrom (594)

jplindstrom
  (email not shown publicly)

Journal of jplindstrom (594)

Friday January 04, 2008
01:18 PM

Source makeover

[ #35289 ]

Badly formatted source code is ugly. But, a few keyboard macros later and it's much nicer.

And this little defun helped a lot, maybe someone will find it as useful as I did.

(defun jpl-makeover-remove-pod-sub-whitespace ()
  "Clean up Perl source whitespace formatting"
  (interactive)
 
  (save-excursion
    ;; Remove =cut with more POD as the next thing
    (replace-regexp "=cut\n\n+=" "\n\n=" nil (point-min) (point-max))
 
    ;; Remove whitespace between POD and sub
    (replace-regexp "=cut\n+sub " "=cut\nsub " nil (point-min) (point-max))
 
    ;; 3 newlines before subs if no POD
    (replace-regexp "\n\n+sub " "\n\n\n\nsub " nil (point-min) (point-max))
 
    ;; 3 newlines before =head...
    (replace-regexp "\n\n+=head" "\n\n\n\n=head" nil (point-min) (point-max))
 
    ;; ...except at the top POD block where it's more compact
    (replace-regexp "\n\n+=head1 NAME" "\n=head1 NAME" nil (point-min) (point-max))
    (replace-regexp "\n\n+=head1 DESCRIPTION" "\n\n=head1 DESCRIPTION" nil (point-min) (point-max))
    (replace-regexp "\n\n+=head1 SYNOPSIS" "\n\n=head1 SYNOPSIS" nil (point-min) (point-max))
    )
 
  (font-lock-fontify-buffer)   ;; In case it got confused
  )

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.