Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 678
justingordon Avatar asked Nov 15 '12 20:11

justingordon


2 Answers

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.

like image 186
Tao Peng Avatar answered Nov 15 '22 02:11

Tao Peng


Oh, wait, try putting #+BEGIN_SRC sql in lower case. See here for identifiers.


Try refreshing the display, by making the block be reparsed (break the syntax and undo, or something). It often happens to me with python or bibtex blocks, but this fixes it.

I can't see why it wouldn't fontify inline if it finds the right mode when you C-c '.

Also, I'm afraid fontification, while being one of org-mode's nicer features, is not exactly perfectly handled. From the mailing list :

The fontification engine is not very powerful and get easily fooled.

like image 32
Nikana Reklawyks Avatar answered Nov 15 '22 04:11

Nikana Reklawyks