May 26, 2023 by Reion

Emacs Dired Mimeicon mode

This extension allows to display file and folder icons in dired mode and uses mimetype as the displayed logo and adheres to the icon-theme-spec file naming convention, which will help you to apply icon themes that you can download from the internet in your emacs.

|inline|border

From the code, I defined a minor mode of dired-mimeicon-mode that displays icons corresponding to the file types in a Dired buffer. The icons are displayed as overlays on top of the filenames. The icons are loaded from an icon theme located in a directory specified by dired-mimeicon-root-dir and dired-mimeicon-name. The icons are displayed as SVG images with a size of 26x26 pixels. The icon for a file is determined based on its MIME type using the mailcap library. If the MIME type is not recognized or an icon file is not found, a default icon is used.

The code defines several functions:

  • dired-mimeicon-overlays-in: Returns a list of overlays in the specified region that have the dired-mimeicon-overlay property set.
  • dired-mimeicon-clear-overlays: Removes all overlays with the dired-mimeicon-overlay property in the buffer.
  • dired-mimeicon-insert-icon-to-overlay: Adds an icon overlay for a file at the specified position in the buffer.
  • dired-mimeicon-refresh: Refreshes the icons in the buffer by clearing existing overlays and creating new ones for each file in the buffer.
  • dired-mimeicon-refresh-advice: An advice function that calls dired-mimeicon-refresh after certain Dired functions are called.
  • dired-mimeicon-enable: Enables the dired-mimeicon-mode minor mode by adding advice to Dired functions and calling dired-mimeicon-refresh.
  • dired-mimeicon-disable: Disables the dired-mimeicon-mode minor mode by removing advice from Dired functions and clearing icon overlays.
  • dired-mimeicon-mode: The dired-mimeicon-mode minor mode itself. When enabled, it calls dired-mimeicon-enable. When disabled, it calls dired-mimeicon-disable.

Installation

  • Clone the repository to your emacs extension directory
  • Add the following code to your ~/.emacs
(require 'dired-mimeicon)
(add-hook 'dired-mode-hook 'dired-mimeicon-mode)

More details

https://github.com/reionwong/dired-mimeicon