Refactor CL IDE binding code

This is a prelude to writing 'acdw-cl.el', since the two IDEs (that's what I'm
calling them) each have a known structure.  So I'm going to write a little
library to abstract that out.
This commit is contained in:
Case Duckworth 2021-05-06 17:47:07 -05:00
parent ff77f56c21
commit 0f1fe1c098
1 changed files with 31 additions and 9 deletions

40
init.el
View File

@ -649,6 +649,37 @@
(:option inferior-lisp-program acdw/lisp-bin)
(setup (:straight clhs))
(defmacro acdw/cl-define-key (key-string &rest bindings)
"Define KEY-STRING to functions in BINDINGS.
KEY-STRING is passed directly to `kbd'. BINDINGS are a lists of
the form (:IDE MAP FUNC AFTER), where IDE is an IDE (like `slime' or
`sly'), MAP is the mapping in which to bind KEY-STRING, FUNC
is the function to bind KEY-STRING to in that IDE and MAP, and AFTER is the file to `eval-after-load' the `define-key' definition.
`acdw/cl-define-key' only binds the keys that match `acdw/cl-ide'
to save computation time."
(declare (indent 1))
(let* ((binding (catch :found
(dolist (b bindings)
(when (eq (car b) acdw/cl-ide)
(throw :found b)))))
(binding-map `,(nth 1 binding))
(binding-func `(function ,(nth 2 binding)))
(binding-after `,(nth 3 binding)))
`(with-eval-after-load ',binding-after
(define-key ,binding-map (kbd ,key-string) ,binding-func))))
(dolist (key '("RET" "<return>"))
(acdw/cl-define-key key
(:slime slime-repl-mode-map slime-repl-return-at-end slime)
(:sly sly-mrepl-mode-map sly-mrepl-return-at-end sly-mrepl)))
(eval-after-load 'sly-mrepl
(function
(lambda nil
(define-key sly-mrepl-mode-map
(kbd "C-c C-c")
(function sly-mrepl-return)))))
(pcase acdw/cl-ide
(:slime
@ -661,10 +692,6 @@
"~/var/quicklisp/slime-helper.el"))))
(load slime-helper))
(with-eval-after-load 'slime
(dolist (key (list (kbd "RET")
(kbd "<return>")))
(define-key slime-repl-mode-map key #'slime-repl-return-at-end)))
(defun slime-repl-return-at-end ()
(interactive)
(if (<= (point-max) (point))
@ -680,11 +707,6 @@
(:sly
(setup (:straight sly)
(:option sly-kill-without-query-p t)
(with-eval-after-load 'sly-mrepl
(dolist (key (list (kbd "RET")
(kbd "<return>")))
(define-key sly-mrepl-mode-map key #'sly-mrepl-return-at-end)))
(defun sly-mrepl-return-at-end ()
(interactive)