Commit 6cfd4f3a authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(prolog-program-name): Use gprolog if available.

(prolog-mode-syntax-table, prolog-mode-abbrev-table, prolog-mode-map):
Bring together declaration and initialization.
(prolog-mode-variables): Don't set the syntax table.
Don't set paragraph-start and comment-indent-function.
Add /*..*/ to the comment regexps.
(prolog-mode-commands): Remove.  Do it during init of prolog-mode-map.
(prolog-mode-map): Don't bind TAB.
(prolog-mode): Set the syntax table.
(prolog-comment-indent): Remove.
(inferior-prolog-mode-map): Initialize in the declaration.
(inferior-prolog-mode-syntax-table)
(inferior-prolog-mode-abbrev-table): New vars.
(inferior-prolog-mode): Derive from comint-mode.
(run-prolog): Avoid switch-to-buffer which can fail in dedicated and
minibuffer windows.
parent c3c6c23c
;;; prolog.el --- major mode for editing and running Prolog under Emacs
;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
;; Copyright (C) 1986, 1987, 2003, 2004 Free Software Foundation, Inc.
;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
;; Keywords: languages
......@@ -30,16 +30,17 @@
;;; Code:
(defvar prolog-mode-syntax-table nil)
(defvar prolog-mode-abbrev-table nil)
(defvar prolog-mode-map nil)
(defgroup prolog nil
"Major mode for editing and running Prolog under Emacs"
:group 'languages)
(defcustom prolog-program-name "prolog"
(defcustom prolog-program-name
(let ((names '("prolog" "gprolog")))
(while (and names
(not (executable-find (car names))))
(setq names (cdr names)))
(or (car names) "prolog"))
"*Program name for invoking an inferior Prolog with `run-prolog'."
:type 'string
:group 'prolog)
......@@ -75,8 +76,7 @@ nil means send actual operating system end of file."
(3 font-lock-variable-name-face)))
"Font-lock keywords for Prolog mode.")
(if prolog-mode-syntax-table
()
(defvar prolog-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?_ "w" table)
(modify-syntax-entry ?\\ "\\" table)
......@@ -90,17 +90,14 @@ nil means send actual operating system end of file."
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?\' "\"" table)
(setq prolog-mode-syntax-table table)))
table))
(defvar prolog-mode-abbrev-table nil)
(define-abbrev-table 'prolog-mode-abbrev-table ())
(defun prolog-mode-variables ()
(set-syntax-table prolog-mode-syntax-table)
(setq local-abbrev-table prolog-mode-abbrev-table)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
(make-local-variable 'paragraph-separate)
(setq paragraph-separate paragraph-start)
(setq paragraph-separate (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'imenu-generic-expression)
......@@ -110,20 +107,16 @@ nil means send actual operating system end of file."
(make-local-variable 'comment-start)
(setq comment-start "%")
(make-local-variable 'comment-start-skip)
(setq comment-start-skip "%+ *")
(setq comment-start-skip "\\(?:%+\\|/\\*+\\)[ \t]*")
(make-local-variable 'comment-end-skip)
(setq comment-end-skip "[ \t]*\\(\n\\|\\*+/\\)")
(make-local-variable 'comment-column)
(setq comment-column 48)
(make-local-variable 'comment-indent-function)
(setq comment-indent-function 'prolog-comment-indent))
(defun prolog-mode-commands (map)
(define-key map "\t" 'prolog-indent-line)
(define-key map "\e\C-x" 'prolog-consult-region))
(setq comment-column 48))
(if prolog-mode-map
nil
(setq prolog-mode-map (make-sparse-keymap))
(prolog-mode-commands prolog-mode-map))
(defvar prolog-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\e\C-x" 'prolog-consult-region)
map))
;;;###autoload
(defun prolog-mode ()
......@@ -136,6 +129,7 @@ if that value is non-nil."
(interactive)
(kill-all-local-variables)
(use-local-map prolog-mode-map)
(set-syntax-table prolog-mode-syntax-table)
(setq major-mode 'prolog-mode)
(setq mode-name "Prolog")
(prolog-mode-variables)
......@@ -143,7 +137,7 @@ if that value is non-nil."
(setq font-lock-defaults '(prolog-font-lock-keywords
nil nil nil
beginning-of-line))
(run-hooks 'prolog-mode-hook))
(run-mode-hooks 'prolog-mode-hook))
(defun prolog-indent-line (&optional whole-exp)
"Indent current line as Prolog code.
......@@ -217,26 +211,20 @@ rigidly along with this one (not yet)."
(if (re-search-forward comment-start-skip eolpos 'move)
(goto-char (match-beginning 0)))
(skip-chars-backward " \t")))
(defun prolog-comment-indent ()
"Compute prolog comment indentation."
(cond ((looking-at "%%%") 0)
((looking-at "%%") (prolog-indent-level))
(t
(save-excursion
(skip-chars-backward " \t")
;; Insert one space at least, except at left margin.
(max (+ (current-column) (if (bolp) 0 1))
comment-column)))
))
;;;
;;; Inferior prolog mode
;;;
(defvar inferior-prolog-mode-map nil)
(defvar inferior-prolog-mode-map
(let ((map (make-sparse-keymap)))
;; This map will inherit from `comint-mode-map' when entering
;; inferior-prolog-mode.
map))
(defvar inferior-prolog-mode-syntax-table prolog-mode-syntax-table)
(defvar inferior-prolog-mode-abbrev-table prolog-mode-abbrev-table)
(defun inferior-prolog-mode ()
(define-derived-mode inferior-prolog-mode comint-mode "Inferior Prolog"
"Major mode for interacting with an inferior Prolog process.
The following commands are available:
......@@ -260,25 +248,15 @@ Return not at end copies rest of line to end and sends it.
\\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
\\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
\\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
(interactive)
(require 'comint)
(comint-mode)
(setq major-mode 'inferior-prolog-mode
mode-name "Inferior Prolog"
comint-prompt-regexp "^| [ ?][- ] *")
(prolog-mode-variables)
(if inferior-prolog-mode-map nil
(setq inferior-prolog-mode-map (copy-keymap comint-mode-map))
(prolog-mode-commands inferior-prolog-mode-map))
(use-local-map inferior-prolog-mode-map)
(run-hooks 'prolog-mode-hook))
(setq comint-prompt-regexp "^| [ ?][- ] *")
(prolog-mode-variables))
;;;###autoload
(defun run-prolog ()
"Run an inferior Prolog process, input and output via buffer *prolog*."
(interactive)
(require 'comint)
(switch-to-buffer (make-comint "prolog" prolog-program-name))
(pop-to-buffer (make-comint "prolog" prolog-program-name))
(inferior-prolog-mode))
(defun prolog-consult-region (compile beg end)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment