*** empty log message ***
[bpt/emacs.git] / lisp / progmodes / prolog.el
index cb45179..53a010a 100644 (file)
@@ -1,17 +1,17 @@
 ;;; prolog.el --- major mode for editing and running Prolog under Emacs
 
-;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+;;   2008, 2009  Free Software Foundation, Inc.
 
 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
 ;; Keywords: languages
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -32,7 +30,7 @@
 ;;; Code:
 
 (defvar comint-prompt-regexp)
-
+(defvar comint-process-echoes)
 
 (defgroup prolog nil
   "Major mode for editing and running Prolog under Emacs."
@@ -240,6 +238,17 @@ rigidly along with this one (not yet)."
 (defvar inferior-prolog-mode-syntax-table prolog-mode-syntax-table)
 (defvar inferior-prolog-mode-abbrev-table prolog-mode-abbrev-table)
 
+(defvar inferior-prolog-error-regexp-alist
+  ;; GNU Prolog used to not follow the GNU standard format.
+  '(("^\\(.*?\\):\\([0-9]+\\) error: .*(char:\\([0-9]+\\)" 1 2 3)
+    gnu))
+
+(declare-function comint-mode "comint")
+(declare-function comint-send-string "comint" (process string))
+(declare-function comint-send-region "comint" (process start end))
+(declare-function comint-send-eof "comint" ())
+(defvar compilation-error-regexp-alist)
+
 (define-derived-mode inferior-prolog-mode comint-mode "Inferior Prolog"
   "Major mode for interacting with an inferior Prolog process.
 
@@ -265,10 +274,19 @@ Return not at end copies rest of line to end and sends it.
 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
   (setq comint-prompt-regexp "^| [ ?][- ] *")
+  (set (make-local-variable 'compilation-error-regexp-alist)
+       inferior-prolog-error-regexp-alist)
+  (compilation-shell-minor-mode)
   (prolog-mode-variables))
 
 (defvar inferior-prolog-buffer nil)
 
+(defvar inferior-prolog-flavor 'unknown
+  "Either a symbol or a buffer position offset by one.
+If a buffer position, the flavor has not been determined yet and
+it is expected that the process's output has been or will
+be inserted at that position plus one.")
+
 (defun inferior-prolog-run (&optional name)
   (with-current-buffer (make-comint "prolog" (or name prolog-program-name))
     (inferior-prolog-mode)
@@ -302,12 +320,6 @@ Return not at end copies rest of line to end and sends it.
         ;; Try again.
         (inferior-prolog-process))))
 
-(defvar inferior-prolog-flavor 'unknown
-  "Either a symbol or a buffer position offset by one.
-If a buffer position, the flavor has not been determined yet and
-it is expected that the process's output has been or will
-be inserted at that position plus one.")
-
 (defun inferior-prolog-guess-flavor (&optional ignored)
   (save-excursion
     (goto-char (1+ inferior-prolog-flavor))
@@ -354,7 +366,11 @@ With prefix argument \\[universal-prefix], prompt for the program to use."
              (save-excursion
                (goto-char (- pmark 3))
                (looking-at " \\? ")))
-        (comint-send-string proc (string last-command-char))
+        ;; This is GNU prolog waiting to know whether you want more answers
+        ;; or not (or abort, etc...).  The answer is a single char, not
+        ;; a line, so pass this char directly rather than wait for RET to
+        ;; send a whole line.
+        (comint-send-string proc (string last-command-event))
       (call-interactively 'self-insert-command))))
 
 (defun prolog-consult-region (compile beg end)
@@ -379,6 +395,9 @@ If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
   (prolog-consult-region compile beg end)
   (pop-to-buffer inferior-prolog-buffer))
 
+;; inferior-prolog-mode uses the autoloaded compilation-shell-minor-mode.
+(declare-function compilation-forget-errors "compile" ())
+
 (defun inferior-prolog-load-file ()
   "Pass the current buffer's file to the inferior prolog process."
   (interactive)
@@ -386,6 +405,7 @@ If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
   (let ((file buffer-file-name)
         (proc (inferior-prolog-process)))
     (with-current-buffer (process-buffer proc)
+      (compilation-forget-errors)
       (comint-send-string proc (concat "['" (file-relative-name file) "'].\n"))
       (pop-to-buffer (current-buffer)))))