diff options
| author | Basil L. Contovounesios | 2018-05-15 01:23:35 +0900 |
|---|---|---|
| committer | Tino Calancha | 2018-05-15 01:23:35 +0900 |
| commit | c2caf763cfe3bb85b4933ffac12695a7cb366cd4 (patch) | |
| tree | 687c8cc66bbd97c90df375864a4f5e49fbb7fb7f | |
| parent | 81fb3761ef491d55ba659594aed433f7f836f5b1 (diff) | |
| download | emacs-c2caf763cfe3bb85b4933ffac12695a7cb366cd4.tar.gz emacs-c2caf763cfe3bb85b4933ffac12695a7cb366cd4.zip | |
Minor refactoring in shell-command
* lisp/simple.el (shell-command): Use call-process-shell-command,
start-process-shell-command, and file-attribute-size. (bug#30280).
| -rw-r--r-- | lisp/simple.el | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index a0a6898e17f..57e70a8d153 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -3400,6 +3400,8 @@ a shell (with its need to quote arguments)." | |||
| 3400 | (setq command (concat command " &"))) | 3400 | (setq command (concat command " &"))) |
| 3401 | (shell-command command output-buffer error-buffer)) | 3401 | (shell-command command output-buffer error-buffer)) |
| 3402 | 3402 | ||
| 3403 | (declare-function comint-output-filter "comint" (process string)) | ||
| 3404 | |||
| 3403 | (defun shell-command (command &optional output-buffer error-buffer) | 3405 | (defun shell-command (command &optional output-buffer error-buffer) |
| 3404 | "Execute string COMMAND in inferior shell; display output, if any. | 3406 | "Execute string COMMAND in inferior shell; display output, if any. |
| 3405 | With prefix argument, insert the COMMAND's output at point. | 3407 | With prefix argument, insert the COMMAND's output at point. |
| @@ -3477,12 +3479,11 @@ impose the use of a shell (with its need to quote arguments)." | |||
| 3477 | (not (or (bufferp output-buffer) (stringp output-buffer)))) | 3479 | (not (or (bufferp output-buffer) (stringp output-buffer)))) |
| 3478 | ;; Output goes in current buffer. | 3480 | ;; Output goes in current buffer. |
| 3479 | (let ((error-file | 3481 | (let ((error-file |
| 3480 | (if error-buffer | 3482 | (and error-buffer |
| 3481 | (make-temp-file | 3483 | (make-temp-file |
| 3482 | (expand-file-name "scor" | 3484 | (expand-file-name "scor" |
| 3483 | (or small-temporary-file-directory | 3485 | (or small-temporary-file-directory |
| 3484 | temporary-file-directory))) | 3486 | temporary-file-directory)))))) |
| 3485 | nil))) | ||
| 3486 | (barf-if-buffer-read-only) | 3487 | (barf-if-buffer-read-only) |
| 3487 | (push-mark nil t) | 3488 | (push-mark nil t) |
| 3488 | ;; We do not use -f for csh; we will not support broken use of | 3489 | ;; We do not use -f for csh; we will not support broken use of |
| @@ -3490,24 +3491,22 @@ impose the use of a shell (with its need to quote arguments)." | |||
| 3490 | ;; "if ($?prompt) exit" before things which are not useful | 3491 | ;; "if ($?prompt) exit" before things which are not useful |
| 3491 | ;; non-interactively. Besides, if someone wants their other | 3492 | ;; non-interactively. Besides, if someone wants their other |
| 3492 | ;; aliases for shell commands then they can still have them. | 3493 | ;; aliases for shell commands then they can still have them. |
| 3493 | (call-process shell-file-name nil | 3494 | (call-process-shell-command command nil (if error-file |
| 3494 | (if error-file | 3495 | (list t error-file) |
| 3495 | (list t error-file) | 3496 | t)) |
| 3496 | t) | ||
| 3497 | nil shell-command-switch command) | ||
| 3498 | (when (and error-file (file-exists-p error-file)) | 3497 | (when (and error-file (file-exists-p error-file)) |
| 3499 | (if (< 0 (nth 7 (file-attributes error-file))) | 3498 | (when (< 0 (file-attribute-size (file-attributes error-file))) |
| 3500 | (with-current-buffer (get-buffer-create error-buffer) | 3499 | (with-current-buffer (get-buffer-create error-buffer) |
| 3501 | (let ((pos-from-end (- (point-max) (point)))) | 3500 | (let ((pos-from-end (- (point-max) (point)))) |
| 3502 | (or (bobp) | 3501 | (or (bobp) |
| 3503 | (insert "\f\n")) | 3502 | (insert "\f\n")) |
| 3504 | ;; Do no formatting while reading error file, | 3503 | ;; Do no formatting while reading error file, |
| 3505 | ;; because that can run a shell command, and we | 3504 | ;; because that can run a shell command, and we |
| 3506 | ;; don't want that to cause an infinite recursion. | 3505 | ;; don't want that to cause an infinite recursion. |
| 3507 | (format-insert-file error-file nil) | 3506 | (format-insert-file error-file nil) |
| 3508 | ;; Put point after the inserted errors. | 3507 | ;; Put point after the inserted errors. |
| 3509 | (goto-char (- (point-max) pos-from-end))) | 3508 | (goto-char (- (point-max) pos-from-end))) |
| 3510 | (display-buffer (current-buffer)))) | 3509 | (display-buffer (current-buffer)))) |
| 3511 | (delete-file error-file)) | 3510 | (delete-file error-file)) |
| 3512 | ;; This is like exchange-point-and-mark, but doesn't | 3511 | ;; This is like exchange-point-and-mark, but doesn't |
| 3513 | ;; activate the mark. It is cleaner to avoid activation, | 3512 | ;; activate the mark. It is cleaner to avoid activation, |
| @@ -3526,12 +3525,11 @@ impose the use of a shell (with its need to quote arguments)." | |||
| 3526 | (let* ((buffer (get-buffer-create | 3525 | (let* ((buffer (get-buffer-create |
| 3527 | (or output-buffer "*Async Shell Command*"))) | 3526 | (or output-buffer "*Async Shell Command*"))) |
| 3528 | (bname (buffer-name buffer)) | 3527 | (bname (buffer-name buffer)) |
| 3529 | (directory default-directory) | 3528 | (proc (get-buffer-process buffer)) |
| 3530 | proc) | 3529 | (directory default-directory)) |
| 3531 | ;; Remove the ampersand. | 3530 | ;; Remove the ampersand. |
| 3532 | (setq command (substring command 0 (match-beginning 0))) | 3531 | (setq command (substring command 0 (match-beginning 0))) |
| 3533 | ;; Ask the user what to do with already running process. | 3532 | ;; Ask the user what to do with already running process. |
| 3534 | (setq proc (get-buffer-process buffer)) | ||
| 3535 | (when proc | 3533 | (when proc |
| 3536 | (cond | 3534 | (cond |
| 3537 | ((eq async-shell-command-buffer 'confirm-kill-process) | 3535 | ((eq async-shell-command-buffer 'confirm-kill-process) |
| @@ -3563,14 +3561,14 @@ impose the use of a shell (with its need to quote arguments)." | |||
| 3563 | (with-current-buffer buffer | 3561 | (with-current-buffer buffer |
| 3564 | (shell-command--save-pos-or-erase) | 3562 | (shell-command--save-pos-or-erase) |
| 3565 | (setq default-directory directory) | 3563 | (setq default-directory directory) |
| 3566 | (setq proc (start-process "Shell" buffer shell-file-name | 3564 | (setq proc |
| 3567 | shell-command-switch command)) | 3565 | (start-process-shell-command "Shell" buffer command)) |
| 3568 | (setq mode-line-process '(":%s")) | 3566 | (setq mode-line-process '(":%s")) |
| 3569 | (require 'shell) (shell-mode) | 3567 | (require 'shell) (shell-mode) |
| 3570 | (set-process-sentinel proc 'shell-command-sentinel) | 3568 | (set-process-sentinel proc #'shell-command-sentinel) |
| 3571 | ;; Use the comint filter for proper handling of | 3569 | ;; Use the comint filter for proper handling of |
| 3572 | ;; carriage motion (see comint-inhibit-carriage-motion). | 3570 | ;; carriage motion (see comint-inhibit-carriage-motion). |
| 3573 | (set-process-filter proc 'comint-output-filter) | 3571 | (set-process-filter proc #'comint-output-filter) |
| 3574 | (if async-shell-command-display-buffer | 3572 | (if async-shell-command-display-buffer |
| 3575 | ;; Display buffer immediately. | 3573 | ;; Display buffer immediately. |
| 3576 | (display-buffer buffer '(nil (allow-no-window . t))) | 3574 | (display-buffer buffer '(nil (allow-no-window . t))) |