summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2015-09-20 23:01:16 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2015-09-20 23:01:16 -0400
commit57d48c364cf24c9f99f3d03eb74d9d2a81f4ae31 (patch)
tree71f7b6c0b5051b022e182782f2d3d8cee3eedb4d /lisp
parentdadcf33984391a285ef0b161c1122864264e4386 (diff)
downloademacs-57d48c364cf24c9f99f3d03eb74d9d2a81f4ae31.tar.gz
Subject: * lisp/progmodes/prolog.el: Improve handling of if/then/else
(prolog-smie-rules): Accomodate standard if/then/else special indentation. (prolog-mode): Add . to electric-indent-chars. (prolog-electric--if-then-else): Re-indent the line before adding space after the new char (bug#21526).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/prolog.el33
1 files changed, 29 insertions, 4 deletions
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index b36df213ce1..24ac8d75960 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -925,12 +925,30 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24."
(`(:after . ".") '(column . 0)) ;; To work around smie-closer-alist.
;; Allow indentation of if-then-else as:
;; ( test
- ;; -> thenrule
- ;; ; elserule
+ ;; -> thenrule
+ ;; ; elserule
;; )
(`(:before . ,(or `"->" `";"))
- (and (smie-rule-bolp) (smie-rule-parent-p "(") (smie-rule-parent 1)))
- (`(:after . ,(or `":-" `"->" `"-->")) prolog-indent-width)))
+ (and (smie-rule-bolp) (smie-rule-parent-p "(") (smie-rule-parent 0)))
+ (`(:after . ,(or `"->" `"*->"))
+ ;; We distinguish
+ ;;
+ ;; (a ->
+ ;; b;
+ ;; c)
+ ;; and
+ ;; ( a ->
+ ;; b
+ ;; ; c)
+ ;;
+ ;; based on the space between the open paren and the "a".
+ (unless (and (smie-rule-parent-p "(")
+ (save-excursion
+ (smie-indent-forward-token)
+ (smie-backward-sexp 'halfsexp)
+ (not (eq ?\( (char-before)))))
+ prolog-indent-width))
+ (`(:after . ,(or `":-" `"-->")) prolog-indent-width)))
;;-------------------------------------------------------------------
@@ -1121,6 +1139,9 @@ Commands:
(dolist (ar prolog-align-rules) (add-to-list 'align-rules-list ar))
(add-hook 'post-self-insert-hook #'prolog-post-self-insert nil t)
;; `imenu' entry moved to the appropriate hook for consistency.
+ (when prolog-electric-dot-flag
+ (setq-local electric-indent-chars
+ (cons ?\. electric-indent-chars)))
;; Load SICStus debugger if suitable
(if (and (eq prolog-system 'sicstus)
@@ -2078,6 +2099,7 @@ whitespace characters, parentheses, or then/else branches."
(when prolog-electric-if-then-else-flag
(save-excursion
(let ((regexp (concat "(\\|" prolog-left-indent-regexp))
+ (pos (point))
level)
(beginning-of-line)
(skip-chars-forward " \t")
@@ -2087,6 +2109,9 @@ whitespace characters, parentheses, or then/else branches."
;; prolog-paren-indent))
;; work on all subsequent "->", "(", ";"
+ (and (looking-at regexp)
+ (= pos (match-end 0))
+ (indent-according-to-mode))
(while (looking-at regexp)
(goto-char (match-end 0))
(setq level (+ (prolog-find-unmatched-paren) prolog-paren-indent))