aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-23 10:46:07 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-23 10:46:07 +0100
commit264230f58acd1dea38eae29c57b555a5b48d5b35 (patch)
tree33d4b19c4f5fa9a7d31f77e94ef2b17f80d66e57 /lisp/mastodon-toot.el
parent468add918b8e1e790294cdc7ff5e34cf1bf862f6 (diff)
working capf completion
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el52
1 files changed, 25 insertions, 27 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 6ba3a75..5abe362 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -914,20 +914,24 @@ meta fields respectively."
(annotation (funcall annot-fun arg))
(meta (funcall meta-fun arg)))))
-(defun mastodon-toot-mentions-capf ()
+(defun mastodon-toot--get-bounds (regex)
+ "Get bounds of tag or handle before point."
+ ;; needed because # and @ are not part of any existing thing at point
+ (save-match-data
+ (save-excursion
+ ;; match full handle inc. domain, or tag including #
+ ;; (see the regexes for subexp 2)
+ (when (re-search-backward regex nil :no-error)
+ (cons (match-beginning 2)
+ (match-end 2))))))
+
+(defun mastodon-toot--mentions-capf ()
"Build a mentions completion backend for `completion-at-point-functions'."
- (let* ((handle-bounds
- ;; hack for @handles@with.domains, as "@" is not inc in any thing at pt!
- (save-match-data
- (save-excursion
- ;; match full handle inc. domain (see the regex for subexp 2)
- (when (re-search-backward mastodon-toot-handle-regex nil :no-error)
- ;; (when (match-string-no-properties 2)
- (cons (match-beginning 2)
- (match-end 2))))))
- (start (car handle-bounds))
- (end (cdr handle-bounds)))
- (when handle-bounds
+ (let* ((bounds
+ (mastodon-toot--get-bounds mastodon-toot-handle-regex))
+ (start (car bounds))
+ (end (cdr bounds)))
+ (when bounds
(list start
end
;; only search when necessary:
@@ -938,19 +942,13 @@ meta fields respectively."
:capf)))
:exclusive 'no))))
-(defun mastodon-toot-tags-capf ()
+(defun mastodon-toot--tags-capf ()
"Build a tags completion backend for `completion-at-point-functions'."
- (let* ((tag-bounds
- (save-match-data
- (save-excursion
- ;; match full tag with # (see regex for subexp)
- (re-search-backward mastodon-toot-tag-regex nil :no-error)
- (when (match-string-no-properties 2)
- (cons (match-beginning 2)
- (match-end 2))))))
- (start (car tag-bounds))
- (end (cdr tag-bounds)))
- (when tag-bounds
+ (let* ((bounds
+ (mastodon-toot--get-bounds mastodon-toot-tag-regex))
+ (start (car bounds))
+ (end (cdr bounds)))
+ (when bounds
(list start
end
;; only search when necessary:
@@ -1533,10 +1531,10 @@ a draft into the buffer."
(make-local-variable 'completion-at-point-functions)
(add-to-list
'completion-at-point-functions
- #'mastodon-toot-mentions-capf))
+ #'mastodon-toot--mentions-capf))
(add-to-list
'completion-at-point-functions
- #'mastodon-toot-tags-capf)
+ #'mastodon-toot--tags-capf)
(when mastodon-toot--use-company-for-completion
(company-mode-on)))
;; after-change: