Index: tramp.el =================================================================== RCS file: /cvsroot/tramp/tramp/lisp/tramp.el,v retrieving revision 2.359.2.46 diff -u -r2.359.2.46 tramp.el --- tramp.el 7 Aug 2005 15:06:53 -0000 2.359.2.46 +++ tramp.el 3 Sep 2005 13:30:19 -0000 @@ -842,7 +842,7 @@ :type 'regexp) (defcustom tramp-password-prompt-regexp - "^.*\\([pP]assword\\|passphrase.*\\):address@hidden *" + "^.*\\([pP]assword\\|passphrase\\).*:address@hidden *" "*Regexp matching password-like prompts. The regexp should match at end of buffer. @@ -1362,26 +1362,53 @@ checked via the following code: (with-temp-buffer - (let ((bytes 1000) - (proc (start-process (buffer-name) (current-buffer) \"wc\" \"-c\"))) - (process-send-string proc (make-string bytes ?x)) - (process-send-eof proc) - (process-send-eof proc) - (accept-process-output proc 1) - (goto-char (point-min)) - (re-search-forward \"\\\\w+\") - (message \"Bytes sent: %s\\tBytes received: %s\" bytes (match-string 0)))) - -In the Emacs normally running Tramp, evaluate the above code. -You can do this, for example, by pasting it into the `*scratch*' -buffer and then hitting C-j with the cursor after the last -closing parenthesis. - -If your Emacs is buggy, the sent and received numbers will be -different. In that case, you'll want to set this variable to -some number. For those people who have needed it, the value 500 -seems to have worked well. There is no way to predict what value -you need; maybe you could just experiment a bit. + (let* ((user \"xxx\") (host \"yyy\") + (init 0) (step 50) + (sent init) (received init)) + (while (= sent received) + (setq sent (+ sent step)) + (erase-buffer) + (let ((proc (start-process (buffer-name) (current-buffer) + \"ssh\" \"-l\" user host \"wc\" \"-c\"))) + (when (memq (process-status proc) '(run open)) + (process-send-string proc (make-string sent ?\\ )) + (process-send-eof proc) + (process-send-eof proc)) + (while (not (progn (goto-char (point-min)) + (re-search-forward \"\\\\w+\" (point-max) t))) + (accept-process-output proc 1)) + (when (memq (process-status proc) '(run open)) + (setq received (string-to-number (match-string 0))) + (delete-process proc) + (message \"Bytes sent: %s\\tBytes received: %s\" sent received) + (sit-for 0)))) + (if (> sent (+ init step)) + (message \"You should set `tramp-chunksize' to a maximum of %s\" + (- sent step)) + (message \"Test does not work\") + (display-buffer (current-buffer)) + (sit-for 30)))) + +In the Emacs normally running Tramp, evaluate the above code +(replace \"xxx\" and \"yyy\" by the remote user and host name, +respectively). You can do this, for example, by pasting it into +the `*scratch*' buffer and then hitting C-j with the cursor after the +last closing parenthesis. Note that it works only if you have configured +\"ssh\" to run without password query, see ssh-agent(1). + +You will see the number of bytes sent successfully to the remote host. +If that number exceeds 1000, you can stop the execution by hitting +C-g, because your Emacs is likely clean. + +If your Emacs is buggy, the code stops and gives you an indication +about the value `tramp-chunksize' should be set. Maybe you could just +experiment a bit, e.g. changing the values of `init' and `step' +in the third line of the code. + +When it is necessary to set `tramp-chunksize', you might consider to +use an out-of-the-band method (like \"scp\") instead of an internal one +(like \"ssh\"), because setting `tramp-chunksize' to non-nil decreases +performance. Please raise a bug report via \"M-x tramp-bug\" if your system needs this variable to be set as well." @@ -1856,6 +1883,7 @@ (insert-file-contents . tramp-handle-insert-file-contents) (write-region . tramp-handle-write-region) (find-backup-file-name . tramp-handle-find-backup-file-name) + (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory) (dired-compress-file . tramp-handle-dired-compress-file) (dired-call-process . tramp-handle-dired-call-process) @@ -1863,7 +1891,7 @@ . tramp-handle-dired-recursive-delete-directory) (set-visited-file-modtime . tramp-handle-set-visited-file-modtime) (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)) - "Alist of handler functions. + "Alist of handler functions. Operations not mentioned here will be handled by the normal Emacs functions.") ;; Handlers for partial tramp file names. For GNU Emacs just @@ -2368,11 +2396,14 @@ (buffer-name))) (if time-list (tramp-run-real-handler 'set-visited-file-modtime (list time-list)) - (let ((f (buffer-file-name))) + (let ((f (buffer-file-name)) + coding-system-used) (with-parsed-tramp-file-name f nil (let* ((attr (file-attributes f)) ;; '(-1 65535) means file doesn't exists yet. (modtime (or (nth 5 attr) '(-1 65535)))) + (when (boundp 'last-coding-system-used) + (setq coding-system-used (symbol-value 'last-coding-system-used))) ;; We use '(0 0) as a don't-know value. See also ;; `tramp-handle-file-attributes-with-ls'. (if (not (equal modtime '(0 0))) @@ -2387,6 +2418,8 @@ (setq attr (buffer-substring (point) (progn (end-of-line) (point))))) (setq tramp-buffer-file-attributes attr)) + (when (boundp 'last-coding-system-used) + (set 'last-coding-system-used coding-system-used)) nil))))) ;; CCC continue here @@ -3747,7 +3780,7 @@ 'insert-file-contents) 'file-local-copy))) (file-local-copy filename))) - (result nil)) + coding-system-used result) (when visit (setq buffer-file-name filename) (set-visited-file-modtime) @@ -3756,10 +3789,15 @@ multi-method method user host 9 "Inserting local temp file `%s'..." local-copy) (setq result (insert-file-contents local-copy nil beg end replace)) + ;; Now `last-coding-system-used' has right value. Remember it. + (when (boundp 'last-coding-system-used) + (setq coding-system-used (symbol-value 'last-coding-system-used))) (tramp-message-for-buffer multi-method method user host 9 "Inserting local temp file `%s'...done" local-copy) (delete-file local-copy) + (when (boundp 'last-coding-system-used) + (set 'last-coding-system-used coding-system-used)) (list (expand-file-name filename) (second result)))))) @@ -3807,6 +3845,41 @@ (tramp-run-real-handler 'find-backup-file-name (list filename))))) +(defun tramp-handle-make-auto-save-file-name () + "Like `make-auto-save-file-name' for tramp files. +Returns a file name in `tramp-auto-save-directory' for autosaving this file." + (when tramp-auto-save-directory + (unless (file-exists-p tramp-auto-save-directory) + (make-directory tramp-auto-save-directory t))) + ;; jka-compr doesn't like auto-saving, so by appending "~" to the + ;; file name we make sure that jka-compr isn't used for the + ;; auto-save file. + (let ((buffer-file-name + (if tramp-auto-save-directory + (expand-file-name + (tramp-subst-strs-in-string + '(("_" . "|") + ("/" . "_a") + (":" . "_b") + ("|" . "__") + ("[" . "_l") + ("]" . "_r")) + (buffer-file-name)) + tramp-auto-save-directory) + (buffer-file-name)))) + ;; Run plain `make-auto-save-file-name'. There might be an advice when + ;; it is not a magic file name operation (since Emacs 22). + ;; We must deactivate it temporarily. + (if (not (ad-is-active 'make-auto-save-file-name)) + (tramp-run-real-handler + 'make-auto-save-file-name nil) + ;; else + (ad-deactivate 'make-auto-save-file-name) + (prog1 + (tramp-run-real-handler + 'make-auto-save-file-name nil) + (ad-activate 'make-auto-save-file-name))))) + ;; CCC grok APPEND, LOCKNAME, CONFIRM (defun tramp-handle-write-region @@ -3838,6 +3911,13 @@ (loc-dec (tramp-get-local-decoding multi-method method user host)) (trampbuf (get-buffer-create "*tramp output*")) (modes (file-modes filename)) + ;; We use this to save the value of `last-coding-system-used' + ;; after writing the tmp file. At the end of the function, + ;; we set `last-coding-system-used' to this saved value. + ;; This way, any intermediary coding systems used while + ;; talking to the remote shell or suchlike won't hose this + ;; variable. This approach was snarfed from ange-ftp.el. + coding-system-used tmpfil) ;; Write region into a tmp file. This isn't really needed if we ;; use an encoding function, but currently we use it always @@ -3854,6 +3934,9 @@ (if confirm ; don't pass this arg unless defined for backward compat. (list start end tmpfil append 'no-message lockname confirm) (list start end tmpfil append 'no-message lockname))) + ;; Now, `last-coding-system-used' has the right value. Remember it. + (when (boundp 'last-coding-system-used) + (setq coding-system-used (symbol-value 'last-coding-system-used))) ;; The permissions of the temporary file should be set. If ;; filename does not exist (eq modes nil) it has been renamed to ;; the backup file. This case `save-buffer' handles @@ -3960,6 +4043,9 @@ ;; We must pass modtime explicitely, because filename can be different ;; from (buffer-file-name), f.e. if `file-precious-flag' is set. (nth 5 (file-attributes filename)))) + ;; Make `last-coding-system-used' have the right value. + (when (boundp 'last-coding-system-used) + (set 'last-coding-system-used coding-system-used)) (when (or (eq visit t) (eq visit nil) (stringp visit)) @@ -4086,8 +4172,9 @@ (nth 2 args)) ; BUF ((member operation - (list 'set-visited-file-modtime 'verify-visited-file-modtime - ; XEmacs only + (list 'make-auto-save-file-name + 'set-visited-file-modtime 'verify-visited-file-modtime + ; XEmacs only 'backup-buffer)) (buffer-file-name (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer)))) @@ -6905,33 +6992,28 @@ ;; Auto saving to a special directory. -(defun tramp-make-auto-save-file-name (fn) - "Returns a file name in `tramp-auto-save-directory' for autosaving this file." - (when tramp-auto-save-directory - (unless (file-exists-p tramp-auto-save-directory) - (make-directory tramp-auto-save-directory t))) - ;; jka-compr doesn't like auto-saving, so by appending "~" to the - ;; file name we make sure that jka-compr isn't used for the - ;; auto-save file. - (let ((buffer-file-name (expand-file-name - (tramp-subst-strs-in-string '(("_" . "|") - ("/" . "_a") - (":" . "_b") - ("|" . "__") - ("[" . "_l") - ("]" . "_r")) - fn) - tramp-auto-save-directory))) - (make-auto-save-file-name))) - -(defadvice make-auto-save-file-name - (around tramp-advice-make-auto-save-file-name () activate) - "Invoke `tramp-make-auto-save-file-name' for tramp files." - (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name)) - tramp-auto-save-directory) - (setq ad-return-value - (tramp-make-auto-save-file-name (buffer-file-name))) - ad-do-it)) +(defun tramp-exists-file-name-handler (operation &rest args) + (let ((buffer-file-name "/") + (fnha file-name-handler-alist) + (check-file-name-operation operation) + (file-name-handler-alist + (list + (cons "/" + '(lambda (operation &rest args) + "Returns OPERATION if it is the one to be checked" + (if (equal check-file-name-operation operation) + operation + (let ((file-name-handler-alist fnha)) + (apply operation args)))))))) + (eq (apply operation args) operation))) + +(unless (tramp-exists-file-name-handler 'make-auto-save-file-name) + (defadvice make-auto-save-file-name + (around tramp-advice-make-auto-save-file-name () activate) + "Invoke `tramp-handle-make-auto-save-file-name' for tramp files." + (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name))) + (setq ad-return-value (tramp-handle-make-auto-save-file-name)) + ad-do-it))) ;; In Emacs < 22 and XEmacs < 21.5 autosaved remote files have ;; permission 0666 minus umask. This is a security threat. @@ -6949,7 +7031,7 @@ ;; auto-saved file belonging to another original file. This could ;; be a security threat. (set-file-modes buffer-auto-save-file-name - (or (file-modes bfn) #o600))))) + (or (file-modes bfn) (tramp-octal-to-decimal "0600")))))) (unless (or (> emacs-major-version 21) (and (featurep 'xemacs)