aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authormartianh <martianh@noreply.codeberg.org>2024-02-08 08:04:48 +0000
committermartianh <martianh@noreply.codeberg.org>2024-02-08 08:04:48 +0000
commit51132d08682b7b13473d24a4bf60417541905c81 (patch)
tree201cc33faec6c856418fc5565d3b81892ad4d394 /lisp/mastodon-toot.el
parenta01eec0d57ed64f8a83784cd48e44fc2961e0d64 (diff)
parent2e6bcd41a9bb5953b20758ada8cec2b4ff8e9b4f (diff)
Merge pull request 'Use display-buffer to allow customization' (#522) from rahguzar/mastodon.el:display-buffer into develop
Reviewed-on: https://codeberg.org/martianh/mastodon.el/pulls/522
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el19
1 files changed, 6 insertions, 13 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index bffa20e..462f925 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1698,20 +1698,13 @@ REPLY-REGION is a string to be injected into the buffer."
URLs always = 23, and domain names of handles are not counted.
This is how mastodon does it.
CW is the content warning, which contributes to the character count."
- (with-temp-buffer
- (switch-to-buffer (current-buffer))
- (insert toot-string)
- (goto-char (point-min))
- ;; handle URLs
- (while (search-forward-regexp mastodon-toot-url-regex nil t)
- ; "\\w+://[^ \n]*" old regex
- (replace-match "xxxxxxxxxxxxxxxxxxxxxxx")) ; 23 x's
- ;; handle @handles
- (goto-char (point-min))
- (while (search-forward-regexp mastodon-toot-handle-regex nil t)
- (replace-match (match-string 2))) ; replace with handle only
+ (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))))
(+ (length cw)
- (length (buffer-substring (point-min) (point-max))))))
+ (length count-str))))
;;; DRAFTS