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: " ±"
Creating a new minor mode is really easy, it's just a matter of understanding Emacs' conventions. Mode names should end in -mode and the command for toggling the mode should be the same name. They keymap for the mode should be called mode -map and the mode's toggle hook should be called mode -hook .
Usually, the major mode is automatically set by Emacs, when you first visit a file or create a buffer (see Choosing File Modes). You can explicitly select a new major mode by using an M-x command.
The mode line is the line, usually in inverse video, at the bottom of a window in Emacs. When there is only one window, the mode line will appear directly above the echo area (where the minibuffer appears). If there are multiple windows, each window will have a mode line underneath it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With