[emacs-w3m:13952] w3m-print-this-url forces message-truncate-lines on anchor movement, with no way to opt out

Mark Diekhans <[email protected]>
Newsgroups gmane.emacs.w3m
Message-ID <[email protected]>
Reporting against emacs-w3m 1.4.632 on GNU Emacs 30.2, on behalf of VM (View
Mail), where it turns up when reading HTML mail: emacs-w3m renders the message
and VM installs `w3m-minor-mode-map' over the rendered region, so moving between
anchors is emacs-w3m's own `w3m-next-anchor'.

The complaint from our side is https://gitlab.com/emacs-vm/vm/-/issues/479 --
a long URL shown on anchor movement runs off the right of the screen instead of
wrapping, so it cannot be read or selected.  It is not a VM bug, and I do not
think it is quite what emacs-w3m intends either.

The mechanism
-------------

`w3m-print-this-url' begins:

    (message-truncate-lines (or message-truncate-lines
                                (not interactive-p)))

and `w3m-next-anchor', `w3m-previous-anchor', `w3m-next-image',
`w3m-previous-image', `w3m-goto-next-form' and `w3m-goto-previous-form' all end
by calling

    (w3m-print-this-url)

with no argument.  So on every anchor movement `interactive-p' is nil,
`message-truncate-lines' is bound to t, and the echo area is held to a single
line that the URL is then cut off in the middle of.  Pressing `u' calls the same
function interactively, `(not interactive-p)' is nil, the user's own
`message-truncate-lines' applies, and the URL wraps as one would hope.

Measured both ways over a hand-made anchor, with `message' instrumented:

    global message-truncate-lines = nil, w3m-verbose = nil

    non-interactively (what w3m-next-anchor does):
        message-truncate-lines while messaging = t
        url reached message whole:              yes
    interactively (what `u' does):
        message-truncate-lines while messaging = nil
        url reached message whole:              yes

Worth noting the second line of each pair: the whole URL reaches `message'
either way.  Nothing shortens the string; only the echo area's willingness to
use more than one line differs.

Why it cannot be configured around
----------------------------------

Because of the `or', neither value of `message-truncate-lines' gives an
unabridged URL on anchor movement:

    nil  ->  (or nil t)  = t    truncated
    t    ->  (or t   t)  = t    truncated

So a user who wants to see the whole URL as they move over links has no setting
available, and no obvious recourse short of advising `w3m-print-this-url' or
rebinding the movement commands -- both of which mean a downstream package
overriding emacs-w3m's own behaviour, which we would rather not do in VM.

Suggestion
----------

Something along the lines of

    (defcustom w3m-print-this-url-truncate-lines t
      "Whether to hold the URL shown on anchor movement to one echo-area line.
    Anchor movement shows the URL under point without being asked to, so
    truncating it keeps the echo area from growing as the cursor passes over
    long links.  Set to nil to see such URLs in full."
      :group 'w3m
      :type 'boolean)

and then

    (message-truncate-lines (or message-truncate-lines
                                (and (not interactive-p)
                                     w3m-print-this-url-truncate-lines)))

which keeps today's behaviour as the default and gives the user a way out.  I
have not sent a patch because the naming and the default are yours to choose,
and there may be a reason for the current behaviour I have not seen -- an echo
area that grows and shrinks as the cursor crosses links is genuinely
distracting, so I can see why it is the default.  If you would prefer a patch
in some particular shape, say so and I will send one.

A smaller alternative, if a new option is unwelcome: have the movement commands
call `(w3m-print-this-url t)'.  That reuses the interactive path and so respects
whatever the user has set `message-truncate-lines' to, but it also starts putting
URLs in the kill ring on mere cursor movement, which would be worse.

One related observation, not a bug
----------------------------------

The same VM report expected these URLs to appear in *Messages* and was puzzled
that they do not.  That is `w3m-verbose' defaulting to nil, with `w3m-message'
binding `message-log-max' to nil -- deliberate, documented in the docstring, and
easy to switch on.  Mentioned only because the two questions arrived together
and someone searching the archive may have both.

Thanks for emacs-w3m; it is what makes HTML mail readable in VM at all.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.