Last active
December 14, 2023 01:09
-
-
Save rtrppl/2f0397fc8d61be2dcd42b8e525fba43a to your computer and use it in GitHub Desktop.
Hacks for mastodon.el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun lt/mastodon-toot--copy-orgified-toot-to-clipboard () | |
"Copy org-ified toot at point to clipboard." | |
(interactive) | |
(let* ((toot (or (mastodon-tl--property 'base-toot) | |
(mastodon-tl--property 'item-json)))) | |
(let* ((url (mastodon-toot--toot-url)) | |
(content (mastodon-tl--content toot))) | |
(-let* ((dom (plz 'get url :as #'org-web-tools--sanitized-dom)) | |
((title . readable) (org-web-tools--eww-readable dom))) | |
(with-temp-buffer | |
(emacs-lisp-mode) | |
(insert content) | |
(let* ((content (buffer-substring (point-min) (point-max))) | |
(complete-toot (concat "\[\[" url "\]\[" (replace-regexp-in-string "\n" "" title) "\]\]\n\n" | |
"\"" (string-trim-right content) "\"\n"))) | |
(kill-new complete-toot) | |
(message "Copied: '%s' to the clipboard." title))))))) | |
(defun lt/mastodon-toot--copy-orgified-toot-to-org-capture () | |
"Copy org-ified toot at point to org-capture." | |
(interactive) | |
(lt/mastodon-toot--copy-orgified-toot-to-clipboard) | |
(org-capture) | |
(org-yank)) | |
(defun lt/mastodon-open-toot-in-browser () | |
"Opens toot at point in the browser." | |
(interactive) | |
(let* ((toot (or (mastodon-tl--property 'base-toot) | |
(mastodon-tl--property 'item-json)))) | |
(let* ((url (mastodon-toot--toot-url))) | |
(org-open-link-from-string url)))) | |
(define-key mastodon-mode-map (kbd "j") 'lt/mastodon-toot--copy-orgified-toot-to-clipboard) | |
(define-key mastodon-mode-map (kbd "J") 'lt/mastodon-toot--copy-orgified-toot-to-org-capture) | |
(define-key mastodon-mode-map (kbd "o") 'lt/mastodon-open-toot-in-browser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment