diff options
| -rw-r--r-- | lisp/ido.el | 138 |
1 files changed, 105 insertions, 33 deletions
diff --git a/lisp/ido.el b/lisp/ido.el index c1d40df5c69..6bc2f45709f 100644 --- a/lisp/ido.el +++ b/lisp/ido.el | |||
| @@ -613,6 +613,7 @@ A tramp file name uses the following syntax: /method:user@host:filename." | |||
| 613 | 613 | ||
| 614 | (defcustom ido-cache-ftp-work-directory-time 1.0 | 614 | (defcustom ido-cache-ftp-work-directory-time 1.0 |
| 615 | "*Maximum time to cache contents of an ftp directory (in hours). | 615 | "*Maximum time to cache contents of an ftp directory (in hours). |
| 616 | Use C-l in prompt to refresh list. | ||
| 616 | If zero, ftp directories are not cached." | 617 | If zero, ftp directories are not cached." |
| 617 | :type 'number | 618 | :type 'number |
| 618 | :group 'ido) | 619 | :group 'ido) |
| @@ -629,6 +630,18 @@ equivalent function, e.g. `find-file' rather than `ido-find-file'." | |||
| 629 | :type '(repeat regexp) | 630 | :type '(repeat regexp) |
| 630 | :group 'ido) | 631 | :group 'ido) |
| 631 | 632 | ||
| 633 | (defcustom ido-unc-hosts nil | ||
| 634 | "*List of known UNC host names to complete after initial //." | ||
| 635 | :type '(repeat string) | ||
| 636 | :group 'ido) | ||
| 637 | |||
| 638 | (defcustom ido-cache-unc-host-shares-time 8.0 | ||
| 639 | "*Maximum time to cache shares of an UNC host (in hours). | ||
| 640 | Use C-l in prompt to refresh list. | ||
| 641 | If zero, unc host shares are not cached." | ||
| 642 | :type 'number | ||
| 643 | :group 'ido) | ||
| 644 | |||
| 632 | (defcustom ido-max-work-file-list 10 | 645 | (defcustom ido-max-work-file-list 10 |
| 633 | "*Maximum number of names of recently opened files to record. | 646 | "*Maximum number of names of recently opened files to record. |
| 634 | This is the list the file names (sans directory) which have most recently | 647 | This is the list the file names (sans directory) which have most recently |
| @@ -1103,6 +1116,16 @@ it doesn't interfere with other minibuffer usage.") | |||
| 1103 | (string-match "\\`/[^/]+[@:]\\'" | 1116 | (string-match "\\`/[^/]+[@:]\\'" |
| 1104 | (or dir ido-current-directory)))) | 1117 | (or dir ido-current-directory)))) |
| 1105 | 1118 | ||
| 1119 | (defun ido-is-unc-root (&optional dir) | ||
| 1120 | (and ido-unc-hosts | ||
| 1121 | (string-equal "//" | ||
| 1122 | (or dir ido-current-directory)))) | ||
| 1123 | |||
| 1124 | (defun ido-is-unc-host (&optional dir) | ||
| 1125 | (and ido-unc-hosts | ||
| 1126 | (string-match "\\`//[^/]+/\\'" | ||
| 1127 | (or dir ido-current-directory)))) | ||
| 1128 | |||
| 1106 | (defun ido-is-root-directory (&optional dir) | 1129 | (defun ido-is-root-directory (&optional dir) |
| 1107 | (setq dir (or dir ido-current-directory)) | 1130 | (setq dir (or dir ido-current-directory)) |
| 1108 | (or | 1131 | (or |
| @@ -1148,6 +1171,12 @@ it doesn't interfere with other minibuffer usage.") | |||
| 1148 | (or (not time) | 1171 | (or (not time) |
| 1149 | (< (- (ido-time-stamp) time) ido-cache-ftp-work-directory-time)))) | 1172 | (< (- (ido-time-stamp) time) ido-cache-ftp-work-directory-time)))) |
| 1150 | 1173 | ||
| 1174 | (defun ido-cache-unc-valid (&optional time) | ||
| 1175 | (and (numberp ido-cache-unc-host-shares-time) | ||
| 1176 | (> ido-cache-unc-host-shares-time 0) | ||
| 1177 | (or (not time) | ||
| 1178 | (< (- (ido-time-stamp) time) ido-cache-unc-host-shares-time)))) | ||
| 1179 | |||
| 1151 | (defun ido-may-cache-directory (&optional dir) | 1180 | (defun ido-may-cache-directory (&optional dir) |
| 1152 | (setq dir (or dir ido-current-directory)) | 1181 | (setq dir (or dir ido-current-directory)) |
| 1153 | (cond | 1182 | (cond |
| @@ -1157,10 +1186,11 @@ it doesn't interfere with other minibuffer usage.") | |||
| 1157 | (or ido-enable-tramp-completion | 1186 | (or ido-enable-tramp-completion |
| 1158 | (memq system-type '(windows-nt ms-dos)))) | 1187 | (memq system-type '(windows-nt ms-dos)))) |
| 1159 | nil) | 1188 | nil) |
| 1160 | ((not (ido-is-ftp-directory dir)) | 1189 | ((ido-is-unc-host dir) |
| 1161 | t) | 1190 | (ido-cache-unc-valid)) |
| 1162 | ((ido-cache-ftp-valid) | 1191 | ((ido-is-ftp-directory dir) |
| 1163 | t))) | 1192 | (ido-cache-ftp-valid)) |
| 1193 | (t t))) | ||
| 1164 | 1194 | ||
| 1165 | (defun ido-pp (list &optional sep) | 1195 | (defun ido-pp (list &optional sep) |
| 1166 | (let ((print-level nil) (eval-expression-print-level nil) | 1196 | (let ((print-level nil) (eval-expression-print-level nil) |
| @@ -1262,15 +1292,21 @@ Removes badly formatted data and ignored directories." | |||
| 1262 | (and | 1292 | (and |
| 1263 | (stringp dir) | 1293 | (stringp dir) |
| 1264 | (consp time) | 1294 | (consp time) |
| 1265 | (if (integerp (car time)) | 1295 | (cond |
| 1266 | (and (/= (car time) 0) | 1296 | ((integerp (car time)) |
| 1267 | (integerp (car (cdr time))) | 1297 | (and (/= (car time) 0) |
| 1268 | (/= (car (cdr time)) 0) | 1298 | (integerp (car (cdr time))) |
| 1269 | (ido-may-cache-directory dir)) | 1299 | (/= (car (cdr time)) 0) |
| 1270 | (and (eq (car time) 'ftp) | 1300 | (ido-may-cache-directory dir))) |
| 1271 | (numberp (cdr time)) | 1301 | ((eq (car time) 'ftp) |
| 1302 | (and (numberp (cdr time)) | ||
| 1272 | (ido-is-ftp-directory dir) | 1303 | (ido-is-ftp-directory dir) |
| 1273 | (ido-cache-ftp-valid (cdr time)))) | 1304 | (ido-cache-ftp-valid (cdr time)))) |
| 1305 | ((eq (car time) 'unc) | ||
| 1306 | (and (numberp (cdr time)) | ||
| 1307 | (ido-is-unc-host dir) | ||
| 1308 | (ido-cache-unc-valid (cdr time)))) | ||
| 1309 | (t nil)) | ||
| 1274 | (let ((s files) (ok t)) | 1310 | (let ((s files) (ok t)) |
| 1275 | (while s | 1311 | (while s |
| 1276 | (if (stringp (car s)) | 1312 | (if (stringp (car s)) |
| @@ -1535,6 +1571,7 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise." | |||
| 1535 | ;; connect on incomplete tramp paths (after entring just method:). | 1571 | ;; connect on incomplete tramp paths (after entring just method:). |
| 1536 | (let ((ido-enable-tramp-completion nil)) | 1572 | (let ((ido-enable-tramp-completion nil)) |
| 1537 | (and (ido-final-slash dir) | 1573 | (and (ido-final-slash dir) |
| 1574 | (not (ido-is-unc-host dir)) | ||
| 1538 | (file-directory-p dir) | 1575 | (file-directory-p dir) |
| 1539 | (not (file-readable-p dir))))) | 1576 | (not (file-readable-p dir))))) |
| 1540 | 1577 | ||
| @@ -1545,6 +1582,7 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise." | |||
| 1545 | (let ((ido-enable-tramp-completion nil)) | 1582 | (let ((ido-enable-tramp-completion nil)) |
| 1546 | (and (numberp ido-max-directory-size) | 1583 | (and (numberp ido-max-directory-size) |
| 1547 | (ido-final-slash dir) | 1584 | (ido-final-slash dir) |
| 1585 | (not (ido-is-unc-host dir)) | ||
| 1548 | (file-directory-p dir) | 1586 | (file-directory-p dir) |
| 1549 | (> (nth 7 (file-attributes dir)) ido-max-directory-size)))) | 1587 | (> (nth 7 (file-attributes dir)) ido-max-directory-size)))) |
| 1550 | 1588 | ||
| @@ -1560,8 +1598,18 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise." | |||
| 1560 | (unless (and ido-enable-tramp-completion | 1598 | (unless (and ido-enable-tramp-completion |
| 1561 | (string-match "\\`/[^/]*@\\'" dir)) | 1599 | (string-match "\\`/[^/]*@\\'" dir)) |
| 1562 | (setq dir (ido-final-slash dir t)))) | 1600 | (setq dir (ido-final-slash dir t)))) |
| 1563 | (if (equal dir ido-current-directory) | 1601 | (if (get-buffer ido-completion-buffer) |
| 1564 | nil | 1602 | (kill-buffer ido-completion-buffer)) |
| 1603 | (cond | ||
| 1604 | ((equal dir ido-current-directory) | ||
| 1605 | nil) | ||
| 1606 | ((ido-is-unc-root dir) | ||
| 1607 | (ido-trace "unc" dir) | ||
| 1608 | (setq ido-current-directory dir) | ||
| 1609 | (setq ido-directory-nonreadable nil) | ||
| 1610 | (setq ido-directory-too-big nil) | ||
| 1611 | t) | ||
| 1612 | (t | ||
| 1565 | (ido-trace "cd" dir) | 1613 | (ido-trace "cd" dir) |
| 1566 | (setq ido-current-directory dir) | 1614 | (setq ido-current-directory dir) |
| 1567 | (if (get-buffer ido-completion-buffer) | 1615 | (if (get-buffer ido-completion-buffer) |
| @@ -1569,7 +1617,7 @@ With ARG, turn ido speed-up on if arg is positive, off otherwise." | |||
| 1569 | (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir)) | 1617 | (setq ido-directory-nonreadable (ido-nonreadable-directory-p dir)) |
| 1570 | (setq ido-directory-too-big (and (not ido-directory-nonreadable) | 1618 | (setq ido-directory-too-big (and (not ido-directory-nonreadable) |
| 1571 | (ido-directory-too-big-p dir))) | 1619 | (ido-directory-too-big-p dir))) |
| 1572 | t)) | 1620 | t))) |
| 1573 | 1621 | ||
| 1574 | (defun ido-set-current-home (&optional dir) | 1622 | (defun ido-set-current-home (&optional dir) |
| 1575 | ;; Set ido's current directory to user's home directory | 1623 | ;; Set ido's current directory to user's home directory |
| @@ -1940,6 +1988,7 @@ If INITIAL is non-nil, it specifies the initial input string." | |||
| 1940 | (setq ido-exit 'fallback | 1988 | (setq ido-exit 'fallback |
| 1941 | done t) | 1989 | done t) |
| 1942 | (setq ido-set-default-item t))) | 1990 | (setq ido-set-default-item t))) |
| 1991 | |||
| 1943 | ((or (string-match "[/\\][^/\\]" ido-selected) | 1992 | ((or (string-match "[/\\][^/\\]" ido-selected) |
| 1944 | (and (memq system-type '(windows-nt ms-dos)) | 1993 | (and (memq system-type '(windows-nt ms-dos)) |
| 1945 | (string-match "\\`.:" ido-selected))) | 1994 | (string-match "\\`.:" ido-selected))) |
| @@ -3184,36 +3233,52 @@ for first matching file." | |||
| 3184 | (defun ido-file-name-all-completions (dir) | 3233 | (defun ido-file-name-all-completions (dir) |
| 3185 | ;; Return name of all files in DIR | 3234 | ;; Return name of all files in DIR |
| 3186 | ;; Uses and updates ido-dir-file-cache | 3235 | ;; Uses and updates ido-dir-file-cache |
| 3187 | (if (and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0) | 3236 | (cond |
| 3188 | (stringp dir) (> (length dir) 0) | 3237 | ((ido-is-unc-root dir) |
| 3189 | (ido-may-cache-directory dir)) | 3238 | (mapcar |
| 3190 | (let* ((cached (assoc dir ido-dir-file-cache)) | 3239 | (lambda (host) |
| 3240 | (if (string-match "/\\'" host) host (concat host "/"))) | ||
| 3241 | ido-unc-hosts)) | ||
| 3242 | ((and (numberp ido-max-dir-file-cache) (> ido-max-dir-file-cache 0) | ||
| 3243 | (stringp dir) (> (length dir) 0) | ||
| 3244 | (ido-may-cache-directory dir)) | ||
| 3245 | (let* ((cached (assoc dir ido-dir-file-cache)) | ||
| 3191 | (ctime (nth 1 cached)) | 3246 | (ctime (nth 1 cached)) |
| 3192 | (ftp (ido-is-ftp-directory dir)) | 3247 | (ftp (ido-is-ftp-directory dir)) |
| 3193 | (attr (if ftp nil (file-attributes dir))) | 3248 | (unc (ido-is-unc-host dir)) |
| 3249 | (attr (if (or ftp unc) nil (file-attributes dir))) | ||
| 3194 | (mtime (nth 5 attr)) | 3250 | (mtime (nth 5 attr)) |
| 3195 | valid) | 3251 | valid) |
| 3196 | (when cached ; should we use the cached entry ? | 3252 | (when cached ; should we use the cached entry ? |
| 3197 | (if ftp | 3253 | (cond |
| 3198 | (setq valid (and (eq (car ctime) 'ftp) | 3254 | (ftp |
| 3199 | (ido-cache-ftp-valid (cdr ctime)))) | 3255 | (setq valid (and (eq (car ctime) 'ftp) |
| 3256 | (ido-cache-ftp-valid (cdr ctime))))) | ||
| 3257 | (unc | ||
| 3258 | (setq valid (and (eq (car ctime) 'unc) | ||
| 3259 | (ido-cache-unc-valid (cdr ctime))))) | ||
| 3260 | (t | ||
| 3200 | (if attr | 3261 | (if attr |
| 3201 | (setq valid (and (= (car ctime) (car mtime)) | 3262 | (setq valid (and (= (car ctime) (car mtime)) |
| 3202 | (= (car (cdr ctime)) (car (cdr mtime))))))) | 3263 | (= (car (cdr ctime)) (car (cdr mtime)))))))) |
| 3203 | (if (not valid) | 3264 | (unless valid |
| 3204 | (setq ido-dir-file-cache (delq cached ido-dir-file-cache) | 3265 | (setq ido-dir-file-cache (delq cached ido-dir-file-cache) |
| 3205 | cached nil))) | 3266 | cached nil))) |
| 3206 | (unless cached | 3267 | (unless cached |
| 3207 | (if (and ftp (file-readable-p dir)) | 3268 | (cond |
| 3208 | (setq mtime (cons 'ftp (ido-time-stamp)))) | 3269 | (unc |
| 3270 | (setq mtime (cons 'unc (ido-time-stamp)))) | ||
| 3271 | ((and ftp (file-readable-p dir)) | ||
| 3272 | (setq mtime (cons 'ftp (ido-time-stamp))))) | ||
| 3209 | (if mtime | 3273 | (if mtime |
| 3210 | (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir))) | 3274 | (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir))) |
| 3211 | ido-dir-file-cache (cons cached ido-dir-file-cache))) | 3275 | ido-dir-file-cache (cons cached ido-dir-file-cache))) |
| 3212 | (if (> (length ido-dir-file-cache) ido-max-dir-file-cache) | 3276 | (if (> (length ido-dir-file-cache) ido-max-dir-file-cache) |
| 3213 | (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil))) | 3277 | (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil))) |
| 3214 | (and cached | 3278 | (and cached |
| 3215 | (cdr (cdr cached)))) | 3279 | (cdr (cdr cached))))) |
| 3216 | (ido-file-name-all-completions-1 dir))) | 3280 | (t |
| 3281 | (ido-file-name-all-completions-1 dir)))) | ||
| 3217 | 3282 | ||
| 3218 | (defun ido-remove-cached-dir (dir) | 3283 | (defun ido-remove-cached-dir (dir) |
| 3219 | ;; Remove dir from ido-dir-file-cache | 3284 | ;; Remove dir from ido-dir-file-cache |
| @@ -3227,7 +3292,8 @@ for first matching file." | |||
| 3227 | (defun ido-make-file-list-1 (dir &optional merged) | 3292 | (defun ido-make-file-list-1 (dir &optional merged) |
| 3228 | ;; Return list of non-ignored files in DIR | 3293 | ;; Return list of non-ignored files in DIR |
| 3229 | ;; If MERGED is non-nil, each file is cons'ed with DIR | 3294 | ;; If MERGED is non-nil, each file is cons'ed with DIR |
| 3230 | (and (or (ido-is-tramp-root dir) (file-directory-p dir)) | 3295 | (and (or (ido-is-tramp-root dir) (ido-is-unc-root dir) |
| 3296 | (file-directory-p dir)) | ||
| 3231 | (delq nil | 3297 | (delq nil |
| 3232 | (mapcar | 3298 | (mapcar |
| 3233 | (lambda (name) | 3299 | (lambda (name) |
| @@ -3956,10 +4022,16 @@ For details of keybindings, do `\\[describe-function] ido-find-file'." | |||
| 3956 | ) | 4022 | ) |
| 3957 | 4023 | ||
| 3958 | ((= (length contents) 1) | 4024 | ((= (length contents) 1) |
| 3959 | (when (and (ido-is-tramp-root) (string-equal contents "/")) | 4025 | (cond |
| 4026 | ((and (ido-is-tramp-root) (string-equal contents "/")) | ||
| 3960 | (ido-set-current-directory ido-current-directory contents) | 4027 | (ido-set-current-directory ido-current-directory contents) |
| 3961 | (setq refresh t)) | 4028 | (setq refresh t)) |
| 3962 | ) | 4029 | ((and ido-unc-hosts (string-equal contents "/") |
| 4030 | (let ((ido-enable-tramp-completion nil)) | ||
| 4031 | (ido-is-root-directory))) | ||
| 4032 | (ido-set-current-directory "//") | ||
| 4033 | (setq refresh t)) | ||
| 4034 | )) | ||
| 3963 | 4035 | ||
| 3964 | ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") contents) | 4036 | ((and (string-match (if ido-enable-tramp-completion "..[:@]\\'" "..:\\'") contents) |
| 3965 | (ido-is-root-directory)) ;; Ange-ftp or tramp | 4037 | (ido-is-root-directory)) ;; Ange-ftp or tramp |