1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;; This is an extension to SLIME that is inspired by (and works
3 ;;;; like) the SLIME 'C-c M-m' macroexpansion feature.
5 ;;;; After loading, 'C-c j' (PS) or 'C-c d' (PS-DOC) at a ParenScript
6 ;;;; expression in a slime-mode buffer will bring up a buffer with the
7 ;;;; resulting Javascript code. Note that the extension does not work
8 ;;;; in slime-repl-mode, which is intentional.
10 ;;;; Copyright 2007, Vladimir Sedach. See the COPYING file in the
11 ;;;; Parenscript distribution for licensing information.
13 ;;; The code below is a generic facility for adding "macroexpand-like" buffer expansion to Slime
14 (defun slime-eval-custom-expand (expander exp-str package buffer-name buffer-mode printer
)
15 (lexical-let ((package package
)
16 (buffer-name buffer-name
)
17 (buffer-mode buffer-mode
)
20 (list 'swank
:eval-and-grab-output
(format "(%s %s)" expander exp-str
))
22 (slime-with-popup-buffer (buffer-name)
24 (setq buffer-read-only nil
)
26 (insert (funcall printer
(second expansion
)))
27 (setq buffer-read-only t
)
28 (font-lock-fontify-buffer)))
31 (defun* slime-add-custom-expander
(key expander buffer-name
&optional
(buffer-mode 'slime-mode
) (printer #'identity
))
32 (define-key slime-parent-map
(concat "\C-c" key
)
33 (lexical-let ((expander expander
)
34 (buffer-name buffer-name
)
35 (buffer-mode buffer-mode
)
39 (slime-eval-custom-expand expander
40 (first (slime-sexp-at-point-for-macroexpansion))
41 (slime-current-package)
46 ;;; This actually defines the expander. If the code above belongs in slime.el, the code below would go into .emacs
48 (slime-add-custom-expander (car x
)
50 "*Parenscript generated Javascript*"
51 (if (featurep 'javascript-mode
) 'javascript-mode
'c-mode
)
53 '(("j" . ps
:ps
) ("d" . ps
:ps-doc
)))