diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b483f60..c5df026c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this * Psalm: [Supported Annotations](https://psalm.dev/docs/annotating_code/supported_annotations/) * Psalm: [Template Annotations](https://psalm.dev/docs/annotating_code/templated_annotations/) * Add `php-mode-replace-flymake-diag-function` custom variable and default activated it ([#718]) + * Add `php-mode-debug-reinstall` command to help users who update Emacs themselves ([#721]) ### Changed @@ -55,6 +56,7 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this [#717]: https://github.com/emacs-php/php-mode/pull/717 [#718]: https://github.com/emacs-php/php-mode/pull/718 [#719]: https://github.com/emacs-php/php-mode/pull/719 +[#721]: https://github.com/emacs-php/php-mode/pull/721 ## [1.24.1] - 2022-10-08 diff --git a/lisp/php-mode-debug.el b/lisp/php-mode-debug.el index d32485a1..b9bd829c 100644 --- a/lisp/php-mode-debug.el +++ b/lisp/php-mode-debug.el @@ -31,9 +31,52 @@ (require 'php-mode) (require 'package) (require 'pkg-info nil t) +(require 'el-get nil t) (declare-function pkg-info-version-info "pkg-info" (library &optional package show)) +(defun php-mode-debug-reinstall (force &optional called-interactive) + "Reinstall PHP Mode to solve Cc Mode version mismatch. + +When FORCE, try to reinstall without interactively asking. +When CALLED-INTERACTIVE then message the result." + (interactive (list (yes-or-no-p (if (string= php-mode-cc-version c-version) + "No need to recompile, but force PHP Mode to reinstall? " + "Force reinstall PHP Mode? ")) + t)) + (let* ((cc-version-mismatched (string= php-mode-cc-version c-version)) + (preface (if cc-version-mismatched + "" + "CC Mode has been updated. "))) + (if (catch 'success + (cond + ((and (not called-interactive) + (not force) + cc-version-mismatched) + nil) + ((and (package-installed-p 'php-mode) + (or force + (yes-or-no-p (format "%sReinstall `php-mode' package? " preface)))) + (package-reinstall 'php-mode) + (throw 'success t)) + ;; This clause is not included in the byte-compiled code when compiled without El-Get + ((and (eval-when-compile (and (fboundp 'el-get-package-is-installed) + (fboundp 'el-get-reinstall))) + (el-get-package-is-installed 'php-mode) + (or force + (yes-or-no-p (format "%sReinstall `php-mode' package by El-Get? " preface)))) + (el-get-reinstall 'php-mode) + (throw 'success t)) + ((not called-interactive) + (user-error + (if cc-version-mismatched + "PHP Mode cannot be reinstalled automatically. Please try manually if necessary" + "Please reinstall or byte recompile PHP Mode files manually"))))) + (user-error "PHP Mode reinstalled successfully. Please restart Emacs") + (prog1 t + (when called-interactive + (message "PHP Mode was not reinstalled")))))) + (defun php-mode-debug--buffer (&optional command &rest args) "Return buffer for php-mode-debug, and execute `COMMAND' with `ARGS'." (with-current-buffer (get-buffer-create "*PHP Mode DEBUG*") @@ -62,7 +105,12 @@ (php-mode-debug--message "Pasting the following information on the issue will help us to investigate the cause.") (php-mode-debug--message "```") (php-mode-debug--message "--- PHP-MODE DEBUG BEGIN ---") - (php-mode-debug--message "versions: %s; %s; Cc Mode %s)" (emacs-version) (php-mode-version) c-version) + (php-mode-debug--message "versions: %s; %s; Cc Mode %s)" + (emacs-version) + (php-mode-version) + (if (string= php-mode-cc-version c-version) + c-version + (format "%s (php-mode-cc-version: %s *mismatched*)" c-version php-mode-cc-version))) (php-mode-debug--message "package-version: %s" (if (fboundp 'pkg-info) (pkg-info-version-info 'php-mode) diff --git a/lisp/php-mode.el b/lisp/php-mode.el index 98654a09..19c066ec 100644 --- a/lisp/php-mode.el +++ b/lisp/php-mode.el @@ -115,6 +115,13 @@ The format is follows: (autoload 'php-mode-debug "php-mode-debug" "Display informations useful for debugging PHP Mode." t) + +(autoload 'php-mode-debug-reinstall "php-mode-debug" + "Reinstall PHP Mode to solve Cc Mode version mismatch. + +When FORCE, try to reinstall without interactively asking. +When CALLED-INTERACTIVE then message the result." t) + ;; Local variables @@ -316,7 +323,7 @@ In that case set to `NIL'." :tag "PHP Mode Enable Project Local Variable" :type 'boolean) -(defconst php-mode-cc-vertion +(defconst php-mode-cc-version (eval-when-compile c-version)) (cl-defun php-mode-version (&key as-number) @@ -1180,11 +1187,8 @@ After setting the stylevars run hooks according to STYLENAME ;; :after-hook (c-update-modeline) ;; (setq abbrev-mode t) - (unless (string= php-mode-cc-vertion c-version) - (user-error "CC Mode has been updated. %s" - (if (package-installed-p 'php-mode) - "Please run `M-x package-reinstall php-mode' command." - "Please byte recompile PHP Mode files."))) + (unless (string= php-mode-cc-version c-version) + (php-mode-debug-reinstall)) (if php-mode-disable-c-mode-hook (php-mode-neutralize-cc-mode-effect)