[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/php-mode 851225b853 1/5: Add php-mode-debug-reinstall
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/php-mode 851225b853 1/5: Add php-mode-debug-reinstall |
Date: |
Sat, 12 Nov 2022 10:59:06 -0500 (EST) |
branch: elpa/php-mode
commit 851225b85329af5800d5e858c3388d8688b3badc
Author: USAMI Kenta <tadsan@zonu.me>
Commit: USAMI Kenta <tadsan@zonu.me>
Add php-mode-debug-reinstall
---
CHANGELOG.md | 2 ++
lisp/php-mode-debug.el | 43 +++++++++++++++++++++++++++++++++++++++++++
lisp/php-mode.el | 16 ++++++++++------
3 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b483f6000..c5df026c24 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 d32485a1e6..57af5d4832 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*")
diff --git a/lisp/php-mode.el b/lisp/php-mode.el
index 98654a092e..19c066ec37 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)