branch: elpa/inf-ruby
commit 441cda957c08fb3f836877dd3ce3f1fda3418a3d
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>
Support completion in Pry 1.0.0.pre1
* Closes #45
* Explicitly drop completion support in rdebug, if it was even still
working. The complexity isn't worth it.
---
inf-ruby.el | 60 +++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/inf-ruby.el b/inf-ruby.el
index bc478bee9f..dfe2fb0289 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -441,29 +441,43 @@ Then switch to the process buffer."
(kept "") completions
;; Guard against running completions in parallel:
inf-ruby-at-top-level-prompt-p)
- (set-process-filter proc (lambda (proc string) (setq kept (concat kept
string))))
- (unwind-protect
- (let ((completion-snippet
- (format (concat "proc { |expr, line| "
- "if defined?(Pry.config) then "
- "completor = Pry.config.completer"
- ".build_completion_proc(binding, defined?(_pry_) ?
_pry_ : Pry.new)"
- " elsif defined?(Bond.agent) && Bond.started? then "
- "completor = Bond.agent"
- " end ? (puts completor.call(expr, line).compact) :
"
- "if defined?(IRB::InputCompletor::CompletionProc)
then "
- "puts
IRB::InputCompletor::CompletionProc.call(expr).compact "
- "end }.call('%s', '%s')\n")
- (ruby-escape-single-quoted expr)
- (ruby-escape-single-quoted line))))
- (process-send-string proc completion-snippet)
- (while (and (not (string-match inf-ruby-prompt-pattern kept))
- (accept-process-output proc 2)))
- (setq completions (butlast (split-string kept "\r?\n") 2))
- ;; Subprocess echoes output on Windows and OS X.
- (when (and completions (string= (concat (car completions) "\n")
completion-snippet))
- (setq completions (cdr completions))))
- (set-process-filter proc comint-filt))
+ (unless (equal "(rdb:1) " (buffer-substring (car comint-last-prompt)
+ (cdr comint-last-prompt)))
+ (set-process-filter proc (lambda (proc string) (setq kept (concat kept
string))))
+ (unwind-protect
+ (let ((completion-snippet
+ (format
+ (concat
+ "proc { |expr, line, old_wp|"
+ " require 'ostruct';"
+ " begin"
+ " Bond.agent.instance_variable_set('@weapon',"
+ " OpenStruct.new(line_buffer: line)) if old_wp;"
+ " if defined?(_pry_.complete) then"
+ " puts _pry_.complete(expr)"
+ " else"
+ " completer = if defined?(_pry_) then"
+ "
Pry.config.completer.build_completion_proc(binding, _pry_)"
+ " elsif old_wp then"
+ " Bond.agent"
+ " elsif defined?(IRB::InputCompletor::CompletionProc)
then"
+ " IRB::InputCompletor::CompletionProc"
+ " end and puts completer.call(expr).compact"
+ " end"
+ " ensure"
+ " Bond.agent.instance_variable_set('@weapon', old_wp) if
old_wp "
+ " end "
+ "}.call('%s', '%s', defined?(Bond) && Bond.started? &&
Bond.agent.weapon)\n")
+ (ruby-escape-single-quoted expr)
+ (ruby-escape-single-quoted line))))
+ (process-send-string proc completion-snippet)
+ (while (and (not (string-match inf-ruby-prompt-pattern kept))
+ (accept-process-output proc 2)))
+ (setq completions (butlast (split-string kept "\r?\n") 2))
+ ;; Subprocess echoes output on Windows and OS X.
+ (when (and completions (string= (concat (car completions) "\n")
completion-snippet))
+ (setq completions (cdr completions))))
+ (set-process-filter proc comint-filt)))
completions))
(defconst inf-ruby-ruby-expr-break-chars " \t\n\"\'`><,;|&{(")