I would like to write a major mode for inspecting netCDF files. These are binary files which can be multiple GB in size. So I don't want to open them in emacs.

The interaction that I have in mind is the following:

  1. User opens netCDF file like any other file in emacs.
  2. A command line program (ncdump -h) is executed on the file and the output is interpreted by emacs.

The problem is that there seems to be no way to stop emacs from actually opening the file.

  • 3
    Interesting problem. You won't be able to do this from the major mode because that runs too late: Emacs needs to open the file first because it can choose the major mode based on the file contents (e.g. -*-my-mode-*-). You'd need to hook earlier in find-find-noselect, perhaps at the place where there's now an exception for directories. Commented Jul 20, 2016 at 19:11
  • 4
    Do you just need a function that runs a process and sends the output to a particular buffer (with the filename being an argument that the user can choose)? In what other way would you need a major-mode, since that normally implies operating on a particular buffer (e.g., what is the purpose of the major-mode, what does it do . . .)? Here is the link to the manual describing various processes that can be started with Emacs: gnu.org/software/emacs/manual/html_node/elisp/…
    – lawlist
    Commented Jul 20, 2016 at 19:52
  • 2
    A start would be to use process-file or call-process on such a file, using ncdump -h etc.
    – Drew
    Commented Jul 20, 2016 at 19:58
  • 2
    Do you know the package vlf from elpa? I have the impression that this package does exactly do what you try to accomplish not with binary files but with text files. I think you can learn from that package how to do what you want. If you have a 64-bit emacs then the integer-limitations of emacs are also of no concern with this package. You can install the package via M-x package-install.
    – Tobias
    Commented Jul 21, 2016 at 15:48
  • 1
    I recommend you take another look at @Tobias's suggestion. Not because you want vlf's functionality, but because vlf needs the same functionality you need, so it's worth looking at how it does it.
    – Stefan
    Commented Jul 27, 2016 at 21:27

2 Answers 2


Pretty sure you can do something like this by making your file name "magic". See this part of the elisp reference manual.


I use a package called vorbiscomment, which I now can't find at the URL in its header comment, and which doesn't appear in *ELPA or on EmacsWiki. Here's that non-functioning URL:


Anyway, it lets you edit the tag metadata for (binary) OGG Vorbis audio files, which sounds conceptually similar to what you want. It's really just a simple wrapper around command-line tools.

I've copied it to the following gist:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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