Function: erc-stamp--reset-on-clear

erc-stamp--reset-on-clear is a byte-compiled function defined in erc-stamp.el.gz.

Signature

(erc-stamp--reset-on-clear ORIG BEG END)

Documentation

Forget date stamps older than POS and remake newest culled.

Call ORIG, an erc--clear-function, with BEG and END markers.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-stamp.el.gz
(defun erc-stamp--reset-on-clear (orig beg end)
  "Forget date stamps older than POS and remake newest culled.
Call ORIG, an `erc--clear-function', with BEG and END markers."
  (let ((fullp (= (1- erc-insert-marker) end)) ; /CLEAR-p
        (skipp (or (erc--memq-msg-prop 'erc--skip 'stamp)
                   (and erc--msg-prop-overrides
                        (memq 'stamp (alist-get 'erc--skip
                                                erc--msg-prop-overrides)))))
        (culled ()))
    (when erc-stamp--date-stamps
      (setq erc-stamp--date-stamps
            ;; Assume `seq-filter' visits items in order.
            (seq-filter (lambda (o)
                          (or (> (erc-stamp--date-marker o) end)
                              (ignore
                               (set-marker (erc-stamp--date-marker o) nil)
                               (push o culled))))
                        erc-stamp--date-stamps)))
    ;; Before /CLEAR'ing a data stamp, skip past last blank in headroom.
    (when (and fullp culled (not skipp) (< 1 beg 3 end))
      (set-marker beg 3))
    (funcall orig beg end)
    (when-let* ((culled)
                ((not skipp))
                (ct (erc-stamp--date-ts (car culled)))
                (hook (make-symbol "temporary-hook"))
                (rendered (erc-stamp--format-date-stamp ct))
                (data (make-erc-stamp--date :ts ct :str rendered)))
      (cl-assert erc-stamp--date-mode)
      ;; Object successfully removed from model but snapshot remains.
      (cl-assert (null (cl-find rendered erc-stamp--date-stamps
                                :test #'string=
                                :key #'erc-stamp--date-str)))
      (let ((erc-stamp--deferred-date-stamp data)
            ;; At midnight, `rendered' may still be yesterday while
            ;; `erc-timestamp-last-inserted-left' is already today.
            (erc-timestamp-last-inserted-left nil))
        (erc-stamp--defer-date-insertion-on-post-modify hook)
        (set-marker (erc-stamp--date-marker data) end)
        (run-hooks hook)
        ;; After /CLEAR'ing, remove new date stamp's trailing newline
        ;; because one resides between `end' and `erc-input-marker'
        ;; (originally meant to protect `erc-last-saved-position').
        (when (and fullp (= end erc-last-saved-position))
          (cl-assert (or erc--called-as-input-p (null erc--msg-props)))
          (delete-region (1- end) end)))
      (when fullp
        (setq erc-timestamp-last-inserted-right nil
              erc-timestamp-last-inserted nil)))))