emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/inf-ruby d39ea0bd59 212/265: Use a more common idea of pre


From: ELPA Syncer
Subject: [nongnu] elpa/inf-ruby d39ea0bd59 212/265: Use a more common idea of prefix
Date: Sat, 9 Jul 2022 21:59:27 -0400 (EDT)

branch: elpa/inf-ruby
commit d39ea0bd59e5f62eb92a051c1ab3d7a0f896ae0c
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    Use a more common idea of prefix
    
    Spanning from the last dot, not from the beginning of expression.
    
    To work better with company-minimum-prefix-length,
    https://github.com/dgutov/robe/issues/96#issuecomment-359110539.
---
 inf-ruby.el | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/inf-ruby.el b/inf-ruby.el
index 9d3d8a0d7b..920254ac0c 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -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:
@@ -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 ?_)))
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]