Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment bug with comments/forms following a closing delimiter #525

Open
yuhan0 opened this issue May 4, 2019 · 5 comments
Open

Alignment bug with comments/forms following a closing delimiter #525

yuhan0 opened this issue May 4, 2019 · 5 comments

Comments

@yuhan0
Copy link
Contributor

yuhan0 commented May 4, 2019

Expected behavior

M-x clojure-align on the following forms should be a no-op:

{:a [123
     456
     789] :b 10}

(cond foo  {:bar 1  ; initialize the Bar
            :baz 2} ; and the Baz
      quux {})

Actual behavior

The second "column" is pushed farther and farther to the right every time clojure-align is called.

{:a [123
     456
     789] :b 10}

=>

{:a       [123
           456
           789] :b 10}

=>

{:a             [123
                 456
                 789] :b 10}

=>

{:a                   [123
                       456
                       789] :b 10}

Steps to reproduce the problem

Execute clojure-align on any hashmap or function defined in clojure-cond-align-forms, which has a symbol or comment following a closing delimiter that is on a different line from its opening delimiter:

;; this is fine
{:a [1 2] ; comment
 }

;; this is also fine
{:a [[1
      2] ; comment
     3]
 }

;; but not this
{:a [1
     2
     3] ; comment
 }

The offending delimiter must belong to the second or greater "column" of the alignment

;; This is alright
(are [x y z] (= (count y) x (inc z))
  [100
   200
   300] 3 2)

;; This is not
(are [x y z] (= x (count y) (inc z))
  3 [100
     200
     300] 2)

Environment & Version information

clojure-mode version information

Include here the version string displayed by M-x clojure-mode-display-version. Here's an example:

clojure-mode (version 5.10.0)

Emacs version

26.2

Operating system

macOS 10.14

@bbatsov
Copy link
Member

bbatsov commented May 8, 2019

@Malabarba is our master of alignment. :-) Perhaps he has an idea why this is happening?

@skuro
Copy link

skuro commented Jun 24, 2019

I experienced a similar issue with long keys destructuring (see screencast):

(let [{:keys [one two three
              four five six
              seven eight nine] :as whole} bigstuff])

Setting clojure-align-separator to 'group fixed it, apparently without changing any other alignment behavior from default (although I didn't test it extensively quite yet)

@manuel-uberti
Copy link
Contributor

manuel-uberti commented Jun 24, 2019

FWIW, @skuro's suggestion works for me too. Tested on:

(are [x y z] (= x (count y) (inc z))
  3 [100
     200
     300] 2)

As reported by @yuhan0.

@yuhan0
Copy link
Contributor Author

yuhan0 commented Jun 25, 2019

Changing clojure-align-separator to 'group did help with this bug. However the behavior is slightly different, it doesn't align across multi-line expressions:

{:x    [123]
 :abcd [123
        456]
 :long-var-name [789]}

@Malabarba
Copy link
Member

Hi everyone.

I can verify all of the bugs and solutions mentioned. Sadly all I can say is that it's either a bug in clojure--search-whitespace-after-next-sexp or an Emacs bug. =/

The Emacs alignment engine is pretty dense and I remember when I first implemented this feature in clojure-mode it was very hit-or-miss.

Anyone who wants to help is invited to read through the docs for align-region and for align-rules-list and try to determine if there's a better way to do this.
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants