2910 |
"Like `shell-command' for tramp files. |
"Like `shell-command' for tramp files. |
2911 |
This will break if COMMAND prints a newline, followed by the value of |
This will break if COMMAND prints a newline, followed by the value of |
2912 |
`tramp-end-of-output', followed by another newline." |
`tramp-end-of-output', followed by another newline." |
2913 |
(when (tramp-tramp-file-p default-directory) |
(if (tramp-tramp-file-p default-directory) |
2914 |
(with-parsed-tramp-file-name default-directory nil |
(with-parsed-tramp-file-name default-directory nil |
2915 |
(when (tramp-ange-ftp-file-name-p multi-method method user host) |
(when (tramp-ange-ftp-file-name-p multi-method method user host) |
2916 |
(let ((default-directory (tramp-make-ange-ftp-file-name |
(let ((default-directory (tramp-make-ange-ftp-file-name |
2917 |
user host path))) |
user host path))) |
2918 |
(tramp-invoke-ange-ftp 'shell-command |
(tramp-invoke-ange-ftp 'shell-command |
2919 |
command output-buffer error-buffer))) |
command output-buffer error-buffer))) |
2920 |
(let (status) |
(let (status) |
2921 |
(when (string-match "&[ \t]*\\'" command) |
(when (string-match "&[ \t]*\\'" command) |
2922 |
(error "Tramp doesn't grok asynchronous shell commands, yet")) |
(error "Tramp doesn't grok asynchronous shell commands, yet")) |
2923 |
(when error-buffer |
(when error-buffer |
2924 |
(error "Tramp doesn't grok optional third arg ERROR-BUFFER, yet")) |
(error "Tramp doesn't grok optional third arg ERROR-BUFFER, yet")) |
2925 |
(save-excursion |
(save-excursion |
2926 |
(tramp-barf-unless-okay |
(tramp-barf-unless-okay |
2927 |
multi-method method user host |
multi-method method user host |
2928 |
(format "cd %s" (tramp-shell-quote-argument path)) |
(format "cd %s" (tramp-shell-quote-argument path)) |
2929 |
nil 'file-error |
nil 'file-error |
2930 |
"tramp-handle-shell-command: Couldn't `cd %s'" |
"tramp-handle-shell-command: Couldn't `cd %s'" |
2931 |
(tramp-shell-quote-argument path)) |
(tramp-shell-quote-argument path)) |
2932 |
(tramp-send-command multi-method method user host |
(tramp-send-command multi-method method user host |
2933 |
(concat command "; tramp_old_status=$?")) |
(concat command "; tramp_old_status=$?")) |
2934 |
;; This will break if the shell command prints "/////" |
;; This will break if the shell command prints "/////" |
2935 |
;; somewhere. Let's just hope for the best... |
;; somewhere. Let's just hope for the best... |
2936 |
(tramp-wait-for-output)) |
(tramp-wait-for-output)) |
2937 |
(unless output-buffer |
(unless output-buffer |
2938 |
(setq output-buffer (get-buffer-create "*Shell Command Output*")) |
(setq output-buffer (get-buffer-create "*Shell Command Output*")) |
2939 |
|
(set-buffer output-buffer) |
2940 |
|
(erase-buffer)) |
2941 |
|
(unless (bufferp output-buffer) |
2942 |
|
(setq output-buffer (current-buffer))) |
2943 |
(set-buffer output-buffer) |
(set-buffer output-buffer) |
2944 |
(erase-buffer)) |
(insert-buffer (tramp-get-buffer multi-method method user host)) |
2945 |
(unless (bufferp output-buffer) |
(save-excursion |
2946 |
(setq output-buffer (current-buffer))) |
(tramp-send-command multi-method method user host "cd") |
2947 |
(set-buffer output-buffer) |
(tramp-wait-for-output) |
2948 |
(insert-buffer (tramp-get-buffer multi-method method user host)) |
(tramp-send-command |
2949 |
(save-excursion |
multi-method method user host |
2950 |
(tramp-send-command multi-method method user host "cd") |
(concat "tramp_set_exit_status $tramp_old_status;" |
2951 |
(tramp-wait-for-output) |
" echo tramp_exit_status $?")) |
2952 |
(tramp-send-command |
(tramp-wait-for-output) |
2953 |
multi-method method user host |
(goto-char (point-max)) |
2954 |
(concat "tramp_set_exit_status $tramp_old_status;" |
(unless (search-backward "tramp_exit_status " nil t) |
2955 |
" echo tramp_exit_status $?")) |
(error "Couldn't find exit status of `%s'" command)) |
2956 |
(tramp-wait-for-output) |
(skip-chars-forward "^ ") |
2957 |
(goto-char (point-max)) |
(setq status (read (current-buffer)))) |
2958 |
(unless (search-backward "tramp_exit_status " nil t) |
(unless (zerop (buffer-size)) |
2959 |
(error "Couldn't find exit status of `%s'" command)) |
(pop-to-buffer output-buffer)) |
2960 |
(skip-chars-forward "^ ") |
status)) |
2961 |
(setq status (read (current-buffer)))) |
;; The following is only executed if something strange was |
2962 |
(unless (zerop (buffer-size)) |
;; happening. Emit a helpful message and do it anyway. |
2963 |
(pop-to-buffer output-buffer)) |
(message "tramp-handle-shell-command called with non-tramp directory: `%s'" |
2964 |
status))) |
default-directory) |
2965 |
;; The following is only executed if something strange was |
(tramp-run-real-handler 'shell-command |
2966 |
;; happening. Emit a helpful message and do it anyway. |
(list command output-buffer error-buffer)))) |
|
(message "tramp-handle-shell-command called with non-tramp directory: `%s'" |
|
|
default-directory) |
|
|
(tramp-run-real-handler 'shell-command |
|
|
(list command output-buffer error-buffer))) |
|
2967 |
|
|
2968 |
;; File Editing. |
;; File Editing. |
2969 |
|
|