Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

elisp

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: " ±"

like image 624
lawlist Avatar asked May 29 '14 23:05

lawlist


People also ask

How do I create a minor mode in Emacs?

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 .

How do I set mode in Emacs?

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.

What is the mode line in Emacs?

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.


1 Answers

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.

like image 106
phils Avatar answered Oct 13 '22 00:10

phils