Skip to content

Not properly indenting "let" binding sequences #45

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

Closed
grkuntzmd opened this issue Oct 20, 2011 · 5 comments
Closed

Not properly indenting "let" binding sequences #45

grkuntzmd opened this issue Oct 20, 2011 · 5 comments

Comments

@grkuntzmd
Copy link

"let" binding blocks containing complex bindings are not indented properly.

(let [[x
       y] (range 2)

       [a b] (["foo" "bar"])]
  (print x y a b))

Notice that the line that starts with [a ...] is lined up under the y in the line above. It should line up under the [x .... It appears to be a problem with having 2 s-expressions on the lines starting [x ...

@AimHere
Copy link

AimHere commented Feb 23, 2012

I have a similar issue that may or may not be related. When you have a multi-line condition in a 'cond' block, the code is inappropriately indented to the right, like so:

(cond (or (= foo 69)
          (= foo 42)) (println "foo is magic")

          (= foo (Math/sqrt -1)) (println "foo is imaginary"))  

Here, the lowest line should be aligned with the "(or ...", not the other "(= ...)" lines.
Putting both halves of the 'or' expression on the same line behaves correctly

version 1.11.5

@miner
Copy link

miner commented Feb 4, 2013

With clojure-mode 2.0, you can fix the "cond" problem by adding the following to your .emacs. You need to repeat 6 8 as many times as you're likely to have clauses in your cond. I'm working on a patch to simplify that.

(put 'cond 'clojure-backtracking-indent '(6 8 6 8 6 8 6 8 6 8 6 8 6 8 6 8))

Sorry, I've got nothing for the "let" case. It's more complicated because (I think) the [square brackets] don't count as a s-expr so the backtracking doesn't work right. I'm not really sure about that.

@vmfhrmfoaj
Copy link
Contributor

My English is poor, but I hope you can understand me.

Hi @bbatsov
First, sorry to pollute(dirty pull request) the issue board.
This problem caused by following code:

(progn
  (if (not (> (save-excursion (forward-line 1) (point))
              calculate-lisp-indent-last-sexp))
      (progn (goto-char calculate-lisp-indent-last-sexp)
             (beginning-of-line)
             (parse-partial-sexp (point)
                                 calculate-lisp-indent-last-sexp 0 t)))
  ;; Indent under the list or under the first sexp on the same
  ;; line as calculate-lisp-indent-last-sexp.  Note that first
  ;; thing on that line has to be complete sexp since we are
  ;; inside the innermost containing sexp.
  (backward-prefix-chars)
  (current-column))

This code means that return a column number of first S-expression of the previous line.
We meet the problem, when there are difference between indentation level of previous line and indentation level of current line.
For example:

(let [[x  
       y] (range 2) ; --> indent level 3; ([[
       [a ; --> indent level 2; ([
        b] (["foo" "bar"])]
  (print x y a b))

So, we need to make sure whether the previous line and the indentation level of the current line are equal.

@mrcslws
Copy link

mrcslws commented Jul 4, 2015

I'm not sure if "+1"s are useful, but I run into this one all the time. I sometimes work around it by writing ugly code:

(let [[a b
       c]
      (foo bar)
      d 41])

instead of the more natural but wrongly indented

(let [[a b
       c] (foo bar)
       d 41])

Obviously all of this code looks silly, but it makes sense when you are either:

a. Destructuring lots of values and need to wrap to a new line
b. Avoiding indenting (foo bar) way to the right, since it might be a big sexpr, e.g. a reduce.

@bbatsov
Copy link
Member

bbatsov commented Jul 4, 2015

Patches are way more useful. :-) I have a ton of work and fixing this is pretty low on my todo list, so help is welcome.

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

No branches or pull requests

6 participants