Skip to content

Commit

Permalink
Make completion contexts work in repls
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Sep 23, 2023
1 parent d843721 commit c030370
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 4 additions & 6 deletions cider-completion-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ the current symbol at point."
(end (cider-completion-symbol-end-pos))
(_ (beginning-of-defun-raw))
(expr-start (point))
(_ (end-of-defun))
(_ (if (derived-mode-p 'cider-repl-mode)
(end-of-buffer)
(end-of-defun)))
(expr-end (point)))
(string-remove-suffix "\n"
(concat (when pref-start (substring context 0 (- pref-start expr-start)))
Expand Down Expand Up @@ -100,11 +102,7 @@ form, with symbol at point replaced by __prefix__."
"Extract context depending (maybe of INFO type).
Output depends on `cider-completion-use-context' and the current major mode."
(let ((context (if (and cider-completion-use-context
;; Important because `beginning-of-defun' and
;; `ending-of-defun' work incorrectly in the REPL
;; buffer, so context extraction fails there.
(derived-mode-p 'clojure-mode))
(let ((context (if cider-completion-use-context
;; We use ignore-errors here since grabbing the context
;; might fail because of unbalanced parens, or other
;; technical reasons, yet we don't want to lose all
Expand Down
4 changes: 3 additions & 1 deletion cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ If BOUNDS is non-nil, return a list of its starting and ending position
instead."
(save-excursion
(save-match-data
(end-of-defun)
(if (derived-mode-p 'cider-repl-mode)
(end-of-buffer) ;; in repls, end-of-defun won't work, so we perform the closest reasonable thing
(end-of-defun))
(let ((end (point)))
(clojure-backward-logical-sexp 1)
(cider--text-or-limits bounds (point) end)))))
Expand Down

0 comments on commit c030370

Please sign in to comment.