[slime-cvs] CVS slime/contrib
CVS User sboukarev
sboukarev at common-lisp.net
Tue May 31 10:19:07 UTC 2011
Update of /project/slime/cvsroot/slime/contrib
In directory common-lisp.net:/tmp/cvs-serv26172
Modified Files:
ChangeLog slime-package-fu.el
Log Message:
* slime-package-fu.el (slime-export-symbol-representation-auto):
New variable. Default value is NIL.
Determine automatically which style is used for symbols, #: or :
If it's mixed or no symbols are exported so far,
use `slime-export-symbol-representation-function'.
--- /project/slime/cvsroot/slime/contrib/ChangeLog 2011/05/26 00:27:14 1.461
+++ /project/slime/cvsroot/slime/contrib/ChangeLog 2011/05/31 10:19:07 1.462
@@ -1,7 +1,15 @@
+2011-05-31 Stas Boukarev <stassats at gmail.com>
+
+ * slime-package-fu.el (slime-export-symbol-representation-auto):
+ New variable. Default value is NIL.
+ Determine automatically which style is used for symbols, #: or :
+ If it's mixed or no symbols are exported so far,
+ use `slime-export-symbol-representation-function'.
+
2011-05-26 Stas Boukarev <stassats at gmail.com>
* slime-package-fu.el (slime-add-export): Add :export to the end
- of a defpackage form when there's no :export present.
+ of a defpackage form when there's no :export present.
2011-05-21 Helmut Eller <heller at common-lisp.net>
--- /project/slime/cvsroot/slime/contrib/slime-package-fu.el 2011/05/26 00:27:14 1.13
+++ /project/slime/cvsroot/slime/contrib/slime-package-fu.el 2011/05/31 10:19:07 1.14
@@ -23,10 +23,14 @@
(defvar slime-export-symbol-representation-function
#'(lambda (n) (format "#:%s" n)))
+(defvar slime-export-symbol-representation-auto nil
+ "Determine automatically which style is used for symbols, #: or :
+If it's mixed or no symbols are exported so far,
+use `slime-export-symbol-representation-function'.")
+
(defvar slime-defpackage-regexp
"^(\\(cl:\\|common-lisp:\\)?defpackage\\>[ \t']*")
-
(defun slime-find-package-definition-rpc (package)
(slime-eval `(swank:find-definition-for-thing (swank::guess-package ,package))))
@@ -195,10 +199,39 @@
(insert "(:export ")
(save-excursion (insert ")"))))))
+(defun slime-export-symbols ()
+ "Return a list of symbols inside :export clause of a defpackage."
+ ;; Assumes we're at the beginning of :export
+ (save-excursion
+ (loop while (ignore-errors (forward-sexp) t)
+ collect (slime-symbol-at-point))))
+
+(defun slime-determine-symbol-style ()
+ ;; Assumes we're inside :export
+ (save-excursion
+ (slime-beginning-of-list)
+ (slime-forward-sexp)
+ (let ((symbols (slime-export-symbols)))
+ (cond ((every (lambda (x)
+ (string-match "^:" x))
+ symbols)
+ (lambda (n) (format ":%s" n)))
+ ((every (lambda (x)
+ (string-match "^#:" x))
+ symbols)
+ (lambda (n) (format "#:%s" n)))
+ (t
+ slime-export-symbol-representation-function)))))
+
+(defun slime-format-symbol-for-defpackage (symbol-name)
+ (funcall (if slime-export-symbol-representation-auto
+ (slime-determine-symbol-style)
+ slime-export-symbol-representation-function)
+ symbol-name))
+
(defun slime-insert-export (symbol-name)
;; Assumes we're at the inside :export after the last symbol
- (let ((symbol-name (funcall slime-export-symbol-representation-function
- symbol-name)))
+ (let ((symbol-name (slime-format-symbol-for-defpackage symbol-name)))
(unless (looking-back "^\\s-*")
(newline-and-indent))
(insert symbol-name)))
More information about the slime-cvs
mailing list