help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Emacs Lisp: Indentation of higher order functions?


From: Klaus-Dieter Bauer
Subject: Emacs Lisp: Indentation of higher order functions?
Date: Tue, 9 Sep 2014 14:22:55 +0200

Hello!

I was wondering about the indentation rules of higher order functions in
emacs-lisp. Consider e.g. this case:

(let ((incr-string
       (apply #'string
      (mapcar #'1+
      "Hello World"))))
  ...)

or likewise within the same indentation rules

(let ((incr-string
       (apply
#'string
(mapcar
 #'1+
 "Hello World"))))
  ...)

In emacs lisp higher order functions typically don't declare special
indentation rules. The result however is that chaining higher order
functions often becomes highly verbose in terms of whitespace, using either
unnecessarily much space vertically or horizontally, subjectively making
the code harder to read.

As far as I understand, the 2-column indentation is intended to signify
"this is going to be executed as a code block" while a 4-column indentation
should signify "this is a special argument to the special form" and hence
assigning (declare (indent 1)) would conflict with formatting expectations.
Yet the verbosity of nested function calls seems like a relevant
disadvantage.

Personally I tried using a file-variable `lisp-indent-offset:2', but this
breaks formatting of `let' type forms and multil-ine alist-constants,
resulting in an awkward distinction of indentation between the first and
further elements and would likely make the code less readable to others.
For some time I thus changed the `lisp-indent-function' entry for know
higher-order functions through code in my .emacs file, but this leads to
the same problems (and would harm when changing another person's emacs lisp
code by not being file-specific).

What is the proper way to deal with such situations in emacs lisp?

regards, Klaus


reply via email to

[Prev in Thread] Current Thread [Next in Thread]