Mercurial > emacs
annotate lisp/progmodes/prolog.el @ 86338:cc3ad12e2f26
(set_internal): Set the value in the `cons-cell' (for
Buffer_Local_values) not only for frame-local variables.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 22 Nov 2007 19:48:57 +0000 |
parents | 4d615a83cee2 |
children | f6591f36eb87 |
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 |
75347 | 3 ;; Copyright (C) 1986, 1987, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
64699
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 | 5 |
17977 | 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 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
78234
c1ec1c8a8d2e
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
41 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
41 | 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 |
85510
e2eac01cf548
* progmodes/prolog.el: Undo previous change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85451
diff
changeset
|
34 (defvar comint-prompt-regexp) |
e2eac01cf548
* progmodes/prolog.el: Undo previous change.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85451
diff
changeset
|
35 (defvar comint-process-echoes) |
65238
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 |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
44 (let ((names '("prolog" "gprolog" "swipl"))) |
53891
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")) |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
49 "Program name for invoking an inferior Prolog with `run-prolog'." |
17414
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 | 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" |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
54 "(Re)Consult mode (for C-Prolog and Quintus Prolog). " |
17414
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 | 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" |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
59 "Compile mode (for Quintus Prolog)." |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 :type 'string |
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
61 :group 'prolog) |
41 | 62 |
17414
f967f12c8ec8
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
63 (defcustom prolog-eof-string "end_of_file.\n" |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
64 "String that represents end of file for Prolog. |
64072
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 | 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 | 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 | 85 (let ((table (make-syntax-table))) |
86 (modify-syntax-entry ?_ "w" table) | |
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 | 90 (modify-syntax-entry ?+ "." table) |
91 (modify-syntax-entry ?- "." table) | |
92 (modify-syntax-entry ?= "." table) | |
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 | 95 (modify-syntax-entry ?< "." table) |
96 (modify-syntax-entry ?> "." table) | |
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 | 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 | 101 (define-abbrev-table 'prolog-mode-abbrev-table ()) |
102 | |
103 (defun prolog-mode-variables () | |
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 | 106 (make-local-variable 'paragraph-ignore-fill-prefix) |
107 (setq paragraph-ignore-fill-prefix t) | |
20396 | 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 | 110 (make-local-variable 'indent-line-function) |
111 (setq indent-line-function 'prolog-indent-line) | |
112 (make-local-variable 'comment-start) | |
113 (setq comment-start "%") | |
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 | 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 | 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) |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
124 (define-key map "\C-c\C-l" 'inferior-prolog-load-file) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
125 (define-key map "\C-c\C-z" 'switch-to-prolog) |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
126 map)) |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
127 |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
128 (easy-menu-define prolog-mode-menu prolog-mode-map "Menu for Prolog mode." |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
129 ;; Mostly copied from scheme-mode's menu. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
130 ;; Not tremendously useful, but it's a start. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
131 '("Prolog" |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
132 ["Indent line" indent-according-to-mode t] |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
133 ["Indent region" indent-region t] |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
134 ["Comment region" comment-region t] |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
135 ["Uncomment region" uncomment-region t] |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
136 "--" |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
137 ["Run interactive Prolog session" run-prolog t] |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
138 )) |
41 | 139 |
258 | 140 ;;;###autoload |
41 | 141 (defun prolog-mode () |
142 "Major mode for editing Prolog code for Prologs. | |
143 Blank lines and `%%...' separate paragraphs. `%'s start comments. | |
144 Commands: | |
145 \\{prolog-mode-map} | |
242 | 146 Entry to this mode calls the value of `prolog-mode-hook' |
41 | 147 if that value is non-nil." |
148 (interactive) | |
149 (kill-all-local-variables) | |
150 (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
|
151 (set-syntax-table prolog-mode-syntax-table) |
41 | 152 (setq major-mode 'prolog-mode) |
153 (setq mode-name "Prolog") | |
154 (prolog-mode-variables) | |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
155 (set (make-local-variable 'comment-add) 1) |
45608
706ae7fb4033
(prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
20396
diff
changeset
|
156 ;; font lock |
706ae7fb4033
(prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
20396
diff
changeset
|
157 (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
|
158 nil nil nil |
706ae7fb4033
(prolog-mode-syntax-table): Add flags to ?/ and ?* entries
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
20396
diff
changeset
|
159 beginning-of-line)) |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
160 (run-mode-hooks 'prolog-mode-hook)) |
41 | 161 |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
162 (defun prolog-indent-line () |
41 | 163 "Indent current line as Prolog code. |
164 With argument, indent any additional lines of the same clause | |
165 rigidly along with this one (not yet)." | |
166 (interactive "p") | |
167 (let ((indent (prolog-indent-level)) | |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
168 (pos (- (point-max) (point)))) |
41 | 169 (beginning-of-line) |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
170 (indent-line-to indent) |
41 | 171 (if (> (- (point-max) pos) (point)) |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
172 (goto-char (- (point-max) pos))))) |
41 | 173 |
174 (defun prolog-indent-level () | |
64072
db79be1bac82
(prolog-eof-string): Doc fixes.
Juanma Barranquero <lekktu@gmail.com>
parents:
64048
diff
changeset
|
175 "Compute Prolog indentation level." |
41 | 176 (save-excursion |
177 (beginning-of-line) | |
178 (skip-chars-forward " \t") | |
179 (cond | |
180 ((looking-at "%%%") 0) ;Large comment starts | |
181 ((looking-at "%[^%]") comment-column) ;Small comment starts | |
182 ((bobp) 0) ;Beginning of buffer | |
183 (t | |
184 (let ((empty t) ind more less) | |
185 (if (looking-at ")") | |
186 (setq less t) ;Find close | |
187 (setq less nil)) | |
188 ;; See previous indentation | |
189 (while empty | |
190 (forward-line -1) | |
191 (beginning-of-line) | |
192 (if (bobp) | |
193 (setq empty nil) | |
194 (skip-chars-forward " \t") | |
195 (if (not (or (looking-at "%[^%]") (looking-at "\n"))) | |
196 (setq empty nil)))) | |
197 (if (bobp) | |
198 (setq ind 0) ;Beginning of buffer | |
199 (setq ind (current-column))) ;Beginning of clause | |
200 ;; See its beginning | |
201 (if (looking-at "%%[^%]") | |
202 ind | |
203 ;; Real prolog code | |
204 (if (looking-at "(") | |
205 (setq more t) ;Find open | |
206 (setq more nil)) | |
207 ;; See its tail | |
208 (end-of-prolog-clause) | |
209 (or (bobp) (forward-char -1)) | |
210 (cond ((looking-at "[,(;>]") | |
211 (if (and more (looking-at "[^,]")) | |
212 (+ ind prolog-indent-width) ;More indentation | |
213 (max tab-width ind))) ;Same indentation | |
214 ((looking-at "-") tab-width) ;TAB | |
215 ((or less (looking-at "[^.]")) | |
216 (max (- ind prolog-indent-width) 0)) ;Less indentation | |
217 (t 0)) ;No indentation | |
218 ))) | |
219 ))) | |
220 | |
221 (defun end-of-prolog-clause () | |
222 "Go to end of clause in this line." | |
223 (beginning-of-line 1) | |
224 (let* ((eolpos (save-excursion (end-of-line) (point)))) | |
225 (if (re-search-forward comment-start-skip eolpos 'move) | |
226 (goto-char (match-beginning 0))) | |
227 (skip-chars-backward " \t"))) | |
228 | |
229 ;;; | |
230 ;;; Inferior prolog mode | |
231 ;;; | |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
232 (defvar inferior-prolog-mode-map |
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
233 (let ((map (make-sparse-keymap))) |
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
234 ;; 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
|
235 ;; inferior-prolog-mode. |
72696
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
236 (define-key map [remap self-insert-command] |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
237 'inferior-prolog-self-insert-command) |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
238 map)) |
41 | 239 |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
240 (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
|
241 (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
|
242 |
86243
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85510
diff
changeset
|
243 (declare-function comint-mode "../comint") |
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85510
diff
changeset
|
244 (declare-function comint-send-string "../comint" (process string)) |
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85510
diff
changeset
|
245 (declare-function comint-send-region "../comint" (process start end)) |
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85510
diff
changeset
|
246 (declare-function comint-send-eof "../comint" ()) |
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85510
diff
changeset
|
247 |
53891
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
248 (define-derived-mode inferior-prolog-mode comint-mode "Inferior Prolog" |
41 | 249 "Major mode for interacting with an inferior Prolog process. |
250 | |
251 The following commands are available: | |
252 \\{inferior-prolog-mode-map} | |
253 | |
242 | 254 Entry to this mode calls the value of `prolog-mode-hook' with no arguments, |
255 if that value is non-nil. Likewise with the value of `comint-mode-hook'. | |
256 `prolog-mode-hook' is called after `comint-mode-hook'. | |
41 | 257 |
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
|
258 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
|
259 `process-send-region', `process-send-string' and \\[prolog-consult-region]. |
41 | 260 |
261 Commands: | |
262 Tab indents for Prolog; with argument, shifts rest | |
263 of expression rigidly with the current line. | |
242 | 264 Paragraphs are separated only by blank lines and '%%'. |
265 '%'s start comments. | |
41 | 266 |
267 Return at end of buffer sends line as input. | |
268 Return not at end copies rest of line to end and sends it. | |
269 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing. | |
270 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any. | |
271 \\[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
|
272 (setq comint-prompt-regexp "^| [ ?][- ] *") |
4b85b1e3d610
(prolog-program-name): Use gprolog if available.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
273 (prolog-mode-variables)) |
41 | 274 |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
275 (defvar inferior-prolog-buffer nil) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
276 |
85451
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
277 (defvar inferior-prolog-flavor 'unknown |
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
278 "Either a symbol or a buffer position offset by one. |
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
279 If a buffer position, the flavor has not been determined yet and |
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
280 it is expected that the process's output has been or will |
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
281 be inserted at that position plus one.") |
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78234
diff
changeset
|
282 |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
283 (defun inferior-prolog-run (&optional name) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
284 (with-current-buffer (make-comint "prolog" (or name prolog-program-name)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
285 (inferior-prolog-mode) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
286 (setq-default inferior-prolog-buffer (current-buffer)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
287 (make-local-variable 'inferior-prolog-buffer) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
288 (when (and name (not (equal name prolog-program-name))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
289 (set (make-local-variable 'prolog-program-name) name)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
290 (set (make-local-variable 'inferior-prolog-flavor) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
291 ;; Force re-detection. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
292 (let* ((proc (get-buffer-process (current-buffer))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
293 (pmark (and proc (marker-position (process-mark proc))))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
294 (cond |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
295 ((null pmark) (1- (point-min))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
296 ;; The use of insert-before-markers in comint.el together with |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
297 ;; the potential use of comint-truncate-buffer in the output |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
298 ;; filter, means that it's difficult to reliably keep track of |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
299 ;; the buffer position where the process's output started. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
300 ;; If possible we use a marker at "start - 1", so that |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
301 ;; insert-before-marker at `start' won't shift it. And if not, |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
302 ;; we fall back on using a plain integer. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
303 ((> pmark (point-min)) (copy-marker (1- pmark))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
304 (t (1- pmark))))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
305 (add-hook 'comint-output-filter-functions |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
306 'inferior-prolog-guess-flavor nil t))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
307 |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
308 (defun inferior-prolog-process (&optional dontstart) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
309 (or (and (buffer-live-p inferior-prolog-buffer) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
310 (get-buffer-process inferior-prolog-buffer)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
311 (unless dontstart |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
312 (inferior-prolog-run) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
313 ;; Try again. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
314 (inferior-prolog-process)))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
315 |
72696
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
316 (defun inferior-prolog-guess-flavor (&optional ignored) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
317 (save-excursion |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
318 (goto-char (1+ inferior-prolog-flavor)) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
319 (setq inferior-prolog-flavor |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
320 (cond |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
321 ((looking-at "GNU Prolog") 'gnu) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
322 ((looking-at "Welcome to SWI-Prolog") 'swi) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
323 ((looking-at ".*\n") 'unknown) ;There's at least one line. |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
324 (t inferior-prolog-flavor)))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
325 (when (symbolp inferior-prolog-flavor) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
326 (remove-hook 'comint-output-filter-functions |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
327 'inferior-prolog-guess-flavor t) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
328 (if (eq inferior-prolog-flavor 'gnu) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
329 (set (make-local-variable 'comint-process-echoes) t)))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
330 |
258 | 331 ;;;###autoload |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
332 (defalias 'run-prolog 'switch-to-prolog) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
333 ;;;###autoload |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
334 (defun switch-to-prolog (&optional name) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
335 "Run an inferior Prolog process, input and output via buffer *prolog*. |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
336 With prefix argument \\[universal-prefix], prompt for the program to use." |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
337 (interactive |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
338 (list (when current-prefix-arg |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
339 (let ((proc (inferior-prolog-process 'dontstart))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
340 (if proc |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
341 (if (yes-or-no-p "Kill current process before starting new one? ") |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
342 (kill-process proc) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
343 (error "Abort"))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
344 (read-string "Run Prolog: " prolog-program-name))))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
345 (unless (inferior-prolog-process 'dontstart) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
346 (inferior-prolog-run name)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
347 (pop-to-buffer inferior-prolog-buffer)) |
41 | 348 |
72696
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
349 (defun inferior-prolog-self-insert-command () |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
350 "Insert the char in the buffer or pass it directly to the process." |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
351 (interactive) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
352 (let* ((proc (get-buffer-process (current-buffer))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
353 (pmark (and proc (marker-position (process-mark proc))))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
354 (if (and (eq inferior-prolog-flavor 'gnu) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
355 pmark |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
356 (null current-prefix-arg) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
357 (eobp) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
358 (eq (point) pmark) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
359 (save-excursion |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
360 (goto-char (- pmark 3)) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
361 (looking-at " \\? "))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
362 (comint-send-string proc (string last-command-char)) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
363 (call-interactively 'self-insert-command)))) |
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
364 |
41 | 365 (defun prolog-consult-region (compile beg end) |
242 | 366 "Send the region to the Prolog process made by \"M-x run-prolog\". |
367 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." | |
41 | 368 (interactive "P\nr") |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
369 (let ((proc (inferior-prolog-process))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
370 (comint-send-string proc |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
371 (if compile prolog-compile-string |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
372 prolog-consult-string)) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
373 (comint-send-region proc beg end) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
374 (comint-send-string proc "\n") ;May be unnecessary |
41 | 375 (if prolog-eof-string |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
376 (comint-send-string proc prolog-eof-string) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
377 (with-current-buffer (process-buffer proc) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
378 (comint-send-eof))))) ;Send eof to prolog process. |
41 | 379 |
380 (defun prolog-consult-region-and-go (compile beg end) | |
381 "Send the region to the inferior Prolog, and switch to *prolog* buffer. | |
242 | 382 If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." |
41 | 383 (interactive "P\nr") |
384 (prolog-consult-region compile beg end) | |
72696
560a2e73e11b
(inferior-prolog-flavor): New var left out of previous commit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
72684
diff
changeset
|
385 (pop-to-buffer inferior-prolog-buffer)) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
386 |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
387 (defun inferior-prolog-load-file () |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
388 "Pass the current buffer's file to the inferior prolog process." |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
389 (interactive) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
390 (save-buffer) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
391 (let ((file buffer-file-name) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
392 (proc (inferior-prolog-process))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
393 (with-current-buffer (process-buffer proc) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
394 (comint-send-string proc (concat "['" (file-relative-name file) "'].\n")) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
395 (pop-to-buffer (current-buffer))))) |
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
396 |
18383 | 397 (provide 'prolog) |
398 | |
72684
f65ec4fd2be1
Remove * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
399 ;; arch-tag: f3ec6748-1272-4ab6-8826-c50cb1607636 |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
400 ;;; prolog.el ends here |