diff options
| -rw-r--r-- | lisp/progmodes/prolog.el | 36 | ||||
| -rw-r--r-- | test/indent/prolog.prolog | 52 |
2 files changed, 70 insertions, 18 deletions
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el index 3d9b0c322ab..ff2769e7493 100644 --- a/lisp/progmodes/prolog.el +++ b/lisp/progmodes/prolog.el | |||
| @@ -840,6 +840,8 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24." | |||
| 840 | 840 | ||
| 841 | (require 'smie) | 841 | (require 'smie) |
| 842 | 842 | ||
| 843 | (defconst prolog-operator-chars "-\\\\#&*+./:<=>?@\\^`~") | ||
| 844 | |||
| 843 | (defun prolog-smie-forward-token () | 845 | (defun prolog-smie-forward-token () |
| 844 | ;; FIXME: Add support for 0'<char>, if needed after adding it to | 846 | ;; FIXME: Add support for 0'<char>, if needed after adding it to |
| 845 | ;; syntax-propertize-functions. | 847 | ;; syntax-propertize-functions. |
| @@ -848,7 +850,7 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24." | |||
| 848 | (point) | 850 | (point) |
| 849 | (progn (cond | 851 | (progn (cond |
| 850 | ((looking-at "[!;]") (forward-char 1)) | 852 | ((looking-at "[!;]") (forward-char 1)) |
| 851 | ((not (zerop (skip-chars-forward "#&*+-./:<=>?@\\^`~")))) | 853 | ((not (zerop (skip-chars-forward prolog-operator-chars)))) |
| 852 | ((not (zerop (skip-syntax-forward "w_'")))) | 854 | ((not (zerop (skip-syntax-forward "w_'")))) |
| 853 | ;; In case of non-ASCII punctuation. | 855 | ;; In case of non-ASCII punctuation. |
| 854 | ((not (zerop (skip-syntax-forward "."))))) | 856 | ((not (zerop (skip-syntax-forward "."))))) |
| @@ -861,8 +863,8 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24." | |||
| 861 | (buffer-substring-no-properties | 863 | (buffer-substring-no-properties |
| 862 | (point) | 864 | (point) |
| 863 | (progn (cond | 865 | (progn (cond |
| 864 | ((memq (char-before) '(?! ?\;)) (forward-char -1)) | 866 | ((memq (char-before) '(?! ?\; ?\,)) (forward-char -1)) |
| 865 | ((not (zerop (skip-chars-backward "#&*+-./:<=>?@\\^`~")))) | 867 | ((not (zerop (skip-chars-backward prolog-operator-chars)))) |
| 866 | ((not (zerop (skip-syntax-backward "w_'")))) | 868 | ((not (zerop (skip-syntax-backward "w_'")))) |
| 867 | ;; In case of non-ASCII punctuation. | 869 | ;; In case of non-ASCII punctuation. |
| 868 | ((not (zerop (skip-syntax-backward "."))))) | 870 | ((not (zerop (skip-syntax-backward "."))))) |
| @@ -947,12 +949,36 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24." | |||
| 947 | ;; ; c) | 949 | ;; ; c) |
| 948 | ;; | 950 | ;; |
| 949 | ;; based on the space between the open paren and the "a". | 951 | ;; based on the space between the open paren and the "a". |
| 950 | (unless (and (smie-rule-parent-p "(") | 952 | (unless (and (smie-rule-parent-p "(" ";") |
| 951 | (save-excursion | 953 | (save-excursion |
| 952 | (smie-indent-forward-token) | 954 | (smie-indent-forward-token) |
| 953 | (smie-backward-sexp 'halfsexp) | 955 | (smie-backward-sexp 'halfsexp) |
| 954 | (not (eq ?\( (char-before))))) | 956 | (if (smie-rule-parent-p "(") |
| 957 | (not (eq (char-before) ?\()) | ||
| 958 | (smie-indent-backward-token) | ||
| 959 | (smie-rule-bolp)))) | ||
| 955 | prolog-indent-width)) | 960 | prolog-indent-width)) |
| 961 | (`(:after . ";") | ||
| 962 | ;; Align with same-line comment as in: | ||
| 963 | ;; ; %% Toto | ||
| 964 | ;; foo | ||
| 965 | (and (smie-rule-bolp) | ||
| 966 | (looking-at ";[ \t]*\\(%\\)") | ||
| 967 | (let ((offset (- (save-excursion (goto-char (match-beginning 1)) | ||
| 968 | (current-column)) | ||
| 969 | (current-column)))) | ||
| 970 | ;; Only do it for small offsets, since the comment may actually be | ||
| 971 | ;; an "end-of-line" comment at comment-column! | ||
| 972 | (if (<= offset prolog-indent-width) offset)))) | ||
| 973 | (`(:after . ",") | ||
| 974 | ;; Special indent for: | ||
| 975 | ;; foopredicate(x) :- !, | ||
| 976 | ;; toto. | ||
| 977 | (and (eq (char-before) ?!) | ||
| 978 | (save-excursion | ||
| 979 | (smie-indent-backward-token) ;Skip ! | ||
| 980 | (equal ":-" (car (smie-indent-backward-token)))) | ||
| 981 | (smie-rule-parent prolog-indent-width))) | ||
| 956 | (`(:after . ,(or `":-" `"-->")) prolog-indent-width))) | 982 | (`(:after . ,(or `":-" `"-->")) prolog-indent-width))) |
| 957 | 983 | ||
| 958 | 984 | ||
diff --git a/test/indent/prolog.prolog b/test/indent/prolog.prolog index 6bf9437b883..9ac6df1b6c7 100644 --- a/test/indent/prolog.prolog +++ b/test/indent/prolog.prolog | |||
| @@ -1,16 +1,18 @@ | |||
| 1 | %% -*- mode: prolog; coding: utf-8; fill-column: 78 -*- | 1 | %% -*- mode: prolog; coding: utf-8; fill-column: 78 -*- |
| 2 | 2 | ||
| 3 | %% bug#21526 | 3 | %% bug#21526 |
| 4 | test1 :- | 4 | test21526_1 :- |
| 5 | ( a -> | 5 | ( a -> |
| 6 | ( a -> | 6 | ( a -> |
| 7 | b | 7 | b |
| 8 | ; c | 8 | ; c |
| 9 | ) | 9 | ) |
| 10 | ; c | 10 | ; % Toto |
| 11 | c -> | ||
| 12 | d | ||
| 11 | ). | 13 | ). |
| 12 | 14 | ||
| 13 | test2 :- | 15 | test21526_2 :- |
| 14 | ( a | 16 | ( a |
| 15 | -> ( a, | 17 | -> ( a, |
| 16 | b | 18 | b |
| @@ -19,7 +21,31 @@ test2 :- | |||
| 19 | b2 | 21 | b2 |
| 20 | ; c1, | 22 | ; c1, |
| 21 | c2 | 23 | c2 |
| 22 | ) | 24 | ). |
| 25 | |||
| 26 | test21526_3 :- | ||
| 27 | X \= Y, | ||
| 28 | \+ a, | ||
| 29 | b, | ||
| 30 | \+ \+ c, | ||
| 31 | d. | ||
| 32 | |||
| 33 | test21526_4 :- | ||
| 34 | ( \+ a -> | ||
| 35 | b | ||
| 36 | ; \+ c, | ||
| 37 | \+ d | ||
| 38 | ). | ||
| 39 | |||
| 40 | |||
| 41 | test21526_5 :- | ||
| 42 | (a; | ||
| 43 | b -> | ||
| 44 | c). | ||
| 45 | |||
| 46 | test21526_predicate(c) :- !, | ||
| 47 | test_goal1, | ||
| 48 | test_goal2. | ||
| 23 | 49 | ||
| 24 | %% Testing correct tokenizing. | 50 | %% Testing correct tokenizing. |
| 25 | foo(X) :- 0'= = X. | 51 | foo(X) :- 0'= = X. |
| @@ -74,11 +100,11 @@ subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)) :- | |||
| 74 | %% If X is equal to Y, X is shadowed, so no subst can take place. | 100 | %% If X is equal to Y, X is shadowed, so no subst can take place. |
| 75 | -> Y1 = Y, Bo = Bi | 101 | -> Y1 = Y, Bo = Bi |
| 76 | ; (member((Y, _), FV) | 102 | ; (member((Y, _), FV) |
| 77 | %% If Y appears in FV, it can appear in V, so we need to | 103 | %% If Y appears in FV, it can appear in V, so we need to |
| 78 | %% rename it to avoid name capture. | 104 | %% rename it to avoid name capture. |
| 79 | -> new_atom(Y, Y1), | 105 | -> new_atom(Y, Y1), |
| 80 | subst(Y, Y1, [], Bi, Bi1) | 106 | subst(Y, Y1, [], Bi, Bi1) |
| 81 | ; Y1 = Y, Bi1 = Bi), | 107 | ; Y1 = Y, Bi1 = Bi), |
| 82 | %% Perform substitution on the body. | 108 | %% Perform substitution on the body. |
| 83 | subst(X, V, FV, Bi1, Bo) | 109 | subst(X, V, FV, Bi1, Bo) |
| 84 | ). | 110 | ). |