X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d364dee6ba29f72f1ed1e715043e865af5fc98ef..c94d5f81aaef23672bf1be040c9388f8fe9f88e5:/lisp/progmodes/prolog.el diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el index 7bb8c3a3f4..7cff1bc516 100644 --- a/lisp/progmodes/prolog.el +++ b/lisp/progmodes/prolog.el @@ -1,6 +1,6 @@ ;;; prolog.el --- major mode for editing and running Prolog under Emacs -;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005, 2006 +;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005, 2006, 2007 ;; Free Software Foundation, Inc. ;; Author: Masanobu UMEDA @@ -10,7 +10,7 @@ ;; 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) +;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, @@ -233,6 +233,8 @@ rigidly along with this one (not yet)." (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 @@ 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)) + (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 @@ With prefix argument \\[universal-prefix], prompt for the program to use." (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." 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."