Search code examples
emacsorg-modedot-emacsemacs24sql-mode

Font-locking for SQL-MODE inside of ORG-MODE not font-locking


Related to question: org-mode: fontify code blocks natively

I've got the latest org-mode and emacs versions as of November 1, 2012 (org stored in org-20121105).

I've also got the sql-mode that comes with emacs-24.

I've got fontification turned one:

;; fontify code in code blocks
(setq org-src-fontify-natively t)

Yet this does not fontify in my org documents. Java, bash, etc. all work.

#+BEGIN_SRC SQL
   SELECT foo FROM bar
#+END_SRC 

When I open a file foobar.sql, the mode indicator says SQL[ANSI] (which I also tried as the source type), and font-locking works.

Thanks in advance for any tips.


Solution

  • Firstly, the name of the SRC block mode is case-sensitive. It should be sql instead of SQL.

    #+BEGIN_SRC sql
       SELECT foo FROM bar
    #+END_SRC
    

    Secondly, the initial font-lock of sql-mode seams not to highlight SQL keywords, (at least to me, it looks no difference no matter you turn it on or off). Therefore, you need to specify which kind of SQL you want to highlight. If you are using MySQL for example:

    (add-hook 'sql-mode-hook
              (lambda ()
                (sql-highlight-mysql-keywords)))
    

    Then Restart Emacs. It should work now.