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


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

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

  • Where is the duplicated (original) question? Commented Jun 16, 2017 at 14:26

1 Answer 1


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.

  • 7
    You can make that a bit more concise by using add-to-list. Also relevant: C-h i g (elisp) Auto Major Mode. Commented Nov 5, 2015 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
    Commented Nov 6, 2015 at 13:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.