php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

Define individual faces for individual keywords

Open minikN opened this issue 4 years ago • 3 comments

At the moment, changing the php-keyword face, will affect elements like new, public, function, extends and more.

I believe this is because most *-kwds constants will get assigned font-lock-keyword-face by font-lock. In particular:

(c-lang-defconst c-typeless-decl-kwds
  php (append (c-lang-const c-class-decl-kwds) '("function")))

(c-lang-defconst c-modifier-kwds
  php '("abstract" "const" "final" "static"))

(c-lang-defconst c-protection-kwds
  "Access protection label keywords in classes."
  php '("private" "protected" "public"))

(c-lang-defconst c-postfix-decl-spec-kwds
  php '("implements" "extends"))

(c-lang-defconst c-type-list-kwds
  php '("@new" ;; @new is *NOT* language construct, it's workaround for coloring.
        "new" "use" "implements" "extends" "namespace" "instanceof" "insteadof"))

(c-lang-defconst c-ref-list-kwds
  php nil)

(c-lang-defconst c-block-stmt-2-kwds
  php '("catch" "declare" "elseif" "for" "foreach" "if" "switch" "while"))

(c-lang-defconst c-simple-stmt-kwds
  php '("break" "continue" "die" "echo" "exit" "goto" "return" "throw"
        "include" "include_once" "print" "require" "require_once"))

(c-lang-defconst c-constant-kwds
  php '("true" "false" "null"))

(c-lang-defconst c-lambda-kwds
  php '("function" "use"))

(c-lang-defconst c-other-block-decl-kwds
  php '("namespace"))

(c-lang-defconst c-other-kwds
  "Keywords not accounted for by any other `*-kwds' language constant."
  php
  '(
    "__halt_compiler"
    "and"
    "array"
    "as"
    "break"
    "catch"
    "clone"
    "default"
    "empty"
    "enddeclare"
    "endfor"
    "endforeach"
    "endif"
    "endswitch"
    "endwhile"
    "eval"
    "fn" ;; NOT c-lambda-kwds
    "global"
    "isset"
    "list"
    "or"
    "parent"
    "static"
    "unset"
    "var"
    "xor"
    "yield"
    "yield from"

    ;; Below keywords are technically not reserved keywords, but
    ;; threated no differently by php-mode from actual reserved
    ;; keywords
    ;;
    ;;; declare directives:
    "encoding"
    "ticks"
    "strict_types"

    ;;; self for static references:
    "self"
    ))

these. In my opinon the user should have more freedom in choosing which statement should be fontified by what face (E.g. maybe I want if to be colored different from class ... extends ...).

I could write a PR for that, but first I wanted to make sure a change like that would be welcomed by the maintainer.

Waiting on feedback for this.

minikN avatar Dec 23 '19 11:12 minikN

@minikN I can't make a decision without seeing the implementation, but I think you can probably accept your suggestion. If there is a problem with your pull-request I will re-implement it.

zonuexe avatar Dec 23 '19 14:12 zonuexe

Alright. Will create PR shortly.

minikN avatar Dec 23 '19 14:12 minikN

There you go: #606

minikN avatar Jan 03 '20 09:01 minikN