1
votes

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;
    }
    
3
Sorry, I could not format the code well. I am still new here. Please format it and also tell me the correct way to get it done properly.uyetch
And initial scratch message: stackoverflow.com/questions/1498258/…Patrick

3 Answers

1
votes

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;
}")
0
votes

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.)

0
votes

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)