🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.editor.emacs
Article #555

dired に色付けよ

#555
From: 金田 浩司
Date: Sat, 04 Sep 2004 04:38
52 lines
4033 bytes
こんにちは
emacs-21 で dired 使っていて、ふと、ファイルを色分け表示
したいと思って調べてみたけど、見つけられなかったんで、
見よう見まねで書いてみました。
昔 mule 辺りの頃は hilit19 とかで結構簡単にできたと思うんですが。

elisp 久々なんで、もっとうまい書き方できるかもしれませんが、
つーか、ひょっとして簡単に実現する方法あるかもしんないけど、
一応投稿します。

;;;;; dired でファイル名を拡張子によって色分け表示
(defface my-source-file1-face	'((t (:foreground "NavyBlue"))) nil)
(defface my-source-file2-face	'((t (:foreground "brown4"))) nil)
(defface my-archive-file-face	'((t (:foreground "gray40" :weight bold))) nil)
(defface my-binary-file-face	'((t (:foreground "gray45"))) nil)
(defface my-image-file-face	'((t (:foreground "green4"))) nil)
(defface my-audio-file-face	'((t (:foreground "magenta3"))) nil)
(defface my-movie-file-face	'((t (:foreground "cyan4"))) nil)
(defvar my-source-file1-face	'my-source-file1-face)
(defvar my-source-file2-face	'my-source-file2-face)
(defvar my-archive-file-face	'my-archive-file-face)
(defvar my-binary-file-face	'my-binary-file-face)
(defvar my-image-file-face	'my-image-file-face)
(defvar my-audio-file-face	'my-audio-file-face)
(defvar my-movie-file-face	'my-movie-file-face)
(set-face-font 'my-archive-file-face (face-font 'bold))

(add-hook 'dired-mode-hook '(lambda ()
  (font-lock-add-keywords major-mode
    (list
     '("\\.\\(c\\|cpp\\|C\\)$"
       (".+" (dired-move-to-filename) nil (0 my-source-file1-face)))
     '("\\.\\(h\\|H\\|hpp\\|sh\\|el\\|pl\\)$"
       (".+" (dired-move-to-filename) nil (0 my-source-file2-face)))
     '("\\.\\(tar\\|gz\\|tgz\\|zip\\|bz2\\|tbz\\|rpm\\|lzh\\|Z\\)$"
       (".+" (dired-move-to-filename) nil (0 my-archive-file-face)))
     '("\\.\\(bin\\|out\\|o\\|core\\|a\\|so\\|dbg\\|elc\\|com\\|exe\\)$"
       (".+" (dired-move-to-filename) nil (0 my-binary-file-face)))
     '("\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|p[pgb]m\\|xpm\\|xbm\\|xwd\\)$"
       (".+" (dired-move-to-filename) nil (0 my-image-file-face)))
     '("\\.\\(mp3\\|midi\\|wav\\|aw\\|au\\|aif\\)$"
       (".+" (dired-move-to-filename) nil (0 my-audio-file-face)))
     '("\\.\\(mpe?g\\|rm\\|avi\\|wmv\\|mov\\|qt\\)$"
       (".+" (dired-move-to-filename) nil (0 my-movie-file-face)))
     )
    t)))
  ; ※ `completion-ignored-extensions' のファイルは `font-lock-string-face'
  ;    で色付けされちゃう

Emacs 21.3.1 でテスト
____________________________________________
 金田 浩司 <sunya@bi.wakwak.com> [検印廃止]
Technical Details
Message-ID: <chbgru$2l06$1@news1.wakwak.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsfeed.media.kyoto-u.ac.jp!news.yamada.gr.jp!onion.ish.org!nf1.xephion.ne.jp!news1.wakwak.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: ff358,3253bd05a034cee,start
X-Google-Attributes: gidff358,public
X-Google-Language: Japanese,JIS
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsfeed.media.kyoto-u.ac.jp!news.yamada.gr.jp!onion.ish.org!nf1.xephion.ne.jp!news1.wakwak.com!not-for-mail
From: 金田 浩司 <sunya@bi.wakwak.com>
Newsgroups: fj.editor.emacs
Subject: dired に色付けよ
Date: Sat, 04 Sep 2004 13:38:21 +0900
Organization: wakwak.com
Lines: 52
Distribution: fj
Message-ID: <chbgru$2l06$1@news1.wakwak.com>
NNTP-Posting-Host: z47.61-115-84.ppp.wakwak.ne.jp
Mime-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen")
Content-Type: text/plain; charset=ISO-2022-JP
X-Trace: news1.wakwak.com 1094272702 87046 61.115.84.47 (4 Sep 2004 04:38:22 GMT)
X-Complaints-To: abuse@wakwak.com
NNTP-Posting-Date: 4 Sep 2004 04:38:22 GMT
X-Alphabet-From: Kaneda Hiloshi <sunya@bi.wakwak.com>
X-Face: .P?<m\SXm2qBJR3XU5^T8~j/j?/HOK$[?.{X?So_qcbO6B^twkjk5~|1qzV*o(n;9uP7_xy
 b^4JGOqx1my6tEfSxMTP`3Z_1YBGY1;^XAT<cxpV:RM`TpDK;0>RHb4S#iki&cw0xjzcM<p`R:N,H+
 8nNNB`tMNmwo@&#TDh<qL-4K.Zl'*G4`nH1KC:A6`t:2K6o,0leMoH*7ZL)?>u!j@M0?`!W^yoFBJE
 p{%-cVQiML87?-]L@T]42VG=dD-kmk(Z
User-Agent: T-gnus/6.16.2 (based on Gnus v5.10.2) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.4 Emacs/21.3 (i386--freebsd) MULE/5.0 (SAKAKI)