I'm working on some compiler shortcuts:
I want to write a function (cmp FILE-NAME &optional args)
that will use FILE-NAME
and args to construct the appropriate COMMAND
to call (compile COMMAND)
with.
For example: (cmp "Test.java" "-Xlint:all")
will run (compile "javac Test.java -Xlint:all")
This is mostly so I can write my default args that I'll want to compile specific programs with.
As part of this, I'll need my function to determine the programming language of the given file. I could do this with some simple expressions like:
(setq file-ext (substring file-name (string-match "\.[^.]*$" file-name)))
(setq programming-language (cond ((equal ".java" file-ext) "java")
((equal ".c" file-ext) "c")
((equal ".sc" file-ext) "scala")))
This would work but I'd have to add a new condition for any new programming language, and it seems overkill because I know that Emacs is already able to determine a file's programming language: it's how it knows to, for example, load java-mode
when I open a Java file.
So I know it's probably a simple question, but I can't find documentation to show me how Emacs determines a file's programming language, and how I can leverage that same function for my own customization.