I have the following function
(defun fphp/find-unimported-classes ()
(interactive)
(mapcar (lambda (classentry)
(ov-clear (classentry-overlay classentry))
)
classentries)
(setq classentries '())
(save-excursion
(goto-char (point-min))
(while (re-search-forward "$[A-Z]+" nil t)
(backward-word)
(backward-word)
(setq word (current-word))
(setq wordpoint (point))
(forward-word)
(setq endwordpoint (point))
(forward-word)
(if (string= (capitalize word) word)
(add-to-list 'classentries (make-classentry :word word))))
(mapcar (lambda (classentry)
(goto-char (point-max))
(setq word (classentry-word classentry))
(message word)
(setq classregexp (concat "\\(" (substring word 0 1) "\\)"
(substring word 1) "\s"))
(if (buffer-contains-string (concat "use [A-Z+\\]+" word ";"))
(ov-set classregexp 'face 'class-defined-face '(classentry-overlay classentry) t)
(ov-set classregexp 'face 'class-undefined-face '(classentry-overlay classentry) t)
)
)
classentries)
))
It's purpose is to match all unimported classes in the php code and it works quite well, however it matches also variable names, like:
$className
I want to modify it to match only capitalized words. The regexp is built here:
(setq classregexp (concat "\\(" (substring word 0 1) "\\)"
(substring word 1) "\s"))
How can I achieve it? Now it matches all cases of the first character.
[:upper:]
matches uppercase characters whencase-fold-search
is non-nil
. Also, you're using$
in your regular expression without escaping it, and in that case it matches end of the line, which probably isn't what you're looking for.$
has its special meaning only at the end of a regexp or before\)
or\|
.[:upper:]
. But you should write: "even whencase-fold-search
is non-nil" in your answer to stress that that version works withcase-fold-search
set tot
ornil
, i.e. that regexp is independent from the setting ofcase-fold-search
.