32

I would like emacs to switch to gnuplot-mode when I open a file ending in .g or .gnuplot.

I tried

;; gnuplot mode-name
(add-to-list 'gnuplot-mode '("\\.g\\'" . gnuplot-mode))

or

;; gnuplot mode-name
(add-to-list 'gnuplot '("\\.g\\'" . gnuplot))

Neither works. How do I make Emacs behave this way?

Dan
  • 32,584
  • 6
  • 98
  • 168
Stein
  • 551
  • 1
  • 5
  • 11

1 Answers1

32

The full syntax for specifying file extensions for gnuplot-mode is:

(add-to-list 'auto-mode-alist '("\\.g\\'" . gnuplot-mode))

The other point to verify is that you are using Bruce Ravel's recent (year 2012) implementation of gnuplot-mode. This is a separate MELPA package that requires gnuplot version 4.4 and higher.

Lastly avoid gnuplot-mode files that come pre-packaged with gnuplot itself. They have not been kept compatible with newer emacs versions.

Stefan
  • 26,154
  • 3
  • 46
  • 84
Emacs User
  • 5,553
  • 18
  • 48
  • 7
    You can make that a bit more concise by using `add-to-list`. Also relevant: `C-h i g (elisp) Auto Major Mode`. – Kaushal Modi Nov 05 '15 at 23:50
  • 2
    @kaushalmodi: since `add-to-list` is probably the canonical idiom, could you add that as a separate answer for future users? – Dan Nov 06 '15 at 13:04