From 0b598a96760bfc09c29984fe1ca7d7ac660caa98 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 29 Nov 2023 02:37:19 +0900 Subject: [PATCH 1/2] Add php-base-mode for common parent mode for php editing modes --- CHANGELOG.md | 9 ++++++++- lisp/php.el | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ffd2693..62f59096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ 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 + +### 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). + +[#772]: https://github.com/emacs-php/php-mode/pull/772 ## [1.25.1] - 2023-11-24 diff --git a/lisp/php.el b/lisp/php.el index 3c5f3490..8fa7a6d5 100644 --- a/lisp/php.el +++ b/lisp/php.el @@ -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." From 52f82976069d002d8be10bd17b1cf476f83811d3 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 29 Nov 2023 02:38:15 +0900 Subject: [PATCH 2/2] Make php-mode inherit from php-base-mode instead of c-mode --- CHANGELOG.md | 4 ++++ lisp/php-mode.el | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f59096..649c8132 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * 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 diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 022b2a62..e19faea8 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -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) @@ -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)) @@ -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 "// ") @@ -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))