Last active
September 16, 2023 19:36
-
-
Save xenodium/7cb21cf64a1db49f3984617e02e85fc0 to your computer and use it in GitHub Desktop.
Select text in an Emacs buffer and send with M-x send-to-kindle-as-txt
This file contains 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
(defcustom send-to-kindle-from-email | |
nil | |
"Your own email address to send from via mu4e." | |
:type 'string | |
:group 'send-to-kindle) | |
(defcustom send-to-kindle-to-email | |
nil | |
"Your Kindle email address to send pdf to." | |
:type 'string | |
:group 'send-to-kindle) | |
(defun send-to-kindle-as-txt (review) | |
(interactive "P") | |
(unless send-to-kindle-from-email | |
(setq send-to-kindle-from-email | |
(read-string "From email address: "))) | |
(unless send-to-kindle-to-email | |
(setq send-to-kindle-to-email | |
(read-string "To email address: "))) | |
(let* ((content (string-trim (if (region-active-p) | |
(buffer-substring (region-beginning) (region-end)) | |
(buffer-string)))) | |
(note-name (let ((name (string-trim (read-string "Note name: ")))) | |
(if (string-empty-p name) | |
(nth | |
0 (string-split | |
(substring content 0 (min 40 (length content))) "\n")) | |
name))) | |
(path (concat (temporary-file-directory) note-name)) | |
(txt (concat path ".txt")) | |
(buffer (get-buffer-create (generate-new-buffer-name "*Email txt*")))) | |
(with-temp-buffer | |
(insert content) | |
(write-file txt)) | |
(with-current-buffer buffer | |
(erase-buffer) | |
(message-mode) | |
(insert | |
(format | |
"From: %s | |
To: %s | |
Subject: %s | |
--text follows this line-- | |
<#multipart type=mixed> | |
<#part type=\"text/plain\" filename=\"%s\" disposition=attachment> | |
<#/part> | |
<#/multipart>" | |
send-to-kindle-from-email | |
send-to-kindle-to-email | |
note-name txt)) | |
(unless review | |
(message-send-and-exit))) | |
(when review | |
(switch-to-buffer buffer)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment