Subject: bug#13755: 24.3.50; regression: incorrect font-lock highlighting

From: "Drew Adams" <[email-masked]>
Date: Sun, 10 Mar 2013 10:16:29 -0700

> >              "\\>[ \t'\(]*\\(\\sw+\\)?")
>                 ^^^
> There's your bug: you should use \\_>.
> 
> >    ("(\\(icicle-condition-case-no-debug\\)\\>"
>                                             ^^^
> Same here.

Actually, \\_> does NOT work for older Emacs versions (e.g. 20).

And \\>, instead of \\_>, DOES work - for all versions, even for the latest
build.  It's not clear to me why that is so, given that you suggested changing
it, and given that hyphen has `symbol', not `word' syntax in Emacs-Lisp mode.
Can you explain this?

> >       "\\_>[ \t'\(]*\\(\\sw+\\)?")
>                          ^^^^
> and this needs to be \\(?:\\sw\\|\\s_\\).

I now have the following, which seems to work for all Emacs versions (20 through
latest 24 trunk build):

(font-lock-add-keywords
 'emacs-lisp-mode
 `((,(concat "(" (regexp-opt
                  '("icicle-define-add-to-alist-command"
                    "icicle-define-bookmark-command"
                    "icicle-define-bookmark-other-window-command"
                    "icicle-define-command"
                    "icicle-define-file-command"
                    "icicle-define-search-bookmark-command"
                    "icicle-define-sort-command")
                  t)
             "\\>[ \t'\(]*\\(\\(\\sw\\|\\s_\\)+\\)?")
    (1 font-lock-keyword-face)
    ,(list (if (string-match "\\(?:\\)" "") 2 3)
           'font-lock-function-name-face nil t))
   ("(\\(icicle-condition-case-no-debug\\)\\>"
    1 font-lock-keyword-face)
   ("(\\(icicle-user-error\\)\\>"
    1 font-lock-warning-face)))

(FWIW, back in 2006 I used "\\s-+\\(\\sw\\(\\sw\\|\\s_\\)+\\)", but I changed
that to "\\>[ \t'\(]*\\(\\sw+\\)?" - I do not recall just why, wrt the last
part.  IOW, I purposely changed to use just \\sw.)

Please help me understand more.  Just what changed wrt font-locking of Lisp code
between the Emacs builds of Feb 15 and Feb 17?  What is the change that makes
such code changes necessary?

I've searched NEWS and looked at font-lock.el, but so far I do not understand
what you have changed in Emacs that broke the regexp that worked previously
(across all Emacs versions):
"\\>[ \t'\(]*\\(\\sw+\\)?".

I would like to understand why `word' syntax worked here before, even though
hyphen has and had then `symbol', not `word' syntax.  I would like to understand
just what has changed in Emacs.  Was there, e.g., a bug before, which made `-'
sometimes be treated as a word constituent?  What is behind this change?  Thx.