[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/webpaste 0e4ac51 132/298: Added support for buffer-languag
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/webpaste 0e4ac51 132/298: Added support for buffer-language depending on mode for some providers |
Date: |
Thu, 9 Dec 2021 18:59:59 -0500 (EST) |
branch: elpa/webpaste
commit 0e4ac51b5745e72461cd6b400af428d5f4f39c93
Author: Elis Axelsson <elis.axelsson@gmail.com>
Commit: Elis Axelsson <elis.axelsson@gmail.com>
Added support for buffer-language depending on mode for some providers
This only works for providers that posts this info when creating the
paste. Currently 3/6 providers does this. The rest of them just
transforms the URL on return which is slightly different and will be
solved later.
This refs #7.
Squashed commit of the following:
commit 612c2c4a0d9278d1ed3c7d794dca29acfa91e647
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 16:24:41 2017 +0200
Enable gist.github.com paste code highlighting by sending filename
commit f7fc4366b8a514247eaf9a6568da0632f2ee4c93
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 16:09:58 2017 +0200
Repair github by allowing other keys so it doesn't break again
commit 16cf85a74f94f5c2ab059d99dab835de643221d1
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 16:02:17 2017 +0200
Set clojure for emacs-lisp-mode for dpaste.com and dpaste.de
commit 442187a27fe32be028483367ca70aee797698148
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 15:55:59 2017 +0200
Added option lang-overrides to webpaste-provider to enable overiding of
language mappings
commit 2691c6690e7a4ed5bddb1fa4c27e09aea9b61887
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 15:39:18 2017 +0200
Added ert-test for the lang-alist overrides
commit a9b651024f9360793406f51572a5732b912bb4f8
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 14:55:46 2017 +0200
Added function to apply an override list to the default list and return
it
commit e282bbb8a72ea580a8d72c67873ca0b44b7c789c
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 12:58:27 2017 +0200
Added language field to dpaste.com and dpaste.de
commit e8671743d2ee6afc8ae9a42b64d1a9bdea800d67
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 12:14:15 2017 +0200
Logic to add fields to add language to post data
commit 71cab8124b596d7e8e36ac71399cd64e16f48d42
Author: Elis Axelsson <elis.axelsson@gmail.com>
Date: Wed May 3 09:18:29 2017 +0200
Added a small first list of mode to language mappings.
---
test/webpaste-test.el | 31 ++++++++++++++++++
webpaste.el | 91 ++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 110 insertions(+), 12 deletions(-)
diff --git a/test/webpaste-test.el b/test/webpaste-test.el
index 3363aac..056735a 100644
--- a/test/webpaste-test.el
+++ b/test/webpaste-test.el
@@ -167,6 +167,37 @@ result from the good provider only."
;; Check that we got the expected result
(should (string= returned-result "Working: test-string"))))
+
+
+(ert-deftest webpaste-test/get-lang-alist-with-overrides ()
+ "This test tests all cases that should happen when overriding langs."
+
+ (let ((webpaste/default-lang-alist '((python-mode . "python")
+ (php-mode . "php"))))
+
+ ;; Test adding mode
+ (should (equal (webpaste/get-lang-alist-with-overrides
+ '((emacs-lisp-mode . "lisp")))
+
+ '((emacs-lisp-mode . "lisp")
+ (python-mode . "python")
+ (php-mode . "php"))))
+
+ ;; Test removing mode / clearing it's value
+ (should (equal (webpaste/get-lang-alist-with-overrides
+ '((python-mode . nil)))
+
+ '((python-mode)
+ (python-mode . "python")
+ (php-mode . "php"))))
+
+ ;; Test overriding mode
+ (should (equal (webpaste/get-lang-alist-with-overrides
+ '((python-mode . "python3")))
+
+ '((python-mode . "python3")
+ (python-mode . "python")
+ (php-mode . "php"))))))
;;; webpaste-test.el ends here
diff --git a/webpaste.el b/webpaste.el
index 079ccf5..0a72d88 100644
--- a/webpaste.el
+++ b/webpaste.el
@@ -54,6 +54,21 @@ default to all providers in order defined in
‘webpaste-providers’ list."
:type '(repeat string))
+(defcustom webpaste/default-lang-alist
+ '((css-mode . "css")
+ (fundamental-mode . "text")
+ (html-mode . "html")
+ (java-mode . "java")
+ (js-mode . "js")
+ (go-mode . "go")
+ (php-mode . "php")
+ (python-mode . "python")
+ (yaml-mode . "yaml"))
+ "Alist that maps `major-mode' names to language names."
+ :type '(alist :key-type symbol :value-type string)
+ :group 'webpaste)
+
+
(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
@@ -98,9 +113,21 @@ each run.")
(defvar webpaste/providers-default-post-field-lambda
(cl-function (lambda (&key text
post-field
+ (post-lang-field-name nil)
+ (lang-overrides nil)
(post-data '()))
(cl-pushnew (cons post-field text) post-data)
+ (when post-lang-field-name
+ ;; Get language name based on major-mode
+ (let ((language-name (cdr (assoc major-mode
(webpaste/get-lang-alist-with-overrides lang-overrides)))))
+ ;; If not set correctly, get the fundamental-mode one
which should be plaintext
+ (unless language-name
+ (setq language-name (cdr (assoc 'fundamental-mode
(webpaste/get-lang-alist-with-overrides lang-overrides)))))
+
+ ;; Append language to the post-data
+ (cl-pushnew (cons post-lang-field-name language-name)
post-data)))
+
post-data))
"Predefined lambda for building post fields.")
@@ -111,7 +138,9 @@ each run.")
success-lambda
(type "POST")
(post-data '())
+ (post-lang-field-name nil)
(parser 'buffer-string)
+ (lang-overrides '())
(error-lambda
webpaste/providers-error-lambda)
(post-field-lambda
webpaste/providers-default-post-field-lambda)
(sync nil))
@@ -137,6 +166,13 @@ Optional params:
:post-data Default post fields sent to service. Defaults to nil.
+:post-lang-field-name Fieldname for defining which language your paste should
+ use to the provider.
+
+:lang-overrides Alist defining overides for languages for this provider. If
+ a mode is set to nil, it will use fundamental-mode's value
as
+ fallback. Fundamental-mode's value can also be overridden.
+
:parser Defines how request.el parses the result. Look up :parser
for
`request'. This defaults to 'buffer-string.
@@ -149,7 +185,9 @@ Optional params:
:post-field-lambda Function that builds and returns the post data that should
be
sent to the provider. It should accept named parameters by
the names TEXT, POST-FIELD and POST-DATA. POST-DATA should
- default to `nil' or empty list.
+ 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'.
TEXT contains the data that should be sent.
POST-FIELD cointains the name of the field to be sent.
@@ -167,6 +205,8 @@ Optional params:
:data (funcall post-field-lambda
:text text
:post-field post-field
+ :post-lang-field-name post-lang-field-name
+ :lang-overrides lang-overrides
:post-data post-data)
:parser parser
:success success-lambda
@@ -198,32 +238,37 @@ Optional params:
("dpaste.com"
,(webpaste-provider
:uri "http://dpaste.com/api/v2/"
- :post-data '(("syntax" . "text")
- ("title" . "")
+ :post-data '(("title" . "")
("poster" . "")
("expiry_days" . 1))
:post-field "content"
+ :post-lang-field-name "syntax"
+ :lang-overrides '((emacs-lisp-mode . "clojure"))
:success-lambda webpaste/providers-success-location-header))
("dpaste.de"
,(webpaste-provider
:uri "https://dpaste.de/api/"
- :post-data '(("lexer" . "text")
- ("format" . "url")
- ("expires" . 86400))
+ :post-data '(("expires" . 86400))
:post-field "content"
+ :post-lang-field-name "lexer"
+ :lang-overrides '((emacs-lisp-mode . "clojure"))
:success-lambda webpaste/providers-success-returned-string))
("gist.github.com"
,(webpaste-provider
:uri "https://api.github.com/gists"
:post-field nil
- :post-field-lambda (cl-function (lambda (&key text post-field
(post-data '()))
- (json-encode `(("description" . "Pasted from Emacs
with webpaste.el")
- ("public" . "false")
- ("files" .
- (("file.txt" .
- (("content" . ,text)))))))))
+ :post-field-lambda (cl-function (lambda (&key text
+ post-field
+ (post-data '())
+ &allow-other-keys)
+ (let ((filename (or
(file-name-nondirectory (buffer-file-name)) "file.txt")))
+ (json-encode `(("description" .
"Pasted from Emacs with webpaste.el")
+ ("public" . "false")
+ ("files" .
+ ((,filename .
+ (("content" .
,text))))))))))
:success-lambda (cl-function (lambda (&key data &allow-other-keys)
(when data
(webpaste-return-url
@@ -239,6 +284,28 @@ return it to the user."
+(defun webpaste/get-lang-alist-with-overrides (overrides)
+ "Fetches lang-alist with OVERRIDES applied."
+
+ (let ((lang-alist webpaste/default-lang-alist))
+ ;; Go through list of overrides
+ (dolist (override-element overrides)
+ ;; Set key and value from override list
+ (let ((key (car override-element))
+ (value (cdr override-element)))
+
+ ;; If the element doesn't exist, add it
+ (unless (assoc (car override-element) lang-alist)
+ (cl-pushnew (cons key value) lang-alist))
+
+ ;; If the element in the list is changed
+ (unless (equal (cdr (assoc key lang-alist)) value)
+ (cl-pushnew (cons key value) lang-alist))))
+
+ lang-alist))
+
+
+
(defun webpaste/get-provider-priority ()
"Return provider priority."
- [nongnu] elpa/webpaste 272757b 056/298: Change documentation string, (continued)
- [nongnu] elpa/webpaste 272757b 056/298: Change documentation string, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 58f66ef 069/298: Bump version to prepare for melpa stable, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 6e34759 072/298: Added another privider to list to implement, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste f378ca9 075/298: Added Cask file, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 2bb8a4c 077/298: Set up tests directory, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste f338ca7 083/298: Added Travis-CI build status image, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste f658339 096/298: Bump version number for stable release, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste e485847 107/298: Break out pasting to provider to own function, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 406d713 115/298: Shared success lambdas between different paste providers, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 7f62fed 118/298: Tidy up some lists in tests with backquotes, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 0e4ac51 132/298: Added support for buffer-language depending on mode for some providers,
ELPA Syncer <=
- [nongnu] elpa/webpaste 9ddc617 133/298: Simplify webpaste/get-lang-alist-with-overrides implementation, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste f08a2dc 136/298: Rename internal variable, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste af0474e 139/298: Merge branch 'naclander-master', ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste b9b2ce0 143/298: Added support for languages for providers that appends language to the URL, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste c091dab 146/298: Change some types based on actual use, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 0144016 147/298: Remove unused variable, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste b5491ab 150/298: Bump version for stable release, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 29d10d7 151/298: Added paste.pound-python.org as provider, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste 410e286 152/298: Added webpaste confirmation tests, ELPA Syncer, 2021/12/09
- [nongnu] elpa/webpaste db8c605 154/298: Rewrite test to cover both if link is opened in external browser or not, ELPA Syncer, 2021/12/09