Emacs -- how to consolidate :lighter(s) for minor modes

elisp, emacs

Solution

You can dynamically alter the lighter value for any minor MODE by modifying `minor-mode-alist`:

(setcar (cdr (assq 'MODE minor-mode-alist)) VALUE)

When either of your modes is activated or deactivated, check the status of the other, and set the lighter text accordingly. When both are active you can make one an empty string, and the other your 'combined' lighter.

Or, better, take advantage of the fact that any mode-line construct is valid, and make it automatic. Using delight.el as a wrapper for the above, and assuming both modes are defined by `mylibrary.el` you might say:

(delight '((mode+ (mode- " ±" " +") "mylibrary")
           (mode- (mode+ "" " -") "mylibrary")))

That's not perfect -- if you want the associated pop-up menus to also combine the details of both modes, there's rather more to do; but I would recommend that you don't worry about that if you don't need to. The appearance of the mode line is the low-hanging fruit here.

Problem

Is it possible to consolidate `:lighters` on the mode-line when a certain combination of active minor modes exists? If so, then how please? Example: Minor mode number one has a :lighter of `" -"` Minor mode number two has a :lighter of `" +"` If both minor modes are active in the buffer, then consolidate lighters: `" ±"`

Original source