Mercurial > emacs
annotate lisp/progmodes/prolog.el @ 18527:bb491744ccd7
(desktop-clear): Don't kill buffers here.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 02 Jul 1997 03:37:27 +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 |