aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authormousebot <mousebot@riseup.net>2021-10-21 14:35:40 +0200
committermousebot <mousebot@riseup.net>2021-10-21 14:41:05 +0200
commitc08bc9dea693388a779d5702fc6cc421353bb889 (patch)
treede9e653a41873bd75c9d9e02ef33ae3c0cf158a6 /lisp/mastodon-toot.el
parent156b32132f78ede03e3e6188ecf3bf67790b6846 (diff)
improvements to toot mentions completion
- customize option for completion off, following-only, or all. - 'following=true' is forwarded to http--get-search accordingly. - use company-grab-symbol-cons + regex, prepend "@" to it - also prepend '@' to the list in get-user-info-no-url - this makes company display user handles prepended with '@', and to match and - enter a handle without duplicating the '@'
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el23
1 files changed, 11 insertions, 12 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index da559ef..51c2431 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -80,10 +80,13 @@ Must be one of \"public\", \"unlisted\", \"private\" (for followers-only), or \"
:type 'string)
(when (require 'company nil :noerror)
- (defcustom mastodon-toot--use-company-completion-for-mentions t
+ (defcustom mastodon-toot--enable-completion-for-mentions "followers"
"Whether to enable company completion for mentions in toot compose buffer."
:group 'mastodon-toot
- :type 'boolean))
+ :type '(choice
+ (const :tag "off" nil)
+ (const :tag "followers only" "followers")
+ (const :tag "all users" "all"))))
(defvar mastodon-toot--content-warning nil
"A flag whether the toot should be marked with a content warning.")
@@ -406,20 +409,16 @@ The prefix string is tested against both user handles and display names."
(handle (cadr candidate)))
(propertize handle 'meta display-name)))
-(defun mastodon-toot--mentions-company-backend (command &optional arg &rest ignored)
+(defun mastodon-toot--mentions-completion (command &optional arg &rest ignored)
"A company completion backend for toot mentions."
(interactive (list 'interactive))
(cl-case command
- (interactive (company-begin-backend 'mastodon-toot--mentions-company-backend))
+ (interactive (company-begin-backend 'mastodon-toot--mentions-completion))
(prefix (and (bound-and-true-p mastodon-toot-mode) ; if masto toot minor mode
- (save-excursion
- (backward-word)
- (backward-char)
- (looking-at "@")) ; if we have a mention
- (company-grab-symbol))) ;; get thing before point, sans @
+ ;; @ + thing before point
+ (concat "@" (company-grab-symbol-cons "^@[0-9A-Za-z-.\\_@]+" 2))))
(candidates (mastodon-toot--mentions-company-candidates arg))
(annotation (mastodon-toot--mentions-company-annotation arg))))
- ;; (meta (mastodon-toot--mentions-company-meta arg))))
(defun mastodon-toot--reply ()
"Reply to toot at `point'."
@@ -677,9 +676,9 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var."
(mastodon-toot--display-docs-and-status-fields)
(mastodon-toot--setup-as-reply reply-to-user reply-to-id))
(mastodon-toot-mode t)
- (when mastodon-toot--use-company-completion-for-mentions
+ (when mastodon-toot--enable-completion-for-mentions
(set (make-local-variable 'company-backends)
- (add-to-list 'company-backends 'mastodon-toot--mentions-company-backend))
+ (add-to-list 'company-backends 'mastodon-toot--mentions-completion))
(company-mode-on))
(make-local-variable 'after-change-functions)
(push #'mastodon-toot--update-status-fields after-change-functions)