From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#44140: 26.3; ERC stamps: Really use latest buffer's window's width prior to `fill-column' Date: Tue, 08 Jun 2021 20:56:12 -0700 Message-ID: <87bl8f7ktf.fsf__47789.1007483535$1623211038$gmane$org@neverwas.me> References: <1821306.tpkKSVv8f3@ravel> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22511"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 44140@debbugs.gnu.org, emacs-erc@gnu.org To: Olivier Certner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 09 05:57:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqpL3-0005gy-EW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 05:57:09 +0200 Original-Received: from localhost ([::1]:59086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqpL2-00040R-H6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Jun 2021 23:57:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqpKw-000403-PU for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 23:57:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqpKw-00008O-If for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 23:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lqpKw-0001tZ-9g for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 23:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Jun 2021 03:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44140 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 44140-submit@debbugs.gnu.org id=B44140.16232109897244 (code B ref 44140); Wed, 09 Jun 2021 03:57:02 +0000 Original-Received: (at 44140) by debbugs.gnu.org; 9 Jun 2021 03:56:29 +0000 Original-Received: from localhost ([127.0.0.1]:60261 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqpKO-0001sl-Nx for submit@debbugs.gnu.org; Tue, 08 Jun 2021 23:56:29 -0400 Original-Received: from mail-108-mta222.mxroute.com ([136.175.108.222]:41165) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqpKM-0001sW-SD for 44140@debbugs.gnu.org; Tue, 08 Jun 2021 23:56:27 -0400 Original-Received: from filter004.mxroute.com ([149.28.56.236] filter004.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta222.mxroute.com (ZoneMTA) with ESMTPSA id 179eee9e396000774e.001 for <44140@debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Wed, 09 Jun 2021 03:56:16 +0000 X-Zone-Loop: 0516234f2fdc2c663391c813e83361b26a8aa79028b8 X-Originating-IP: [149.28.56.236] In-Reply-To: <1821306.tpkKSVv8f3@ravel> (Olivier Certner's message of "Thu, 22 Oct 2020 15:25:40 +0200") X-AuthUser: masked@neverwas.me X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:208269 Archived-At: --=-=-= Content-Type: text/plain Hi Olivier, Olivier Certner writes: > 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! I followed the steps and observed the effects as you describe. Setting fill-column to nil (which I wasn't aware was possible) makes it use the width of whichever window's currently active. Definitely worthy of a "!". > 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. Storing the last window's width seems like a good idea because these buffers are often buried. I'm a little fuzzy on how the ALL-FRAMES = t param for the function `get-buffer-window' works exactly. The windows within each frame should follow the normal cyclic ordering (right?). But I think I learned somewhere that frame ordering is different and isn't affected by whichever one was last selected. If true, I suppose frame users (not me) are already used to this behavior and won't be surprised by it. Anyway, I happened upon another approach for the final display part (see attached sketch). If you see anything useful, just take it. Otherwise, sorry for the distraction. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ERC-stamps-Use-latest-buffer-s-window-s-width-prior-.patch >From f10df51f8b65cf4e25a77eb52d3e3a0320e317a8 Mon Sep 17 00:00:00 2001 From: Olivier Certner Date: Thu, 22 Oct 2020 12:01:26 +0200 Subject: [PATCH 1/2] 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. --- lisp/erc/erc-stamp.el | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 31de9e80697..40457a1a2b4 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -181,6 +181,11 @@ erc-add-timestamp (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-local erc-timestamp-last-inserted nil "Last timestamp inserted into the buffer.") @@ -250,27 +255,32 @@ erc-fill-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) @@ -278,10 +288,14 @@ erc-insert-timestamp-right (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.31.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Use-dynamic-align-to-spec-for-ERC-right-stamp.patch >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 --=-=-=--