Object oriented framework for multiple emacs modes based on indirect buffers
Emacs Lisp

readme.md

unstable

Overview

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.

Installation

Note: Oldest supported Emacs version is 24.4

From MELPA

M-x package-install polymode.

Manually

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:

  1. By registering a file extension by adding modes to auto-mode-alist:

    ;;; 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.

  2. By setting local mode variable in you file:

// -*- mode: poly-C++R -*-
or
## -*- mode: poly-brew+R; -*-

Basic Usage

All polymode keys start with the prefix defined by polymode-prefix-key, default is M-n. The polymode-mode-map is the parent of all polymodes' maps:

  • BACKENDS

    e polymode-export

    E polymode-set-exporter

    w polymode-weave

    W polymode-set-weaver

    t polymode-tangle ;; not implemented yet

    T polymode-set-tangler ;; not implemented yet

    $ polymode-show-process-buffer

  • NAVIGATION

    C-n polymode-next-chunk

    C-p polymode-previous-chunk

    C-M-n polymode-next-chunk-same-type

    C-M-p polymode-previous-chunk-same-type

  • MANIPULATION

    M-k polymode-kill-chunk

    M-m polymode-mark-or-extend-chunk

    C-t polymode-toggle-chunk-narrowing

    M-i polymode-insert-new-chunk

Warnings

  • 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 c-mode.

Developing with Polymode

For the relevant terminology and development info see these docs.

Screenshots

slim

markdown+R

markdown+R+YAML

org mode

Ess-help buffer

C++R