Background:
I am creating a secondary mode that gives the user “hints” about whether they use the buffer they visit for tabs or spaces for indentation (just by looking at the first character of each line in the buffer). Some functions that I plan to add include an information display in the mode line and several functions for switching between using tabs or spaces, tab widths, etc.
I'm not interested in the usefulness of this secondary mode. In fact, I would be surprised if there wasn’t something that does the same. This is mainly an exercise when writing secondary modes.
Question:
What will be the clean, unobtrusive way to insert / remove text from the mode line when turning on / off my secondary mode? I do not want the user to change their mode-line-format , I just want to not destroy the text and delete it . Right now I'm using a function that looks something like this:
(defun update-indent-hints-mode-line (what-this-buffer-loves) (let ((indent-hints-mode-line-text (concat " " "[" what-this-buffer-loves "-loving" "]")) (my-mode-line-buffer-identification (remq " [Tab-loving]" (remq " [Space-loving]" mode-line-buffer-identification)))) (setq mode-line-buffer-identification (add-to-list 'my-mode-line-buffer-identification indent-hints-mode-line-text t)) (force-mode-line-update)))
It works fine, but finding and removing "[Tab-loving]" and "[Space-loving]" seems pretty hacky and ugly ... Is there a cleaner way to do this?
Bonus points: Any comments on the humble beginnings of my equally modest minor mode: https://github.com/mgalgs/indent-hints-mode/blob/master/indent-hints.el I am obviously elisp n00b, but I am here , in order to study.
source share