Revert "Don't use ellipses while cl-printing strings."

This reverts commit 761f8901ff.
This commit is contained in:
Alan Mackenzie 2023-09-27 09:54:33 +00:00
parent a3a840c80a
commit 6956382033
2 changed files with 30 additions and 5 deletions

View file

@ -264,17 +264,27 @@ into a button whose action shows the function's disassembly.")
(cl-defmethod cl-print-object ((object string) stream)
(unless stream (setq stream standard-output))
(let* ((has-properties (or (text-properties-at 0 object)
(next-property-change 0 object))))
(next-property-change 0 object)))
(len (length object))
(limit (if (natnump print-length) (min print-length len) len)))
(if (and has-properties
cl-print--depth
(natnump print-level)
(> cl-print--depth print-level))
(cl-print-insert-ellipsis object nil stream)
;; Print the string.
;; Print all or part of the string
(when has-properties
(princ "#(" stream))
(prin1 (if has-properties (substring-no-properties object) object)
stream)
(if (= limit len)
(prin1 (if has-properties (substring-no-properties object) object)
stream)
(let ((part (concat (substring-no-properties object 0 limit) "...")))
(prin1 part stream)
(when (bufferp stream)
(with-current-buffer stream
(cl-print-propertize-ellipsis object limit
(- (point) 4)
(- (point) 1) stream)))))
;; Print the property list.
(when has-properties
(cl-print--string-props object 0 stream)

View file

@ -58,6 +58,21 @@
(cl-print-tests-check-ellipsis-expansion
[a [b [c [d [e]]]]] "[a [b [c ...]]]" "[d [e]]")))
(ert-deftest cl-print-tests-ellipsis-string ()
"Ellipsis expansion works in strings."
(let ((print-length 4)
(print-level 3))
(cl-print-tests-check-ellipsis-expansion
"abcdefg" "\"abcd...\"" "efg")
(cl-print-tests-check-ellipsis-expansion
"abcdefghijk" "\"abcd...\"" "efgh...")
(cl-print-tests-check-ellipsis-expansion
'(1 (2 (3 #("abcde" 0 5 (test t)))))
"(1 (2 (3 ...)))" "#(\"abcd...\" 0 5 (test t))")
(cl-print-tests-check-ellipsis-expansion
#("abcd" 0 1 (bold t) 1 2 (invisible t) 3 4 (italic t))
"#(\"abcd\" 0 1 (bold t) ...)" "1 2 (invisible t) ...")))
(ert-deftest cl-print-tests-ellipsis-struct ()
"Ellipsis expansion works in structures."
(let ((print-length 4)
@ -129,7 +144,7 @@
;; Print something which needs to be abbreviated and which can be.
(should (< (length (cl-print-to-string-with-limit #'cl-prin1 thing100 100))
150 ;; 100. The LIMIT argument is advisory rather than absolute.
100
(length (cl-prin1-to-string thing100))))
;; Print something resistant to easy abbreviation.