all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Help with font-lock / syntax-propertize-function
Date: Fri, 19 Dec 2014 09:53:10 -0800	[thread overview]
Message-ID: <CAOj2CQQBLR7xHwyWMvfprLU9UFNmQDb+5OpeXaEih6bXSUErXw@mail.gmail.com> (raw)

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


             reply	other threads:[~2014-12-19 17:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-19 17:53 John Mastro [this message]
2014-12-20 14:27 ` Help with font-lock / syntax-propertize-function Stefan Monnier
2014-12-20 19:34   ` John Mastro
2014-12-21  2:20     ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOj2CQQBLR7xHwyWMvfprLU9UFNmQDb+5OpeXaEih6bXSUErXw@mail.gmail.com \
    --to=john.b.mastro@gmail.com \
    --cc=help-gnu-emacs@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.