From 9e0338e6836dc33f8204f613b9bcb4af433b04db Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Fri, 20 Dec 2019 16:12:11 +0100 Subject: [PATCH] Dynamically create hydra from `db/frequently-used-features' --- init.el | 12 ++++++++---- site-lisp/db-hydras.el | 23 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/init.el b/init.el index 968e594..2c78663 100644 --- a/init.el +++ b/init.el @@ -169,8 +169,7 @@ (bind-key "" #'winner-undo) (bind-key "" #'winner-redo) (bind-key "" #'db/run-or-hide-eshell) - (bind-key " i" #'counsel-info-lookup-symbol) - (bind-key " u" #'counsel-unicode-char) + (bind-key "" #'hydra-shortcuts/body) (bind-key "" #'rgrep) (bind-key "" #'hydra-zoom/body) (bind-key "" #'dictcc) @@ -591,7 +590,9 @@ (use-package db-hydras :commands (hydra-toggle/body hydra-zoom/body - hydra-rectangle/body)) + hydra-rectangle/body + hydra-shortcuts/body + db/define-hydra-from-frequently-used-features)) (use-package git-commit :commands (global-git-commit-mode)) @@ -657,7 +658,10 @@ them. Can be used in application shortcuts such as short description, a shortcut character, and the function to call." :group 'personal-settings - :type '(repeat (list string character function))) + :type '(repeat (list string character function)) + :set #'(lambda (symbol value) + (set symbol value) + (db/define-hydra-from-frequently-used-features))) (defcustom db/important-documents-path "~/Documents/library/" "Path to look for documents that can be listed in extended diff --git a/site-lisp/db-hydras.el b/site-lisp/db-hydras.el index d62f05c..4e63350 100644 --- a/site-lisp/db-hydras.el +++ b/site-lisp/db-hydras.el @@ -6,9 +6,6 @@ (require 'hydra) - -;;; Hydras - (defhydra hydra-toggle (:color blue) "toggle" ("c" column-number-mode "column") @@ -53,8 +50,24 @@ _h_ _l_ _o_k _y_ank ("e" rectangle-exchange-point-and-mark nil) ("o" nil nil)) - -;; End +(defun hydra-shortcuts/body () + "Dummy default value for shortcuts hydra. Will simply barf." + (interactive) + (user-error "Shortcuts Hydra not defined yet.")) + +(defun db/define-hydra-from-frequently-used-features () + "Defines `hydra-shortcuts/body' based on the current value of +`db/frequently-used-features'. Raises an error if the latter is +not bound." + (if (not (boundp 'db/frequently-used-features)) + (user-error "Variable `db/frequently-used-features' is not defined, please set that variable first.") + (eval + `(defhydra hydra-shortcuts (:color blue) + "" + ,@(mapcar (lambda (entry) + (pcase-let ((`(,description ,shortcut ,function) entry)) + (list (string shortcut) function description))) + db/frequently-used-features))))) (provide 'db-hydras) ;; db-hydras.el ends here