diff options
| author | Stefan Monnier | 1999-10-13 00:48:17 +0000 |
|---|---|---|
| committer | Stefan Monnier | 1999-10-13 00:48:17 +0000 |
| commit | b005abd5c098532dd0b09654ac77a990bfe51510 (patch) | |
| tree | 780b3680c13b6d8c66aa578a64dd3e5a2a854405 | |
| parent | ce87039d4db7d3f0abcc42d17bce0ea3c619a52e (diff) | |
| download | emacs-b005abd5c098532dd0b09654ac77a990bfe51510.tar.gz emacs-b005abd5c098532dd0b09654ac77a990bfe51510.zip | |
(shell-command, shell-command-on-region): use make-temp-file.
(clone-buffer, clone-process, clone-buffer-hook): new functions.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/simple.el | 101 |
2 files changed, 102 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 742588131b8..f0f91cb3779 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 1999-10-12 Stefan Monnier <monnier@cs.yale.edu> | 1 | 1999-10-12 Stefan Monnier <monnier@cs.yale.edu> |
| 2 | 2 | ||
| 3 | * simple.el (shell-command, shell-command-on-region): use make-temp-file. | ||
| 4 | (clone-buffer, clone-process, clone-buffer-hook): new functions. | ||
| 5 | |||
| 3 | * subr.el (with-current-buffer): don't use backquotes to avoid | 6 | * subr.el (with-current-buffer): don't use backquotes to avoid |
| 4 | bootstrapping problems. | 7 | bootstrapping problems. |
| 5 | loadup.el (load-path): add subdirs for bootstrapping. | 8 | loadup.el (load-path): add subdirs for bootstrapping. |
diff --git a/lisp/simple.el b/lisp/simple.el index 9a77e3de806..15fe04b4c7e 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -1118,7 +1118,7 @@ specifies the value of ERROR-BUFFER." | |||
| 1118 | (not (or (bufferp output-buffer) (stringp output-buffer)))) | 1118 | (not (or (bufferp output-buffer) (stringp output-buffer)))) |
| 1119 | (let ((error-file | 1119 | (let ((error-file |
| 1120 | (if error-buffer | 1120 | (if error-buffer |
| 1121 | (make-temp-name | 1121 | (make-temp-file |
| 1122 | (expand-file-name "scor" | 1122 | (expand-file-name "scor" |
| 1123 | (or small-temporary-file-directory | 1123 | (or small-temporary-file-directory |
| 1124 | temporary-file-directory))) | 1124 | temporary-file-directory))) |
| @@ -1253,7 +1253,7 @@ specifies the value of ERROR-BUFFER." | |||
| 1253 | shell-command-default-error-buffer))) | 1253 | shell-command-default-error-buffer))) |
| 1254 | (let ((error-file | 1254 | (let ((error-file |
| 1255 | (if error-buffer | 1255 | (if error-buffer |
| 1256 | (make-temp-name | 1256 | (make-temp-file |
| 1257 | (expand-file-name "scor" | 1257 | (expand-file-name "scor" |
| 1258 | (or small-temporary-file-directory | 1258 | (or small-temporary-file-directory |
| 1259 | temporary-file-directory))) | 1259 | temporary-file-directory))) |
| @@ -3991,4 +3991,101 @@ PREFIX is the string that represents this modifier in an event type symbol." | |||
| 3991 | (kp-divide ?/) | 3991 | (kp-divide ?/) |
| 3992 | (kp-equal ?=))) | 3992 | (kp-equal ?=))) |
| 3993 | 3993 | ||
| 3994 | ;;;; | ||
| 3995 | ;;;; forking a twin copy of a buffer. | ||
| 3996 | ;;;; | ||
| 3997 | |||
| 3998 | (defvar clone-buffer-hook nil | ||
| 3999 | "Normal hook to run in the new buffer at the end of `clone-buffer'.") | ||
| 4000 | |||
| 4001 | (defun clone-process (process &optional newname) | ||
| 4002 | "Create a twin copy of PROCESS. | ||
| 4003 | If NEWNAME is nil, it defaults to PROCESS' name; | ||
| 4004 | NEWNAME is modified by adding or incrementing <N> at the end as necessary. | ||
| 4005 | If PROCESS is associated with a buffer, the new process will be associated | ||
| 4006 | with the current buffer instead. | ||
| 4007 | Returns nil if PROCESS has already terminated." | ||
| 4008 | (setq newname (or newname (process-name process))) | ||
| 4009 | (if (string-match "<[0-9]+>\\'" newname) | ||
| 4010 | (setq newname (substring newname 0 (match-beginning 0)))) | ||
| 4011 | (when (memq (process-status process) '(run stop open)) | ||
| 4012 | (let* ((process-connection-type (process-tty-name process)) | ||
| 4013 | (old-kwoq (process-kill-without-query process nil)) | ||
| 4014 | (new-process | ||
| 4015 | (if (memq (process-status process) '(open)) | ||
| 4016 | (apply 'open-network-stream newname | ||
| 4017 | (if (process-buffer process) (current-buffer)) | ||
| 4018 | (process-contact process)) | ||
| 4019 | (apply 'start-process newname | ||
| 4020 | (if (process-buffer process) (current-buffer)) | ||
| 4021 | (process-command process))))) | ||
| 4022 | (process-kill-without-query new-process old-kwoq) | ||
| 4023 | (process-kill-without-query process old-kwoq) | ||
| 4024 | (set-process-inherit-coding-system-flag | ||
| 4025 | new-process (process-inherit-coding-system-flag process)) | ||
| 4026 | (set-process-filter new-process (process-filter process)) | ||
| 4027 | (set-process-sentinel new-process (process-sentinel process)) | ||
| 4028 | new-process))) | ||
| 4029 | |||
| 4030 | ;; things to maybe add (currently partly covered by `funcall mode': | ||
| 4031 | ;; - syntax-table | ||
| 4032 | ;; - overlays | ||
| 4033 | (defun clone-buffer (&optional newname display-flag) | ||
| 4034 | "Create a twin copy of the current buffer. | ||
| 4035 | If NEWNAME is nil, it defaults to the current buffer's name; | ||
| 4036 | NEWNAME is modified by adding or incrementing <N> at the end as necessary. | ||
| 4037 | |||
| 4038 | If DISPLAY-FLAG is non-nil, the new buffer is shown with `pop-to-buffer'. | ||
| 4039 | This runs the normal hook `clone-buffer-hook' in the new buffer | ||
| 4040 | after it has been set up properly in other respects." | ||
| 4041 | (interactive (list (if current-prefix-arg (read-string "Name: ")) | ||
| 4042 | t)) | ||
| 4043 | (if buffer-file-name | ||
| 4044 | (error "Cannot clone a file-visiting buffer")) | ||
| 4045 | (if (get major-mode 'no-clone) | ||
| 4046 | (error "Cannot clone a buffer in %s mode" mode-name)) | ||
| 4047 | (setq newname (or newname (buffer-name))) | ||
| 4048 | (if (string-match "<[0-9]+>\\'" newname) | ||
| 4049 | (setq newname (substring newname 0 (match-beginning 0)))) | ||
| 4050 | (let ((buf (current-buffer)) | ||
| 4051 | (ptmin (point-min)) | ||
| 4052 | (ptmax (point-max)) | ||
| 4053 | (pt (point)) | ||
| 4054 | (mk (if mark-active (mark t))) | ||
| 4055 | (modified (buffer-modified-p)) | ||
| 4056 | (mode major-mode) | ||
| 4057 | (lvars (buffer-local-variables)) | ||
| 4058 | (process (get-buffer-process (current-buffer))) | ||
| 4059 | (new (generate-new-buffer (or newname (buffer-name))))) | ||
| 4060 | (save-restriction | ||
| 4061 | (widen) | ||
| 4062 | (with-current-buffer new | ||
| 4063 | (insert-buffer-substring buf))) | ||
| 4064 | (with-current-buffer new | ||
| 4065 | (narrow-to-region ptmin ptmax) | ||
| 4066 | (goto-char pt) | ||
| 4067 | (if mk (set-mark mk)) | ||
| 4068 | (set-buffer-modified-p modified) | ||
| 4069 | |||
| 4070 | ;; Clone the old buffer's process, if any. | ||
| 4071 | (when process (clone-process process)) | ||
| 4072 | |||
| 4073 | ;; Now set up the major mode. | ||
| 4074 | (funcall mode) | ||
| 4075 | |||
| 4076 | ;; Set up other local variables. | ||
| 4077 | (mapcar (lambda (v) | ||
| 4078 | (condition-case () ;in case var is read-only | ||
| 4079 | (if (symbolp v) | ||
| 4080 | (makunbound v) | ||
| 4081 | (set (make-local-variable (car v)) (cdr v))) | ||
| 4082 | (error nil))) | ||
| 4083 | lvars) | ||
| 4084 | |||
| 4085 | ;; Run any hooks (typically set up by the major mode | ||
| 4086 | ;; for cloning to work properly). | ||
| 4087 | (run-hooks 'clone-buffer-hook)) | ||
| 4088 | (if display-flag (pop-to-buffer new)) | ||
| 4089 | new)) | ||
| 4090 | |||
| 3994 | ;;; simple.el ends here | 4091 | ;;; simple.el ends here |