mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-09 13:40:50 +00:00
ERC right stamps: also use latest buffer's window's width (Bug#44140)
* 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 shown, 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 message text. While here, fix the off by one calculation of point start when the reference is the window's width.
This commit is contained in:
parent
75ecce4323
commit
b77f6af24e
1 changed files with 31 additions and 16 deletions
|
@ -192,6 +192,11 @@ or `erc-send-modify-hook'."
|
||||||
(list (lambda (_window _before dir)
|
(list (lambda (_window _before dir)
|
||||||
(erc-echo-timestamp dir ct))))))))
|
(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
|
(defvar erc-timestamp-last-inserted nil
|
||||||
"Last timestamp inserted into the buffer.")
|
"Last timestamp inserted into the buffer.")
|
||||||
(make-variable-buffer-local 'erc-timestamp-last-inserted)
|
(make-variable-buffer-local 'erc-timestamp-last-inserted)
|
||||||
|
@ -267,27 +272,32 @@ property to get to the POSth column."
|
||||||
|
|
||||||
(defun erc-insert-timestamp-right (string)
|
(defun erc-insert-timestamp-right (string)
|
||||||
"Insert timestamp on the right side of the screen.
|
"Insert timestamp on the right side of the screen.
|
||||||
STRING is the timestamp to insert. The function is a possible value
|
STRING is the timestamp to insert. This function is a possible
|
||||||
for `erc-insert-timestamp-function'.
|
value for `erc-insert-timestamp-function'.
|
||||||
|
|
||||||
If `erc-timestamp-only-if-changed-flag' is nil, a timestamp is always
|
If `erc-timestamp-only-if-changed-flag' is nil, a timestamp is
|
||||||
printed. If this variable is non-nil, a timestamp is only printed if
|
always printed. If this variable is non-nil, a timestamp is only
|
||||||
it is different from the last.
|
printed if it is different from the last.
|
||||||
|
|
||||||
If `erc-timestamp-right-column' is set, its value will be used as the
|
If `erc-timestamp-right-column' is set, its value will be used as
|
||||||
column at which the timestamp is to be printed. If it is nil, and
|
the column at which the timestamp is to be printed. If it is
|
||||||
`erc-fill-mode' is active, then the timestamp will be printed just
|
nil, and `erc-fill-mode' is active, then the timestamp will be
|
||||||
before `erc-fill-column'. Otherwise, if the current buffer is
|
printed just before `erc-fill-column'. Otherwise, if the current
|
||||||
shown in a window, that window's width is used. If the buffer is
|
buffer is shown in a window, that window's width is used as the
|
||||||
not shown, and `fill-column' is set, then the timestamp will be
|
right boundary. In case multiple windows show the buffer, the
|
||||||
printed just `fill-column'. As a last resort, the timestamp will
|
width of the most recently selected one is used. If the buffer
|
||||||
be printed just before the window-width."
|
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
|
(unless (and erc-timestamp-only-if-changed-flag
|
||||||
(string-equal string erc-timestamp-last-inserted))
|
(string-equal string erc-timestamp-last-inserted))
|
||||||
(setq erc-timestamp-last-inserted string)
|
(setq erc-timestamp-last-inserted string)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(forward-char -1);; before the last newline
|
(forward-char -1) ; before the last newline
|
||||||
(let* ((str-width (string-width string))
|
(let* ((str-width (string-width string))
|
||||||
|
window ; used in computation of `pos' only
|
||||||
(pos (cond
|
(pos (cond
|
||||||
(erc-timestamp-right-column erc-timestamp-right-column)
|
(erc-timestamp-right-column erc-timestamp-right-column)
|
||||||
((and (boundp 'erc-fill-mode)
|
((and (boundp 'erc-fill-mode)
|
||||||
|
@ -295,10 +305,15 @@ be printed just before the window-width."
|
||||||
(boundp 'erc-fill-column)
|
(boundp 'erc-fill-column)
|
||||||
erc-fill-column)
|
erc-fill-column)
|
||||||
(1+ (- erc-fill-column str-width)))
|
(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
|
(fill-column
|
||||||
(1+ (- fill-column str-width)))
|
(1+ (- fill-column str-width)))
|
||||||
(t
|
(t (current-column))))
|
||||||
(- (window-width) str-width 1))))
|
|
||||||
(from (point))
|
(from (point))
|
||||||
(col (current-column)))
|
(col (current-column)))
|
||||||
;; The following is a kludge used to calculate whether to move
|
;; The following is a kludge used to calculate whether to move
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue