aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)))))