[slime-devel] propose change to `slime-handle-repl-shortcut'

MON KEY monkey at sandpframing.com
Sat Jan 22 23:24:17 UTC 2011


`slime-handle-repl-shortcut' uses completing-read to help user find
repl shortcuts.

However, it currently doesn't handle the "?" alias properly and it is
not possible to acctually get a "?" completion because
`minibuffer-local-completion-map' already sits on that binding with
`minibuffer-completion-help' which isn't really useful in the slime
context (or any other FTM).

Proposed changes put "?" in the `slime-repl-shortcut-history'.
This allows user to get to "?" via `previous-history-element'.

Changes `slime-handle-repl-shortcut' by binding the local `shortcut`
var to the return value of `slime-complete-repl-shortcuts' which is
cleaner IMHO.

Adds a new function `slime-complete-repl-shortcuts'.

The purpose of this function is to steal back some control from
completing-read.  This is done by dynamically bind
`minibuffer-local-completion-map' to a copy of itself then dynamically
binds the copied keymap to value of `overriding-local-map'.

Within the scope, of this binding a local keybinding is established
for the copied keymap which attaches an anonymous function to insert a
"?" such that the user can actually type enter with "?" as the
completed value.

The cummulative affect of these changes is taht user will now have the
benefit of actually being able to access `slime-repl-shortcut-help'
which in turn will present a nice popup buffer per
`slime-list-repl-short-cuts'.

A patch against CVS is attached and as follows:


--- slime-repl.el.~1.52.~	2010-09-26 14:10:33.000000000 -0400
+++ slime-repl.el	2011-01-22 18:56:02.876713429 -0500
@@ -1191,25 +1191,32 @@
 (defvar slime-repl-shortcut-table nil
   "A list of slime-repl-shortcuts")

-(defvar slime-repl-shortcut-history '()
+(defvar slime-repl-shortcut-history '("?")
   "History list of shortcut command names.")

 (defvar slime-within-repl-shortcut-handler-p nil
   "Bound to T if we're in a REPL shortcut handler invoked from the REPL.")

+(defun slime-complete-repl-shortcuts ()
+  (let* ((new-local-map (copy-keymap minibuffer-local-completion-map))
+         (minibuffer-local-completion-map new-local-map)
+         (overriding-local-map minibuffer-local-completion-map))
+    (define-key new-local-map "?" (function (lambda () (interactive)
(insert 63))))
+    (slime-lookup-shortcut
+     (completing-read "Slime REPL shortcut: "
+                      (slime-bogus-completion-alist
+                       (slime-list-all-repl-shortcuts))
+                      nil t nil
+                      'slime-repl-shortcut-history))))
+
 (defun slime-handle-repl-shortcut ()
   (interactive)
   (if (> (point) slime-repl-input-start-mark)
       (insert (string slime-repl-shortcut-dispatch-char))
-      (let ((shortcut (slime-lookup-shortcut
-                       (completing-read "Command: "
-                                        (slime-bogus-completion-alist
-                                         (slime-list-all-repl-shortcuts))
-                                        nil t nil
-                                        'slime-repl-shortcut-history))))
-        (with-struct (slime-repl-shortcut. handler) shortcut
-          (let ((slime-within-repl-shortcut-handler-p t))
-            (call-interactively handler))))))
+    (let ((shortcut (slime-complete-repl-shortcuts)))
+      (with-struct (slime-repl-shortcut. handler) shortcut
+        (let ((slime-within-repl-shortcut-handler-p t))
+          (call-interactively handler))))))

 (defun slime-list-all-repl-shortcuts ()
   (loop for shortcut in slime-repl-shortcut-table
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slime-repl.el-diff
Type: application/octet-stream
Size: 2089 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/slime-devel/attachments/20110122/b67ca1d5/attachment.obj>


More information about the slime-devel mailing list