comparison lisp/net/tramp.el @ 104216:bf65b05e8cf1

* net/tramp.el (tramp-get-ls-command-with-dired): New defun. (tramp-handle-insert-directory): Handle "--dired". (Bug#4075)
author Michael Albinus <michael.albinus@gmx.de>
date Sun, 09 Aug 2009 14:27:45 +0000
parents 49b412e99f1e
children b9b60c07064d
comparison
equal deleted inserted replaced
104215:eec5a3966960 104216:bf65b05e8cf1
139 139
140 ;; Load foreign FISH method. 140 ;; Load foreign FISH method.
141 'tramp-fish 141 'tramp-fish
142 142
143 ;; tramp-gvfs needs D-Bus messages. Available since Emacs 23 143 ;; tramp-gvfs needs D-Bus messages. Available since Emacs 23
144 ;; on some system types. 144 ;; on some system types. We don't call `dbus-ping', because
145 ;; this would load dbus.el.
145 (when (and (featurep 'dbusbind) 146 (when (and (featurep 'dbusbind)
146 (condition-case nil 147 (condition-case nil
147 (funcall 'dbus-get-unique-name :session) 148 (funcall 'dbus-get-unique-name :session)
148 (error nil)) 149 (error nil))
149 (tramp-compat-process-running-p "gvfs-fuse-daemon")) 150 (tramp-compat-process-running-p "gvfs-fuse-daemon"))
3639 (with-parsed-tramp-file-name filename nil 3640 (with-parsed-tramp-file-name filename nil
3640 (if (and (featurep 'ls-lisp) 3641 (if (and (featurep 'ls-lisp)
3641 (not (symbol-value 'ls-lisp-use-insert-directory-program))) 3642 (not (symbol-value 'ls-lisp-use-insert-directory-program)))
3642 (tramp-run-real-handler 3643 (tramp-run-real-handler
3643 'insert-directory (list filename switches wildcard full-directory-p)) 3644 'insert-directory (list filename switches wildcard full-directory-p))
3644 ;; For the moment, we assume that the remote "ls" program does not 3645 (when (and (string-match "^--dired\\s-+" switches)
3645 ;; grok "--dired". In the future, we should detect this on 3646 (not (tramp-get-ls-command-with-dired v)))
3646 ;; connection setup.
3647 (when (string-match "^--dired\\s-+" switches)
3648 (setq switches (replace-match "" nil t switches))) 3647 (setq switches (replace-match "" nil t switches)))
3649 (tramp-message 3648 (tramp-message
3650 v 4 "Inserting directory `ls %s %s', wildcard %s, fulldir %s" 3649 v 4 "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
3651 switches filename (if wildcard "yes" "no") 3650 switches filename (if wildcard "yes" "no")
3652 (if full-directory-p "yes" "no")) 3651 (if full-directory-p "yes" "no"))
3691 'file-name-nondirectory (list localname))))) 3690 'file-name-nondirectory (list localname)))))
3692 "" 3691 ""
3693 (tramp-shell-quote-argument 3692 (tramp-shell-quote-argument
3694 (tramp-run-real-handler 3693 (tramp-run-real-handler
3695 'file-name-nondirectory (list localname))))))) 3694 'file-name-nondirectory (list localname)))))))
3696 ;; We cannot use `insert-buffer-substring' because the Tramp buffer 3695 (let ((beg (point)))
3697 ;; changes its contents before insertion due to calling 3696 ;; We cannot use `insert-buffer-substring' because the Tramp
3698 ;; `expand-file' and alike. 3697 ;; buffer changes its contents before insertion due to calling
3699 (insert 3698 ;; `expand-file' and alike.
3700 (with-current-buffer (tramp-get-buffer v) 3699 (insert
3701 (buffer-string)))))) 3700 (with-current-buffer (tramp-get-buffer v)
3701 (buffer-string)))
3702
3703 ;; Check for "--dired" output.
3704 (goto-char (point-max))
3705 (forward-line -2)
3706 (when (looking-at "//DIRED//")
3707 (let ((end (line-end-position))
3708 (linebeg (point)))
3709 ;; Now read the numeric positions of file names.
3710 (goto-char linebeg)
3711 (forward-word 1)
3712 (forward-char 3)
3713 (while (< (point) end)
3714 (let ((start (+ beg (read (current-buffer))))
3715 (end (+ beg (read (current-buffer)))))
3716 (if (memq (char-after end) '(?\n ?\s))
3717 ;; End is followed by \n or by " -> ".
3718 (put-text-property start end 'dired-filename t)))))
3719 ;; Reove training lines.
3720 (goto-char (point-max))
3721 (forward-line -1)
3722 (while (looking-at "//")
3723 (forward-line 1)
3724 (delete-region (match-beginning 0) (point))
3725 (forward-line -1))))
3726 (goto-char (point-max)))))
3702 3727
3703 (defun tramp-handle-unhandled-file-name-directory (filename) 3728 (defun tramp-handle-unhandled-file-name-directory (filename)
3704 "Like `unhandled-file-name-directory' for Tramp files." 3729 "Like `unhandled-file-name-directory' for Tramp files."
3705 ;; With Emacs 23, we could simply return `nil'. But we must keep it 3730 ;; With Emacs 23, we could simply return `nil'. But we must keep it
3706 ;; for backward compatibility. 3731 ;; for backward compatibility.
7357 vec (format "%s -lnd /" result))) 7382 vec (format "%s -lnd /" result)))
7358 (throw 'ls-found result)) 7383 (throw 'ls-found result))
7359 (setq dl (cdr dl)))))) 7384 (setq dl (cdr dl))))))
7360 (tramp-error vec 'file-error "Couldn't find a proper `ls' command"))))) 7385 (tramp-error vec 'file-error "Couldn't find a proper `ls' command")))))
7361 7386
7387 (defun tramp-get-ls-command-with-dired (vec)
7388 (save-match-data
7389 (with-connection-property vec "ls-dired"
7390 (tramp-message vec 5 "Checking, whether `ls --dired' works")
7391 (zerop (tramp-send-command-and-check
7392 vec (format "%s --diredd /" (tramp-get-ls-command vec)))))))
7393
7362 (defun tramp-get-test-command (vec) 7394 (defun tramp-get-test-command (vec)
7363 (with-connection-property vec "test" 7395 (with-connection-property vec "test"
7364 (with-current-buffer (tramp-get-buffer vec) 7396 (with-current-buffer (tramp-get-buffer vec)
7365 (tramp-message vec 5 "Finding a suitable `test' command") 7397 (tramp-message vec 5 "Finding a suitable `test' command")
7366 (if (zerop (tramp-send-command-and-check vec "test 0")) 7398 (if (zerop (tramp-send-command-and-check vec "test 0"))
7812 ;; place where it's actually needed: around any potentially 7844 ;; place where it's actually needed: around any potentially
7813 ;; indefinitely blocking piece of code. In this case it would be 7845 ;; indefinitely blocking piece of code. In this case it would be
7814 ;; within Tramp around one of its calls to accept-process-output (or 7846 ;; within Tramp around one of its calls to accept-process-output (or
7815 ;; around one of the loops that calls accept-process-output) 7847 ;; around one of the loops that calls accept-process-output)
7816 ;; (Stefan Monnier). 7848 ;; (Stefan Monnier).
7817 ;; * Autodetect if remote `ls' groks the "--dired" switch.
7818 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using 7849 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
7819 ;; `shell-quote-argument'. 7850 ;; `shell-quote-argument'.
7820 ;; * In Emacs 21, `insert-directory' shows total number of bytes used 7851 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
7821 ;; by the files in that directory. Add this here. 7852 ;; by the files in that directory. Add this here.
7822 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman) 7853 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
7829 ;; if it does show files when run locally. 7860 ;; if it does show files when run locally.
7830 ;; * How to deal with MULE in `insert-file-contents' and `write-region'? 7861 ;; * How to deal with MULE in `insert-file-contents' and `write-region'?
7831 ;; * Grok `append' parameter for `write-region'. 7862 ;; * Grok `append' parameter for `write-region'.
7832 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'? 7863 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'?
7833 ;; * abbreviate-file-name 7864 ;; * abbreviate-file-name
7834 ;; * better error checking. At least whenever we see something 7865 ;; * Better error checking. At least whenever we see something
7835 ;; strange when doing zerop, we should kill the process and start 7866 ;; strange when doing zerop, we should kill the process and start
7836 ;; again. (Greg Stark) 7867 ;; again. (Greg Stark)
7837 ;; * Provide a local cache of old versions of remote files for the rsync 7868 ;; * Provide a local cache of old versions of remote files for the rsync
7838 ;; transfer method to use. (Greg Stark) 7869 ;; transfer method to use. (Greg Stark)
7839 ;; * Remove unneeded parameters from methods. 7870 ;; * Remove unneeded parameters from methods.