gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interactive shell commands


From: Sebastian Tennant
Subject: Re: Interactive shell commands
Date: Tue, 20 Jan 2009 21:59:36 +0000
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux)

Whoops!

Just realised that I forgot to rename the sentinel function so that it
doesn't break the standard function; shell-command.

Please use this code, not that included in my previous post.

Sebastian

----8<--------8<--------8<--------8<--------8<--------8<--------8<----

;;; sentinel for asynchronous commands
(defun interactive-shell-command-sentinel (process signal)
  (if (memq (process-status process) '(exit signal))
      (message "%s: %s."
               (car (cdr (cdr (cdr (process-command process)))))
               (substring signal 0 -1))))

(defun interactive-shell-command (command)
  (interactive "sCommand: ")
  (if (string-match  "[ \t]*&[ \t]*\\'" command)
      ;; asynchronous command
      (asynchronous-interactive-shell-command
        (substring command 0 (match-beginning 0))) ;strip ampersand
    (progn
      (set-buffer (get-buffer-create "*Shell Command Output*"))
      (erase-buffer)
      (let ((exit-code (call-process shell-file-name nil t t "-i" "-c" 
command)))
        (if (> (buffer-size) 0)
            (display-buffer (current-buffer))
          (progn (kill-buffer nil)
                 (if (eq exit-code 0)
                     (message "(Shell command succeeded with no output)")
                   (message "(Shell command failed with code %d and no output)"
                            exit-code))))))))

(defun asynchronous-interactive-shell-command (command)
  (interactive "sCommand: ")
  (set-buffer (get-buffer-create "*Async Shell Command*"))
  (if (get-buffer-process (current-buffer))
      (progn (message "(An asynchronous process is already in progress)")
             (unless current-prefix-arg (display-buffer (current-buffer))))
    (progn (erase-buffer)
           (set-process-sentinel
            (get-buffer-process
             (make-comint-in-buffer
              "async-int-shell-command"
              (current-buffer) shell-file-name nil "-i" "-c" command))
             'interactive-shell-command-sentinel)
             (setq mode-line-process '(":%s"))
             (unless current-prefix-arg (display-buffer (current-buffer))))))

----8<--------8<--------8<--------8<--------8<--------8<--------8<----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]