8
8
9
9
; ; SPDX-License-Identifier: GPL-3.0-or-later
10
10
11
+ (require 'compat ) ; for text-property-search-{forward backward}
11
12
(require 'easymenu )
12
13
(require 'rx )
13
14
(require 'racket-custom )
31
32
" ---"
32
33
[" Clear" racket-logger-clear]))
33
34
34
- (defconst racket-logger-font-lock-keywords
35
- (eval-when-compile
36
- `((,#'racket--font-lock-config . racket-logger-config-face)
37
- (,(rx bol " [ fatal]" ) . racket-logger-fatal-face)
38
- (,(rx bol " [ error]" ) . racket-logger-error-face)
39
- (,(rx bol " [warning]" ) . racket-logger-warning-face)
40
- (,(rx bol " [ info]" ) . racket-logger-info-face)
41
- (,(rx bol " [ debug]" ) . racket-logger-debug-face)
42
- (,(rx bol ?\[ (+? anything) ?\] space
43
- (group (+? anything) ?: ) space)
44
- 1 racket-logger-topic-face))))
45
-
46
- (defconst racket--logger-print-config-prefix
47
- " racket-logger-config:\n " )
48
-
49
- (defun racket--font-lock-config (limit )
50
- " Handle multi-line font-lock of the configuration info."
51
- (ignore-errors
52
- (when (re-search-forward (concat " ^" racket--logger-print-config-prefix) limit t )
53
- (let ((md (match-data )))
54
- (goto-char (match-end 0 ))
55
- (forward-sexp 1 )
56
- (setf (elt md 1 ) (point )) ; ; set (match-end 0)
57
- (set-match-data md)
58
- t ))))
59
-
60
35
(define-derived-mode racket-logger-mode special-mode " Racket-Logger"
61
36
" Major mode for Racket logger output.
62
37
\\ <racket-logger-mode-map>
@@ -70,9 +45,7 @@ For more information see:
70
45
71
46
\\ {racket-logger-mode-map}
72
47
"
73
- (setq-local font-lock-defaults
74
- (list racket-logger-font-lock-keywords
75
- t )) ; keywords-only #751
48
+ (setq-local font-lock-defaults (list nil t )) ; no font lock
76
49
(setq-local truncate-lines t )
77
50
(setq-local buffer-undo-list t ) ; disable undo
78
51
(setq-local window-point-insertion-type t ))
@@ -90,21 +63,37 @@ For more information see:
90
63
(racket--logger-activate-config)))
91
64
(get-buffer name)))
92
65
93
- (defun racket--logger-on-notify (back-end-name str )
66
+ (defun racket--logger-on-notify (back-end-name v )
94
67
" This is called from `racket--cmd-dispatch-response' .
95
68
96
69
As a result, we might create this buffer before the user does a
97
70
`racket-logger-mode' command."
98
71
(when noninteractive ; emacs --batch
99
72
(princ (format " {logger %s }: %s "
100
73
(racket-back-end-name)
101
- str )))
74
+ v )))
102
75
(with-current-buffer (racket--logger-get-buffer-create back-end-name)
103
- (let* ((inhibit-read-only t )
104
- (original-point (point ))
105
- (point-was-at-end-p (equal original-point (point-max ))))
76
+ (pcase-let* ((`(, level , topic , message ) v)
77
+ (`(, level-str . , level-face )
78
+ (pcase level
79
+ ('fatal (cons " [ fatal]" racket-logger-fatal-face))
80
+ ('error (cons " [ error]" racket-logger-error-face))
81
+ ('warning (cons " [warning]" racket-logger-warning-face))
82
+ ('info (cons " [ info]" racket-logger-info-face))
83
+ ('debug (cons " [ debug]" racket-logger-debug-face))))
84
+ (inhibit-read-only t )
85
+ (original-point (point ))
86
+ (point-was-at-end-p (equal original-point (point-max ))))
106
87
(goto-char (point-max ))
107
- (insert str)
88
+ (insert (propertize level-str
89
+ 'face level-face
90
+ 'racket-logger-item-level t )
91
+ " "
92
+ (propertize (symbol-name topic)
93
+ 'face racket-logger-topic-face)
94
+ " : "
95
+ message
96
+ " \n " )
108
97
(unless point-was-at-end-p
109
98
(goto-char original-point)))))
110
99
@@ -115,9 +104,9 @@ As a result, we might create this buffer before the user does a
115
104
(with-current-buffer (racket--logger-get-buffer-create)
116
105
(let ((inhibit-read-only t ))
117
106
(goto-char (point-max ))
118
- (insert (propertize (concat racket-- logger-print- config-prefix
107
+ (insert (propertize (concat " racket-logger-config: \n "
119
108
(pp-to-string racket-logger-config))
120
- 'font-lock-multiline t ))
109
+ 'face racket-logger-config-face ))
121
110
(goto-char (point-max )))))
122
111
123
112
(defun racket--logger-set (topic level )
@@ -168,31 +157,31 @@ As a result, we might create this buffer before the user does a
168
157
(delete-region (point-min ) (point-max )))
169
158
(racket--logger-activate-config))))
170
159
171
- (defconst racket--logger-item-rx
172
- (rx bol ?\[ (0+ space) (or " fatal" " error" " warning" " info" " debug" ) ?\] space))
173
-
174
160
(defun racket-logger-next-item (&optional count )
175
- " Move point N items forward.
176
-
177
- An \" item\" is a line starting with a log level in brackets.
178
-
179
- Interactively, N is the numeric prefix argument.
180
- If N is omitted or nil, move point 1 item forward."
181
- (interactive " P" )
182
- (forward-char 1 )
183
- (if (re-search-forward racket--logger-item-rx nil t count)
184
- (beginning-of-line )
185
- (backward-char 1 )))
161
+ " Move point forward COUNT logger output items.
162
+
163
+ Interactively, COUNT is the numeric prefix argument. If COUNT is
164
+ omitted or nil, move point 1 item forward."
165
+ (interactive " p" )
166
+ (let* ((count (or count 1 ))
167
+ (step (if (< 0 count) -1 1 ))
168
+ (search (if (< 0 count)
169
+ #'text-property-search-forward
170
+ #'text-property-search-backward )))
171
+ (while (not (zerop count))
172
+ (let ((match (funcall search 'racket-logger-item-level t t t )))
173
+ (if (not match )
174
+ (setq count 0 )
175
+ (goto-char (prop-match-beginning match ))
176
+ (setq count (+ count step)))))))
186
177
187
178
(defun racket-logger-previous-item (&optional count )
188
- " Move point N items backward.
189
-
190
- An \" item\" is a line starting with a log level in brackets.
179
+ " Move point backward COUNT logger output items.
191
180
192
- Interactively, N is the numeric prefix argument.
193
- If N is omitted or nil, move point 1 item backward."
194
- (interactive " P " )
195
- (re-search-backward racket-- logger-item-rx nil t count))
181
+ Interactively, COUNT is the numeric prefix argument. If COUNT is
182
+ omitted or nil, move point 1 item backward."
183
+ (interactive " p " )
184
+ (racket-logger-next-item ( if count ( - count) -1 ) ))
196
185
197
186
(defun racket-logger-topic-level ()
198
187
" Set or unset the level for a topic.
0 commit comments