Add arch taglines
[bpt/emacs.git] / lisp / progmodes / prolog.el
index 9005859..48ed5a9 100644 (file)
@@ -1,12 +1,15 @@
-;; Major mode for editing Prolog, and for running Prolog under Emacs
+;;; prolog.el --- major mode for editing and running Prolog under Emacs
+
 ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
-;; Author Masanobu UMEDA (umerin@flab.flab.fujitsu.junet)
+
+;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
+;; Keywords: languages
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 1, or (at your option)
+;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;; This package provides a major mode for editing Prolog.  It knows
+;; about Prolog syntax and comments, and can send regions to an inferior
+;; Prolog interpreter process.  Font locking is tuned towards GNU Prolog.
+
+;;; Code:
 
 (defvar prolog-mode-syntax-table nil)
 (defvar prolog-mode-abbrev-table nil)
 (defvar prolog-mode-map nil)
-  
-(defvar prolog-program-name "prolog"
-  "*Program name for invoking an inferior Prolog with `run-prolog'.")
 
-(defvar prolog-consult-string "reconsult(user).\n"
-  "*(Re)Consult mode (for C-Prolog and Quintus Prolog). ")
+(defgroup prolog nil
+  "Major mode for editing and running Prolog under Emacs"
+  :group 'languages)
+
 
-(defvar prolog-compile-string "compile(user).\n"
-  "*Compile mode (for Quintus Prolog).")
+(defcustom prolog-program-name "prolog"
+  "*Program name for invoking an inferior Prolog with `run-prolog'."
+  :type 'string
+  :group 'prolog)
 
-(defvar prolog-eof-string "end_of_file.\n"
+(defcustom prolog-consult-string "reconsult(user).\n"
+  "*(Re)Consult mode (for C-Prolog and Quintus Prolog). "
+  :type 'string
+  :group 'prolog)
+
+(defcustom prolog-compile-string "compile(user).\n"
+  "*Compile mode (for Quintus Prolog)."
+  :type 'string
+  :group 'prolog)
+
+(defcustom prolog-eof-string "end_of_file.\n"
   "*String that represents end of file for prolog.
-nil means send actual operating system end of file.")
+nil means send actual operating system end of file."
+  :type 'string
+  :group 'prolog)
+
+(defcustom prolog-indent-width 4
+  "Level of indentation in Prolog buffers."
+  :type 'integer
+  :group 'prolog)
 
-(defvar prolog-indent-width 4)
+(defvar prolog-font-lock-keywords
+  '(("\\(#[<=]=>\\|:-\\)\\|\\(#=\\)\\|\\(#[#<>\\/][=\\/]*\\|!\\)"
+     0 font-lock-keyword-face)
+    ("\\<\\(is\\|write\\|nl\\|read_\\sw+\\)\\>"
+     1 font-lock-keyword-face)
+    ("^\\(\\sw+\\)\\s-*\\((\\(.+\\))\\)*"
+     (1 font-lock-function-name-face)
+     (3 font-lock-variable-name-face)))
+  "Font-lock keywords for Prolog mode.")
 
 (if prolog-mode-syntax-table
     ()
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?_ "w" table)
     (modify-syntax-entry ?\\ "\\" table)
-    (modify-syntax-entry ?/ "." table)
-    (modify-syntax-entry ?* "." table)
+    (modify-syntax-entry ?/ ". 14" table)
+    (modify-syntax-entry ?* ". 23" table)
     (modify-syntax-entry ?+ "." table)
     (modify-syntax-entry ?- "." table)
     (modify-syntax-entry ?= "." table)
     (modify-syntax-entry ?% "<" table)
+    (modify-syntax-entry ?\n ">" table)
     (modify-syntax-entry ?< "." table)
     (modify-syntax-entry ?> "." table)
     (modify-syntax-entry ?\' "\"" table)
@@ -59,11 +98,13 @@ nil means send actual operating system end of file.")
   (set-syntax-table prolog-mode-syntax-table)
   (setq local-abbrev-table prolog-mode-abbrev-table)
   (make-local-variable 'paragraph-start)
-  (setq paragraph-start (concat "^%%\\|^$\\|" page-delimiter)) ;'%%..'
+  (setq paragraph-start (concat "%%\\|$\\|" page-delimiter)) ;'%%..'
   (make-local-variable 'paragraph-separate)
   (setq paragraph-separate paragraph-start)
   (make-local-variable 'paragraph-ignore-fill-prefix)
   (setq paragraph-ignore-fill-prefix t)
+  (make-local-variable 'imenu-generic-expression)
+  (setq imenu-generic-expression "^[a-z][a-zA-Z0-9_]+")
   (make-local-variable 'indent-line-function)
   (setq indent-line-function 'prolog-indent-line)
   (make-local-variable 'comment-start)
@@ -72,8 +113,8 @@ nil means send actual operating system end of file.")
   (setq comment-start-skip "%+ *")
   (make-local-variable 'comment-column)
   (setq comment-column 48)
-  (make-local-variable 'comment-indent-hook)
-  (setq comment-indent-hook 'prolog-comment-indent))
+  (make-local-variable 'comment-indent-function)
+  (setq comment-indent-function 'prolog-comment-indent))
 
 (defun prolog-mode-commands (map)
   (define-key map "\t" 'prolog-indent-line)
@@ -84,6 +125,7 @@ nil means send actual operating system end of file.")
   (setq prolog-mode-map (make-sparse-keymap))
   (prolog-mode-commands prolog-mode-map))
 
+;;;###autoload
 (defun prolog-mode ()
   "Major mode for editing Prolog code for Prologs.
 Blank lines and `%%...' separate paragraphs.  `%'s start comments.
@@ -97,6 +139,10 @@ if that value is non-nil."
   (setq major-mode 'prolog-mode)
   (setq mode-name "Prolog")
   (prolog-mode-variables)
+  ;; font lock
+  (setq font-lock-defaults '(prolog-font-lock-keywords
+                             nil nil nil
+                             beginning-of-line))
   (run-hooks 'prolog-mode-hook))
 
 (defun prolog-indent-line (&optional whole-exp)
@@ -227,6 +273,7 @@ Return not at end copies rest of line to end and sends it.
   (use-local-map inferior-prolog-mode-map)
   (run-hooks 'prolog-mode-hook))
 
+;;;###autoload
 (defun run-prolog ()
   "Run an inferior Prolog process, input and output via buffer *prolog*."
   (interactive)
@@ -254,3 +301,8 @@ If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode."
   (interactive "P\nr")
   (prolog-consult-region compile beg end)
   (switch-to-buffer "*prolog*"))
+
+(provide 'prolog)
+
+;;; arch-tag: f3ec6748-1272-4ab6-8826-c50cb1607636
+;;; prolog.el ends here