Skip to content

Commit 7ff913f

Browse files
authored
Merge pull request #772 from emacs-php/feature/php-base-mode
Make php-mode inherit from php-base-mode instead of c-mode
2 parents f7beda8 + 52f8297 commit 7ff913f

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
All notable changes of the PHP Mode 1.19.1 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5-
<!-- ## Unreleased -->
5+
## Unreleased
6+
7+
### Added
8+
9+
* Add `php-base-mode` which is the base of php related modes ([#772])
10+
* `php-base-mode` is designed as a common parent mode for `php-mode` and [`php-ts-mode`](https://github.com/emacs-php/php-ts-mode).
11+
12+
### Changed
13+
14+
* Make `php-mode` inherit from `php-base-mode` instead of `c-mode` ([#772])
15+
16+
[#772]: https://github.com/emacs-php/php-mode/pull/772
617

718
## [1.25.1] - 2023-11-24
819

lisp/php-mode.el

+14-5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ as a function. Call with AS-NUMBER keyword to compare by `version<'.
327327

328328
(defvar php-mode-map
329329
(let ((map (make-sparse-keymap "PHP Mode")))
330+
(set-keymap-parent map c-mode-base-map)
330331
;; Remove menu item for c-mode
331332
(define-key map [menu-bar C] nil)
332333

@@ -1150,14 +1151,14 @@ After setting the stylevars run hook `php-mode-STYLENAME-hook'."
11501151
table))
11511152

11521153
;;;###autoload
1153-
(define-derived-mode php-mode c-mode "PHP"
1154+
(define-derived-mode php-mode php-base-mode "PHP"
11541155
"Major mode for editing PHP code.
11551156
11561157
\\{php-mode-map}"
11571158
:syntax-table php-mode-syntax-table
1158-
;; :after-hook (c-update-modeline)
1159-
;; (setq abbrev-mode t)
1160-
1159+
:after-hook (progn (c-make-noise-macro-regexps)
1160+
(c-make-macro-with-semi-re)
1161+
(c-update-modeline))
11611162
(unless (string= php-mode-cc-version c-version)
11621163
(php-mode-debug-reinstall nil))
11631164

@@ -1168,8 +1169,16 @@ After setting the stylevars run hook `php-mode-STYLENAME-hook'."
11681169
:warning))
11691170

11701171
(c-initialize-cc-mode t)
1172+
(setq abbrev-mode t)
1173+
1174+
;; Must be called once as c-mode to enable font-lock for Heredoc.
1175+
;; TODO: This call may be removed in the future.
1176+
(c-common-init 'c-mode)
1177+
11711178
(c-init-language-vars php-mode)
11721179
(c-common-init 'php-mode)
1180+
(cc-imenu-init cc-imenu-c-generic-expression)
1181+
11731182
(setq-local c-auto-align-backslashes nil)
11741183

11751184
(setq-local comment-start "// ")
@@ -1252,7 +1261,7 @@ After setting the stylevars run hook `php-mode-STYLENAME-hook'."
12521261
(advice-add 'acm-backend-tabnine-candidate-expand
12531262
:filter-args #'php-acm-backend-tabnine-candidate-expand-filter-args)
12541263

1255-
(when (>= emacs-major-version 25)
1264+
(when (eval-when-compile (>= emacs-major-version 25))
12561265
(with-silent-modifications
12571266
(save-excursion
12581267
(let* ((start (point-min))

lisp/php.el

+9
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,15 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
627627
(setq mode nil)))
628628
(or mode php-default-major-mode)))
629629

630+
;;;###autoload
631+
(define-derived-mode php-base-mode prog-mode "PHP"
632+
"Generic major mode for editing PHP.
633+
634+
This mode is intended to be inherited by concrete major modes.
635+
Currently there are `php-mode' and `php-ts-mode'."
636+
:group 'php
637+
nil)
638+
630639
;;;###autoload
631640
(defun php-mode-maybe ()
632641
"Select PHP mode or other major mode."

0 commit comments

Comments
 (0)