🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.sources
Article #341

patch to make background behave like shell-command

#341
From: John Interrante
Date: Wed, 27 Jan 1993 05:37
100 lines
4608 bytes
I felt that background should behave like shell-command; that is, it
should display the process buffer if and only if the background job
produces any output.  Here're my changes to background.el.  I deleted
the user variables background-show and background-select and I added a
process filter to display the buffer the first time the background job
produces any output.  I have been using these changes for one week
before posting them and they have not given me any problems.

John Interrante / interran@uluru.stanford.edu
Computer Systems Laboratory, Stanford University

*** comint-2.03/background.el.save	Sat Aug 24 13:36:36 1991
--- comint-2.03/background.el	Wed Jan 20 10:36:23 1993
***************
*** 17,38 ****
  ;; - Fixed up the sentinel to protect match-data around invocations.
  ;;   Also slightly rearranged the cd match code for similar reasons.
  ;;   Olin 7/16/91
  
  (provide 'background)
  (require 'comint)
  
- ;; user variables
- (defvar background-show t
-   "*If non-nil, background jobs' buffers are shown when they're started.")
- (defvar background-select nil
-   "*If non-nil, background jobs' buffers are selected when they're started.")
- 
  (defun background (command)
!   "Run COMMAND in the background like csh.  
  A message is displayed when the job starts and finishes.  The buffer is in
  comint mode, so you can send input and signals to the job.  The process object
! is returned if anyone cares.  See also comint-mode and the variables
! background-show and background-select."
    (interactive "s%% ")
    (let ((job-number 1)
  	(job-name "%1")
--- 17,34 ----
  ;; - Fixed up the sentinel to protect match-data around invocations.
  ;;   Also slightly rearranged the cd match code for similar reasons.
  ;;   Olin 7/16/91
+ ;; - Made background behave like shell-command in that it displays the
+ ;;   process buffer if and only if the background job produces any output.
+ ;;   J. Interrante 1/18/93
  
  (provide 'background)
  (require 'comint)
  
  (defun background (command)
!   "Run COMMAND in the background like csh; display output, if any.
  A message is displayed when the job starts and finishes.  The buffer is in
  comint mode, so you can send input and signals to the job.  The process object
! is returned if anyone cares.  See also comint-mode."
    (interactive "s%% ")
    (let ((job-number 1)
  	(job-name "%1")
***************
*** 39,47 ****
  	(dir default-directory))
      (while (process-status job-name)
        (setq job-name (concat "%" (setq job-number (1+ job-number)))))
!     (if background-select (pop-to-buffer job-name)
!       (if background-show (with-output-to-temp-buffer job-name)) ; cute
!       (set-buffer (get-buffer-create job-name)))
      (erase-buffer)
  
      (setq default-directory dir) ; Do this first, in case cd is relative path.
--- 35,41 ----
  	(dir default-directory))
      (while (process-status job-name)
        (setq job-name (concat "%" (setq job-number (1+ job-number)))))
!     (set-buffer (get-buffer-create job-name))
      (erase-buffer)
  
      (setq default-directory dir) ; Do this first, in case cd is relative path.
***************
*** 60,65 ****
--- 54,60 ----
        (comint-mode)
        ;; COND because the proc may have died before the G-B-P is called.
        (cond (proc (set-process-sentinel proc 'background-sentinel)
+ 		  (set-process-filter proc 'background-filter)
  		  (message "[%d] %d" job-number (process-id proc))))
        (setq mode-name "Background")
        proc)))
***************
*** 90,92 ****
--- 85,96 ----
  		       (if at-end (goto-char (point-max))))
  		     (set-buffer-modified-p nil)))))
        (store-match-data ms))))
+ 
+ (defun background-filter (process output)
+   "Called to make buffer visible when a background job produces output."
+   (save-excursion
+     (display-buffer (set-buffer (process-buffer process)))
+     (goto-char (point-max))
+     (insert output)
+     (set-marker (process-mark process) (point))
+     (set-process-filter process nil)))
Technical Details
Message-ID: <INTERRAN.93Jan26223729@uluru.Stanford.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!saimiri.primate.wisc.edu!ames!agate!stanford.edu!nntp.Stanford.EDU!nntp!interran

Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.sources
Path: arc1-ca.pugleaf.net!sparky!uunet!UB.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!saimiri.primate.wisc.edu!ames!agate!stanford.edu!nntp.Stanford.EDU!nntp!interran
From: interran@uluru.Stanford.EDU (John Interrante)
Subject: patch to make background behave like shell-command
Message-ID: <INTERRAN.93Jan26223729@uluru.Stanford.EDU>
Sender: news@leland.Stanford.EDU (Mr News)
Organization: Stanford University
Date: 27 Jan 1993 05:37:29 GMT
Lines: 100