help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs . How can I associate *.cu files as cc mode as a default ?


From: Tyler Smith
Subject: Re: Emacs . How can I associate *.cu files as cc mode as a default ?
Date: 19 Sep 2007 00:28:09 GMT
User-agent: slrn/0.9.8.1pl1 (Debian)

On 2007-09-19, Mike H <hspnew@gmail.com> 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:

(defun my-find-file-hook()
  (let ((fn (buffer-file-name)))
    (when (string-match "\\.cu$" fn)
      (cc-mode))))

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).

HTH,

Tyler


reply via email to

[Prev in Thread] Current Thread [Next in Thread]