annotate lisp/progmodes/prolog.el @ 33030:867e27924dcd

Some markup fixes. Don't call Windows a ``win''.
author Eli Zaretskii <eliz@gnu.org>
date Sun, 29 Oct 2000 16:52:33 +0000
parents ba46225fd687
children 706ae7fb4033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
3 ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
4
17977
727cf56647a4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17414
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
9
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
13 ;; any later version.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
14
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
18 ;; GNU General Public License for more details.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
19
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10890
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10890
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10890
diff changeset
23 ;; Boston, MA 02111-1307, USA.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
33 (defvar prolog-mode-syntax-table nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
34 (defvar prolog-mode-abbrev-table nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
67
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
68 (if prolog-mode-syntax-table
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
69 ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
70 (let ((table (make-syntax-table)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
71 (modify-syntax-entry ?_ "w" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
72 (modify-syntax-entry ?\\ "\\" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
73 (modify-syntax-entry ?/ "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
74 (modify-syntax-entry ?* "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
75 (modify-syntax-entry ?+ "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
76 (modify-syntax-entry ?- "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
77 (modify-syntax-entry ?= "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
80 (modify-syntax-entry ?< "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
81 (modify-syntax-entry ?> "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
82 (modify-syntax-entry ?\' "\"" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
83 (setq prolog-mode-syntax-table table)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
84
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
85 (define-abbrev-table 'prolog-mode-abbrev-table ())
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
86
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
87 (defun prolog-mode-variables ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
88 (set-syntax-table prolog-mode-syntax-table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
89 (setq local-abbrev-table prolog-mode-abbrev-table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
92 (make-local-variable 'paragraph-separate)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
93 (setq paragraph-separate paragraph-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
94 (make-local-variable 'paragraph-ignore-fill-prefix)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
95 (setq paragraph-ignore-fill-prefix t)
20396
ba46225fd687 (prolog-mode-variables):
Karl Heuer <kwzh@gnu.org>
parents: 18383
diff changeset
96 (make-local-variable 'imenu-generic-expression)
ba46225fd687 (prolog-mode-variables):
Karl Heuer <kwzh@gnu.org>
parents: 18383
diff changeset
97 (setq imenu-generic-expression "^[a-z][a-zA-Z0-9_]+")
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
98 (make-local-variable 'indent-line-function)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
99 (setq indent-line-function 'prolog-indent-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
100 (make-local-variable 'comment-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
101 (setq comment-start "%")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
102 (make-local-variable 'comment-start-skip)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
103 (setq comment-start-skip "%+ *")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
104 (make-local-variable 'comment-column)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
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
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
108
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
109 (defun prolog-mode-commands (map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
110 (define-key map "\t" 'prolog-indent-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
111 (define-key map "\e\C-x" 'prolog-consult-region))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
112
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
113 (if prolog-mode-map
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
114 nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
115 (setq prolog-mode-map (make-sparse-keymap))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
116 (prolog-mode-commands prolog-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
117
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 242
diff changeset
118 ;;;###autoload
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
119 (defun prolog-mode ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
120 "Major mode for editing Prolog code for Prologs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
121 Blank lines and `%%...' separate paragraphs. `%'s start comments.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
122 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
123 \\{prolog-mode-map}
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
124 Entry to this mode calls the value of `prolog-mode-hook'
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
125 if that value is non-nil."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
126 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
127 (kill-all-local-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
128 (use-local-map prolog-mode-map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
129 (setq major-mode 'prolog-mode)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
130 (setq mode-name "Prolog")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
131 (prolog-mode-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
132 (run-hooks 'prolog-mode-hook))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
133
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
134 (defun prolog-indent-line (&optional whole-exp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
135 "Indent current line as Prolog code.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
136 With argument, indent any additional lines of the same clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
137 rigidly along with this one (not yet)."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
138 (interactive "p")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
139 (let ((indent (prolog-indent-level))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
140 (pos (- (point-max) (point))) beg)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
141 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
142 (setq beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
143 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
144 (if (zerop (- indent (current-column)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
145 nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
146 (delete-region beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
147 (indent-to indent))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
148 (if (> (- (point-max) pos) (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
149 (goto-char (- (point-max) pos)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
150 ))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
151
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
152 (defun prolog-indent-level ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
153 "Compute prolog indentation level."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
154 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
155 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
156 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
157 (cond
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
158 ((looking-at "%%%") 0) ;Large comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
159 ((looking-at "%[^%]") comment-column) ;Small comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
160 ((bobp) 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
161 (t
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
162 (let ((empty t) ind more less)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
163 (if (looking-at ")")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
164 (setq less t) ;Find close
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
165 (setq less nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
166 ;; See previous indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
167 (while empty
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
168 (forward-line -1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
169 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
170 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
171 (setq empty nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
172 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
173 (if (not (or (looking-at "%[^%]") (looking-at "\n")))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
174 (setq empty nil))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
175 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
176 (setq ind 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
177 (setq ind (current-column))) ;Beginning of clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
178 ;; See its beginning
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
179 (if (looking-at "%%[^%]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
180 ind
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
181 ;; Real prolog code
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
182 (if (looking-at "(")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
183 (setq more t) ;Find open
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
184 (setq more nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
185 ;; See its tail
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
186 (end-of-prolog-clause)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
187 (or (bobp) (forward-char -1))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
188 (cond ((looking-at "[,(;>]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
189 (if (and more (looking-at "[^,]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
190 (+ ind prolog-indent-width) ;More indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
191 (max tab-width ind))) ;Same indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
192 ((looking-at "-") tab-width) ;TAB
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
193 ((or less (looking-at "[^.]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
194 (max (- ind prolog-indent-width) 0)) ;Less indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
195 (t 0)) ;No indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
196 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
197 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
198
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
199 (defun end-of-prolog-clause ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
200 "Go to end of clause in this line."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
201 (beginning-of-line 1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
202 (let* ((eolpos (save-excursion (end-of-line) (point))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
203 (if (re-search-forward comment-start-skip eolpos 'move)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
204 (goto-char (match-beginning 0)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
205 (skip-chars-backward " \t")))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
206
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
207 (defun prolog-comment-indent ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
208 "Compute prolog comment indentation."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
209 (cond ((looking-at "%%%") 0)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
210 ((looking-at "%%") (prolog-indent-level))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
211 (t
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
212 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
213 (skip-chars-backward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
214 ;; Insert one space at least, except at left margin.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
215 (max (+ (current-column) (if (bolp) 0 1))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
216 comment-column)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
217 ))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
218
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
219
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
220 ;;;
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
221 ;;; Inferior prolog mode
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
222 ;;;
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
223 (defvar inferior-prolog-mode-map nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
224
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
225 (defun inferior-prolog-mode ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
226 "Major mode for interacting with an inferior Prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
227
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
228 The following commands are available:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
229 \\{inferior-prolog-mode-map}
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
230
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
231 Entry to this mode calls the value of `prolog-mode-hook' with no arguments,
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
232 if that value is non-nil. Likewise with the value of `comint-mode-hook'.
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
233 `prolog-mode-hook' is called after `comint-mode-hook'.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
234
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
235 You can send text to the inferior Prolog from other buffers
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
236 using the commands `send-region', `send-string' and \\[prolog-consult-region].
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
237
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
238 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
239 Tab indents for Prolog; with argument, shifts rest
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
240 of expression rigidly with the current line.
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
241 Paragraphs are separated only by blank lines and '%%'.
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
242 '%'s start comments.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
243
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
244 Return at end of buffer sends line as input.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
245 Return not at end copies rest of line to end and sends it.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
246 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
247 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
248 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
249 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
250 (require 'comint)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
251 (comint-mode)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
252 (setq major-mode 'inferior-prolog-mode
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
253 mode-name "Inferior Prolog"
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
254 comint-prompt-regexp "^| [ ?][- ] *")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
255 (prolog-mode-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
256 (if inferior-prolog-mode-map nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
257 (setq inferior-prolog-mode-map (copy-keymap comint-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
258 (prolog-mode-commands inferior-prolog-mode-map))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
259 (use-local-map inferior-prolog-mode-map)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
260 (run-hooks 'prolog-mode-hook))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
261
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 242
diff changeset
262 ;;;###autoload
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
263 (defun run-prolog ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
264 "Run an inferior Prolog process, input and output via buffer *prolog*."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
265 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
266 (require 'comint)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
267 (switch-to-buffer (make-comint "prolog" prolog-program-name))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
268 (inferior-prolog-mode))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
269
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
270 (defun prolog-consult-region (compile beg end)
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
271 "Send the region to the Prolog process made by \"M-x run-prolog\".
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
272 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
273 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
274 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
275 (if compile
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
276 (send-string "prolog" prolog-compile-string)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
277 (send-string "prolog" prolog-consult-string))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
278 (send-region "prolog" beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
279 (send-string "prolog" "\n") ;May be unnecessary
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
280 (if prolog-eof-string
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
281 (send-string "prolog" prolog-eof-string)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
282 (process-send-eof "prolog")))) ;Send eof to prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
283
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
284 (defun prolog-consult-region-and-go (compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
285 "Send the region to the inferior Prolog, and switch to *prolog* buffer.
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
286 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
287 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
288 (prolog-consult-region compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
289 (switch-to-buffer "*prolog*"))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
290
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17977
diff changeset
291 (provide 'prolog)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17977
diff changeset
292
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
293 ;;; prolog.el ends here