Skip to content

Commit 78d116b

Browse files
committed
Add php-core.el for the dependency-free primitives
php.el is required by every PHP package, but it requires flymake, php-project and (for now) CC Mode. A module that only wants the `php' customization group or a syntax-ppss predicate pays for all of it: `(require 'php)' pulls in 17 features and ~53 ms. Move the definitions that depend on nothing into php-core.el: - the `php' customization group, - `php-executable', - `php-in-string-p' and its siblings, - `php-base-mode'. php.el requires php-core.el and therefore still exposes all of them, so `(require 'php)' behaves exactly as before and nothing has to migrate. php-indent.el, which only ever wanted the customization group, now requires php-core.el instead: 2 features and ~1 ms, with no flymake, php-project or cc-engine in its dependency chain. Two consequences worth noting: * php.el's defcustoms specify `:group 'php' again. #813 removed those as redundant, which was true only while the defgroup sat in the same file: `custom-current-group' keys off `load-file-name', so with the defgroup in php-core.el they would silently fall out of the group (`M-x customize-group php' listed 2 members instead of 29). They are required now, not redundant. * The syntax tables stay in php.el for the moment. They are built with `c-populate-syntax-table', so moving them would drag CC Mode into php-core.el and defeat the purpose; they can follow once php.el stops requiring cc-engine. Verified that (get GROUP 'custom-group) membership is identical to before for every php* group.
1 parent 22e5c80 commit 78d116b

4 files changed

Lines changed: 119 additions & 42 deletions

File tree

Eask

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(package-file "lisp/php-mode.el")
1111
(files
1212
"lisp/php.el"
13+
"lisp/php-core.el"
1314
"lisp/php-complete.el"
1415
"lisp/php-defs.el"
1516
"lisp/php-indent.el"

lisp/php-core.el

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
;;; php-core.el --- Core definitions shared by PHP packages -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2026 Friends of Emacs-PHP development
4+
5+
;; Author: USAMI Kenta <tadsan@zonu.me>
6+
;; Maintainer: USAMI Kenta <tadsan@zonu.me>
7+
;; URL: https://github.com/emacs-php/php-mode
8+
;; Keywords: languages, php
9+
;; License: GPL-3.0-or-later
10+
11+
;; This program is free software; you can redistribute it and/or modify
12+
;; it under the terms of the GNU General Public License as published by
13+
;; the Free Software Foundation, either version 3 of the License, or
14+
;; (at your option) any later version.
15+
16+
;; This program is distributed in the hope that it will be useful,
17+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
;; GNU General Public License for more details.
20+
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
23+
24+
;;; Commentary:
25+
26+
;; This file holds the handful of definitions that every PHP package
27+
;; needs and that depend on nothing else: the `php' customization group,
28+
;; the `php-executable' path, the `syntax-ppss' predicates and the
29+
;; `php-base-mode' parent mode.
30+
;;
31+
;; It exists so that a module can reach those primitives without pulling
32+
;; in the whole of php.el, which requires `flymake' and `php-project'
33+
;; (and, for now, CC Mode). php.el itself requires this file and
34+
;; re-exports everything here, so `(require 'php)' keeps working exactly
35+
;; as before; nothing needs to migrate.
36+
;;
37+
;; Keep this file free of dependencies. Anything that needs `flymake',
38+
;; `php-project', CC Mode or a PHP syntax table belongs in php.el, not
39+
;; here.
40+
41+
;;; Code:
42+
43+
44+
;;; Customization group
45+
46+
;;;###autoload
47+
(defgroup php nil
48+
"Language support for PHP."
49+
:tag "PHP"
50+
:group 'languages
51+
:link '(url-link :tag "Official Site" "https://github.com/emacs-php/php-mode")
52+
:link '(url-link :tag "PHP Mode Wiki" "https://github.com/emacs-php/php-mode/wiki"))
53+
54+
(defcustom php-executable (or (executable-find "php") "php")
55+
"The location of the PHP executable."
56+
:tag "PHP Executable"
57+
:type 'string)
58+
59+
60+
;;; Utility for locating language constructs
61+
62+
(defsubst php-in-string-p ()
63+
"Return non-nil if inside a string.
64+
It is the character that will terminate the string, or t if the string should
65+
be terminated by a generic string delimiter."
66+
(nth 3 (syntax-ppss)))
67+
68+
(defsubst php-in-comment-p ()
69+
"Return NIL if outside a comment, T if inside a non-nestable comment, else
70+
an integer (the current comment nesting)."
71+
(nth 4 (syntax-ppss)))
72+
73+
(defsubst php-in-string-or-comment-p ()
74+
"Return character address of start of comment or string; nil if not in one."
75+
(nth 8 (syntax-ppss)))
76+
77+
(defsubst php-in-poly-php-html-mode ()
78+
"Return T if current buffer is in `poly-html-mode'."
79+
(bound-and-true-p poly-php-html-mode))
80+
81+
82+
;;; Base major mode
83+
84+
;;;###autoload
85+
(define-derived-mode php-base-mode prog-mode "PHP"
86+
"Generic major mode for editing PHP.
87+
88+
This mode is intended to be inherited by concrete major modes.
89+
Currently there are `php-mode' and `php-ts-mode'."
90+
nil)
91+
92+
(provide 'php-core)
93+
;;; php-core.el ends here

lisp/php-indent.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
;;; Code:
4242

43-
(require 'php)
43+
(require 'php-core)
4444

4545
;;; Customization
4646

lisp/php.el

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,34 @@
3838
(require 'cl-lib))
3939
(require 'cc-engine)
4040
(require 'flymake)
41+
(require 'php-core)
4142
(require 'php-project)
4243
(require 'rx)
4344

44-
;;;###autoload
45-
(defgroup php nil
46-
"Language support for PHP."
47-
:tag "PHP"
48-
:group 'languages
49-
:link '(url-link :tag "Official Site" "https://github.com/emacs-php/php-mode")
50-
:link '(url-link :tag "PHP Mode Wiki" "https://github.com/emacs-php/php-mode/wiki"))
51-
52-
(defcustom php-executable (or (executable-find "php") "php")
53-
"The location of the PHP executable."
54-
:tag "PHP Executable"
55-
:type 'string)
56-
5745
(defcustom php-phpdbg-executable (list "phpdbg")
5846
"The location of the PHPDBG executable."
47+
:group 'php
5948
:tag "PHP PHPDBG Executable"
6049
:type '(repeat string))
6150

6251
(defcustom php-php-parse-executabe nil
6352
"The location of the php-parse executable."
53+
:group 'php
6454
:tag "PHP php-parse Executable"
6555
:type '(repeat string))
6656

6757
(defcustom php-site-url "https://www.php.net/"
6858
"Default PHP.net site URL.
6959
7060
The URL to use open PHP manual and search word."
61+
:group 'php
7162
:tag "PHP Site URL"
7263
:type 'string)
7364

7465
(defcustom php-manual-url 'en
7566
"URL at which to find PHP manual.
7667
You can replace \"en\" with your ISO language code."
68+
:group 'php
7769
:tag "PHP Manual URL"
7870
:type '(choice (const :tag "English" en)
7971
(const :tag "Brazilian Portuguese" pt_BR)
@@ -89,20 +81,24 @@ You can replace \"en\" with your ISO language code."
8981

9082
(defcustom php-search-url nil
9183
"URL at which to search for documentation on a word."
84+
:group 'php
9285
:tag "PHP Search URL"
9386
:type '(choice (string :tag "URL to search PHP documentation")
9487
(const :tag "Use `php-site-url' variable" nil)))
9588

9689
(defcustom php-completion-file ""
9790
"Path to the file which contains the function names known to PHP."
91+
:group 'php
9892
:type 'string)
9993

10094
(defcustom php-manual-path ""
10195
"Path to the directory which contains the PHP manual."
96+
:group 'php
10297
:type 'string)
10398

10499
(defcustom php-search-documentation-function #'php-search-web-documentation
105100
"Function to search PHP Manual at cursor position."
101+
:group 'php
106102
:tag "PHP Search Documentation Function"
107103
:type '(choice (const :tag "Use online documentation" php-search-web-documentation)
108104
(const :tag "Use local documentation" php-local-manual-search)
@@ -113,6 +109,7 @@ You can replace \"en\" with your ISO language code."
113109
114110
If non-nil, this shadows the value of `browse-url-browser-function' when
115111
calling `php-search-documentation' or `php-search-local-documentation'."
112+
:group 'php
116113
:tag "PHP Search Documentation Browser Function"
117114
:type '(choice (const :tag "default" nil) function)
118115
:link '(variable-link browse-url-browser-function))
@@ -157,24 +154,29 @@ a completion list."
157154

158155
(defcustom php-class-suffix-when-insert "::"
159156
"Suffix for inserted class."
157+
:group 'php
160158
:type 'string)
161159

162160
(defcustom php-namespace-suffix-when-insert "\\"
163161
"Suffix for inserted namespace."
162+
:group 'php
164163
:type 'string)
165164

166165
(defcustom php-default-major-mode 'php-mode
167166
"Major mode for editing PHP script."
167+
:group 'php
168168
:tag "PHP Default Major Mode"
169169
:type 'function)
170170

171171
(defcustom php-html-template-major-mode 'web-mode
172172
"Major mode for editing PHP-HTML template."
173+
:group 'php
173174
:tag "PHP-HTML Template Major Mode"
174175
:type 'function)
175176

176177
(defcustom php-blade-template-major-mode 'web-mode
177178
"Major mode for editing Blade template."
179+
:group 'php
178180
:tag "PHP Blade Template Major Mode"
179181
:type 'function)
180182

@@ -183,40 +185,47 @@ a completion list."
183185
("\\.phpt\\'" . ,(if (fboundp 'phpt-mode) 'phpt-mode php-default-major-mode))
184186
("\\.phtml\\'" . ,php-html-template-major-mode))
185187
"Automatically use another MAJOR-MODE when open template file."
188+
:group 'php
186189
:tag "PHP Template Mode Alist"
187190
:type '(alist :key-type regexp :value-type function)
188191
:link '(url-link :tag "web-mode" "http://web-mode.org/")
189192
:link '(url-link :tag "phpt-mode" "https://github.com/emacs-php/phpt-mode"))
190193

191194
(defcustom php-mode-maybe-hook nil
192195
"List of functions to be executed on entry to `php-mode-maybe'."
196+
:group 'php
193197
:tag "PHP Mode Maybe Hook"
194198
:type 'hook)
195199

196200
(defcustom php-default-builtin-web-server-port 3939
197201
"Port number of PHP Built-in HTTP server (php -S)."
202+
:group 'php
198203
:tag "PHP Default Built-in Web Server Port"
199204
:type 'integer
200205
:link '(url-link :tag "Built-in web server"
201206
"https://www.php.net/manual/features.commandline.webserver.php"))
202207

203208
(defcustom php-topsy-separator " > "
204209
"Separator string for `php-topsy-beginning-of-defun-with-class'."
210+
:group 'php
205211
:tag "PHP Topsy Separator"
206212
:type 'string)
207213

208214
(defcustom php-function-call 'php-function-call-traditional
209215
"Face name to use for method call."
216+
:group 'php
210217
:tag "PHP Function Call"
211218
:type 'face)
212219

213220
(defcustom php-method-call 'php-method-call-traditional
214221
"Face name to use for method call."
222+
:group 'php
215223
:tag "PHP Method Call"
216224
:type 'face)
217225

218226
(defcustom php-static-method-call 'php-static-method-call-traditional
219227
"Face name to use for method call."
228+
:group 'php
220229
:tag "PHP Static Method Call"
221230
:type 'face)
222231

@@ -239,26 +248,6 @@ see https://www.php.net/manual/language.constants.predefined.php")
239248
"[" "]" "(" ")" "{" "}" ";")
240249
t)))
241250

242-
;;; Utillity for locate language construction
243-
(defsubst php-in-string-p ()
244-
"Return non-nil if inside a string.
245-
It is the character that will terminate the string, or t if the string should
246-
be terminated by a generic string delimiter."
247-
(nth 3 (syntax-ppss)))
248-
249-
(defsubst php-in-comment-p ()
250-
"Return NIL if outside a comment, T if inside a non-nestable comment, else
251-
an integer (the current comment nesting)."
252-
(nth 4 (syntax-ppss)))
253-
254-
(defsubst php-in-string-or-comment-p ()
255-
"Return character address of start of comment or string; nil if not in one."
256-
(nth 8 (syntax-ppss)))
257-
258-
(defsubst php-in-poly-php-html-mode ()
259-
"Return T if current buffer is in `poly-html-mode'."
260-
(bound-and-true-p poly-php-html-mode))
261-
262251
(defconst php-beginning-of-defun-regexp
263252
(eval-when-compile
264253
(rx bol
@@ -451,6 +440,7 @@ can be used to match against definitions for that classlike."
451440

452441
(defcustom php-imenu-generic-expression 'php-imenu-generic-expression-default
453442
"Default Imenu generic expression for PHP Mode. See `imenu-generic-expression'."
443+
:group 'php
454444
:type '(choice (alist :key-type string :value-type (list string))
455445
(const php-imenu-generic-expression-legacy)
456446
(const php-imenu-generic-expression-simple)
@@ -599,6 +589,7 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
599589

600590
(defcustom php-re-detect-html-tag 'php-re-detect-html-tag-default
601591
"Regexp pattern variable-name of HTML detection."
592+
:group 'php
602593
:tag "PHP Re Detect HTML Tag"
603594
:type '(choice (const :tag "Default pattern" php-re-detect-html-tag-default)
604595
(const :tag "Aggressive pattern" php-re-detect-html-tag-aggressive)
@@ -653,14 +644,6 @@ indentation."
653644
(setq mode nil)))
654645
(or mode php-default-major-mode)))
655646

656-
;;;###autoload
657-
(define-derived-mode php-base-mode prog-mode "PHP"
658-
"Generic major mode for editing PHP.
659-
660-
This mode is intended to be inherited by concrete major modes.
661-
Currently there are `php-mode' and `php-ts-mode'."
662-
nil)
663-
664647
;;;###autoload
665648
(defun php-mode-maybe ()
666649
"Select PHP mode or other major mode."

0 commit comments

Comments
 (0)