/subpar

subset of ParEdit for CodeMirror

Primary LanguageJavaScriptMIT LicenseMIT

SubPar

SubPar is an approximate implementation of a subset of ParEdit for CodeMirror.

SubPar is written in ClojureScript.

Demo

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.

Usage

Here are the steps I took to create the demo example.

  1. Started with a copy of one of the dmeo pages from CodeMirror, like this one.
  2. 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).
  3. Included the resulting codemirror-compressed.js file in my page's header with a script tag.
  4. 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.)
  5. Set the keyMap option to "subpar"

Features / Keys

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

Customization

You can change the key shortcuts by editing your copy of resources/public/js/subpar.js

Making Changes

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:

  1. src-cljs/subpar/core.cljs (stuff related to parsing and finding things goes here)
  2. 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).

Running the Tests

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.

License

See MIT License file.