From 7bc512d546477d8399208fcdf9fa53540fb5cdae Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Apr 2023 12:02:00 +0200 Subject: variable pitch for toot compose buffer, but not for docs --- lisp/mastodon.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 980e31f..c29fd25 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -241,6 +241,20 @@ Use. e.g. \"%c\" for your locale's date and time format." '((t :inherit success)) "Face used for content warning.") +(defface mastodon-toot-docs-face + `((t :inherit font-lock-comment-face + :height 1.0 + :family ,(face-attribute 'default :family))) + "Face used for documentation in toot compose buffer. +If `mastodon-tl--enable-proportional-fonts' is changed, +mastodon.el needs to be re-loaded for this to be correctly set.") + +(defface mastodon-toot-docs-reply-text-face + `((t :inherit font-lock-comment-face + :family ,(face-attribute 'variable-pitch :family))) + "Face used for reply text in toot compose buffer. +See `mastodon-toot-display-orig-in-reply-buffer'.") + ;;;###autoload (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." -- cgit v1.2.3 From 5bb860d943cde9260ced8bc6eb9570d1dbb3273d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 15:42:05 +0200 Subject: flychecks --- lisp/mastodon-iso.el | 1 - lisp/mastodon-profile.el | 2 +- lisp/mastodon-views.el | 6 ++++-- lisp/mastodon.el | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-iso.el b/lisp/mastodon-iso.el index 341593c..909d3dd 100644 --- a/lisp/mastodon-iso.el +++ b/lisp/mastodon-iso.el @@ -3,7 +3,6 @@ ;; Copyright (C) 2022 Marty Hiatt ;; Author: Marty Hiatt ;; Version: 1.0.0 -;; Package-Requires: ((emacs "27.1") (request "0.3.0")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 7fb36ad..35a9ebb 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -6,7 +6,6 @@ ;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 -;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. @@ -78,6 +77,7 @@ (autoload 'mastodon-toot--get-max-toot-chars "mastodon-toot") (autoload 'mastodon-views--add-account-to-list "mastodon-views") +(defvar mastodon-tl--horiz-bar) (defvar mastodon-tl--update-point) (defvar mastodon-toot--max-toot-chars) (defvar mastodon-toot--visibility) 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)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index c29fd25..722e927 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -1,4 +1,4 @@ -;;; mastodon.el --- Client for fediverse services that implement the Mastodon API -*- lexical-binding: t -*- +;;; mastodon.el --- Client for fediverse services using Mastodon API -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2022 Marty Hiatt -- cgit v1.2.3 From 51f8b782ac6721939e20eca459fe88eb4304857c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 3 May 2023 21:29:27 +0200 Subject: with-mastodon-buffer macro --- lisp/mastodon-profile.el | 176 +++++++++++++++++++++++------------------------ lisp/mastodon-search.el | 58 ++++++++-------- lisp/mastodon-tl.el | 176 +++++++++++++++++++++-------------------------- lisp/mastodon.el | 10 +++ 4 files changed, 202 insertions(+), 218 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 35a9ebb..fe7d7d2 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -39,6 +39,7 @@ (require 'persist) (require 'parse-time) +(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") @@ -605,95 +606,92 @@ 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-current-buffer (get-buffer-create buffer) - (let ((inhibit-read-only t)) - (switch-to-buffer buffer) - (erase-buffer) - (mastodon-mode) - (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))))) + (with-mastodon-buffer + buffer + (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) "Format a human-readable Joined string from timestamp JOINED. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 8cfa3cb..86ebb90 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -35,6 +35,7 @@ (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") @@ -153,36 +154,33 @@ 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-current-buffer (get-buffer-create buffer) - (switch-to-buffer buffer) - (mastodon-mode) - (let ((inhibit-read-only t)) - (erase-buffer) - (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-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 f72c6fb..ed1940b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -42,6 +42,7 @@ (autoload 'mastodon-mode "mastodon") (autoload 'mastodon-notifications-get "mastodon") (autoload 'mastodon-url-lookup "mastodon") +(autoload 'with-mastodon-buffer "mastodon") (autoload 'mastodon-auth--get-account-id "mastodon-auth") (autoload 'mastodon-auth--get-account-name "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") @@ -1709,16 +1710,13 @@ 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-current-buffer (get-buffer-create buffer) - (let ((inhibit-read-only t)) - (erase-buffer) - (switch-to-buffer buffer) - (mastodon-mode) - (mastodon-tl--set-buffer-spec buffer - (format "statuses/%s" id) - nil) - (let ((inhibit-read-only t)) - (mastodon-tl--toot toot :detailed-p))))))) + (with-mastodon-buffer + buffer + (mastodon-tl--set-buffer-spec buffer + (format "statuses/%s" id) + nil) + (let ((inhibit-read-only t)) + (mastodon-tl--toot toot :detailed-p)))))) (defun mastodon-tl--view-whole-thread () "From a thread view, view entire thread. @@ -1758,27 +1756,23 @@ view all branches of a thread." (length (alist-get 'descendants context))) 0) ;; if we have a thread: - (progn - (with-current-buffer (get-buffer-create buffer) - (let ((inhibit-read-only t) - (marker (make-marker))) - (switch-to-buffer buffer) - (erase-buffer) - (mastodon-mode) - (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 + (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))))))) @@ -2572,44 +2566,31 @@ 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-current-buffer (get-buffer-create buffer) - (let ((inhibit-read-only t)) - (erase-buffer) - (switch-to-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 - link-header - update-params - hide-replies) - (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-mode) - (mastodon-tl--set-buffer-spec buffer - endpoint - update-function - link-header - update-params - hide-replies) - (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) - (mastodon-tl--goto-first-item)))))))) + (with-mastodon-buffer + buffer + (mastodon-tl--set-buffer-spec buffer + endpoint + update-function + link-header + update-params + hide-replies) + (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 + (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) + (mastodon-tl--goto-first-item))))))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -2625,36 +2606,33 @@ 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-current-buffer (get-buffer-create buffer) - (let ((inhibit-read-only t)) - (erase-buffer) - (switch-to-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) - (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-mode) - (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))) + (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) + (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) ;;; mastodon-tl.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 722e927..fca376d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -255,6 +255,16 @@ 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." + (declare (debug 'body)) + `(with-current-buffer (get-buffer-create ,buffer) + (let ((inhibit-read-only t)) + (erase-buffer) + (switch-to-buffer ,buffer) + (mastodon-mode) + ,@body))) + ;;;###autoload (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." -- cgit v1.2.3 From 59e5e3ece54bcac36d9debad392bff25a31438b5 Mon Sep 17 00:00:00 2001 From: marty hiatt 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.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 e9feadee56f66d34bf4711ff792d537b3e1b9f64 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:31:08 +0200 Subject: remove old var-pitch-mode code --- lisp/mastodon-toot.el | 10 ---------- lisp/mastodon.el | 4 +--- 2 files changed, 1 insertion(+), 13 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index dd8d032..ec4a0d1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1701,8 +1701,6 @@ EDIT means we are editing an existing toot, not composing a new one." (point-marker)))) (switch-to-buffer-other-window buffer) (text-mode) - (when mastodon-toot--enable-proportional-fonts-compose-buffer - (variable-pitch-mode)) (mastodon-toot-mode t) (setq mastodon-toot--visibility (or (plist-get mastodon-profile-account-settings 'privacy) @@ -1764,14 +1762,6 @@ EDIT means we are editing an existing toot, not composing a new one." (lambda () (auto-fill-mode -1))) -;; scale fixed-pitch docs relative to any possible variable pitch scaling set: -(add-hook 'mastodon-toot-mode-hook - (lambda () - (when mastodon-toot--enable-proportional-fonts-compose-buffer - (let ((height (/ 1 (face-attribute 'variable-pitch :height)))) - (set-face-attribute 'mastodon-toot-docs-face nil - :height height))))) - (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." :keymap mastodon-toot-mode-map diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f52579c..4662010 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -242,9 +242,7 @@ Use. e.g. \"%c\" for your locale's date and time format." "Face used for content warning.") (defface mastodon-toot-docs-face - `((t :inherit font-lock-comment-face - :height 1.0 - :family ,(face-attribute 'default :family))) + `((t :inherit font-lock-comment-face)) "Face used for documentation in toot compose buffer. If `mastodon-tl--enable-proportional-fonts' is changed, mastodon.el needs to be re-loaded for this to be correctly set.") -- cgit v1.2.3 From a411879809215d09520e3a7c21d3f07a3f2b5272 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 16:59:29 +0200 Subject: wrap commentary --- lisp/mastodon.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 4662010..36cb058 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -29,8 +29,11 @@ ;;; Commentary: -;; mastodon.el is a client for fediverse services that implement the Mastodon API. See . -;; See the readme file at https://codeberg.org/martianh/mastodon.el for set up and usage details. +;; mastodon.el is a client for fediverse services that implement the Mastodon +;; API. See . + +;; See the readme file at https://codeberg.org/martianh/mastodon.el for set up +;; and usage details. ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon -- cgit v1.2.3 From c7446f48e5e8378a2240959dbf7fcd66a7de44e7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 14:40:19 +0200 Subject: with-masto-buffer declare --- lisp/mastodon.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 36cb058..1fcb234 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -261,7 +261,8 @@ See `mastodon-toot-display-orig-in-reply-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)) + (declare (debug t) + (indent defun)) `(with-current-buffer (get-buffer-create ,buffer) (let ((inhibit-read-only t)) (erase-buffer) @@ -271,6 +272,7 @@ than `switch-to-buffer'." (funcall ,mode-fun) ,@body))) + ;;;###autoload (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." -- cgit v1.2.3 From 5970c9de908fbb8009de86a2371578de231b3cee Mon Sep 17 00:00:00 2001 From: marty hiatt 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.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 7ca70346ac60436c359a754de56842fdc7280fe3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 14:47:31 +0200 Subject: Revert "with-mastodon-buffer macro" This reverts commit 51f8b782ac6721939e20eca459fe88eb4304857c. --- lisp/mastodon-profile.el | 176 ++++++++++++++++++++++++----------------------- lisp/mastodon-search.el | 58 ++++++++-------- lisp/mastodon-tl.el | 176 ++++++++++++++++++++++++++--------------------- lisp/mastodon.el | 11 --- 4 files changed, 218 insertions(+), 203 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index fe7d7d2..35a9ebb 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -39,7 +39,6 @@ (require 'persist) (require 'parse-time) -(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") @@ -606,92 +605,95 @@ 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-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)))) + (with-current-buffer (get-buffer-create buffer) + (let ((inhibit-read-only t)) + (switch-to-buffer buffer) + (erase-buffer) + (mastodon-mode) + (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) "Format a human-readable Joined string from timestamp JOINED. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 86ebb90..8cfa3cb 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -35,7 +35,6 @@ (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") @@ -154,33 +153,36 @@ 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-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-current-buffer (get-buffer-create buffer) + (switch-to-buffer buffer) + (mastodon-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (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 759dde8..5797f7b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -42,7 +42,6 @@ (autoload 'mastodon-mode "mastodon") (autoload 'mastodon-notifications-get "mastodon") (autoload 'mastodon-url-lookup "mastodon") -(autoload 'with-mastodon-buffer "mastodon") (autoload 'mastodon-auth--get-account-id "mastodon-auth") (autoload 'mastodon-auth--get-account-name "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") @@ -1721,13 +1720,16 @@ 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-tl--set-buffer-spec buffer - (format "statuses/%s" id) - nil) - (let ((inhibit-read-only t)) - (mastodon-tl--toot toot :detailed-p)))))) + (with-current-buffer (get-buffer-create buffer) + (let ((inhibit-read-only t)) + (erase-buffer) + (switch-to-buffer buffer) + (mastodon-mode) + (mastodon-tl--set-buffer-spec buffer + (format "statuses/%s" id) + nil) + (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,23 +1769,27 @@ view all branches of a thread." (length (alist-get 'descendants context))) 0) ;; if we have a thread: - (with-mastodon-buffer - buffer - (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))) + (progn + (with-current-buffer (get-buffer-create buffer) + (let ((inhibit-read-only t) + (marker (make-marker))) + (switch-to-buffer buffer) + (erase-buffer) + (mastodon-mode) + (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))))))) @@ -2583,31 +2589,44 @@ 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-tl--set-buffer-spec buffer - endpoint - update-function - link-header - update-params - hide-replies) - (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 - (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) - (mastodon-tl--goto-first-item))))))) + (with-current-buffer (get-buffer-create buffer) + (let ((inhibit-read-only t)) + (erase-buffer) + (switch-to-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 + link-header + update-params + hide-replies) + (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-mode) + (mastodon-tl--set-buffer-spec buffer + endpoint + update-function + link-header + update-params + hide-replies) + (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) + (mastodon-tl--goto-first-item)))))))) (defun mastodon-tl--init-sync (buffer-name endpoint update-function &optional note-type) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. @@ -2623,33 +2642,36 @@ 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 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)) + (with-current-buffer (get-buffer-create buffer) + (let ((inhibit-read-only t)) + (erase-buffer) + (switch-to-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) + (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-mode) + (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) ;;; mastodon-tl.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6b6ab9c..e181786 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -256,17 +256,6 @@ 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." - (declare (debug 'body)) - `(with-current-buffer (get-buffer-create ,buffer) - (let ((inhibit-read-only t)) - (erase-buffer) - (switch-to-buffer ,buffer) - (mastodon-mode) - ,@body))) - - ;;;###autoload (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." -- cgit v1.2.3 From ebb44f398037c3bd6aca1c85799ed353c44e9c3d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 11 May 2023 09:51:19 +0200 Subject: package header line edit --- lisp/mastodon.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index e181786..21bd763 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -1,4 +1,4 @@ -;;; mastodon.el --- Client for fediverse services using Mastodon API -*- lexical-binding: t -*- +;;; mastodon.el --- Client for fediverse services using the Mastodon API -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2022 Marty Hiatt -- cgit v1.2.3