0

My minor-mode is inserting text in the current buffer. I want the default format of the text to be different depending on what major-mode the buffer is in, and to allow the user to override this format for different mode, with some default format to fall back to when nothing specific has been configured for the current major-mode.

While I can think of ways of doing that, like an alist that maps from major-mode to a function that inserts the text, maybe there already exists a convention for how minor-modes are expected to do this?

1

1 Answer 1

0

While I can think of ways of doing that, like an alist that maps from major-mode to a function that inserts the text, maybe there already exists a convention for how minor-modes are expected to do this?

No, as far as I know there's no such convention.

And it's hard to guess what convention there might be, since how you might want your minor mode to depend on the major mode isn't clear from your question. If you're just asking how to specify conditional minor-mode behavior, in this case conditional on what the major mode is, then what you describe sounds as good as it gets: test the major mode and evaluate the corresponding minor-mode code that gives the behavior you want for that major mode.

1
  • As the question mentioned, my minor-mode inserts text. Could be a list of numbers for instance, and there are many ways to format that depending on what type of text is in the buffer. I thought about this some more after posting the question and one possibility might be some kind of buffer-local variable that can be set in hooks for different major-modes. That, I think, would also allow users to override the format in specific buffers, which would be more flexible than my original idea of a mapping for different major-modes only. But I would still want a good default for some popular modes.
    – pelle
    Commented Oct 18, 2023 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.