diff options
-rw-r--r-- | lisp/mastodon-views.el | 118 |
1 files changed, 48 insertions, 70 deletions
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 16bcaa1..3ee68d9 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -168,26 +168,23 @@ provides the JSON data." (insert (mastodon-tl--set-face (concat "\n " mastodon-tl--horiz-bar "\n " (upcase view-name) - "\n " - mastodon-tl--horiz-bar "\n\n") + "\n " mastodon-tl--horiz-bar "\n\n") 'success) (if bindings-string - (mastodon-tl--set-face - (concat "[" bindings-string "]" - "\n\n") - 'font-lock-comment-face) + (mastodon-tl--set-face (concat "[" bindings-string "]\n\n") + 'font-lock-comment-face) "")) (if (seq-empty-p data) (insert (propertize (format "Looks like you have no %s for now." view-name) 'face font-lock-comment-face 'byline t - 'toot-id "0")) ; so point can move here when no filters + 'toot-id "0")) ; so point can move here when no item (funcall insert-fun data) (goto-char (point-min))) - ;; (when json + ;; (when data ;; FIXME: this seems to trigger a new request, but ideally would run. - ;; (mastodon-tl--goto-next-toot)))) + ;; (mastodon-tl--goto-next-toot)) ) @@ -196,8 +193,7 @@ provides the JSON data." (defun mastodon-views--view-lists () "Show the user's lists in a new buffer." (interactive) - (mastodon-tl--init-sync "lists" - "lists" + (mastodon-tl--init-sync "lists" "lists" 'mastodon-views--insert-lists) (with-current-buffer "*mastodon-lists*" (use-local-map mastodon-views--view-lists-keymap))) @@ -214,8 +210,7 @@ provides the JSON data." (defun mastodon-views--print-list-set (lists) "Print each account plus a separator for each list in LISTS." - (let ((lists-names - (mastodon-tl--map-alist 'title lists))) + (let ((lists-names (mastodon-tl--map-alist 'title lists))) (mapc (lambda (x) (mastodon-views--print-list-accounts x) (insert (propertize (concat " " mastodon-tl--horiz-bar "\n\n") @@ -237,16 +232,14 @@ a: add account to this list, r: remove account from this list" 'keymap mastodon-views--list-name-keymap 'list-name list-name 'list-id id) - (propertize - "\n\n" - 'list t - 'keymap mastodon-views--list-name-keymap - 'list-name list-name - 'list-id id) + (propertize "\n\n" + 'list t + 'keymap mastodon-views--list-name-keymap + 'list-name list-name + 'list-id id) (propertize (mapconcat #'mastodon-search--propertize-user accounts " ") - ;; (mastodon-search--insert-users-propertized accounts) 'list t 'keymap mastodon-views--list-name-keymap 'list-name list-name @@ -293,13 +286,12 @@ If ID is provided, use that list." (let* ((list-names (unless id (mastodon-views--get-lists-names))) (name-old (if id (mastodon-tl--property 'list-name :no-move) - (completing-read "Edit list: " - list-names))) + (completing-read "Edit list: " list-names))) (id (or id (mastodon-views--get-list-id name-old))) (name-choice (read-string "List name: " name-old)) (replies-policy (completing-read "Replies policy: " ; give this a proper name '("followed" "list" "none") - nil t nil nil "list")) + nil :match nil nil "list")) (url (mastodon-http--api (format "lists/%s" id))) (response (mastodon-http--put url `(("title" . ,name-choice) @@ -341,7 +333,7 @@ Prompt for name and replies policy." (let* ((title (read-string "New list name: ")) (replies-policy (completing-read "Replies policy: " ; give this a proper name '("followed" "list" "none") - nil t nil nil "list")) ; default + nil :match nil nil "list")) ; default (response (mastodon-http--post (mastodon-http--api "lists") `(("title" . ,title) ("replies_policy" . ,replies-policy)) @@ -362,8 +354,7 @@ If ID is provided, delete that list." (let* ((list-names (unless id (mastodon-views--get-lists-names))) (name (if id (mastodon-views--get-list-name id) - (completing-read "Delete list: " - list-names))) + (completing-read "Delete list: " list-names))) (id (or id (mastodon-views--get-list-id name))) (url (mastodon-http--api (format "lists/%s" id)))) (when (y-or-n-p (format "Delete list %s?" name)) @@ -402,11 +393,9 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting." handles nil t))) (account-id (or account-id (alist-get account handles nil nil 'equal))) (url (mastodon-http--api (format "lists/%s/accounts" list-id))) - (response (mastodon-http--post url - `(("account_ids[]" . ,account-id))))) + (response (mastodon-http--post url `(("account_ids[]" . ,account-id))))) (mastodon-views--list-action-triage - response - (message "%s added to list %s!" account list-name)))) + response (message "%s added to list %s!" account list-name)))) (defun mastodon-views--add-toot-account-at-point-to-list () "Prompt for a list, and add the account of the toot at point to it." @@ -441,8 +430,7 @@ If ID is provided, use that list." (args (mastodon-http--build-array-params-alist "account_ids[]" `(,account-id))) (response (mastodon-http--delete url args))) (mastodon-views--list-action-triage - response - (message "%s removed from list %s!" account list-name)))) + response (message "%s removed from list %s!" account list-name)))) (defun mastodon-views--list-action-triage (response message) "Call `mastodon-http--triage' on RESPONSE and display MESSAGE." @@ -590,8 +578,7 @@ NO-CONFIRM means there is no ask or message, there is only do." (defun mastodon-views--view-filters () "View the user's filters in a new buffer." (interactive) - (mastodon-tl--init-sync "filters" - "filters" + (mastodon-tl--init-sync "filters" "filters" 'mastodon-views--insert-filters) (with-current-buffer "*mastodon-filters*" (use-local-map mastodon-views--view-filters-keymap))) @@ -643,8 +630,7 @@ Prompt for a context, must be a list containting at least one of \"home\", (completing-read-multiple "Contexts to filter [TAB for options]: " '("home" "notifications" "public" "thread") - nil ; no predicate - t))) ; require-match, as context is mandatory + nil :match))) (contexts-processed (if (equal nil contexts) (error "You must select at least one context for a filter") @@ -657,7 +643,6 @@ Prompt for a context, must be a list containting at least one of \"home\", (mastodon-http--triage response (lambda () (message "Filter created for %s!" word) - ;; reload if we are in filters view: (when (mastodon-tl--buffer-type-eq 'filters) (mastodon-views--view-filters)))))) @@ -666,15 +651,15 @@ Prompt for a context, must be a list containting at least one of \"home\", (interactive) (let* ((filter-id (mastodon-tl--property 'toot-id :no-move)) (phrase (mastodon-tl--property 'phrase :no-move)) - (url (mastodon-http--api - (format "filters/%s" filter-id)))) + (url (mastodon-http--api (format "filters/%s" filter-id)))) (if (null phrase) (error "No filter at point?") (when (y-or-n-p (format "Delete filter %s? " phrase))) (let ((response (mastodon-http--delete url))) - (mastodon-http--triage response (lambda () - (mastodon-views--view-filters) - (message "Filter for \"%s\" deleted!" phrase))))))) + (mastodon-http--triage + response (lambda () + (mastodon-views--view-filters) + (message "Filter for \"%s\" deleted!" phrase))))))) ;;; FOLLOW SUGGESTIONS @@ -757,8 +742,7 @@ INSTANCE is an instance domain name." (let* ((toot (if (mastodon-tl--profile-buffer-p) ;; we may be on profile description itself: (or (mastodon-tl--property 'profile-json) - ;; or on profile account listings, which use toot-json: - ;; or just toots: + ;; or on profile account listings, or just toots: (mastodon-tl--property 'toot-json)) ;; normal timeline/account listing: (mastodon-tl--property 'toot-json))) @@ -820,16 +804,14 @@ INSTANCE is the instance were are working with." (format (concat "%-" (number-to-string pad) "s: ") - (propertize - (prin1-to-string (car el)) - 'face '(:underline t)))) + (propertize (prin1-to-string (car el)) + 'face '(:underline t)))) (defun mastodon-views--print-json-keys (response &optional ind) "Print the JSON keys and values in RESPONSE. IND is the optional indentation level to print at." - (let* ((cars (mapcar - (lambda (x) (symbol-name (car x))) - response)) + (let* ((cars (mapcar (lambda (x) (symbol-name (car x))) + response)) (pad (1+ (cl-reduce #'max (mapcar #'length cars))))) (while response (let ((el (pop response))) @@ -838,9 +820,8 @@ IND is the optional indentation level to print at." ((and (vectorp (cdr el)) (not (seq-empty-p (cdr el))) (consp (seq-elt (cdr el) 0))) - (insert - (mastodon-views--format-key el pad) - "\n\n") + (insert (mastodon-views--format-key el pad) + "\n\n") (seq-do #'mastodon-views--print-instance-rules-or-fields (cdr el)) (insert "\n")) ;; vector of strings (media types): @@ -849,19 +830,17 @@ IND is the optional indentation level to print at." (< 1 (seq-length (cdr el))) (stringp (seq-elt (cdr el) 0))) (when ind (indent-to ind)) - (insert - (mastodon-views--format-key el pad) - "\n" - (seq-mapcat - (lambda (x) (concat x ", ")) - (cdr el) 'string) - "\n\n")) + (insert (mastodon-views--format-key el pad) + "\n" + (seq-mapcat + (lambda (x) (concat x ", ")) + (cdr el) 'string) + "\n\n")) ;; basic nesting: ((consp (cdr el)) (when ind (indent-to ind)) - (insert - (mastodon-views--format-key el pad) - "\n\n") + (insert (mastodon-views--format-key el pad) + "\n\n") (mastodon-views--print-json-keys (cdr el) (if ind (+ ind 4) 4))) (t @@ -887,13 +866,12 @@ IND is the optional indentation level to print at." (let ((key (or .id .name .shortcode)) (value (or .text .value .url))) (indent-to 4) - (insert - (format "%-5s: " - (propertize key 'face '(:underline t))) - (mastodon-views--newline-if-long value) - (format "%s" (mastodon-tl--render-text - value)) - "\n")))) + (insert (format "%-5s: " + (propertize key 'face '(:underline t))) + (mastodon-views--newline-if-long value) + (format "%s" (mastodon-tl--render-text + value)) + "\n")))) (defun mastodon-views--newline-if-long (el) "Return a newline string if the cdr of EL is over 50 characters long." |