From: Michael Mauger <mmaug@yahoo.com>
Cc: emacs-devel@gnu.org
Subject: Re: Patch for sql.el
Date: Thu, 6 May 2004 15:30:12 -0700 (PDT) [thread overview]
Message-ID: <20040506223012.96520.qmail@web60305.mail.yahoo.com> (raw)
In-Reply-To: <jwv4qqvvprg.fsf-monnier+emacs@gnu.org>
--- Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> I guess the "cleanest" way to do it with the current
> font-lock.el code would be to only put the ANSI patterns on
> sql-font-lock-keywords and then use font-lock-add-keywords and
> font-lock-remove-keywords for the product-specific patterns
> (and call font-lock-fontify-buffer to refresh the buffer).
>
> But that does not allow you to play with the syntax-alist property.
>
Thanks, Stefan, for your efforts on this. I inherited much of this code
and you've helped me clean it up significantly.
Now, back to font-lock's syntax-alist property. What if it were possible
to add and remove syntax-alist entries ala keywords.
For example:
(defun font-lock-add-syntax (syntax-alist)
(dolist (selem syntax-alist)
;; The character to modify may be a single CHAR or a STRING.
(let ((syntax (cdr selem)))
(dolist (char (if (numberp (car selem))
(list (car selem))
(mapcar 'identity (car selem))))
;; Modify the entry for CHAR to be SYNTAX.
(modify-syntax-entry char syntax font-lock-syntax-table)))))
(defun font-lock-remove-syntax (syntax-alist)
(dolist (selem syntax-alist)
;; The character to modify may be a single CHAR or a STRING.
(let ((syntax (string-to-syntax (cdr selem))))
(dolist (char (if (numberp (car selem))
(list (car selem))
(mapcar 'identity (car selem))))
;; If the entry for CHAR is SYNTAX then reset to base entry.
(if (equal (aref font-lock-syntax-table char) syntax))
(aset font-lock-syntax-table char
(aref (syntax-table) char)))))))
Basically, `font-lock-add-syntax' duplicates the code in
`font-lock-set-defaults' and could be used there.
`font-lock-remove-syntax' takes the same parameter as `-add-syntax' and
restores the syntax setting from the buffer's base sytax table *only* if
the value in font-lock's syntax table is the same as the value in the
SYNTAX-ALIST argument.
With the above functions loaded, try this in *scratch*
;; This should be a comment
(aref font-lock-syntax-table ?\;) ;; => (11)
;; Reset the semicolon character class
(font-lock-add-syntax '((?\; . "w")))
(font-lock-fontify-buffer)
;; Comments should now not be highlighted
(aref font-lock-syntax-table ?\;) ;; => (2)
(font-lock-remove-syntax '((?\; . "(")))
(font-lock-fontify-buffer)
;; Comments should still not be highlighted
;; because semis were set to words not parens
(aref font-lock-syntax-table ?\;) ;; => (2)
(font-lock-remove-syntax '((?\; . "w")))
(font-lock-fontify-buffer)
;; They're baaaack!
(aref font-lock-syntax-table ?\;) ;; => (11)
If this is worth doing in font-lock, I can implement the incremental
loading and unloading of product specific keywords and syntax entries in
sql.el.
Or are we pushing the feature freeze...?
-- Michael
next prev parent reply other threads:[~2004-05-06 22:30 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 ` Patch for sql.el Michael Mauger
2004-05-04 21:59 ` Stefan Monnier
2004-05-06 22:30 ` Michael Mauger [this message]
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=20040506223012.96520.qmail@web60305.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).