Skip to content

clojure-thread-last breaks with line comments #619

Open
@yuhan0

Description

@yuhan0

Expected behavior

Running clojure-thread-last-all on the following

(foo x ;; grobble
  (bar y))

should preserve the comments and not unbalance parens.
eg.

(->> y
  (bar)
  (foo x ;; grobble
    ))

Actual behavior

(->> (bar y)
(foo x ;; grobble))

The closing parens are merged into the comment, breaking the structure.

Steps to reproduce the problem

Run C-c C-r l on an expression with a line comment.
Breaks even when comment is on its own line

(drop 2
  ;; TODO use transducers
  (map inc
    (filter even?
      (range 100))))

This could probably be fixed by adding a (clojure--in-comment-p) check in the right place. But I wonder if some of these refactorings could be written with parseclj to be more robust.. Eg. most don't deal well with metadata or #_ ignored forms. The threading commands happen to be the most complex from the looks of the code.

Environment & Version information

clojure-mode version

clojure-mode (version 5.13.0)

Emacs version

28.0.91

Operating system

macOS 12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions