comparison lisp/ido.el @ 63476:a02cb15bf34c

2005-06-15 Matt Hodges <MPHodges@member.fsf.org> * ido.el (ido-incomplete-regexp): New variable. (ido-set-matches-1): Handle invalid-regexp error and set ido-incomplete-regexp. (ido-incomplete-regexp): New face. (ido-completions): Use it. (ido-complete, ido-exit-minibuffer, ido-completions): Handle incomplete regexps. (ido-completions): Add check for complete match when entering a regexp.
author Kim F. Storm <storm@cua.dk>
date Wed, 15 Jun 2005 22:44:09 +0000
parents 0e0fb0040526
children 6fb026ad601f 82d495f87e7b
comparison
equal deleted inserted replaced
63475:69bb366fab26 63476:a02cb15bf34c
768 :width condensed)) 768 :width condensed))
769 (t (:inverse-video t))) 769 (t (:inverse-video t)))
770 "*Font used by ido for highlighting its indicators." 770 "*Font used by ido for highlighting its indicators."
771 :group 'ido) 771 :group 'ido)
772 772
773 (defface ido-incomplete-regexp
774 '((t
775 (:inherit font-lock-warning-face)))
776 "Ido face for indicating incomplete regexps."
777 :group 'ido)
778
773 (defcustom ido-make-file-list-hook nil 779 (defcustom ido-make-file-list-hook nil
774 "*List of functions to run when the list of matching files is created. 780 "*List of functions to run when the list of matching files is created.
775 Each function on the list may modify the dynamically bound variable 781 Each function on the list may modify the dynamically bound variable
776 `ido-temp-list' which contains the current list of matching files." 782 `ido-temp-list' which contains the current list of matching files."
777 :type 'hook 783 :type 'hook
957 (defvar ido-use-mycompletion-depth 0 963 (defvar ido-use-mycompletion-depth 0
958 "Non-nil means use `ido' completion feedback. 964 "Non-nil means use `ido' completion feedback.
959 Is set by ido functions to the current minibuffer-depth, so that 965 Is set by ido functions to the current minibuffer-depth, so that
960 it doesn't interfere with other minibuffer usage.") 966 it doesn't interfere with other minibuffer usage.")
961 967
968 (defvar ido-incomplete-regexp nil
969 "Non-nil if an incomplete regexp is entered.")
962 970
963 ;;; Variables with dynamic bindings. 971 ;;; Variables with dynamic bindings.
964 ;;; Declared here to keep the byte compiler quiet. 972 ;;; Declared here to keep the byte compiler quiet.
965 973
966 ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list). 974 ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list).
2168 (defun ido-complete () 2176 (defun ido-complete ()
2169 "Try and complete the current pattern amongst the file names." 2177 "Try and complete the current pattern amongst the file names."
2170 (interactive) 2178 (interactive)
2171 (let (res) 2179 (let (res)
2172 (cond 2180 (cond
2181 (ido-incomplete-regexp
2182 ;; Do nothing
2183 )
2173 ((and (memq ido-cur-item '(file dir)) 2184 ((and (memq ido-cur-item '(file dir))
2174 (string-match "[$]" ido-text)) 2185 (string-match "[$]" ido-text))
2175 (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text)))) 2186 (let ((evar (substitute-in-file-name (concat ido-current-directory ido-text))))
2176 (if (not (file-exists-p (file-name-directory evar))) 2187 (if (not (file-exists-p (file-name-directory evar)))
2177 (message "Expansion generates non-existing directory name") 2188 (message "Expansion generates non-existing directory name")
2392 (exit-minibuffer)))) 2403 (exit-minibuffer))))
2393 2404
2394 (defun ido-exit-minibuffer () 2405 (defun ido-exit-minibuffer ()
2395 "Exit minibuffer, but make sure we have a match if one is needed." 2406 "Exit minibuffer, but make sure we have a match if one is needed."
2396 (interactive) 2407 (interactive)
2397 (if (or (not ido-require-match) 2408 (if (and (or (not ido-require-match)
2398 (ido-existing-item-p)) 2409 (ido-existing-item-p))
2410 (not ido-incomplete-regexp))
2399 (exit-minibuffer))) 2411 (exit-minibuffer)))
2400 2412
2401 (defun ido-select-text () 2413 (defun ido-select-text ()
2402 "Select the buffer or file named by the prompt. 2414 "Select the buffer or file named by the prompt.
2403 If no buffer or file exactly matching the prompt exists, maybe create a new one." 2415 If no buffer or file exactly matching the prompt exists, maybe create a new one."
3273 (= (length ido-text) 0))) 3285 (= (length ido-text) 0)))
3274 3286
3275 full-matches 3287 full-matches
3276 prefix-matches 3288 prefix-matches
3277 matches) 3289 matches)
3278 (mapcar 3290 (setq ido-incomplete-regexp nil)
3279 (lambda (item) 3291 (condition-case error
3280 (let ((name (ido-name item))) 3292 (mapcar
3281 (if (and (or non-prefix-dot 3293 (lambda (item)
3282 (if (= (aref ido-text 0) ?.) 3294 (let ((name (ido-name item)))
3283 (= (aref name 0) ?.) 3295 (if (and (or non-prefix-dot
3284 (/= (aref name 0) ?.))) 3296 (if (= (aref ido-text 0) ?.)
3285 (string-match re name)) 3297 (= (aref name 0) ?.)
3286 (cond 3298 (/= (aref name 0) ?.)))
3287 ((and full-re (string-match full-re name)) 3299 (string-match re name))
3288 (setq full-matches (cons item full-matches))) 3300 (cond
3289 ((and prefix-re (string-match prefix-re name)) 3301 ((and full-re (string-match full-re name))
3290 (setq prefix-matches (cons item prefix-matches))) 3302 (setq full-matches (cons item full-matches)))
3291 (t (setq matches (cons item matches)))))) 3303 ((and prefix-re (string-match prefix-re name))
3292 t) 3304 (setq prefix-matches (cons item prefix-matches)))
3293 items) 3305 (t (setq matches (cons item matches))))))
3306 t)
3307 items)
3308 (invalid-regexp
3309 (setq ido-incomplete-regexp t
3310 ;; Consider the invalid regexp message internally as a
3311 ;; special-case single match, and handle appropriately
3312 ;; elsewhere.
3313 matches (cdr error))))
3294 (if prefix-matches 3314 (if prefix-matches
3295 (setq matches (nconc prefix-matches matches))) 3315 (setq matches (nconc prefix-matches matches)))
3296 (if full-matches 3316 (if full-matches
3297 (setq matches (nconc full-matches matches))) 3317 (setq matches (nconc full-matches matches)))
3298 (when (and (null matches) 3318 (when (and (null matches)
4046 (let* ((fn (ido-name (car comps))) 4066 (let* ((fn (ido-name (car comps)))
4047 (ln (length fn))) 4067 (ln (length fn)))
4048 (setq first (format "%s" fn)) 4068 (setq first (format "%s" fn))
4049 (put-text-property 0 ln 'face 4069 (put-text-property 0 ln 'face
4050 (if (= (length comps) 1) 4070 (if (= (length comps) 1)
4051 'ido-only-match 4071 (if ido-incomplete-regexp
4072 'ido-incomplete-regexp
4073 'ido-only-match)
4052 'ido-first-match) 4074 'ido-first-match)
4053 first) 4075 first)
4054 (if ind (setq first (concat first ind))) 4076 (if ind (setq first (concat first ind)))
4055 (setq comps (cons first (cdr comps))))) 4077 (setq comps (cons first (cdr comps)))))
4056 4078
4061 (ido-directory-too-big 4083 (ido-directory-too-big
4062 (or (nth 9 ido-decorations) " [Too big]")) 4084 (or (nth 9 ido-decorations) " [Too big]"))
4063 (ido-report-no-match 4085 (ido-report-no-match
4064 (nth 6 ido-decorations)) ;; [No match] 4086 (nth 6 ido-decorations)) ;; [No match]
4065 (t ""))) 4087 (t "")))
4066 4088 (ido-incomplete-regexp
4089 (concat " " (car comps)))
4067 ((null (cdr comps)) ;one match 4090 ((null (cdr comps)) ;one match
4068 (concat (if (> (length (ido-name (car comps))) (length name)) 4091 (concat (if (if (not ido-enable-regexp)
4069 ;; when there is one match, show the matching file name in full 4092 (= (length (ido-name (car comps))) (length name))
4070 (concat (nth 4 ido-decorations) ;; [ ... ] 4093 ;; We can't rely on the length of the input
4071 (ido-name (car comps)) 4094 ;; for regexps, so explicitly check for a
4072 (nth 5 ido-decorations)) 4095 ;; complete match
4073 "") 4096 (string-match name (ido-name (car comps)))
4097 (string-equal (match-string 0 (ido-name (car comps)))
4098 (ido-name (car comps))))
4099 ""
4100 ;; when there is one match, show the matching file name in full
4101 (concat (nth 4 ido-decorations) ;; [ ... ]
4102 (ido-name (car comps))
4103 (nth 5 ido-decorations)))
4074 (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched] 4104 (if (not ido-use-faces) (nth 7 ido-decorations)))) ;; [Matched]
4075 (t ;multiple matches 4105 (t ;multiple matches
4076 (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999)) 4106 (let* ((items (if (> ido-max-prospects 0) (1+ ido-max-prospects) 999))
4077 (alternatives 4107 (alternatives
4078 (apply 4108 (apply