daveg@csvax.cs.caltech.edu (David Gillespie) (10/15/90)
Posting-number: Volume 15, Issue 47 Submitted-by: daveg@csvax.cs.caltech.edu (David Gillespie) Archive-name: calc-1.05/part20 #!/bin/sh # this is part 20 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file calc.patch continued # CurArch=20 if test ! -r s2_seq_.tmp then echo "Please unpack part 1 first!" exit 1; fi ( read Scheck if test "$Scheck" != $CurArch then echo "Please unpack part $Scheck next!" exit 1; else exit 0; fi ) < s2_seq_.tmp || exit 1 sed 's/^X//' << 'SHAR_EOF' >> calc.patch X+ ((and (eq key-symbol 'quoted-insert) X+ (MacEdit-peek-char)) X+ (insert "quoted-insert\n") X+ (let ((ch (MacEdit-read-char)) X+ ch2) X+ (if (and (>= ch ?0) (<= ch ?7)) X+ (progn X+ (setq ch (- ch ?0) X+ ch2 (MacEdit-read-char)) X+ (if ch2 X+ (if (and (>= ch2 ?0) (<= ch2 ?7)) X+ (progn X+ (setq ch (+ (* ch 8) (- ch2 ?0)) X+ ch2 (MacEdit-read-char)) X+ (if ch2 X+ (if (and (>= ch2 ?0) (<= ch2 ?7)) X+ (setq ch (+ (* ch 8) (- ch2 ?0))) X+ (MacEdit-unread-chars ch2)))) X+ (MacEdit-unread-chars ch2))))) X+ (if (or (and (>= ch ?0) (<= ch ?7)) X+ (< ch 32) (> ch 126)) X+ (insert (format "type \"\\%03o\"\n" ch)) X+ (insert "type \"" (char-to-string ch) "\"\n")))) X+ ((memq key-symbol '(isearch-forward X+ isearch-backward X+ isearch-forward-regexp X+ isearch-backward-regexp)) X+ (insert (symbol-name key-symbol) "\n") X+ (MacEdit-isearch-argument)) X+ ((eq key-symbol 'execute-extended-command) X+ (MacEdit-read-argument obarray 'commandp)) X+ (t X+ (let ((cust (get key-symbol 'MacEdit-print))) X+ (if cust X+ (funcall cust) X+ (insert (symbol-name key-symbol)) X+ (indent-to 30) X+ (insert " # ") X+ (MacEdit-insert-string key-str) X+ (insert "\n") X+ (let ((int (MacEdit-get-interactive key-symbol))) X+ (if (string-match "\\`\\*" int) X+ (setq int (substring int 1))) X+ (while (> (length int) 0) X+ (cond ((= (aref int 0) ?a) X+ (MacEdit-read-argument X+ obarray nil)) X+ ((memq (aref int 0) '(?b ?B ?D ?f ?F ?n X+ ?s ?S ?x ?X)) X+ (MacEdit-read-argument)) X+ ((and (= (aref int 0) ?c) X+ (MacEdit-peek-char)) X+ (insert "type \"") X+ (MacEdit-insert-string X+ (char-to-string X+ (MacEdit-read-char))) X+ (insert "\"\n")) X+ ((= (aref int 0) ?C) X+ (MacEdit-read-argument X+ obarray 'commandp)) X+ ((= (aref int 0) ?k) X+ (MacEdit-read-key) X+ (if key-symbol X+ (progn X+ (insert "type \"") X+ (MacEdit-insert-string key-str) X+ (insert "\"\n")) X+ (MacEdit-unread-chars key-str))) X+ ((= (aref int 0) ?N) X+ (or this-prefix X+ (MacEdit-read-argument))) X+ ((= (aref int 0) ?v) X+ (MacEdit-read-argument X+ obarray 'user-variable-p))) X+ (let ((nl (string-match "\n" int))) X+ (setq int (if nl X+ (substring int (1+ nl)) X+ ""))))))))))) X+ (use-local-map save-map))) X+ ) X+ X+ (defun MacEdit-prefix-arg (char c-u value) X+ (let ((sign 1)) X+ (if (and (numberp value) (< value 0)) X+ (setq sign -1 value (- value))) X+ (if (eq value '-) X+ (setq sign -1 value nil)) X+ (while (and char (= ?- char)) X+ (setq sign (- sign) c-u nil) X+ (setq char (MacEdit-read-char))) X+ (while (and char (>= char ?0) (<= char ?9)) X+ (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)) c-u nil) X+ (setq char (MacEdit-read-char))) X+ (setq prefix-arg X+ (cond (c-u (list c-u)) X+ ((numberp value) (* value sign)) X+ ((= sign -1) '-))) X+ (MacEdit-unread-chars char)) X+ ) X+ X+ (defun MacEdit-insert-string (str) X+ (let ((i 0) j ch) X+ (while (< i (length str)) X+ (if (and (> (setq ch (aref str i)) 127) X+ (< ch 160)) X+ (progn X+ (setq ch (- ch 128)) X+ (insert "\\M-"))) X+ (if (< ch 32) X+ (cond ((= ch 8) (insret "\\b")) X+ ((= ch 9) (insert "\\t")) X+ ((= ch 10) (insert "\\n")) X+ ((= ch 13) (insert "\\r")) X+ ((= ch 27) (insert "\\e")) X+ (t (insert "\\C-" (char-to-string (downcase (+ ch 64)))))) X+ (if (< ch 127) X+ (if (or (= ch 34) (= ch 92)) X+ (insert "\\" (char-to-string ch)) X+ (setq j i) X+ (while (and (< (setq i (1+ i)) (length str)) X+ (>= (setq ch (aref str i)) 32) X+ (/= ch 34) (/= ch 92) X+ (< ch 127))) X+ (insert (substring str j i)) X+ (setq i (1- i))) X+ (if (memq ch '(127 255)) X+ (insert (format "\\%03o" ch)) X+ (insert "\\M-" (char-to-string (- ch 128)))))) X+ (setq i (1+ i)))) X+ ) X+ X+ (defun MacEdit-lookup-key (map) X+ (let ((loc (and map (lookup-key map macro-str))) X+ (glob (lookup-key (current-global-map) macro-str)) X+ (loc-str macro-str) X+ (glob-str macro-str)) X+ (and (integerp loc) X+ (setq loc-str (substring macro-str 0 loc) X+ loc (lookup-key map loc-str))) X+ (and (consp loc) X+ (setq loc nil)) X+ (or loc X+ (setq loc-str "")) X+ (and (integerp glob) X+ (setq glob-str (substring macro-str 0 glob) X+ glob (lookup-key (current-global-map) glob-str))) X+ (and (consp glob) X+ (setq glob nil)) X+ (or glob X+ (setq glob-str "")) X+ (if (> (length glob-str) (length loc-str)) X+ (setq key-symbol glob X+ key-str glob-str) X+ (setq key-symbol loc X+ key-str loc-str)) X+ (setq key-last (and (> (length key-str) 0) X+ (logand (aref key-str (1- (length key-str))) 127))) X+ key-symbol) X+ ) X+ X+ (defun MacEdit-read-argument (&optional obarray pred) ;; currently ignored X+ (let ((str "") X+ (min-bsp 0) X+ (exec (eq key-symbol 'execute-extended-command)) X+ str-base) X+ (while (progn X+ (MacEdit-lookup-key (current-global-map)) X+ (or (and (eq key-symbol 'self-insert-command) X+ (< (length str) 60)) X+ (memq key-symbol X+ '(backward-delete-char X+ delete-backward-char X+ backward-delete-char-untabify)) X+ (eq key-last 9))) X+ (setq macro-str (substring macro-str (length key-str))) X+ (or (and (eq key-last 9) X+ obarray X+ (let ((comp (try-completion str obarray pred))) X+ (and (stringp comp) X+ (> (length comp) (length str)) X+ (setq str comp)))) X+ (if (or (eq key-symbol 'self-insert-command) X+ (and (or (eq key-last 9) X+ (<= (length str) min-bsp)) X+ (setq min-bsp (+ (length str) (length key-str))))) X+ (setq str (concat str key-str)) X+ (setq str (substring str 0 -1))))) X+ (setq str-base str X+ str (concat str key-str) X+ macro-str (substring macro-str (length key-str))) X+ (if exec X+ (let ((comp (try-completion str-base obarray pred))) X+ (if (if (stringp comp) X+ (and (commandp (intern comp)) X+ (setq str-base comp)) X+ (commandp (intern str-base))) X+ (insert str-base "\n") X+ (insert "execute-extended-command\n") X+ (insert "type \"") X+ (MacEdit-insert-string str) X+ (insert "\"\n"))) X+ (if (> (length str) 0) X+ (progn X+ (insert "type \"") X+ (MacEdit-insert-string str) X+ (insert "\"\n"))))) X+ ) X+ X+ (defun MacEdit-isearch-argument () X+ (let ((str "") X+ (min-bsp 0) X+ ch) X+ (while (and (setq ch (MacEdit-read-char)) X+ (or (<= ch 127) (not search-exit-option)) X+ (not (eq ch search-exit-char)) X+ (or (eq ch search-repeat-char) X+ (eq ch search-reverse-char) X+ (eq ch search-delete-char) X+ (eq ch search-yank-word-char) X+ (eq ch search-yank-line-char) X+ (eq ch search-quote-char) X+ (eq ch ?\r) X+ (eq ch ?\t) X+ (not search-exit-option) X+ (and (/= ch 127) (>= ch 32)))) X+ (if (and (eq ch search-quote-char) X+ (MacEdit-peek-char)) X+ (setq str (concat str (char-to-string ch) X+ (char-to-string (MacEdit-read-char))) X+ min-bsp (length str)) X+ (if (or (and (< ch 127) (>= ch 32)) X+ (eq ch search-yank-word-char) X+ (eq ch search-yank-line-char) X+ (and (or (not (eq ch search-delete-char)) X+ (<= (length str) min-bsp)) X+ (setq min-bsp (1+ (length str))))) X+ (setq str (concat str (char-to-string ch))) X+ (setq str (substring str 0 -1))))) X+ (if (eq ch search-exit-char) X+ (if (= (length str) 0) ;; non-incremental search X+ (progn X+ (setq str (concat str (char-to-string ch))) X+ (and (eq (MacEdit-peek-char) ?\C-w) X+ (progn X+ (setq str (concat str "\C-w")) X+ (MacEdit-read-char))) X+ (if (> (length str) 0) X+ (progn X+ (insert "type \"") X+ (MacEdit-insert-string str) X+ (insert "\"\n"))) X+ (MacEdit-read-argument) X+ (setq str ""))) X+ (MacEdit-unread-chars ch)) X+ (if (> (length str) 0) X+ (progn X+ (insert "type \"") X+ (MacEdit-insert-string str) X+ (insert "\\e\"\n")))) X+ ) X+ X+ ;;; Get the next keystroke-sequence from the input stream. X+ ;;; Sets key-symbol, key-str, and key-last as a side effect. X+ (defun MacEdit-read-key () X+ (MacEdit-lookup-key (current-local-map)) X+ (and key-symbol X+ (setq macro-str (substring macro-str (length key-str)))) X+ ) X+ X+ (defun MacEdit-peek-char () X+ (and (> (length macro-str) 0) X+ (aref macro-str 0)) X+ ) X+ X+ (defun MacEdit-read-char () X+ (and (> (length macro-str) 0) X+ (prog1 X+ (aref macro-str 0) X+ (setq macro-str (substring macro-str 1)))) X+ ) X+ X+ (defun MacEdit-unread-chars (chars) X+ (and (integerp chars) X+ (setq chars (char-to-string chars))) X+ (and chars X+ (setq macro-str (concat chars macro-str))) X+ ) X+ X+ (defun MacEdit-dump (mac) X+ (set-mark-command nil) X+ (insert "\n\n") X+ (MacEdit-print-macro mac (current-local-map)) X+ ) X+ X+ X+ X+ ;;; Parse a string of spelled-out keystrokes, as produced by key-description. X+ X+ (defun MacEdit-parse-keys (str) X+ (let ((pos 0) X+ (mac "") X+ part) X+ (while (and (< pos (length str)) X+ (string-match "[^ \t\n]+" str pos)) X+ (setq pos (match-end 0) X+ part (substring str (match-beginning 0) (match-end 0)) X+ mac (concat mac X+ (if (and (> (length part) 2) X+ (= (aref part 1) ?-) X+ (= (aref part 0) ?M)) X+ (progn X+ (setq part (substring part 2)) X+ "\e") X+ (if (and (> (length part) 4) X+ (= (aref part 0) ?C) X+ (= (aref part 1) ?-) X+ (= (aref part 2) ?M) X+ (= (aref part 3) ?-)) X+ (progn X+ (setq part (concat "C-" (substring part 4))) X+ "\e") X+ "")) X+ (or (cdr (assoc part '( ( "NUL" . "\0" ) X+ ( "RET" . "\r" ) X+ ( "LFD" . "\n" ) X+ ( "TAB" . "\t" ) X+ ( "ESC" . "\e" ) X+ ( "SPC" . " " ) X+ ( "DEL" . "\177" ) X+ ( "C-?" . "\177" ) X+ ( "C-2" . "\0" ) X+ ( "C-SPC" . "\0") ))) X+ (and (equal part "REM") X+ (setq pos (or (string-match "\n" str pos) X+ (length str))) X+ "") X+ (and (= (length part) 3) X+ (= (aref part 0) ?C) X+ (= (aref part 1) ?-) X+ (char-to-string (logand (aref part 2) 31))) X+ part)))) X+ mac) X+ ) X+ X+ X+ X+ X+ ;;; Parse a keyboard macro description in MacEdit-print-macro's format. X+ X+ (defun MacEdit-read-macro (&optional map) X+ (or map (setq map (current-local-map))) X+ (let ((macro-str "")) X+ (while (not (progn X+ (skip-chars-forward " \t\n") X+ (eobp))) X+ (cond ((looking-at "#")) ;; comment X+ ((looking-at "prefix-arg[ \t]*-[ \t]*\n") X+ (MacEdit-append-chars "\C-u-")) X+ ((looking-at "prefix-arg[ \t]*\\(-?[0-9]+\\)[ \t]*\n") X+ (MacEdit-append-chars (concat "\C-u" (MacEdit-match-string 1)))) X+ ((looking-at "prefix-arg[ \t]*(\\([0-9]+\\))[ \t]*\n") X+ (let ((val (string-to-int (MacEdit-match-string 1)))) X+ (while (> val 1) X+ (or (= (% val 4) 0) X+ (error "Bad prefix argument value")) X+ (MacEdit-append-chars "\C-u") X+ (setq val (/ val 4))))) X+ ((looking-at "prefix-arg") X+ (error "Bad prefix argument syntax")) X+ ((looking-at "insert ") X+ (forward-char 7) X+ (MacEdit-append-chars (read (current-buffer))) X+ (if (< (current-column) 7) X+ (forward-line -1))) X+ ((looking-at "type ") X+ (forward-char 5) X+ (MacEdit-append-chars (read (current-buffer))) X+ (if (< (current-column) 5) X+ (forward-line -1))) X+ ((looking-at "keys \\(.*\\)\n") X+ (goto-char (1- (match-end 0))) X+ (MacEdit-append-chars (MacEdit-parse-keys X+ (buffer-substring (match-beginning 1) X+ (match-end 1))))) X+ ((looking-at "\\([-a-zA-z0-9_]+\\)[ \t]*\\(.*\\)\n") X+ (let* ((func (intern (MacEdit-match-string 1))) X+ (arg (MacEdit-match-string 2)) X+ (cust (get func 'MacEdit-read))) X+ (if cust X+ (funcall cust arg) X+ (or (commandp func) X+ (error "Not an Emacs command")) X+ (or (equal arg "") X+ (string-match "\\`#" arg) X+ (error "Unexpected argument to command")) X+ (let ((keys X+ (or (where-is-internal func map t) X+ (where-is-internal func (current-global-map) t)))) X+ (if keys X+ (MacEdit-append-chars keys) X+ (MacEdit-append-chars (concat "\ex" X+ (symbol-name func) X+ "\n"))))))) X+ (t (error "Syntax error"))) X+ (forward-line 1)) X+ macro-str) X+ ) X+ X+ (defun MacEdit-append-chars (chars) X+ (setq macro-str (concat macro-str chars)) X+ ) X+ X+ (defun MacEdit-match-string (n) X+ (if (match-beginning n) X+ (buffer-substring (match-beginning n) (match-end n)) X+ "") X+ ) X+ X+ X+ X+ (defun MacEdit-get-interactive (func) X+ (if (symbolp func) X+ (let ((cust (get func 'MacEdit-interactive))) X+ (if cust X+ cust X+ (MacEdit-get-interactive (symbol-function func)))) X+ (or (and (eq (car-safe func) 'lambda) X+ (let ((int (if (consp (nth 2 func)) X+ (nth 2 func) X+ (nth 3 func)))) X+ (and (eq (car-safe int) 'interactive) X+ (stringp (nth 1 int)) X+ (nth 1 int)))) X+ "")) X+ ) X+ X+ (put 'search-forward 'MacEdit-interactive "s") X+ (put 'search-backward 'MacEdit-interactive "s") X+ (put 'word-search-forward 'MacEdit-interactive "s") X+ (put 'word-search-backward 'MacEdit-interactive "s") X+ (put 're-search-forward 'MacEdit-interactive "s") X+ (put 're-search-backward 'MacEdit-interactive "s") X+ (put 'switch-to-buffer 'MacEdit-interactive "B") X+ (put 'kill-buffer 'MacEdit-interactive "B") X+ (put 'rename-buffer 'MacEdit-interactive "B\nB") X+ (put 'goto-char 'MacEdit-interactive "N") X+ (put 'global-set-key 'MacEdit-interactive "k\nC") X+ (put 'global-unset-key 'MacEdit-interactive "k") X+ (put 'local-set-key 'MacEdit-interactive "k\nC") X+ (put 'local-unset-key 'MacEdit-interactive "k") X+ X+ ;;; Think about kbd-macro-query X+ X+ X+ X+ ;;; Edit a keyboard macro in another buffer. X+ ;;; (Prefix argument is currently ignored.) X+ X+ (defun MacEdit-edit-macro (mac repl &optional prefix buffer hook arg) X+ (or (stringp mac) X+ (error "Not a keyboard macro")) X+ (let ((oldbuf (current-buffer)) X+ (local (current-local-map)) X+ (buf (get-buffer-create (or buffer "*Edit Macro*")))) X+ (set-buffer buf) X+ (kill-all-local-variables) X+ (use-local-map MacEdit-mode-map) X+ (setq buffer-read-only nil) X+ (setq major-mode 'MacEdit-mode) X+ (setq mode-name "Edit Macro") X+ (make-local-variable 'MacEdit-original-buffer) X+ (setq MacEdit-original-buffer oldbuf) X+ (make-local-variable 'MacEdit-replace-function) X+ (setq MacEdit-replace-function repl) X+ (make-local-variable 'MacEdit-replace-argument) X+ (setq MacEdit-replace-argument arg) X+ (make-local-variable 'MacEdit-finish-hook) X+ (setq MacEdit-finish-hook hook) X+ (erase-buffer) X+ (insert "# Keyboard Macro Editor. Press C-c C-c to finish; press C-x k RET to cancel.\n") X+ (insert "# Original keys: " (key-description mac) "\n\n") X+ (message "Formatting keyboard macro...") X+ (MacEdit-print-macro mac local) X+ (switch-to-buffer buf) X+ (goto-char (point-min)) X+ (forward-line 3) X+ (recenter '(4)) X+ (set-buffer-modified-p nil) X+ (message "Formatting keyboard macro...done") X+ (run-hooks 'MacEdit-format-hook)) X+ ) X+ X+ (defun MacEdit-finish-edit () X+ (interactive) X+ (or (and (boundp 'MacEdit-original-buffer) X+ (boundp 'MacEdit-replace-function) X+ (boundp 'MacEdit-replace-argument) X+ (boundp 'MacEdit-finish-hook) X+ (eq major-mode 'MacEdit-mode)) X+ (error "This command is valid only in buffers created by edit-kbd-macro.")) X+ (let ((buf (current-buffer)) X+ (str (buffer-string)) X+ (func MacEdit-replace-function) X+ (arg MacEdit-replace-argument) X+ (hook MacEdit-finish-hook)) X+ (goto-char (point-min)) X+ (run-hooks 'MacEdit-compile-hook) X+ (and (buffer-modified-p) X+ func X+ (progn X+ (message "Compiling keyboard macro...") X+ (let ((mac (MacEdit-read-macro X+ (and (buffer-name MacEdit-original-buffer) X+ (save-excursion X+ (set-buffer MacEdit-original-buffer) X+ (current-local-map)))))) X+ (and (buffer-name MacEdit-original-buffer) X+ (switch-to-buffer MacEdit-original-buffer)) X+ (funcall func mac arg)) X+ (message "Compiling keyboard macro...done"))) X+ (kill-buffer buf) X+ (if hook X+ (funcall hook arg))) X+ ) X+ X+ (defun MacEdit-mode () X+ "Keyboard Macro Editing mode. Press C-c C-c to save and exit. X+ To abort the edit, just kill this buffer with C-x k RET. X+ X+ The keyboard macro is represented as a series of M-x style command names. X+ Keystrokes which do not correspond to simple M-x commands are written as X+ \"type\" commands. When you press C-c C-c, MacEdit converts each command X+ back into a suitable keystroke sequence; \"type\" commands are converted X+ directly back into keystrokes." X+ (interactive) X+ (error "This mode can be enabled only by edit-kbd-macro or edit-last-kbd-macro.") X+ ) X+ (put 'MacEdit-mode 'mode-class 'special) X+ X+ (defvar MacEdit-mode-map nil) X+ (if MacEdit-mode-map X+ () X+ (setq MacEdit-mode-map (make-sparse-keymap)) X+ (define-key MacEdit-mode-map "\C-c\C-c" 'MacEdit-finish-edit) X+ ) X+ SHAR_EOF chmod 0666 calc.patch || echo "restore of calc.patch fails" rm -f s2_seq_.tmp echo "You have unpacked the last part" exit 0