Function: erc-insert-timestamp-left-and-right

erc-insert-timestamp-left-and-right is a byte-compiled function defined in erc-stamp.el.gz.

Signature

(erc-insert-timestamp-left-and-right STRING)

Documentation

Insert a stamp on either side when it changes.

When the deprecated option erc-timestamp-format-right is nil, use STRING, which originates from erc-timestamp-format, for the right-hand stamp. Use erc-timestamp-format-left for formatting the left-sided "date stamp," and expect it to change less frequently. Include all but the final trailing newline present in the latter (if any) as part of the erc-timestamp field. Allow the stamp's invisible property to span that same interval but also cover the previous newline, in order to satisfy folding requirements related to erc-legacy-invisible-bounds-p. Additionally, ensure every date stamp is identifiable as such via the function erc-stamp-inserting-date-stamp-p so that internal modules can easily distinguish between other left-sided stamps and date stamps inserted by this function.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-stamp.el.gz
(defun erc-insert-timestamp-left-and-right (string)
  "Insert a stamp on either side when it changes.
When the deprecated option `erc-timestamp-format-right' is nil,
use STRING, which originates from `erc-timestamp-format', for the
right-hand stamp.  Use `erc-timestamp-format-left' for formatting
the left-sided \"date stamp,\" and expect it to change less
frequently.  Include all but the final trailing newline present
in the latter (if any) as part of the `erc-timestamp' field.
Allow the stamp's `invisible' property to span that same interval
but also cover the previous newline, in order to satisfy folding
requirements related to `erc-legacy-invisible-bounds-p'.
Additionally, ensure every date stamp is identifiable as such via
the function `erc-stamp-inserting-date-stamp-p' so that internal
modules can easily distinguish between other left-sided stamps
and date stamps inserted by this function."
  (unless (or erc-stamp--date-format-end erc-stamp-prepend-date-stamps-p
              (and (or (null erc-timestamp-format-left)
                       (string-empty-p ; compat
                        (string-trim erc-timestamp-format-left "\n")))
                   (always (erc-stamp--date-mode -1))
                   (setq erc-stamp-prepend-date-stamps-p t)))
    (erc-stamp--date-mode +1))
  (let* ((ct (erc-stamp--current-time))
         (ts-right (with-suppressed-warnings
                       ((obsolete erc-timestamp-format-right))
                     (if erc-timestamp-format-right
                         (erc-format-timestamp ct erc-timestamp-format-right)
                       string))))
    ;; We should arguably be ensuring a trailing newline on legacy
    ;; "prepended" date stamps as well.  However, since this is a
    ;; compatibility oriented code path, and pre-5.6 did no such
    ;; thing, better to punt.
    (if-let* ((erc-stamp-prepend-date-stamps-p)
              (ts-left (erc-format-timestamp ct erc-timestamp-format-left))
              ((not (string= ts-left erc-timestamp-last-inserted-left))))
        (progn
          (goto-char (point-min))
          (erc-put-text-property 0 (length ts-left) 'field 'erc-timestamp
                                 ts-left)
          (insert (setq erc-timestamp-last-inserted-left ts-left)))
      (when-let*
          (((null erc-stamp--deferred-date-stamp))
           (rendered (erc-stamp--format-date-stamp ct))
           ((not (string-equal rendered erc-timestamp-last-inserted-left)))
           ((null (cl-find rendered erc-stamp--date-stamps
                           :test #'string= :key #'erc-stamp--date-str))))
        ;; Force `erc-insert-timestamp-right' to stamp this message.
        (setq erc-timestamp-last-inserted-right nil)
        (setq erc-stamp--deferred-date-stamp
              (make-erc-stamp--date :ts ct :str rendered))))
    ;; insert right timestamp
    (let ((erc-timestamp-only-if-changed-flag t)
	  (erc-timestamp-last-inserted erc-timestamp-last-inserted-right))
      (erc-insert-timestamp-right ts-right)
      (setq erc-timestamp-last-inserted-right ts-right))))