]> code.delx.au - gnu-emacs/commitdiff
* prolog.el: Fix indentation of empty line
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 22 Sep 2015 15:11:50 +0000 (11:11 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 22 Sep 2015 15:11:50 +0000 (11:11 -0400)
* lisp/emacs-lisp/smie.el (smie-rules-function): Document new
`empty-line-token' element.
(smie-indent-empty-line): New function.
(smie-indent-functions): Add it.

* lisp/progmodes/prolog.el (prolog-smie-rules): Fix :list-intro behavior
and use the new `empty-line-token' element (bug#21526).
(prolog-mode-variables): Fix comment-start-skip setting to match
comment-start.

* test/indent/prolog.prolog: Add nested indentation tests.

* lisp/newcomment.el (comment-normalize-vars): Fix default value of
comment-start-skip not to misuse submatch 1.

lisp/emacs-lisp/smie.el
lisp/newcomment.el
lisp/progmodes/prolog.el
test/indent/prolog.prolog

index eb5a7132c7e56eac34d1adae075da798c76bf1f0..f305025f2158894f95bb6f9b81a99d38deaa4d96 100644 (file)
@@ -1136,6 +1136,8 @@ METHOD can be:
 - :elem, in which case the function should return either:
   - the offset to use to indent function arguments (ARG = `arg')
   - the basic indentation step (ARG = `basic').
+  - the token to use (when ARG = `empty-line-token') when we don't know how
+    to indent an empty line.
 - :list-intro, in which case ARG is a token and the function should return
   non-nil if TOKEN is followed by a list of expressions (not separated by any
   token) rather than an expression.
@@ -1686,6 +1688,19 @@ should not be computed on the basis of the following token."
         (+ (smie-indent-virtual) (smie-indent--offset 'basic))) ;
        (t (smie-indent-virtual))))))                            ;An infix.
 
+(defun smie-indent-empty-line ()
+  "Indentation rule when there's nothing yet on the line."
+  ;; Without this rule, SMIE assumes that an empty line will be filled with an
+  ;; argument (since it falls back to smie-indent-sexps), which tends
+  ;; to indent far too deeply.
+  (when (eolp)
+    (let ((token (or (funcall smie-rules-function :elem 'empty-line-token)
+                     ;; FIXME: Should we default to ";"?
+                     ;; ";"
+                     )))
+      (when (assoc token smie-grammar)
+        (smie-indent-keyword token)))))
+
 (defun smie-indent-exps ()
   ;; Indentation of sequences of simple expressions without
   ;; intervening keywords or operators.  E.g. "a b c" or "g (balbla) f".
@@ -1744,7 +1759,7 @@ should not be computed on the basis of the following token."
     smie-indent-comment smie-indent-comment-continue smie-indent-comment-close
     smie-indent-comment-inside smie-indent-inside-string
     smie-indent-keyword smie-indent-after-keyword
-                          smie-indent-exps)
+    smie-indent-empty-line smie-indent-exps)
   "Functions to compute the indentation.
 Each function is called with no argument, shouldn't move point, and should
 return either nil if it has no opinion, or an integer representing the column
index 60f35c834b3e6cfec1ff7568ed41c61760319fd8..7df05a0c39835caa6ae493e8118a24da15058265 100644 (file)
@@ -382,7 +382,7 @@ function should first call this function explicitly."
           (concat (unless (eq comment-use-syntax t)
                      ;; `syntax-ppss' will detect escaping.
                      "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)")
-                   "\\(\\s<+\\|"
+                   "\\(?:\\s<+\\|"
                   (regexp-quote (comment-string-strip comment-start t t))
                   ;; Let's not allow any \s- but only [ \t] since \n
                   ;; might be both a comment-end marker and \s-.
index 8c02e5402a2a34e6be2ef9c4f8ee6ccbb6a077a5..3d9b0c322ab670aad7b461780dd7158e4298e347 100644 (file)
@@ -922,6 +922,11 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24."
 (defun prolog-smie-rules (kind token)
   (pcase (cons kind token)
     (`(:elem . basic) prolog-indent-width)
+    ;; The list of arguments can never be on a separate line!
+    (`(:list-intro . ,_) t)
+    ;; When we don't know how to indent an empty line, assume the most
+    ;; likely token will be ";".
+    (`(:elem . empty-line-token) ";")
     (`(:after . ".") '(column . 0)) ;; To work around smie-closer-alist.
     ;; Allow indentation of if-then-else as:
     ;;    (   test
@@ -1023,7 +1028,7 @@ VERSION is of the format (Major . Minor)"
   (setq-local comment-start "%")
   (setq-local comment-end "")
   (setq-local comment-add 1)
-  (setq-local comment-start-skip "\\(?:/\\*+ *\\|%%+ *\\)")
+  (setq-local comment-start-skip "\\(?:/\\*+ *\\|%+ *\\)")
   (setq-local parens-require-spaces nil)
   ;; Initialize Prolog system specific variables
   (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators
index ca4d2c91d3270bf01a444099b32540faf56f5011..6bf9437b8836e196b882b65d580b7d71a0eb64a5 100644 (file)
@@ -3,25 +3,24 @@
 %% bug#21526
 test1 :-
     (   a ->
-        b
+            (   a ->
+                b
+            ;   c
+            )
     ;   c
     ).
 
 test2 :-
     (    a
-    ->   b1,
+    ->   (   a,
+             b
+         ;   c
+         ),
          b2
     ;    c1,
          c2
     )
 
-test3 :-
-    (   a,
-        b
-    ;   c
-    ).
-
-
 %% Testing correct tokenizing.
 foo(X) :- 0'= = X.
 foo(X) :- 8'234 = X.