Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2af94d0
Rename php-mode.el to php-cc-mode.el and freeze the cc-mode implement…
zonuexe Jul 15, 2026
1826bb1
Remove CC Mode dependency from php.el and share coding-style options
zonuexe Jul 15, 2026
96dd008
Add php-style.el, a variable-based coding style system
zonuexe Jul 15, 2026
d5b394d
Fix comment-style syntax flags and PHPDoc-less chain indentation
zonuexe Jul 15, 2026
c213cce
Add cc-mode independent php-mode.el as the new mode body
zonuexe Jul 15, 2026
a955901
Add base "php" coding style shared by all styles
zonuexe Jul 15, 2026
10fd4e8
Fix font-lock, string syntax and style bugs found by the test suite
zonuexe Jul 15, 2026
c8ac8a6
Rewrite php-mode-test.el for the cc-mode independent php-mode
zonuexe Jul 15, 2026
5ccb930
Add php-cc-mode regression test suite
zonuexe Jul 15, 2026
a1fc930
Require Emacs 28.1 and run php-cc-mode tests in CI
zonuexe Jul 15, 2026
69850c4
Namespace-separate php-cc-mode from the cc-mode independent php-mode
zonuexe Jul 15, 2026
afa8188
Actually verify faces in php-mode-test-issue-136
zonuexe Jul 15, 2026
c334dd6
Update README and CHANGELOG for the cc-mode independent php-mode
zonuexe Jul 16, 2026
41bad51
Indent statement continuations and chains like CC Mode
zonuexe Jul 16, 2026
4d46113
Port open-tag fontification and fixup-whitespace from php-cc-mode
zonuexe Jul 16, 2026
c01203f
Un-defer the resolved php-mode tests and consolidate faces fixtures
zonuexe Jul 16, 2026
6751f13
Test indentation of the PHP 8.5 pipe operator and clone-with
zonuexe Jul 16, 2026
243d328
Fontify the pipe operator in the cc-mode independent php-mode
zonuexe Jul 16, 2026
292bdd9
Test indentation of attribute arguments and property hooks
zonuexe Jul 16, 2026
e4e2f9e
Indent the line after a `=>' left at the end of a line
zonuexe Jul 16, 2026
072f7bf
Add `__DIR__` path completion capf and `php-dot-context` primitive
zonuexe Jul 17, 2026
b6e7b77
docs: register completion capfs via a named function
zonuexe Jul 17, 2026
51792e6
Keep PHPDoc face when refontifying inside a doc comment
zonuexe Aug 24, 2026
5724be5
Quiet the obsolete c-basic-offset warning
zonuexe Aug 24, 2026
1018004
Simplify php-style--apply-project-or-default-style with when-let*
zonuexe Aug 24, 2026
fac1523
Fix comment misfontification after attributes with # in a string
zonuexe Aug 24, 2026
2c31f15
Sync the php-mode.el version header with the 1.28.0 release
zonuexe Aug 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ jobs:
- uses: actions/checkout@v7
- name: Run tests
run: 'make .eask test'
- name: Run php-cc-mode regression tests
run: 'make test-cc'
- name: Run tests (allow failure)
run: 'make .eask test || true'
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@ This file documents notable changes to PHP Mode according to the [Keep a Changel

## Unreleased

### Added

* **Rewrite `php-mode` as a CC Mode independent major mode**
* Indentation is handled by `php-indent.el`, a `syntax-ppss` based engine ported from `js.el` bundled with GNU Emacs
* Coding styles are handled by `php-style.el`, a variable-based style system that replaces CC Mode's `c-set-style`
* PHP language keyword tables are provided by `php-keywords.el`
* Preserve the legacy CC Mode based implementation as `php-cc-mode`
* This replaces the forward-compatibility alias introduced in 1.28.0 ([#828]) with the real renamed implementation
* `php-cc-mode` is in frozen maintenance: only regression fixes are accepted, and new development happens in the CC Mode independent `php-mode`
* For backward compatibility, `php-cc-mode` runs `php-mode-hook` in addition to its own `php-cc-mode-hook`
* Settings described in [the CC Mode manual] now apply only to `php-cc-mode`; see the commentary at the top of `lisp/php-cc-mode.el`

### Changed

* Change the default of `php-mode-coding-style` from `pear` to `per` ([PER Coding Style 2.0])

### Deprecated

* `c-basic-offset` is obsolete in `php-mode`; use `php-indent-offset` instead
* A migration layer still honors a buffer-local `c-basic-offset` (for example set via `.dir-locals.el`) by copying its value into `php-indent-offset` with a warning
* `php-mode-lineup-cascaded-calls` is obsolete; use `php-indent-chain-indent` instead
* `php-mode-enable-backup-style-variables` is obsolete; use `php-style-delete-trailing-whitespace` instead

### Removed

* Drop support for Emacs 27.x ([#811])
* **Drop support for Emacs 27; PHP Mode now requires Emacs 28.1 or later** ([#811])
* Remove the `symfony2` coding style from `php-mode`, which is superseded by `per`
* The style remains available in `php-cc-mode`
* `php-enable-symfony2-coding-style` is now an obsolete alias for `php-enable-per-coding-style`

[PER Coding Style 2.0]: https://www.php-fig.org/per/coding-style/
[the CC Mode manual]: https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html

## [1.28.0] - 2026-08-25

Expand Down
7 changes: 4 additions & 3 deletions Eask
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
(package-file "lisp/php-mode.el")
(files
"lisp/php.el"
"lisp/php-mode.el"
"lisp/php-core.el"
"lisp/php-complete.el"
"lisp/php-defs.el"
"lisp/php-cc-mode.el"
"lisp/php-indent.el"
"lisp/php-style.el"
"lisp/php-keywords.el"
"lisp/php-complete.el"
"lisp/php-defs.el"
"lisp/php-face.el"
"lisp/php-flymake.el"
"lisp/php-format.el"
Expand All @@ -24,7 +26,6 @@
"lisp/php-ide-phpactor.el"
"lisp/php-ide.el"
"lisp/php-align.el"
"lisp/php-cc-mode.el"
"lisp/php-mode-debug.el")

(script "test" "echo \"Error: no test specified\" && exit 1")
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ test: clean all
$(EASK) install polymode web-mode
$(EASK) test ert ./tests/php-mode-test.el

.PHONY: all authors autoloads clean test
# Regression tests for the frozen CC Mode based `php-cc-mode'. Run in a
# separate Eask invocation (process) from the `php-mode' tests so that
# the two major modes, which still share several public symbol names, do
# not clobber each other in a single Emacs session.
test-cc: clean all
$(EASK) test ert ./tests/php-cc-mode-test.el

.PHONY: all authors autoloads clean test test-cc
79 changes: 77 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ A powerful and flexible Emacs major mode for editing PHP scripts
> [!NOTE]
> [最新版][releases]のPHP ModeはEmacs 30をサポートしています。<br />アップグレードに伴うトラブルは[Discussions][discussions-emacs30]に気軽に書き込んでください。

> [!IMPORTANT]
> PHP Modeは書き直され、CC Modeに依存しなくなりました。インデントはGNU Emacsに同梱されている`js.el`に由来するエンジンで処理されます。従来のCC Modeベースの実装は`php-cc-mode`として引き続き利用できます。詳しくは[レガシーなCC Mode実装](#レガシーなcc-mode実装-php-cc-mode)をお読みください。

> [!WARNING]
> Emacsをアップグレードした直後に初めてPHPファイルを開いたときに、CC Mode関連のエラーが発生する可能性があります。これは以前のバージョンのEmacsでバイトコンパイルされたPHP Modeがディスクにキャッシュされているために起こるので、PHP Modeの再インストールによって解決します。
>
Expand All @@ -29,7 +32,7 @@ A powerful and flexible Emacs major mode for editing PHP scripts

## インストール

**PHP ModeはEmacs 28.1以降で動作します**。対応バージョンの詳細は[Supported Version]をお読みください。Emacs 28.1以降では単に以下のコマンドを実行するだけでインストールできます。
**PHP ModeはEmacs 28.1以降で動作します**([#811])。対応バージョンの詳細は[Supported Version]をお読みください。Emacs 28.1以降では単に以下のコマンドを実行するだけでインストールできます。

```
M-x package-install php-mode
Expand Down Expand Up @@ -75,6 +78,14 @@ M-x package-install php-mode
(php-project-coding-style . psr2)))
```

### コーディングスタイル

`php-mode`は`php-mode-coding-style`に従ってインデントや編集関連の変数を設定します。既定のスタイルは`per`([PER Coding Style 2.0][per-cs])です。以前のバージョンの既定は`pear`でした。利用できるスタイルは`per`、`psr2`、`pear`、`drupal`、`wordpress`です。

`symfony2`スタイルは削除されました。現代のSymfonyが採用するコーディングスタイルはPERに置き換えられているためです。`php-cc-mode`では引き続き利用できます。

インデントエンジンはもはやCC Modeを使わないため、`php-mode`では`c-basic-offset`はobsoleteです。かわりに`php-indent-offset`をカスタマイズしてください。後方互換のため、プロジェクトが`c-basic-offset`をバッファローカルに設定している場合(`.dir-locals.el`やファイルローカル変数など)は、`php-mode`がその値を`php-indent-offset`に引き継ぎ、警告を表示します。

### PHP-IDE: LSPクライアントおよびPhpactorとの連携

`php-ide`(`php-ide.el`)は、PHP Modeと[Eglot](https://github.com/joaotavora/eglot)・[lsp-mode](https://github.com/emacs-lsp/lsp-mode)・[lsp-bridge](https://github.com/manateelazycat/lsp-bridge)・[Phpactor](https://github.com/emacs-php/phpactor.el)のようなIDE的機能を橋渡しする**実験的**な機能です。これらの機能自体を実装するものではなく、選んだものを`php-ide-mode`という単一のマイナーモード経由で有効化・無効化するだけです。詳細な仕様は`php-ide.el`冒頭のCommentaryを参照してください。
Expand Down Expand Up @@ -126,6 +137,59 @@ M-x package-install php-mode
(add-hook 'project-find-functions #'php-project-project-find-function 90)
```

## 補完

`php-complete.el`は、言語サーバーなしでも使える依存の軽い小さな`completion-at-point`関数(capf)をいくつか提供します。いずれも`M-x`コマンドとしても、[`cape`][cape]の`cape-capf-super`で合成する部品としても使えます。

- `php-complete-complete-function` — 組み込み関数名。
- `php-complete-complete-path` — `__DIR__ . '/...'`イディオムの中でパスを補完します。1階層ずつ辿り、起点は現在のファイルのディレクトリ(実行時に`__DIR__`が解決する先)です。

名前付き関数から登録すると、あとから設定を変更しやすくなります。無名クロージャをフックに追加すると、削除や再定義が困難になります。

```elisp
(defun my-php-mode-setup-completion ()
"現在のバッファで `php-mode' の補完ソースを有効にする。"
(add-hook 'completion-at-point-functions
#'php-complete-complete-path nil t))

(with-eval-after-load 'php-mode
(add-hook 'php-mode-hook #'my-php-mode-setup-completion))
```

`cape`で複数のオフラインソースを1つの super-capf に合成するには、同じ関数の中で`cape-capf-super`を登録します。

```elisp
(defun my-php-mode-setup-completion ()
"現在のバッファで `php-mode' の補完ソースを有効にする。"
(add-hook 'completion-at-point-functions
(cape-capf-super #'php-complete-complete-function
#'php-complete-complete-path)
nil t))
```

### 文脈依存の `.` キー

`__DIR__`とパス補完を橋渡しする`. '/'`の挿入は、あえてcapfの仕事にはしていません。これは編集環境側に委ねます。そのための primitive が`php-dot-context`です。ポイントが文字列/コメント内か(`string-or-comment`)、文字列リテラルや`__DIR__`のようなマジック定数の直後か(`next-to-string`)、素のコードか(`code`)を返します。capf とこの primitive は「文字列」と「マジック定数」の定義を共有するため、キー挿入と補完の挙動が食い違いません。

たとえば[smartchr][smartchr]では、`.`キーをコード中では`->` / `.` / `. `で循環させ、文字列内ではリテラルの`.`を挿入し、`__DIR__`の直後では`. `を優先(そのまま`php-complete-complete-path`につながる)といった設定が書けます。

```elisp
(defun my-php-smartchr-dot (code within-string next-to-string)
"`php-dot-context' を使って `.' キーの smartchr を作る。"
(let ((select (lambda ()
(pcase (php-dot-context)
('string-or-comment within-string)
('next-to-string next-to-string)
(_ code)))))
(smartchr-make-struct
:cleanup-fn (lambda () (delete-char (- (length (funcall select)))))
:insert-fn (lambda () (insert (funcall select))))))

;; (smartchr (my-php-smartchr-dot "->" "." ". ")
;; (my-php-smartchr-dot ". " ".." "..")
;; "...")
```

## HTMLとPHPが混在するファイルの編集

`php-mode`は純粋なPHPスクリプトのためのメジャーモードです。テンプレートのようにHTMLの中にPHPを埋め込んだファイルは、両方の言語を理解するメジャーモードで編集するほうが適しています。特にインデントは、HTML部分を素の`php-mode`で編集すると正しく動作しません。
Expand Down Expand Up @@ -158,6 +222,12 @@ M-x package-install php-mode

すでに`php-mode`でHTMLタグを含むファイルをインデントしようとすると、PHP Modeは警告し、`php-html-template-major-mode`への切り替えを尋ねます。このプロンプトを無効にするには`php-mode-warn-if-html-template`を`nil`に設定してください。

## レガシーなCC Mode実装 (php-cc-mode)

これまでのPHP ModeはEmacs組み込みのCC Modeの上に実装されていました。この実装は`php-cc-mode`として保存されており、凍結メンテナンス状態です。リグレッション修正のみ受け付け、新規の開発はCC Mode非依存の`php-mode`で行われます。レガシー実装でファイルを開くには`M-x php-cc-mode`を実行するか、自分で`auto-mode-alist`にエントリを追加してください。

既存の設定が動き続けるように、`php-cc-mode`は自身の`php-cc-mode-hook`に加えて`php-mode-hook`も実行します。[CC Modeマニュアル][cc-mode-manual]に記載されている設定が適用されるのは`php-cc-mode`だけです。詳細は`lisp/php-cc-mode.el`冒頭のコメントをお読みください。

## 不具合を報告する

バグ報告の際には `M-x php-mode-debug` の出力を含めてください。この情報は問題の再現に役立ちます。
Expand All @@ -171,7 +241,7 @@ M-x package-install php-mode

PHP Modeは[GNU General Public License Version 3][gpl-v3] (GPLv3) でライセンスされています。

このプロジェクトは1999年に[Turadg Aleahmad][@turadg]が書いた`php-mode.el`に起源を持ちます。2013年に[Daniel Hackney][@haxney]がEmacs組み込みのCC Modeをもとに書き直し始めました。PHPモードの改善に協力した貢献者のリストは[Authors]と[Contributors]に掲載されています。
このプロジェクトは1999年に[Turadg Aleahmad][@turadg]が書いた`php-mode.el`に起源を持ちます。2013年に[Daniel Hackney][@haxney]がEmacs組み込みのCC Modeをもとに書き直し始めました。2026年にCC Modeへの依存を取り除くための書き直しが行われました。PHPモードの改善に協力した貢献者のリストは[Authors]と[Contributors]に掲載されています。

このプロジェクトは2017年まで[Eric James Michael Ritz][@ejmr]によりメンテナンスされていました。現在は[Friends of Emacs-PHP Development][@emacs-php]コミュニティが引き継いで開発しています。

Expand Down Expand Up @@ -202,7 +272,12 @@ PHP Modeは[GNU General Public License Version 3][gpl-v3] (GPLv3) でライセ
[Authors]: https://github.com/emacs-php/php-mode/wiki/Authors
[Contributors]: https://github.com/emacs-php/php-mode/graphs/contributors
[Supported Version]: https://github.com/emacs-php/php-mode/wiki/Supported-Version
[cape]: https://github.com/minad/cape
[cc-mode-manual]: https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html
[gpl-v3]: https://www.gnu.org/licenses/gpl-3.0
[per-cs]: https://www.php-fig.org/per/coding-style/
[smartchr]: https://github.com/imakado/emacs-smartchr
[#811]: https://github.com/emacs-php/php-mode/issues/811
[nongnu-elpa-badge]: https://elpa.nongnu.org/nongnu/php-mode.svg
[nongnu-elpa]: https://elpa.nongnu.org/nongnu/php-mode.html
[melpa-badge]: http://melpa.org/packages/php-mode-badge.svg
Expand Down
Loading
Loading