[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proposal: change indentation rules for one-dimensional lists in emacs-li
From: |
akater |
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 |
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.
- Proposal: change indentation rules for one-dimensional lists in emacs-lisp-mode and lisp-mode,
akater <=