Skip to content

Instantly share code, notes, and snippets.

@joefromct
Created May 22, 2024 15:31
Show Gist options
  • Save joefromct/a4a04b4c999e343012283df1d769b640 to your computer and use it in GitHub Desktop.
Save joefromct/a4a04b4c999e343012283df1d769b640 to your computer and use it in GitHub Desktop.
hydra example

Text-scaling (hydra example)

fn’s

adjust-font-size

(defun my/adjust-font-size (height)
  "Adjust font size by given height. If height is '0', reset font
  size. This function also handles icons and modeline font sizes."
  (interactive "nHeight ('0' to reset): ")
  (let ((new-height (if (zerop height)
                        my/default-font-size
                      (+ height (face-attribute 'default :height)))))
    (set-face-attribute 'default nil :height new-height)
    (set-face-attribute 'mode-line nil :height new-height)
    (set-face-attribute 'mode-line-inactive nil :height new-height)
    (message "Font size: %s" new-height))
  (let ((new-size (if (zerop height)
                      my/default-icon-size
                    (+ (/ height 5) treemacs--icon-size))))
    (when (fboundp 'treemacs-resize-icons)
      (treemacs-resize-icons new-size))
    (when (fboundp 'company-box-icons-resize)
      (company-box-icons-resize new-size)))
  (when diff-hl-mode
    (diff-hl-maybe-redefine-bitmaps)))

increase-font-size

(defun my/increase-font-size ()
  "Increase font size by 0.5 (5 in height)."
  (interactive)
  (my/adjust-font-size 5))

decrease-font-size

(defun my/decrease-font-size ()
  "Decrease font size by 0.5 (5 in height)."
  (interactive)
  (my/adjust-font-size -5))

reset-font-size

(defun my/reset-font-size ()
  "Reset font size according to the `my/default-font-size'."
  (interactive)
  (my/adjust-font-size 0))

hydra body

  (use-package hydra :straight t)

  (defhydra hydra-text-scale (:timeout 4)
    "scale text"
    ("j" text-scale-increase "in")
    ("k" text-scale-decrease "out")
    ("+" text-scale-increase "in")
    ("-" text-scale-decrease "out")
    ("q" nil "quit" :exit t))

(general-define-key :modes '(global override)
                    "C-, C-w C-z" 'hydra-text-scale/body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment