unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Help with font-lock / syntax-propertize-function
@ 2014-12-19 17:53 John Mastro
  2014-12-20 14:27 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: John Mastro @ 2014-12-19 17:53 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hello Emacsers,

I'm trying to customize the fontification done by SQL mode in Emacs 24.4
(the PostgreSQL product, though IIUC that's not relevant to this
situation).

Column names that need to be quoted are put in double quotes. By
default, the text within the double quotes is fontified as if it were
not in quotes. So if I have a column name like "Date of Birth", the word
"Date" is fontified like a type name. (My understanding is that this is
because double quotes are treated as punctuation rather than string
delimiters).

I find that a little distracting - it makes it harder to tell where the
column name starts. What I'd like to do is force the text within double
quotes not to be fontified at all. However, even after reading the
relevant manual sections and some very useful blog posts[1][2] I'm still
not sure how to go about this.

I've cargo-culted some code, unsuccessfully. Any pointers on what I'm
doing wrong?

    (defun my-sql-syntax-propertize-function (beg end)
      (goto-char beg)
      (funcall
       (syntax-propertize-rules
        ((rx "\"" (1+ not-newline) "\"")
         (0 (ignore (my-sql-syntax-propertize-double-quotes)))))))

    (defun my-sql-syntax-propertize-double-quotes ()
      (let ((beg (match-beginning 0))
            (end (match-end 0)))
        (put-text-property beg end 'font-lock-face nil)))

    (defun my-sql-add-syntax-propertize-function ()
      (setq-local syntax-propertize-function
                  #'my-sql-syntax-propertize-function))

    (add-hook 'sql-mode-hook #'my-sql-add-syntax-propertize-function)

Thanks

[1]
http://www.lunaryorn.com/2014/03/12/syntactic-fontification-in-emacs.html
[2]
http://www.lunaryorn.com/2014/06/16/advanced-syntactic-fontification.html

-- 
john


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-21  2:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-19 17:53 Help with font-lock / syntax-propertize-function John Mastro
2014-12-20 14:27 ` Stefan Monnier
2014-12-20 19:34   ` John Mastro
2014-12-21  2:20     ` Stefan Monnier

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).