aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-07 13:54:41 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-07 13:54:41 +0100
commitfad04189a514f0d5dd1b2ec5d1958bc0d30b6695 (patch)
tree06f8fc4d5131f30edab7ae2975d0ebdd6fca5013
parent5613c11e037ceb1d9beab26a48f2958c669ea029 (diff)
parent327bcc896e8307827502d41c6ac92f04ec649ebb (diff)
Merge branch 'prop-tags-handles-compose'
-rw-r--r--lisp/mastodon-toot.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index bd24f6f..60cc4da 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1203,6 +1203,33 @@ Added to `after-change-functions' in new toot buffers."
(setq mastodon-toot-draft-toots-list nil)
(message "All drafts deleted!"))
+(defun mastodon-toot--propertize-tags-and-handles (&rest _args)
+ "Propertize tags and handles in toot compose buffer.
+Added to `after-change-functions'."
+ (when (mastodon-toot-compose-buffer-p)
+ (let ((header-region
+ (mastodon-tl--find-property-range 'toot-post-header
+ (point-min))))
+ ;; cull any prev props:
+ ;; stops all text after a handle or mention being propertized:
+ (set-text-properties (cdr header-region) (point-max) nil)
+ ;; TODO: confirm allowed hashtag/handle characters:
+ (mastodon-toot--propertize-item "#[1-9a-zA-Z_]+"
+ 'success
+ (cdr header-region))
+ (mastodon-toot--propertize-item "@[1-9a-zA-Z._]+"
+ 'mastodon-display-name-face
+ (cdr header-region)))))
+
+(defun mastodon-toot--propertize-item (regex face start)
+ "Propertize item matching REGEX with FACE starting from START."
+ (save-excursion
+ (goto-char start)
+ (cl-loop while (search-forward-regexp regex nil :noerror)
+ do (add-text-properties (match-beginning 0)
+ (match-end 0)
+ `(face ,face)))))
+
(defun mastodon-toot-compose-buffer-p ()
"Return t if compose buffer is current."
(equal (buffer-name (current-buffer)) "*new toot*"))
@@ -1252,6 +1279,7 @@ a draft into the buffer."
;; draft toot text saving:
(setq mastodon-toot-current-toot-text nil)
(push #'mastodon-toot--save-toot-text after-change-functions)
+ (push #'mastodon-toot--propertize-tags-and-handles after-change-functions)
(when initial-text
(insert initial-text))))