Having a Parinfer implementation written in Emacs Lisp allows Parinfer to reach Emacs users easily.
Please note that this project is solely for the library that implements the core Parinfer algorithm; it is not an Emacs extension that can be used for editing.
This is basically a 1-to-1 port of parinfer.js.
This is my first Emacs Lisp project. There is likely lots of room for improvement in this implementation. PR's welcome :)
This library is namespaced under
It is expected that extension authors will use the namespace
It exposes two public functions:
(parinferlib-indent-mode txt options)
(parinferlib-paren-mode txt options)
txt should be a string of the text you want to process. Optional
should be a Property List (plist) with the following keys:
:cursor-line- zero-based line number of the cursor
:cursor-x- zero-based x-position of the cursor
:cursor-dx- amount that the cursor moved horizontally if something was inserted or deleted (only used by Paren Mode)
nil, when set to
tin Indent Mode, it shows the cursor's scope on an empty line by inserting close-parens after it (read more here)
The return value is a plist with keys:
nil, indicating if the input was properly formatted enough to create a valid result
:text- a string, is the full text output (this is just the original text if
:cursor-x- the new x-position of the cursor (since Parinfer may shift it around)
:changed-lines- a vector of plists representing only the lines Parinfer changed, plist keys are:
:line-no- zero-based line number
:line- full text of the line
:error- a plist if
:name- the name of the error
:message- a message describing the error
:line-no- a zero-based line number where the error occurred
:x- a zero-based column where the error occurred
:tab-stops- a vector of plists representing Tab stops. Only populated in Indent Mode when a cursor position is supplied. plist keys are:
:x- a zero-based x-position of the tab stop
:line-no- a zero-based line number of the open-paren responsible for the tab stop
:ch- the character of the open-paren responsible for the tab stop (e.g.
This library closely mirrors the parinfer.js API. Please see there for more information.
To run tests:
emacs --script test.el
To test performance:
emacs --script perf.el