aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2006-03-31 23:47:02 +0000
committerKim F. Storm2006-03-31 23:47:02 +0000
commit4c2ee078aaa8d5690578dfd22f725c61195c0737 (patch)
tree79d0b89e2e7a7f4b07239a3cd28f8ef45ea38ea8
parente701756a5a36a451e97ae12c50059f718cd725b8 (diff)
downloademacs-4c2ee078aaa8d5690578dfd22f725c61195c0737.tar.gz
emacs-4c2ee078aaa8d5690578dfd22f725c61195c0737.zip
(ido-unc-hosts-cache): New defvar.
(ido-unc-hosts): If value of defcustom is a function, call it to get list of UNC hosts. Add function-item choices to specify ido-unc-hosts-net-view or user function. (ido-ignore-unc-host-regexps): New defcustom. (ido-unc-hosts-net-view, ido-unc-hosts): New functions. (ido-is-unc-root, ido-is-unc-host, ido-file-name-all-completions) (ido-exhibit): Call ido-unc-hosts to get list of UNC hosts.
-rw-r--r--lisp/ido.el71
1 files changed, 65 insertions, 6 deletions
diff --git a/lisp/ido.el b/lisp/ido.el
index 3de76a36e07..e4ec2be700d 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -630,9 +630,28 @@ equivalent function, e.g. `find-file' rather than `ido-find-file'."
630 :type '(repeat regexp) 630 :type '(repeat regexp)
631 :group 'ido) 631 :group 'ido)
632 632
633(defvar ido-unc-hosts-cache t
634 "Cached value from ido-unc-hosts function.")
635
633(defcustom ido-unc-hosts nil 636(defcustom ido-unc-hosts nil
634 "*List of known UNC host names to complete after initial //." 637 "*List of known UNC host names to complete after initial //.
635 :type '(repeat string) 638If value is a function, that function is called to search network for
639hosts on first use of UNC path."
640 :type '(choice (repeat :tag "List of UNC host names" string)
641 (function-item :tag "Use `NET VIEW'"
642 :value ido-unc-hosts-net-view)
643 (function :tag "Your own function"))
644 :set #'(lambda (symbol value)
645 (set symbol value)
646 (setq ido-unc-hosts-cache t))
647 :group 'ido)
648
649(defcustom ido-ignore-unc-host-regexps nil
650 "*List of regexps matching UNC hosts to ignore."
651 :type '(repeat regexp)
652 :set #'(lambda (symbol value)
653 (set symbol value)
654 (setq ido-unc-hosts-cache t))
636 :group 'ido) 655 :group 'ido)
637 656
638(defcustom ido-cache-unc-host-shares-time 8.0 657(defcustom ido-cache-unc-host-shares-time 8.0
@@ -1111,18 +1130,58 @@ it doesn't interfere with other minibuffer usage.")
1111 (pop-to-buffer b t t) 1130 (pop-to-buffer b t t)
1112 (setq truncate-lines t))))) 1131 (setq truncate-lines t)))))
1113 1132
1133(defun ido-unc-hosts (&optional query)
1134 "Return list of UNC host names."
1135 (cond
1136 ((listp ido-unc-hosts)
1137 ido-unc-hosts) ;; static list or nil
1138 ((listp ido-unc-hosts-cache)
1139 ido-unc-hosts-cache) ;; result of net search
1140 ((and query (fboundp ido-unc-hosts))
1141 (message "Searching for UNC hosts...")
1142 (let ((hosts (funcall ido-unc-hosts)) host re-list re)
1143 (setq ido-unc-hosts-cache nil)
1144 (while hosts
1145 (setq host (downcase (car hosts))
1146 hosts (cdr hosts)
1147 re-list ido-ignore-unc-host-regexps)
1148 (while re-list
1149 (setq re (car re-list)
1150 re-list (cdr re-list))
1151 (if (string-match re host)
1152 (setq re-list nil
1153 host nil)))
1154 (if host
1155 (setq ido-unc-hosts-cache (cons host ido-unc-hosts-cache)))))
1156 (message nil)
1157 (setq ido-unc-hosts-cache
1158 (sort ido-unc-hosts-cache #'string<)))
1159 (query
1160 (setq ido-unc-hosts-cache nil))
1161 (t (fboundp ido-unc-hosts))))
1162
1163(defun ido-unc-hosts-net-view ()
1164 "Query network for list of UNC host names using `NET VIEW'."
1165 (let (hosts)
1166 (with-temp-buffer
1167 (shell-command "net view" t)
1168 (goto-char (point-min))
1169 (while (re-search-forward "^\\\\\\\\\\([[:graph:]]+\\)" nil t)
1170 (setq hosts (cons (match-string 1) hosts))))
1171 hosts))
1172
1114(defun ido-is-tramp-root (&optional dir) 1173(defun ido-is-tramp-root (&optional dir)
1115 (and ido-enable-tramp-completion 1174 (and ido-enable-tramp-completion
1116 (string-match "\\`/[^/]+[@:]\\'" 1175 (string-match "\\`/[^/]+[@:]\\'"
1117 (or dir ido-current-directory)))) 1176 (or dir ido-current-directory))))
1118 1177
1119(defun ido-is-unc-root (&optional dir) 1178(defun ido-is-unc-root (&optional dir)
1120 (and ido-unc-hosts 1179 (and (ido-unc-hosts)
1121 (string-equal "//" 1180 (string-equal "//"
1122 (or dir ido-current-directory)))) 1181 (or dir ido-current-directory))))
1123 1182
1124(defun ido-is-unc-host (&optional dir) 1183(defun ido-is-unc-host (&optional dir)
1125 (and ido-unc-hosts 1184 (and (ido-unc-hosts)
1126 (string-match "\\`//[^/]+/\\'" 1185 (string-match "\\`//[^/]+/\\'"
1127 (or dir ido-current-directory)))) 1186 (or dir ido-current-directory))))
1128 1187
@@ -3238,7 +3297,7 @@ for first matching file."
3238 (mapcar 3297 (mapcar
3239 (lambda (host) 3298 (lambda (host)
3240 (if (string-match "/\\'" host) host (concat host "/"))) 3299 (if (string-match "/\\'" host) host (concat host "/")))
3241 ido-unc-hosts)) 3300 (ido-unc-hosts t)))
3242 ((and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0) 3301 ((and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0)
3243 (stringp dir) (> (length dir) 0) 3302 (stringp dir) (> (length dir) 0)
3244 (ido-may-cache-directory dir)) 3303 (ido-may-cache-directory dir))
@@ -4026,7 +4085,7 @@ For details of keybindings, do `\\[describe-function] ido-find-file'."
4026 ((and (ido-is-tramp-root) (string-equal contents "/")) 4085 ((and (ido-is-tramp-root) (string-equal contents "/"))
4027 (ido-set-current-directory ido-current-directory contents) 4086 (ido-set-current-directory ido-current-directory contents)
4028 (setq refresh t)) 4087 (setq refresh t))
4029 ((and ido-unc-hosts (string-equal contents "/") 4088 ((and (ido-unc-hosts) (string-equal contents "/")
4030 (let ((ido-enable-tramp-completion nil)) 4089 (let ((ido-enable-tramp-completion nil))
4031 (ido-is-root-directory))) 4090 (ido-is-root-directory)))
4032 (ido-set-current-directory "//") 4091 (ido-set-current-directory "//")