如何更改 Emacs?默认字体大小和字体类型?
我使用的是 Emacs 23.3。如何更改字体大小和字体类型?
I am using Emacs 23.3. How can I change the font size and font type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我使用的是 Emacs 23.3。如何更改字体大小和字体类型?
I am using Emacs 23.3. How can I change the font size and font type?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
您还可以在
.emacs
文件中执行以下操作。Emacs 23.1
旧版本的 Emacs
You can also do the following in your
.emacs
file.Emacs 23.1
Older versions of Emacs
您可以使用菜单栏。转到
选项
->设置默认字体...
。选择字体后,不要忘记按
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.通过以下方式获取当前字体:
Mx describe-font
(如果看到
字体名称(ASCII 字符的默认当前选择):
,请按Enter
)这将显示可以在 init.el 中设置的属性列表。查看完这些值后,通过
Cx 1
最小化消息缓冲区。现在执行
Mx custom-face
并:Enter
” State”,然后 1 = 保存以供将来的会话或者,在
init.el
中,您可以有类似以下内容:注意: 如果您有窗口大小(宽度和高度)的预设), 这字体的
height
属性会干扰该布局。Get current font by:
M-x describe-font
(Hit
Enter
if you seeFont 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 byC-x 1
.Now do a
M-x customize-face
and:Enter
on "State" and then 1 = Save for Future SessionsAlternatively, in
init.el
you could have something like: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.要获取自定义使用的扩展列表
To get an extended list of customization use
在我的回答中,我将集中精力通过 X 资源设置默认字体大小。 X资源的使用已经在提到
~/.Xdefaults
的答案中提到过;我将提供更多详细信息(与我已经在 https://unix.stackexchange.com/a/426914 中描述的内容相同) /4319. 除了 Emacs 中“默认”“face”的高度之外,还可以类似地设置其他字体参数,我已将其放入
/etc/ 中。 X11/Xresources-site
(/etc/X11/Xresources
也可以,尽管可以被您的发行版覆盖):这也会影响 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
中的一行(由启动脚本读取):因此
/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):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 likexrdb -merge /etc/X11/Xresources-site
. The X resources can be viewed byxrdb -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):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 withxrdb -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.
macOS 上的 Emacs 25.1 默认使用 Menlo 12。我想增加尺寸。
Cx Cf
~/.emacs
将其添加到
~/.emacs
文件的末尾:要在
~/.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:To see the change take effect immediately while staying in
~/.emacs
:M-x eval-buffer [RET]
Emacs 方式
customize-group
faces
The Emacs way
customize-group
faces
如果您使用Linux/X11,您可能需要在
~/.Xdefaults
中进行设置。我已经在那里设置了字体,因为这里的其他答案没有效果。
我可以通过在 Emacs 中运行来查看可用的字体设置:
helm-select-xfont
然后我开始输入
Conso
并看到如下条目:然后我将其放入
~/.Xdefaults
中,设置大小12
as:并重新启动 Emacs。
If you use Linux/X11, you may need to set this in
~/.Xdefaults
. Ihave 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:So then I put it into
~/.Xdefaults
, setting size12
as:and restart Emacs.
只需按
Mx
,然后输入set-frame-font
。将显示您计算机中存在的所有可用字体。选择您要寻找的那个。我用这种方法来简单地改变我的 Emacs 中的字体类型;而不是更改
.spacemacs
或.emacs
文件。Simply press
M-x
, and then type inset-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.使用 customize 设置字体大小发生得太晚了,第一个
emacs 框架“闪烁”(并且可能会在屏幕边缘调整大小),
因此,在 emacs 29.4 中我添加了以下内容
~/.emacs.d/early-init.el
: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
:s/EmblCondHack/Monospace/
should work for everyone