From 1b7c9ecc8f55675207d0b38ea4007de3aede9941 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 8 Jul 2023 15:10:23 -0400 Subject: [PATCH] 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. --- lisp/emacs-lisp/pp.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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)) -- 2.39.2