diff options
| author | Michael Albinus | 2015-11-01 13:43:35 +0100 |
|---|---|---|
| committer | Michael Albinus | 2015-11-01 13:43:35 +0100 |
| commit | df660da45bbde075ac8990cdef73128a37413a41 (patch) | |
| tree | 34ed329b99a7217f5b93b069b9d8362deb462312 | |
| parent | 150066727c063e2f16ee617947d63ec8ca5793ca (diff) | |
| download | emacs-df660da45bbde075ac8990cdef73128a37413a41.tar.gz emacs-df660da45bbde075ac8990cdef73128a37413a41.zip | |
Improve completion in tramp-gvfs.el
* lisp/net/tramp-gvfs.el (tramp-zeroconf-parse-device-names):
Renamed from `tramp-zeroconf-parse-service-device-names'.
(tramp-zeroconf-parse-webdav-device-names): Removed. Code merged
with `tramp-zeroconf-parse-device-names'.
(tramp-gvfs-parse-device-names): New defun.
(top): Use it when `tramp-zeroconf-parse-device-names' is not
applicable.
* lisp/net/tramp.el (tramp-set-completion-function): The argument
could also be a zeroconf service type.
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 77 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 20 |
2 files changed, 68 insertions, 29 deletions
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index b93c4cf57a5..8683241fcd1 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -1722,14 +1722,7 @@ be used." | |||
| 1722 | 1722 | ||
| 1723 | ;; D-Bus zeroconf functions. | 1723 | ;; D-Bus zeroconf functions. |
| 1724 | 1724 | ||
| 1725 | (defun tramp-zeroconf-parse-service-device-names (service) | 1725 | (defun tramp-zeroconf-parse-device-names (service) |
| 1726 | "Return a list of (user host) tuples allowed to access." | ||
| 1727 | (mapcar | ||
| 1728 | (lambda (x) | ||
| 1729 | (list nil (zeroconf-service-host x))) | ||
| 1730 | (zeroconf-list-services service))) | ||
| 1731 | |||
| 1732 | (defun tramp-zeroconf-parse-webdav-device-names (_ignore) | ||
| 1733 | "Return a list of (user host) tuples allowed to access." | 1726 | "Return a list of (user host) tuples allowed to access." |
| 1734 | (mapcar | 1727 | (mapcar |
| 1735 | (lambda (x) | 1728 | (lambda (x) |
| @@ -1745,22 +1738,64 @@ be used." | |||
| 1745 | (setq user (match-string 1 (car text)))) | 1738 | (setq user (match-string 1 (car text)))) |
| 1746 | (setq text (cdr text))) | 1739 | (setq text (cdr text))) |
| 1747 | (list user host))) | 1740 | (list user host))) |
| 1748 | (zeroconf-list-services "_webdav._tcp"))) | 1741 | (zeroconf-list-services service))) |
| 1742 | |||
| 1743 | (defun tramp-gvfs-parse-device-names (service) | ||
| 1744 | "Return a list of (user host) tuples allowed to access. | ||
| 1745 | This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi." | ||
| 1746 | (let ((result | ||
| 1747 | (split-string | ||
| 1748 | (shell-command-to-string (format "avahi-browse -trkp %s" service)) | ||
| 1749 | "[\n\r]+" 'omit "^\\+;.*$"))) | ||
| 1750 | (tramp-compat-delete-dups | ||
| 1751 | (mapcar | ||
| 1752 | (lambda (x) | ||
| 1753 | (let* ((list (split-string x ";")) | ||
| 1754 | (host (nth 6 list)) | ||
| 1755 | (port (nth 8 list)) | ||
| 1756 | (text (split-string (nth 9 list) "\" \"" 'omit "\"")) | ||
| 1757 | user) | ||
| 1758 | ; (when (and port (not (string-equal port "0"))) | ||
| 1759 | ; (setq host (format "%s%s%s" host tramp-prefix-port-regexp port))) | ||
| 1760 | ;; A user is marked in a TXT field like "u=guest". | ||
| 1761 | (while text | ||
| 1762 | (when (string-match "u=\\(.+\\)$" (car text)) | ||
| 1763 | (setq user (match-string 1 (car text)))) | ||
| 1764 | (setq text (cdr text))) | ||
| 1765 | (list user host))) | ||
| 1766 | result)))) | ||
| 1749 | 1767 | ||
| 1750 | ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods. | 1768 | ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods. |
| 1751 | (when (and tramp-gvfs-enabled | 1769 | (when tramp-gvfs-enabled |
| 1752 | (member zeroconf-service-avahi (dbus-list-known-names :system))) | ||
| 1753 | (zeroconf-init tramp-gvfs-zeroconf-domain) | 1770 | (zeroconf-init tramp-gvfs-zeroconf-domain) |
| 1754 | (tramp-set-completion-function | 1771 | (if (zeroconf-list-service-types) |
| 1755 | "afp" '((tramp-zeroconf-parse-service-device-names "_afpovertcp._tcp"))) | 1772 | (progn |
| 1756 | (tramp-set-completion-function | 1773 | (tramp-set-completion-function |
| 1757 | "dav" '((tramp-zeroconf-parse-webdav-device-names ""))) | 1774 | "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp"))) |
| 1758 | (tramp-set-completion-function | 1775 | (tramp-set-completion-function |
| 1759 | "davs" '((tramp-zeroconf-parse-webdav-device-names ""))) | 1776 | "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp"))) |
| 1760 | (tramp-set-completion-function | 1777 | (tramp-set-completion-function |
| 1761 | "sftp" '((tramp-zeroconf-parse-service-device-names "_workstation._tcp"))) | 1778 | "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp"))) |
| 1762 | (tramp-set-completion-function | 1779 | (tramp-set-completion-function |
| 1763 | "smb" '((tramp-zeroconf-parse-service-device-names "_smb._tcp")))) | 1780 | "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp") |
| 1781 | (tramp-zeroconf-parse-device-names "_workstation._tcp"))) | ||
| 1782 | (when (member "smb" tramp-gvfs-methods) | ||
| 1783 | (tramp-set-completion-function | ||
| 1784 | "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp"))))) | ||
| 1785 | |||
| 1786 | (when (executable-find "avahi-browse") | ||
| 1787 | (tramp-set-completion-function | ||
| 1788 | "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp"))) | ||
| 1789 | (tramp-set-completion-function | ||
| 1790 | "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp"))) | ||
| 1791 | (tramp-set-completion-function | ||
| 1792 | "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp"))) | ||
| 1793 | (tramp-set-completion-function | ||
| 1794 | "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp") | ||
| 1795 | (tramp-gvfs-parse-device-names "_workstation._tcp"))) | ||
| 1796 | (when (member "smb" tramp-gvfs-methods) | ||
| 1797 | (tramp-set-completion-function | ||
| 1798 | "smb" '((tramp-gvfs-parse-device-names "_smb._tcp"))))))) | ||
| 1764 | 1799 | ||
| 1765 | 1800 | ||
| 1766 | ;; D-Bus SYNCE functions. | 1801 | ;; D-Bus SYNCE functions. |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 2f811bb73ca..89aad07ddfe 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -1765,14 +1765,18 @@ Example: | |||
| 1765 | (setcdr v (delete (car v) (cdr v)))) | 1765 | (setcdr v (delete (car v) (cdr v)))) |
| 1766 | ;; Check for function and file or registry key. | 1766 | ;; Check for function and file or registry key. |
| 1767 | (unless (and (functionp (nth 0 (car v))) | 1767 | (unless (and (functionp (nth 0 (car v))) |
| 1768 | (if (string-match "^HKEY_CURRENT_USER" (nth 1 (car v))) | 1768 | (cond |
| 1769 | ;; Windows registry. | 1769 | ;; Windows registry. |
| 1770 | (and (memq system-type '(cygwin windows-nt)) | 1770 | ((string-match "^HKEY_CURRENT_USER" (nth 1 (car v))) |
| 1771 | (zerop | 1771 | (and (memq system-type '(cygwin windows-nt)) |
| 1772 | (tramp-call-process | 1772 | (zerop |
| 1773 | v "reg" nil nil nil "query" (nth 1 (car v))))) | 1773 | (tramp-call-process |
| 1774 | ;; Configuration file. | 1774 | v "reg" nil nil nil "query" (nth 1 (car v)))))) |
| 1775 | (file-exists-p (nth 1 (car v))))) | 1775 | ;; Zeroconf service type. |
| 1776 | ((string-match | ||
| 1777 | "^_[[:alpha:]]+\\._[[:alpha:]]+$" (nth 1 (car v)))) | ||
| 1778 | ;; Configuration file. | ||
| 1779 | (t (file-exists-p (nth 1 (car v)))))) | ||
| 1776 | (setq r (delete (car v) r))) | 1780 | (setq r (delete (car v) r))) |
| 1777 | (setq v (cdr v))) | 1781 | (setq v (cdr v))) |
| 1778 | 1782 | ||