Skip to content

Instantly share code, notes, and snippets.

@goromlagche
Created April 27, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goromlagche/63a6005eb7c0c3e3657ac339a8ac8458 to your computer and use it in GitHub Desktop.
Save goromlagche/63a6005eb7c0c3e3657ac339a8ac8458 to your computer and use it in GitHub Desktop.
sends til's to littil
(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