Skip to content

Commit 1e63608

Browse files
Dan Suttonbbatsov
authored andcommitted
Add "Project-Only" filter for stackframes
hooks up a shortcut, corrects the underlining for other filters
1 parent 16e2a72 commit 1e63608

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* Filter stacktrace to just frames from your project.
78
* [#1918](https://github.com/clojure-emacs/cider/issues/1918): Add new commands `cider-browse-spec` and `cider-browse-spec-all` which start a spec browser.
89
* [#2015](https://github.com/clojure-emacs/cider/pull/2015): Show symbols as special forms *and* macros in `cider-doc`
910
* [#2012](https://github.com/clojure-emacs/cider/pull/2012): Support special forms in `cider-apropos` and `cider-grimoire-lookup`.

cider-stacktrace.el

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ The error types are represented as strings."
129129
:group 'cider-stacktrace
130130
:package-version '(cider . "0.6.0"))
131131

132+
(defface cider-stacktrace-filter-positive-face
133+
'((t (:inherit button :underline t :weight normal)))
134+
"Face for filter buttons representing frames currently filtered out"
135+
:group 'cider-stacktrace
136+
:package-version '(cider . "0.15.0"))
137+
132138
(defface cider-stacktrace-face
133139
'((t (:inherit default)))
134140
"Face for stack frame text"
@@ -194,6 +200,7 @@ The error types are represented as strings."
194200
(define-key map "r" #'cider-stacktrace-toggle-repl)
195201
(define-key map "t" #'cider-stacktrace-toggle-tooling)
196202
(define-key map "d" #'cider-stacktrace-toggle-duplicates)
203+
(define-key map "p" #'cider-stacktrace-show-only-project)
197204
(define-key map "a" #'cider-stacktrace-toggle-all)
198205
(define-key map "1" #'cider-stacktrace-cycle-cause-1)
199206
(define-key map "2" #'cider-stacktrace-cycle-cause-2)
@@ -224,6 +231,7 @@ The error types are represented as strings."
224231
["Show/hide REPL frames" cider-stacktrace-toggle-repl]
225232
["Show/hide tooling frames" cider-stacktrace-toggle-tooling]
226233
["Show/hide duplicate frames" cider-stacktrace-toggle-duplicates]
234+
["Show only project frames" cider-stacktrace-show-only-project]
227235
["Show/hide all frames" cider-stacktrace-toggle-all]))
228236
map))
229237

@@ -242,29 +250,34 @@ The error types are represented as strings."
242250

243251
;; Stacktrace filtering
244252

245-
(defun cider-stacktrace-indicate-filters (filters)
253+
(defun cider-stacktrace--face-for-filter (filter neg-filters pos-filters)
254+
"Return whether we should mark the filter is active or not."
255+
(cond ((member filter neg-filters) 'cider-stacktrace-filter-hidden-face)
256+
((member filter pos-filters) 'cider-stacktrace-filter-positive-face)
257+
((member filter '(project)) 'cider-stacktrace-filter-hidden-face)
258+
((null filter) 'cider-stacktrace-filter-hidden-face)
259+
(t 'cider-stacktrace-filter-shown-face)))
260+
261+
(defun cider-stacktrace-indicate-filters (filters pos-filters)
246262
"Update enabled state of filter buttons.
247263
248264
Find buttons with a 'filter property; if filter is a member of FILTERS, or
249265
if filter is nil ('show all') and the argument list is non-nil, fontify the
250266
button as disabled. Upon finding text with a 'hidden-count property, stop
251-
searching and update the hidden count text."
267+
searching and update the hidden count text. POS-FILTERS is the list of
268+
positive filters to always include."
252269
(with-current-buffer cider-error-buffer
253270
(save-excursion
254271
(goto-char (point-min))
255-
(let ((inhibit-read-only t)
256-
(get-face (lambda (hide)
257-
(if hide
258-
'cider-stacktrace-filter-hidden-face
259-
'cider-stacktrace-filter-shown-face))))
272+
(let ((inhibit-read-only t))
260273
;; Toggle buttons
261274
(while (not (or (get-text-property (point) 'hidden-count) (eobp)))
262275
(let ((button (button-at (point))))
263276
(when button
264277
(let* ((filter (button-get button 'filter))
265-
(face (funcall get-face (if filter
266-
(member filter filters)
267-
filters))))
278+
(face (cider-stacktrace--face-for-filter filter
279+
filters
280+
pos-filters)))
268281
(button-put button 'face face)))
269282
(goto-char (or (next-property-change (point))
270283
(point-max)))))
@@ -465,6 +478,21 @@ When it reaches 3, it wraps to 0."
465478
(cons flag cider-stacktrace-filters)))
466479
cider-stacktrace-positive-filters))
467480

481+
(defun cider-stacktrace-show-only-project (&optional button)
482+
"Display only the stackframes from the project.
483+
BUTTON is the button at the top of the error buffer as the button calls
484+
with the button."
485+
(interactive)
486+
(if (null cider-stacktrace-positive-filters)
487+
(progn
488+
(setq-local cider-stacktrace-prior-filters cider-stacktrace-filters)
489+
(setq-local cider-stacktrace-filters '(java clj repl tooling dup))
490+
(setq-local cider-stacktrace-positive-filters '(project)))
491+
(progn
492+
(setq-local cider-stacktrace-filters cider-stacktrace-prior-filters)
493+
(setq-local cider-stacktrace-positive-filters nil)))
494+
(cider-stacktrace-apply-filters cider-stacktrace-filters
495+
cider-stacktrace-positive-filters))
468496

469497
(defun cider-stacktrace-toggle-java ()
470498
"Toggle display of Java stack frames."
@@ -570,6 +598,13 @@ prompt and whether to use a new window. Similar to `cider-find-var'."
570598
"Emit into BUFFER toggle buttons for each of the FILTERS."
571599
(with-current-buffer buffer
572600
(insert " Show: ")
601+
(insert-text-button "Project-Only"
602+
'filter 'project
603+
'follow-link t
604+
'action 'cider-stacktrace-show-only-project
605+
'help-echo "Project frames only")
606+
(insert " ") ;; if you put the space after project-only the button
607+
;; highlighting spills into the next button
573608
(dolist (filter filters)
574609
(insert-text-button (car filter)
575610
'filter (cadr filter)
@@ -578,6 +613,7 @@ prompt and whether to use a new window. Similar to `cider-find-var'."
578613
'help-echo (format "Toggle %s stack frames"
579614
(car filter)))
580615
(insert " "))
616+
581617
(let ((hidden "(0 frames hidden)"))
582618
(put-text-property 0 (length hidden) 'hidden-count t hidden)
583619
(insert " " hidden "\n"))))
@@ -748,7 +784,6 @@ through the `cider-stacktrace-suppressed-errors' variable."
748784
(cider-stacktrace-initialize causes)
749785
(font-lock-refresh-defaults)))
750786

751-
752787
(provide 'cider-stacktrace)
753788

754789
;;; cider-stacktrace.el ends here

doc/navigating_stacktraces.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Command | Keyboard shortcut | D
2121
`cider-stacktrace-toggle-repl` |<kbd>r</kbd> | Toggle display of REPL frames
2222
`cider-stacktrace-toggle-tooling` |<kbd>t</kbd> | Toggle display of tooling frames (e.g. compiler, nREPL middleware)
2323
`cider-stacktrace-toggle-duplicates` |<kbd>d</kbd> | Toggle display of duplicate frames
24+
`cider-stacktrace-show-only-project |<kbd>p</kbd> | Toggle display only project frames
2425
`cider-stacktrace-toggle-all` |<kbd>a</kbd> | Toggle display of all frames
2526

2627
You can configure whether the error buffer with stacktraces should be automatically

0 commit comments

Comments
 (0)