branch: elpa/idris-mode
commit 7211af2fc8a6739a81de1f8e37082f914718ecbf
Merge: 281ed4ddc1 7c0cbfa11b
Author: Jan de Muijnck-Hughes <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #670 from keram/idris-repl-compl
Improve repl completion by complete only current word in multi-token input,
not whole input
---
idris-repl.el | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/idris-repl.el b/idris-repl.el
index aa5fbadd88..add8346f19 100644
--- a/idris-repl.el
+++ b/idris-repl.el
@@ -334,12 +334,28 @@ Invokes `idris-repl-mode-hook'."
(defun idris-repl-complete ()
"Completion of the current input."
(when idris-completion-via-compiler
- (let* ((input (idris-repl-current-input))
- (result (idris-eval `(:repl-completions ,input))))
- (cl-destructuring-bind (completions partial) (car result)
- (if (null completions)
- nil
- (list (+ idris-input-start (length partial)) (point-max)
completions))))))
+ (when-let* ((thing (idris-repl--thing-to-complete))
+ (result (idris-eval `(:repl-completions ,(car thing)))))
+ (pcase (car result)
+ (`(,completions ,partial)
+ (when completions
+ (list (+ (cdr thing) (length partial)) (point-max)
completions)))))))
+
+(defun idris-repl--thing-to-complete ()
+ (let ((input (idris-repl-current-input)))
+ (if (string-match-p "\\s-" input)
+ (when-let* ((bounds (idris-repl--word-bounds)))
+ (cons (buffer-substring-no-properties (car bounds) (cdr bounds))
+ (car bounds)))
+ (cons input idris-input-start))))
+
+(defun idris-repl--word-bounds ()
+ "Return (START . END) of the Idris identifier at point, or nil."
+ (save-excursion
+ (let ((end (point)))
+ (skip-chars-backward "[:alnum:]_.'")
+ (unless (= (point) end)
+ (cons (point) end)))))
(defun idris-repl-begin-of-prompt ()
"Go to the beginning of line or the prompt."