Font-locking for SQL-MODE inside of ORG-MODE not font-locking
Asked Answered
D

2

5

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.

Dialectologist answered 15/11, 2012 at 20:50 Comment(1)
The setq has been eval'ed of course ? Can you C-c ' (C-c quote) in the block to open it in a new buffer, with the right major-mode, and see if it's correctly detected ?Shudder
T
8

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.

Testate answered 15/11, 2012 at 22:40 Comment(1)
I'm not sure the second part is going to affect the inline formatting in org.Shudder
S
2

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.

Shudder answered 15/11, 2012 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.