eraserhd / parinfer-rust

A Rust port of parinfer.
ISC License
536 stars 41 forks source link

Common LISP code get borked in kakoune #86

Open rapenne-s opened 4 years ago

rapenne-s commented 4 years ago

I tried parinfer-rust for the first time using kakoune.

I installed parinfer-rust following the manual installation process, using git and make install to get the very latest version.

I opened a few lisp files that are known to work and the display in kakoune is totally wrong in some places, if I open the file with other editors the content is correct. I tried in the 3 different modes but it ends with t he same issue.

After fiddling, I came to a small example of code reproducing the issue.

tabs are important

Original code:

        (let ((title (format nil "~80a"
                       (if (< 80 (length (foo-title foo)))
                           (subseq (foo-title foo) 0 80)
                           (foo-title foo)))
          (replace title (foo-rawdate foo) :start1 (- (length title) (length (foo-rawdate foo)))))
        (getf *config* :srv-port)))

code displayed by kakoune:

        (let ((title (format nil "~80a"~80a"
                     (if (< 80 (length (foo-title foo)))foo)))
                      (subseq (foo-title foo) 0 80)le foo) 0 80)
                      (foo-title foo)))-title foo)))
           (replace title (foo-rawdate foo) :start1 (- (length title) (length (foo-rawdate foo))))))))))
                (getf *config* :srv-port)))rt)))
eraserhd commented 4 years ago

Hi!

I don't see any tabs in your example, so I'm not sure if you mean the indentation is important or maybe github ate the tabs? If the tab characters are important, can you link to a gist?

I don't see any problems loading this snippet as it is.

Parinfer doesn't know how wide tabs are and replaces them with two spaces as it applies its algorithm. That said, the editor plugins should run paren mode once and make a "correct" file before any other editing occurs.

I'm not sure where the duplication artifacts you are seeing could be coming from. Try piping the raw (with tabs, presumably) text to parinfer-rust -m paren. If the artifacts aren't there, try removing all your Kakoune plugins except for parinfer-rust, and see what happens.

joulaud commented 3 years ago

I have a minimal example showing the problem. I confirm it is related to the use of tab character.

With parinfer-rust -m paren it does not replaces the tab by two spaces but it add two spaces before the tab.

$ cat <<EOF >x.scm
(test name
  (k    v))
EOF

$ cat x.scm | od -a
0000000   (   t   e   s   t  sp   n   a   m   e  nl  sp  sp   (   k  ht
0000020   v   )   )  nl

$ cat x.scm | parinfer-rust -m paren | od -a
0000000   (   t   e   s   t  sp   n   a   m   e  nl  sp  sp   (   k  sp
0000020  sp  ht   v   )   )  nl

It must break some offset calculation somewhere.

joulaud commented 3 years ago

~~The problem is probably in the use of -display-column option of kakoune select command when selecting the text to replace. When there is tabs the selection is not complete and the end of the text to replace is kept.~~

We have indeed exactly the reverse problem as for https://github.com/eraserhd/parinfer-rust/issues/55

EDIT: disregard this comment, it is probably not relevant.