diff options
| author | F. Jason Park | 2023-11-01 19:22:49 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-11-04 15:36:24 -0700 |
| commit | f7c7f7ac20defe3ee8a32659a6799b20ddd58aeb (patch) | |
| tree | 1afcd3ca1d12fb45bed630fd37fa48c8098639ee | |
| parent | fb578ddfb25371621df6e300a98a1ea1463dd06b (diff) | |
| download | emacs-f7c7f7ac20defe3ee8a32659a6799b20ddd58aeb.tar.gz emacs-f7c7f7ac20defe3ee8a32659a6799b20ddd58aeb.zip | |
Don't over-truncate erc-timestamp-format-left
* lisp/erc/erc-stamp.el (erc-timestamp-format-left): Fix typo in doc
string and mention that changing the value mid-session requires
cycling the minor mode.
(erc-echo-timestamp-format): Add Custom :tag for choices.
(erc-stamp--date-format-end): Revise doc string.
(erc-stamp--format-date-stamp): Fix bug involving erroneous truncation
parameter for `substring' when `erc-timestamp-format-left' doesn't end
in a newline. Thanks to Emanuel Berg for catching this.
(erc-stamp-prepend-date-stamps-p) Revise doc string.
(erc-insert-timestamp-left-and-right): Add comment regarding
compatibility concession. (Bug#60936)
| -rw-r--r-- | lisp/erc/erc-stamp.el | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 412740ac192..b5224674783 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el | |||
| @@ -60,7 +60,7 @@ If nil, timestamping is turned off." | |||
| 60 | Only considered when `erc-insert-timestamp-function' is set to | 60 | Only considered when `erc-insert-timestamp-function' is set to |
| 61 | `erc-insert-timestamp-left-and-right'. Used for displaying date | 61 | `erc-insert-timestamp-left-and-right'. Used for displaying date |
| 62 | stamps on their own line, between messages. ERC inserts this | 62 | stamps on their own line, between messages. ERC inserts this |
| 63 | flavor of stamp as a separate \"psuedo message\", so a final | 63 | flavor of stamp as a separate \"pseudo message\", so a final |
| 64 | newline isn't necessary. For compatibility, only additional | 64 | newline isn't necessary. For compatibility, only additional |
| 65 | trailing newlines beyond the first become empty lines. For | 65 | trailing newlines beyond the first become empty lines. For |
| 66 | example, the default value results in an empty line after the | 66 | example, the default value results in an empty line after the |
| @@ -69,7 +69,8 @@ followed immediately by the next message on the next line. ERC | |||
| 69 | expects to display these stamps less frequently, so the | 69 | expects to display these stamps less frequently, so the |
| 70 | formatting specifiers should reflect that. To omit these stamps | 70 | formatting specifiers should reflect that. To omit these stamps |
| 71 | entirely, use a different `erc-insert-timestamp-function', such | 71 | entirely, use a different `erc-insert-timestamp-function', such |
| 72 | as `erc-timestamp-format-right'." | 72 | as `erc-timestamp-format-right'. Note that changing this value |
| 73 | during an ERC session requires cycling `erc-stamp-mode'." | ||
| 73 | :type 'string) | 74 | :type 'string) |
| 74 | 75 | ||
| 75 | (defcustom erc-timestamp-format-right nil | 76 | (defcustom erc-timestamp-format-right nil |
| @@ -147,8 +148,9 @@ appropriate ERC buffer before the change will take effect." | |||
| 147 | "Format string to be used when `erc-echo-timestamps' is non-nil. | 148 | "Format string to be used when `erc-echo-timestamps' is non-nil. |
| 148 | This string specifies the format of the timestamp being echoed in | 149 | This string specifies the format of the timestamp being echoed in |
| 149 | the minibuffer." | 150 | the minibuffer." |
| 150 | :type '(choice (const "Timestamped %A, %H:%M:%S") | 151 | :type '(choice (const :tag "Timestamped Monday, 15:04:05" |
| 151 | (const "%Y-%m-%d %H:%M:%S %Z") | 152 | "Timestamped %A, %H:%M:%S") |
| 153 | (const :tag "2006-01-02 15:04:05 MST" "%F %T %Z") | ||
| 152 | string)) | 154 | string)) |
| 153 | 155 | ||
| 154 | (defcustom erc-echo-timestamp-zone nil | 156 | (defcustom erc-echo-timestamp-zone nil |
| @@ -629,7 +631,11 @@ printed just after each line's text (no alignment)." | |||
| 629 | "Functions appended to send and modify hooks when inserting date stamp.") | 631 | "Functions appended to send and modify hooks when inserting date stamp.") |
| 630 | 632 | ||
| 631 | (defvar-local erc-stamp--date-format-end nil | 633 | (defvar-local erc-stamp--date-format-end nil |
| 632 | "Substring index marking usable portion of date stamp format.") | 634 | "Tristate value indicating how and whether date stamps have been set up. |
| 635 | A non-nil value means the buffer has been initialized to use date | ||
| 636 | stamps. An integer marks the `substring' TO parameter for | ||
| 637 | truncating `erc-timestamp-format-left' prior to rendering. A | ||
| 638 | value of t means the option's value doesn't require trimming.") | ||
| 633 | 639 | ||
| 634 | (defun erc-stamp--propertize-left-date-stamp () | 640 | (defun erc-stamp--propertize-left-date-stamp () |
| 635 | (add-text-properties (point-min) (1- (point-max)) | 641 | (add-text-properties (point-min) (1- (point-max)) |
| @@ -645,12 +651,14 @@ printed just after each line's text (no alignment)." | |||
| 645 | (unless erc-stamp--date-format-end | 651 | (unless erc-stamp--date-format-end |
| 646 | ;; Don't add text properties to the trailing newline. | 652 | ;; Don't add text properties to the trailing newline. |
| 647 | (setq erc-stamp--date-format-end | 653 | (setq erc-stamp--date-format-end |
| 648 | (if (string-suffix-p "\n" erc-timestamp-format-left) -1 0))) | 654 | (if (string-suffix-p "\n" erc-timestamp-format-left) -1 t))) |
| 649 | ;; Ignore existing `invisible' prop value because date stamps should | 655 | ;; Ignore existing `invisible' prop value because date stamps should |
| 650 | ;; never be hideable except via `timestamp'. | 656 | ;; never be hideable except via `timestamp'. |
| 651 | (let (erc-stamp--invisible-property) | 657 | (let (erc-stamp--invisible-property) |
| 652 | (erc-format-timestamp ct (substring erc-timestamp-format-left | 658 | (erc-format-timestamp ct (if (numberp erc-stamp--date-format-end) |
| 653 | 0 erc-stamp--date-format-end)))) | 659 | (substring erc-timestamp-format-left |
| 660 | 0 erc-stamp--date-format-end) | ||
| 661 | erc-timestamp-format-left)))) | ||
| 654 | 662 | ||
| 655 | ;; Calling `erc-display-message' from within a hook it's currently | 663 | ;; Calling `erc-display-message' from within a hook it's currently |
| 656 | ;; running is roundabout, but it's a definite means of ensuring hooks | 664 | ;; running is roundabout, but it's a definite means of ensuring hooks |
| @@ -689,11 +697,13 @@ printed just after each line's text (no alignment)." | |||
| 689 | 697 | ||
| 690 | (defvar erc-stamp-prepend-date-stamps-p nil | 698 | (defvar erc-stamp-prepend-date-stamps-p nil |
| 691 | "When non-nil, date stamps are not independent messages. | 699 | "When non-nil, date stamps are not independent messages. |
| 692 | Users should think twice about enabling this escape hatch. It | 700 | This flag restores pre-5.6 behavior in which date stamps formed |
| 693 | will likely degraded the user experience by causing post-5.5 | 701 | the leading portion of affected messages. Beware that enabling |
| 694 | features, like `fill-wrap', dynamic invisibility, etc., to | 702 | this degrades the user experience by causing 5.6+ features, like |
| 695 | malfunction. Basic support for the default configuration may | 703 | `fill-wrap', dynamic invisibility, etc., to malfunction. When |
| 696 | expire earlier than normally expected.") | 704 | non-nil, none of the newline twiddling mentioned in the doc |
| 705 | string for `erc-timestamp-format-left' occurs. That is, ERC does | ||
| 706 | not append or remove trailing newlines.") | ||
| 697 | (make-obsolete-variable 'erc-stamp-prepend-date-stamps-p | 707 | (make-obsolete-variable 'erc-stamp-prepend-date-stamps-p |
| 698 | "unsupported legacy behavior" "30.1") | 708 | "unsupported legacy behavior" "30.1") |
| 699 | 709 | ||
| @@ -731,7 +741,10 @@ left-sided stamps and date stamps inserted by this function." | |||
| 731 | (if erc-timestamp-format-right | 741 | (if erc-timestamp-format-right |
| 732 | (erc-format-timestamp ct erc-timestamp-format-right) | 742 | (erc-format-timestamp ct erc-timestamp-format-right) |
| 733 | string)))) | 743 | string)))) |
| 734 | ;; Maybe insert legacy date stamp. | 744 | ;; We should arguably be ensuring a trailing newline on legacy |
| 745 | ;; "prepended" date stamps as well. However, since this is a | ||
| 746 | ;; compatibility oriented code path, and pre-5.6 did no such | ||
| 747 | ;; thing, better to punt. | ||
| 735 | (when-let ((erc-stamp-prepend-date-stamps-p) | 748 | (when-let ((erc-stamp-prepend-date-stamps-p) |
| 736 | (ts-left (erc-format-timestamp ct erc-timestamp-format-left)) | 749 | (ts-left (erc-format-timestamp ct erc-timestamp-format-left)) |
| 737 | ((not (string= ts-left erc-timestamp-last-inserted-left)))) | 750 | ((not (string= ts-left erc-timestamp-last-inserted-left)))) |