Automatically update hydra for shortcuts after customization

This commit is contained in:
Daniel - 2020-09-19 14:02:50 +02:00
parent 14cfae155a
commit a576ef123d
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
3 changed files with 24 additions and 8 deletions

View File

@ -611,6 +611,7 @@
:commands (hydra-toggle/body
hydra-zoom/body
hydra-rectangle/body
db/define-feature-shortcuts-hydra
hydra-feature-shortcuts/body))
(use-package exec-path-from-shell

View File

@ -155,7 +155,12 @@ short description, a shortcut character, and the function to
call. Customizing this variable redefines the global
`hydra-shortcuts' mapping."
:group 'personal-settings
:type '(repeat (list string character function)))
:type '(repeat (list string character function))
:set #'(lambda (symbol value)
(set-default symbol value)
;; Update hydra when already possible available
(when (fboundp 'db/define-feature-shortcuts-hydra)
(db/define-feature-shortcuts-hydra))))

View File

@ -53,13 +53,23 @@ _h_ _l_ _o_k _y_ank
("e" rectangle-exchange-point-and-mark nil)
("o" nil nil))
(eval
`(defhydra hydra-feature-shortcuts (:color blue)
""
,@(mapcar (lambda (entry)
(pcase-let ((`(,description ,shortcut ,function) entry))
(list (string shortcut) function description)))
db/frequently-used-features)))
;; The hydra for our frequently used features should be defined here, but should
;; also be redefined every time `db/frequently-used-features' is redefined via
;; customize. To this end, we provide a special function here that defines this
;; hydra, that can also be called in the setter of
;; `db/frequently-used-features'.
(defun db/define-feature-shortcuts-hydra ()
"Globally define `hydra-feature-shortcuts' for feature shortcuts."
(eval
`(defhydra hydra-feature-shortcuts (:color blue)
""
,@(mapcar (lambda (entry)
(pcase-let ((`(,description ,shortcut ,function) entry))
(list (string shortcut) function description)))
db/frequently-used-features))))
(db/define-feature-shortcuts-hydra)
(provide 'db-hydras)
;; db-hydras.el ends here