comparison lisp/ido.el @ 62378:4d270efed583

(ido-magic-forward-char, ido-magic-backward-char) (ido-magic-delete-char): New commands for C-f, C-b, C-d. (ido-wide-find-dir-or-delete-dir): New command for M-d. (ido-define-mode-map): Bind them. Add C-x prefix to fallback commands. (ido-read-file-name): Handle commands with ido property value equal to find-file as reading a file name, to allow C-d to enter dired. (ibuffer-find-file): Add ido property with value find-file.
author Kim F. Storm <storm@cua.dk>
date Sun, 15 May 2005 23:03:36 +0000
parents e002770fe3ac
children 43a311177040
comparison
equal deleted inserted replaced
62377:720fa1d7457c 62378:4d270efed583
1390 (define-key map [(control ?@)] 'ido-restrict-to-matches) 1390 (define-key map [(control ?@)] 'ido-restrict-to-matches)
1391 (define-key map [right] 'ido-next-match) 1391 (define-key map [right] 'ido-next-match)
1392 (define-key map [left] 'ido-prev-match) 1392 (define-key map [left] 'ido-prev-match)
1393 (define-key map "?" 'ido-completion-help) 1393 (define-key map "?" 'ido-completion-help)
1394 1394
1395 ;; Magic commands.
1396 (define-key map "\C-b" 'ido-magic-backward-char)
1397 (define-key map "\C-f" 'ido-magic-forward-char)
1398 (define-key map "\C-d" 'ido-magic-delete-char)
1399
1395 (when (memq ido-cur-item '(file dir)) 1400 (when (memq ido-cur-item '(file dir))
1396 (define-key map "\C-b" (or ido-context-switch-command 'ido-enter-switch-buffer)) 1401 (define-key map "\C-x\C-b" (or ido-context-switch-command 'ido-enter-switch-buffer))
1397 (define-key map "\C-d" (or (and ido-context-switch-command 'ignore) 'ido-enter-dired)) 1402 (define-key map "\C-x\C-f" 'ido-fallback-command)
1398 (define-key map "\C-f" 'ido-fallback-command) 1403 (define-key map "\C-x\C-d" (or (and ido-context-switch-command 'ignore) 'ido-enter-dired))
1399 (define-key map [down] 'ido-next-match-dir) 1404 (define-key map [down] 'ido-next-match-dir)
1400 (define-key map [up] 'ido-prev-match-dir) 1405 (define-key map [up] 'ido-prev-match-dir)
1401 (define-key map [(meta up)] 'ido-prev-work-directory) 1406 (define-key map [(meta up)] 'ido-prev-work-directory)
1402 (define-key map [(meta down)] 'ido-next-work-directory) 1407 (define-key map [(meta down)] 'ido-next-work-directory)
1403 (define-key map [backspace] 'ido-delete-backward-updir) 1408 (define-key map [backspace] 'ido-delete-backward-updir)
1404 (define-key map "\d" 'ido-delete-backward-updir) 1409 (define-key map "\d" 'ido-delete-backward-updir)
1405 (define-key map [(meta backspace)] 'ido-delete-backward-word-updir) 1410 (define-key map [(meta backspace)] 'ido-delete-backward-word-updir)
1406 (define-key map [(control backspace)] 'ido-up-directory) 1411 (define-key map [(control backspace)] 'ido-up-directory)
1407 (define-key map "\C-l" 'ido-reread-directory) 1412 (define-key map "\C-l" 'ido-reread-directory)
1408 (define-key map [(meta ?d)] 'ido-wide-find-dir) 1413 (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
1409 (define-key map [(meta ?b)] 'ido-push-dir) 1414 (define-key map [(meta ?b)] 'ido-push-dir)
1410 (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir) 1415 (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
1411 (define-key map [(meta ?k)] 'ido-forget-work-directory) 1416 (define-key map [(meta ?k)] 'ido-forget-work-directory)
1412 (define-key map [(meta ?m)] 'ido-make-directory) 1417 (define-key map [(meta ?m)] 'ido-make-directory)
1413 (define-key map [(meta ?n)] 'ido-next-work-directory) 1418 (define-key map [(meta ?n)] 'ido-next-work-directory)
1424 (define-key map [(meta ?l)] 'ido-toggle-literal) 1429 (define-key map [(meta ?l)] 'ido-toggle-literal)
1425 (define-key map "\C-v" 'ido-toggle-vc) 1430 (define-key map "\C-v" 'ido-toggle-vc)
1426 ) 1431 )
1427 1432
1428 (when (eq ido-cur-item 'buffer) 1433 (when (eq ido-cur-item 'buffer)
1429 (define-key map "\C-f" (or ido-context-switch-command 'ido-enter-find-file)) 1434 (define-key map "\C-x\C-f" (or ido-context-switch-command 'ido-enter-find-file))
1430 (define-key map "\C-b" 'ido-fallback-command) 1435 (define-key map "\C-x\C-b" 'ido-fallback-command)
1431 (define-key map "\C-k" 'ido-kill-buffer-at-head) 1436 (define-key map "\C-k" 'ido-kill-buffer-at-head)
1432 ) 1437 )
1433 1438
1434 (when (if (boundp 'viper-mode) viper-mode) 1439 (when (if (boundp 'viper-mode) viper-mode)
1435 (define-key map [remap viper-intercept-ESC-key] 'ignore) 1440 (define-key map [remap viper-intercept-ESC-key] 'ignore)
2256 (ido-matches 2261 (ido-matches
2257 (setq ido-try-merged-list t)) 2262 (setq ido-try-merged-list t))
2258 ((not ido-use-merged-list) 2263 ((not ido-use-merged-list)
2259 (ido-merge-work-directories)))) 2264 (ido-merge-work-directories))))
2260 2265
2266 ;;; Magic C-f
2267
2268 (defun ido-magic-forward-char ()
2269 "Move forward in user input or perform magic action.
2270 If no user input is present, perform magic actions:
2271 C-x C-f C-f fallback to non-ido find-file.
2272 C-x C-d C-f fallback to non-ido brief dired.
2273 C-x d C-f fallback to non-ido dired."
2274 (interactive)
2275 (cond
2276 ((not (eobp))
2277 (forward-char 1))
2278 ((and (= (length ido-text) 0)
2279 (memq ido-cur-item '(file dir)))
2280 (ido-fallback-command))))
2281
2282 ;;; Magic C-b
2283
2284 (defun ido-magic-backward-char ()
2285 "Move backward in user input or perform magic action.
2286 If no user input is present, perform magic actions:
2287 C-x C-b C-b fallback to non-ido switch-to-buffer."
2288 (interactive)
2289 (cond
2290 ((> (length ido-text) 0)
2291 (if (> (point) (minibuffer-prompt-end))
2292 (forward-char -1)))
2293 ((eq ido-cur-item 'buffer)
2294 (ido-fallback-command))))
2295
2296 ;;; Magic C-d
2297
2298 (defun ido-magic-delete-char ()
2299 "Delete following char in user input or perform magic action.
2300 If at end of user input, perform magic actions:
2301 C-x C-f ... C-d enter dired on current directory."
2302 (interactive)
2303 (cond
2304 ((not (eobp))
2305 (delete-char 1))
2306 (ido-context-switch-command
2307 nil)
2308 ((memq ido-cur-item '(file dir))
2309 (ido-enter-dired))))
2310
2311
2261 ;;; TOGGLE FUNCTIONS 2312 ;;; TOGGLE FUNCTIONS
2262 2313
2263 (defun ido-toggle-case () 2314 (defun ido-toggle-case ()
2264 "Toggle the value of `ido-case-fold'." 2315 "Toggle the value of `ido-case-fold'."
2265 (interactive) 2316 (interactive)
2502 (setq ido-use-merged-list t ido-try-merged-list 'wide) 2553 (setq ido-use-merged-list t ido-try-merged-list 'wide)
2503 (setq ido-exit 'refresh) 2554 (setq ido-exit 'refresh)
2504 (setq ido-text-init (ido-final-slash dir t)) 2555 (setq ido-text-init (ido-final-slash dir t))
2505 (setq ido-rotate-temp t) 2556 (setq ido-rotate-temp t)
2506 (exit-minibuffer))) 2557 (exit-minibuffer)))
2558
2559 (defun ido-wide-find-dir-or-delete-dir (&optional dir)
2560 "Prompt for DIR to search for using find, starting from current directory.
2561 If input stack is non-empty, delete current directory component."
2562 (interactive)
2563 (if ido-input-stack
2564 (ido-delete-backward-word-updir 1)
2565 (ido-wide-find-dir)))
2507 2566
2508 (defun ido-push-dir () 2567 (defun ido-push-dir ()
2509 "Move to previous directory in file name, push current input on stack." 2568 "Move to previous directory in file name, push current input on stack."
2510 (interactive) 2569 (interactive)
2511 (setq ido-exit 'push) 2570 (setq ido-exit 'push)
4075 (ido-to-end summaries))) 4134 (ido-to-end summaries)))
4076 4135
4077 ;;; Helper functions for other programs 4136 ;;; Helper functions for other programs
4078 4137
4079 (put 'dired-do-rename 'ido 'ignore) 4138 (put 'dired-do-rename 'ido 'ignore)
4139 (put 'ibuffer-find-file 'ido 'find-file)
4080 4140
4081 ;;;###autoload 4141 ;;;###autoload
4082 (defun ido-read-buffer (prompt &optional default require-match) 4142 (defun ido-read-buffer (prompt &optional default require-match)
4083 "Ido replacement for the built-in `read-buffer'. 4143 "Ido replacement for the built-in `read-buffer'.
4084 Return the name of a buffer selected. 4144 Return the name of a buffer selected.
4109 (ido-read-directory-name prompt dir default-filename mustmatch initial))) 4169 (ido-read-directory-name prompt dir default-filename mustmatch initial)))
4110 ((and (not (eq (get this-command 'ido) 'ignore)) 4170 ((and (not (eq (get this-command 'ido) 'ignore))
4111 (not (memq this-command ido-read-file-name-non-ido)) 4171 (not (memq this-command ido-read-file-name-non-ido))
4112 (or (null predicate) (eq predicate 'file-exists-p))) 4172 (or (null predicate) (eq predicate 'file-exists-p)))
4113 (let* (ido-saved-vc-hb 4173 (let* (ido-saved-vc-hb
4114 (ido-context-switch-command 'ignore) 4174 (ido-context-switch-command
4175 (if (eq (get this-command 'ido) 'find-file) nil 'ignore))
4115 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends)) 4176 (vc-handled-backends (and (boundp 'vc-handled-backends) vc-handled-backends))
4116 (ido-current-directory (ido-expand-directory dir)) 4177 (ido-current-directory (ido-expand-directory dir))
4117 (ido-directory-nonreadable (not (file-readable-p ido-current-directory))) 4178 (ido-directory-nonreadable (not (file-readable-p ido-current-directory)))
4118 (ido-directory-too-big (and (not ido-directory-nonreadable) 4179 (ido-directory-too-big (and (not ido-directory-nonreadable)
4119 (ido-directory-too-big-p ido-current-directory))) 4180 (ido-directory-too-big-p ido-current-directory)))
4124 (setq filename 4185 (setq filename
4125 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial)) 4186 (ido-read-internal 'file prompt 'ido-file-history default-filename mustmatch initial))
4126 (cond 4187 (cond
4127 ((eq ido-exit 'fallback) 4188 ((eq ido-exit 'fallback)
4128 (setq filename 'fallback)) 4189 (setq filename 'fallback))
4190 ((eq ido-exit 'dired)
4191 (setq filename ido-current-directory))
4129 (filename 4192 (filename
4130 (setq filename 4193 (setq filename
4131 (concat ido-current-directory filename)))))) 4194 (concat ido-current-directory filename))))))
4132 (t 4195 (t
4133 (setq filename 'fallback))) 4196 (setq filename 'fallback)))