Question

When I try to highlight SQL code in org-mode, the highlighting fails:

#+BEGIN_SRC SQL
SELECT *
FROM Production.Product
ORDER BY Name ASC;
#+END_SRC SQL

It works great for Python, shell etc, but not for SQL. I wonder if I am using the wrong keyword.

Given this:

  • How can I highlight SQL code?
  • Where can I find the list of languages supported?
Was it helpful?

Solution

SQL should be lowercase, sql, and you don't need to repeat the language name on the END_SRC line:

#+BEGIN_SRC sql
  SELECT *
  FROM Production.Product
  ORDER BY Name ASC;
#+END_SRC

org-mode just appends -mode to the language name given and tries to find a major mode function. Emacs Lisp function names are case sensitive, so sql-mode exists while SQL-mode doesn't.

You can get a list of all such functions by typing C-h a -mode$, i.e. search for all functions that end with -mode, but the resulting list contains many modes that are not major modes for programming languages.

OTHER TIPS

Another option is to tell org-mode that sql-mode should be used for SQL snippets. This can be done with the variable org-src-lang-modes:

(add-to-list 'org-src-lang-modes (cons "SQL" 'sql))

For example, this kind of linking is enabled by default for C (c-mode) and C++ / c++ (cpp-mode).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top