[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: XKCD/541 compliance, anyone?
From: |
Stefan Monnier |
Subject: |
Re: XKCD/541 compliance, anyone? |
Date: |
Thu, 01 Jan 2015 12:07:49 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
> (defvar smiley-regex "[:;x>B][,']?-?[]()PD]"
> "This regex should match smileys.")
> (defun make-smileys-punctuation (beg end)
> "Look for smileys between BEG and END position in the buffer, and
> change their syntax property to punctuation."
> (goto-char beg)
> (while (re-search-forward smiley-regex end t)
> (put-text-property (match-beginning 0) (match-end 0) 'syntax-table '(1))))
You can also use
(syntax-propertize-rules (smiley-regex (0 ".")))
> (defun enable-smileys-punctuation ()
> (setq syntax-propertize-function #'make-smileys-punctuation)
Beware: syntax-propertize-function might already be in use, in which
case you should probably use add-function to combine the two.
> (setq parse-sexp-lookup-properties t))
This is not necessary, it will be set by the syntax-propertize function.
> However, it did not work (in text mode); my make-smileys-punctuation
> seems not even to get called.
Right, syntax-propertization is done lazily, so if nothing calls
syntax-propertize, then that's that. Usually the main triggers for
syntax-propertize are syntax-ppss and font-lock, but neither is likely
to be used in text-mode. So you'll probably need to arrange for font-lock to
be enabled *and* for font-lock-keywords-only not to be set to t.
> but then again, not in message mode, for instance.
Probably because font-lock-keywords-only is set to t, so font-lock
doesn't end up calling syntax-ppss.
Stefan
- Re: XKCD/541 compliance, anyone?,
Stefan Monnier <=
Re: XKCD/541 compliance, anyone?, Marcin Borkowski, 2015/01/02
Re: XKCD/541 compliance, anyone?, Marcin Borkowski, 2015/01/07