[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d3311499339: (pp): Indent lines right when starting in col > 0
From: |
Stefan Monnier |
Subject: |
master d3311499339: (pp): Indent lines right when starting in col > 0 |
Date: |
Mon, 26 Aug 2024 11:51:34 -0400 (EDT) |
branch: master
commit d3311499339fab0371cb7502a1e2481fbcd2c65d
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
(pp): Indent lines right when starting in col > 0
This refines the fix for bug#72561: commit 0a500193087e fixes
the bug by changing `ert--pp-with-indentation-and-newline`,
but it turns out that `pp` was inconsistent (it sometimes
indented the subsequent lines correctly and sometimes not,
depending on the current-buffer's major mode).
So the fix really should be in `pp`, which is what this patch does.
* lisp/emacs-lisp/pp.el (pp): Appropriately indent subsequent lines
if the first line is not inserted in column 0 (tho only when
printing into a buffer since otherwise it's somewhere between
ill-defined and impossible to implement).
* lisp/emacs-lisp/ert.el (ert--pp-with-indentation-and-newline):
Remove the indentation code after `pp` which was just working
around the bug in `pp`. Also remove the redundant addition of
`\n` since `pp` always does it nowadays.
* test/lisp/help-mode-tests.el (help-mode-tests-xref-on-pp):
Fix thinko.
---
lisp/emacs-lisp/ert.el | 8 ++------
lisp/emacs-lisp/pp.el | 29 ++++++++++++++++++-----------
test/lisp/help-mode-tests.el | 2 +-
3 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
index 105c44d49aa..fa1b7a60a90 100644
--- a/lisp/emacs-lisp/ert.el
+++ b/lisp/emacs-lisp/ert.el
@@ -1316,13 +1316,9 @@ empty string."
(defun ert--pp-with-indentation-and-newline (object)
"Pretty-print OBJECT, indenting it to the current column of point.
Ensures a final newline is inserted."
- (let ((begin (point))
- (cols (current-column))
- (pp-escape-newlines t)
+ (let ((pp-escape-newlines t)
(print-escape-control-characters t))
- (pp object (current-buffer))
- (unless (bolp) (insert "\n"))
- (indent-rigidly begin (point) cols)))
+ (pp object (current-buffer))))
(defun ert--insert-infos (result)
"Insert `ert-info' infos from RESULT into current buffer.
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index e550bd4d689..12346b3d285 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -308,17 +308,24 @@ can handle, whenever this is possible.
Uses the pretty-printing code specified in `pp-default-function'.
Output stream is STREAM, or value of `standard-output' (which see)."
- (cond
- ((and (eq (or stream standard-output) (current-buffer))
- ;; Make sure the current buffer is setup sanely.
- (eq (syntax-table) emacs-lisp-mode-syntax-table)
- (eq indent-line-function #'lisp-indent-line))
- ;; Skip the buffer->string->buffer middle man.
- (funcall pp-default-function object)
- ;; Preserve old behavior of (usually) finishing with a newline.
- (unless (bolp) (insert "\n")))
- (t
- (princ (pp-to-string object) (or stream standard-output)))))
+ (let ((stream (or stream standard-output)))
+ (cond
+ ((and (eq stream (current-buffer))
+ ;; Make sure the current buffer is setup sanely.
+ (eq (syntax-table) emacs-lisp-mode-syntax-table)
+ (eq indent-line-function #'lisp-indent-line))
+ ;; Skip the buffer->string->buffer middle man.
+ (funcall pp-default-function object)
+ ;; Preserve old behavior of (usually) finishing with a newline.
+ (unless (bolp) (insert "\n")))
+ (t
+ (save-current-buffer
+ (when (bufferp stream) (set-buffer stream))
+ (let ((begin (point))
+ (cols (current-column)))
+ (princ (pp-to-string object) (or stream standard-output))
+ (when (and (> cols 0) (bufferp stream))
+ (indent-rigidly begin (point) cols))))))))
;;;###autoload
(defun pp-display-expression (expression out-buffer-name &optional lisp)
diff --git a/test/lisp/help-mode-tests.el b/test/lisp/help-mode-tests.el
index 4c149ae7430..2e64b12732e 100644
--- a/test/lisp/help-mode-tests.el
+++ b/test/lisp/help-mode-tests.el
@@ -92,7 +92,7 @@ Lisp concepts such as car, cdr, cons cell and list.")
(ert-deftest help-mode-tests-xref-on-pp ()
(with-temp-buffer
- (insert (pp '(cons fill-column)))
+ (pp '(cons fill-column) (current-buffer))
(help-xref-on-pp (point-min) (point-max))
(goto-char (point-min))
(search-forward "co")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master d3311499339: (pp): Indent lines right when starting in col > 0,
Stefan Monnier <=