mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 16:51:06 -07:00
(pp): Indent lines right when starting in col > 0
This refines the fix for bug#72561: commit 0a50019308 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.
This commit is contained in:
parent
da6e4a8625
commit
d331149933
3 changed files with 21 additions and 18 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue