Reputation: 1912
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
Upvotes: 1
Views: 115
Reputation: 28531
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.
Upvotes: 1
Reputation: 15944
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))))
Upvotes: 3
Reputation: 26094
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
.
Upvotes: 2