Skip to content

Commit

Permalink
Use a more common idea of prefix
Browse files Browse the repository at this point in the history
Spanning from the last dot, not from the beginning of expression.

To work better with company-minimum-prefix-length,
dgutov/robe#96 (comment).
  • Loading branch information
dgutov committed Jan 22, 2018
1 parent 5ae6149 commit d39ea0b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions inf-ruby.el
Expand Up @@ -566,12 +566,14 @@ Then switch to the process buffer."
(replace-regexp-in-string "\n" "\\\\n"
(replace-regexp-in-string "\\\\" "\\\\\\\\" str))))

(defun inf-ruby-completions (expr)
(defun inf-ruby-completions (prefix)
"Return a list of completions for the Ruby expression starting with EXPR."
(let* ((proc (inf-ruby-proc))
(line (buffer-substring (save-excursion (move-beginning-of-line 1)
(point))
(point)))
(expr (inf-ruby-completion-expr-at-point))
(prefix-offset (- (length expr) (length prefix)))
(comint-filt (process-filter proc))
(kept "") completions
;; Guard against running completions in parallel:
Expand Down Expand Up @@ -613,10 +615,19 @@ Then switch to the process buffer."
(when (and completions (string= (concat (car completions) "\n") completion-snippet))
(setq completions (cdr completions))))
(set-process-filter proc comint-filt)))
completions))
(mapcar
(lambda (str)
(substring str prefix-offset))
completions)))

(defconst inf-ruby-ruby-expr-break-chars " \t\n\"\'`><,;|&{(")

(defun inf-ruby-completion-bounds-of-prefix ()
"Return bounds of expression at point to complete."
(let ((inf-ruby-ruby-expr-break-chars
(concat inf-ruby-ruby-expr-break-chars ".")))
(inf-ruby-completion-bounds-of-expr-at-point)))

(defun inf-ruby-completion-bounds-of-expr-at-point ()
"Return bounds of expression at point to complete."
(when (not (memq (char-syntax (following-char)) '(?w ?_)))
Expand All @@ -634,7 +645,7 @@ Then switch to the process buffer."
(defun inf-ruby-completion-at-point ()
"Retrieve the list of completions and prompt the user.
Returns the selected completion or nil."
(let ((bounds (inf-ruby-completion-bounds-of-expr-at-point)))
(let ((bounds (inf-ruby-completion-bounds-of-prefix)))
(when bounds
(list (car bounds) (cdr bounds)
(when inf-ruby-at-top-level-prompt-p
Expand Down

0 comments on commit d39ea0b

Please sign in to comment.