File: prolog.el.html
This package provides a major mode for editing Prolog code, with all the bells and whistles one would expect, including syntax highlighting and auto indentation. It can also send regions to an inferior Prolog process.
Some settings you may wish to use:
(setq prolog-system 'swi) ; optional, the system you are using;
; see prolog-system below for possible values
(setq auto-mode-alist (append '(("\\\\.pl\\\\'" . prolog-mode)
("\\\\.m\\\\'" . mercury-mode))
auto-mode-alist))
The last expression above makes sure that files ending with .pl are assumed to be Prolog files and not Perl, which is the default Emacs setting. If this is not wanted, remove this line. It is then necessary to either
o insert in your Prolog files the following comment as the first line:
% -*- Mode: Prolog -*-
and then the file will be open in Prolog mode no matter its
extension, or
o manually switch to prolog mode after opening a Prolog file, by typing
M-x prolog-mode.
If the command to start the prolog process ('sicstus', 'pl' or
'swipl' for SWI prolog, etc.) is not available in the default path,
then it is necessary to set the value of the environment variable
EPROLOG to a shell command to invoke the prolog process.
You can also customize the variable
prolog-program-name(var)/prolog-program-name(fun) (in the group prolog-inferior) and provide
a full path for your Prolog system (swi, scitus, etc.).
Note: I (Stefan, the current maintainer) work under XEmacs. Future
developments will thus be biased towards XEmacs (OK, I admit it,
I am biased towards XEmacs in general), though I will do my best
to keep the GNU Emacs compatibility. So if you work under Emacs
and see something that does not work do drop me a line, as I have
a smaller chance to notice this kind of bugs otherwise.
; [The above comment dates from 2011.]
Changelog:
Version 1.22:
o Allowed both 'swipl' and 'pl' as names for the SWI Prolog
interpreter.
o Atoms that start a line are not blindly colored as
predicates. Instead we check that they are followed by ( or
:- first. Patch suggested by Guy Wiener.
Version 1.21:
o Cleaned up the code that defines faces. The missing face
warnings on some Emacsen should disappear.
Version 1.20:
o Improved the handling of clause start detection and multi-line
comments: prolog-clause-start no longer finds non-predicate
(e.g., capitalized strings) beginning of clauses.
prolog-tokenize recognizes when the end point is within a
multi-line comment.
Version 1.19:
o Minimal changes for Aquamacs inclusion and in general for
better coping with finding the Prolog executable. Patch
provided by David Reitter
Version 1.18:
o Fixed syntax highlighting for clause heads that do not begin at
the beginning of the line.
o Fixed compilation warnings under Emacs.
o Updated the email address of the current maintainer.
Version 1.17:
o Minor indentation fix (patch by Markus Triska)
o prolog-underscore-wordchar-flag defaults now to nil (more
consistent to other Emacs modes)
Version 1.16:
o Eliminated a possible compilation warning.
Version 1.15:
o Introduced three new customizable variables: electric colon
(prolog-electric-colon-flag, default nil), electric dash
(prolog-electric-dash-flag, default nil), and a possibility
to prevent the predicate template insertion from adding commas
(prolog-electric-dot-full-predicate-template, defaults to t
since it seems quicker to me to just type those commas). A
trivial adaptation of a patch by Markus Triska.
o Improved the behavior of electric if-then-else to only skip
forward if the parenthesis/semicolon is preceded by
whitespace. Once more a trivial adaptation of a patch by
Markus Triska.
Version 1.14:
o Cleaned up align code. prolog-align-flag is eliminated (since
on a second thought it does not do anything useful). Added key
binding (C-c C-a) and menu entry for alignment.
o Condensed regular expressions for lower and upper case
characters (GNU Emacs seems to go over the regexp length limit
with the original form). My code on the matter was improved
considerably by Markus Triska.
o Fixed prolog-insert-spaces-after-paren (which used an
uninitialized variable).
o Minor changes to clean up the code and avoid some implicit
package requirements.
Version 1.13:
o Removed the use of map-char-table in prolog-build-case-strings
which appears to cause problems in (at least) Emacs 23.0.0.1.
o Added if-then-else indentation + corresponding electric
characters. New customization: prolog-electric-if-then-else-flag
o Align support (requires align). New customization:
prolog-align-flag.
o Temporary consult files have now the same name throughout the
session. This prevents issues with reconsulting a buffer
(this event is no longer passed to Prolog as a request to
consult a new file).
o Adaptive fill mode is now turned on. Comment indentation is
still worse than it could be though, I am working on it.
o Improved filling and auto-filling capabilities. Now block
comments should be [auto-]filled correctly most of the time;
the following pattern in particular is worth noting as being
filled correctly:
<some code here> % some comment here that goes beyond the
% rightmost column, possibly combined with
% subsequent comment lines
o prolog-char-quote-workaround now defaults to nil.
o Note: Many of the above improvements have been suggested by
Markus Triska, who also provided useful patches on the matter
when he realized that I was slow in responding. Many thanks.
Version 1.11 / 1.12
o GNU Emacs compatibility fix for paragraph filling (fixed
incorrectly in 1.11, fix fixed in 1.12).
Version 1.10
o Added paragraph filling in comment blocks and also correct auto
filling for comments.
o Fixed the possible "Regular expression too big" error in
prolog-electric-dot.
Version 1.9
o Parenthesis expressions are now indented by default so that
components go one underneath the other, just as for compound
terms. You can use the old style (the second and subsequent
lines being indented to the right in a parenthesis expression)
by setting the customizable variable prolog-paren-indent-p
(group "Prolog Indentation") to t.
o (Somehow awkward) handling of the 0' character escape
sequence. I am looking into a better way of doing it but
prospects look bleak. If this breaks things for you please let
me know and also set the prolog-char-quote-workaround (group
"Prolog Other") to nil.
Version 1.8
o Key binding fix.
Version 1.7
o Fixed a number of issues with the syntax of single quotes,
including Debian bug #324520.
Version 1.6
o Fixed mercury mode menu initialization (Debian bug #226121).
o Fixed (i.e., eliminated) Delete remapping (Debian bug #229636).
o Corrected indentation for clauses defining quoted atoms.
Version 1.5:
o Keywords fontifying should work in console mode so this is
enabled everywhere.
Version 1.4:
o Now supports GNU Prolog--minor adaptation of a patch by Stefan
Moeding.
Version 1.3:
o Info-follow-nearest-node now called correctly under Emacs too
(thanks to Nicolas Pelletier). Should be implemented more
elegantly (i.e., without compilation warnings) in the future.
Version 1.2:
o Another prompt fix, still in SWI mode (people seem to have
changed the prompt of SWI Prolog).
Version 1.1:
o Fixed dots in the end of line comments causing indentation
problems. The following code is now correctly indented (note
the dot terminating the comment):
a(X) :- b(X),
c(X). % comment here.
a(X).
and so is this (and variants):
a(X) :- b(X),
c(X). /* comment here. */
a(X).
Version 1.0:
o Revamped the menu system.
o Yet another prompt recognition fix (SWI mode).
o This is more of a renumbering than a new edition. I promoted
the mode to version 1.0 to emphasize the fact that it is now
mature and stable enough to be considered production (in my
opinion anyway).
Version 0.1.41:
o GNU Emacs compatibility fixes.
Version 0.1.40:
o prolog-get-predspec is now suitable to be called as
imenu-extract-index-name-function. The predicate index works.
o Since imenu works now as advertised, prolog-imenu-flag is t
by default.
o Eliminated prolog-create-predicate-index since the imenu
utilities now work well. Actually, this function is also
buggy, and I see no reason to fix it since we do not need it
anyway.
o Fixed prolog-pred-start, prolog-clause-start, prolog-clause-info.
o Fix for prolog-build-case-strings; now prolog-upper-case-string
and prolog-lower-case-string are correctly initialized,
o Various font-lock changes; most importantly, block comments (/*
... */) are now correctly fontified in XEmacs even when they
extend on multiple lines.
Version 0.1.36:
o The debug prompt of SWI Prolog is now correctly recognized.
Version 0.1.35:
o Minor font-lock bug fixes.
Defined variables (70)
mercury-mode-abbrev-table | Abbrev table for ‘mercury-mode’. |
mercury-mode-hook | Hook run after entering Prolog[Mercury] mode. |
mercury-mode-map | Keymap for ‘mercury-mode’. |
mercury-mode-syntax-table | Syntax table for ‘mercury-mode’. |
prolog-atom-char-regexp | Regexp specifying characters which constitute atoms without quoting. |
prolog-char-quote-workaround | If non-nil, declare 0 as a quote character to handle 0’<char>. |
prolog-compilation-buffer | Name of the output buffer for Prolog compilation/consulting. |
prolog-compile-string | Alist of strings and lists defining predicate for recompilation. |
prolog-consult-compile-file | The file to compile/consult (can be a temporary file). |
prolog-consult-compile-first-line | The number of the first line of the file to consult/compile. |
prolog-consult-compile-output | Hold the unprocessed output from the current prolog task. |
prolog-consult-compile-real-file | The file name of the buffer to compile/consult. |
prolog-consult-string | Alist of strings defining predicate for reconsulting. |
prolog-debug-off-string | Predicate for disabling debug mode. |
prolog-debug-on-string | Predicate for enabling debug mode. |
prolog-determinism-specificators | Alist of Prolog determinism specificators used by font locking. |
prolog-directives | Alist of Prolog source code directives used by font locking. |
prolog-edit-menu-insert-move | Commands for Prolog code manipulation. |
prolog-edit-menu-runtime | Runtime Prolog commands available from the editing buffer. |
prolog-electric-colon-flag | Non-nil means make ‘:’ electric (inserts ‘:-’ on a new line). |
prolog-electric-dash-flag | Non-nil means make ‘-’ electric (inserts a ‘-->’ on a new line). |
prolog-electric-dot-flag | Non-nil means make dot key electric. |
prolog-electric-dot-full-predicate-template | If nil, electric dot inserts only the current predicate’s name and ‘(’ |
prolog-electric-if-then-else-flag | Non-nil makes ‘(’, ‘>’ and ‘;’ electric |
prolog-electric-underscore-flag | Non-nil means make underscore key electric. |
prolog-eof-string | String or alist of strings that represent end of file for prolog. |
prolog-head-delimiter | A regexp for matching on the end delimiter of a head (e.g. ":-"). |
prolog-help-function | Alist for the name of the function for finding help on a predicate. |
prolog-imenu-flag | Non-nil means add a clause index menu for all prolog files. |
prolog-imenu-max-lines | The maximum number of lines of the file for imenu to be enabled. |
prolog-indent-width | The indentation width used by the editing buffer. |
prolog-inferior-menu-all | Menu for the inferior Prolog buffer. |
prolog-inferior-mode-abbrev-table | Abbrev table for ‘prolog-inferior-mode’. |
prolog-inferior-mode-hook | List of functions to call after the inferior prolog mode has initialized. |
prolog-inferior-mode-map | Keymap for ‘prolog-inferior-mode’. |
prolog-inferior-mode-syntax-table | Syntax table for ‘prolog-inferior-mode’. |
prolog-info-alist | Alist with all builtin predicates. |
prolog-info-predicate-index | The info node for the SICStus predicate index. |
prolog-keywords | Alist of Prolog keywords which is used for font locking of directives. |
prolog-left-indent-regexp | Regexp for ‘prolog-electric-if-then-else-flag’. |
prolog-left-paren | The characters used as left parentheses for the indentation code. |
prolog-menu-help | Help menu for the Prolog mode. |
prolog-mode-abbrev-table | Abbrev table for ‘prolog-mode’. |
prolog-mode-hook | List of functions to call after the prolog mode has initialized. |
prolog-mode-map | Keymap for ‘prolog-mode’. |
prolog-mode-specificators | Alist of Prolog mode specificators used by font locking. |
prolog-mode-syntax-table | Syntax table for ‘prolog-mode’. |
prolog-mode-version | Prolog mode version number. |
prolog-old-sicstus-keys-flag | Non-nil means old SICStus Prolog mode keybindings are used. |
prolog-paren-indent | The indentation increase for parenthesis expressions. |
prolog-paren-indent-p | If non-nil, increase indentation for parenthesis expressions. |
prolog-parse-mode | The parse mode used (decides from which point parsing is done). |
prolog-process-flag | Non-nil means that a prolog task (i.e. a consultation or compilation job) |
prolog-program-name | Alist of program names for invoking an inferior Prolog with ‘run-prolog’. |
prolog-program-switches | Alist of switches given to inferior Prolog run with ‘run-prolog’. |
prolog-prompt-regexp | Alist of prompts of the prolog system command line. |
prolog-quoted-atom-regexp | Regexp matching a quoted atom. |
prolog-right-paren | The characters used as right parentheses for the indentation code. |
prolog-smie-grammar | Precedence levels of infix operators. |
prolog-string-regexp | Regexp matching a string. |
prolog-system | Prolog interpreter/compiler used. |
prolog-system-version | Alist of Prolog system versions. |
prolog-trace-off-string | Predicate for disabling tracing. |
prolog-trace-on-string | Predicate for enabling tracing. |
prolog-types | Alist of Prolog types used by font locking. |
prolog-underscore-wordchar-flag | Non-nil means underscore (_) is a word-constituent character. |
prolog-use-sicstus-sd | If non-nil, use the source level debugger of SICStus 3#7 and later. |
prolog-use-standard-consult-compile-method-flag | Non-nil means use the standard compilation method. |
prolog-zip-off-string | Predicate for disabling zip mode for SICStus. |
prolog-zip-on-string | Predicate for enabling zip mode for SICStus. |