alphapapa / ement.el

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

@usernames aren't linked at the beginnings of lines, except for the first line #267

Closed phil-s closed 3 months ago

phil-s commented 3 months ago

For the following example message, the first username on the second line does not end up linked:

@phil.catalyst:matrix.org linked? @phil.catalyst:matrix.org linked?
@phil.catalyst:matrix.org linked? @phil.catalyst:matrix.org linked?

So the respective output end up like this:

phil.catalyst​:
11:40 phil.catalyst linked? phil.catalyst linked? @phil.catalyst:matrix.org linked? phil.catalyst linked?

It looks like the issue is the regexp in ement--format-body-mentions. For a @ immediately following a newline, that initial (or bos bow (1+ blank)) doesn't match because @ isn't word syntax, and newlines aren't [:blank:]. Let's simply add a newline to that set of alternatives?

(rx (or bos bow (1+ blank))
    (or (seq (group
              ;; Group 1: full @-prefixed MXID.
              "@" (group
                   ;; Group 2: displayname.  (NOTE: Does not work
                   ;; with displaynames containing spaces.)
                   (1+ (seq (optional ".") alnum)))
              (optional ":" (1+ (seq (optional ".") alnum))))
             (or ":" eow eos (syntax punctuation)))
        (seq (group
              ;; Group 3: MXID username or displayname.
              (1+ (not blank)))
             ":" (1+ blank))))
phil-s commented 3 months ago

This?

-                 (regexp (rx (or bos bow (1+ blank))
+                 (regexp (rx (or bos bow (1+ (or blank "\n"))

Looks like it does the trick.

Does that 1+ help? Maybe preventing some potential backtracking? It doesn't look necessary for matching purposes, but I'm interested to know if it's better that way.

If there's no benefit to that, then I think we could alternatively simplify slightly to:

-                 (regexp (rx (or bos bow (1+ blank))
+                 (regexp (rx (or bos bow blank "\n")