SubPar is an approximate implementation of a subset of ParEdit for CodeMirror.
SubPar is written in ClojureScript.
Here is a page that hosts a demo.
NOTE: You might have to reload the demo page to get the source code to load inside the CodeMirror.
Here are the steps I took to create the demo example.
- Started with a copy of one of the dmeo pages from CodeMirror, like this one.
- Used the CodeMirror compression page to get a minified bundle of codemirror.js, clojure.js, emacs.js (wasn't sure whether emacs was necessary but included it anyway).
- Included the resulting codemirror-compressed.js file in my page's header with a script tag.
- Included resources/public/js/subpar.core.js and resources/public/js/subpar.js. (If you find an issue and wish to investigate, you can subpar.core.debug.js instead for non-minified symbols.)
- Set the keyMap option to "subpar"
- Delimiters
- Backspace, Delete, Ctrl-D handle these: () {} [] "" \
- Delimiters are created in pairs: () {} [] ""
- Typing a closing delimiter moves past it after deleting any whitespace at the end of the current list
- Movement
- Forward: Ctrl-Alt-F
- Backward: Ctrl-Alt-B
- Backward Up: Ctrl-Alt-U
- Forward Down: Ctrl-Alt-D
- Backward Down: Ctrl-Alt-P
- Forward Up: Ctrl-Alt-N
- Barf / Slurp
- Backward Barf: Shift-Ctrl-[ or Ctrl-Alt-Right or Ctrl-]
- Forward Barf: Shift-Ctrl-] or Ctrl-Left
- Backward Slurp: Shift-Ctrl-9 or Ctrl-Alt-Left or Ctrl-[
- Forward Slurp: Shift-Ctrl-0 or Ctrl-Right
- Splicing
- Splice: Alt-S
- Splice Delete Backward: Alt-Up
- Splice Delete Forward: Alt-Down
- Indentation
- Indent Selection: Ctrl-Alt-\
Bug reports are definitely welcome. I'll need to add Cmd versions to support Mac OS.
You can change the key shortcuts by editing your copy of resources/public/js/subpar.js
The project is laid out just like the advanced example in emezeske / lein-cljsbuild. Working with this project requires the same things as the advanced example (Leiningen 1.7.0 or higher, PhantomJS).
The resources/public/js/subpar.core.js file is generated. Bug fixes and improvements should go in the following files:
- src-cljs/subpar/core.cljs (stuff related to parsing and finding things goes here)
- resources/public/js/subpar.js (stuff directly dealing with CodeMirror's API goes here, including changes to the keymap)
If src-cljs/subpar/core.cljs is changed, you can generate a new resources/public/js/subpar.core.js by compiling (or also by running the tests, see below).
The unit tests live in test-cljs. To run the unit tests, you need
PhantomJS.
$ lein cljsbuild test unit
See the phantom/unit-test.js file for more details on how PhantomJS
is configured to make this work.
See MIT License file.