aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-01-28 14:46:58 -0500
committerStefan Monnier2011-01-28 14:46:58 -0500
commit01c63f4ce4a85d3429dc56b72fdb8514dea8874d (patch)
treee829ee10d629fd04fca55a4cf256cac8b342c2e7
parent2f224f0b1a8d826ced25a1c8b7e79987090dbd08 (diff)
downloademacs-01c63f4ce4a85d3429dc56b72fdb8514dea8874d.tar.gz
emacs-01c63f4ce4a85d3429dc56b72fdb8514dea8874d.zip
Port features from the previous prolog.el to the new one.
* lisp/progmodes/prolog.el (prolog-system): Add GNU and ECLiPSe options. (prolog-program-name, prolog-program-switches, prolog-consult-string) (prolog-compile-string, prolog-prompt-regexp): Get rid of the <foo>-i variable and use a function to compute the value dynamically. (prolog-prompt-regexp): Add regexp for GNU Prolog. (prolog-continued-prompt-regexp): Remove, unused. (prolog-find-value-by-system): Try and use the value of prolog-system in the *prolog* buffer if it helps. (prolog-mode-keybindings-common): Bind C-c C-z unconditionally... (prolog-zip-on): ..and check prolog-system and version here instead. (prolog-inferior-self-insert-command): New command. (prolog-inferior-mode-map): Use it. (prolog-inferior-error-regexp-alist): New var. (prolog-inferior-mode): Use it, along with compilation-shell-minor-mode. (prolog-input-filter): Use derived-mode-p. (prolog-inferior-guess-flavor): New function. (prolog-ensure-process): Use it. Use make-comint-in-buffer rather than make-comint to avoid running comint-mode twice. (prolog-inferior-buffer): New fun. (prolog-old-process-region, prolog-old-process-file): Don't call prolog-bsts here... (prolog-build-prolog-command): ...do it here instead. (prolog-old-process-region, prolog-old-process-file): Use compilation-fake-loc and compilation-forget-errors. (prolog-consult-compile-region): Use bolp.
-rw-r--r--lisp/ChangeLog29
-rw-r--r--lisp/progmodes/prolog.el248
2 files changed, 215 insertions, 62 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2e1a5f2e257..2606b5d62ea 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,32 @@
12011-01-28 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 Port features from the previous prolog.el to the new one.
4 * progmodes/prolog.el (prolog-system): Add GNU and ECLiPSe options.
5 (prolog-program-name, prolog-program-switches, prolog-consult-string)
6 (prolog-compile-string, prolog-prompt-regexp): Get rid of the <foo>-i
7 variable and use a function to compute the value dynamically.
8 (prolog-prompt-regexp): Add regexp for GNU Prolog.
9 (prolog-continued-prompt-regexp): Remove, unused.
10 (prolog-find-value-by-system): Try and use the value of prolog-system
11 in the *prolog* buffer if it helps.
12 (prolog-mode-keybindings-common): Bind C-c C-z unconditionally...
13 (prolog-zip-on): ..and check prolog-system and version here instead.
14 (prolog-inferior-self-insert-command): New command.
15 (prolog-inferior-mode-map): Use it.
16 (prolog-inferior-error-regexp-alist): New var.
17 (prolog-inferior-mode): Use it, along with compilation-shell-minor-mode.
18 (prolog-input-filter): Use derived-mode-p.
19 (prolog-inferior-guess-flavor): New function.
20 (prolog-ensure-process): Use it. Use make-comint-in-buffer rather than
21 make-comint to avoid running comint-mode twice.
22 (prolog-inferior-buffer): New fun.
23 (prolog-old-process-region, prolog-old-process-file):
24 Don't call prolog-bsts here...
25 (prolog-build-prolog-command): ...do it here instead.
26 (prolog-old-process-region, prolog-old-process-file):
27 Use compilation-fake-loc and compilation-forget-errors.
28 (prolog-consult-compile-region): Use bolp.
29
12011-01-28 Chong Yidong <cyd@stupidchicken.com> 302011-01-28 Chong Yidong <cyd@stupidchicken.com>
2 31
3 * image-mode.el (image-display-size): Doc fix (Bug#7820). 32 * image-mode.el (image-display-size): Doc fix (Bug#7820).
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index 98c89ee70cf..fd79cfd2399 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -344,6 +344,10 @@ gnu - GNU Prolog"
344 :group 'prolog 344 :group 'prolog
345 :type '(choice (const :tag "SICStus" :value sicstus) 345 :type '(choice (const :tag "SICStus" :value sicstus)
346 (const :tag "SWI Prolog" :value swi) 346 (const :tag "SWI Prolog" :value swi)
347 (const :tag "GNU Prolog" :value gnu)
348 (const :tag "ECLiPSe Prolog" :value eclipse)
349 ;; Mercury shouldn't be needed since we have a separate
350 ;; major mode for it.
347 (const :tag "Default" :value nil))) 351 (const :tag "Default" :value nil)))
348(make-variable-buffer-local 'prolog-system) 352(make-variable-buffer-local 'prolog-system)
349 353
@@ -356,6 +360,7 @@ gnu - GNU Prolog"
356 (mercury (0 . 0)) 360 (mercury (0 . 0))
357 (eclipse (3 . 7)) 361 (eclipse (3 . 7))
358 (gnu (0 . 0))) 362 (gnu (0 . 0)))
363 ;; FIXME: This should be auto-detected instead of user-provided.
359 "*Alist of Prolog system versions. 364 "*Alist of Prolog system versions.
360The version numbers are of the format (Major . Minor)." 365The version numbers are of the format (Major . Minor)."
361 :group 'prolog) 366 :group 'prolog)
@@ -568,6 +573,8 @@ the first column (i.e., DCG heads) inserts ` -->' and newline."
568 "*Alist of program names for invoking an inferior Prolog with `run-prolog'." 573 "*Alist of program names for invoking an inferior Prolog with `run-prolog'."
569 :group 'prolog-inferior 574 :group 'prolog-inferior
570 :type 'sexp) 575 :type 'sexp)
576(defun prolog-program-name ()
577 (prolog-find-value-by-system prolog-program-name))
571 578
572(defcustom prolog-program-switches 579(defcustom prolog-program-switches
573 '((sicstus ("-i")) 580 '((sicstus ("-i"))
@@ -575,6 +582,8 @@ the first column (i.e., DCG heads) inserts ` -->' and newline."
575 "*Alist of switches given to inferior Prolog run with `run-prolog'." 582 "*Alist of switches given to inferior Prolog run with `run-prolog'."
576 :group 'prolog-inferior 583 :group 'prolog-inferior
577 :type 'sexp) 584 :type 'sexp)
585(defun prolog-program-switches ()
586 (prolog-find-value-by-system prolog-program-switches))
578 587
579(defcustom prolog-consult-string 588(defcustom prolog-consult-string
580 '((eclipse "[%f].") 589 '((eclipse "[%f].")
@@ -596,6 +605,8 @@ Some parts of the string are replaced:
596 the region." 605 the region."
597 :group 'prolog-inferior 606 :group 'prolog-inferior
598 :type 'sexp) 607 :type 'sexp)
608(defun prolog-consult-string ()
609 (prolog-find-value-by-system prolog-consult-string))
599 610
600(defcustom prolog-compile-string 611(defcustom prolog-compile-string
601 '((eclipse "[%f].") 612 '((eclipse "[%f].")
@@ -619,6 +630,8 @@ If `prolog-program-name' is non-nil, it is a string sent to a Prolog process.
619If `prolog-program-name' is nil, it is an argument to the `compile' function." 630If `prolog-program-name' is nil, it is an argument to the `compile' function."
620 :group 'prolog-inferior 631 :group 'prolog-inferior
621 :type 'sexp) 632 :type 'sexp)
633(defun prolog-compile-string ()
634 (prolog-find-value-by-system prolog-compile-string))
622 635
623(defcustom prolog-eof-string "end_of_file.\n" 636(defcustom prolog-eof-string "end_of_file.\n"
624 "*Alist of strings that represent end of file for prolog. 637 "*Alist of strings that represent end of file for prolog.
@@ -630,17 +643,20 @@ nil means send actual operating system end of file."
630 '((eclipse "^[a-zA-Z0-9()]* *\\?- \\|^\\[[a-zA-Z]* [0-9]*\\]:") 643 '((eclipse "^[a-zA-Z0-9()]* *\\?- \\|^\\[[a-zA-Z]* [0-9]*\\]:")
631 (sicstus "| [ ?][- ] *") 644 (sicstus "| [ ?][- ] *")
632 (swi "^\\(\\[[a-zA-Z]*\\] \\)?[1-9]?[0-9]*[ ]?\\?- \\|^| +") 645 (swi "^\\(\\[[a-zA-Z]*\\] \\)?[1-9]?[0-9]*[ ]?\\?- \\|^| +")
633 (t "^ *\\?-")) 646 (gnu "^| \\?-")
647 (t "^|? *\\?-"))
634 "*Alist of prompts of the prolog system command line." 648 "*Alist of prompts of the prolog system command line."
635 :group 'prolog-inferior 649 :group 'prolog-inferior
636 :type 'sexp) 650 :type 'sexp)
651(defun prolog-prompt-regexp ()
652 (prolog-find-value-by-system prolog-prompt-regexp))
637 653
638(defcustom prolog-continued-prompt-regexp 654;; (defcustom prolog-continued-prompt-regexp
639 '((sicstus "^\\(| +\\| +\\)") 655;; '((sicstus "^\\(| +\\| +\\)")
640 (t "^|: +")) 656;; (t "^|: +"))
641 "*Alist of regexps matching the prompt when consulting `user'." 657;; "*Alist of regexps matching the prompt when consulting `user'."
642 :group 'prolog-inferior 658;; :group 'prolog-inferior
643 :type 'sexp) 659;; :type 'sexp)
644 660
645(defcustom prolog-debug-on-string "debug.\n" 661(defcustom prolog-debug-on-string "debug.\n"
646 "*Predicate for enabling debug mode." 662 "*Predicate for enabling debug mode."
@@ -786,9 +802,9 @@ Set by prolog-build-case-strings.")
786(defvar prolog-atom-regexp "" 802(defvar prolog-atom-regexp ""
787 "Set by prolog-set-atom-regexps.") 803 "Set by prolog-set-atom-regexps.")
788 804
789(defconst prolog-left-paren "[[({]" 805(defconst prolog-left-paren "[[({]" ;FIXME: Why not \\s(?
790 "The characters used as left parentheses for the indentation code.") 806 "The characters used as left parentheses for the indentation code.")
791(defconst prolog-right-paren "[])}]" 807(defconst prolog-right-paren "[])}]" ;FIXME: Why not \\s)?
792 "The characters used as right parentheses for the indentation code.") 808 "The characters used as right parentheses for the indentation code.")
793 809
794(defconst prolog-quoted-atom-regexp 810(defconst prolog-quoted-atom-regexp
@@ -809,13 +825,8 @@ Set by prolog-build-case-strings.")
809(defvar prolog-mode-specificators-i nil) 825(defvar prolog-mode-specificators-i nil)
810(defvar prolog-determinism-specificators-i nil) 826(defvar prolog-determinism-specificators-i nil)
811(defvar prolog-directives-i nil) 827(defvar prolog-directives-i nil)
812(defvar prolog-program-name-i nil)
813(defvar prolog-program-switches-i nil)
814(defvar prolog-consult-string-i nil)
815(defvar prolog-compile-string-i nil)
816(defvar prolog-eof-string-i nil) 828(defvar prolog-eof-string-i nil)
817(defvar prolog-prompt-regexp-i nil) 829;; (defvar prolog-continued-prompt-regexp-i nil)
818(defvar prolog-continued-prompt-regexp-i nil)
819(defvar prolog-help-function-i nil) 830(defvar prolog-help-function-i nil)
820 831
821(defvar prolog-align-rules 832(defvar prolog-align-rules
@@ -856,24 +867,27 @@ VERSION is of the format (Major . Minor)"
856 867
857(defun prolog-find-value-by-system (alist) 868(defun prolog-find-value-by-system (alist)
858 "Get value from ALIST according to `prolog-system'." 869 "Get value from ALIST according to `prolog-system'."
859 (if (listp alist) 870 (let ((system (or prolog-system
860 (let (result 871 (buffer-local-value 'prolog-system
861 id) 872 (prolog-inferior-buffer 'dont-run)))))
862 (while alist 873 (if (listp alist)
863 (setq id (car (car alist))) 874 (let (result
864 (if (or (eq id prolog-system) 875 id)
865 (eq id t) 876 (while alist
866 (and (listp id) 877 (setq id (car (car alist)))
867 (eval id))) 878 (if (or (eq id system)
868 (progn 879 (eq id t)
869 (setq result (car (cdr (car alist)))) 880 (and (listp id)
870 (if (and (listp result) 881 (eval id)))
871 (eq (car result) 'eval)) 882 (progn
872 (setq result (eval (car (cdr result))))) 883 (setq result (car (cdr (car alist))))
873 (setq alist nil)) 884 (if (and (listp result)
874 (setq alist (cdr alist)))) 885 (eq (car result) 'eval))
875 result) 886 (setq result (eval (car (cdr result)))))
876 alist)) 887 (setq alist nil))
888 (setq alist (cdr alist))))
889 result)
890 alist)))
877 891
878(defconst prolog-syntax-propertize-function 892(defconst prolog-syntax-propertize-function
879 (when (fboundp 'syntax-propertize-rules) 893 (when (fboundp 'syntax-propertize-rules)
@@ -914,14 +928,13 @@ VERSION is of the format (Major . Minor)"
914 ;; Initialize Prolog system specific variables 928 ;; Initialize Prolog system specific variables
915 (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators 929 (dolist (var '(prolog-keywords prolog-types prolog-mode-specificators
916 prolog-determinism-specificators prolog-directives 930 prolog-determinism-specificators prolog-directives
917 prolog-program-name prolog-program-switches 931 prolog-eof-string
918 prolog-consult-string prolog-compile-string prolog-eof-string 932 ;; prolog-continued-prompt-regexp
919 prolog-prompt-regexp prolog-continued-prompt-regexp
920 prolog-help-function)) 933 prolog-help-function))
921 (set (intern (concat (symbol-name var) "-i")) 934 (set (intern (concat (symbol-name var) "-i"))
922 (prolog-find-value-by-system (symbol-value var)))) 935 (prolog-find-value-by-system (symbol-value var))))
923 (when (null prolog-program-name-i) 936 (when (null (prolog-program-name))
924 (set (make-local-variable 'compile-command) prolog-compile-string-i)) 937 (set (make-local-variable 'compile-command) (prolog-compile-string)))
925 (set (make-local-variable 'font-lock-defaults) 938 (set (make-local-variable 'font-lock-defaults)
926 '(prolog-font-lock-keywords nil nil ((?_ . "w")))) 939 '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
927 (set (make-local-variable 'syntax-propertize-function) 940 (set (make-local-variable 'syntax-propertize-function)
@@ -934,9 +947,7 @@ VERSION is of the format (Major . Minor)"
934 (define-key map "\C-c/" 'prolog-help-apropos) 947 (define-key map "\C-c/" 'prolog-help-apropos)
935 (define-key map "\C-c\C-d" 'prolog-debug-on) 948 (define-key map "\C-c\C-d" 'prolog-debug-on)
936 (define-key map "\C-c\C-t" 'prolog-trace-on) 949 (define-key map "\C-c\C-t" 'prolog-trace-on)
937 (if (and (eq prolog-system 'sicstus) 950 (define-key map "\C-c\C-z" 'prolog-zip-on)
938 (prolog-atleast-version '(3 . 7)))
939 (define-key map "\C-c\C-z" 'prolog-zip-on))
940 (define-key map "\C-c\r" 'run-prolog)) 951 (define-key map "\C-c\r" 'run-prolog))
941 952
942(defun prolog-mode-keybindings-edit (map) 953(defun prolog-mode-keybindings-edit (map)
@@ -1074,11 +1085,47 @@ Actually this is just customized `prolog-mode'."
1074 (let ((map (make-sparse-keymap))) 1085 (let ((map (make-sparse-keymap)))
1075 (prolog-mode-keybindings-common map) 1086 (prolog-mode-keybindings-common map)
1076 (prolog-mode-keybindings-inferior map) 1087 (prolog-mode-keybindings-inferior map)
1088 (define-key map [remap self-insert-command]
1089 'prolog-inferior-self-insert-command)
1077 map)) 1090 map))
1078 1091
1079(defvar prolog-inferior-mode-hook nil 1092(defvar prolog-inferior-mode-hook nil
1080 "List of functions to call after the inferior prolog mode has initialised.") 1093 "List of functions to call after the inferior prolog mode has initialised.")
1081 1094
1095(defvar prolog-inferior-error-regexp-alist
1096 '(;; GNU Prolog used to not follow the GNU standard format.
1097 ;; ("^\\(.*?\\):\\([0-9]+\\) error: .*(char:\\([0-9]+\\)" 1 2 3)
1098 ;; SWI-Prolog.
1099 ("^\\(?:\\?- *\\)?\\(\\(?:ERROR\\|\\(W\\)arning\\): *\\(.*?\\):\\([1-9][0-9]*\\):\\(?:\\([0-9]*\\):\\)?\\)\\(?:$\\| \\)"
1100 3 4 5 (2 . nil) 1)
1101 ;; GNU-Prolog now uses the GNU standard format.
1102 gnu))
1103
1104(defun prolog-inferior-self-insert-command ()
1105 "Insert the char in the buffer or pass it directly to the process."
1106 (interactive)
1107 (let* ((proc (get-buffer-process (current-buffer)))
1108 (pmark (and proc (marker-position (process-mark proc)))))
1109 ;; FIXME: the same treatment would be needed for SWI-Prolog, but I can't
1110 ;; seem to find any way for Emacs to figure out when to use it because
1111 ;; SWI doesn't include a " ? " or some such recognizable marker.
1112 (if (and (eq prolog-system 'gnu)
1113 pmark
1114 (null current-prefix-arg)
1115 (eobp)
1116 (eq (point) pmark)
1117 (save-excursion
1118 (goto-char (- pmark 3))
1119 ;; FIXME: check this comes from the process's output, maybe?
1120 (looking-at " \\? ")))
1121 ;; This is GNU prolog waiting to know whether you want more answers
1122 ;; or not (or abort, etc...). The answer is a single char, not
1123 ;; a line, so pass this char directly rather than wait for RET to
1124 ;; send a whole line.
1125 (comint-send-string proc (string last-command-event))
1126 (call-interactively 'self-insert-command))))
1127
1128
1082(define-derived-mode prolog-inferior-mode comint-mode "Inferior Prolog" 1129(define-derived-mode prolog-inferior-mode comint-mode "Inferior Prolog"
1083 "Major mode for interacting with an inferior Prolog process. 1130 "Major mode for interacting with an inferior Prolog process.
1084 1131
@@ -1111,13 +1158,16 @@ To find out what version of Prolog mode you are running, enter
1111 (setq comint-input-filter 'prolog-input-filter) 1158 (setq comint-input-filter 'prolog-input-filter)
1112 (setq mode-line-process '(": %s")) 1159 (setq mode-line-process '(": %s"))
1113 (prolog-mode-variables) 1160 (prolog-mode-variables)
1114 (setq comint-prompt-regexp prolog-prompt-regexp-i) 1161 (setq comint-prompt-regexp (prolog-prompt-regexp))
1115 (set (make-local-variable 'shell-dirstack-query) "pwd.") 1162 (set (make-local-variable 'shell-dirstack-query) "pwd.")
1163 (set (make-local-variable 'compilation-error-regexp-alist)
1164 prolog-inferior-error-regexp-alist)
1165 (compilation-shell-minor-mode)
1116 (prolog-inferior-menu)) 1166 (prolog-inferior-menu))
1117 1167
1118(defun prolog-input-filter (str) 1168(defun prolog-input-filter (str)
1119 (cond ((string-match "\\`\\s *\\'" str) nil) ;whitespace 1169 (cond ((string-match "\\`\\s *\\'" str) nil) ;whitespace
1120 ((not (eq major-mode 'prolog-inferior-mode)) t) 1170 ((not (derived-mode-p 'prolog-inferior-mode)) t)
1121 ((= (length str) 1) nil) ;one character 1171 ((= (length str) 1) nil) ;one character
1122 ((string-match "\\`[rf] *[0-9]*\\'" str) nil) ;r(edo) or f(ail) 1172 ((string-match "\\`[rf] *[0-9]*\\'" str) nil) ;r(edo) or f(ail)
1123 (t t))) 1173 (t t)))
@@ -1127,6 +1177,8 @@ To find out what version of Prolog mode you are running, enter
1127 "Run an inferior Prolog process, input and output via buffer *prolog*. 1177 "Run an inferior Prolog process, input and output via buffer *prolog*.
1128With prefix argument ARG, restart the Prolog process if running before." 1178With prefix argument ARG, restart the Prolog process if running before."
1129 (interactive "P") 1179 (interactive "P")
1180 ;; FIXME: It should be possible to interactively specify the command to use
1181 ;; to run prolog.
1130 (if (and arg (get-process "prolog")) 1182 (if (and arg (get-process "prolog"))
1131 (progn 1183 (progn
1132 (process-send-string "prolog" "halt.\n") 1184 (process-send-string "prolog" "halt.\n")
@@ -1143,18 +1195,55 @@ With prefix argument ARG, restart the Prolog process if running before."
1143 (prolog-ensure-process) 1195 (prolog-ensure-process)
1144 )) 1196 ))
1145 1197
1198(defun prolog-inferior-guess-flavor (&optional ignored)
1199 (setq prolog-system
1200 (when (or (numberp prolog-system) (markerp prolog-system))
1201 (save-excursion
1202 (goto-char (1+ prolog-system))
1203 (cond
1204 ((looking-at "GNU Prolog") 'gnu)
1205 ((looking-at "Welcome to SWI-Prolog\\|%.*\\<swi_") 'swi)
1206 ((looking-at ".*\n") nil) ;There's at least one line.
1207 (t prolog-system)))))
1208 (when (symbolp prolog-system)
1209 (remove-hook 'comint-output-filter-functions
1210 'prolog-inferior-guess-flavor t)
1211 (when prolog-system
1212 (setq comint-prompt-regexp (prolog-prompt-regexp))
1213 (if (eq prolog-system 'gnu)
1214 (set (make-local-variable 'comint-process-echoes) t)))))
1215
1146(defun prolog-ensure-process (&optional wait) 1216(defun prolog-ensure-process (&optional wait)
1147 "If Prolog process is not running, run it. 1217 "If Prolog process is not running, run it.
1148If the optional argument WAIT is non-nil, wait for Prolog prompt specified by 1218If the optional argument WAIT is non-nil, wait for Prolog prompt specified by
1149the variable `prolog-prompt-regexp'." 1219the variable `prolog-prompt-regexp'."
1150 (if (null prolog-program-name-i) 1220 (if (null (prolog-program-name))
1151 (error "This Prolog system has defined no interpreter.")) 1221 (error "This Prolog system has defined no interpreter."))
1152 (if (comint-check-proc "*prolog*") 1222 (if (comint-check-proc "*prolog*")
1153 () 1223 ()
1154 (apply 'make-comint "prolog" prolog-program-name-i nil 1224 (with-current-buffer (get-buffer-create "*prolog*")
1155 prolog-program-switches-i)
1156 (with-current-buffer "*prolog*"
1157 (prolog-inferior-mode) 1225 (prolog-inferior-mode)
1226 (apply 'make-comint-in-buffer "prolog" (current-buffer)
1227 (prolog-program-name) nil (prolog-program-switches))
1228 (unless prolog-system
1229 ;; Setup auto-detection.
1230 (set (make-local-variable 'prolog-system)
1231 ;; Force re-detection.
1232 (let* ((proc (get-buffer-process (current-buffer)))
1233 (pmark (and proc (marker-position (process-mark proc)))))
1234 (cond
1235 ((null pmark) (1- (point-min)))
1236 ;; The use of insert-before-markers in comint.el together with
1237 ;; the potential use of comint-truncate-buffer in the output
1238 ;; filter, means that it's difficult to reliably keep track of
1239 ;; the buffer position where the process's output started.
1240 ;; If possible we use a marker at "start - 1", so that
1241 ;; insert-before-marker at `start' won't shift it. And if not,
1242 ;; we fall back on using a plain integer.
1243 ((> pmark (point-min)) (copy-marker (1- pmark)))
1244 (t (1- pmark)))))
1245 (add-hook 'comint-output-filter-functions
1246 'prolog-inferior-guess-flavor nil t))
1158 (if wait 1247 (if wait
1159 (progn 1248 (progn
1160 (goto-char (point-max)) 1249 (goto-char (point-max))
@@ -1162,10 +1251,16 @@ the variable `prolog-prompt-regexp'."
1162 (save-excursion 1251 (save-excursion
1163 (not 1252 (not
1164 (re-search-backward 1253 (re-search-backward
1165 (concat "\\(" prolog-prompt-regexp-i "\\)" "\\=") 1254 (concat "\\(" (prolog-prompt-regexp) "\\)" "\\=")
1166 nil t))) 1255 nil t)))
1167 (sit-for 0.1))))))) 1256 (sit-for 0.1)))))))
1168 1257
1258(defun prolog-inferior-buffer (&optional dont-run)
1259 (or (get-buffer "*prolog*")
1260 (unless dont-run
1261 (prolog-ensure-process)
1262 (get-buffer "*prolog*"))))
1263
1169(defun prolog-process-insert-string (process string) 1264(defun prolog-process-insert-string (process string)
1170 "Insert STRING into inferior Prolog buffer running PROCESS." 1265 "Insert STRING into inferior Prolog buffer running PROCESS."
1171 ;; Copied from elisp manual, greek to me 1266 ;; Copied from elisp manual, greek to me
@@ -1188,7 +1283,7 @@ the variable `prolog-prompt-regexp'."
1188If COMPILEP is non-nil then use compilation, otherwise consulting." 1283If COMPILEP is non-nil then use compilation, otherwise consulting."
1189 (prolog-ensure-process) 1284 (prolog-ensure-process)
1190 ;(let ((tmpfile prolog-temp-filename) 1285 ;(let ((tmpfile prolog-temp-filename)
1191 (let ((tmpfile (prolog-bsts (prolog-temporary-file))) 1286 (let ((tmpfile (prolog-temporary-file))
1192 ;(process (get-process "prolog")) 1287 ;(process (get-process "prolog"))
1193 (first-line (1+ (count-lines 1288 (first-line (1+ (count-lines
1194 (point-min) 1289 (point-min)
@@ -1196,6 +1291,10 @@ If COMPILEP is non-nil then use compilation, otherwise consulting."
1196 (goto-char start) 1291 (goto-char start)
1197 (point)))))) 1292 (point))))))
1198 (write-region start end tmpfile) 1293 (write-region start end tmpfile)
1294 (setq start (copy-marker start))
1295 (with-current-buffer (prolog-inferior-buffer)
1296 (compilation-forget-errors)
1297 (compilation-fake-loc start tmpfile))
1199 (process-send-string 1298 (process-send-string
1200 "prolog" (prolog-build-prolog-command 1299 "prolog" (prolog-build-prolog-command
1201 compilep tmpfile (prolog-bsts buffer-file-name) 1300 compilep tmpfile (prolog-bsts buffer-file-name)
@@ -1218,19 +1317,21 @@ If COMPILEP is non-nil then use compilation, otherwise consulting."
1218If COMPILEP is non-nil then use compilation, otherwise consulting." 1317If COMPILEP is non-nil then use compilation, otherwise consulting."
1219 (save-some-buffers) 1318 (save-some-buffers)
1220 (prolog-ensure-process) 1319 (prolog-ensure-process)
1221 (let ((filename (prolog-bsts buffer-file-name))) 1320 (with-current-buffer (prolog-inferior-buffer)
1321 (compilation-forget-errors))
1222 (process-send-string 1322 (process-send-string
1223 "prolog" (prolog-build-prolog-command 1323 "prolog" (prolog-build-prolog-command
1224 compilep filename filename)) 1324 compilep buffer-file-name
1225 (prolog-goto-prolog-process-buffer))) 1325 (prolog-bsts buffer-file-name)))
1326 (prolog-goto-prolog-process-buffer))
1226 1327
1227 1328
1228;;------------------------------------------------------------ 1329;;------------------------------------------------------------
1229;; Consulting and compiling 1330;; Consulting and compiling
1230;;------------------------------------------------------------ 1331;;------------------------------------------------------------
1231 1332
1232;;; Interactive interface functions, used by both the standard 1333;; Interactive interface functions, used by both the standard
1233;;; and the experimental consultation and compilation functions 1334;; and the experimental consultation and compilation functions
1234(defun prolog-consult-file () 1335(defun prolog-consult-file ()
1235 "Consult file of current buffer." 1336 "Consult file of current buffer."
1236 (interactive) 1337 (interactive)
@@ -1321,9 +1422,12 @@ Bases decision on buffer contents (-*- line)."
1321 "Make Prolog command for FILE compilation/consulting. 1422 "Make Prolog command for FILE compilation/consulting.
1322If COMPILEP is non-nil, consider compilation, otherwise consulting." 1423If COMPILEP is non-nil, consider compilation, otherwise consulting."
1323 (let* ((compile-string 1424 (let* ((compile-string
1324 (if compilep prolog-compile-string-i prolog-consult-string-i)) 1425 ;; FIXME: If the process is not running yet, the auto-detection of
1426 ;; prolog-system won't help here, so we should make sure
1427 ;; we first run Prolog and then build the command.
1428 (if compilep (prolog-compile-string) (prolog-consult-string)))
1325 (module (prolog-buffer-module)) 1429 (module (prolog-buffer-module))
1326 (file-name (concat "'" file "'")) 1430 (file-name (concat "'" (prolog-bsts file) "'"))
1327 (module-name (if module (concat "'" module "'"))) 1431 (module-name (if module (concat "'" module "'")))
1328 (module-file (if module 1432 (module-file (if module
1329 (concat module-name ":" file-name) 1433 (concat module-name ":" file-name)
@@ -1359,7 +1463,7 @@ If COMPILEP is non-nil, consider compilation, otherwise consulting."
1359 (setq compile-string (concat strbeg (format "%d" lineoffset) strend))) 1463 (setq compile-string (concat strbeg (format "%d" lineoffset) strend)))
1360 (concat compile-string "\n"))) 1464 (concat compile-string "\n")))
1361 1465
1362;;; The rest of this page is experimental code! 1466;; The rest of this page is experimental code!
1363 1467
1364;; Global variables for process filter function 1468;; Global variables for process filter function
1365(defvar prolog-process-flag nil 1469(defvar prolog-process-flag nil
@@ -1395,14 +1499,20 @@ This function must be called from the source code buffer."
1395 (old-filter (process-filter process))) 1499 (old-filter (process-filter process)))
1396 (with-current-buffer buffer 1500 (with-current-buffer buffer
1397 (delete-region (point-min) (point-max)) 1501 (delete-region (point-min) (point-max))
1502 ;; FIXME: Wasn't this supposed to use prolog-inferior-mode?
1398 (compilation-mode) 1503 (compilation-mode)
1504 ;; FIXME: This doesn't seem to cooperate well with new(ish) compile.el.
1399 ;; Setting up font-locking for this buffer 1505 ;; Setting up font-locking for this buffer
1400 (set (make-local-variable 'font-lock-defaults) 1506 (set (make-local-variable 'font-lock-defaults)
1401 '(prolog-font-lock-keywords nil nil ((?_ . "w")))) 1507 '(prolog-font-lock-keywords nil nil ((?_ . "w"))))
1402 (if (eq prolog-system 'sicstus) 1508 (if (eq prolog-system 'sicstus)
1403 (progn 1509 ;; FIXME: This looks really problematic: not only is this using
1510 ;; the old compilation-parse-errors-function, but
1511 ;; prolog-parse-sicstus-compilation-errors only accepts one argument
1512 ;; whereas compile.el calls it with 2 (and did so at least since
1513 ;; Emacs-20).
1404 (set (make-local-variable 'compilation-parse-errors-function) 1514 (set (make-local-variable 'compilation-parse-errors-function)
1405 'prolog-parse-sicstus-compilation-errors))) 1515 'prolog-parse-sicstus-compilation-errors))
1406 (toggle-read-only 0) 1516 (toggle-read-only 0)
1407 (insert command-string "\n")) 1517 (insert command-string "\n"))
1408 (save-selected-window 1518 (save-selected-window
@@ -1498,6 +1608,7 @@ Argument OUTPUT is a name of the output file."
1498 1608
1499 ;; If temporary files were used, then we change the error 1609 ;; If temporary files were used, then we change the error
1500 ;; messages to point to the original source file. 1610 ;; messages to point to the original source file.
1611 ;; FIXME: Use compilation-fake-loc instead.
1501 (cond 1612 (cond
1502 1613
1503 ;; If the prolog process was in trace mode then it requires 1614 ;; If the prolog process was in trace mode then it requires
@@ -1552,7 +1663,7 @@ Argument OUTPUT is a name of the output file."
1552 (insert output))) 1663 (insert output)))
1553 1664
1554 ;; If the prompt is visible, then the task is finished 1665 ;; If the prompt is visible, then the task is finished
1555 (if (string-match prolog-prompt-regexp-i prolog-consult-compile-output) 1666 (if (string-match (prolog-prompt-regexp) prolog-consult-compile-output)
1556 (setq prolog-process-flag nil))) 1667 (setq prolog-process-flag nil)))
1557 1668
1558(defun prolog-consult-compile-file (compilep) 1669(defun prolog-consult-compile-file (compilep)
@@ -1579,7 +1690,7 @@ If COMPILEP is non-nil, compile, otherwise consult."
1579 (write-region beg end file nil 'no-message) 1690 (write-region beg end file nil 'no-message)
1580 (write-region "\n" nil file t 'no-message) 1691 (write-region "\n" nil file t 'no-message)
1581 (prolog-consult-compile compilep file 1692 (prolog-consult-compile compilep file
1582 (if (looking-at "^") (1+ lines) lines)) 1693 (if (bolp) (1+ lines) lines))
1583 (delete-file file))) 1694 (delete-file file)))
1584 1695
1585(defun prolog-consult-compile-predicate (compilep) 1696(defun prolog-consult-compile-predicate (compilep)
@@ -1760,8 +1871,10 @@ Argument BOUND is a buffer position limiting searching."
1760 0 'prolog-warning-face))) 1871 0 'prolog-warning-face)))
1761 ;; Inferior mode specific patterns 1872 ;; Inferior mode specific patterns
1762 (prompt 1873 (prompt
1763 (list prolog-prompt-regexp-i 0 'font-lock-keyword-face)) 1874 ;; FIXME: Should be handled by comint already.
1875 (list (prolog-prompt-regexp) 0 'font-lock-keyword-face))
1764 (trace-exit 1876 (trace-exit
1877 ;; FIXME: Add to compilation-error-regexp-alist instead.
1765 (cond 1878 (cond
1766 ((eq prolog-system 'sicstus) 1879 ((eq prolog-system 'sicstus)
1767 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exit\\):" 1880 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exit\\):"
@@ -1770,6 +1883,7 @@ Argument BOUND is a buffer position limiting searching."
1770 '("[ \t]*\\(Exit\\):[ \t]*([ \t0-9]*)" 1 prolog-exit-face)) 1883 '("[ \t]*\\(Exit\\):[ \t]*([ \t0-9]*)" 1 prolog-exit-face))
1771 (t nil))) 1884 (t nil)))
1772 (trace-fail 1885 (trace-fail
1886 ;; FIXME: Add to compilation-error-regexp-alist instead.
1773 (cond 1887 (cond
1774 ((eq prolog-system 'sicstus) 1888 ((eq prolog-system 'sicstus)
1775 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Fail\\):" 1889 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Fail\\):"
@@ -1778,6 +1892,7 @@ Argument BOUND is a buffer position limiting searching."
1778 '("[ \t]*\\(Fail\\):[ \t]*([ \t0-9]*)" 1 prolog-warning-face)) 1892 '("[ \t]*\\(Fail\\):[ \t]*([ \t0-9]*)" 1 prolog-warning-face))
1779 (t nil))) 1893 (t nil)))
1780 (trace-redo 1894 (trace-redo
1895 ;; FIXME: Add to compilation-error-regexp-alist instead.
1781 (cond 1896 (cond
1782 ((eq prolog-system 'sicstus) 1897 ((eq prolog-system 'sicstus)
1783 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Redo\\):" 1898 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Redo\\):"
@@ -1786,6 +1901,7 @@ Argument BOUND is a buffer position limiting searching."
1786 '("[ \t]*\\(Redo\\):[ \t]*([ \t0-9]*)" 1 prolog-redo-face)) 1901 '("[ \t]*\\(Redo\\):[ \t]*([ \t0-9]*)" 1 prolog-redo-face))
1787 (t nil))) 1902 (t nil)))
1788 (trace-call 1903 (trace-call
1904 ;; FIXME: Add to compilation-error-regexp-alist instead.
1789 (cond 1905 (cond
1790 ((eq prolog-system 'sicstus) 1906 ((eq prolog-system 'sicstus)
1791 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Call\\):" 1907 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Call\\):"
@@ -1795,6 +1911,7 @@ Argument BOUND is a buffer position limiting searching."
1795 1 font-lock-function-name-face)) 1911 1 font-lock-function-name-face))
1796 (t nil))) 1912 (t nil)))
1797 (trace-exception 1913 (trace-exception
1914 ;; FIXME: Add to compilation-error-regexp-alist instead.
1798 (cond 1915 (cond
1799 ((eq prolog-system 'sicstus) 1916 ((eq prolog-system 'sicstus)
1800 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exception\\):" 1917 '("[ \t]*[0-9]+[ \t]+[0-9]+[ \t]*\\(Exception\\):"
@@ -1804,6 +1921,7 @@ Argument BOUND is a buffer position limiting searching."
1804 1 prolog-exception-face)) 1921 1 prolog-exception-face))
1805 (t nil))) 1922 (t nil)))
1806 (error-message-identifier 1923 (error-message-identifier
1924 ;; FIXME: Add to compilation-error-regexp-alist instead.
1807 (cond 1925 (cond
1808 ((eq prolog-system 'sicstus) 1926 ((eq prolog-system 'sicstus)
1809 '("{\\([A-Z]* ?ERROR:\\)" 1 prolog-exception-face prepend)) 1927 '("{\\([A-Z]* ?ERROR:\\)" 1 prolog-exception-face prepend))
@@ -1811,6 +1929,7 @@ Argument BOUND is a buffer position limiting searching."
1811 '("^[[]\\(WARNING:\\)" 1 prolog-builtin-face prepend)) 1929 '("^[[]\\(WARNING:\\)" 1 prolog-builtin-face prepend))
1812 (t nil))) 1930 (t nil)))
1813 (error-whole-messages 1931 (error-whole-messages
1932 ;; FIXME: Add to compilation-error-regexp-alist instead.
1814 (cond 1933 (cond
1815 ((eq prolog-system 'sicstus) 1934 ((eq prolog-system 'sicstus)
1816 '("{\\([A-Z]* ?ERROR:.*\\)}[ \t]*$" 1935 '("{\\([A-Z]* ?ERROR:.*\\)}[ \t]*$"
@@ -1819,6 +1938,7 @@ Argument BOUND is a buffer position limiting searching."
1819 '("^[[]WARNING:[^]]*[]]$" 0 font-lock-comment-face append)) 1938 '("^[[]WARNING:[^]]*[]]$" 0 font-lock-comment-face append))
1820 (t nil))) 1939 (t nil)))
1821 (error-warning-messages 1940 (error-warning-messages
1941 ;; FIXME: Add to compilation-error-regexp-alist instead.
1822 ;; Mostly errors that SICStus asks the user about how to solve, 1942 ;; Mostly errors that SICStus asks the user about how to solve,
1823 ;; such as "NAME CLASH:" for example. 1943 ;; such as "NAME CLASH:" for example.
1824 (cond 1944 (cond
@@ -1826,6 +1946,7 @@ Argument BOUND is a buffer position limiting searching."
1826 '("^[A-Z ]*[A-Z]+:" 0 prolog-warning-face)) 1946 '("^[A-Z ]*[A-Z]+:" 0 prolog-warning-face))
1827 (t nil))) 1947 (t nil)))
1828 (warning-messages 1948 (warning-messages
1949 ;; FIXME: Add to compilation-error-regexp-alist instead.
1829 (cond 1950 (cond
1830 ((eq prolog-system 'sicstus) 1951 ((eq prolog-system 'sicstus)
1831 '("\\({ ?\\(Warning\\|WARNING\\) ?:.*}\\)[ \t]*$" 1952 '("\\({ ?\\(Warning\\|WARNING\\) ?:.*}\\)[ \t]*$"
@@ -2974,6 +3095,9 @@ When called with prefix argument ARG, disable tracing instead."
2974 "Enable zipping (for SICStus 3.7 and later). 3095 "Enable zipping (for SICStus 3.7 and later).
2975When called with prefix argument ARG, disable zipping instead." 3096When called with prefix argument ARG, disable zipping instead."
2976 (interactive "P") 3097 (interactive "P")
3098 (if (not (and (eq prolog-system 'sicstus)
3099 (prolog-atleast-version '(3 . 7))))
3100 (error "Only works for SICStus 3.7 and later"))
2977 (if arg 3101 (if arg
2978 (prolog-zip-off) 3102 (prolog-zip-off)
2979 (prolog-process-insert-string (get-process "prolog") 3103 (prolog-process-insert-string (get-process "prolog")