diff --git a/README.org b/README.org index 1d7b7f7..b89e42b 100644 --- a/README.org +++ b/README.org @@ -57,12 +57,12 @@ This can be added to the =:config= section of use-package: *** Confirm pasting with a yes/no confirmation before pasting To enable a confirmation dialog to always pop up and require you to confirm pasting before text is actually sent to a paste-provider you just need to set -the variable =webpaste/paste-confirmation= to a value that is non-nil. +the variable =webpaste-paste-confirmation= to a value that is non-nil. Example: #+begin_src emacs-lisp :tangle yes ;; Require confirmation before doing paste - (setq webpaste/paste-confirmation t) + (setq webpaste-paste-confirmation t) #+end_src Can also be put in the =:config= section of =use-package= the same way as the @@ -76,26 +76,26 @@ This is webpaste's default behavior. After a succesfull paste, the returned URL from the provider will be sent to the killring. You can disable this with #+BEGIN_SRC emacs-lisp -(setq webpaste/add-to-killring nil) +(setq webpaste-add-to-killring nil) #+END_SRC **** Copy URL to the clipboard -If you have [[https://github.com/rolandwalker/simpleclip][simpleclip]] installed, you can copy the returned URL to the +If you have [[https://github.com/rolandwalker/simpleclip][simpleclip]] installed, you can copy the returned URL to the clipboard. You can enable this with #+BEGIN_SRC emacs-lisp -(setq webpaste/copy-to-clipboard t) +(setq webpaste-copy-to-clipboard t) #+END_SRC **** Open the recently created paste in the browser To enable opening of recently created pastes in an external browser, you can -enable the option =webpaste/open-in-browser= by setting this value to a +enable the option =webpaste-open-in-browser= by setting this value to a non-nil value. Example: #+begin_src emacs-lisp :tangle yes ;; Open recently created pastes in an external browser - (setq webpaste/open-in-browser t) + (setq webpaste-open-in-browser t) #+end_src Can also be put in the =:config= section of =use-package= the same way as the diff --git a/tests/unit/test-webpaste-error-lambdas.el b/tests/unit/test-webpaste-error-lambdas.el index 7891c7c..2e23070 100644 --- a/tests/unit/test-webpaste-error-lambdas.el +++ b/tests/unit/test-webpaste-error-lambdas.el @@ -16,7 +16,7 @@ (it "with fallback" - (let ((error-lambda (webpaste/providers-error-lambda :text "my text"))) + (let ((error-lambda (webpaste-providers-error-lambda :text "my text"))) (funcall error-lambda :error-thrown "my error") (expect 'message @@ -30,7 +30,7 @@ (it "without fallback" - (let ((error-lambda (webpaste/providers-error-lambda-no-failover :text "my text"))) + (let ((error-lambda (webpaste-providers-error-lambda-no-failover :text "my text"))) (funcall error-lambda :error-thrown "my error") (expect 'message diff --git a/tests/unit/test-webpaste-get-provider-priority.el b/tests/unit/test-webpaste-get-provider-priority.el index af5d62b..549c695 100644 --- a/tests/unit/test-webpaste-get-provider-priority.el +++ b/tests/unit/test-webpaste-get-provider-priority.el @@ -16,7 +16,7 @@ ("provider3" . "lambda")))) ;; Do test - (expect (webpaste/get-provider-priority) + (expect (webpaste-get-provider-priority) :to-equal '("provider1" "provider2" "provider3")))) @@ -27,7 +27,7 @@ (let ((webpaste-provider-priority '("provider2" "provider1" "provider3"))) ;; Do test - (expect (webpaste/get-provider-priority) + (expect (webpaste-get-provider-priority) :to-equal '("provider2" "provider1" "provider3"))))) diff --git a/tests/unit/test-webpaste-paste-region-and-buffer.el b/tests/unit/test-webpaste-paste-region-and-buffer.el index 58c34f5..fb28f9d 100644 --- a/tests/unit/test-webpaste-paste-region-and-buffer.el +++ b/tests/unit/test-webpaste-paste-region-and-buffer.el @@ -12,10 +12,10 @@ (before-each (spy-on 'webpaste-paste-text) (spy-on 'yes-or-no-p :and-return-value nil) - (setq webpaste/paste-confirmation t)) + (setq webpaste-paste-confirmation t)) (after-each - (setq webpaste/paste-confirmation nil)) + (setq webpaste-paste-confirmation nil)) (it "can't paste because of answer to question is no" @@ -35,10 +35,10 @@ (before-each (spy-on 'webpaste-paste-text) (spy-on 'yes-or-no-p :and-return-value t) - (setq webpaste/paste-confirmation t)) + (setq webpaste-paste-confirmation t)) (after-each - (setq webpaste/paste-confirmation nil)) + (setq webpaste-paste-confirmation nil)) (it "can paste because of answer to question is yes" diff --git a/tests/unit/test-webpaste-paste-text.el b/tests/unit/test-webpaste-paste-text.el index 042612c..aedf6c9 100644 --- a/tests/unit/test-webpaste-paste-text.el +++ b/tests/unit/test-webpaste-paste-text.el @@ -8,11 +8,11 @@ (describe "Paste text to provider" - :var (webpaste/tested-providers) + :var (webpaste-tested-providers) (before-each ;; Override which fake providers exists - (spy-on 'webpaste/get-provider-priority + (spy-on 'webpaste-get-provider-priority :and-return-value '("provider1" "provider2")) @@ -20,7 +20,7 @@ (spy-on 'webpaste-paste-text-to-provider) ;; And let tested list be resetted for each test - (setq webpaste/tested-providers nil)) + (setq webpaste-tested-providers nil)) (it @@ -45,7 +45,7 @@ "provider2") ;; Check that the tested list is empty so another run would restart - (expect webpaste/tested-providers :to-equal nil))) + (expect webpaste-tested-providers :to-equal nil))) (describe diff --git a/tests/unit/test-webpaste-return-url.el b/tests/unit/test-webpaste-return-url.el index aaf9b36..22056f4 100644 --- a/tests/unit/test-webpaste-return-url.el +++ b/tests/unit/test-webpaste-return-url.el @@ -33,7 +33,7 @@ (it "can open an external browser with the url" - (let ((webpaste/open-in-browser t)) + (let ((webpaste-open-in-browser t)) (webpaste-return-url "https://example.com/") (expect 'browse-url-generic @@ -43,9 +43,9 @@ (it "can append language on return" - (let ((webpaste/provider-separators + (let ((webpaste-provider-separators '(("https://example.com/" . "?lang="))) - (webpaste/provider-lang-alists + (webpaste-provider-lang-alists '(("https://example.com/" . ((lisp-interaction-mode . "lisp")))))) (spy-calls-reset 'kill-new) @@ -58,8 +58,8 @@ (it "can put contents in clipboard using simpleclip" - (let ((webpaste/copy-to-clipboard t) - (webpaste/webpaste/add-to-killring nil)) + (let ((webpaste-copy-to-clipboard t) + (webpaste-add-to-killring nil)) (webpaste-return-url "https://example.com/") diff --git a/tests/unit/test-webpaste-success-lambdas.el b/tests/unit/test-webpaste-success-lambdas.el index 19e8a24..1f2f5e6 100644 --- a/tests/unit/test-webpaste-success-lambdas.el +++ b/tests/unit/test-webpaste-success-lambdas.el @@ -17,7 +17,7 @@ (it "using a response header" - (let ((success-lambda (webpaste/providers-success-location-header))) + (let ((success-lambda (webpaste-providers-success-location-header))) (funcall success-lambda :response "my fake response") (expect 'webpaste-return-url @@ -27,7 +27,7 @@ (xit "when using some request.el response thingy" - (let ((success-lambda (webpaste/providers-success-response-url))) + (let ((success-lambda (webpaste-providers-success-response-url))) (funcall success-lambda :response "my fake response") (expect 'webpaste-return-url @@ -38,7 +38,7 @@ (it "when returning a string with an url" - (let ((success-lambda (webpaste/providers-success-returned-string))) + (let ((success-lambda (webpaste-providers-success-returned-string))) (funcall success-lambda :data "\"https://example.com/\" ") diff --git a/webpaste.el b/webpaste.el index b61ee81..fb4fbf7 100644 --- a/webpaste.el +++ b/webpaste.el @@ -54,51 +54,53 @@ default to all providers in order defined in ‘webpaste-providers’ list." :type '(repeat string)) -(defcustom webpaste/paste-confirmation nil +(defcustom webpaste-paste-confirmation nil "Prompt for a yes/no confirmation before attempting to paste a region or buffer." :group 'webpaste :type 'boolean) -(defcustom webpaste/open-in-browser nil +(defcustom webpaste-open-in-browser nil "Open recently created pastes in a browser. This uses `browse-url-generic' to open URLs." :group 'webpaste :type 'boolean) -(defcustom webpaste/copy-to-clipboard nil + +(defcustom webpaste-copy-to-clipboard nil "Uses simpleclip to send the provider's returned URL to the clipboard. This uses `simpleclip-set-contents' to copy to clipboard." :group 'webpaste :type 'boolean) -(defcustom webpaste/add-to-killring t + +(defcustom webpaste-add-to-killring t "Add the returned URL to the killring after paste." :group 'webpaste :type 'boolean) -(defvar webpaste/tested-providers () +(defvar webpaste-tested-providers () "Variable for storing which providers to try in which order while running. This list will be re-populated each run based on ‘webpaste-provider-priority’ or if that variable is nil, it will use the list of names from ‘webpaste-providers’ each run.") -(defvar webpaste/provider-separators () +(defvar webpaste-provider-separators () "Variable for storing separators for providers that doesn't post language. Some providers accepts a post parameter with which language the code is. But some providers want to append the language to the resulting URL.") -(defvar webpaste/provider-lang-alists () +(defvar webpaste-provider-lang-alists () "Variable for storing alists with languages for highlighting for providers. This list will be populated when you add providers to have the languages precalculated, and also available both for pre and post request access.") -(defvar webpaste/default-lang-alist +(defvar webpaste-default-lang-alist '((css-mode . "css") (fundamental-mode . "text") (html-mode . "html") @@ -112,21 +114,21 @@ precalculated, and also available both for pre and post request access.") ;;; Predefined error lambda for providers -(cl-defun webpaste/providers-error-lambda (&key text) +(cl-defun webpaste-providers-error-lambda (&key text) "Predefined error callback for providers that always does failover." (cl-function (lambda (&key error-thrown &allow-other-keys) (message "Got error: %S" error-thrown) (webpaste-paste-text text)))) -(cl-defun webpaste/providers-error-lambda-no-failover (&key text) +(cl-defun webpaste-providers-error-lambda-no-failover (&key text) "Predefined error callback for providers that shouldn't do failover." (cl-function (lambda (&key error-thrown &allow-other-keys) (message "Got error: %S" error-thrown)))) ;;; Predefined success lambdas for providers -(cl-defun webpaste/providers-success-location-header () +(cl-defun webpaste-providers-success-location-header () "Predefined success callback for providers returning a Location header." (cl-function (lambda (&key response &allow-other-keys) (when response @@ -134,7 +136,7 @@ precalculated, and also available both for pre and post request access.") (request-response-header response "Location")))))) -(cl-defun webpaste/providers-success-response-url () +(cl-defun webpaste-providers-success-response-url () "Predefined success callback for providers that and up with an URL somehow." (cl-function (lambda (&key response &allow-other-keys) (when response @@ -142,7 +144,7 @@ precalculated, and also available both for pre and post request access.") (request-response-url response)))))) -(cl-defun webpaste/providers-success-returned-string () +(cl-defun webpaste-providers-success-returned-string () "Predefined success callback for providers returning a string with URL." (cl-function (lambda (&key data &allow-other-keys) (when data @@ -152,7 +154,7 @@ precalculated, and also available both for pre and post request access.") (webpaste-return-url data))))) -(cl-defun webpaste/providers-default-post-field-lambda () +(cl-defun webpaste-providers-default-post-field-lambda () "Predefined lambda for building post fields." (cl-function (lambda (&key text post-field @@ -162,7 +164,7 @@ precalculated, and also available both for pre and post request access.") (cl-pushnew (cons post-field text) post-data) ;; Fetch alist of languages for this provider - (let ((provider-lang-alist (cdr (assoc provider-uri webpaste/provider-lang-alists)))) + (let ((provider-lang-alist (cdr (assoc provider-uri webpaste-provider-lang-alists)))) ;; Fetch language name for this major mode for this provider (let ((language-name (cdr (assoc major-mode provider-lang-alist)))) (if (and post-lang-field-name language-name) @@ -172,11 +174,11 @@ precalculated, and also available both for pre and post request access.") -(defun webpaste/get-lang-alist-with-overrides (overrides) +(defun webpaste-get-lang-alist-with-overrides (overrides) "Fetches lang-alist with OVERRIDES applied." ;; Copy original list to temporary list - (let ((lang-alist webpaste/default-lang-alist)) + (let ((lang-alist webpaste-default-lang-alist)) ;; Go through list of overrides and append them to the temporary list (dolist (override-element overrides) (cl-pushnew override-element lang-alist)) @@ -195,8 +197,8 @@ precalculated, and also available both for pre and post request access.") (parser 'buffer-string) (lang-overrides '()) (lang-uri-separator nil) - (error-lambda 'webpaste/providers-error-lambda) - (post-field-lambda 'webpaste/providers-default-post-field-lambda)) + (error-lambda 'webpaste-providers-error-lambda) + (post-field-lambda 'webpaste-providers-default-post-field-lambda)) "Function to create the lambda function for a provider. Usage: @@ -210,8 +212,8 @@ Required params: :success-lambda Callback sent to `request', look up how to write these in the documentation for `request'. Two good examples are - `webpaste/providers-success-location-header' and - `webpaste/providers-success-returned-string' as well as the + `webpaste-providers-success-location-header' and + `webpaste-providers-success-returned-string' as well as the custom one used for the gist.github.com provider. Optional params: @@ -235,8 +237,8 @@ Optional params: :error-lambda Callback sent to `request', look up how to write these in the documentation for `request'. The default value for this is - `webpaste/providers-error-lambda', but there's also - `webpaste/providers-error-lambda-no-failover' available if + `webpaste-providers-error-lambda', but there's also + `webpaste-providers-error-lambda-no-failover' available if you need a provider that isn't allowed to failover. :post-field-lambda Function that builds and returns the post data that should be @@ -244,7 +246,7 @@ Optional params: the names TEXT, POST-FIELD and POST-DATA. POST-DATA should default to `nil' or empty list. It also takes the option LANG-OVERRIDES which is a list that enables overiding of - `webpaste/default-lang-alist'. + `webpaste-default-lang-alist'. TEXT contains the data that should be sent. POST-FIELD cointains the name of the field to be sent. @@ -252,11 +254,11 @@ Optional params: ;; If we get a separator sent to the function, append it to the list of ;; separators for later use (when lang-uri-separator - (cl-pushnew (cons uri lang-uri-separator) webpaste/provider-separators)) + (cl-pushnew (cons uri lang-uri-separator) webpaste-provider-separators)) ;; Add pre-calculated list of webpaste lang alists - (cl-pushnew (cons uri (webpaste/get-lang-alist-with-overrides lang-overrides)) - webpaste/provider-lang-alists) + (cl-pushnew (cons uri (webpaste-get-lang-alist-with-overrides lang-overrides)) + webpaste-provider-lang-alists) (cl-function (lambda (text @@ -289,7 +291,7 @@ Optional params: :post-field "c" :lang-uri-separator "/" :lang-overrides '((emacs-lisp-mode . "elisp")) - :success-lambda 'webpaste/providers-success-location-header)) + :success-lambda 'webpaste-providers-success-location-header)) ("ix.io" ,(webpaste-provider @@ -297,7 +299,7 @@ Optional params: :post-field "f:1" :lang-uri-separator "/" :lang-overrides '((emacs-lisp-mode . "elisp")) - :success-lambda 'webpaste/providers-success-returned-string)) + :success-lambda 'webpaste-providers-success-returned-string)) ("sprunge.us" ,(webpaste-provider @@ -305,7 +307,7 @@ Optional params: :post-field "sprunge" :lang-uri-separator "?" :lang-overrides '((emacs-lisp-mode . "elisp")) - :success-lambda 'webpaste/providers-success-returned-string)) + :success-lambda 'webpaste-providers-success-returned-string)) ("dpaste.com" ,(webpaste-provider @@ -316,7 +318,7 @@ Optional params: :post-field "content" :post-lang-field-name "syntax" :lang-overrides '((emacs-lisp-mode . "clojure")) - :success-lambda 'webpaste/providers-success-location-header)) + :success-lambda 'webpaste-providers-success-location-header)) ("dpaste.de" ,(webpaste-provider @@ -325,7 +327,7 @@ Optional params: :post-field "content" :post-lang-field-name "lexer" :lang-overrides '((emacs-lisp-mode . "clojure")) - :success-lambda 'webpaste/providers-success-returned-string)) + :success-lambda 'webpaste-providers-success-returned-string)) ("gist.github.com" ,(webpaste-provider @@ -350,7 +352,7 @@ Optional params: :post-field "code" :post-lang-field-name "language" :lang-overrides '((emacs-lisp-mode . "clojure")) - :success-lambda 'webpaste/providers-success-response-url))) + :success-lambda 'webpaste-providers-success-response-url))) "Define all webpaste.el providers. Consists of provider name and lambda function to do the actuall call to the @@ -359,7 +361,7 @@ return it to the user.") -(defun webpaste/get-provider-priority () +(defun webpaste-get-provider-priority () "Return provider priority." ;; Populate webpaste-provider-priority if needed @@ -381,11 +383,11 @@ return it to the user.") "Return RETURNED-URL to user from the result of the paste service." ;; Loop providers separators - (dolist (provider-separator webpaste/provider-separators) + (dolist (provider-separator webpaste-provider-separators) ;; Match if the separator is for this URI (when (string-match-p (regexp-quote (car provider-separator)) returned-url) ;; Get alist of languages for this provider - (let ((provider-lang-alist (cdr (assoc (car provider-separator) webpaste/provider-lang-alists)))) + (let ((provider-lang-alist (cdr (assoc (car provider-separator) webpaste-provider-lang-alists)))) ;; Get language name from list of languages (let ((language-name (cdr (assoc major-mode provider-lang-alist)))) ;; If we get a language name @@ -394,19 +396,19 @@ return it to the user.") (setq returned-url (concat returned-url (cdr provider-separator) language-name))))))) ;; Reset tested providers after successful paste - (setq webpaste/tested-providers nil) + (setq webpaste-tested-providers nil) ;; If the user want to open the link in an external browser, do so. - (when webpaste/open-in-browser + (when webpaste-open-in-browser (browse-url-generic returned-url)) ;; Send RETURNED-URL to the clipboard using simpleclip - (when webpaste/copy-to-clipboard + (when webpaste-copy-to-clipboard (simpleclip-set-contents returned-url) (message "URL copied to clipboard.")) ;; Add RETURNED-URL to killring for easy pasting - (when webpaste/add-to-killring + (when webpaste-add-to-killring (kill-new returned-url) (message "Added %S to kill ring." returned-url))) @@ -426,25 +428,25 @@ make `webpaste-paste-text' do less magic things all at once." If ‘webpaste-provider-priority’ isn't populated, it will populate it with the default providers. -Then if ‘webpaste/tested-providers’ isn't populated it will be populated by +Then if ‘webpaste-tested-providers’ isn't populated it will be populated by ‘webpaste-provider-priority’. -Then it extracts the first element of ‘webpaste/tested-providers’ and drops +Then it extracts the first element of ‘webpaste-tested-providers’ and drops the first element from that list and gets the lambda for the provider and runs the lambda to paste TEXT to the paste service. The paste-service in turn might call this function again with TEXT as param to retry if it failed. When we run out of providers to try, it will restart since -‘webpaste/tested-providers’ will be empty and then populated again." +‘webpaste-tested-providers’ will be empty and then populated again." ;; Populate tested providers for this request if needed - (unless webpaste/tested-providers - (setq webpaste/tested-providers (webpaste/get-provider-priority))) + (unless webpaste-tested-providers + (setq webpaste-tested-providers (webpaste-get-provider-priority))) ;; Get name of provider at the top of the list - (let ((provider-name (car webpaste/tested-providers))) + (let ((provider-name (car webpaste-tested-providers))) ;; Drop the name at the top of the list - (setq webpaste/tested-providers (cdr webpaste/tested-providers)) + (setq webpaste-tested-providers (cdr webpaste-tested-providers)) ;; Run pasting function (webpaste-paste-text-to-provider text provider-name))) @@ -458,7 +460,7 @@ Argument MARK Current mark." (interactive "r") ;; unless we wanted a paste confirmation and declined - (unless (and webpaste/paste-confirmation + (unless (and webpaste-paste-confirmation (not (yes-or-no-p "paste entire region?"))) ;; Extract the buffer contents with buffer-substring and paste it (webpaste-paste-text (buffer-substring point mark)))) @@ -470,7 +472,7 @@ Argument MARK Current mark." (interactive) ;; unless we wanted a paste confirmation and declined - (unless (and webpaste/paste-confirmation + (unless (and webpaste-paste-confirmation (not (yes-or-no-p "paste entire buffer?"))) ;; Extract the buffer contents with buffer-substring and paste it (webpaste-paste-text (buffer-substring (point-min) (point-max)))))