views:

125

answers:

1

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!

+1  A: 

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:

Trey Jackson
Thanks for that! If you know it, could you also tell me whether my regex looks right?
Vivi
A good way to play with regexes is RE-Builder. Go to the *scratch* buffer, type some characters and type M-x regexp-builder RET. Now you can do "live" regex matching. Keep in mind, though, that RE-Builder interprets your input as a string. That means you'll have to type "\\\\" to match a single '\' and "\\." for a dot. When dealing with regexes in Emacs you always have to know if they're interpreted as strings or directly.
mmmasterluke
Nice! thank you, that was very helpful :)
Vivi
@mmmasterluke And even more for Vivi - use RE-Builder in the `dired` buffer.
Trey Jackson
Note that the regex syntax used in elisp differs in some notable ways from that of most modern programming languages. The emacs documentation is clear enough, but keep in mind that generic tutorials on regular expressions will often be focussed on PCRE.
phils
I tried that RE-builder but I found it confused me more. I think I need to learn a bit before I venture into RE-builder. There is just so much to learn it is hard to keep up. There are so many questions in my mind, things that I want to do, that I feel like the ball the players have been kicking in South Africa :) @phils: I will try and find out what PCRE is, thanks!
Vivi