3.9 KiB
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:
-
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.
-
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-exportE
polymode-set-exporterw
polymode-weaveW
polymode-set-weavert
polymode-tangle;; not implemented yetT
polymode-set-tangler;; not implemented yet$
polymode-show-process-buffer -
NAVIGATION
C-n
polymode-next-chunkC-p
polymode-previous-chunkC-M-n
polymode-next-chunk-same-typeC-M-p
polymode-previous-chunk-same-type -
MANIPULATION
M-k
polymode-kill-chunkM-m
polymode-mark-or-extend-chunkC-t
polymode-toggle-chunk-narrowingM-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