1

I'm trying to get the font-lock stuff in plsql.el (https://www.emacswiki.org//emacs/plsql.el) to work in Emacs 24 (that's the version provided by my Linux distro), but it doesn't highlight automatically on entering the mode and it only highlights strings and comments, not keywords like procedure.

This module is working on the old computer with Emacs 21, so I assume something has changed. The docs on emacswiki seem vague to a non-elisp programmer. (I can read elisp, and have written a few macros, but not an expert by any stretch.)

So, unless somebody knows of an alternative working PL/SQL mode that works with font-lock on 24, I'd like to start by looking at the font-lock settings, but I don't see any usable functions that start with font-lock- in the autocomplete list. How do I do this? side by side putty with example package

I made the change suggested by Stefan and moved the sql-mode line and got the same thing. The image is after running M-x font-lock-fontify-buffer. New computer on left, old on right.

Plain SQL mode doesn't do anything different.

  • The standard sql.el that comes with Emacs seems to have support for highlighting PL/SQL keywords. Whether that was already present in Emacs-24, I cannot say but it's quite possible. Have you tried that? If yes, then please describe what you found missing from that sql.el support. – Stefan Feb 13 at 17:28
  • @Stefan SQL mode does the same thing--only basic highlighting. Maybe the Oracle Linux distribution broke it somehow? – that it guy Feb 13 at 18:38
  • Looking at the history of sql.el, I think Emacs-24's sql-mode should already highlight your code like you want. Try emacs -Q .../test.pkb -f sql-mode. – Stefan Feb 13 at 19:17
1

After reading the sql-mode source, I discovered what I think is the issue. Here's a workaround in case anyone else has this (or when I have the same issue 6 months from now...)

sql-mode apparently has different dialects of SQL that it can recognize. When it loads at startup it defaults to ANSI mode. But if you run it via M-x sql-mode it doesn't do that and only loads the most basic keywords into font-lock.

A second command, M-x sql-set-product oracle or M-x sql-set-product ansi is required to set the appropriate dialect, which loads the keywords. I added that to the plsql.el file after the call to sql-mode and that seems to have gotten it to work.

(defun plsql-mode ()
  "Programming support mode for PL/SQL code."

  (interactive)
;;  (require 'sql)
    (sql-mode)
    (sql-set-product "oracle")
0

Looking at plsql.el I suspect the problem is in:

(defun plsql-mode ()
  "Programming support mode for PL/SQL code."
  (interactive)
  (require 'sql)
  [...]
  (setq sql-mode-font-lock-keywords ...)
  (setq font-lock-mark-block-function 'mark-visible)
  (sql-mode)
  [...]

since when we call sql-mode, it will re-set sql-mode-font-lock-keywords, so the call to sql-mode should come first (basically right where is the redundant (require 'sql)).

If you define plsql-mode with define-derived-mode this will be taken care of automatically ;-)

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.