From: akater <nuclearspace@gmail.com>
To: emacs-devel@gnu.org
Subject: Proposal: change indentation rules for one-dimensional lists in emacs-lisp-mode and lisp-mode
Date: Tue, 03 Mar 2020 00:12:00 +0000 [thread overview]
Message-ID: <87pnduz48f.fsf@gmail.com> (raw)
If you read this in recent Emacs, you can M-x org-mode for better
reading experience. It'll work fine even if you don't generally use
org-mode.
* Quick overview: Proposed indentation
My proposal is: when there's whitespace after the opening paren, always
indent list contents as data, as opposed to code:
#+begin_src emacs-lisp
;; proposed indentation
(blob '( a b c
d e f))
(blob `( a b c
d e f))
(blob ( a b c
d e f))
#+end_src
#+begin_src lisp
;; proposed indentation
(blob '( a b c
d e f))
(blob `( a b c
d e f))
(blob ( a b c
d e f))
#+end_src
This will be more aesthetically pleasing and will utilise whitespace
more efficiently when dealing with data lists. It will also bring more
consistency, as outlined below.
The proposal does apply to backquote, as backquote is not used solely
for code in practice. Sometimes data is backquoted, with parts of it
evaluated.
It won't affect code indentation as corresponding expressions never have
whitespace after the opening paren, according to my experience.
* Quick overview: Estabilished indentation
At the moment one-dimensional lists are indented disregarding the
post-open-paren whitespace:
#+begin_src emacs-lisp
;; estabilished indentation
(blob '( a b c
d e f))
(blob `( a b c
d e f))
(blob ( a b c
d e f))
#+end_src
#+name: the-first-one-is-particularly-ugly
#+begin_src lisp
;; estabilished indentation
(blob '( a b c
d e f))
(blob `( a b c
d e f))
(blob ( a b c
d e f))
#+end_src
* Motivation
When not at top-level, one-dimensional lists quoted with quote are
indented differently in lisp-mode and emacs-lisp-mode:
#+begin_src emacs-lisp
(blob '(a b c
d e f))
#+end_src
#+begin_src lisp
(blob '(a b c
d e f))
#+end_src
While lisp-mode employs data indentation here, emacs-lisp-mode uses code
indentation which I believe is a misfeature in emacs-lisp-mode.
One-dimensional lists quoted with backquote are indented as code in both
cases:
#+begin_src emacs-lisp
(blob `(a b c
d e f))
#+end_src
#+begin_src lisp
(blob `(a b c
d e f))
#+end_src
Sometimes the lists in question actually represent data. In those cases,
they should be indented unlike code and like, say, two-dimensional lists
are currently indented:
#+begin_src emacs-lisp
(blob '((a b c)
(d e f)))
#+end_src
#+begin_src lisp
(blob '((a b c)
(d e f)))
#+end_src
Note that unquoted lists
#+begin_src emacs-lisp
(blob (a b c
d e f))
#+end_src
#+begin_src lisp
(blob (a b c
d e f))
#+end_src
often enough represent data, too.
This case is treated satisfactorily now for two-dimensional lists across
the modes in question:
#+begin_src emacs-lisp
(blob ((a b c)
(d e f)))
#+end_src
#+begin_src lisp
(blob ((a b c)
(d e f)))
#+end_src
Currently, the only way to indent one-dimensional list as data in emacs-lisp-mode, is this:
#+begin_src emacs-lisp
(blob '(
a b c
d e f))
#+end_src
which works for backquote and unquoted sexp as well. This is how I
actually deal with this issue now. lisp-mode (as opposed to
emacs-lisp-mode) handles it better, unless there actually is post-quote
whitespace not containing a newline, in which case the indentation is
particularly ugly, as can be observed in
[[the-first-one-is-particularly-ugly]] block above.
* Further notes
Note how the estabilished indentation is inconsistent within lisp-mode:
lisp-mode indentation simply disregards post-quote whitespace but
respects post-backquote whitespace and “unquoted
whitespace”. Estabilished indentation rules are also inconsistent
between lisp-mode and emacs-lisp-mode for no good reason that I can see.
My proposal does not look like a significant step away from estabilished
indentation rules. It could be equivalently formulated as
“indent-as-data should be triggered by any whitespace after the opening
paren, not just by whitespace containing newline.” Proposal also makes
rules more consistent between the two modes.
Note that this would fit with the estabilished indentation style for
two-dimensional lists, as currently adopted by emacs-lisp-mode:
#+begin_src emacs-lisp
;; estabilished indentation
(blob '( (a b c)
(d e f)))
(blob `( (a b c)
(d e f)))
(blob ( (a b c)
(d e f)))
#+end_src
lisp-mode, on the other hand, ignores the post-quote whitespace again,
like in the case of one-dimensional lists. I believe this is a
misfeature. The proposal otherwise fits with the lisp-mode indentation
rules.
#+begin_src lisp
;; estabilished indentation
(blob '( (a b c)
(d e f)))
(blob `( (a b c)
(d e f)))
(blob ( (a b c)
(d e f)))
#+end_src
* Side note: top-level quoted indentation (or rather, lack thereof)
Note also that quoted lists are never auto-indented at top-level at all:
#+begin_src emacs-lisp
;; estabilished indentation
'(a b c
d e f)
`(a b c
d e f)
#+end_src
#+begin_src lisp
;; estabilished indentation
'(a b c
d e f)
`(a b c
d e f)
#+end_src
while unquoted lists (of course) are:
#+begin_src emacs-lisp
(a b c
d e f)
#+end_src
#+begin_src lisp
(a b c
d e f)
#+end_src
but I didn't give this any thought and meniton it just for the sake of
completeness.
next reply other threads:[~2020-03-03 0:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 0:12 akater [this message]
2020-03-03 18:14 ` Proposal: change indentation rules for one-dimensional lists in emacs-lisp-mode and lisp-mode Richard Stallman
2020-03-03 20:09 ` Stefan Monnier
2020-05-01 6:26 ` akater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pnduz48f.fsf@gmail.com \
--to=nuclearspace@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).