ChatGPT解决这个技术问题 Extra ChatGPT

emacs zoom in/zoom out

Is there a way to zoom in and out (dynamically change the font size, quite smoothly) on emacs?

Also works on emacs 24

7
7 revs, 6 users 44%

Try C-x C-+ and C-x C--; that is, Control-x Control-Minus/Control-Plus.

After one combination (C-x C-+ or C-x C--), successives + or - increase or decrease the text scale without typing C-x C- again.

Addition by sawa

I looked up the function that was assigned to the keys mentioned, and found out that they are text-scale-increase and text-scale-decrease. I added the following to my configuration file so that I can do Ctrl+Scroll to zoom in/out. It is useful.

(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)

Thanks, it helped. I will try to assign that to scroll wheel (maybe with Ctrl) on the mouse.
You can also call (text-scale-set LEVEL) if you know in advance what you want. For instance, I use this to reduce the font size in ibuffer by default: (add-hook 'ibuffer-mode-hook 'my-ibuffer-mode-hook) (defun my-ibuffer-mode-hook () (text-scale-set -1))
For smoothly zooming in and out, I can use the functions that nvm let me know. For having different display modes, phils function maybe good.
Somehow Sawa's wheel up/down command doesn't work for me, but this one does: (global-set-key (kbd "C-<wheel-up>") 'text-scale-increase) (global-set-key (kbd "C-<wheel-down>") 'text-scale-decrease)
It seems that the minus must be from the typewriter keys, not the numeric keypad.
e
elemakil

The -very nice- answer of user173973 is binding the functions to non-generic mouse events. That is to say that for example on my windows system, the binding command is not valid.

To use it on windows (or probably anywhere) you can use these generic bindings :

(global-set-key [C-mouse-wheel-up-event]  'text-scale-increase)
(global-set-key  [C-mouse-wheel-down-event] 'text-scale-decrease)

This doesn't work for me, even with (setq w32-pass-extra-mouse-buttons-to-system t). Any ideas? (I'm on Windows 7.)
I've got it now, from Xah Lee's blog, I have success with (kbd "<C-wheel-up>"). Especially, describe key with C-h k ctrl+scroll-up.
For me (on unix) this doesn't work. Only the answer of @sawa works.
S
Stacksys

This config worked for me:

(global-set-key [C-wheel-up] 'text-scale-increase)
(global-set-key [C-wheel-down] 'text-scale-decrease)

The [C-wheel-up] event also worked for me. However, I found [C-S-wheel-up] more prudent as it's not already assigned by default.
M
Micah Elliott

All windows

You'll often want to change your font size because you're showing something to others. Then you likely want all windows to zoom in (including mode-line). For this, default-text-scale is great.

I bind it as such:

(key-seq-define-global "q-" 'default-text-scale-decrease)
(key-seq-define-global "q+" 'default-text-scale-increase)

(global-set-key (kbd "C-M-_") 'default-text-scale-decrease)
(global-set-key (kbd "C-M-+") 'default-text-scale-increase)

Quick single window, and back

For a really quick heavy (16x) zoom-in, you can use: C-u C-u C-x C-+

For going to single-window mode, say for a org presentation: C-x 1

Then you can undo the single-window and return to whatever layout you had before with winner-undo: C-c <left>

Whole desktop

Relatedly, for sharing over a video call, it might be easiest to just change (lower) your desktop resolution. On linux, I pop up arandr for this before starting a sharing session.