Last active
June 12, 2020 16:30
-
-
Save freyes/a987bbaae4a33f00d07cba8001738922 to your computer and use it in GitHub Desktop.
emacs webpaste support for https://paste.ubuntu.com
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
(require 'request) | |
(require 'cl-lib) | |
(require 'webpaste) | |
(defun paste-ubuntu-field-lambda () | |
"lambda for building post compatible with paste.ubuntu.com." | |
(cl-function (lambda (&key text | |
post-field | |
provider-uri | |
(post-lang-field-name nil) | |
(post-data '())) | |
(cl-pushnew (cons post-field text) post-data) | |
;; Fetch language name for this provider | |
(let ((language-name (webpaste--get-buffer-language provider-uri))) | |
(if (and post-lang-field-name language-name) | |
;; Append language to the post-data | |
(cl-pushnew (cons post-lang-field-name language-name) post-data) | |
;; if language coudn't be detected simply use text the | |
;; default handler ommits the post-lang-field-name if | |
;; couldn't be detected, but for paste.ubuntu.com this is | |
;; mandatory | |
(cl-pushnew (cons post-lang-field-name "text") post-data) | |
)) | |
post-data))) | |
(cl-defun paste-ubuntu-location-header () | |
"Callback to get the Location header and append it to paste.ubuntu.com." | |
(cl-function (lambda (&key response &allow-other-keys) | |
(when response | |
(webpaste--return-url | |
(request-response-url response)))))) | |
(add-to-list | |
'webpaste-providers-alist | |
'("paste.ubuntu.com" | |
:uri "https://paste.ubuntu.com/" | |
:post-data (("poster" . (user-login-name)) | |
;; make the paste expire in a week. | |
("expiration" . "week")) | |
:post-field "content" | |
:post-lang-field-name "syntax" | |
:post-field-lambda paste-ubuntu-field-lambda | |
:success-lambda paste-ubuntu-location-header | |
) | |
) | |
(setq webpaste-provider-priority '("paste.ubuntu.com")) | |
;; To build your own hook to use simpleclip, you could do like this: | |
(add-hook 'webpaste-return-url-hook | |
(lambda (url) | |
(message "Copied URL to clipboard: %S" url) | |
(simpleclip-set-contents url))) | |
;; Open recently created pastes in an external browser | |
(setq webpaste-open-in-browser t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment