如何更改 Emacs?默认字体大小和字体类型?

发布于 2024-11-08 01:16:00 字数 38 浏览 0 评论 0原文

我使用的是 Emacs 23.3。如何更改字体大小和字体类型?

I am using Emacs 23.3. How can I change the font size and font type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

兔小萌 2024-11-15 01:16:00

您还可以在 .emacs 文件中执行以下操作。

Emacs 23.1

(set-frame-font "Inconsolata 12" nil t)

旧版本的 Emacs

(set-default-font "Inconsolata 12" nil t)

You can also do the following in your .emacs file.

Emacs 23.1

(set-frame-font "Inconsolata 12" nil t)

Older versions of Emacs

(set-default-font "Inconsolata 12" nil t)
难忘№最初的完美 2024-11-15 01:16:00

您可以使用菜单栏。转到选项->设置默认字体...

选择字体后,不要忘记按Options->Save Options——否则关闭 Emacs 后您的新字体将不会被保存。

You can use the menu bar. Go to Options->Set Default Font....

After you choose a font, don't forget to press Options->Save Options—otherwise your new font will not be saved after you close Emacs.

你丑哭了我 2024-11-15 01:16:00

通过以下方式获取当前字体:
Mx describe-font

(如果看到字体名称(ASCII 字符的默认当前选择):,请按 Enter

这将显示可以在 init.el 中设置的属性列表。查看完这些值后,通过 Cx 1 最小化消息缓冲区。

现在执行 Mx custom-face 并:

  1. 向下滚动到“默认”部分
  2. 更改“字体系列”的值
  3. 更改“高度”的值
  4. 在“上按 Enter” State”,然后 1 = 保存以供将来的会话

或者,在 init.el 中,您可以有类似以下内容:

(set-face-attribute 'default nil :font "Monospace" :height 160)

注意: 如果您有窗口大小(宽度和高度)的预设), 这字体的 height 属性会干扰该布局。

Get current font by:
M-x describe-font

(Hit Enter if you see Font name (default current choice for ASCII chars):)

This will show a list of attributes which can be set in init.el. After you've had a look the values, minimize the message buffer by C-x 1.

Now do a M-x customize-face and:

  1. Scroll down to the "Default" section
  2. Change the value of "Font Family"
  3. Change the value of "Height"
  4. Hit Enter on "State" and then 1 = Save for Future Sessions

Alternatively, in init.el you could have something like:

(set-face-attribute 'default nil :font "Monospace" :height 160)

Note: If you have a preset for window size (width and height), the height attribute of the font is going to interfere with that layout.

空‖城人不在 2024-11-15 01:16:00

要获取自定义使用的扩展列表

Mx 定制面 RET

To get an extended list of customization use

M-x customize-face RET

硬不硬你别怂 2024-11-15 01:16:00

在我的回答中,我将集中精力通过 X 资源设置默认字体大小。 X资源的使用已经在提到~/.Xdefaults的答案中提到过;我将提供更多详细信息(与我已经在 https://unix.stackexchange.com/a/426914 中描述的内容相同) /4319. 除了 Emacs 中“默认”“face”的高度之外,还可以类似地设置其他字体参数,

我已将其放入 /etc/ 中。 X11/Xresources-site/etc/X11/Xresources 也可以,尽管可以被您的发行版覆盖):

Emacs.default.attributeHeight: 94

这也会影响 Emacs 远程 X 客户端(例如 emacs)通过 ssh 在远程主机上启动)

/etc/X11/Xresources-site/etc/X11/Xresources (可能还有 ~/.Xresources)。 code> 和 ~/.Xdefaults) 通常在 X 会话开始时读取;要立即影响当前的 X 资源,请运行 xrdb -merge /etc/X11/Xresources- X 资源可以通过 xrdb -query 来读取。

实际上,在我的例子中, /etc/X11/Xresources 中的一行(由启动脚本读取):

#include "/etc/X11/Xresources-site"

因此 /etc/X11/Xresources 是肯定会读取的内容。

还有一些具有相同语法的文件,每次启动 X 程序(如 emacs)时都会读取这些文件。就我而言,它们是: ~/.Xdefaults-MY_HOST_NAME/etc/X11/app-defaults/Emacs (仅适用于 emacs-athena,不适用于 emacs-gtk3 )、/usr/share/X11/app-defaults/Emacs 等(但我更喜欢加载 X 资源的想法——用 xrdb -query 显示;所以远程 X 客户端读取相同的 X 资源。)

Emacs 理解的其他 X 资源在 https://www.gnu.org/software/emacs/manual/html_node/emacs/Table-of-Resources.html#资源表< /a>.

Emacs 24.3 有一个错误,导致它不支持默认界面的属性来自 X 资源,例如我上面的示例。自 24.4 起,此问题已修复

In my answer, I'll concentrate on setting the default font size through X resources. The use of X resources has already been mentioned in the answer mentioning ~/.Xdefaults; I'll give more details (the same which I have already described in https://unix.stackexchange.com/a/426914/4319. Apart from the height of the "default" "face" in Emacs, one can similarly set other font parameters.

To set a specific default font height for Emacs, I have put into /etc/X11/Xresources-site (/etc/X11/Xresources is also OK, though can be overwritten by your distro):

Emacs.default.attributeHeight: 94

This would affect also remote X clients which are Emacs (e.g., emacs started on a remote host via ssh).

/etc/X11/Xresources-site and /etc/X11/Xresources (and probably ~/.Xresources and ~/.Xdefaults) are usually read at the start of your X session; to affect your current X resources immediately, run something like xrdb -merge /etc/X11/Xresources-site. The X resources can be viewed by xrdb -query.

Actually, in my case, /etc/X11/Xresources-site is being read thanks to a line in /etc/X11/Xresources (which is read by the start scripts):

#include "/etc/X11/Xresources-site"

so /etc/X11/Xresources is the thing that is read for sure.

There are also some files with the same syntax which are read each time an X program like emacs starts. In my case, they are: ~/.Xdefaults-MY_HOST_NAME, /etc/X11/app-defaults/Emacs (only for emacs-athena, not for emacs-gtk3), /usr/share/X11/app-defaults/Emacs etc. (But I like the idea of loaded X resources more -- shown with xrdb -query; so that remote X clients read the same X resources.)

Other X resources which Emacs understands are described at https://www.gnu.org/software/emacs/manual/html_node/emacs/Table-of-Resources.html#Table-of-Resources.

Emacs 24.3 had a bug which made it not honor the attributes for the default face coming from the X resources, such as in my example above. This was fixed since 24.4.

海之角 2024-11-15 01:16:00

macOS 上的 Emacs 25.1 默认使用 Menlo 12。我想增加尺寸。

Cx Cf ~/.emacs

将其添加到 ~/.emacs 文件的末尾:

(设置默认字体“Menlo 14”)

要在 ~/.emacs 中查看更改立即生效:

Mx eval-buffer [RET]

Emacs 25.1 on macOS has Menlo 12 as default. I wanted to increase the size.

C-x C-f ~/.emacs

Add this to end of the ~/.emacs file:

(set-default-font "Menlo 14")

To see the change take effect immediately while staying in ~/.emacs:

M-x eval-buffer [RET]

渡你暖光 2024-11-15 01:16:00

Emacs 方式

  1. M-x customize-group
  2. 输入 faces
  3. 点击“Basic Faces”
  4. 打开/展开“Default”
  5. 更改字体名称(如“Inconsolata”)并取消选择“foundry”
  6. 点击“应用并保存”

The Emacs way

  1. M-x customize-group
  2. Enter faces
  3. Click on "Basic Faces"
  4. Open / Expand "Default"
  5. Change the font name (like "Inconsolata") and deselect "foundry"
  6. Click "Apply and save"
无声情话 2024-11-15 01:16:00

如果您使用Linux/X11,您可能需要在~/.Xdefaults中进行设置。我
已经在那里设置了字体,因为这里的其他答案没有效果。

我可以通过在 Emacs 中运行来查看可用的字体设置:
helm-select-xfont

然后我开始输入 Conso 并看到如下条目:

-Consolas-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1
...

然后我将其放入 ~/.Xdefaults 中,设置大小12 as:

Emacs.font: xft:-*-Consolas-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1

并重新启动 Emacs。

If you use Linux/X11, you may need to set this in ~/.Xdefaults. I
have set the font there since the other answers here have no effect.

I'm able to see available font settings by running in Emacs:
helm-select-xfont

Then I start typing Conso and I see entries like:

-Consolas-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1
...

So then I put it into ~/.Xdefaults, setting size 12 as:

Emacs.font: xft:-*-Consolas-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1

and restart Emacs.

深府石板幽径 2024-11-15 01:16:00

只需按 Mx,然后输入 set-frame-font。将显示您计算机中存在的所有可用字体。

选择您要寻找的那个。我用这种方法来简单地改变我的 Emacs 中的字体类型;而不是更改 .spacemacs.emacs 文件。

Simply press M-x, and then type in set-frame-font. All available fonts which exist in your machine will be displayed.

Choose the one you look for. I use this way to change font-type in my Emacs so simply; rather than altering the .spacemacs or .emacs file.

北斗星光 2024-11-15 01:16:00

使用 customize 设置字体大小发生得太晚了,第一个
emacs 框架“闪烁”(并且可能会在屏幕边缘调整大小),
因此,在 emacs 29.4 中我添加了以下内容
~/.emacs.d/early-init.el

(when initial-window-system ;; i-w-s from stack exchange
  (add-to-list 'default-frame-alist '(font . "EmblCondHack-13")))

s/EmblCondHack/Monospace/ 应该适合每个人

Using customize to set font size happens too late and the first
emacs frame "flashes" (and may resize over the edge of a screen),
therefore, with emacs 29.4 I've added the following in
~/.emacs.d/early-init.el:

(when initial-window-system ;; i-w-s from stack exchange
  (add-to-list 'default-frame-alist '(font . "EmblCondHack-13")))

s/EmblCondHack/Monospace/ should work for everyone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文