summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2015-09-22 11:11:50 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2015-09-22 11:11:50 -0400
commit6c33e7ada5c0aa0dac1e6298c5b45c0134a90b92 (patch)
treefcfc8703ab42a2dad49d95741310849414615cbd /lisp/emacs-lisp
parent2fa2c87cac834cae253a7fc6fcab280723660f74 (diff)
downloademacs-6c33e7ada5c0aa0dac1e6298c5b45c0134a90b92.tar.gz
emacs-6c33e7ada5c0aa0dac1e6298c5b45c0134a90b92.tar.bz2
emacs-6c33e7ada5c0aa0dac1e6298c5b45c0134a90b92.zip
* prolog.el: Fix indentation of empty line
* 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.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/smie.el17
1 files changed, 16 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index eb5a7132c7e..f305025f215 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -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