summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/php.el
diff options
context:
space:
mode:
authorSimeon Simeonov2019-12-19 14:30:16 +0100
committerSimeon Simeonov2019-12-19 14:30:16 +0100
commit447890a7ea96da048fa720d313b32860c995e8bb (patch)
treea5dbe162bbec074c5f0b9b637279bf5e772de1b6 /.emacs.d/lisp/php.el
parentf781cd3408b85b321ad5bc78945a7f44fc3ec751 (diff)
Many changes...
Diffstat (limited to '.emacs.d/lisp/php.el')
-rw-r--r--.emacs.d/lisp/php.el60
1 files changed, 60 insertions, 0 deletions
diff --git a/.emacs.d/lisp/php.el b/.emacs.d/lisp/php.el
index 336c267..2bf117b 100644
--- a/.emacs.d/lisp/php.el
+++ b/.emacs.d/lisp/php.el
@@ -28,8 +28,10 @@
28;; This file provides common variable and functions for PHP packages. 28;; This file provides common variable and functions for PHP packages.
29 29
30;;; Code: 30;;; Code:
31(require 'cl-lib)
31(require 'flymake) 32(require 'flymake)
32(require 'php-project) 33(require 'php-project)
34(require 'rx)
33 35
34;;;###autoload 36;;;###autoload
35(defgroup php nil 37(defgroup php nil
@@ -121,6 +123,14 @@ You can replace \"en\" with your ISO language code."
121 :group 'php 123 :group 'php
122 :tag "PHP Mode Maybe Hook" 124 :tag "PHP Mode Maybe Hook"
123 :type 'hook) 125 :type 'hook)
126
127(defcustom php-default-builtin-web-server-port 3939
128 "Port number of PHP Built-in HTTP server (php -S)."
129 :group 'php
130 :tag "PHP Default Built-in Web Server Port"
131 :type 'integer
132 :link '(url-link :tag "Built-in web server"
133 "https://www.php.net/manual/features.commandline.webserver.php"))
124 134
125;;; PHP Keywords 135;;; PHP Keywords
126(defconst php-magical-constants 136(defconst php-magical-constants
@@ -299,5 +309,55 @@ Look at the `php-executable' variable instead of the constant \"php\" command."
299 (when matched 309 (when matched
300 (insert (concat matched php-namespace-suffix-when-insert))))) 310 (insert (concat matched php-namespace-suffix-when-insert)))))
301 311
312;;;###autoload
313(defun php-run-builtin-web-server (router-or-dir hostname port &optional document-root)
314 "Run PHP Built-in web server.
315
316`ROUTER-OR-DIR': Path to router PHP script or Document root.
317`HOSTNAME': Hostname or IP address of Built-in web server.
318`PORT': Port number of Built-in web server.
319`DOCUMENT-ROOT': Path to Document root.
320
321When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'."
322 (interactive
323 (let ((insert-default-directory t)
324 (d-o-r (read-file-name "Document root or Script: " default-directory)))
325 (list
326 (expand-file-name d-o-r)
327 (read-string "Hostname: " "0.0.0.0")
328 (read-number "Port: " php-default-builtin-web-server-port)
329 (if (file-directory-p d-o-r)
330 nil
331 (let ((root-input (read-file-name "Document root: " (directory-file-name d-o-r))))
332 (file-name-directory
333 (if (file-directory-p root-input)
334 root-input
335 (directory-file-name root-input))))))))
336 (let* ((default-directory
337 (or document-root
338 (if (file-directory-p router-or-dir)
339 router-or-dir
340 (directory-file-name router-or-dir))))
341 (pattern (rx-form `(: bos ,(getenv "HOME"))))
342 (short-dirname (replace-regexp-in-string pattern "~" default-directory))
343 (short-filename (replace-regexp-in-string pattern "~" router-or-dir))
344 (buf-name (format "php -S %s:%s -t %s %s"
345 hostname
346 port
347 short-dirname
348 (if document-root short-filename "")))
349 (args (cl-remove-if
350 #'null
351 (list "-S"
352 (format "%s:%d" hostname port)
353 "-t"
354 default-directory
355 (when document-root router-or-dir)))))
356 (message "Run PHP built-in server: %s" buf-name)
357 (apply #'make-comint buf-name php-executable nil args)
358 (funcall
359 (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
360 (format "*%s*" buf-name))))
361
302(provide 'php) 362(provide 'php)
303;;; php.el ends here 363;;; php.el ends here