Skip to content

Commit

Permalink
Add php-ide-mode-functions instead of php-ide-mode-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Mar 18, 2023
1 parent a01bb22 commit 337d205
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lisp/php-ide.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,28 @@
;;
;; Put follows code into your .emacs (~/.emacs.d/init.el) file:
;;
;; (defun my-php-mode-setup ()
;; (defun init-php-mode-setup ()
;; (add-hook 'hack-local-variables-hook #'php-ide-mode t t))
;;
;; (defun init-php-ide-mode-setup (feature activate)
;; (pcase feature
;; (`lsp-bridge
;; (if activate
;; (progn (yas-minor-mode +1)
;; (corfu-mode -1))
;; (yas-minor-mode -1)
;; (corfu-mode +1)))))
;; (add-hook 'php-ide-mode-functions #'init-php-ide-mode)
;;
;; (with-eval-after-load 'php-ide
;; (custom-set-variables
;; '(php-ide-features . 'eglot) ;; and/or 'none, 'phpactor, 'lsp-mode
;; '(php-ide-eglot-executable "psalm-language-server") ;; or "intelephense", '("php" "vendor/bin/path/to/server")
;; ;; If you want to hide php-ide-mode from the mode line, set an empty string
;; '(php-ide-mode-lighter ""))
;;
;; (add-hook 'php-mode #'my-php-mode-setup))
;; (add-hook 'php-mode-hook #'init-php-mode-setup)
;; (add-hook 'php-ide-mode-functions #'init-php-ide-mode-setup))
;;
;; If you don't enable IDE support by default, set '(php-ide-feature 'none)
;;
Expand Down Expand Up @@ -168,7 +179,19 @@
:type 'string
:safe #'stringp)

(defvar php-ide-mode-hooks nil)
(defcustom php-ide-mode-functions nil
"Hook functions called when before activating or deactivating PHP-IDE.
Notice that two arguments (FEATURE ACTIVATE) are given.
FEATURE: A symbol, like 'lsp-mode.
ACTIVATE: T is given when activeting, NIL when deactivating PHP-IDE."
:tag "PHP-IDE Mode Functions"
:group 'php-ide
:type '(repeat function)
:safe (lambda (functions)
(and (listp functions)
(cl-loop for function in functions
always (functionp function)))))

;;;###autoload
(define-minor-mode php-ide-mode
Expand All @@ -182,11 +205,11 @@
ide-features
(mapconcat (lambda (feature) (concat "'" (symbol-name feature)))
(php-ide--avilable-features) ", ")))
(run-hooks 'php-ide-mode-hooks)
(cl-loop for feature in ide-features
for ide-plist = (cdr-safe (assq feature php-ide-feature-alist))
do (if (null ide-plist)
(message "Please set `php-ide-feature' variable in .dir-locals.el or custom variable")
(run-hook-with-args 'php-ide-mode-functions feature php-ide-mode)
(if php-ide-mode
(php-ide--activate-buffer feature ide-plist)
(php-ide--deactivate-buffer ide-plist))))))
Expand Down

0 comments on commit 337d205

Please sign in to comment.