aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-20 12:30:11 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-20 15:32:46 +0100
commitff859ba22c23c01bdc9f4390e41eedc3254b9334 (patch)
tree9becce6e7f9be31b5f5041a40e676595c10b45ab /lisp/mastodon-toot.el
parent91020f86cf2b19bfb3136a9a92facd77bd0ccda0 (diff)
mastodon-handle-regex: use for company + propertizing
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el42
1 files changed, 27 insertions, 15 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 125eeea..572d575 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -186,6 +186,14 @@ For the moment we just put all composed toots in here, as we want
to also capture toots that are 'sent' but that don't successfully
send.")
+(defvar mastodon-handle-regex
+ (concat
+ ;; preceding space or bol [boundary doesn't work with @]
+ "\\([\n\t ]\\|^\\)"
+ "\\(?2:@[1-9a-zA-Z._-]+" ; a handle
+ "\\(@[^ \n\t]*\\)?\\)" ; with poss domain, * = allow only @
+ "\\b"))
+
(defvar mastodon-toot-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'mastodon-toot--send)
@@ -770,17 +778,24 @@ for matches, CANDIDATES-FUN, ANNOT-FUN, and META-FUN are
functions called on ARG to generate formatted candidates, annotation, and
meta fields respectively."
(interactive (list 'interactive))
- (cl-case command
- (interactive (company-begin-backend (quote backend-name)))
- (prefix (when (and (bound-and-true-p mastodon-toot-mode) ; if masto toot minor mode
- (save-excursion
- (forward-whitespace -1)
- (forward-whitespace 1)
- (looking-at str-prefix)))
- (concat str-prefix (company-grab-symbol))))
- (candidates (funcall candidates-fun arg))
- (annotation (funcall annot-fun arg))
- (meta (funcall meta-fun arg))))
+ (let ((handle-before
+ (save-match-data
+ (save-excursion
+ (re-search-backward mastodon-handle-regex nil :no-error)
+ (if (match-string-no-properties 2)
+ (buffer-substring-no-properties (match-beginning 2) (match-end 2))
+ "")))))
+ (cl-case command
+ (interactive (company-begin-backend (quote backend-name)))
+ (prefix (when (and (bound-and-true-p mastodon-toot-mode) ; if masto toot minor mode
+ (save-excursion
+ (forward-whitespace -1)
+ (forward-whitespace 1)
+ (looking-at str-prefix)))
+ (concat str-prefix (substring-no-properties handle-before 1))))
+ (candidates (funcall candidates-fun arg))
+ (annotation (funcall annot-fun arg))
+ (meta (funcall meta-fun arg)))))
(defun mastodon-toot-mentions (command &optional arg &rest ignored)
"A company completion backend for toot mentions.
@@ -1266,10 +1281,7 @@ Added to `after-change-functions'."
'success
(cdr header-region))
(mastodon-toot--propertize-item
- (concat "\\([\n\t ]\\|^\\)" ; preceding space or bol
- "\\(?2:@[1-9a-zA-Z._-]+" ; a handle
- "\\(@[1-9a-zA-Z._-]+\\)?\\)" ; with poss domain
- "\\b") ; boundary
+ mastodon-handle-regex
'mastodon-display-name-face
(cdr header-region)))))