2

There are multiple questions along these lines but I haven't been able to find what I need from start to finish. I have been using emacs for a few years but am not used to its customization.

I have a unique file type, identified by its extension, which emacs is not configured for. Its comment style is

<!-- text -->

and I would like to set the variables comment-start and comment-end to the relevant values (which I am assuming will allow me to use comment-region). I don't know the correct way to do this so that it will always be configured when I open this file type but won't affect the default behavior of emacs.

Do I need to make a new major mode for this file type, and then set the variables, or is there an easier way of doing it? An example of the complete requirements for my .emacs file would be much appreciated!

Mike
  • 111
  • 1
  • 4

1 Answers1

4

See here. I think this will work:

(add-to-list 'auto-mode-alist
             '("\\.extension\\'" . (lambda ()
                                     (setq-local comment-start "<!--")
                                     (setq-local comment-end   "-->"))))

Alternatively, if this file extension is well known (or if these files are close enough to a well known syntax), you may be able to just find a major-mode online that does what you want. For example, NXML Mode may just give you the comment syntax you want along with some other useful features.

0x5453
  • 12,753
  • 1
  • 32
  • 61