GNU bug report logs - #44140
26.3; ERC stamps: Really use latest buffer's window's width prior to `fill-column'

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Olivier Certner <olivier.certner@HIDDEN>; Keywords: patch; dated Thu, 22 Oct 2020 15:15:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 44140 <at> debbugs.gnu.org:


Received: (at 44140) by debbugs.gnu.org; 22 Oct 2020 15:36:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 22 11:36:47 2020
Received: from localhost ([127.0.0.1]:53564 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kVcdy-0005NU-Ig
	for submit <at> debbugs.gnu.org; Thu, 22 Oct 2020 11:36:47 -0400
Received: from smtp3-g21.free.fr ([212.27.42.3]:6901)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ocert.dev@HIDDEN>) id 1kVcQ7-0002us-5q
 for 44140 <at> debbugs.gnu.org; Thu, 22 Oct 2020 11:22:28 -0400
Received: from ravel.localnet (unknown [90.8.148.191])
 (Authenticated sender: ocert.dev@HIDDEN)
 by smtp3-g21.free.fr (Postfix) with ESMTPSA id BB15B13F8C6
 for <44140 <at> debbugs.gnu.org>; Thu, 22 Oct 2020 17:22:24 +0200 (CEST)
From: Olivier Certner <ocert.dev@HIDDEN>
To: 44140 <at> debbugs.gnu.org
Subject: Patch
Date: Thu, 22 Oct 2020 17:22:24 +0200
Message-ID: <2482975.FrFBg55ix7@ravel>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="nextPart41136114.RqoaopZvpL"
Content-Transfer-Encoding: 7Bit
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: In attachment. -- Olivier Certner From
 33b1c2d7b7574a70591f27c6718dffb29503b2de
 Mon Sep 17 00:00:00 2001 From: Olivier Certner Date: Thu, 22 Oct 2020 12:01:26
 +0200 Subject: [PATCH] ERC stamps: Use latest buffer's [...] 
 Content analysis details:   (2.0 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [212.27.42.3 listed in list.dnswl.org]
 -0.0 RCVD_IN_MSPIKE_H2      RBL: Average reputation (+2)
 [212.27.42.3 listed in wl.mailspike.net]
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 0.0 SPF_NONE               SPF: sender does not publish an SPF Record
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (ocert.dev[at]free.fr)
 2.0 SPOOFED_FREEMAIL       No description available.
X-Debbugs-Envelope-To: 44140
X-Mailman-Approved-At: Thu, 22 Oct 2020 11:36:44 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

This is a multi-part message in MIME format.

--nextPart41136114.RqoaopZvpL
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="UTF-8"

In attachment.

-- 
Olivier Certner
--nextPart41136114.RqoaopZvpL
Content-Disposition: attachment; filename="0001-ERC-stamps-Use-latest-buffer-s-window-s-width-prior-.patch"
Content-Transfer-Encoding: 7Bit
Content-Type: text/x-patch; charset="UTF-8"; name="0001-ERC-stamps-Use-latest-buffer-s-window-s-width-prior-.patch"

From 33b1c2d7b7574a70591f27c6718dffb29503b2de Mon Sep 17 00:00:00 2001
From: Olivier Certner <ocert.dev@HIDDEN>
Date: Thu, 22 Oct 2020 12:01:26 +0200
Subject: [PATCH] ERC stamps: Use latest buffer's window's width prior to
 `fill-column'

* lisp/erc/erc-stamp.el (erc-insert-timestamp-right): Use latest
buffer's window's width to position the timestamp, if both
`erc-timestamp-right-column' and `erc-fill-column' are not set (or
`erc-fill-mode' is off).  This is what the documentation says, but was
not implemented.  Also fix the bug of using selected window's width
instead of the (or some) window showing the buffer.  The latest
window's width is saved in `erc-timestamp-last-window-width' and used
when the buffer is no more shown.  In case the buffer was never
showed, which I'm not sure can happen, either use `fill-column' if
set, or give up on aligning and just output the timestamp (modulo the
kludge) right after each the text on the concerned line.  While here,
fix the off by one calculation of point start when the reference is
the window's width.
---
 ChangeLog.3           | 19 +++++++++++++++++
 lisp/erc/erc-stamp.el | 48 ++++++++++++++++++++++++++++---------------
 2 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/ChangeLog.3 b/ChangeLog.3
index ec2d3f8d46..c040fa889e 100644
--- a/ChangeLog.3
+++ b/ChangeLog.3
@@ -1,3 +1,22 @@
+2020-10-22  Olivier Certner  <ocert.dev@HIDDEN>
+
+	ERC stamps: Use latest buffer's window's width prior to `fill-column'
+
+	* lisp/erc/erc-stamp.el (erc-insert-timestamp-right): Use latest
+	buffer's window's width to position the timestamp, if both
+	`erc-timestamp-right-column' and `erc-fill-column' are not set (or
+	`erc-fill-mode' is off).  This is what the documentation says, but
+	was not implemented.  Also fix the bug of using selected window's
+	width instead of the (or some) window showing the buffer.  The
+	latest window's width is saved in
+	`erc-timestamp-last-window-width' and used when the buffer is no
+	more shown.  In case the buffer was never showed, which I'm not
+	sure can happen, either use `fill-column' if set, or give up on
+	aligning and just output the timestamp (modulo the kludge) right
+	after each the text on the concerned line.  While here, fix the
+	off by one calculation of point start when the reference is the
+	window's width.
+
 2020-08-03  Phil Sainty  <psainty@HIDDEN>
 
 	lisp/so-long.el: Improve support for major mode hooks
diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el
index 08970f2d70..437b428e03 100644
--- a/lisp/erc/erc-stamp.el
+++ b/lisp/erc/erc-stamp.el
@@ -191,6 +191,11 @@ or `erc-send-modify-hook'."
 				 (list (lambda (_window _before dir)
 					 (erc-echo-timestamp dir ct))))))))
 
+(defvar-local erc-timestamp-last-window-width nil
+  "Stores the width of the last window that showed the current
+buffer. This is used by `erc-insert-timestamp-right' when the
+current buffer is not shown in any window.")
+
 (defvar erc-timestamp-last-inserted nil
   "Last timestamp inserted into the buffer.")
 (make-variable-buffer-local 'erc-timestamp-last-inserted)
@@ -266,27 +271,32 @@ property to get to the POSth column."
 
 (defun erc-insert-timestamp-right (string)
   "Insert timestamp on the right side of the screen.
-STRING is the timestamp to insert.  The function is a possible value
-for `erc-insert-timestamp-function'.
-
-If `erc-timestamp-only-if-changed-flag' is nil, a timestamp is always
-printed.  If this variable is non-nil, a timestamp is only printed if
-it is different from the last.
-
-If `erc-timestamp-right-column' is set, its value will be used as the
-column at which the timestamp is to be printed.  If it is nil, and
-`erc-fill-mode' is active, then the timestamp will be printed just
-before `erc-fill-column'.  Otherwise, if the current buffer is
-shown in a window, that window's width is used.  If the buffer is
-not shown, and `fill-column' is set, then the timestamp will be
-printed just `fill-column'.  As a last resort, the timestamp will
-be printed just before the window-width."
+STRING is the timestamp to insert.  The function is a possible
+value for `erc-insert-timestamp-function'.
+
+If `erc-timestamp-only-if-changed-flag' is nil, a timestamp is
+always printed.  If this variable is non-nil, a timestamp is only
+printed if it is different from the last.
+
+If `erc-timestamp-right-column' is set, its value will be used as
+the column at which the timestamp is to be printed.  If it is
+nil, and `erc-fill-mode' is active, then the timestamp will be
+printed just before `erc-fill-column'.  Otherwise, if the current
+buffer is shown in a window, that window's width is used.  In
+case multiple windows show the buffer, the width of the most
+recently selected one is used.  If the buffer is not shown, the
+timestamp will be printed just before the window width of the
+last window that showed it.  If the buffer was never shown, and
+`fill-column' is set, it will be printed just before
+`fill-column'.  As a last resort, timestamp will be printed just
+after each line's text (no alignment)."
   (unless (and erc-timestamp-only-if-changed-flag
 	       (string-equal string erc-timestamp-last-inserted))
     (setq erc-timestamp-last-inserted string)
     (goto-char (point-max))
     (forward-char -1);; before the last newline
     (let* ((str-width (string-width string))
+           window ; Used in 'pos' computation only
 	   (pos (cond
 		 (erc-timestamp-right-column erc-timestamp-right-column)
 		 ((and (boundp 'erc-fill-mode)
@@ -294,10 +304,14 @@ be printed just before the window-width."
 		       (boundp 'erc-fill-column)
 		       erc-fill-column)
 		  (1+ (- erc-fill-column str-width)))
+                 ((setq window (get-buffer-window nil t))
+                  (setq erc-timestamp-last-window-width (window-width window))
+                  (- erc-timestamp-last-window-width str-width))
+                 (erc-timestamp-last-window-width
+		  (- erc-timestamp-last-window-width str-width))
 		 (fill-column
 		  (1+ (- fill-column str-width)))
-		 (t
-		  (- (window-width) str-width 1))))
+                 (t (current-column))))
 	   (from (point))
 	   (col (current-column)))
       ;; The following is a kludge used to calculate whether to move
-- 
2.24.1


--nextPart41136114.RqoaopZvpL--







Information forwarded to bug-gnu-emacs@HIDDEN:
bug#44140; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 22 Oct 2020 15:14:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 22 11:14:21 2020
Received: from localhost ([127.0.0.1]:53513 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1kVcIG-0002g0-E2
	for submit <at> debbugs.gnu.org; Thu, 22 Oct 2020 11:14:21 -0400
Received: from lists.gnu.org ([209.51.188.17]:57120)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <olivier.certner@HIDDEN>) id 1kVabD-0001UI-W1
 for submit <at> debbugs.gnu.org; Thu, 22 Oct 2020 09:25:48 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:34120)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <olivier.certner@HIDDEN>)
 id 1kVabD-0000n8-Ka
 for bug-gnu-emacs@HIDDEN; Thu, 22 Oct 2020 09:25:47 -0400
Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]:40639)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <olivier.certner@HIDDEN>)
 id 1kVabB-0003fY-Pg
 for bug-gnu-emacs@HIDDEN; Thu, 22 Oct 2020 09:25:47 -0400
Received: from ravel.localnet (unknown [2.15.200.177])
 (Authenticated sender: olivier.certner)
 by smtp2-g21.free.fr (Postfix) with ESMTPSA id 4ECBA2003CF
 for <bug-gnu-emacs@HIDDEN>; Thu, 22 Oct 2020 15:25:41 +0200 (CEST)
From: Olivier Certner <olivier.certner@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 26.3; ERC stamps: Really use latest buffer's window's width prior to
 `fill-column'
Date: Thu, 22 Oct 2020 15:25:40 +0200
Message-ID: <1821306.tpkKSVv8f3@ravel>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="UTF-8"
Received-SPF: none client-ip=2a01:e0c:1:1599::11;
 envelope-from=olivier.certner@HIDDEN; helo=smtp2-g21.free.fr
X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache.
 That's all we know.
X-Spam_score_int: 1
X-Spam_score: 0.1
X-Spam_bar: /
X-Spam_report: (0.1 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001,
 SPF_HELO_NONE=0.001, SPF_NONE=0.001,
 SPOOFED_FREEMAIL=1.999 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -0.3 (/)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 22 Oct 2020 11:14:19 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Applies to 26.3, but also all more recent versions as well.

Bug trigger:
1. Load ERC (e.g., open some IRC connection).
2. In some ERC buffer, deactivate ERC fill mode (if not deactivated
globally in your configuration), e.g., M-x erc-fill-mode.
3. Notice that `fill-column' (if non-nil; if nil, set it temporarily to
some small value, e.g., 40, to see the effect) will be used in this
case, contrary to what the documentation of `erc-insert-timestamp-right'
says (window's width is supposed to be used in priority when
erc-fill-mode is not activated).
4. Set `fill-column' to nil. Then, move to another window selecting
another buffer, whose size is visibly smaller. Wait for messages to
arrive in the ERC buffer and observe the timestamp position: It is
relative to the currently selected window's width!

Root causes:
1. Precedence of window's width over `fill-column' not implemented,
contrary to what the documentation states, which makes much more sense.
2. `window-width' is called to obtain window's width, but this gets the
width of the selected window, which is not necessarily where the buffer
is actually displayed. Moreover, the buffer may not be displayed at the
moment, so some other fallback is necessary.

Patch:
To be attached shortly after bug creation.

-- 
Olivier Certner






Acknowledgement sent to Olivier Certner <olivier.certner@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#44140; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 22 Oct 2020 16:15:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.