Search code examples
regexemacselispdired

How can I highlight different types of file in dired mode in Emacs?


In a nutshell, I want to have different faces for some types of file in dired mode. I don't think it matters, but I am using Aquamacs.

The example I will use here is .tex files. If I can do it for .tex, then I can just apply the same structure to do create other faces for other types of files.

From what I understand, I have to create a variable, write a regular expression, then apply a hook. I read a bit about regex and so far I have

^(.+)\.tex$

I think my structure and regular expression are not really correct. I am not a programmer (though I have an interest on it), I have only been using Emacs for 2 weeks or so, so any help would be greatly appreciated.

What I need is at least the basic structure of what I have to do. I understand there may be modes already created that do something similar (such as maybe Wdired and Dired-X), and I would not complain if someone told me about them, but what I really want is to have an elisp code (either already written or that I can work on), as I plan on learning a bit of elisp to be able to write my own customisations and this would be a way to learn.

Thank you!


Solution

  • Since you want to learn how to do it, try checking out the extension dired+.el. This mode does a lot more than what you want, but it does add new faces. Specifically, look for the variable diredp-font-lock-keywords-1 and how it is used. That should get you going.

    Other SO questions that seem relevant are: