aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-24 11:42:13 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-24 11:42:13 +0100
commitf5420dd98a335d434f3cdc2c8456504f25c6ac9d (patch)
tree32a2f3211ffbaadec8c0a3d3ab863e5c37dcec62
parent9dd3db84b9164517239121188e58e188fe13b393 (diff)
add annotation to completions (URL for tag, username for mention)
this is still rough, uses a defvar-local which may be avoidable.
-rw-r--r--lisp/mastodon-toot.el47
1 files changed, 36 insertions, 11 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index c13d43b..6855280 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -949,10 +949,17 @@ meta fields respectively."
;; only search when necessary:
(completion-table-dynamic
(lambda (_)
- (mastodon-search--search-accounts-query
- (buffer-substring-no-properties start end)
- :capf)))
- :exclusive 'no))))
+ ;; TODO: do we really need to set a local var here
+ ;; just for the annotation-function?
+ (setq mastodon-toot-completions
+ (mastodon-search--search-accounts-query
+ (buffer-substring-no-properties start end)
+ :capf))))
+ :exclusive 'no
+ :annotation-function
+ (lambda (candidate)
+ (concat " "
+ (mastodon-toot--mentions-annotation-fun candidate)))))))
(defun mastodon-toot--tags-capf ()
"Build a tags completion backend for `completion-at-point-functions'."
@@ -966,13 +973,31 @@ meta fields respectively."
;; only search when necessary:
(completion-table-dynamic
(lambda (_)
- (let ((tags (mastodon-search--search-tags-query
- (buffer-substring-no-properties start end))))
- (mapcar (lambda (x)
- (list (concat "#" (car x))
- (cdr x)))
- tags))))
- :exclusive 'no))))
+ (setq mastodon-toot-completions
+ (let ((tags (mastodon-search--search-tags-query
+ (buffer-substring-no-properties start end))))
+ (mapcar (lambda (x)
+ (list (concat "#" (car x))
+ (cdr x)))
+ tags)))))
+ :exclusive 'no
+ :annotation-function
+ (lambda (candidate)
+ (concat " "
+ (mastodon-toot--tags-annotation-fun candidate)))))))
+
+(defvar-local mastodon-toot-completions nil
+ "The data of completion candidates for the current completion at point.")
+
+(defun mastodon-toot--mentions-annotation-fun (candidate)
+ "Given a handle completion CANDIDATE, return its annotation string, a username."
+ (caddr (assoc candidate mastodon-toot-completions)))
+
+(defun mastodon-toot--tags-annotation-fun (candidate)
+ "Given a tag string CANDIDATE, return an annotation, the tag's URL."
+ ;; FIXME check the list returned here? should be cadr
+ ;;or make it an alist and use cdr
+ (caadr (assoc candidate mastodon-toot-completions)))
(defun mastodon-toot-mentions (command &optional arg &rest ignored)
"A company completion backend for toot mentions.