aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mastodon-profile.el31
-rw-r--r--lisp/mastodon-search.el33
-rw-r--r--lisp/mastodon-tl.el16
-rw-r--r--lisp/mastodon-toot.el45
-rw-r--r--lisp/mastodon-views.el45
-rw-r--r--lisp/mastodon.el13
6 files changed, 85 insertions, 98 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index fe7d7d2..5bee7e9 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -494,22 +494,19 @@ This endpoint only holds a few preferences. For others, see
(let* ((url (mastodon-http--api "preferences"))
(response (mastodon-http--get-json url))
(buf (get-buffer-create "*mastodon-preferences*")))
- (with-current-buffer buf
- (switch-to-buffer-other-window buf)
- (erase-buffer)
- (special-mode)
- (mastodon-tl--set-buffer-spec (buffer-name buf)
- "preferences"
- nil)
- (let ((inhibit-read-only t))
- (while response
- (let ((el (pop response)))
- (insert
- (format "%-30s %s"
- (prin1-to-string (car el))
- (prin1-to-string (cdr el)))
- "\n\n"))))
- (goto-char (point-min)))))
+ (with-mastodon-buffer
+ buf #'special-mode :other-window
+ (mastodon-tl--set-buffer-spec (buffer-name buf)
+ "preferences"
+ nil)
+ (while response
+ (let ((el (pop response)))
+ (insert
+ (format "%-30s %s"
+ (prin1-to-string (car el))
+ (prin1-to-string (cdr el)))
+ "\n\n")))
+ (goto-char (point-min)))))
;; PROFILE VIEW DETAILS
@@ -607,7 +604,7 @@ HEADERS means also fetch link headers for pagination."
(pinned (mastodon-profile--get-statuses-pinned account))
(joined (mastodon-profile--account-field account 'created_at)))
(with-mastodon-buffer
- buffer
+ buffer #'mastodon-mode nil
(mastodon-profile-mode)
(setq mastodon-profile--account account)
(mastodon-tl--set-buffer-spec buffer
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index 86ebb90..26790ea 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -100,7 +100,7 @@ QUERY is the string to search."
status-ids-list)))
(defun mastodon-search--view-trending (type print-fun)
- "Display a list of tags trending on your instance.
+ "Display a list of items trending on your instance.
TYPE is a string, either tags, statuses, or links.
PRINT-FUN is the function used to print the data from the response."
(let* ((url (mastodon-http--api
@@ -119,22 +119,19 @@ PRINT-FUN is the function used to print the data from the response."
(message "todo"))))
(buffer (get-buffer-create
(format "*mastodon-trending-%s*" type))))
- (with-current-buffer buffer
- (switch-to-buffer (current-buffer))
- (mastodon-mode)
- (let ((inhibit-read-only t))
- (erase-buffer)
- (mastodon-tl--set-buffer-spec (buffer-name buffer)
- (format "api/v1/trends/%s" type)
- nil)
- (insert (mastodon-tl--set-face
- (concat "\n " mastodon-tl--horiz-bar "\n"
- (upcase (format " TRENDING %s\n" type))
- " " mastodon-tl--horiz-bar "\n\n")
- 'success))
- (funcall print-fun data)
- (unless (equal type "statuses")
- (goto-char (point-min)))))))
+ (with-mastodon-buffer
+ buffer #'mastodon-mode nil
+ (mastodon-tl--set-buffer-spec (buffer-name buffer)
+ (format "api/v1/trends/%s" type)
+ nil)
+ (insert (mastodon-tl--set-face
+ (concat "\n " mastodon-tl--horiz-bar "\n"
+ (upcase (format " TRENDING %s\n" type))
+ " " mastodon-tl--horiz-bar "\n\n")
+ 'success))
+ (funcall print-fun data)
+ (unless (equal type "statuses")
+ (goto-char (point-min))))))
;; functions for mastodon search
@@ -155,7 +152,7 @@ PRINT-FUN is the function used to print the data from the response."
(toots-list-json
(mastodon-search--get-full-statuses-data statuses)))
(with-mastodon-buffer
- buffer
+ buffer #'mastodon-mode nil
(mastodon-tl--set-buffer-spec buffer
"api/v2/search"
nil)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index ed1940b..8fe12fa 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1711,12 +1711,11 @@ ID is that of the toot to view."
(if (equal (caar toot) 'error)
(message "Error: %s" (cdar toot))
(with-mastodon-buffer
- buffer
+ buffer #'mastodon-mode nil
(mastodon-tl--set-buffer-spec buffer
(format "statuses/%s" id)
nil)
- (let ((inhibit-read-only t))
- (mastodon-tl--toot toot :detailed-p))))))
+ (mastodon-tl--toot toot :detailed-p)))))
(defun mastodon-tl--view-whole-thread ()
"From a thread view, view entire thread.
@@ -1757,7 +1756,7 @@ view all branches of a thread."
0)
;; if we have a thread:
(with-mastodon-buffer
- buffer
+ buffer #'mastodon-mode nil
(let ((marker (make-marker)))
(mastodon-tl--set-buffer-spec buffer
endpoint
@@ -2567,7 +2566,7 @@ JSON and http headers, without it just the JSON."
(let* ((headers (if headers (cdr response) nil))
(link-header (mastodon-tl--get-link-header-from-response headers)))
(with-mastodon-buffer
- buffer
+ buffer #'mastodon-mode nil
(mastodon-tl--set-buffer-spec buffer
endpoint
update-function
@@ -2607,12 +2606,7 @@ Optional arg NOTE-TYPE means only get that type of note."
(buffer (concat "*mastodon-" buffer-name "*"))
(json (mastodon-http--get-json url args)))
(with-mastodon-buffer
- buffer
- ;; mastodon-mode wipes buffer-spec, so order must unforch be:
- ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec.
- ;; which means we cannot use buffer-spec for update-function
- ;; unless we set it both before and after the others
- (mastodon-tl--set-buffer-spec buffer endpoint update-function)
+ buffer #'mastodon-mode nil
(setq
;; Initialize with a minimal interval; we re-scan at least once
;; every 5 minutes to catch any timestamps we may have missed
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 9d44bfd..de6a5d4 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -902,30 +902,27 @@ instance to edit a toot."
(interactive)
(let ((id (mastodon-tl--property 'base-toot-id))
(history (mastodon-tl--property 'edit-history)))
- (with-current-buffer (get-buffer-create "*mastodon-toot-edits*")
- (let ((inhibit-read-only t))
- (special-mode)
- (erase-buffer)
- (let ((count 1))
- (mapc (lambda (x)
- (insert (propertize (if (= count 1)
- (format "%s [original]:\n" count)
- (format "%s:\n" count))
- 'face font-lock-comment-face)
- (mastodon-toot--insert-toot-iter x)
- "\n")
- (cl-incf count))
- history))
- (switch-to-buffer-other-window (current-buffer))
- (setq-local header-line-format
- (propertize
- (format "Edits to toot by %s:"
- (alist-get 'username
- (alist-get 'account (car history))))
- 'face font-lock-comment-face))
- (mastodon-tl--set-buffer-spec (buffer-name (current-buffer))
- (format "statuses/%s/history" id)
- nil)))))
+ (with-mastodon-buffer
+ "*mastodon-toot-edits*" #'special-mode :other-window
+ (let ((count 1))
+ (mapc (lambda (x)
+ (insert (propertize (if (= count 1)
+ (format "%s [original]:\n" count)
+ (format "%s:\n" count))
+ 'face font-lock-comment-face)
+ (mastodon-toot--insert-toot-iter x)
+ "\n")
+ (cl-incf count))
+ history))
+ (setq-local header-line-format
+ (propertize
+ (format "Edits to toot by %s:"
+ (alist-get 'username
+ (alist-get 'account (car history))))
+ 'face font-lock-comment-face))
+ (mastodon-tl--set-buffer-spec (buffer-name (current-buffer))
+ (format "statuses/%s/history" id)
+ nil))))
(defun mastodon-toot--insert-toot-iter (it)
"Insert iteration IT of toot."
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el
index 7481fc3..8585bb0 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -799,30 +799,27 @@ INSTANCE is the instance were are working with."
(let* ((domain (url-file-nondirectory instance))
(buf (get-buffer-create
(format "*mastodon-instance-%s*" domain))))
- (with-current-buffer buf
- (switch-to-buffer-other-window buf)
- (let ((inhibit-read-only t))
- (erase-buffer)
- (special-mode)
- (when brief
- (setq response
- (list (assoc 'uri response)
- (assoc 'title response)
- (assoc 'short_description response)
- (assoc 'email response)
- (cons 'contact_account
- (list
- (assoc 'username
- (assoc 'contact_account response))))
- (assoc 'rules response)
- (assoc 'stats response))))
- (mastodon-views--print-json-keys response)
- ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving
- ;; split window
- (mastodon-tl--set-buffer-spec (buffer-name buf)
- "instance"
- nil)
- (goto-char (point-min)))))))
+ (with-mastodon-buffer
+ buf #'special-mode :other-window
+ (when brief
+ (setq response
+ (list (assoc 'uri response)
+ (assoc 'title response)
+ (assoc 'short_description response)
+ (assoc 'email response)
+ (cons 'contact_account
+ (list
+ (assoc 'username
+ (assoc 'contact_account response))))
+ (assoc 'rules response)
+ (assoc 'stats response))))
+ (mastodon-views--print-json-keys response)
+ ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving
+ ;; split window
+ (mastodon-tl--set-buffer-spec (buffer-name buf)
+ "instance"
+ nil)
+ (goto-char (point-min))))))
(defun mastodon-views--format-key (el pad)
"Format a key of element EL, a cons, with PAD padding."
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index fca376d..f52579c 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -255,14 +255,19 @@ mastodon.el needs to be re-loaded for this to be correctly set.")
"Face used for reply text in toot compose buffer.
See `mastodon-toot-display-orig-in-reply-buffer'.")
-(defmacro with-mastodon-buffer (buffer &rest body)
- "Evaluate BODY in a new `mastodon-mode' buffer called BUFFER."
+(defmacro with-mastodon-buffer (buffer mode-fun other-window &rest body)
+ "Evaluate BODY in a new or existing buffer called BUFFER.
+MODE-FUN is called to set the major mode.
+OTHER-WINDOW means call `switch-to-buffer-other-window' rather
+than `switch-to-buffer'."
(declare (debug 'body))
`(with-current-buffer (get-buffer-create ,buffer)
(let ((inhibit-read-only t))
(erase-buffer)
- (switch-to-buffer ,buffer)
- (mastodon-mode)
+ (if ,other-window
+ (switch-to-buffer-other-window ,buffer)
+ (switch-to-buffer ,buffer))
+ (funcall ,mode-fun)
,@body)))
;;;###autoload