Mercurial > hg > xemacs-beta
comparison lisp/emulators/mlconvert.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | b82b59fe008d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; mlconvert.el --- convert buffer of Mocklisp code to real lisp. | |
2 ;; Keywords: emulations | |
3 | |
4 ;; Copyright (C) 1985 Free Software Foundation, Inc. | |
5 | |
6 ;; This file is part of XEmacs. | |
7 | |
8 ;; XEmacs is free software; you can redistribute it and/or modify it | |
9 ;; under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; XEmacs is distributed in the hope that it will be useful, but | |
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 ;; General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 ;;;###autoload | |
23 (defun convert-mocklisp-buffer () | |
24 "Convert buffer of Mocklisp code to real Lisp that GNU Emacs can run." | |
25 (interactive) | |
26 (emacs-lisp-mode) | |
27 (set-syntax-table (copy-sequence (syntax-table))) | |
28 (modify-syntax-entry ?\| "w") | |
29 (message "Converting mocklisp (ugh!)...") | |
30 (goto-char (point-min)) | |
31 (fix-mlisp-syntax) | |
32 | |
33 ;; Emulation of mocklisp is accurate only within a mocklisp-function | |
34 ;; so turn any non-function into a defun and then call it. | |
35 (goto-char (point-min)) | |
36 (condition-case ignore | |
37 (while t | |
38 (let ((opt (point)) | |
39 (form (read (current-buffer)))) | |
40 (and (listp form) | |
41 (not (eq (car form) 'defun)) | |
42 (progn (insert "))\n\n(ml-foo)\n\n") | |
43 (save-excursion | |
44 (goto-char opt) | |
45 (skip-chars-forward "\n") | |
46 (insert "(defun (ml-foo \n ")))))) | |
47 (end-of-file nil)) | |
48 | |
49 (goto-char (point-min)) | |
50 (insert ";;; GNU Emacs code converted from Mocklisp\n") | |
51 (insert "(require 'mlsupport)\n\n") | |
52 (fix-mlisp-symbols) | |
53 | |
54 (goto-char (point-min)) | |
55 (message "Converting mocklisp...done")) | |
56 | |
57 (defun fix-mlisp-syntax () | |
58 (while (re-search-forward "['\"]" nil t) | |
59 (if (= (preceding-char) ?\") | |
60 (progn (forward-char -1) | |
61 (forward-sexp 1)) | |
62 (delete-char -1) | |
63 (insert "?") | |
64 (if (or (= (following-char) ?\\) (= (following-char) ?^)) | |
65 (forward-char 1) | |
66 (if (looking-at "[^a-zA-Z]") | |
67 (insert ?\\))) | |
68 (forward-char 1) | |
69 (delete-char 1)))) | |
70 | |
71 (defun fix-mlisp-symbols () | |
72 (while (progn | |
73 (skip-chars-forward " \t\n()") | |
74 (not (eobp))) | |
75 (cond ((or (= (following-char) ?\?) | |
76 (= (following-char) ?\")) | |
77 (forward-sexp 1)) | |
78 ((= (following-char) ?\;) | |
79 (forward-line 1)) | |
80 (t | |
81 (let ((start (point)) prop) | |
82 (forward-sexp 1) | |
83 (setq prop (get (intern-soft (buffer-substring start (point))) | |
84 'mocklisp)) | |
85 (cond ((null prop)) | |
86 ((stringp prop) | |
87 (delete-region start (point)) | |
88 (insert prop)) | |
89 (t | |
90 (save-excursion | |
91 (goto-char start) | |
92 (funcall prop))))))))) | |
93 | |
94 (defun ml-expansion (ml-name lisp-string) | |
95 (put ml-name 'mocklisp lisp-string)) | |
96 | |
97 (ml-expansion 'defun "ml-defun") | |
98 (ml-expansion 'if "ml-if") | |
99 (ml-expansion 'setq '(lambda () | |
100 (if (looking-at "setq[ \t\n]+buffer-modified-p") | |
101 (replace-match "set-buffer-modified-p")))) | |
102 | |
103 (ml-expansion 'while '(lambda () | |
104 (let ((end (progn (forward-sexp 2) (point-marker))) | |
105 (start (progn (forward-sexp -1) (point)))) | |
106 (let ((cond (buffer-substring start end))) | |
107 (cond ((equal cond "1") | |
108 (delete-region (point) end) | |
109 (insert "t")) | |
110 (t | |
111 (insert "(not (zerop ") | |
112 (goto-char end) | |
113 (insert "))"))) | |
114 (set-marker end nil) | |
115 (goto-char start))))) | |
116 | |
117 (ml-expansion 'arg "ml-arg") | |
118 (ml-expansion 'nargs "ml-nargs") | |
119 (ml-expansion 'interactive "ml-interactive") | |
120 (ml-expansion 'message "ml-message") | |
121 (ml-expansion 'print "ml-print") | |
122 (ml-expansion 'set "ml-set") | |
123 (ml-expansion 'set-default "ml-set-default") | |
124 (ml-expansion 'provide-prefix-argument "ml-provide-prefix-argument") | |
125 (ml-expansion 'prefix-argument-loop "ml-prefix-argument-loop") | |
126 (ml-expansion 'prefix-argument "ml-prefix-arg") | |
127 (ml-expansion 'use-local-map "ml-use-local-map") | |
128 (ml-expansion 'use-global-map "ml-use-global-map") | |
129 (ml-expansion 'modify-syntax-entry "ml-modify-syntax-entry") | |
130 (ml-expansion 'error-message "error") | |
131 | |
132 (ml-expansion 'dot "point-marker") | |
133 (ml-expansion 'mark "mark-marker") | |
134 (ml-expansion 'beginning-of-file "beginning-of-buffer") | |
135 (ml-expansion 'end-of-file "end-of-buffer") | |
136 (ml-expansion 'exchange-dot-and-mark "exchange-point-and-mark") | |
137 (ml-expansion 'set-mark "set-mark-command") | |
138 (ml-expansion 'argument-prefix "universal-arg") | |
139 | |
140 (ml-expansion 'previous-page "ml-previous-page") | |
141 (ml-expansion 'next-page "ml-next-page") | |
142 (ml-expansion 'next-window "ml-next-window") | |
143 (ml-expansion 'previous-window "ml-previous-window") | |
144 | |
145 (ml-expansion 'newline "ml-newline") | |
146 (ml-expansion 'next-line "ml-next-line") | |
147 (ml-expansion 'previous-line "ml-previous-line") | |
148 (ml-expansion 'self-insert "self-insert-command") | |
149 (ml-expansion 'meta-digit "digit-argument") | |
150 (ml-expansion 'meta-minus "negative-argument") | |
151 | |
152 (ml-expansion 'newline-and-indent "ml-newline-and-indent") | |
153 (ml-expansion 'yank-from-killbuffer "yank") | |
154 (ml-expansion 'yank-buffer "insert-buffer") | |
155 (ml-expansion 'copy-region "copy-region-as-kill") | |
156 (ml-expansion 'delete-white-space "delete-horizontal-space") | |
157 (ml-expansion 'widen-region "widen") | |
158 | |
159 (ml-expansion 'forward-word '(lambda () | |
160 (if (looking-at "forward-word[ \t\n]*)") | |
161 (replace-match "forward-word 1)")))) | |
162 (ml-expansion 'backward-word '(lambda () | |
163 (if (looking-at "backward-word[ \t\n]*)") | |
164 (replace-match "backward-word 1)")))) | |
165 | |
166 (ml-expansion 'forward-paren "forward-list") | |
167 (ml-expansion 'backward-paren "backward-list") | |
168 (ml-expansion 'search-reverse "ml-search-backward") | |
169 (ml-expansion 're-search-reverse "ml-re-search-backward") | |
170 (ml-expansion 'search-forward "ml-search-forward") | |
171 (ml-expansion 're-search-forward "ml-re-search-forward") | |
172 (ml-expansion 'quote "regexp-quote") | |
173 (ml-expansion 're-query-replace "query-replace-regexp") | |
174 (ml-expansion 're-replace-string "replace-regexp") | |
175 | |
176 ; forward-paren-bl, backward-paren-bl | |
177 | |
178 (ml-expansion 'get-tty-character "read-char") | |
179 (ml-expansion 'get-tty-input "read-input") | |
180 (ml-expansion 'get-tty-string "read-string") | |
181 (ml-expansion 'get-tty-buffer "read-buffer") | |
182 (ml-expansion 'get-tty-command "read-command") | |
183 (ml-expansion 'get-tty-variable "read-variable") | |
184 (ml-expansion 'get-tty-no-blanks-input "read-no-blanks-input") | |
185 (ml-expansion 'get-tty-key "read-key") | |
186 | |
187 (ml-expansion 'c= "char-equal") | |
188 (ml-expansion 'goto-character "goto-char") | |
189 (ml-expansion 'substr "ml-substr") | |
190 (ml-expansion 'variable-apropos "apropos") | |
191 (ml-expansion 'execute-mlisp-buffer "eval-current-buffer") | |
192 (ml-expansion 'execute-mlisp-file "load") | |
193 (ml-expansion 'visit-file "find-file") | |
194 (ml-expansion 'read-file "find-file") | |
195 (ml-expansion 'write-modified-files "save-some-buffers") | |
196 (ml-expansion 'backup-before-writing "make-backup-files") | |
197 (ml-expansion 'write-file-exit "save-buffers-kill-emacs") | |
198 (ml-expansion 'write-named-file "write-file") | |
199 (ml-expansion 'change-file-name "set-visited-file-name") | |
200 (ml-expansion 'change-buffer-name "rename-buffer") | |
201 (ml-expansion 'buffer-exists "get-buffer") | |
202 (ml-expansion 'delete-buffer "kill-buffer") | |
203 (ml-expansion 'unlink-file "delete-file") | |
204 (ml-expansion 'unlink-checkpoint-files "delete-auto-save-files") | |
205 (ml-expansion 'file-exists "file-exists-p") | |
206 (ml-expansion 'write-current-file "save-buffer") | |
207 (ml-expansion 'change-directory "cd") | |
208 (ml-expansion 'temp-use-buffer "set-buffer") | |
209 (ml-expansion 'fast-filter-region "filter-region") | |
210 | |
211 (ml-expansion 'pending-input "input-pending-p") | |
212 (ml-expansion 'execute-keyboard-macro "call-last-kbd-macro") | |
213 (ml-expansion 'start-remembering "start-kbd-macro") | |
214 (ml-expansion 'end-remembering "end-kbd-macro") | |
215 (ml-expansion 'define-keyboard-macro "name-last-kbd-macro") | |
216 (ml-expansion 'define-string-macro "ml-define-string-macro") | |
217 | |
218 (ml-expansion 'current-column "ml-current-column") | |
219 (ml-expansion 'current-indent "ml-current-indent") | |
220 (ml-expansion 'insert-character "insert") | |
221 | |
222 (ml-expansion 'users-login-name "user-login-name") | |
223 (ml-expansion 'users-full-name "user-full-name") | |
224 (ml-expansion 'current-time "current-time-string") | |
225 (ml-expansion 'current-numeric-time "current-numeric-time-you-lose") | |
226 (ml-expansion 'current-buffer-name "buffer-name") | |
227 (ml-expansion 'current-file-name "buffer-file-name") | |
228 | |
229 (ml-expansion 'local-binding-of "local-key-binding") | |
230 (ml-expansion 'global-binding-of "global-key-binding") | |
231 | |
232 ;defproc (ProcedureType, "procedure-type"); | |
233 | |
234 (ml-expansion 'remove-key-binding "global-unset-key") | |
235 (ml-expansion 'remove-binding "global-unset-key") | |
236 (ml-expansion 'remove-local-binding "local-unset-key") | |
237 (ml-expansion 'remove-all-local-bindings "use-local-map nil") | |
238 (ml-expansion 'autoload "ml-autoload") | |
239 | |
240 (ml-expansion 'checkpoint-frequency "auto-save-interval") | |
241 | |
242 (ml-expansion 'mode-string "mode-name") | |
243 (ml-expansion 'right-margin "fill-column") | |
244 (ml-expansion 'tab-size "tab-width") | |
245 (ml-expansion 'default-right-margin "default-fill-column") | |
246 (ml-expansion 'default-tab-size "default-tab-width") | |
247 (ml-expansion 'buffer-is-modified "(buffer-modified-p)") | |
248 | |
249 (ml-expansion 'file-modified-time "you-lose-on-file-modified-time") | |
250 (ml-expansion 'needs-checkpointing "you-lose-on-needs-checkpointing") | |
251 | |
252 (ml-expansion 'lines-on-screen "set-screen-height") | |
253 (ml-expansion 'columns-on-screen "set-screen-width") | |
254 | |
255 (ml-expansion 'dumped-emacs "t") | |
256 | |
257 (ml-expansion 'buffer-size "ml-buffer-size") | |
258 (ml-expansion 'dot-is-visible "pos-visible-in-window-p") | |
259 | |
260 (ml-expansion 'track-eol-on-^N-^P "track-eol") | |
261 (ml-expansion 'ctlchar-with-^ "ctl-arrow") | |
262 (ml-expansion 'help-on-command-completion-error "completion-auto-help") | |
263 (ml-expansion 'dump-stack-trace "backtrace") | |
264 (ml-expansion 'pause-emacs "suspend-emacs") | |
265 (ml-expansion 'compile-it "compile") | |
266 | |
267 (ml-expansion '!= "/=") | |
268 (ml-expansion '& "logand") | |
269 (ml-expansion '| "logior") | |
270 (ml-expansion '^ "logxor") | |
271 (ml-expansion '! "ml-not") | |
272 (ml-expansion '<< "lsh") | |
273 | |
274 ;Variable pause-writes-files | |
275 |