multi-mode

Some­times it is de­sirable to have differ­ent major modes in one buffer. One such case occurs when editing com­ments in a pro­gram­ming language buffer. Here it might be de­sirable to use a totally differ­ent mode than the one used for editing the pro­gram code itself.

I have adoped this practice for editing Pro­log. The code itself is edited in pro­log-mode, whereas the com­ments are edited in LaTeX-mode.

It is de­sirable to use differ­ent modes in­stead of enhancing one mode be­cause much efford has al­ready been put in va­ri­ous modes which needs not to be duplicated.

The multi-mode minor mode pro­vides a means to accomplish such a feature.

The modes are de­scribed by initializing strings. I assume that cer­tain tokens (i.e. transition strings) indicate the places where a new mode should be entered. To de­ter­mine the mode at a point it is only neccessary to find the last transition string be­fore point.

The desired modes are de­scribed in a list of pairs or triples con­sis­ting of a transition string and a mode (a sym­bol). Optionally a function sym­bol can be spe­ci­fied which is evalu­ated to activate the desired mode. Additionally the mode in absence of preceding transition strings has to be spe­ci­fied.

Down­load

Here you can down­load the sources and do­cu­men­ta­tion.

Code for mode and do­cu­men­ta­tion
multi-mode.el, 10 kb