[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mastodon 703655f109 26/45: Merge branch 'emoji-capf' into
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mastodon 703655f109 26/45: Merge branch 'emoji-capf' into develop |
Date: |
Thu, 1 Feb 2024 10:00:58 -0500 (EST) |
branch: elpa/mastodon
commit 703655f109d38e6a8c0c15af01ea8b9f4314155d
Merge: 6a306afeed 638e5e09df
Author: marty hiatt <martianhiatus@riseup.net>
Commit: marty hiatt <martianhiatus@riseup.net>
Merge branch 'emoji-capf' into develop
---
lisp/mastodon-toot.el | 88 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 55 insertions(+), 33 deletions(-)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 90cf9a952d..c96ee5b533 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -239,12 +239,20 @@ send.")
(group-n 2 ?# (+ (any "A-Z" "a-z" "0-9")))
(| "'" word-boundary))) ; boundary or possessive
+(defvar mastodon-toot-emoji-regex
+ (rx (| (any ?\( "\n" "\t" " ") bol)
+ (group-n 2 ?: ; opening :
+ (+ (any "A-Z" "a-z" "0-9" "_"))
+ (? ?:)) ; closing :
+ word-boundary)) ; boundary
+
(defvar mastodon-toot-url-regex
;; adapted from ffap-url-regexp
(concat
"\\(?2:\\(news\\(post\\)?:\\|mailto:\\|file:\\|\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\)://\\)"
; uri prefix
"[^ \n\t]*\\)" ; any old thing, that is, i.e. we allow invalid/unwise chars
;; "[ .,:;!?]\\b"))
+ ;; "/" ; poss an ending slash? incompat with boundary end:
"\\>")) ; boundary end
@@ -1013,25 +1021,33 @@ Federated user: `username@host.co`."
(cons (match-beginning 2)
(match-end 2))))))
-(defun mastodon-toot--fetch-completion-candidates (start end &optional tags)
+(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
- (if tags
- (let ((tags-list (mastodon-search--search-tags-query
- (buffer-substring-no-properties start end))))
- (cl-loop for tag in tags-list
- collect (cons (concat "#" (car tag))
- (cdr tag))))
- (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))
+ (cond ((eq type :tags)
+ (let ((tags-list (mastodon-search--search-tags-query
+ (buffer-substring-no-properties start end))))
+ (cl-loop for tag in tags-list
+ collect (cons (concat "#" (car tag))
+ (cdr tag)))))
+ ((eq type :emoji)
+ (cl-loop for e in emojify-user-emojis
+ collect (car e)))
+ (t
+ (mastodon-search--search-accounts-query
+ (buffer-substring-no-properties start end))))))
+
+(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
@@ -1042,32 +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'."
+ (mastodon-toot--make-capf mastodon-toot-emoji-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."
@@ -1079,6 +1094,11 @@ If TAGS, we search for tags, else we search for handles."
;; or make it an alist and use cdr
(cadr (assoc candidate mastodon-toot-completions)))
+(defun mastodon-toot--emoji-annotation-fun (_candidate)
+ "."
+ ;; TODO: emoji image as annot
+ )
+
;;; REPLY
@@ -1817,6 +1837,8 @@ EDIT means we are editing an existing toot, not composing
a new one."
#'mastodon-toot--mentions-capf))
(add-to-list 'completion-at-point-functions
#'mastodon-toot--tags-capf)
+ (add-to-list 'completion-at-point-functions
+ #'mastodon-toot--emoji-capf)
;; company
(when (and mastodon-toot--use-company-for-completion
(require 'company nil :no-error))
- [nongnu] elpa/mastodon ee33bd1d2d 22/45: toot--send: check for media with media-attachment-ids for speed, (continued)
- [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, 2024/02/01
- [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 <=
- [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
- [nongnu] elpa/mastodon 9a8d24f9fa 02/45: call remove-overlays in --thread (fix bug display of play if we reload a thread), ELPA Syncer, 2024/02/01
- [nongnu] elpa/mastodon fda3e5963d 44/45: Merge pull request 'Add a couple of key bindings that I have found useful' (#525) from dme/mastodon.el:devel/suspend into develop, ELPA Syncer, 2024/02/01