aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Mastro <john.b.mastro@gmail.com>2013-07-19 22:48:54 -0700
committerJohn Mastro <john.b.mastro@gmail.com>2013-07-19 22:48:54 -0700
commit5afe08922cfc65467b2886f49be4473a164bb28c (patch)
tree3bc4774868dc679002fcfc436e905113972961c9
parentd3659f6c5606eed5241b43e3ab88b703459173f5 (diff)
downloadtrident-mode.el-5afe08922cfc65467b2886f49be4473a164bb28c.tar.gz
trident-mode.el-5afe08922cfc65467b2886f49be4473a164bb28c.tar.bz2
trident-mode.el-5afe08922cfc65467b2886f49be4473a164bb28c.zip
Change optional key binding arrangement
Remove function for shadowing SLIME's keys, just mention it in the README as an option. I don't think it would be a popular approach. Add sps-add-keys-with-prefix for adding key bindings for all commands behind a user-specified prefix. This seems like a more useful approach.
-rw-r--r--readme.org72
-rw-r--r--sps-mode.el41
2 files changed, 80 insertions, 33 deletions
diff --git a/readme.org b/readme.org
index 9f1fbdb..41ec5d6 100644
--- a/readme.org
+++ b/readme.org
@@ -31,7 +31,7 @@ the others through [[http://www.emacswiki.org/emacs/ELPA][ELPA]].
** Setup
-To enable sps-mode in a SLIME buffer: =M-x sps-mode=.
+To enable =sps-mode= in a SLIME buffer: =M-x sps-mode=.
To have =lisp-mode=, =slime-mode=, and =sps-mode= all enable automatically for
any file with an extension of ".paren":
@@ -88,16 +88,68 @@ immediately send to it the browser to be evaluated:
- =sps-eval-buffer=
- =sps-eval-dwim=
-** Keybindings
+** Key bindings
-Many programming modes, including most Skewer modes, use keybindings which
-overlap with SLIME's. To enable those bindings, thus shadowing SLIME's, you can
-use =(sps-shadow-slime-keybindings!)=.
+The traditional set of code evaluation key bindings is a poor fit for
+=sps-mode=, since they would shadow SLIME's equivalent commands and that's
+probably not what you want. That leaves us without a clear convention to
+follow, so by default we don't establish any key bindings at all. However, the
+function =sps-add-keys-with-prefix= will add two-key key bindings for all
+commands behind a prefix of your choice.
-However /this isn't recommended/. There's a good chance you'll want the
-flexibility to evaluate the code in an =sps-mode= buffer as either Common Lisp
-or Parenscript, in which case you won't want to shadow the SLIME keybindings.
-In this case you should assign key bindings yourself.
+For example:
+
+#+BEGIN_SRC emacs-lisp
+(sps-add-keys-with-prefix "C-c C-e")
+;; The key sequence for sps-eval-region is "er", so it's now bound to
+;; "C-c C-e er"
+#+END_SRC
+
+The full list of key bindings =sps-add-keys-with-prefix= will establish is:
+
+ - =e RET= -- =sps-eval-sexp=
+ - =ee= -- =sps-eval-last-expression=
+ - =ed= -- =sps-eval-defun=
+ - =er= -- =sps-eval-region=
+ - =eb= -- =sps-eval-buffer=
+ - =e SPC= -- =sps-eval-dwim=
+ - =x RET= -- =sps-expand-sexp=
+ - =xe= -- =sps-expand-last-expression=
+ - =xd= -- =sps-expand-defun=
+ - =xr= -- =sps-expand-region=
+ - =xb= -- =sps-expand-buffer=
+ - =x SPC= -- =sps-expand-dwim=
+
+Evaluation commands begin with an "e", expansion commands with "x". The second
+letter is generally mnemonic but not always. The =-sexp= commands use =RET= in
+correspondence to =slime-expand-1=, and the =-dwim= commands use the space bar
+because it's easy and comfortable to hit.
+
+Please consider these keys provisional, and let me know if you have any ideas
+for improving the arrangement.
+
+If you really want to shadow SLIME's key bindings in buffers where =sps-mode= is
+active you could do something like this:
+
+#+BEGIN_SRC emacs-lisp
+(defun steal-slime-keys-for-sps! ()
+ ;; Don't affect all SLIME buffers, just where invoked
+ (make-local-variable 'slime-mode-map)
+ (let ((map slime-mode-map))
+ (define-key map (kbd "C-x C-e") nil)
+ (define-key map (kbd "C-c C-r") nil)
+ (define-key map (kbd "C-M-x") nil)
+ (define-key map (kbd "C-c C-k") nil)
+ (define-key map (kbd "C-c C-m") nil))
+ (let ((map sps-mode-map))
+ (define-key map (kbd "C-x C-e") 'sps-eval-last-expression)
+ (define-key map (kbd "C-c C-r") 'sps-eval-region)
+ (define-key map (kbd "C-M-x") 'sps-eval-defun)
+ (define-key map (kbd "C-c C-k") 'sps-eval-buffer)
+ (define-key map (kbd "C-c C-m") 'sps-expand-sexp)))
+
+(add-hook 'sps-mode-hook 'steal-slime-keys-for-sps!)
+#+END_SRC
** Still do be done
@@ -107,8 +159,6 @@ In this case you should assign key bindings yourself.
- See if more integration with SLIME is possible (e.g. the selector).
- Command(s) for compiling with the output going to a file.
- Similar support for [[http://weitz.de/cl-who/][CL-WHO]] and/or [[https://github.com/paddymul/css-lite][CSS-LITE]]?
- - Optional default keybindings that don't shadow SLIME.
- - Function(s) to add keybindings behind prefix keys (see js2r).
- Get to know ELPA and packaging.
- Add support for Customize.
diff --git a/sps-mode.el b/sps-mode.el
index 4ee062a..27e1f54 100644
--- a/sps-mode.el
+++ b/sps-mode.el
@@ -194,30 +194,27 @@ If the region is active this is equivalent to invoking
;;;; Keybindings
-(defun sps-shadow-slime-keybindings! ()
- "Rebind SLIME's evaluation keys for Parenscript.
+(defun sps-prefix-keys (prefix keys)
+ "Prepend PREFIX to KEYS and read with `read-kbd-macro`."
+ (read-kbd-macro (concat prefix " " keys)))
-This uses the same keys that `slime-mode` uses, thus shadowing
-them. If you want to use both sets of evaluation commands in the
-same buffer you will likely want to define other keys manually.
-
-This command must be run in the buffer that the keybindings are
-to be used in - it relies on `make-local-variable` to avoid
-changing SLIME's bindings in other buffers."
- (interactive)
- (make-local-variable 'slime-mode-map)
- (let ((map slime-mode-map))
- (define-key map (kbd "C-x C-e") nil)
- (define-key map (kbd "C-c C-r") nil)
- (define-key map (kbd "C-M-x") nil)
- (define-key map (kbd "C-c C-k") nil)
- (define-key map (kbd "C-c RET") nil))
+(defun sps-add-keys-with-prefix (p)
+ "Add keybindings for `sps-mode` commands behind prefix P."
(let ((map sps-mode-map))
- (define-key map (kbd "C-x C-e") 'sps-eval-last-expression)
- (define-key map (kbd "C-c C-r") 'sps-eval-region)
- (define-key map (kbd "C-M-x") 'sps-eval-defun)
- (define-key map (kbd "C-c C-k") 'sps-eval-buffer)
- (define-key map (kbd "C-c RET") 'sps-expand-sexp)))
+ ;; Evaluation commands
+ (define-key map (sps-prefix-keys p "e C-m") 'sps-eval-sexp)
+ (define-key map (sps-prefix-keys p "ee") 'sps-eval-last-expression)
+ (define-key map (sps-prefix-keys p "ed") 'sps-eval-defun)
+ (define-key map (sps-prefix-keys p "er") 'sps-eval-region)
+ (define-key map (sps-prefix-keys p "eb") 'sps-eval-buffer)
+ (define-key map (sps-prefix-keys p "e SPC") 'sps-eval-dwim)
+ ;; Expansion commands
+ (define-key map (sps-prefix-keys p "x C-m") 'sps-expand-sexp)
+ (define-key map (sps-prefix-keys p "xe") 'sps-expand-last-expression)
+ (define-key map (sps-prefix-keys p "xd") 'sps-expand-defun)
+ (define-key map (sps-prefix-keys p "xr") 'sps-expand-region)
+ (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