unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Olivier Certner <ocert.dev@free.fr>
To: 44140@debbugs.gnu.org
Subject: bug#44140: Patch
Date: Thu, 22 Oct 2020 17:22:24 +0200	[thread overview]
Message-ID: <2482975.FrFBg55ix7@ravel> (raw)
In-Reply-To: <1821306.tpkKSVv8f3@ravel>

[-- Attachment #1: Type: text/plain, Size: 35 bytes --]

In attachment.

-- 
Olivier Certner

[-- Attachment #2: 0001-ERC-stamps-Use-latest-buffer-s-window-s-width-prior-.patch --]
[-- Type: text/x-patch, Size: 6288 bytes --]

From 33b1c2d7b7574a70591f27c6718dffb29503b2de Mon Sep 17 00:00:00 2001
From: Olivier Certner <ocert.dev@free.fr>
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@free.fr>
+
+	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@orcon.net.nz>
 
 	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


  reply	other threads:[~2020-10-22 15:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 13:25 bug#44140: 26.3; ERC stamps: Really use latest buffer's window's width prior to `fill-column' Olivier Certner
2020-10-22 15:22 ` Olivier Certner [this message]
2021-06-09  3:56 ` J.P.
2021-06-09  5:29 ` J.P.
     [not found] ` <87v96n61xu.fsf@neverwas.me>
2021-06-09  9:31   ` J.P.
2021-07-06 12:09 ` bug#44140: Updated patch Olivier Certner
2021-08-06  5:28   ` bug#44140: 26.3; ERC stamps: Really use latest buffer's window's width prior to `fill-column' Amin Bandali
     [not found] ` <87bl8f7ktf.fsf@neverwas.me>
2021-07-06 15:15   ` Olivier Certner
2021-07-07 12:28     ` J.P.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2482975.FrFBg55ix7@ravel \
    --to=ocert.dev@free.fr \
    --cc=44140@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).