parinfer-rust icon indicating copy to clipboard operation
parinfer-rust copied to clipboard

Unexpected handling of tabs

Open bentxt opened this issue 2 years ago • 2 comments

Hi I like using parinfer but in this case something goes wrong. Since I cannot figure out what the problem is, I had to disable parinfer completely, because otherwise it messes up existing code like:

(define (read-file name)
  (call-with-input-file name
    (lambda (port)
      (letrec ((recur (lambda ()
			(let ((expr (read port)))
			  (if (eof-object? expr)
			      '()
			      (cons expr (recur)))))))
	(recur)))))

which parinfer transforms to:


(define (read-file name)
  (call-with-input-file name
    (lambda (port)
      (letrec ((recur (lambda ()))))
      			(let ((expr (read port)))
      			  (if (eof-object? expr)
      			      '()
      			      (cons expr (recur))))))
  	(recur))

bentxt avatar Jan 10 '22 14:01 bentxt

I think by reformating the source code I prevent the unwanted transformation:

(define (read-file name)
   (call-with-input-file name
      (lambda (port)
         (letrec 
            ((recur 
               (lambda () 
                  (let ((expr (read port)))
                     (if (eof-object? expr)
                        '()
                        (cons expr (recur)))))))
           (recur)))))

I somehow possible I would prefer the source code in its original form

bentxt avatar Jan 10 '22 14:01 bentxt

Hi! It looks like there are tabs in the original, and neither the original parinfer implementation, nor this one, supports them well (they both replace the tabs with exactly two spaces regardless of where the tab is aligned). If I replace the tabs with spaces, I get the result you want.

I think that fixing this would require specifying tab widths, and adding real tab logic based on input column.

Related: #86

eraserhd avatar Jan 12 '22 10:01 eraserhd