-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathphp-repl.el
More file actions
123 lines (100 loc) · 3.58 KB
/
php-repl.el
File metadata and controls
123 lines (100 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;;; php-repl.el --- Interact with PHP
;; Copyright © 2009 Ian Eure
;; Maintainer: Ian Eure <ieure@php.net>
;; Author: Ian Eure
;; Keywords: php repl
;; Created: 2009-03-27
;; Modified: 2009-03-27
;; X-URL: http://atomized.org
;;; License
;; This file is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this file; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Usage
;; Put this file in your Emacs lisp path (eg. site-lisp) and add to
;; your .emacs file:
;;
;; (require 'php-repl)
;;
;; You can run an inferior PHP by invoking run-php.
;;
(defconst php-repl-version-number "0.8.2"
"PHP_Repl Mode version number.")
(require 'comint)
(defgroup php-repl nil
"Major mode for interacting with an inferior PHP interpreter."
:prefix "ph-repl-"
:group 'php)
(defcustom php-repl-program
"php-repl"
"Path to the PHP interpreter"
:type '(file))
(defcustom php-repl-program-arguments
'()
"Arguments for the PHP program."
:type '(repeat string))
(defcustom php-use-eval-php-mode nil
"Whether to enable php-eval-mode for PHP buffers."
:type 'boolean
:group 'php)
(defvar inferior-php-buffer nil
"The buffer of the current inferior PHP processs")
;;;###autoload
(defun run-php (&optional arg)
"Run an inferior PHP interpreter."
(interactive "p")
(let ((buf (cond ((buffer-live-p inferior-php-buffer) inferior-php-buffer)
(t (generate-new-buffer "*inferior-php*")))))
(make-comint-in-buffer
"PHP" buf php-repl-program nil
(mapconcat 'identity php-repl-program-arguments " "))
(setq inferior-php-buffer buf)
(display-buffer buf t)
;; (pop-to-buffer buf t)
(inferior-php-mode)))
(define-derived-mode inferior-php-mode comint-mode "Inferior PHP")
(defvar inferior-php-mode-abbrev-table
(make-abbrev-table))
(derived-mode-merge-abbrev-tables php-mode-abbrev-table
inferior-php-mode-abbrev-table)
(derived-mode-set-abbrev-table 'inferior-php-mode)
(defvar eval-php-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-r" 'php-send-region)
;; (define-key map "\C-\M-x" 'php-send-defun)
(define-key map "\C-x\C-e" 'php-send-sexp)
;; (define-key map "\C-x\C-:" 'php-send-expression)
map)
"Keymap for eval-php-mode.")
(define-minor-mode eval-php-mode
"Minor mode for evaluating PHP code in an inferior process." nil "eval"
:keymap eval-php-mode-map
:group 'php-repl
:global nil)
(add-hook 'php-mode-hook
'(lambda ()
(when php-use-eval-php-mode (eval-php-mode t)))
(defun php-send-region (start end)
"Send a region to the inferior PHP process."
(interactive "r")
(if (not (buffer-live-p inferior-php-buffer))
(run-php))
(save-excursion
(comint-send-region inferior-php-buffer start end)
(if (not (string-match "\n$" (buffer-substring start end)))
(comint-send-string sql-buffer "\n"))
(display-buffer inferior-php-buffer))))
(defun php-eval-sexp ())
(defun php-eval-expression ())
(defun php-eval-buffer ())
(defun php-eval-line ())
(provide 'php-repl)