smalltalk-tng
view r3/tng-r3.el @ 321:c4a0718c2d3c
Sketch of dependencies
| author | Tony Garnock-Jones <tonygarnockjones@gmail.com> |
|---|---|
| date | Sat Oct 08 15:36:03 2011 -0400 (7 months ago) |
| parents | 4f1328b847bb |
| children |
line source
1 ;;; tng-r3.el --- ThiNG r3 code editing commands for Emacs
3 ;; Add code like the following to your .emacs to install:
4 ;; (autoload 'tng-r3-mode "...path.to.wherever.you.put.this.file.../tng-r3.el" nil t)
5 ;; (setq auto-mode-alist (cons '("\\.tng\\'" . tng-r3-mode)
6 ;; auto-mode-alist))
8 ;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc.
9 ;; Copyright (C) 2003, 2005 Tony Garnock-Jones <tonyg@lshift.net>
11 ;; This file is based on GNU Emacs' AWK mode (awk-mode.el).
13 ;; This is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; This is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this software; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
28 (require 'cmuscheme)
29 (require 'comint)
30 (require 'cc-mode)
32 (defvar tng-r3-mode-syntax-table nil
33 "Syntax table in use in tng-r3-mode buffers.")
35 (if tng-r3-mode-syntax-table
36 ()
37 (setq tng-r3-mode-syntax-table (make-syntax-table))
38 (cond ((memq '8-bit c-emacs-features) ;; XEmacs
39 (modify-syntax-entry ?\" "! " tng-r3-mode-syntax-table))
40 ((memq '1-bit c-emacs-features) ;; Proper Emacs
41 (modify-syntax-entry ?\" "! " tng-r3-mode-syntax-table)))
42 (modify-syntax-entry ?_ "_" tng-r3-mode-syntax-table)
43 (mapcar #'(lambda (x) (modify-syntax-entry x "." tng-r3-mode-syntax-table))
44 '(?, ?\; ?- ?+ ?= ?| ?/ ?? ?. ?< ?> ?* ?& ?^ ?% ?$ ?# ?@ ?! ?` ?~))
45 (modify-syntax-entry ?\' "\"" tng-r3-mode-syntax-table))
47 (defconst tng-r3-font-lock-keywords
48 (eval-when-compile
49 (list
50 '(";;" . font-lock-warning-face)
52 ;; Atoms.
53 ;;'("\\.\\<\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-constant-face)
55 ;; Keywords.
56 '("\\<define\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-keyword-face)
57 ;; '("\\<\\(new\\)\\s \\([a-zA-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\|::\\)*\\)\\>"
58 ;; (1 font-lock-keyword-face) (2 font-lock-type-face))
59 (regexp-opt
60 '(
61 "do"
62 "in"
63 "let"
64 "self"
65 ;;"letrec"
66 "module"
67 ;;"new"
68 "return"
69 "case"
70 "of"
71 )
72 'words)
74 ;; Namespaces.
75 '("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>::" . font-lock-type-face)
77 ;; Selectors.
78 ;;'("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>:" . font-lock-function-name-face)
80 ;; Symbols (by convention).
81 '("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-type-face)
82 ;;'("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-constant-face)
84 ;; Functions.
85 ;;'("(\\(\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>\\)\\($\\|\\s [^-+=_|/?<>*&^%$@!`~#]\\)"
86 ;;(1 font-lock-function-name-face))
88 ;; Variables.
89 ;'("+\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-variable-name-face)
90 '("\\.\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>" . font-lock-variable-name-face)
91 ;'("\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>@" . font-lock-variable-name-face)
93 ;; Infixops.
94 '("\\<[-+=_|/?<>*&^%$@!`~]\\([-a-zA-Z0-9+=_|/?<>*&^%$@!`~]\\)*\\>"
95 . font-lock-function-name-face)
96 ))
97 "Default expressions to highlight in TNG-R3 mode.")
99 (defun tng-mode-variables ()
100 (make-local-variable 'comment-start)
101 (make-local-variable 'comment-end)
102 (make-local-variable 'comment-start-skip)
103 (setq comment-start "\"")
104 (setq comment-end "\"")
105 (setq comment-start-skip "\" *")
106 (make-local-variable 'c-syntactic-indentation)
107 (setq c-syntactic-indentation nil)
108 (make-local-variable 'font-lock-defaults)
109 (setq font-lock-defaults '(tng-r3-font-lock-keywords nil nil ((?_ . "w")))))
111 ;;;###autoload
112 (define-derived-mode tng-r3-mode c-mode "TNG-R3"
113 "Major mode for editing TNG-R3 code.
114 This is much like C mode except for the syntax of comments. Its keymap
115 inherits from C mode's and it has the same variables for customizing
116 indentation. It has its own abbrev table and its own syntax table.
118 Turning on TNG-R3 mode runs `tng-r3-mode-hook'." ;; actually a lie
119 (tng-mode-variables))
121 ;---------------------------------------------------------------------------
123 (defcustom tng-program-name "./main.scm"
124 "*Program invoked by the `run-tng' command."
125 :type 'string
126 :group 'tng)
128 (defcustom inferior-tng-mode-hook nil
129 "*Hook for customising inferior-tng mode."
130 :type 'hook
131 :group 'tng)
133 (defvar tng-buffer)
135 (define-derived-mode inferior-tng-mode comint-mode "Inferior ThiNG"
136 "Major mode for interacting with an inferior ThiNG process."
137 ;; Customise in inferior-tng-mode-hook
138 (setq comint-prompt-regexp "^\"[^\"\n]*\" *")
139 (tng-mode-variables)
140 (setq mode-line-process '(":%s")))
142 ;;;###autoload
143 (defun run-tng (cmd)
144 "Run an inferior ThiNG process, input and output via buffer *tng*.
145 If there is a process already running in `*tng*', switch to that buffer.
146 With argument, allows you to edit the command line (default is value
147 of `tng-program-name'). Runs the hooks `inferior-tng-mode-hook'
148 \(after the `comint-mode-hook' is run).
149 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
150 (interactive (list (if current-prefix-arg
151 (read-string "Run ThiNG: " tng-program-name)
152 tng-program-name)))
153 (if (not (comint-check-proc "*tng*"))
154 (let ((cmdlist (scheme-args-to-list cmd)))
155 (set-buffer (apply 'make-comint "tng" (car cmdlist)
156 nil (cdr cmdlist)))
157 (inferior-tng-mode)))
158 (setq tng-program-name cmd)
159 (setq tng-buffer "*tng*")
160 (pop-to-buffer "*tng*"))
162 (provide 'tng-r3-mode)
164 ;;; tng-r3.el ends here
