Created
April 27, 2019 17:30
-
-
Save goromlagche/63a6005eb7c0c3e3657ac339a8ac8458 to your computer and use it in GitHub Desktop.
sends til's to littil
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
(defun sendTil() | |
"Sends til to littil. If you select a region and sendTil then it will send the content of that region, else it will send the whole buffer content." | |
(interactive) | |
(request | |
"http://littil.io/api/tils" | |
:type "POST" | |
:data (json-encode '(("til" . (("snippet" . ,(if (use-region-p) | |
(buffer-substring (region-beginning) (region-end)) | |
(buffer-string))))))) | |
:headers '(("Content-Type" . "application/json") ("Authorization" . "Basic *your key*")) | |
:parser 'buffer-string | |
:success (lambda (&rest _) (message "Success!")) | |
:error (lambda (&rest _) (message "Failure!")) | |
:complete | |
(cl-function (lambda (&key data &allow-other-keys) | |
(with-current-buffer (get-buffer-create "*til demo*") | |
(erase-buffer) | |
(insert data) | |
(pop-to-buffer (current-buffer))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment