diff --git a/init.el b/init.el index 74993fe..9e6f79f 100644 --- a/init.el +++ b/init.el @@ -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" "")) + (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 ""))) - (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 ""))) - (define-key sly-mrepl-mode-map key #'sly-mrepl-return-at-end))) (defun sly-mrepl-return-at-end () (interactive)