aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authorclarkenciel <clarkenciel@gmail.com>2017-04-27 10:41:14 -0700
committerJohnson Denen <johnson.denen@gmail.com>2017-04-28 19:57:23 -0400
commit3cb4464ac7d06943b7a19cff3c171d7ecbefb3b8 (patch)
treec2daa77468a427352d0e70b9f50ae70f433efaf1 /lisp/mastodon-toot.el
parent773d5b8cad3b029a8c1d230db5715d06df0ad525 (diff)
adding keybinding documentation to the new-toot buffer
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el58
1 files changed, 57 insertions, 1 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 84d0286..6e70f8b 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -101,10 +101,15 @@ Set `mastodon-toot--content-warning' to nil."
(interactive)
(mastodon-toot--kill))
+(defun mastodon-toot--remove-docs (toot-buffer-contents)
+ "Get the body of a toot from a TOOT-BUFFER-CONTENTS composed in a toot compose buffer."
+ (let ((re "^=+\\(\n\\|.\\)*=+\nToot Text:\n\n"))
+ (replace-regexp-in-string re "" toot-buffer-contents)))
+
(defun mastodon-toot--send ()
"Kill new-toot buffer/window and POST contents to the Mastodon instance."
(interactive)
- (let* ((toot (buffer-string))
+ (let* ((toot (mastodon-toot--remove-docs (buffer-string)))
(endpoint (mastodon-http--api "statuses"))
(spoiler (when mastodon-toot--content-warning
(read-string "Warning: ")))
@@ -134,6 +139,57 @@ Set `mastodon-toot--content-warning' to nil."
(setq mastodon-toot--content-warning
(not mastodon-toot--content-warning)))
+(defun mastodon-toot--get-mode-kbinds ()
+ "Get a list of the keybindings in the mastodon-toot-mode."
+ (remove-if-not (lambda (x) (listp x))
+ (cadr mastodon-toot-mode-map)))
+
+(defun mastodon-toot--format-kbind (kbind)
+ "Format a single keybinding, KBIND, for display in documentation."
+ (let ((key (help-key-description (vector (car kbind)) nil))
+ (command (cdr kbind)))
+ (format "\t%s - %s" key command)))
+
+(defun mastodon-toot--format-kbinds (kbinds)
+ "Format a list keybindings, KBINDS, for display in documentation."
+ (string-join (cons "" (mapcar #'mastodon-toot--format-kbind kbinds))
+ "\n"))
+
+(defun mastodon-toot--make-mode-docs ()
+ "Create formatted documentation text for the mastodon-toot-mode."
+ (let ((kbinds (mastodon-toot--get-mode-kbinds)))
+ (concat
+ "=================================================================\n"
+ "Compose a new toot here. The following keybindings are available:"
+ (mastodon-toot--format-kbinds kbinds)
+ "\n=================================================================\n"
+ "Toot Text:\n\n")))
+
+(defun mastodon-toot--display-docs ()
+ "Display documentation about mastodon-toot mode."
+ (insert
+ (propertize
+ (mastodon-toot--make-mode-docs)
+ 'face 'comment)))
+
+(defun mastodon-toot--setup-as-reply (reply-to-user reply-to-id)
+ "If REPLY-TO-USER is provided, inject their handle into the message.
+If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var."
+ (when reply-to-user
+ (insert (format "@%s " reply-to-user))
+ (setq mastodon-toot--reply-to-id reply-to-id)))
+
+(defun mastodon-toot--compose-buffer (reply-to-user reply-to-id)
+ "Create a new buffer to capture text for a new toot.
+If REPLY-TO-USER is provided, inject their handle into the message.
+If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var."
+ (let ((buffer (get-buffer-create "*new toot*")))
+ (switch-to-buffer-other-window buffer)
+ (mastodon-toot--display-docs)
+ (mastodon-toot--setup-as-reply reply-to-user reply-to-id)
+ (mastodon-toot-mode t)
+ ))
+
(defvar mastodon-toot-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'mastodon-toot--send)