I want to be able to use emacs to view log files. There are chunks in the log files that are nicely formatted text, and chunks that are formatted in XML. Is there a way of getting emacs to format and colour the XML sections as if it were in XML mode and then the rest of the file in a different mode?


Two options I'm aware of:

mmm-mode is a minor mode for Emacs that allows Multiple Major Modes to coexist in one buffer. It is well-suited to editing:

  • Preprocessed code, such as server-side Ruby, Perl or PHP embedded in HTML
  • Code generating code, such as HTML output by CGI scripts
  • Embedded code, such as Javascript in HTML
  • Literate programming: code interspersed with documentation, e.g. Noweb

[copied from the github page, I don't use it myself]

polymode is a framework for multiple major modes (MMM) inside a single Emacs buffer. It is fast and has a simple but flexible object oriented design. Creating new polymodes normally takes a few lines of code.

polymode development is more active than MMM nowadays, and I do use it regularly as it supports a combination I use out-of-the-box (R and markdown). There may be support for the combination you want; if not, it is supposed to be relatively easy to add new combinations. See the github page for more info on how to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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