Skip to content

Commit b8589e0

Browse files
committed
Merge pull request #1491 from cap10morgan/v0.10
More bug fixes from master for the 0.10.1 release
2 parents ec7b3f7 + 0f0bb06 commit b8589e0

File tree

10 files changed

+135
-55
lines changed

10 files changed

+135
-55
lines changed

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Changelog
22

3-
## master (unreleased)
4-
53
## 0.10.1 / (unreleased)
64

5+
### Changes
6+
7+
* Suppress eldoc when the current sexp seems to be too large.
8+
* [#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.
9+
710
### Bugs fixed
811

912
* [#1480](https://github.com/clojure-emacs/cider/issues/1480): Fix an error in `cider-restart` caused by not using the REPL's buffer as the current connection when calling `cider-current-connection` from REPL buffer.
1013
* [#1450](https://github.com/clojure-emacs/cider/pull/1450): Fix an error in `cider-restart` caused by a reference to a killed buffer.
1114
* [#1459](https://github.com/clojure-emacs/cider/issues/1459): Add support for dynamic dispatch in scratch buffers.
1215
* [#1466](https://github.com/clojure-emacs/cider/issues/1466): Correctly font-lock pretty-printed results in the REPL.
1316
* [#1475](https://github.com/clojure-emacs/cider/pull/1475): Fix `args-out-of-range` error in `cider--get-symbol-indent`.
17+
* [#1479](https://github.com/clojure-emacs/cider/pull/1479): Make paredit and `cider-repl-mode` play nice.
18+
* [#1452](https://github.com/clojure-emacs/cider/issues/1452): Fix wrong ANSI coloring in the REPL buffer.
19+
* [#1486](https://github.com/clojure-emacs/cider/issues/1486): Complete a partial fix in stacktrace font-locking.
20+
* [#1482](https://github.com/clojure-emacs/cider/issues/1482): Clear nREPL sessions when a connection is closed.
21+
* [#1435](https://github.com/clojure-emacs/cider/issues/1435): Improve error display in cider-test.
22+
* [#1379](https://github.com/clojure-emacs/cider/issues/1379): Fix test highlighting at start of line.
23+
* [#1490](https://github.com/clojure-emacs/cider/issues/1490): Don't display the inspector buffer when evaluation fails.
1424

1525
## 0.10.0 / 2015-12-03
1626

cider-debug.el

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,7 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
536536
(setq cider--debug-mode-response response)
537537
(cider--debug-mode 1)))
538538
(when inspect
539-
(cider-inspector--value-handler nil inspect)
540-
(cider-inspector--done-handler (current-buffer))))
539+
(cider-inspector--value-handler nil inspect)))
541540
;; If something goes wrong, we send a "quit" or the session hangs.
542541
(error (cider-debug-mode-send-reply ":quit" key)
543542
(message "Error encountered while handling the debug message: %S" e)))))

cider-eldoc.el

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
(defvar cider-extra-eldoc-commands '("yas-expand")
4343
"Extra commands to be added to eldoc's safe commands list.")
4444

45+
(defvar cider-eldoc-max-num-sexps-to-skip 30
46+
"The maximum number of sexps to skip while searching the beginning of current sexp.")
47+
4548
(defvar-local cider-eldoc-last-symbol nil
4649
"The eldoc information for the last symbol we checked.")
4750

@@ -89,7 +92,8 @@ POS is the index of current argument."
8992
(defun cider-eldoc-beginning-of-sexp ()
9093
"Move to the beginning of current sexp.
9194
92-
Return the number of nested sexp the point was over or after."
95+
Return the number of nested sexp the point was over or after. Return nil
96+
if the maximum number of sexps to skip is exceeded."
9397
(let ((parse-sexp-ignore-comments t)
9498
(num-skipped-sexps 0))
9599
(condition-case _
@@ -107,14 +111,25 @@ Return the number of nested sexp the point was over or after."
107111
(let ((p (point)))
108112
(forward-sexp -1)
109113
(when (< (point) p)
110-
(setq num-skipped-sexps (1+ num-skipped-sexps))))))
114+
(setq num-skipped-sexps
115+
(unless (and cider-eldoc-max-num-sexps-to-skip
116+
(>= num-skipped-sexps
117+
cider-eldoc-max-num-sexps-to-skip))
118+
;; Without the above guard,
119+
;; `cider-eldoc-beginning-of-sexp' could traverse the
120+
;; whole buffer when the point is not within a
121+
;; list. This behavior is problematic especially with
122+
;; a buffer containing a large number of
123+
;; non-expressions like a REPL buffer.
124+
(1+ num-skipped-sexps)))))))
111125
(error))
112126
num-skipped-sexps))
113127

114128
(defun cider-eldoc-info-in-current-sexp ()
115129
"Return a list of the current sexp and the current argument index."
116130
(save-excursion
117-
(let ((argument-index (1- (cider-eldoc-beginning-of-sexp))))
131+
(when-let ((beginning-of-sexp (cider-eldoc-beginning-of-sexp))
132+
(argument-index (1- beginning-of-sexp)))
118133
;; If we are at the beginning of function name, this will be -1.
119134
(when (< argument-index 0)
120135
(setq argument-index 0))

cider-inspector.el

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,15 @@ The page size can be also changed interactively within the inspector."
9494
;; Operations
9595
(defun cider-inspector--value-handler (_buffer value)
9696
(cider-make-popup-buffer cider-inspector-buffer 'cider-inspector-mode)
97-
(cider-irender cider-inspector-buffer value))
97+
(cider-inspector-render cider-inspector-buffer value)
98+
(cider-popup-buffer-display cider-inspector-buffer t))
9899

99100
(defun cider-inspector--out-handler (_buffer value)
100101
(cider-emit-interactive-eval-output value))
101102

102103
(defun cider-inspector--err-handler (_buffer err)
103104
(cider-emit-interactive-eval-err-output err))
104105

105-
(defun cider-inspector--done-handler (buffer)
106-
(when (get-buffer cider-inspector-buffer)
107-
(with-current-buffer buffer
108-
(cider-popup-buffer-display cider-inspector-buffer t))))
109-
110106
(defun cider-inspector-response-handler (buffer)
111107
"Create an inspector response handler for BUFFER.
112108
@@ -120,7 +116,7 @@ Used for all inspector nREPL ops."
120116
#'cider-inspector--value-handler
121117
#'cider-inspector--out-handler
122118
#'cider-inspector--err-handler
123-
#'cider-inspector--done-handler))
119+
#'identity))
124120

125121
(defun cider-inspect-expr (expr ns)
126122
(cider--prep-interactive-eval expr)
@@ -176,33 +172,33 @@ Current page will be reset to zero."
176172
(cider-inspector-response-handler (current-buffer))))
177173

178174
;; Render Inspector from Structured Values
179-
(defun cider-irender (buffer str)
175+
(defun cider-inspector-render (buffer str)
180176
(with-current-buffer buffer
181177
(cider-inspector-mode)
182178
(let ((inhibit-read-only t))
183179
(condition-case nil
184-
(cider-irender* (car (read-from-string str)))
180+
(cider-inspector-render* (car (read-from-string str)))
185181
(error (insert "\nInspector error for: " str))))
186182
(goto-char (point-min))))
187183

188-
(defun cider-irender* (elements)
184+
(defun cider-inspector-render* (elements)
189185
(dolist (el elements)
190-
(cider-irender-el* el)))
186+
(cider-inspector-render-el* el)))
191187

192-
(defun cider-irender-el* (el)
188+
(defun cider-inspector-render-el* (el)
193189
(cond ((symbolp el) (insert (symbol-name el)))
194190
((stringp el) (insert (propertize el 'font-lock-face 'font-lock-keyword-face)))
195191
((and (consp el) (eq (car el) :newline))
196192
(insert "\n"))
197193
((and (consp el) (eq (car el) :value))
198-
(cider-irender-value (cadr el) (cl-caddr el)))
194+
(cider-inspector-render-value (cadr el) (cl-caddr el)))
199195
(t (message "Unrecognized inspector object: %s" el))))
200196

201-
(defun cider-irender-value (value idx)
197+
(defun cider-inspector-render-value (value idx)
202198
(cider-propertize-region
203199
(list 'cider-value-idx idx
204200
'mouse-face 'highlight)
205-
(cider-irender-el* (cider-font-lock-as-clojure value))))
201+
(cider-inspector-render-el* (cider-font-lock-as-clojure value))))
206202

207203

208204
;; ===================================================
@@ -277,7 +273,7 @@ If ARG is negative, move forwards."
277273

278274
(defun cider-inspector-operate-on-point ()
279275
"Invoke the command for the text at point.
280-
1. If point is on a value then recursivly call the inspector on
276+
1. If point is on a value then recursively call the inspector on
281277
that value.
282278
2. If point is on an action then call that action.
283279
3. If point is on a range-button fetch and insert the range."

cider-repl.el

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,22 +469,21 @@ If BOL is non-nil insert at the beginning of line."
469469
(goto-char position)
470470
;; TODO: Review the need for bol
471471
(when (and bol (not (bolp))) (insert-before-markers "\n"))
472-
(cider-propertize-region `(font-lock-face ,output-face
473-
rear-nonsticky (font-lock-face))
474-
(insert-before-markers string)
475-
(when (and (= (point) cider-repl-prompt-start-mark)
476-
(not (bolp)))
477-
(insert-before-markers "\n")
478-
(set-marker cider-repl-output-end (1- (point))))))))
472+
(insert-before-markers (ansi-color-apply (propertize string
473+
'font-lock-face output-face
474+
'rear-nonsticky '(font-lock-face))))
475+
(when (and (= (point) cider-repl-prompt-start-mark)
476+
(not (bolp)))
477+
(insert-before-markers "\n")
478+
(set-marker cider-repl-output-end (1- (point)))))))
479479
(cider-repl--show-maximum-output)))
480480

481481
(defun cider-repl--emit-interactive-output (string face)
482482
"Emit STRING as interactive output using FACE."
483483
(with-current-buffer (cider-current-repl-buffer)
484484
(let ((pos (cider-repl--end-of-line-before-input-start))
485485
(string (replace-regexp-in-string "\n\\'" "" string)))
486-
(cider-repl--emit-output-at-pos (current-buffer) string face pos t)
487-
(ansi-color-apply-on-region pos (point-max)))))
486+
(cider-repl--emit-output-at-pos (current-buffer) string face pos t))))
488487

489488
(defun cider-repl-emit-interactive-stdout (string)
490489
"Emit STRING as interactive output."
@@ -509,9 +508,7 @@ FORMAT is a format string to compile with ARGS and display on the REPL."
509508
"Using BUFFER, emit STRING font-locked with FACE.
510509
If BOL is non-nil, emit at the beginning of the line."
511510
(with-current-buffer buffer
512-
(let ((pos (cider-repl--end-of-line-before-input-start)))
513-
(cider-repl--emit-output-at-pos buffer string face cider-repl-input-start-mark bol)
514-
(ansi-color-apply-on-region pos (point-max)))))
511+
(cider-repl--emit-output-at-pos buffer string face cider-repl-input-start-mark bol)))
515512

516513
(defun cider-repl-emit-stdout (buffer string)
517514
"Using BUFFER, emit STRING as standard output."
@@ -731,12 +728,17 @@ text property `cider-old-input'."
731728

732729
(defvar cider-repl-clear-buffer-hook)
733730

731+
(defun cider-repl--clear-region (start end)
732+
"Delete the output and its overlays between START and END."
733+
(mapc 'delete-overlay (overlays-in start end))
734+
(delete-region start end))
735+
734736
(defun cider-repl-clear-buffer ()
735737
"Delete the output generated by the Clojure process."
736738
(interactive)
737739
(let ((inhibit-read-only t))
738-
(delete-region (point-min) cider-repl-prompt-start-mark)
739-
(delete-region cider-repl-output-start cider-repl-output-end)
740+
(cider-repl--clear-region (point-min) cider-repl-prompt-start-mark)
741+
(cider-repl--clear-region cider-repl-output-start cider-repl-output-end)
740742
(when (< (point) cider-repl-input-start-mark)
741743
(goto-char cider-repl-input-start-mark))
742744
(recenter t))
@@ -761,7 +763,7 @@ With a prefix argument CLEAR-REPL it will clear the entire REPL buffer instead."
761763
(end (cider-repl--end-of-line-before-input-start)))
762764
(when (< start end)
763765
(let ((inhibit-read-only t))
764-
(delete-region start end)
766+
(cider-repl--clear-region start end)
765767
(save-excursion
766768
(goto-char start)
767769
(insert
@@ -1231,7 +1233,7 @@ constructs."
12311233
(cider-repl-history-load cider-repl-history-file)
12321234
(add-hook 'kill-buffer-hook #'cider-repl-history-just-save t t)
12331235
(add-hook 'kill-emacs-hook #'cider-repl-history-just-save))
1234-
(add-hook 'paredit-mode-hook #'clojure-paredit-setup))
1236+
(add-hook 'paredit-mode-hook (lambda () (clojure-paredit-setup cider-repl-mode-map))))
12351237

12361238
(provide 'cider-repl)
12371239

cider-stacktrace.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ This associates text properties to enable filtering and source navigation."
497497
'flags flags 'follow-link t
498498
'action 'cider-stacktrace-navigate
499499
'help-echo "View source at this location"
500-
'face 'cider-stacktrace-face)
500+
'font-lock-face 'cider-stacktrace-face
501+
'type 'cider-plain-button)
501502
(save-excursion
502503
(let ((p4 (point))
503504
(p1 (search-backward " "))

cider-test.el

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@
196196
(status (when causes
197197
(cider-stacktrace-render
198198
(cider-popup-buffer cider-error-buffer
199-
cider-auto-select-error-buffer)
199+
cider-auto-select-error-buffer
200+
#'cider-stacktrace-mode)
200201
(reverse causes))))))))))
201202

202203
(defun cider-test-stacktrace ()
@@ -287,18 +288,20 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
287288
(cider-insert var 'font-lock-function-name-face t)
288289
(when context (cider-insert context 'font-lock-doc-face t))
289290
(when message (cider-insert message 'font-lock-doc-string-face t))
290-
(when expected (cider-insert "expected: " 'font-lock-comment-face nil
291-
(cider-font-lock-as-clojure expected)))
292-
(when actual (cider-insert " actual: " 'font-lock-comment-face)
293-
(if error
294-
(progn (insert-text-button
295-
error
296-
'follow-link t
297-
'action '(lambda (_button) (cider-test-stacktrace))
298-
'help-echo "View causes and stacktrace")
299-
(insert "\n"))
300-
(insert (cider-font-lock-as-clojure actual)))))
301-
(insert "\n"))))
291+
(when expected
292+
(cider-insert "expected: " 'font-lock-comment-face nil
293+
(cider-font-lock-as-clojure expected)))
294+
(when actual
295+
(cider-insert " actual: " 'font-lock-comment-face nil
296+
(cider-font-lock-as-clojure actual)))
297+
(when error
298+
(cider-insert " error: " 'font-lock-comment-face nil)
299+
(insert-text-button error
300+
'follow-link t
301+
'action '(lambda (_button) (cider-test-stacktrace))
302+
'help-echo "View causes and stacktrace")
303+
(insert "\n"))
304+
(insert "\n")))))
302305

303306
(defun cider-test-render-report (buffer ns summary results)
304307
"Emit into BUFFER the report for the NS, SUMMARY, and test RESULTS."
@@ -358,8 +361,7 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
358361
(save-excursion
359362
(goto-char (point-min))
360363
(forward-line (1- line))
361-
(forward-whitespace 1)
362-
(forward-char)
364+
(search-forward "(" nil t)
363365
(let ((beg (point)))
364366
(forward-sexp)
365367
(let ((overlay (make-overlay beg (point))))

cider-util.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ Unless you specify a BUFFER it will default to the current one."
269269
"Font-lock STRING as Clojure code."
270270
(cider-font-lock-as 'clojure-mode string))
271271

272+
;; Button allowing use of `font-lock-face', ignoring any inherited `face'
273+
(define-button-type 'cider-plain-button
274+
'face nil)
275+
272276
;;; Colors
273277

274278
(defun cider-scale-color (color scale)

nrepl-client.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ and kill the process buffer."
615615
(substring message 0 -1)))
616616
(when (equal (process-status process) 'closed)
617617
(when-let ((client-buffer (process-buffer process)))
618+
(nrepl--clear-client-sessions client-buffer)
618619
(with-current-buffer client-buffer
619620
(run-hooks 'nrepl-disconnected-hook)
620621
(when (buffer-live-p nrepl-server-buffer)
@@ -800,6 +801,12 @@ values of *1, *2, etc."
800801
(setq nrepl-ops ops)
801802
(setq nrepl-versions versions)))))
802803

804+
(defun nrepl--clear-client-sessions (conn-buffer)
805+
"Clear client nREPL sessions in CONN-BUFFER."
806+
(with-current-buffer conn-buffer
807+
(setq nrepl-session nil)
808+
(setq nrepl-tooling-session nil)))
809+
803810
(define-obsolete-function-alias 'nrepl-close 'cider--close-connection-buffer "0.10.0")
804811

805812
;;; Client: Response Handling

test/cider-tests.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,54 @@
517517
(should (equal (cider-repl-prompt-abbreviated "some.pretty.long.namespace.name")
518518
"s.p.l.n.name> ")))
519519

520+
(ert-deftest test-cider-repl--emit-output-at-pos-with-ansi-code ()
521+
(with-temp-buffer
522+
(let* ((ansi-color-names-vector ["black" "red3" "green3" "yellow3" "blue2" "magenta3" "cyan3" "gray90"])
523+
(ansi-color-map (ansi-color-make-color-map)))
524+
(cider-repl-reset-markers)
525+
526+
(cider-repl--emit-output-at-pos (current-buffer) "a" 'cider-repl-stdout-face (point))
527+
(cider-repl--emit-output-at-pos (current-buffer) "b" 'cider-repl-stdout-face (point))
528+
(cider-repl--emit-output-at-pos (current-buffer) "c" 'cider-repl-stdout-face (point))
529+
(cider-repl--emit-output-at-pos (current-buffer) "d" 'cider-repl-stdout-face (point))
530+
531+
(should (string= (buffer-string) "a\nb\nc\nd\n"))
532+
(should (equal (get-text-property 1 'font-lock-face) '(foreground-color . "black")))
533+
(should (equal (get-text-property 3 'font-lock-face) 'cider-repl-stdout-face))
534+
(should (equal (get-text-property 5 'font-lock-face) '(foreground-color . "red3")))
535+
(should (equal (get-text-property 7 'font-lock-face) '(foreground-color . "red3"))))))
536+
520537
(ert-deftest test-cider--url-to-file ()
521538
(should (equal "/space test" (cider--url-to-file "file:/space%20test")))
522539
(should (equal "C:/space test" (cider--url-to-file "file:/C:/space%20test"))))
523540

541+
(ert-deftest test-cider-eldoc-beginning-of-sexp ()
542+
(with-temp-buffer
543+
(save-excursion
544+
(insert "(a (b b) (c c) d)"))
545+
(search-forward "d")
546+
547+
(let ((cider-eldoc-max-num-sexps-to-skip nil))
548+
(save-excursion
549+
(should (eq (cider-eldoc-beginning-of-sexp) 4))
550+
(should (eq (point) 2))))
551+
552+
(let ((cider-eldoc-max-num-sexps-to-skip 4))
553+
(save-excursion
554+
(should (eq (cider-eldoc-beginning-of-sexp) 4))
555+
(should (eq (point) 2))))
556+
557+
(let ((cider-eldoc-max-num-sexps-to-skip 3))
558+
(save-excursion
559+
(should (eq (cider-eldoc-beginning-of-sexp) nil))
560+
(should (eq (point) 2))))
561+
562+
(let ((cider-eldoc-max-num-sexps-to-skip 2))
563+
(save-excursion
564+
(should (eq (cider-eldoc-beginning-of-sexp) nil))
565+
(should (eq (point) 4))))))
566+
567+
524568

525569
;;; Cygwin tests
526570

0 commit comments

Comments
 (0)