0
|
1 ;;; mlsupport.el --- run-time support for mocklisp code.
|
|
2
|
|
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6 ;; Keywords: extensions
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
4
|
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
23 ;; 02111-1307, USA.
|
0
|
24
|
4
|
25 ;;; Synched up with: FSF 19.34.
|
0
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ;; This package provides equivalents of certain primitives from Gosling
|
|
30 ;; Emacs (including the commercial UniPress versions). These have an
|
|
31 ;; ml- prefix to distinguish them from native GNU Emacs functions with
|
4
|
32 ;; similar names. The package mlconvert.el translates Mocklisp code
|
0
|
33 ;; to use these names.
|
|
34
|
|
35 ;;; Code:
|
|
36
|
|
37 (or (fboundp 'ml-prefix-argument-loop)
|
|
38 (error "emacs was not compiled with #define MOCKLISP_SUPPORT in config.h"))
|
|
39
|
|
40 (defmacro ml-defun (&rest defs)
|
|
41 (list 'ml-defun-1 (list 'quote defs)))
|
|
42
|
|
43 (defun ml-defun-1 (args)
|
|
44 (while args
|
|
45 (fset (car (car args)) (cons 'mocklisp (cdr (car args))))
|
|
46 (setq args (cdr args))))
|
|
47
|
|
48 (defmacro declare-buffer-specific (&rest vars)
|
|
49 (cons 'progn
|
|
50 (mapcar (function (lambda (var)
|
|
51 (list 'make-variable-buffer-local (list 'quote var))))
|
|
52 vars)))
|
|
53
|
|
54 (defun ml-set-default (varname value)
|
|
55 (set-default (intern varname) value))
|
|
56
|
|
57 ; Lossage: must make various things default missing args to the prefix arg
|
|
58 ; Alternatively, must make provide-prefix-argument do something hairy.
|
|
59
|
|
60 (defun >> (val count)
|
|
61 (lsh val (- count)))
|
|
62 (defun novalue ()
|
|
63 nil)
|
|
64
|
|
65 (defun ml-not (arg)
|
|
66 (if (zerop arg) 1 0))
|
|
67
|
|
68 (defun provide-prefix-arg (arg form)
|
|
69 (funcall (car form) arg))
|
|
70
|
|
71 (defun define-keymap (name)
|
|
72 (fset (intern name) (make-keymap)))
|
|
73
|
4
|
74 ;; Make it work to use ml-use-...-map on "esc" and such.
|
|
75 (fset 'esc-map esc-map)
|
|
76 (fset 'ctl-x-map ctl-x-map)
|
|
77
|
0
|
78 (defun ml-use-local-map (name)
|
|
79 (use-local-map (intern (concat name "-map"))))
|
|
80
|
|
81 (defun ml-use-global-map (name)
|
|
82 (use-global-map (intern (concat name "-map"))))
|
|
83
|
|
84 (defun local-bind-to-key (name key)
|
|
85 (or (current-local-map)
|
|
86 (use-local-map (make-keymap)))
|
|
87 (define-key (current-local-map)
|
|
88 (if (integerp key)
|
|
89 (if (>= key 128)
|
|
90 (concat (char-to-string meta-prefix-char)
|
|
91 (char-to-string (- key 128)))
|
|
92 (char-to-string key))
|
|
93 key)
|
|
94 (intern name)))
|
|
95
|
|
96 (defun bind-to-key (name key)
|
|
97 (define-key global-map (if (integerp key) (char-to-string key) key)
|
|
98 (intern name)))
|
|
99
|
|
100 (defun ml-autoload (name file)
|
|
101 (autoload (intern name) file))
|
|
102
|
|
103 (defun ml-define-string-macro (name defn)
|
|
104 (fset (intern name) defn))
|
|
105
|
|
106 (defun push-back-character (char)
|
|
107 (setq unread-command-event (character-to-event char)))
|
|
108
|
|
109 (defun to-col (column)
|
|
110 (indent-to column 0))
|
|
111
|
|
112 (defmacro is-bound (&rest syms)
|
|
113 (cons 'and (mapcar (function (lambda (sym) (list 'boundp (list 'quote sym)))) syms)))
|
|
114
|
|
115 (defmacro declare-global (&rest syms)
|
|
116 (cons 'progn (mapcar (function (lambda (sym) (list 'defvar sym nil))) syms)))
|
|
117
|
|
118 (defmacro error-occurred (&rest body)
|
|
119 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
|
|
120
|
|
121 (defun return-prefix-argument (value)
|
|
122 (setq prefix-arg value))
|
|
123
|
|
124 (defun ml-prefix-argument ()
|
|
125 (cond ((null current-prefix-arg)
|
|
126 1)
|
|
127 ((listp current-prefix-arg)
|
|
128 (car current-prefix-arg))
|
|
129 ((eq current-prefix-arg '-)
|
|
130 -1)
|
|
131 (t
|
|
132 current-prefix-arg)))
|
|
133
|
|
134 (defun ml-print (varname)
|
|
135 (interactive "vPrint variable: ")
|
|
136 (if (boundp varname)
|
|
137 (message "%s => %s" (symbol-name varname) (symbol-value varname))
|
|
138 (message "%s has no value" (symbol-name varname))))
|
|
139
|
|
140 (defun ml-set (str val) (set (intern str) val))
|
|
141
|
|
142 (defun ml-message (&rest args) (message "%s" (apply 'concat args)))
|
|
143
|
|
144 (defun kill-to-end-of-line ()
|
|
145 (ml-prefix-argument-loop
|
|
146 (if (eolp)
|
|
147 (kill-region (point) (1+ (point)))
|
|
148 (kill-region (point) (if (search-forward ?\n nil t)
|
|
149 (1- (point)) (point-max))))))
|
|
150
|
|
151 (defun set-auto-fill-hook (arg)
|
|
152 (setq auto-fill-function (intern arg)))
|
|
153
|
|
154 (defun auto-execute (function pattern)
|
|
155 (if (/= (aref pattern 0) ?*)
|
|
156 (error "Only patterns starting with * supported in auto-execute"))
|
|
157 (setq auto-mode-alist (cons (cons (concat "\\." (substring pattern 1)
|
|
158 "\\'")
|
|
159 function)
|
|
160 auto-mode-alist)))
|
|
161
|
|
162 (defun move-to-comment-column ()
|
|
163 (indent-to comment-column))
|
|
164
|
|
165 (defun erase-region ()
|
|
166 (delete-region (point) (mark)))
|
|
167
|
|
168 (defun delete-region-to-buffer (bufname)
|
|
169 (copy-to-buffer bufname (point) (mark))
|
|
170 (delete-region (point) (mark)))
|
|
171
|
|
172 (defun copy-region-to-buffer (bufname)
|
|
173 (copy-to-buffer bufname (point) (mark)))
|
|
174
|
|
175 (defun append-region-to-buffer (bufname)
|
|
176 (append-to-buffer bufname (point) (mark)))
|
|
177
|
|
178 (defun prepend-region-to-buffer (bufname)
|
|
179 (prepend-to-buffer bufname (point) (mark)))
|
|
180
|
|
181 (defun delete-next-character ()
|
|
182 (delete-char (ml-prefix-argument)))
|
|
183
|
|
184 (defun delete-next-word ()
|
|
185 (delete-region (point)
|
|
186 (progn (forward-word (ml-prefix-argument)) (point))))
|
|
187
|
|
188 (defun delete-previous-word ()
|
|
189 (delete-region (point)
|
|
190 (progn (backward-word (ml-prefix-argument)) (point))))
|
|
191
|
|
192 (defun delete-previous-character ()
|
|
193 (delete-backward-char (ml-prefix-argument)))
|
|
194
|
|
195 (defun forward-character ()
|
|
196 (forward-char (ml-prefix-argument)))
|
|
197
|
|
198 (defun backward-character ()
|
|
199 (backward-char (ml-prefix-argument)))
|
|
200
|
|
201 (defun ml-newline ()
|
|
202 (newline (ml-prefix-argument)))
|
|
203
|
|
204 (defun ml-next-line ()
|
|
205 (next-line (ml-prefix-argument)))
|
|
206
|
|
207 (defun ml-previous-line ()
|
|
208 (previous-line (ml-prefix-argument)))
|
|
209
|
|
210 (defun delete-to-kill-buffer ()
|
|
211 (kill-region (point) (mark)))
|
|
212
|
|
213 (defun narrow-region ()
|
|
214 (narrow-to-region (point) (mark)))
|
|
215
|
|
216 (defun ml-newline-and-indent ()
|
|
217 (let ((column (current-indentation)))
|
|
218 (newline (ml-prefix-argument))
|
|
219 (indent-to column)))
|
|
220
|
|
221 (defun newline-and-backup ()
|
|
222 (open-line (ml-prefix-argument)))
|
|
223
|
|
224 (defun quote-char ()
|
|
225 (quoted-insert (ml-prefix-argument)))
|
|
226
|
|
227 (defun ml-current-column ()
|
|
228 (1+ (current-column)))
|
|
229
|
|
230 (defun ml-current-indent ()
|
|
231 (1+ (current-indentation)))
|
|
232
|
|
233 (defun region-around-match (&optional n)
|
|
234 (set-mark (match-beginning n))
|
|
235 (goto-char (match-end n)))
|
|
236
|
|
237 (defun region-to-string ()
|
|
238 (buffer-substring (min (point) (mark)) (max (point) (mark))))
|
|
239
|
|
240 (defun use-abbrev-table (name)
|
|
241 (let ((symbol (intern (concat name "-abbrev-table"))))
|
|
242 (or (boundp symbol)
|
|
243 (define-abbrev-table symbol nil))
|
|
244 (symbol-value symbol)))
|
|
245
|
4
|
246 ;; XEmacs
|
0
|
247 (defun define-hooked-local-abbrev (name exp hook)
|
|
248 (define-abbrev (or local-abbrev-table
|
|
249 (error "Major mode has no abbrev table"))
|
|
250 (downcase name)
|
|
251 exp (intern hook)))
|
|
252
|
4
|
253 ;; XEmacs
|
0
|
254 (defun define-hooked-global-abbrev (name exp hook)
|
|
255 (define-abbrev global-abbrev-table (downcase name)
|
|
256 exp (intern hook)))
|
|
257
|
|
258 (defun case-word-lower ()
|
|
259 (ml-casify-word 'downcase-region))
|
|
260
|
|
261 (defun case-word-upper ()
|
|
262 (ml-casify-word 'upcase-region))
|
|
263
|
|
264 (defun case-word-capitalize ()
|
|
265 (ml-casify-word 'capitalize-region))
|
|
266
|
|
267 (defun ml-casify-word (fun)
|
|
268 (save-excursion
|
|
269 (forward-char 1)
|
|
270 (forward-word -1)
|
|
271 (funcall fun (point)
|
|
272 (progn (forward-word (ml-prefix-argument))
|
|
273 (point)))))
|
|
274
|
|
275 (defun case-region-lower ()
|
|
276 (downcase-region (point) (mark)))
|
|
277
|
|
278 (defun case-region-upper ()
|
|
279 (upcase-region (point) (mark)))
|
|
280
|
|
281 (defun case-region-capitalize ()
|
|
282 (capitalize-region (point) (mark)))
|
|
283
|
|
284 (defvar saved-command-line-args nil)
|
|
285
|
|
286 (defun argc ()
|
|
287 (or saved-command-line-args
|
|
288 (setq saved-command-line-args command-line-args
|
|
289 command-line-args ()))
|
|
290 (length command-line-args))
|
|
291
|
|
292 (defun argv (i)
|
|
293 (or saved-command-line-args
|
|
294 (setq saved-command-line-args command-line-args
|
|
295 command-line-args ()))
|
|
296 (nth i saved-command-line-args))
|
|
297
|
|
298 (defun invisible-argc ()
|
|
299 (length (or saved-command-line-args
|
|
300 command-line-args)))
|
|
301
|
|
302 (defun invisible-argv (i)
|
|
303 (nth i (or saved-command-line-args
|
|
304 command-line-args)))
|
|
305
|
|
306 (defun exit-emacs ()
|
|
307 (interactive)
|
|
308 (condition-case ()
|
|
309 (exit-recursive-edit)
|
|
310 (error (kill-emacs))))
|
|
311
|
|
312 ;; Lisp function buffer-size returns total including invisible;
|
|
313 ;; mocklisp wants just visible.
|
|
314 (defun ml-buffer-size ()
|
|
315 (- (point-max) (point-min)))
|
|
316
|
|
317 (defun previous-command ()
|
|
318 last-command)
|
|
319
|
|
320 (defun beginning-of-window ()
|
|
321 (goto-char (window-start)))
|
|
322
|
|
323 (defun end-of-window ()
|
|
324 (goto-char (window-start))
|
|
325 (vertical-motion (- (window-height) 2)))
|
|
326
|
|
327 (defun ml-search-forward (string)
|
|
328 (search-forward string nil nil (ml-prefix-argument)))
|
|
329
|
|
330 (defun ml-re-search-forward (string)
|
|
331 (re-search-forward string nil nil (ml-prefix-argument)))
|
|
332
|
|
333 (defun ml-search-backward (string)
|
|
334 (search-backward string nil nil (ml-prefix-argument)))
|
|
335
|
|
336 (defun ml-re-search-backward (string)
|
|
337 (re-search-backward string nil nil (ml-prefix-argument)))
|
|
338
|
|
339 (defvar use-users-shell 1
|
|
340 "Mocklisp compatibility variable; 1 means use shell from SHELL env var.
|
|
341 0 means use /bin/sh.")
|
|
342
|
|
343 (defvar use-csh-option-f 1
|
|
344 "Mocklisp compatibility variable; 1 means pass -f when calling csh.")
|
|
345
|
4
|
346 ;; XEmacs (FSF bugfix? -sb)
|
0
|
347 (defun filter-region (command)
|
|
348 (let* ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh"))
|
|
349 (csh (equal (file-name-nondirectory shell) "csh")))
|
|
350 (call-process-region (point) (mark) shell t t nil
|
|
351 (if (and csh use-csh-option-f) "-cf" "-c")
|
|
352 (concat "exec " command))))
|
|
353
|
4
|
354 ;; XEmacs (FSF bugfix? -sb)
|
0
|
355 (defun execute-monitor-command (command)
|
|
356 (let* ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh"))
|
|
357 (csh (equal (file-name-nondirectory shell) "csh")))
|
|
358 (call-process shell nil t t
|
|
359 (if (and csh use-csh-option-f) "-cf" "-c")
|
|
360 (concat "exec " command))))
|
|
361
|
|
362 (defun use-syntax-table (name)
|
|
363 (set-syntax-table (symbol-value (intern (concat name "-syntax-table")))))
|
|
364
|
|
365 (defun line-to-top-of-window ()
|
|
366 (recenter (1- (ml-prefix-argument))))
|
|
367
|
|
368 (defun ml-previous-page (&optional arg)
|
|
369 (let ((count (or arg (ml-prefix-argument))))
|
|
370 (while (> count 0)
|
|
371 (scroll-down nil)
|
|
372 (setq count (1- count)))
|
|
373 (while (< count 0)
|
|
374 (scroll-up nil)
|
|
375 (setq count (1+ count)))))
|
|
376
|
|
377 (defun ml-next-page ()
|
|
378 (ml-previous-page (- (ml-prefix-argument))))
|
|
379
|
|
380 (defun page-next-window (&optional arg)
|
|
381 (let ((count (or arg (ml-prefix-argument))))
|
|
382 (while (> count 0)
|
|
383 (scroll-other-window nil)
|
|
384 (setq count (1- count)))
|
|
385 (while (< count 0)
|
|
386 (scroll-other-window '-)
|
|
387 (setq count (1+ count)))))
|
|
388
|
|
389 (defun ml-next-window ()
|
|
390 (select-window (next-window)))
|
|
391
|
|
392 (defun ml-previous-window ()
|
|
393 (select-window (previous-window)))
|
|
394
|
|
395 (defun scroll-one-line-up ()
|
|
396 (scroll-up (ml-prefix-argument)))
|
|
397
|
|
398 (defun scroll-one-line-down ()
|
|
399 (scroll-down (ml-prefix-argument)))
|
|
400
|
|
401 (defun split-current-window ()
|
|
402 (split-window (selected-window)))
|
|
403
|
|
404 (defun last-key-struck () last-command-char)
|
|
405
|
|
406 (defun execute-mlisp-line (string)
|
|
407 (eval (read string)))
|
|
408
|
|
409 (defun move-dot-to-x-y (x y)
|
|
410 (goto-char (window-start (selected-window)))
|
|
411 (vertical-motion (1- y))
|
|
412 (move-to-column (1- x)))
|
|
413
|
|
414 (defun ml-modify-syntax-entry (string)
|
|
415 (let ((i 5)
|
|
416 (len (length string))
|
|
417 (datastring (substring string 0 2)))
|
|
418 (if (= (aref string 0) ?\-)
|
|
419 (aset datastring 0 ?\ ))
|
|
420 (if (= (aref string 2) ?\{)
|
|
421 (if (= (aref string 4) ?\ )
|
|
422 (aset datastring 0 ?\<)
|
|
423 (error "Two-char comment delimiter: use modify-syntax-entry directly")))
|
|
424 (if (= (aref string 3) ?\})
|
|
425 (if (= (aref string 4) ?\ )
|
|
426 (aset datastring 0 ?\>)
|
|
427 (error "Two-char comment delimiter: use modify-syntax-entry directly")))
|
|
428 (while (< i len)
|
|
429 (modify-syntax-entry (aref string i) datastring)
|
|
430 (setq i (1+ i))
|
|
431 (if (and (< i len)
|
|
432 (= (aref string i) ?\-))
|
|
433 (let ((c (aref string (1- i)))
|
|
434 (lim (aref string (1+ i))))
|
|
435 (while (<= c lim)
|
|
436 (modify-syntax-entry c datastring)
|
|
437 (setq c (1+ c)))
|
|
438 (setq i (+ 2 i)))))))
|
|
439
|
|
440
|
|
441
|
|
442 (defun ml-substr (string from to)
|
|
443 (let ((length (length string)))
|
|
444 (if (< from 0) (setq from (+ from length)))
|
|
445 (if (< to 0) (setq to (+ to length)))
|
|
446 (substring string from (+ from to))))
|
|
447
|
4
|
448 ;; XEmacs
|
0
|
449 (defun ml-nargs ()
|
|
450 "Number of arguments to currently executing mocklisp function."
|
|
451 (if (eq mocklisp-arguments 'interactive)
|
|
452 0
|
|
453 (length mocklisp-arguments)))
|
|
454
|
|
455 (defun ml-arg (n prompt)
|
|
456 "Argument number N to currently executing mocklisp function."
|
|
457 (if (eq mocklisp-arguments 'interactive)
|
|
458 (read-from-minibuffer prompt)
|
|
459 ;; Mocklisp likes to be origin 1
|
|
460 (elt mocklisp-arguments (1- n))))
|
|
461
|
|
462 (defun ml-interactive ()
|
|
463 "True if currently executing mocklisp function was called interactively."
|
|
464 (eq mocklisp-arguments 'interactive))
|
|
465
|
|
466 ;; Now in subr.el, because too many loser call it.
|
|
467 ;(defun insert-string (&rest args)
|
|
468 ; "Mocklisp-compatibility insert function.
|
|
469 ;Like the function `insert' except that any argument that is a number
|
|
470 ;is converted into a string by expressing it in decimal. (Yuck!!)"
|
|
471 ; (while args
|
|
472 ; (let ((arg (car args)))
|
|
473 ; (if (integerp arg)
|
|
474 ; (insert (number-to-string arg))
|
|
475 ; (insert arg))
|
|
476 ; (setq args (cdr args)))))
|
|
477
|
|
478 (defun ml-concat (&rest args)
|
|
479 (let ((newargs nil) this)
|
|
480 (while args
|
|
481 (setq this (car args))
|
|
482 (if (numberp this)
|
|
483 (setq this (number-to-string this)))
|
|
484 (setq newargs (cons this newargs)
|
|
485 args (cdr args)))
|
|
486 (apply 'concat (nreverse newargs))))
|
|
487
|
|
488
|
|
489 ;;; Lose, please. None of these should be used in non-automatically-converted
|
|
490 ;;; code, so issue compilation warnings in case someone is using them because
|
|
491 ;;; they don't know any better.
|
|
492
|
|
493 (make-obsolete 'read-no-blanks-input 'read-string)
|
|
494 (make-obsolete 'declare-buffer-specific 'make-variable-buffer-local)
|
|
495 (make-obsolete '>> 'lsh)
|
|
496 (make-obsolete 'novalue 'ignore)
|
|
497 (make-obsolete 'define-keymap "use (fset 'symbol (make-keymap))")
|
|
498 (make-obsolete 'local-bind-to-key 'local-set-key)
|
|
499 (make-obsolete 'bind-to-key 'global-set-key)
|
|
500 (make-obsolete 'to-col 'indent-to)
|
|
501 (make-obsolete 'is-bound 'boundp)
|
|
502 (make-obsolete 'declare-global 'defvar)
|
|
503 (make-obsolete 'error-occurred 'condition-case)
|
|
504 (make-obsolete 'set-auto-fill-hook "set variable auto-fill-function instead")
|
|
505 (make-obsolete 'auto-execute "set variable auto-mode-alist instead")
|
|
506 (make-obsolete 'move-to-comment-column "use (indent-to comment-column)")
|
|
507 (make-obsolete 'erase-region 'delete-region)
|
|
508 (make-obsolete 'delete-region-to-buffer "use copy-to-buffer and delete-region")
|
|
509 (make-obsolete 'copy-region-to-buffer 'copy-to-buffer)
|
|
510 (make-obsolete 'append-region-to-buffer 'append-to-buffer)
|
|
511 (make-obsolete 'prepend-region-to-buffer 'prepend-to-buffer)
|
|
512 (make-obsolete 'delete-next-character 'delete-char)
|
|
513 (make-obsolete 'forward-character 'forward-char)
|
|
514 (make-obsolete 'backward-character 'backward-char)
|
|
515 (make-obsolete 'delete-to-kill-buffer 'kill-region)
|
|
516 (make-obsolete 'narrow-region 'narrow-to-region)
|
|
517 (make-obsolete 'newline-and-backup 'open-line)
|
|
518 (make-obsolete 'quote-char 'quoted-insert)
|
|
519 (make-obsolete 'region-to-string 'buffer-substring)
|
|
520 (make-obsolete 'define-hooked-local-abbrev 'define-abbrev)
|
|
521 (make-obsolete 'define-hooked-global-abbrev 'define-abbrev)
|
|
522 (make-obsolete 'filter-region 'call-process-region)
|
|
523 (make-obsolete 'execute-monitor-command 'call-process)
|
|
524 (make-obsolete 'use-syntax-table 'set-syntax-table)
|
|
525 (make-obsolete 'line-to-top-of-window 'recenter)
|
|
526 (make-obsolete 'insert-string 'insert)
|
|
527
|
|
528 (provide 'mlsupport)
|
|
529
|
|
530 ;;; mlsupport.el ends here
|