author | Tony Garnock-Jones <tonyg@kcbbs.gen.nz> |
Fri, 21 Oct 2005 20:29:10 +1300 | |
changeset 35 | 0415292cf581 |
parent 34 | 570a02bb7a27 |
child 45 | 604988e365e5 |
permissions | -rw-r--r-- |
33 | 1 |
;;; tng-r3.el --- ThiNG r3 code editing commands for Emacs |
2 |
||
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)) |
|
7 |
||
8 |
;; Copyright (C) 1988,94,96,2000 Free Software Foundation, Inc. |
|
9 |
;; Copyright (C) 2003, 2005 Tony Garnock-Jones <tonyg@lshift.net> |
|
10 |
||
11 |
;; This file is based on GNU Emacs' AWK mode (awk-mode.el). |
|
12 |
||
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. |
|
17 |
||
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. |
|
22 |
||
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. |
|
27 |
||
35
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
28 |
(require 'cmuscheme) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
29 |
(require 'comint) |
33 | 30 |
(require 'cc-mode) |
31 |
||
32 |
(defvar tng-r3-mode-syntax-table nil |
|
33 |
"Syntax table in use in tng-r3-mode buffers.") |
|
34 |
||
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)) |
|
46 |
||
47 |
(defconst tng-r3-font-lock-keywords |
|
48 |
(eval-when-compile |
|
49 |
(list |
|
50 |
'(";;" . font-lock-warning-face) |
|
51 |
||
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
52 |
;; Atoms. |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
53 |
'("#\\<\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>" . font-lock-constant-face) |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
54 |
|
33 | 55 |
;; Keywords. |
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
56 |
'("\\<define\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>" . font-lock-keyword-face) |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
57 |
'("\\<\\(new\\)\\s \\([a-zA-Z]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\|::\\)*\\)\\>" |
33 | 58 |
(1 font-lock-keyword-face) (2 font-lock-type-face)) |
59 |
(regexp-opt |
|
60 |
'( |
|
61 |
"define" |
|
62 |
"in" |
|
63 |
"let" |
|
64 |
"letrec" |
|
65 |
"module" |
|
66 |
"new" |
|
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
67 |
"return" |
33 | 68 |
) |
69 |
'words) |
|
70 |
||
71 |
;; Namespaces. |
|
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
72 |
'("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>::" . font-lock-type-face) |
33 | 73 |
|
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
74 |
;; Types. |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
75 |
'("\\<[A-Z]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>" . font-lock-type-face) |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
76 |
|
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
77 |
;; Functions. |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
78 |
'("(\\(\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>\\)\\($\\|\\s [^-+=_|/?.<>*&^%$@!`~#]\\)" |
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
79 |
(1 font-lock-function-name-face)) |
33 | 80 |
|
81 |
;; Variables. |
|
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
82 |
'("\\<[a-zA-Z]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>" . font-lock-variable-name-face) |
33 | 83 |
|
84 |
;; Infixops. |
|
34
570a02bb7a27
New, more uniform syntax. Evaluator needs updating.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
33
diff
changeset
|
85 |
'("\\<[-+=_|/?.<>*&^%$@!`~]\\([-a-zA-Z0-9+=_|/?.<>*&^%$@!`~]\\)*\\>" |
33 | 86 |
. font-lock-function-name-face) |
87 |
)) |
|
88 |
"Default expressions to highlight in TNG-R3 mode.") |
|
89 |
||
35
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
90 |
(defun tng-mode-variables () |
33 | 91 |
(make-local-variable 'comment-start) |
92 |
(make-local-variable 'comment-end) |
|
93 |
(make-local-variable 'comment-start-skip) |
|
94 |
(setq comment-start "\"") |
|
95 |
(setq comment-end "\"") |
|
96 |
(setq comment-start-skip "\" *") |
|
97 |
(make-local-variable 'c-syntactic-indentation) |
|
98 |
(setq c-syntactic-indentation nil) |
|
99 |
(make-local-variable 'font-lock-defaults) |
|
100 |
(setq font-lock-defaults '(tng-r3-font-lock-keywords nil nil ((?_ . "w"))))) |
|
101 |
||
35
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
102 |
;;;###autoload |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
103 |
(define-derived-mode tng-r3-mode c-mode "TNG-R3" |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
104 |
"Major mode for editing TNG-R3 code. |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
105 |
This is much like C mode except for the syntax of comments. Its keymap |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
106 |
inherits from C mode's and it has the same variables for customizing |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
107 |
indentation. It has its own abbrev table and its own syntax table. |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
108 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
109 |
Turning on TNG-R3 mode runs `tng-r3-mode-hook'." ;; actually a lie |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
110 |
(tng-mode-variables)) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
111 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
112 |
;--------------------------------------------------------------------------- |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
113 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
114 |
(defcustom tng-program-name "./main.scm" |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
115 |
"*Program invoked by the `run-tng' command." |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
116 |
:type 'string |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
117 |
:group 'tng) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
118 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
119 |
(defcustom inferior-tng-mode-hook nil |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
120 |
"*Hook for customising inferior-tng mode." |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
121 |
:type 'hook |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
122 |
:group 'tng) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
123 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
124 |
(defvar tng-buffer) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
125 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
126 |
(define-derived-mode inferior-tng-mode comint-mode "Inferior ThiNG" |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
127 |
"Major mode for interacting with an inferior ThiNG process." |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
128 |
;; Customise in inferior-tng-mode-hook |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
129 |
(setq comint-prompt-regexp "^\"[^\"\n]*\" *") |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
130 |
(tng-mode-variables) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
131 |
(setq mode-line-process '(":%s"))) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
132 |
|
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
133 |
;;;###autoload |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
134 |
(defun run-tng (cmd) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
135 |
"Run an inferior ThiNG process, input and output via buffer *tng*. |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
136 |
If there is a process already running in `*tng*', switch to that buffer. |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
137 |
With argument, allows you to edit the command line (default is value |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
138 |
of `tng-program-name'). Runs the hooks `inferior-tng-mode-hook' |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
139 |
\(after the `comint-mode-hook' is run). |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
140 |
\(Type \\[describe-mode] in the process buffer for a list of commands.)" |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
141 |
(interactive (list (if current-prefix-arg |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
142 |
(read-string "Run ThiNG: " tng-program-name) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
143 |
tng-program-name))) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
144 |
(if (not (comint-check-proc "*tng*")) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
145 |
(let ((cmdlist (scheme-args-to-list cmd))) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
146 |
(set-buffer (apply 'make-comint "tng" (car cmdlist) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
147 |
nil (cdr cmdlist))) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
148 |
(inferior-tng-mode))) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
149 |
(setq tng-program-name cmd) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
150 |
(setq tng-buffer "*tng*") |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
151 |
(pop-to-buffer "*tng*")) |
0415292cf581
Printer for ThiNG CST; improved emacs mode, including comint run-tng.
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
parents:
34
diff
changeset
|
152 |
|
33 | 153 |
(provide 'tng-r3-mode) |
154 |
||
155 |
;;; tng-r3.el ends here |