1

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;
    }
    
Michael Hoffman
  • 32,526
  • 7
  • 64
  • 86
uyetch
  • 2,150
  • 3
  • 28
  • 33
  • 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 Nov 22 '11 at 23:16
  • Set font in emacs: http://stackoverflow.com/questions/6026713/how-do-i-change-emacs-default-font-size-and-font-type – Patrick Nov 22 '11 at 23:27
  • And initial scratch message: http://stackoverflow.com/questions/1498258/how-do-i-change-the-scratch-message-in-emacs – Patrick Nov 22 '11 at 23:31

3 Answers3

1

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;
}")
Community
  • 1
  • 1
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • Thanks for the answer, but can you tell me where( and how) do I save this. – uyetch Nov 22 '11 at 23:23
  • There is a file called ``.emacs``, it's in your $HOME folder. This file is evaluated when you start emacs. If you are on шiпdoшs, try to look for system variables like HOME or PATH, and create file in that folder. – desudesudesu Nov 22 '11 at 23:33
0

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

Rörd
  • 6,556
  • 21
  • 27
0

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)
jarodeells
  • 356
  • 1
  • 5
  • 14