1

I am using the Emacs editor, and every time I start Emacs, I lose my previous settings.

For example, every time I have to type:

  • M-x cua-mode RET
  • M-x auto-complete-mode RET

How can I save my settings in Emacs?

Thanks.

phils
  • 71,335
  • 11
  • 153
  • 198
hrishikeshp19
  • 8,838
  • 26
  • 78
  • 141
  • I googled the subject and top 5 results resolve this. Can you explain why you couldn't google this yourself? I'm actually curious and not just trying to be snarky. – event_jr Jan 15 '12 at 06:48

3 Answers3

5

You can add them to your .emacs file.

(cua-mode)
(auto-complete-mode)

If you find that there are already things in your .emacs file, then you might want to add the commands at the end.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
  • 5
    In general you want to be explicit about whether you are turning a mode on or off, as most modes *toggle* their state when no argument is supplied. So you probably want to use `(cua-mode 1)` and `(auto-complete-mode 1)` (although the latter is not a default part of Emacs, so I haven't verified that one). – phils Jan 15 '12 at 00:05
  • Would `t` work as well? e.g. I have `(setq inhibit-splash-screen t)` in my .emacs file. I guess I'm asking if t and 1 are equivalent. – BillRobertson42 Jan 15 '12 at 00:57
  • 1
    No, `t` and `1` are not equivalent. That is not to say that they won't sometimes have the same effect, but it's certainly not a guarantee. `t` means True (with `nil` meaning False), but you should check the documentation to be certain of the valid values for a given variable or function argument. For your example, `C-h v inhibit-splash-screen RET` tells us that *any* non-`nil` value will prevent the splash screen from showing. For the mode functions, a value of `0` usually disables the mode (`nil` would toggle), so even if `t` also enables, it seems more consistent to also use a number. – phils Jan 15 '12 at 03:38
  • 1
    I see that in Emacs 24, the `define-minor-mode` macro now makes calling a minor mode function without an argument from lisp (i.e. non-interactively) equivalent to `(mode-function 1)`. Perhaps to avoid this very issue. – phils Jan 15 '12 at 03:47
  • Thanks for the answer. I think I should have read the user manual. – hrishikeshp19 Jan 15 '12 at 14:23
4

The best answer I can think of is to point you at the manual:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Customization.html

In particular, see the sections on "Easy Customization" and the "Init File"; but I would recommend at least skimming over everything in this section.

phils
  • 71,335
  • 11
  • 153
  • 198
0

In your emacs directory there is a site-lisp folder. Normally it will be empty. you could create a file default.el in this folder. Add these two lines (cua-mode t) (auto-complete-mode) and save it.This will be executed during Init. If you want to set environment variables for your emacs application only(not permanent) add a file called site-start.el in the site-lisp directory and define value for that variable ex:(setenv "VARIABLENAME" "value"). The site-lisp directory is in the standard search path for Lisp library.

Asha
  • 1
  • `default.el` is not the way to save user-specific settings. If you place it in the site-lisp directory then it will affect *all* users on the machine (this being its purpose). If you put it a directory which is added to your path by your own user init file, then there's no point -- you could have just used your init file. See the details in the manual under "Init File", as linked in the accepted answer. – phils Jun 13 '13 at 23:32