*** prolog-1.14/prolog.el 2006-12-21 17:47:36.000000000 +0100 --- prolog.el 2007-02-15 10:20:21.000000000 +0100 *************** *** 457,462 **** --- 457,470 ---- :group 'prolog-keyboard :type 'boolean) + (defcustom prolog-electric-dot-full-predicate-template t + "*If nil, electric dot inserts only the current predicate's + name and `(' for recursive calls or new clause heads. Non-nil + means to also insert enough commata to cover the predicate's + arity and `)', and dot and newline for recursive calls." + :group 'prolog-keyboard + :type 'boolean) + (defcustom prolog-electric-underscore-flag nil "*Non-nil means make underscore key electric. Electric underscore replaces the current variable with underscore. *************** *** 472,478 **** :type 'boolean) (defcustom prolog-electric-if-then-else-flag nil ! "*Non-nil makes (, -> and ; it-then-else electric." :group 'prolog-keyboard :type 'boolean) --- 480,499 ---- :type 'boolean) (defcustom prolog-electric-if-then-else-flag nil ! "*Non-nil makes `(', `>' and `;' electric to automatically ! indent if-then-else constructs." ! :group 'prolog-keyboard ! :type 'boolean) ! ! (defcustom prolog-electric-colon-flag nil ! "*If non-nil, pressing `:' at the end of a line that starts in ! the first column (i.e., clause heads) inserts ` :-' and newline." ! :group 'prolog-keyboard ! :type 'boolean) ! ! (defcustom prolog-electric-dash-flag nil ! "*If non-nil, pressing `-' at the end of a line that starts in ! the first column (i.e., DCG heads) inserts ` -->' and newline." :group 'prolog-keyboard :type 'boolean) *************** *** 892,897 **** --- 913,920 ---- (define-key map "(" 'prolog-electric-if-then-else) (define-key map ";" 'prolog-electric-if-then-else) (define-key map ">" 'prolog-electric-if-then-else) + (define-key map ":" 'prolog-electric-colon) + (define-key map "-" 'prolog-electric-dash) (if prolog-electric-newline-flag (define-key map "\r" 'newline-and-indent)) *************** *** 3329,3340 **** (if (> arity 0) (progn (insert "(") ! (setq oldp (point)) ! (while (< n arity) ! (insert ",") ! (setq n (1+ n))) ! (insert ")") ! (goto-char oldp) )) )) --- 3352,3364 ---- (if (> arity 0) (progn (insert "(") ! (when prolog-electric-dot-full-predicate-template ! (setq oldp (point)) ! (while (< n arity) ! (insert ",") ! (setq n (1+ n))) ! (insert ")") ! (goto-char oldp)) )) )) *************** *** 3430,3441 **** (put 'prolog-electric-delete 'pending-delete 'supersede) (defun prolog-electric-if-then-else (arg) ! "If `prolog-electric-if-then-else-flag' is non-nil, indent if-then-else constructs. ! Bound to the >, ; and ( keys." (interactive "P") (self-insert-command (prefix-numeric-value arg)) (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren))) (defun prolog-electric-dot (arg) "Insert dot and newline or a head of a new clause. --- 3454,3497 ---- (put 'prolog-electric-delete 'pending-delete 'supersede) (defun prolog-electric-if-then-else (arg) ! "If `prolog-electric-if-then-else-flag' is non-nil, indent ! if-then-else constructs. Bound to the >, ; and ( keys." (interactive "P") (self-insert-command (prefix-numeric-value arg)) (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren))) + (defun prolog-electric-colon (arg) + "If `prolog-electric-colon-flag' is non-nil, insert space (if + appropriate), `:-' and newline if colon is pressed at the end of + a line that starts in the first column (i.e., clause heads)." + (interactive "P") + (if (and prolog-electric-colon-flag + (null arg) + (= (point) (line-end-position)) + (not (= (point) (line-beginning-position))) + (not (string-match "^\\(\\s \\:\\|%\\)" (thing-at-point 'line)))) + (progn + (unless (looking-back "\\s ") (insert " ")) + (insert ":-\n") + (prolog-indent-line)) + (self-insert-command (prefix-numeric-value arg)))) + + (defun prolog-electric-dash (arg) + "If `prolog-electric-dash-flag' is non-nil, insert space (if + appropriate), `-->' and newline if dash is pressed at the end of + a line that starts in the first column (i.e., DCG heads)." + (interactive "P") + (if (and prolog-electric-dash-flag + (null arg) + (= (point) (line-end-position)) + (not (= (point) (line-beginning-position))) + (not (string-match "^\\(\\s \\|:\\|%\\)" (thing-at-point 'line)))) + (progn + (unless (looking-back "\\s ") (insert " ")) + (insert "-->\n") + (prolog-indent-line)) + (self-insert-command (prefix-numeric-value arg)))) + (defun prolog-electric-dot (arg) "Insert dot and newline or a head of a new clause. *************** *** 3492,3503 **** (beginning-of-line) (looking-at "[ \t]+$")) (prolog-insert-predicate-template) ! (save-excursion ! (end-of-line) ! (insert ".\n"))) ;; Default (t ! (insert ".\n")) ))) (defun prolog-electric-underscore () --- 3548,3562 ---- (beginning-of-line) (looking-at "[ \t]+$")) (prolog-insert-predicate-template) ! (when prolog-electric-dot-full-predicate-template ! (save-excursion ! (end-of-line) ! (insert ".\n")))) ;; Default (t ! (insert ".") ! (when prolog-electric-dot-full-predicate-template ! (insert "\n"))) ))) (defun prolog-electric-underscore ()