sudeepdino008
sudeepdino008

Reputation: 3364

Enabling modes in emacs

I have just started to customize the emacs. If I want to enable some mode (globally) in emacs, I need to put some code in the .emacs file. For visual mode the code will be (global-visual-line-mode t). But the same syntax doesn't work for something like show-paren-mode. So is there any way to recognise the syntax has to be used for globally enabling a mode? Or is it something which has to be known?

Upvotes: 2

Views: 2711

Answers (3)

DavidRR
DavidRR

Reputation: 19397

Use the Emacs help system:

M-x describe-function RET show-paren-mode RET

...or use the 'Help' menu in the menu bar:

Help => Describe => Describe Function... show-paren-mode RET

,,,or the keyboard binding:

C-h f describe-function RET show-paren-mode RET

Finally, consider using the Emacs 'custom' package (M-x customize RET) which will maintain many settings in your .emacs file for you. Or for a specific option, from the menu bar:

Options => Customize Emacs => Specific Option...

Also, while typing in the minibuffer, entering zero or more characters followed by TAB will offer completion options.

Upvotes: 4

tripleee
tripleee

Reputation: 189357

The generally helpful answer is to use customize. They you don't have to know the exact syntax (or even in fact any Elisp at all); just tick the checkbox and enable for all sessions.

If you really care about the Elisp, there are regrettably three different conventions.

  • As you have discovered, many modes have something like (activate-mode) or (name-of-mode t).
  • Others have a toggle, some of which work with an optional numeric argument to not toggle, but turn on or off; (toggle-mode -1) to turn on unconditionally.
  • The mode may have a variable associated with it, so you would (setq mode-variable t) and the mode would know to activate itself. This is a marginal case.

Upvotes: 3

thecosmicorange
thecosmicorange

Reputation: 21

I believe whether a minor mode is global or not is just specific to that mode, so to answer your question, you would have to know which ones are global and which ones are buffer-specific.

I'm not really sure how to write the code to do this (I'm a little new to Emacs Lisp) but you CAN write a hook to enable a minor mode whenever you are using a specific Major mode of your choice. Check out the Emacs info pages for this one, everything is in there.

From what I understand the minor modes that aren't global are buffer-specific because they might be inconvenient (like flyspell mode when writing code :D)

Upvotes: 2

Related Questions