Skip to content

Commit f92c0ac

Browse files
authored
Merge pull request #828 from emacs-php/feature/backport-php-cc-mode
Backport php-cc-mode compatibility scaffolding
2 parents a3658f6 + 300c970 commit f92c0ac

7 files changed

Lines changed: 432 additions & 42 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
1313
* Shows whether it is on, what is configured, and what is available
1414
* Add `php-ide-eglot-activate`, which registers `php-ide-eglot-executable` into `eglot-server-programs`
1515
* Buffer-local, so only buffers that set the variable are affected; previously the variable had no effect on Eglot at all
16+
* Add `php-cc-mode` as a forward-compatible alias for the CC Mode based `php-mode`
17+
* Lets configuration and third-party code refer to the CC Mode implementation by the name it will keep once `php-mode` becomes cc-mode independent; loading it has no effect on `php-mode` itself
18+
* `php-cc-mode-hook`, `php-cc-mode-lineup-cascaded-calls` and `php-cc-mode-enable-backup-style-variables` are provided as aliases of their current `php-mode-*` counterparts
1619

1720
### Changed
1821

Eask

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"lisp/php-complete.el"
1515
"lisp/php-defs.el"
1616
"lisp/php-indent.el"
17+
"lisp/php-style.el"
1718
"lisp/php-keywords.el"
1819
"lisp/php-face.el"
1920
"lisp/php-flymake.el"
@@ -23,6 +24,7 @@
2324
"lisp/php-ide-phpactor.el"
2425
"lisp/php-ide.el"
2526
"lisp/php-align.el"
27+
"lisp/php-cc-mode.el"
2628
"lisp/php-mode-debug.el")
2729

2830
(script "test" "echo \"Error: no test specified\" && exit 1")

lisp/php-cc-mode.el

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
;;; php-cc-mode.el --- Compatibility alias for the CC Mode based php-mode -*- 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 is a forward-compatibility shim introduced while PHP Mode is
27+
;; being reworked to no longer depend on CC Mode.
28+
;;
29+
;; In the target design, the CC Mode based implementation is renamed to
30+
;; `php-cc-mode' and the name `php-mode' is reused for a cc-mode
31+
;; independent major mode. During the transition `php-mode' (in
32+
;; php-mode.el) is still the CC Mode based implementation, so this file
33+
;; only establishes the *names* that code will migrate to, without
34+
;; changing any behavior:
35+
;;
36+
;; - `php-cc-mode' is provided as an alias for `php-mode', so that
37+
;; configuration or third-party code written against the new name
38+
;; works now and keeps working after the eventual swap.
39+
;; - Variable names that will belong to `php-cc-mode' are provided as
40+
;; aliases of their current `php-mode-*' counterparts.
41+
;;
42+
;; Loading this file has no effect on `php-mode' itself: it does not
43+
;; register any `auto-mode-alist' / `interpreter-mode-alist' entry, and
44+
;; it does not redefine `php-mode'. It is intentionally kept out of the
45+
;; `php-mode' require graph and is loaded only when something asks for
46+
;; `php-cc-mode'.
47+
48+
;;; Code:
49+
50+
(require 'php-mode)
51+
52+
;;;###autoload
53+
(defalias 'php-cc-mode 'php-mode
54+
"Major mode for editing PHP code, based on CC Mode.
55+
56+
This is currently an alias for `php-mode'. It exists so that code can
57+
already refer to the CC Mode based implementation by the name it will
58+
keep (`php-cc-mode') once the default `php-mode' becomes the cc-mode
59+
independent implementation.")
60+
61+
;; Hook: configuration hung on `php-cc-mode-hook' should run for the CC
62+
;; Mode based mode. While `php-cc-mode' is an alias for `php-mode', the
63+
;; hook is an alias too, so setting either one has the same effect.
64+
(defvaralias 'php-cc-mode-hook 'php-mode-hook
65+
"Hook run when entering `php-cc-mode'.
66+
Currently an alias for `php-mode-hook'.")
67+
68+
;; Variables that will be owned by `php-cc-mode' in the target design.
69+
;; They are aliased to the current `php-mode-*' names so that either
70+
;; spelling works during the transition.
71+
(defvaralias 'php-cc-mode-lineup-cascaded-calls 'php-mode-lineup-cascaded-calls
72+
"Indent chained method calls to the previous line.
73+
Currently an alias for `php-mode-lineup-cascaded-calls'.")
74+
75+
(defvaralias 'php-cc-mode-enable-backup-style-variables 'php-mode-enable-backup-style-variables
76+
"When non-nil, back up values set by hook and buffer local variables.
77+
Currently an alias for `php-mode-enable-backup-style-variables'.")
78+
79+
(provide 'php-cc-mode)
80+
;;; php-cc-mode.el ends here

lisp/php-mode.el

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ Turning this on will open it whenever `php-mode' is loaded."
165165
(when val
166166
(speedbar 1))))
167167

168-
(define-obsolete-variable-alias 'php-template-compatibility 'php-mode-template-compatibility "1.20.0")
169-
(defcustom php-mode-template-compatibility t
170-
"Should detect presence of html tags."
171-
:tag "PHP Mode Template Compatibility"
172-
:type 'boolean)
168+
;; `php-mode-template-compatibility' is defined in php.el (shared).
173169

174170
(define-obsolete-variable-alias 'php-lineup-cascaded-calls 'php-mode-lineup-cascaded-calls "1.20.0")
175171
(defcustom php-mode-lineup-cascaded-calls nil
@@ -216,31 +212,14 @@ enabled."
216212
:tag "PHP Mode Hook"
217213
:type 'hook)
218214

219-
(defcustom php-mode-pear-hook nil
220-
"Hook called when a PHP PEAR file is opened with `php-mode'."
221-
:tag "PHP Mode Pear Hook"
222-
:type 'hook)
223-
224-
(defcustom php-mode-drupal-hook nil
225-
"Hook called when a Drupal file is opened with `php-mode'."
226-
:tag "PHP Mode Drupal Hook"
227-
:type 'hook)
228-
229-
(defcustom php-mode-wordpress-hook nil
230-
"Hook called when a WordPress file is opened with `php-mode'."
231-
:tag "PHP Mode WordPress Hook"
232-
:type 'hook)
215+
;; `php-mode-pear-hook', `php-mode-drupal-hook', `php-mode-wordpress-hook'
216+
;; and `php-mode-psr2-hook' are defined in php.el (shared).
233217

234218
(defcustom php-mode-symfony2-hook nil
235219
"Hook called when a Symfony2 file is opened with `php-mode'."
236220
:tag "PHP Mode Symfony2 Hook"
237221
:type 'hook)
238222

239-
(defcustom php-mode-psr2-hook nil
240-
"Hook called when a PSR-2 file is opened with `php-mode'."
241-
:tag "PHP Mode PSR-2 Hook"
242-
:type 'hook)
243-
244223
(defcustom php-mode-force-pear nil
245224
"Normally PEAR coding rules are enforced only when the filename contains \"PEAR\".
246225
Turning this on will force PEAR rules on all PHP files."
@@ -254,24 +233,7 @@ Turning this on will force PEAR rules on all PHP files."
254233
:type '(choice (const :tag "Warn" t) (const :tag "Don't warn" nil)))
255234
(make-obsolete-variable 'php-mode-warn-if-mumamo-off 'php-mode-warn-if-html-template "2.0.0")
256235

257-
(defcustom php-mode-coding-style 'pear
258-
"Select default coding style to use with `php-mode'.
259-
This variable can take one of the following symbol values:
260-
261-
`Default' - use a reasonable default style for PHP.
262-
`PSR-2' - use PSR standards (PSR-2, PSR-12).
263-
`PEAR' - use coding styles preferred for PEAR code and modules.
264-
`Drupal' - use coding styles preferred for working with Drupal projects.
265-
`WordPress' - use coding styles preferred for working with WordPress projects.
266-
`Symfony2' - use coding styles preferred for working with Symfony2 projects."
267-
:tag "PHP Mode Coding Style"
268-
:type '(choice (const :tag "Default" php)
269-
(const :tag "PEAR" pear)
270-
(const :tag "Drupal" drupal)
271-
(const :tag "WordPress" wordpress)
272-
(const :tag "Symfony2" symfony2)
273-
(const :tag "PSR-2" psr2))
274-
:initialize #'custom-initialize-default)
236+
;; `php-mode-coding-style' is defined in php.el (shared).
275237

276238
;; Since this function has a bad influence on the environment of many users,
277239
;; temporarily disable it

0 commit comments

Comments
 (0)