[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mastodon 0c7322e839 24/45: refactor mastodon-toot--make-ca
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mastodon 0c7322e839 24/45: refactor mastodon-toot--make-capf |
Date: |
Thu, 1 Feb 2024 10:00:57 -0500 (EST) |
branch: elpa/mastodon
commit 0c7322e839f76882a4993516c5921c8ee82e25fa
Author: marty hiatt <martianhiatus@riseup.net>
Commit: marty hiatt <martianhiatus@riseup.net>
refactor mastodon-toot--make-capf
---
lisp/mastodon-toot.el | 63 +++++++++++++++++++--------------------------------
1 file changed, 23 insertions(+), 40 deletions(-)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 65268e35fe..14bc7db20c 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1024,7 +1024,7 @@ Federated user: `username@host.co`."
(defun mastodon-toot--fetch-completion-candidates (start end &optional type)
"Search for a completion prefix from buffer positions START to END.
Return a list of candidates.
-If TAGS, we search for tags, else we search for handles."
+TYPE is the candidate type, it may be :tags, :handles, or :emoji."
;; we can't save the first two-letter search then only filter the
;; resulting list, as max results returned is 40.
(setq mastodon-toot-completions
@@ -1041,9 +1041,13 @@ If TAGS, we search for tags, else we search for handles."
(mastodon-search--search-accounts-query
(buffer-substring-no-properties start end))))))
-(defun mastodon-toot--mentions-capf ()
- "Build a mentions completion backend for `completion-at-point-functions'."
- (let* ((bounds (mastodon-toot--get-bounds mastodon-toot-handle-regex))
+(defun mastodon-toot--make-capf (regex type &optional annot-fun)
+ "Build a completion backend for `completion-at-point-functions'.
+REGEX is the regex to match preceding text.
+Type is a keyword symbol for `mastodon-toot--fetch-completion-candidates'.
+ANNOT-FUN is a function returning an annotatation from a single
+arg, a candidate."
+ (let* ((bounds (mastodon-toot--get-bounds regex))
(start (car bounds))
(end (cdr bounds)))
(when bounds
@@ -1054,52 +1058,31 @@ If TAGS, we search for tags, else we search for
handles."
;; Interruptible candidate computation, from minad/d mendler,
thanks!
(let ((result
(while-no-input
- (mastodon-toot--fetch-completion-candidates start
end))))
+ (mastodon-toot--fetch-completion-candidates
+ start end type))))
(and (consp result) result))))
:exclusive 'no
:annotation-function
(lambda (cand)
- (concat " " (mastodon-toot--mentions-annotation-fun cand)))))))
+ (concat " " (funcall annot-fun cand)))))))
+
+(defun mastodon-toot--mentions-capf ()
+ "Build a mentions completion backend for `completion-at-point-functions'."
+ (mastodon-toot--make-capf mastodon-toot-handle-regex
+ #'mastodon-toot--mentions-annotation-fun
+ :handles))
(defun mastodon-toot--tags-capf ()
"Build a tags completion backend for `completion-at-point-functions'."
- (let* ((bounds (mastodon-toot--get-bounds mastodon-toot-tag-regex))
- (start (car bounds))
- (end (cdr bounds)))
- (when bounds
- (list start
- end
- (completion-table-dynamic ; only search when necessary:
- (lambda (_)
- ;; Interruptible candidate computation, from minad/d mendler,
thanks!
- (let ((result
- (while-no-input
- (mastodon-toot--fetch-completion-candidates start end
:tags))))
- (and (consp result) result))))
- :exclusive 'no
- :annotation-function
- (lambda (cand)
- (concat " " (mastodon-toot--tags-annotation-fun cand)))))))
+ (mastodon-toot--make-capf mastodon-toot-tag-regex
+ #'mastodon-toot--tags-annotation-fun
+ :tags))
(defun mastodon-toot--emoji-capf ()
"Build an emoji completion backend for `completion-at-point-functions'."
- (let* ((bounds (mastodon-toot--get-bounds mastodon-emoji-tag-regex))
- (start (car bounds))
- (end (cdr bounds)))
- (when bounds
- (list start
- end
- (completion-table-dynamic ; only search when necessary:
- (lambda (_)
- ;; Interruptible candidate computation, from minad/d mendler,
thanks!
- (let ((result
- (while-no-input
- (mastodon-toot--fetch-completion-candidates start end
:emoji))))
- (and (consp result) result))))
- :exclusive 'no
- :annotation-function
- (lambda (cand)
- (concat " " (mastodon-toot--emoji-annotation-fun cand)))))))
+ (mastodon-toot--make-capf mastodon-emoji-tag-regex
+ #'mastodon-toot--emoji-annotation-fun
+ :emoji))
(defun mastodon-toot--mentions-annotation-fun (candidate)
"Given a handle completion CANDIDATE, return its annotation string, a
username."
- [nongnu] elpa/mastodon updated (a8c80d25b7 -> 136e4d387a), ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon e5c9f403b6 14/45: Merge branch 'quote-region' into develop, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon ee33bd1d2d 22/45: toot--send: check for media with media-attachment-ids for speed, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 2f68bc776d 29/45: tl--content: only call tl--media if we have media, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon f0137a0ad6 42/45: Add 'o' binding to open the current toot in a browser, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 2e195ee009 01/45: update cmd index, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 1da8ab0675 05/45: add cmd to url-lookup with no fedi-like check, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon d9959ace12 04/45: update info re patches, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 406d87cc7a 07/45: display-media-p var > defcustom, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 33d0011c7c 11/45: toot--reply: call toot--compose-buffer not just toot, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 0c7322e839 24/45: refactor mastodon-toot--make-capf,
ELPA Syncer <=
- [nongnu] elpa/mastodon 0c048e154b 20/45: copy image caption cmd, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 703655f109 26/45: Merge branch 'emoji-capf' into develop, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon a6680b093e 13/45: remove ; ; Version: strings in buffers other than mastodon.el, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 8108187270 10/45: buffer-for: fix () to ensure goto point min works on cycle, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 3b3f5228ac 35/45: profile: Use v2 search when looking for users, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 6fc44fe225 34/45: fix signature of make-capf so we call it right!, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 844a97ca89 39/45: fix typo in fun name, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 9ffe93009c 38/45: edit attachments description fun, ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 792e18037d 27/45: Use `equal' to access alist entries by `mastodon-instance-url', ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon 07b9052501 40/45: Merge pull request 'profile: Use v2 search when looking for users' (#524) from dme/mastodon.el:develop into develop, ELPA Syncer, 2024/02/01