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 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-toot.el') 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 -- 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index fe7d7d2..5bee7e9 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -494,22 +494,19 @@ This endpoint only holds a few preferences. For others, see (let* ((url (mastodon-http--api "preferences")) (response (mastodon-http--get-json url)) (buf (get-buffer-create "*mastodon-preferences*"))) - (with-current-buffer buf - (switch-to-buffer-other-window buf) - (erase-buffer) - (special-mode) - (mastodon-tl--set-buffer-spec (buffer-name buf) - "preferences" - nil) - (let ((inhibit-read-only t)) - (while response - (let ((el (pop response))) - (insert - (format "%-30s %s" - (prin1-to-string (car el)) - (prin1-to-string (cdr el))) - "\n\n")))) - (goto-char (point-min))))) + (with-mastodon-buffer + buf #'special-mode :other-window + (mastodon-tl--set-buffer-spec (buffer-name buf) + "preferences" + nil) + (while response + (let ((el (pop response))) + (insert + (format "%-30s %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + "\n\n"))) + (goto-char (point-min))))) ;; PROFILE VIEW DETAILS @@ -607,7 +604,7 @@ HEADERS means also fetch link headers for pagination." (pinned (mastodon-profile--get-statuses-pinned account)) (joined (mastodon-profile--account-field account 'created_at))) (with-mastodon-buffer - buffer + buffer #'mastodon-mode nil (mastodon-profile-mode) (setq mastodon-profile--account account) (mastodon-tl--set-buffer-spec buffer diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 86ebb90..26790ea 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -100,7 +100,7 @@ QUERY is the string to search." status-ids-list))) (defun mastodon-search--view-trending (type print-fun) - "Display a list of tags trending on your instance. + "Display a list of items trending on your instance. TYPE is a string, either tags, statuses, or links. PRINT-FUN is the function used to print the data from the response." (let* ((url (mastodon-http--api @@ -119,22 +119,19 @@ PRINT-FUN is the function used to print the data from the response." (message "todo")))) (buffer (get-buffer-create (format "*mastodon-trending-%s*" type)))) - (with-current-buffer buffer - (switch-to-buffer (current-buffer)) - (mastodon-mode) - (let ((inhibit-read-only t)) - (erase-buffer) - (mastodon-tl--set-buffer-spec (buffer-name buffer) - (format "api/v1/trends/%s" type) - nil) - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - (upcase (format " TRENDING %s\n" type)) - " " mastodon-tl--horiz-bar "\n\n") - 'success)) - (funcall print-fun data) - (unless (equal type "statuses") - (goto-char (point-min))))))) + (with-mastodon-buffer + buffer #'mastodon-mode nil + (mastodon-tl--set-buffer-spec (buffer-name buffer) + (format "api/v1/trends/%s" type) + nil) + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + (upcase (format " TRENDING %s\n" type)) + " " mastodon-tl--horiz-bar "\n\n") + 'success)) + (funcall print-fun data) + (unless (equal type "statuses") + (goto-char (point-min)))))) ;; functions for mastodon search @@ -155,7 +152,7 @@ PRINT-FUN is the function used to print the data from the response." (toots-list-json (mastodon-search--get-full-statuses-data statuses))) (with-mastodon-buffer - buffer + buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer "api/v2/search" nil) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ed1940b..8fe12fa 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1711,12 +1711,11 @@ ID is that of the toot to view." (if (equal (caar toot) 'error) (message "Error: %s" (cdar toot)) (with-mastodon-buffer - buffer + buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer (format "statuses/%s" id) nil) - (let ((inhibit-read-only t)) - (mastodon-tl--toot toot :detailed-p)))))) + (mastodon-tl--toot toot :detailed-p))))) (defun mastodon-tl--view-whole-thread () "From a thread view, view entire thread. @@ -1757,7 +1756,7 @@ view all branches of a thread." 0) ;; if we have a thread: (with-mastodon-buffer - buffer + buffer #'mastodon-mode nil (let ((marker (make-marker))) (mastodon-tl--set-buffer-spec buffer endpoint @@ -2567,7 +2566,7 @@ JSON and http headers, without it just the JSON." (let* ((headers (if headers (cdr response) nil)) (link-header (mastodon-tl--get-link-header-from-response headers))) (with-mastodon-buffer - buffer + buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer endpoint update-function @@ -2607,12 +2606,7 @@ Optional arg NOTE-TYPE means only get that type of note." (buffer (concat "*mastodon-" buffer-name "*")) (json (mastodon-http--get-json url args))) (with-mastodon-buffer - buffer - ;; mastodon-mode wipes buffer-spec, so order must unforch be: - ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. - ;; which means we cannot use buffer-spec for update-function - ;; unless we set it both before and after the others - (mastodon-tl--set-buffer-spec buffer endpoint update-function) + buffer #'mastodon-mode nil (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9d44bfd..de6a5d4 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -902,30 +902,27 @@ instance to edit a toot." (interactive) (let ((id (mastodon-tl--property 'base-toot-id)) (history (mastodon-tl--property 'edit-history))) - (with-current-buffer (get-buffer-create "*mastodon-toot-edits*") - (let ((inhibit-read-only t)) - (special-mode) - (erase-buffer) - (let ((count 1)) - (mapc (lambda (x) - (insert (propertize (if (= count 1) - (format "%s [original]:\n" count) - (format "%s:\n" count)) - 'face font-lock-comment-face) - (mastodon-toot--insert-toot-iter x) - "\n") - (cl-incf count)) - history)) - (switch-to-buffer-other-window (current-buffer)) - (setq-local header-line-format - (propertize - (format "Edits to toot by %s:" - (alist-get 'username - (alist-get 'account (car history)))) - 'face font-lock-comment-face)) - (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) - (format "statuses/%s/history" id) - nil))))) + (with-mastodon-buffer + "*mastodon-toot-edits*" #'special-mode :other-window + (let ((count 1)) + (mapc (lambda (x) + (insert (propertize (if (= count 1) + (format "%s [original]:\n" count) + (format "%s:\n" count)) + 'face font-lock-comment-face) + (mastodon-toot--insert-toot-iter x) + "\n") + (cl-incf count)) + history)) + (setq-local header-line-format + (propertize + (format "Edits to toot by %s:" + (alist-get 'username + (alist-get 'account (car history)))) + 'face font-lock-comment-face)) + (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) + (format "statuses/%s/history" id) + nil)))) (defun mastodon-toot--insert-toot-iter (it) "Insert iteration IT of toot." diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 7481fc3..8585bb0 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -799,30 +799,27 @@ INSTANCE is the instance were are working with." (let* ((domain (url-file-nondirectory instance)) (buf (get-buffer-create (format "*mastodon-instance-%s*" domain)))) - (with-current-buffer buf - (switch-to-buffer-other-window buf) - (let ((inhibit-read-only t)) - (erase-buffer) - (special-mode) - (when brief - (setq response - (list (assoc 'uri response) - (assoc 'title response) - (assoc 'short_description response) - (assoc 'email response) - (cons 'contact_account - (list - (assoc 'username - (assoc 'contact_account response)))) - (assoc 'rules response) - (assoc 'stats response)))) - (mastodon-views--print-json-keys response) - ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving - ;; split window - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) - (goto-char (point-min))))))) + (with-mastodon-buffer + buf #'special-mode :other-window + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) + (mastodon-views--print-json-keys response) + ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving + ;; split window + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) + (goto-char (point-min)))))) (defun mastodon-views--format-key (el pad) "Format a key of element EL, a cons, with PAD padding." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index fca376d..f52579c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -255,14 +255,19 @@ mastodon.el needs to be re-loaded for this to be correctly set.") "Face used for reply text in toot compose buffer. See `mastodon-toot-display-orig-in-reply-buffer'.") -(defmacro with-mastodon-buffer (buffer &rest body) - "Evaluate BODY in a new `mastodon-mode' buffer called BUFFER." +(defmacro with-mastodon-buffer (buffer mode-fun other-window &rest body) + "Evaluate BODY in a new or existing buffer called BUFFER. +MODE-FUN is called to set the major mode. +OTHER-WINDOW means call `switch-to-buffer-other-window' rather +than `switch-to-buffer'." (declare (debug 'body)) `(with-current-buffer (get-buffer-create ,buffer) (let ((inhibit-read-only t)) (erase-buffer) - (switch-to-buffer ,buffer) - (mastodon-mode) + (if ,other-window + (switch-to-buffer-other-window ,buffer) + (switch-to-buffer ,buffer)) + (funcall ,mode-fun) ,@body))) ;;;###autoload -- cgit v1.2.3 From 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(+) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index dd8d032..ec4a0d1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1701,8 +1701,6 @@ EDIT means we are editing an existing toot, not composing a new one." (point-marker)))) (switch-to-buffer-other-window buffer) (text-mode) - (when mastodon-toot--enable-proportional-fonts-compose-buffer - (variable-pitch-mode)) (mastodon-toot-mode t) (setq mastodon-toot--visibility (or (plist-get mastodon-profile-account-settings 'privacy) @@ -1764,14 +1762,6 @@ EDIT means we are editing an existing toot, not composing a new one." (lambda () (auto-fill-mode -1))) -;; scale fixed-pitch docs relative to any possible variable pitch scaling set: -(add-hook 'mastodon-toot-mode-hook - (lambda () - (when mastodon-toot--enable-proportional-fonts-compose-buffer - (let ((height (/ 1 (face-attribute 'variable-pitch :height)))) - (set-face-attribute 'mastodon-toot-docs-face nil - :height height))))) - (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." :keymap mastodon-toot-mode-map diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f52579c..4662010 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -242,9 +242,7 @@ Use. e.g. \"%c\" for your locale's date and time format." "Face used for content warning.") (defface mastodon-toot-docs-face - `((t :inherit font-lock-comment-face - :height 1.0 - :family ,(face-attribute 'default :family))) + `((t :inherit font-lock-comment-face)) "Face used for documentation in toot compose buffer. If `mastodon-tl--enable-proportional-fonts' is changed, mastodon.el needs to be re-loaded for this to be correctly set.") -- cgit v1.2.3 From 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(+) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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(-) (limited to 'lisp/mastodon-toot.el') 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 5970c9de908fbb8009de86a2371578de231b3cee Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 14:46:34 +0200 Subject: Revert "updates to with-mastodon-buffer macro" This reverts commit 59e5e3ece54bcac36d9debad392bff25a31438b5. --- lisp/mastodon-profile.el | 31 ++++++++++++++------------ lisp/mastodon-search.el | 33 ++++++++++++++------------- lisp/mastodon-tl.el | 58 ++++++++++++++++++++++++++---------------------- lisp/mastodon-toot.el | 45 +++++++++++++++++++------------------ lisp/mastodon-views.el | 45 +++++++++++++++++++------------------ lisp/mastodon.el | 16 +++++-------- 6 files changed, 120 insertions(+), 108 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5bee7e9..fe7d7d2 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -494,19 +494,22 @@ This endpoint only holds a few preferences. For others, see (let* ((url (mastodon-http--api "preferences")) (response (mastodon-http--get-json url)) (buf (get-buffer-create "*mastodon-preferences*"))) - (with-mastodon-buffer - buf #'special-mode :other-window - (mastodon-tl--set-buffer-spec (buffer-name buf) - "preferences" - nil) - (while response - (let ((el (pop response))) - (insert - (format "%-30s %s" - (prin1-to-string (car el)) - (prin1-to-string (cdr el))) - "\n\n"))) - (goto-char (point-min))))) + (with-current-buffer buf + (switch-to-buffer-other-window buf) + (erase-buffer) + (special-mode) + (mastodon-tl--set-buffer-spec (buffer-name buf) + "preferences" + nil) + (let ((inhibit-read-only t)) + (while response + (let ((el (pop response))) + (insert + (format "%-30s %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + "\n\n")))) + (goto-char (point-min))))) ;; PROFILE VIEW DETAILS @@ -604,7 +607,7 @@ HEADERS means also fetch link headers for pagination." (pinned (mastodon-profile--get-statuses-pinned account)) (joined (mastodon-profile--account-field account 'created_at))) (with-mastodon-buffer - buffer #'mastodon-mode nil + buffer (mastodon-profile-mode) (setq mastodon-profile--account account) (mastodon-tl--set-buffer-spec buffer diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 26790ea..86ebb90 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -100,7 +100,7 @@ QUERY is the string to search." status-ids-list))) (defun mastodon-search--view-trending (type print-fun) - "Display a list of items trending on your instance. + "Display a list of tags trending on your instance. TYPE is a string, either tags, statuses, or links. PRINT-FUN is the function used to print the data from the response." (let* ((url (mastodon-http--api @@ -119,19 +119,22 @@ PRINT-FUN is the function used to print the data from the response." (message "todo")))) (buffer (get-buffer-create (format "*mastodon-trending-%s*" type)))) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (mastodon-tl--set-buffer-spec (buffer-name buffer) - (format "api/v1/trends/%s" type) - nil) - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - (upcase (format " TRENDING %s\n" type)) - " " mastodon-tl--horiz-bar "\n\n") - 'success)) - (funcall print-fun data) - (unless (equal type "statuses") - (goto-char (point-min)))))) + (with-current-buffer buffer + (switch-to-buffer (current-buffer)) + (mastodon-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (mastodon-tl--set-buffer-spec (buffer-name buffer) + (format "api/v1/trends/%s" type) + nil) + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + (upcase (format " TRENDING %s\n" type)) + " " mastodon-tl--horiz-bar "\n\n") + 'success)) + (funcall print-fun data) + (unless (equal type "statuses") + (goto-char (point-min))))))) ;; functions for mastodon search @@ -152,7 +155,7 @@ PRINT-FUN is the function used to print the data from the response." (toots-list-json (mastodon-search--get-full-statuses-data statuses))) (with-mastodon-buffer - buffer #'mastodon-mode nil + buffer (mastodon-tl--set-buffer-spec buffer "api/v2/search" nil) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index cef995d..759dde8 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1722,11 +1722,12 @@ ID is that of the toot to view." (if (equal (caar toot) 'error) (message "Error: %s" (cdar toot)) (with-mastodon-buffer - buffer #'mastodon-mode nil + buffer (mastodon-tl--set-buffer-spec buffer (format "statuses/%s" id) nil) - (mastodon-tl--toot toot :detailed-p))))) + (let ((inhibit-read-only t)) + (mastodon-tl--toot toot :detailed-p)))))) (defun mastodon-tl--view-whole-thread () "From a thread view, view entire thread. @@ -1767,7 +1768,7 @@ view all branches of a thread." 0) ;; if we have a thread: (with-mastodon-buffer - buffer #'mastodon-mode nil + buffer (let ((marker (make-marker))) (mastodon-tl--set-buffer-spec buffer endpoint @@ -2582,20 +2583,20 @@ JSON and http headers, without it just the JSON." (message "Looks like nothing returned from endpoint: %s" endpoint) (let* ((headers (if headers (cdr response) nil)) (link-header (mastodon-tl--get-link-header-from-response headers))) - (with-mastodon-buffer buffer - #'mastodon-mode nil + (with-mastodon-buffer + buffer (mastodon-tl--set-buffer-spec buffer endpoint update-function link-header update-params hide-replies) - (funcall update-function json) (setq ;; Initialize with a minimal interval; we re-scan at least once ;; every 5 minutes to catch any timestamps we may have missed mastodon-tl--timestamp-next-update (time-add (current-time) (seconds-to-time 300))) + (funcall update-function json) (setq mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps (run-at-time (time-to-seconds @@ -2623,26 +2624,31 @@ Optional arg NOTE-TYPE means only get that type of note." (buffer (concat "*mastodon-" buffer-name "*")) (json (mastodon-http--get-json url args))) (with-mastodon-buffer - buffer #'mastodon-mode nil - (setq - ;; Initialize with a minimal interval; we re-scan at least once - ;; every 5 minutes to catch any timestamps we may have missed - mastodon-tl--timestamp-next-update (time-add (current-time) - (seconds-to-time 300))) - (funcall update-function json) - (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args) - (setq mastodon-tl--timestamp-update-timer - (when mastodon-tl--enable-relative-timestamps - (run-at-time (time-to-seconds - (time-subtract mastodon-tl--timestamp-next-update - (current-time))) - nil ;; don't repeat - #'mastodon-tl--update-timestamps-callback - (current-buffer) - nil))) - (unless (mastodon-tl--profile-buffer-p) - ;; FIXME: this breaks test (because test has empty buffer) - (mastodon-tl--goto-first-item))) + buffer + ;; mastodon-mode wipes buffer-spec, so order must unforch be: + ;; 1 run update-function, 2 enable masto-mode, 3 set buffer spec. + ;; which means we cannot use buffer-spec for update-function + ;; unless we set it both before and after the others + (mastodon-tl--set-buffer-spec buffer endpoint update-function) + (setq + ;; Initialize with a minimal interval; we re-scan at least once + ;; every 5 minutes to catch any timestamps we may have missed + mastodon-tl--timestamp-next-update (time-add (current-time) + (seconds-to-time 300))) + (funcall update-function json) + (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args) + (setq mastodon-tl--timestamp-update-timer + (when mastodon-tl--enable-relative-timestamps + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) + nil ;; don't repeat + #'mastodon-tl--update-timestamps-callback + (current-buffer) + nil))) + (unless (mastodon-tl--profile-buffer-p) + ;; FIXME: this breaks test (because test has empty buffer) + (mastodon-tl--goto-first-item))) buffer)) (provide 'mastodon-tl) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1265132..5f9e6eb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -902,27 +902,30 @@ instance to edit a toot." (interactive) (let ((id (mastodon-tl--property 'base-toot-id)) (history (mastodon-tl--property 'edit-history))) - (with-mastodon-buffer - "*mastodon-toot-edits*" #'special-mode :other-window - (let ((count 1)) - (mapc (lambda (x) - (insert (propertize (if (= count 1) - (format "%s [original]:\n" count) - (format "%s:\n" count)) - 'face font-lock-comment-face) - (mastodon-toot--insert-toot-iter x) - "\n") - (cl-incf count)) - history)) - (setq-local header-line-format - (propertize - (format "Edits to toot by %s:" - (alist-get 'username - (alist-get 'account (car history)))) - 'face font-lock-comment-face)) - (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) - (format "statuses/%s/history" id) - nil)))) + (with-current-buffer (get-buffer-create "*mastodon-toot-edits*") + (let ((inhibit-read-only t)) + (special-mode) + (erase-buffer) + (let ((count 1)) + (mapc (lambda (x) + (insert (propertize (if (= count 1) + (format "%s [original]:\n" count) + (format "%s:\n" count)) + 'face font-lock-comment-face) + (mastodon-toot--insert-toot-iter x) + "\n") + (cl-incf count)) + history)) + (switch-to-buffer-other-window (current-buffer)) + (setq-local header-line-format + (propertize + (format "Edits to toot by %s:" + (alist-get 'username + (alist-get 'account (car history)))) + 'face font-lock-comment-face)) + (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) + (format "statuses/%s/history" id) + nil))))) (defun mastodon-toot--insert-toot-iter (it) "Insert iteration IT of toot." diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 8585bb0..7481fc3 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -799,27 +799,30 @@ INSTANCE is the instance were are working with." (let* ((domain (url-file-nondirectory instance)) (buf (get-buffer-create (format "*mastodon-instance-%s*" domain)))) - (with-mastodon-buffer - buf #'special-mode :other-window - (when brief - (setq response - (list (assoc 'uri response) - (assoc 'title response) - (assoc 'short_description response) - (assoc 'email response) - (cons 'contact_account - (list - (assoc 'username - (assoc 'contact_account response)))) - (assoc 'rules response) - (assoc 'stats response)))) - (mastodon-views--print-json-keys response) - ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving - ;; split window - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) - (goto-char (point-min)))))) + (with-current-buffer buf + (switch-to-buffer-other-window buf) + (let ((inhibit-read-only t)) + (erase-buffer) + (special-mode) + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) + (mastodon-views--print-json-keys response) + ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving + ;; split window + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) + (goto-char (point-min))))))) (defun mastodon-views--format-key (el pad) "Format a key of element EL, a cons, with PAD padding." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 1fcb234..6b6ab9c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -256,20 +256,14 @@ mastodon.el needs to be re-loaded for this to be correctly set.") "Face used for reply text in toot compose buffer. See `mastodon-toot-display-orig-in-reply-buffer'.") -(defmacro with-mastodon-buffer (buffer mode-fun other-window &rest body) - "Evaluate BODY in a new or existing buffer called BUFFER. -MODE-FUN is called to set the major mode. -OTHER-WINDOW means call `switch-to-buffer-other-window' rather -than `switch-to-buffer'." - (declare (debug t) - (indent defun)) +(defmacro with-mastodon-buffer (buffer &rest body) + "Evaluate BODY in a new `mastodon-mode' buffer called BUFFER." + (declare (debug 'body)) `(with-current-buffer (get-buffer-create ,buffer) (let ((inhibit-read-only t)) (erase-buffer) - (if ,other-window - (switch-to-buffer-other-window ,buffer) - (switch-to-buffer ,buffer)) - (funcall ,mode-fun) + (switch-to-buffer ,buffer) + (mastodon-mode) ,@body))) -- cgit v1.2.3 From aa6e9c55152ac1301efbdbdce9aa7fc3e8fea7c9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 6 May 2023 16:00:00 +0200 Subject: eval-when-compile for with-mastodon-buffer, and re-indent --- lisp/mastodon-profile.el | 197 +++++++++++++++++++++++------------------------ lisp/mastodon-search.el | 81 ++++++++++--------- lisp/mastodon-tl.el | 90 +++++++++++----------- lisp/mastodon-toot.el | 45 +++++------ lisp/mastodon-views.el | 43 ++++++----- 5 files changed, 226 insertions(+), 230 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 5bee7e9..b4812d7 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -38,8 +38,9 @@ (require 'cl-lib) (require 'persist) (require 'parse-time) +(eval-when-compile + (require 'mastodon-tl)) -(autoload 'with-mastodon-buffer "mastodon") (autoload 'mastodon-auth--get-account-id "mastodon-auth") (autoload 'mastodon-auth--get-account-name "mastodon-auth.el") (autoload 'mastodon-http--api "mastodon-http.el") @@ -494,19 +495,18 @@ This endpoint only holds a few preferences. For others, see (let* ((url (mastodon-http--api "preferences")) (response (mastodon-http--get-json url)) (buf (get-buffer-create "*mastodon-preferences*"))) - (with-mastodon-buffer - buf #'special-mode :other-window - (mastodon-tl--set-buffer-spec (buffer-name buf) - "preferences" - nil) - (while response - (let ((el (pop response))) - (insert - (format "%-30s %s" - (prin1-to-string (car el)) - (prin1-to-string (cdr el))) - "\n\n"))) - (goto-char (point-min))))) + (with-mastodon-buffer buf #'special-mode :other-window + (mastodon-tl--set-buffer-spec (buffer-name buf) + "preferences" + nil) + (while response + (let ((el (pop response))) + (insert + (format "%-30s %s" + (prin1-to-string (car el)) + (prin1-to-string (cdr el))) + "\n\n"))) + (goto-char (point-min))))) ;; PROFILE VIEW DETAILS @@ -603,91 +603,90 @@ HEADERS means also fetch link headers for pagination." (fields (mastodon-profile--fields-get account)) (pinned (mastodon-profile--get-statuses-pinned account)) (joined (mastodon-profile--account-field account 'created_at))) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (mastodon-profile-mode) - (setq mastodon-profile--account account) - (mastodon-tl--set-buffer-spec buffer - endpoint - update-function - link-header) - (let* ((inhibit-read-only t) - (is-statuses (string= endpoint-type "statuses")) - (is-followers (string= endpoint-type "followers")) - (is-following (string= endpoint-type "following")) - (endpoint-name (cond - (is-statuses (if no-reblogs - " TOOTS (no boosts)" - " TOOTS ")) - (is-followers " FOLLOWERS ") - (is-following " FOLLOWING ")))) - (insert - (propertize - (concat - "\n" - (mastodon-profile--image-from-account account 'avatar_static) - (mastodon-profile--image-from-account account 'header_static) - "\n" - (propertize (mastodon-profile--account-field - account 'display_name) - 'face 'mastodon-display-name-face) - "\n" - (propertize (concat "@" acct) - 'face 'default) - (if (equal locked t) - (concat " " (mastodon-tl--symbol 'locked)) - "") - "\n " mastodon-tl--horiz-bar "\n" - ;; profile note: - ;; account here to enable tab-stops in profile note - (mastodon-tl--render-text note account) - ;; meta fields: - (if fields - (concat "\n" - (mastodon-tl--set-face - (mastodon-profile--fields-insert fields) - 'success)) - "") - "\n" - ;; Joined date: - (propertize - (mastodon-profile--format-joined-date-string joined) - 'face 'success) - "\n\n") - 'profile-json account) - ;; insert counts - (mastodon-tl--set-face - (concat " " mastodon-tl--horiz-bar "\n" - " TOOTS: " toots-count " | " - "FOLLOWERS: " followers-count " | " - "FOLLOWING: " following-count "\n" - " " mastodon-tl--horiz-bar "\n\n") - 'success) - ;; insert relationship (follows) - (if followsp - (mastodon-tl--set-face - (concat (when (equal follows-you 't) - " | FOLLOWS YOU") - (when (equal followed-by-you 't) - " | FOLLOWED BY YOU") - (when (equal requested-you 't) - " | REQUESTED TO FOLLOW YOU") - "\n\n") - 'success) - "") ; if no followsp we still need str-or-char-p for insert - ;; insert endpoint - (mastodon-tl--set-face - (concat " " mastodon-tl--horiz-bar "\n" - endpoint-name "\n" - " " mastodon-tl--horiz-bar "\n") - 'success)) - (setq mastodon-tl--update-point (point)) - (mastodon-media--inline-images (point-min) (point)) - ;; insert pinned toots first - (when (and pinned (equal endpoint-type "statuses")) - (mastodon-profile--insert-statuses-pinned pinned) - (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots - (funcall update-function json))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (mastodon-profile-mode) + (setq mastodon-profile--account account) + (mastodon-tl--set-buffer-spec buffer + endpoint + update-function + link-header) + (let* ((inhibit-read-only t) + (is-statuses (string= endpoint-type "statuses")) + (is-followers (string= endpoint-type "followers")) + (is-following (string= endpoint-type "following")) + (endpoint-name (cond + (is-statuses (if no-reblogs + " TOOTS (no boosts)" + " TOOTS ")) + (is-followers " FOLLOWERS ") + (is-following " FOLLOWING ")))) + (insert + (propertize + (concat + "\n" + (mastodon-profile--image-from-account account 'avatar_static) + (mastodon-profile--image-from-account account 'header_static) + "\n" + (propertize (mastodon-profile--account-field + account 'display_name) + 'face 'mastodon-display-name-face) + "\n" + (propertize (concat "@" acct) + 'face 'default) + (if (equal locked t) + (concat " " (mastodon-tl--symbol 'locked)) + "") + "\n " mastodon-tl--horiz-bar "\n" + ;; profile note: + ;; account here to enable tab-stops in profile note + (mastodon-tl--render-text note account) + ;; meta fields: + (if fields + (concat "\n" + (mastodon-tl--set-face + (mastodon-profile--fields-insert fields) + 'success)) + "") + "\n" + ;; Joined date: + (propertize + (mastodon-profile--format-joined-date-string joined) + 'face 'success) + "\n\n") + 'profile-json account) + ;; insert counts + (mastodon-tl--set-face + (concat " " mastodon-tl--horiz-bar "\n" + " TOOTS: " toots-count " | " + "FOLLOWERS: " followers-count " | " + "FOLLOWING: " following-count "\n" + " " mastodon-tl--horiz-bar "\n\n") + 'success) + ;; insert relationship (follows) + (if followsp + (mastodon-tl--set-face + (concat (when (equal follows-you 't) + " | FOLLOWS YOU") + (when (equal followed-by-you 't) + " | FOLLOWED BY YOU") + (when (equal requested-you 't) + " | REQUESTED TO FOLLOW YOU") + "\n\n") + 'success) + "") ; if no followsp we still need str-or-char-p for insert + ;; insert endpoint + (mastodon-tl--set-face + (concat " " mastodon-tl--horiz-bar "\n" + endpoint-name "\n" + " " mastodon-tl--horiz-bar "\n") + 'success)) + (setq mastodon-tl--update-point (point)) + (mastodon-media--inline-images (point-min) (point)) + ;; insert pinned toots first + (when (and pinned (equal endpoint-type "statuses")) + (mastodon-profile--insert-statuses-pinned pinned) + (setq mastodon-tl--update-point (point))) ;updates to follow pinned toots + (funcall update-function json))) (goto-char (point-min)))) (defun mastodon-profile--format-joined-date-string (joined) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 26790ea..a6b4492 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -29,13 +29,14 @@ ;;; Code: (require 'json) +(eval-when-compile + (require 'mastodon-tl)) (autoload 'mastodon-auth--access-token "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-http--get-search-json "mastodon-http") (autoload 'mastodon-mode "mastodon") -(autoload 'with-mastodon-buffer "mastodon") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-tl--render-text "mastodon-tl") @@ -119,19 +120,18 @@ PRINT-FUN is the function used to print the data from the response." (message "todo")))) (buffer (get-buffer-create (format "*mastodon-trending-%s*" type)))) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (mastodon-tl--set-buffer-spec (buffer-name buffer) - (format "api/v1/trends/%s" type) - nil) - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - (upcase (format " TRENDING %s\n" type)) - " " mastodon-tl--horiz-bar "\n\n") - 'success)) - (funcall print-fun data) - (unless (equal type "statuses") - (goto-char (point-min)))))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (mastodon-tl--set-buffer-spec (buffer-name buffer) + (format "api/v1/trends/%s" type) + nil) + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + (upcase (format " TRENDING %s\n" type)) + " " mastodon-tl--horiz-bar "\n\n") + 'success)) + (funcall print-fun data) + (unless (equal type "statuses") + (goto-char (point-min)))))) ;; functions for mastodon search @@ -151,33 +151,32 @@ PRINT-FUN is the function used to print the data from the response." tags)) (toots-list-json (mastodon-search--get-full-statuses-data statuses))) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (mastodon-tl--set-buffer-spec buffer - "api/v2/search" - nil) - ;; user results: - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - " USERS\n" - " " mastodon-tl--horiz-bar "\n\n") - 'success)) - (mastodon-search--insert-users-propertized accts :note) - ;; hashtag results: - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - " HASHTAGS\n" - " " mastodon-tl--horiz-bar "\n\n") - 'success)) - (mastodon-search--print-tags-list tags-list) - ;; status results: - (insert (mastodon-tl--set-face - (concat "\n " mastodon-tl--horiz-bar "\n" - " STATUSES\n" - " " mastodon-tl--horiz-bar "\n") - 'success)) - (mapc #'mastodon-tl--toot toots-list-json) - (goto-char (point-min))))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (mastodon-tl--set-buffer-spec buffer + "api/v2/search" + nil) + ;; user results: + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + " USERS\n" + " " mastodon-tl--horiz-bar "\n\n") + 'success)) + (mastodon-search--insert-users-propertized accts :note) + ;; hashtag results: + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + " HASHTAGS\n" + " " mastodon-tl--horiz-bar "\n\n") + 'success)) + (mastodon-search--print-tags-list tags-list) + ;; status results: + (insert (mastodon-tl--set-face + (concat "\n " mastodon-tl--horiz-bar "\n" + " STATUSES\n" + " " mastodon-tl--horiz-bar "\n") + 'success)) + (mapc #'mastodon-tl--toot toots-list-json) + (goto-char (point-min))))) (defun mastodon-search--insert-users-propertized (json &optional note) "Insert users list into the buffer. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f62413f..3352b13 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1738,12 +1738,11 @@ ID is that of the toot to view." (mastodon-http--api (concat "statuses/" id))))) (if (equal (caar toot) 'error) (message "Error: %s" (cdar toot)) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (mastodon-tl--set-buffer-spec buffer - (format "statuses/%s" id) - nil) - (mastodon-tl--toot toot :detailed-p))))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (mastodon-tl--set-buffer-spec buffer + (format "statuses/%s" id) + nil) + (mastodon-tl--toot toot :detailed-p))))) (defun mastodon-tl--view-whole-thread () "From a thread view, view entire thread. @@ -1783,23 +1782,22 @@ view all branches of a thread." (length (alist-get 'descendants context))) 0) ;; if we have a thread: - (with-mastodon-buffer - buffer #'mastodon-mode nil - (let ((marker (make-marker))) - (mastodon-tl--set-buffer-spec buffer - endpoint - #'mastodon-tl--thread) - (mastodon-tl--timeline (alist-get 'ancestors context) - :thread) - (goto-char (point-max)) - (move-marker marker (point)) - ;; print re-fetched toot: - (mastodon-tl--toot toot :detailed-p :thread) - (mastodon-tl--timeline (alist-get 'descendants context) - :thread) - ;; put point at the toot: - (goto-char (marker-position marker)) - (mastodon-tl--goto-next-toot))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (let ((marker (make-marker))) + (mastodon-tl--set-buffer-spec buffer + endpoint + #'mastodon-tl--thread) + (mastodon-tl--timeline (alist-get 'ancestors context) + :thread) + (goto-char (point-max)) + (move-marker marker (point)) + ;; print re-fetched toot: + (mastodon-tl--toot toot :detailed-p :thread) + (mastodon-tl--timeline (alist-get 'descendants context) + :thread) + ;; put point at the toot: + (goto-char (marker-position marker)) + (mastodon-tl--goto-next-toot))) ;; else just print the lone toot: (mastodon-tl--single-toot id))))))) @@ -2596,11 +2594,10 @@ RESPONSE is the data returned from the server by JSON and http headers, without it just the JSON." (let ((json (if headers (car response) response))) (if (not json) ; praying this is right here, else try "\n[]" - (message "Looks like nothing returned from endpoint: %s" endpoint) + (message "Looks like nothing returned from endpoint: %s" endpoint) (let* ((headers (if headers (cdr response) nil)) (link-header (mastodon-tl--get-link-header-from-response headers))) - (with-mastodon-buffer buffer - #'mastodon-mode nil + (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-tl--set-buffer-spec buffer endpoint update-function @@ -2639,27 +2636,26 @@ Optional arg NOTE-TYPE means only get that type of note." (url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*")) (json (mastodon-http--get-json url args))) - (with-mastodon-buffer - buffer #'mastodon-mode nil - (setq - ;; Initialize with a minimal interval; we re-scan at least once - ;; every 5 minutes to catch any timestamps we may have missed - mastodon-tl--timestamp-next-update (time-add (current-time) - (seconds-to-time 300))) - (funcall update-function json) - (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args) - (setq mastodon-tl--timestamp-update-timer - (when mastodon-tl--enable-relative-timestamps - (run-at-time (time-to-seconds - (time-subtract mastodon-tl--timestamp-next-update - (current-time))) - nil ;; don't repeat - #'mastodon-tl--update-timestamps-callback - (current-buffer) - nil))) - (unless (mastodon-tl--profile-buffer-p) - ;; FIXME: this breaks test (because test has empty buffer) - (mastodon-tl--goto-first-item))) + (with-mastodon-buffer buffer #'mastodon-mode nil + (setq + ;; Initialize with a minimal interval; we re-scan at least once + ;; every 5 minutes to catch any timestamps we may have missed + mastodon-tl--timestamp-next-update (time-add (current-time) + (seconds-to-time 300))) + (funcall update-function json) + (mastodon-tl--set-buffer-spec buffer endpoint update-function nil args) + (setq mastodon-tl--timestamp-update-timer + (when mastodon-tl--enable-relative-timestamps + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) + nil ;; don't repeat + #'mastodon-tl--update-timestamps-callback + (current-buffer) + nil))) + (unless (mastodon-tl--profile-buffer-p) + ;; FIXME: this breaks test (because test has empty buffer) + (mastodon-tl--goto-first-item))) buffer)) (provide 'mastodon-tl) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1265132..a2fa35f 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -44,13 +44,15 @@ (require 'facemenu) (require 'text-property-search) +(eval-when-compile + (require 'mastodon-tl)) + (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--enable-proportional-fonts) (defvar mastodon-profile-account-settings) (autoload 'iso8601-parse "iso8601") -(autoload 'with-mastodon-buffer "mastodon") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--build-array-params-alist "mastodon-http") @@ -902,27 +904,26 @@ instance to edit a toot." (interactive) (let ((id (mastodon-tl--property 'base-toot-id)) (history (mastodon-tl--property 'edit-history))) - (with-mastodon-buffer - "*mastodon-toot-edits*" #'special-mode :other-window - (let ((count 1)) - (mapc (lambda (x) - (insert (propertize (if (= count 1) - (format "%s [original]:\n" count) - (format "%s:\n" count)) - 'face font-lock-comment-face) - (mastodon-toot--insert-toot-iter x) - "\n") - (cl-incf count)) - history)) - (setq-local header-line-format - (propertize - (format "Edits to toot by %s:" - (alist-get 'username - (alist-get 'account (car history)))) - 'face font-lock-comment-face)) - (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) - (format "statuses/%s/history" id) - nil)))) + (with-mastodon-buffer "*mastodon-toot-edits*" #'special-mode :other-window + (let ((count 1)) + (mapc (lambda (x) + (insert (propertize (if (= count 1) + (format "%s [original]:\n" count) + (format "%s:\n" count)) + 'face font-lock-comment-face) + (mastodon-toot--insert-toot-iter x) + "\n") + (cl-incf count)) + history)) + (setq-local header-line-format + (propertize + (format "Edits to toot by %s:" + (alist-get 'username + (alist-get 'account (car history)))) + 'face font-lock-comment-face)) + (mastodon-tl--set-buffer-spec (buffer-name (current-buffer)) + (format "statuses/%s/history" id) + nil)))) (defun mastodon-toot--insert-toot-iter (it) "Insert iteration IT of toot." diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 8585bb0..51e4bd6 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -36,6 +36,8 @@ (require 'cl-lib) (require 'mastodon-http) +(eval-when-compile + (require 'mastodon-tl)) (defvar mastodon-mode-map) (defvar mastodon-tl--horiz-bar) @@ -799,27 +801,26 @@ INSTANCE is the instance were are working with." (let* ((domain (url-file-nondirectory instance)) (buf (get-buffer-create (format "*mastodon-instance-%s*" domain)))) - (with-mastodon-buffer - buf #'special-mode :other-window - (when brief - (setq response - (list (assoc 'uri response) - (assoc 'title response) - (assoc 'short_description response) - (assoc 'email response) - (cons 'contact_account - (list - (assoc 'username - (assoc 'contact_account response)))) - (assoc 'rules response) - (assoc 'stats response)))) - (mastodon-views--print-json-keys response) - ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving - ;; split window - (mastodon-tl--set-buffer-spec (buffer-name buf) - "instance" - nil) - (goto-char (point-min)))))) + (with-mastodon-buffer buf #'special-mode :other-window + (when brief + (setq response + (list (assoc 'uri response) + (assoc 'title response) + (assoc 'short_description response) + (assoc 'email response) + (cons 'contact_account + (list + (assoc 'username + (assoc 'contact_account response)))) + (assoc 'rules response) + (assoc 'stats response)))) + (mastodon-views--print-json-keys response) + ;; (mastodon-mode) ; breaks our 'q' binding that avoids leaving + ;; split window + (mastodon-tl--set-buffer-spec (buffer-name buf) + "instance" + nil) + (goto-char (point-min)))))) (defun mastodon-views--format-key (el pad) "Format a key of element EL, a cons, with PAD padding." -- cgit v1.2.3