emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Feature request: Easy customisation of sql-mode product keywords


From: Nik Clayton
Subject: Feature request: Easy customisation of sql-mode product keywords
Date: Tue, 7 May 2019 19:33:59 +0200

Hi, I've got a feature request for sql-mode.

[not 100% certain if this list was better than bug-gnu-emacs, but https://www.emacswiki.org/emacs/MichaelMauger mentioned monitoring this list, so I figured it was a better fit]

I'd like to be able to easily either:

1. Configure the mode to only recongnise keywords in uppercase, or
2. Customise the keywords associated with an SQL product in sql-mode.

The specific problem I have, and why this would solve it is as follows.

I produce some teaching material using Emacs and org-mode, exporting the results to HTML. This uses the syntax highlighting in Emacs to generate syntax highlighted SQL in the slides and course notes.

However, given a query like the following:

  SELECT name
    FROM track
   WHERE trackid = 1222;

the "name" on the first line is highlighted as a keyword. Because it is, it shows up in sql-mode-ansi-font-lock-keywords.

However, this means that it's rendered differently to "track" snd "trackid = 1222;" in that example.

This is not easy behaviour to customise in my Emacs configuration (as far as I can tell), for a few reasons.

The most important is that the code that creates sql-mode-ansi-font-lock-keywords runs under eval-when-compile -- it's not a function that I can call again after making some modifications, or provide advice around to customise the behaviour.

Similarly, this means that I can't advise sql-font-lock-keywords-builder, and change its arguments so that it only receives upper-case keywords -- by the time my code runs its too late.

The actual list of keywords in sql.el aren't bound to a list, only the resulting regexp is. Which means I can't take that list, modify it, and create a new value for sql-mode-ansi-font-lock-keywords

So I resorted to this:

(setf (car (car sql-mode-ansi-font-lock-keywords))
      (s-replace "n\\(?:ame\\|u\\(?:llable\\|mber\\)\\))"
                 "nu\\(?:llable\\|mber\\))"
                 (car (car sql-mode-ansi-font-lock-keywords))))

Best, N

reply via email to

[Prev in Thread] Current Thread [Next in Thread]