(require 'smie)
+(defconst prolog-operator-chars "-\\\\#&*+./:<=>?@\\^`~")
+
(defun prolog-smie-forward-token ()
;; FIXME: Add support for 0'<char>, if needed after adding it to
;; syntax-propertize-functions.
(point)
(progn (cond
((looking-at "[!;]") (forward-char 1))
- ((not (zerop (skip-chars-forward "#&*+-./:<=>?@\\^`~"))))
+ ((not (zerop (skip-chars-forward prolog-operator-chars))))
((not (zerop (skip-syntax-forward "w_'"))))
;; In case of non-ASCII punctuation.
((not (zerop (skip-syntax-forward ".")))))
(buffer-substring-no-properties
(point)
(progn (cond
- ((memq (char-before) '(?! ?\;)) (forward-char -1))
- ((not (zerop (skip-chars-backward "#&*+-./:<=>?@\\^`~"))))
+ ((memq (char-before) '(?! ?\; ?\,)) (forward-char -1))
+ ((not (zerop (skip-chars-backward prolog-operator-chars))))
((not (zerop (skip-syntax-backward "w_'"))))
;; In case of non-ASCII punctuation.
((not (zerop (skip-syntax-backward ".")))))
;; ; c)
;;
;; based on the space between the open paren and the "a".
- (unless (and (smie-rule-parent-p "(")
+ (unless (and (smie-rule-parent-p "(" ";")
(save-excursion
(smie-indent-forward-token)
(smie-backward-sexp 'halfsexp)
- (not (eq ?\( (char-before)))))
+ (if (smie-rule-parent-p "(")
+ (not (eq (char-before) ?\())
+ (smie-indent-backward-token)
+ (smie-rule-bolp))))
prolog-indent-width))
+ (`(:after . ";")
+ ;; Align with same-line comment as in:
+ ;; ; %% Toto
+ ;; foo
+ (and (smie-rule-bolp)
+ (looking-at ";[ \t]*\\(%\\)")
+ (let ((offset (- (save-excursion (goto-char (match-beginning 1))
+ (current-column))
+ (current-column))))
+ ;; Only do it for small offsets, since the comment may actually be
+ ;; an "end-of-line" comment at comment-column!
+ (if (<= offset prolog-indent-width) offset))))
+ (`(:after . ",")
+ ;; Special indent for:
+ ;; foopredicate(x) :- !,
+ ;; toto.
+ (and (eq (char-before) ?!)
+ (save-excursion
+ (smie-indent-backward-token) ;Skip !
+ (equal ":-" (car (smie-indent-backward-token))))
+ (smie-rule-parent prolog-indent-width)))
(`(:after . ,(or `":-" `"-->")) prolog-indent-width)))
\f
%% -*- mode: prolog; coding: utf-8; fill-column: 78 -*-
%% bug#21526
-test1 :-
+test21526_1 :-
( a ->
- ( a ->
- b
- ; c
- )
- ; c
+ ( a ->
+ b
+ ; c
+ )
+ ; % Toto
+ c ->
+ d
).
-test2 :-
+test21526_2 :-
( a
-> ( a,
b
b2
; c1,
c2
- )
+ ).
+
+test21526_3 :-
+ X \= Y,
+ \+ a,
+ b,
+ \+ \+ c,
+ d.
+
+test21526_4 :-
+ ( \+ a ->
+ b
+ ; \+ c,
+ \+ d
+ ).
+
+
+test21526_5 :-
+ (a;
+ b ->
+ c).
+
+test21526_predicate(c) :- !,
+ test_goal1,
+ test_goal2.
%% Testing correct tokenizing.
foo(X) :- 0'= = X.
%% If X is equal to Y, X is shadowed, so no subst can take place.
-> Y1 = Y, Bo = Bi
; (member((Y, _), FV)
- %% If Y appears in FV, it can appear in V, so we need to
- %% rename it to avoid name capture.
- -> new_atom(Y, Y1),
- subst(Y, Y1, [], Bi, Bi1)
- ; Y1 = Y, Bi1 = Bi),
+ %% If Y appears in FV, it can appear in V, so we need to
+ %% rename it to avoid name capture.
+ -> new_atom(Y, Y1),
+ subst(Y, Y1, [], Bi, Bi1)
+ ; Y1 = Y, Bi1 = Bi),
%% Perform substitution on the body.
subst(X, V, FV, Bi1, Bo)
).