comparison lisp/ido.el @ 62985:d1cbfe7309c1

(ido-make-merged-file-list-1): New defun split from ido-make-merged-file-list. (ido-make-merged-file-list): Bind throw-on-input around call to ido-make-merged-file-list-1. Return input-pending-p if interrupted by more input available. (ido-read-internal): Handle input-pending-p return value from ido-make-merged-file-list.
author Kim F. Storm <storm@cua.dk>
date Fri, 03 Jun 2005 23:21:58 +0000
parents 43a311177040
children bf364cb1c987 01137c1fdbe9
comparison
equal deleted inserted replaced
62984:4bb4e96b2e17 62985:d1cbfe7309c1
1644 (oign ido-ignored-list) 1644 (oign ido-ignored-list)
1645 (omat ido-matches) 1645 (omat ido-matches)
1646 (l (ido-make-merged-file-list ido-text-init 1646 (l (ido-make-merged-file-list ido-text-init
1647 (eq ido-use-merged-list 'auto) 1647 (eq ido-use-merged-list 'auto)
1648 (eq ido-try-merged-list 'wide)))) 1648 (eq ido-try-merged-list 'wide))))
1649 (ido-trace "merged" l)
1649 (cond 1650 (cond
1650 ((not l) 1651 ((not l)
1651 (if (eq ido-try-merged-list 'wide) 1652 (if (eq ido-try-merged-list 'wide)
1652 (setq ido-pre-merge-state 1653 (setq ido-pre-merge-state
1653 (list "" ido-current-directory olist oign omat) 1654 (list "" ido-current-directory olist oign omat)
1663 ido-keep-item-list t 1664 ido-keep-item-list t
1664 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil) 1665 ido-try-merged-list (if (eq ido-use-merged-list 'auto) 'auto nil)
1665 ido-use-merged-list nil))) 1666 ido-use-merged-list nil)))
1666 ((eq l t) 1667 ((eq l t)
1667 (setq ido-use-merged-list nil)) 1668 (setq ido-use-merged-list nil))
1669 ((eq l 'input-pending-p)
1670 (setq ido-try-merged-list t
1671 ido-use-merged-list nil))
1668 (t 1672 (t
1669 (setq ido-pre-merge-state 1673 (setq ido-pre-merge-state
1670 (list ido-text-init ido-current-directory olist oign omat)) 1674 (list ido-text-init ido-current-directory olist oign omat))
1671 (ido-set-current-directory (car (cdr (car l)))) 1675 (ido-set-current-directory (car (cdr (car l))))
1672 (if (ido-final-slash ido-text-init) 1676 (if (ido-final-slash ido-text-init)
2491 (if (and dir 2495 (if (and dir
2492 (not (equal dir ido-current-directory)) 2496 (not (equal dir ido-current-directory))
2493 (file-directory-p dir) 2497 (file-directory-p dir)
2494 (or (not must-match) 2498 (or (not must-match)
2495 ;; TODO. check for nonreadable and too-big. 2499 ;; TODO. check for nonreadable and too-big.
2496 (ido-set-matches1 2500 (ido-set-matches-1
2497 (if (eq ido-cur-item 'file) 2501 (if (eq ido-cur-item 'file)
2498 (ido-make-file-list1 dir) 2502 (ido-make-file-list-1 dir)
2499 (ido-make-dir-list1 dir))))) 2503 (ido-make-dir-list-1 dir)))))
2500 (setq j n) 2504 (setq j n)
2501 (setq dir nil))) 2505 (setq dir nil)))
2502 (if dir 2506 (if dir
2503 (setq ido-work-directory-index i)) 2507 (setq ido-work-directory-index i))
2504 dir)) 2508 dir))
2784 ;; Return unsorted list of all competions. 2788 ;; Return unsorted list of all competions.
2785 (let ((ido-process-ignore-lists nil) 2789 (let ((ido-process-ignore-lists nil)
2786 (ido-directory-too-big nil)) 2790 (ido-directory-too-big nil))
2787 (cond 2791 (cond
2788 ((eq ido-cur-item 'file) 2792 ((eq ido-cur-item 'file)
2789 (ido-make-file-list1 ido-current-directory)) 2793 (ido-make-file-list-1 ido-current-directory))
2790 ((eq ido-cur-item 'dir) 2794 ((eq ido-cur-item 'dir)
2791 (ido-make-dir-list1 ido-current-directory)) 2795 (ido-make-dir-list-1 ido-current-directory))
2792 ((eq ido-cur-item 'buffer) 2796 ((eq ido-cur-item 'buffer)
2793 (ido-make-buffer-list1)) 2797 (ido-make-buffer-list-1))
2794 ((eq ido-cur-item 'list) 2798 ((eq ido-cur-item 'list)
2795 ido-choice-list) 2799 ido-choice-list)
2796 (t nil)))) 2800 (t nil))))
2797 2801
2798 2802
2906 (setq res (cons (concat (car dirs) file) res) 2910 (setq res (cons (concat (car dirs) file) res)
2907 dirs (cdr dirs)))) 2911 dirs (cdr dirs))))
2908 (setq items (cdr items))) 2912 (setq items (cdr items)))
2909 res)) 2913 res))
2910 2914
2915
2916 (defun ido-make-merged-file-list-1 (text auto wide)
2917 (let (res)
2918 (if (and (ido-final-slash text) ido-dir-file-cache)
2919 (if wide
2920 (setq res (ido-wide-find-dirs-or-files
2921 ido-current-directory (substring text 0 -1) ido-enable-prefix t))
2922 ;; Use list of cached directories
2923 (let ((re (concat (regexp-quote (substring text 0 -1)) "[^/:]*/\\'"))
2924 (dirs ido-dir-file-cache)
2925 dir b d f)
2926 (if nil ;; simple
2927 (while dirs
2928 (setq dir (car (car dirs))
2929 dirs (cdr dirs))
2930 (when (and (string-match re dir)
2931 (not (ido-ignore-item-p dir ido-ignore-directories-merge))
2932 (file-directory-p dir))
2933 (setq b (substring dir 0 -1)
2934 f (concat (file-name-nondirectory b) "/")
2935 d (file-name-directory b)
2936 res (cons (cons f d) res))))
2937 (while dirs
2938 (setq dir (car dirs)
2939 d (car dir)
2940 dirs (cdr dirs))
2941 (when (not (ido-ignore-item-p d ido-ignore-directories-merge))
2942 (setq dir (cdr (cdr dir)))
2943 (while dir
2944 (setq f (car dir)
2945 dir (cdr dir))
2946 (if (and (string-match re f)
2947 (not (ido-ignore-item-p f ido-ignore-directories)))
2948 (setq res (cons (cons f d) res)))))
2949 (if (and auto (input-pending-p))
2950 (setq dirs nil
2951 res t))))))
2952 (if wide
2953 (setq res (ido-wide-find-dirs-or-files
2954 ido-current-directory text ido-enable-prefix nil))
2955 (let ((ido-text text)
2956 (dirs ido-work-directory-list)
2957 (must-match (and text (> (length text) 0)))
2958 dir fl)
2959 (if (and auto (not (member ido-current-directory dirs)))
2960 (setq dirs (cons ido-current-directory dirs)))
2961 (while dirs
2962 (setq dir (car dirs)
2963 dirs (cdr dirs))
2964 (when (and dir (stringp dir)
2965 (or ido-merge-ftp-work-directories
2966 (not (ido-is-ftp-directory dir)))
2967 (file-directory-p dir)
2968 ;; TODO. check for nonreadable and too-big.
2969 (setq fl (if (eq ido-cur-item 'file)
2970 (ido-make-file-list-1 dir t)
2971 (ido-make-dir-list-1 dir t))))
2972 (if must-match
2973 (setq fl (ido-set-matches-1 fl)))
2974 (if fl
2975 (setq res (nconc fl res))))
2976 (if (and auto (input-pending-p))
2977 (setq dirs nil
2978 res t))))))
2979 res))
2980
2911 (defun ido-make-merged-file-list (text auto wide) 2981 (defun ido-make-merged-file-list (text auto wide)
2912 (let (res) 2982 (let (res)
2913 (message "Searching for `%s'...." text) 2983 (message "Searching for `%s'...." text)
2914 (condition-case nil 2984 (condition-case nil
2915 (if (and (ido-final-slash text) ido-dir-file-cache) 2985 (unless (catch 'input-pending-p
2916 (if wide 2986 (let ((throw-on-input 'input-pending-p))
2917 (setq res (ido-wide-find-dirs-or-files 2987 (setq res (ido-make-merged-file-list-1 text auto wide))
2918 ido-current-directory (substring text 0 -1) ido-enable-prefix t)) 2988 t))
2919 ;; Use list of cached directories 2989 (setq res 'input-pending-p))
2920 (let ((re (concat (regexp-quote (substring text 0 -1)) "[^/:]*/\\'")) 2990 (quit
2921 (dirs ido-dir-file-cache) 2991 (setq res t
2922 dir b d f) 2992 ido-try-merged-list nil
2923 (if nil ;; simple 2993 ido-use-merged-list nil)))
2924 (while dirs 2994 (when (and res (listp res))
2925 (setq dir (car (car dirs)) 2995 (setq res (ido-sort-merged-list res auto)))
2926 dirs (cdr dirs))
2927 (when (and (string-match re dir)
2928 (not (ido-ignore-item-p dir ido-ignore-directories-merge))
2929 (file-directory-p dir))
2930 (setq b (substring dir 0 -1)
2931 f (concat (file-name-nondirectory b) "/")
2932 d (file-name-directory b)
2933 res (cons (cons f d) res))))
2934 (while dirs
2935 (setq dir (car dirs)
2936 d (car dir)
2937 dirs (cdr dirs))
2938 (when (not (ido-ignore-item-p d ido-ignore-directories-merge))
2939 (setq dir (cdr (cdr dir)))
2940 (while dir
2941 (setq f (car dir)
2942 dir (cdr dir))
2943 (if (and (string-match re f)
2944 (not (ido-ignore-item-p f ido-ignore-directories)))
2945 (setq res (cons (cons f d) res)))))
2946 (if (and auto (input-pending-p))
2947 (setq dirs nil
2948 res t))))))
2949 (if wide
2950 (setq res (ido-wide-find-dirs-or-files
2951 ido-current-directory text ido-enable-prefix nil))
2952 (let ((ido-text text)
2953 (dirs ido-work-directory-list)
2954 (must-match (and text (> (length text) 0)))
2955 dir fl)
2956 (if (and auto (not (member ido-current-directory dirs)))
2957 (setq dirs (cons ido-current-directory dirs)))
2958 (while dirs
2959 (setq dir (car dirs)
2960 dirs (cdr dirs))
2961 (when (and dir (stringp dir)
2962 (or ido-merge-ftp-work-directories
2963 (not (ido-is-ftp-directory dir)))
2964 (file-directory-p dir)
2965 ;; TODO. check for nonreadable and too-big.
2966 (setq fl (if (eq ido-cur-item 'file)
2967 (ido-make-file-list1 dir t)
2968 (ido-make-dir-list1 dir t))))
2969 (if must-match
2970 (setq fl (ido-set-matches1 fl)))
2971 (if fl
2972 (setq res (nconc fl res))))
2973 (if (and auto (input-pending-p))
2974 (setq dirs nil
2975 res t))))))
2976 (quit (setq res t)))
2977 (if (and res (not (eq res t)))
2978 (setq res (ido-sort-merged-list res auto)))
2979 (when (and (or ido-rotate-temp ido-rotate-file-list-default) 2996 (when (and (or ido-rotate-temp ido-rotate-file-list-default)
2980 (listp res) 2997 (listp res)
2981 (> (length text) 0)) 2998 (> (length text) 0))
2982 (let ((elt (assoc text res))) 2999 (let ((elt (assoc text res)))
2983 (when (and elt (not (eq elt (car res)))) 3000 (when (and elt (not (eq elt (car res))))
2984 (setq res (delq elt res)) 3001 (setq res (delq elt res))
2985 (setq res (cons elt res))))) 3002 (setq res (cons elt res)))))
2986 (message nil) 3003 (message nil)
2987 res)) 3004 res))
2988 3005
2989 (defun ido-make-buffer-list1 (&optional frame visible) 3006 (defun ido-make-buffer-list-1 (&optional frame visible)
2990 ;; Return list of non-ignored buffer names 3007 ;; Return list of non-ignored buffer names
2991 (delq nil 3008 (delq nil
2992 (mapcar 3009 (mapcar
2993 (lambda (x) 3010 (lambda (x)
2994 (let ((name (buffer-name x))) 3011 (let ((name (buffer-name x)))
3002 ;; The hook `ido-make-buflist-hook' is run after the list has been 3019 ;; The hook `ido-make-buflist-hook' is run after the list has been
3003 ;; created to allow the user to further modify the order of the buffer names 3020 ;; created to allow the user to further modify the order of the buffer names
3004 ;; in this list. If DEFAULT is non-nil, and corresponds to an existing buffer, 3021 ;; in this list. If DEFAULT is non-nil, and corresponds to an existing buffer,
3005 ;; it is put to the start of the list. 3022 ;; it is put to the start of the list.
3006 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current)) 3023 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current))
3007 (ido-temp-list (ido-make-buffer-list1 (selected-frame) ido-current-buffers))) 3024 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
3008 (if ido-temp-list 3025 (if ido-temp-list
3009 (nconc ido-temp-list ido-current-buffers) 3026 (nconc ido-temp-list ido-current-buffers)
3010 (setq ido-temp-list ido-current-buffers)) 3027 (setq ido-temp-list ido-current-buffers))
3011 (if default 3028 (if default
3012 (progn 3029 (progn
3039 items) 3056 items)
3040 (if ido-temp-list 3057 (if ido-temp-list
3041 (nconc ido-temp-list items) 3058 (nconc ido-temp-list items)
3042 (setq ido-temp-list items))) 3059 (setq ido-temp-list items)))
3043 3060
3044 (defun ido-file-name-all-completions1 (dir) 3061 (defun ido-file-name-all-completions-1 (dir)
3045 (cond 3062 (cond
3046 ((ido-nonreadable-directory-p dir) '()) 3063 ((ido-nonreadable-directory-p dir) '())
3047 ;; do not check (ido-directory-too-big-p dir) here. 3064 ;; do not check (ido-directory-too-big-p dir) here.
3048 ;; Caller must have done that if necessary. 3065 ;; Caller must have done that if necessary.
3049 ((and ido-enable-tramp-completion 3066 ((and ido-enable-tramp-completion
3096 cached nil))) 3113 cached nil)))
3097 (unless cached 3114 (unless cached
3098 (if (and ftp (file-readable-p dir)) 3115 (if (and ftp (file-readable-p dir))
3099 (setq mtime (cons 'ftp (ido-time-stamp)))) 3116 (setq mtime (cons 'ftp (ido-time-stamp))))
3100 (if mtime 3117 (if mtime
3101 (setq cached (cons dir (cons mtime (ido-file-name-all-completions1 dir))) 3118 (setq cached (cons dir (cons mtime (ido-file-name-all-completions-1 dir)))
3102 ido-dir-file-cache (cons cached ido-dir-file-cache))) 3119 ido-dir-file-cache (cons cached ido-dir-file-cache)))
3103 (if (> (length ido-dir-file-cache) ido-max-dir-file-cache) 3120 (if (> (length ido-dir-file-cache) ido-max-dir-file-cache)
3104 (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil))) 3121 (setcdr (nthcdr (1- ido-max-dir-file-cache) ido-dir-file-cache) nil)))
3105 (and cached 3122 (and cached
3106 (cdr (cdr cached)))) 3123 (cdr (cdr cached))))
3107 (ido-file-name-all-completions1 dir))) 3124 (ido-file-name-all-completions-1 dir)))
3108 3125
3109 (defun ido-remove-cached-dir (dir) 3126 (defun ido-remove-cached-dir (dir)
3110 ;; Remove dir from ido-dir-file-cache 3127 ;; Remove dir from ido-dir-file-cache
3111 (if (and ido-dir-file-cache 3128 (if (and ido-dir-file-cache
3112 (stringp dir) (> (length dir) 0)) 3129 (stringp dir) (> (length dir) 0))
3113 (let ((cached (assoc dir ido-dir-file-cache))) 3130 (let ((cached (assoc dir ido-dir-file-cache)))
3114 (if cached 3131 (if cached
3115 (setq ido-dir-file-cache (delq cached ido-dir-file-cache)))))) 3132 (setq ido-dir-file-cache (delq cached ido-dir-file-cache))))))
3116 3133
3117 3134
3118 (defun ido-make-file-list1 (dir &optional merged) 3135 (defun ido-make-file-list-1 (dir &optional merged)
3119 ;; Return list of non-ignored files in DIR 3136 ;; Return list of non-ignored files in DIR
3120 ;; If MERGED is non-nil, each file is cons'ed with DIR 3137 ;; If MERGED is non-nil, each file is cons'ed with DIR
3121 (and (or (ido-is-tramp-root dir) (file-directory-p dir)) 3138 (and (or (ido-is-tramp-root dir) (file-directory-p dir))
3122 (delq nil 3139 (delq nil
3123 (mapcar 3140 (mapcar
3130 ;; Return the current list of files. 3147 ;; Return the current list of files.
3131 ;; Currently visible files are put at the end of the list. 3148 ;; Currently visible files are put at the end of the list.
3132 ;; The hook `ido-make-file-list-hook' is run after the list has been 3149 ;; The hook `ido-make-file-list-hook' is run after the list has been
3133 ;; created to allow the user to further modify the order of the file names 3150 ;; created to allow the user to further modify the order of the file names
3134 ;; in this list. 3151 ;; in this list.
3135 (let ((ido-temp-list (ido-make-file-list1 ido-current-directory))) 3152 (let ((ido-temp-list (ido-make-file-list-1 ido-current-directory)))
3136 (setq ido-temp-list (sort ido-temp-list 3153 (setq ido-temp-list (sort ido-temp-list
3137 (if ido-file-extensions-order 3154 (if ido-file-extensions-order
3138 #'ido-file-extension-lessp 3155 #'ido-file-extension-lessp
3139 #'ido-file-lessp))) 3156 #'ido-file-lessp)))
3140 (let ((default-directory ido-current-directory)) 3157 (let ((default-directory ido-current-directory))
3166 (setq ido-temp-list (delete "." ido-temp-list)) 3183 (setq ido-temp-list (delete "." ido-temp-list))
3167 (setq ido-temp-list (cons "." ido-temp-list))) 3184 (setq ido-temp-list (cons "." ido-temp-list)))
3168 (run-hooks 'ido-make-file-list-hook) 3185 (run-hooks 'ido-make-file-list-hook)
3169 ido-temp-list)) 3186 ido-temp-list))
3170 3187
3171 (defun ido-make-dir-list1 (dir &optional merged) 3188 (defun ido-make-dir-list-1 (dir &optional merged)
3172 ;; Return list of non-ignored subdirs in DIR 3189 ;; Return list of non-ignored subdirs in DIR
3173 ;; If MERGED is non-nil, each subdir is cons'ed with DIR 3190 ;; If MERGED is non-nil, each subdir is cons'ed with DIR
3174 (and (or (ido-is-tramp-root dir) (file-directory-p dir)) 3191 (and (or (ido-is-tramp-root dir) (file-directory-p dir))
3175 (delq nil 3192 (delq nil
3176 (mapcar 3193 (mapcar
3182 (defun ido-make-dir-list (default) 3199 (defun ido-make-dir-list (default)
3183 ;; Return the current list of directories. 3200 ;; Return the current list of directories.
3184 ;; The hook `ido-make-dir-list-hook' is run after the list has been 3201 ;; The hook `ido-make-dir-list-hook' is run after the list has been
3185 ;; created to allow the user to further modify the order of the 3202 ;; created to allow the user to further modify the order of the
3186 ;; directory names in this list. 3203 ;; directory names in this list.
3187 (let ((ido-temp-list (ido-make-dir-list1 ido-current-directory))) 3204 (let ((ido-temp-list (ido-make-dir-list-1 ido-current-directory)))
3188 (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp)) 3205 (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp))
3189 (ido-to-end ;; move . files to end 3206 (ido-to-end ;; move . files to end
3190 (delq nil (mapcar 3207 (delq nil (mapcar
3191 (lambda (x) (if (string-equal (substring x 0 1) ".") x)) 3208 (lambda (x) (if (string-equal (substring x 0 1) ".") x))
3192 ido-temp-list))) 3209 ido-temp-list)))
3236 (setq ido-bufs-in-frame 3253 (setq ido-bufs-in-frame
3237 (cons buf ido-bufs-in-frame))))) 3254 (cons buf ido-bufs-in-frame)))))
3238 3255
3239 ;;; FIND MATCHING ITEMS 3256 ;;; FIND MATCHING ITEMS
3240 3257
3241 (defun ido-set-matches1 (items &optional do-full) 3258 (defun ido-set-matches-1 (items &optional do-full)
3242 ;; Return list of matches in items 3259 ;; Return list of matches in items
3243 (let* ((case-fold-search ido-case-fold) 3260 (let* ((case-fold-search ido-case-fold)
3244 (slash (and (not ido-enable-prefix) (ido-final-slash ido-text))) 3261 (slash (and (not ido-enable-prefix) (ido-final-slash ido-text)))
3245 (text (if slash (substring ido-text 0 -1) ido-text)) 3262 (text (if slash (substring ido-text 0 -1) ido-text))
3246 (rexq (concat (if ido-enable-regexp text (regexp-quote text)) (if slash ".*/" ""))) 3263 (rexq (concat (if ido-enable-regexp text (regexp-quote text)) (if slash ".*/" "")))
3294 3311
3295 3312
3296 (defun ido-set-matches () 3313 (defun ido-set-matches ()
3297 ;; Set `ido-matches' to the list of items matching prompt 3314 ;; Set `ido-matches' to the list of items matching prompt
3298 (when ido-rescan 3315 (when ido-rescan
3299 (setq ido-matches (ido-set-matches1 (reverse ido-cur-list) (not ido-rotate)) 3316 (setq ido-matches (ido-set-matches-1 (reverse ido-cur-list) (not ido-rotate))
3300 ido-rotate nil))) 3317 ido-rotate nil)))
3301 3318
3302 (defun ido-ignore-item-p (name re-list &optional ignore-ext) 3319 (defun ido-ignore-item-p (name re-list &optional ignore-ext)
3303 ;; Return t if the buffer or file NAME should be ignored. 3320 ;; Return t if the buffer or file NAME should be ignored.
3304 (or (member name ido-ignore-item-temp-list) 3321 (or (member name ido-ignore-item-temp-list)