2011-11-22 37 views
1

我想配置Emacs的,以便它具有:改變Emacs的默認字體大小和新的緩衝區文本

  1. 增加默認字體大小。目前我使用Shift + 點擊每次打開一個文件就改變它,但我希望我的配置保存到emacs配置文件中。

  2. 我希望在打開要更改的新緩衝區時出現默認文本。我假設它會像默認打開的一些模板。這裏是我希望看到的作爲默認文本的代碼,當我啓動emacs時,我可以直接處理它。

    #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; 
    } 
    
+0

對不起,我無法很好地格式化代碼。我在這裏還是新手。請格式化,並告訴我正確的方法來完成它。 – uyetch

+0

在emacs中設置字體:http://stackoverflow.com/questions/6026713/how-do-i-change-emacs-default-font-size-and-font-type – Patrick

+0

並初始化臨時消息:http:// stackoverflow .com/questions/1498258/how-do-i-change-the-scratch-message-in-emacs – Patrick

回答

1

有更好的方法來插入模板,但是這應該爲你做的伎倆。顯然,自定義字體到你想要的。

將下面的代碼在你的.emacs,它可以在你的home目錄中找到,或通過做C-X C-F〜/的.emacs RET(和一堆其他位置是可能的,看到這些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; 
}") 
+0

感謝您的回答,但您能否告訴我在哪裏(以及如何)保存此內容。 – uyetch

+0

有一個名爲''.emacs''的文件,它位於$ HOME文件夾中。這個文件在你啓動emacs時被評估。如果您在шiпdoшs上,請嘗試查找像HOME或PATH這樣的系統變量,並在該文件夾中創建文件。 – desudesudesu

+0

謝謝它幫助我! – uyetch

0

要更改默認字體(大小),不只是第一個,但每個Emacs框架(即更常見的術語窗口),在您的.emacs使用:

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

(當然與所需的字體和大小替換Terminus 10

0

使用掛鉤,只要你創建一個新的文件,以指定所需的文本:

(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) 
相關問題