Function: prolog-electric--if-then-else

prolog-electric--if-then-else is a byte-compiled function defined in prolog.el.gz.

Signature

(prolog-electric--if-then-else)

Documentation

Insert spaces after the opening parenthesis.

"then" (->) and "else" (;) branches.
Spaces are inserted if all preceding objects on the line are whitespace characters, parentheses, or then/else branches.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/prolog.el.gz
(defun prolog-electric--if-then-else ()
  "Insert spaces after the opening parenthesis.
\"then\" (->) and \"else\" (;) branches.
Spaces are inserted if all preceding objects on the line are
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")
        ;; Treat "( If -> " lines specially.
        ;;(setq incr (if (looking-at "(.*->")
        ;;               2
        ;;             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))

          ;; Remove old white space
          (let ((start (point)))
            (skip-chars-forward " \t")
            (delete-region start (point)))
          (indent-to level)
          (skip-chars-forward " \t"))
        ))
    (when (save-excursion
            (backward-char 2)
            (looking-at "\\s ;\\|\\s (\\|->")) ; (looking-at "\\s \\((\\|;\\)"))
      (skip-chars-forward " \t"))
    ))