Function: ido-file-internal
ido-file-internal is a byte-compiled function defined in ido.el.gz.
Signature
(ido-file-internal METHOD &optional FALLBACK DEFAULT PROMPT ITEM INITIAL SWITCH-CMD)
Source Code
;; Defined in /usr/src/emacs/lisp/ido.el.gz
(defun ido-file-internal (method &optional fallback default prompt item initial switch-cmd)
;; Internal function for ido-find-file and friends
(unless item
(setq item 'file))
(setq ido-fallback nil)
(let ((ido-current-directory (ido-expand-directory default))
(ido-context-switch-command switch-cmd)
ido-directory-nonreadable ido-directory-too-big
filename)
(if (or (not ido-mode) (ido-is-slow-ftp-host))
(setq filename t
ido-exit 'fallback)
(setq ido-directory-nonreadable
(ido-nonreadable-directory-p ido-current-directory)
ido-directory-too-big
(and (not ido-directory-nonreadable)
(ido-directory-too-big-p ido-current-directory))))
(when (and (eq item 'file)
(or ido-use-url-at-point ido-use-filename-at-point))
(let (fn)
(require 'ffap)
;; Duplicate code from ffap-guesser as we want different
;; behavior for files and URLs.
(cond
((with-no-warnings
(and ido-use-url-at-point
ffap-url-regexp
(ffap-fixup-url (or (ffap-url-at-point)
(ffap-gopher-at-point)))))
(setq ido-exit 'ffap
filename t))
((and ido-use-filename-at-point
(setq fn (with-no-warnings
(if (eq ido-use-filename-at-point 'guess)
(ffap-guesser)
(ffap-string-at-point))))
(not (string-match (rx bos "http" (? "s") ":/") fn)))
(let ((absolute-fn (expand-file-name fn)))
(cond
((file-directory-p absolute-fn)
(setq ido-current-directory
(file-name-as-directory absolute-fn)))
((file-directory-p (file-name-directory absolute-fn))
(setq ido-current-directory (file-name-directory absolute-fn))
(setq initial (file-name-nondirectory absolute-fn)))))))))
(let (ido-saved-vc-hb
(vc-handled-backends (and (boundp 'vc-handled-backends)
vc-handled-backends))
(ido-work-directory-index -1)
(ido-work-file-index -1)
(ido-find-literal nil))
(unless filename
(setq ido-saved-vc-hb vc-handled-backends)
(let ((minibuffer-completing-file-name t))
(setq filename
(ido-read-internal item
(or prompt "Find file: ")
'ido-file-history
(and (eq method 'alt-file) buffer-file-name)
(confirm-nonexistent-file-or-buffer)
initial))))
;; Choose the file name: either the text typed in, or the head
;; of the list of matches
(cond
((eq ido-exit 'fallback)
;; Need to guard setting of default-directory here, since
;; we don't want to change directory of current buffer.
(let ((default-directory ido-current-directory)
(read-file-name-function nil))
(setq this-command (or ido-fallback fallback 'find-file))
(run-hook-with-args 'ido-before-fallback-functions this-command)
(if (eq this-command 'write-file)
(write-file (read-file-name
"Write file: "
default-directory
(and buffer-file-name
(expand-file-name
(file-name-nondirectory buffer-file-name)
default-directory)))
t)
(call-interactively this-command))))
((eq ido-exit 'switch-to-buffer)
(ido-buffer-internal
(if (memq method '(other-window other-frame))
method ido-default-buffer-method)
nil nil nil ido-text))
((eq ido-exit 'insert-buffer)
(ido-buffer-internal 'insert 'insert-buffer "Insert buffer: "
nil ido-text 'ido-enter-insert-file))
((eq ido-exit 'dired)
(funcall (cond ((eq method 'other-window) #'dired-other-window)
((eq method 'other-frame) #'dired-other-frame)
(t #'dired))
(concat ido-current-directory (or ido-text ""))))
((eq ido-exit 'ffap)
(find-file-at-point))
((eq method 'alt-file)
(ido-record-work-file filename)
(setq default-directory ido-current-directory)
(ido-record-work-directory)
(find-alternate-file filename))
((eq method 'alt-file-other-window)
(ido-record-work-file filename)
(setq default-directory ido-current-directory)
(ido-record-work-directory)
(find-alternate-file-other-window filename))
((memq method '(dired dired-other-window dired-other-frame
list-directory))
(if (equal filename ".")
(setq filename ""))
(let* ((dirname (ido-final-slash
(concat ido-current-directory filename) t))
(file (substring dirname 0 -1)))
(cond
((file-directory-p dirname)
(ido-record-command method dirname)
(ido-record-work-directory dirname)
(funcall method dirname))
((file-directory-p ido-current-directory)
(cond
((file-exists-p file)
(ido-record-command method ido-current-directory)
(ido-record-work-directory)
(funcall method ido-current-directory)
(if (eq method 'dired)
(with-no-warnings
(dired-goto-file (expand-file-name file)))))
((string-match "[[*?]" filename)
(setq dirname (concat ido-current-directory filename))
(ido-record-command method dirname)
(ido-record-work-directory)
(funcall method dirname))
((y-or-n-p (format "Directory %s does not exist. Create it? "
filename))
(ido-record-command method dirname)
(ido-record-work-directory dirname)
(make-directory dirname)
(funcall method dirname))
(t
;; put make-directory command on history
(ido-record-command 'make-directory dirname))))
(t (error "No such directory")))))
((eq method 'write)
(ido-record-work-file filename)
(setq default-directory ido-current-directory)
(setq filename (concat ido-current-directory filename))
(ido-record-command 'write-file filename)
(add-to-history 'file-name-history filename)
(ido-record-work-directory)
(write-file filename t))
((eq method 'read-only)
(ido-record-work-file filename)
(setq filename (concat ido-current-directory filename))
(ido-record-command fallback filename)
(ido-record-work-directory)
(run-hook-with-args 'ido-before-fallback-functions fallback)
(funcall fallback filename))
((eq method 'insert)
(ido-record-work-file filename)
(setq filename (concat ido-current-directory filename))
(ido-record-command
(if ido-find-literal 'insert-file-literally 'insert-file)
filename)
(add-to-history 'file-name-history filename)
(ido-record-work-directory)
(insert-file-1 filename
(if ido-find-literal
#'insert-file-contents-literally
#'insert-file-contents)))
(filename
(ido-record-work-file filename)
(setq filename (concat ido-current-directory filename))
(ido-record-command 'find-file filename)
(add-to-history 'file-name-history filename)
(ido-record-work-directory)
(ido-visit-buffer (find-file-noselect filename nil ido-find-literal)
method))))))