更改 Emacs 默认字体大小和新的缓冲区文本

发布于 2024-12-17 16:01:31 字数 533 浏览 7 评论 0原文

我想配置 Emacs,使其具有:

  1. 增加默认字体大小。目前,我每次打开文件时都使用 Shift+Click 来更改它,但我希望将我的配置保存到 emacs 配置文件中。

  2. 我希望在打开要更改的新缓冲区时显示默认文本。我认为它就像默认打开的某些模板。这是我希望在启动 emacs 时将其视为默认文本的代码,以便我可以直接对其进行操作。

    #include ;
    #include ;
    #include 
    #include ;
    #include ;
    #include ;
    #include ;
    
    int main(int argc, char *argv[])
    {
       返回0;
    }
    

I want to configure Emacs so that it has:

  1. Increased default font size. Currently I use Shift+Click to change it every time I open a file, but I want my configurations saved to the emacs config file.

  2. I wanted to have the default text that appears while I open a new buffer to be changed. I assume it would be like some template that opens by default. Here is the code which I would like to see as the default text when I start emacs, so that I can directly work on it.

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <errno.h>
    #include <pthread.h>
    
    int main(int argc, char *argv[])
    {
       return 0;
    }
    

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

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

发布评论

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

评论(3

月寒剑心 2024-12-24 16:01:34

要更改默认字体(大小),不仅要更改第一个,还要更改每个 Emacs 框架(即更常见的术语中的窗口),请在 .emacs 中使用它:(

(setq default-frame-alist
      '((font . "Terminus 10")))

当然,替换 Terminus 10 使用您想要的字体和大小。)

To change the default font (size) not just for the first, but each Emacs frame (i.e. window in more common terms), use this in your .emacs:

(setq default-frame-alist
      '((font . "Terminus 10")))

(Of course, replace Terminus 10 with your desired font and size.)

只是一片海 2024-12-24 16:01:34

每当您创建新文件时,请使用挂钩指定所需的文本:

(defun cpp-file-not-found ()`
  (if (or (equal (file-name-extension (buffer-file-name)) "cpp")
      (equal (file-name-extension (buffer-file-name)) "cxx")
      (equal (file-name-extension (buffer-file-name)) "cc")
      (equal (file-name-extension (buffer-file-name)) "C")
      (equal (file-name-extension (buffer-file-name)) "c")
      )
      (progn
        (goto-char 1)
        (insert "#include <stdio.h>\n")
        (insert "int main (int argc, char *argv[]) {\n")
        (insert "  return 0;\n")
        (insert "}\n")
        )
    )
  )
(add-hook 'find-file-not-found-functions 'cpp-file-not-found)

Use a hook to specify the desired text whenever you create a new file:

(defun cpp-file-not-found ()`
  (if (or (equal (file-name-extension (buffer-file-name)) "cpp")
      (equal (file-name-extension (buffer-file-name)) "cxx")
      (equal (file-name-extension (buffer-file-name)) "cc")
      (equal (file-name-extension (buffer-file-name)) "C")
      (equal (file-name-extension (buffer-file-name)) "c")
      )
      (progn
        (goto-char 1)
        (insert "#include <stdio.h>\n")
        (insert "int main (int argc, char *argv[]) {\n")
        (insert "  return 0;\n")
        (insert "}\n")
        )
    )
  )
(add-hook 'find-file-not-found-functions 'cpp-file-not-found)
鹿港巷口少年归 2024-12-24 16:01:33

有更好的方法来插入模板,但这应该可以满足您的需要。显然将字体定制为您想要的。

将以下代码放入您的 .emacs 中,该代码可以在您的主目录中找到,或者通过执行 Cx Cf ~/.emacs RET (还有许多其他位置)如果可能,请参阅这些SO问题)。

(setq inhibit-startup-message t)
(switch-to-buffer "temp")
(set-frame-font "courier-16")
(insert "#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <pthread.h>

int main(int argc, char *argv[])
{
   return 0;
}")

There are better ways to insert a template, but this should do the trick for you. Obviously customize the font to what you want.

Put the following code in your .emacs, which can be found in your home directory, or by doing C-x C-f ~/.emacs RET (and a bunch of other locations are possible, see these SO questions).

(setq inhibit-startup-message t)
(switch-to-buffer "temp")
(set-frame-font "courier-16")
(insert "#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <pthread.h>

int main(int argc, char *argv[])
{
   return 0;
}")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文