annotate lisp/progmodes/prolog.el @ 67201:ef8e06ff56b9

Throw error if facemenu is not loaded to prevent accidental change of loading order in loadup.el. (Suggested by RMS.)
author Luc Teirlinck <teirllm@auburn.edu>
date Tue, 29 Nov 2005 05:03:21 +0000
parents a11fdee52c05
children dc49655f57ae 7beb78bc1f8e
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
64699
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64085
diff changeset
3 ;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64085
diff changeset
4 ;; Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
5
17977
727cf56647a4 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17414
diff changeset
6 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
7 ;; Keywords: languages
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
8
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
10
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
12 ;; 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
13 ;; the Free Software Foundation; either version 2, or (at your option)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
14 ;; any later version.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
15
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
19 ;; GNU General Public License for more details.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
20
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
21 ;; 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
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 64072
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 64072
diff changeset
24 ;; Boston, MA 02110-1301, USA.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
25
2308
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
26 ;;; Commentary:
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
27
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
28 ;; 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
29 ;; about Prolog syntax and comments, and can send regions to an inferior
45608
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
30 ;; Prolog interpreter process. Font locking is tuned towards GNU Prolog.
2308
f287613dfc28 Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
31
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
32 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 659
diff changeset
33
65238
a372b82c546e (comint-prompt-regexp): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64699
diff changeset
34 (defvar comint-prompt-regexp)
a372b82c546e (comint-prompt-regexp): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64699
diff changeset
35
a372b82c546e (comint-prompt-regexp): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64699
diff changeset
36
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
37 (defgroup prolog nil
64048
6182d0adade2 (prolog): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 62461
diff changeset
38 "Major mode for editing and running Prolog under Emacs."
66963
a11fdee52c05 Add :link (custom-group-link font-lock-faces) to defgroup.
Juri Linkov <juri@jurta.org>
parents: 65238
diff changeset
39 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
40 :group 'languages)
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
41
45608
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
42
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
43 (defcustom prolog-program-name
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
44 (let ((names '("prolog" "gprolog")))
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
45 (while (and names
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
46 (not (executable-find (car names))))
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
47 (setq names (cdr names)))
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
48 (or (car names) "prolog"))
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
49 "*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
50 :type 'string
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
51 :group 'prolog)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
52
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
53 (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
54 "*(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
55 :type 'string
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
56 :group 'prolog)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
57
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
58 (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
59 "*Compile mode (for Quintus Prolog)."
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-eof-string "end_of_file.\n"
64072
db79be1bac82 (prolog-eof-string): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 64048
diff changeset
64 "*String that represents end of file for Prolog.
db79be1bac82 (prolog-eof-string): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 64048
diff changeset
65 When nil, send actual operating system end of file."
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
66 :type 'string
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
67 :group 'prolog)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
68
17414
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
69 (defcustom prolog-indent-width 4
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
70 "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
71 :type 'integer
f967f12c8ec8 Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
72 :group 'prolog)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
73
45608
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
74 (defvar prolog-font-lock-keywords
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
75 '(("\\(#[<=]=>\\|:-\\)\\|\\(#=\\)\\|\\(#[#<>\\/][=\\/]*\\|!\\)"
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
76 0 font-lock-keyword-face)
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
77 ("\\<\\(is\\|write\\|nl\\|read_\\sw+\\)\\>"
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
78 1 font-lock-keyword-face)
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
79 ("^\\(\\sw+\\)\\s-*\\((\\(.+\\))\\)*"
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
80 (1 font-lock-function-name-face)
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
81 (3 font-lock-variable-name-face)))
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
82 "Font-lock keywords for Prolog mode.")
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
83
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
84 (defvar prolog-mode-syntax-table
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
85 (let ((table (make-syntax-table)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
86 (modify-syntax-entry ?_ "w" table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
87 (modify-syntax-entry ?\\ "\\" table)
45608
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
88 (modify-syntax-entry ?/ ". 14" table)
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
89 (modify-syntax-entry ?* ". 23" table)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
90 (modify-syntax-entry ?+ "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
91 (modify-syntax-entry ?- "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
92 (modify-syntax-entry ?= "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
93 (modify-syntax-entry ?% "<" table)
8217
a09642334f69 (prolog-mode-syntax-table): Make newline end comments.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
94 (modify-syntax-entry ?\n ">" table)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
95 (modify-syntax-entry ?< "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
96 (modify-syntax-entry ?> "." table)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
97 (modify-syntax-entry ?\' "\"" table)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
98 table))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
99
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
100 (defvar prolog-mode-abbrev-table nil)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
101 (define-abbrev-table 'prolog-mode-abbrev-table ())
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
102
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
103 (defun prolog-mode-variables ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
104 (make-local-variable 'paragraph-separate)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
105 (setq paragraph-separate (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
106 (make-local-variable 'paragraph-ignore-fill-prefix)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
107 (setq paragraph-ignore-fill-prefix t)
20396
ba46225fd687 (prolog-mode-variables):
Karl Heuer <kwzh@gnu.org>
parents: 18383
diff changeset
108 (make-local-variable 'imenu-generic-expression)
58713
75d6f143fced (prolog-mode-variables): Fix imenu-generic-expression.
Juri Linkov <juri@jurta.org>
parents: 53891
diff changeset
109 (setq imenu-generic-expression '((nil "^\\sw+" 0)))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
110 (make-local-variable 'indent-line-function)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
111 (setq indent-line-function 'prolog-indent-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
112 (make-local-variable 'comment-start)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
113 (setq comment-start "%")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
114 (make-local-variable 'comment-start-skip)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
115 (setq comment-start-skip "\\(?:%+\\|/\\*+\\)[ \t]*")
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
116 (make-local-variable 'comment-end-skip)
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
117 (setq comment-end-skip "[ \t]*\\(\n\\|\\*+/\\)")
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
118 (make-local-variable 'comment-column)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
119 (setq comment-column 48))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
120
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
121 (defvar prolog-mode-map
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
122 (let ((map (make-sparse-keymap)))
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
123 (define-key map "\e\C-x" 'prolog-consult-region)
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
124 map))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
125
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 242
diff changeset
126 ;;;###autoload
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
127 (defun prolog-mode ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
128 "Major mode for editing Prolog code for Prologs.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
129 Blank lines and `%%...' separate paragraphs. `%'s start comments.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
130 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
131 \\{prolog-mode-map}
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
132 Entry to this mode calls the value of `prolog-mode-hook'
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
133 if that value is non-nil."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
134 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
135 (kill-all-local-variables)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
136 (use-local-map prolog-mode-map)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
137 (set-syntax-table prolog-mode-syntax-table)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
138 (setq major-mode 'prolog-mode)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
139 (setq mode-name "Prolog")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
140 (prolog-mode-variables)
45608
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
141 ;; font lock
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
142 (setq font-lock-defaults '(prolog-font-lock-keywords
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
143 nil nil nil
706ae7fb4033 (prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 20396
diff changeset
144 beginning-of-line))
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
145 (run-mode-hooks 'prolog-mode-hook))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
146
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
147 (defun prolog-indent-line (&optional whole-exp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
148 "Indent current line as Prolog code.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
149 With argument, indent any additional lines of the same clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
150 rigidly along with this one (not yet)."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
151 (interactive "p")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
152 (let ((indent (prolog-indent-level))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
153 (pos (- (point-max) (point))) beg)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
154 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
155 (setq beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
156 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
157 (if (zerop (- indent (current-column)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
158 nil
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
159 (delete-region beg (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
160 (indent-to indent))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
161 (if (> (- (point-max) pos) (point))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
162 (goto-char (- (point-max) pos)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
163 ))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
164
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
165 (defun prolog-indent-level ()
64072
db79be1bac82 (prolog-eof-string): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents: 64048
diff changeset
166 "Compute Prolog indentation level."
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
167 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
168 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
169 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
170 (cond
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
171 ((looking-at "%%%") 0) ;Large comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
172 ((looking-at "%[^%]") comment-column) ;Small comment starts
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
173 ((bobp) 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
174 (t
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
175 (let ((empty t) ind more less)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
176 (if (looking-at ")")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
177 (setq less t) ;Find close
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
178 (setq less nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
179 ;; See previous indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
180 (while empty
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
181 (forward-line -1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
182 (beginning-of-line)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
183 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
184 (setq empty nil)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
185 (skip-chars-forward " \t")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
186 (if (not (or (looking-at "%[^%]") (looking-at "\n")))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
187 (setq empty nil))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
188 (if (bobp)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
189 (setq ind 0) ;Beginning of buffer
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
190 (setq ind (current-column))) ;Beginning of clause
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
191 ;; See its beginning
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
192 (if (looking-at "%%[^%]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
193 ind
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
194 ;; Real prolog code
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
195 (if (looking-at "(")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
196 (setq more t) ;Find open
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
197 (setq more nil))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
198 ;; See its tail
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
199 (end-of-prolog-clause)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
200 (or (bobp) (forward-char -1))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
201 (cond ((looking-at "[,(;>]")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
202 (if (and more (looking-at "[^,]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
203 (+ ind prolog-indent-width) ;More indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
204 (max tab-width ind))) ;Same indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
205 ((looking-at "-") tab-width) ;TAB
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
206 ((or less (looking-at "[^.]"))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
207 (max (- ind prolog-indent-width) 0)) ;Less indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
208 (t 0)) ;No indentation
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
209 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
210 )))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
211
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
212 (defun end-of-prolog-clause ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
213 "Go to end of clause in this line."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
214 (beginning-of-line 1)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
215 (let* ((eolpos (save-excursion (end-of-line) (point))))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
216 (if (re-search-forward comment-start-skip eolpos 'move)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
217 (goto-char (match-beginning 0)))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
218 (skip-chars-backward " \t")))
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 ;;;
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
223 (defvar inferior-prolog-mode-map
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
224 (let ((map (make-sparse-keymap)))
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
225 ;; This map will inherit from `comint-mode-map' when entering
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
226 ;; inferior-prolog-mode.
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
227 map))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
228
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
229 (defvar inferior-prolog-mode-syntax-table prolog-mode-syntax-table)
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
230 (defvar inferior-prolog-mode-abbrev-table prolog-mode-abbrev-table)
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
231
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
232 (define-derived-mode inferior-prolog-mode comint-mode "Inferior Prolog"
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
233 "Major mode for interacting with an inferior Prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
234
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
235 The following commands are available:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
236 \\{inferior-prolog-mode-map}
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
237
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
238 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
239 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
240 `prolog-mode-hook' is called after `comint-mode-hook'.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
241
62461
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
242 You can send text to the inferior Prolog from other buffers using the commands
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
243 `process-send-region', `process-send-string' and \\[prolog-consult-region].
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
244
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
245 Commands:
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
246 Tab indents for Prolog; with argument, shifts rest
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
247 of expression rigidly with the current line.
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
248 Paragraphs are separated only by blank lines and '%%'.
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
249 '%'s start comments.
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
250
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
251 Return at end of buffer sends line as input.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
252 Return not at end copies rest of line to end and sends it.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
253 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
254 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
255 \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal."
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
256 (setq comint-prompt-regexp "^| [ ?][- ] *")
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
257 (prolog-mode-variables))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
258
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 242
diff changeset
259 ;;;###autoload
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
260 (defun run-prolog ()
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
261 "Run an inferior Prolog process, input and output via buffer *prolog*."
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
262 (interactive)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
263 (require 'comint)
53891
4b85b1e3d610 (prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
264 (pop-to-buffer (make-comint "prolog" prolog-program-name))
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
265 (inferior-prolog-mode))
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
266
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
267 (defun prolog-consult-region (compile beg end)
242
5647f2040009 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 41
diff changeset
268 "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
269 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
270 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
271 (save-excursion
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
272 (if compile
62461
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
273 (process-send-string "prolog" prolog-compile-string)
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
274 (process-send-string "prolog" prolog-consult-string))
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
275 (process-send-region "prolog" beg end)
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
276 (process-send-string "prolog" "\n") ;May be unnecessary
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
277 (if prolog-eof-string
62461
3321bf6b1f4d Replace `send-string' by `process-send-string'; replace `send-region' by `process-send-region'.
Juanma Barranquero <lekktu@gmail.com>
parents: 58713
diff changeset
278 (process-send-string "prolog" prolog-eof-string)
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
279 (process-send-eof "prolog")))) ;Send eof to prolog process.
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
280
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
281 (defun prolog-consult-region-and-go (compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
282 "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
283 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
41
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
284 (interactive "P\nr")
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
285 (prolog-consult-region compile beg end)
467ee6fe6503 Initial revision
root <root>
parents:
diff changeset
286 (switch-to-buffer "*prolog*"))
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
287
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17977
diff changeset
288 (provide 'prolog)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17977
diff changeset
289
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 45608
diff changeset
290 ;;; arch-tag: f3ec6748-1272-4ab6-8826-c50cb1607636
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
291 ;;; prolog.el ends here