diff options
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r-- | lisp/mastodon-toot.el | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 82ad03b..a48d5d9 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -549,16 +549,18 @@ base toot." "Translate text of toot at point. Uses `lingva.el'." (interactive) - (if (not (require 'lingva nil :no-error)) - (message "Looks like you need to install lingva.el first.") - (if mastodon-tl--buffer-spec - (if-let ((toot (mastodon-tl--property 'item-json))) - (lingva-translate nil - (mastodon-tl--content toot) - (when mastodon-tl--enable-proportional-fonts - t)) - (message "No toot to translate?")) - (message "No mastodon buffer?")))) + (if mastodon-tl--buffer-spec + (if-let ((toot (mastodon-tl--property 'item-json))) + (condition-case x + (lingva-translate nil + (mastodon-tl--content toot) + (when mastodon-tl--enable-proportional-fonts + t)) + (void-function + (message "Looks like you need to install lingva.el. Error: %s" + (error-message-string x)))) + (message "No toot to translate?")) + (message "No mastodon buffer?"))) (defun mastodon-toot--own-toot-p (toot) "Check if TOOT is user's own, for deleting, editing, or pinning it." @@ -697,7 +699,7 @@ CANCEL means the toot was not sent, so we save the toot text as a draft." (mastodon-toot--restore-previous-window-config prev-window-config))) (defun mastodon-toot--cancel () - "Kill new-toot buffer/window. Does not POST content to Mastodon. + "Kill new-toot buffer/window. Does not POST content. If toot is not empty, prompt to save text as a draft." (interactive) (if (mastodon-toot--empty-p) @@ -838,7 +840,7 @@ to `emojify-user-emojis', and the emoji data is updated." ;;; SEND TOOT FUNCTION (defun mastodon-toot--send () - "POST contents of new-toot buffer to Mastodon instance and kill buffer. + "POST contents of new-toot buffer to fediverse instance and kill buffer. If media items have been attached and uploaded with `mastodon-toot--attach-media', they are attached to the toot. If `mastodon-toot--edit-item-id' is non-nil, PUT contents to @@ -1374,7 +1376,7 @@ LENGTH is the maximum character length allowed for a poll option." collect (read-string (format "Poll option [%s/%s] [max %s chars]: " x count length)))) - (longest (cl-reduce #'max (mapcar #'length choices)))) + (longest (apply #'max (mapcar #'length choices)))) (if (> longest length) (progn (message "looks like you went over the max length. Try again.") @@ -1843,7 +1845,15 @@ a draft into the buffer. EDIT means we are editing an existing toot, not composing a new one." (let* ((buffer-name (if edit "*edit toot*" "*new toot*")) (buffer-exists (get-buffer buffer-name)) - (buffer (or buffer-exists (get-buffer-create buffer-name))) + (buffer (if (not buffer-exists) + (get-buffer-create buffer-name) + ;; if a user hits reply while a compose buffer is already + ;; open, we really ought to wipe it all and start over. + (switch-to-buffer-other-window buffer-exists) + (if (not (y-or-n-p "Overwrite existing compose buffer?")) + (user-error "Aborting") + (kill-buffer-and-window) + (get-buffer-create buffer-name)))) (inhibit-read-only t) (reply-text (alist-get 'content (or (alist-get 'reblog reply-json) @@ -1858,19 +1868,18 @@ EDIT means we are editing an existing toot, not composing a new one." ;; use toot visibility setting from the server: (mastodon-profile--get-source-pref 'privacy) "public")) ; fallback - (unless buffer-exists - (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 - ;; reply-to-user. - (mastodon-toot--setup-as-reply reply-to-user reply-to-id reply-json - ;; only initial-text if reply (not edit): - (when reply-json initial-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 + ;; reply-to-user. + (mastodon-toot--setup-as-reply reply-to-user reply-to-id reply-json + ;; only initial-text if reply (not edit): + (when reply-json initial-text)) (unless mastodon-toot--max-toot-chars ;; no need to fetch from `mastodon-profile-account-settings' as ;; `mastodon-toot--max-toot-chars' is set when we set it @@ -1944,7 +1953,7 @@ Only text that is not one of these faces will be spell-checked." (define-minor-mode mastodon-toot-mode - "Minor mode to capture Mastodon toots." + "Minor mode for composing toots." :keymap mastodon-toot-mode-map :global nil) |