简体   繁体   English

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

[英]How to set the font size in Emacs?

I also want to save the font size in my .emacs file.我还想将字体大小保存在我的.emacs文件中。

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

该值的单位是1 / 10pt,因此100等于10pt,依此类推。

From Emacswiki , GNU Emacs 23 has a built-in key combination: Emacswiki中 ,GNU Emacs 23具有内置的组合键:

Cx C-+ and Cx C-- to increase or decrease the buffer text size Cx C- +Cx C--增加或减少缓冲区文本大小

Press Shift and the first mouse button. 按下Shift键和第一个鼠标键。 You can change the font size in the following way: This website has more detail. 您可以通过以下方式更改字体大小: 该网站有更多详细信息。

Mx customize-face RET default will allow you to set the face default face, on which all other faces base on. Mx customize-face RET default将允许您设置所有其他面都基于的default面。 There you can set the font-size. 在那里您可以设置字体大小。

Here is what is in my .emacs. 这是我的.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的custom-face机制编写:

;; 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")))))

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

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" . 您可以将选择的任何字体替换为"Monospace-11" The set of available options is highly system-dependent. 可用选项集高度依赖于系统。 Using Mx set-default-font and looking at the tab-completions will give you some ideas. 使用Mx set-default-font并查看制表符补全将为您提供一些想法。 On my system, with Emacs 23 and anti-aliasing enabled, can choose system fonts by name, eg, Monospace , Sans Serif , etc. 在我的系统上,启用Emacs 23和抗锯齿功能后,可以按名称选择系统字体,例如MonospaceSans Serif等。

Open emacs in X11, goto menu Options, select "set default font ...", change the font size. 在X11中打开emacs,转到菜单选项,选择“设置默认字体...”,更改字体大小。 Select "save options" in the same menu. 在同一菜单中选择“保存选项”。 Done. 做完了

zoom.cfg and global-zoom.cfg provide font size change bindings (from EmacsWiki) zoom.cfgglobal-zoom.cfg提供字体大小更改绑定(来自EmacsWiki)

  • C-- or C-mousewheel-up: increases font size. C-或C-mousewheel-up:增加字体大小。
  • C-+ or C-mousewheel-down: decreases font size. C- +或C-mousewheel-down:减小字体大小。
  • C-0 reverts font size to default. C-0将字体大小恢复为默认值。

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. 我不喜欢使用text-scale-increasetext-scale-decrease解决方案,因为装订线中的行号之后可能会被截断。

Firefox and other programs allow you to increase and decrease the font size with C-+ and C--. Firefox和其他程序允许您使用C- +和C--增大和减小字体大小。 I set up my .emacs so that I have that same ability by adding these lines of code: 我设置了.emacs,以便通过添加以下代码行来具有相同的功能:

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

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

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" , eg: FONT类似于"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. Wiki上的第一个建议中有一个额外的右括号,这导致启动时出错。 I finally noticed the extra closing parenthesis, and I subsequently corrected the suggestion on the wiki. 我终于注意到了多余的右括号,随后我更正了Wiki上的建议。 Then both of the suggestions worked for me. 然后,这两个建议对我都有效。

It all depends what you mean by change the font size. 这完全取决于更改字体大小的含义。 This EmacsWiki section provides the best and most complete information. 此EmacsWiki部分提供了最佳和最完整的信息。 It distinguishes the various cases (text scaling, frame font, buffer/frame, etc.): Changing Font Size . 它区分了各种情况(文本缩放,框架字体,缓冲区/框架等): 更改字体大小

I you're happy with console emacs (emacs -nw), modern vterm implementations (like gnome-terminal) tend to have better font support. 我对控制台emacs(emacs -nw)感到满意,现代vterm实现(例如gnome-terminal)往往具有更好的字体支持。 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. 另外,如果您习惯了这一点,则可以使用tmux,因此即使没有X,也可以在远程服务器上使用完整环境。

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

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 . 我使用hydra包通过按f2 + + + + / f2 - - - -连续控制字体的增加/减少,这意味着按f2一次,然后使用+ / -仅进行控制,并按f2 0恢复默认字体大小。 Because i have keypad, so I also bind keypad to the font setting. 因为我有键盘,所以我也将键盘绑定到字体设置。

(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. 以及以下按键绑定所支持的现代编辑器鼠标控件功能,请按Control +鼠标滚轮来增加/减少字体。

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

Here's a snippet that lets you directly specify the global font size using an interactive function: 这是一个片段,使您可以使用交互式功能直接指定全局字体大小:

(defun set-font-size ()
    "Set the font size."
  (interactive)
  (set-face-attribute
   'default nil :height
   (string-to-number
    (read-string "Font size: " (number-to-string (face-attribute 'default :height nil))))))

在NTEmacs 23.1中,“选项”菜单具有“设置默认字体...”选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM