home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / emacs / sources / 856 < prev    next >
Encoding:
Text File  |  1992-12-12  |  4.1 KB  |  120 lines

  1. Xref: sparky gnu.emacs.sources:856 alt.gopher:1422
  2. Newsgroups: gnu.emacs.sources,alt.gopher
  3. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!128.174.5.61!marca
  4. From: marca@ncsa.uiuc.edu (Marc Andreessen)
  5. Subject: Re: emacs elisp files for gopher
  6. References: <MIKE.92Dec12174733@cucbs.chem.columbia.edu>
  7. Message-ID: <MARCA.92Dec12210219@wintermute.ncsa.uiuc.edu>
  8. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  9. Organization: Nat'l Center for Supercomputing Applications
  10. Distribution: gnu.emacs.sources,alt.gopher
  11. In-Reply-To: mike@cucbs.chem.columbia.edu's message of Sat, 12 Dec 1992 22:47:32 GMT
  12. Date: Sun, 13 Dec 1992 02:02:19 GMT
  13. Lines: 105
  14.  
  15. background.el, for use with gopher.el, follows:
  16.  
  17. ;Date: Thu, 28 Jan 88 22:11:49 -0500 (EST)
  18. ;From: "Joseph G. Keane" <jk3k+@ANDREW.CMU.EDU>
  19. ;X-Andrew-Message-Size: 3169+0
  20. ;To: unix-emacs@BBN.COM
  21. ;Subject: background.el
  22. ;
  23. ;
  24. ;Here's a useful file which provides a csh-like interface to background jobs.  
  25. ;I like to bind background to ESC !.  Please send back any modifications.  
  26. ;--Joe
  27. ;;; Fun with background jobs.
  28. ;; Copyright (C) 1988 Joe Keane <jk3k+@andrew.cmu.edu>
  29. ;; Refer to the GNU Emacs General Public License for copyright info
  30.  
  31. ;; user variables
  32. (defvar background-show t
  33.   "*If non-nil, background jobs' buffers are shown when they're started.")
  34. (defvar background-select nil
  35.   "*If non-nil, background jobs' buffers are selected when they're started.")
  36.  
  37. ;; patches to shell-mode
  38. (require 'shell)
  39. (define-key shell-mode-map "\C-c\C-f" 'continue-shell-subjob)
  40. (define-key shell-mode-map "\C-c\C-k" 'kill-shell-subjob)
  41. (defun continue-shell-subjob ()
  42.   "Continue this shell's current subjob."
  43.   (interactive)
  44.   (continue-process nil t))
  45.  
  46. (defun background (command)
  47.   "Run COMMAND in the background like csh.  A message is displayed when
  48. the job starts and finishes.  The buffer is in shell mode, so among
  49. other things you can control the job and send input to it.  The
  50. process object is returned if anyone cares.  See also shell-mode and
  51. the variables background-show and background-select."
  52.   (interactive "s%% ")
  53.   (let*
  54.       ((job-number 1)
  55.        (process
  56.     (let ((job-name "%1"))
  57.       (while (process-status job-name)
  58.         (setq job-name (concat "%" (setq job-number (1+ job-number)))))
  59.       (setq default-directory
  60.        (prog1
  61.            (if (string-match
  62.             "^cd[\t ]+\\([^\t ;]+\\)[\t ]*;[\t ]*"
  63.             command)
  64.            (prog1
  65.                (file-name-as-directory
  66.             (expand-file-name
  67.              (substring command
  68.               (match-beginning 1) (match-end 1))))
  69.              (setq command (substring command (match-end 0))))
  70.          default-directory)
  71.          (if background-select (pop-to-buffer job-name)
  72.            (and background-show (with-output-to-temp-buffer job-name))
  73.            (set-buffer (get-buffer-create job-name)))))
  74.       (start-process job-name job-name shell-file-name "-c" command))))
  75.     (message "[%d] %d" job-number (process-id process))
  76.     (erase-buffer)
  77.     (insert "% cd " default-directory "\n% " command ?\n)
  78.     (set-marker (process-mark process) (point))
  79.     (set-process-sentinel process 'background-sentinel)
  80.     (shell-mode)
  81.     (setq mode-name "Background")
  82.     process))
  83.  
  84. (defun background-sentinel (process msg)
  85.   "Called when a background job changes state."
  86.   (message
  87.    "[%s] %s %s"
  88.    (substring (process-name process) 1)
  89.    (setq msg
  90.     (cond
  91.      ((string= msg "finished\n") "Done")
  92.      ((string-match "^exited" msg)
  93.       (concat "Exit " (substring msg 28 -1)))
  94.      ((zerop (length msg)) "Continuing") ;;Emacs bug
  95.      (t (concat (upcase (substring msg 0 1)) (substring msg 1 -1)))))
  96.    (nth 2 (process-command process)))
  97.   (if (buffer-name (process-buffer process))
  98.       (and
  99.        (memq (process-status process) '(signal exit))
  100.        (set-buffer
  101.     (prog1 (current-buffer)
  102.       (set-buffer (process-buffer process))
  103.       (and
  104.        (prog1 (eobp)
  105.          (save-excursion
  106.            (goto-char (point-max))
  107.            (insert ?\n msg ? 
  108.         (substring (current-time-string) 11 19) ?\n)))
  109.        (goto-char (point-max)))
  110.       (set-buffer-modified-p nil))))
  111.     (set-process-buffer process nil)))
  112.  
  113. Marc
  114.  
  115. --
  116. Marc Andreessen
  117. Software Development Group
  118. National Center for Supercomputing Applications
  119. marca@ncsa.uiuc.edu
  120.