diff options
author | Case Duckworth | 2021-05-06 17:47:07 -0500 |
---|---|---|
committer | Case Duckworth | 2021-05-06 17:48:20 -0500 |
commit | 0f1fe1c098f5f4aecec03482155cc42c397f2a4c (patch) | |
tree | c12b0575213e46d3e0ee34a3cd6fb094499b55cc | |
parent | Configure `gnus-cloud-covered-servers' (diff) | |
download | emacs-0f1fe1c098f5f4aecec03482155cc42c397f2a4c.tar.gz emacs-0f1fe1c098f5f4aecec03482155cc42c397f2a4c.zip |
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.
-rw-r--r-- | init.el | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/init.el b/init.el index 74993fe..9e6f79f 100644 --- a/init.el +++ b/init.el | |||
@@ -649,6 +649,37 @@ | |||
649 | (:option inferior-lisp-program acdw/lisp-bin) | 649 | (:option inferior-lisp-program acdw/lisp-bin) |
650 | 650 | ||
651 | (setup (:straight clhs)) | 651 | (setup (:straight clhs)) |
652 | |||
653 | (defmacro acdw/cl-define-key (key-string &rest bindings) | ||
654 | "Define KEY-STRING to functions in BINDINGS. | ||
655 | KEY-STRING is passed directly to `kbd'. BINDINGS are a lists of | ||
656 | the form (:IDE MAP FUNC AFTER), where IDE is an IDE (like `slime' or | ||
657 | `sly'), MAP is the mapping in which to bind KEY-STRING, FUNC | ||
658 | 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. | ||
659 | `acdw/cl-define-key' only binds the keys that match `acdw/cl-ide' | ||
660 | to save computation time." | ||
661 | (declare (indent 1)) | ||
662 | (let* ((binding (catch :found | ||
663 | (dolist (b bindings) | ||
664 | (when (eq (car b) acdw/cl-ide) | ||
665 | (throw :found b))))) | ||
666 | (binding-map `,(nth 1 binding)) | ||
667 | (binding-func `(function ,(nth 2 binding))) | ||
668 | (binding-after `,(nth 3 binding))) | ||
669 | `(with-eval-after-load ',binding-after | ||
670 | (define-key ,binding-map (kbd ,key-string) ,binding-func)))) | ||
671 | |||
672 | (dolist (key '("RET" "<return>")) | ||
673 | (acdw/cl-define-key key | ||
674 | (:slime slime-repl-mode-map slime-repl-return-at-end slime) | ||
675 | (:sly sly-mrepl-mode-map sly-mrepl-return-at-end sly-mrepl))) | ||
676 | |||
677 | (eval-after-load 'sly-mrepl | ||
678 | (function | ||
679 | (lambda nil | ||
680 | (define-key sly-mrepl-mode-map | ||
681 | (kbd "C-c C-c") | ||
682 | (function sly-mrepl-return))))) | ||
652 | 683 | ||
653 | (pcase acdw/cl-ide | 684 | (pcase acdw/cl-ide |
654 | (:slime | 685 | (:slime |
@@ -661,10 +692,6 @@ | |||
661 | "~/var/quicklisp/slime-helper.el")))) | 692 | "~/var/quicklisp/slime-helper.el")))) |
662 | (load slime-helper)) | 693 | (load slime-helper)) |
663 | 694 | ||
664 | (with-eval-after-load 'slime | ||
665 | (dolist (key (list (kbd "RET") | ||
666 | (kbd "<return>"))) | ||
667 | (define-key slime-repl-mode-map key #'slime-repl-return-at-end))) | ||
668 | (defun slime-repl-return-at-end () | 695 | (defun slime-repl-return-at-end () |
669 | (interactive) | 696 | (interactive) |
670 | (if (<= (point-max) (point)) | 697 | (if (<= (point-max) (point)) |
@@ -680,11 +707,6 @@ | |||
680 | (:sly | 707 | (:sly |
681 | (setup (:straight sly) | 708 | (setup (:straight sly) |
682 | (:option sly-kill-without-query-p t) | 709 | (:option sly-kill-without-query-p t) |
683 | |||
684 | (with-eval-after-load 'sly-mrepl | ||
685 | (dolist (key (list (kbd "RET") | ||
686 | (kbd "<return>"))) | ||
687 | (define-key sly-mrepl-mode-map key #'sly-mrepl-return-at-end))) | ||
688 | 710 | ||
689 | (defun sly-mrepl-return-at-end () | 711 | (defun sly-mrepl-return-at-end () |
690 | (interactive) | 712 | (interactive) |