views:

149

answers:

1

According to the emacs info page, here's how you enable iswitchb-mode:

To enable Iswitchb mode, type M-x iswitchb-mode, or customize the variable iswitchb-mode to t

So I put the following in my .emacs:

(setq iswitchb-mode t)

However, this doesn't seem to work. After searching the emacs wiki, I found that I need to use this:

(iswitchb-mode 1)

Could someone explain why I need to enable it this way? I'd like to get a better understanding of elisp rather than just copying and pasting things from places.

+6  A: 

Typically a mode will define both a variable and a function with the same name. The function will set the variable properly when it's called, but it's the function that turns on the mode, not just the variable (that only tracks the mode's state).

In your specific case, you were told told customize the variable, but you simply set it instead. The difference is that when the value of the variable changes, custom knows to do something and `setq' knows nothing of this. If you look at the help for this variable (C-h v iswitchb-mode) you'd get:

iswitchb-mode is a variable defined in `iswitchb.el'.
Its value is t

Documentation:
Non-nil if Iswitchb mode is enabled.
See the command `iswitchb-mode' for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `iswitchb-mode'.

You can customize this variable.
Joe Casadonte
Thank you. I wasn't aware of all of this about elisp.
Jason Baker
Unfortunately, it's not that easy to deduce (aside from the variable's description). iswitchb (and most minor modes) use a macro `define-minor-mode' to take care of the actual mechanics of constructing the mode, turning it on and off, customizing variables, keymaps and the like, so you have to dig into the function definition of `define-minor-mode' itself to glean how this stuff is put together.
Joe Casadonte