From ab9245d58f2cb2fd8e65a13bca03f28451ccc693 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 15 Jun 2025 18:22:09 +0200 Subject: [PATCH] Replace hydra for frequently used features by simple map Easier :) --- init.el | 8 +++----- site-lisp/db-customize.el | 11 ++++++++--- site-lisp/db-utils.el | 23 ----------------------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/init.el b/init.el index 8657690..d4f5a93 100644 --- a/init.el +++ b/init.el @@ -476,8 +476,7 @@ split horizontally again, but this extra work should not matter much." db/dired-jump-to-bottom db/dired-get-size hydra-toggle/body - hydra-rectangle/body - hydra-feature-shortcuts/body) + hydra-rectangle/body) :autoload (turn-on-flycheck-when-file db/sort-nsm-permanent-settings endless/colorize-compilation @@ -487,8 +486,7 @@ split horizontally again, but this extra work should not matter much." db/replace-variables-in-string db/grep-read-files db/make-selector-from-table-header - db/get-library-version - db/define-feature-shortcuts-hydra)) + db/get-library-version)) (use-package diminish :ensure t) @@ -3111,7 +3109,7 @@ eventuelly be set to nil, however)." (bind-key "" #'winner-redo) (bind-key "" 'scroll-lock-mode) (bind-key "" #'db/run-or-hide-eshell) - (bind-key "" #'hydra-feature-shortcuts/body) + (bind-key "" db/frequently-used-features-map) (bind-key "" #'project-find-regexp) (bind-key "" #'text-scale-adjust) (bind-key "" #'dictcc) diff --git a/site-lisp/db-customize.el b/site-lisp/db-customize.el index 6023d24..ca1850c 100644 --- a/site-lisp/db-customize.el +++ b/site-lisp/db-customize.el @@ -149,6 +149,9 @@ in the main agenda view." :group 'personal-settings :type '(choice (const nil) file)) +(defvar db/frequently-used-features-map (make-sparse-keymap) + "Functions from `db/frequently-used-features' bound to shortcuts.") + (defcustom db/frequently-used-features '(("Mail" ?m db/gnus) ("Agenda" ?a db/org-agenda) @@ -175,9 +178,11 @@ can be chosen, in which case no entry in the :type '(repeat (list string (choice character (const nil)) 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)))) + (setq db/frequently-used-features-map (make-sparse-keymap)) + (mapc #'(lambda (entry) + (pcase-let ((`(_ ,shortcut ,function) entry)) + (keymap-set db/frequently-used-features-map (string shortcut) function))) + db/frequently-used-features))) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 87e4db6..9c42799 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -714,29 +714,6 @@ _h_ _l_ _o_k _y_ank ("e" rectangle-exchange-point-and-mark nil) ("o" nil nil)) -;; 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. -If instead of a shortcut character nil is provided, no entry in -the hydra will be generated. See documentation of -`db/frequently-used-features' for details." - (eval - `(defhydra hydra-feature-shortcuts (:color blue) - "" - ,@(mapcar (lambda (entry) - (pcase-let ((`(,description ,shortcut ,function) entry)) - (list (string shortcut) function description))) - (cl-remove-if #'(lambda (entry) - (null (cl-second entry))) - db/frequently-used-features))))) - -(db/define-feature-shortcuts-hydra) - ;;; Base45 Decoding