annotate lisp/modes/prolog.el @ 2:ac2d302a0011 r19-15b2

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