Skip to content

Commit e952f37

Browse files
authored
Merge pull request #45 from mbarbin/summary-box-in-buffer
Summary box in buffer
2 parents 3d7262d + b1d2fe6 commit e952f37

File tree

4 files changed

+84
-15
lines changed

4 files changed

+84
-15
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
## 0.0.2025XXXX (unreleased)
22

3+
### Added
4+
5+
- Add 's' for summary tables in emacs crs-grep-mode (#45, @mbarbin).
6+
37
### Changed
48

5-
- Add buffer line header in emacs crs-grep-mode by default (@mbarbin).
9+
- Add buffer line header in emacs crs-grep-mode by default (#44, @mbarbin).
610

711
### Fixed
812

editor-integration/emacs/crs-grep.el

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Set this to an absolute path if the executable is not in your `PATH`."
4747

4848
(defcustom crs-grep-default-filter "now"
4949
"Default filter for `crs-grep` when opening the CRs buffer.
50-
Should be one of: all, crs, xcrs, now, soon, someday, invalid."
50+
Should be one of: all, crs, xcrs, now, soon, someday, invalid, summary."
5151
:type
5252
'(choice
5353
(const "all")
@@ -56,7 +56,8 @@ Should be one of: all, crs, xcrs, now, soon, someday, invalid."
5656
(const "now")
5757
(const "soon")
5858
(const "someday")
59-
(const "invalid"))
59+
(const "invalid")
60+
(const "summary"))
6061
:group 'crs-grep)
6162

6263
(defcustom crs-grep-enable-next-error-follow nil
@@ -158,6 +159,8 @@ Always a string, e.g. \"now\", \"all\", etc.")
158159
"emacs-grep"
159160
"--path-display-mode=absolute"
160161
(concat "--" crs-grep-current-filter))))
162+
(when (fboundp 'ansi-color-apply-on-region)
163+
(ansi-color-apply-on-region (point-min) (point-max)))
161164
(if (eq exit-code 0)
162165
(progn
163166
(crs-grep-mode)
@@ -208,12 +211,13 @@ If `crs-grep-repo-root` is nil, shows an error message."
208211
(defun crs-grep-set-filter (filter-name)
209212
"Set the CRs type filter to FILTER-NAME (string) and refresh the CRs buffer.
210213
Prompts if called interactively."
211-
(interactive (list
212-
(completing-read
213-
"Filter (all, crs, xcrs, now, soon, someday, invalid): "
214-
'("all" "crs" "xcrs" "now" "soon" "someday" "invalid")
215-
nil
216-
t)))
214+
(interactive
215+
(list
216+
(completing-read
217+
"Filter (all, crs, xcrs, now, soon, someday, invalid, summary): "
218+
'("all" "crs" "xcrs" "now" "soon" "someday" "invalid" "summary")
219+
nil
220+
t)))
217221
(setq crs-grep-current-filter filter-name)
218222
(crs-grep-refresh))
219223

@@ -266,6 +270,13 @@ Further refreshing the buffer will continue to show invalid CRs only."
266270
(interactive)
267271
(crs-grep-set-filter "invalid"))
268272

273+
(defun crs-grep-set-filter-summary ()
274+
"Set the CRs type filter to \"summary\" and refresh the CRs buffer.
275+
This will show only the summary box.
276+
Further refreshing the buffer will continue to show the summary only."
277+
(interactive)
278+
(crs-grep-set-filter "summary"))
279+
269280
;;; Mode
270281

271282
(defvar crs-grep-mode-map
@@ -280,6 +291,7 @@ Further refreshing the buffer will continue to show invalid CRs only."
280291
(define-key map "d" 'crs-grep-set-filter-someday)
281292
(define-key map "i" 'crs-grep-set-filter-invalid)
282293
(define-key map "a" 'crs-grep-set-filter-all)
294+
(define-key map "s" 'crs-grep-set-filter-summary)
283295
map)
284296
"Keymap for `crs-grep-mode`.
285297
@@ -293,6 +305,7 @@ Keys:
293305
o Show only CRs to be worked on \"soon\" (set filter)
294306
d Show only CRs to be worked on \"someday\" (set filter)
295307
i Show only invalid CRs (set filter)
308+
s Show only the summary box (set filter)
296309
q Quit")
297310

298311
;;;###autoload
@@ -310,6 +323,7 @@ Keys:
310323
o Show only CRs to be worked on \"soon\" (set filter)
311324
d Show only CRs to be worked on \"someday\" (set filter)
312325
i Show only invalid CRs (set filter)
326+
s Show only the summary box (set filter)
313327
q Quit"
314328
:keymap crs-grep-mode-map)
315329

lib/crs_cli/src/cmd__tools__emacs_grep.ml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ By default the file paths are displayed relative to the command's $(b,cwd).
9595
~docv:"MODE"
9696
~doc:"Specify how the paths are displayed."
9797
~default:Relative_to_cwd
98+
and+ summary =
99+
Arg.flag
100+
[ "summary" ]
101+
~doc:"Print CR counts in summary tables instead of listing each CR."
98102
and+ filters = Common_helpers.filters in
99103
let cwd = Unix.getcwd () |> Absolute_path.v in
100104
let { Enclosing_repo.vcs_kind = _; repo_root; vcs } =
@@ -111,10 +115,21 @@ By default the file paths are displayed relative to the command's $(b,cwd).
111115
List.filter all_crs ~f:(fun cr ->
112116
List.exists filters ~f:(fun filter -> Cr_comment.Filter.matches filter ~cr))
113117
in
114-
output_list
115-
crs
116-
~oc:Out_channel.stdout
117-
~repo_root
118-
~below:(Vcs.Path_in_repo.to_relative_path below)
119-
~path_display_mode)
118+
if summary
119+
then (
120+
let by_type = Summary_table.By_type.make crs |> Summary_table.By_type.to_box in
121+
let summary = Summary_table.make crs |> Summary_table.to_box in
122+
let tables =
123+
List.filter_opt [ by_type; summary ]
124+
|> List.map ~f:Summary_table.Box.to_string
125+
|> String.concat ~sep:"\n"
126+
in
127+
Out_channel.output_string Stdio.stdout tables)
128+
else
129+
output_list
130+
crs
131+
~oc:Out_channel.stdout
132+
~repo_root
133+
~below:(Vcs.Path_in_repo.to_relative_path below)
134+
~path_display_mode)
120135
;;

test/cram/emacs-grep.t

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,39 @@ It is however also possible to display the path using some other styles.
117117

118118
We do not exercise here the display of absolute path because it would make this
119119
test unstable, however this rendering option is available.
120+
121+
The emacs grep command supports showing summary tables.
122+
123+
$ crs tools emacs-grep --summary
124+
┌─────────┬───────┐
125+
│ CR Type │ Count │
126+
├─────────┼───────┤
127+
│ CR │ 2
128+
│ XCR │ 1
129+
│ Soon │ 1
130+
│ Someday │ 1
131+
└─────────┴───────┘
132+
133+
┌──────────┬───────┬─────┬──────┬──────┬─────────┬───────┐
134+
│ Reporter │ For │ CRs │ XCRs │ Soon │ Someday │ Total │
135+
├──────────┼───────┼─────┼──────┼──────┼─────────┼───────┤
136+
│ user1 │ │ │ 1113
137+
│ user1 │ user2 │ 1 │ │ │ │ 1
138+
│ user1 │ user3 │ 1 │ │ │ │ 1
139+
└──────────┴───────┴─────┴──────┴──────┴─────────┴───────┘
140+
141+
This option may be combined with other filters when calling from the command
142+
line, however when used through emacs, the filter applied is always "all".
143+
144+
$ crs tools emacs-grep --summary --xcrs
145+
┌─────────┬───────┐
146+
│ CR Type │ Count │
147+
├─────────┼───────┤
148+
│ XCR │ 1
149+
└─────────┴───────┘
150+
151+
┌──────────┬──────┬───────┐
152+
│ Reporter │ XCRs │ Total │
153+
├──────────┼──────┼───────┤
154+
│ user1 │ 11
155+
└──────────┴──────┴───────┘

0 commit comments

Comments
 (0)