changeset 110446:f81447dd641c

* lisp/progmodes/prolog.el (prolog-smie-forward-token) (prolog-smie-backward-token): New functions. (prolog-mode-variables): Use them to parse "!," correctly. Set up smie-blink-matching for ".". * test/indent/prolog.prolog: Use normal spacing around !.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 20 Sep 2010 16:22:16 +0200
parents 8035d26918c9
children 2ecf65f18c7c
files lisp/ChangeLog lisp/progmodes/prolog.el test/indent/prolog.prolog
diffstat 3 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Sep 20 16:15:27 2010 +0200
+++ b/lisp/ChangeLog	Mon Sep 20 16:22:16 2010 +0200
@@ -1,5 +1,10 @@
 2010-09-20  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* progmodes/prolog.el (prolog-smie-forward-token)
+	(prolog-smie-backward-token): New functions.
+	(prolog-mode-variables): Use them to parse "!," correctly.
+	Set up smie-blink-matching for ".".
+
 	* textmodes/ispell.el (ispell-start, ispell-end): Rename from `start'
 	and `end'.
 	(ispell-region, ispell-process-line): Update users.
--- a/lisp/progmodes/prolog.el	Mon Sep 20 16:15:27 2010 +0200
+++ b/lisp/progmodes/prolog.el	Mon Sep 20 16:22:16 2010 +0200
@@ -99,12 +99,36 @@
 (defvar prolog-mode-abbrev-table nil)
 (define-abbrev-table 'prolog-mode-abbrev-table ())
 
+(defun prolog-smie-forward-token ()
+  (forward-comment (point-max))
+  (buffer-substring-no-properties
+   (point)
+   (progn (cond
+           ((looking-at "[!;]") (forward-char 1))
+           ((not (zerop (skip-chars-forward "#&*+-./:<=>?@\\^`~"))))
+           ((not (zerop (skip-syntax-forward "w_'"))))
+           ;; In case of non-ASCII punctuation.
+           ((not (zerop (skip-syntax-forward ".")))))
+          (point))))
+
+(defun prolog-smie-backward-token ()
+  (forward-comment (- (point-max)))
+  (buffer-substring-no-properties
+   (point)
+   (progn (cond
+           ((memq (char-before) '(?! ?\;)) (forward-char -1))
+           ((not (zerop (skip-chars-backward "#&*+-./:<=>?@\\^`~"))))
+           ((not (zerop (skip-syntax-backward "w_'"))))
+           ;; In case of non-ASCII punctuation.
+           ((not (zerop (skip-syntax-backward ".")))))
+          (point))))
+
 (defconst prolog-smie-op-levels
   ;; Rather than construct the operator levels table from the BNF,
   ;; we directly provide the operator precedences from GNU Prolog's
-  ;; manual.  The only problem is that GNU Prolog's manual uses
-  ;; precedence levels in the opposite sense (higher numbers bind less
-  ;; tightly) than SMIE, so we use negative numbers.
+  ;; manual (7.14.10 op/3).  The only problem is that GNU Prolog's
+  ;; manual uses precedence levels in the opposite sense (higher
+  ;; numbers bind less tightly) than SMIE, so we use negative numbers.
   '(("." -10000 -10000)
     (":-" -1200 -1200)
     ("-->" -1200 -1200)
@@ -162,9 +186,18 @@
   (make-local-variable 'imenu-generic-expression)
   (setq imenu-generic-expression '((nil "^\\sw+" 0)))
   (smie-setup prolog-smie-op-levels prolog-smie-indent-rules)
+  (set (make-local-variable 'smie-forward-token-function)
+       #'prolog-smie-forward-token)
+  (set (make-local-variable 'smie-backward-token-function)
+       #'prolog-smie-backward-token)
   (set (make-local-variable 'forward-sexp-function)
        'smie-forward-sexp-command)
   (set (make-local-variable 'smie-indent-basic) prolog-indent-width)
+  (set (make-local-variable 'smie-blink-matching-triggers) '(?.))
+  (set (make-local-variable 'smie-closer-alist) '((t . ".")))
+  (add-hook 'post-self-insert-hook #'smie-blink-matching-open 'append 'local)
+  ;; There's no real closer in Prolog anyway.
+  (set (make-local-variable 'smie-blink-matching-inners) t)
   (make-local-variable 'comment-start)
   (setq comment-start "%")
   (make-local-variable 'comment-start-skip)
--- a/test/indent/prolog.prolog	Mon Sep 20 16:15:27 2010 +0200
+++ b/test/indent/prolog.prolog	Mon Sep 20 16:22:16 2010 +0200
@@ -150,7 +150,7 @@
 %% instantiate(+X, +T, -E)
 %% Utilise la variable X de type T.  Le résultat E est X auquel on ajoute
 %% tous les arguments implicites (de valeur inconnue).
-instantiate(X, T, X) :- var(T), ! .
+instantiate(X, T, X) :- var(T), !.
 instantiate(X, forall(_, _, T), app(E, _)) :- !, instantiate(X, T, E).
 instantiate(X, _, X).