# HG changeset patch # User Richard M. Stallman # Date 719832682 0 # Node ID af4fe5e670f2381811225efb0ea90cab1eab79eb # Parent 01e760e7de34b0853088aeac03ccd8f0ccd40ed0 (insert-kbd-macro): Replace nonprinting chars with escapes. diff -r 01e760e7de34 -r af4fe5e670f2 lisp/macros.el --- a/lisp/macros.el Fri Oct 23 09:20:44 1992 +0000 +++ b/lisp/macros.el Fri Oct 23 09:31:22 1992 +0000 @@ -41,7 +41,7 @@ (defun insert-kbd-macro (macroname &optional keys) "Insert in buffer the definition of kbd macro NAME, as Lisp code. Optional second arg KEYS means also record the keys it is on -(this is the prefix argument, when calling interactively). +\(this is the prefix argument, when calling interactively). This Lisp code will, when executed, define the kbd macro with the same definition it has now. If you say to record the keys, the Lisp code @@ -49,13 +49,35 @@ are recorded since executing this Lisp code always makes global bindings. -To save a kbd macro, visit a file of Lisp code such as your ~/.emacs, +To save a kbd macro, visit a file of Lisp code such as your `~/.emacs', use this command, and then save the file." (interactive "CInsert kbd macro (name): \nP") (insert "(fset '") (prin1 macroname (current-buffer)) (insert "\n ") - (prin1 (symbol-function macroname) (current-buffer)) + (let ((beg (point)) end) + (prin1 (symbol-function macroname) (current-buffer)) + (setq end (point-marker)) + (goto-char beg) + (while (< (point) end) + (let ((char (following-char))) + (cond ((< char 32) + (delete-region (point) (1+ (point))) + (insert "\\C-" (+ 96 char))) + ((< char 127) + (forward-char 1)) + ((= char 127) + (delete-region (point) (1+ (point))) + (insert "\\C-?")) + ((< char 160) + (delete-region (point) (1+ (point))) + (insert "\\M-C-" (- char 32))) + ((< char 255) + (delete-region (point) (1+ (point))) + (insert "\\M-" (- char 128))) + ((= char 255) + (delete-region (point) (1+ (point))) + (insert "\\M-C-?")))))) (insert ")\n") (if keys (let ((keys (where-is-internal macroname nil)))