From 2a05d0274cbf5bb723ab087566c2dc12fe1a96b7 Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Sat, 10 Jun 2017 19:05:33 +0200 Subject: [PATCH] Added supports for custom hooks when returning URLs. This fixes #22. --- README.org | 16 ++++++++++++++++ webpaste.el | 14 +++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index b89e42b..f9960d0 100644 --- a/README.org +++ b/README.org @@ -101,6 +101,22 @@ Example: Can also be put in the =:config= section of =use-package= the same way as the provider definitions above. +**** Use a custom hook +You can define a custom hook to send your URL's to when returning them from +the paste provider. This is just like regular hooks for major modes etc. You +can have several hooks as well if you want it to do several custom things. + +#+begin_src emacs-lisp + ;; Simple hook to just message the URL, this is more or less the default + ;; already. But if you disable the default and still want a message, this + ;; would work fine. + (add-hook 'webpaste-return-url-hook 'message) + + ;; To build your own send-to-browser hook, you could do like this: + (add-hook 'webpaste-return-url-hook + (lambda (url) (browse-url-generic url))) +#+end_src + ** TODO Providers to implement [7/10] - [X] ptpb.pw - [X] ix.io diff --git a/webpaste.el b/webpaste.el index 6f0f536..ae8fc8e 100644 --- a/webpaste.el +++ b/webpaste.el @@ -79,6 +79,11 @@ This uses `simpleclip-set-contents' to copy to clipboard." :group 'webpaste :type 'boolean) +(defcustom webpaste-return-url-hook nil + "Hook executed with the returned url as parameter." + :group 'webpaste + :type 'hook) + (defvar webpaste-tested-providers () @@ -410,7 +415,14 @@ return it to the user.") ;; Add RETURNED-URL to killring for easy pasting (when webpaste-add-to-killring (kill-new returned-url) - (message "Added %S to kill ring." returned-url))) + (message "Added %S to kill ring." returned-url)) + + ;; Run user defined hooks + (dolist (hook webpaste-return-url-hook) + (funcall hook returned-url)) + + ;; Return URL instead of nil + returned-url)