On 2007-09-19, Mike H <hspnew@xxxxxxxxx> wrote:
> Emacs . How can I associate *.cu files as cc mode as a default ?
> cc mode is automatically triggered when I open *.c, *.cpp files.
> However, I would like to add the new file type :)
You can do this with find-file-hooks. This is code that runs anytime
you find (open) a file. In this case, you want to check and see if the
file you've found ends with .cu, and if so, to use cc-mode. This
function will do that:
(let ((fn (buffer-file-name)))
(when (string-match "\\.cu$" fn)
You have to tell Emacs to run this function every time you open a new
file, so you add the hook:
(add-hook 'find-file-hooks 'my-find-file-hook)
Put both forms in your .emacs, and the next time you open emacs you'll
be all ready to go. (you can also load them into a running emacs using
C-x C-e to execute the previous command in a lisp-mode buffer, such as
scratch or .emacs).