Question

For my c (c++) files, I added this reference to a cc-mode to my .emacs file:

(setq c-default-style "stroustrup"
c-basic-offset 4)

I would like to use the same for a custom extension ".dec." I tried to naively adjust this SO question doing

(defun my-decaf-mode ()   
    (when (and (stringp buffer-file-name)   
           (string-match "\\.dec\\'" buffer-file-name))   

           (setq c-default-style "stroustrup")    
           (c-basic-offset 4)) )    

(add-hook 'find-file-hook 'my-decaf-mode)   

which didn't work (I wrote a few lines in C; the support I would get giving the file a .c extension was not there). I also tried the actual customization type as in

           (setq c-default-style "stroustrup"    
           c-basic-offset 4)) )    

How could I get this done?

Was it helpful?

Solution

This answer assumes that the function my-decaf-mode does exactly what the original poster wants, and that the only thing needed is to associate *.dec extension files with c-mode and then call the function my-decaf-mode when the major-mode c-mode is activated in a buffer:

(add-to-list 'auto-mode-alist '("\\.dec\\'" . c-mode))

(add-hook 'c-mode-hook 'my-decaf-mode)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top