[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help with font-lock / syntax-propertize-function
From: |
John Mastro |
Subject: |
Help with font-lock / syntax-propertize-function |
Date: |
Fri, 19 Dec 2014 09:53:10 -0800 |
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
- Help with font-lock / syntax-propertize-function,
John Mastro <=