Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch ifi-notify
Excluding Merge-Ins
This is equivalent to a diff from
92d1f8312d
to cb07aac592
2021-09-26
| | |
06:15 |
|
check-in: 78ae7439ef user: sebyte tags: ifi
|
2021-09-25
| | |
18:59 |
|
Leaf
check-in: cb07aac592 user: sebyte tags: ifi-notify
|
17:11 |
|
check-in: 92d1f8312d user: sebyte tags: ifi
|
10:06 |
|
check-in: 20b8c27190 user: sebyte tags: ifi
|
2021-08-12
| | |
10:23 |
|
check-in: eb30e4a556 user: sebyte tags: ifi-notify
|
| | |
Changes to ifi-ckout.el.
︙ | | |
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
-
+
+
|
(defun ifi-ckout-fossil-all-checkouts ()
(split-string
(ifi-lib-fossil-output-to-string "all" "list" "--ckout") "\n"))
(defun ifi-ckout-refresh-stanza-state (checkout)
(let ((s (ifi-state checkout)))
(ifi-lib-refresh-headline-state s)
(ifi-state-parse-changes-differ s)))
(ifi-state-parse-changes-differ s)
(ifi-state-parse-ls s)))
(defun ifi-ckout-checkout-states ()
;; ifi-ckout-all-checkouts is bound in #'ifi-ckout-update-buffer
(mapcar (lambda (c) (ifi-state c)) ifi-ckout-all-checkouts))
(defun ifi-ckout-forget-all-stanza-markers ()
;; #'ifi-state-headline-marker returns nil when
|
︙ | | |
Changes to ifi-lib.el.
︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
+
|
;;; Commentary:
;;
;; • IFI functions used in more than one ifi-*.el file.
;;; Code:
(require 'filenotify)
(require 'ifi-custom)
(require 'ifi-state)
;;; utils
(defun ifi-lib-strip-trailing-whitespace (string)
(if (string-match "[ \t\n\r]+\\'" string)
|
︙ | | |
Changes to ifi-state.el.
︙ | | |
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
-
-
+
+
|
(require 'cl-macs)
(defvar ifi-states nil)
(cl-defstruct ifi-state
;; IFI data
canonical-directory headline-marker change-markers
shell-buffer ui-buffer ui-port
canonical-directory canonical-subdirectories directory-watchers events
headline-marker change-markers shell-buffer ui-buffer ui-port
;; Fossil info
project-name repository local-root config-db project-code
checkout parent tags comment check-ins
;; Other fossil data
autosync default-remote current-branch timeline-position changes)
(defun ifi-state-get-state (dir)
|
︙ | | |
179
180
181
182
183
184
185
186
187
188
189
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
(defun ifi-state-parse-changes-differ (s)
(let* ((default-directory (ifi-state-canonical-directory s))
(output
(ifi-lib-fossil-output-to-string "changes" "--differ")))
(setf (ifi-state-changes s) (split-string output "\n"))
output))
(defun ifi-state-parse-ls (s)
(let* ((default-directory (ifi-state-canonical-directory s))
(output (ifi-lib-fossil-output-to-string "ls" )))
(setf (ifi-state-canonical-subdirectories s)
(mapcar (lambda (f) (mapconcat #'identity f "/"))
(remove nil (cl-remove-duplicates
(mapcar (lambda (f)
(butlast
(split-string f "/" t)))
(split-string output "\n"))
:test #'equal))))
output))
;;; Notifications
;;;
;;; • Implementation
;;;
;;; Function `ifi-state-start-watchers' employs Emacs'
;;; `file-notify-add-watch' to add a watch for the canonical directory
;;; and any subdirectories to slot `directory-watchers'. A single
;;; callback function; `ifi-state--watcher-callback', receives _all_
;;; events from _every_ watch, and adds a cons cell of the form
;;; (TIME . "FILE ACTION") to the `events' slot of the applicable
;;; `ifi-state'. Special variable `ifi-state--watcher-file-filter'
;;; is a regular expression employed in
;;; `ifi-state--watcher-callback' to decide which FILEs should be
;;; ignored. One ACTION is also ignored; the 'stopped' action.
;;;
;;; When events are being monitored, variable
;;; `ifi-state--event-monitor' is bound to an idle timer which calls
;;; function `ifi-state--event-monitor' every
;;; `ifi-state--event-monitor-frequency' seconds (default value 1).
;;;
;;; Function `ifi-state--event-monitor' maps function
;;; `ifi-state--act-on-events' across ALL `ifi-state's. Function
;;; `ifi-state--act-on-events' looks at the most recent event in
;;; each `events' slot and passes the `ifi-state' to each function
;;; in the list variable `ifi-state-event-actions' when the age of
;;; the most recent event is greater than
;;; `ifi-state--event-age-limit' (default value 1). If the
;;; `ifi-state--event-age-limit' has not been reached, nothing is
;;; done and events may continue to accumulate. Thus
;;; `ifi-state-event-actions' are not performed multiple times in
;;; rapid succession when bursts of events occur, e.g. on checkouts.
;;;
;;; Functions in `ifi-state-event-actions' must accept an
;;; `ifi-state' argument and should immediately consider the
;;; contents of the `events' slot. The contents will be erased by
;;; what should always be the final action in the list;
;;; `ifi-state--discard-events'.
;;;
;;; • Example usage (in a checkout directory)
;;;
;;; (ifi-state-start-watchers (ifi-state "~/workspace/foo"))
;;; (ifi-state-start-event-monitor) ; monitors ALL ifi-states
;;; (push ACTION ifi-state-event-actions)
;;; ...
;;; (ifi-state-stop-event-monitor)
;;; (ifi-state-stop-watchers (ifi-state "~/workspace/foo"))
;;;
;;; ACTION is a function accepting a single `ifi-state' argument.
;;; Adding function `ifi-state-event-debugger' to
;;; `ifi-state-event-actions', e.g.
;;;
;;; (push 'ifi-state-event-debugger ifi-state-event-actions)
;;;
;;; is a good way to see what's going on.
(defvar ifi-state--watcher-file-filter
(let ((emacs-autosave-files "\\.?#.+")
(fossil-bookkeeping-files "\\.fslckout.*")
(fossil-comment-files ".+-comment-[0-9A-F]+\\.txt"))
(format ".+/\\(%s\\|%s\\|%s\\)"
emacs-autosave-files
fossil-bookkeeping-files
fossil-comment-files)))
(defvar ifi-state--event-age-limit 1)
(defvar ifi-state--event-monitor-frequency 1)
(defvar ifi-state--event-monitor nil) ; for `cancel-timer'
;;; utils
(defun ifi-state--watcher-state (watcher)
(catch 'found
(dolist (s ifi-states)
(when (member watcher (ifi-state-directory-watchers s))
(throw 'found s)))
nil)) ; '--- return value
(defun ifi-state--watcher-callback (event)
(cl-destructuring-bind (watcher action &rest files) event
(dolist (file files)
(unless (or (string-match ifi-state--watcher-file-filter file)
(string= action "stopped"))
(push (cons (float-time (current-time))
(format "%s %s" file action))
(ifi-state-events
(ifi-state--watcher-state watcher)))))))
(defun ifi-state--discard-events (s)
(setf (ifi-state-events s) nil))
(defun ifi-state--act-on-events (s)
(let* ((most-recent-event (car (ifi-state-events s)))
(age (float-time (time-subtract
nil (car most-recent-event)))))
(when (> age ifi-state--event-age-limit)
(dolist (action ifi-state-event-actions) (funcall action s)))))
(defun ifi-state--event-monitor ()
(mapc #'ifi-state--act-on-events ifi-states))
;;; API
(defvar ifi-state-event-actions '(ifi-state--discard-events))
(defun ifi-state-start-watchers (s)
;; should the watchers report changes to file attributes?
(unless (ifi-state-directory-watchers s)
(setf (ifi-state-directory-watchers s)
(list (file-notify-add-watch
(ifi-state-canonical-directory s)
'(change) ; attribute-change
#'ifi-state--watcher-callback)))
(dolist (d (ifi-state-canonical-subdirectories s))
(push (file-notify-add-watch
d '(change) ; attribute-change
#'ifi-state--watcher-callback)
(ifi-state-directory-watchers s)))
(length (ifi-state-directory-watchers s))))
(defun ifi-state-stop-watchers (s)
(mapc #'file-notify-rm-watch (ifi-state-directory-watchers s))
(setf (ifi-state-directory-watchers s) nil))
(defun ifi-state-start-event-monitor ()
(unless ifi-state--event-monitor
(setq ifi-state--event-monitor
(run-with-timer
ifi-state--event-monitor-frequency
ifi-state--event-monitor-frequency
#'ifi-state--event-monitor))))
(defun ifi-state-stop-event-monitor ()
(when ifi-state--event-monitor
(setf ifi-state--event-monitor
(cancel-timer ; returns NIL
ifi-state--event-monitor))))
(defun ifi-state-event-debugger (s) ; for `ifi-state-event-actions'
(with-current-buffer (get-buffer-create "*fossil notifications*")
(goto-char (point-max))
(dolist (e (ifi-state-events s))
(insert (format "%-18s %s\n" (car e) (cdr e))))
(display-buffer (current-buffer))))
(provide 'ifi-state)
;;; ifi-state.el ends here
|