Annotation of 43BSDReno/contrib/emacs-18.55/lisp/prolog.el, revision 1.1.1.1

1.1       root        1: ;; Major mode for editing Prolog, and for running Prolog under Emacs
                      2: ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
                      3: ;; Author Masanobu UMEDA ([email protected])
                      4: 
                      5: ;; This file is part of GNU Emacs.
                      6: 
                      7: ;; GNU Emacs is distributed in the hope that it will be useful,
                      8: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      9: ;; accepts responsibility to anyone for the consequences of using it
                     10: ;; or for whether it serves any particular purpose or works at all,
                     11: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     12: ;; License for full details.
                     13: 
                     14: ;; Everyone is granted permission to copy, modify and redistribute
                     15: ;; GNU Emacs, but only under the conditions described in the
                     16: ;; GNU Emacs General Public License.   A copy of this license is
                     17: ;; supposed to have been given to you along with GNU Emacs so you
                     18: ;; can know your rights and responsibilities.  It should be in a
                     19: ;; file named COPYING.  Among other things, the copyright notice
                     20: ;; and this notice must be preserved on all copies.
                     21: 
                     22: (defvar prolog-mode-syntax-table nil)
                     23: (defvar prolog-mode-abbrev-table nil)
                     24: (defvar prolog-mode-map nil)
                     25:   
                     26: (defvar prolog-consult-string "reconsult(user).\n"
                     27:   "*(Re)Consult mode (for C-Prolog and Quintus Prolog). ")
                     28: 
                     29: (defvar prolog-compile-string "compile(user).\n"
                     30:   "*Compile mode (for Quintus Prolog).")
                     31: 
                     32: (defvar prolog-eof-string "end_of_file.\n"
                     33:   "*String that represents end of file for prolog.
                     34: nil means send actual operaing system end of file.")
                     35: 
                     36: (defvar prolog-indent-width 4)
                     37: 
                     38: (if prolog-mode-syntax-table
                     39:     ()
                     40:   (let ((table (make-syntax-table)))
                     41:     (modify-syntax-entry ?_ "w" table)
                     42:     (modify-syntax-entry ?\\ "\\" table)
                     43:     (modify-syntax-entry ?/ "." table)
                     44:     (modify-syntax-entry ?* "." table)
                     45:     (modify-syntax-entry ?+ "." table)
                     46:     (modify-syntax-entry ?- "." table)
                     47:     (modify-syntax-entry ?= "." table)
                     48:     (modify-syntax-entry ?% "<" table)
                     49:     (modify-syntax-entry ?< "." table)
                     50:     (modify-syntax-entry ?> "." table)
                     51:     (modify-syntax-entry ?\' "\"" table)
                     52:     (setq prolog-mode-syntax-table table)))
                     53: 
                     54: (define-abbrev-table 'prolog-mode-abbrev-table ())
                     55: 
                     56: (defun prolog-mode-variables ()
                     57:   (set-syntax-table prolog-mode-syntax-table)
                     58:   (setq local-abbrev-table prolog-mode-abbrev-table)
                     59:   (make-local-variable 'paragraph-start)
                     60:   (setq paragraph-start (concat "^%%\\|^$\\|" page-delimiter)) ;'%%..'
                     61:   (make-local-variable 'paragraph-separate)
                     62:   (setq paragraph-separate paragraph-start)
                     63:   (make-local-variable 'paragraph-ignore-fill-prefix)
                     64:   (setq paragraph-ignore-fill-prefix t)
                     65:   (make-local-variable 'indent-line-function)
                     66:   (setq indent-line-function 'prolog-indent-line)
                     67:   (make-local-variable 'comment-start)
                     68:   (setq comment-start "%")
                     69:   (make-local-variable 'comment-start-skip)
                     70:   (setq comment-start-skip "%+ *")
                     71:   (make-local-variable 'comment-column)
                     72:   (setq comment-column 48)
                     73:   (make-local-variable 'comment-indent-hook)
                     74:   (setq comment-indent-hook 'prolog-comment-indent))
                     75: 
                     76: (defun prolog-mode-commands (map)
                     77:   (define-key map "\t" 'prolog-indent-line)
                     78:   (define-key map "\e\C-x" 'prolog-consult-region))
                     79: 
                     80: (if prolog-mode-map
                     81:     nil
                     82:   (setq prolog-mode-map (make-sparse-keymap))
                     83:   (prolog-mode-commands prolog-mode-map))
                     84: 
                     85: (defun prolog-mode ()
                     86:   "Major mode for editing Prolog code for Prologs.
                     87: Blank lines and `%%...' separate paragraphs.  `%'s start comments.
                     88: Commands:
                     89: \\{prolog-mode-map}
                     90: Entry to this mode calls the value of prolog-mode-hook
                     91: if that value is non-nil."
                     92:   (interactive)
                     93:   (kill-all-local-variables)
                     94:   (use-local-map prolog-mode-map)
                     95:   (setq major-mode 'prolog-mode)
                     96:   (setq mode-name "Prolog")
                     97:   (prolog-mode-variables)
                     98:   (run-hooks 'prolog-mode-hook))
                     99: 
                    100: (defun prolog-indent-line (&optional whole-exp)
                    101:   "Indent current line as Prolog code.
                    102: With argument, indent any additional lines of the same clause
                    103: rigidly along with this one (not yet)."
                    104:   (interactive "p")
                    105:   (let ((indent (prolog-indent-level))
                    106:        (pos (- (point-max) (point))) beg)
                    107:     (beginning-of-line)
                    108:     (setq beg (point))
                    109:     (skip-chars-forward " \t")
                    110:     (if (zerop (- indent (current-column)))
                    111:        nil
                    112:       (delete-region beg (point))
                    113:       (indent-to indent))
                    114:     (if (> (- (point-max) pos) (point))
                    115:        (goto-char (- (point-max) pos)))
                    116:     ))
                    117: 
                    118: (defun prolog-indent-level ()
                    119:   "Compute prolog indentation level."
                    120:   (save-excursion
                    121:     (beginning-of-line)
                    122:     (skip-chars-forward " \t")
                    123:     (cond
                    124:      ((looking-at "%%%") 0)            ;Large comment starts
                    125:      ((looking-at "%[^%]") comment-column) ;Small comment starts
                    126:      ((bobp) 0)                                ;Beginning of buffer
                    127:      (t
                    128:       (let ((empty t) ind more less)
                    129:        (if (looking-at ")")
                    130:            (setq less t)               ;Find close
                    131:          (setq less nil))
                    132:        ;; See previous indentation
                    133:        (while empty
                    134:          (forward-line -1)
                    135:          (beginning-of-line)
                    136:          (if (bobp)
                    137:              (setq empty nil)
                    138:            (skip-chars-forward " \t")
                    139:            (if (not (or (looking-at "%[^%]") (looking-at "\n")))
                    140:                (setq empty nil))))
                    141:        (if (bobp)
                    142:            (setq ind 0)                ;Beginning of buffer
                    143:          (setq ind (current-column)))  ;Beginning of clause
                    144:        ;; See its beginning
                    145:        (if (looking-at "%%[^%]")
                    146:            ind
                    147:          ;; Real prolog code
                    148:          (if (looking-at "(")
                    149:              (setq more t)             ;Find open
                    150:            (setq more nil))
                    151:          ;; See its tail
                    152:          (end-of-prolog-clause)
                    153:          (or (bobp) (forward-char -1))
                    154:          (cond ((looking-at "[,(;>]")
                    155:                 (if (and more (looking-at "[^,]"))
                    156:                     (+ ind prolog-indent-width) ;More indentation
                    157:                   (max tab-width ind))) ;Same indentation
                    158:                ((looking-at "-") tab-width) ;TAB
                    159:                ((or less (looking-at "[^.]"))
                    160:                 (max (- ind prolog-indent-width) 0)) ;Less indentation
                    161:                (t 0))                  ;No indentation
                    162:          )))
                    163:      )))
                    164: 
                    165: (defun end-of-prolog-clause ()
                    166:   "Go to end of clause in this line."
                    167:   (beginning-of-line 1)
                    168:   (let* ((eolpos (save-excursion (end-of-line) (point))))
                    169:     (if (re-search-forward comment-start-skip eolpos 'move)
                    170:        (goto-char (match-beginning 0)))
                    171:     (skip-chars-backward " \t")))
                    172: 
                    173: (defun prolog-comment-indent ()
                    174:   "Compute prolog comment indentation."
                    175:   (cond ((looking-at "%%%") 0)
                    176:        ((looking-at "%%") (prolog-indent-level))
                    177:        (t
                    178:         (save-excursion
                    179:               (skip-chars-backward " \t")
                    180:               (max (1+ (current-column)) ;Insert one space at least
                    181:                    comment-column)))
                    182:        ))
                    183: 
                    184: 
                    185: ;;;
                    186: ;;; Inferior prolog mode
                    187: ;;;
                    188: (defvar inferior-prolog-mode-map nil)
                    189: 
                    190: ;; Moved into inferior-prolog-mode
                    191: ;;(if inferior-prolog-mode-map
                    192: ;;    nil
                    193: ;;  (setq inferior-prolog-mode-map (copy-alist shell-mode-map))
                    194: ;;  (prolog-mode-commands inferior-prolog-mode-map))
                    195: 
                    196: (defun inferior-prolog-mode ()
                    197:   "Major mode for interacting with an inferior Prolog process.
                    198: 
                    199: The following commands are available:
                    200: \\{inferior-prolog-mode-map}
                    201: 
                    202: Entry to this mode calls the value of prolog-mode-hook with no arguments,
                    203: if that value is non-nil.  Likewise with the value of shell-mode-hook.
                    204: prolog-mode-hook is called after shell-mode-hook.
                    205: 
                    206: You can send text to the inferior Prolog from other buffers
                    207: using the commands send-region, send-string and \\[prolog-consult-region].
                    208: 
                    209: Commands:
                    210: Tab indents for Prolog; with argument, shifts rest
                    211:  of expression rigidly with the current line.
                    212: Paragraphs are separated only by blank lines and '%%'. '%'s start comments.
                    213: 
                    214: Return at end of buffer sends line as input.
                    215: Return not at end copies rest of line to end and sends it.
                    216: \\[shell-send-eof] sends end-of-file as input.
                    217: \\[kill-shell-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
                    218: \\[interrupt-shell-subjob] interrupts the shell or its current subjob if any.
                    219: \\[stop-shell-subjob] stops, likewise. \\[quit-shell-subjob] sends quit signal, likewise."
                    220:   (interactive)
                    221:   (kill-all-local-variables)
                    222:   (setq major-mode 'inferior-prolog-mode)
                    223:   (setq mode-name "Inferior Prolog")
                    224:   (setq mode-line-process '(": %s"))
                    225:   (prolog-mode-variables)
                    226:   (require 'shell)
                    227:   (if inferior-prolog-mode-map
                    228:       nil
                    229:     (setq inferior-prolog-mode-map (copy-alist shell-mode-map))
                    230:     (prolog-mode-commands inferior-prolog-mode-map))
                    231:   (use-local-map inferior-prolog-mode-map)
                    232:   (make-local-variable 'last-input-start)
                    233:   (setq last-input-start (make-marker))
                    234:   (make-local-variable 'last-input-end)
                    235:   (setq last-input-end (make-marker))
                    236:   (make-variable-buffer-local 'shell-prompt-pattern)
                    237:   (setq shell-prompt-pattern "^| [ ?][- ] *") ;Set prolog prompt pattern
                    238:   (run-hooks 'shell-mode-hook 'prolog-mode-hook))
                    239: 
                    240: (defun run-prolog ()
                    241:   "Run an inferior Prolog process, input and output via buffer *prolog*."
                    242:   (interactive)
                    243:   (require 'shell)
                    244:   (switch-to-buffer (make-shell "prolog" "prolog"))
                    245:   (inferior-prolog-mode))
                    246: 
                    247: (defun prolog-consult-region (compile beg end)
                    248:   "Send the region to the Prolog process made by M-x run-prolog.
                    249:  If COMPILE (prefix arg) is not nil,
                    250:  use compile mode rather than consult mode."
                    251:   (interactive "P\nr")
                    252:   (save-excursion
                    253:     (if compile
                    254:        (send-string "prolog" prolog-compile-string)
                    255:       (send-string "prolog" prolog-consult-string))
                    256:     (send-region "prolog" beg end)
                    257:     (send-string "prolog" "\n")                ;May be unnecessary
                    258:     (if prolog-eof-string
                    259:        (send-string "prolog" prolog-eof-string)
                    260:       (process-send-eof "prolog")))) ;Send eof to prolog process.
                    261: 
                    262: (defun prolog-consult-region-and-go (compile beg end)
                    263:   "Send the region to the inferior Prolog, and switch to *prolog* buffer.
                    264:  If COMPILE (prefix arg) is not nil,
                    265:  use compile mode rather than consult mode."
                    266:   (interactive "P\nr")
                    267:   (prolog-consult-region compile beg end)
                    268:   (switch-to-buffer "*prolog*"))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.