Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect highlighting of superglobals and predefined constants #75

Open
flack opened this issue Mar 6, 2013 · 3 comments
Open

Incorrect highlighting of superglobals and predefined constants #75

flack opened this issue Mar 6, 2013 · 3 comments
Assignees
Labels

Comments

@flack
Copy link
Contributor

flack commented Mar 6, 2013

ATM, php-mode treats all constants and superglobals as case-insensitive, i.e. $_server or pHp_VeRsIon are highlighted as if the were correct, but PHP will only throw errors if you run this.

From what I've gathered from the PHP documentation, only the eight magic constants are case-insensitive. All superglobals and predefined constants and the ones from core extensions are case-sensitive, and should only be highlighted if they are all caps

@ghost ghost assigned ejmr Mar 9, 2013
@ejmr
Copy link
Collaborator

ejmr commented Mar 9, 2013

I started work on this but I'm going to have to email some more knowledgable Elisp programmers to find the best way to resolve it.

@ejmr
Copy link
Collaborator

ejmr commented Mar 9, 2013

In case anyone cares to follow the related Q&A on gmane.emacs.help:

http://permalink.gmane.org/gmane.emacs.help/89444

@ejmr
Copy link
Collaborator

ejmr commented Mar 13, 2013

I could not find any way to tell font-lock to treat some regular expressions in a case-insensitive way. So what I am doing is making php-mode treat all regular expressions as case-sensitive by default and then I'm going to manually craft expressions for the magic constants that are case-insensitive. Here is a utility function I wrote to help create those expressions, which others may find useful.

(defun make-case-insensitive-regexp (word)
  "Make a case-insensitive regular expression matching WORD."
  (apply (function concat)
   (mapcar #'(lambda (character)
               (if (char-equal ?_ character)
                   (string character)
                 (string ?\[
                         (downcase character)
                         (upcase character)
                         ?\])))
           word)))

So for example (make-case-insensitive-regexp "__FUNCTION__") returns the string "__[fF][uU][nN][cC][tT][iI][oO][nN]__". Not pretty, but the best solution I could come up with. So hopefully I can write a full patch to fix this issue soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants