emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/php-mode 5f3155f542 3/5: Merge pull request #721 from emac


From: ELPA Syncer
Subject: [nongnu] elpa/php-mode 5f3155f542 3/5: Merge pull request #721 from emacs-php/feature/php-mode-debug-reinstall
Date: Sat, 12 Nov 2022 10:59:07 -0500 (EST)

branch: elpa/php-mode
commit 5f3155f54284d0eabc9f2b8864d62c41ecf8fd2f
Merge: bbed922fa9 5e799dac48
Author: USAMI Kenta <tadsan@pixiv.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #721 from emacs-php/feature/php-mode-debug-reinstall
    
    Add php-mode-debug-reinstall
---
 CHANGELOG.md           |  2 ++
 lisp/php-mode-debug.el | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 lisp/php-mode.el       | 16 ++++++++++------
 3 files changed, 61 insertions(+), 7 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..b9bd829c44 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 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]