aboutsummaryrefslogtreecommitdiffstats
path: root/sps-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'sps-mode.el')
-rw-r--r--sps-mode.el84
1 files changed, 71 insertions, 13 deletions
diff --git a/sps-mode.el b/sps-mode.el
index 27e1f54..ffd8cab 100644
--- a/sps-mode.el
+++ b/sps-mode.el
@@ -29,10 +29,9 @@
(defvar sps-mode-map (make-sparse-keymap)
"Keymap for sps-mode.
-This keymap is initialized empty. To repurpose the keys SLIME
-uses for its normal code evaluation and expansion commands, call
-`sps-shadow-slime-keybindings!`. Of course, you can alternatively
-define your own keybindings in the usual way.")
+This keymap is initialized empty. You can optionally use
+`sps-add-keys-with-prefix` to add bindings for all commands on
+two-key sequences behind a prefix of your choice.")
(defvar sps-expansion-mode-map
(let ((map (make-sparse-keymap)))
@@ -41,6 +40,9 @@ define your own keybindings in the usual way.")
map)
"Keymap for `sps-expansion-mode` buffers.")
+(defvar sps-scratch-mode-map (make-sparse-keymap)
+ "Keymap for the *sps-scratch* buffer.")
+
(defvar sps-expansion-major-mode 'javascript-mode
"The major mode to enable in expansion buffers.
Note that a serious bug seems to be triggered when using js2-mode
@@ -192,6 +194,14 @@ If the region is active this is equivalent to invoking
(sps-eval-region (region-beginning) (region-end))
(sps-eval-defun)))
+(defun sps-send-expanded-code ()
+ "Send the expanded code to the browser.
+For use from `sps-expansion-mode` buffers."
+ (interactive)
+ (skewer-eval
+ (buffer-substring-no-properties (point-min) (point-max))
+ #'skewer-post-minibuffer))
+
;;;; Keybindings
(defun sps-prefix-keys (prefix keys)
@@ -216,7 +226,58 @@ If the region is active this is equivalent to invoking
(define-key map (sps-prefix-keys p "xb") 'sps-expand-buffer)
(define-key map (sps-prefix-keys p "x SPC") 'sps-expand-dwim)))
-;;;; The minor mode
+;;;; Scratch buffer
+
+(defun sps-scratch-buffer ()
+ "Return the scratch buffer, creating it if necessary."
+ (let ((name "*sps-scratch*"))
+ (or (get-buffer name)
+ (with-current-buffer (get-buffer-create name)
+ (lisp-mode)
+ (slime-mode t)
+ (sps-mode 1)
+ (sps-scratch-mode 1)
+ (current-buffer)))))
+
+(defun sps-switch-to-scratch-buffer ()
+ "Jump to the *sps-scratch* buffer."
+ (set-buffer (sps-scratch-buffer))
+ (unless (eq (current-buffer) (window-buffer))
+ (pop-to-buffer (current-buffer) t)))
+
+(defun sps-scratch ()
+ "Jump to the *sps-scratch* buffer."
+ (interactive)
+ (sps-switch-to-scratch-buffer))
+
+;;;; A little extra SLIME integration
+
+(defun sps-mode-buffer-p (buffer)
+ "Return t if `sps-mode` is active in BUFFER."
+ (with-current-buffer buffer
+ (bound-and-true-p sps-mode)))
+
+(defun sps-recently-visited-sps-buffer ()
+ "Return the most recently visited `sps-mode` buffer.
+Only considers buffers that are not already visible."
+ (or (-first #'(lambda (b) (and (sps-mode-buffer-p b)
+ (null (get-buffer-window b 'visible))))
+ (buffer-list))
+ (error "Can't find unshown buffer in sps-mode")))
+
+(defun sps-add-slime-selector-methods ()
+ "Add methods to `slime-selector` for `sps-mode` buffers.
+Allows access to the most recently visited buffer with `sps-mode`
+active via \"p\" and to the *sps-scratch* buffer via \"P\"."
+ (interactive)
+ (def-slime-selector-method ?p
+ "most recently visited buffer using sps-mode."
+ (sps-recently-visited-sps-buffer))
+ (def-slime-selector-method ?P
+ "*sps-scratch* buffer."
+ (sps-scratch-buffer)))
+
+;;;; The minor modes
;;;###autoload
(define-minor-mode sps-mode
@@ -224,14 +285,11 @@ If the region is active this is equivalent to invoking
:lighter " sps"
:keymap sps-mode-map)
-;;;; Expansion minor mode
-
-(defun sps-send-expanded-code ()
- "Send the expanded code to the browser."
- (interactive)
- (skewer-eval
- (buffer-substring-no-properties (point-min) (point-max))
- #'skewer-post-minibuffer))
+;;;###autoload
+(define-minor-mode sps-scratch-mode
+ "Mode for sps-mode scratch buffer."
+ :lighter nil
+ :keymap sps-scratch-mode-map)
(define-minor-mode sps-expansion-mode
"Minor mode for displaying the code generated by Parenscript."