
dispicon - obtain a displayed icon for specified file name.
		  				       by Yuuichi Teranishi

How to use:

Put dispicon.exe on your exec-path and put dispicon.el on your load-path.
Then put following setting on your '.emacs'.

(autoload 'dispicon "dispicon")

Then you can use following API:

FUNCTION
dispicon (filename &optional type size depth bgcolor ignore-errors)

Obtain an icon which associates to FILENAME.
If optional TYPE is specified, icon type is changed.
It is a symbol of `small' or `large'.
If second optional SIZE is specified, it is used as width and height of
the icon.
If third optional DEPTH is specified, it is used as the depth of the icon.
If fourth optional BGCOLOR is specified, it is used as the default bgcolor.
If fifth optional IGNORE-ERRORS is specified, error is ignored.

How to setup:

;; Display icons on SEMI.
(eval-after-load "mime-view"
  '(defun mime-view-entity-title (entity)
     (or (mime-entity-read-field entity 'Content-Description)
	 (mime-entity-read-field entity 'Subject)
	 (let ((file (mime-entity-filename entity)))
	   (when file
	     (concat (dispicon file) file)))
	 "")))

;; Display icons on Dired.
(eval-after-load "dired"
  '(progn
     (defadvice dired-revert (before dired-revert-remove-overlays activate)
       "Remove overlays."
       (save-excursion
	 (let ((pos (point-min)))
	   (while (not (eq (setq pos (next-overlay-change pos)) (point-max)))
	     (dolist (overlay (overlays-at pos))
	       (delete-overlay overlay))))))
     (defun dired-insert-set-properties (beg end)
       (save-excursion
	 (goto-char beg)
	 (while (< (point) end)
	   (condition-case nil
	       (when (dired-move-to-filename)
		 (let ((beg (point))
		       end file)
		   (add-text-properties
		    beg
		    (setq end (save-excursion
				(dired-move-to-end-of-filename)
				(point)))
		    '(mouse-face highlight
				 help-echo
				 "mouse-2: visit this file in other window"))
		   (setq file (buffer-substring beg end))
		   (overlay-put (make-overlay beg end)
				'before-string
				(dispicon
				 (with-temp-buffer
				   (insert (expand-file-name
					    file
					    dired-directory))
				   (goto-char (point-min))
				   (while (search-forward "/" nil t)
				     (replace-match "\\" nil t))
				   (buffer-string))
				 'small 16))))
	     (error nil))
	   (forward-line 1))))))
