From f014c4fca064783d0fd20395f911ecb98b2199ce Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Sun, 30 Jul 2023 12:28:59 +0300 Subject: [PATCH] feat(emacs): attach files to mastodon --- .emacs.d/init.el | 18 +++++++++++++++++- Emacs.org | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index f0dea79..7f6eb34 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -4451,6 +4451,21 @@ With ARG, repeats or can move backward if negative." ement-room ement-session))))) +(defun my/dired-attach-to-mastodon (files mastodon-buffer) + (interactive + (list (dired-get-marked-files nil nil #'dired-nondirectory-p) + (or (cl-loop for buf being the buffers + if (eq (buffer-local-value 'mastodon-toot-mode buf) t) + return buf) + (user-error "No buffer found!")))) + (unless files + (user-error "No (non-directory) files selected")) + (with-current-buffer mastodon-buffer + (dolist (file files) + (mastodon-toot--attach-media + file + (read-from-minibuffer (format "Description for %s: " file)))))) + (with-eval-after-load 'dired (general-define-key :states '(normal) @@ -4458,7 +4473,8 @@ With ARG, repeats or can move backward if negative." "a" nil "at" #'my/dired-attach-to-telega "am" #'my/dired-attach-to-notmuch - "ai" #'my/dired-attach-to-ement)) + "ai" #'my/dired-attach-to-ement + "an" #'my/dired-attach-to-mastodon)) (when my/is-termux (straight-use-package 'vterm)) diff --git a/Emacs.org b/Emacs.org index 36f6543..746f0b0 100644 --- a/Emacs.org +++ b/Emacs.org @@ -6335,6 +6335,24 @@ Attach files to ement. ement-session))))) #+end_src +Attach files to mastodon. +#+begin_src emacs-lisp +(defun my/dired-attach-to-mastodon (files mastodon-buffer) + (interactive + (list (dired-get-marked-files nil nil #'dired-nondirectory-p) + (or (cl-loop for buf being the buffers + if (eq (buffer-local-value 'mastodon-toot-mode buf) t) + return buf) + (user-error "No buffer found!")))) + (unless files + (user-error "No (non-directory) files selected")) + (with-current-buffer mastodon-buffer + (dolist (file files) + (mastodon-toot--attach-media + file + (read-from-minibuffer (format "Description for %s: " file)))))) +#+end_src + And the keybindings: #+begin_src emacs-lisp (with-eval-after-load 'dired @@ -6344,7 +6362,8 @@ And the keybindings: "a" nil "at" #'my/dired-attach-to-telega "am" #'my/dired-attach-to-notmuch - "ai" #'my/dired-attach-to-ement)) + "ai" #'my/dired-attach-to-ement + "an" #'my/dired-attach-to-mastodon)) #+end_src ** Shells / Terminals *** vterm