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