如何设置Emacs中的字体大小?

时间:2022-06-29 23:12:58

I also want to save the font size in my .emacs file.

我还想保存.emacs文件中的字体大小。

16 个解决方案

#1


342  

(set-face-attribute 'default nil :height 100)

The value is in 1/10pt, so 100 will give you 10pt, etc.

它的值是1/10pt,所以100会给你10pt,等等。

#2


329  

From Emacswiki, GNU Emacs 23 has a built-in key combination:

从Emacswiki, GNU Emacs 23有一个内置的关键组合:

C-xC-+ and C-xC-- to increase or decrease the buffer text size

C-xC-+和C-xC-增加或减少缓冲文本的大小。

#3


77  

Press Shift and the first mouse button. You can change the font size in the following way: This website has more detail.

按Shift键和第一个鼠标按钮。你可以通过以下方式改变字体大小:这个网站有更多的细节。

#4


36  

M-x customize-face RET default will allow you to set the face default face, on which all other faces base on. There you can set the font-size.

M-x定制-face RET默认将允许你设置人脸默认的脸,所有其他的脸都基于此。在那里你可以设置字体大小。

Here is what is in my .emacs. actually, color-theme will set the basics, then my custom face setting will override some stuff. the custom-set-faces is written by emacs's customize-face mechanism:

这是我的。emacs。实际上,颜色主题将设置基础,然后我的自定义面板将覆盖一些东西。定制的人脸是由emacs的自定义面机制编写的:

;; my colour theme is whateveryouwant :)
(require 'color-theme)
(color-theme-initialize)
(color-theme-whateveryouwant)

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))
 '(font-lock-comment-face ((t (:foreground "darkorange4"))))
 '(font-lock-function-name-face ((t (:foreground "navy"))))
 '(font-lock-keyword-face ((t (:foreground "red4"))))
 '(font-lock-type-face ((t (:foreground "black"))))
 '(linum ((t (:inherit shadow :background "gray95"))))
 '(mode-line ((t (nil nil nil nil :background "grey90" (:line-width -1 :color nil :style released-button) "black" :box nil :width condensed :foundry "unknown" :family "DejaVu Sans Mono")))))

#5


25  

This is another simple solution. Works in 24 as well

这是另一个简单的解。也可以在24小时内工作。

(set-default-font "Monaco 14")

Short cuts:

捷径:

`C-+` increases font size
`C--` Decreases font size

#6


11  

I've got the following in my .emacs:

在我的。emacs中有以下内容:

(defun fontify-frame (frame)
  (set-frame-parameter frame 'font "Monospace-11"))

;; Fontify current frame
(fontify-frame nil)
;; Fontify any future frames
(push 'fontify-frame after-make-frame-functions) 

You can subsitute any font of your choosing for "Monospace-11". The set of available options is highly system-dependent. Using M-x set-default-font and looking at the tab-completions will give you some ideas. On my system, with Emacs 23 and anti-aliasing enabled, can choose system fonts by name, e.g., Monospace, Sans Serif, etc.

你可以为“Monospace-11”选择任何字体。可用选项集是高度依赖系统的。使用M-x set-default-font和查看表完成会给您一些建议。在我的系统中,使用Emacs 23和抗锯齿功能,可以通过名称选择系统字体,例如,Monospace、Sans Serif等。

#7


6  

Open emacs in X11, goto menu Options, select "set default font ...", change the font size. Select "save options" in the same menu. Done.

在X11中打开emacs, goto菜单选项,选择“设置默认字体…”,更改字体大小。在相同的菜单中选择“保存选项”。完成了。

#8


6  

Firefox and other programs allow you to increase and decrease the font size with C-+ and C--. I set up my .emacs so that I have that same ability by adding these lines of code:

Firefox和其他程序允许你增加和减少字体大小C-+和C-。我设置了。emacs,这样我就有了同样的能力通过添加这些代码行:

(global-set-key [C-kp-add] 'text-scale-increase)

(global-set-key [C-kp-subtract] 'text-scale-decrease)

#9


6  

zoom.cfg and global-zoom.cfg provide font size change bindings (from EmacsWiki)

变焦。cfg和global-zoom。cfg提供字体大小更改绑定(从EmacsWiki)

  • C-- or C-mousewheel-up: increases font size.
  • C——或者C- mousewheelup:增加字体大小。
  • C-+ or C-mousewheel-down: decreases font size.
  • C-+或C-mousewheel-down:减小字体大小。
  • C-0 reverts font size to default.
  • C-0返回默认的字体大小。

#10


4  

Here's an option for resizing the font heights interactively, one point at a time:

这里有一个选项,可以交互式地调整字体高度,一次一个点:

;; font sizes
(global-set-key (kbd "s-=")
                (lambda ()
                  (interactive)
                  (let ((old-face-attribute (face-attribute 'default :height)))
                    (set-face-attribute 'default nil :height (+ old-face-attribute 10)))))

(global-set-key (kbd "s--")
                (lambda ()
                  (interactive)
                  (let ((old-face-attribute (face-attribute 'default :height)))
                    (set-face-attribute 'default nil :height (- old-face-attribute 10)))))

This is preferable when you want to resize text in all buffers. I don't like solutions using text-scale-increase and text-scale-decrease as line numbers in the gutter can get cut off afterwards.

当您想在所有缓冲区中调整文本的大小时,这是可取的。我不喜欢使用文本放大和文本缩小的解决方案,因为在排水沟里的行号会被切断。

#11


3  

It all depends what you mean by change the font size. This EmacsWiki section provides the best and most complete information. It distinguishes the various cases (text scaling, frame font, buffer/frame, etc.): Changing Font Size.

这完全取决于你所说的改变字体大小。这个EmacsWiki部分提供了最好和最完整的信息。它区分了不同的情况(文本缩放、框架字体、缓冲/框架等):改变字体大小。

#12


1  

I you're happy with console emacs (emacs -nw), modern vterm implementations (like gnome-terminal) tend to have better font support. Plus if you get used to that, you can then use tmux, and so working with your full environment on remote servers becomes possible, even without X.

我喜欢控制台emacs (emacs -nw),现代的vterm实现(比如gnome-terminal)往往有更好的字体支持。此外,如果您习惯了这一点,您就可以使用tmux,因此,即使没有X,也可以在远程服务器上使用完整的环境。

#13


1  

In AquaMacs CMD + and CMD - adjust the font size for the current buffer.

在AquaMacs CMD +和CMD -调整当前缓冲区的字体大小。

#14


0  

In NTEmacs 23.1, the Options menu has a "Set default font..." option.

在NTEmacs 23.1中,选项菜单有一个“设置默认字体…”选项。

#15


0  

I use hydra package to control font increase/decrease contiguously by pressing f2 + + + +/f2 - - - -, which means that press f2 once, and then using +/- to control only, and restore default font size by f2 0. Because i have keypad, so I also bind keypad to the font setting.

我使用hydra软件包来控制字体的增加/减少,通过按f2 + + + +/f2 - - -,这意味着按f2一次,然后使用+/-来控制,并通过f2 0恢复默认字体大小。因为我有键盘,所以我也把键盘绑定到字体设置上。

(defhydra hydra-zoom (global-map "<f2>")
  "zoom"
  ("<kp-add>" text-scale-increase "in")
  ("+" text-scale-increase "in")
  ("-" text-scale-decrease "out")
  ("<kp-subtract>" text-scale-decrease "out")
  ("0" (text-scale-set 0) "reset")
  ("<kp-0>" (text-scale-set 0) "reset"))

And modern editor mouse control functionality supported by below key bindings, press control + mouse wheel to increase/decrease font.

和现代编辑器鼠标控制功能,支持以下键绑定,按控制+鼠标滚轮增加/减少字体。

(global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
(global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)

#16


0  

Aquamacs:

Aquamacs:

(set-face-attribute 'default nil :font "Monaco-16" )

From the Emacs Wiki Globally Change the Default Font, it says you can use either of these:

从Emacs Wiki全球更改默认字体,它说您可以使用其中任何一个:

(set-face-attribute 'default nil :font FONT )

(set-frame-font FONT nil t)

Where FONT is something like "Monaco-16", e.g.:

字体在什么地方像“Monaco-16”,例如:

(set-face-attribute 'default nil :font "Monaco-16" )

There was an extra closing parenthesis in the first suggestion on the wiki, which caused an error on startup. I finally noticed the extra closing parenthesis, and I subsequently corrected the suggestion on the wiki. Then both of the suggestions worked for me.

在wiki的第一个建议中有一个附加的关闭括号,这在启动时导致了一个错误。最后,我注意到附加的闭括号,随后我更正了wiki上的建议。然后这两个建议对我都有效。

#1


342  

(set-face-attribute 'default nil :height 100)

The value is in 1/10pt, so 100 will give you 10pt, etc.

它的值是1/10pt,所以100会给你10pt,等等。

#2


329  

From Emacswiki, GNU Emacs 23 has a built-in key combination:

从Emacswiki, GNU Emacs 23有一个内置的关键组合:

C-xC-+ and C-xC-- to increase or decrease the buffer text size

C-xC-+和C-xC-增加或减少缓冲文本的大小。

#3


77  

Press Shift and the first mouse button. You can change the font size in the following way: This website has more detail.

按Shift键和第一个鼠标按钮。你可以通过以下方式改变字体大小:这个网站有更多的细节。

#4


36  

M-x customize-face RET default will allow you to set the face default face, on which all other faces base on. There you can set the font-size.

M-x定制-face RET默认将允许你设置人脸默认的脸,所有其他的脸都基于此。在那里你可以设置字体大小。

Here is what is in my .emacs. actually, color-theme will set the basics, then my custom face setting will override some stuff. the custom-set-faces is written by emacs's customize-face mechanism:

这是我的。emacs。实际上,颜色主题将设置基础,然后我的自定义面板将覆盖一些东西。定制的人脸是由emacs的自定义面机制编写的:

;; my colour theme is whateveryouwant :)
(require 'color-theme)
(color-theme-initialize)
(color-theme-whateveryouwant)

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))
 '(font-lock-comment-face ((t (:foreground "darkorange4"))))
 '(font-lock-function-name-face ((t (:foreground "navy"))))
 '(font-lock-keyword-face ((t (:foreground "red4"))))
 '(font-lock-type-face ((t (:foreground "black"))))
 '(linum ((t (:inherit shadow :background "gray95"))))
 '(mode-line ((t (nil nil nil nil :background "grey90" (:line-width -1 :color nil :style released-button) "black" :box nil :width condensed :foundry "unknown" :family "DejaVu Sans Mono")))))

#5


25  

This is another simple solution. Works in 24 as well

这是另一个简单的解。也可以在24小时内工作。

(set-default-font "Monaco 14")

Short cuts:

捷径:

`C-+` increases font size
`C--` Decreases font size

#6


11  

I've got the following in my .emacs:

在我的。emacs中有以下内容:

(defun fontify-frame (frame)
  (set-frame-parameter frame 'font "Monospace-11"))

;; Fontify current frame
(fontify-frame nil)
;; Fontify any future frames
(push 'fontify-frame after-make-frame-functions) 

You can subsitute any font of your choosing for "Monospace-11". The set of available options is highly system-dependent. Using M-x set-default-font and looking at the tab-completions will give you some ideas. On my system, with Emacs 23 and anti-aliasing enabled, can choose system fonts by name, e.g., Monospace, Sans Serif, etc.

你可以为“Monospace-11”选择任何字体。可用选项集是高度依赖系统的。使用M-x set-default-font和查看表完成会给您一些建议。在我的系统中,使用Emacs 23和抗锯齿功能,可以通过名称选择系统字体,例如,Monospace、Sans Serif等。

#7


6  

Open emacs in X11, goto menu Options, select "set default font ...", change the font size. Select "save options" in the same menu. Done.

在X11中打开emacs, goto菜单选项,选择“设置默认字体…”,更改字体大小。在相同的菜单中选择“保存选项”。完成了。

#8


6  

Firefox and other programs allow you to increase and decrease the font size with C-+ and C--. I set up my .emacs so that I have that same ability by adding these lines of code:

Firefox和其他程序允许你增加和减少字体大小C-+和C-。我设置了。emacs,这样我就有了同样的能力通过添加这些代码行:

(global-set-key [C-kp-add] 'text-scale-increase)

(global-set-key [C-kp-subtract] 'text-scale-decrease)

#9


6  

zoom.cfg and global-zoom.cfg provide font size change bindings (from EmacsWiki)

变焦。cfg和global-zoom。cfg提供字体大小更改绑定(从EmacsWiki)

  • C-- or C-mousewheel-up: increases font size.
  • C——或者C- mousewheelup:增加字体大小。
  • C-+ or C-mousewheel-down: decreases font size.
  • C-+或C-mousewheel-down:减小字体大小。
  • C-0 reverts font size to default.
  • C-0返回默认的字体大小。

#10


4  

Here's an option for resizing the font heights interactively, one point at a time:

这里有一个选项,可以交互式地调整字体高度,一次一个点:

;; font sizes
(global-set-key (kbd "s-=")
                (lambda ()
                  (interactive)
                  (let ((old-face-attribute (face-attribute 'default :height)))
                    (set-face-attribute 'default nil :height (+ old-face-attribute 10)))))

(global-set-key (kbd "s--")
                (lambda ()
                  (interactive)
                  (let ((old-face-attribute (face-attribute 'default :height)))
                    (set-face-attribute 'default nil :height (- old-face-attribute 10)))))

This is preferable when you want to resize text in all buffers. I don't like solutions using text-scale-increase and text-scale-decrease as line numbers in the gutter can get cut off afterwards.

当您想在所有缓冲区中调整文本的大小时,这是可取的。我不喜欢使用文本放大和文本缩小的解决方案,因为在排水沟里的行号会被切断。

#11


3  

It all depends what you mean by change the font size. This EmacsWiki section provides the best and most complete information. It distinguishes the various cases (text scaling, frame font, buffer/frame, etc.): Changing Font Size.

这完全取决于你所说的改变字体大小。这个EmacsWiki部分提供了最好和最完整的信息。它区分了不同的情况(文本缩放、框架字体、缓冲/框架等):改变字体大小。

#12


1  

I you're happy with console emacs (emacs -nw), modern vterm implementations (like gnome-terminal) tend to have better font support. Plus if you get used to that, you can then use tmux, and so working with your full environment on remote servers becomes possible, even without X.

我喜欢控制台emacs (emacs -nw),现代的vterm实现(比如gnome-terminal)往往有更好的字体支持。此外,如果您习惯了这一点,您就可以使用tmux,因此,即使没有X,也可以在远程服务器上使用完整的环境。

#13


1  

In AquaMacs CMD + and CMD - adjust the font size for the current buffer.

在AquaMacs CMD +和CMD -调整当前缓冲区的字体大小。

#14


0  

In NTEmacs 23.1, the Options menu has a "Set default font..." option.

在NTEmacs 23.1中,选项菜单有一个“设置默认字体…”选项。

#15


0  

I use hydra package to control font increase/decrease contiguously by pressing f2 + + + +/f2 - - - -, which means that press f2 once, and then using +/- to control only, and restore default font size by f2 0. Because i have keypad, so I also bind keypad to the font setting.

我使用hydra软件包来控制字体的增加/减少,通过按f2 + + + +/f2 - - -,这意味着按f2一次,然后使用+/-来控制,并通过f2 0恢复默认字体大小。因为我有键盘,所以我也把键盘绑定到字体设置上。

(defhydra hydra-zoom (global-map "<f2>")
  "zoom"
  ("<kp-add>" text-scale-increase "in")
  ("+" text-scale-increase "in")
  ("-" text-scale-decrease "out")
  ("<kp-subtract>" text-scale-decrease "out")
  ("0" (text-scale-set 0) "reset")
  ("<kp-0>" (text-scale-set 0) "reset"))

And modern editor mouse control functionality supported by below key bindings, press control + mouse wheel to increase/decrease font.

和现代编辑器鼠标控制功能,支持以下键绑定,按控制+鼠标滚轮增加/减少字体。

(global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
(global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)

#16


0  

Aquamacs:

Aquamacs:

(set-face-attribute 'default nil :font "Monaco-16" )

From the Emacs Wiki Globally Change the Default Font, it says you can use either of these:

从Emacs Wiki全球更改默认字体,它说您可以使用其中任何一个:

(set-face-attribute 'default nil :font FONT )

(set-frame-font FONT nil t)

Where FONT is something like "Monaco-16", e.g.:

字体在什么地方像“Monaco-16”,例如:

(set-face-attribute 'default nil :font "Monaco-16" )

There was an extra closing parenthesis in the first suggestion on the wiki, which caused an error on startup. I finally noticed the extra closing parenthesis, and I subsequently corrected the suggestion on the wiki. Then both of the suggestions worked for me.

在wiki的第一个建议中有一个附加的关闭括号,这在启动时导致了一个错误。最后,我注意到附加的闭括号,随后我更正了wiki上的建议。然后这两个建议对我都有效。