]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/lisp-mode.el: Add new indentation convention
authorakater <nuclearspace@gmail.com>
Fri, 29 May 2020 04:26:09 +0000 (00:26 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 29 May 2020 04:26:09 +0000 (00:26 -0400)
(calculate-lisp-indent): To distinguish code and data when indenting,
introduce the convention that a space between an open paren and
a symbol indicate that this should be indented as a simple data list.

etc/NEWS
lisp/emacs-lisp/lisp-mode.el
test/manual/indent/elisp.el [new file with mode: 0644]
test/manual/indent/lisp.lisp [new file with mode: 0644]

index cb17a93f0694c19342a31937432e12e9984c46e7..64cf0abbdb4a79fdfb63802c44c391beb420b056 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -128,6 +128,10 @@ displayed and which are kept hidden.
 ** Emacs Lisp mode
 
 *** The mode-line now indicates whether we're using lexical or dynamic scoping.
+*** A space between an open paren and a symbol changes the indentation rule.
+The presence of a space between an open paren and a symbol now is
+taken as a statement by the programmer that this should be indented
+as a data list rather than as a piece of code.
 
 ** Dired
 
index 7098a41f274052c6648d55324f227cbf55ffd924..1311d94cb0115d2996e44780acd22f1846e9458a 100644 (file)
@@ -956,6 +956,7 @@ is the buffer position of the start of the containing expression."
           ;; setting this to a number inhibits calling hook
           (desired-indent nil)
           (retry t)
+          whitespace-after-open-paren
           calculate-lisp-indent-last-sexp containing-sexp)
       (cond ((or (markerp parse-start) (integerp parse-start))
              (goto-char parse-start))
@@ -985,6 +986,7 @@ is the buffer position of the start of the containing expression."
           nil
         ;; Innermost containing sexp found
         (goto-char (1+ containing-sexp))
+        (setq whitespace-after-open-paren (looking-at (rx whitespace)))
         (if (not calculate-lisp-indent-last-sexp)
            ;; indent-point immediately follows open paren.
            ;; Don't call hook.
@@ -999,9 +1001,11 @@ is the buffer position of the start of the containing expression."
                    calculate-lisp-indent-last-sexp)
                 ;; This is the first line to start within the containing sexp.
                 ;; It's almost certainly a function call.
-                (if (= (point) calculate-lisp-indent-last-sexp)
+                (if (or (= (point) calculate-lisp-indent-last-sexp)
+                         whitespace-after-open-paren)
                     ;; Containing sexp has nothing before this line
-                    ;; except the first element.  Indent under that element.
+                    ;; except the first element, or the first element is
+                     ;; preceded by whitespace.  Indent under that element.
                     nil
                   ;; Skip the first element, find start of second (the first
                   ;; argument of the function call) and indent under.
diff --git a/test/manual/indent/elisp.el b/test/manual/indent/elisp.el
new file mode 100644 (file)
index 0000000..f3874b5
--- /dev/null
@@ -0,0 +1,5 @@
+(defun x ()
+  (print (quote ( thingy great
+                 stuff)))
+  (print (quote (thingy great
+                       stuff))))
diff --git a/test/manual/indent/lisp.lisp b/test/manual/indent/lisp.lisp
new file mode 100644 (file)
index 0000000..f3874b5
--- /dev/null
@@ -0,0 +1,5 @@
+(defun x ()
+  (print (quote ( thingy great
+                 stuff)))
+  (print (quote (thingy great
+                       stuff))))