Skip to content

Commit

Permalink
Add php-mode-debug-reinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Nov 12, 2022
1 parent bbed922 commit aceef8b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
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
43 changes: 43 additions & 0 deletions 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-vertion 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-vertion 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
12 changes: 8 additions & 4 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 @@ -1181,10 +1188,7 @@ After setting the stylevars run hooks according to STYLENAME
;; (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.")))
(php-mode-debug-reinstall))

(if php-mode-disable-c-mode-hook
(php-mode-neutralize-cc-mode-effect)
Expand Down

0 comments on commit aceef8b

Please sign in to comment.