aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-01-11 00:07:32 -0500
committerStefan Monnier2011-01-11 00:07:32 -0500
commit04380ff1b8d938ff37e370ba7305d38ab7671cb7 (patch)
treee671cea083c0264a53044bb8aac7a814d6aab116
parente20195263bcdca959570c9631c3b66ed406b5d7a (diff)
downloademacs-04380ff1b8d938ff37e370ba7305d38ab7671cb7.tar.gz
emacs-04380ff1b8d938ff37e370ba7305d38ab7671cb7.zip
* lisp/progmodes/prolog.el: Fix up coding conventions and such.
(prolog-indent-width): Use the same default as in previous prolog.el rather than tab-width which depends on which buffer is current when the file is loaded. (prolog-electric-newline-flag): Only enable if electric-indent-mode is not available. (prolog-emacs): Remove. Use (featurep 'xemacs) instead. (prolog-known-systems): Remove. (prolog-mode-syntax-table, prolog-inferior-mode-map): Move initialization into declaration. (prolog-mode-map): Move initialization into declaration. Remove system-specific mode-map vars, since they referred to the same keymap anyway. (prolog-mode-variables): Obey the user's preference w.r.t adaptive-fill-mode. Prefer symbol-value to `eval'. (prolog-mode-keybindings-edit): Add compatibility bindings. (prolog-mode): Use define-derived-mode. Don't handle mercury here. (mercury-mode-map): New var. (mercury-mode, prolog-inferior-mode): Use define-derived-mode. (prolog-ensure-process, prolog-process-insert-string) (prolog-consult-compile): Use with-current-buffer. (prolog-guess-fill-prefix): Simplify data flow. (prolog-replace-in-string): New function to use instead of replace-in-string. (prolog-enable-sicstus-sd): Don't abuse `eval'. (prolog-uncomment-region): Use `uncomment-region' when available. (prolog-electric-colon, prolog-electric-dash): Use `eolp'. (prolog-int-to-char, prolog-char-to-int): New functions to use instead of int-to-char and char-to-int. (prolog-mode-hook, prolog-inferior-mode-hook): Don't force font-lock.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/ChangeLog33
-rw-r--r--lisp/progmodes/prolog.el557
3 files changed, 276 insertions, 318 deletions
diff --git a/etc/NEWS b/etc/NEWS
index a4b39da3c60..92d96fd1806 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -323,6 +323,10 @@ prompts for a number to count from and for a format string.
323 323
324* Changes in Specialized Modes and Packages in Emacs 24.1 324* Changes in Specialized Modes and Packages in Emacs 24.1
325 325
326** Prolog mode has been completely revamped, with lots of additional
327functionality such as more intelligent indentation, electricty, support for
328more variants, including Mercury, and a lot more.
329
326** shell-mode can track your cwd by reading it from your prompt. 330** shell-mode can track your cwd by reading it from your prompt.
327Just set shell-dir-cookie-re to an appropriate regexp. 331Just set shell-dir-cookie-re to an appropriate regexp.
328 332
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 913779c3d07..71bf97b0997 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,36 @@
12011-01-11 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * progmodes/prolog.el: Fix up coding convention and such.
4 (prolog-indent-width): Use the same default as in
5 previous prolog.el rather than tab-width which depends on which buffer
6 is current when the file is loaded.
7 (prolog-electric-newline-flag): Only enable if electric-indent-mode
8 is not available.
9 (prolog-emacs): Remove. Use (featurep 'xemacs) instead.
10 (prolog-known-systems): Remove.
11 (prolog-mode-syntax-table, prolog-inferior-mode-map):
12 Move initialization into declaration.
13 (prolog-mode-map): Move initialization into declaration.
14 Remove system-specific mode-map vars, since they referred to the same
15 keymap anyway.
16 (prolog-mode-variables): Obey the user's preference w.r.t
17 adaptive-fill-mode. Prefer symbol-value to `eval'.
18 (prolog-mode-keybindings-edit): Add compatibility bindings.
19 (prolog-mode): Use define-derived-mode. Don't handle mercury here.
20 (mercury-mode-map): New var.
21 (mercury-mode, prolog-inferior-mode): Use define-derived-mode.
22 (prolog-ensure-process, prolog-process-insert-string)
23 (prolog-consult-compile): Use with-current-buffer.
24 (prolog-guess-fill-prefix): Simplify data flow.
25 (prolog-replace-in-string): New function to use instead of
26 replace-in-string.
27 (prolog-enable-sicstus-sd): Don't abuse `eval'.
28 (prolog-uncomment-region): Use `uncomment-region' when available.
29 (prolog-electric-colon, prolog-electric-dash): Use `eolp'.
30 (prolog-int-to-char, prolog-char-to-int): New functions to use instead
31 of int-to-char and char-to-int.
32 (prolog-mode-hook, prolog-inferior-mode-hook): Don't force font-lock.
33
12011-01-11 Stefan Bruda <stefan@bruda.ca> 342011-01-11 Stefan Bruda <stefan@bruda.ca>
2 35
3 * progmodes/prolog.el: Replace by a whole new file. 36 * progmodes/prolog.el: Replace by a whole new file.
diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el
index fb6bbb7843b..16450ee3b69 100644
--- a/lisp/progmodes/prolog.el
+++ b/lisp/progmodes/prolog.el
@@ -1,6 +1,6 @@
1;; prolog.el --- major mode for editing and running Prolog (and Mercury) code 1;;; prolog.el --- major mode for editing and running Prolog (and Mercury) code
2 2
3;; Copyright (C) 1986, 1987, 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc. 3;; Copyright (C) 1986, 1987, 1997, 1998, 1999, 2002, 2003, 2011 Free Software Foundation, Inc.
4 4
5;; Authors: Emil Åström <emil_astrom(at)hotmail(dot)com> 5;; Authors: Emil Åström <emil_astrom(at)hotmail(dot)com>
6;; Milan Zamazal <pdm(at)freesoft(dot)cz> 6;; Milan Zamazal <pdm(at)freesoft(dot)cz>
@@ -9,22 +9,22 @@
9;; Keywords: prolog major mode sicstus swi mercury 9;; Keywords: prolog major mode sicstus swi mercury
10 10
11(defvar prolog-mode-version "1.22" 11(defvar prolog-mode-version "1.22"
12 "Prolog mode version number") 12 "Prolog mode version number.")
13 13
14;; This program is free software; you can redistribute it and/or modify 14;; This file is part of GNU Emacs.
15
16;; GNU Emacs is free software: you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by 17;; it under the terms of the GNU General Public License as published by
16;; the Free Software Foundation; either version 2, or (at your option) 18;; the Free Software Foundation, either version 3 of the License, or
17;; any later version. 19;; (at your option) any later version.
18 20
19;; This program is distributed in the hope that it will be useful, 21;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details. 24;; GNU General Public License for more details.
23 25
24;; You should have received a copy of the GNU General Public License 26;; You should have received a copy of the GNU General Public License
25;; along with GNU Emacs; see the file COPYING. If not, write to the 27;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27;; Boston, MA 02111-1307, USA.
28 28
29;; Original author: Masanobu UMEDA <umerin(at)mse(dot)kyutech(dot)ac(dot)jp> 29;; Original author: Masanobu UMEDA <umerin(at)mse(dot)kyutech(dot)ac(dot)jp>
30;; Parts of this file was taken from a modified version of the original 30;; Parts of this file was taken from a modified version of the original
@@ -52,7 +52,7 @@
52;; inferior Prolog process. 52;; inferior Prolog process.
53;; 53;;
54;; The code requires the comint, easymenu, info, imenu, and font-lock 54;; The code requires the comint, easymenu, info, imenu, and font-lock
55;; libraries. These are normally distributed with GNU Emacs and 55;; libraries. These are normally distributed with GNU Emacs and
56;; XEmacs. 56;; XEmacs.
57 57
58;;; Installation: 58;;; Installation:
@@ -81,7 +81,7 @@
81;; 81;;
82;; The last s-expression above makes sure that files ending with .pl 82;; The last s-expression above makes sure that files ending with .pl
83;; are assumed to be Prolog files and not Perl, which is the default 83;; are assumed to be Prolog files and not Perl, which is the default
84;; Emacs setting. If this is not wanted, remove this line. It is then 84;; Emacs setting. If this is not wanted, remove this line. It is then
85;; necessary to either 85;; necessary to either
86;; 86;;
87;; o insert in your Prolog files the following comment as the first line: 87;; o insert in your Prolog files the following comment as the first line:
@@ -154,7 +154,7 @@
154;; whitespace. Once more a trivial adaptation of a patch by 154;; whitespace. Once more a trivial adaptation of a patch by
155;; Markus Triska. 155;; Markus Triska.
156;; Version 1.14: 156;; Version 1.14:
157;; o Cleaned up align code. `prolog-align-flag' is eliminated (since 157;; o Cleaned up align code. `prolog-align-flag' is eliminated (since
158;; on a second thought it does not do anything useful). Added key 158;; on a second thought it does not do anything useful). Added key
159;; binding (C-c C-a) and menu entry for alignment. 159;; binding (C-c C-a) and menu entry for alignment.
160;; o Condensed regular expressions for lower and upper case 160;; o Condensed regular expressions for lower and upper case
@@ -205,7 +205,7 @@
205;; by setting the customizable variable `prolog-paren-indent-p' 205;; by setting the customizable variable `prolog-paren-indent-p'
206;; (group "Prolog Indentation") to t. 206;; (group "Prolog Indentation") to t.
207;; o (Somehow awkward) handling of the 0' character escape 207;; o (Somehow awkward) handling of the 0' character escape
208;; sequence. I am looking into a better way of doing it but 208;; sequence. I am looking into a better way of doing it but
209;; prospects look bleak. If this breaks things for you please let 209;; prospects look bleak. If this breaks things for you please let
210;; me know and also set the `prolog-char-quote-workaround' (group 210;; me know and also set the `prolog-char-quote-workaround' (group
211;; "Prolog Other") to nil. 211;; "Prolog Other") to nil.
@@ -240,7 +240,7 @@
240;; a(X). 240;; a(X).
241;; and so is this (and variants): 241;; and so is this (and variants):
242;; a(X) :- b(X), 242;; a(X) :- b(X),
243;; c(X). /* comment here. */ 243;; c(X). /* comment here. */
244;; a(X). 244;; a(X).
245;; Version 1.0: 245;; Version 1.0:
246;; o Revamped the menu system. 246;; o Revamped the menu system.
@@ -358,7 +358,7 @@ The version numbers are of the format (Major . Minor)."
358 358
359;; Indentation 359;; Indentation
360 360
361(defcustom prolog-indent-width tab-width 361(defcustom prolog-indent-width 4
362 "*The indentation width used by the editing buffer." 362 "*The indentation width used by the editing buffer."
363 :group 'prolog-indentation 363 :group 'prolog-indentation
364 :type 'integer) 364 :type 'integer)
@@ -405,7 +405,7 @@ Only used in ( If -> Then ; Else) and ( Disj1 ; Disj2 ) style expressions."
405 "*The parse mode used (decides from which point parsing is done). 405 "*The parse mode used (decides from which point parsing is done).
406Legal values: 406Legal values:
407'beg-of-line - starts parsing at the beginning of a line, unless the 407'beg-of-line - starts parsing at the beginning of a line, unless the
408 previous line ends with a backslash. Fast, but has 408 previous line ends with a backslash. Fast, but has
409 problems detecting multiline /* */ comments. 409 problems detecting multiline /* */ comments.
410'beg-of-clause - starts parsing at the beginning of the current clause. 410'beg-of-clause - starts parsing at the beginning of the current clause.
411 Slow, but copes better with /* */ comments." 411 Slow, but copes better with /* */ comments."
@@ -477,7 +477,7 @@ Legal values:
477 477
478;; Keyboard 478;; Keyboard
479 479
480(defcustom prolog-electric-newline-flag t 480(defcustom prolog-electric-newline-flag (not (fboundp 'electric-indent-mode))
481 "*Non-nil means automatically indent the next line when the user types RET." 481 "*Non-nil means automatically indent the next line when the user types RET."
482 :group 'prolog-keyboard 482 :group 'prolog-keyboard
483 :type 'boolean) 483 :type 'boolean)
@@ -493,7 +493,7 @@ Electric dot appends newline or inserts head of a new clause.
493If dot is pressed at the end of a line where at least one white space 493If dot is pressed at the end of a line where at least one white space
494precedes the point, it inserts a recursive call to the current predicate. 494precedes the point, it inserts a recursive call to the current predicate.
495If dot is pressed at the beginning of an empty line, it inserts the head 495If dot is pressed at the beginning of an empty line, it inserts the head
496of a new clause for the current predicate. It does not apply in strings 496of a new clause for the current predicate. It does not apply in strings
497and comments. 497and comments.
498It does not apply in strings and comments." 498It does not apply in strings and comments."
499 :group 'prolog-keyboard 499 :group 'prolog-keyboard
@@ -501,7 +501,7 @@ It does not apply in strings and comments."
501 501
502(defcustom prolog-electric-dot-full-predicate-template nil 502(defcustom prolog-electric-dot-full-predicate-template nil
503 "*If nil, electric dot inserts only the current predicate's name and `(' 503 "*If nil, electric dot inserts only the current predicate's name and `('
504for recursive calls or new clause heads. Non-nil means to also 504for recursive calls or new clause heads. Non-nil means to also
505insert enough commata to cover the predicate's arity and `)', 505insert enough commata to cover the predicate's arity and `)',
506and dot and newline for recursive calls." 506and dot and newline for recursive calls."
507 :group 'prolog-keyboard 507 :group 'prolog-keyboard
@@ -522,7 +522,7 @@ in ( If -> Then ; Else) and ( Disj1 ; Disj2 ) style expressions."
522 :type 'boolean) 522 :type 'boolean)
523 523
524(defcustom prolog-electric-if-then-else-flag nil 524(defcustom prolog-electric-if-then-else-flag nil
525 "*Non-nil makes `(', `>' and `;' electric 525 "*Non-nil makes `(', `>' and `;' electric
526to automatically indent if-then-else constructs." 526to automatically indent if-then-else constructs."
527 :group 'prolog-keyboard 527 :group 'prolog-keyboard
528 :type 'boolean) 528 :type 'boolean)
@@ -586,7 +586,7 @@ Some parts of the string are replaced:
586`%f' by the name of the consulted file (can be a temporary file) 586`%f' by the name of the consulted file (can be a temporary file)
587`%b' by the file name of the buffer to consult 587`%b' by the file name of the buffer to consult
588`%m' by the module name and name of the consulted file separated by colon 588`%m' by the module name and name of the consulted file separated by colon
589`%l' by the line offset into the file. This is 0 unless consulting a 589`%l' by the line offset into the file. This is 0 unless consulting a
590 region of a buffer, in which case it is the number of lines before 590 region of a buffer, in which case it is the number of lines before
591 the region." 591 the region."
592 :group 'prolog-inferior 592 :group 'prolog-inferior
@@ -606,7 +606,7 @@ Some parts of the string are replaced:
606`%f' by the name of the compiled file (can be a temporary file) 606`%f' by the name of the compiled file (can be a temporary file)
607`%b' by the file name of the buffer to compile 607`%b' by the file name of the buffer to compile
608`%m' by the module name and name of the compiled file separated by colon 608`%m' by the module name and name of the compiled file separated by colon
609`%l' by the line offset into the file. This is 0 unless compiling a 609`%l' by the line offset into the file. This is 0 unless compiling a
610 region of a buffer, in which case it is the number of lines before 610 region of a buffer, in which case it is the number of lines before
611 the region. 611 the region.
612 612
@@ -669,13 +669,13 @@ nil means send actual operating system end of file."
669 669
670(defcustom prolog-use-standard-consult-compile-method-flag t 670(defcustom prolog-use-standard-consult-compile-method-flag t
671 "*Non-nil means use the standard compilation method. 671 "*Non-nil means use the standard compilation method.
672Otherwise the new compilation method will be used. This 672Otherwise the new compilation method will be used. This
673utilises a special compilation buffer with the associated 673utilises a special compilation buffer with the associated
674features such as parsing of error messages and automatically 674features such as parsing of error messages and automatically
675jumping to the source code responsible for the error. 675jumping to the source code responsible for the error.
676 676
677Warning: the new method is so far only experimental and 677Warning: the new method is so far only experimental and
678does contain bugs. The recommended setting for the novice user 678does contain bugs. The recommended setting for the novice user
679is non-nil for this variable." 679is non-nil for this variable."
680 :group 'prolog-inferior 680 :group 'prolog-inferior
681 :type 'boolean) 681 :type 'boolean)
@@ -717,6 +717,7 @@ Relevant only when `prolog-imenu-flag' is non-nil."
717 :type 'boolean) 717 :type 'boolean)
718 718
719(defcustom prolog-char-quote-workaround nil 719(defcustom prolog-char-quote-workaround nil
720 ;; FIXME: Use syntax-propertize-function to fix it right.
720 "*If non-nil, declare 0 as a quote character so that 0'<char> does not break syntax highlighting. 721 "*If non-nil, declare 0 as a quote character so that 0'<char> does not break syntax highlighting.
721This is really kludgy but I have not found any better way of handling it." 722This is really kludgy but I have not found any better way of handling it."
722 :group 'prolog-other 723 :group 'prolog-other
@@ -727,20 +728,39 @@ This is really kludgy but I have not found any better way of handling it."
727;; Internal variables 728;; Internal variables
728;;------------------------------------------------------------------- 729;;-------------------------------------------------------------------
729 730
730(defvar prolog-emacs 731;;(defvar prolog-temp-filename "") ; Later set by `prolog-temporary-file'
731 (if (string-match "XEmacs\\|Lucid" emacs-version)
732 'xemacs
733 'gnuemacs)
734 "The variant of Emacs we're running.
735Valid values are 'gnuemacs and 'xemacs.")
736 732
737(defvar prolog-known-systems '(eclipse mercury sicstus swi gnu)) 733(defvar prolog-mode-syntax-table
734 (let ((table (make-syntax-table)))
735 (if prolog-underscore-wordchar-flag
736 (modify-syntax-entry ?_ "w" table)
737 (modify-syntax-entry ?_ "_" table))
738 738
739;(defvar prolog-temp-filename "") ; Later set by `prolog-temporary-file' 739 (modify-syntax-entry ?+ "." table)
740 (modify-syntax-entry ?- "." table)
741 (modify-syntax-entry ?= "." table)
742 (modify-syntax-entry ?< "." table)
743 (modify-syntax-entry ?> "." table)
744 (modify-syntax-entry ?| "." table)
745 (modify-syntax-entry ?\' "\"" table)
740 746
741(defvar prolog-mode-syntax-table nil) 747 ;; Any better way to handle the 0'<char> construct?!?
748 (when prolog-char-quote-workaround
749 (modify-syntax-entry ?0 "\\" table))
750
751 (modify-syntax-entry ?% "<" table)
752 (modify-syntax-entry ?\n ">" table)
753 (if (featurep 'xemacs)
754 (progn
755 (modify-syntax-entry ?* ". 67" table)
756 (modify-syntax-entry ?/ ". 58" table)
757 )
758 ;; Emacs wants to see this it seems:
759 (modify-syntax-entry ?* ". 23b" table)
760 (modify-syntax-entry ?/ ". 14" table)
761 )
762 table))
742(defvar prolog-mode-abbrev-table nil) 763(defvar prolog-mode-abbrev-table nil)
743(defvar prolog-mode-map nil)
744(defvar prolog-upper-case-string "" 764(defvar prolog-upper-case-string ""
745 "A string containing all upper case characters. 765 "A string containing all upper case characters.
746Set by prolog-build-case-strings.") 766Set by prolog-build-case-strings.")
@@ -820,38 +840,6 @@ VERSION is of the format (Major . Minor)"
820 (<= (cdr version) thisminor))) 840 (<= (cdr version) thisminor)))
821 )) 841 ))
822 842
823(if prolog-mode-syntax-table
824 ()
825 (let ((table (make-syntax-table)))
826 (if prolog-underscore-wordchar-flag
827 (modify-syntax-entry ?_ "w" table)
828 (modify-syntax-entry ?_ "_" table))
829
830 (modify-syntax-entry ?+ "." table)
831 (modify-syntax-entry ?- "." table)
832 (modify-syntax-entry ?= "." table)
833 (modify-syntax-entry ?< "." table)
834 (modify-syntax-entry ?> "." table)
835 (modify-syntax-entry ?| "." table)
836 (modify-syntax-entry ?\' "\"" table)
837
838 ;; Any better way to handle the 0'<char> construct?!?
839 (when prolog-char-quote-workaround
840 (modify-syntax-entry ?0 "\\" table))
841
842 (modify-syntax-entry ?% "<" table)
843 (modify-syntax-entry ?\n ">" table)
844 (if (eq prolog-emacs 'xemacs)
845 (progn
846 (modify-syntax-entry ?* ". 67" table)
847 (modify-syntax-entry ?/ ". 58" table)
848 )
849 ;; Emacs wants to see this it seems:
850 (modify-syntax-entry ?* ". 23b" table)
851 (modify-syntax-entry ?/ ". 14" table)
852 )
853 (setq prolog-mode-syntax-table table)))
854
855(define-abbrev-table 'prolog-mode-abbrev-table ()) 843(define-abbrev-table 'prolog-mode-abbrev-table ())
856 844
857(defun prolog-find-value-by-system (alist) 845(defun prolog-find-value-by-system (alist)
@@ -884,8 +872,6 @@ VERSION is of the format (Major . Minor)"
884 (setq paragraph-separate paragraph-start) 872 (setq paragraph-separate paragraph-start)
885 (make-local-variable 'paragraph-ignore-fill-prefix) 873 (make-local-variable 'paragraph-ignore-fill-prefix)
886 (setq paragraph-ignore-fill-prefix t) 874 (setq paragraph-ignore-fill-prefix t)
887 (make-local-variable 'adaptive-fill-mode)
888 (setq adaptive-fill-mode t)
889 (make-local-variable 'normal-auto-fill-function) 875 (make-local-variable 'normal-auto-fill-function)
890 (setq normal-auto-fill-function 'prolog-do-auto-fill) 876 (setq normal-auto-fill-function 'prolog-do-auto-fill)
891 (make-local-variable 'indent-line-function) 877 (make-local-variable 'indent-line-function)
@@ -903,8 +889,6 @@ VERSION is of the format (Major . Minor)"
903 (make-local-variable 'comment-column) 889 (make-local-variable 'comment-column)
904 (make-local-variable 'comment-indent-function) 890 (make-local-variable 'comment-indent-function)
905 (setq comment-indent-function 'prolog-comment-indent) 891 (setq comment-indent-function 'prolog-comment-indent)
906 (make-local-variable 'comment-indent-function)
907 (setq comment-indent-function 'prolog-comment-indent)
908 (make-local-variable 'parens-require-spaces) 892 (make-local-variable 'parens-require-spaces)
909 (setq parens-require-spaces nil) 893 (setq parens-require-spaces nil)
910 ;; Initialize Prolog system specific variables 894 ;; Initialize Prolog system specific variables
@@ -916,7 +900,7 @@ VERSION is of the format (Major . Minor)"
916 prolog-help-function))) 900 prolog-help-function)))
917 (while vars 901 (while vars
918 (set (intern (concat (symbol-name (car vars)) "-i")) 902 (set (intern (concat (symbol-name (car vars)) "-i"))
919 (prolog-find-value-by-system (eval (car vars)))) 903 (prolog-find-value-by-system (symbol-value (car vars))))
920 (setq vars (cdr vars)))) 904 (setq vars (cdr vars))))
921 (when (null prolog-program-name-i) 905 (when (null prolog-program-name-i)
922 (make-local-variable 'compile-command) 906 (make-local-variable 'compile-command)
@@ -990,35 +974,32 @@ VERSION is of the format (Major . Minor)"
990 (define-key map "\C-c\C-cp" 'prolog-compile-predicate) 974 (define-key map "\C-c\C-cp" 'prolog-compile-predicate)
991 (define-key map "\C-c\C-cr" 'prolog-compile-region) 975 (define-key map "\C-c\C-cr" 'prolog-compile-region)
992 (define-key map "\C-c\C-cb" 'prolog-compile-buffer) 976 (define-key map "\C-c\C-cb" 'prolog-compile-buffer)
993 (define-key map "\C-c\C-cf" 'prolog-compile-file))) 977 (define-key map "\C-c\C-cf" 'prolog-compile-file))
978
979 ;; Inherited from the old prolog.el.
980 (define-key map "\e\C-x" 'prolog-consult-region)
981 (define-key map "\C-c\C-l" 'prolog-consult-file)
982 (define-key map "\C-c\C-z" 'switch-to-prolog))
994 983
995(defun prolog-mode-keybindings-inferior (map) 984(defun prolog-mode-keybindings-inferior (map)
996 "Define keybindings for inferior Prolog mode in MAP." 985 "Define keybindings for inferior Prolog mode in MAP."
997 ;; No inferior mode specific keybindings now. 986 ;; No inferior mode specific keybindings now.
998 ) 987 )
999 988
1000(if prolog-mode-map 989(defvar prolog-mode-map
1001 () 990 (let ((map (make-sparse-keymap)))
1002 (setq prolog-mode-map (make-sparse-keymap)) 991 (prolog-mode-keybindings-common map)
1003 (prolog-mode-keybindings-common prolog-mode-map) 992 (prolog-mode-keybindings-edit map)
1004 (prolog-mode-keybindings-edit prolog-mode-map) 993 map))
1005 ;; System dependent keymaps for system dependent menus
1006 (let ((systems prolog-known-systems))
1007 (while systems
1008 (set (intern (concat "prolog-mode-map-"
1009 (symbol-name (car systems))))
1010 ;(cons 'keymap prolog-mode-map)
1011 prolog-mode-map
1012 )
1013 (setq systems (cdr systems))))
1014 )
1015 994
1016 995
1017(defvar prolog-mode-hook nil 996(defvar prolog-mode-hook nil
1018 "List of functions to call after the prolog mode has initialised.") 997 "List of functions to call after the prolog mode has initialised.")
1019 998
999(unless (fboundp 'prog-mode)
1000 (defalias 'prog-mode 'fundamental-mode))
1020;;;###autoload 1001;;;###autoload
1021(defun prolog-mode (&optional system) 1002(define-derived-mode prolog-mode prog-mode "Prolog"
1022 "Major mode for editing Prolog code. 1003 "Major mode for editing Prolog code.
1023 1004
1024Blank lines and `%%...' separate paragraphs. `%'s starts a comment 1005Blank lines and `%%...' separate paragraphs. `%'s starts a comment
@@ -1033,27 +1014,13 @@ Commands:
1033\\{prolog-mode-map} 1014\\{prolog-mode-map}
1034Entry to this mode calls the value of `prolog-mode-hook' 1015Entry to this mode calls the value of `prolog-mode-hook'
1035if that value is non-nil." 1016if that value is non-nil."
1036 (interactive)
1037 (kill-all-local-variables)
1038 (if system (setq prolog-system system))
1039 (use-local-map
1040 (if prolog-system
1041 ;; ### Looks like it works under XEmacs as well...
1042 ;; (and prolog-system
1043 ;; (not (eq prolog-emacs 'xemacs)))
1044 (eval (intern (concat "prolog-mode-map-" (symbol-name prolog-system))))
1045 prolog-mode-map)
1046 )
1047 (setq major-mode 'prolog-mode)
1048 (setq mode-name (concat "Prolog" 1017 (setq mode-name (concat "Prolog"
1049 (cond 1018 (cond
1050 ((eq prolog-system 'eclipse) "[ECLiPSe]") 1019 ((eq prolog-system 'eclipse) "[ECLiPSe]")
1051 ((eq prolog-system 'mercury) "[Mercury]")
1052 ((eq prolog-system 'sicstus) "[SICStus]") 1020 ((eq prolog-system 'sicstus) "[SICStus]")
1053 ((eq prolog-system 'swi) "[SWI]") 1021 ((eq prolog-system 'swi) "[SWI]")
1054 ((eq prolog-system 'gnu) "[GNU]") 1022 ((eq prolog-system 'gnu) "[GNU]")
1055 (t "")))) 1023 (t ""))))
1056 (set-syntax-table prolog-mode-syntax-table)
1057 (prolog-mode-variables) 1024 (prolog-mode-variables)
1058 (prolog-build-case-strings) 1025 (prolog-build-case-strings)
1059 (prolog-set-atom-regexps) 1026 (prolog-set-atom-regexps)
@@ -1065,27 +1032,34 @@ if that value is non-nil."
1065 (if (and (eq prolog-system 'sicstus) 1032 (if (and (eq prolog-system 'sicstus)
1066 (prolog-atleast-version '(3 . 7)) 1033 (prolog-atleast-version '(3 . 7))
1067 prolog-use-sicstus-sd) 1034 prolog-use-sicstus-sd)
1068 (prolog-enable-sicstus-sd)) 1035 (prolog-enable-sicstus-sd)))
1069 1036
1070 (run-mode-hooks 'prolog-mode-hook)) 1037(defvar mercury-mode-map
1038 (let ((map (make-sparse-keymap)))
1039 (set-keymap-parent map prolog-mode-map)
1040 map))
1071 1041
1072;;;###autoload 1042;;;###autoload
1073(defun mercury-mode () 1043(define-derived-mode mercury-mode prolog-mode "Prolog[Mercury]"
1074 "Major mode for editing Mercury programs. 1044 "Major mode for editing Mercury programs.
1075Actually this is just customized `prolog-mode'." 1045Actually this is just customized `prolog-mode'."
1076 (interactive) 1046 (set (make-local-variable 'prolog-system) 'mercury))
1077 (prolog-mode 'mercury))
1078 1047
1079 1048
1080;;------------------------------------------------------------------- 1049;;-------------------------------------------------------------------
1081;; Inferior prolog mode 1050;; Inferior prolog mode
1082;;------------------------------------------------------------------- 1051;;-------------------------------------------------------------------
1083 1052
1084(defvar prolog-inferior-mode-map nil) 1053(defvar prolog-inferior-mode-map
1054 (let ((map (make-sparse-keymap)))
1055 (prolog-mode-keybindings-common map)
1056 (prolog-mode-keybindings-inferior map)
1057 map))
1058
1085(defvar prolog-inferior-mode-hook nil 1059(defvar prolog-inferior-mode-hook nil
1086 "List of functions to call after the inferior prolog mode has initialised.") 1060 "List of functions to call after the inferior prolog mode has initialised.")
1087 1061
1088(defun prolog-inferior-mode () 1062(define-derived-mode prolog-inferior-mode comint-mode "Inferior Prolog"
1089 "Major mode for interacting with an inferior Prolog process. 1063 "Major mode for interacting with an inferior Prolog process.
1090 1064
1091The following commands are available: 1065The following commands are available:
@@ -1114,26 +1088,11 @@ imitating normal Unix input editing.
1114 1088
1115To find out what version of Prolog mode you are running, enter 1089To find out what version of Prolog mode you are running, enter
1116`\\[prolog-mode-version]'." 1090`\\[prolog-mode-version]'."
1117 (interactive) 1091 (setq comint-input-filter 'prolog-input-filter)
1118 (cond ((not (eq major-mode 'prolog-inferior-mode)) 1092 (setq mode-line-process '(": %s"))
1119 (kill-all-local-variables) 1093 (prolog-mode-variables)
1120 (comint-mode) 1094 (setq comint-prompt-regexp prolog-prompt-regexp-i)
1121 (setq comint-input-filter 'prolog-input-filter) 1095 (set (make-local-variable 'shell-dirstack-query) "pwd."))
1122 (setq major-mode 'prolog-inferior-mode)
1123 (setq mode-name "Inferior Prolog")
1124 (setq mode-line-process '(": %s"))
1125 (prolog-mode-variables)
1126 (if prolog-inferior-mode-map
1127 ()
1128 (setq prolog-inferior-mode-map (copy-keymap comint-mode-map))
1129 (prolog-mode-keybindings-common prolog-inferior-mode-map)
1130 (prolog-mode-keybindings-inferior prolog-inferior-mode-map))
1131 (use-local-map prolog-inferior-mode-map)
1132 (setq comint-prompt-regexp prolog-prompt-regexp-i)
1133 ;(make-variable-buffer-local 'shell-dirstack-query)
1134 (make-local-variable 'shell-dirstack-query)
1135 (setq shell-dirstack-query "pwd.")
1136 (run-hooks 'prolog-inferior-mode-hook))))
1137 1096
1138(defun prolog-input-filter (str) 1097(defun prolog-input-filter (str)
1139 (cond ((string-match "\\`\\s *\\'" str) nil) ;whitespace 1098 (cond ((string-match "\\`\\s *\\'" str) nil) ;whitespace
@@ -1173,8 +1132,7 @@ the variable `prolog-prompt-regexp'."
1173 () 1132 ()
1174 (apply 'make-comint "prolog" prolog-program-name-i nil 1133 (apply 'make-comint "prolog" prolog-program-name-i nil
1175 prolog-program-switches-i) 1134 prolog-program-switches-i)
1176 (save-excursion 1135 (with-current-buffer "*prolog*"
1177 (set-buffer "*prolog*")
1178 (prolog-inferior-mode) 1136 (prolog-inferior-mode)
1179 (if wait 1137 (if wait
1180 (progn 1138 (progn
@@ -1190,19 +1148,15 @@ the variable `prolog-prompt-regexp'."
1190(defun prolog-process-insert-string (process string) 1148(defun prolog-process-insert-string (process string)
1191 "Insert STRING into inferior Prolog buffer running PROCESS." 1149 "Insert STRING into inferior Prolog buffer running PROCESS."
1192 ;; Copied from elisp manual, greek to me 1150 ;; Copied from elisp manual, greek to me
1193 (let ((buf (current-buffer))) 1151 (with-current-buffer (process-buffer process)
1194 (unwind-protect 1152 ;; FIXME: Use window-point-insertion-type instead.
1195 (let (moving) 1153 (let ((moving (= (point) (process-mark process))))
1196 (set-buffer (process-buffer process)) 1154 (save-excursion
1197 (setq moving (= (point) (process-mark process))) 1155 ;; Insert the text, moving the process-marker.
1198 (save-excursion 1156 (goto-char (process-mark process))
1199 ;; Insert the text, moving the process-marker. 1157 (insert string)
1200 (goto-char (process-mark process)) 1158 (set-marker (process-mark process) (point)))
1201 (insert string) 1159 (if moving (goto-char (process-mark process))))))
1202 (set-marker (process-mark process) (point)))
1203 (if moving (goto-char (process-mark process))))
1204 (set-buffer buf))))
1205
1206 1160
1207;;------------------------------------------------------------ 1161;;------------------------------------------------------------
1208;; Old consulting and compiling functions 1162;; Old consulting and compiling functions
@@ -1416,8 +1370,7 @@ This function must be called from the source code buffer."
1416 real-file first-line)) 1370 real-file first-line))
1417 (process (get-process "prolog")) 1371 (process (get-process "prolog"))
1418 (old-filter (process-filter process))) 1372 (old-filter (process-filter process)))
1419 (save-excursion 1373 (with-current-buffer buffer
1420 (set-buffer buffer)
1421 (delete-region (point-min) (point-max)) 1374 (delete-region (point-min) (point-max))
1422 (compilation-mode) 1375 (compilation-mode)
1423 ;; Setting up font-locking for this buffer 1376 ;; Setting up font-locking for this buffer
@@ -1441,8 +1394,7 @@ This function must be called from the source code buffer."
1441 file buffer-file-name) 1394 file buffer-file-name)
1442 nil 1395 nil
1443 real-file)) 1396 real-file))
1444 (save-excursion 1397 (with-current-buffer buffer
1445 (set-buffer buffer)
1446 (goto-char (point-max)) 1398 (goto-char (point-max))
1447 (set-process-filter process 'prolog-consult-compile-filter) 1399 (set-process-filter process 'prolog-consult-compile-filter)
1448 (process-send-string "prolog" command-string) 1400 (process-send-string "prolog" command-string)
@@ -1533,7 +1485,7 @@ Argument OUTPUT is a name of the output file."
1533 (eq outputtype 'trace)) 1485 (eq outputtype 'trace))
1534 (let (input) 1486 (let (input)
1535 (setq input (concat (read-string output) "\n")) 1487 (setq input (concat (read-string output) "\n"))
1536 (process-send-string "prolog" input) 1488 (process-send-string process input)
1537 (setq output (concat output input)))) 1489 (setq output (concat output input))))
1538 1490
1539 ((eq prolog-system 'sicstus) 1491 ((eq prolog-system 'sicstus)
@@ -2352,79 +2304,79 @@ whitespace characters, parentheses, or then/else branches."
2352;;;; Comment filling 2304;;;; Comment filling
2353 2305
2354(defun prolog-comment-limits () 2306(defun prolog-comment-limits ()
2355 "Returns the current comment limits plus the comment type (block or line). 2307 "Return the current comment limits plus the comment type (block or line).
2356The comment limits are the range of a block comment or the range that 2308The comment limits are the range of a block comment or the range that
2357contains all adjacent line comments (i.e. all comments that starts in 2309contains all adjacent line comments (i.e. all comments that starts in
2358the same column with no empty lines or non-whitespace characters 2310the same column with no empty lines or non-whitespace characters
2359between them)." 2311between them)."
2360(let ((here (point)) 2312 (let ((here (point))
2361 lit-limits-b lit-limits-e lit-type beg end 2313 lit-limits-b lit-limits-e lit-type beg end
2362 ) 2314 )
2363 (save-restriction 2315 (save-restriction
2364 ;; Widen to catch comment limits correctly. 2316 ;; Widen to catch comment limits correctly.
2365 (widen) 2317 (widen)
2366 (setq end (save-excursion (end-of-line) (point)) 2318 (setq end (save-excursion (end-of-line) (point))
2367 beg (save-excursion (beginning-of-line) (point))) 2319 beg (save-excursion (beginning-of-line) (point)))
2368 (save-excursion 2320 (save-excursion
2369 (beginning-of-line) 2321 (beginning-of-line)
2370 (setq lit-type (if (search-forward-regexp "%" end t) 'line 'block)) 2322 (setq lit-type (if (search-forward-regexp "%" end t) 'line 'block))
2371 ; (setq lit-type 'line) 2323 ; (setq lit-type 'line)
2372 ;(if (search-forward-regexp "^[ \t]*%" end t) 2324 ;(if (search-forward-regexp "^[ \t]*%" end t)
2373 ; (setq lit-type 'line) 2325 ; (setq lit-type 'line)
2374 ; (if (not (search-forward-regexp "%" end t)) 2326 ; (if (not (search-forward-regexp "%" end t))
2375 ; (setq lit-type 'block) 2327 ; (setq lit-type 'block)
2376 ; (if (not (= (forward-line 1) 0)) 2328 ; (if (not (= (forward-line 1) 0))
2377 ; (setq lit-type 'block) 2329 ; (setq lit-type 'block)
2378 ; (setq done t 2330 ; (setq done t
2379 ; ret (prolog-comment-limits))) 2331 ; ret (prolog-comment-limits)))
2380 ; )) 2332 ; ))
2381 (if (eq lit-type 'block) 2333 (if (eq lit-type 'block)
2382 (progn 2334 (progn
2383 (goto-char here) 2335 (goto-char here)
2384 (when (looking-at "/\\*") (forward-char 2)) 2336 (when (looking-at "/\\*") (forward-char 2))
2385 (when (and (looking-at "\\*") (> (point) (point-min)) 2337 (when (and (looking-at "\\*") (> (point) (point-min))
2386 (forward-char -1) (looking-at "/")) 2338 (forward-char -1) (looking-at "/"))
2387 (forward-char 1)) 2339 (forward-char 1))
2388 (when (save-excursion (search-backward "/*" nil t)) 2340 (when (save-excursion (search-backward "/*" nil t))
2389 (list (save-excursion (search-backward "/*") (point)) 2341 (list (save-excursion (search-backward "/*") (point))
2390 (or (search-forward "*/" nil t) (point-max)) lit-type))) 2342 (or (search-forward "*/" nil t) (point-max)) lit-type)))
2391 ;; line comment 2343 ;; line comment
2392 (setq lit-limits-b (- (point) 1) 2344 (setq lit-limits-b (- (point) 1)
2393 lit-limits-e end) 2345 lit-limits-e end)
2394 (condition-case nil 2346 (condition-case nil
2395 (if (progn (goto-char lit-limits-b) 2347 (if (progn (goto-char lit-limits-b)
2396 (looking-at "%")) 2348 (looking-at "%"))
2397 (let ((col (current-column)) done) 2349 (let ((col (current-column)) done)
2398 (setq beg (point) 2350 (setq beg (point)
2399 end lit-limits-e) 2351 end lit-limits-e)
2400 ;; Always at the beginning of the comment 2352 ;; Always at the beginning of the comment
2401 ;; Go backward now 2353 ;; Go backward now
2402 (beginning-of-line) 2354 (beginning-of-line)
2403 (while (and (zerop (setq done (forward-line -1))) 2355 (while (and (zerop (setq done (forward-line -1)))
2404 (search-forward-regexp "^[ \t]*%" (save-excursion (end-of-line) (point)) t) 2356 (search-forward-regexp "^[ \t]*%" (save-excursion (end-of-line) (point)) t)
2405 (= (+ 1 col) (current-column))) 2357 (= (+ 1 col) (current-column)))
2406 (setq beg (- (point) 1))) 2358 (setq beg (- (point) 1)))
2407 (when (= done 0) 2359 (when (= done 0)
2408 (forward-line 1)) 2360 (forward-line 1))
2409 ;; We may have a line with code above... 2361 ;; We may have a line with code above...
2410 (when (and (zerop (setq done (forward-line -1))) 2362 (when (and (zerop (setq done (forward-line -1)))
2411 (search-forward "%" (save-excursion (end-of-line) (point)) t) 2363 (search-forward "%" (save-excursion (end-of-line) (point)) t)
2412 (= (+ 1 col) (current-column))) 2364 (= (+ 1 col) (current-column)))
2413 (setq beg (- (point) 1))) 2365 (setq beg (- (point) 1)))
2414 (when (= done 0) 2366 (when (= done 0)
2415 (forward-line 1)) 2367 (forward-line 1))
2416 ;; Go forward 2368 ;; Go forward
2417 (goto-char lit-limits-b) 2369 (goto-char lit-limits-b)
2418 (beginning-of-line) 2370 (beginning-of-line)
2419 (while (and (zerop (forward-line 1)) 2371 (while (and (zerop (forward-line 1))
2420 (search-forward-regexp "^[ \t]*%" (save-excursion (end-of-line) (point)) t) 2372 (search-forward-regexp "^[ \t]*%" (save-excursion (end-of-line) (point)) t)
2421 (= (+ 1 col) (current-column))) 2373 (= (+ 1 col) (current-column)))
2422 (setq end (save-excursion (end-of-line) (point)))) 2374 (setq end (save-excursion (end-of-line) (point))))
2423 (list beg end lit-type)) 2375 (list beg end lit-type))
2424 (list lit-limits-b lit-limits-e lit-type) 2376 (list lit-limits-b lit-limits-e lit-type)
2425 ) 2377 )
2426 (error (list lit-limits-b lit-limits-e lit-type)))) 2378 (error (list lit-limits-b lit-limits-e lit-type))))
2427 )))) 2379 ))))
2428 2380
2429(defun prolog-guess-fill-prefix () 2381(defun prolog-guess-fill-prefix ()
2430 ;; fill 'txt entities? 2382 ;; fill 'txt entities?
@@ -2434,7 +2386,7 @@ between them)."
2434 (let* ((bounds (prolog-comment-limits)) 2386 (let* ((bounds (prolog-comment-limits))
2435 (cbeg (car bounds)) 2387 (cbeg (car bounds))
2436 (type (nth 2 bounds)) 2388 (type (nth 2 bounds))
2437 beg end str) 2389 beg end)
2438 (save-excursion 2390 (save-excursion
2439 (end-of-line) 2391 (end-of-line)
2440 (setq end (point)) 2392 (setq end (point))
@@ -2442,20 +2394,20 @@ between them)."
2442 (setq beg (point)) 2394 (setq beg (point))
2443 (if (and (eq type 'line) 2395 (if (and (eq type 'line)
2444 (> cbeg beg) 2396 (> cbeg beg)
2445 (save-excursion (not (search-forward-regexp "^[ \t]*%" cbeg t)))) 2397 (save-excursion (not (search-forward-regexp "^[ \t]*%"
2398 cbeg t))))
2446 (progn 2399 (progn
2447 (goto-char cbeg) 2400 (goto-char cbeg)
2448 (search-forward-regexp "%+[ \t]*" end t) 2401 (search-forward-regexp "%+[ \t]*" end t)
2449 (setq str (replace-in-string (buffer-substring beg (point)) "[^ \t%]" " ")) 2402 (prolog-replace-in-string (buffer-substring beg (point))
2450 ) 2403 "[^ \t%]" " "))
2451 ;(goto-char beg) 2404 ;(goto-char beg)
2452 (if (search-forward-regexp "^[ \t]*\\(%+\\|\\*+\\|/\\*+\\)[ \t]*" end t) 2405 (if (search-forward-regexp "^[ \t]*\\(%+\\|\\*+\\|/\\*+\\)[ \t]*"
2453 (setq str (replace-in-string (buffer-substring beg (point)) "/" " ")) 2406 end t)
2407 (prolog-replace-in-string (buffer-substring beg (point)) "/" " ")
2454 (beginning-of-line) 2408 (beginning-of-line)
2455 (when (search-forward-regexp "^[ \t]+" end t) 2409 (when (search-forward-regexp "^[ \t]+" end t)
2456 (setq str (buffer-substring beg (point))))) 2410 (buffer-substring beg (point)))))))))
2457 ))
2458 str)))
2459 2411
2460(defun prolog-fill-paragraph () 2412(defun prolog-fill-paragraph ()
2461 "Fill paragraph comment at or after point." 2413 "Fill paragraph comment at or after point."
@@ -2486,45 +2438,17 @@ between them)."
2486 2438
2487(defun prolog-do-auto-fill () 2439(defun prolog-do-auto-fill ()
2488 "Carry out Auto Fill for Prolog mode. 2440 "Carry out Auto Fill for Prolog mode.
2489In effect it sets the fill-prefix when inside comments and then calls 2441In effect it sets the `fill-prefix' when inside comments and then calls
2490`do-auto-fill'." 2442`do-auto-fill'."
2491 (let ((fill-prefix (prolog-guess-fill-prefix))) 2443 (let ((fill-prefix (prolog-guess-fill-prefix)))
2492 (do-auto-fill) 2444 (do-auto-fill)
2493 )) 2445 ))
2494 2446
2495(unless (fboundp 'replace-in-string) 2447(defalias 'prolog-replace-in-string
2496 (defun replace-in-string (str regexp newtext &optional literal) 2448 (if (fboundp 'replace-in-string)
2497 "Replace all matches in STR for REGEXP with NEWTEXT string, 2449 #'replace-in-string
2498 and returns the new string. 2450 (lambda (str regexp newtext &optional literal)
2499Optional LITERAL non-nil means do a literal replacement. 2451 (replace-regexp-in-string regexp newtext str nil literal))))
2500Otherwise treat `\\' in NEWTEXT as special:
2501 `\\&' in NEWTEXT means substitute original matched text.
2502 `\\N' means substitute what matched the Nth `\\(...\\)'.
2503 If Nth parens didn't match, substitute nothing.
2504 `\\\\' means insert one `\\'.
2505 `\\u' means upcase the next character.
2506 `\\l' means downcase the next character.
2507 `\\U' means begin upcasing all following characters.
2508 `\\L' means begin downcasing all following characters.
2509 `\\E' means terminate the effect of any `\\U' or `\\L'."
2510 (if (> (length str) 50)
2511 (let ((cfs case-fold-search))
2512 (with-temp-buffer
2513 (setq case-fold-search cfs)
2514 (insert str)
2515 (goto-char 1)
2516 (while (re-search-forward regexp nil t)
2517 (replace-match newtext t literal))
2518 (buffer-string)))
2519 (let ((start 0) newstr)
2520 (while (string-match regexp str start)
2521 (setq newstr (replace-match newtext t literal str)
2522 start (+ (match-end 0) (- (length newstr) (length str)))
2523 str newstr))
2524 str)))
2525 )
2526
2527
2528 2452
2529;;------------------------------------------------------------------- 2453;;-------------------------------------------------------------------
2530;; The tokenizer 2454;; The tokenizer
@@ -2546,7 +2470,7 @@ Otherwise treat `\\' in NEWTEXT as special:
2546 2470
2547(defun prolog-tokenize (beg end &optional stopcond) 2471(defun prolog-tokenize (beg end &optional stopcond)
2548 "Tokenize a region of prolog code between BEG and END. 2472 "Tokenize a region of prolog code between BEG and END.
2549STOPCOND decides the stop condition of the parsing. Valid values 2473STOPCOND decides the stop condition of the parsing. Valid values
2550are 'zerodepth which stops the parsing at the first right parenthesis 2474are 'zerodepth which stops the parsing at the first right parenthesis
2551where the parenthesis depth is zero, 'skipover which skips over 2475where the parenthesis depth is zero, 'skipover which skips over
2552the current entity (e.g. a list, a string, etc.) and nil. 2476the current entity (e.g. a list, a string, etc.) and nil.
@@ -2760,10 +2684,9 @@ The rest of the elements are undefined."
2760 (pop-to-buffer buffer))) 2684 (pop-to-buffer buffer)))
2761 2685
2762(defun prolog-Info-follow-nearest-node () 2686(defun prolog-Info-follow-nearest-node ()
2763 (if (eq prolog-emacs 'xemacs) 2687 (if (featurep 'xemacs)
2764 (Info-follow-nearest-node (point)) 2688 (Info-follow-nearest-node (point))
2765 (Info-follow-nearest-node)) 2689 (Info-follow-nearest-node)))
2766)
2767 2690
2768(defun prolog-help-online (predicate) 2691(defun prolog-help-online (predicate)
2769 (prolog-ensure-process) 2692 (prolog-ensure-process)
@@ -2985,7 +2908,7 @@ and end of list building."
2985(defun prolog-enable-sicstus-sd () 2908(defun prolog-enable-sicstus-sd ()
2986 "Enable the source level debugging facilities of SICStus 3.7 and later." 2909 "Enable the source level debugging facilities of SICStus 3.7 and later."
2987 (interactive) 2910 (interactive)
2988 (require 'pltrace) ; Load the SICStus debugger code 2911 (require 'pltrace) ; Load the SICStus debugger code
2989 ;; Turn on the source level debugging by default 2912 ;; Turn on the source level debugging by default
2990 (add-hook 'prolog-inferior-mode-hook 'pltrace-on) 2913 (add-hook 'prolog-inferior-mode-hook 'pltrace-on)
2991 (if (not prolog-use-sicstus-sd) 2914 (if (not prolog-use-sicstus-sd)
@@ -2995,8 +2918,7 @@ and end of list building."
2995 ;; Avoid compilation warnings by using eval 2918 ;; Avoid compilation warnings by using eval
2996 (eval '(pltrace-on))) 2919 (eval '(pltrace-on)))
2997 (setq prolog-use-sicstus-sd t) 2920 (setq prolog-use-sicstus-sd t)
2998 )) 2921 )))
2999 )
3000 2922
3001(defun prolog-disable-sicstus-sd () 2923(defun prolog-disable-sicstus-sd ()
3002 "Disable the source level debugging facilities of SICStus 3.7 and later." 2924 "Disable the source level debugging facilities of SICStus 3.7 and later."
@@ -3238,6 +3160,7 @@ objects (relevent only if 'prolog-system' is set to 'sicstus)."
3238 (let ((case-fold-search nil)) 3160 (let ((case-fold-search nil))
3239 (re-search-backward 3161 (re-search-backward
3240 ;; (format "^[%s$']" prolog-lower-case-string) 3162 ;; (format "^[%s$']" prolog-lower-case-string)
3163 ;; FIXME: Use [:lower:]
3241 (format "^\\([%s$']\\|[:?]-\\)" prolog-lower-case-string) 3164 (format "^\\([%s$']\\|[:?]-\\)" prolog-lower-case-string)
3242 nil t))) 3165 nil t)))
3243 (let ((bal (prolog-paren-balance))) 3166 (let ((bal (prolog-paren-balance)))
@@ -3488,10 +3411,12 @@ The module name should be written manually just before the semi-colon."
3488 (insert "%%% -*- Module: ; -*-\n") 3411 (insert "%%% -*- Module: ; -*-\n")
3489 (backward-char 6)) 3412 (backward-char 6))
3490 3413
3491(defun prolog-uncomment-region (beg end) 3414(defalias 'prolog-uncomment-region
3492 "Uncomment the region between BEG and END." 3415 (if (fboundp 'uncomment-region) #'uncomment-region
3493 (interactive "r") 3416 (lambda (beg end)
3494 (comment-region beg end -1)) 3417 "Uncomment the region between BEG and END."
3418 (interactive "r")
3419 (comment-region beg end -1))))
3495 3420
3496(defun prolog-goto-comment-column (&optional nocreate) 3421(defun prolog-goto-comment-column (&optional nocreate)
3497 "Move comments on the current line to the correct position. 3422 "Move comments on the current line to the correct position.
@@ -3573,35 +3498,37 @@ Bound to the >, ; and ( keys."
3573 (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren))) 3498 (if prolog-electric-if-then-else-flag (prolog-insert-spaces-after-paren)))
3574 3499
3575(defun prolog-electric-colon (arg) 3500(defun prolog-electric-colon (arg)
3576 "If `prolog-electric-colon-flag' is non-nil, insert the electric `:' construct, 3501 "If `prolog-electric-colon-flag' is non-nil, insert the electric `:' construct.
3577that is, space (if appropriate), `:-' and newline if colon is pressed 3502That is, insert space (if appropriate), `:-' and newline if colon is pressed
3578at the end of a line that starts in the first column (i.e., clause 3503at the end of a line that starts in the first column (i.e., clause
3579heads)." 3504heads)."
3580 (interactive "P") 3505 (interactive "P")
3581 (if (and prolog-electric-colon-flag 3506 (if (and prolog-electric-colon-flag
3582 (null arg) 3507 (null arg)
3583 (= (point) (line-end-position)) 3508 (eolp)
3584 ;(not (string-match "^\\s " (thing-at-point 'line)))) 3509 ;(not (string-match "^\\s " (thing-at-point 'line))))
3585 (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line)))) 3510 (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line))))
3586 (progn 3511 (progn
3587 (unless (save-excursion (backward-char 1) (looking-at "\\s ")) (insert " ")) 3512 (unless (save-excursion (backward-char 1) (looking-at "\\s "))
3513 (insert " "))
3588 (insert ":-\n") 3514 (insert ":-\n")
3589 (prolog-indent-line)) 3515 (prolog-indent-line))
3590 (self-insert-command (prefix-numeric-value arg)))) 3516 (self-insert-command (prefix-numeric-value arg))))
3591 3517
3592(defun prolog-electric-dash (arg) 3518(defun prolog-electric-dash (arg)
3593 "If `prolog-electric-dash-flag' is non-nil, insert the electric `-' construct, 3519 "If `prolog-electric-dash-flag' is non-nil, insert the electric `-' construct.
3594that is, space (if appropriate), `-->' and newline if dash is pressed 3520that is, insert space (if appropriate), `-->' and newline if dash is pressed
3595at the end of a line that starts in the first column (i.e., DCG 3521at the end of a line that starts in the first column (i.e., DCG
3596heads)." 3522heads)."
3597 (interactive "P") 3523 (interactive "P")
3598 (if (and prolog-electric-dash-flag 3524 (if (and prolog-electric-dash-flag
3599 (null arg) 3525 (null arg)
3600 (= (point) (line-end-position)) 3526 (eolp)
3601 ;(not (string-match "^\\s " (thing-at-point 'line)))) 3527 ;(not (string-match "^\\s " (thing-at-point 'line))))
3602 (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line)))) 3528 (not (string-match "^\\(\\s \\|%\\)" (thing-at-point 'line))))
3603 (progn 3529 (progn
3604 (unless (save-excursion (backward-char 1) (looking-at "\\s ")) (insert " ")) 3530 (unless (save-excursion (backward-char 1) (looking-at "\\s "))
3531 (insert " "))
3605 (insert "-->\n") 3532 (insert "-->\n")
3606 (prolog-indent-line)) 3533 (prolog-indent-line))
3607 (self-insert-command (prefix-numeric-value arg)))) 3534 (self-insert-command (prefix-numeric-value arg))))
@@ -3638,13 +3565,13 @@ When called with prefix argument ARG, insert just dot."
3638 (re-search-backward 3565 (re-search-backward
3639 ;; "\\(^\\|[])}a-zA-Z]+\\)[ \t]*\\=" nil t))) 3566 ;; "\\(^\\|[])}a-zA-Z]+\\)[ \t]*\\=" nil t)))
3640 (format "\\(^\\|[])}%s]+\\)[ \t]*\\=" 3567 (format "\\(^\\|[])}%s]+\\)[ \t]*\\="
3641 prolog-lower-case-string) 3568 prolog-lower-case-string) ;FIXME: [:lower:]
3642 nil t)) 3569 nil t))
3643 (save-excursion 3570 (save-excursion
3644 (re-search-backward 3571 (re-search-backward
3645 ;; "\\(^\\|[])}a-zA-Z]+\\)[ \t]*\\=" nil t))) 3572 ;; "\\(^\\|[])}a-zA-Z]+\\)[ \t]*\\=" nil t)))
3646 (format "\\(^\\|[])}%s]+\\)[ \t]*\\=" 3573 (format "\\(^\\|[])}%s]+\\)[ \t]*\\="
3647 prolog-upper-case-string) 3574 prolog-upper-case-string) ;FIXME: [:upper:]
3648 nil t)) 3575 nil t))
3649 ) 3576 )
3650 ) 3577 )
@@ -3686,7 +3613,8 @@ If the point is not on a variable then insert underscore."
3686 ;; ###### 3613 ;; ######
3687 ;;(skip-chars-backward "a-zA-Z_") 3614 ;;(skip-chars-backward "a-zA-Z_")
3688 (skip-chars-backward 3615 (skip-chars-backward
3689 (format "%s%s_" 3616 (format "%s%s_"
3617 ;; FIXME: Why not "a-zA-Z"?
3690 prolog-lower-case-string 3618 prolog-lower-case-string
3691 prolog-upper-case-string)) 3619 prolog-upper-case-string))
3692 3620
@@ -3695,6 +3623,7 @@ If the point is not on a variable then insert underscore."
3695 ;; ###### 3623 ;; ######
3696 ;; (looking-at "\\<[_A-Z][a-zA-Z_0-9]*\\>")) 3624 ;; (looking-at "\\<[_A-Z][a-zA-Z_0-9]*\\>"))
3697 (looking-at (format "\\<[_%s][%s%s_0-9]*\\>" 3625 (looking-at (format "\\<[_%s][%s%s_0-9]*\\>"
3626 ;; FIXME: Use [:upper:] and friends.
3698 prolog-upper-case-string 3627 prolog-upper-case-string
3699 prolog-lower-case-string 3628 prolog-lower-case-string
3700 prolog-upper-case-string))) 3629 prolog-upper-case-string)))
@@ -3711,7 +3640,7 @@ If the point is not on a variable then insert underscore."
3711 3640
3712(defun prolog-find-term (functor arity &optional prefix) 3641(defun prolog-find-term (functor arity &optional prefix)
3713 "Go to the position at the start of the next occurance of a term. 3642 "Go to the position at the start of the next occurance of a term.
3714The term is specified with FUNCTOR and ARITY. The optional argument 3643The term is specified with FUNCTOR and ARITY. The optional argument
3715PREFIX is the prefix of the search regexp." 3644PREFIX is the prefix of the search regexp."
3716 (let* (;; If prefix is not set then use the default "\\<" 3645 (let* (;; If prefix is not set then use the default "\\<"
3717 (prefix (if (not prefix) 3646 (prefix (if (not prefix)
@@ -3759,6 +3688,7 @@ PREFIX is the prefix of the search regexp."
3759Must be called after `prolog-build-case-strings'." 3688Must be called after `prolog-build-case-strings'."
3760 (setq prolog-atom-char-regexp 3689 (setq prolog-atom-char-regexp
3761 (format "[%s%s0-9_$]" 3690 (format "[%s%s0-9_$]"
3691 ;; FIXME: why not a-zA-Z?
3762 prolog-lower-case-string 3692 prolog-lower-case-string
3763 prolog-upper-case-string)) 3693 prolog-upper-case-string))
3764 (setq prolog-atom-regexp 3694 (setq prolog-atom-regexp
@@ -3778,20 +3708,20 @@ Uses the current case-table for extracting the relevant information."
3778 ;; `map-char-table' causes problems under Emacs 23.0.0.1, the 3708 ;; `map-char-table' causes problems under Emacs 23.0.0.1, the
3779 ;; while loop seems to do its job well (Ryszard Szopa) 3709 ;; while loop seems to do its job well (Ryszard Szopa)
3780 ;; 3710 ;;
3781 ;;(if (and (not (eq prolog-emacs 'xemacs)) 3711 ;;(if (and (not (featurep 'xemacs))
3782 ;; (fboundp 'map-char-table)) 3712 ;; (fboundp 'map-char-table))
3783 ;; (map-char-table 3713 ;; (map-char-table
3784 ;; (lambda (key value) 3714 ;; (lambda (key value)
3785 ;; (cond 3715 ;; (cond
3786 ;; ((and 3716 ;; ((and
3787 ;; (eq (int-to-char key) (downcase key)) 3717 ;; (eq (prolog-int-to-char key) (downcase key))
3788 ;; (eq (int-to-char key) (upcase key))) 3718 ;; (eq (prolog-int-to-char key) (upcase key)))
3789 ;; ;; Do nothing if upper and lower case are the same 3719 ;; ;; Do nothing if upper and lower case are the same
3790 ;; ) 3720 ;; )
3791 ;; ((eq (int-to-char key) (downcase key)) 3721 ;; ((eq (prolog-int-to-char key) (downcase key))
3792 ;; ;; The char is lower case 3722 ;; ;; The char is lower case
3793 ;; (setq low_string (format "%s%c" low_string key))) 3723 ;; (setq low_string (format "%s%c" low_string key)))
3794 ;; ((eq (int-to-char key) (upcase key)) 3724 ;; ((eq (prolog-int-to-char key) (upcase key))
3795 ;; ;; The char is upper case 3725 ;; ;; The char is upper case
3796 ;; (setq up_string (format "%s%c" up_string key))) 3726 ;; (setq up_string (format "%s%c" up_string key)))
3797 ;; )) 3727 ;; ))
@@ -3801,14 +3731,14 @@ Uses the current case-table for extracting the relevant information."
3801 (while (< key 256) 3731 (while (< key 256)
3802 (cond 3732 (cond
3803 ((and 3733 ((and
3804 (eq (int-to-char key) (downcase key)) 3734 (eq (prolog-int-to-char key) (downcase key))
3805 (eq (int-to-char key) (upcase key))) 3735 (eq (prolog-int-to-char key) (upcase key)))
3806 ;; Do nothing if upper and lower case are the same 3736 ;; Do nothing if upper and lower case are the same
3807 ) 3737 )
3808 ((eq (int-to-char key) (downcase key)) 3738 ((eq (prolog-int-to-char key) (downcase key))
3809 ;; The char is lower case 3739 ;; The char is lower case
3810 (setq low_string (format "%s%c" low_string key))) 3740 (setq low_string (format "%s%c" low_string key)))
3811 ((eq (int-to-char key) (upcase key)) 3741 ((eq (prolog-int-to-char key) (upcase key))
3812 ;; The char is upper case 3742 ;; The char is upper case
3813 (setq up_string (format "%s%c" up_string key))) 3743 (setq up_string (format "%s%c" up_string key)))
3814 ) 3744 )
@@ -3820,7 +3750,7 @@ Uses the current case-table for extracting the relevant information."
3820 )) 3750 ))
3821 3751
3822;(defun prolog-regexp-dash-continuous-chars (chars) 3752;(defun prolog-regexp-dash-continuous-chars (chars)
3823; (let ((ints (mapcar #'char-to-int (string-to-list chars))) 3753; (let ((ints (mapcar #'prolog-char-to-int (string-to-list chars)))
3824; (beg 0) 3754; (beg 0)
3825; (end 0)) 3755; (end 0))
3826; (if (null ints) 3756; (if (null ints)
@@ -3860,7 +3790,7 @@ Uses the current case-table for extracting the relevant information."
3860 3790
3861(defun prolog-dash-letters (string) 3791(defun prolog-dash-letters (string)
3862 "Return a condensed regexp covering all letters in STRING." 3792 "Return a condensed regexp covering all letters in STRING."
3863 (let ((intervals (prolog-ints-intervals (mapcar #'char-to-int 3793 (let ((intervals (prolog-ints-intervals (mapcar #'prolog-char-to-int
3864 (string-to-list string)))) 3794 (string-to-list string))))
3865 codes) 3795 codes)
3866 (while intervals 3796 (while intervals
@@ -3884,16 +3814,11 @@ Uses the current case-table for extracting the relevant information."
3884 3814
3885;; GNU Emacs compatibility: GNU Emacs does not differentiate between 3815;; GNU Emacs compatibility: GNU Emacs does not differentiate between
3886;; ints and chars, or at least these two are interchangeable. 3816;; ints and chars, or at least these two are interchangeable.
3887(or (fboundp 'int-to-char) 3817(defalias 'prolog-int-to-char
3888 ;; Introduced in Emacs 19.29. 3818 (if (fboundp 'int-to-char) #'int-to-char #'identity))
3889 (defun int-to-char (num)
3890 num))
3891
3892(or (fboundp 'char-to-int)
3893 ;; Introduced in Emacs 19.29.
3894 (defun char-to-int (num)
3895 num))
3896 3819
3820(defalias 'prolog-char-to-int
3821 (if (fboundp 'char-to-int) #'char-to-int #'identity))
3897 3822
3898;;------------------------------------------------------------------- 3823;;-------------------------------------------------------------------
3899;; Menu stuff (both for the editing buffer and for the inferior 3824;; Menu stuff (both for the editing buffer and for the inferior
@@ -3906,7 +3831,7 @@ Uses the current case-table for extracting the relevant information."
3906 (mark))) 3831 (mark)))
3907 3832
3908(defun prolog-menu () 3833(defun prolog-menu ()
3909 "Creates the menus for the Prolog editing buffers. 3834 "Create the menus for the Prolog editing buffers.
3910These menus are dynamically created because one may change systems 3835These menus are dynamically created because one may change systems
3911during the life of an Emacs session, and because GNU Emacs wants them 3836during the life of an Emacs session, and because GNU Emacs wants them
3912so by ignoring `easy-menu-add'." 3837so by ignoring `easy-menu-add'."
@@ -3918,7 +3843,7 @@ so by ignoring `easy-menu-add'."
3918 prolog-edit-menu-help (current-local-map) 3843 prolog-edit-menu-help (current-local-map)
3919 "Help menu for the Prolog mode." 3844 "Help menu for the Prolog mode."
3920 (append 3845 (append
3921 (if (eq prolog-emacs 'xemacs) '("Help") '("Prolog-help")) 3846 (if (featurep 'xemacs) '("Help") '("Prolog-help"))
3922 (cond 3847 (cond
3923 ((eq prolog-system 'sicstus) 3848 ((eq prolog-system 'sicstus)
3924 '(["On predicate" prolog-help-on-predicate t] 3849 '(["On predicate" prolog-help-on-predicate t]
@@ -3983,7 +3908,7 @@ so by ignoring `easy-menu-add'."
3983 ;; default (mercury) nil 3908 ;; default (mercury) nil
3984 ) 3909 )
3985 (list "---" 3910 (list "---"
3986 (if (eq prolog-emacs 'xemacs) 3911 (if (featurep 'xemacs)
3987 [(concat "Run " (cond ((eq prolog-system 'eclipse) "ECLiPSe") 3912 [(concat "Run " (cond ((eq prolog-system 'eclipse) "ECLiPSe")
3988 ((eq prolog-system 'mercury) "Mercury") 3913 ((eq prolog-system 'mercury) "Mercury")
3989 (t "Prolog"))) 3914 (t "Prolog")))
@@ -4042,7 +3967,7 @@ so by ignoring `easy-menu-add'."
4042 (easy-menu-add prolog-edit-menu-help)) 3967 (easy-menu-add prolog-edit-menu-help))
4043 3968
4044(defun prolog-inferior-menu () 3969(defun prolog-inferior-menu ()
4045 "Creates the menus for the Prolog inferior buffer. 3970 "Create the menus for the Prolog inferior buffer.
4046This menu is dynamically created because one may change systems during 3971This menu is dynamically created because one may change systems during
4047the life of an Emacs session." 3972the life of an Emacs session."
4048 3973
@@ -4050,7 +3975,7 @@ the life of an Emacs session."
4050 prolog-inferior-menu-help (current-local-map) 3975 prolog-inferior-menu-help (current-local-map)
4051 "Help menu for the Prolog inferior mode." 3976 "Help menu for the Prolog inferior mode."
4052 (append 3977 (append
4053 (if (eq prolog-emacs 'xemacs) '("Help") '("Prolog-help")) 3978 (if (featurep 'xemacs) '("Help") '("Prolog-help"))
4054 (cond 3979 (cond
4055 ((eq prolog-system 'sicstus) 3980 ((eq prolog-system 'sicstus)
4056 '(["On predicate" prolog-help-on-predicate t] 3981 '(["On predicate" prolog-help-on-predicate t]
@@ -4108,12 +4033,8 @@ the life of an Emacs session."
4108 (easy-menu-add prolog-inferior-menu-all) 4033 (easy-menu-add prolog-inferior-menu-all)
4109 (easy-menu-add prolog-inferior-menu-help)) 4034 (easy-menu-add prolog-inferior-menu-help))
4110 4035
4111(add-hook 'prolog-mode-hook 'prolog-menu) 4036(add-hook 'prolog-mode-hook 'prolog-menu) ;FIXME.
4112(add-hook 'prolog-inferior-mode-hook 'prolog-inferior-menu) 4037(add-hook 'prolog-inferior-mode-hook 'prolog-inferior-menu) ;FIXME.
4113
4114(add-hook 'prolog-mode-hook '(lambda () (font-lock-mode 1)))
4115(add-hook 'prolog-inferior-mode-hook '(lambda () (font-lock-mode 1)))
4116
4117 4038
4118(defun prolog-mode-version () 4039(defun prolog-mode-version ()
4119 "Echo the current version of Prolog mode in the minibuffer." 4040 "Echo the current version of Prolog mode in the minibuffer."