Annotation of 43BSD/contrib/emacs/lisp/mlsupport.el, revision 1.1.1.1

1.1       root        1: ;; Run-time support for mocklisp code.
                      2: ;; Copyright (C) 1985 Richard M. Stallman.
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     20: 
                     21: 
                     22: (provide 'mlsupport)
                     23: 
                     24: (defmacro ml-defun (&rest defs)
                     25:   (list 'ml-defun-1 (list 'quote defs)))
                     26: 
                     27: (defun ml-defun-1 (args)
                     28:   (while args
                     29:     (fset (car (car args)) (cons 'mocklisp (cdr (car args))))
                     30:     (setq args (cdr args))))
                     31: 
                     32: (defmacro declare-buffer-specific (&rest vars)
                     33:   (cons 'progn (mapcar (function (lambda (var) (list 'make-variable-buffer-local (list 'quote var)))) vars)))
                     34: 
                     35: (defmacro setq-default (var val)
                     36:   (list 'set-default (list 'quote var) val))
                     37: 
                     38: (defun ml-set-default (varname value)
                     39:   (set-default (intern varname) value))
                     40: 
                     41: ; Lossage: must make various things default missing args to the prefix arg
                     42: ; Alternatively, must make provide-prefix-argument do something hairy.
                     43: 
                     44: (defun >> (val count) (lsh val (- count)))
                     45: (defun novalue () nil)
                     46: 
                     47: (defun provide-prefix-arg (arg form)
                     48:   (funcall (car form) arg))
                     49: 
                     50: (defun define-keymap (name)
                     51:   (fset (intern name) (make-keymap)))
                     52: 
                     53: (defun ml-use-local-map (name)
                     54:   (use-local-map (intern (concat name "-map"))))
                     55: 
                     56: (defun ml-use-global-map (name)
                     57:   (use-global-map (intern (concat name "-map"))))
                     58: 
                     59: (defun local-bind-to-key (name key)
                     60:   (or (current-local-map)
                     61:       (use-local-map (make-keymap)))
                     62:   (define-key (current-local-map)
                     63:     (if (integerp key)
                     64:        (if (>= key 128)
                     65:            (concat (char-to-string meta-prefix-char)
                     66:                    (char-to-string (- key 128)))
                     67:          (char-to-string key))
                     68:       key)
                     69:     (intern name)))
                     70: 
                     71: (defun bind-to-key (name key)
                     72:   (define-key global-map (if (integerp key) (char-to-string key) key)
                     73:     (intern name)))
                     74: 
                     75: (defun ml-autoload (name file)
                     76:   (autoload (intern name) file))
                     77: 
                     78: (defun ml-define-string-macro (name defn)
                     79:   (fset (intern name) defn))
                     80: 
                     81: (defun push-back-character (char)
                     82:   (setq unread-command-char char))
                     83: 
                     84: (defun to-col (column)
                     85:   (indent-to column 0))
                     86: 
                     87: (defmacro is-bound (&rest syms)
                     88:   (cons 'and (mapcar (function (lambda (sym) (list 'boundp (list 'quote sym)))) syms)))
                     89: 
                     90: (defmacro declare-global (&rest syms)
                     91:   (cons 'progn (mapcar (function (lambda (sym) (list 'defvar sym nil))) syms)))
                     92: 
                     93: (defmacro error-occurred (&rest body)
                     94:   (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
                     95: 
                     96: (defun return-prefix-argument (value)
                     97:   (setq prefix-arg value))
                     98: 
                     99: (defun ml-prefix-argument ()
                    100:   (if (null current-prefix-arg) 1
                    101:     (if (listp current-prefix-arg) (car current-prefix-arg)
                    102:       (if (eq current-prefix-arg '-) -1
                    103:        current-prefix-arg))))
                    104: 
                    105: (defun ml-print (varname)
                    106:   (interactive "vPrint variable: ")
                    107:   (if (boundp varname)
                    108:     (message "%s => %s" (symbol-name varname) (symbol-value varname))
                    109:     (message "%s has no value" (symbol-name varname))))
                    110: 
                    111: (defun ml-set (str val) (set (intern str) val))
                    112: 
                    113: (defun ml-message (&rest args) (message "%s" (apply 'concat args)))
                    114: 
                    115: (defun kill-to-end-of-line ()
                    116:   (ml-prefix-argument-loop
                    117:     (if (eolp)
                    118:        (kill-region (point) (1+ (point)))
                    119:       (kill-region (point) (if (search-forward ?\n nil t)
                    120:                               (1- (point)) (point-max))))))
                    121: 
                    122: (defun set-auto-fill-hook (arg)
                    123:   (setq auto-fill-hook (intern arg)))
                    124: 
                    125: (defun auto-execute (function pattern)
                    126:   (if (/= (aref pattern 0) ?*)
                    127:       (error "Only patterns starting with * supported in auto-execute"))
                    128:   (setq auto-mode-alist
                    129:        (cons (cons (substring pattern 1) function)
                    130:              auto-mode-alist)))
                    131: 
                    132: (defun move-to-comment-column ()
                    133:   (indent-to comment-column))
                    134: 
                    135: (defun erase-region ()
                    136:   (delete-region (point) (mark)))
                    137: 
                    138: (defun delete-region-to-buffer (bufname)
                    139:   (copy-to-buffer bufname (point) (mark))
                    140:   (delete-region (point) (mark)))
                    141: 
                    142: (defun copy-region-to-buffer (bufname)
                    143:   (copy-to-buffer bufname (point) (mark)))
                    144: 
                    145: (defun append-region-to-buffer (bufname)
                    146:   (append-to-buffer bufname (point) (mark)))
                    147: 
                    148: (defun prepend-region-to-buffer (bufname)
                    149:   (prepend-to-buffer bufname (point) (mark)))
                    150: 
                    151: (defun delete-next-character ()
                    152:   (delete-char (ml-prefix-argument)))
                    153: 
                    154: (defun delete-next-word ()
                    155:   (delete-region (point) (progn (forward-word (ml-prefix-argument)) (point))))
                    156: 
                    157: (defun delete-previous-word ()
                    158:   (delete-region (point) (progn (backward-word (ml-prefix-argument)) (point))))
                    159: 
                    160: (defun delete-previous-character ()
                    161:   (delete-backward-char (ml-prefix-argument)))
                    162: 
                    163: (defun forward-character ()
                    164:   (forward-char (ml-prefix-argument)))
                    165: 
                    166: (defun backward-character ()
                    167:   (backward-char (ml-prefix-argument)))
                    168: 
                    169: (defun ml-newline ()
                    170:   (newline (ml-prefix-argument)))
                    171: 
                    172: (defun ml-next-line ()
                    173:   (next-line (ml-prefix-argument)))
                    174: 
                    175: (defun ml-previous-line ()
                    176:   (previous-line (ml-prefix-argument)))
                    177: 
                    178: (defun delete-to-kill-buffer ()
                    179:   (kill-region (point) (mark)))
                    180: 
                    181: (defun narrow-region ()
                    182:   (narrow-to-region (point) (mark)))
                    183: 
                    184: (defun ml-newline-and-indent ()
                    185:   (let ((column (current-indentation)))
                    186:     (newline (ml-prefix-argument))
                    187:     (indent-to column)))
                    188: 
                    189: (defun newline-and-backup ()
                    190:   (open-line (ml-prefix-argument)))
                    191: 
                    192: (defun quote-char ()
                    193:   (quoted-insert (ml-prefix-argument)))
                    194: 
                    195: (defun ml-current-column ()
                    196:   (1+ (current-column)))
                    197: 
                    198: (defun ml-current-indent ()
                    199:   (1+ (current-indentation)))
                    200: 
                    201: (defun region-around-match (&optional n)
                    202:   (set-mark (match-beginning n))
                    203:   (goto-char (match-end n)))
                    204: 
                    205: (defun region-to-string ()
                    206:   (buffer-substring (min (point) (mark)) (max (point) (mark))))
                    207: 
                    208: (defun use-abbrev-table (name)
                    209:   (let ((symbol (intern (concat name "-abbrev-table"))))
                    210:     (or (boundp symbol)
                    211:        (define-abbrev-table symbol nil))
                    212:     (symbol-value symbol)))
                    213: 
                    214: (defun define-hooked-local-abbrev (name exp hook)
                    215:   (define-local-abbrev name exp (intern hook)))
                    216: 
                    217: (defun define-hooked-global-abbrev (name exp hook)
                    218:   (define-global-abbrev name exp (intern hook)))
                    219: 
                    220: (defun case-word-lower ()
                    221:   (ml-casify-word 'downcase-region))
                    222: 
                    223: (defun case-word-upper ()
                    224:   (ml-casify-word 'upcase-region))
                    225: 
                    226: (defun case-word-capitalize ()
                    227:   (ml-casify-word 'capitalize-region))
                    228: 
                    229: (defun ml-casify-word (fun)
                    230:   (save-excursion
                    231:    (forward-char 1)
                    232:    (forward-word -1)
                    233:    (funcall fun (point)
                    234:            (progn (forward-word (ml-prefix-argument))
                    235:                   (point)))))
                    236: 
                    237: (defun case-region-lower ()
                    238:   (downcase-region (point) (mark)))
                    239: 
                    240: (defun case-region-upper ()
                    241:   (upcase-region (point) (mark)))
                    242: 
                    243: (defun case-region-capitalize ()
                    244:   (capitalize-region (point) (mark)))
                    245: 
                    246: (defun argc ()
                    247:   (setq inhibit-command-line t)
                    248:   (length command-line-args))
                    249: 
                    250: (defun argv (i)
                    251:   (setq inhibit-command-line t)
                    252:   (nth i command-line-args))
                    253: 
                    254: (defun invisible-argc ()
                    255:   (length command-line-args))
                    256: 
                    257: (defun invisible-argv (i)
                    258:   (nth i command-line-args))
                    259: 
                    260: (defun exit-emacs ()
                    261:   (interactive)
                    262:   (condition-case ()
                    263:                  (exit-recursive-edit)
                    264:     (error (kill-emacs))))
                    265: 
                    266: ;; Lisp function buffer-size returns total including invisible;
                    267: ;; mocklisp wants just visible.
                    268: (defun ml-buffer-size ()
                    269:   (- (point-max) (point-min)))
                    270: 
                    271: (defun previous-command ()
                    272:   last-command)
                    273: 
                    274: (defun beginning-of-window ()
                    275:   (goto-char (window-start)))
                    276: 
                    277: (defun end-of-window ()
                    278:   (goto-char (window-start))
                    279:   (vertical-motion (- (window-height) 2)))
                    280: 
                    281: (defun ml-search-forward (string)
                    282:   (search-forward string nil nil (ml-prefix-argument)))
                    283: 
                    284: (defun ml-re-search-forward (string)
                    285:   (re-search-forward string nil nil (ml-prefix-argument)))
                    286: 
                    287: (defun ml-search-backward (string)
                    288:   (search-backward string nil nil (ml-prefix-argument)))
                    289: 
                    290: (defun ml-re-search-backward (string)
                    291:   (re-search-backward string nil nil (ml-prefix-argument)))
                    292: 
                    293: (defvar use-users-shell 1
                    294:   "Mocklisp compatibility variable; 1 means use shell from SHELL env var.
                    295: 0 means use /bin/sh.")
                    296: 
                    297: (defvar use-csh-option-f 1
                    298:   "Mocklisp compatibility variable; 1 means pass -f when calling csh.")
                    299: 
                    300: (defun filter-region (command)
                    301:   (let ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh"))
                    302:        (csh (equal (file-name-nondirectory shell) "csh")))
                    303:     (call-process-region (point) (mark) shell t t nil
                    304:                         (if (and csh use-csh-option-f) "-cf" "-c")
                    305:                         (concat "exec " command))))
                    306: 
                    307: (defun execute-monitor-command (command)
                    308:   (let ((shell (if (/= use-users-shell 0) shell-file-name "/bin/sh"))
                    309:        (csh (equal (file-name-nondirectory shell) "csh")))
                    310:     (call-process shell nil t t
                    311:                  (if (and csh use-csh-option-f) "-cf" "-c")
                    312:                  (concat "exec " command))))
                    313: 
                    314: (defun use-syntax-table (name)
                    315:   (set-syntax-table (symbol-value (intern (concat name "-syntax-table")))))
                    316: 
                    317: (defun line-to-top-of-window ()
                    318:   (recenter (1- (ml-prefix-argument))))
                    319: 
                    320: (defun ml-previous-page (&optional arg)
                    321:   (let ((count (or arg (ml-prefix-argument))))
                    322:     (while (> count 0)
                    323:       (scroll-down nil)
                    324:       (setq count (1- count)))
                    325:     (while (< count 0)
                    326:       (scroll-up nil)
                    327:       (setq count (1+ count)))))
                    328: 
                    329: (defun ml-next-page ()
                    330:   (previous-page (- (ml-prefix-argument))))
                    331: 
                    332: (defun page-next-window (&optional arg)
                    333:   (let ((count (or arg (ml-prefix-argument))))
                    334:     (while (> count 0)
                    335:       (scroll-other-window nil)
                    336:       (setq count (1- count)))
                    337:     (while (< count 0)
                    338:       (scroll-other-window '-)
                    339:       (setq count (1+ count)))))
                    340: 
                    341: (defun ml-next-window ()
                    342:   (select-window (next-window)))
                    343: 
                    344: (defun ml-previous-window ()
                    345:   (select-window (previous-window)))
                    346: 
                    347: (defun scroll-one-line-up ()
                    348:   (scroll-up (ml-prefix-argument)))
                    349: 
                    350: (defun scroll-one-line-down ()
                    351:   (scroll-down (ml-prefix-argument)))
                    352: 
                    353: (defun split-current-window ()
                    354:   (split-window (selected-window)))
                    355: 
                    356: (defun last-key-struck () last-command-char)
                    357: 
                    358: (defun execute-mlisp-line (string)
                    359:   (eval (read string)))
                    360: 
                    361: (defun move-dot-to-x-y (x y)
                    362:   (goto-char (window-start (selected-window)))
                    363:   (vertical-motion (1- y))
                    364:   (move-to-column (1- x)))
                    365: 
                    366: (defun ml-modify-syntax-entry (string)
                    367:   (let ((i 5)
                    368:        (len (length string))
                    369:        (datastring (substring string 0 2)))
                    370:     (if (= (aref string 0) ?\-)
                    371:        (aset datastring 0 ?\ ))
                    372:     (if (= (aref string 2) ?\{)
                    373:        (if (= (aref string 4) ?\ )
                    374:            (aset datastring 0 ?\<)
                    375:          (error "Two-char comment delimiter: use modify-syntax-entry directly")))
                    376:     (if (= (aref string 3) ?\})
                    377:        (if (= (aref string 4) ?\ )
                    378:            (aset datastring 0 ?\>)
                    379:          (error "Two-char comment delimiter: use modify-syntax-entry directly")))
                    380:     (while (< i len)
                    381:       (modify-syntax-entry
                    382:        (aref string i)
                    383:        datastring)
                    384:       (setq i (1+ i))
                    385:       (if (and (< i len)
                    386:               (= (aref string i) ?\-))
                    387:          (let ((c (aref string (1- i)))
                    388:                (lim (aref string (1+ i))))
                    389:            (while (<= c lim)
                    390:              (modify-syntax-entry c datastring)
                    391:              (setq c (1+ c)))
                    392:            (setq i (+ 2 i)))))))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.