unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs Lisp: Indentation of higher order functions?
@ 2014-09-09 12:22 Klaus-Dieter Bauer
  2014-09-09 15:57 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 2+ messages in thread
From: Klaus-Dieter Bauer @ 2014-09-09 12:22 UTC (permalink / raw)
  To: emacs help

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Emacs Lisp: Indentation of higher order functions?
  2014-09-09 12:22 Emacs Lisp: Indentation of higher order functions? Klaus-Dieter Bauer
@ 2014-09-09 15:57 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Thien-Thi Nguyen @ 2014-09-09 15:57 UTC (permalink / raw)
  To: emacs help

[-- Attachment #1: Type: text/plain, Size: 960 bytes --]

() Klaus-Dieter Bauer <bauer.klaus.dieter@gmail.com>
() Tue, 9 Sep 2014 14:22:55 +0200

   [...] 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.

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

If it is a truly subjective matter, you can change the subject.
Personally, sometimes i read source code, type ‘M-x zone RET’,
wait a bit, and then reassert control, to see what exactly has
changed (in my memory / understanding / appreciation).  I don't
think this is "the proper way", but neither is it così improper.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-09 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-09 12:22 Emacs Lisp: Indentation of higher order functions? Klaus-Dieter Bauer
2014-09-09 15:57 ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).