1

I've got an emacs configuration file whatever.el :

(abbrev-mode +1)
(provide 'whatever)

and in my init.el :

(require 'whatever)

but when i start emacs, abbrev-mode isn't enabled. why ?

thank you

jney
  • 1,862
  • 2
  • 17
  • 21
  • I don't think I've ever seen `+` used like that, but I see it's valid (if redundant :) – phils May 17 '12 at 22:59
  • i learned it reading the code from http://github.com/bbatsov/prelude i find it very readable activating with `+1` and desactivating with `-1` – jney May 18 '12 at 08:29

3 Answers3

3

Quoting from http://emacswiki.org/emacs/AbbrevMode:

You can also put the following in your ~/.emacs file if you want it always on:

(setq default-abbrev-mode t)

If you only want it on in text and derived modes, you could do something like this:

(add-hook 'text-mode-hook (lambda () (abbrev-mode 1)))

For multiple modes, use something like the following:

(dolist (hook '(erc-mode-hook
                emacs-lisp-mode-hook
                text-mode-hook))
  (add-hook hook (lambda () (abbrev-mode 1))))
Edward Loper
  • 15,374
  • 7
  • 43
  • 52
2

Abbrev-mode is enabled per-buffer.

One way is to create a hook function that you could add to the major mode hooks you will want to use it in.

For example:

(defun my-enable-abbrev-mode ()
  (abbrev-mode 1))
(add-hook 'c-mode-hook 'my-enable-abbrev-hook)
(add-hook 'java-mode-hook 'my-enable-abbrev-hook)

Another approach is to use change-major-mode-hook.

Lindydancer
  • 25,428
  • 4
  • 49
  • 68
1

While others explained how to get what you presumably want, I'll just point out that w.r.t to your actual question ("Why?"), the reason is simple: abbrev-mode is a buffer-local minor-mode, so when you run (abbrev-mode +1) at startup it will just enable abbrev-mode in the buffer that happens to be current during evaluation of the ~/.emacs (typically scratch) but not in subsequent buffers.

Stefan
  • 27,908
  • 4
  • 53
  • 82