From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Certner Newsgroups: gmane.emacs.bugs Subject: bug#44140: Patch Date: Thu, 22 Oct 2020 17:22:24 +0200 Message-ID: <2482975.FrFBg55ix7@ravel> References: <1821306.tpkKSVv8f3@ravel> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart41136114.RqoaopZvpL" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26429"; mail-complaints-to="usenet@ciao.gmane.io" To: 44140@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 22 17:37:12 2020 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 1kVceN-0006mr-O5 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 22 Oct 2020 17:37:11 +0200 Original-Received: from localhost ([::1]:44126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVceM-00073i-Pv for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 22 Oct 2020 11:37:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVceE-00071G-EE for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 11:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVceE-00062Q-2v for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 11:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kVceD-0005O4-W0 for bug-gnu-emacs@gnu.org; Thu, 22 Oct 2020 11:37:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <1821306.tpkKSVv8f3@ravel> Resent-From: Olivier Certner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 22 Oct 2020 15:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44140 X-GNU-PR-Package: emacs Original-Received: via spool by 44140-submit@debbugs.gnu.org id=B44140.160338100720681 (code B ref 44140); Thu, 22 Oct 2020 15:37:01 +0000 Original-Received: (at 44140) by debbugs.gnu.org; 22 Oct 2020 15:36:47 +0000 Original-Received: from localhost ([127.0.0.1]:53564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVcdy-0005NU-Ig for submit@debbugs.gnu.org; Thu, 22 Oct 2020 11:36:47 -0400 Original-Received: from smtp3-g21.free.fr ([212.27.42.3]:6901) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVcQ7-0002us-5q for 44140@debbugs.gnu.org; Thu, 22 Oct 2020 11:22:28 -0400 Original-Received: from ravel.localnet (unknown [90.8.148.191]) (Authenticated sender: ocert.dev@free.fr) by smtp3-g21.free.fr (Postfix) with ESMTPSA id BB15B13F8C6 for <44140@debbugs.gnu.org>; Thu, 22 Oct 2020 17:22:24 +0200 (CEST) X-Mailman-Approved-At: Thu, 22 Oct 2020 11:36:44 -0400 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:191289 Archived-At: 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 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 + + 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 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--