diff options
-rw-r--r-- | lisp/mastodon-profile.el | 31 | ||||
-rw-r--r-- | lisp/mastodon-search.el | 33 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 58 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 45 | ||||
-rw-r--r-- | lisp/mastodon-views.el | 45 | ||||
-rw-r--r-- | lisp/mastodon.el | 16 |
6 files changed, 120 insertions, 108 deletions
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))) |