Well In my last blog about dired, I customized
Documentation:
User-defined alist of rules for suggested commands.
These rules take precedence over the predefined rules in the variable
`dired-guess-shell-alist-default’ (to which they are prepended).
Each element of this list looks like
(REGEXP COMMAND…)
where each COMMAND can either be a string or a Lisp expression that evaluates
to a string. If several COMMANDs are given, the first one will be the default
and the rest will be added temporarily to the history and can be retrieved
with M-x previous-history-element (M-p) .
You can set this variable in your ~/.emacs. For example, to add rules for
`.foo’ and `.bar’ files, write
(setq dired-guess-shell-alist-user
(list (list “\\.foo\\’” “FOO-COMMAND”);; fixed rule
;; possibly more rules …
(list “\\.bar\’”;; rule with condition test
‘(if condition
“BAR-COMMAND-1″
“BAR-COMMAND-2″))))
You can customize this variable.
to open an external viewer according to file extension. However keeping this long list is a tedious work. Today I’ve found a much easier way: utilize the mime.types file and mailcaps!
These are the Unix traditional ways to define what external program could be used to view the attachements in mailx. And they are common to many mail clients, including Emacs Gnus. Basicly mime.types defines what mime type is associated to what file externsion, and mailcaps file defines what external viewer could be used to view that specified mime type. According to RFC 1524 we could also define the file externsion in mailcaps usingt the “nametemplate” field, but looks not to many people are using it.
The file is gnus-dired.el, in the gnus package. To utilize it, add the following to .emacs:
(require ‘gnus-dired) ;, isn’t needed due to autoload cookies
(add-hook ‘dired-mode-hook ‘turn-on-gnus-dired-mode)
Now we could press C-c C-m C-l in an dired buffer and watch the external viewer running, as long as we have our mime.types and mailcaps file set. It should be OK most of the time even if we don’t have those two files, because Emacs has a pretty planty long list mailcap-mime-extensions and mailcap-mime-data which works like mime.types and mailcaps, accordingly. Just override in those two files if you don’t like the default viewer.
And now the only thing left is bind gnus-dired-find-file-mailcap to a key easier to type, which is always the hardest when I found some new function. Fortunatly this time I could use “V” for dired-do-run-mail which related to VM or RMail that I don’t use. So,
And we are done.
Post a Comment
You could use <code type="name"> to get your code colorized