diff options
| author | Jonas Bernoulli | 2012-12-11 21:16:05 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2012-12-11 21:16:05 -0500 |
| commit | 69e1c203e96afb6e95fdda422d00c07b0bcbf76c (patch) | |
| tree | 9d7d049ca43d5291ddf379d9ce00d973c1c2ad73 | |
| parent | 030f4af55bc3ce886c3dab85cd3d4a988dcb93f6 (diff) | |
| download | emacs-69e1c203e96afb6e95fdda422d00c07b0bcbf76c.tar.gz emacs-69e1c203e96afb6e95fdda422d00c07b0bcbf76c.zip | |
* lisp/emacs-lisp/eieio.el: Prettier object pretty-printing.
(eieio-override-prin1): Don't quote kewords and booleans.
(object-write) <eieio-default-superclass>: Don't put closing parens
on new line, avoid needless empty lines, align values that are objects
with the slot keyword (instead of beginning on the same line).
(eieio-list-prin1): Align value with slot keyword; increase
eieio-print-depth before printing members of the list.
Fixes: debbugs:13115
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/eieio.el | 42 |
2 files changed, 35 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d6d7b18955e..49e129cd77a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2012-12-12 Jonas Bernoulli <jonas@bernoul.li> | ||
| 2 | |||
| 3 | * lisp/emacs-lisp/eieio.el: Prettier object pretty-printing (bug#13115). | ||
| 4 | (eieio-override-prin1): Don't quote kewords and booleans. | ||
| 5 | (object-write) <eieio-default-superclass>: Don't put closing parens | ||
| 6 | on new line, avoid needless empty lines, align values that are objects | ||
| 7 | with the slot keyword (instead of beginning on the same line). | ||
| 8 | (eieio-list-prin1): Align value with slot keyword; increase | ||
| 9 | eieio-print-depth before printing members of the list. | ||
| 10 | |||
| 1 | 2012-12-11 Stefan Monnier <monnier@iro.umontreal.ca> | 11 | 2012-12-11 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 12 | ||
| 3 | * mail/emacsbug.el (report-emacs-bug): Move the intangible text to | 13 | * mail/emacsbug.el (report-emacs-bug): Move the intangible text to |
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index 3f7b49bde25..ebc35f6237c 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el | |||
| @@ -2850,28 +2850,36 @@ this object." | |||
| 2850 | (v (eieio-oref this (car publa))) | 2850 | (v (eieio-oref this (car publa))) |
| 2851 | ) | 2851 | ) |
| 2852 | (unless (or (not i) (equal v (car publd))) | 2852 | (unless (or (not i) (equal v (car publd))) |
| 2853 | (unless (bolp) | ||
| 2854 | (princ "\n")) | ||
| 2853 | (princ (make-string (* eieio-print-depth 2) ? )) | 2855 | (princ (make-string (* eieio-print-depth 2) ? )) |
| 2854 | (princ (symbol-name i)) | 2856 | (princ (symbol-name i)) |
| 2855 | (princ " ") | ||
| 2856 | (if (car publp) | 2857 | (if (car publp) |
| 2857 | ;; Use our public printer | 2858 | ;; Use our public printer |
| 2858 | (funcall (car publp) v) | 2859 | (progn |
| 2860 | (princ " ") | ||
| 2861 | (funcall (car publp) v)) | ||
| 2859 | ;; Use our generic override prin1 function. | 2862 | ;; Use our generic override prin1 function. |
| 2860 | (eieio-override-prin1 v)) | 2863 | (princ (if (or (eieio-object-p v) |
| 2861 | (princ "\n")))) | 2864 | (eieio-object-p (car-safe v))) |
| 2865 | "\n" " ")) | ||
| 2866 | (eieio-override-prin1 v))))) | ||
| 2862 | (setq publa (cdr publa) publd (cdr publd) | 2867 | (setq publa (cdr publa) publd (cdr publd) |
| 2863 | publp (cdr publp))) | 2868 | publp (cdr publp)))) |
| 2864 | (princ (make-string (* eieio-print-depth 2) ? ))) | 2869 | (princ ")") |
| 2865 | (princ ")\n"))) | 2870 | (when (= eieio-print-depth 0) |
| 2871 | (princ "\n")))) | ||
| 2866 | 2872 | ||
| 2867 | (defun eieio-override-prin1 (thing) | 2873 | (defun eieio-override-prin1 (thing) |
| 2868 | "Perform a `prin1' on THING taking advantage of object knowledge." | 2874 | "Perform a `prin1' on THING taking advantage of object knowledge." |
| 2869 | (cond ((eieio-object-p thing) | 2875 | (cond ((eieio-object-p thing) |
| 2870 | (object-write thing)) | 2876 | (object-write thing)) |
| 2871 | ((listp thing) | 2877 | ((consp thing) |
| 2872 | (eieio-list-prin1 thing)) | 2878 | (eieio-list-prin1 thing)) |
| 2873 | ((class-p thing) | 2879 | ((class-p thing) |
| 2874 | (princ (class-name thing))) | 2880 | (princ (class-name thing))) |
| 2881 | ((or (keywordp thing) (booleanp thing)) | ||
| 2882 | (prin1 thing)) | ||
| 2875 | ((symbolp thing) | 2883 | ((symbolp thing) |
| 2876 | (princ (concat "'" (symbol-name thing)))) | 2884 | (princ (concat "'" (symbol-name thing)))) |
| 2877 | (t (prin1 thing)))) | 2885 | (t (prin1 thing)))) |
| @@ -2882,16 +2890,16 @@ this object." | |||
| 2882 | (progn | 2890 | (progn |
| 2883 | (princ "'") | 2891 | (princ "'") |
| 2884 | (prin1 list)) | 2892 | (prin1 list)) |
| 2885 | (princ "(list ") | ||
| 2886 | (if (eieio-object-p (car list)) (princ "\n ")) | ||
| 2887 | (while list | ||
| 2888 | (if (eieio-object-p (car list)) | ||
| 2889 | (object-write (car list)) | ||
| 2890 | (princ "'") | ||
| 2891 | (prin1 (car list))) | ||
| 2892 | (princ " ") | ||
| 2893 | (setq list (cdr list))) | ||
| 2894 | (princ (make-string (* eieio-print-depth 2) ? )) | 2893 | (princ (make-string (* eieio-print-depth 2) ? )) |
| 2894 | (princ "(list") | ||
| 2895 | (let ((eieio-print-depth (1+ eieio-print-depth))) | ||
| 2896 | (while list | ||
| 2897 | (princ "\n") | ||
| 2898 | (if (eieio-object-p (car list)) | ||
| 2899 | (object-write (car list)) | ||
| 2900 | (princ (make-string (* eieio-print-depth 2) ? )) | ||
| 2901 | (eieio-override-prin1 (car list))) | ||
| 2902 | (setq list (cdr list)))) | ||
| 2895 | (princ ")"))) | 2903 | (princ ")"))) |
| 2896 | 2904 | ||
| 2897 | 2905 | ||