diff options
| -rw-r--r-- | lisp/subr.el | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 9bea598b8a5..63ea674a1c1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -937,9 +937,9 @@ See also `with-temp-buffer'." | |||
| 937 | (set-buffer ,buffer) | 937 | (set-buffer ,buffer) |
| 938 | ,@body)) | 938 | ,@body)) |
| 939 | 939 | ||
| 940 | (defmacro with-temp-file (file &rest forms) | 940 | (defmacro with-temp-file (file &rest body) |
| 941 | "Create a new buffer, evaluate FORMS there, and write the buffer to FILE. | 941 | "Create a new buffer, evaluate BODY there, and write the buffer to FILE. |
| 942 | The value of the last form in FORMS is returned, like `progn'. | 942 | The value returned is the value of the last form in BODY. |
| 943 | See also `with-temp-buffer'." | 943 | See also `with-temp-buffer'." |
| 944 | (let ((temp-file (make-symbol "temp-file")) | 944 | (let ((temp-file (make-symbol "temp-file")) |
| 945 | (temp-buffer (make-symbol "temp-buffer"))) | 945 | (temp-buffer (make-symbol "temp-buffer"))) |
| @@ -949,22 +949,35 @@ See also `with-temp-buffer'." | |||
| 949 | (unwind-protect | 949 | (unwind-protect |
| 950 | (prog1 | 950 | (prog1 |
| 951 | (with-current-buffer ,temp-buffer | 951 | (with-current-buffer ,temp-buffer |
| 952 | ,@forms) | 952 | ,@body) |
| 953 | (with-current-buffer ,temp-buffer | 953 | (with-current-buffer ,temp-buffer |
| 954 | (widen) | 954 | (widen) |
| 955 | (write-region (point-min) (point-max) ,temp-file nil 0))) | 955 | (write-region (point-min) (point-max) ,temp-file nil 0))) |
| 956 | (and (buffer-name ,temp-buffer) | 956 | (and (buffer-name ,temp-buffer) |
| 957 | (kill-buffer ,temp-buffer)))))) | 957 | (kill-buffer ,temp-buffer)))))) |
| 958 | 958 | ||
| 959 | (defmacro with-temp-buffer (&rest forms) | 959 | (defmacro with-temp-message (message &rest body) |
| 960 | "Create a temporary buffer, and evaluate FORMS there like `progn'. | 960 | "Display MESSAGE temporarily while BODY is evaluated. |
| 961 | The original message is restored to the echo area after BODY has finished. | ||
| 962 | The value returned is the value of the last form in BODY. | ||
| 963 | MESSAGE is written to the message log buffer if `message-log-max' is non-nil." | ||
| 964 | (let ((current-message (make-symbol "current-message"))) | ||
| 965 | `(let ((,current-message (current-message))) | ||
| 966 | (unwind-protect | ||
| 967 | (progn | ||
| 968 | (message ,message) | ||
| 969 | ,@body) | ||
| 970 | (message ,current-message))))) | ||
| 971 | |||
| 972 | (defmacro with-temp-buffer (&rest body) | ||
| 973 | "Create a temporary buffer, and evaluate BODY there like `progn'. | ||
| 961 | See also `with-temp-file' and `with-output-to-string'." | 974 | See also `with-temp-file' and `with-output-to-string'." |
| 962 | (let ((temp-buffer (make-symbol "temp-buffer"))) | 975 | (let ((temp-buffer (make-symbol "temp-buffer"))) |
| 963 | `(let ((,temp-buffer | 976 | `(let ((,temp-buffer |
| 964 | (get-buffer-create (generate-new-buffer-name " *temp*")))) | 977 | (get-buffer-create (generate-new-buffer-name " *temp*")))) |
| 965 | (unwind-protect | 978 | (unwind-protect |
| 966 | (with-current-buffer ,temp-buffer | 979 | (with-current-buffer ,temp-buffer |
| 967 | ,@forms) | 980 | ,@body) |
| 968 | (and (buffer-name ,temp-buffer) | 981 | (and (buffer-name ,temp-buffer) |
| 969 | (kill-buffer ,temp-buffer)))))) | 982 | (kill-buffer ,temp-buffer)))))) |
| 970 | 983 | ||