* Feature request: Easy customisation of sql-mode product keywords
@ 2019-05-07 17:33 Nik Clayton
0 siblings, 0 replies; 2+ messages in thread
From: Nik Clayton @ 2019-05-07 17:33 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1990 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 2437 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Feature request: Easy customisation of sql-mode product keywords
@ 2019-06-03 2:17 Michael Mauger
0 siblings, 0 replies; 2+ messages in thread
From: Michael Mauger @ 2019-06-03 2:17 UTC (permalink / raw)
To: emacs-devel\@gnu.org, Nik Clayton
On Tue, 7 May 2019 19:33:59 +0200, Nic Clayton said:
> 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]>
Sorry for the delay in responding-- I've been laid up for a while...
> 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.
>
> ...
>
> 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.
>
There are two ways to alter the keyword locking in your case:
1) Set `sql-mode-ansi-font-lock-keywords` to nil and rely upon only on the
dialect keywords
(setq sql-mode-ansi-font-lock-keywords nil)
2) Add keyword matching rules that override the default settings so that you get
highlighting that you want.
(sql-add-product-keywords 'mysql
(cons
(regexp-opt '("name" "table_name" "index_name" "constraint_name")
'symbols)
'(quote default)))
I am looking to add more sophisticated font locking to sql-mode to avoid
highlighting keywords in places where the syntax isn't looking for one.
>
> Best, N
Hopefully this helps. Happy Hacking!
--
MICHAEL@MAUGER.COM // FSF and EFF member // GNU Emacs sql.el maintainer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-03 2:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 2:17 Feature request: Easy customisation of sql-mode product keywords Michael Mauger
-- strict thread matches above, loose matches on Subject: below --
2019-05-07 17:33 Nik Clayton
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).