Skip to content

Commit 95fb5d1

Browse files
authored
Merge pull request #27 from vlatkoB/master
Fix for #8, #25 and #26
2 parents 3c10918 + 23b745b commit 95fb5d1

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

psci.el

+36-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,37 @@ default to the current buffer's directory."
164164
map)
165165
"Basic mode map for `psci'.")
166166

167+
(defun psci-completion-preoutput-filter (string)
168+
(setq psci-completion-captured-output (concat psci-completion-captured-output string))
169+
"")
170+
171+
(defun psci-tidy-completion-output (response)
172+
(let* ((response-lines (split-string response "\n" t nil))
173+
(response-lines-without-prompt (nbutlast response-lines)))
174+
response-lines-without-prompt))
175+
176+
177+
(defun psci-tab-completion ()
178+
(let* ((line (thing-at-point 'line t))
179+
(command (format ":complete %s" line)))
180+
(-when-let (process (get-buffer-process (psci--process-name psci/buffer-name)))
181+
(add-hook 'comint-preoutput-filter-functions 'psci-completion-preoutput-filter nil t)
182+
(comint-simple-send process command)
183+
(accept-process-output process)
184+
(remove-hook 'comint-preoutput-filter-functions 'psci-completion-preoutput-filter t)
185+
(let ((response psci-completion-captured-output))
186+
(setq psci-completion-captured-output "")
187+
(when (not (string-prefix-p "Unrecognized directive." response))
188+
(save-excursion
189+
(let* ((end (point))
190+
(start (+ (re-search-backward comint-prompt-regexp)
191+
(length psci/prompt)))
192+
(results (psci-tidy-completion-output response)))
193+
(list start end results))))))))
194+
195+
(defvar psci-dynamic-complete-functions
196+
'(psci-tab-completion))
197+
167198
;;;###autoload
168199
(define-derived-mode psci-mode comint-mode "psci"
169200
"Major mode for `run-psci'.
@@ -181,7 +212,10 @@ default to the current buffer's directory."
181212
(setq-local comint-input-filter-functions nil)
182213
(setq-local font-lock-defaults '(purescript-font-lock-keywords t))
183214
(setq-local comment-start "-- ")
184-
(setq-local comment-use-syntax t))
215+
(setq-local comment-use-syntax t)
216+
(setq-local comment-use-syntax t)
217+
(setq-local comint-dynamic-complete-functions psci-dynamic-complete-functions)
218+
(setq-local psci-completion-captured-output ""))
185219

186220
;;;###autoload
187221
(defun psci/load-current-file! ()
@@ -202,7 +236,7 @@ default to the current buffer's directory."
202236
(defun psci/reset! ()
203237
"Reset the current status of the repl session."
204238
(interactive)
205-
(psci--run-psci-command! ":reset"))
239+
(psci--run-psci-command! ":clear"))
206240

207241
;;;###autoload
208242
(defun psci/quit! ()

0 commit comments

Comments
 (0)