annotate lisp/progmodes/prolog.el @ 41:467ee6fe6503

Initial revision
author root <root>
date Mon, 11 Dec 1989 04:58:09 +0000
parents
children 5647f2040009
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
1 ;; Major mode for editing Prolog, and for running Prolog under Emacs
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
2 ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
3 ;; Author Masanobu UMEDA (umerin@flab.flab.fujitsu.junet)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
4
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
6
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 1, or (at your option)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
10 ;; any later version.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
11
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
15 ;; GNU General Public License for more details.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
16
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
20
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
21 (defvar prolog-mode-syntax-table nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
22 (defvar prolog-mode-abbrev-table nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
23 (defvar prolog-mode-map nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
24
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
25 (defvar prolog-program-name "prolog"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
26 "*Program name for invoking an inferior Prolog with `run-prolog'.")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
27
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
28 (defvar prolog-consult-string "reconsult(user).\n"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
29 "*(Re)Consult mode (for C-Prolog and Quintus Prolog). ")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
30
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
31 (defvar prolog-compile-string "compile(user).\n"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
32 "*Compile mode (for Quintus Prolog).")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
33
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
34 (defvar prolog-eof-string "end_of_file.\n"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
35 "*String that represents end of file for prolog.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
36 nil means send actual operaing system end of file.")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
37
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
38 (defvar prolog-indent-width 4)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
39
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
40 (if prolog-mode-syntax-table
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
41 ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
42 (let ((table (make-syntax-table)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
43 (modify-syntax-entry ?_ "w" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
44 (modify-syntax-entry ?\\ "\\" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
45 (modify-syntax-entry ?/ "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
46 (modify-syntax-entry ?* "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
47 (modify-syntax-entry ?+ "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
48 (modify-syntax-entry ?- "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
49 (modify-syntax-entry ?= "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
50 (modify-syntax-entry ?% "<" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
51 (modify-syntax-entry ?< "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
52 (modify-syntax-entry ?> "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
53 (modify-syntax-entry ?\' "\"" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
54 (setq prolog-mode-syntax-table table)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
55
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
56 (define-abbrev-table 'prolog-mode-abbrev-table ())
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
57
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
58 (defun prolog-mode-variables ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
59 (set-syntax-table prolog-mode-syntax-table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
60 (setq local-abbrev-table prolog-mode-abbrev-table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
61 (make-local-variable 'paragraph-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
62 (setq paragraph-start (concat "^%%\\|^$\\|" page-delimiter)) ;'%%..'
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
63 (make-local-variable 'paragraph-separate)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
64 (setq paragraph-separate paragraph-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
65 (make-local-variable 'paragraph-ignore-fill-prefix)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
66 (setq paragraph-ignore-fill-prefix t)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
67 (make-local-variable 'indent-line-function)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
68 (setq indent-line-function 'prolog-indent-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
69 (make-local-variable 'comment-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
70 (setq comment-start "%")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
71 (make-local-variable 'comment-start-skip)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
72 (setq comment-start-skip "%+ *")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
73 (make-local-variable 'comment-column)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
74 (setq comment-column 48)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
75 (make-local-variable 'comment-indent-hook)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
76 (setq comment-indent-hook 'prolog-comment-indent))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
77
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
78 (defun prolog-mode-commands (map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
79 (define-key map "\t" 'prolog-indent-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
80 (define-key map "\e\C-x" 'prolog-consult-region))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
81
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
82 (if prolog-mode-map
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
83 nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
84 (setq prolog-mode-map (make-sparse-keymap))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
85 (prolog-mode-commands prolog-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
86
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
87 (defun prolog-mode ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
88 "Major mode for editing Prolog code for Prologs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
89 Blank lines and `%%...' separate paragraphs. `%'s start comments.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
90 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
91 \\{prolog-mode-map}
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
92 Entry to this mode calls the value of prolog-mode-hook
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
93 if that value is non-nil."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
94 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
95 (kill-all-local-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
96 (use-local-map prolog-mode-map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
97 (setq major-mode 'prolog-mode)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
98 (setq mode-name "Prolog")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
99 (prolog-mode-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
100 (run-hooks 'prolog-mode-hook))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
101
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
102 (defun prolog-indent-line (&optional whole-exp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
103 "Indent current line as Prolog code.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
104 With argument, indent any additional lines of the same clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
105 rigidly along with this one (not yet)."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
106 (interactive "p")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
107 (let ((indent (prolog-indent-level))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
108 (pos (- (point-max) (point))) beg)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
109 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
110 (setq beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
111 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
112 (if (zerop (- indent (current-column)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
113 nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
114 (delete-region beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
115 (indent-to indent))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
116 (if (> (- (point-max) pos) (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
117 (goto-char (- (point-max) pos)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
118 ))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
119
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
120 (defun prolog-indent-level ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
121 "Compute prolog indentation level."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
122 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
123 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
124 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
125 (cond
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
126 ((looking-at "%%%") 0) ;Large comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
127 ((looking-at "%[^%]") comment-column) ;Small comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
128 ((bobp) 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
129 (t
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
130 (let ((empty t) ind more less)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
131 (if (looking-at ")")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
132 (setq less t) ;Find close
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
133 (setq less nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
134 ;; See previous indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
135 (while empty
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
136 (forward-line -1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
137 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
138 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
139 (setq empty nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
140 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
141 (if (not (or (looking-at "%[^%]") (looking-at "\n")))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
142 (setq empty nil))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
143 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
144 (setq ind 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
145 (setq ind (current-column))) ;Beginning of clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
146 ;; See its beginning
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
147 (if (looking-at "%%[^%]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
148 ind
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
149 ;; Real prolog code
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
150 (if (looking-at "(")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
151 (setq more t) ;Find open
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
152 (setq more nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
153 ;; See its tail
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
154 (end-of-prolog-clause)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
155 (or (bobp) (forward-char -1))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
156 (cond ((looking-at "[,(;>]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
157 (if (and more (looking-at "[^,]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
158 (+ ind prolog-indent-width) ;More indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
159 (max tab-width ind))) ;Same indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
160 ((looking-at "-") tab-width) ;TAB
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
161 ((or less (looking-at "[^.]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
162 (max (- ind prolog-indent-width) 0)) ;Less indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
163 (t 0)) ;No indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
164 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
165 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
166
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
167 (defun end-of-prolog-clause ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
168 "Go to end of clause in this line."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
169 (beginning-of-line 1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
170 (let* ((eolpos (save-excursion (end-of-line) (point))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
171 (if (re-search-forward comment-start-skip eolpos 'move)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
172 (goto-char (match-beginning 0)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
173 (skip-chars-backward " \t")))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
174
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
175 (defun prolog-comment-indent ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
176 "Compute prolog comment indentation."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
177 (cond ((looking-at "%%%") 0)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
178 ((looking-at "%%") (prolog-indent-level))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
179 (t
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
180 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
181 (skip-chars-backward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
182 ;; Insert one space at least, except at left margin.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
183 (max (+ (current-column) (if (bolp) 0 1))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
184 comment-column)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
185 ))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
186
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
187
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
188 ;;;
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
189 ;;; Inferior prolog mode
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
190 ;;;
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
191 (defvar inferior-prolog-mode-map nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
192
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
193 (defun inferior-prolog-mode ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
194 "Major mode for interacting with an inferior Prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
195
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
196 The following commands are available:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
197 \\{inferior-prolog-mode-map}
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
198
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
199 Entry to this mode calls the value of prolog-mode-hook with no arguments,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
200 if that value is non-nil. Likewise with the value of comint-mode-hook.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
201 prolog-mode-hook is called after comint-mode-hook.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
202
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
203 You can send text to the inferior Prolog from other buffers
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
204 using the commands send-region, send-string and \\[prolog-consult-region].
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
205
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
206 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
207 Tab indents for Prolog; with argument, shifts rest
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
208 of expression rigidly with the current line.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
209 Paragraphs are separated only by blank lines and '%%'. '%'s start comments.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
210
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
211 Return at end of buffer sends line as input.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
212 Return not at end copies rest of line to end and sends it.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
213 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
214 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
215 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
216 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
217 (require 'comint)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
218 (comint-mode)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
219 (setq major-mode 'inferior-prolog-mode
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
220 mode-name "Inferior Prolog"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
221 comint-prompt-regexp "^| [ ?][- ] *")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
222 (prolog-mode-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
223 (if inferior-prolog-mode-map nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
224 (setq inferior-prolog-mode-map (copy-keymap comint-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
225 (prolog-mode-commands inferior-prolog-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
226 (use-local-map inferior-prolog-mode-map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
227 (run-hooks 'prolog-mode-hook))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
228
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
229 (defun run-prolog ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
230 "Run an inferior Prolog process, input and output via buffer *prolog*."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
231 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
232 (require 'comint)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
233 (switch-to-buffer (make-comint "prolog" prolog-program-name))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
234 (inferior-prolog-mode))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
235
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
236 (defun prolog-consult-region (compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
237 "Send the region to the Prolog process made by M-x run-prolog.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
238 If COMPILE (prefix arg) is not nil,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
239 use compile mode rather than consult mode."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
240 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
241 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
242 (if compile
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
243 (send-string "prolog" prolog-compile-string)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
244 (send-string "prolog" prolog-consult-string))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
245 (send-region "prolog" beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
246 (send-string "prolog" "\n") ;May be unnecessary
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
247 (if prolog-eof-string
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
248 (send-string "prolog" prolog-eof-string)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
249 (process-send-eof "prolog")))) ;Send eof to prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
250
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
251 (defun prolog-consult-region-and-go (compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
252 "Send the region to the inferior Prolog, and switch to *prolog* buffer.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
253 If COMPILE (prefix arg) is not nil,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
254 use compile mode rather than consult mode."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
255 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
256 (prolog-consult-region compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
257 (switch-to-buffer "*prolog*"))