Mercurial > emacs
annotate lisp/emulation/mlsupport.el @ 1959:3c827b8110db
(walk-windows): Doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 26 Feb 1993 06:28:04 +0000 |
parents | 2cbd4cfb7f4c |
children | f287613dfc28 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; mlsupport.el --- run-time support for mocklisp code. |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
841 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: extensions |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
35 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
35 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
24 ;;; Code: |
35 | 25 |
26 (defmacro ml-defun (&rest defs) | |
27 (list 'ml-defun-1 (list 'quote defs))) | |
28 | |
29 (defun ml-defun-1 (args) | |
30 (while args | |
31 (fset (car (car args)) (cons 'mocklisp (cdr (car args)))) | |
32 (setq args (cdr args)))) | |
33 | |
34 (defmacro declare-buffer-specific (&rest vars) | |
35 (cons 'progn (mapcar (function (lambda (var) (list 'make-variable-buffer-local (list 'quote var)))) vars))) | |
36 | |
37 (defun ml-set-default (varname value) | |
38 (set-default (intern varname) value)) | |
39 | |
40 ; Lossage: must make various things default missing args to the prefix arg | |
41 ; Alternatively, must make provide-prefix-argument do something hairy. | |
42 | |
43 (defun >> (val count) (lsh val (- count))) | |
44 (defun novalue () nil) | |
45 | |
46 (defun ml-not (arg) (if (zerop arg) 1 0)) | |
47 | |
48 (defun provide-prefix-arg (arg form) | |
49 (funcall (car form) arg)) | |
50 | |
51 (defun define-keymap (name) | |
52 (fset (intern name) (make-keymap))) | |
53 | |
1897
2cbd4cfb7f4c
(esc-map, ctl-x-map): Define as functions.
Richard M. Stallman <rms@gnu.org>
parents:
1820
diff
changeset
|
54 ;; Make it work to use ml-use-...-map on "esc" and such. |
2cbd4cfb7f4c
(esc-map, ctl-x-map): Define as functions.
Richard M. Stallman <rms@gnu.org>
parents:
1820
diff
changeset
|
55 (fset 'esc-map esc-map) |
2cbd4cfb7f4c
(esc-map, ctl-x-map): Define as functions.
Richard M. Stallman <rms@gnu.org>
parents:
1820
diff
changeset
|
56 (fset 'ctl-x-map ctl-x-map) |
2cbd4cfb7f4c
(esc-map, ctl-x-map): Define as functions.
Richard M. Stallman <rms@gnu.org>
parents:
1820
diff
changeset
|
57 |
35 | 58 (defun ml-use-local-map (name) |
59 (use-local-map (intern (concat name "-map")))) | |
60 | |
61 (defun ml-use-global-map (name) | |
62 (use-global-map (intern (concat name "-map")))) | |
63 | |
64 (defun local-bind-to-key (name key) | |
65 (or (current-local-map) | |
66 (use-local-map (make-keymap))) | |
67 (define-key (current-local-map) | |
68 (if (integerp key) | |
69 (if (>= key 128) | |
70 (concat (char-to-string meta-prefix-char) | |
71 (char-to-string (- key 128))) | |
72 (char-to-string key)) | |
73 key) | |
74 (intern name))) | |
75 | |
76 (defun bind-to-key (name key) | |
77 (define-key global-map (if (integerp key) (char-to-string key) key) | |
78 (intern name))) | |
79 | |
80 (defun ml-autoload (name file) | |
81 (autoload (intern name) file)) | |
82 | |
83 (defun ml-define-string-macro (name defn) | |
84 (fset (intern name) defn)) | |
85 | |
86 (defun push-back-character (char) | |
1820
b95bdb97c3e8
JimB's changes from January 18 to present
Jim Blandy <jimb@redhat.com>
parents:
1617
diff
changeset
|
87 (setq unread-command-events (list char))) |
35 | 88 |
89 (defun to-col (column) | |
90 (indent-to column 0)) | |
91 | |
92 (defmacro is-bound (&rest syms) | |
93 (cons 'and (mapcar (function (lambda (sym) (list 'boundp (list 'quote sym)))) syms))) | |
94 | |
95 (defmacro declare-global (&rest syms) | |
96 (cons 'progn (mapcar (function (lambda (sym) (list 'defvar sym nil))) syms))) | |
97 | |
98 (defmacro error-occurred (&rest body) | |
99 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t))) | |
100 | |
101 (defun return-prefix-argument (value) | |
102 (setq prefix-arg value)) | |
103 | |
104 (defun ml-prefix-argument () | |
105 (if (null current-prefix-arg) 1 | |
106 (if (listp current-prefix-arg) (car current-prefix-arg) | |
107 (if (eq current-prefix-arg '-) -1 | |
108 current-prefix-arg)))) | |
109 | |
110 (defun ml-print (varname) | |
111 (interactive "vPrint variable: ") | |
112 (if (boundp varname) | |
113 (message "%s => %s" (symbol-name varname) (symbol-value varname)) | |
114 (message "%s has no value" (symbol-name varname)))) | |
115 | |
116 (defun ml-set (str val) (set (intern str) val)) | |
117 | |
118 (defun ml-message (&rest args) (message "%s" (apply 'concat args))) | |
119 | |
120 (defun kill-to-end-of-line () | |
121 (ml-prefix-argument-loop | |
122 (if (eolp) | |
123 (kill-region (point) (1+ (point))) | |
124 (kill-region (point) (if (search-forward ?\n nil t) | |
125 (1- (point)) (point-max)))))) | |
126 | |
127 (defun set-auto-fill-hook (arg) | |
128 (setq auto-fill-function (intern arg))) | |
129 | |
130 (defun auto-execute (function pattern) | |
131 (if (/= (aref pattern 0) ?*) | |
132 (error "Only patterns starting with * supported in auto-execute")) | |
133 (setq auto-mode-alist (cons (cons (concat "\\." (substring pattern 1) | |
134 "$") | |
135 function) | |
136 auto-mode-alist))) | |
137 | |
138 (defun move-to-comment-column () | |
139 (indent-to comment-column)) | |
140 | |
141 (defun erase-region () | |
142 (delete-region (point) (mark))) | |
143 | |
144 (defun delete-region-to-buffer (bufname) | |
145 (copy-to-buffer bufname (point) (mark)) | |
146 (delete-region (point) (mark))) | |
147 | |
148 (defun copy-region-to-buffer (bufname) | |
149 (copy-to-buffer bufname (point) (mark))) | |
150 | |
151 (defun append-region-to-buffer (bufname) | |
152 (append-to-buffer bufname (point) (mark))) | |
153 | |
154 (defun prepend-region-to-buffer (bufname) | |
155 (prepend-to-buffer bufname (point) (mark))) | |
156 | |
157 (defun delete-next-character () | |
158 (delete-char (ml-prefix-argument))) | |
159 | |
160 (defun delete-next-word () | |
161 (delete-region (point) (progn (forward-word (ml-prefix-argument)) (point)))) | |
162 | |
163 (defun delete-previous-word () | |
164 (delete-region (point) (progn (backward-word (ml-prefix-argument)) (point)))) | |
165 | |
166 (defun delete-previous-character () | |
167 (delete-backward-char (ml-prefix-argument))) | |
168 | |
169 (defun forward-character () | |
170 (forward-char (ml-prefix-argument))) | |
171 | |
172 (defun backward-character () | |
173 (backward-char (ml-prefix-argument))) | |
174 | |
175 (defun ml-newline () | |
176 (newline (ml-prefix-argument))) | |
177 | |
178 (defun ml-next-line () | |
179 (next-line (ml-prefix-argument))) | |
180 | |
181 (defun ml-previous-line () | |
182 (previous-line (ml-prefix-argument))) | |
183 | |
184 (defun delete-to-kill-buffer () | |
185 (kill-region (point) (mark))) | |
186 | |
187 (defun narrow-region () | |
188 (narrow-to-region (point) (mark))) | |
189 | |
190 (defun ml-newline-and-indent () | |
191 (let ((column (current-indentation))) | |
192 (newline (ml-prefix-argument)) | |
193 (indent-to column))) | |
194 | |
195 (defun newline-and-backup () | |
196 (open-line (ml-prefix-argument))) | |
197 | |
198 (defun quote-char () | |
199 (quoted-insert (ml-prefix-argument))) | |
200 | |
201 (defun ml-current-column () | |
202 (1+ (current-column))) | |
203 | |
204 (defun ml-current-indent () | |
205 (1+ (current-indentation))) | |
206 | |
207 (defun region-around-match (&optional n) | |
208 (set-mark (match-beginning n)) | |
209 (goto-char (match-end n))) | |
210 | |
211 (defun region-to-string () | |
212 (buffer-substring (min (point) (mark)) (max (point) (mark)))) | |
213 | |
214 (defun use-abbrev-table (name) | |
215 (let ((symbol (intern (concat name "-abbrev-table")))) | |
216 (or (boundp symbol) | |
217 (define-abbrev-table symbol nil)) | |
218 (symbol-value symbol))) | |
219 | |
220 (defun define-hooked-local-abbrev (name exp hook) | |
221 (define-local-abbrev name exp (intern hook))) | |
222 | |
223 (defun define-hooked-global-abbrev (name exp hook) | |
224 (define-global-abbrev name exp (intern hook))) | |
225 | |
226 (defun case-word-lower () | |
227 (ml-casify-word 'downcase-region)) | |
228 | |
229 (defun case-word-upper () | |
230 (ml-casify-word 'upcase-region)) | |
231 | |
232 (defun case-word-capitalize () | |
233 (ml-casify-word 'capitalize-region)) | |
234 | |
235 (defun ml-casify-word (fun) | |
236 (save-excursion | |
237 (forward-char 1) | |
238 (forward-word -1) | |
239 (funcall fun (point) | |
240 (progn (forward-word (ml-prefix-argument)) | |
241 (point))))) | |
242 | |
243 (defun case-region-lower () | |
244 (downcase-region (point) (mark))) | |
245 | |
246 (defun case-region-upper () | |
247 (upcase-region (point) (mark))) | |
248 | |
249 (defun case-region-capitalize () | |
250 (capitalize-region (point) (mark))) | |
251 | |
252 (defvar saved-command-line-args nil) | |
253 | |
254 (defun argc () | |
255 (or saved-command-line-args | |
256 (setq saved-command-line-args command-line-args | |
257 command-line-args ())) | |
258 (length command-line-args)) | |
259 | |
260 (defun argv (i) | |
261 (or saved-command-line-args | |
262 (setq saved-command-line-args command-line-args | |
263 command-line-args ())) | |
264 (nth i saved-command-line-args)) | |
265 | |
266 (defun invisible-argc () | |
267 (length (or saved-command-line-args | |
268 command-line-args))) | |
269 | |
270 (defun invisible-argv (i) | |
271 (nth i (or saved-command-line-args | |
272 command-line-args))) | |
273 | |
274 (defun exit-emacs () | |
275 (interactive) | |
276 (condition-case () | |
277 (exit-recursive-edit) | |
278 (error (kill-emacs)))) | |
279 | |
280 ;; Lisp function buffer-size returns total including invisible; | |
281 ;; mocklisp wants just visible. | |
282 (defun ml-buffer-size () | |
283 (- (point-max) (point-min))) | |
284 | |
285 (defun previous-command () | |
286 last-command) | |
287 | |
288 (defun beginning-of-window () | |
289 (goto-char (window-start))) | |
290 | |
291 (defun end-of-window () | |
292 (goto-char (window-start)) | |
293 (vertical-motion (- (window-height) 2))) | |
294 | |
295 (defun ml-search-forward (string) | |
296 (search-forward string nil nil (ml-prefix-argument))) | |
297 | |
298 (defun ml-re-search-forward (string) | |
299 (re-search-forward string nil nil (ml-prefix-argument))) | |
300 | |
301 (defun ml-search-backward (string) | |
302 (search-backward string nil nil (ml-prefix-argument))) | |
303 | |
304 (defun ml-re-search-backward (string) | |
305 (re-search-backward string nil nil (ml-prefix-argument))) | |
306 | |
307 (defvar use-users-shell 1 | |
308 "Mocklisp compatibility variable; 1 means use shell from SHELL env var. | |
309 0 means use /bin/sh.") | |
310 | |
311 (defvar use-csh-option-f 1 | |
312 "Mocklisp compatibility variable; 1 means pass -f when calling csh.") | |
313 | |
314 (defun filter-region (command) | |
315 (let ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh")) | |
316 (csh (equal (file-name-nondirectory shell) "csh"))) | |
317 (call-process-region (point) (mark) shell t t nil | |
318 (if (and csh use-csh-option-f) "-cf" "-c") | |
319 (concat "exec " command)))) | |
320 | |
321 (defun execute-monitor-command (command) | |
322 (let ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh")) | |
323 (csh (equal (file-name-nondirectory shell) "csh"))) | |
324 (call-process shell nil t t | |
325 (if (and csh use-csh-option-f) "-cf" "-c") | |
326 (concat "exec " command)))) | |
327 | |
328 (defun use-syntax-table (name) | |
329 (set-syntax-table (symbol-value (intern (concat name "-syntax-table"))))) | |
330 | |
331 (defun line-to-top-of-window () | |
332 (recenter (1- (ml-prefix-argument)))) | |
333 | |
334 (defun ml-previous-page (&optional arg) | |
335 (let ((count (or arg (ml-prefix-argument)))) | |
336 (while (> count 0) | |
337 (scroll-down nil) | |
338 (setq count (1- count))) | |
339 (while (< count 0) | |
340 (scroll-up nil) | |
341 (setq count (1+ count))))) | |
342 | |
343 (defun ml-next-page () | |
344 (previous-page (- (ml-prefix-argument)))) | |
345 | |
346 (defun page-next-window (&optional arg) | |
347 (let ((count (or arg (ml-prefix-argument)))) | |
348 (while (> count 0) | |
349 (scroll-other-window nil) | |
350 (setq count (1- count))) | |
351 (while (< count 0) | |
352 (scroll-other-window '-) | |
353 (setq count (1+ count))))) | |
354 | |
355 (defun ml-next-window () | |
356 (select-window (next-window))) | |
357 | |
358 (defun ml-previous-window () | |
359 (select-window (previous-window))) | |
360 | |
361 (defun scroll-one-line-up () | |
362 (scroll-up (ml-prefix-argument))) | |
363 | |
364 (defun scroll-one-line-down () | |
365 (scroll-down (ml-prefix-argument))) | |
366 | |
367 (defun split-current-window () | |
368 (split-window (selected-window))) | |
369 | |
370 (defun last-key-struck () last-command-char) | |
371 | |
372 (defun execute-mlisp-line (string) | |
373 (eval (read string))) | |
374 | |
375 (defun move-dot-to-x-y (x y) | |
376 (goto-char (window-start (selected-window))) | |
377 (vertical-motion (1- y)) | |
378 (move-to-column (1- x))) | |
379 | |
380 (defun ml-modify-syntax-entry (string) | |
381 (let ((i 5) | |
382 (len (length string)) | |
383 (datastring (substring string 0 2))) | |
384 (if (= (aref string 0) ?\-) | |
385 (aset datastring 0 ?\ )) | |
386 (if (= (aref string 2) ?\{) | |
387 (if (= (aref string 4) ?\ ) | |
388 (aset datastring 0 ?\<) | |
389 (error "Two-char comment delimiter: use modify-syntax-entry directly"))) | |
390 (if (= (aref string 3) ?\}) | |
391 (if (= (aref string 4) ?\ ) | |
392 (aset datastring 0 ?\>) | |
393 (error "Two-char comment delimiter: use modify-syntax-entry directly"))) | |
394 (while (< i len) | |
395 (modify-syntax-entry (aref string i) datastring) | |
396 (setq i (1+ i)) | |
397 (if (and (< i len) | |
398 (= (aref string i) ?\-)) | |
399 (let ((c (aref string (1- i))) | |
400 (lim (aref string (1+ i)))) | |
401 (while (<= c lim) | |
402 (modify-syntax-entry c datastring) | |
403 (setq c (1+ c))) | |
404 (setq i (+ 2 i))))))) | |
405 | |
406 | |
407 | |
408 (defun ml-substr (string from to) | |
409 (let ((length (length string))) | |
410 (if (< from 0) (setq from (+ from length))) | |
411 (if (< to 0) (setq to (+ to length))) | |
412 (substring string from (+ from to)))) | |
584 | 413 |
414 (provide 'mlsupport) | |
415 | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
416 ;;; mlsupport.el ends here |