From: Michael Mauger <mmaug@yahoo.com>
Cc: emacs-devel@gnu.org
Subject: Re: Patch for sql.el
Date: Mon, 3 May 2004 19:59:02 -0700 (PDT) [thread overview]
Message-ID: <20040504025902.840.qmail@web60301.mail.yahoo.com> (raw)
In-Reply-To: <m1vfjis64o.fsf-monnier+emacs@gnu.org>
Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Here is a counter patch. It is guaranteed 100% untested.
> It tries to avoid hardocding knowdlege about which version of
> Emacs provides which feature. So it just uses the right font-
> lock face and then arranges to define it if Emacs doesn't.
> Also it uses ". 12b" for syntax which AFAIK also works under
> XEmacs. Furthermore, it sets up font-lock in the normal way
> (if some of the code I removed turns out to be necessary, it
> either deserves changing font-lock or adding a comment
> explaining why sql.el is special).
<snip />
I did a little testing and made some adjustments. Sql.el is
a little different from most modes -- the keywords are dependent
upon the setting of a buffer local variable (`sql-product').
It is therefore possible that the font-lock settings may change
after the buffer has been fontified. I addressed this by setting
the variable `font-lock-set-defaults' to nil when `font-lock-
defaults' is changed. If `font-lock-mode' is active, I call
`font-lock-mode-internal' to turn it off and then call it
again to restore font-lock with the new settings.
If there is a better way to reset font-lock, let me know.
Here's the updated patch and ChangeLog:
2004-05-03 Michael Mauger <mmaug@yahoo.com>
* emacs/lisp/progmodes/sql.el (sql-xemacs-p, sql-emacs19-p)
(sql-emacs20-p): Removed.
(sql-mode-syntax-table): Used shared GNU EMacs/XEmacs syntax.
(sql-builtin-face, sql-doc-face): Removed.
(sql-mode-ansi-font-lock-keywords)
(sql-mode-oracle-font-lock-keywords)
(sql-mode-postgres-font-lock-keywords)
(sql-mode-linter-font-lock-keywords)
(sql-mode-ms-font-lock-keywords)
(sql-mode-mysql-font-lock-keywords): Use standard fonts.
(sql-product-font-lock): Fix font-lock reset when font rules
change.
(sql-highlight-product): Removed incorrect font-lock reset logic.
Index: emacs/lisp/progmodes/sql.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/sql.el,v
retrieving revision 1.40
diff -u -r1.40 sql.el
--- emacs/lisp/progmodes/sql.el 29 Apr 2004 21:55:28 -0000 1.40
+++ emacs/lisp/progmodes/sql.el 4 May 2004 02:09:55 -0000
@@ -4,7 +4,7 @@
;; Author: Alex Schroeder <alex@gnu.org>
;; Maintainer: Michael Mauger <mmaug@yahoo.com>
-;; Version: 2.0.0
+;; Version: 2.0.1
;; Keywords: comm languages processes
;; URL:
http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el
;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode
@@ -200,8 +200,11 @@
;; Gregor Zych <zych@pool.informatik.rwth-aachen.de>
;; nino <nino@inform.dk>
;; Berend de Boer <berend@pobox.com>
-;; Michael Mauger <mmaug@yahoo.com>
;; Adam Jenkins <adam@thejenkins.org>
+;; Michael Mauger <mmaug@yahoo.com> -- improved product support
+;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support
+;; Harald Maier <maierh@myself.com> -- sql-send-string
+;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections
\f
@@ -693,18 +696,6 @@
;;; Variables which do not need customization
-(defvar sql-xemacs-p
- (string-match "XEmacs\\|Lucid" emacs-version)
- "Is this a non-GNU Emacs?")
-
-(defvar sql-emacs19-p
- (string-match "GNU Emacs 19" emacs-version)
- "Is this a GNU Emacs 19?")
-
-(defvar sql-emacs20-p
- (string-match "20" emacs-version)
- "Is this a GNU Emacs 20?")
-
(defvar sql-user-history nil
"History of usernames used.")
@@ -876,9 +867,7 @@
(modify-syntax-entry ?/ ". 14" table)
(modify-syntax-entry ?* ". 23" table)
;; double-dash starts comment
- (if sql-xemacs-p
- (modify-syntax-entry ?- ". 56" table)
- (modify-syntax-entry ?- ". 12b" table))
+ (modify-syntax-entry ?- ". 12b" table)
;; newline and formfeed end coments
(modify-syntax-entry ?\n "> b" table)
(modify-syntax-entry ?\f "> b" table)
@@ -905,25 +894,6 @@
statement. The format of variable should be a valid
`font-lock-keywords' entry.")
-(defvar sql-builtin-face
- (if sql-xemacs-p
- ;; XEmacs doesn't have the builtin face
- 'font-lock-preprocessor-face
- ;; GNU Emacs 19 doesn't either
- (if sql-emacs19-p
- 'font-lock-keyword-face
- ;; Emacs 2x
- 'font-lock-builtin-face))
- "Builtin face for font-lock in SQL mode.")
-
-(defvar sql-doc-face
- (if (or sql-xemacs-p
- sql-emacs19-p
- sql-emacs20-p)
- 'font-lock-string-face
- 'font-lock-doc-face)
- "Documentation face for font-lock in SQL mode.")
-
(defmacro sql-keywords-re (&rest keywords)
"Compile-time generation of regexp matching any one of KEYWORDS."
`(eval-when-compile
@@ -1020,7 +990,7 @@
`((,ansi-non-reserved . font-lock-keyword-face)
(,ansi-reserved . font-lock-keyword-face)
- (,ansi-funcs . ,sql-builtin-face)
+ (,ansi-funcs . font-lock-builtin-face)
(,ansi-types . font-lock-type-face)))
"ANSI SQL keywords used by font-lock.
@@ -1230,11 +1200,11 @@
"\\b.*$"
))))
- `((,sqlplus-commands . ,sql-doc-face)
- (,oracle-functions . ,sql-builtin-face)
+ `((,sqlplus-commands . font-lock-doc-face)
+ (,oracle-functions . font-lock-builtin-face)
(,oracle-keywords . font-lock-keyword-face)
(,oracle-types . font-lock-type-face)
- (,plsql-functions . ,sql-builtin-face)
+ (,plsql-functions . font-lock-builtin-face)
(,plsql-keywords . font-lock-keyword-face)
(,plsql-type . font-lock-type-face)
(,plsql-warning . font-lock-warning-face)))
@@ -1323,7 +1293,7 @@
"timestamp" "varchar" "varying" "void" "zone"
)))
- `((,pg-funcs . ,sql-builtin-face)
+ `((,pg-funcs . font-lock-builtin-face)
(,pg-reserved . font-lock-keyword-face)
(,pg-types . font-lock-type-face)))
@@ -1404,7 +1374,7 @@
`((,linter-keywords . font-lock-keyword-face)
(,linter-reserved . font-lock-keyword-face)
- (,linter-functions . ,sql-builtin-face)
+ (,linter-functions . font-lock-builtin-face)
(,linter-types . font-lock-type-face)))
"Linter SQL keywords used by font-lock.
@@ -1507,9 +1477,9 @@
) t)
"\\)\\)\\|go\\s-*\\|use\\s-+\\|setuser\\s-+\\|dbcc\\s-+\\).*$"))))
- `((,ms-commands . ,sql-doc-face)
+ `((,ms-commands . font-lock-doc-face)
(,ms-reserved . font-lock-keyword-face)
- (,ms-functions . ,sql-builtin-face)
+ (,ms-functions . font-lock-builtin-face)
(,ms-vars . font-lock-variable-name-face)
(,ms-types . font-lock-type-face)))
@@ -1626,7 +1596,7 @@
"zerofill"
)))
- `((,mysql-funcs . ,sql-builtin-face)
+ `((,mysql-funcs . font-lock-builtin-face)
(,mysql-keywords . font-lock-keyword-face)
(,mysql-types . font-lock-type-face)))
@@ -1687,17 +1657,36 @@
;; Get the product-specific keywords.
(setq sql-mode-font-lock-keywords
(append
- (eval (sql-product-feature :font-lock))
+ (unless (eq sql-product 'ansi)
+ (eval (sql-product-feature :font-lock)))
+ ;; Always highlight ANSI keywords
(eval (sql-product-feature :font-lock 'ansi))
+ ;; Fontify object names in CREATE, DROP and ALTER DDL
+ ;; statements
(list sql-mode-font-lock-object-name)))
- ;; Setup font-lock. (What is the minimum we should have to do
- ;; here?)
- (setq font-lock-set-defaults nil
- font-lock-keywords sql-mode-font-lock-keywords
- font-lock-defaults (list 'sql-mode-font-lock-keywords
+ ;; Setup font-lock. Force re-parsing of `font-lock-defaults'.
+ (set (make-local-variable 'font-lock-set-defaults) nil)
+ (setq font-lock-defaults (list 'sql-mode-font-lock-keywords
keywords-only t syntax-alist))
+ ;; Force font lock to reinitialize if it is already on
+ ;; Otherwise, we can wait until it can be started.
+ (when (and (fboundp 'font-lock-mode)
+ font-lock-mode)
+ (font-lock-mode-internal nil)
+ (font-lock-mode-internal t))
+
+ (add-hook 'font-lock-mode-hook
+ (lambda ()
+ ;; Provide defaults for new font-lock faces.
+ (defvar font-lock-builtin-face
+ (if (boundp 'font-lock-preprocessor-face)
+ font-lock-preprocessor-face
+ font-lock-keyword-face))
+ (defvar font-lock-doc-face font-lock-string-face))
+ nil t)
+
;; Setup imenu; it needs the same syntax-alist.
(when imenu
(setq imenu-syntax-alist syntax-alist))))
@@ -1743,11 +1732,6 @@
(when (eq major-mode 'sql-mode)
;; Setup font-lock
(sql-product-font-lock nil t)
-
- ;; Force fontification, if its enabled.
- (if (and (boundp 'font-lock-mode)
- font-lock-mode)
- (font-lock-fontify-buffer))
;; Set the mode name to include the product.
(setq mode-name (concat "SQL[" (prin1-to-string sql-product) "]"))))
next parent reply other threads:[~2004-05-04 2:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m1vfjis64o.fsf-monnier+emacs@gnu.org>
2004-05-04 2:59 ` Michael Mauger [this message]
2004-05-04 21:59 ` Patch for sql.el Stefan Monnier
2004-05-06 22:30 ` Michael Mauger
2004-05-06 22:41 ` Stefan Monnier
2004-05-07 15:27 ` Michael Mauger
2004-05-07 16:48 ` Kevin Rodgers
2004-05-08 21:59 ` Richard Stallman
2004-05-08 21:59 ` Richard Stallman
2004-04-28 3:29 Michael Mauger
2004-04-29 23:28 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040504025902.840.qmail@web60301.mail.yahoo.com \
--to=mmaug@yahoo.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).