summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2017-03-18 21:24:39 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2017-03-18 21:24:39 -0400
commit32bb5a945a47b14fa85dc1c2f1776b6baa3b0dcc (patch)
tree477818c6388435bcabbf968d2b2851f06b728ae1 /lisp/emacs-lisp
parente0eb1af55f7b6d0b41e6f0180438f8317628894b (diff)
downloademacs-32bb5a945a47b14fa85dc1c2f1776b6baa3b0dcc.tar.gz
emacs-32bb5a945a47b14fa85dc1c2f1776b6baa3b0dcc.tar.bz2
emacs-32bb5a945a47b14fa85dc1c2f1776b6baa3b0dcc.zip
Improve describe-symbol's layout of slots when describing types
* lisp/emacs-lisp/cl-extra.el (cl--print-table): New function. (cl--describe-class-slots): Use it.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/cl-extra.el51
1 files changed, 50 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index 8cba9137105..8b3d6eecf5c 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -865,6 +865,40 @@ including `cl-block' and `cl-eval-when'."
"\n")))
"\n"))
+(defun cl--print-table (header rows)
+ ;; FIXME: Isn't this functionality already implemented elsewhere?
+ (let ((cols (apply #'vector (mapcar #'string-width header)))
+ (col-space 2))
+ (dolist (row rows)
+ (dotimes (i (length cols))
+ (let* ((x (pop row))
+ (curwidth (aref cols i))
+ (newwidth (if x (string-width x) 0)))
+ (if (> newwidth curwidth)
+ (setf (aref cols i) newwidth)))))
+ (let ((formats '())
+ (tmp-head header)
+ (col 0))
+ (dotimes (i (length cols))
+ (let ((head (pop tmp-head)))
+ (push (concat (propertize " "
+ 'display
+ `(space :align-to ,(+ col col-space)))
+ "%s")
+ formats)
+ (cl-incf col (+ col-space (aref cols i)))))
+ (let ((format (mapconcat #'identity (nreverse formats) "")))
+ (insert (apply #'format format
+ (mapcar (lambda (str) (propertize str 'face 'italic))
+ header))
+ "\n")
+ (insert (apply #'format format
+ (mapcar (lambda (str) (make-string (string-width str) ?—))
+ header))
+ "\n")
+ (dolist (row rows)
+ (insert (apply #'format format row) "\n"))))))
+
(defun cl--describe-class-slots (class)
"Print help description for the slots in CLASS.
Outputs to the current buffer."
@@ -877,7 +911,22 @@ Outputs to the current buffer."
(cl-struct-unknown-slot nil))))
(insert (propertize "Instance Allocated Slots:\n\n"
'face 'bold))
- (mapc #'cl--describe-class-slot slots)
+ (let* ((has-doc nil)
+ (slots-strings
+ (mapcar
+ (lambda (slot)
+ (list (cl-prin1-to-string (cl--slot-descriptor-name slot))
+ (cl-prin1-to-string (cl--slot-descriptor-type slot))
+ (cl-prin1-to-string (cl--slot-descriptor-initform slot))
+ (let ((doc (alist-get :documentation
+ (cl--slot-descriptor-props slot))))
+ (if (not doc) ""
+ (setq has-doc t)
+ (substitute-command-keys doc)))))
+ slots)))
+ (cl--print-table `("Name" "Type" "Default" . ,(if has-doc '("Doc")))
+ slots-strings))
+ (insert "\n")
(when (> (length cslots) 0)
(insert (propertize "\nClass Allocated Slots:\n\n" 'face 'bold))
(mapc #'cl--describe-class-slot cslots))))