Skip to content

Commit 95834aa

Browse files
authored
Merge pull request #819 from emacs-php/refactor/magical-constants
Move php-magical-constants to php-keywords.el
2 parents 09855bd + edc3d97 commit 95834aa

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

lisp/php-keywords.el

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353
;; of scope, and deliberately not duplicated here:
5454
;;
5555
;; - built-in function names -- see lisp/php-defs.el;
56-
;; - the magic constants (`__LINE__' and friends), which are written
57-
;; upper-case and matched case-sensitively -- php.el owns that list
58-
;; as `php-magical-constants', and both major modes build their
59-
;; font-lock rule from it directly;
6056
;; - predefined runtime constants such as `PHP_EOL' or `PHP_INT_MAX',
6157
;; which are library symbols rather than language keywords.
58+
;;
59+
;; `php-magical-constants' is the one exception to the naming convention
60+
;; above. It is a long-standing public symbol that php.el used to own,
61+
;; and both major modes build their font-lock rule straight from it, so
62+
;; it keeps its name; php.el requires this file and re-exports it.
6263

6364
;;; Code:
6465

@@ -226,21 +227,29 @@ Match against buffer text with `case-fold-search' bound to non-nil.")
226227
;; PHP language constants; stored lower-case here, same convention as
227228
;; every other list in this file).
228229
;;
229-
;; The magic constants (`__CLASS__', `__LINE__', ...) are intentionally
230-
;; NOT mirrored here. They are not part of php-cc-mode.el's 367-609
231-
;; c-lang-defconst block either: both major modes fontify them straight
232-
;; from php.el's `php-magical-constants', which stays the single source
233-
;; of truth for that list.
230+
;; The magic constants (`__CLASS__', `__LINE__', ...) are not part of
231+
;; php-cc-mode.el's 367-609 c-lang-defconst block: both major modes
232+
;; fontify them straight from `php-magical-constants', which php.el used
233+
;; to define and which now sits below, next to the rest of the
234+
;; vocabulary.
234235
(defconst php-keywords--constants
235236
'("true" "false" "null")
236237
"PHP literal keywords `true', `false' and `null' (case-insensitive).
237238
The upper-case magic constants (`__LINE__' and friends) are matched
238-
case-sensitively and live in php.el's `php-magical-constants'.")
239+
case-sensitively; see `php-magical-constants'.")
239240

240241
(defconst php-keywords--constants-re
241242
(regexp-opt php-keywords--constants 'symbols)
242243
"`regexp-opt' of `php-keywords--constants', symbol-bounded.
243244
Match against buffer text with `case-fold-search' bound to non-nil.")
244245

246+
(defconst php-magical-constants
247+
'("__CLASS__" "__DIR__" "__FILE__" "__FUNCTION__" "__LINE__"
248+
"__METHOD__" "__NAMESPACE__" "__TRAIT__")
249+
"Magical keyword that is expanded at compile time.
250+
251+
These are different from \"constants\" in strict terms.
252+
see https://www.php.net/manual/language.constants.predefined.php")
253+
245254
(provide 'php-keywords)
246255
;;; php-keywords.el ends here

lisp/php.el

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
(require 'cc-engine)
4040
(require 'flymake)
4141
(require 'php-core)
42+
(require 'php-keywords)
4243
(require 'php-project)
4344
(require 'rx)
4445

@@ -244,14 +245,6 @@ out and get `php-default-major-mode' instead."
244245
:type 'face)
245246

246247
;;; PHP Keywords
247-
(defconst php-magical-constants
248-
'("__CLASS__" "__DIR__" "__FILE__" "__FUNCTION__" "__LINE__"
249-
"__METHOD__" "__NAMESPACE__" "__TRAIT__")
250-
"Magical keyword that is expanded at compile time.
251-
252-
These are different from \"constants\" in strict terms.
253-
see https://www.php.net/manual/language.constants.predefined.php")
254-
255248
(defconst php-re-token-symbols
256249
(eval-when-compile
257250
(regexp-opt (list "&" "&=" "array(" "(array)" "&&" "||" "(bool)" "(boolean)" "break;" "?>" "%>"

0 commit comments

Comments
 (0)