Increase/Decrease the "font size" of the frame

While the `text-scale-increase` works fine for a single window, if I
want the font for the entire window, I needed something else. Added it
to the "Window" Hydra, so it could be a pink toggle.

While I was at it, I changed more `ha/` to `ha-` ... consistency!
This commit is contained in:
Howard Abrams 2021-11-11 21:05:41 -08:00
parent ddbdc55eaf
commit ee2eab464d
5 changed files with 103 additions and 52 deletions

View file

@ -511,7 +511,7 @@ This package, bound to ~SPC w w~, also allows operations specified before choosi
- ~b~ - split window horizontally
- ~o~ - maximize current window
- ~?~ - show these command bindings
Keep in mind, these shortcuts only work with lots of windows open. For instance, ~SPC w w x 3~ closes the "3" window.
To jump to a window even quicker, use the [[https://github.com/deb0ch/emacs-winum][winum package]]:
#+BEGIN_SRC emacs-lisp
@ -519,6 +519,8 @@ To jump to a window even quicker, use the [[https://github.com/deb0ch/emacs-winu
:config
(winum-mode +1))
#+END_SRC
This is nice since the window numbers are always present on a Doom modeline, however, they order the window numbers /differently/ than =ace-window=. Let's see which I end up liking better.
The ~0~ key/window should be always associated with a project-specific tree window:
#+BEGIN_SRC emacs-lisp
(add-to-list 'winum-assign-functions
@ -533,8 +535,8 @@ Let's try this out with a Hydra since some commands (enlarge window), I want to
(defhydra hydra-window-resize (:color blue :hint nil) "
_w_: select _n_: new _^_: taller (t) _z_: Swap _+_: text larger
_c_: cycle _d_: delete _V_: shorter (T) _u_: undo _-_: text smaller
_j_: go up _=_: balance _>_: wider _U_: undo+
_k_: down _m_: maximize _<_: narrower _r_: redo
_j_: go up _=_: balance _>_: wider _U_: undo+ _F_: font larger
_k_: down _m_: maximize _<_: narrower _r_: redo _f_: font smaller
_h_: left _s_: h-split _e_: balanced _R_: redo+
_l_: right _v_: v-split _o_: choose by number (also 0-9)
"
@ -561,6 +563,8 @@ _l_: right _v_: v-split _o_: choose by number (also 0-9)
("s" evil-window-split)
("v" evil-window-vsplit)
("F" font-size-increase :color pink)
("f" font-size-decrease :color pink)
("+" text-scale-increase :color pink)
("=" text-scale-increase :color pink)
("-" text-scale-decrease :color pink)

View file

@ -150,7 +150,7 @@ brew install --cask font-hack-nerd-font
** Specifying a Font
My /current/ favorite font is actually the top list of fonts that may be installed on my system (they usually are):
#+BEGIN_SRC emacs-lisp
(defvar ha/fixed-font
(defvar ha-fixed-font
(when window-system
(cond ((x-list-fonts "Hack Nerd Font") "Hack Nerd Font")
((x-list-fonts "Cousine Nerd Font") "Cousine Nerd Font")
@ -168,12 +168,12 @@ My /current/ favorite font is actually the top list of fonts that may be install
Force something as well:
#+BEGIN_SRC emacs-lisp :tangle no
(setq ha/fixed-font "Hack Nerd Font")
(setq ha-fixed-font "Hack Nerd Font")
#+END_SRC
I probably don't need to have such a ranking system, as chances are really good that I'll have all of them installed. Still.
#+BEGIN_SRC emacs-lisp
(defvar ha/variable-font
(defvar ha-variable-font
(when window-system
(cond ((x-list-fonts "Overpass") "Overpass")
((x-list-fonts "Source Sans Pro") "Source Sans Pro")
@ -184,52 +184,99 @@ I probably don't need to have such a ranking system, as chances are really good
"My variable width font available to org-mode files and whatnot.")
#+END_SRC
Simple function that gives me the font information based on the size I need.
This calls =set-frame-font=, but also sets the monospaced font for org code blocks.
#+BEGIN_SRC emacs-lisp :results none
(defun ha/set-favorite-font-size (size)
(let ((fav-font (format "%s-%d" ha/fixed-font size)))
(set-frame-font fav-font nil t)
;; When using variable-pitch in org, we need to specifically set the
;; fixed-pitch as my default fixed-pitched font.
(custom-theme-set-faces
'user
`(variable-pitch ((t (:family ,ha/variable-font :slant normal :weight normal :height 1.1 :width normal))))
`(fixed-pitch ((t (:family ,ha/fixed-font :slant normal :weight normal :height 1.0 :width normal)))))))
#+END_SRC
Define a few /interactive/ functions to quickly adjusting the font size based on my computing scenario:
Simple function that gives me the font information based on the size I
need. This calls =set-frame-font=, but also sets the monospaced font
for org code blocks.
#+BEGIN_SRC emacs-lisp
(defun ha/mac-monitor-fontsize ()
(defun ha-set-favorite-font-size (size)
(let ((fav-font (format "%s-%d" ha-fixed-font size)))
(set-frame-font fav-font nil t)
;; When using variable-pitch in org, we need to specifically set the
;; fixed-pitch as my default fixed-pitched font.
(custom-theme-set-faces
'user
`(variable-pitch ((t (:family ,ha-variable-font :slant normal :weight normal :height 1.1 :width normal))))
`(fixed-pitch ((t (:family ,ha-fixed-font :slant normal :weight normal :height 1.0 :width normal)))))))
#+END_SRC
Define /interactive/ functions to quickly adjusting the font size based on my computing scenario:
#+BEGIN_SRC emacs-lisp
(defun ha-mac-monitor-fontsize ()
"Quickly set reset my font size when I connect my laptop to a monitor on a Mac."
(interactive)
(ha/set-favorite-font-size 13))
(ha-set-favorite-font-size 13))
(defun ha/linux-monitor-fontsize ()
(defun ha-linux-monitor-fontsize ()
"Quickly set reset my font size when I connect my laptop to a monitor on Linux."
(interactive)
(ha/set-favorite-font-size 12))
(ha-set-favorite-font-size 12))
(defun ha/mac-laptop-fontsize ()
(defun ha-mac-laptop-fontsize ()
"Quickly set reset my font size when I disconnect my laptop to a monitor from a Mac."
(interactive)
(ha/set-favorite-font-size 32))
(ha-set-favorite-font-size 32))
(defun ha/linux-laptop-fontsize ()
(defun ha-linux-laptop-fontsize ()
"Quickly set reset my font size when I disconnect my laptop to a monitor from Linux."
(interactive)
(ha/set-favorite-font-size 14))
(ha-set-favorite-font-size 14))
#+END_SRC
Which font to choose?
#+BEGIN_SRC emacs-lisp
(if (eq system-type 'gnu/linux)
(ha/linux-laptop-fontsize)
(ha/mac-monitor-fontsize))
(defun font-monitor-size-default ()
"Set the default size according to my preference."
(interactive)
(if (eq system-type 'gnu/linux)
(ha-linux-monitor-fontsize)
(ha-mac-monitor-fontsize)))
(defun font-laptop-size-default ()
"Set the default size according to my preference."
(interactive)
(if (eq system-type 'gnu/linux)
(ha-linux-laptop-fontsize)
(ha-mac-laptop-fontsize)))
(font-monitor-size-default)
#+END_SRC
** Zooming or Increasing Font Size
Do we want to increase the size of font in a single window (using =text-scale-increase=), or globally (using my new =font-size-increase=)?
Increase or decrease the set size of the face:
#+BEGIN_SRC emacs-lisp
(defun font-size-adjust (delta)
"Adjust the current frame's font size.
DELTA would be something like 1 or -1."
(interactive "nFont size difference: ")
(when (null delta) (setq delta 1))
(let* ((font-family (face-attribute 'default :font))
(font-size (font-get font-family :size))
(new-size (+ delta font-size)))
(ha-set-favorite-font-size new-size)))
(defun font-size-increase ()
"Increase the `default' font size of all frames."
(interactive)
(font-size-adjust 1))
(defun font-size-decrease ()
"Decrease the `default' font size of all frames."
(interactive)
(font-size-adjust -1))
#+END_SRC
And some keybindings to call them:
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "s-+") 'font-size-increase)
(global-set-key (kbd "s-=") 'font-size-increase)
(global-set-key (kbd "s--") 'font-size-decrease)
(global-set-key (kbd "s-0") 'font-size-monitor-default)
(global-set-key (kbd "s-9") 'font-size-laptop-default)
#+END_SRC
* Ligatures

View file

@ -46,7 +46,7 @@ First step is to make all Org header levels to use the variable font, and be the
(let ((default-color (face-attribute 'default :foreground)))
(dolist (face '(org-level-1 org-level-2 org-level-3 org-level-4 org-level-5 org-level-6 org-level-7 org-level-8))
(set-face-attribute face nil
:foreground default-color :weight 'bold :font ha/variable-font))))
:foreground default-color :weight 'bold :font ha-variable-font))))
#+END_SRC
Next, we just need to change the header sizes:
@ -101,7 +101,7 @@ I add a hook to standard Org, and since this is a Lisp-2, I can get away with:
According to an idea by [[https://jft.home.blog/2019/07/17/use-unicode-symbol-to-display-org-mode-checkboxes/][Huy Trần]], we can prettify the list checkboxes as well:
#+BEGIN_SRC emacs-lisp
(defun ha/org-prettify-checkboxes ()
(defun ha-org-prettify-checkboxes ()
"Beautify Org Checkbox Symbol"
(push '("[ ]" . "☐") prettify-symbols-alist)
(push '("[X]" . "☒") prettify-symbols-alist)
@ -112,7 +112,7 @@ According to an idea by [[https://jft.home.blog/2019/07/17/use-unicode-symbol-to
And now we can attach it to a newly loaded org files:
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook 'ha/org-prettify-checkboxes)
(add-hook 'org-mode-hook 'ha-org-prettify-checkboxes)
#+END_SRC
To make it more distinguishable, he also changed the colors:
@ -144,21 +144,21 @@ The [[https://github.com/TonCherAmi/org-padding][org-padding]] project looks pla
#+END_SRC
However, I'm just going to have to write a function to clean this.
#+BEGIN_SRC emacs-lisp
(defun ha/remove-superfluous-org-padding ()
(defun ha-remove-superfluous-org-padding ()
(interactive)
(goto-char (point-min))
(ha/remove-org-header-padding)
(ha-remove-org-header-padding)
(goto-char (point-min))
(ha/remove-org-block-padding))
(ha-remove-org-block-padding))
(defun ha/remove-org-header-padding ()
(defun ha-remove-org-header-padding ()
;; (goto-char (point-min))
(while (re-search-forward (rx (optional bol (zero-or-more space) eol "\n")
(group bol (one-or-more "*") (one-or-more space) (one-or-more any) "\n")
(optional bol (zero-or-more space) eol "\n")) nil t)
(replace-match (match-string 1) nil :no-error)))
(defun ha/remove-org-block-padding ()
(defun ha-remove-org-block-padding ()
;; (goto-char (point-min))
(while (re-search-forward (rx (optional bol (zero-or-more space) eol "\n")
(group bol (zero-or-more space) "#+BEGIN" (one-or-more any) eol "\n"
@ -171,7 +171,7 @@ Now that is some complicated regular expressions.
* Pasting
I like the idea that I will paste HTML text from the clipboard and have it converted to org-formatted text:
#+BEGIN_SRC emacs-lisp :results silent
(defun ha/org-paste ()
(defun ha-org-paste ()
(interactive)
(if (eq system-type 'gnu/linux)
(shell-command "xclip -t text/html -o | pandoc -r html -w org" t)))

View file

@ -79,19 +79,19 @@ Hitting the ~Return~ key in an org file should format the following line based o
We begin with the interactive function that calls our code only if we are at the end of the line.
#+BEGIN_SRC emacs-lisp
(defun ha/org-return ()
(defun ha-org-return ()
"If at the end of a line, do something special based on the
information about the line by calling `ha/org-special-return',
information about the line by calling `ha-org-special-return',
otherwise, just call `org-return' as usual."
(interactive)
(if (eolp)
(ha/org-special-return)
(ha-org-special-return)
(org-return)))
#+END_SRC
And bind it to the Return key:
#+BEGIN_SRC emacs-lisp
(define-key org-mode-map (kbd "RET") #'ha/org-return)
(define-key org-mode-map (kbd "RET") #'ha-org-return)
#+END_SRC
What should we do if we are at the end of a line?
@ -104,7 +104,7 @@ What should we do if we are at the end of a line?
I really should break this function into smaller bits ...
#+BEGIN_SRC emacs-lisp
(defun ha/org-special-return (&optional ignore)
(defun ha-org-special-return (&optional ignore)
"Add new list item, heading or table row with RET.
A double return on an empty element deletes it.
Use a prefix arg to get regular RET."
@ -256,7 +256,7 @@ And turn on ALL the languages:
When I create images or other artifacts that I consider /part/ of the org document, I want to have them based on the org file, but with a prepended number. Keeping track of what numbers are now free is difficult, so for a /default/ let's figure it out:
#+BEGIN_SRC emacs-lisp
(defun ha/org-next-image-number (&optional prefix)
(defun ha-org-next-image-number (&optional prefix)
(when (null prefix)
(if (null (buffer-file-name))
(setq prefix "cool-image")
@ -274,7 +274,7 @@ When I create images or other artifacts that I consider /part/ of the org docume
To make the snippets more context aware, this predicate
#+BEGIN_SRC emacs-lisp
(defun ha/org-nested-in-plantuml-block ()
(defun ha-org-nested-in-plantuml-block ()
"Predicate is true if point is inside a Plantuml Source code block in org-mode."
(equal "plantuml"
(plist-get (cadr (org-element-at-point)) :language)))

View file

@ -324,7 +324,7 @@ Sacha had an [[https://sachachua.com/blog/2021/04/emacs-making-a-hydra-cheatshee
#+BEGIN_SRC emacs-lisp :var bindings=bindings :colnames yes :tangle no
(defvar my-lispy-bindings bindings)
(defvar ha/hydra-lispy-bindings
(defvar ha-hydra-lispy-bindings
(cl-loop for x in my-lispy-bindings
unless (string= "" (elt x 2))
collect
@ -339,7 +339,7 @@ Sacha had an [[https://sachachua.com/blog/2021/04/emacs-making-a-hydra-cheatshee
(eval
`(defhydra
,(append '(("<f14>" nil :exit t)) ha/hydra-lispy-bindings )
,(append '(("<f14>" nil :exit t)) ha-hydra-lispy-bindings )
))
(funcall defhydra