|
41 | 41 | ;;; Code: |
42 | 42 | (require 'json) |
43 | 43 | (require 'php-project) |
| 44 | +(require 'ring) |
44 | 45 |
|
45 | 46 | ;; Variables |
46 | 47 | ;;;###autoload |
|
63 | 64 | (or (null v) (stringp v)))))) |
64 | 65 |
|
65 | 66 | (defvar phpactor--debug nil) |
| 67 | +(defvar phpactor-history-size 100) |
| 68 | +(defvar phpactor-history-ring nil) |
66 | 69 |
|
67 | 70 | (defvar phpactor--buffer-name "*Phpactor*") |
68 | 71 |
|
|
71 | 74 | ;; Special variables |
72 | 75 | (defvar phpactor--execute-async nil) |
73 | 76 |
|
| 77 | +;; Utility functions |
74 | 78 | (defun phpactor-find-executable () |
75 | 79 | "Return Phpactor command or path to executable." |
76 | 80 | (or phpactor-executable |
|
89 | 93 | (cons (phpactor-find-executable) |
90 | 94 | (cons sub-command args)) |
91 | 95 | " ")) |
| 96 | + |
| 97 | +(defun phpactor--add-history (name entry) |
| 98 | + "Add Phpactor history by `NAME' and `ENTRY'." |
| 99 | + (unless phpactor-history-ring |
| 100 | + (setq phpactor-history-ring (make-ring phpactor-history-size))) |
| 101 | + (ring-insert phpactor-history-ring (cons name entry))) |
| 102 | + |
92 | 103 |
|
93 | 104 | ;; Phpactor RPC |
94 | 105 | (defun phpactor--rpc (action arguments) |
95 | 106 | "Execute Phpactor `ACTION' subcommand with `ARGUMENTS'." |
| 107 | + (phpactor--add-history 'phpactor--rpc (list :action action :parameters arguments)) |
96 | 108 | (let ((json (json-encode (list :action action |
97 | 109 | :parameters arguments))) |
98 | 110 | (cmd (phpactor--make-command-string "rpc" |
|
103 | 115 | (with-current-buffer (get-buffer-create "*Phpactor Input*") |
104 | 116 | (erase-buffer) |
105 | 117 | (insert json) |
106 | | - (when phpactor--debug |
107 | | - (message "Phpactor RPC input: %s" (buffer-substring-no-properties |
108 | | - (point-min) (point-max)))) |
109 | 118 | (shell-command-on-region (point-min) (point-max) cmd output) |
110 | 119 | (with-current-buffer output |
111 | 120 | (goto-char (point-min)) |
|
249 | 258 | ;; Dispatcher: |
250 | 259 | (cl-defun phpactor-action-dispatch (&key action parameters) |
251 | 260 | "Execite action by `NAME' and `PARAMETERS'." |
252 | | - (when phpactor--debug |
253 | | - (message "Phpactor dispatch %s %s" action parameters)) |
| 261 | + (phpactor--add-history 'phpactor-action-dispatch (list :action action :parameters parameters)) |
254 | 262 | (let ((func (cdr-safe (assq (intern action) phpactor-action-table)))) |
255 | 263 | (if func |
256 | 264 | (apply func parameters) |
|
0 commit comments