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 /sps-mode.el | |
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
Diffstat (limited to 'sps-mode.el')
-rw-r--r-- | sps-mode.el | 84 |
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." |