diff --git a/reindent-perl.el b/reindent-perl.el new file mode 100644 index 0000000..17ff125 --- /dev/null +++ b/reindent-perl.el @@ -0,0 +1,45 @@ +;; Import with-demoted-errors from Emacs 24.5.1 (present in 23.1+). +(when (not (fboundp 'macroexp-progn)) + (defun macroexp-progn (exps) + "Return an expression equivalent to `(progn ,@EXPS)." + (if (cdr exps) `(progn ,@exps) (car exps)))) + +(when (not (fboundp 'with-demoted-errors)) + (defmacro with-demoted-errors (format &rest body) + "Run BODY and demote any errors to simple messages. +FORMAT is a string passed to `message' to format any error message. +It should contain a single %-sequence; e.g., \"Error: %S\". + +If `debug-on-error' is non-nil, run BODY without catching its errors. +This is to be used around code which is not expected to signal an error +but which should be robust in the unexpected case that an error is signaled. + +For backward compatibility, if FORMAT is not a constant string, it +is assumed to be part of BODY, in which case the message format +used is \"Error: %S\"." + (let ((err (make-symbol "err")) + (format (if (and (stringp format) body) format + (prog1 "Error: %S" + (if format (push format body)))))) + `(condition-case ,err + ,(macroexp-progn body) + (error (message ,format ,err) nil))))) + + +(load (expand-file-name "./src/tools/editors/emacs.samples")) +(setq enable-local-variables :all) ; not actually needed, given emacs.samples + +(while (setq fname (read-from-minibuffer "File name: ")) + (set-buffer "*scratch*") + (find-file fname) + (message "%s" + (list + (current-buffer) + perl-indent-level + tab-width + (if (boundp 'perl-indent-continued-arguments) + perl-indent-continued-arguments "no-such-var") + (if (boundp 'perl-indent-parens-as-block) + perl-indent-parens-as-block "no-such-var"))) + (with-demoted-errors (indent-region (point-min) (point-max) nil)) + (save-buffer)) diff --git a/reindent-perl.sh b/reindent-perl.sh new file mode 100644 index 0000000..ae34646 --- /dev/null +++ b/reindent-perl.sh @@ -0,0 +1,10 @@ +# Reindent Perl source using Emacs perl-mode. This tests how well perl-mode +# matches perltidy. + +if [ -n "$1" ]; then + for arg; do printf '%s\n' "$arg"; done # Try specific files. +else + . src/tools/perlcheck/find_perl_files + find_perl_files +fi | emacs -no-site-file -batch -load reindent-perl.el +git diff --shortstat