casl-mode.el revision f4152ab9d084afebd592edfcde4bf5a0d8556edd
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;;;###autoload
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(autoload 'turn-on-casl-indent "casl-indent" "Turn on CASL indentation." t)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Version number
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang(defconst casl-mode-version "0.2"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Version of CASL-Mode")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defgroup casl nil
3e4305eb6432c65bb0dfe8d9af9707dfc92383eaChristian Maeder "Major mode for editing (heterogeneous) CASL programs."
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang :group 'languages
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang :prefix "casl-")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; casl major mode setup
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-mode-hook nil)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-mode-map (let ((keymap (make-keymap)))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (define-key keymap "\C-c\C-c" 'comment-region)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (define-key keymap "\C-c\C-r" 'casl-run-hets)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (define-key keymap "\C-c\C-g" 'casl-run-hetsg)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (define-key keymap "\C-c\C-n" 'casl-compile-goto-next-error)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang keymap)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Keymap for CASL major mode")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Are we running FSF Emacs or XEmacs?
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-running-xemacs
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (string-match "Lucid\\|XEmacs" emacs-version)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "non-nil if we are running XEmacs, nil otherwise.")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; ============= K E Y W O R D H I G H L I G H T I N G ============
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang(defface casl-black-komma-face
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang `((t (:foreground "black")))
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang ""
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang :group 'basic-faces)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang(defvar casl-black-komma-face 'casl-black-komma-face
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang "Face name to use for black komma.")
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-annotation-face 'casl-annotation-face
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "CASL mode face for Annotations")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-annotation-face 'font-lock-constant-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-keyword-face 'casl-keyword-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-keyword-face 'font-lock-keyword-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-library-name-face 'casl-library-name-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-library-name-face 'font-lock-type-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-name-face 'casl-name-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-name-face 'font-lock-variable-name-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-builtin-face 'casl-builtin-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-builtin-face 'font-lock-builtin-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-comment-face 'casl-comment-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-comment-face 'font-lock-comment-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-other-name-face 'casl-other-name-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(setq casl-other-name-face 'font-lock-function-name-face)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang(defvar casl-string-char-face 'casl-string-char-face)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang(setq casl-string-char-face 'font-lock-string-face)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Syntax highlighting of CASL
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defconst casl-font-lock-keywords
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (list
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Keywords of loading Library
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\(\\<\\|\\s-+\\)\\(logic\\|from\\|get\\|library\\|version\\)[ :\t\n]+"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (2 casl-builtin-face keep t))
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang;; '("\\(\\<\\|\\s-+\\)\\(%authors\\|%date\\|%display\\|%prec\\|%left_assoc\\|%number\\|%floating\\|%LATEX\\|%implies\\)[ :\t\n]+"
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang;; (2 casl-annotation-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Library and Logic name
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang '("\\(\\<\\|\\s-+\\)\\(library\\|logic\\)\\s-+\\(\\(\\w\\|/\\)+\\)[ \t\n]*"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (3 casl-library-name-face keep t))
c10df434f8e16b46ccf703bf2e38b799f7bcb38bHeng Jiang ;; name of from, get and given
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\(\\<\\|[ \t]+\\)\\(get\\|given\\)[ \t\n]+\\(\\(\\sw+\\s-*\\(,\\|$\\)[ \t\n]*\\)+\\)"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (3 casl-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\(\\<\\|\\s-+\\)from\\([ \t]+\\)\\(.+\\)\\(get\\|\\s-*\\)"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (3 casl-library-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; the name of specification and view
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\(\\<\\|\\[\\)\\(spec\\|view\\)\\s-+\\(\\w+\\)[ \t]*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?\\s-*.*\\([]=:]\\|::=\\)"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (3 casl-name-face keep t) (5 casl-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; then, and + name
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\(\\<\\|\\s-+\\)\\(and\\|then\\)[ \t\n]*\\([A-Z]\\w*\\)\\s-*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (3 casl-name-face keep t) (5 casl-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; names before and after to
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("[ \t\n]*\\(\\w+\\)[ \t\n]+to[ \t\n]+\\(\\(\\w+\\)\\s-*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?[, \t]*\\)?"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (1 casl-name-face keep t) (3 casl-name-face keep t) (5 casl-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; instance name of specification
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("\\<spec.+=\\s-*\\(%\\sw+\\s-*\\)?[ \t\n]*\\([A-Z]\\sw*\\)\\s-*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (2 casl-name-face keep t) (4 casl-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Basic signature: sort X, Y, Z
c10df434f8e16b46ccf703bf2e38b799f7bcb38bHeng Jiang '("\\(\\<\\|\\s-+\\)sorts?[ \t]+\\(\\(\\sw+\\s-*\\(\\[\\(\\sw\\|,\\)+\\]\\s-*\\)?\\(,\\(\\s-\\)*\\|$\\|<\\|;\\|=\\)\\(\\sw\\|=\\|<\\|;\\|,\\)*[ \t\n]*\\)+\\)"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (2 casl-other-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Basic signature: op ,pred and var name
b0905caf30330ed73d5363e67c9f1f4576737ee1Heng Jiang '("\\(^\\|\\bops?\\|\\bpreds?\\|\\bvars?\\)\\s-+\\([^.]\\(,\\s-*\\)?\\(\\sw\\(,\\s-*\\)?\\|\\(\\s_\\|\\s_+::?\\s_+\\)\\(,\\s-*\\)?\\|\\s(\\|\\s)\\)*\\)\\s-*\\(\(.*\)\\)?\\s-*\\(:\\??\\|<=>\\)[^:\n]*;?[ \t]*$"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (2 casl-other-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; type name
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang '("\\s-+\\(\\sw+\\)[ \t\n]*::?=\\s-*\\(\\sw*\\).*"
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (1 casl-other-name-face keep t) (2 casl-other-name-face keep t) )
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang ;; constructor
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang '("\\(\\sw+\\)?\\s-*|\\s-*\\(\\sw+\\)\\s-*[|(]?\\([ \t\n]*\\|$\\)"
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (1 casl-other-name-face keep t) (2 casl-other-name-face keep t))
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang ;; in ()1
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang '("\(\\(\\(\\sw\\|,\\)*\\)\\s-*:\\??[^)]*\)"
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang (1 casl-other-name-face keep t))
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang ;; in ()2
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang '("\([^;]*;\\s-*\\(\\sw+\\)\\s-*:\\??.*\)"
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang (1 casl-other-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; names before and after '|->'
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("[ \t\n]*\\([^[ \t\n]+\\)\\s-*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?[ \t\n]+|->[ \t\n]+\\([^[ \t\n]+\\)\\s-*\\(\\[\\([A-Z]\\w*\\).*\\]\\)?[, \t]*"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (1 casl-other-name-face keep t) (3 casl-other-name-face keep t)
31ac08a9e5233b83a63fd5aaac494c32305c4c77Heng Jiang (4 casl-other-name-face keep t) (6 casl-other-name-face keep t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; reserved keyword
3e4305eb6432c65bb0dfe8d9af9707dfc92383eaChristian Maeder '("\\(\\<\\|\\s-+\\)\\(/\\\\\\|\\\\/\\|=>\\|<=>\\|and\\|arch\\|assoc\\|behaviourally\\|closed\\|comm\\|else\\|end\\|exists\\|fit\\|forall\\|free\\|generated\\|given\\|hide\\|idem\\|if\\|local\\|not\\|refined\\|refinement\\|reveal\\|spec\\|then\\|to\\|unit\\|via\\|view\\|when\\|within\\|with\\|\\(\\(op\\|pred\\|var\\|type\\|sort\\)s?\\)\\)[,;]?[ \t\n]"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (2 casl-keyword-face keep t))
f0a4ace924cef940ca4cc646fa180df70ef405d8Klaus Luettich '("[,;]" (0 casl-black-komma-face t t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang )
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Reserved keywords highlighting")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang;; String and Char
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang(defconst casl-font-lock-string
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang (append casl-font-lock-keywords
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang (list '("\\(\\(\"\\|^>[ \t]*\\\\\\)\\([^\"\\\\\n]\\|\\\\.\\)*\\(\"\\|\\\\[ \t]*$\\)\\|'\\([^'\\\\\n]\\|\\\\.[^'\n]*\\)'\\)" (0 casl-string-char-face t t))
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang ))
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang "Syntax highlighting of String and Char")
0b31ea5ec0e20f17d55845a5d803c48466e01ca3Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Alternativ for Annotation
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defconst casl-font-lock-annotations
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (append casl-font-lock-string
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (list
31ac08a9e5233b83a63fd5aaac494c32305c4c77Heng Jiang ;; %word(...)\n
31ac08a9e5233b83a63fd5aaac494c32305c4c77Heng Jiang '("%\\sw+\([^%\n]+\)$" (0 casl-annotation-face t t))
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang ;; %words \n
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang '("%\\w+[^\n]*$" (0 casl-annotation-face t t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; %( ... )%
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("%\([^)%]*\)%[ \t\n]*" (0 casl-annotation-face t t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; %word( ... )%
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '("%\\sw+\([^)%]*\)%[ \t\n]*" (0 casl-annotation-face t t))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Annotation")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang ;; Comment
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang(defconst casl-font-lock-specialcomment
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (append casl-font-lock-annotations
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (list '("\\(%%.*$\\)" (0 casl-comment-face t t))
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang '("\\(%{[^}%]*}%\\)[ \t\n]*" (1 casl-comment-face t t))
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang ))
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang "Special Comment")
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Define default highlighting level
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; (defvar casl-font-lock-syntax-highligthing casl-font-lock-keywords
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang(defvar casl-font-lock-syntax-highligthing casl-font-lock-specialcomment
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Default syntax highlighting level in CASL mode")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; ====================== S Y N T A X T A B L E ==================
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Syntax table for CASL major mode
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defvar casl-mode-syntax-table nil
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Syntax table for CASL mode.")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(if casl-mode-syntax-table
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (let ((table (make-syntax-table)))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Indicate that underscore may be part of a word
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?_ "w" table)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang (modify-syntax-entry ?\t " " table)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang (modify-syntax-entry ?\" "\"" table)
806bce66335c88260a63e7524b1efc68d8dfacc1Heng Jiang (modify-syntax-entry ?\' "\'" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Commnets
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if casl-running-xemacs
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ((modify-syntax-entry ?% ". 58" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?\[ "(] 6" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?\] ")[ 7" table))
f0a4ace924cef940ca4cc646fa180df70ef405d8Klaus Luettich (modify-syntax-entry ?% ". 14nb" table)
f0a4ace924cef940ca4cc646fa180df70ef405d8Klaus Luettich (modify-syntax-entry ?\[ "(] 2n" table)
f0a4ace924cef940ca4cc646fa180df70ef405d8Klaus Luettich (modify-syntax-entry ?\] ")[ 3n" table))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; commenting-out plus including other kinds of comment
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?\( "()" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?\) ")(" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?{ "(}" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry ?} "){" table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (mapcar (lambda (x)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (modify-syntax-entry x "_" table))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Some of these are actually OK by default.
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang "!#$&*+.,/\\\\:<=>?@^|~")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq casl-mode-syntax-table table))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang )
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Various mode variables.
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-vars ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (kill-all-local-variables)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-start)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-start "%[")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-padding)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-padding 0)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-start-skip)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-start-skip "%[%{[] *")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-column)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-column 40)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-indent-function)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-indent-function 'casl-comment-indent)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'comment-end)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq comment-end "]%"))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Find the indentation level for a comment.
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-comment-indent ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (skip-chars-backward " \t")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; if the line is blank, put the comment at the beginning,
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; else at comment-column
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if (bolp) 0 (max (1+ (current-column)) comment-column)))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; ======================= R U N H E T S =======================
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(require 'compile)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
36089fe7ad5167b48f702514056071fd8739faeaHeng Jiang(setq casl-error-list nil)
175c9e5fde43fc804a8d25198133288669b9d54cKlaus Luettich(defvar hets-program nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang(defvar old-buffer nil)
175c9e5fde43fc804a8d25198133288669b9d54cKlaus Luettich
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-run-hets ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Run hets process to compile the current CASL file."
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (interactive)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (save-buffer nil)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq old-buffer (current-buffer))
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (let* ((casl-hets-file-name (buffer-file-name))
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (outbuf (get-buffer-create "*hets-run*")))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if hets-program
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq casl-hets-program hets-program)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq casl-hets-program "hets"))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq hets-command (concat casl-hets-program " " casl-hets-file-name))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Pop up the compilation buffer.
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (set-buffer outbuf)
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (setq buffer-read-only nil)
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (buffer-disable-undo (current-buffer))
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (erase-buffer)
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (buffer-enable-undo (current-buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-buffer-modified-p nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (insert hets-command "\n")
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (pop-to-buffer outbuf)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; (display-buffer outbuf nil t)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (save-excursion
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; (set-buffer outbuf)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (compilation-mode "hets-compile")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Start the compilation.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (fboundp 'start-process)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let* ((process-environment
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (append
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (and (boundp 'system-uses-terminfo)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang system-uses-terminfo)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (list "TERM=dumb" "TERMCAP="
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (format "COLUMNS=%d" (window-width)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (list "TERM=emacs"
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (format "TERMCAP=emacs:co#%d:tc=unknown:"
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (window-width))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Set the EMACS variable, but
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; don't override users' setting of $EMACS.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (getenv "EMACS")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang process-environment
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (cons "EMACS=t" process-environment))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (proc (start-process-shell-command "hets-compile" outbuf
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang hets-command)))
f4152ab9d084afebd592edfcde4bf5a0d8556eddKlaus Luettich (setq buffer-read-only nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-process-sentinel proc 'casl-compilation-sentinel)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-process-filter proc 'casl-compilation-filter)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-marker (process-mark proc) (point) outbuf))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer old-buffer)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
c51b5677113ce7260c44afb3c5932eea6c875e27Heng Jiang
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski(defun casl-run-hetsg ()
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang "Run hets process with -g to compile the current CASL file."
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (interactive)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (save-buffer nil)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (setq old-buffer (current-buffer))
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (let* ((casl-hets-file-name (buffer-file-name))
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (outbuf (get-buffer-create "*hets-run*")))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if hets-program
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq casl-hets-program hets-program)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq casl-hets-program "hets"))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq hets-command (concat casl-hets-program " -g " casl-hets-file-name))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Pop up the compilation buffer.
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (set-buffer outbuf)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (setq buffer-read-only nil)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (buffer-disable-undo (current-buffer))
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (erase-buffer)
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (buffer-enable-undo (current-buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-buffer-modified-p nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (insert hets-command "\n")
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski (pop-to-buffer outbuf)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; (display-buffer outbuf nil t)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (save-excursion
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-buffer outbuf)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (compilation-mode "hets-compile")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Start the compilation.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (fboundp 'start-process)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let* ((process-environment
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (append
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (and (boundp 'system-uses-terminfo)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang system-uses-terminfo)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (list "TERM=dumb" "TERMCAP="
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (format "COLUMNS=%d" (window-width)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (list "TERM=emacs"
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (format "TERMCAP=emacs:co#%d:tc=unknown:"
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (window-width))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Set the EMACS variable, but
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; don't override users' setting of $EMACS.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (getenv "EMACS")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang process-environment
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (cons "EMACS=t" process-environment))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (proc (start-process-shell-command "hets-compile" outbuf
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang hets-command)))
f4152ab9d084afebd592edfcde4bf5a0d8556eddKlaus Luettich (setq buffer-read-only nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-process-sentinel proc 'casl-compilation-sentinel)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-process-filter proc 'casl-compilation-filter)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-marker (process-mark proc) (point) outbuf))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang )))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer old-buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang;; sentinel and filter of asynchronous process of hets
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang;; Called when compilation process changes state.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang(defun casl-compilation-sentinel (proc msg)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang "Sentinel for compilation buffers."
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let ((buffer (process-buffer proc)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (memq (process-status proc) '(signal exit))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (progn
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (null (buffer-name buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; buffer killed
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-process-buffer proc nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let ((obuf (current-buffer)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; save-excursion isn't the right thing if
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; process-buffer is current-buffer
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (unwind-protect
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (progn
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Write something in the compilation buffer
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; and hack its mode line.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-buffer buffer)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (casl-compilation-handle-exit (process-status proc)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (process-exit-status proc)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang msg)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Since the buffer and mode line will show that the
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; process is dead, we can delete it now. Otherwise it
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; will stay around until M-x list-processes.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (delete-process proc))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-buffer obuf))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; (setq compilation-in-progress (delq proc compilation-in-progress))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang;; show the message from hets compile direct on *hets-run* buffer
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang(defun casl-compilation-filter (proc string)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (display-buffer (process-buffer proc))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (unless (equal (buffer-name) "*hets-run*")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (progn
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer "*hets-run*")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (with-current-buffer (process-buffer proc)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let ((moving (= (point) (process-mark proc))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (save-excursion
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Insert the text, advancing the process marker.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (process-mark proc))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (insert string)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (set-marker (process-mark proc) (point)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if moving (goto-char (process-mark proc)))))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer old-buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang(defun casl-compilation-handle-exit (process-status exit-status msg)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang "Write msg in the current buffer and hack its mode-line-process."
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (let ((buffer-read-only nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (status (cons msg exit-status))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (omax (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (opoint (point)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Record where we put the message, so we can ignore it
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; later on.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; (goto-char omax)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (insert ?\n mode-name " " (car status))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (bolp)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (forward-char -1))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (insert " at " (substring (current-time-string) 0 19))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char (point-max))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq mode-line-process (format ":%s [%s]" process-status (cdr status)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Force mode line redisplay soon.
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (force-mode-line-update)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (and opoint (< opoint omax))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char opoint))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; Automatically parse (and mouse-highlight) error messages:
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (if (zerop exit-status)
6c8dc7ab7cb52a12cba748fe0f6b8d8d17a95eb9Heng Jiang (setq casl-error-list nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq casl-error-list nil)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (casl-parse-error)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (message "%s errors have been found." (length casl-error-list)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer old-buffer)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ))
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski
67d5e49547d78aa56a8f9ba5e64a950b730eba66Till Mossakowski
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang;; also functions with old hets-program?
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-parse-error ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Error Parser"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (interactive)
c10df434f8e16b46ccf703bf2e38b799f7bcb38bHeng Jiang (setq casl-error-list nil)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;;;(pop-to-buffer compiler-buffer)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer "*hets-run*")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (goto-char (point-min))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (while (not (eobp))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if (not (or (looking-at "Fail") (looking-at "\\*\\*\\*")))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (forward-line 1)
3d59ee7815197f19948fc512cd90f9f26fd4d78fHeng Jiang (skip-chars-forward "a-zA-Z*,/._\\- ")
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang (if (not (search-forward ":" (save-excursion (end-of-line) (point)) t 1))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (forward-line 1)
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (re-search-backward "\\(\(\\|\\s-+\\)\\([^.]+\\.\\(casl\\|het\\)\\)" nil t 1)
c51b5677113ce7260c44afb3c5932eea6c875e27Heng Jiang (setq file-name (match-string-no-properties 2))
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang (re-search-forward ":\\([0-9]+\\)\\.\\([0-9]+\\)[:,]" (save-excursion (end-of-line) (point)) t 1)
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang (when (not (string= (match-string-no-properties 0) ""))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq error-line (match-string-no-properties 1))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq error-colnum (match-string-no-properties 2))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq error-window-point (point))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq casl-error-list
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (nconc casl-error-list (list (list file-name error-line error-colnum error-window-point))))
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang )
c51b5677113ce7260c44afb3c5932eea6c875e27Heng Jiang (forward-line 1)))))
c51b5677113ce7260c44afb3c5932eea6c875e27Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-compile-goto-next-error ()
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang "search the next error position from error-list, and move to it."
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (interactive)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; if error-list is empty ...
3d59ee7815197f19948fc512cd90f9f26fd4d78fHeng Jiang (if (null casl-error-list)
3d59ee7815197f19948fc512cd90f9f26fd4d78fHeng Jiang (casl-parse-error))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if (null casl-error-list)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if (member (get-buffer "*hets-run*") (buffer-list))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (message "no error.")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (message "this file have not yet been compiled."))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (let* ((this-error (pop casl-error-list))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (error-file-name (nth 0 this-error))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (error-line (nth 1 this-error))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (error-column (nth 2 this-error))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (error-window-point (nth 3 this-error)))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang
b91c4dbd00294ce29ab1ae84ad4e8c93ca5ad943Heng Jiang ;; (message "DEBUG<Goto Error>: file: %s, line: %s, column: %s" error-file-name error-line error-column)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; if the file already opened ...
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (if (get-file-buffer error-file-name)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (pop-to-buffer (get-file-buffer error-file-name))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (generate-new-buffer error-file-name)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (pop-to-buffer error-file-name)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (insert-file-contents error-file-name))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; switch to hets-run window to jump to next error message
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (setq file-buffer (current-buffer))
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer "*hets-run*")
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (goto-char error-window-point)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang ;; return to current file
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang (pop-to-buffer file-buffer)
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang (goto-line (string-to-number error-line))
c51b5677113ce7260c44afb3c5932eea6c875e27Heng Jiang (move-to-column (- (string-to-number error-column) 1))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (message "goto next error... line: %s column: %s" error-line error-column)
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang (setq casl-error-list (nconc casl-error-list (list this-error)))
b3c65285705f6d184b5f8b00b1a328d96b6b19c5Heng Jiang )))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; ================= C A S L M A J O R M O D E ===============
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; Definition of CASL major mode
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(defun casl-mode ()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang "Major mode for editing CASL models"
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (interactive)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (casl-vars)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq major-mode 'casl-mode)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq mode-name "CASL")
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Load keymap
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (use-local-map casl-mode-map)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Load syntax table
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (set-syntax-table casl-mode-syntax-table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; (casl-create-syntax-table)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Highlight CASL keywords
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (make-local-variable 'font-lock-defaults)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (setq font-lock-defaults
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang '(casl-font-lock-syntax-highligthing))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; Support for compile.el
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; We just substitute our own functions to go to the error.
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (add-hook 'compilation-mode-hook
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (lambda()
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (set (make-local-variable 'compile-auto-highlight) 40)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang ;; FIXME: This has global impact! -stef
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (define-key compilation-minor-mode-map [mouse-2]
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang 'casl-compile-mouse-goto-error)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (define-key compilation-minor-mode-map "\C-m"
36089fe7ad5167b48f702514056071fd8739faeaHeng Jiang 'casl-compile-goto-next-error)))
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang (run-hooks 'casl-mode-hook)
44ea7e3effe9200ccc6abd3231ae56cf5cfb0fb8Heng Jiang )
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang(provide 'casl-mode)
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang
95242ab07e9aa13b37c16cac36a75d190e1766e4Heng Jiang;; CASL-mode ends here