diff options
author | John Mastro <john.b.mastro@gmail.com> | 2013-07-20 09:23:09 -0700 |
---|---|---|
committer | John Mastro <john.b.mastro@gmail.com> | 2013-07-20 09:23:09 -0700 |
commit | 7eec137c46dce7c747386fd0a8a8699fb71fe43f (patch) | |
tree | 12578da8b9021e174de49dcc27dfa6b6fdf68efa | |
parent | 5afe08922cfc65467b2886f49be4473a164bb28c (diff) | |
download | trident-mode.el-7eec137c46dce7c747386fd0a8a8699fb71fe43f.tar.gz trident-mode.el-7eec137c46dce7c747386fd0a8a8699fb71fe43f.tar.bz2 trident-mode.el-7eec137c46dce7c747386fd0a8a8699fb71fe43f.zip |
A scratch buffer and slime-selector integration
-rw-r--r-- | readme.org | 18 | ||||
-rw-r--r-- | sps-mode.el | 84 |
2 files changed, 86 insertions, 16 deletions
@@ -151,13 +151,25 @@ active you could do something like this: (add-hook 'sps-mode-hook 'steal-slime-keys-for-sps!) #+END_SRC +** Other amenities + +=slime-selector= is a great feature and =sps-mode= can optionally integrate +with it. If you call =sps-add-slime-selector-methods=, two entries related to +=sps-mode= will be added. One, invoked with =p=, will take you to the most +recently visited buffer where =sps-mode= is active (excluding buffers which are +already visible). The other, on =P=, will take you to a scratch buffer with +=sps-mode= enabled, creating the buffer if necessary. + +Speaking of the scratch buffer, the =sps-scratch= command will take you +straight there. + ** Still do be done - Test against a wider array of code. Are there problems with quoting? - Better documentation. - - Add a REPL and/or a scratch buffer. - - See if more integration with SLIME is possible (e.g. the selector). - - Command(s) for compiling with the output going to a file. + - Look into adding a REPL. + - See if more integration with SLIME is possible. + - Command(s) for compiling to a file. - Similar support for [[http://weitz.de/cl-who/][CL-WHO]] and/or [[https://github.com/paddymul/css-lite][CSS-LITE]]? - Get to know ELPA and packaging. - Add support for Customize. 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." |