alphapapa / ement.el

A Matrix client for GNU Emacs
GNU General Public License v3.0
501 stars 45 forks source link

URLs garbled with custom message format spec #116

Open wymmij opened 1 year ago

wymmij commented 1 year ago

First of all complements on the package. I only started using it at the weekend; indeed, it was only last weekend that I'd even found out about Matrix so I'm still very much new to the whole thing. Nevertheless I'd long wanted to be able to just keep in touch with friends that use the likes of Whatsapp etc., but to do so from Emacs, and now I finally can!

So thank you for the package (and for Burly too!).

Now to the problem I've encountered. Actually with the default settings there is no problem, but I've set a few variables, namely:

(setq ement-room-message-format-spec "%t%L%B%r")
(setq ement-room-sender-headers t)
(setq ement-room-sender-in-headers t)
(setq ement-room-sender-in-left-margin nil)

Unfortunately, a consequence of that particular format spec is that URLs don't seem to be getting detected by browse-url correctly - either the timestamp gets interspersed within the URL string or some other garbling occurs. In any case, the links break. I'm still taken to a browser, but it's only my homepage.

alphapapa commented 1 year ago

Hi,

Thanks for the kind words. I'm glad to hear that Ement is useful to you, and Burly as well. (In case you didn't know, Ement supports Burly, so you can bookmark a window configuration of Ement buffers and rooms and have them restored by a Burly bookmark. I use this to open a config with the room list sidebar window and windows for my main 4 rooms.)

I'm not sure exactly what URLs you're referring to, but please note that at least some of those variables are customization options, which means that you may encounter weird problems when setting them with setq, because it doesn't run any associated setter functions. Instead, try using the customization system to set them, and that may fix the problem.

wymmij commented 1 year ago

Okay, I set these via customize, or at least the ones which were created with defcustom, but unfortunately it didn't make any difference.

Still, investigating a little further I think I've found the problem.

I'll give a fuller concrete example of a typical URL that gets garbled. A friend sends me (at 04:54:42) a link to a tweet, say: https://twitter.com/elonmusk/status/1519480761749016577

With my problematic message format ("%t%L%B%r"), (browse-url-url-at-point) reads this as: http://04:54:42https://twitter.com/elonmusk/status/1519480761749016577

Without my default message format or indeed any of the others you've predefined and set via ement-room-set-message-format, then there is no such garbling and (browse-url-url-at-point) reads the URL correctly.

More to the point, the timestamp %t and message body %B being adjacent to each other and with no delimiter such as a space between them then just gets read as one long string and thus results in nonsense web addresses. So just adding a space between the timestamp and the message body will suffice to solve the issue, thus "%t %L%B%r", although I actually added a zero width space instead as it also works well enough.

Also thanks for the heads-up about the Burly support within Ement. Yes, this might well prove useful - I'm trying to work out a best practice for myself still with using multiple rooms and I'm caught between having a window configuration with multiple rooms as you suggest or alternatively a smaller window that I can just pop-up at the bottom of my screen with a ‘last used Ement room’ buffer that I can manually set. Mind you, as an example of my unfamiliarity still with all the capabilities of Ement, I wasn't even aware of the side window room list command already available so at least now I can just use that and get rid of the edits I'd made to display-buffer-alist in my init file!

alphapapa commented 1 year ago

Thanks for investigating and explaining further.

Yes, the nature of using the window margins can present a problem in some cases, especially if the window fringes are not visible (e.g. on TTY displays). The way url-at-point parses that is strange, but I'm not surprised that the lack of a space between the timestamp and the URL causes a problem.

I'm not sure of the best course of action here. A couple of ideas:

  1. Add explanation to the docstring about the need for a space between the text in the margin and the text adjacent to it.
  2. Add code in the setter function to automatically add a zero-width space after any text in the margin (it wouldn't prevent the appearance of the text running into other text when no fringe is visible, but I guess it would solve problems with thing-at-pt, etc).

What do you think?

a smaller window that I can just pop-up at the bottom of my screen with a ‘last used Ement room’ buffer that I can manually set.

That's an interesting idea. FYI, you could probably automate that by writing a little code to go through the buffer list and choose the first Ement buffer in the list (since they are usually ordered by recency).