changeset 72696:560a2e73e11b

(inferior-prolog-flavor): New var left out of previous commit. (inferior-prolog-guess-flavor): New fun left out of previous commit. (prolog-consult-region-and-go): Don't hard code "*prolog*" and don't burp in dedicated windows. (inferior-prolog-self-insert-command): New command. (inferior-prolog-mode-map): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 07 Sep 2006 16:18:06 +0000
parents 31cd9bba3cdd
children 223d4d3bae83
files lisp/ChangeLog lisp/progmodes/prolog.el
diffstat 2 files changed, 50 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Sep 07 15:11:43 2006 +0000
+++ b/lisp/ChangeLog	Thu Sep 07 16:18:06 2006 +0000
@@ -1,3 +1,13 @@
+2006-09-07  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* progmodes/prolog.el (inferior-prolog-flavor): New var left out of
+	previous commit.
+	(inferior-prolog-guess-flavor): New fun left out of previous commit.
+	(prolog-consult-region-and-go): Don't hard code "*prolog*" and don't
+	burp in dedicated windows.
+	(inferior-prolog-self-insert-command): New command.
+	(inferior-prolog-mode-map): Use it.
+
 2006-09-07  Reiner Steib  <Reiner.Steib@gmx.de>
 
 	* international/latexenc.el (latex-inputenc-coding-alist): Add cp858.
--- a/lisp/progmodes/prolog.el	Thu Sep 07 15:11:43 2006 +0000
+++ b/lisp/progmodes/prolog.el	Thu Sep 07 16:18:06 2006 +0000
@@ -233,6 +233,8 @@
   (let ((map (make-sparse-keymap)))
     ;; This map will inherit from `comint-mode-map' when entering
     ;; inferior-prolog-mode.
+    (define-key map [remap self-insert-command]
+      'inferior-prolog-self-insert-command)
     map))
 
 (defvar inferior-prolog-mode-syntax-table prolog-mode-syntax-table)
@@ -300,6 +302,27 @@
         ;; 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))
+    (setq inferior-prolog-flavor
+          (cond
+           ((looking-at "GNU Prolog") 'gnu)
+           ((looking-at "Welcome to SWI-Prolog") 'swi)
+           ((looking-at ".*\n") 'unknown) ;There's at least one line.
+           (t inferior-prolog-flavor))))
+  (when (symbolp inferior-prolog-flavor)
+    (remove-hook 'comint-output-filter-functions
+                 'inferior-prolog-guess-flavor t)
+    (if (eq inferior-prolog-flavor 'gnu)
+        (set (make-local-variable 'comint-process-echoes) t))))
+
 ;;;###autoload
 (defalias 'run-prolog 'switch-to-prolog)
 ;;;###autoload
@@ -318,6 +341,22 @@
     (inferior-prolog-run name))
   (pop-to-buffer inferior-prolog-buffer))
 
+(defun inferior-prolog-self-insert-command ()
+  "Insert the char in the buffer or pass it directly to the process."
+  (interactive)
+  (let* ((proc (get-buffer-process (current-buffer)))
+         (pmark (and proc (marker-position (process-mark proc)))))
+    (if (and (eq inferior-prolog-flavor 'gnu)
+             pmark
+             (null current-prefix-arg)
+             (eobp)
+             (eq (point) pmark)
+             (save-excursion
+               (goto-char (- pmark 3))
+               (looking-at " \\? ")))
+        (comint-send-string proc (string last-command-char))
+      (call-interactively 'self-insert-command))))
+
 (defun prolog-consult-region (compile beg end)
   "Send the region to the Prolog process made by \"M-x run-prolog\".
 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
@@ -338,7 +377,7 @@
 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
   (interactive "P\nr")
   (prolog-consult-region compile beg end)
-  (switch-to-buffer "*prolog*"))
+  (pop-to-buffer inferior-prolog-buffer))
 
 (defun inferior-prolog-load-file ()
   "Pass the current buffer's file to the inferior prolog process."