Mercurial > emacs
annotate lisp/progmodes/prolog.el @ 89363:66640ed1aeae
(x_new_fontset): Fix previous change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 11 Jan 2003 01:50:19 +0000 |
parents | ba46225fd687 |
children | 706ae7fb4033 |
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) | |
20396 | 96 (make-local-variable 'imenu-generic-expression) |
97 (setq imenu-generic-expression "^[a-z][a-zA-Z0-9_]+") | |
41 | 98 (make-local-variable 'indent-line-function) |
99 (setq indent-line-function 'prolog-indent-line) | |
100 (make-local-variable 'comment-start) | |
101 (setq comment-start "%") | |
102 (make-local-variable 'comment-start-skip) | |
103 (setq comment-start-skip "%+ *") | |
104 (make-local-variable 'comment-column) | |
105 (setq comment-column 48) | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
106 (make-local-variable 'comment-indent-function) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
107 (setq comment-indent-function 'prolog-comment-indent)) |
41 | 108 |
109 (defun prolog-mode-commands (map) | |
110 (define-key map "\t" 'prolog-indent-line) | |
111 (define-key map "\e\C-x" 'prolog-consult-region)) | |
112 | |
113 (if prolog-mode-map | |
114 nil | |
115 (setq prolog-mode-map (make-sparse-keymap)) | |
116 (prolog-mode-commands prolog-mode-map)) | |
117 | |
258 | 118 ;;;###autoload |
41 | 119 (defun prolog-mode () |
120 "Major mode for editing Prolog code for Prologs. | |
121 Blank lines and `%%...' separate paragraphs. `%'s start comments. | |
122 Commands: | |
123 \\{prolog-mode-map} | |
242 | 124 Entry to this mode calls the value of `prolog-mode-hook' |
41 | 125 if that value is non-nil." |
126 (interactive) | |
127 (kill-all-local-variables) | |
128 (use-local-map prolog-mode-map) | |
129 (setq major-mode 'prolog-mode) | |
130 (setq mode-name "Prolog") | |
131 (prolog-mode-variables) | |
132 (run-hooks 'prolog-mode-hook)) | |
133 | |
134 (defun prolog-indent-line (&optional whole-exp) | |
135 "Indent current line as Prolog code. | |
136 With argument, indent any additional lines of the same clause | |
137 rigidly along with this one (not yet)." | |
138 (interactive "p") | |
139 (let ((indent (prolog-indent-level)) | |
140 (pos (- (point-max) (point))) beg) | |
141 (beginning-of-line) | |
142 (setq beg (point)) | |
143 (skip-chars-forward " \t") | |
144 (if (zerop (- indent (current-column))) | |
145 nil | |
146 (delete-region beg (point)) | |
147 (indent-to indent)) | |
148 (if (> (- (point-max) pos) (point)) | |
149 (goto-char (- (point-max) pos))) | |
150 )) | |
151 | |
152 (defun prolog-indent-level () | |
153 "Compute prolog indentation level." | |
154 (save-excursion | |
155 (beginning-of-line) | |
156 (skip-chars-forward " \t") | |
157 (cond | |
158 ((looking-at "%%%") 0) ;Large comment starts | |
159 ((looking-at "%[^%]") comment-column) ;Small comment starts | |
160 ((bobp) 0) ;Beginning of buffer | |
161 (t | |
162 (let ((empty t) ind more less) | |
163 (if (looking-at ")") | |
164 (setq less t) ;Find close | |
165 (setq less nil)) | |
166 ;; See previous indentation | |
167 (while empty | |
168 (forward-line -1) | |
169 (beginning-of-line) | |
170 (if (bobp) | |
171 (setq empty nil) | |
172 (skip-chars-forward " \t") | |
173 (if (not (or (looking-at "%[^%]") (looking-at "\n"))) | |
174 (setq empty nil)))) | |
175 (if (bobp) | |
176 (setq ind 0) ;Beginning of buffer | |
177 (setq ind (current-column))) ;Beginning of clause | |
178 ;; See its beginning | |
179 (if (looking-at "%%[^%]") | |
180 ind | |
181 ;; Real prolog code | |
182 (if (looking-at "(") | |
183 (setq more t) ;Find open | |
184 (setq more nil)) | |
185 ;; See its tail | |
186 (end-of-prolog-clause) | |
187 (or (bobp) (forward-char -1)) | |
188 (cond ((looking-at "[,(;>]") | |
189 (if (and more (looking-at "[^,]")) | |
190 (+ ind prolog-indent-width) ;More indentation | |
191 (max tab-width ind))) ;Same indentation | |
192 ((looking-at "-") tab-width) ;TAB | |
193 ((or less (looking-at "[^.]")) | |
194 (max (- ind prolog-indent-width) 0)) ;Less indentation | |
195 (t 0)) ;No indentation | |
196 ))) | |
197 ))) | |
198 | |
199 (defun end-of-prolog-clause () | |
200 "Go to end of clause in this line." | |
201 (beginning-of-line 1) | |
202 (let* ((eolpos (save-excursion (end-of-line) (point)))) | |
203 (if (re-search-forward comment-start-skip eolpos 'move) | |
204 (goto-char (match-beginning 0))) | |
205 (skip-chars-backward " \t"))) | |
206 | |
207 (defun prolog-comment-indent () | |
208 "Compute prolog comment indentation." | |
209 (cond ((looking-at "%%%") 0) | |
210 ((looking-at "%%") (prolog-indent-level)) | |
211 (t | |
212 (save-excursion | |
213 (skip-chars-backward " \t") | |
214 ;; Insert one space at least, except at left margin. | |
215 (max (+ (current-column) (if (bolp) 0 1)) | |
216 comment-column))) | |
217 )) | |
218 | |
219 | |
220 ;;; | |
221 ;;; Inferior prolog mode | |
222 ;;; | |
223 (defvar inferior-prolog-mode-map nil) | |
224 | |
225 (defun inferior-prolog-mode () | |
226 "Major mode for interacting with an inferior Prolog process. | |
227 | |
228 The following commands are available: | |
229 \\{inferior-prolog-mode-map} | |
230 | |
242 | 231 Entry to this mode calls the value of `prolog-mode-hook' with no arguments, |
232 if that value is non-nil. Likewise with the value of `comint-mode-hook'. | |
233 `prolog-mode-hook' is called after `comint-mode-hook'. | |
41 | 234 |
235 You can send text to the inferior Prolog from other buffers | |
242 | 236 using the commands `send-region', `send-string' and \\[prolog-consult-region]. |
41 | 237 |
238 Commands: | |
239 Tab indents for Prolog; with argument, shifts rest | |
240 of expression rigidly with the current line. | |
242 | 241 Paragraphs are separated only by blank lines and '%%'. |
242 '%'s start comments. | |
41 | 243 |
244 Return at end of buffer sends line as input. | |
245 Return not at end copies rest of line to end and sends it. | |
246 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing. | |
247 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any. | |
248 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal." | |
249 (interactive) | |
250 (require 'comint) | |
251 (comint-mode) | |
252 (setq major-mode 'inferior-prolog-mode | |
253 mode-name "Inferior Prolog" | |
254 comint-prompt-regexp "^| [ ?][- ] *") | |
255 (prolog-mode-variables) | |
256 (if inferior-prolog-mode-map nil | |
257 (setq inferior-prolog-mode-map (copy-keymap comint-mode-map)) | |
258 (prolog-mode-commands inferior-prolog-mode-map)) | |
259 (use-local-map inferior-prolog-mode-map) | |
260 (run-hooks 'prolog-mode-hook)) | |
261 | |
258 | 262 ;;;###autoload |
41 | 263 (defun run-prolog () |
264 "Run an inferior Prolog process, input and output via buffer *prolog*." | |
265 (interactive) | |
266 (require 'comint) | |
267 (switch-to-buffer (make-comint "prolog" prolog-program-name)) | |
268 (inferior-prolog-mode)) | |
269 | |
270 (defun prolog-consult-region (compile beg end) | |
242 | 271 "Send the region to the Prolog process made by \"M-x run-prolog\". |
272 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." | |
41 | 273 (interactive "P\nr") |
274 (save-excursion | |
275 (if compile | |
276 (send-string "prolog" prolog-compile-string) | |
277 (send-string "prolog" prolog-consult-string)) | |
278 (send-region "prolog" beg end) | |
279 (send-string "prolog" "\n") ;May be unnecessary | |
280 (if prolog-eof-string | |
281 (send-string "prolog" prolog-eof-string) | |
282 (process-send-eof "prolog")))) ;Send eof to prolog process. | |
283 | |
284 (defun prolog-consult-region-and-go (compile beg end) | |
285 "Send the region to the inferior Prolog, and switch to *prolog* buffer. | |
242 | 286 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." |
41 | 287 (interactive "P\nr") |
288 (prolog-consult-region compile beg end) | |
289 (switch-to-buffer "*prolog*")) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
290 |
18383 | 291 (provide 'prolog) |
292 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
293 ;;; prolog.el ends here |