emacselispminor-mode

enable other minor mode after calling for my node


I'd like to write minor mode that switches several other modes when run. Some kind of umbrella mode.

Now I'm stack with the simplest task - create mode that enables single other mode.

I'v wrote

(require 'whitespace)
(define-minor-mode
  myspace-mode
  "some doc"
  nil
  nil
  (if myspace-mode
    (whitespace-mode 1)
    (whitespace-mode -1)
 )
)

When I toggle this mode from M-x nothing happens. But when I evaluate directly (whitespace-mode ±1) it works as expected.

What do I miss?


Solution

  • There is one parameter missing from your definition. For this reason, your (if ...) form is actually interpreted as the keymap parameter.

    Try this:

    (define-minor-mode
      myspace-mode
      "some doc"
      nil
      nil
      nil
      (if myspace-mode
          (whitespace-mode 1)
          (whitespace-mode -1)))