branch: elpa/mastodon commit ca99f7544dd8d7f944e17adcb7eb28ab719fc59e Author: marty hiatt <martianhia...@disroot.org> Commit: marty hiatt <martianhia...@disroot.org>
toot.el: make char count include handles sans domain. #721. removed a stray plus from mastodon-toot-handle-regex so that our group 4 excludes domain. i "think" this is how masto works, and what our old code was trying but failing to do. we also need to use two \ in replace-regex-in-string for the arg to work right. --- lisp/mastodon-toot.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 697e582049..02b4d1f0b0 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -251,9 +251,12 @@ send.") ;;; REGEXES (defvar mastodon-toot-handle-regex - (rx (| (any ?\( "\n" "\t "" ") bol) ; preceding things - (group-n 2 (+ ?@ (* (any ?- ?_ ?. "A-Z" "a-z" "0-9" ))) ; handle - (? ?@ (* (not (any "\n" "\t" " "))))) ; optional domain + (rx (group-n 2 ; include domain + (group-n 4 ; exclude domain + (| (any ?\( "\n" "\t" " ") bol) ; preceding things + ?@ ; first @ + (* (any ?- ?_ ?. "A-Z" "a-z" "0-9" ))) ; username + (? ?@ (* (not (any "\n" "\t" " "))))) ; optional domain (| "'" word-boundary))) ; boundary or possessive (defvar mastodon-toot-tag-regex @@ -1884,10 +1887,11 @@ CW is the content warning, which contributes to the character count." ;; FIXME: URL chars is avail at /api/v1/instance ;; for masto, it's .statuses.characters_reserved_per_url (let* ((url-replacement (make-string 23 ?x)) - (count-str (replace-regexp-in-string ; handle @handles - mastodon-toot-handle-regex "\2" - (replace-regexp-in-string ; handle URLs - mastodon-toot-url-regex url-replacement toot-string)))) + (count-str + (replace-regexp-in-string ; handle @handles + mastodon-toot-handle-regex "\\4" + (replace-regexp-in-string ; handle URLs + mastodon-toot-url-regex url-replacement toot-string)))) (+ (length cw) (length count-str))))