Skip to content

Commit 01ced48

Browse files
authored
Merge pull request #118 from emacs-php/feature/phpactor-executable-defcustom-take2
declare phpactor-executable as defcustom (take two)
2 parents aacb70e + 16561e8 commit 01ced48

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

README.org

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ This package is Emacs interface to [[http://phpactor.github.io/phpactor/][Phpact
4242

4343
*NOTICE*: To ensure the supported version of Phpactor is installed, you might need to run this command again after an upgrade of this package.
4444

45-
Alternatively, you can install Phpactor on your own and configure `phpactor-executable` but please be aware that any change in Phpactor's rpc protocol can introduce breakages.
46-
45+
Alternatively, you can install Phpactor on your own and customize `phpactor-executable` but please be aware that any change in Phpactor's rpc protocol can introduce breakages.
4746

4847
** Configuration
4948
*** completion

company-phpactor.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Here we create a temporary syntax table in order to add $ to symbols."
7979
(defun company-phpactor (command &optional arg &rest ignored)
8080
"`company-mode' completion backend for Phpactor."
8181
(interactive (list 'interactive))
82-
(when (phpactor-find-executable)
82+
(when phpactor-executable
8383
(save-restriction
8484
(widen)
8585
(pcase command

phpactor.el

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@
7474
:type 'boolean)
7575

7676
;; Variables
77-
;;;###autoload
78-
(progn
79-
(defvar phpactor-executable nil
80-
"Path to `phpactor' executable file.")
81-
(make-variable-buffer-local 'phpactor-executable)
82-
(put 'phpactor-executable 'safe-local-variable
83-
#'(lambda (v) (if (consp v)
84-
(and (eq 'root (car v)) (stringp (cdr v)))
85-
(or (null v) (stringp v))))))
86-
8777
(defvar phpactor--debug nil)
8878
(defvar phpactor-history-size 100)
8979
(defvar phpactor-history-ring nil)
@@ -121,16 +111,24 @@ of GitHub.")
121111

122112
;; Special variables
123113
(defvar phpactor--execute-async nil)
114+
115+
;;;###autoload
116+
(defun phpactor--find-executable ()
117+
(let ((vendor-executable (f-join phpactor-install-directory "vendor/bin/phpactor")))
118+
(if (file-exists-p vendor-executable)
119+
vendor-executable
120+
(warn "Phpactor not found. Please run phpactor-install-or-update")
121+
nil)))
122+
123+
(defcustom phpactor-executable (phpactor--find-executable)
124+
"Path to phpactor executable.
125+
It is recommemded not to customize this, but if you do, you'll
126+
have to ensure a compatible version of phpactor is used."
127+
:type '(string)
128+
:safe #'stringp
129+
:group 'phpactor)
124130

125131
;; Utility functions
126-
(defun phpactor-find-executable ()
127-
"Return Phpactor command or path to executable."
128-
(or (when phpactor-executable
129-
(php-project--eval-bootstrap-scripts phpactor-executable))
130-
(let ((vendor-executable (f-join phpactor-install-directory "vendor/bin/phpactor")))
131-
(when (file-exists-p vendor-executable)
132-
vendor-executable))
133-
(error "Phpactor not found. Please run phpactor-install-or-update")))
134132

135133
;;;###autoload
136134
(defun phpactor-install-or-update ()
@@ -154,7 +152,9 @@ of GitHub.")
154152
(php-runtime-quote-string (concat directory file))
155153
(php-runtime-quote-string (concat phpactor-install-directory file)))
156154
do (php-runtime-expr code))
155+
(add-hook 'compilation-finish-functions (lambda (buffer desc) (setq phpactor-executable (phpactor--find-executable))))
157156
(composer nil "install" "--no-dev")))
157+
158158
(defalias 'phpactor-update #'phpactor-install-or-update)
159159

160160
(defun phpactor-get-working-dir ()
@@ -172,7 +172,7 @@ of GitHub.")
172172
"Return command string by `SUB-COMMAND' and `ARGS'."
173173
(declare (indent 1))
174174
(mapconcat 'shell-quote-argument
175-
(cons (phpactor-find-executable)
175+
(cons phpactor-executable
176176
(cons sub-command args))
177177
" "))
178178

@@ -199,7 +199,6 @@ of GitHub.")
199199
(let ((json (phpactor--serialize-json (list :action action
200200
:parameters arguments)))
201201
(output (get-buffer-create "*Phpactor Output*"))
202-
(phpactor-executable (phpactor-find-executable))
203202
(coding-system-for-write 'utf-8)
204203
(cwd (phpactor-get-working-dir)))
205204
(with-current-buffer output (erase-buffer))
@@ -543,9 +542,9 @@ function."
543542
(cl-defun phpactor-action-dispatch (&key action parameters version)
544543
"Execite action by `NAME' and `PARAMETERS'."
545544
(when (and version (not (equal phpactor--supported-rpc-version version)))
546-
(if (phpactor-find-executable)
545+
(if phpactor-executable
547546
(error "Phpactor uses rpc protocol %s but this package requires %s" version phpactor--supported-rpc-version)
548-
(error "Phpactor should be upgraded. Please run phpactor-update")))
547+
(error "Phpactor should be upgraded. Please run phpactor-install-or-update")))
549548
(phpactor--add-history 'phpactor-action-dispatch (list :action action :parameters parameters :version version))
550549
(let ((func (cdr-safe (assq (intern action) phpactor-action-table))))
551550
(if func

tests/e2e/test-sanity.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
(with-timeout
5656
(timeout-duration (display-warning 'buttercup (format "Error : timeout waiting %s seconds for composer install to finish" timeout-duration)))
5757
(while (not (file-exists-p (f-join phpactor-install-directory "vendor/bin/phpactor")))
58-
(sleep-for 1)))
59-
(expect (phpactor-find-executable) :to-equal (f-join phpactor-install-directory "vendor/bin/phpactor"))
58+
(sleep-for 1))
59+
(sleep-for 1))
60+
(expect phpactor-executable :to-equal (f-join phpactor-install-directory "vendor/bin/phpactor"))
6061
)))
6162

6263
(describe "defun: `phpactor-get-working-dir'"

0 commit comments

Comments
 (0)