From b3830b686842fc917cc3984116e703f9406aee5c Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 15 Jun 2025 16:59:49 +0200 Subject: [PATCH] Move hydras to main db-utils package No need to keep them separate. Will be replaced partially by repeat-maps when possible. --- init.el | 16 ++++---- site-lisp/db-hydras.el | 84 ------------------------------------------ site-lisp/db-utils.el | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 93 deletions(-) delete mode 100644 site-lisp/db-hydras.el diff --git a/init.el b/init.el index 0d49dfc..6c161a2 100644 --- a/init.el +++ b/init.el @@ -474,7 +474,11 @@ split horizontally again, but this extra work should not matter much." db/dired-ediff-files db/dired-back-to-top db/dired-jump-to-bottom - db/dired-get-size) + db/dired-get-size + hydra-toggle/body + hydra-zoom/body + hydra-rectangle/body + hydra-feature-shortcuts/body) :autoload (turn-on-flycheck-when-file db/sort-nsm-permanent-settings endless/colorize-compilation @@ -484,14 +488,8 @@ 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)) - -(use-package db-hydras - :commands (hydra-toggle/body - hydra-zoom/body - hydra-rectangle/body - db/define-feature-shortcuts-hydra - hydra-feature-shortcuts/body)) + db/get-library-version + db/define-feature-shortcuts-hydra)) (use-package diminish :ensure t) diff --git a/site-lisp/db-hydras.el b/site-lisp/db-hydras.el deleted file mode 100644 index 72dff7a..0000000 --- a/site-lisp/db-hydras.el +++ /dev/null @@ -1,84 +0,0 @@ -;;; db-hydras.el --- Personal hydras ' -*- lexical-binding: t -*- - -;;; Commentary: - -;;; Code: - -(autoload 'rectangle-exchange-point-and-mark "rect") - -(require 'hydra) -(require 'db-customize) - -(defhydra hydra-toggle (:color blue) - "toggle" - ("c" column-number-mode "column") - ("d" toggle-debug-on-error "debug-on-error") - ("e" toggle-debug-on-error "debug-on-error") - ("f" auto-fill-mode "auto-fill") - ("l" toggle-truncate-lines "truncate lines") - ("q" toggle-debug-on-quit "debug-on-quit") - ("r" read-only-mode "read-only")) - -;; zooming with single keystrokes (from oremacs) -(defhydra hydra-zoom (:color red - :body-pre (require 'face-remap)) - ;; the following newline is important, as otherwise the format string is not - ;; interpreted correctly; cf. https://oremacs.com/2015/02/23/hydra-0.11.0/ - " -Zoom (%`text-scale-mode-amount): " - ("g" text-scale-increase "increase") - ("l" text-scale-decrease "decrease") - ("0" (text-scale-adjust 0) "reset")) - -(defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1) - :color pink - :post (deactivate-mark)) - " - ^_k_^ _d_elete _s_tring -_h_ _l_ _o_k _y_ank - ^_j_^ _n_ew-copy _r_eset -^^^^ _e_xchange _u_ndo -^^^^ ^ ^ _p_aste -" - ("h" backward-char nil) - ("l" forward-char nil) - ("k" previous-line nil) - ("j" next-line nil) - ("n" copy-rectangle-as-kill nil) - ("d" delete-rectangle nil) - ("r" (if (region-active-p) - (deactivate-mark) - (rectangle-mark-mode 1)) - nil) - ("y" yank-rectangle nil) - ("u" undo nil) - ("s" string-rectangle nil) - ("p" kill-rectangle nil) - ("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) - -(provide 'db-hydras) -;;; db-hydras.el ends here diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 10bb263..1443080 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -22,6 +22,7 @@ (require 's) (require 'shr) (require 'recentf) +(require 'hydra) (autoload 'async-start "async") (autoload 'lispy-mode "lispy") @@ -29,6 +30,7 @@ (autoload 'find-libary-name "find-func") (autoload 'lm-header "lisp-mnt") (autoload 'dired-dwim-target-directory "dired-aux") +(autoload 'rectangle-exchange-point-and-mark "rect") (declare-function w32-shell-execute "w32fns.c") (declare-function org-password-manager-get-password-by-id nil) @@ -675,6 +677,76 @@ quite sure whether something like this exists already?" (defalias 'check-git-repos #'db/list-changed-git-repositories) ; old name of former shell script +(defhydra hydra-toggle (:color blue) + "toggle" + ("c" column-number-mode "column") + ("d" toggle-debug-on-error "debug-on-error") + ("e" toggle-debug-on-error "debug-on-error") + ("f" auto-fill-mode "auto-fill") + ("l" toggle-truncate-lines "truncate lines") + ("q" toggle-debug-on-quit "debug-on-quit") + ("r" read-only-mode "read-only")) + +(defhydra hydra-zoom (:color red + :body-pre (require 'face-remap)) + ;; the following newline is important, as otherwise the format string is not + ;; interpreted correctly; cf. https://oremacs.com/2015/02/23/hydra-0.11.0/ + " +Zoom (%`text-scale-mode-amount): " + ("g" text-scale-increase "increase") + ("l" text-scale-decrease "decrease") + ("0" (text-scale-adjust 0) "reset")) + +(defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1) + :color pink + :post (deactivate-mark)) + " + ^_k_^ _d_elete _s_tring +_h_ _l_ _o_k _y_ank + ^_j_^ _n_ew-copy _r_eset +^^^^ _e_xchange _u_ndo +^^^^ ^ ^ _p_aste +" + ("h" backward-char nil) + ("l" forward-char nil) + ("k" previous-line nil) + ("j" next-line nil) + ("n" copy-rectangle-as-kill nil) + ("d" delete-rectangle nil) + ("r" (if (region-active-p) + (deactivate-mark) + (rectangle-mark-mode 1)) + nil) + ("y" yank-rectangle nil) + ("u" undo nil) + ("s" string-rectangle nil) + ("p" kill-rectangle nil) + ("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