2

As I write more Elisp, I find myself using the threading macro increasingly often. However, since it is an imported, not a built-in one, the indentation is not like what I want it to be.

For example, I want the auto-indentation to be, not like this:

(->> '(1 2 3 4)
  (mapcar #'1+)
  (seq-filter #'evenp)
  (reduce #'+))

but like this:

(->> '(1 2 3 4)
     (mapcar #'1+)
     (seq-filter #'evenp)
     (reduce #'+))

...so that the inner expressions are aligned together vertically.

How can I specially designate the indent level, based on the expression's car?

Basil
  • 12,019
  • 43
  • 69
Namudon'tdie
  • 159
  • 6
  • 1
    AFAIK `->>` comes from `dash.el` and I just checked the current version of that, and it *does* indent your example the way you want. So I guess you just need to update `dash`? – phils Jun 03 '21 at 02:37
  • @phils That's odd, I just the version of my `dash` and it says `20210602.1928`, version `2.18.1`. It looks pretty recent, but it still does not provide such indentation. `(require 'dash)` did not help either. – Namudon'tdie Jun 03 '21 at 02:43
  • 1
    I used `dash-2.18.1` from GNU ELPA. The `->>` definition doesn't `declare` any indentation rules, so it works the way you want. Do you see the same thing from `emacs -Q` if you load `dash`? – phils Jun 03 '21 at 03:10
  • 1
    @phils The macro `->>` gained an indentation declaration after that release; try the more recent version on GNU-devel ELPA instead: https://elpa.gnu.org/devel/dash.html – Basil Jun 03 '21 at 20:13

2 Answers2

3

This is what I do:

(with-eval-after-load 'dash
  (function-put '-> 'lisp-indent-function nil)
  (function-put '->> 'lisp-indent-function nil))

Dash maintainers refused to keep ->/->> indentation in sync with other Lisps. See https://github.com/magnars/dash.el/pull/375#issuecomment-817947545

See (info "(elisp) Indenting Macros") for more details.

Basil
  • 12,019
  • 43
  • 69
2

The Dash project has gone back and forth on the indentation of these Clojure-inspired threading macros a couple of times in the past:

And, most recently:

This pull request (re)introduced the indentation that OP describes as undesirable for -> and ->> on 2021-03-08. However, this controversial change was never included as part of an official Dash release, and was present only for 4 months in the development version that can be installed from GNU-devel ELPA or MELPA.

The release of Dash 2.19.0 on 2021-07-08 restored Clojure-like indentation for the macros ->, ->>, and --> for both development and non-development versions of the Dash package:

(->> '(1 2 3 4)
     (mapcar #'1+)
     (seq-filter #'cl-evenp)
     (reduce #'+))

Once upgraded to this version, no further steps are required to achieve the desirable indentation, but see Ivan's answer for a general mechanism to customise Elisp indentation.

Basil
  • 12,019
  • 43
  • 69