Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a simple way to combine two Emacs major modes, or to change an existing mode?

In Emacs, I'm working with a file that is a hybrid of two languages.

Question 1: Is there a simple way to write a major mode file that combines two major modes?

Details:

  • The language is called "brew" (not the "BREW" of "Binary Runtime Environment for Wireless").

  • brew is made up of the languages R and Latex, whose modes are R-mode and latex-mode.

  • The R code appears between the tags <% and %>. Everything else is Latex.

  • How can I write a brew-mode.el file? (Or is one already available?)

One idea, which I got from this posting, is to use Latex mode, and treat the code of the form <% ... %> as a comment.

like image 963
Winston C. Yang Avatar asked Apr 29 '10 14:04

Winston C. Yang


People also ask

How do I change my major mode in Emacs?

You can change to a different major mode by executing its command. For TextMode (indicated by “Text” in the mode-line), for example, do 'M-x text-mode' . You can use 'C-h m' for help on the current major mode, and 'C-h b' to see all the bindings in effect.

What are Emacs modes?

A mode is a set of definitions that customize Emacs behavior in useful ways. There are two varieties of modes: minor modes, which provide features that users can turn on and off while editing; and major modes, which are used for editing or interacting with a particular kind of text.

What is the default mode of Emacs?

The standard default value is fundamental-mode . If the default value is nil , then whenever Emacs creates a new buffer via a command such as C-x b ( switch-to-buffer ), the new buffer is put in the major mode of the previously current buffer.

How do I enable minor mode in Emacs?

If you invoke the mode command directly with no prefix argument (either via M-x , or by binding it to a key and typing that key; see Customizing Key Bindings), that toggles the minor mode. The minor mode is turned on if it was off, and turned off if it was on.


1 Answers

A number of folks have written solutions enabling you to use multiple major modes at once. See the Emacs Wiki for Multiple Modes. I personally have no experience with them and cannot recommend one over another.

like image 98
Trey Jackson Avatar answered Oct 05 '22 07:10

Trey Jackson