Polymode is an emacs package that offers generic support for multiple major modes inside a single emacs buffer. It is lightweight, object oriented and highly extensible. Creating new polymodes typically takes a few lines of code.
Polymode also provides extensible facilities for external literate programming tools for exporting, weaving and tangling.
Note: Oldest supported Emacs version is 24.4
git clone https://github.com/vitoshka/polymode.git
Add "polymode" directory and "polymode/modes" to your emacs path:
(setq load-path (append '("path/to/polymode/" "path/to/polymode/modes") load-path))
Require any polymode bundles that you are interested in. For example:
(require 'poly-R) (require 'poly-markdown)
Activation of Polymodes
Polymodes are functions, just like ordinary emacs modes. The can be used in place of emacs major or minor modes alike. There are two main ways to automatically activate emacs (poly)modes:
By registering a file extension by adding modes to
;;; MARKDOWN (add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode)) ;;; R modes (add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode)) (add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode)) (add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
See polymode-configuration.el for more examples.
By setting local mode variable in you file:
// -*- mode: poly-C++R -*-
## -*- mode: poly-brew+R; -*-
All polymode keys start with the prefix defined by
default is M-n. The
polymode-mode-map is the parent of all
polymode-tangle;; not implemented yet
polymode-set-tangler;; not implemented yet
- Tested with Emacs 24.3.1 and 24.4.5.
Some things still don't work as expected. For example:
- To kill a polymode buffer you will have position the cursor in the host mode buffer.
- Customization interface is not working as expected (an eieio bug) and is not even tested.
- Indentation and font-lock is not always right and requires some more
tweaking. This is especially true for complex modes like
Developing with Polymode
For the relevant terminology and development info see these docs.