From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Mauger Newsgroups: gmane.emacs.devel Subject: Re: Patch for sql.el Date: Thu, 6 May 2004 15:30:12 -0700 (PDT) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <20040506223012.96520.qmail@web60305.mail.yahoo.com> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1083884857 23821 80.91.224.253 (6 May 2004 23:07:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 6 May 2004 23:07:37 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri May 07 01:07:27 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BLrxf-0001mc-00 for ; Fri, 07 May 2004 01:07:27 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BLrxf-0003q0-00 for ; Fri, 07 May 2004 01:07:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BLrcp-0007YL-Pf for emacs-devel@quimby.gnus.org; Thu, 06 May 2004 18:45:55 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BLrZ5-0006Mx-QL for emacs-devel@gnu.org; Thu, 06 May 2004 18:42:03 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BLrNe-0004HM-I4 for emacs-devel@gnu.org; Thu, 06 May 2004 18:30:45 -0400 Original-Received: from [216.109.118.116] (helo=web60305.mail.yahoo.com) by monty-python.gnu.org with smtp (Exim 4.30) id 1BLrNd-0004Gg-NO for emacs-devel@gnu.org; Thu, 06 May 2004 18:30:13 -0400 Original-Received: from [32.97.32.246] by web60305.mail.yahoo.com via HTTP; Thu, 06 May 2004 15:30:12 PDT Original-To: Stefan Monnier In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:22887 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22887 --- Stefan Monnier 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