From 0c422cf727ccec76c77bfeff1c73171e6bb1b0b9 Mon Sep 17 00:00:00 2001 From: shoshin Date: Sun, 17 Jul 2022 11:47:17 -0500 Subject: Add: personal with-map-defkey macro for leader keymaps --- shoshin-config.org | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) (limited to 'shoshin-config.org') diff --git a/shoshin-config.org b/shoshin-config.org index eced968..8d381ea 100644 --- a/shoshin-config.org +++ b/shoshin-config.org @@ -220,6 +220,95 @@ to go away. (define-key 'xah-fly-leader-key-map (kbd "1") #'delete-other-windows) #+end_src +** with-map-defkey + +#+begin_src emacs-lisp + (defmacro with-map-defkey (keymap leader &rest pairs) + "Define a new KEYMAP with prefix key LEADER, and list of bindings in it." + (declare (indent 2)) + `(progn + (defvar ,keymap (make-sparse-keymap)) + (define-prefix-command (quote ,keymap)) + (global-set-key (kbd ,leader) ,keymap) + (mapc (lambda (pair) + (define-key ,keymap + (kbd (if (numberp (car pair)) (number-to-string (car pair)) + (symbol-name (car pair)))) + (cadr pair))) + (quote ,(seq-partition pairs 2))))) + + (defvar *my-config* "~/projects/shoshimacs/shoshin-config.org" + "Path to my main configuration file.") + + (defun my-configuration () + (interactive) + (find-file *my-config*)) + + (defun my-reload-config () + "Tangles and reloads a literate config with `org-babel-load-file'" + (interactive) + (org-babel-load-file *my-config*)) + + (with-map-defkey my-key-map "M-m" + 1 delete-other-windows + a apropos + b consult-buffer + c my-config + d embark-act + e eshell + f find-file + g magit + h info + i consult-imenu + j describe-function + k describe-variable + t consult-theme + w which-key-mode + my-reload-config) +#+end_src + +** COMMENT bind-map + +there is a package available in nongnu elpa that offers a macro that +sort of generalizes the leader key idea. it also hooks into the evil package +a bit to allow definition of bindings over different "states" that your +editor might be in, like command or insert mode in xah-fly-keys. its fairly +geared toward evil in that way, so i'm not sure how it will interact, but let us +find out. the other option would be to make a simple macro of our own to hook +into leader key maps. + +#+begin_src emacs-lisp + (package-install 'bind-map) + + (bind-map my-keymap + :keys ("M-m")) + + (bind-map my-org-map + :keys ("M-m m") + :major-modes (org-mode) + :bindings ("," #'org-insert-structure-template)) + + (bind-map my-elisp-map + :keys ("M-m m") + :major-modes (emacs-lisp-mode + lisp-interaction-mode) + :bindings ("e" #'edebug-instrument-function)) + + (bind-map my-ruby-map + :keys ("M-m m") + :major-modes (ruby-mode) + :bindings ("d" #'ruby-beginning-of-defun)) + + (bind-map-set-keys my-keymap + "b" #'consult-buffer + "c" #'my-config + "g" #'magit + "j" #'consult-grep + "k" #'consult-imenu + "n" #'tab-next + "t" #'consult-theme) +#+end_src + * Completion :PROPERTIES: :header-args:emacs-lisp: :noweb-ref completion :noweb-sep "\n\n" :results silent @@ -542,7 +631,7 @@ i'm interested to try it out since i still pay for the account, plus the forge i free software and could be self-hosted if it comes to it. it also depends on ~plz~ which is another new package providing a nicer API for -HTTP requests I was going +HTTP requests. #+begin_src emacs-lisp (package-install 'srht) -- cgit v1.2.3