Mercurial > emacs
annotate lisp/progmodes/prolog.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128
typos.
author | Jeff Law <law@redhat.com> |
---|---|
date | Wed, 10 Sep 1997 21:16:20 +0000 |
parents | 11218164bc54 |
children | ba46225fd687 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; prolog.el --- major mode for editing and running Prolog under Emacs |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc. |
4 | |
17977 | 5 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp> |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: languages |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
41 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
41 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
41 | 24 |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
25 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
26 |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
27 ;; This package provides a major mode for editing Prolog. It knows |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
28 ;; about Prolog syntax and comments, and can send regions to an inferior |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
29 ;; Prolog interpreter process. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
30 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
31 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
32 |
41 | 33 (defvar prolog-mode-syntax-table nil) |
34 (defvar prolog-mode-abbrev-table nil) | |
35 (defvar prolog-mode-map nil) | |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
36 |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
37 (defgroup prolog nil |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
38 "Major mode for editing and running Prolog under Emacs" |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
39 :group 'languages) |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
40 |
41 | 41 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
42 (defcustom prolog-program-name "prolog" |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
43 "*Program name for invoking an inferior Prolog with `run-prolog'." |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
44 :type 'string |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
45 :group 'prolog) |
41 | 46 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
47 (defcustom prolog-consult-string "reconsult(user).\n" |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
48 "*(Re)Consult mode (for C-Prolog and Quintus Prolog). " |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
49 :type 'string |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
50 :group 'prolog) |
41 | 51 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
52 (defcustom prolog-compile-string "compile(user).\n" |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
53 "*Compile mode (for Quintus Prolog)." |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
54 :type 'string |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
55 :group 'prolog) |
41 | 56 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
57 (defcustom prolog-eof-string "end_of_file.\n" |
41 | 58 "*String that represents end of file for prolog. |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
59 nil means send actual operating system end of file." |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 :type 'string |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
61 :group 'prolog) |
41 | 62 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
63 (defcustom prolog-indent-width 4 |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
64 "Level of indentation in Prolog buffers." |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
65 :type 'integer |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
66 :group 'prolog) |
41 | 67 |
68 (if prolog-mode-syntax-table | |
69 () | |
70 (let ((table (make-syntax-table))) | |
71 (modify-syntax-entry ?_ "w" table) | |
72 (modify-syntax-entry ?\\ "\\" table) | |
73 (modify-syntax-entry ?/ "." table) | |
74 (modify-syntax-entry ?* "." table) | |
75 (modify-syntax-entry ?+ "." table) | |
76 (modify-syntax-entry ?- "." table) | |
77 (modify-syntax-entry ?= "." table) | |
78 (modify-syntax-entry ?% "<" table) | |
8217
a09642334f69
(prolog-mode-syntax-table): Make newline end comments.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
79 (modify-syntax-entry ?\n ">" table) |
41 | 80 (modify-syntax-entry ?< "." table) |
81 (modify-syntax-entry ?> "." table) | |
82 (modify-syntax-entry ?\' "\"" table) | |
83 (setq prolog-mode-syntax-table table))) | |
84 | |
85 (define-abbrev-table 'prolog-mode-abbrev-table ()) | |
86 | |
87 (defun prolog-mode-variables () | |
88 (set-syntax-table prolog-mode-syntax-table) | |
89 (setq local-abbrev-table prolog-mode-abbrev-table) | |
90 (make-local-variable 'paragraph-start) | |
10890
cf071af7db56
(prolog-mode-variables): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
8217
diff
changeset
|
91 (setq paragraph-start (concat "%%\\|$\\|" page-delimiter)) ;'%%..' |
41 | 92 (make-local-variable 'paragraph-separate) |
93 (setq paragraph-separate paragraph-start) | |
94 (make-local-variable 'paragraph-ignore-fill-prefix) | |
95 (setq paragraph-ignore-fill-prefix t) | |
96 (make-local-variable 'indent-line-function) | |
97 (setq indent-line-function 'prolog-indent-line) | |
98 (make-local-variable 'comment-start) | |
99 (setq comment-start "%") | |
100 (make-local-variable 'comment-start-skip) | |
101 (setq comment-start-skip "%+ *") | |
102 (make-local-variable 'comment-column) | |
103 (setq comment-column 48) | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
104 (make-local-variable 'comment-indent-function) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
105 (setq comment-indent-function 'prolog-comment-indent)) |
41 | 106 |
107 (defun prolog-mode-commands (map) | |
108 (define-key map "\t" 'prolog-indent-line) | |
109 (define-key map "\e\C-x" 'prolog-consult-region)) | |
110 | |
111 (if prolog-mode-map | |
112 nil | |
113 (setq prolog-mode-map (make-sparse-keymap)) | |
114 (prolog-mode-commands prolog-mode-map)) | |
115 | |
258 | 116 ;;;###autoload |
41 | 117 (defun prolog-mode () |
118 "Major mode for editing Prolog code for Prologs. | |
119 Blank lines and `%%...' separate paragraphs. `%'s start comments. | |
120 Commands: | |
121 \\{prolog-mode-map} | |
242 | 122 Entry to this mode calls the value of `prolog-mode-hook' |
41 | 123 if that value is non-nil." |
124 (interactive) | |
125 (kill-all-local-variables) | |
126 (use-local-map prolog-mode-map) | |
127 (setq major-mode 'prolog-mode) | |
128 (setq mode-name "Prolog") | |
129 (prolog-mode-variables) | |
130 (run-hooks 'prolog-mode-hook)) | |
131 | |
132 (defun prolog-indent-line (&optional whole-exp) | |
133 "Indent current line as Prolog code. | |
134 With argument, indent any additional lines of the same clause | |
135 rigidly along with this one (not yet)." | |
136 (interactive "p") | |
137 (let ((indent (prolog-indent-level)) | |
138 (pos (- (point-max) (point))) beg) | |
139 (beginning-of-line) | |
140 (setq beg (point)) | |
141 (skip-chars-forward " \t") | |
142 (if (zerop (- indent (current-column))) | |
143 nil | |
144 (delete-region beg (point)) | |
145 (indent-to indent)) | |
146 (if (> (- (point-max) pos) (point)) | |
147 (goto-char (- (point-max) pos))) | |
148 )) | |
149 | |
150 (defun prolog-indent-level () | |
151 "Compute prolog indentation level." | |
152 (save-excursion | |
153 (beginning-of-line) | |
154 (skip-chars-forward " \t") | |
155 (cond | |
156 ((looking-at "%%%") 0) ;Large comment starts | |
157 ((looking-at "%[^%]") comment-column) ;Small comment starts | |
158 ((bobp) 0) ;Beginning of buffer | |
159 (t | |
160 (let ((empty t) ind more less) | |
161 (if (looking-at ")") | |
162 (setq less t) ;Find close | |
163 (setq less nil)) | |
164 ;; See previous indentation | |
165 (while empty | |
166 (forward-line -1) | |
167 (beginning-of-line) | |
168 (if (bobp) | |
169 (setq empty nil) | |
170 (skip-chars-forward " \t") | |
171 (if (not (or (looking-at "%[^%]") (looking-at "\n"))) | |
172 (setq empty nil)))) | |
173 (if (bobp) | |
174 (setq ind 0) ;Beginning of buffer | |
175 (setq ind (current-column))) ;Beginning of clause | |
176 ;; See its beginning | |
177 (if (looking-at "%%[^%]") | |
178 ind | |
179 ;; Real prolog code | |
180 (if (looking-at "(") | |
181 (setq more t) ;Find open | |
182 (setq more nil)) | |
183 ;; See its tail | |
184 (end-of-prolog-clause) | |
185 (or (bobp) (forward-char -1)) | |
186 (cond ((looking-at "[,(;>]") | |
187 (if (and more (looking-at "[^,]")) | |
188 (+ ind prolog-indent-width) ;More indentation | |
189 (max tab-width ind))) ;Same indentation | |
190 ((looking-at "-") tab-width) ;TAB | |
191 ((or less (looking-at "[^.]")) | |
192 (max (- ind prolog-indent-width) 0)) ;Less indentation | |
193 (t 0)) ;No indentation | |
194 ))) | |
195 ))) | |
196 | |
197 (defun end-of-prolog-clause () | |
198 "Go to end of clause in this line." | |
199 (beginning-of-line 1) | |
200 (let* ((eolpos (save-excursion (end-of-line) (point)))) | |
201 (if (re-search-forward comment-start-skip eolpos 'move) | |
202 (goto-char (match-beginning 0))) | |
203 (skip-chars-backward " \t"))) | |
204 | |
205 (defun prolog-comment-indent () | |
206 "Compute prolog comment indentation." | |
207 (cond ((looking-at "%%%") 0) | |
208 ((looking-at "%%") (prolog-indent-level)) | |
209 (t | |
210 (save-excursion | |
211 (skip-chars-backward " \t") | |
212 ;; Insert one space at least, except at left margin. | |
213 (max (+ (current-column) (if (bolp) 0 1)) | |
214 comment-column))) | |
215 )) | |
216 | |
217 | |
218 ;;; | |
219 ;;; Inferior prolog mode | |
220 ;;; | |
221 (defvar inferior-prolog-mode-map nil) | |
222 | |
223 (defun inferior-prolog-mode () | |
224 "Major mode for interacting with an inferior Prolog process. | |
225 | |
226 The following commands are available: | |
227 \\{inferior-prolog-mode-map} | |
228 | |
242 | 229 Entry to this mode calls the value of `prolog-mode-hook' with no arguments, |
230 if that value is non-nil. Likewise with the value of `comint-mode-hook'. | |
231 `prolog-mode-hook' is called after `comint-mode-hook'. | |
41 | 232 |
233 You can send text to the inferior Prolog from other buffers | |
242 | 234 using the commands `send-region', `send-string' and \\[prolog-consult-region]. |
41 | 235 |
236 Commands: | |
237 Tab indents for Prolog; with argument, shifts rest | |
238 of expression rigidly with the current line. | |
242 | 239 Paragraphs are separated only by blank lines and '%%'. |
240 '%'s start comments. | |
41 | 241 |
242 Return at end of buffer sends line as input. | |
243 Return not at end copies rest of line to end and sends it. | |
244 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing. | |
245 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any. | |
246 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal." | |
247 (interactive) | |
248 (require 'comint) | |
249 (comint-mode) | |
250 (setq major-mode 'inferior-prolog-mode | |
251 mode-name "Inferior Prolog" | |
252 comint-prompt-regexp "^| [ ?][- ] *") | |
253 (prolog-mode-variables) | |
254 (if inferior-prolog-mode-map nil | |
255 (setq inferior-prolog-mode-map (copy-keymap comint-mode-map)) | |
256 (prolog-mode-commands inferior-prolog-mode-map)) | |
257 (use-local-map inferior-prolog-mode-map) | |
258 (run-hooks 'prolog-mode-hook)) | |
259 | |
258 | 260 ;;;###autoload |
41 | 261 (defun run-prolog () |
262 "Run an inferior Prolog process, input and output via buffer *prolog*." | |
263 (interactive) | |
264 (require 'comint) | |
265 (switch-to-buffer (make-comint "prolog" prolog-program-name)) | |
266 (inferior-prolog-mode)) | |
267 | |
268 (defun prolog-consult-region (compile beg end) | |
242 | 269 "Send the region to the Prolog process made by \"M-x run-prolog\". |
270 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." | |
41 | 271 (interactive "P\nr") |
272 (save-excursion | |
273 (if compile | |
274 (send-string "prolog" prolog-compile-string) | |
275 (send-string "prolog" prolog-consult-string)) | |
276 (send-region "prolog" beg end) | |
277 (send-string "prolog" "\n") ;May be unnecessary | |
278 (if prolog-eof-string | |
279 (send-string "prolog" prolog-eof-string) | |
280 (process-send-eof "prolog")))) ;Send eof to prolog process. | |
281 | |
282 (defun prolog-consult-region-and-go (compile beg end) | |
283 "Send the region to the inferior Prolog, and switch to *prolog* buffer. | |
242 | 284 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." |
41 | 285 (interactive "P\nr") |
286 (prolog-consult-region compile beg end) | |
287 (switch-to-buffer "*prolog*")) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
288 |
18383 | 289 (provide 'prolog) |
290 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
291 ;;; prolog.el ends here |