From d006e8ef3de29d1e4374718eb909babc32d70090 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Tue, 8 Jun 2021 20:22:59 -0700 Subject: [PATCH 2/2] Use dynamic align-to spec for ERC right stamp * erc-stamp.el (erc-timestamp-use-align-to, erc-timestamp-align-to-gap): replace former with latter. Assume :align-to display property is always supported regardless of windowing system. New variable specifies space between right timestamp and right margin. (erc-insert-aligned): Always use display spec regardless of windowing system. Make arg POS optional. When not provided, use dynamic offset. (erc-fill-column): Only use computed position to determine whether to insert newline before stamp. --- lisp/erc/erc-stamp.el | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 40457a1a2b4..985bb785da3 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -217,14 +217,12 @@ erc-timestamp-right-column (integer :tag "Column number") (const :tag "Unspecified" nil))) -(defcustom erc-timestamp-use-align-to (eq window-system 'x) - "If non-nil, use the :align-to display property to align the stamp. -This gives better results when variable-width characters (like -Asian language characters and math symbols) precede a timestamp. +(defcustom erc-timestamp-align-to-gap 2 + "Amount of space between right margin and right timestamp." + :type 'number) -A side effect of enabling this is that there will only be one -space before a right timestamp in any saved logs." - :type 'boolean) +(make-obsolete-variable 'erc-timestamp-use-align-to + 'erc-timestamp-align-to-gap "28.1") (defun erc-insert-timestamp-left (string) "Insert timestamps at the beginning of the line." @@ -238,17 +236,14 @@ erc-insert-timestamp-left (erc-put-text-property 0 len 'invisible 'timestamp s) (insert s))) -(defun erc-insert-aligned (string pos) - "Insert STRING at the POSth column. - -If `erc-timestamp-use-align-to' is t, use the :align-to display -property to get to the POSth column." - (if (not erc-timestamp-use-align-to) - (indent-to pos) - (insert " ") - (put-text-property (1- (point)) (point) 'display - (list 'space ':align-to pos))) - (insert string)) +(defun erc-insert-aligned (string &optional pos) + "Insert STRING as right timestamp. +Use POS when provided, otherwise use string's width and +`erc-timestamp-align-to-gap' to determine position." + (let ((spec (or pos `(- right ,(+ erc-timestamp-align-to-gap + (string-width string)))))) + (insert (propertize " " 'display `(space :align-to ,spec)) + string))) ;; Silence byte-compiler (defvar erc-fill-column) @@ -303,12 +298,8 @@ erc-insert-timestamp-right ;; some margin of error if what is displayed on the line differs ;; from the number of characters on the line. (setq col (+ col (ceiling (/ (- col (- (point) (point-at-bol))) 1.6)))) - (if (< col pos) - (erc-insert-aligned string pos) - (newline) - (indent-to pos) - (setq from (point)) - (insert string)) + (when (>= col pos) (newline)) + (erc-insert-aligned string erc-timestamp-right-column) (erc-put-text-property from (point) 'field 'erc-timestamp) (erc-put-text-property from (point) 'rear-nonsticky t) (when erc-timestamp-intangible -- 2.31.1