annotate lisp/modes/prolog.el @ 48:56c54cf7c5b6 r19-16b90

Import from CVS: tag r19-16b90
author cvs
date Mon, 13 Aug 2007 08:56:04 +0200
parents 0293115a14e9
children 34a5b81f86ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; prolog.el --- major mode for editing and running Prolog under Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1986, 1987, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: Not synched with FSF, we appear to have a newer version
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This package provides a major mode for editing Prolog. It knows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; about Prolog syntax and comments, and can send regions to an inferior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Prolog interpreter process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar prolog-mode-syntax-table nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defvar prolog-mode-abbrev-table nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defvar prolog-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar prolog-program-name "prolog"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "*Program name for invoking an inferior Prolog with `run-prolog'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar prolog-consult-string "reconsult(user).\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 "*(Re)Consult mode (for C-Prolog and Quintus Prolog). ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar prolog-compile-string "compile(user).\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 "*Compile mode (for Quintus Prolog).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (defvar prolog-eof-string "end_of_file.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "*String that represents end of file for prolog.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 nil means send actual operating system end of file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defvar prolog-indent-width 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defconst prolog-font-lock-keywords (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (cons (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "[( \t]\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (mapconcat 'identity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 '("write" "writeq" "nl" "is" "call" "read" "get" "get0"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "tell" "told" "open" "close" "format" "put"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "assert" "asserta" "assertz"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "retract" "retractall" "clause"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "record" "recorda" "abolish"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "setof" "bagof" "findall" "sort" "compare"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "var" "nonvar" "integer" "float" "number" "ground"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "atom" "atomic" "simple" "callable" "compound"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "functor" "arg" "copy_term" "numbervars"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "atom_chars" "number_chars" "atom_to_chars"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "length" "unix" "halt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "op" "dynamic" "meta_predicate" "raise_exception"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "module" "ensure_loaded" "use_module"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "fail" "true"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "module_interface" "begin_module" "define_struct"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "import" "export" "global" "tool" "external"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "define_macro" "local" "library" "from"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "\\)[ .,\t\n()]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 '("^[a-z][a-zA-Z0-9_]+" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ; '("[@!$#]" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 '("!" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 '("@" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 '("<=>" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 '("==>" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 '(";" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 '(":-" 0 font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 '("\\[" 0 font-lock-keyword-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 '("\\]" 0 font-lock-keyword-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 '("|" 0 font-lock-keyword-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Additional expressions to highlight in Prolog mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (if prolog-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (let ((table (make-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (modify-syntax-entry ?/ ". 14" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (modify-syntax-entry ?* ". 23" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (modify-syntax-entry ?% "< b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (modify-syntax-entry ?\n "> b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (modify-syntax-entry ?_ "w" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (modify-syntax-entry ?\\ "\\" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (modify-syntax-entry ?\' "\"" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (modify-syntax-entry ?+ "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (modify-syntax-entry ?- "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (modify-syntax-entry ?= "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (modify-syntax-entry ?< "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (modify-syntax-entry ?> "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq prolog-mode-syntax-table table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (define-abbrev-table 'prolog-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun prolog-mode-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (set-syntax-table prolog-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq local-abbrev-table prolog-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (setq paragraph-start (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq paragraph-separate paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (make-local-variable 'paragraph-ignore-fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq paragraph-ignore-fill-prefix t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq indent-line-function 'prolog-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq comment-start "%")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq comment-start-skip "%+ *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (setq comment-column 48)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (make-local-variable 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq comment-indent-function 'prolog-comment-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun prolog-mode-commands (map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (define-key map "\t" 'prolog-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (define-key map "\e\C-x" 'prolog-consult-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (if prolog-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq prolog-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (prolog-mode-commands prolog-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defun prolog-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "Major mode for editing Prolog code for Prologs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Blank lines and `%%...' separate paragraphs. `%'s start comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 \\{prolog-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Entry to this mode calls the value of `prolog-mode-hook'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (use-local-map prolog-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq major-mode 'prolog-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setq mode-name "Prolog")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (prolog-mode-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (run-hooks 'prolog-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defun prolog-indent-line (&optional whole-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "Indent current line as Prolog code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 With argument, indent any additional lines of the same clause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 rigidly along with this one (not yet)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (let ((indent (prolog-indent-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (pos (- (point-max) (point))) beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (if (zerop (- indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (indent-to indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defun prolog-indent-level ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Compute prolog indentation level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ((looking-at "%%%") 0) ;Large comment starts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ((looking-at "%[^%]") comment-column) ;Small comment starts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ((bobp) 0) ;Beginning of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (let ((empty t) ind more less)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (looking-at ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (setq less t) ;Find close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (setq less nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; See previous indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (while empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq empty nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (not (or (looking-at "%[^%]") (looking-at "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (setq empty nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setq ind 0) ;Beginning of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq ind (current-column))) ;Beginning of clause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; See its beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (looking-at "%%[^%]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Real prolog code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (if (looking-at "(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq more t) ;Find open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq more nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;; See its tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (end-of-prolog-clause)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (or (bobp) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (cond ((looking-at "[,(;>]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (if (and more (looking-at "[^,]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (+ ind prolog-indent-width) ;More indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (max tab-width ind))) ;Same indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ((looking-at "-") tab-width) ;TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ((or less (looking-at "[^.]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (max (- ind prolog-indent-width) 0)) ;Less indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (t 0)) ;No indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun end-of-prolog-clause ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Go to end of clause in this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let* ((eolpos (save-excursion (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if (re-search-forward comment-start-skip eolpos 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (goto-char (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (skip-chars-backward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun prolog-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "Compute prolog comment indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (cond ((looking-at "%%%") 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ((looking-at "%%") (prolog-indent-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; Insert one space at least, except at left margin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (max (+ (current-column) (if (bolp) 0 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 comment-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;;; Inferior prolog mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defvar inferior-prolog-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defun inferior-prolog-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 "Major mode for interacting with an inferior Prolog process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 The following commands are available:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 \\{inferior-prolog-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Entry to this mode calls the value of `prolog-mode-hook' with no arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 if that value is non-nil. Likewise with the value of `comint-mode-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 `prolog-mode-hook' is called after `comint-mode-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 You can send text to the inferior Prolog from other buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 using the commands `send-region', `send-string' and \\[prolog-consult-region].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 Tab indents for Prolog; with argument, shifts rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 of expression rigidly with the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Paragraphs are separated only by blank lines and '%%'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 '%'s start comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Return at end of buffer sends line as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 Return not at end copies rest of line to end and sends it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (setq major-mode 'inferior-prolog-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 mode-name "Inferior Prolog"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 comint-prompt-regexp "^| [ ?][- ] *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (prolog-mode-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if inferior-prolog-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq inferior-prolog-mode-map (copy-keymap comint-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (prolog-mode-commands inferior-prolog-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (use-local-map inferior-prolog-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (run-hooks 'prolog-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defun run-prolog ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Run an inferior Prolog process, input and output via buffer *prolog*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (switch-to-buffer (make-comint "prolog" prolog-program-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (inferior-prolog-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (defun prolog-consult-region (compile beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 "Send the region to the Prolog process made by \"M-x run-prolog\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (interactive "P\nr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (send-string "prolog" prolog-compile-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (send-string "prolog" prolog-consult-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (send-region "prolog" beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (send-string "prolog" "\n") ;May be unnecessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if prolog-eof-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (send-string "prolog" prolog-eof-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (process-send-eof "prolog")))) ;Send eof to prolog process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defun prolog-consult-region-and-go (compile beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 "Send the region to the inferior Prolog, and switch to *prolog* buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (interactive "P\nr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (prolog-consult-region compile beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (switch-to-buffer "*prolog*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;;; prolog.el ends here