Mercurial > emacs
view lisp/progmodes/prolog.el @ 29005:b396df3a5181
(ONE_MORE_BYTE, TWO_MORE_BYTES): Set coding->resutl to
CODING_FINISH_INSUFFICIENT_SRC if there's not enough source.
(ONE_MORE_CHAR, EMIT_CHAR, EMIT_ONE_BYTE, EMIT_TWO_BYTE,
EMIT_BYTES): New macros.
(THREE_MORE_BYTES, DECODE_CHARACTER_ASCII,
DECODE_CHARACTER_DIMENSION1, DECODE_CHARACTER_DIMENSION2): These
macros deleted.
(CHECK_CODE_RANGE_A0_FF): This macro deleted.
(detect_coding_emacs_mule): Use UNIBYTE_STR_AS_MULTIBYTE_P to
check the validity of multibyte sequence.
(decode_coding_emacs_mule): New function.
(encode_coding_emacs_mule): New macro.
(detect_coding_iso2022): Use ONE_MORE_BYTE to fetch a byte from
the source.
(DECODE_ISO_CHARACTER): Just return a character code.
(DECODE_COMPOSITION_START): Set coding->result instead of result.
(decode_coding_iso2022, decode_coding_sjis_big5, decode_eol): Use
EMIT_CHAR to produced decoded characters. Exit the loop only by
macros ONE_MORE_BYTE or EMIT_CHAR. Don't handle the case of last
block here.
(ENCODE_ISO_CHARACTER): Don't translate character here. Produce
only position codes for an invalid character.
(encode_designation_at_bol): Return new destination pointer. 5th
arg DSTP is changed to DST.
(encode_coding_iso2022, decode_coding_sjis_big5): Get a character
from the source by ONE_MORE_CHAR. Don't handle the case of last
block here.
(DECODE_SJIS_BIG5_CHARACTER, ENCODE_SJIS_BIG5_CHARACTER): These
macros deleted.
(detect_coding_sjis, detect_coding_big5, detect_coding_utf_8,
detect_coding_utf_16, detect_coding_ccl): Use ONE_MORE_BYTE and
TWO_MORE_BYTES to fetch a byte from the source.
(encode_eol): Pay attention to coding->src_multibyte.
(detect_coding, detect_eol): Preserve members src_multibyte and
dst_multibyte.
(DECODING_BUFFER_MAG): Return 2 even for coding_type_raw_text.
(encoding_buffer_size): Set magnification to 3 for all coding
systems that require encoding.
(ccl_coding_driver): For decoding, be sure that the result is
valid multibyte sequence.
(decode_coding): Initialize coding->errors and coding->result.
For emacs-mule, call decode_coding_emacs_mule. For no-conversion
and raw-text, always call decode_eol. Handle the case of last
block here. If not coding->dst_multibyte, convert the resulting
sequence to unibyte.
(encode_coding): Initialize coding->errors and coding->result.
For emacs-mule, call encode_coding_emacs_mule. For no-conversion
and raw-text, always call encode_eol. Handle the case of last
block here.
(shrink_decoding_region, shrink_encoding_region): Detect cases
that we can't skip data more rigidly.
(code_convert_region): Setup src_multibyte and dst_multibyte
members of coding. For decoding, if the buffer is multibyte,
convert the source sequence to unibyte in advance. For encoding,
if the buffer is multibyte, convert the resulting sequence to
multibyte afterward.
(run_pre_post_conversion_on_str): New function.
(code_convert_string): Deleted and divided into the following two.
(decode_coding_string, encode_coding_string): New functions.
(code_convert_string1, code_convert_string_norecord): Call one of
above.
(Fdecode_sjis_char, Fdecode_big5_char): Use MAKE_CHAR instead of
MAKE_NON_ASCII_CHAR.
(Fset_terminal_coding_system_internal,
Fset_safe_terminal_coding_system_internal): Setup src_multibyte
and dst_multibyte members.
(init_coding_once): Initialize iso_code_class with new enum
ISO_control_0 and ISO_control_1.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 19 May 2000 23:54:56 +0000 |
parents | ba46225fd687 |
children | 706ae7fb4033 |
line wrap: on
line source
;;; prolog.el --- major mode for editing and running Prolog under Emacs ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc. ;; 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 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; 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, 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. ;;; Code: (defvar prolog-mode-syntax-table nil) (defvar prolog-mode-abbrev-table nil) (defvar prolog-mode-map nil) (defgroup prolog nil "Major mode for editing and running Prolog under Emacs" :group 'languages) (defcustom prolog-program-name "prolog" "*Program name for invoking an inferior Prolog with `run-prolog'." :type 'string :group 'prolog) (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." :type 'string :group 'prolog) (defcustom prolog-indent-width 4 "Level of indentation in Prolog buffers." :type 'integer :group 'prolog) (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 ?+ "." 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) (setq prolog-mode-syntax-table table))) (define-abbrev-table 'prolog-mode-abbrev-table ()) (defun prolog-mode-variables () (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)) ;'%%..' (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) (setq comment-start "%") (make-local-variable 'comment-start-skip) (setq comment-start-skip "%+ *") (make-local-variable 'comment-column) (setq comment-column 48) (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) (define-key map "\e\C-x" 'prolog-consult-region)) (if prolog-mode-map nil (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. Commands: \\{prolog-mode-map} Entry to this mode calls the value of `prolog-mode-hook' if that value is non-nil." (interactive) (kill-all-local-variables) (use-local-map prolog-mode-map) (setq major-mode 'prolog-mode) (setq mode-name "Prolog") (prolog-mode-variables) (run-hooks 'prolog-mode-hook)) (defun prolog-indent-line (&optional whole-exp) "Indent current line as Prolog code. With argument, indent any additional lines of the same clause rigidly along with this one (not yet)." (interactive "p") (let ((indent (prolog-indent-level)) (pos (- (point-max) (point))) beg) (beginning-of-line) (setq beg (point)) (skip-chars-forward " \t") (if (zerop (- indent (current-column))) nil (delete-region beg (point)) (indent-to indent)) (if (> (- (point-max) pos) (point)) (goto-char (- (point-max) pos))) )) (defun prolog-indent-level () "Compute prolog indentation level." (save-excursion (beginning-of-line) (skip-chars-forward " \t") (cond ((looking-at "%%%") 0) ;Large comment starts ((looking-at "%[^%]") comment-column) ;Small comment starts ((bobp) 0) ;Beginning of buffer (t (let ((empty t) ind more less) (if (looking-at ")") (setq less t) ;Find close (setq less nil)) ;; See previous indentation (while empty (forward-line -1) (beginning-of-line) (if (bobp) (setq empty nil) (skip-chars-forward " \t") (if (not (or (looking-at "%[^%]") (looking-at "\n"))) (setq empty nil)))) (if (bobp) (setq ind 0) ;Beginning of buffer (setq ind (current-column))) ;Beginning of clause ;; See its beginning (if (looking-at "%%[^%]") ind ;; Real prolog code (if (looking-at "(") (setq more t) ;Find open (setq more nil)) ;; See its tail (end-of-prolog-clause) (or (bobp) (forward-char -1)) (cond ((looking-at "[,(;>]") (if (and more (looking-at "[^,]")) (+ ind prolog-indent-width) ;More indentation (max tab-width ind))) ;Same indentation ((looking-at "-") tab-width) ;TAB ((or less (looking-at "[^.]")) (max (- ind prolog-indent-width) 0)) ;Less indentation (t 0)) ;No indentation ))) ))) (defun end-of-prolog-clause () "Go to end of clause in this line." (beginning-of-line 1) (let* ((eolpos (save-excursion (end-of-line) (point)))) (if (re-search-forward comment-start-skip eolpos 'move) (goto-char (match-beginning 0))) (skip-chars-backward " \t"))) (defun prolog-comment-indent () "Compute prolog comment indentation." (cond ((looking-at "%%%") 0) ((looking-at "%%") (prolog-indent-level)) (t (save-excursion (skip-chars-backward " \t") ;; Insert one space at least, except at left margin. (max (+ (current-column) (if (bolp) 0 1)) comment-column))) )) ;;; ;;; Inferior prolog mode ;;; (defvar inferior-prolog-mode-map nil) (defun inferior-prolog-mode () "Major mode for interacting with an inferior Prolog process. The following commands are available: \\{inferior-prolog-mode-map} Entry to this mode calls the value of `prolog-mode-hook' with no arguments, if that value is non-nil. Likewise with the value of `comint-mode-hook'. `prolog-mode-hook' is called after `comint-mode-hook'. You can send text to the inferior Prolog from other buffers using the commands `send-region', `send-string' and \\[prolog-consult-region]. Commands: Tab indents for Prolog; with argument, shifts rest of expression rigidly with the current line. Paragraphs are separated only by blank lines and '%%'. '%'s start comments. Return at end of buffer sends line as input. Return not at end copies rest of line to end and sends it. \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing. \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any. \\[comint-stop-subjob] stops. \\[comint-quit-subjob] sends quit signal." (interactive) (require 'comint) (comint-mode) (setq major-mode 'inferior-prolog-mode mode-name "Inferior Prolog" comint-prompt-regexp "^| [ ?][- ] *") (prolog-mode-variables) (if inferior-prolog-mode-map nil (setq inferior-prolog-mode-map (copy-keymap comint-mode-map)) (prolog-mode-commands inferior-prolog-mode-map)) (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) (require 'comint) (switch-to-buffer (make-comint "prolog" prolog-program-name)) (inferior-prolog-mode)) (defun prolog-consult-region (compile beg end) "Send the region to the Prolog process made by \"M-x run-prolog\". If COMPILE (prefix arg) is not nil, use compile mode rather than consult mode." (interactive "P\nr") (save-excursion (if compile (send-string "prolog" prolog-compile-string) (send-string "prolog" prolog-consult-string)) (send-region "prolog" beg end) (send-string "prolog" "\n") ;May be unnecessary (if prolog-eof-string (send-string "prolog" prolog-eof-string) (process-send-eof "prolog")))) ;Send eof to prolog process. (defun prolog-consult-region-and-go (compile beg end) "Send the region to the inferior Prolog, and switch to *prolog* buffer. 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) ;;; prolog.el ends here