Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make php-mode inherit from php-base-mode instead of c-mode #772

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

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.

<!-- ## Unreleased -->
## Unreleased

### Added

* Add `php-base-mode` which is the base of php related modes ([#772])
* `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).

### Changed

* Make `php-mode` inherit from `php-base-mode` instead of `c-mode` ([#772])

[#772]: https://github.com/emacs-php/php-mode/pull/772

## [1.25.1] - 2023-11-24

Expand Down
19 changes: 14 additions & 5 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ as a function. Call with AS-NUMBER keyword to compare by `version<'.

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

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

;;;###autoload
(define-derived-mode php-mode c-mode "PHP"
(define-derived-mode php-mode php-base-mode "PHP"
"Major mode for editing PHP code.

\\{php-mode-map}"
:syntax-table php-mode-syntax-table
;; :after-hook (c-update-modeline)
;; (setq abbrev-mode t)

:after-hook (progn (c-make-noise-macro-regexps)
(c-make-macro-with-semi-re)
(c-update-modeline))
(unless (string= php-mode-cc-version c-version)
(php-mode-debug-reinstall nil))

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

(c-initialize-cc-mode t)
(setq abbrev-mode t)

;; Must be called once as c-mode to enable font-lock for Heredoc.
;; TODO: This call may be removed in the future.
(c-common-init 'c-mode)

(c-init-language-vars php-mode)
(c-common-init 'php-mode)
(cc-imenu-init cc-imenu-c-generic-expression)

(setq-local c-auto-align-backslashes nil)

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

(when (>= emacs-major-version 25)
(when (eval-when-compile (>= emacs-major-version 25))
(with-silent-modifications
(save-excursion
(let* ((start (point-min))
Expand Down
9 changes: 9 additions & 0 deletions lisp/php.el
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,15 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
(setq mode nil)))
(or mode php-default-major-mode)))

;;;###autoload
(define-derived-mode php-base-mode prog-mode "PHP"
"Generic major mode for editing PHP.

This mode is intended to be inherited by concrete major modes.
Currently there are `php-mode' and `php-ts-mode'."
:group 'php
nil)

;;;###autoload
(defun php-mode-maybe ()
"Select PHP mode or other major mode."
Expand Down
Loading