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

* Re: Help with font-lock / syntax-propertize-function
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2014-12-20 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

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

I think the simplest way to do that is, oddly enough to set the
syntax-table to have the " character be given the " syntax (so that
"..." is then fontified by font-lock with the font-lock-string-face),
and then to customize your font-lock-string-face to look very much like
the default face.


        Stefan




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

* Re: Help with font-lock / syntax-propertize-function
  2014-12-20 14:27 ` Stefan Monnier
@ 2014-12-20 19:34   ` John Mastro
  2014-12-21  2:20     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: John Mastro @ 2014-12-20 19:34 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hi Stefan,

Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> I think the simplest way to do that is, oddly enough to set the
> syntax-table to have the " character be given the " syntax (so that
> "..." is then fontified by font-lock with the font-lock-string-face),
> and then to customize your font-lock-string-face to look very much like
> the default face.

Thanks for the reply.

I tried that but it didn't seem to affect fontification. If I run
(modify-syntax-entry ?\" "\"") in a SQL mode buffer, commands like
`kill-sexp' will then work on these column names (which was another of
my goals), but fontification is unaffected (even after M-x
font-lock-fontify-buffer).

Am I modifying the syntax table incorrectly?

By the way, my ideal solution would continue to highlight "real" strings
(those in single quotes) as strings, and only prevent highlighting of
column names (double quoted strings). So if you have any other thoughts
on how to accomplish that, it would be much appreciated.

-- 
john



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

* Re: Help with font-lock / syntax-propertize-function
  2014-12-20 19:34   ` John Mastro
@ 2014-12-21  2:20     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-12-21  2:20 UTC (permalink / raw)
  To: help-gnu-emacs

> I tried that but it didn't seem to affect fontification. If I run
> (modify-syntax-entry ?\" "\"") in a SQL mode buffer, commands like
> `kill-sexp' will then work on these column names (which was another of
> my goals), but fontification is unaffected (even after M-x
> font-lock-fontify-buffer).

> Am I modifying the syntax table incorrectly?

I don't know.  I'd need more details.  I suggest you report it as a bug,


        Stefan




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