GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jurjanpaul/codemirror6-parinfer: CodeMirror 6 Parinfer extension

BranchesTags
Open more actions menu

Latest commit

 

History

132 Commits
132 Commits

Folders and files

NameName
Last commit message
Last commit date
cljs
cljs
 
 
docs
docs
 
 
ts
ts
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
index.html
index.html
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
rollup.config.js
rollup.config.js
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

CodeMirror 6 Parinfer extension

NPM version badge

A CodeMirror 6 extension that integrates Parinfer, which facilitates structural editing of Lisp code (Clojure code in particular) by indentation.

By default smartMode is applied, but both indentMode and parenMode can be selected as well.

Initially I used ClojureScript on Scittle to explore what was needed to get the integration to work, but the actual extension is written in TypeScript and available as ES module (with the parinfer.js dependency inlined for more convenient downstream bundling) from npmjs.com.

Try it at the demo page!

Please let me know if you have a use for this or have any feedback!

Basic usage

import { basicSetup } from 'codemirror';
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { parinferExtension } from '@jurjanpaul/codemirror6-parinfer';

const doc = `
(defn foo []
  [:bar \"baz\"])`

new EditorView({
  state: EditorState.create({
    doc,
    extensions: [basicSetup, parinferExtension()],
  }),
  parent: document.getElementById("editor")
});

API

@jurjanpaul/codemirror6-parinfer TypeScript module

parinferExtension(initialConfig?: ParinferExtensionConfig): Extension

Main entry point: initialises the extension with optional configuration.
By default Parinfer is enabled in "smart" mode.

type ParinferExtensionConfig = {
  enabled?: boolean
  mode?: ParinferMode
}
type ParinferMode = "smart" | "indent" | "paren"
configField: StateField<ParinferExtensionConfig>

CodeMirror state field with the current extension configuration.


setConfigEffect: StateEffectType<ParinferExtensionConfig>

CodeMirror state effect that can be used in a transaction to update the extension's configuration.


configureParinfer(view: EditorView, config: ParinferExtensionConfig)

Convenience wrapper around the setConfigEffect state effect.

switchMode(view: EditorView, mode: ParinferMode)

Speaks for itself. Convenience wrapper for configureParinfer.

disableParinfer(view: EditorView)

Speaks for itself. Convenience wrapper for configureParinfer.

enableParinfer(view: EditorView)

Speaks for itself. Convenience wrapper for configureParinfer.

Out of scope (at least for the foreseeable future)

  • visualising/styling the Paren Trail that parinfer includes in its result;
  • visualising the tabStops that parinfer includes in its result;
  • smart indentation (because that is now provided by the separate CodeMirror 6 Clojure Smart Indentation extension!).

Motivation

I had previously used CodeMirror 5 with Parinfer in the Away from Preferred Editor ClojureScript Playground and hoped to upgrade to CodeMirror 6 as soon as somebody would make a Parinfer extension available.

For quite a while, as a Clojure programmer I was simply too intimidated by the statically typed CodeMirror 6 module architecture to even consider taking on that task myself next to a few other side projects. But still not finding one some years after the CodeMirror 6 release, I finally found the time and motivation to take up the challenge, starting with studying TypeScript, etc.

Implementation

Some observations w.r.t. the implementation can be found here.

About

CodeMirror 6 Parinfer extension

www.npmjs.com/package/@jurjanpaul/codemirror6-parinfer

Topics

6clojurecodemirrorcodemirror6parinferscittle

Resources

Readme
MIT license
Activity

Stars

5 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.