aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshoshin <shoshin@cicadas.surf>2022-07-17 11:47:17 -0500
committershoshin <shoshin@cicadas.surf>2022-07-17 11:47:17 -0500
commit0c422cf727ccec76c77bfeff1c73171e6bb1b0b9 (patch)
tree7b22d954ad2fccd5d3cd12318581078423e12937
parentf7841f24ae6ea0d36b5ad397268fd90fafdec1bd (diff)
Add: personal with-map-defkey macro for leader keymaps
-rw-r--r--shoshin-config.el43
-rw-r--r--shoshin-config.org91
2 files changed, 133 insertions, 1 deletions
diff --git a/shoshin-config.el b/shoshin-config.el
index 3718296..c104247 100644
--- a/shoshin-config.el
+++ b/shoshin-config.el
@@ -29,6 +29,49 @@
(define-key 'xah-fly-leader-key-map (kbd "1") #'delete-other-windows)
+(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
+ <f1> my-reload-config)
+
;;; Completion
(setq completion-styles '(flex basic partial-completion emacs22)
completion-cycle-threshold 3
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
+ <f1> 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)