From 5bb860d943cde9260ced8bc6eb9570d1dbb3273d Mon Sep 17 00:00:00 2001
From: marty hiatt <martianhiatus [a t] riseup [d o t] net>
Date: Sun, 30 Apr 2023 15:42:05 +0200
Subject: flychecks

---
 lisp/mastodon-views.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'lisp/mastodon-views.el')

diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el
index 8064282..7481fc3 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -38,6 +38,8 @@
 (require 'mastodon-http)
 
 (defvar mastodon-mode-map)
+(defvar mastodon-tl--horiz-bar)
+(defvar mastodon-tl--timeline-posts-count)
 
 (autoload 'mastodon-mode "mastodon")
 (autoload 'mastodon-tl--init "mastodon-tl")
@@ -902,8 +904,8 @@ IND is the optional indentation level to print at."
     (indent-to 4)
     (insert
      (format "%-5s: "
-             (propertize key)
-             'face '(:underline t))
+             (propertize key
+                         'face '(:underline t)))
      (mastodon-views--newline-if-long value)
      (format "%s" (mastodon-tl--render-text
                    value))
-- 
cgit v1.2.3


From 59e5e3ece54bcac36d9debad392bff25a31438b5 Mon Sep 17 00:00:00 2001
From: marty hiatt <martianhiatus [a t] riseup [d o t] net>
Date: Thu, 4 May 2023 09:12:23 +0200
Subject: updates to with-mastodon-buffer macro

---
 lisp/mastodon-profile.el | 31 ++++++++++++++-----------------
 lisp/mastodon-search.el  | 33 +++++++++++++++------------------
 lisp/mastodon-tl.el      | 16 +++++-----------
 lisp/mastodon-toot.el    | 45 +++++++++++++++++++++------------------------
 lisp/mastodon-views.el   | 45 +++++++++++++++++++++------------------------
 lisp/mastodon.el         | 13 +++++++++----
 6 files changed, 85 insertions(+), 98 deletions(-)

(limited to 'lisp/mastodon-views.el')

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
-- 
cgit v1.2.3


From 5970c9de908fbb8009de86a2371578de231b3cee Mon Sep 17 00:00:00 2001
From: marty hiatt <martianhiatus [a t] riseup [d o t] net>
Date: Sat, 6 May 2023 14:46:34 +0200
Subject: Revert "updates to with-mastodon-buffer macro"

This reverts commit 59e5e3ece54bcac36d9debad392bff25a31438b5.
---
 lisp/mastodon-profile.el | 31 ++++++++++++++------------
 lisp/mastodon-search.el  | 33 ++++++++++++++-------------
 lisp/mastodon-tl.el      | 58 ++++++++++++++++++++++++++----------------------
 lisp/mastodon-toot.el    | 45 +++++++++++++++++++------------------
 lisp/mastodon-views.el   | 45 +++++++++++++++++++------------------
 lisp/mastodon.el         | 16 +++++--------
 6 files changed, 120 insertions(+), 108 deletions(-)

(limited to 'lisp/mastodon-views.el')

diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 5bee7e9..fe7d7d2 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -494,19 +494,22 @@ 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-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)))))
+    (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)))))
 
 ;; PROFILE VIEW DETAILS
 
@@ -604,7 +607,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 #'mastodon-mode nil
+     buffer
      (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 26790ea..86ebb90 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 items trending on your instance.
+  "Display a list of tags 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,19 +119,22 @@ 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-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))))))
+    (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)))))))
 
 ;; functions for mastodon search
 
@@ -152,7 +155,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 #'mastodon-mode nil
+     buffer
      (mastodon-tl--set-buffer-spec buffer
                                    "api/v2/search"
                                    nil)
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index cef995d..759dde8 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1722,11 +1722,12 @@ ID is that of the toot to view."
     (if (equal (caar toot) 'error)
         (message "Error: %s" (cdar toot))
       (with-mastodon-buffer
-       buffer #'mastodon-mode nil
+       buffer
        (mastodon-tl--set-buffer-spec buffer
                                      (format "statuses/%s" id)
                                      nil)
-       (mastodon-tl--toot toot :detailed-p)))))
+       (let ((inhibit-read-only t))
+         (mastodon-tl--toot toot :detailed-p))))))
 
 (defun mastodon-tl--view-whole-thread ()
   "From a thread view, view entire thread.
@@ -1767,7 +1768,7 @@ view all branches of a thread."
                  0)
               ;; if we have a thread:
               (with-mastodon-buffer
-               buffer #'mastodon-mode nil
+               buffer
                (let ((marker (make-marker)))
                  (mastodon-tl--set-buffer-spec buffer
                                                endpoint
@@ -2582,20 +2583,20 @@ JSON and http headers, without it just the JSON."
 	    (message "Looks like nothing returned from endpoint: %s" endpoint)
       (let* ((headers (if headers (cdr response) nil))
              (link-header (mastodon-tl--get-link-header-from-response headers)))
-        (with-mastodon-buffer buffer
-          #'mastodon-mode nil
+        (with-mastodon-buffer
+          buffer
           (mastodon-tl--set-buffer-spec buffer
                                         endpoint
                                         update-function
                                         link-header
                                         update-params
                                         hide-replies)
-          (funcall update-function json)
           (setq
            ;; Initialize with a minimal interval; we re-scan at least once
            ;; every 5 minutes to catch any timestamps we may have missed
            mastodon-tl--timestamp-next-update (time-add (current-time)
                                                         (seconds-to-time 300)))
+          (funcall update-function json)
           (setq mastodon-tl--timestamp-update-timer
                 (when mastodon-tl--enable-relative-timestamps
                   (run-at-time (time-to-seconds
@@ -2623,26 +2624,31 @@ 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 nil
-     (setq
-      ;; Initialize with a minimal interval; we re-scan at least once
-      ;; every 5 minutes to catch any timestamps we may have missed
-      mastodon-tl--timestamp-next-update (time-add (current-time)
-                                                   (seconds-to-time 300)))
-     (funcall update-function json)
-     (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args)
-     (setq mastodon-tl--timestamp-update-timer
-           (when mastodon-tl--enable-relative-timestamps
-             (run-at-time (time-to-seconds
-                           (time-subtract mastodon-tl--timestamp-next-update
-                                          (current-time)))
-                          nil ;; don't repeat
-                          #'mastodon-tl--update-timestamps-callback
-                          (current-buffer)
-                          nil)))
-     (unless (mastodon-tl--profile-buffer-p)
-       ;; FIXME: this breaks test (because test has empty buffer)
-       (mastodon-tl--goto-first-item)))
+      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)
+      (setq
+       ;; Initialize with a minimal interval; we re-scan at least once
+       ;; every 5 minutes to catch any timestamps we may have missed
+       mastodon-tl--timestamp-next-update (time-add (current-time)
+                                                    (seconds-to-time 300)))
+      (funcall update-function json)
+      (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args)
+      (setq mastodon-tl--timestamp-update-timer
+            (when mastodon-tl--enable-relative-timestamps
+              (run-at-time (time-to-seconds
+                            (time-subtract mastodon-tl--timestamp-next-update
+                                           (current-time)))
+                           nil ;; don't repeat
+                           #'mastodon-tl--update-timestamps-callback
+                           (current-buffer)
+                           nil)))
+      (unless (mastodon-tl--profile-buffer-p)
+        ;; FIXME: this breaks test (because test has empty buffer)
+        (mastodon-tl--goto-first-item)))
     buffer))
 
 (provide 'mastodon-tl)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 1265132..5f9e6eb 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -902,27 +902,30 @@ instance to edit a toot."
   (interactive)
   (let ((id (mastodon-tl--property 'base-toot-id))
         (history (mastodon-tl--property 'edit-history)))
-    (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))))
+    (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)))))
 
 (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 8585bb0..7481fc3 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -799,27 +799,30 @@ INSTANCE is the instance were are working with."
     (let* ((domain (url-file-nondirectory instance))
            (buf (get-buffer-create
                  (format "*mastodon-instance-%s*" domain))))
-      (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))))))
+      (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)))))))
 
 (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 1fcb234..6b6ab9c 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -256,20 +256,14 @@ 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 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 t)
-           (indent defun))
+(defmacro with-mastodon-buffer (buffer &rest body)
+  "Evaluate BODY in a new `mastodon-mode' buffer called BUFFER."
+  (declare (debug 'body))
   `(with-current-buffer (get-buffer-create ,buffer)
      (let ((inhibit-read-only t))
        (erase-buffer)
-       (if ,other-window
-           (switch-to-buffer-other-window ,buffer)
-         (switch-to-buffer ,buffer))
-       (funcall ,mode-fun)
+       (switch-to-buffer ,buffer)
+       (mastodon-mode)
        ,@body)))
 
 
-- 
cgit v1.2.3


From aa6e9c55152ac1301efbdbdce9aa7fc3e8fea7c9 Mon Sep 17 00:00:00 2001
From: marty hiatt <martianhiatus [a t] riseup [d o t] net>
Date: Sat, 6 May 2023 16:00:00 +0200
Subject: eval-when-compile for with-mastodon-buffer, and re-indent

---
 lisp/mastodon-profile.el | 197 +++++++++++++++++++++++------------------------
 lisp/mastodon-search.el  |  81 ++++++++++---------
 lisp/mastodon-tl.el      |  90 +++++++++++-----------
 lisp/mastodon-toot.el    |  45 +++++------
 lisp/mastodon-views.el   |  43 ++++++-----
 5 files changed, 226 insertions(+), 230 deletions(-)

(limited to 'lisp/mastodon-views.el')

diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 5bee7e9..b4812d7 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -38,8 +38,9 @@
 (require 'cl-lib)
 (require 'persist)
 (require 'parse-time)
+(eval-when-compile
+  (require 'mastodon-tl))
 
-(autoload 'with-mastodon-buffer "mastodon")
 (autoload 'mastodon-auth--get-account-id "mastodon-auth")
 (autoload 'mastodon-auth--get-account-name "mastodon-auth.el")
 (autoload 'mastodon-http--api "mastodon-http.el")
@@ -494,19 +495,18 @@ 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-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)))))
+    (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
 
@@ -603,91 +603,90 @@ HEADERS means also fetch link headers for pagination."
          (fields (mastodon-profile--fields-get account))
          (pinned (mastodon-profile--get-statuses-pinned account))
          (joined (mastodon-profile--account-field account 'created_at)))
-    (with-mastodon-buffer
-     buffer #'mastodon-mode nil
-     (mastodon-profile-mode)
-     (setq mastodon-profile--account account)
-     (mastodon-tl--set-buffer-spec buffer
-                                   endpoint
-                                   update-function
-                                   link-header)
-     (let* ((inhibit-read-only t)
-            (is-statuses (string= endpoint-type "statuses"))
-            (is-followers (string= endpoint-type "followers"))
-            (is-following (string= endpoint-type "following"))
-            (endpoint-name (cond
-                            (is-statuses (if no-reblogs
-                                             "  TOOTS (no boosts)"
-                                           "    TOOTS    "))
-                            (is-followers "  FOLLOWERS  ")
-                            (is-following "  FOLLOWING  "))))
-       (insert
-        (propertize
-         (concat
-          "\n"
-          (mastodon-profile--image-from-account account 'avatar_static)
-          (mastodon-profile--image-from-account account 'header_static)
-          "\n"
-          (propertize (mastodon-profile--account-field
-                       account 'display_name)
-                      'face 'mastodon-display-name-face)
-          "\n"
-          (propertize (concat "@" acct)
-                      'face 'default)
-          (if (equal locked t)
-              (concat " " (mastodon-tl--symbol 'locked))
-            "")
-          "\n " mastodon-tl--horiz-bar "\n"
-          ;; profile note:
-          ;; account here to enable tab-stops in profile note
-          (mastodon-tl--render-text note account)
-          ;; meta fields:
-          (if fields
-              (concat "\n"
-                      (mastodon-tl--set-face
-                       (mastodon-profile--fields-insert fields)
-                       'success))
-            "")
-          "\n"
-          ;; Joined date:
-          (propertize
-           (mastodon-profile--format-joined-date-string joined)
-           'face 'success)
-          "\n\n")
-         'profile-json account)
-        ;; insert counts
-        (mastodon-tl--set-face
-         (concat " " mastodon-tl--horiz-bar "\n"
-                 " TOOTS: " toots-count " | "
-                 "FOLLOWERS: " followers-count " | "
-                 "FOLLOWING: " following-count "\n"
-                 " " mastodon-tl--horiz-bar "\n\n")
-         'success)
-        ;; insert relationship (follows)
-        (if followsp
-            (mastodon-tl--set-face
-             (concat (when (equal follows-you 't)
-                       " | FOLLOWS YOU")
-                     (when (equal followed-by-you 't)
-                       " | FOLLOWED BY YOU")
-                     (when (equal requested-you 't)
-                       " | REQUESTED TO FOLLOW YOU")
-                     "\n\n")
-             'success)
-          "") ; if no followsp we still need str-or-char-p for insert
-        ;; insert endpoint
-        (mastodon-tl--set-face
-         (concat " " mastodon-tl--horiz-bar "\n"
-                 endpoint-name "\n"
-                 " " mastodon-tl--horiz-bar "\n")
-         'success))
-       (setq mastodon-tl--update-point (point))
-       (mastodon-media--inline-images (point-min) (point))
-       ;; insert pinned toots first
-       (when (and pinned (equal endpoint-type "statuses"))
-         (mastodon-profile--insert-statuses-pinned pinned)
-         (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots
-       (funcall update-function json)))
+    (with-mastodon-buffer buffer #'mastodon-mode nil
+      (mastodon-profile-mode)
+      (setq mastodon-profile--account account)
+      (mastodon-tl--set-buffer-spec buffer
+                                    endpoint
+                                    update-function
+                                    link-header)
+      (let* ((inhibit-read-only t)
+             (is-statuses (string= endpoint-type "statuses"))
+             (is-followers (string= endpoint-type "followers"))
+             (is-following (string= endpoint-type "following"))
+             (endpoint-name (cond
+                             (is-statuses (if no-reblogs
+                                              "  TOOTS (no boosts)"
+                                            "    TOOTS    "))
+                             (is-followers "  FOLLOWERS  ")
+                             (is-following "  FOLLOWING  "))))
+        (insert
+         (propertize
+          (concat
+           "\n"
+           (mastodon-profile--image-from-account account 'avatar_static)
+           (mastodon-profile--image-from-account account 'header_static)
+           "\n"
+           (propertize (mastodon-profile--account-field
+                        account 'display_name)
+                       'face 'mastodon-display-name-face)
+           "\n"
+           (propertize (concat "@" acct)
+                       'face 'default)
+           (if (equal locked t)
+               (concat " " (mastodon-tl--symbol 'locked))
+             "")
+           "\n " mastodon-tl--horiz-bar "\n"
+           ;; profile note:
+           ;; account here to enable tab-stops in profile note
+           (mastodon-tl--render-text note account)
+           ;; meta fields:
+           (if fields
+               (concat "\n"
+                       (mastodon-tl--set-face
+                        (mastodon-profile--fields-insert fields)
+                        'success))
+             "")
+           "\n"
+           ;; Joined date:
+           (propertize
+            (mastodon-profile--format-joined-date-string joined)
+            'face 'success)
+           "\n\n")
+          'profile-json account)
+         ;; insert counts
+         (mastodon-tl--set-face
+          (concat " " mastodon-tl--horiz-bar "\n"
+                  " TOOTS: " toots-count " | "
+                  "FOLLOWERS: " followers-count " | "
+                  "FOLLOWING: " following-count "\n"
+                  " " mastodon-tl--horiz-bar "\n\n")
+          'success)
+         ;; insert relationship (follows)
+         (if followsp
+             (mastodon-tl--set-face
+              (concat (when (equal follows-you 't)
+                        " | FOLLOWS YOU")
+                      (when (equal followed-by-you 't)
+                        " | FOLLOWED BY YOU")
+                      (when (equal requested-you 't)
+                        " | REQUESTED TO FOLLOW YOU")
+                      "\n\n")
+              'success)
+           "") ; if no followsp we still need str-or-char-p for insert
+         ;; insert endpoint
+         (mastodon-tl--set-face
+          (concat " " mastodon-tl--horiz-bar "\n"
+                  endpoint-name "\n"
+                  " " mastodon-tl--horiz-bar "\n")
+          'success))
+        (setq mastodon-tl--update-point (point))
+        (mastodon-media--inline-images (point-min) (point))
+        ;; insert pinned toots first
+        (when (and pinned (equal endpoint-type "statuses"))
+          (mastodon-profile--insert-statuses-pinned pinned)
+          (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots
+        (funcall update-function json)))
     (goto-char (point-min))))
 
 (defun mastodon-profile--format-joined-date-string (joined)
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index 26790ea..a6b4492 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -29,13 +29,14 @@
 
 ;;; Code:
 (require 'json)
+(eval-when-compile
+  (require 'mastodon-tl))
 
 (autoload 'mastodon-auth--access-token "mastodon-auth")
 (autoload 'mastodon-http--api "mastodon-http")
 (autoload 'mastodon-http--get-json "mastodon-http")
 (autoload 'mastodon-http--get-search-json "mastodon-http")
 (autoload 'mastodon-mode "mastodon")
-(autoload 'with-mastodon-buffer "mastodon")
 (autoload 'mastodon-tl--as-string "mastodon-tl")
 (autoload 'mastodon-tl--as-string "mastodon-tl")
 (autoload 'mastodon-tl--render-text "mastodon-tl")
@@ -119,19 +120,18 @@ 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-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))))))
+    (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
 
@@ -151,33 +151,32 @@ PRINT-FUN is the function used to print the data from the response."
                             tags))
          (toots-list-json
           (mastodon-search--get-full-statuses-data statuses)))
-    (with-mastodon-buffer
-     buffer #'mastodon-mode nil
-     (mastodon-tl--set-buffer-spec buffer
-                                   "api/v2/search"
-                                   nil)
-     ;; user results:
-     (insert (mastodon-tl--set-face
-              (concat "\n " mastodon-tl--horiz-bar "\n"
-                      " USERS\n"
-                      " " mastodon-tl--horiz-bar "\n\n")
-              'success))
-     (mastodon-search--insert-users-propertized accts :note)
-     ;; hashtag results:
-     (insert (mastodon-tl--set-face
-              (concat "\n " mastodon-tl--horiz-bar "\n"
-                      " HASHTAGS\n"
-                      " " mastodon-tl--horiz-bar "\n\n")
-              'success))
-     (mastodon-search--print-tags-list tags-list)
-     ;; status results:
-     (insert (mastodon-tl--set-face
-              (concat "\n " mastodon-tl--horiz-bar "\n"
-                      " STATUSES\n"
-                      " " mastodon-tl--horiz-bar "\n")
-              'success))
-     (mapc #'mastodon-tl--toot toots-list-json)
-     (goto-char (point-min)))))
+    (with-mastodon-buffer buffer #'mastodon-mode nil
+      (mastodon-tl--set-buffer-spec buffer
+                                    "api/v2/search"
+                                    nil)
+      ;; user results:
+      (insert (mastodon-tl--set-face
+               (concat "\n " mastodon-tl--horiz-bar "\n"
+                       " USERS\n"
+                       " " mastodon-tl--horiz-bar "\n\n")
+               'success))
+      (mastodon-search--insert-users-propertized accts :note)
+      ;; hashtag results:
+      (insert (mastodon-tl--set-face
+               (concat "\n " mastodon-tl--horiz-bar "\n"
+                       " HASHTAGS\n"
+                       " " mastodon-tl--horiz-bar "\n\n")
+               'success))
+      (mastodon-search--print-tags-list tags-list)
+      ;; status results:
+      (insert (mastodon-tl--set-face
+               (concat "\n " mastodon-tl--horiz-bar "\n"
+                       " STATUSES\n"
+                       " " mastodon-tl--horiz-bar "\n")
+               'success))
+      (mapc #'mastodon-tl--toot toots-list-json)
+      (goto-char (point-min)))))
 
 (defun mastodon-search--insert-users-propertized (json &optional note)
   "Insert users list into the buffer.
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index f62413f..3352b13 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1738,12 +1738,11 @@ ID is that of the toot to view."
                 (mastodon-http--api (concat "statuses/" id)))))
     (if (equal (caar toot) 'error)
         (message "Error: %s" (cdar toot))
-      (with-mastodon-buffer
-       buffer #'mastodon-mode nil
-       (mastodon-tl--set-buffer-spec buffer
-                                     (format "statuses/%s" id)
-                                     nil)
-       (mastodon-tl--toot toot :detailed-p)))))
+      (with-mastodon-buffer buffer #'mastodon-mode nil
+        (mastodon-tl--set-buffer-spec buffer
+                                      (format "statuses/%s" id)
+                                      nil)
+        (mastodon-tl--toot toot :detailed-p)))))
 
 (defun mastodon-tl--view-whole-thread ()
   "From a thread view, view entire thread.
@@ -1783,23 +1782,22 @@ view all branches of a thread."
                     (length (alist-get 'descendants context)))
                  0)
               ;; if we have a thread:
-              (with-mastodon-buffer
-               buffer #'mastodon-mode nil
-               (let ((marker (make-marker)))
-                 (mastodon-tl--set-buffer-spec buffer
-                                               endpoint
-                                               #'mastodon-tl--thread)
-                 (mastodon-tl--timeline (alist-get 'ancestors context)
-                                        :thread)
-                 (goto-char (point-max))
-                 (move-marker marker (point))
-                 ;; print re-fetched toot:
-                 (mastodon-tl--toot toot :detailed-p :thread)
-                 (mastodon-tl--timeline (alist-get 'descendants context)
-                                        :thread)
-                 ;; put point at the toot:
-                 (goto-char (marker-position marker))
-                 (mastodon-tl--goto-next-toot)))
+              (with-mastodon-buffer buffer #'mastodon-mode nil
+                (let ((marker (make-marker)))
+                  (mastodon-tl--set-buffer-spec buffer
+                                                endpoint
+                                                #'mastodon-tl--thread)
+                  (mastodon-tl--timeline (alist-get 'ancestors context)
+                                         :thread)
+                  (goto-char (point-max))
+                  (move-marker marker (point))
+                  ;; print re-fetched toot:
+                  (mastodon-tl--toot toot :detailed-p :thread)
+                  (mastodon-tl--timeline (alist-get 'descendants context)
+                                         :thread)
+                  ;; put point at the toot:
+                  (goto-char (marker-position marker))
+                  (mastodon-tl--goto-next-toot)))
             ;; else just print the lone toot:
             (mastodon-tl--single-toot id)))))))
 
@@ -2596,11 +2594,10 @@ RESPONSE is the data returned from the server by
 JSON and http headers, without it just the JSON."
   (let ((json (if headers (car response) response)))
     (if (not json) ; praying this is right here, else try "\n[]"
-	    (message "Looks like nothing returned from endpoint: %s" endpoint)
+	(message "Looks like nothing returned from endpoint: %s" endpoint)
       (let* ((headers (if headers (cdr response) nil))
              (link-header (mastodon-tl--get-link-header-from-response headers)))
-        (with-mastodon-buffer buffer
-          #'mastodon-mode nil
+        (with-mastodon-buffer buffer #'mastodon-mode nil
           (mastodon-tl--set-buffer-spec buffer
                                         endpoint
                                         update-function
@@ -2639,27 +2636,26 @@ Optional arg NOTE-TYPE means only get that type of note."
          (url (mastodon-http--api endpoint))
          (buffer (concat "*mastodon-" buffer-name "*"))
          (json (mastodon-http--get-json url args)))
-    (with-mastodon-buffer
-     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
-      mastodon-tl--timestamp-next-update (time-add (current-time)
-                                                   (seconds-to-time 300)))
-     (funcall update-function json)
-     (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args)
-     (setq mastodon-tl--timestamp-update-timer
-           (when mastodon-tl--enable-relative-timestamps
-             (run-at-time (time-to-seconds
-                           (time-subtract mastodon-tl--timestamp-next-update
-                                          (current-time)))
-                          nil ;; don't repeat
-                          #'mastodon-tl--update-timestamps-callback
-                          (current-buffer)
-                          nil)))
-     (unless (mastodon-tl--profile-buffer-p)
-       ;; FIXME: this breaks test (because test has empty buffer)
-       (mastodon-tl--goto-first-item)))
+    (with-mastodon-buffer 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
+       mastodon-tl--timestamp-next-update (time-add (current-time)
+                                                    (seconds-to-time 300)))
+      (funcall update-function json)
+      (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args)
+      (setq mastodon-tl--timestamp-update-timer
+            (when mastodon-tl--enable-relative-timestamps
+              (run-at-time (time-to-seconds
+                            (time-subtract mastodon-tl--timestamp-next-update
+                                           (current-time)))
+                           nil ;; don't repeat
+                           #'mastodon-tl--update-timestamps-callback
+                           (current-buffer)
+                           nil)))
+      (unless (mastodon-tl--profile-buffer-p)
+        ;; FIXME: this breaks test (because test has empty buffer)
+        (mastodon-tl--goto-first-item)))
     buffer))
 
 (provide 'mastodon-tl)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 1265132..a2fa35f 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -44,13 +44,15 @@
 (require 'facemenu)
 (require 'text-property-search)
 
+(eval-when-compile
+  (require 'mastodon-tl))
+
 (defvar mastodon-instance-url)
 (defvar mastodon-tl--buffer-spec)
 (defvar mastodon-tl--enable-proportional-fonts)
 (defvar mastodon-profile-account-settings)
 
 (autoload 'iso8601-parse "iso8601")
-(autoload 'with-mastodon-buffer "mastodon")
 (autoload 'mastodon-auth--user-acct "mastodon-auth")
 (autoload 'mastodon-http--api "mastodon-http")
 (autoload 'mastodon-http--build-array-params-alist "mastodon-http")
@@ -902,27 +904,26 @@ instance to edit a toot."
   (interactive)
   (let ((id (mastodon-tl--property 'base-toot-id))
         (history (mastodon-tl--property 'edit-history)))
-    (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))))
+    (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 8585bb0..51e4bd6 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -36,6 +36,8 @@
 
 (require 'cl-lib)
 (require 'mastodon-http)
+(eval-when-compile
+  (require 'mastodon-tl))
 
 (defvar mastodon-mode-map)
 (defvar mastodon-tl--horiz-bar)
@@ -799,27 +801,26 @@ INSTANCE is the instance were are working with."
     (let* ((domain (url-file-nondirectory instance))
            (buf (get-buffer-create
                  (format "*mastodon-instance-%s*" domain))))
-      (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))))))
+      (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."
-- 
cgit v1.2.3