From: Stefan Monnier Date: Sat, 8 Jul 2023 19:10:23 +0000 (-0400) Subject: pp-fill: Fix missing indentation in some cases X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1b7c9ecc8f55675207d0b38ea4007de3aede9941;p=emacs.git pp-fill: Fix missing indentation in some cases * lisp/emacs-lisp/pp.el (pp-fill): Improve handling of char-tables. (pp-buffer): Improve backward compatibility. --- diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el index 625fc5f252d..550fab2f4b3 100644 --- a/lisp/emacs-lisp/pp.el +++ b/lisp/emacs-lisp/pp.el @@ -177,8 +177,9 @@ it inserts and pretty-prints that arg at point." (< (point) end)) (let ((beg (point)) ;; Whether we're in front of an element with paired delimiters. - ;; Can be something funky like #'(lambda ..) or ,'#s(...). - (paired (when (looking-at "['`,#]*[[:alpha:]]*\\([({[\"]\\)") + ;; Can be something funky like #'(lambda ..) or ,'#s(...) + ;; Or also #^[..]. + (paired (when (looking-at "['`,#]*[[:alpha:]^]*\\([({[\"]\\)") (match-beginning 1)))) ;; Go to the end of the sexp. (goto-char (or (scan-sexps (or paired (point)) 1) end)) @@ -238,7 +239,15 @@ it inserts and pretty-prints that arg at point." (defun pp-buffer () "Prettify the current buffer with printed representation of a Lisp object." (interactive) - (funcall pp-default-function (point-min) (point-max)) + ;; The old code used `indent-sexp' which mostly works "anywhere", + ;; so let's make sure we also work right in buffers that aren't + ;; setup specifically for Lisp. + (if (and (eq (syntax-table) emacs-lisp-mode-syntax-table) + (eq indent-line-function #'lisp-indent-line)) + (funcall pp-default-function (point-min) (point-max)) + (with-syntax-table emacs-lisp-mode-syntax-table + (let ((indent-line-function #'lisp-indent-line)) + (funcall pp-default-function (point-min) (point-max))))) ;; Preserve old behavior of (usually) finishing with a newline and ;; with point at BOB. (goto-char (point-max))