Download
(defun ido-preview-cond()
"Function using lot of dynamic variables inside.
Return string.
The general rule: (car ido-matches) - item we are watching here."
(cond
((and file
(file-exists-p file)
(not (file-directory-p file))
ido-current-directory)
(save-excursion
(save-window-excursion
(when (find-file file)
(prog1 (buffer-substring (point-min) (point-max)) (kill-buffer))))))
((consp (car ido-matches))
(cond
((and (cdar ido-matches) (stringp (cadar ido-matches)))
(cadar ido-matches))
(t (ido-name ido-matches))))
((and (stringp (car ido-matches)) (functionp (intern (car ido-matches))))
(flet ((message(&rest args))) (save-window-excursion (describe-function (intern (car ido-matches))))))
((and (stringp (car ido-matches)) (bufferp (get-buffer (car ido-matches))))
(save-excursion (set-buffer (get-buffer (car ido-matches))) (buffer-substring (point-min) (point-max))))
((stringp (car ido-matches)) (car ido-matches))
(t "No matches, sir.")))
(defun ido-preview-forward(&optional arg)
"Complete the minibuffer contents as far as possible.
Return nil if there is no valid completion, else t.
If no characters can be completed, display a list of possible completions.
If you repeat this command after it displayed such a list,
scroll the window of possible completions."
(interactive "P")
(unless (or (equal 'ido-preview-forward last-command) (equal 'ido-preview-backward last-command))
(setq minibuffer-scroll-window nil))
(let ((window minibuffer-scroll-window))
(if (window-live-p window)
(with-current-buffer (window-buffer window)
(scroll-other-window arg)
nil)
(progn
(let ((enable-recursive-minibuffers t)
(file (ido-name (car ido-matches))))
(if file
(setq file (concat ido-current-directory file)))
(get-buffer-create " *preview-ido*")
(other-window 1)
(delete-other-windows)
(setq minibuffer-scroll-window (get-buffer-window (switch-to-buffer " *preview-ido*")))
(other-window -1)
(with-current-buffer " *preview-ido*"
(text-mode)
(erase-buffer)
(insert (ido-preview-cond))
(normal-mode)
))))))
(defun ido-preview-backward(arg)
"Complete the minibuffer contents as far as possible.
Return nil if there is no valid completion, else t.
If no characters can be completed, display a list of possible completions.
If you repeat this command after it displayed such a list,
scroll the window of possible completions."
(interactive "P")
(unless (or (equal 'ido-preview-forward last-command) (equal 'ido-preview-backward last-command))
(setq minibuffer-scroll-window nil))
(let ((window minibuffer-scroll-window))
(if (window-live-p window)
(with-current-buffer (window-buffer window)
(scroll-other-window
(cond
((not arg) '-)
(t (- arg))))
nil)
(progn
(let ((enable-recursive-minibuffers t)
(file (ido-name (car ido-matches))))
(if file
(setq file (concat ido-current-directory file)))
(get-buffer-create " *preview-ido*")
(other-window 1)
(delete-other-windows)
(setq minibuffer-scroll-window (get-buffer-window (switch-to-buffer " *preview-ido*")))
(other-window -1)
(with-current-buffer " *preview-ido*"
(text-mode)
(erase-buffer)
(insert (ido-preview-cond))
(normal-mode)
))))))
(provide 'ido-preview)