Mercurial > emacs
comparison lisp/ido.el @ 90370:e3bacb89536a
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-46
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 157-163)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 58-61)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 19 Mar 2006 19:43:57 +0000 |
parents | 8a1ee48a8386 4a6d7cd41a8f |
children | 482dfed28bee |
comparison
equal
deleted
inserted
replaced
90369:88810aee3a45 | 90370:e3bacb89536a |
---|---|
611 :type 'boolean | 611 :type 'boolean |
612 :group 'ido) | 612 :group 'ido) |
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) |
619 | 620 |
620 (defcustom ido-slow-ftp-hosts nil | 621 (defcustom ido-slow-ftp-hosts nil |
625 :group 'ido) | 626 :group 'ido) |
626 | 627 |
627 (defcustom ido-slow-ftp-host-regexps nil | 628 (defcustom ido-slow-ftp-host-regexps nil |
628 "*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')." | 629 "*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')." |
629 :type '(repeat regexp) | 630 :type '(repeat regexp) |
631 :group 'ido) | |
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 | |
630 :group 'ido) | 643 :group 'ido) |
631 | 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 |
1099 (setq truncate-lines t))))) | 1112 (setq truncate-lines t))))) |
1100 | 1113 |
1101 (defun ido-is-tramp-root (&optional dir) | 1114 (defun ido-is-tramp-root (&optional dir) |
1102 (and ido-enable-tramp-completion | 1115 (and ido-enable-tramp-completion |
1103 (string-match "\\`/[^/]+[@:]\\'" | 1116 (string-match "\\`/[^/]+[@:]\\'" |
1117 (or dir ido-current-directory)))) | |
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 "\\`//[^/]+/\\'" | |
1104 (or dir ido-current-directory)))) | 1127 (or dir ido-current-directory)))) |
1105 | 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 |
1146 (and (numberp ido-cache-ftp-work-directory-time) | 1169 (and (numberp ido-cache-ftp-work-directory-time) |
1147 (> ido-cache-ftp-work-directory-time 0) | 1170 (> ido-cache-ftp-work-directory-time 0) |
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 |
1154 ((ido-directory-too-big-p dir) | 1183 ((ido-directory-too-big-p dir) |
1155 nil) | 1184 nil) |
1156 ((and (ido-is-root-directory dir) | 1185 ((and (ido-is-root-directory dir) |
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) |
1167 (print-length nil) (eval-expression-print-length nil)) | 1197 (print-length nil) (eval-expression-print-length nil)) |
1168 (insert "\n;; ----- " (symbol-name list) " -----\n(\n ") | 1198 (insert "\n;; ----- " (symbol-name list) " -----\n(\n ") |
1260 (time (car (cdr (car l)))) | 1290 (time (car (cdr (car l)))) |
1261 (files (cdr (cdr (car l))))) | 1291 (files (cdr (cdr (car l))))) |
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)) |
1277 (setq s (cdr s)) | 1313 (setq s (cdr s)) |
1278 (setq s nil ok nil))) | 1314 (setq s nil ok nil))) |
1533 ;; Return t if dir is a directory, but not readable | 1569 ;; Return t if dir is a directory, but not readable |
1534 ;; Do not check for non-readable directories via tramp, as this causes a premature | 1570 ;; Do not check for non-readable directories via tramp, as this causes a premature |
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 |
1541 (defun ido-directory-too-big-p (dir) | 1578 (defun ido-directory-too-big-p (dir) |
1542 ;; Return t if dir is a directory, but too big to show | 1579 ;; Return t if dir is a directory, but too big to show |
1543 ;; Do not check for non-readable directories via tramp, as this causes a premature | 1580 ;; Do not check for non-readable directories via tramp, as this causes a premature |
1544 ;; connect on incomplete tramp paths (after entring just method:). | 1581 ;; connect on incomplete tramp paths (after entring just method:). |
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 |
1551 (defun ido-set-current-directory (dir &optional subdir no-merge) | 1589 (defun ido-set-current-directory (dir &optional subdir no-merge) |
1552 ;; Set ido's current directory to DIR or DIR/SUBDIR | 1590 ;; Set ido's current directory to DIR or DIR/SUBDIR |
1558 (when subdir | 1596 (when subdir |
1559 (setq dir (concat dir subdir)) | 1597 (setq dir (concat dir subdir)) |
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) |
1568 (kill-buffer ido-completion-buffer)) | 1616 (kill-buffer ido-completion-buffer)) |
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 |
1576 (ido-set-current-directory (expand-file-name (or dir "~/")))) | 1624 (ido-set-current-directory (expand-file-name (or dir "~/")))) |
1577 | 1625 |
1938 (ido-trace "tramp prefix" ido-selected) | 1986 (ido-trace "tramp prefix" ido-selected) |
1939 (if (ido-is-slow-ftp-host) | 1987 (if (ido-is-slow-ftp-host) |
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))) |
1946 (ido-set-current-directory (file-name-directory ido-selected)) | 1995 (ido-set-current-directory (file-name-directory ido-selected)) |
1947 (setq ido-set-default-item t)) | 1996 (setq ido-set-default-item t)) |
1971 ido-selected)) | 2020 ido-selected)) |
1972 | 2021 |
1973 (defun ido-edit-input () | 2022 (defun ido-edit-input () |
1974 "Edit absolute file name entered so far with ido; terminate by RET." | 2023 "Edit absolute file name entered so far with ido; terminate by RET." |
1975 (interactive) | 2024 (interactive) |
1976 (setq ido-text-init ido-text) | 2025 (setq ido-text-init (if ido-matches (car ido-matches) ido-text)) |
1977 (setq ido-exit 'edit) | 2026 (setq ido-exit 'edit) |
1978 (exit-minibuffer)) | 2027 (exit-minibuffer)) |
1979 | 2028 |
1980 ;;; MAIN FUNCTIONS | 2029 ;;; MAIN FUNCTIONS |
1981 (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd) | 2030 (defun ido-buffer-internal (method &optional fallback prompt default initial switch-cmd) |
3182 (file-name-all-completions "" dir)))) | 3231 (file-name-all-completions "" dir)))) |
3183 | 3232 |
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 |
3220 (if (and ido-dir-file-cache | 3285 (if (and ido-dir-file-cache |
3221 (stringp dir) (> (length dir) 0)) | 3286 (stringp dir) (> (length dir) 0)) |
3225 | 3290 |
3226 | 3291 |
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) |
3234 (if (not (ido-ignore-item-p name ido-ignore-files t)) | 3300 (if (not (ido-ignore-item-p name ido-ignore-files t)) |
3235 (if merged (cons name dir) name))) | 3301 (if merged (cons name dir) name))) |
3954 | 4020 |
3955 ((= (length contents) 0) | 4021 ((= (length contents) 0) |
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 |
3966 (ido-set-current-directory ido-current-directory contents) | 4038 (ido-set-current-directory ido-current-directory contents) |
3967 (when (ido-is-slow-ftp-host) | 4039 (when (ido-is-slow-ftp-host) |