Nicholas Hubbard
Nicholas Hubbard

Reputation: 537

How can I run a command whenever a new buffer is opened?

I would like to have auto-complete-mode enabled by default. For some reason global-auto-complete-mode does not seem to have an effect on anything. What I have been doing to this point is manually enabling auto-complete-mode whenever I open a new buffer. What are my options here?

Upvotes: 1

Views: 337

Answers (2)

Thomas
Thomas

Reputation: 17422

global-auto-complete-mode is not as global as you may think it is. From the manual:

Enable auto-complete-mode automatically for specific modes

auto-complete-mode won't be enabled automatically for modes that are not in ac-modes. So you need to set if necessary:

(add-to-list 'ac-modes 'brandnew-mode)

Thus if you would like to have, say, all buffers that are in prog-mode or in eshell-mode to automatically have auto-complete-mode enabled, you'd have to put the following in your .emacs file:

(add-to-list 'ac-modes 'prog-mode)
(add-to-list 'ac-modes 'eshell-mode)

Upvotes: 1

Benjamin Cassidy
Benjamin Cassidy

Reputation: 837

(add-hook 'prog-mode-hook #'auto-complete-mode)

Upvotes: 1

Related Questions