Xah Talk Show 2025-07-08 Ep676 Perl Find Replace, Format Perl Code, and in Emacs

xah talk show ep676 1c364
xah talk show ep676 1c364
(defun xah-perl-format-buffer ()
  "Reformat current file by calling perltidy.
Buffer is saved first.

Created: 2025-07-08
Version: 2025-07-08"
  (interactive)
  (when (not (buffer-file-name)) (user-error "buffer %s is not a file." (buffer-name)))
  (when (buffer-modified-p) (save-buffer))
  (let ((xoutbuf (get-buffer-create "*xah-perl-format output*")))
    (with-current-buffer xoutbuf (erase-buffer))
    (call-process "perltidy" nil xoutbuf nil "-b" buffer-file-name)
    (revert-buffer t t t)))