From b607c4e800235312350b56f7e845a56fe6b29248 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 11 Sep 2022 14:40:22 +0200 Subject: docstrings autoloads local funs --- lisp/mastodon-toot.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 2f58bfb..f1d4343 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -50,6 +50,8 @@ (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--enable-proportional-fonts) +(defvar mastodon-profile-account-settings) + (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--delete "mastodon-http") @@ -196,13 +198,17 @@ send.") nil t))) (mastodon-profile--update-preference "privacy" vis :source))) -(defun mastodon-toot--get-max-toot-chars (&optional no-toot) - "Fetch max_toot_chars from `mastodon-instance-url' asynchronously." +(defun mastodon-toot--get-max-toot-chars (&optional _no-toot) + "Fetch max_toot_chars from `mastodon-instance-url' asynchronously. +NO-TOOT means we are not calling from a toot buffer." (mastodon-http--get-json-async - (mastodon-http--api "instance") 'mastodon-toot--get-max-toot-chars-callback 'no-toot)) + (mastodon-http--api "instance") + 'mastodon-toot--get-max-toot-chars-callback 'no-toot)) -(defun mastodon-toot--get-max-toot-chars-callback (json-response &optional no-toot) - "Set max_toot_chars returned in JSON-RESPONSE and display in new toot buffer." +(defun mastodon-toot--get-max-toot-chars-callback (json-response + &optional no-toot) + "Set max_toot_chars returned in JSON-RESPONSE and display in new toot buffer. +NO-TOOT means we are not calling from a toot buffer." (let ((max-chars (or (alist-get 'max_toot_chars json-response) @@ -1066,16 +1072,15 @@ REPLY-JSON is the full JSON of the toot being replied to." (list 'invisible (not mastodon-toot--content-warning) 'face 'mastodon-cw-face))))) -(defun mastodon-toot-save-toot-text (&rest _args) +(defun mastodon-toot--save-toot-text (&rest _args) "Save the current toot text in `mastodon-toot-current-toot-text'. Added to `after-change-functions' in new toot buffers." - (interactive) (let ((text (mastodon-toot--remove-docs))) (unless (string-empty-p text) (setq mastodon-toot-current-toot-text text)))) (defun mastodon-toot-open-draft-toot () - "Prompt for a draft toot and open a new compose buffer containing the draft." + "Prompt for a draft and compose a toot with it." (interactive) (if mastodon-toot-draft-toots-list (let ((text (completing-read "Select draft toot: " @@ -1165,7 +1170,7 @@ a draft into the buffer." (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--save-toot-text after-change-functions) (when initial-text (insert initial-text)))) -- cgit v1.2.3 From 16acbea70362310985667a6eb65b60863f97448a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 11 Sep 2022 14:40:32 +0200 Subject: prompt to save draft on toot cancel --- lisp/mastodon-toot.el | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f1d4343..79a99ad 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -465,26 +465,32 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (mastodon-toot-set-cw toot-cw) (mastodon-toot--update-status-fields)))) -(defun mastodon-toot--kill (&optional cancel) - "Kill `mastodon-toot-mode' buffer and window. -CANCEL means the toot was not sent, so we save the toot text as a draft." +(defun mastodon-toot--kill () + "Kill `mastodon-toot-mode' buffer and window." (with-current-buffer (get-buffer "*new toot*") - (unless (eq mastodon-toot-current-toot-text nil) - (when cancel - (cl-pushnew mastodon-toot-current-toot-text - mastodon-toot-draft-toots-list :test 'equal))) - ;; prevent some weird bug when cancelling a non-empty toot: - (delete #'mastodon-toot-save-toot-text after-change-functions) + ;; FIXME: prevent some weird bug when cancelling a non-empty toot: + (delete #'mastodon-toot--save-toot-text after-change-functions) (kill-buffer-and-window))) (defun mastodon-toot--cancel () "Kill new-toot buffer/window. Does not POST content to Mastodon. -Toot text is saved as a draft." +If toot is not empty, prompt to save text as a draft." (interactive) (if (mastodon-toot-empty-p) - (mastodon-toot--kill :cancel) - (when (y-or-n-p "Discard draft toot? (text will be saved)") - (mastodon-toot--kill :cancel)))) + (mastodon-toot--kill) + (when (y-or-n-p "Save draft toot?") + (mastodon-toot-save-draft)) + (mastodon-toot--kill))) + +(defun mastodon-toot-save-draft () + "Save the current compose toot text as a draft. +Pushes `mastodon-toot-current-toot-text' to +`mastodon-toot-draft-toots-list'." + (interactive) + (unless (eq mastodon-toot-current-toot-text nil) + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal) + (message "Draft saved!"))) (defun mastodon-toot-empty-p (&optional text-only) "Return t if no text or attachments have been added to the compose buffer. -- cgit v1.2.3 From 9420b5ee57eeab7a62297cbf56c37f979c46a02b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 20 Sep 2022 14:44:22 +0200 Subject: FIX getting of 'parent-toot properties in mastodon-toot--reply --- lisp/mastodon-toot.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 79a99ad..076405c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -774,7 +774,9 @@ Customize `mastodon-toot-display-orig-in-reply-buffer' to display text of the toot being replied to in the compose buffer." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling + ;; NB: we cannot use mastodon-tl--property for 'parent-toot + ;; because if it doesn't have one, it is fetched from next toot! + (parent (get-text-property (point) 'parent-toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) -- cgit v1.2.3 From 020c8efaa235e67aaa07284beae84dd9134fbc90 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 20 Sep 2022 14:44:22 +0200 Subject: FIX getting of 'parent-toot properties in mastodon-toot--reply --- lisp/mastodon-toot.el | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 076405c..172839c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -774,9 +774,7 @@ Customize `mastodon-toot-display-orig-in-reply-buffer' to display text of the toot being replied to in the compose buffer." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - ;; NB: we cannot use mastodon-tl--property for 'parent-toot - ;; because if it doesn't have one, it is fetched from next toot! - (parent (get-text-property (point) 'parent-toot)) ; for new notifs handling + (parent (mastodon-tl--field 'parent-toot toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) -- cgit v1.2.3 From e07ccef99359230a88b33360e1a5657a6bf49b33 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 27 Oct 2022 12:53:03 +0200 Subject: FIX fetching parent toot in --reply, for notifs --- 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 172839c..79a99ad 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -774,7 +774,7 @@ Customize `mastodon-toot-display-orig-in-reply-buffer' to display text of the toot being replied to in the compose buffer." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - (parent (mastodon-tl--field 'parent-toot toot)) ; for new notifs handling + (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) -- cgit v1.2.3 From 50bd192c33e018ca207fe6734597786b2c17fc3c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Oct 2022 12:34:37 +0200 Subject: Revert "FIX getting of 'parent-toot properties in mastodon-toot--reply" this FIXes the FIX and the other FIX so that it should finally be FIXXXED This reverts commit 020c8efaa235e67aaa07284beae84dd9134fbc90. --- lisp/mastodon-toot.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 79a99ad..a96bdbf 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -774,7 +774,10 @@ Customize `mastodon-toot-display-orig-in-reply-buffer' to display text of the toot being replied to in the compose buffer." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) - (parent (mastodon-tl--property 'parent-toot)) ; for new notifs handling + ;; NB: we cannot use mastodon-tl--property for 'parent-toot + ;; because if it doesn't have one, it is fetched from next toot! + ;; we also cannot use --field because we need to get a different property first + (parent (get-text-property (point) 'parent-toot)) ; for new notifs handling (id (mastodon-tl--as-string (mastodon-tl--field 'id (or parent toot)))) (account (mastodon-tl--field 'account toot)) -- cgit v1.2.3 From 4bfe8b8696ae36e3331f6900101aed003185be90 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Oct 2022 13:27:51 +0200 Subject: restore -toot--kill fun for use with draft toot functionality --- lisp/mastodon-toot.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a96bdbf..bcf9c83 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -465,12 +465,16 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (mastodon-toot-set-cw toot-cw) (mastodon-toot--update-status-fields)))) -(defun mastodon-toot--kill () - "Kill `mastodon-toot-mode' buffer and window." - (with-current-buffer (get-buffer "*new toot*") - ;; FIXME: prevent some weird bug when cancelling a non-empty toot: - (delete #'mastodon-toot--save-toot-text after-change-functions) - (kill-buffer-and-window))) +(defun mastodon-toot--kill (&optional cancel) + "Kill `mastodon-toot-mode' buffer and window. +CANCEL means the toot was not sent, so we save the toot text as a draft." + (unless (eq mastodon-toot-current-toot-text nil) + (when cancel + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal))) + ;; prevent some weird bug when cancelling a non-empty toot: + (delete #'mastodon-toot-save-toot-text after-change-functions) + (kill-buffer-and-window)) (defun mastodon-toot--cancel () "Kill new-toot buffer/window. Does not POST content to Mastodon. -- cgit v1.2.3