parinfer / parinfer.js Goto Github PK
View Code? Open in Web Editor NEWLet's simplify the way we write Lisp
Home Page: https://shaunlebron.github.io/parinfer
License: MIT License
Let's simplify the way we write Lisp
Home Page: https://shaunlebron.github.io/parinfer
License: MIT License
Looks like someone from Microsoft is working on a Parinfer extension for Visual Studio Code.
Need to add this to the Parinfer webpage.
It's a bit strange to dedent this line and not see the change until leaving the line:
<[:div]
[:h1 "title"]
Since we only prevent stripping delimiters on the current line to allow us to insert tokens after them, I think we only need to prevent stripping ones appearing after the cursor.
just a code mirror integration problem, not the algorithm
if change is insertion, place cursor after the first occurrence of that character starting at the previous cursor position
In the first example [1], change the :div
to a :span
:
(defn component []
(html)
[:span {:style {:background "#FFF"
:color "#000"}}]
[:h1 "title"])
It is now difficult to get the keywords to line up in the map literal.
right now, I think the state returned by process-text-change
is unstable if the input is invalid (i.e. unclosed quote).
I think this will be good for giving the user freedom to create a closing paren before an open paren if they want. We can just highlight it red until they match it, like editors will commonly do.
I've been working with hiccup this week and I found a problem in insert mode that keeps biting me. I'm not sure if #49 is describing existing bugs or just trying to find a better way of handling this stuff, but I wanted to raise an issue for this because it's coming up so often in my codebase.
Here's the test-case
in
(for [col columns]
"|
[:div.td {:style "max-width: 500px;"}])
out
(for [col columns]
"
[:div.td {:style "max-width: 500px;"}])
The test error is
expected----------------------------------
(for [col columns]
"
[:div.td {:style "max-width: 500px;"}])
actual------------------------------------
(for [col columns]
"
[:div.td {:style "max-width: 500px);"}])
expected: "(for [col columns]\n \"\n [:div.td {:style \"max-width: 500px;\"}])"
actual: "(for [col columns]\n \"\n [:div.td {:style \"max-width: 500px);\"}])"
diff: - "(for [col columns]\n \"\n [:div.td {:style \"max-width: 500px;\"}])"
+ "(for [col columns]\n \"\n [:div.td {:style \"max-width: 500px);\"}])"
supporting this can have an effect on #39, in that we might have to just handle changes sequentially
Starting this issue to track separation of "Parinfer the library" from "Parinfer the website".
Specifically, I'm looking for a library version of Parinfer in order to create an Atom editor plugin that will allow it's use.
editors waiting on this:
need a way to expose parinfer-lib to JS. @oakmac, could you reiterate your thoughts on this?
when multiple lines are selected:
only advances the cursor one character, but inserts two spaces ahead of it
(defn foo
[a b
(let [x (+ a b
x
( ( [ (
x
should be able to quickly move between the valid indentation levels listed above.
Looks like someone's working on an extension for Visual Studio Code. I'm not quite sure how to make it work yet, though.
this will signal to the user that these are not in stone, and can be reposition by indented lines
will have to implement a new clojure mode in CodeMirror to highlight them differently
this allows us to type matching right-parens at the start of a line without them disappearing
the API may have to return the corrected cursor position under the following circumstances:
we can add this to the test case output blocks with a pipe |
.
There are two extra features related to auto-indentation that Parinfer users are starting to expect. Parinfer may grow in scope to handle these cases somehow, or we will have to detail how this can be handled external to it:
Specifically, @snoe and @SevereOverfl0w expect the following from item 1: when pressing enter at the end of the last line:
(defn foo [a b]
(let [x (+ a b)]
x))|
They expect the cursor to be at the following position:
(defn foo [a b]
(let [x (+ a b)]
x))
|
This behavior is handled in vim by using a mode called autoindent
(seen here), which trivially copies the indentation of the previous line.
The behavior for item 2 can be handled by vim-clojure-static
, which defines configurable rules for how to indent forms.
These two modes conflict with each other inside vim, so a solution to this problem must combine them when appropriate.
Hi Shaun, I've decided this will be a great way to work on my elisp chops so I'm working on emacs-parinfer which is planned to be a minor mode for emacs. Depending on how much work I get done over the coming holiday I might be at a point of making code public in a week or so. Thanks for all the work you have done so far!
Roger
There seems to a necessity for a separate mode when performing certain edits. Given this:
(defn foo [a b]
(+ a b))
Prepending the first line with an ignore form macro in infer-mode, gives this:
#_(defn foo [a b])
(+ a b)
whereas, we want this instead:
#_(defn foo [a b]
(+ a b))
I think this is the job for the prep function during live editing. We will have to extend the prep function to accept a cursor position and cursor delta (maybe just previous cursor position to compute delta). The delta is required so we can preserve relative indentation of expressions after the cursor (we can just add the cursor delta to the indent-delta
line data at the cursor). This could get tricky for selection-based editing. Just keep it simple with cursor for now.
I'd be interested in making a Parinfer bundle for Howl, but Howl's written in MoonScript and can't interface easily with Clojure. Would it be possible to have a sockets-based API to allow other editors to access Parinfer?
If I have the following string:
"]"
And I insert a quote at the beginning of this line, I end up with this:
"""
This happens because it considers ]
to be code now. And since we disallow unmatched closing delims, it is erased.
I am not sure how to solve this problem:
introducing this extra complexity may result in the antithesis of my objective for an approachable lisp.
We can describe all text changes with this model: https://github.com/shaunlebron/parinfer/blob/master/test-cases/text-change.md
but right now, the parinfer api requires us to specify changes differently depending on the mode:
this requires a lot of manual work on the api user, so if we simply accept a change object described by the above link (which I think most editors expose on change events), we can offload this work to the modes themselves.
This should be done before #24 (creating the standalone parinfer-lib)
we currently don't remove whitespace here, represented as an underscore:
(def b_)
(def b)_
but we do remove whitespace between close-parens:
(def b []_)
(def b [])
<-- whitespace removedNeed to be consistent about this
This would be fantastic for Light Table and all of the Lispy languages our users use.
Light Table uses Code Mirror internally so maybe this isn't too hard.
I waited too long to write these down and it's not fresh on my mind anymore, but here are some suggestions from clojure conj folks:
But I'm now recalling a goal which seems to prevent these from working: we want to preserve reversibility. Imagine commenting and uncommenting a line of code. In my mind, the resulting line shouldn't be different (i.e. 1 and 4 below should be the same):
We have a line with a quote:
"foo
We comment it out:
; "foo
Quote fixer escapes it
; \"foo
Uncomment
\"foo
We also talked about how the source of the problem is that quotes are non-directional, and how their meaning is dependent on the number of quotes before it, allowing strings to be turned inside out when parity changes. svmbrown proposed that we imagine how chaotic this would be if parens were non-directional.
needs to hold parens on the right side of the cursor
each format function returns the full text, but we may want to return only an index of lines that have changed
right now, process-text-change
will process until the end of the file if an imbalanced quote is inserted. we could probably track the number of unescaped quotes (in both code and comment) per line to cutoff processing. not sure though
possible that we need to share a cm instance:
It would be nice to know the license for this through a LICENSE file or at least in the README.md. If there's a license in the source I haven't found it yet.
don't use the editor for the quick look. it doesn't communicate the essence of the idea. we need to show the parens actually moving with css transitions. We can do that by scripting a simple css animation.
\,))
is being transformed to this
\)),
whitespace?
function doesn't consider that \,
is a literal character not the whitespace comma.
problem is that escape state can be checked prior to push-char, but not after.
need a lot of ecape char tests
the publish script somehow pushed out a development build
I put together a plugin for neovim, it's super early but I'd love to get feedback or have some people try it out. This is an amazing tool, thank you!
Editor is slow for large enough files. Need to cache the state at each line to reduce unnecessary work.
I only want to do two things with the cursor:
This:
((a ) ;
Produces:
((a ;))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.