4

Here is a screenshot showing the difference between sql-interactive-mode (top) and sql-mode (bottom).

At the top, sql-interactive mode, at the bottom, sql-mode

Why does the string not get highlighted properly in sql-interactive-mode? (Note - this also happens with no color theme enabled.

5

There's code in sql-interactive-mode which says:

;; Note that making KEYWORDS-ONLY nil will cause havoc if you try
;; SELECT 'x' FROM DUAL with SQL*Plus, because the title of the column
;; will have just one quote.  Therefore syntactic highlighting is
;; disabled for interactive buffers.  No imenu support.
(sql-product-font-lock t nil)

and the t says "only highlight keywords".

So if you don't care about SQL*Plus - as should be the case for any reasonable person in control of his destiny and happiness - you can do the following:

(defun my-font-lock-everything-in-sql-interactive-mode ()
  (unless (eq 'oracle sql-product)
    (sql-product-font-lock nil nil)))
(add-hook 'sql-interactive-mode-hook 'my-font-lock-everything-in-sql-interactive-mode)

And indeed that seems to work nicely with PostgreSQL, at least in the simple case.

Where you might run into problems is if you SELECT data which contains, say, unmatched quote characters. The font locking will likely be applied to all of that data too, and the quotes might confuse it. So be prepared for quirks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.