Multi-language syntax highlighting in Emacs
When I'm using some SQL in C, I have a system using MMM-Mode; wrapping the required statement in a set of comments,
/* SQL */
and
/* #SQL */
the following will give me SQL syntax highlighting:
(require 'mmm-mode)
(set-face-background 'mmm-default-submode-face nil)
(mmm-add-classes
'((embedded-sql
:submode sql-mode
:front "/* SQL */"
:back "/* #SQL */")))
(mmm-add-mode-ext-class 'c-mode "*.c" 'c-sql)
(setq mmm-never-modes
(append '(ediff-mode) '(text-mode) mmm-never-modes))
I can then use the mmm-ify-by-class to apply the c-sql class - Perhaps you can do similar in Python?
For me, the following lisp allows Emacs to see the sample SQL string in the sample python as SQL (Light gray background indicates where MMM mode is active)
(Modified again to allow single line statements)
(require 'mmm-mode)
(mmm-add-classes
'((python-sql
:submode sql-mode
:face mmm-code-submode-face
:front "# SQL\\(\n\\|\t\\)*\\(\[ -_A-Z0-9\]+\\)\\(\[ =\]\\)\\(\"\"\"\\|'''\\)"
:back "\\(\"\"\"\\|'''\\)\\( \\|\t\\|\n\\)*\\# /SQL")))
(mmm-add-mode-ext-class 'python-mode "*.py" 'python-sql)