Subject: Re: bug#54406: 28.0.91; rcirc text wrapping

From: Ken Raeburn <[email-masked]>
Date: Tue, 15 Mar 2022 18:24:22 -0400

Aha, debugging printfs to the rescue. :-)

I made a little tweak to rcirc-print, and added some logging advice to
rcirc-markup-fill and rcirc-fill-paragraph, then just sat back and
waited for some #emacs traffic; this is the one that triggered:

            (save-restriction
              (narrow-to-region (point) (point))
              (insert (propertize (rcirc-format-response-string process sender response
                                                              nil text)
                                'rcirc-msgid (rcirc-get-tag "msgid"))
		      (propertize "\n" 'hard t))

              ;; squeeze spaces out of text before rcirc-text
              ;; ADDED MESSAGE CALL:
	      (message "rcirc-print(process=%S sender=%S response=%S target=%S text=%S activity=%S)\n\tfilling region: buffer=%S region=%S flag=%S"
		       process sender response target text activity
		       (current-buffer)
		       (buffer-substring (point-min) (point-max))
		       rcirc-fill-flag)
              (fill-region (point-min) (point-max))

rcirc-print(process=#<process irc.libera.chat> sender=#("userxy" 0 6 (font-lock-face (rcirc-other-nick))) response="PRIVMSG" target="#emacs" text="a bunch of text here" activity=t)
	filling region: buffer=#<buffer [email-masked]> region=#("<userxy> a bunch of text here
" 0 1 (rcirc-msgid nil) 1 7 (font-lock-face (rcirc-other-nick) rcirc-msgid nil) 7 9 (rcirc-msgid nil) 9 96 (rcirc-text "a bunch of text here" rcirc-msgid nil) 96 97 (hard t)) flag=nil

(For privacy, I’ve replaced the sender name with a same-length dummy,
and replaced the message text, though mine is shorter so the text
properties probably don’t work out.)

The old version in 27.1 did:

 	    ;; squeeze spaces out of text before rcirc-text
	    (fill-region fill-start
			 (1- (or (next-single-property-change fill-start
							      'rcirc-text)
				 rcirc-prompt-end-marker)))

where fill-start is set to

  (marker-position rcirc-prompt-start-marker)

evaluated before inserting the new text.  The new version seems to be
filling the entire narrowed region containing the just-inserted text.

As an experiment, I’m trying

              (fill-region (point-min)
			   (1- (or (next-single-property-change (point-min)
								'rcirc-text)
				   (point-max))))

and it seems to do what I want so far, both for NAMES messages and user
messages.

The property change is also looked up by the goto-char immediately
following the fill-region, so perhaps they could be reversed and the new
position used as a boundary.

Though, it seems to be filling the part of the rcirc-response-formats
formatted string that comes before the message text, and it’s not clear
to me that unconditionally filling that is the right thing, if
rcirc-fill-flag is nil. *shrug* I’m not a terribly experienced IRC user,
maybe it is generally desired.

Ken

P.S. The indentation of the “when” blocks following the goto-char could
use cleaning up.