;;; -*-Scheme-*-
;;;
-;;; $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/dired.scm,v 1.118 1991/10/22 12:27:55 cph Exp $
+;;; $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/dired.scm,v 1.119 1991/10/26 21:07:59 cph Exp $
;;;
;;; Copyright (c) 1986, 1989-91 Massachusetts Institute of Technology
;;;
(set-buffer-read-only! buffer))
(define (read-directory pathname switches mark)
- (with-working-directory-pathname (pathname-directory-path pathname)
- (lambda ()
- (if (file-directory? pathname)
- (run-synchronous-process false
- mark
- (find-program "ls" false)
- switches
- (pathname->string pathname))
- (shell-command (string-append "ls "
- switches
- " "
- (pathname-name-string pathname))
- mark)))))
+ (let ((directory (pathname-directory-path pathname)))
+ (if (file-directory? pathname)
+ (run-synchronous-process false mark directory false
+ (find-program "ls" false)
+ switches
+ (pathname->string pathname))
+ (shell-command false mark directory false
+ (string-append "ls "
+ switches
+ " "
+ (pathname-name-string pathname))))))
(define (add-dired-entry pathname)
(let ((lstart (line-start (current-point) 0))
(directory (pathname-directory-path pathname)))
(if (pathname=? (buffer-default-directory (mark-buffer lstart)) directory)
(let ((start (mark-right-inserting lstart)))
- (run-synchronous-process false
- lstart
+ (run-synchronous-process false lstart directory false
(find-program "ls" directory)
"-d"
(ref-variable dired-listing-switches)
(define (dired-change-line program argument)
(let ((pathname (dired-current-pathname)))
- (run-synchronous-process false
- false
- (find-program program
- (pathname-directory-path pathname))
- argument
- (pathname->string pathname))
+ (let ((directory (pathname-directory-path pathname)))
+ (run-synchronous-process false false directory false
+ (find-program program directory)
+ argument
+ (pathname->string pathname)))
(dired-redisplay pathname)))
(define (dired-redisplay pathname)
;;; -*-Scheme-*-
;;;
-;;; $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/process.scm,v 1.10 1991/10/11 03:58:56 cph Exp $
+;;; $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/edwin/process.scm,v 1.11 1991/10/26 21:08:14 cph Exp $
;;;
;;; Copyright (c) 1991 Massachusetts Institute of Technology
;;;
(mark-right-inserting-copy (buffer-end buffer))))))
\f
(define (start-process name buffer environment program . arguments)
- (let ((directory (buffer-default-directory buffer)))
- (let ((make-subprocess
- (let ((filename (find-program program directory))
- (arguments (list->vector (cons program arguments))))
- (if (and (eq? true (ref-variable process-connection-type))
- ((ucode-primitive have-ptys? 0)))
- (lambda ()
- (start-pty-subprocess filename arguments environment))
- (lambda ()
- (start-pipe-subprocess filename arguments environment))))))
- ;; Calling WITH-WORKING-DIRECTORY-PATHNAME is a kludge --
- ;; there's no other way to specify the working directory of the
- ;; subprocess. The subprocess abstraction should be fixed to
- ;; allow this.
- (with-working-directory-pathname directory
- (lambda ()
- (without-interrupts
- (lambda ()
- (let ((subprocess (make-subprocess)))
- (let ((channel (subprocess-input-channel subprocess)))
- (if channel
- (begin
- (channel-nonblocking channel)
- (channel-register channel))))
- (let ((process
- (%make-process
- subprocess
- (do ((n 2 (+ n 1))
- (name* name
- (string-append name
- "<" (number->string n) ">")))
- ((not (get-process-by-name name*)) name*))
- buffer)))
- (update-process-mark! process)
- (subprocess-put! subprocess 'EDWIN-PROCESS process)
- (set! edwin-processes (cons process edwin-processes))
- process)))))))))
+ (let ((make-subprocess
+ (let ((filename
+ (find-program program (buffer-default-directory buffer)))
+ (arguments (list->vector (cons program arguments))))
+ (if (and (eq? true (ref-variable process-connection-type))
+ ((ucode-primitive have-ptys? 0)))
+ (lambda ()
+ (start-pty-subprocess filename arguments environment))
+ (lambda ()
+ (start-pipe-subprocess filename arguments environment))))))
+ (with-process-directory buffer
+ (lambda ()
+ (without-interrupts
+ (lambda ()
+ (let ((subprocess (make-subprocess)))
+ (let ((channel (subprocess-input-channel subprocess)))
+ (if channel
+ (begin
+ (channel-nonblocking channel)
+ (channel-register channel))))
+ (let ((process
+ (%make-process
+ subprocess
+ (do ((n 2 (+ n 1))
+ (name* name
+ (string-append name
+ "<" (number->string n) ">")))
+ ((not (get-process-by-name name*)) name*))
+ buffer)))
+ (update-process-mark! process)
+ (subprocess-put! subprocess 'EDWIN-PROCESS process)
+ (set! edwin-processes (cons process edwin-processes))
+ process))))))))
+
+(define (with-process-directory buffer thunk)
+ ;; Calling WITH-WORKING-DIRECTORY-PATHNAME is a kludge -- there's
+ ;; no other way to specify the working directory of the subprocess.
+ ;; The subprocess abstraction should be fixed to allow this.
+ (with-working-directory-pathname (buffer-default-directory buffer)
+ thunk))
(define (delete-process process)
(let ((subprocess (process-subprocess process)))
\f
;;;; Synchronous Subprocesses
-(define (shell-command command output-mark)
- (run-synchronous-process false output-mark "/bin/sh" "-c" command))
-
-(define (shell-command-region command output-mark input-region)
- (run-synchronous-process input-region output-mark "/bin/sh" "-c" command))
-
-(define (run-synchronous-process input-region output-mark program . arguments)
- (let ((process false))
+(define (run-synchronous-process input-region output-mark directory pty?
+ program . arguments)
+ (let ((process false)
+ (start-process
+ (lambda ()
+ ((if (and pty? ((ucode-primitive have-ptys? 0)))
+ start-pty-subprocess
+ start-pipe-subprocess)
+ program
+ (list->vector
+ (cons (os/filename-non-directory program) arguments))
+ false))))
(dynamic-wind
(lambda ()
(if (not process)
(set! process
- (start-pipe-subprocess
- program
- (list->vector
- (cons (os/filename-non-directory program) arguments))
- false)))
+ (if directory
+ (with-working-directory-pathname directory start-process)
+ (start-process))))
unspecific)
(lambda ()
(call-with-output-copier process output-mark
insert output in current buffer after point (leave mark after it)."
"sShell command\nP"
(lambda (command insert-at-point?)
- (if insert-at-point?
- (begin
- (if (buffer-read-only? (current-buffer))
- (barf-if-read-only))
- (let ((point (current-point)))
- (push-current-mark! point)
- (shell-command command point))
- ((ref-command exchange-point-and-mark)))
- (shell-command-pop-up-output
- (lambda (output-mark)
- (shell-command command output-mark))))))
+ (let ((directory (buffer-default-directory (current-buffer))))
+ (if insert-at-point?
+ (begin
+ (if (buffer-read-only? (current-buffer))
+ (barf-if-read-only))
+ (let ((point (current-point)))
+ (push-current-mark! point)
+ (shell-command false point directory false command))
+ ((ref-command exchange-point-and-mark)))
+ (shell-command-pop-up-output
+ (lambda (output-mark)
+ (shell-command false output-mark directory false command)))))))
(define-command shell-command-on-region
"Execute string COMMAND in inferior shell with region as input.
Prefix arg means replace the region with it."
"r\nsShell command on region\nP"
(lambda (region command replace-region?)
- (if replace-region?
- (let ((point (current-point))
- (mark (current-mark)))
- (let ((swap? (mark< point mark))
- (temp))
- (dynamic-wind
- (lambda () unspecific)
- (lambda ()
- (set! temp (temporary-buffer " *shell-output*"))
- (shell-command-region command
- (buffer-start temp)
- (make-region point mark))
- (without-interrupts
- (lambda ()
- (delete-string point mark)
- (insert-region (buffer-start temp)
- (buffer-end temp)
- (current-point)))))
- (lambda ()
- (kill-buffer temp)
- (set! temp)
- unspecific))
- (if swap? ((ref-command exchange-point-and-mark)))))
- (shell-command-pop-up-output
- (lambda (output-mark)
- (shell-command-region command output-mark region))))))
+ (let ((directory (buffer-default-directory (current-buffer))))
+ (if replace-region?
+ (let ((point (current-point))
+ (mark (current-mark)))
+ (let ((swap? (mark< point mark))
+ (temp))
+ (dynamic-wind
+ (lambda () unspecific)
+ (lambda ()
+ (set! temp (temporary-buffer " *shell-output*"))
+ (shell-command (make-region point mark)
+ (buffer-start temp)
+ directory
+ false
+ command)
+ (without-interrupts
+ (lambda ()
+ (delete-string point mark)
+ (insert-region (buffer-start temp)
+ (buffer-end temp)
+ (current-point)))))
+ (lambda ()
+ (kill-buffer temp)
+ (set! temp)
+ unspecific))
+ (if swap? ((ref-command exchange-point-and-mark)))))
+ (shell-command-pop-up-output
+ (lambda (output-mark)
+ (shell-command region output-mark directory false command)))))))
(define (shell-command-pop-up-output generate-output)
(let ((buffer (temporary-buffer "*Shell Command Output*")))
(if (mark< start (buffer-end buffer))
(pop-up-buffer buffer false)
(message "(Shell command completed with no output)")))))
+
+(define (shell-command input-region output-mark directory pty? command)
+ (run-synchronous-process input-region output-mark directory pty?
+ "/bin/sh" "-c" command))
\f
;;; These procedures are not specific to the process abstraction.