From ae3a9bcfb51499cdda854c7ef6cf5f7f1bb4401b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 15:59:05 +0200 Subject: v rough thread replies chain --- lisp/mastodon-tl.el | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 92ca02a..e76380f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -140,7 +140,8 @@ nil." (locked . ("🔒" . "[locked]")) (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) - (edited . ("✍" . "[edited]"))) + (edited . ("✍" . "[edited]")) + (replied . ("⬇" . "[replied]"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." @@ -1264,8 +1265,20 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--get-poll toot)) (mastodon-tl--media toot)))) +(defun mastodon-tl--prev-toot-id () + (let ((prev-pos (1- (save-excursion + (previous-single-property-change + (point) + 'base-toot-id))))) + (get-text-property prev-pos 'base-toot-id))) + +(defun mastodon-tl--after-reply-status (reply-to-id) + "" + (let ((prev-id (mastodon-tl--prev-toot-id))) + (string= reply-to-id prev-id))) + (defun mastodon-tl--insert-status (toot body author-byline action-byline - &optional id base-toot detailed-p) + &optional id base-toot detailed-p thread) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. AUTHOR-BYLINE is an optional function for adding the author @@ -1281,13 +1294,21 @@ status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. DETAILED-P means display more detailed info. For now this just means displaying toot client." - (let ((start-pos (point))) + (let* ((start-pos (point)) + (reply-to-id (alist-get 'in_reply_to_id toot)) + (after-reply-status-p + (when (and thread reply-to-id) + (mastodon-tl--after-reply-status reply-to-id)))) (insert (propertize - (concat "\n" - body - " \n" - (mastodon-tl--byline toot author-byline action-byline detailed-p)) + (concat + (if (and after-reply-status-p thread) + (concat (mastodon-tl--symbol 'replied) + "\n") + "") + body + " \n" + (mastodon-tl--byline toot author-byline action-byline detailed-p)) 'toot-id (or id ; notification's own id (alist-get 'id toot)) ; toot id 'base-toot-id (mastodon-tl--toot-id @@ -1363,7 +1384,7 @@ To disable showing the stats, customize (and (null (mastodon-tl--field 'in_reply_to_id toot)) (not (mastodon-tl--field 'rebloged toot)))) -(defun mastodon-tl--toot (toot &optional detailed-p) +(defun mastodon-tl--toot (toot &optional detailed-p thread) "Format TOOT and insert it into the buffer. DETAILED-P means display more detailed info. For now this just means displaying toot client." @@ -1377,12 +1398,14 @@ this just means displaying toot client." 'mastodon-tl--byline-boosted nil nil - detailed-p)) + detailed-p + thread)) -(defun mastodon-tl--timeline (toots) +(defun mastodon-tl--timeline (toots &optional thread) "Display each toot in TOOTS. This function removes replies if user required." - (mapc #'mastodon-tl--toot + (mapc (lambda (toot) + (mastodon-tl--toot toot nil thread)) ;; hack to *not* filter replies on profiles: (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) toots @@ -1739,12 +1762,14 @@ view all branches of a thread." (mastodon-tl--set-buffer-spec buffer endpoint #'mastodon-tl--thread) - (mastodon-tl--timeline (alist-get 'ancestors context)) + (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) - (mastodon-tl--timeline (alist-get 'descendants context)) + (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)))) -- cgit v1.2.3 From 00cb199457d2bd83ed16b296d5c858b291b900c3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 17:06:47 +0200 Subject: docstrings --- lisp/mastodon-tl.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e76380f..7b979d1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1266,6 +1266,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--media toot)))) (defun mastodon-tl--prev-toot-id () + "Return the id of the last toot inserted into the buffer." (let ((prev-pos (1- (save-excursion (previous-single-property-change (point) @@ -1273,7 +1274,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (get-text-property prev-pos 'base-toot-id))) (defun mastodon-tl--after-reply-status (reply-to-id) - "" + "T if REPLY-TO-ID is equal to that of the last toot inserted in the bufer." (let ((prev-id (mastodon-tl--prev-toot-id))) (string= reply-to-id prev-id))) @@ -1293,7 +1294,8 @@ attached as a `toot-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. DETAILED-P means display more detailed info. For now -this just means displaying toot client." +this just means displaying toot client. +THREAD means the status will be displayed in a thread view." (let* ((start-pos (point)) (reply-to-id (alist-get 'in_reply_to_id toot)) (after-reply-status-p @@ -1387,7 +1389,8 @@ To disable showing the stats, customize (defun mastodon-tl--toot (toot &optional detailed-p thread) "Format TOOT and insert it into the buffer. DETAILED-P means display more detailed info. For now -this just means displaying toot client." +this just means displaying toot client. +THREAD means the status will be displayed in a thread view." (mastodon-tl--insert-status toot (mastodon-tl--clean-tabs-and-nl @@ -1403,7 +1406,8 @@ this just means displaying toot client." (defun mastodon-tl--timeline (toots &optional thread) "Display each toot in TOOTS. -This function removes replies if user required." +This function removes replies if user required. +THREAD means the status will be displayed in a thread view." (mapc (lambda (toot) (mastodon-tl--toot toot nil thread)) ;; hack to *not* filter replies on profiles: @@ -1770,7 +1774,7 @@ view all branches of a thread." (mastodon-tl--toot toot :detailed-p :thread) (mastodon-tl--timeline (alist-get 'descendants context) :thread) - ;; put point at the toot: + ;; put point at the toot: (goto-char (marker-position marker)) (mastodon-tl--goto-next-toot)))) ;; else just print the lone toot: @@ -2123,7 +2127,8 @@ PREFIX is sent to `mastodon-tl--show-tag-timeline', which see." (defun mastodon-tl--some-followed-tags-timeline (&optional prefix) "Prompt for some tags, and open a timeline for them. -The suggestions are from followed tags, but any other tags are also allowed." +The suggestions are from followed tags, but any other tags are also allowed. +PREFIX us sent to `mastodon-tl--show-tag-timeline', which see." (interactive "p") (let* ((followed-tags-json (mastodon-tl--followed-tags)) (tags (mastodon-tl--map-alist 'name followed-tags-json)) -- cgit v1.2.3 From b4f463aaed526f637f9bd5d6aa494b9f195272c5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 17:06:53 +0200 Subject: no quasi-quotes for let-alist dots --- lisp/mastodon-tl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7b979d1..4082905 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2206,9 +2206,10 @@ report the account for spam." (defvar crm-separator) (defun mastodon-tl--map-rules-alist (rules) + "Return an alist of the text and id fields of RULES." (mapcar (lambda (x) (let-alist x - `(,.text . ,.id))) + (cons .text .id))) rules)) (defun mastodon-tl--read-rules-ids () -- cgit v1.2.3 From a3b2fcdc726874ff7e3e65db7a8d45f687017e18 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 28 Apr 2023 18:29:56 +0200 Subject: add commented example use of line-prefix prop --- lisp/mastodon-tl.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4082905..ce16f87 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1308,6 +1308,10 @@ THREAD means the status will be displayed in a thread view." (concat (mastodon-tl--symbol 'replied) "\n") "") + ;; (if (and after-reply-status-p thread) + ;; (propertize body + ;; 'line-prefix "|") + ;; body) body " \n" (mastodon-tl--byline toot author-byline action-byline detailed-p)) -- cgit v1.2.3 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-toot.el | 22 +++++++++++++++++++--- lisp/mastodon.el | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a3f337d..1a2a3cd 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -147,6 +147,12 @@ If the original toot visibility is different we use the more restricted one." "Whether to enable your instance's custom emoji by default." :type 'boolean) +(defcustom mastodon-toot--enable-proportional-fonts-compose-buffer nil + "Nonnil to enable using proportional fonts in the compose buffer. +By default fixed width fonts are used." + :type '(boolean :tag "Enable using proportional rather than fixed \ +width fonts")) + (defvar-local mastodon-toot--content-warning nil "A flag whether the toot should be marked with a content warning.") @@ -1452,7 +1458,7 @@ REPLY-TEXT is the text of the toot being replied to." (propertize "None " 'toot-attachments t) "\n") - 'face font-lock-comment-face + 'face 'mastodon-toot-docs-face 'read-only "Edit your message below." 'toot-post-header t) (if reply-text @@ -1461,12 +1467,12 @@ REPLY-TEXT is the text of the toot being replied to." mastodon-toot-orig-in-reply-length) 'read-only "Edit your message below." 'toot-post-header t - 'face '(variable-pitch :foreground "#7c6f64")) + 'face 'mastodon-toot-docs-reply-text-face) "") (propertize (concat divider "\n") 'rear-nonsticky t - 'face font-lock-comment-face + 'face 'mastodon-toot-docs-face 'read-only "Edit your message below." 'toot-post-header t)))) @@ -1680,6 +1686,8 @@ 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) @@ -1738,6 +1746,14 @@ 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 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 7c0bab3efe68aab790820fd7bb3914f8efc4913b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Apr 2023 12:02:34 +0200 Subject: newline after reply text in compose buffer --- lisp/mastodon-toot.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1a2a3cd..5dbdd05 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1462,12 +1462,14 @@ REPLY-TEXT is the text of the toot being replied to." 'read-only "Edit your message below." 'toot-post-header t) (if reply-text - (propertize (truncate-string-to-width - (mastodon-tl--render-text reply-text) - mastodon-toot-orig-in-reply-length) - 'read-only "Edit your message below." - 'toot-post-header t + (concat + (propertize (truncate-string-to-width + (mastodon-tl--render-text reply-text) + mastodon-toot-orig-in-reply-length) + 'read-only "Edit your message below." + 'toot-post-header t 'face 'mastodon-toot-docs-reply-text-face) + "\n") "") (propertize (concat divider "\n") -- cgit v1.2.3 From 9257595153a2fc9046f571cea3e88fb509936314 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Apr 2023 13:33:10 +0200 Subject: add line-prefix and wrap-prefix, ajust shr render width too --- lisp/mastodon-tl.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ce16f87..249e344 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -141,7 +141,8 @@ nil." (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) (edited . ("✍" . "[edited]")) - (replied . ("⬇" . "[replied]"))) + (replied . ("⬇" . "↓")) + (reply-bar . ("┃" . "|"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." @@ -750,7 +751,7 @@ links in the text. If TOOT is nil no parsing occurs." (insert string) (let ((shr-use-fonts mastodon-tl--enable-proportional-fonts) (shr-width (when mastodon-tl--enable-proportional-fonts - (- (window-width) 1)))) + (- (window-width) 3)))) (shr-render-region (point-min) (point-max))) ;; Make all links a tab stop recognized by our own logic, make things point ;; to our own logic (e.g. hashtags), and update keymaps where needed: @@ -1308,11 +1309,13 @@ THREAD means the status will be displayed in a thread view." (concat (mastodon-tl--symbol 'replied) "\n") "") - ;; (if (and after-reply-status-p thread) - ;; (propertize body - ;; 'line-prefix "|") - ;; body) - body + (if (and after-reply-status-p thread) + (let ((bar (mastodon-tl--symbol 'reply-bar))) + (propertize body + 'line-prefix bar + 'wrap-prefix bar)) + body) + ;; body " \n" (mastodon-tl--byline toot author-byline action-byline detailed-p)) 'toot-id (or id ; notification's own id -- cgit v1.2.3 From 3eb8b58152903fc74fba29dca9f1d69e45ba3e9f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 11:37:53 +0200 Subject: tl--mentions not interactive --- lisp/mastodon-toot.el | 1 - 1 file changed, 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a3f337d..4793dd9 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -956,7 +956,6 @@ eg. \"feduser@fed.social\" -> \"@feduser@fed.social\"." The mentioned users look like this: Local user (including the logged in): `username`. Federated user: `username@host.co`." - (interactive) (let* ((boosted (mastodon-tl--field 'reblog status)) (mentions (if boosted -- cgit v1.2.3 From 5e8774d67fff65bd7fd3e9caa4ca887690afcc92 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 11:42:19 +0200 Subject: tl--insert-status: restore initial \n --- lisp/mastodon-tl.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 249e344..ac15f7b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1305,6 +1305,7 @@ THREAD means the status will be displayed in a thread view." (insert (propertize (concat + "\n" (if (and after-reply-status-p thread) (concat (mastodon-tl--symbol 'replied) "\n") -- cgit v1.2.3 From 113727ccde7d753859d075200a807f1f81ac2481 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 11:51:16 +0200 Subject: handle 's after tag or mention --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 4793dd9..84248e5 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -219,14 +219,14 @@ send.") "\\([(\n\t ]\\|^\\)" "\\(?2:@[0-9a-zA-Z._-]+" ; a handle "\\(@[^ \n\t]*\\)?\\)" ; with poss domain, * = allow only @ - "\\b")) + "\\(\\b\\|'\\)")) ; boundary or ' char (defvar mastodon-toot-tag-regex (concat ;; preceding bracket, space or bol [boundary doesn't work with #] "\\([(\n\t ]\\|^\\)" "\\(?2:#[0-9a-zA-Z_]+\\)" ; tag - "\\b")) ; boundary + "\\(\\b\\|'\\)")) ; boundary or ' char (defvar mastodon-toot-url-regex ;; adapted from ffap-url-regexp -- cgit v1.2.3 From 6eff4da01e2fbf21b005dc867f290406bc5a7c5d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 15:36:05 +0200 Subject: docstring CW arg add --- lisp/mastodon-toot.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 269a9b4..d643e37 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1560,7 +1560,8 @@ REPLY-JSON is the full JSON of the toot being replied to." (defun mastodon-toot--count-toot-chars (toot-string &optional cw) "Count the characters in TOOT-STRING. URLs always = 23, and domain names of handles are not counted. -This is how mastodon does it." +This is how mastodon does it. +CW is the content warning, which contributes to the character count." (with-temp-buffer (switch-to-buffer (current-buffer)) (insert toot-string) -- 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(-) 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 84753be746df2bcaa66ff54a60e2dfc63c214826 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 16:30:37 +0200 Subject: remove redundant interactive calls --- lisp/mastodon-tl.el | 1 - lisp/mastodon-toot.el | 1 - 2 files changed, 2 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ac15f7b..be6609f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2317,7 +2317,6 @@ when showing followers or accounts followed." (defun mastodon-tl--more () "Append older toots to timeline, asynchronously." - (interactive) (message "Loading older toots...") (if (mastodon-tl--use-link-header-p) ;; link-header: can't build a URL with --more-json-async, endpoint/id: diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index d643e37..55e65eb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -335,7 +335,6 @@ boosting, or bookmarking toots." (defun mastodon-toot--toggle-boost-or-favourite (type) "Toggle boost or favourite of toot at `point'. TYPE is a symbol, either `favourite' or `boost.'" - (interactive) (mastodon-tl--do-if-toot-strict (let* ((boost-p (equal type 'boost)) (has-id (mastodon-tl--property 'base-toot-id)) -- cgit v1.2.3 From 91b5c03eb49c5bf6d1da00d6bf6f192b4a592f16 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Apr 2023 16:34:07 +0200 Subject: tl media adjust line breaks --- lisp/mastodon-tl.el | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index be6609f..ae51877 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1038,8 +1038,7 @@ message is a link which unhides/hides the main body." (defun mastodon-tl--media-attachment (media-attachment) "Return a propertized string for MEDIA-ATTACHMENT." - (let* ((preview-url - (alist-get 'preview_url media-attachment)) + (let* ((preview-url (alist-get 'preview_url media-attachment)) (remote-url (or (alist-get 'remote_url media-attachment) ;; fallback b/c notifications don't have remote_url @@ -1056,19 +1055,19 @@ message is a link which unhides/hides the main body." (mastodon-media--get-media-link-rendering preview-url remote-url type caption) ; 2nd arg for shr-browse-url ;; return URL/caption: - (concat - (mastodon-tl--propertize-img-str-or-url - (concat "Media:: " preview-url) ;; string - preview-url remote-url type caption - display-str ;; display - ;; FIXME: shr-link underlining is awful for captions with - ;; newlines, as the underlining runs to the edge of the - ;; frame even if the text doesn' - 'shr-link) - "\n")))) - -(defun mastodon-tl--propertize-img-str-or-url (str media-url full-remote-url type - help-echo &optional display face) + (concat (mastodon-tl--propertize-img-str-or-url + (concat "Media:: " preview-url) ;; string + preview-url remote-url type caption + display-str ;; display + ;; FIXME: shr-link underlining is awful for captions with + ;; newlines, as the underlining runs to the edge of the + ;; frame even if the text doesn' + 'shr-link) + "\n")))) + +(defun mastodon-tl--propertize-img-str-or-url (str media-url full-remote-url + type help-echo + &optional display face) "Propertize an media placeholder string \"[img]\" or media URL. STR is the string to propertize, MEDIA-URL is the preview link, FULL-REMOTE-URL is the link to the full resolution image on the -- cgit v1.2.3 From c15901d7a4092d70154faf3669bd9997d308dd02 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 2 May 2023 11:49:32 +0200 Subject: refactor format reply in compose str, propertize docs properly. FIX #448. --- lisp/mastodon-toot.el | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 55e65eb..dc50c01 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1420,6 +1420,19 @@ LONGEST is the length of the longest binding." longest-kbind) nil)))) +(defun mastodon-toot--format-reply-in-compose-string (reply-text) + "Format a REPLY-TEXT for display in compose buffer docs." + (let* ((rendered (mastodon-tl--render-text reply-text)) + (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered))) + (concat " Reply to:\n\"" + ;; (propertize + (truncate-string-to-width + no-newlines + mastodon-toot-orig-in-reply-length) + ;; overridden by containing propertize call: + ;; 'face 'mastodon-toot-docs-reply-text-face) + "...\"\n"))) + (defun mastodon-toot--display-docs-and-status-fields (&optional reply-text) "Insert propertized text with documentation about `mastodon-toot-mode'. Also includes and the status fields which will get updated based @@ -1454,22 +1467,12 @@ REPLY-TEXT is the text of the toot being replied to." " Attachments: " (propertize "None " 'toot-attachments t) + "\n" + (if reply-text + (mastodon-toot--format-reply-in-compose-string reply-text) + "") + divider "\n") - 'face 'mastodon-toot-docs-face - 'read-only "Edit your message below." - 'toot-post-header t) - (if reply-text - (concat - (propertize (truncate-string-to-width - (mastodon-tl--render-text reply-text) - mastodon-toot-orig-in-reply-length) - 'read-only "Edit your message below." - 'toot-post-header t - 'face 'mastodon-toot-docs-reply-text-face) - "\n") - "") - (propertize - (concat divider "\n") 'rear-nonsticky t 'face 'mastodon-toot-docs-face 'read-only "Edit your message below." -- cgit v1.2.3 From 4c1c25110ee759b67502bd8957ef01c3f2776a04 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 2 May 2023 21:28:56 +0200 Subject: don't try to boost direct/unlisted toots --- lisp/mastodon-toot.el | 66 +++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index dc50c01..a2735d6 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -356,37 +356,41 @@ TYPE is a symbol, either `favourite' or `boost.'" (visibility (mastodon-tl--field 'visibility (mastodon-tl--property 'toot-json)))) (if byline-region - (cond ;; actually there's nothing wrong with faving/boosting own toots! - ;;((mastodon-toot--own-toot-p (mastodon-tl--property 'toot-json)) - ;;(error "You can't %s your own toots" action-string)) - ;; & nothing wrong with faving/boosting own toots from notifs: - ;; this boosts/faves the base toot, not the notif status - ((and (equal "reblog" toot-type) - (not (mastodon-tl--buffer-type-eq 'notifications))) - (error "You can't %s boosts" action-string)) - ((and (equal "favourite" toot-type) - (not (mastodon-tl--buffer-type-eq 'notifications))) - (error "You can't %s favourites" action-string)) - ((and (equal "private" visibility) - (equal type 'boost)) - (error "You can't boost private toots")) - (t - (mastodon-toot--action - action - (lambda () - (let ((inhibit-read-only t)) - (add-text-properties (car byline-region) - (cdr byline-region) - (if boost-p - (list 'boosted-p (not boosted)) - (list 'favourited-p (not faved)))) - (mastodon-toot--update-stats-on-action type remove) - (mastodon-toot--action-success - (if boost-p - (mastodon-tl--symbol 'boost) - (mastodon-tl--symbol 'favourite)) - byline-region remove)) - (message (format "%s #%s" (if boost-p msg action) id)))))) + (if (and (or (equal visibility "direct") + (equal visibility "unlisted")) + boost-p) + (message "You cant boost posts with visibility: %s" visibility) + (cond ;; actually there's nothing wrong with faving/boosting own toots! + ;;((mastodon-toot--own-toot-p (mastodon-tl--property 'toot-json)) + ;;(error "You can't %s your own toots" action-string)) + ;; & nothing wrong with faving/boosting own toots from notifs: + ;; this boosts/faves the base toot, not the notif status + ((and (equal "reblog" toot-type) + (not (mastodon-tl--buffer-type-eq 'notifications))) + (error "You can't %s boosts" action-string)) + ((and (equal "favourite" toot-type) + (not (mastodon-tl--buffer-type-eq 'notifications))) + (error "You can't %s favourites" action-string)) + ((and (equal "private" visibility) + (equal type 'boost)) + (error "You can't boost private toots")) + (t + (mastodon-toot--action + action + (lambda () + (let ((inhibit-read-only t)) + (add-text-properties (car byline-region) + (cdr byline-region) + (if boost-p + (list 'boosted-p (not boosted)) + (list 'favourited-p (not faved)))) + (mastodon-toot--update-stats-on-action type remove) + (mastodon-toot--action-success + (if boost-p + (mastodon-tl--symbol 'boost) + (mastodon-tl--symbol 'favourite)) + byline-region remove)) + (message (format "%s #%s" (if boost-p msg action) id))))))) (message (format "Nothing to %s here?!?" action-string)))))) (defun mastodon-toot--inc-or-dec (count subtract) -- cgit v1.2.3 From 651f9de82c65df131b3507361c62104592ffe3e6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 2 May 2023 21:31:40 +0200 Subject: typo --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a2735d6..9d44bfd 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -505,7 +505,7 @@ With FAVOURITE, list favouriters, else list boosters." (defun mastodon-toot--copy-toot-url () "Copy URL of toot at point. -If the toot is a fave/boost notification, copy the URLof the +If the toot is a fave/boost notification, copy the URL of the base toot." (interactive) (let* ((toot (or (mastodon-tl--property 'base-toot) -- cgit v1.2.3 From 718a12d2fc9c16f839735a8e238a01f3174be52e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 2 May 2023 21:28:50 +0200 Subject: comments --- lisp/mastodon-tl.el | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ae51877..f72c6fb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1601,14 +1601,9 @@ buffers that aren't strictly mastodon timelines." We hide replies if user explictly set the `mastodon-tl--hide-replies' or used PREFIX combination to open a timeline." - (and - ;; Only hide replies if we are in a proper timeline - (mastodon-tl--timeline-proper-p) - (or - ;; User configured to hide replies - mastodon-tl--hide-replies - ;; Timeline called with C-u prefix - (equal '(4) prefix)))) + (and (mastodon-tl--timeline-proper-p) ; Only if we are in a proper timeline + (or mastodon-tl--hide-replies ; User configured to hide replies + (equal '(4) prefix)))) ; Timeline called with C-u prefix ;;; UTILITIES -- 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(-) 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 c288bf386cd14abc018a976771b9fb00741f99ac Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 3 May 2023 22:04:58 +0200 Subject: no need to prompt/store media content-type. --- lisp/mastodon-toot.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9d44bfd..de05287 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1140,12 +1140,12 @@ text of the toot being replied to in the compose buffer." (mastodon-toot--refresh-attachments-display) (mastodon-toot--update-status-fields)) -(defun mastodon-toot--attach-media (file content-type description) - "Prompt for an attachment FILE of CONTENT-TYPE with DESCRIPTION. +(defun mastodon-toot--attach-media (file description) + "Prompt for an attachment FILE with DESCRIPTION. A preview is displayed in the new toot buffer, and the file is uploaded asynchronously using `mastodon-toot--upload-attached-media'. File is actually attached to the toot upon posting." - (interactive "fFilename: \nsContent type: \nsDescription: ") + (interactive "fFilename: \nsDescription: ") (when (>= (length mastodon-toot--media-attachments) 4) ;; Only a max. of 4 attachments are allowed, so pop the oldest one. (pop mastodon-toot--media-attachments)) @@ -1154,7 +1154,6 @@ File is actually attached to the toot upon posting." (setq mastodon-toot--media-attachments (nconc mastodon-toot--media-attachments `(((:contents . ,(mastodon-http--read-file-as-string file)) - (:content-type . ,content-type) (:description . ,description) (:filename . ,file))))) (mastodon-toot--refresh-attachments-display) @@ -1196,12 +1195,11 @@ which is used to attach it to a toot when posting." (when image-options 'imagemagick) nil) ; inbuilt scaling in 27.1 t image-options)) - (type (alist-get :content-type attachment)) (description (alist-get :description attachment))) (setq counter (1+ counter)) (list (format "\n %d: " counter) image - (format " \"%s\" (%s)" description type)))) + (format " \"%s\"" description)))) mastodon-toot--media-attachments)) (list "None"))) -- 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(-) 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 b0406630ccbefe50431f6ea1316857fe9674a2ec Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 11:54:52 +0200 Subject: hack to fill reply text in compose buffer. FIX #451. --- lisp/mastodon-toot.el | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 52c7914..05cd1fb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1468,7 +1468,9 @@ REPLY-TEXT is the text of the toot being replied to." 'toot-attachments t) "\n" (if reply-text - (mastodon-toot--format-reply-in-compose-string reply-text) + (propertize + (mastodon-toot--format-reply-in-compose-string reply-text) + 'toot-reply t) "") divider "\n") @@ -1665,6 +1667,16 @@ Added to `after-change-functions'." (or (mastodon-tl--buffer-type-eq 'edit-toot) (mastodon-tl--buffer-type-eq 'new-toot))) +(defun mastodon-toot--fill-reply-in-compose () + (save-excursion + (save-match-data + (goto-char (point-min)) + (let* ((fill-column 67) + (prop (text-property-search-forward 'toot-reply))) + (when prop + (fill-region (prop-match-beginning prop) + (point))))))) + ;; NB: now that we have toot drafts, to ensure offline composing remains ;; possible, avoid any direct requests here: (defun mastodon-toot--compose-buffer (&optional reply-to-user @@ -1697,9 +1709,11 @@ EDIT means we are editing an existing toot, not composing a new one." (mastodon-profile--get-source-pref 'privacy) "public")) ; fallback (unless buffer-exists - (mastodon-toot--display-docs-and-status-fields - (when mastodon-toot-display-orig-in-reply-buffer - reply-text)) + (if mastodon-toot-display-orig-in-reply-buffer + (progn + (mastodon-toot--display-docs-and-status-fields reply-text) + (mastodon-toot--fill-reply-in-compose)) + (mastodon-toot--display-docs-and-status-fields)) ;; `reply-to-user' (alone) is also used by `mastodon-tl--dm-user', so ;; perhaps we should not always call --setup-as-reply, or make its ;; workings conditional on reply-to-id. currently it only checks for -- cgit v1.2.3 From 3e95cd859045591ee31c229694fe8a957bce90ce Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 15:47:50 +0200 Subject: wrap reply in compose buffer --- lisp/mastodon-toot.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 05cd1fb..95b1c5f 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -130,7 +130,8 @@ You need to install company yourself to use this." "Display a copy of the toot replied to in the compose buffer." :type 'boolean) -(defcustom mastodon-toot-orig-in-reply-length 160 +(defcustom mastodon-toot-orig-in-reply-length 191 + ;; three lines of divider width: (- (* 3 67) (length " Reply to: ")) "Length to crop toot replied to in the compose buffer to." :type 'integer) @@ -1422,15 +1423,14 @@ LONGEST is the length of the longest binding." (defun mastodon-toot--format-reply-in-compose-string (reply-text) "Format a REPLY-TEXT for display in compose buffer docs." (let* ((rendered (mastodon-tl--render-text reply-text)) - (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered))) - (concat " Reply to:\n\"" - ;; (propertize - (truncate-string-to-width - no-newlines - mastodon-toot-orig-in-reply-length) - ;; overridden by containing propertize call: - ;; 'face 'mastodon-toot-docs-reply-text-face) - "...\"\n"))) + (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered)) + (crop (string-limit + (concat " Reply to: " no-newlines) + mastodon-toot-orig-in-reply-length))) + (if (> (length no-newlines) + (length crop)) ; we cropped: + (concat crop "\n") + no-newlines))) (defun mastodon-toot--display-docs-and-status-fields (&optional reply-text) "Insert propertized text with documentation about `mastodon-toot-mode'. -- cgit v1.2.3 From 9e1120be537fe7c7083aa2a386fe5feee5420432 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 15:48:06 +0200 Subject: wrap code --- lisp/mastodon-toot.el | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 95b1c5f..0f25db4 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1679,9 +1679,8 @@ Added to `after-change-functions'." ;; NB: now that we have toot drafts, to ensure offline composing remains ;; possible, avoid any direct requests here: -(defun mastodon-toot--compose-buffer (&optional reply-to-user - reply-to-id reply-json initial-text - edit) +(defun mastodon-toot--compose-buffer + (&optional reply-to-user reply-to-id reply-json initial-text edit) "Create a new buffer to capture text for a new toot. If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the `mastodon-toot--reply-to-id' var. @@ -1727,12 +1726,10 @@ EDIT means we are editing an existing toot, not composing a new one." (when mastodon-toot--enable-completion (set ; (setq-local (make-local-variable 'completion-at-point-functions) - (add-to-list - 'completion-at-point-functions - #'mastodon-toot--mentions-capf)) - (add-to-list - 'completion-at-point-functions - #'mastodon-toot--tags-capf) + (add-to-list 'completion-at-point-functions + #'mastodon-toot--mentions-capf)) + (add-to-list 'completion-at-point-functions + #'mastodon-toot--tags-capf) ;; company (when (and mastodon-toot--use-company-for-completion (require 'company nil :no-error)) @@ -1755,7 +1752,8 @@ EDIT means we are editing an existing toot, not composing a new one." (insert initial-text)))) ;;;###autoload -(add-hook 'mastodon-toot-mode-hook #'mastodon-profile--fetch-server-account-settings-maybe) +(add-hook 'mastodon-toot-mode-hook + #'mastodon-profile--fetch-server-account-settings-maybe) ;; disable auto-fill-mode: (add-hook 'mastodon-toot-mode-hook -- cgit v1.2.3 From 067270e5a9630817335dbdb28760324953597d1d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:15:36 +0200 Subject: pushnew not push in compose-buffer --- lisp/mastodon-toot.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 0f25db4..22f001d 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1739,13 +1739,13 @@ EDIT means we are editing an existing toot, not composing a new one." (company-mode-on))) ;; after-change: (make-local-variable 'after-change-functions) - (push #'mastodon-toot--update-status-fields after-change-functions) + (cl-pushnew #'mastodon-toot--update-status-fields after-change-functions) (mastodon-toot--refresh-attachments-display) (mastodon-toot--update-status-fields) ;; draft toot text saving: (setq mastodon-toot-current-toot-text nil) - (push #'mastodon-toot--save-toot-text after-change-functions) - (push #'mastodon-toot--propertize-tags-and-handles after-change-functions) + (cl-pushnew #'mastodon-toot--save-toot-text after-change-functions) + (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions) ;; if we set this before changing modes, it gets nuked: (setq mastodon-toot-previous-window-config previous-window-config) (when initial-text -- cgit v1.2.3 From a4e9c17cd4ee376d00f1c28ad760a599e3dd1595 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:29:52 +0200 Subject: in prop tags and handles: handle variable-pitch for reset props --- lisp/mastodon-toot.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 22f001d..73b9f1a 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1638,10 +1638,12 @@ Added to `after-change-functions'." (when (mastodon-toot--compose-buffer-p) (let ((header-region (mastodon-tl--find-property-range 'toot-post-header - (point-min)))) + (point-min))) + (face (when mastodon-toot--proportional-fonts-compose + 'variable-pitch))) ;; cull any prev props: ;; stops all text after a handle or mention being propertized: - (set-text-properties (cdr header-region) (point-max) nil) + (set-text-properties (cdr header-region) (point-max) `(face ,face)) ;; TODO: confirm allowed hashtag/handle characters: (mastodon-toot--propertize-item mastodon-toot-tag-regex 'success -- cgit v1.2.3 From 497c92aa55675b23b4a5f8a429f631795685482d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:30:34 +0200 Subject: var pitch if mastodon-toot--proportional-fonts-compose --- lisp/mastodon-toot.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 73b9f1a..dd8d032 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1750,6 +1750,8 @@ EDIT means we are editing an existing toot, not composing a new one." (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions) ;; if we set this before changing modes, it gets nuked: (setq mastodon-toot-previous-window-config previous-window-config) + (when mastodon-toot--proportional-fonts-compose + (facemenu-set-face 'variable-pitch)) (when initial-text (insert initial-text)))) -- 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(-) 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 0812e60c6fef4ff251f45689f02e3e67d55d9f46 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:31:21 +0200 Subject: rename prop fonts in compose buffer custom --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index ec4a0d1..42b083e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -148,7 +148,7 @@ If the original toot visibility is different we use the more restricted one." "Whether to enable your instance's custom emoji by default." :type 'boolean) -(defcustom mastodon-toot--enable-proportional-fonts-compose-buffer nil +(defcustom mastodon-toot--proportional-fonts-compose nil "Nonnil to enable using proportional fonts in the compose buffer. By default fixed width fonts are used." :type '(boolean :tag "Enable using proportional rather than fixed \ -- cgit v1.2.3 From 0100fde06e64a695ab07d770d144171671440ab1 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:41:51 +0200 Subject: reorder after-change in compose --- lisp/mastodon-toot.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 42b083e..763e334 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1740,12 +1740,13 @@ EDIT means we are editing an existing toot, not composing a new one." ;; after-change: (make-local-variable 'after-change-functions) (cl-pushnew #'mastodon-toot--update-status-fields after-change-functions) - (mastodon-toot--refresh-attachments-display) + (cl-pushnew #'mastodon-toot--save-toot-text after-change-functions) + (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions) (mastodon-toot--update-status-fields) + (mastodon-toot--propertize-tags-and-handles) + (mastodon-toot--refresh-attachments-display) ;; draft toot text saving: (setq mastodon-toot-current-toot-text nil) - (cl-pushnew #'mastodon-toot--save-toot-text after-change-functions) - (cl-pushnew #'mastodon-toot--propertize-tags-and-handles after-change-functions) ;; if we set this before changing modes, it gets nuked: (setq mastodon-toot-previous-window-config previous-window-config) (when mastodon-toot--proportional-fonts-compose -- cgit v1.2.3 From f6cc1eef9aba596fb8b7029a930d0f7dba9a0795 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 4 May 2023 20:47:38 +0200 Subject: remove comments and wrap code --- lisp/mastodon-toot.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 763e334..78291d0 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1424,9 +1424,8 @@ LONGEST is the length of the longest binding." "Format a REPLY-TEXT for display in compose buffer docs." (let* ((rendered (mastodon-tl--render-text reply-text)) (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered)) - (crop (string-limit - (concat " Reply to: " no-newlines) - mastodon-toot-orig-in-reply-length))) + (crop (string-limit (concat " Reply to: " no-newlines) + mastodon-toot-orig-in-reply-length))) (if (> (length no-newlines) (length crop)) ; we cropped: (concat crop "\n") @@ -1644,7 +1643,6 @@ Added to `after-change-functions'." ;; cull any prev props: ;; stops all text after a handle or mention being propertized: (set-text-properties (cdr header-region) (point-max) `(face ,face)) - ;; TODO: confirm allowed hashtag/handle characters: (mastodon-toot--propertize-item mastodon-toot-tag-regex 'success (cdr header-region)) -- cgit v1.2.3 From 61b3ae0a6751d2bbd495867e4a757c67a4f117a8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 08:05:56 +0200 Subject: wrap long lines in -tl.el --- lisp/mastodon-tl.el | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8fe12fa..78178c5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -421,7 +421,7 @@ With a double PREFIX arg, limit results to your own instance." "tags-multiple" (concat "tag-" tag)) (concat "timelines/tag/" (if (listp tag) - ;; endpoint needs to be /tag/:sometag + ;; endpoint must be /tag/:sth (car tag) tag)) 'mastodon-tl--timeline nil @@ -1149,9 +1149,13 @@ HELP-ECHO, DISPLAY, and FACE are the text properties to add." (let ((parsed (ts-human-duration (ts-diff (ts-parse timestamp) (ts-now))))) (cond ((> (plist-get parsed :days) 0) - (format "%s days, %s hours left" (plist-get parsed :days) (plist-get parsed :hours))) + (format "%s days, %s hours left" + (plist-get parsed :days) + (plist-get parsed :hours))) ((> (plist-get parsed :hours) 0) - (format "%s hours, %s minutes left" (plist-get parsed :hours) (plist-get parsed :minutes))) + (format "%s hours, %s minutes left" + (plist-get parsed :hours) + (plist-get parsed :minutes))) ((> (plist-get parsed :minutes) 0) (format "%s minutes left" (plist-get parsed :minutes))) (t ;; we failed to guess: @@ -1384,9 +1388,12 @@ To disable showing the stats, customize 'replies-field t 'replies-count replies-count 'face font-lock-comment-face))) - (status (concat - (propertize " " 'display `(space :align-to (- right ,(+ (length status) 7)))) - status))) + (status + (concat + (propertize " " + 'display + `(space :align-to (- right ,(+ (length status) 7)))) + status))) status))) (defun mastodon-tl--is-reply (toot) @@ -1594,7 +1601,8 @@ This includes the update profile note buffer, but not the preferences one." "Return non-nil if the current buffer is a 'proper' timeline. A proper timeline excludes notifications, threads, and other toot buffers that aren't strictly mastodon timelines." - (let ((timeline-buffers '(home federated local tag-timeline list-timeline profile-statuses))) + (let ((timeline-buffers + '(home federated local tag-timeline list-timeline profile-statuses))) (member (mastodon-tl--get-buffer-type) timeline-buffers))) (defun mastodon-tl--hide-replies-p (&optional prefix) @@ -2009,7 +2017,8 @@ Action must be either \"unblock\" or \"unmute\"." nil ; predicate t)))) -(defun mastodon-tl--do-user-action-and-response (user-handle action &optional negp notify langs) +(defun mastodon-tl--do-user-action-and-response + (user-handle action &optional negp notify langs) "Do ACTION on user USER-HANDLE. NEGP is whether the action involves un-doing something. If NOTIFY is \"true\", enable notifications when that user posts. @@ -2028,7 +2037,8 @@ LANGS is an array parameters alist of languages to filer user's posts by." (mastodon-profile--lookup-account-in-status user-handle (mastodon-profile--toot-json))))) (user-id (mastodon-profile--account-field account 'id)) - (name (if (not (string-empty-p (mastodon-profile--account-field account 'display_name))) + (name (if (not (string-empty-p + (mastodon-profile--account-field account 'display_name))) (mastodon-profile--account-field account 'display_name) (mastodon-profile--account-field account 'username))) (args (cond (notify @@ -2043,7 +2053,8 @@ LANGS is an array parameters alist of languages to filer user's posts by." (mastodon-tl--do-user-action-function url name user-handle action args))) (message "Cannot find a user with handle %S" user-handle)))) -(defun mastodon-tl--do-user-action-function (url name user-handle action &optional notify args) +(defun mastodon-tl--do-user-action-function + (url name user-handle action &optional notify args) "Post ACTION on user NAME/USER-HANDLE to URL. NOTIFY is either \"true\" or \"false\", and used when we have been called by `mastodon-tl--follow-user' to enable or disable notifications. @@ -2275,7 +2286,10 @@ POS is a number, where point will be placed." endpoint) (mastodon-tl--thread (match-string 2 endpoint)))))) - ;; TODO: sends point to POS, which was where point was in buffer before reload. This is very rough; we may have removed an item (deleted a toot, cleared a notif), so the buffer will be smaller, point will end up past where we were, etc. + ;; TODO: sends point to POS, which was where point was in buffer before + ;; reload. This is very rough; we may have removed an item (deleted a + ;; toot, cleared a notif), so the buffer will be smaller, point will end + ;; up past where we were, etc. (when pos (goto-char pos) (mastodon-tl--goto-prev-item)))) -- cgit v1.2.3 From 8438af1b33930acd17e3ca1b266eaccd8b2e381b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 08:31:34 +0200 Subject: help-echo for toot stats --- lisp/mastodon-tl.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 78178c5..7d48c12 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1377,16 +1377,19 @@ To disable showing the stats, customize (propertize favourites 'favourited-p favourited 'favourites-field t + 'help-echo (format "%s favourites" favourites-count) 'face font-lock-comment-face) (propertize " | " 'face font-lock-comment-face) (propertize boosts 'boosted-p boosted 'boosts-field t + 'help-echo (format "%s boosts" boosts-count) 'face font-lock-comment-face) (propertize " | " 'face font-lock-comment-face) (propertize replies 'replies-field t 'replies-count replies-count + 'help-echo (format "%s replies" replies-count) 'face font-lock-comment-face))) (status (concat -- cgit v1.2.3 From cde7c92d0b0c92fe0f997a1616453287d731af59 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 08:34:16 +0200 Subject: " " for reply in compose --- lisp/mastodon-toot.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 78291d0..1ee3215 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1424,8 +1424,9 @@ LONGEST is the length of the longest binding." "Format a REPLY-TEXT for display in compose buffer docs." (let* ((rendered (mastodon-tl--render-text reply-text)) (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered)) - (crop (string-limit (concat " Reply to: " no-newlines) - mastodon-toot-orig-in-reply-length))) + (crop (string-limit + (concat " Reply to: \"" no-newlines "\"") + mastodon-toot-orig-in-reply-length))) (if (> (length no-newlines) (length crop)) ; we cropped: (concat crop "\n") -- cgit v1.2.3 From ceee243b82c01b6c1b42cf1a703b7aeae455c713 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 09:25:12 +0200 Subject: fill reply in compose: handle multi paragraph reply text. --- lisp/mastodon-toot.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1ee3215..dd54ac2 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1669,12 +1669,12 @@ Added to `after-change-functions'." (mastodon-tl--buffer-type-eq 'new-toot))) (defun mastodon-toot--fill-reply-in-compose () + "Fill reply text in compose buffer to the width of the divider." (save-excursion (save-match-data - (goto-char (point-min)) - (let* ((fill-column 67) - (prop (text-property-search-forward 'toot-reply))) - (when prop + (let* ((fill-column 67)) + (goto-char (point-min)) + (while-let ((prop (text-property-search-forward 'toot-reply))) (fill-region (prop-match-beginning prop) (point))))))) -- cgit v1.2.3 From dce3b60783c02605ad7961f56bf41dd6bc91b51d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 09:25:32 +0200 Subject: flyspell ignore compose buffer items --- lisp/mastodon-toot.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index dd54ac2..f7441c6 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1753,6 +1753,24 @@ EDIT means we are editing an existing toot, not composing a new one." (when initial-text (insert initial-text)))) +;; flyspell ignore masto toot regexes: +(defvar flyspell-generic-check-word-predicate) +(defun mastodon-toot-mode-flyspell-verify () + "A predicate function for `flyspell'. +Only text that is not one of these faces will be spell-checked." + (let ((faces '(mastodon-display-name-face + mastodon-toot-docs-face font-lock-comment-face + success link))) + (unless (eql (point) (point-min)) + ;; (point) is next char after the word. Must check one char before. + (let ((f (get-text-property (1- (point)) 'face))) + (not (memq f faces)))))) + +(add-hook 'mastodon-toot-mode-hook + (lambda () + (setq flyspell-generic-check-word-predicate + 'mastodon-toot-mode-flyspell-verify))) + ;;;###autoload (add-hook 'mastodon-toot-mode-hook #'mastodon-profile--fetch-server-account-settings-maybe) -- cgit v1.2.3 From cf6b3f9f0cb8e9d9a879a18aaf574db835af5223 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 09:25:55 +0200 Subject: autoloads / requires --- lisp/mastodon-toot.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f7441c6..0aadd28 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -38,9 +38,12 @@ (defvar emojify-emojis-dir) (defvar emojify-user-emojis) +(require 'compat) (require 'cl-lib) (require 'persist) (require 'mastodon-iso) +(require 'facemenu) +(require 'text-property-search) (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -48,6 +51,7 @@ (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") @@ -1423,8 +1427,10 @@ LONGEST is the length of the longest binding." (defun mastodon-toot--format-reply-in-compose-string (reply-text) "Format a REPLY-TEXT for display in compose buffer docs." (let* ((rendered (mastodon-tl--render-text reply-text)) - (no-newlines (replace-regexp-in-string "\n\n" "\n" rendered)) - (crop (string-limit + (no-props (substring-no-properties rendered)) + (no-newlines (replace-regexp-in-string "\n\n" "" no-props)) + (crop (truncate-string-to-width + ;; (string-limit (concat " Reply to: \"" no-newlines "\"") mastodon-toot-orig-in-reply-length))) (if (> (length no-newlines) -- cgit v1.2.3 From ff51dc2fb2b66553825c0e5710373eb8db17319c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 10:34:33 +0200 Subject: fixes for reply in compose --- lisp/mastodon-toot.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 0aadd28..be2d0a3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1428,15 +1428,19 @@ LONGEST is the length of the longest binding." "Format a REPLY-TEXT for display in compose buffer docs." (let* ((rendered (mastodon-tl--render-text reply-text)) (no-props (substring-no-properties rendered)) - (no-newlines (replace-regexp-in-string "\n\n" "" no-props)) + ;; FIXME: this regex replaces \n at end of every post + ;; so we have to trim: + (no-newlines (string-trim + (replace-regexp-in-string "[\n]+" " " no-props))) + (reply-to (concat " Reply to: \"" no-newlines "\"")) (crop (truncate-string-to-width ;; (string-limit - (concat " Reply to: \"" no-newlines "\"") + reply-to mastodon-toot-orig-in-reply-length))) (if (> (length no-newlines) (length crop)) ; we cropped: (concat crop "\n") - no-newlines))) + (concat reply-to "\n")))) (defun mastodon-toot--display-docs-and-status-fields (&optional reply-text) "Insert propertized text with documentation about `mastodon-toot-mode'. -- cgit v1.2.3 From 49750e1081201293ad55598a503a0c137cc060bd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 10:35:47 +0200 Subject: revert while-let to when-let --- lisp/mastodon-toot.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index be2d0a3..1138888 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -38,7 +38,6 @@ (defvar emojify-emojis-dir) (defvar emojify-user-emojis) -(require 'compat) (require 'cl-lib) (require 'persist) (require 'mastodon-iso) @@ -1684,7 +1683,9 @@ Added to `after-change-functions'." (save-match-data (let* ((fill-column 67)) (goto-char (point-min)) - (while-let ((prop (text-property-search-forward 'toot-reply))) + ;; while-let shoulndn't be needed here, as we really should only have + ;; one. if we have more, the bug is elsewhere. + (when-let ((prop (text-property-search-forward 'toot-reply))) (fill-region (prop-match-beginning prop) (point))))))) -- cgit v1.2.3 From e6359f8459e20a65e7de4c5ad1b1b8ee05ea91b0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 5 May 2023 16:53:52 +0200 Subject: rx for handle/tag regexes --- lisp/mastodon-toot.el | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1138888..1265132 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -224,19 +224,15 @@ to also capture toots that are 'sent' but that don't successfully send.") (defvar mastodon-toot-handle-regex - (concat - ;; preceding bracket, space or bol [boundary doesn't work with @] - "\\([(\n\t ]\\|^\\)" - "\\(?2:@[0-9a-zA-Z._-]+" ; a handle - "\\(@[^ \n\t]*\\)?\\)" ; with poss domain, * = allow only @ - "\\(\\b\\|'\\)")) ; boundary or ' char + (rx (| (any ?\( "\n" "\t "" ") bol) ; preceding things + (group-n 2 (+ ?@ (* (any ?- ?_ ?. "A-Z" "a-z" "0-9" ))) ; handle + (? ?@ (* (not (any "\n" "\t" " "))))) ; optional domain + (| "'" word-boundary))) ; boundary or possessive (defvar mastodon-toot-tag-regex - (concat - ;; preceding bracket, space or bol [boundary doesn't work with #] - "\\([(\n\t ]\\|^\\)" - "\\(?2:#[0-9a-zA-Z_]+\\)" ; tag - "\\(\\b\\|'\\)")) ; boundary or ' char + (rx (| (any ?\( "\n" "\t" " ") bol) + (group-n 2 ?# (+ (any "A-Z" "a-z" "0-9"))) + (| "'" word-boundary))) ; boundary or possessive (defvar mastodon-toot-url-regex ;; adapted from ffap-url-regexp -- 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(-) 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(-) 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 4a4eaa48557c50c393af2a0b499023fad4474a24 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 14:40:28 +0200 Subject: init* reorder attempt to fix --- lisp/mastodon-tl.el | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7d48c12..cef995d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2579,34 +2579,34 @@ 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 - (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-mastodon-buffer buffer + #'mastodon-mode nil + (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))) + (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. -- 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(-) 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(-) 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 acde8c11694298a734da97be490856c025a96db8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 15:30:53 +0200 Subject: move with-masto-buffer to -tl.el --- lisp/mastodon-tl.el | 16 +++++++++++++++- lisp/mastodon.el | 17 ----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index cef995d..31c73a2 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") @@ -257,6 +256,21 @@ types of mastodon links and not just shr.el-generated ones.") "The keymap to be set for the author byline. It is active where point is placed by `mastodon-tl--goto-next-toot.'") + +;;; MACRO +(defmacro with-mastodon-buffer (buffer &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)) + `(with-current-buffer (get-buffer-create ,buffer) + (let ((inhibit-read-only t)) + (erase-buffer) + (switch-to-buffer ,buffer) + ,@body))) + ;;; NAV diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 1fcb234..e181786 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -256,23 +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 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)) - `(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) - ,@body))) - - ;;;###autoload (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." -- cgit v1.2.3 From 9bada1a9e3fe2e6a8691e17c697ac56d96eca359 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 15:59:11 +0200 Subject: restore old macro form --- lisp/mastodon-tl.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 31c73a2..f62413f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -258,17 +258,20 @@ It is active where point is placed by `mastodon-tl--goto-next-toot.'") ;;; MACRO -(defmacro with-mastodon-buffer (buffer &rest body) +(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)) + (indent 3)) `(with-current-buffer (get-buffer-create ,buffer) (let ((inhibit-read-only t)) (erase-buffer) - (switch-to-buffer ,buffer) + (funcall ,mode-fun) + (if ,other-window + (switch-to-buffer-other-window ,buffer) + (switch-to-buffer ,buffer)) ,@body))) -- cgit v1.2.3 From aa6e9c55152ac1301efbdbdce9aa7fc3e8fea7c9 Mon Sep 17 00:00:00 2001 From: marty hiatt 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(-) 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 From 3341d75817013a2f78445761f2e67e5f33aa371d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 17:07:45 +0200 Subject: macro heading --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ce3f8c3..99406ef 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -195,6 +195,7 @@ If nil `(point-min)' is used instead.") (if (char-displayable-p ?―) (make-string 12 ?―) (make-string 12 ?-))) + ;;; KEYMAPS @@ -257,7 +258,8 @@ types of mastodon links and not just shr.el-generated ones.") It is active where point is placed by `mastodon-tl--goto-next-toot.'") -;;; MACRO +;;; BUFFER MACRO + (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. -- cgit v1.2.3 From 46c9fabb917b31d34162ac2f7da35f1cb08004c0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 17:07:50 +0200 Subject: always use string= in get-buffer-type --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 99406ef..13d97a5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1583,11 +1583,11 @@ call this function after it is set or use something else." ((string-suffix-p "search" endpoint-fun) 'search) ;; trends - ((equal "api/v1/trends/statuses" endpoint-fun) + ((string= "api/v1/trends/statuses" endpoint-fun) 'trending-statuses) - ((equal "api/v1/trends/tags" endpoint-fun) + ((string= "api/v1/trends/tags" endpoint-fun) 'trending-tags) - ((equal "api/v1/trends/links" endpoint-fun) + ((string= "api/v1/trends/links" endpoint-fun) 'trending-links) ;; User's views: ((string= "filters" endpoint-fun) -- cgit v1.2.3 From 1410db49e7b21ba0cab397fc34b0ffbcdd084f4c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 17:47:23 +0200 Subject: useless refactor in tl--get-buffer-type --- lisp/mastodon-tl.el | 59 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 13d97a5..3d6f7cf 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1519,6 +1519,16 @@ HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer." ;;; BUFFERS +(defun mastodon-tl--endpoint-str-= (str &optional type) + "Return T if STR is equal to the current buffer's endpoint. +TYPE may be :prefix or :suffix, in which case, T if STR is a prefix or suffix." + (let ((endpoint-fun (mastodon-tl--get-endpoint nil :no-error))) + (cond ((eq type :prefix) + (string-prefix-p str endpoint-fun)) + ((eq type :suffix) + (string-suffix-p str endpoint-fun)) + (t + (string= str endpoint-fun))))) (defun mastodon-tl--get-buffer-type () "Return a symbol descriptive of current mastodon buffer type. @@ -1526,33 +1536,32 @@ Should work in all mastodon buffers. Note that for many buffers, this requires `mastodon-tl--buffer-spec' to be set. It is set for almost all buffers, but you still have to call this function after it is set or use something else." - (let ((endpoint-fun (mastodon-tl--get-endpoint nil :no-error)) - (buffer-name (mastodon-tl--buffer-name nil :no-error))) + (let ((buffer-name (mastodon-tl--buffer-name nil :no-error))) (cond (mastodon-toot-mode ;; composing/editing: (if (string= "*edit toot*" (buffer-name)) 'edit-toot 'new-toot)) ;; main timelines: - ((string= "timelines/home" endpoint-fun) + ((mastodon-tl--endpoint-str-= "timelines/home") 'home) ((string= "*mastodon-local*" buffer-name) 'local) - ((string= "timelines/public" endpoint-fun) + ((mastodon-tl--endpoint-str-= "timelines/public") 'federated) - ((string-prefix-p "timelines/tag/" endpoint-fun) + ((mastodon-tl--endpoint-str-= "timelines/tag/" :prefix) 'tag-timeline) - ((string-prefix-p "timelines/list/" endpoint-fun) + ((mastodon-tl--endpoint-str-= "timelines/list/" :prefix) 'list-timeline) ;; notifs: ((string-suffix-p "mentions*" buffer-name) 'mentions) - ((string= "notifications" endpoint-fun) + ((mastodon-tl--endpoint-str-= "notifications") 'notifications) ;; threads: - ((string-suffix-p "context" endpoint-fun) + ((mastodon-tl--endpoint-str-= "context" :suffix) 'thread) - ((string-prefix-p "statuses" endpoint-fun) + ((mastodon-tl--endpoint-str-= "statuses" :prefix) 'single-status) ;; profiles: ((mastodon-tl--profile-buffer-p) @@ -1569,43 +1578,43 @@ call this function after it is set or use something else." ;; posts inc. boosts: ((string-suffix-p "no-boosts*" buffer-name) 'profile-statuses-no-boosts) - ((string-suffix-p "statuses" endpoint-fun) + ((mastodon-tl--endpoint-str-= "statuses" :suffix) 'profile-statuses) ;; profile followers - ((string-suffix-p "followers" endpoint-fun) + ((mastodon-tl--endpoint-str-= "followers" :suffix) 'profile-followers) ;; profile following - ((string-suffix-p "following" endpoint-fun) + ((mastodon-tl--endpoint-str-= "following" :suffix) 'profile-following))) - ((string= "preferences" endpoint-fun) + ((mastodon-tl--endpoint-str-= "preferences") 'preferences) ;; search - ((string-suffix-p "search" endpoint-fun) + ((mastodon-tl--endpoint-str-= "search" :suffix) 'search) ;; trends - ((string= "api/v1/trends/statuses" endpoint-fun) + ((mastodon-tl--endpoint-str-= "api/v1/trends/statuses") 'trending-statuses) - ((string= "api/v1/trends/tags" endpoint-fun) + ((mastodon-tl--endpoint-str-= "api/v1/trends/tags") 'trending-tags) - ((string= "api/v1/trends/links" endpoint-fun) + ((mastodon-tl--endpoint-str-= "api/v1/trends/links") 'trending-links) ;; User's views: - ((string= "filters" endpoint-fun) + ((mastodon-tl--endpoint-str-= "filters") 'filters) - ((string= "lists" endpoint-fun) + ((mastodon-tl--endpoint-str-= "lists") 'lists) - ((string= "suggestions" endpoint-fun) + ((mastodon-tl--endpoint-str-= "suggestions") 'follow-suggestions) - ((string= "favourites" endpoint-fun) + ((mastodon-tl--endpoint-str-= "favourites") 'favourites) - ((string= "bookmarks" endpoint-fun) + ((mastodon-tl--endpoint-str-= "bookmarks") 'bookmarks) - ((string= "follow_requests" endpoint-fun) + ((mastodon-tl--endpoint-str-= "follow_requests") 'follow-requests) - ((string= "scheduled_statuses" endpoint-fun) + ((mastodon-tl--endpoint-str-= "scheduled_statuses") 'scheduled-statuses) ;; instance description - ((string= "instance" endpoint-fun) + ((mastodon-tl--endpoint-str-= "instance") 'instance-description) ((string= "*mastodon-toot-edits*" buffer-name) 'toot-edits)))) -- cgit v1.2.3 From c7afbef1ce48ba829b078388cbda5f79103f89c4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 19:53:38 +0200 Subject: ert-helper order for with-mastodon-buffer macro --- test/ert-helper.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ert-helper.el b/test/ert-helper.el index 9c85dfb..4e634b0 100644 --- a/test/ert-helper.el +++ b/test/ert-helper.el @@ -1,5 +1,6 @@ (load-file "lisp/mastodon-http.el") (load-file "lisp/mastodon-iso.el") +(load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-toot.el") (load-file "lisp/mastodon-search.el") (load-file "lisp/mastodon.el") @@ -11,7 +12,6 @@ (load-file "lisp/mastodon-media.el") (load-file "lisp/mastodon-notifications.el") (load-file "lisp/mastodon-profile.el") -(load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-async.el") ;; load tests in bulk to avoid using deprecated `cask exec' -- cgit v1.2.3 From 025d9945a5d3bdc9077095c772adef257c4e6e2f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 21:14:51 +0200 Subject: refactor next/prev tab item --- lisp/mastodon-tl.el | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3d6f7cf..ecefa66 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -279,7 +279,7 @@ than `switch-to-buffer'." ;;; NAV -(defun mastodon-tl--next-tab-item () +(defun mastodon-tl--next-tab-item (&optional previous) "Move to the next interesting item. This could be the next toot, link, or image; whichever comes first. Don't move if nothing else to move to is found, i.e. near the end of the buffer. @@ -287,11 +287,14 @@ This also skips tab items in invisible text, i.e. hidden spoiler text." (interactive) (let (next-range (search-pos (point))) - (while (and (setq next-range (mastodon-tl--find-next-or-previous-property-range - 'mastodon-tab-stop search-pos nil)) + (while (and (setq next-range + (mastodon-tl--find-next-or-previous-property-range + 'mastodon-tab-stop search-pos previous)) (get-text-property (car next-range) 'invisible) - (setq search-pos (1+ (cdr next-range)))) - ;; do nothing, all the action in in the while condition + (setq search-pos (if previous + (1- (car next-range)) + (1+ (cdr next-range))))) + ;; do nothing, all the action is in the while condition ) (if (null next-range) (message "Nothing else here.") @@ -305,18 +308,7 @@ first. Don't move if nothing else to move to is found, i.e. near the start of the buffer. This also skips tab items in invisible text, i.e. hidden spoiler text." (interactive) - (let (next-range - (search-pos (point))) - (while (and (setq next-range (mastodon-tl--find-next-or-previous-property-range - 'mastodon-tab-stop search-pos t)) - (get-text-property (car next-range) 'invisible) - (setq search-pos (1- (car next-range)))) - ;; do nothing, all the action in in the while condition - ) - (if (null next-range) - (message "Nothing else before this.") - (goto-char (car next-range)) - (message "%s" (mastodon-tl--property 'help-echo :no-move))))) + (mastodon-tl--next-tab-item :previous)) (defun mastodon-tl--goto-toot-pos (find-pos refresh &optional pos) "Search for toot with FIND-POS. -- cgit v1.2.3 From 7158b8df3f1e93815644c59b342c3ebc90e83f60 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 7 May 2023 21:19:03 +0200 Subject: tiny line wrapping --- lisp/mastodon-tl.el | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ecefa66..f9db25a 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -368,29 +368,26 @@ If LOCAL, get only local timeline. With a single PREFIX arg, hide-replies. With a double PREFIX arg, only show posts with media." (interactive "p") - (let ((params - `(("limit" . ,mastodon-tl--timeline-posts-count)))) + (let ((params `(("limit" . ,mastodon-tl--timeline-posts-count)))) ;; avoid adding 'nil' to our params alist: (when (eq prefix 16) (push '("only_media" . "true") params)) (when local (push '("local" . "true") params)) (message "Loading federated timeline...") - (mastodon-tl--init - (if local "local" "federated") - "timelines/public" 'mastodon-tl--timeline nil - params - (when (eq prefix 4) t)))) + (mastodon-tl--init (if local "local" "federated") + "timelines/public" 'mastodon-tl--timeline nil + params + (when (eq prefix 4) t)))) (defun mastodon-tl--get-home-timeline (&optional arg) "Open home timeline. With a single prefix ARG, hide replies." (interactive "p") (message "Loading home timeline...") - (mastodon-tl--init - "home" "timelines/home" 'mastodon-tl--timeline nil - `(("limit" . ,mastodon-tl--timeline-posts-count)) - (when (eq arg 4) t))) + (mastodon-tl--init "home" "timelines/home" 'mastodon-tl--timeline nil + `(("limit" . ,mastodon-tl--timeline-posts-count)) + (when (eq arg 4) t))) (defun mastodon-tl--get-local-timeline (&optional prefix) "Open local timeline. @@ -407,7 +404,8 @@ With a single PREFIX arg, only show posts with media. With a double PREFIX arg, limit results to your own instance." (interactive "p") (let* ((word (or (word-at-point) "")) - (input (or tag (read-string (format "Load timeline for tag (%s): " word)))) + (input (or tag (read-string + (format "Load timeline for tag (%s): " word)))) (tag (or tag (if (string-empty-p input) word input)))) (message "Loading timeline for #%s..." tag) (mastodon-tl--show-tag-timeline prefix tag))) @@ -417,8 +415,7 @@ With a double PREFIX arg, limit results to your own instance." If TAG is a list, show a timeline for all tags. With a single PREFIX arg, only show posts with media. With a double PREFIX arg, limit results to your own instance." - (let ((params - `(("limit" . ,mastodon-tl--timeline-posts-count)))) + (let ((params `(("limit" . ,mastodon-tl--timeline-posts-count)))) ;; avoid adding 'nil' to our params alist: (when (eq prefix 4) (push '("only_media" . "true") params)) -- cgit v1.2.3 From a4745455998da50227b71c8c1f6603b3086106a4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 10 May 2023 13:01:19 +0200 Subject: readme re completion --- README.org | 37 ++++++++++++++++++++++----------- mastodon.info | 67 +++++++++++++++++++++++++++++++++-------------------------- mastodon.texi | 39 +++++++++++++++++++++++----------- 3 files changed, 89 insertions(+), 54 deletions(-) diff --git a/README.org b/README.org index ffed894..7bc75db 100644 --- a/README.org +++ b/README.org @@ -196,13 +196,10 @@ not contain =:client_id= and =:client_secret=. *** Composing toots -=M-x mastodon-toot= (or =t= from a mastodon.el buffer). - -Pops a new buffer/window in =text-mode= and =mastodon-toot= minor mode. Enter the -contents of your toot here. =C-c C-c= sends the toot. =C-c C-k= cancels. -Both actions kill the buffer and window. - -Autocompletion of mentions and tags is provided by =completion-at-point-functions= (capf) backends. =mastodon-toot--enable-completion= is enabled by default. If you want to enable =company-mode= in the toot compose buffer, set =mastodon-toot--use-company-for-completion= to =t=. (=mastodon.el= used to run its own native company backends, but these have been removed in favour of capfs.) +=M-x mastodon-toot= (or =t= from a mastodon.el buffer) opens a new buffer/window +in =text-mode= and =mastodon-toot= minor mode. Enter the contents of your toot +here. =C-c C-c= sends the toot. =C-c C-k= cancels. Both actions kill the buffer +and window. Further keybindings are displayed in the buffer, and in the following subsection. Replies preserve visibility status/content warnings, and include boosters by default. @@ -239,6 +236,19 @@ value of that hook is as follows: | =C-c C-l= | Set toot language | |---------+----------------------------------| +**** autocompletion of mentions and tags + +Autocompletion of mentions and tags is provided by +=completion-at-point-functions= (capf) backends. +=mastodon-toot--enable-completion= is enabled by default. If you want to enable +=company-mode= in the toot compose buffer, set +=mastodon-toot--use-company-for-completion= to =t=. (=mastodon.el= used to run its +own native company backends, but these have been removed in favour of capfs.) + +If you don’t run =company= and want immediate, keyless completion, you’ll need +to have another completion engine running that handles capfs. A common +combination is =consult= and =corfu=. + **** Draft toots - Compose buffer text is saved as you type, kept in =mastodon-toot-current-toot-text=. @@ -327,7 +337,8 @@ See =M-x customize-group RET mastodon= to view all customize options. *** Alternative timeline layout -The incomparable Nicholas Rougier has written an alternative timeline layout for =mastodon.el=. +The incomparable Nicholas Rougier has written an alternative timeline layout +for =mastodon.el=. The repo is at [[https://github.com/rougier/mastodon-alt][mastodon-alt]]. @@ -346,9 +357,9 @@ view a timeline with one of the commands that begin with *** Translating toots -You can translate toots with =mastodon-toot--translate-toot-text= (=a= in a timeline). At the moment -this requires [[https://codeberg.org/martianh/lingva.el][lingva.el]], a little interface I wrote to [[https://lingva.ml][lingva.ml]], to -be installed to work. +You can translate toots with =mastodon-toot--translate-toot-text= (=a= in a +timeline). At the moment this requires [[https://codeberg.org/martianh/lingva.el][lingva.el]], a little interface I wrote +to [[https://lingva.ml][lingva.ml]], to be installed to work. You could easily modify the simple function to use your Emacs translator of choice (=libretrans.el= , =google-translate=, =babel=, =go-translate=, etc.), you just @@ -368,7 +379,9 @@ to your translator function as its text argument. Here's what #+end_src *** bookmarks and =mastodon.el= -=mastodon.el= doesn’t currently implement its own bookmark record and handler, which means that emacs bookmarks will not work as is. Until we implement them, you can get bookmarks going immediately by using [[https://github.com/emacsmirror/emacswiki.org/blob/master/bookmark%2b.el][bookmark+.el]]. +=mastodon.el= doesn’t currently implement its own bookmark record and handler, +which means that emacs bookmarks will not work as is. Until we implement them, +you can get bookmarks going immediately by using [[https://github.com/emacsmirror/emacswiki.org/blob/master/bookmark%2b.el][bookmark+.el]]. ** Dependencies diff --git a/mastodon.info b/mastodon.info index d1389a1..12f5da4 100644 --- a/mastodon.info +++ b/mastodon.info @@ -292,19 +292,11 @@ File: mastodon.info, Node: Composing toots, Next: Other commands and account s 1.2.3 Composing toots --------------------- -‘M-x mastodon-toot’ (or ‘t’ from a mastodon.el buffer). - - Pops a new buffer/window in ‘text-mode’ and ‘mastodon-toot’ minor -mode. Enter the contents of your toot here. ‘C-c C-c’ sends the toot. -‘C-c C-k’ cancels. Both actions kill the buffer and window. - - Autocompletion of mentions and tags is provided by -‘completion-at-point-functions’ (capf) backends. -‘mastodon-toot--enable-completion’ is enabled by default. If you want -to enable ‘company-mode’ in the toot compose buffer, set -‘mastodon-toot--use-company-for-completion’ to ‘t’. (‘mastodon.el’ used -to run its own native company backends, but these have been removed in -favour of capfs.) +‘M-x mastodon-toot’ (or ‘t’ from a mastodon.el buffer) opens a new +buffer/window in ‘text-mode’ and ‘mastodon-toot’ minor mode. Enter the +contents of your toot here. ‘C-c C-c’ sends the toot. ‘C-c C-k’ +cancels. Both actions kill the buffer and window. Further keybindings +are displayed in the buffer, and in the following subsection. Replies preserve visibility status/content warnings, and include boosters by default. @@ -340,7 +332,21 @@ is as follows: ‘C-c C-p’ Create a poll ‘C-c C-l’ Set toot language - 2. Draft toots + 2. autocompletion of mentions and tags + + Autocompletion of mentions and tags is provided by + ‘completion-at-point-functions’ (capf) backends. + ‘mastodon-toot--enable-completion’ is enabled by default. If you + want to enable ‘company-mode’ in the toot compose buffer, set + ‘mastodon-toot--use-company-for-completion’ to ‘t’. (‘mastodon.el’ + used to run its own native company backends, but these have been + removed in favour of capfs.) + + If you don’t run ‘company’ and want immediate, keyless completion, + you’ll need to have another completion engine running that handles + capfs. A common combination is ‘consult’ and ‘corfu’. + + 3. Draft toots • Compose buffer text is saved as you type, kept in ‘mastodon-toot-current-toot-text’. @@ -650,22 +656,23 @@ Node: Timelines4522 Ref: Keybindings4997 Ref: Toot byline legend9570 Node: Composing toots9879 -Ref: Keybindings (1)11456 -Ref: Draft toots11974 -Node: Other commands and account settings12445 -Node: Customization15603 -Node: Alternative timeline layout16389 -Node: Live-updating timelines mastodon-async-mode16779 -Node: Translating toots17631 -Node: bookmarks and mastodonel18813 -Node: Dependencies19283 -Node: Network compatibility19889 -Node: Contributing20375 -Node: Bug reports20664 -Node: Fixes and features21570 -Node: Coding style22053 -Node: Supporting mastodonel22677 -Node: Contributors23199 +Ref: Keybindings (1)11118 +Ref: autocompletion of mentions and tags11636 +Ref: Draft toots12349 +Node: Other commands and account settings12820 +Node: Customization15978 +Node: Alternative timeline layout16764 +Node: Live-updating timelines mastodon-async-mode17154 +Node: Translating toots18006 +Node: bookmarks and mastodonel19188 +Node: Dependencies19658 +Node: Network compatibility20264 +Node: Contributing20750 +Node: Bug reports21039 +Node: Fixes and features21945 +Node: Coding style22428 +Node: Supporting mastodonel23052 +Node: Contributors23574  End Tag Table diff --git a/mastodon.texi b/mastodon.texi index 122bbb1..1850844 100644 --- a/mastodon.texi +++ b/mastodon.texi @@ -362,13 +362,10 @@ not contain @samp{:client_id} and @samp{:client_secret}. @node Composing toots @subsection Composing toots -@samp{M-x mastodon-toot} (or @samp{t} from a mastodon.el buffer). - -Pops a new buffer/window in @samp{text-mode} and @samp{mastodon-toot} minor mode. Enter the -contents of your toot here. @samp{C-c C-c} sends the toot. @samp{C-c C-k} cancels. -Both actions kill the buffer and window. - -Autocompletion of mentions and tags is provided by @samp{completion-at-point-functions} (capf) backends. @samp{mastodon-toot--enable-completion} is enabled by default. If you want to enable @samp{company-mode} in the toot compose buffer, set @samp{mastodon-toot--use-company-for-completion} to @samp{t}. (@samp{mastodon.el} used to run its own native company backends, but these have been removed in favour of capfs.) +@samp{M-x mastodon-toot} (or @samp{t} from a mastodon.el buffer) opens a new buffer/window +in @samp{text-mode} and @samp{mastodon-toot} minor mode. Enter the contents of your toot +here. @samp{C-c C-c} sends the toot. @samp{C-c C-k} cancels. Both actions kill the buffer +and window. Further keybindings are displayed in the buffer, and in the following subsection. Replies preserve visibility status/content warnings, and include boosters by default. @@ -418,6 +415,21 @@ value of that hook is as follows: @tab Set toot language @end multitable +@item +@anchor{autocompletion of mentions and tags}autocompletion of mentions and tags + + +Autocompletion of mentions and tags is provided by +@samp{completion-at-point-functions} (capf) backends. +@samp{mastodon-toot--enable-completion} is enabled by default. If you want to enable +@samp{company-mode} in the toot compose buffer, set +@samp{mastodon-toot--use-company-for-completion} to @samp{t}. (@samp{mastodon.el} used to run its +own native company backends, but these have been removed in favour of capfs.) + +If you don’t run @samp{company} and want immediate, keyless completion, you’ll need +to have another completion engine running that handles capfs. A common +combination is @samp{consult} and @samp{corfu}. + @item @anchor{Draft toots}Draft toots @@ -584,7 +596,8 @@ Set default reply visibility @node Alternative timeline layout @subsection Alternative timeline layout -The incomparable Nicholas Rougier has written an alternative timeline layout for @samp{mastodon.el}. +The incomparable Nicholas Rougier has written an alternative timeline layout +for @samp{mastodon.el}. The repo is at @uref{https://github.com/rougier/mastodon-alt, mastodon-alt}. @@ -605,9 +618,9 @@ view a timeline with one of the commands that begin with @node Translating toots @subsection Translating toots -You can translate toots with @samp{mastodon-toot--translate-toot-text} (@samp{a} in a timeline). At the moment -this requires @uref{https://codeberg.org/martianh/lingva.el, lingva.el}, a little interface I wrote to @uref{https://lingva.ml, lingva.ml}, to -be installed to work. +You can translate toots with @samp{mastodon-toot--translate-toot-text} (@samp{a} in a +timeline). At the moment this requires @uref{https://codeberg.org/martianh/lingva.el, lingva.el}, a little interface I wrote +to @uref{https://lingva.ml, lingva.ml}, to be installed to work. You could easily modify the simple function to use your Emacs translator of choice (@samp{libretrans.el} , @samp{google-translate}, @samp{babel}, @samp{go-translate}, etc.), you just @@ -629,7 +642,9 @@ to your translator function as its text argument. Here's what @node bookmarks and @samp{mastodonel} @subsection bookmarks and @samp{mastodon.el} -@samp{mastodon.el} doesn’t currently implement its own bookmark record and handler, which means that emacs bookmarks will not work as is. Until we implement them, you can get bookmarks going immediately by using @uref{https://github.com/emacsmirror/emacswiki.org/blob/master/bookmark%2b.el, bookmark+.el}. +@samp{mastodon.el} doesn’t currently implement its own bookmark record and handler, +which means that emacs bookmarks will not work as is. Until we implement them, +you can get bookmarks going immediately by using @uref{https://github.com/emacsmirror/emacswiki.org/blob/master/bookmark%2b.el, bookmark+.el}. @node Dependencies @section Dependencies -- 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(-) 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