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

Add php-mode-debug-reinstall #721

Merged
merged 2 commits into from
Nov 12, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
50 changes: 49 additions & 1 deletion lisp/php-mode-debug.el
Original file line number Diff line number Diff line change
Expand Up @@ -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*")
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down