Source makeover

jplindstrom on 2008-01-04T18:18:29

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 )