Fork me on GitHub
#nextjournal
<
2022-03-03
>
pmooser12:03:03

Is this an OK place to ask a question about clojure-mode (https://github.com/nextjournal/clojure-mode) ?

pmooser12:03:44

I found something which may be a bug, but it may also just be an artifact of something I'm doing.

pmooser13:03:47

I'm using clojure-mode to implement distributed text editing. That means I have a ViewPlugin that processes (local) user input, and converts it into a data structure which is sent over the wire. When the remote client picks up this data structure, it converts it into a CodeMirror transaction which it applies to its editor (along with an annotation so that we can distinguish local/remote transactions and avoid infinite loops and other stuff). What I am seeing is, if we have an editor with contents like: one two three And I select the two and delete it - everything happens correctly for the user who originated the change, and we get: one three (note that there are two spaces) On the remote host, when I receive the data about this edit, and convert it to a CodeMirror transaction, it is "correct" - that means, it correctly describes deleting just the two. However, what I see is that the ext-format-changed-lines extension used by default in clojure-mode filters the transaction so that we don't have the two spaces, and thus we end up with one three (note the single space).

pmooser13:03:20

It seems to me that this extension should cause that to happen in response to the originating user's edit as well, instead of just modifying the other transaction.

pmooser13:03:31

Does that make sense? It's a bit challenging to describe due to the different moving parts involved.

mkvlr13:03:30

@pmooser clojure-mode is also powering the collaborative editing of Clojure code on http://nextjournal.com. Though it’s a bit different there with codemirror being embedded in a prosemirror doc. Can you check what you get for the https://github.com/nextjournal/clojure-mode/blob/master/src/nextjournal/clojure_mode/extensions/formatting.cljs#L153-L162? Maybe you need to annotate it with “noformat”.

pmooser13:03:44

Wow, ok. I will take a look. But today I learned that you can group constants in case expressions in a list.

pmooser13:03:15

I will try adding that annotation at some point today, and I'll what happens.

pmooser13:03:56

I notice that the paredit bindings need that extension to be present in order to not keep adding spaces ... so it would be cool if that happens to work.

pmooser13:03:22

In any case, thanks for your thoughtful response, and I'll try to get back to you one way or another, although it might take a day or so.

pmooser13:03:09

@mkvlr So that does indeed fix the issue as far as the spaces formatting, but then the paredit bindings cause edits that are incorrect. For example, if I have (foo bar) baz and I put my cursor after r and do a slurp, you'd like to get (foo bar baz). The transactions I generate as I send them across the wire look correct:

{:sequential true,
 :annotations
 [#object[Annotation [object Object]]   ;; remote
  #object[Annotation [object Object]]], ;; noformat
 :changes [{:from 8, :to 9} {:from 12, :insert ")"}]}
So those do like:
;; original
(foo bar) baz
0123456789ABC

;; delete right paren at 8
(foo bar baz 
0123456789ABC

;; insert right paren at 12
(foo bar baz)
0123456789ABC
However ... what I see on the host that executes that transaction (since I tagged the tx with noformat) is: (foo bar ba)z

mkvlr13:03:53

can you only tag the transaction that you receive?

pmooser13:03:00

Does that make sense to you, or does it seem like I'm using your plugin/extensions incorrectly?

pmooser13:03:46

This is a "remote only" problem, meaning that it is only the remote host that has this issue.

pmooser13:03:54

Only the transactions that are generated from "remote data" get tagged as remote/noformat in my code, to be clear.

pmooser13:03:14

And that's partially what I found baffling - that something didn't run in response to user input, but only in response to transactions.

pmooser13:03:30

(creating a desync between local/remote cases for me in particular)

pmooser13:03:51

I think a way forward for me might be to just not use that formatting extension, and then maybe I'll rewrite a set of paredit bindings that don't depend upon it for correctness.

mkvlr14:03:06

we do use that so pretty sure it can be made work with it. But it’s been a good while since we touched that code so can’t say what’s wrong unfortunately.

pmooser14:03:24

Well, yes, and I understand it's a burden on you since my case is reasonably complex as well.

pmooser14:03:35

In any case, I learned some things with your help, so thanks for that.

pmooser14:03:54

I'll invest a bit more time in reading the code, since there's a lot in clojure-mode that I don't understand yet,

pmooser14:03:01

and I'll certainly let you know if I come up with anything useful.

pmooser14:03:02

Thank you!

🙏 1
Ethan Miller16:03:17

Hi I asked this in a thread above but I think it got lost. I have been experimenting/trying to use Clerk with tmd datasets but running into a problem where column names are truncated to the point where you can't read them at all when there are many columns. I've been using clerk/table in the method explained here: https://clojurians.slack.com/archives/C01GH5EN7JA/p1644269714727249?thread_ts=1644268797.698559&amp;cid=C01GH5EN7JA

Ethan Miller16:03:47

I'm wondering if I am doing something wrong to get this result.

mkvlr16:03:07

this looks like a css issue when the row values are really small. Asking @philippmarkovics to talk a look.

🙏 1