[slime-cvs] CVS slime

CVS User trittweiler trittweiler at common-lisp.net
Thu Feb 26 20:53:07 UTC 2009


Update of /project/slime/cvsroot/slime
In directory cl-net:/tmp/cvs-serv22004

Modified Files:
	swank.lisp ChangeLog 
Log Message:
	* swank.lisp (hash-table-to-alist): New function.
	([method] emacs-inspect (hash-table)): Sort keys if they're all
	numbers, symbols, or strings.

	Adapted from Willem Broekema.


--- /project/slime/cvsroot/slime/swank.lisp	2009/02/22 14:18:47	1.636
+++ /project/slime/cvsroot/slime/swank.lisp	2009/02/26 20:53:07	1.637
@@ -3476,6 +3476,12 @@
 ;;;;; Hashtables
 
 
+(defun hash-table-to-alist (ht)
+  (let ((result '()))
+    (maphash #'(lambda (key value)
+                 (setq result (acons key value result)))
+             ht)
+    result))
 
 (defmethod emacs-inspect ((ht hash-table))
   (append
@@ -3492,13 +3498,17 @@
      `((:action "[clear hashtable]" 
                 ,(lambda () (clrhash ht))) (:newline)
        "Contents: " (:newline)))
-   (loop for key being the hash-keys of ht
-         for value being the hash-values of ht
-         append `((:value ,key) " = " (:value ,value)
-                  " " (:action "[remove entry]"
-                               ,(let ((key key))
-                                     (lambda () (remhash key ht))))
-                  (:newline)))))
+   (let ((content (hash-table-to-alist ht)))
+     (cond ((every (lambda (x) (typep (first x) '(or string symbol))) content)
+            (setf content (sort content 'string< :key #'first)))
+           ((every (lambda (x) (typep (first x) 'number)) content)
+            (setf content (sort content '< :key #'first))))
+     (loop for (key . value) in content appending
+           `((:value ,key) " = " (:value ,value)
+             " " (:action "[remove entry]"
+                          ,(let ((key key))
+                                (lambda () (remhash key ht))))
+             (:newline))))))
 
 ;;;;; Arrays
 
--- /project/slime/cvsroot/slime/ChangeLog	2009/02/26 19:57:35	1.1691
+++ /project/slime/cvsroot/slime/ChangeLog	2009/02/26 20:53:07	1.1692
@@ -1,5 +1,13 @@
 2009-02-26  Tobias C. Rittweiler  <tcr at freebits.de>
 
+	* swank.lisp (hash-table-to-alist): New function.
+	([method] emacs-inspect (hash-table)): Sort keys if they're all
+	numbers, symbols, or strings.
+
+	Adapted from Willem Broekema.
+
+2009-02-26  Tobias C. Rittweiler  <tcr at freebits.de>
+
 	* swank-backend.lisp (warn-unimplemented-interfaces):
 	Bind *PRINT-PRETTY* to T. Otherwise no sugar formatting on CCL.
 





More information about the slime-cvs mailing list