1 ;; Run-time support for mocklisp code.
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 (defmacro ml-defun
(&rest defs
)
22 (list 'ml-defun-1
(list 'quote defs
)))
24 (defun ml-defun-1 (args)
26 (fset (car (car args
)) (cons 'mocklisp
(cdr (car args
))))
27 (setq args
(cdr args
))))
29 (defmacro declare-buffer-specific
(&rest vars
)
30 (cons 'progn
(mapcar (function (lambda (var) (list 'make-variable-buffer-local
(list 'quote var
)))) vars
)))
32 (defun ml-set-default (varname value
)
33 (set-default (intern varname
) value
))
35 ; Lossage: must make various things default missing args to the prefix arg
36 ; Alternatively, must make provide-prefix-argument do something hairy.
38 (defun >> (val count
) (lsh val
(- count
)))
39 (defun novalue () nil
)
41 (defun ml-not (arg) (if (zerop arg
) 1 0))
43 (defun provide-prefix-arg (arg form
)
44 (funcall (car form
) arg
))
46 (defun define-keymap (name)
47 (fset (intern name
) (make-keymap)))
49 (defun ml-use-local-map (name)
50 (use-local-map (intern (concat name
"-map"))))
52 (defun ml-use-global-map (name)
53 (use-global-map (intern (concat name
"-map"))))
55 (defun local-bind-to-key (name key
)
56 (or (current-local-map)
57 (use-local-map (make-keymap)))
58 (define-key (current-local-map)
61 (concat (char-to-string meta-prefix-char
)
62 (char-to-string (- key
128)))
67 (defun bind-to-key (name key
)
68 (define-key global-map
(if (integerp key
) (char-to-string key
) key
)
71 (defun ml-autoload (name file
)
72 (autoload (intern name
) file
))
74 (defun ml-define-string-macro (name defn
)
75 (fset (intern name
) defn
))
77 (defun push-back-character (char)
78 (setq unread-command-char char
))
80 (defun to-col (column)
83 (defmacro is-bound
(&rest syms
)
84 (cons 'and
(mapcar (function (lambda (sym) (list 'boundp
(list 'quote sym
)))) syms
)))
86 (defmacro declare-global
(&rest syms
)
87 (cons 'progn
(mapcar (function (lambda (sym) (list 'defvar sym nil
))) syms
)))
89 (defmacro error-occurred
(&rest body
)
90 (list 'condition-case nil
(cons 'progn
(append body
'(nil))) '(error t
)))
92 (defun return-prefix-argument (value)
93 (setq prefix-arg value
))
95 (defun ml-prefix-argument ()
96 (if (null current-prefix-arg
) 1
97 (if (listp current-prefix-arg
) (car current-prefix-arg
)
98 (if (eq current-prefix-arg
'-
) -
1
99 current-prefix-arg
))))
101 (defun ml-print (varname)
102 (interactive "vPrint variable: ")
104 (message "%s => %s" (symbol-name varname
) (symbol-value varname
))
105 (message "%s has no value" (symbol-name varname
))))
107 (defun ml-set (str val
) (set (intern str
) val
))
109 (defun ml-message (&rest args
) (message "%s" (apply 'concat args
)))
111 (defun kill-to-end-of-line ()
112 (ml-prefix-argument-loop
114 (kill-region (point) (1+ (point)))
115 (kill-region (point) (if (search-forward ?
\n nil t
)
116 (1- (point)) (point-max))))))
118 (defun set-auto-fill-hook (arg)
119 (setq auto-fill-function
(intern arg
)))
121 (defun auto-execute (function pattern
)
122 (if (/= (aref pattern
0) ?
*)
123 (error "Only patterns starting with * supported in auto-execute"))
124 (setq auto-mode-alist
(cons (cons (concat "\\." (substring pattern
1)
129 (defun move-to-comment-column ()
130 (indent-to comment-column
))
132 (defun erase-region ()
133 (delete-region (point) (mark)))
135 (defun delete-region-to-buffer (bufname)
136 (copy-to-buffer bufname
(point) (mark))
137 (delete-region (point) (mark)))
139 (defun copy-region-to-buffer (bufname)
140 (copy-to-buffer bufname
(point) (mark)))
142 (defun append-region-to-buffer (bufname)
143 (append-to-buffer bufname
(point) (mark)))
145 (defun prepend-region-to-buffer (bufname)
146 (prepend-to-buffer bufname
(point) (mark)))
148 (defun delete-next-character ()
149 (delete-char (ml-prefix-argument)))
151 (defun delete-next-word ()
152 (delete-region (point) (progn (forward-word (ml-prefix-argument)) (point))))
154 (defun delete-previous-word ()
155 (delete-region (point) (progn (backward-word (ml-prefix-argument)) (point))))
157 (defun delete-previous-character ()
158 (delete-backward-char (ml-prefix-argument)))
160 (defun forward-character ()
161 (forward-char (ml-prefix-argument)))
163 (defun backward-character ()
164 (backward-char (ml-prefix-argument)))
167 (newline (ml-prefix-argument)))
169 (defun ml-next-line ()
170 (next-line (ml-prefix-argument)))
172 (defun ml-previous-line ()
173 (previous-line (ml-prefix-argument)))
175 (defun delete-to-kill-buffer ()
176 (kill-region (point) (mark)))
178 (defun narrow-region ()
179 (narrow-to-region (point) (mark)))
181 (defun ml-newline-and-indent ()
182 (let ((column (current-indentation)))
183 (newline (ml-prefix-argument))
186 (defun newline-and-backup ()
187 (open-line (ml-prefix-argument)))
190 (quoted-insert (ml-prefix-argument)))
192 (defun ml-current-column ()
193 (1+ (current-column)))
195 (defun ml-current-indent ()
196 (1+ (current-indentation)))
198 (defun region-around-match (&optional n
)
199 (set-mark (match-beginning n
))
200 (goto-char (match-end n
)))
202 (defun region-to-string ()
203 (buffer-substring (min (point) (mark)) (max (point) (mark))))
205 (defun use-abbrev-table (name)
206 (let ((symbol (intern (concat name
"-abbrev-table"))))
208 (define-abbrev-table symbol nil
))
209 (symbol-value symbol
)))
211 (defun define-hooked-local-abbrev (name exp hook
)
212 (define-local-abbrev name exp
(intern hook
)))
214 (defun define-hooked-global-abbrev (name exp hook
)
215 (define-global-abbrev name exp
(intern hook
)))
217 (defun case-word-lower ()
218 (ml-casify-word 'downcase-region
))
220 (defun case-word-upper ()
221 (ml-casify-word 'upcase-region
))
223 (defun case-word-capitalize ()
224 (ml-casify-word 'capitalize-region
))
226 (defun ml-casify-word (fun)
231 (progn (forward-word (ml-prefix-argument))
234 (defun case-region-lower ()
235 (downcase-region (point) (mark)))
237 (defun case-region-upper ()
238 (upcase-region (point) (mark)))
240 (defun case-region-capitalize ()
241 (capitalize-region (point) (mark)))
243 (defvar saved-command-line-args nil
)
246 (or saved-command-line-args
247 (setq saved-command-line-args command-line-args
248 command-line-args
()))
249 (length command-line-args
))
252 (or saved-command-line-args
253 (setq saved-command-line-args command-line-args
254 command-line-args
()))
255 (nth i saved-command-line-args
))
257 (defun invisible-argc ()
258 (length (or saved-command-line-args
261 (defun invisible-argv (i)
262 (nth i
(or saved-command-line-args
268 (exit-recursive-edit)
269 (error (kill-emacs))))
271 ;; Lisp function buffer-size returns total including invisible;
272 ;; mocklisp wants just visible.
273 (defun ml-buffer-size ()
274 (- (point-max) (point-min)))
276 (defun previous-command ()
279 (defun beginning-of-window ()
280 (goto-char (window-start)))
282 (defun end-of-window ()
283 (goto-char (window-start))
284 (vertical-motion (- (window-height) 2)))
286 (defun ml-search-forward (string)
287 (search-forward string nil nil
(ml-prefix-argument)))
289 (defun ml-re-search-forward (string)
290 (re-search-forward string nil nil
(ml-prefix-argument)))
292 (defun ml-search-backward (string)
293 (search-backward string nil nil
(ml-prefix-argument)))
295 (defun ml-re-search-backward (string)
296 (re-search-backward string nil nil
(ml-prefix-argument)))
298 (defvar use-users-shell
1
299 "Mocklisp compatibility variable; 1 means use shell from SHELL env var.
300 0 means use /bin/sh.")
302 (defvar use-csh-option-f
1
303 "Mocklisp compatibility variable; 1 means pass -f when calling csh.")
305 (defun filter-region (command)
306 (let ((shell (if (/= use-users-shell
0) shell-file-name
"/bin/sh"))
307 (csh (equal (file-name-nondirectory shell
) "csh")))
308 (call-process-region (point) (mark) shell t t nil
309 (if (and csh use-csh-option-f
) "-cf" "-c")
310 (concat "exec " command
))))
312 (defun execute-monitor-command (command)
313 (let ((shell (if (/= use-users-shell
0) shell-file-name
"/bin/sh"))
314 (csh (equal (file-name-nondirectory shell
) "csh")))
315 (call-process shell nil t t
316 (if (and csh use-csh-option-f
) "-cf" "-c")
317 (concat "exec " command
))))
319 (defun use-syntax-table (name)
320 (set-syntax-table (symbol-value (intern (concat name
"-syntax-table")))))
322 (defun line-to-top-of-window ()
323 (recenter (1- (ml-prefix-argument))))
325 (defun ml-previous-page (&optional arg
)
326 (let ((count (or arg
(ml-prefix-argument))))
329 (setq count
(1- count
)))
332 (setq count
(1+ count
)))))
334 (defun ml-next-page ()
335 (previous-page (- (ml-prefix-argument))))
337 (defun page-next-window (&optional arg
)
338 (let ((count (or arg
(ml-prefix-argument))))
340 (scroll-other-window nil
)
341 (setq count
(1- count
)))
343 (scroll-other-window '-
)
344 (setq count
(1+ count
)))))
346 (defun ml-next-window ()
347 (select-window (next-window)))
349 (defun ml-previous-window ()
350 (select-window (previous-window)))
352 (defun scroll-one-line-up ()
353 (scroll-up (ml-prefix-argument)))
355 (defun scroll-one-line-down ()
356 (scroll-down (ml-prefix-argument)))
358 (defun split-current-window ()
359 (split-window (selected-window)))
361 (defun last-key-struck () last-command-char
)
363 (defun execute-mlisp-line (string)
364 (eval (read string
)))
366 (defun move-dot-to-x-y (x y
)
367 (goto-char (window-start (selected-window)))
368 (vertical-motion (1- y
))
369 (move-to-column (1- x
)))
371 (defun ml-modify-syntax-entry (string)
373 (len (length string
))
374 (datastring (substring string
0 2)))
375 (if (= (aref string
0) ?\-
)
376 (aset datastring
0 ?\
))
377 (if (= (aref string
2) ?\
{)
378 (if (= (aref string
4) ?\
)
379 (aset datastring
0 ?\
<)
380 (error "Two-char comment delimiter: use modify-syntax-entry directly")))
381 (if (= (aref string
3) ?\
})
382 (if (= (aref string
4) ?\
)
383 (aset datastring
0 ?\
>)
384 (error "Two-char comment delimiter: use modify-syntax-entry directly")))
386 (modify-syntax-entry (aref string i
) datastring
)
389 (= (aref string i
) ?\-
))
390 (let ((c (aref string
(1- i
)))
391 (lim (aref string
(1+ i
))))
393 (modify-syntax-entry c datastring
)
395 (setq i
(+ 2 i
)))))))
399 (defun ml-substr (string from to
)
400 (let ((length (length string
)))
401 (if (< from
0) (setq from
(+ from length
)))
402 (if (< to
0) (setq to
(+ to length
)))
403 (substring string from
(+ from to
))))