emacs-diffs
[Top][All Lists]
Advanced

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

master fb1267d: Indent lambdas/closures better


From: Lars Ingebrigtsen
Subject: master fb1267d: Indent lambdas/closures better
Date: Thu, 4 Nov 2021 17:07:57 -0400 (EDT)

branch: master
commit fb1267d90a5c25a29dbdae170ea065e017b05d29
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Indent lambdas/closures better
    
    * lisp/emacs-lisp/pp.el (pp--format-function): Indent lambdas and
    closures better.
---
 lisp/emacs-lisp/pp.el                               | 13 ++++++++++++-
 test/lisp/emacs-lisp/pp-resources/code-formats.erts |  8 ++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index ca3f2a2..1d7b935 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -236,9 +236,20 @@ Ignores leading comment characters."
 (defun pp--format-function (sexp)
   (let* ((sym (car sexp))
          (edebug (get sym 'edebug-form-spec))
-         (indent (get sym 'lisp-indent-function)))
+         (indent (get sym 'lisp-indent-function))
+         (doc (get sym 'doc-string-elt)))
     (when (eq indent 'defun)
       (setq indent 2))
+    ;; We probably want to keep all the elements before the doc string
+    ;; on a single line.
+    (when doc
+      (setq indent (1- doc)))
+    ;; Special-case closures -- these shouldn't really exist in actual
+    ;; source code, so there's no indentation information.  But make
+    ;; them output slightly better.
+    (when (and (not indent)
+               (eq sym 'closure))
+      (setq indent 0))
     (pp--insert "(" sym)
     (pop sexp)
     ;; Get the first entries on the first line.
diff --git a/test/lisp/emacs-lisp/pp-resources/code-formats.erts 
b/test/lisp/emacs-lisp/pp-resources/code-formats.erts
index 821e326..f48e262 100644
--- a/test/lisp/emacs-lisp/pp-resources/code-formats.erts
+++ b/test/lisp/emacs-lisp/pp-resources/code-formats.erts
@@ -95,3 +95,11 @@ Also add the value to the front of the list in the variable 
`values'."
     (values--store-value result)
     (pp-display-expression result "*Pp Eval Output*")))
 =-=-=
+
+Name: code-formats9
+
+=-=
+(lambda ()
+  (interactive)
+  1)
+=-=-=



reply via email to

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