Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress eldoc when the current sexp seems to be too large #1502

Merged
merged 1 commit into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and try to associate the created connection with this project automatically.

### Changes

* Suppress eldoc when the current sexp seems to be too large.
* [#1500](https://github.com/clojure-emacs/cider/pull/1500): Improve the performance of REPL buffers by using text properties instead of overlays for ANSI coloring.
* `cider-current-connection` considers major mode before `cider-repl-type`.
* `cider-inspect` now operates by default on the last sexp. Its behavior can be altered via prefix arguments.
Expand Down
21 changes: 18 additions & 3 deletions cider-eldoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
(defvar cider-extra-eldoc-commands '("yas-expand")
"Extra commands to be added to eldoc's safe commands list.")

(defvar cider-eldoc-max-num-sexps-to-skip 30
"The maximum number of sexps to skip while searching the beginning of current sexp.")

(defvar-local cider-eldoc-last-symbol nil
"The eldoc information for the last symbol we checked.")

Expand Down Expand Up @@ -89,7 +92,8 @@ POS is the index of current argument."
(defun cider-eldoc-beginning-of-sexp ()
"Move to the beginning of current sexp.
Return the number of nested sexp the point was over or after."
Return the number of nested sexp the point was over or after. Return nil
if the maximum number of sexps to skip is exceeded."
(let ((parse-sexp-ignore-comments t)
(num-skipped-sexps 0))
(condition-case _
Expand All @@ -107,14 +111,25 @@ Return the number of nested sexp the point was over or after."
(let ((p (point)))
(forward-sexp -1)
(when (< (point) p)
(setq num-skipped-sexps (1+ num-skipped-sexps))))))
(setq num-skipped-sexps
(unless (and cider-eldoc-max-num-sexps-to-skip
(>= num-skipped-sexps
cider-eldoc-max-num-sexps-to-skip))
;; Without the above guard,
;; `cider-eldoc-beginning-of-sexp' could traverse the
;; whole buffer when the point is not within a
;; list. This behavior is problematic especially with
;; a buffer containing a large number of
;; non-expressions like a REPL buffer.
(1+ num-skipped-sexps)))))))
(error))
num-skipped-sexps))

(defun cider-eldoc-info-in-current-sexp ()
"Return a list of the current sexp and the current argument index."
(save-excursion
(let ((argument-index (1- (cider-eldoc-beginning-of-sexp))))
(when-let ((beginning-of-sexp (cider-eldoc-beginning-of-sexp))
(argument-index (1- beginning-of-sexp)))
;; If we are at the beginning of function name, this will be -1.
(when (< argument-index 0)
(setq argument-index 0))
Expand Down
27 changes: 27 additions & 0 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,33 @@
(should (equal "/space test" (cider--url-to-file "file:/space%20test")))
(should (equal "C:/space test" (cider--url-to-file "file:/C:/space%20test"))))

(ert-deftest test-cider-eldoc-beginning-of-sexp ()
(with-temp-buffer
(save-excursion
(insert "(a (b b) (c c) d)"))
(search-forward "d")

(let ((cider-eldoc-max-num-sexps-to-skip nil))
(save-excursion
(should (eq (cider-eldoc-beginning-of-sexp) 4))
(should (eq (point) 2))))

(let ((cider-eldoc-max-num-sexps-to-skip 4))
(save-excursion
(should (eq (cider-eldoc-beginning-of-sexp) 4))
(should (eq (point) 2))))

(let ((cider-eldoc-max-num-sexps-to-skip 3))
(save-excursion
(should (eq (cider-eldoc-beginning-of-sexp) nil))
(should (eq (point) 2))))

(let ((cider-eldoc-max-num-sexps-to-skip 2))
(save-excursion
(should (eq (cider-eldoc-beginning-of-sexp) nil))
(should (eq (point) 4))))))



;;; Cygwin tests

Expand Down